{"version":3,"file":"resolveApiUrl.mjs","sources":["../../../src/utils/resolveApiUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyUrl, AmplifyUrlSearchParams, } from '@aws-amplify/core/internals/utils';\nimport { RestApiError, RestApiValidationErrorCode, assertValidationError, validationErrorMap, } from '../errors';\n/**\n * Resolve the REST API request URL by:\n * 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.\n * 2. Appending the path to the endpoint.\n * 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API\n *   options.\n * 4. Validating the resulting URL string.\n *\n * @internal\n */\nexport const resolveApiUrl = (amplify, apiName, path, queryParams) => {\n    const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;\n    assertValidationError(!!urlStr, RestApiValidationErrorCode.InvalidApiName);\n    try {\n        let url;\n        if (AmplifyUrl.canParse(urlStr + path)) {\n            url = new AmplifyUrl(urlStr + path);\n        }\n        else {\n            url = new AmplifyUrl(urlStr + path, location?.origin);\n        }\n        if (queryParams) {\n            const mergedQueryParams = new AmplifyUrlSearchParams(url.searchParams);\n            Object.entries(queryParams).forEach(([key, value]) => {\n                mergedQueryParams.set(key, value);\n            });\n            url.search = new AmplifyUrlSearchParams(mergedQueryParams).toString();\n        }\n        return url;\n    }\n    catch (error) {\n        throw new RestApiError({\n            name: RestApiValidationErrorCode.InvalidApiName,\n            ...validationErrorMap[RestApiValidationErrorCode.InvalidApiName],\n            recoverySuggestion: `Please make sure the REST endpoint URL is a valid URL string. Got ${urlStr}`,\n        });\n    }\n};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK;AACtE,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,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