{"version":3,"file":"parseSigningInfo.mjs","sources":["../../../src/utils/parseSigningInfo.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { APIG_HOSTNAME_PATTERN, DEFAULT_IAM_SIGNING_REGION, DEFAULT_REST_IAM_SIGNING_SERVICE, } from './constants';\n/**\n * Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.\n * It supports raw API Gateway endpoint and AppSync endpoint.\n *\n * @internal\n */\nexport const parseSigningInfo = (url, restApiOptions) => {\n    const { service: signingService = DEFAULT_REST_IAM_SIGNING_SERVICE, region: signingRegion = DEFAULT_IAM_SIGNING_REGION, } = restApiOptions?.amplify.getConfig()?.API?.REST?.[restApiOptions?.apiName] ??\n        {};\n    const { hostname } = url;\n    const [, service, region] = APIG_HOSTNAME_PATTERN.exec(hostname) ?? [];\n    if (service === DEFAULT_REST_IAM_SIGNING_SERVICE) {\n        // The configured endpoint is an API Gateway endpoint\n        // @see: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html\n        return {\n            service,\n            region: region ?? signingRegion,\n        };\n    }\n    else if (service === 'appsync-api') {\n        // AppSync endpoint is internally supported because GraphQL operation will send request using POST handler.\n        // example: https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\n        return {\n            service: 'appsync',\n            region: region ?? signingRegion,\n        };\n    }\n    else {\n        return {\n            service: signingService,\n            region: signingRegion,\n        };\n    }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,gBAAgB,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK;AACzD,IAAI,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,gCAAgC,EAAE,MAAM,EAAE,aAAa,GAAG,0BAA0B,GAAG,GAAG,cAAc,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,cAAc,EAAE,OAAO,CAAC;AACzM,QAAQ,EAAE;AACV,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG;AAC5B,IAAI,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;AAC1E,IAAI,IAAI,OAAO,KAAK,gCAAgC,EAAE;AACtD;AACA;AACA,QAAQ,OAAO;AACf,YAAY,OAAO;AACnB,YAAY,MAAM,EAAE,MAAM,IAAI,aAAa;AAC3C,SAAS;AACT,IAAI;AACJ,SAAS,IAAI,OAAO,KAAK,aAAa,EAAE;AACxC;AACA;AACA,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,SAAS;AAC9B,YAAY,MAAM,EAAE,MAAM,IAAI,aAAa;AAC3C,SAAS;AACT,IAAI;AACJ,SAAS;AACT,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,cAAc;AACnC,YAAY,MAAM,EAAE,aAAa;AACjC,SAAS;AACT,IAAI;AACJ;;;;"}