"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALID_DATASOURCE_ENVIRONMENTS = exports.ENVIRONMENT_ALL = exports.ENVIRONMENT_DEV = exports.ENVIRONMENT_STAGING = exports.ENVIRONMENT_PRODUCTION = exports.DatasourceEnvironments = exports.SharedSSHAuthMethod = exports.ViewDatasourceDto = exports.DatasourceDto = exports.PluginCommon = void 0;
exports.getAuthIdFromConfig = getAuthIdFromConfig;
exports.isAuthenticatedDatasourceConfig = isAuthenticatedDatasourceConfig;
exports.isAuthenticatedDatasourceConfigWithDynamicAuthType = isAuthenticatedDatasourceConfigWithDynamicAuthType;
exports.getAuthTypeFromConfig = getAuthTypeFromConfig;
const auth_js_1 = require("./auth.js");
var types_1 = require("@superblocksteam/types");
Object.defineProperty(exports, "PluginCommon", { enumerable: true, get: function () { return types_1.PluginCommonV1; } });
// The DTO for the full datasource (ie all fields). This should only be visible
// to users that can configure the datasource.
class DatasourceDto {
    id;
    name;
    pluginId;
    pluginName;
    organizationId;
    configuration;
    //TODO(alex): delete configurationProd, configurationStaging once we change an interface between UI and server
    // @deprecated use configurationProfiles instead
    configurationProd;
    // @deprecated use configurationProfiles instead
    configurationStaging;
    configurationProfiles;
    isDefault;
    creator;
    demoIntegrationId;
    ownerEmail;
    error;
    constructor(datasource, ownerEmail, configurationProfiles) {
        this.id = datasource.id;
        this.name = datasource.name;
        this.pluginId = datasource.pluginId;
        this.organizationId = datasource.organizationId;
        this.demoIntegrationId = datasource.demoIntegrationId;
        this.configuration = datasource.configurationProd;
        this.configurationProd = datasource.configurationProd;
        this.configurationStaging = datasource.configurationStaging;
        this.configurationProfiles = configurationProfiles;
        this.isDefault = datasource.isDefault;
        this.ownerEmail = ownerEmail;
    }
}
exports.DatasourceDto = DatasourceDto;
// ViewDatasourceDto is just the information needed to use a datasource to
// create steps of that type. Credentials are explicitly excluded - those should
// only be needed to execute the step.
class ViewDatasourceDto {
    id;
    name;
    pluginId;
    organizationId;
    isDefault;
    readOnly;
    ownerEmail;
    constructor(datasource, readOnly, ownerEmail) {
        this.id = datasource.id;
        this.name = datasource.name;
        this.pluginId = datasource.pluginId;
        this.organizationId = datasource.organizationId;
        this.isDefault = datasource.isDefault;
        this.readOnly = readOnly;
        this.ownerEmail = ownerEmail;
    }
}
exports.ViewDatasourceDto = ViewDatasourceDto;
function getAuthIdFromConfig(integrationId, config) {
    if (config.authType) {
        return (0, auth_js_1.getAuthId)(config.authType, config.authConfig, integrationId);
    }
    return 'empty-auth-type';
}
var SharedSSHAuthMethod;
(function (SharedSSHAuthMethod) {
    SharedSSHAuthMethod[SharedSSHAuthMethod["PASSWORD"] = 0] = "PASSWORD";
    SharedSSHAuthMethod[SharedSSHAuthMethod["PUB_KEY_RSA"] = 1] = "PUB_KEY_RSA";
    SharedSSHAuthMethod[SharedSSHAuthMethod["PUB_KEY_ED25519"] = 2] = "PUB_KEY_ED25519";
    SharedSSHAuthMethod[SharedSSHAuthMethod["USER_PRIVATE_KEY"] = 3] = "USER_PRIVATE_KEY";
})(SharedSSHAuthMethod || (exports.SharedSSHAuthMethod = SharedSSHAuthMethod = {}));
function isAuthenticatedDatasourceConfig(dc) {
    if (!('authConfig' in dc)) {
        return false;
    }
    return 'authType' in dc && dc.authType !== undefined;
}
function isAuthenticatedDatasourceConfigWithDynamicAuthType(dc) {
    if (!('authConfig' in dc)) {
        return false;
    }
    if ('authTypeField' in dc &&
        dc.authTypeField &&
        dc[dc.authTypeField] !== undefined &&
        dc[dc.authTypeField] !== null &&
        dc[dc.authTypeField] !== '') {
        return true;
    }
    return false;
}
/**
 * Safely extracts the authType from an authenticated datasource configuration.
 * This function handles both direct authType fields and authTypeField references.
 *
 * @param dc - The datasource configuration
 * @returns The authType if available, undefined otherwise
 */
function getAuthTypeFromConfig(dc) {
    if (isAuthenticatedDatasourceConfig(dc)) {
        return dc.authType;
    }
    else if (isAuthenticatedDatasourceConfigWithDynamicAuthType(dc)) {
        return dc[dc.authTypeField];
    }
    return undefined;
}
var DatasourceEnvironments;
(function (DatasourceEnvironments) {
    DatasourceEnvironments["PRODUCTION"] = "Production";
    DatasourceEnvironments["STAGING"] = "Staging";
    DatasourceEnvironments["DEV"] = "Dev";
})(DatasourceEnvironments || (exports.DatasourceEnvironments = DatasourceEnvironments = {}));
exports.ENVIRONMENT_PRODUCTION = 'production';
exports.ENVIRONMENT_STAGING = 'staging'; // Only for V1 orgs, V2 orgs use ENVIRONMENT_DEV
exports.ENVIRONMENT_DEV = 'dev';
exports.ENVIRONMENT_ALL = '*';
exports.VALID_DATASOURCE_ENVIRONMENTS = [exports.ENVIRONMENT_PRODUCTION, exports.ENVIRONMENT_DEV, exports.ENVIRONMENT_STAGING, exports.ENVIRONMENT_ALL];
__exportStar(require("./auth.js"), exports);
__exportStar(require("./metadata/index.js"), exports);
__exportStar(require("./test.js"), exports);
//# sourceMappingURL=index.js.map