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,GACJ,CAKA,eAAA,GACI,OAAO,UAAU,UAAM,OAAQ,GAAQ,kBAC7B,QAAQ,IAAI,KAAK,QAAQ,KAAK,GAAW,UAAU,UAAM,OAAQ,GAAQ,YAC3E,MAAM,EAAa,KAAK,cAAc,GACtC,EAAO,iBAAmB,EAAW,gBAAgB,EACzD,OAAK,SAAQ,KACT,UAAU,QAAQ,mBAAmB,KAAK,QAAQ,GAE1D,GACJ,CAIA,UAAA,CAAW,GACP,MAAM,EAAU,KAAK,WAAW,QAC3B,EAAQ,SAAS,+BAA+B,UACjD,EAAQ,SAAS,+BAA+B,QAAU,CAAC,GAG/D,IAAI,EAAkC,yBAClC,EAAsB,aACtB,EAAwB,eACxB,EAAO,UAAY,UAAU,QAAQ,SAAS,MAC9C,GAAmC,OACnC,GAAuB,OACvB,GAAyB,QAEpB,EAAO,UAAY,UAAU,QAAQ,SAAS,YACnD,GAAmC,YACnC,GAAuB,YACvB,GAAyB,aAI7B,MAAM,EAAY,UAAU,QAAQ,eAAe,QAAQ,eAAgB,IAC3E,EAAQ,SAAS,+BAA+B,QAAQ,GAAuB,CAC3E,MAAO,EAAO,gBACd,OAAQ,CACJ,KAAM,OAAO,EAAQ,WAAW,KAAa,MAGjD,EAAO,aACP,EAAQ,SAAS,+BAA+B,QAAQ,GAAmC,CACvF,MAAO,EAAO,WAAW,WACzB,OAAQ,CACJ,KAAM,OAAO,EAAQ,WAAW,KAAa,MAGrD,EAAQ,SAAS,+BAA+B,QAAQ,GAAyB,CAC7E,MAAO,EAAO,WAAW,aACzB,OAAQ,CACJ,KAAM,OAAO,EAAQ,WAAW,KAAa,MAI7D,EAEJ,OAAO,QAAU","file":"/npm/serverless-domain-manager@10.1.0/dist/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/serverless-domain-manager@10.1.0/dist/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nconst ACMWrapper = require(\"./aws/acm-wrapper\");\nconst CloudFormationWrapper = require(\"./aws/cloud-formation-wrapper\");\nconst Route53Wrapper = require(\"./aws/route53-wrapper\");\nconst S3Wrapper = require(\"./aws/s3-wrapper\");\nconst DomainConfig = require(\"./models/domain-config\");\nconst globals_1 = __importDefault(require(\"./globals\"));\nconst utils_1 = require(\"./utils\");\nconst APIGatewayV1Wrapper = require(\"./aws/api-gateway-v1-wrapper\");\nconst APIGatewayV2Wrapper = require(\"./aws/api-gateway-v2-wrapper\");\nconst logging_1 = __importDefault(require(\"./logging\"));\nconst node_config_provider_1 = require(\"@smithy/node-config-provider\");\nconst config_resolver_1 = require(\"@smithy/config-resolver\");\nconst client_route_53_1 = require(\"@aws-sdk/client-route-53\");\nclass ServerlessCustomDomain {\n    constructor(serverless, options, v3Utils) {\n        // Domain Manager specific properties\n        this.domains = [];\n        this.serverless = serverless;\n        globals_1.default.serverless = serverless;\n        this.options = options;\n        globals_1.default.options = options;\n        if (v3Utils === null || v3Utils === void 0 ? void 0 : v3Utils.log) {\n            globals_1.default.v3Utils = v3Utils;\n        }\n        /* eslint camelcase: [\"error\", {allow: [\"create_domain\", \"delete_domain\"]}] */\n        this.commands = {\n            create_domain: {\n                lifecycleEvents: [\n                    \"create\",\n                    \"initialize\"\n                ],\n                usage: \"Creates a domain using the domain name defined in the serverless file\"\n            },\n            delete_domain: {\n                lifecycleEvents: [\n                    \"delete\",\n                    \"initialize\"\n                ],\n                usage: \"Deletes a domain using the domain name defined in the serverless file\"\n            }\n        };\n        this.hooks = {\n            \"after:deploy:deploy\": this.hookWrapper.bind(this, this.setupBasePathMappings),\n            \"after:info:info\": this.hookWrapper.bind(this, this.domainSummaries),\n            \"before:deploy:deploy\": this.hookWrapper.bind(this, this.createOrGetDomainForCfOutputs),\n            \"before:remove:remove\": this.hookWrapper.bind(this, this.removeBasePathMappings),\n            \"create_domain:create\": this.hookWrapper.bind(this, this.createDomains),\n            \"delete_domain:delete\": this.hookWrapper.bind(this, this.deleteDomains)\n        };\n    }\n    /**\n     * Wrapper for lifecycle function, initializes variables and checks if enabled.\n     * @param lifecycleFunc lifecycle function that actually does desired action\n     */\n    hookWrapper(lifecycleFunc) {\n        return __awaiter(this, void 0, void 0, function* () {\n            // check if `customDomain` or `customDomains` config exists\n            this.validateConfigExists();\n            // init config variables\n            this.initializeVariables();\n            // Validate the domain configurations\n            this.validateDomainConfigs();\n            // setup AWS resources\n            yield this.initSLSCredentials();\n            yield this.initAWSRegion();\n            yield this.initAWSResources();\n            // start of the legacy AWS SDK V2 creds support\n            // TODO: remove it in case serverless will add V3 support\n            const domain = this.domains[0];\n            if (domain) {\n                try {\n                    yield this.getApiGateway(domain).getCustomDomain(domain);\n                }\n                catch (error) {\n                    if (error.message.includes(\"Could not load credentials from any providers\")) {\n                        globals_1.default.credentials = this.serverless.providers.aws.getCredentials();\n                        yield this.initAWSResources();\n                    }\n                }\n            }\n            // end of the legacy AWS SDK V2 creds support\n            return lifecycleFunc.call(this);\n        });\n    }\n    /**\n     * Validate if the plugin config exists\n     */\n    validateConfigExists() {\n        // Make sure customDomain configuration exists, stop if not\n        const config = this.serverless.service.custom;\n        const domainExists = config && typeof config.customDomain !== \"undefined\";\n        const domainsExists = config && typeof config.customDomains !== \"undefined\";\n        if (typeof config === \"undefined\" || (!domainExists && !domainsExists)) {\n            throw new Error(`${globals_1.default.pluginName}: Plugin configuration is missing.`);\n        }\n    }\n    /**\n     * Goes through custom domain property and initializes local variables and cloudformation template\n     */\n    initializeVariables() {\n        const config = this.serverless.service.custom;\n        const domainConfig = config.customDomain ? [config.customDomain] : [];\n        const domainsConfig = config.customDomains || [];\n        const customDomains = domainConfig.concat(domainsConfig);\n        // Loop over the domain configurations and populate the domains array with DomainConfigs\n        this.domains = [];\n        customDomains.forEach((domain) => {\n            // If the key of the item in config is an API type then using per API type domain structure\n            let isTypeConfigFound = false;\n            Object.keys(globals_1.default.apiTypes).forEach((apiType) => {\n                const domainTypeConfig = domain[apiType];\n                if (domainTypeConfig) {\n                    domainTypeConfig.apiType = apiType;\n                    this.domains.push(new DomainConfig(domainTypeConfig));\n                    isTypeConfigFound = true;\n                }\n            });\n            if (!isTypeConfigFound) {\n                this.domains.push(new DomainConfig(domain));\n            }\n        });\n        // Filter inactive domains\n        this.domains = this.domains.filter((domain) => domain.enabled);\n    }\n    /**\n     * Validates domain configs to make sure they are valid, ie HTTP api cannot be used with EDGE domain\n     */\n    validateDomainConfigs() {\n        this.domains.forEach((domain) => {\n            if (domain.apiType === globals_1.default.apiTypes.rest) {\n                // No validation for REST API types\n            }\n            if (domain.apiType === globals_1.default.apiTypes.http) {\n                // HTTP APIs do not support edge domains\n                if (domain.endpointType === globals_1.default.endpointTypes.edge || domain.endpointType === globals_1.default.endpointTypes.private) {\n                    // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html\n                    throw Error(\"'EDGE' or 'PRIVATE' endpointType is not compatible with HTTP APIs\\n\" +\n                        \"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html\");\n                }\n            }\n            if (domain.apiType === globals_1.default.apiTypes.websocket) {\n                // Websocket APIs do not support edge domains\n                if (domain.endpointType === globals_1.default.endpointTypes.edge || domain.endpointType === globals_1.default.endpointTypes.private) {\n                    throw Error(\"'EDGE' or 'PRIVATE' endpointType is not compatible with WebSocket APIs\");\n                }\n            }\n        });\n    }\n    /**\n     * Init AWS credentials based on sls `provider.profile`\n     */\n    initSLSCredentials() {\n        return __awaiter(this, void 0, void 0, function* () {\n            const slsProfile = globals_1.default.options[\"aws-profile\"] || globals_1.default.serverless.service.provider.profile;\n            globals_1.default.credentials = slsProfile ? yield globals_1.default.getProfileCreds(slsProfile) : null;\n        });\n    }\n    /**\n     * Init AWS current region based on Node options\n     */\n    initAWSRegion() {\n        return __awaiter(this, void 0, void 0, function* () {\n            try {\n                globals_1.default.currentRegion = yield (0, node_config_provider_1.loadConfig)(config_resolver_1.NODE_REGION_CONFIG_OPTIONS, config_resolver_1.NODE_REGION_CONFIG_FILE_OPTIONS)();\n            }\n            catch (err) {\n                logging_1.default.logInfo(\"Node region was not found.\");\n            }\n        });\n    }\n    /**\n     * Setup AWS resources\n     */\n    initAWSResources() {\n        return __awaiter(this, void 0, void 0, function* () {\n            this.apiGatewayV1Wrapper = new APIGatewayV1Wrapper(globals_1.default.credentials);\n            this.apiGatewayV2Wrapper = new APIGatewayV2Wrapper(globals_1.default.credentials);\n            this.cloudFormationWrapper = new CloudFormationWrapper(globals_1.default.credentials);\n            this.s3Wrapper = new S3Wrapper(globals_1.default.credentials);\n        });\n    }\n    getApiGateway(domain) {\n        // 1. https://stackoverflow.com/questions/72339224/aws-v1-vs-v2-api-for-listing-apis-on-aws-api-gateway-return-different-data-for-t\n        // 2. https://aws.amazon.com/blogs/compute/announcing-http-apis-for-amazon-api-gateway/\n        // There are currently two API Gateway namespaces for managing API Gateway deployments.\n        // The API V1 namespace represents REST APIs and API V2 represents WebSocket APIs and the new HTTP APIs.\n        // You can create an HTTP API by using the AWS Management Console, CLI, APIs, CloudFormation, SDKs, or the Serverless Application Model (SAM).\n        if (domain.apiType !== globals_1.default.apiTypes.rest) {\n            return this.apiGatewayV2Wrapper;\n        }\n        // multi-level base path mapping is supported by Gateway V2\n        // https://github.com/amplify-education/serverless-domain-manager/issues/558\n        // https://aws.amazon.com/blogs/compute/using-multiple-segments-in-amazon-api-gateway-base-path-mapping/\n        if (domain.basePath.includes(\"/\")) {\n            return this.apiGatewayV2Wrapper;\n        }\n        return this.apiGatewayV1Wrapper;\n    }\n    /**\n     * Lifecycle function to create a domain\n     * Wraps creating a domain and resource record set\n     */\n    createDomains() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                yield this.createDomain(domain);\n            })));\n        });\n    }\n    /**\n     * Lifecycle function to create a domain\n     * Wraps creating a domain and resource record set\n     */\n    createDomain(domain) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const creationProgress = globals_1.default.v3Utils && globals_1.default.v3Utils.progress.get(`create-${domain.givenDomainName}`);\n            const route53Creds = domain.route53Profile ? yield globals_1.default.getProfileCreds(domain.route53Profile) : globals_1.default.credentials;\n            const apiGateway = this.getApiGateway(domain);\n            const route53 = new Route53Wrapper(route53Creds, domain.route53Region);\n            const acm = new ACMWrapper(globals_1.default.credentials, domain.endpointType);\n            domain.domainInfo = yield apiGateway.getCustomDomain(domain);\n            try {\n                if (!domain.domainInfo) {\n                    if (domain.tlsTruststoreUri) {\n                        yield this.s3Wrapper.assertTlsCertObjectExists(domain);\n                    }\n                    if (!domain.certificateArn) {\n                        domain.certificateArn = yield acm.getCertArn(domain);\n                    }\n                    domain.domainInfo = yield apiGateway.createCustomDomain(domain);\n                    logging_1.default.logInfo(`Custom domain '${domain.givenDomainName}' was created.\n                 New domains may take up to 40 minutes to be initialized.`);\n                }\n                else {\n                    logging_1.default.logInfo(`Custom domain '${domain.givenDomainName}' already exists.`);\n                }\n                yield route53.changeResourceRecordSet(client_route_53_1.ChangeAction.UPSERT, domain);\n            }\n            catch (err) {\n                throw new Error(`Unable to create domain '${domain.givenDomainName}':\\n${err.message}`);\n            }\n            finally {\n                if (creationProgress) {\n                    creationProgress.remove();\n                }\n            }\n        });\n    }\n    /**\n     * Lifecycle function to delete a domain\n     * Wraps deleting a domain and resource record set\n     */\n    deleteDomains() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                yield this.deleteDomain(domain);\n            })));\n        });\n    }\n    /**\n     * Wraps deleting a domain and resource record set\n     */\n    deleteDomain(domain) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const apiGateway = this.getApiGateway(domain);\n            const route53Creds = domain.route53Profile ? yield globals_1.default.getProfileCreds(domain.route53Profile) : null;\n            const route53 = new Route53Wrapper(route53Creds, domain.route53Region);\n            domain.domainInfo = yield apiGateway.getCustomDomain(domain);\n            try {\n                if (domain.domainInfo) {\n                    yield apiGateway.deleteCustomDomain(domain);\n                    yield route53.changeResourceRecordSet(client_route_53_1.ChangeAction.DELETE, domain);\n                    domain.domainInfo = null;\n                    logging_1.default.logInfo(`Custom domain ${domain.givenDomainName} was deleted.`);\n                }\n                else {\n                    logging_1.default.logInfo(`Custom domain ${domain.givenDomainName} does not exist.`);\n                }\n            }\n            catch (err) {\n                throw new Error(`Unable to delete domain '${domain.givenDomainName}':\\n${err.message}`);\n            }\n        });\n    }\n    /**\n     * Lifecycle function to createDomain before deploy and add domain info to the CloudFormation stack's Outputs\n     */\n    createOrGetDomainForCfOutputs() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                if (domain.autoDomain) {\n                    logging_1.default.logInfo(\"Creating domain name before deploy.\");\n                    yield this.createDomain(domain);\n                }\n                const apiGateway = this.getApiGateway(domain);\n                domain.domainInfo = yield apiGateway.getCustomDomain(domain);\n                if (domain.autoDomain) {\n                    const atLeastOneDoesNotExist = () => this.domains.some((d) => !d.domainInfo);\n                    const maxWaitFor = parseInt(domain.autoDomainWaitFor, 10) || 120;\n                    const pollInterval = 3;\n                    for (let i = 0; i * pollInterval < maxWaitFor && atLeastOneDoesNotExist() === true; i++) {\n                        logging_1.default.logInfo(`\n                        Poll #${i + 1}: polling every ${pollInterval} seconds\n                        for domain to exist or until ${maxWaitFor} seconds\n                        have elapsed before starting deployment\n                    `);\n                        yield (0, utils_1.sleep)(pollInterval);\n                        domain.domainInfo = yield apiGateway.getCustomDomain(domain);\n                    }\n                }\n                this.addOutputs(domain);\n            })));\n        });\n    }\n    /**\n     * Lifecycle function to create basepath mapping\n     * Wraps creation of basepath mapping and adds domain name info as output to cloudformation stack\n     */\n    setupBasePathMappings() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                domain.apiId = yield this.cloudFormationWrapper.findApiId(domain.apiType);\n                const apiGateway = this.getApiGateway(domain);\n                const mappings = yield apiGateway.getBasePathMappings(domain);\n                const filteredMappings = mappings.filter((mapping) => {\n                    if (domain.allowPathMatching) {\n                        return mapping.basePath === domain.basePath;\n                    }\n                    return mapping.apiId === domain.apiId;\n                });\n                domain.apiMapping = filteredMappings ? filteredMappings[0] : null;\n                domain.domainInfo = yield apiGateway.getCustomDomain(domain, false);\n                if (!domain.apiMapping) {\n                    yield apiGateway.createBasePathMapping(domain);\n                }\n                else {\n                    yield apiGateway.updateBasePathMapping(domain);\n                }\n            }))).finally(() => {\n                logging_1.default.printDomainSummary(this.domains);\n            });\n        });\n    }\n    /**\n     * Lifecycle function to delete basepath mapping\n     * Wraps deletion of basepath mapping\n     */\n    removeBasePathMappings() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                let externalBasePathExists = false;\n                try {\n                    domain.apiId = yield this.cloudFormationWrapper.findApiId(domain.apiType);\n                    // Unable to find the corresponding API, manual clean up will be required\n                    if (!domain.apiId) {\n                        logging_1.default.logInfo(`Unable to find corresponding API for '${domain.givenDomainName}',\n                        API Mappings may need to be manually removed.`);\n                    }\n                    else {\n                        const apiGateway = this.getApiGateway(domain);\n                        const mappings = yield apiGateway.getBasePathMappings(domain);\n                        const filteredMappings = mappings.filter((mapping) => {\n                            if (domain.allowPathMatching) {\n                                return mapping.basePath === domain.basePath;\n                            }\n                            return mapping.apiId === domain.apiId && mapping.stage === domain.stage;\n                        });\n                        if (domain.preserveExternalPathMappings) {\n                            externalBasePathExists = mappings.length > filteredMappings.length;\n                        }\n                        domain.apiMapping = filteredMappings ? filteredMappings[0] : null;\n                        if (domain.apiMapping) {\n                            yield apiGateway.deleteBasePathMapping(domain);\n                        }\n                        else {\n                            logging_1.default.logWarning(`Api mapping was not found for '${domain.givenDomainName}'. Skipping base path deletion.`);\n                        }\n                    }\n                }\n                catch (err) {\n                    if (err.message.indexOf(\"Failed to find CloudFormation\") > -1) {\n                        logging_1.default.logWarning(`Unable to find Cloudformation Stack for ${domain.givenDomainName},\n                        API Mappings may need to be manually removed.`);\n                    }\n                    else {\n                        logging_1.default.logWarning(`Unable to remove base path mappings for '${domain.givenDomainName}':\\n${err.message}`);\n                    }\n                    if (domain.preserveExternalPathMappings) {\n                        externalBasePathExists = true;\n                    }\n                }\n                if (domain.autoDomain === true && !externalBasePathExists) {\n                    logging_1.default.logInfo(\"Deleting domain name after removing base path mapping.\");\n                    yield this.deleteDomain(domain);\n                }\n            })));\n        });\n    }\n    /**\n     * Lifecycle function to print domain summary\n     * Wraps printing of all domain manager related info\n     */\n    domainSummaries() {\n        return __awaiter(this, void 0, void 0, function* () {\n            yield Promise.all(this.domains.map((domain) => __awaiter(this, void 0, void 0, function* () {\n                const apiGateway = this.getApiGateway(domain);\n                domain.domainInfo = yield apiGateway.getCustomDomain(domain);\n            }))).finally(() => {\n                logging_1.default.printDomainSummary(this.domains);\n            });\n        });\n    }\n    /**\n     *  Adds the domain name and distribution domain name to the CloudFormation outputs\n     */\n    addOutputs(domain) {\n        const service = this.serverless.service;\n        if (!service.provider.compiledCloudFormationTemplate.Outputs) {\n            service.provider.compiledCloudFormationTemplate.Outputs = {};\n        }\n        // Defaults for REST and backwards compatibility\n        let distributionDomainNameOutputKey = \"DistributionDomainName\";\n        let domainNameOutputKey = \"DomainName\";\n        let hostedZoneIdOutputKey = \"HostedZoneId\";\n        if (domain.apiType === globals_1.default.apiTypes.http) {\n            distributionDomainNameOutputKey += \"Http\";\n            domainNameOutputKey += \"Http\";\n            hostedZoneIdOutputKey += \"Http\";\n        }\n        else if (domain.apiType === globals_1.default.apiTypes.websocket) {\n            distributionDomainNameOutputKey += \"Websocket\";\n            domainNameOutputKey += \"Websocket\";\n            hostedZoneIdOutputKey += \"Websocket\";\n        }\n        // for the CloudFormation stack we should use the `base` stage not the plugin custom stage\n        // Remove all special characters\n        const safeStage = globals_1.default.getBaseStage().replace(/[^a-zA-Z\\d]/g, \"\");\n        service.provider.compiledCloudFormationTemplate.Outputs[domainNameOutputKey] = {\n            Value: domain.givenDomainName,\n            Export: {\n                Name: `sls-${service.service}-${safeStage}-${domainNameOutputKey}`\n            }\n        };\n        if (domain.domainInfo) {\n            service.provider.compiledCloudFormationTemplate.Outputs[distributionDomainNameOutputKey] = {\n                Value: domain.domainInfo.domainName,\n                Export: {\n                    Name: `sls-${service.service}-${safeStage}-${distributionDomainNameOutputKey}`\n                }\n            };\n            service.provider.compiledCloudFormationTemplate.Outputs[hostedZoneIdOutputKey] = {\n                Value: domain.domainInfo.hostedZoneId,\n                Export: {\n                    Name: `sls-${service.service}-${safeStage}-${hostedZoneIdOutputKey}`\n                }\n            };\n        }\n    }\n}\nmodule.exports = ServerlessCustomDomain;\n"]}