@aws-amplify/api-rest 0.0.0-unstable-1ca644b-20260128091132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js +17 -0
- package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js.map +1 -0
- package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js +13 -0
- package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js.map +1 -0
- package/dist/cjs/apis/common/internalPost.js +98 -0
- package/dist/cjs/apis/common/internalPost.js.map +1 -0
- package/dist/cjs/apis/common/publicApis.js +57 -0
- package/dist/cjs/apis/common/publicApis.js.map +1 -0
- package/dist/cjs/apis/common/transferHandler.js +92 -0
- package/dist/cjs/apis/common/transferHandler.js.map +1 -0
- package/dist/cjs/apis/index.js +217 -0
- package/dist/cjs/apis/index.js.map +1 -0
- package/dist/cjs/apis/server.js +163 -0
- package/dist/cjs/apis/server.js.map +1 -0
- package/dist/cjs/errors/CanceledError.js +37 -0
- package/dist/cjs/errors/CanceledError.js.map +1 -0
- package/dist/cjs/errors/RestApiError.js +17 -0
- package/dist/cjs/errors/RestApiError.js.map +1 -0
- package/dist/cjs/errors/assertValidatonError.js +18 -0
- package/dist/cjs/errors/assertValidatonError.js.map +1 -0
- package/dist/cjs/errors/index.js +17 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/validation.js +17 -0
- package/dist/cjs/errors/validation.js.map +1 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internals/index.js +12 -0
- package/dist/cjs/internals/index.js.map +1 -0
- package/dist/cjs/internals/server.js +32 -0
- package/dist/cjs/internals/server.js.map +1 -0
- package/dist/cjs/server.js +16 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types/index.js +4 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/constants.js +15 -0
- package/dist/cjs/utils/constants.js.map +1 -0
- package/dist/cjs/utils/createCancellableOperation.js +76 -0
- package/dist/cjs/utils/createCancellableOperation.js.map +1 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isIamAuthApplicable.js +39 -0
- package/dist/cjs/utils/isIamAuthApplicable.js.map +1 -0
- package/dist/cjs/utils/logger.js +9 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/parseSigningInfo.js +43 -0
- package/dist/cjs/utils/parseSigningInfo.js.map +1 -0
- package/dist/cjs/utils/resolveApiUrl.js +48 -0
- package/dist/cjs/utils/resolveApiUrl.js.map +1 -0
- package/dist/cjs/utils/resolveHeaders.js +34 -0
- package/dist/cjs/utils/resolveHeaders.js.map +1 -0
- package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
- package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
- package/dist/cjs/utils/serviceError.js +98 -0
- package/dist/cjs/utils/serviceError.js.map +1 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.d.ts +5 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs +16 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs.map +1 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.d.ts +5 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs +12 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs.map +1 -0
- package/dist/esm/apis/common/internalPost.d.ts +43 -0
- package/dist/esm/apis/common/internalPost.mjs +98 -0
- package/dist/esm/apis/common/internalPost.mjs.map +1 -0
- package/dist/esm/apis/common/publicApis.d.ts +8 -0
- package/dist/esm/apis/common/publicApis.mjs +56 -0
- package/dist/esm/apis/common/publicApis.mjs.map +1 -0
- package/dist/esm/apis/common/transferHandler.d.ts +26 -0
- package/dist/esm/apis/common/transferHandler.mjs +95 -0
- package/dist/esm/apis/common/transferHandler.mjs.map +1 -0
- package/dist/esm/apis/index.d.ts +203 -0
- package/dist/esm/apis/index.mjs +210 -0
- package/dist/esm/apis/index.mjs.map +1 -0
- package/dist/esm/apis/server.d.ts +150 -0
- package/dist/esm/apis/server.mjs +156 -0
- package/dist/esm/apis/server.mjs.map +1 -0
- package/dist/esm/errors/CanceledError.d.ts +20 -0
- package/dist/esm/errors/CanceledError.mjs +34 -0
- package/dist/esm/errors/CanceledError.mjs.map +1 -0
- package/dist/esm/errors/RestApiError.d.ts +4 -0
- package/dist/esm/errors/RestApiError.mjs +15 -0
- package/dist/esm/errors/RestApiError.mjs.map +1 -0
- package/dist/esm/errors/assertValidatonError.d.ts +5 -0
- package/dist/esm/errors/assertValidatonError.mjs +17 -0
- package/dist/esm/errors/assertValidatonError.mjs.map +1 -0
- package/dist/esm/errors/index.d.ts +4 -0
- package/dist/esm/errors/index.mjs +5 -0
- package/dist/esm/errors/index.mjs.map +1 -0
- package/dist/esm/errors/validation.d.ts +5 -0
- package/dist/esm/errors/validation.mjs +15 -0
- package/dist/esm/errors/validation.mjs.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/internals/index.d.ts +2 -0
- package/dist/esm/internals/index.mjs +2 -0
- package/dist/esm/internals/index.mjs.map +1 -0
- package/dist/esm/internals/server.d.ts +20 -0
- package/dist/esm/internals/server.mjs +28 -0
- package/dist/esm/internals/server.mjs.map +1 -0
- package/dist/esm/server.d.ts +2 -0
- package/dist/esm/server.mjs +3 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +122 -0
- package/dist/esm/types/index.mjs +2 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/dist/esm/utils/constants.d.ts +8 -0
- package/dist/esm/utils/constants.mjs +13 -0
- package/dist/esm/utils/constants.mjs.map +1 -0
- package/dist/esm/utils/createCancellableOperation.d.ts +12 -0
- package/dist/esm/utils/createCancellableOperation.mjs +77 -0
- package/dist/esm/utils/createCancellableOperation.mjs.map +1 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.mjs +7 -0
- package/dist/esm/utils/index.mjs.map +1 -0
- package/dist/esm/utils/isIamAuthApplicable.d.ts +32 -0
- package/dist/esm/utils/isIamAuthApplicable.mjs +35 -0
- package/dist/esm/utils/isIamAuthApplicable.mjs.map +1 -0
- package/dist/esm/utils/logger.d.ts +2 -0
- package/dist/esm/utils/logger.mjs +8 -0
- package/dist/esm/utils/logger.mjs.map +1 -0
- package/dist/esm/utils/parseSigningInfo.d.ts +14 -0
- package/dist/esm/utils/parseSigningInfo.mjs +41 -0
- package/dist/esm/utils/parseSigningInfo.mjs.map +1 -0
- package/dist/esm/utils/resolveApiUrl.d.ts +12 -0
- package/dist/esm/utils/resolveApiUrl.mjs +48 -0
- package/dist/esm/utils/resolveApiUrl.mjs.map +1 -0
- package/dist/esm/utils/resolveHeaders.d.ts +1 -0
- package/dist/esm/utils/resolveHeaders.mjs +31 -0
- package/dist/esm/utils/resolveHeaders.mjs.map +1 -0
- package/dist/esm/utils/resolveLibraryOptions.d.ts +8 -0
- package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
- package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
- package/dist/esm/utils/serviceError.d.ts +13 -0
- package/dist/esm/utils/serviceError.mjs +97 -0
- package/dist/esm/utils/serviceError.mjs.map +1 -0
- package/internals/package.json +8 -0
- package/internals/server/package.json +7 -0
- package/package.json +94 -0
- package/server/package.json +7 -0
- package/src/apis/common/baseHandlers/authenticatedHandler.ts +28 -0
- package/src/apis/common/baseHandlers/unauthenticatedHandler.ts +22 -0
- package/src/apis/common/internalPost.ts +123 -0
- package/src/apis/common/publicApis.ts +118 -0
- package/src/apis/common/transferHandler.ts +154 -0
- package/src/apis/index.ts +241 -0
- package/src/apis/server.ts +210 -0
- package/src/errors/CanceledError.ts +37 -0
- package/src/errors/RestApiError.ts +14 -0
- package/src/errors/assertValidatonError.ts +19 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/validation.ts +16 -0
- package/src/index.ts +5 -0
- package/src/internals/index.ts +8 -0
- package/src/internals/server.ts +37 -0
- package/src/server.ts +5 -0
- package/src/types/index.ts +138 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/createCancellableOperation.ts +108 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/isIamAuthApplicable.ts +44 -0
- package/src/utils/logger.ts +6 -0
- package/src/utils/parseSigningInfo.ts +53 -0
- package/src/utils/resolveApiUrl.ts +59 -0
- package/src/utils/resolveHeaders.ts +36 -0
- package/src/utils/resolveLibraryOptions.ts +14 -0
- package/src/utils/serviceError.ts +109 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isIamAuthApplicableForRest = exports.isIamAuthApplicableForGraphQL = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Determines if IAM authentication should be applied for a GraphQL request.
|
|
9
|
+
*
|
|
10
|
+
* This function checks the `headers` of the HTTP request to determine if IAM authentication
|
|
11
|
+
* is applicable. IAM authentication is considered applicable if there is no `authorization`
|
|
12
|
+
* header, no `x-api-key` header, and `signingServiceInfo` is provided.
|
|
13
|
+
*
|
|
14
|
+
* @param request - The HTTP request object containing headers.
|
|
15
|
+
* @param signingServiceInfo - Optional signing service information,
|
|
16
|
+
* including service and region.
|
|
17
|
+
* @returns A boolean `true` if IAM authentication should be applied.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
|
|
22
|
+
exports.isIamAuthApplicableForGraphQL = isIamAuthApplicableForGraphQL;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if IAM authentication should be applied for a REST request.
|
|
25
|
+
*
|
|
26
|
+
* This function checks the `headers` of the HTTP request to determine if IAM authentication
|
|
27
|
+
* is applicable. IAM authentication is considered applicable if there is no `authorization`
|
|
28
|
+
* header and `signingServiceInfo` is provided.
|
|
29
|
+
*
|
|
30
|
+
* @param request - The HTTP request object containing headers.
|
|
31
|
+
* @param signingServiceInfo - Optional signing service information,
|
|
32
|
+
* including service and region.
|
|
33
|
+
* @returns A boolean `true` if IAM authentication should be applied.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;
|
|
38
|
+
exports.isIamAuthApplicableForRest = isIamAuthApplicableForRest;
|
|
39
|
+
//# sourceMappingURL=isIamAuthApplicable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isIamAuthApplicable.js","sources":["../../../src/utils/isIamAuthApplicable.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isIamAuthApplicableForRest = exports.isIamAuthApplicableForGraphQL = void 0;\n/**\n * Determines if IAM authentication should be applied for a GraphQL request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header, no `x-api-key` header, and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nconst isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\nexports.isIamAuthApplicableForGraphQL = isIamAuthApplicableForGraphQL;\n/**\n * Determines if IAM authentication should be applied for a REST request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nconst isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;\nexports.isIamAuthApplicableForRest = isIamAuthApplicableForRest;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,6BAA6B,GAAG,MAAM;AACnF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,6BAA6B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,kBAAkB;AAClJ,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;AACrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,0BAA0B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC,kBAAkB;AACtH,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
8
|
+
exports.logger = new core_1.ConsoleLogger('RestApis');
|
|
9
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../../src/utils/logger.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.logger = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nexports.logger = new core_1.ConsoleLogger('RestApis');\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,MAAM,GAAG,MAAM;AACvB,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAC3C,OAAO,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseSigningInfo = void 0;
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.
|
|
10
|
+
* It supports raw API Gateway endpoint and AppSync endpoint.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
const parseSigningInfo = (url, restApiOptions) => {
|
|
15
|
+
const { service: signingService = constants_1.DEFAULT_REST_IAM_SIGNING_SERVICE, region: signingRegion = constants_1.DEFAULT_IAM_SIGNING_REGION, } = restApiOptions?.amplify.getConfig()?.API?.REST?.[restApiOptions?.apiName] ??
|
|
16
|
+
{};
|
|
17
|
+
const { hostname } = url;
|
|
18
|
+
const [, service, region] = constants_1.APIG_HOSTNAME_PATTERN.exec(hostname) ?? [];
|
|
19
|
+
if (service === constants_1.DEFAULT_REST_IAM_SIGNING_SERVICE) {
|
|
20
|
+
// The configured endpoint is an API Gateway endpoint
|
|
21
|
+
// @see: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html
|
|
22
|
+
return {
|
|
23
|
+
service,
|
|
24
|
+
region: region ?? signingRegion,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else if (service === 'appsync-api') {
|
|
28
|
+
// AppSync endpoint is internally supported because GraphQL operation will send request using POST handler.
|
|
29
|
+
// example: https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql
|
|
30
|
+
return {
|
|
31
|
+
service: 'appsync',
|
|
32
|
+
region: region ?? signingRegion,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return {
|
|
37
|
+
service: signingService,
|
|
38
|
+
region: signingRegion,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.parseSigningInfo = parseSigningInfo;
|
|
43
|
+
//# sourceMappingURL=parseSigningInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSigningInfo.js","sources":["../../../src/utils/parseSigningInfo.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.parseSigningInfo = void 0;\nconst constants_1 = require(\"./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 */\nconst parseSigningInfo = (url, restApiOptions) => {\n const { service: signingService = constants_1.DEFAULT_REST_IAM_SIGNING_SERVICE, region: signingRegion = constants_1.DEFAULT_IAM_SIGNING_REGION, } = restApiOptions?.amplify.getConfig()?.API?.REST?.[restApiOptions?.apiName] ??\n {};\n const { hostname } = url;\n const [, service, region] = constants_1.APIG_HOSTNAME_PATTERN.exec(hostname) ?? [];\n if (service === constants_1.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};\nexports.parseSigningInfo = parseSigningInfo;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,gBAAgB,GAAG,MAAM;AACjC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK;AAClD,IAAI,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,WAAW,CAAC,gCAAgC,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC,0BAA0B,GAAG,GAAG,cAAc,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,cAAc,EAAE,OAAO,CAAC;AACjO,QAAQ,EAAE;AACV,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG;AAC5B,IAAI,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;AACtF,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,gCAAgC,EAAE;AAClE;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,CAAC;AACD,OAAO,CAAC,gBAAgB,GAAG,gBAAgB;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveApiUrl = void 0;
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the REST API request URL by:
|
|
11
|
+
* 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.
|
|
12
|
+
* 2. Appending the path to the endpoint.
|
|
13
|
+
* 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API
|
|
14
|
+
* options.
|
|
15
|
+
* 4. Validating the resulting URL string.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
const resolveApiUrl = (amplify, apiName, path, queryParams) => {
|
|
20
|
+
const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;
|
|
21
|
+
(0, errors_1.assertValidationError)(!!urlStr, errors_1.RestApiValidationErrorCode.InvalidApiName);
|
|
22
|
+
try {
|
|
23
|
+
let url;
|
|
24
|
+
if (utils_1.AmplifyUrl.canParse(urlStr + path)) {
|
|
25
|
+
url = new utils_1.AmplifyUrl(urlStr + path);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
url = new utils_1.AmplifyUrl(urlStr + path, location?.origin);
|
|
29
|
+
}
|
|
30
|
+
if (queryParams) {
|
|
31
|
+
const mergedQueryParams = new utils_1.AmplifyUrlSearchParams(url.searchParams);
|
|
32
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
33
|
+
mergedQueryParams.set(key, value);
|
|
34
|
+
});
|
|
35
|
+
url.search = new utils_1.AmplifyUrlSearchParams(mergedQueryParams).toString();
|
|
36
|
+
}
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new errors_1.RestApiError({
|
|
41
|
+
name: errors_1.RestApiValidationErrorCode.InvalidApiName,
|
|
42
|
+
...errors_1.validationErrorMap[errors_1.RestApiValidationErrorCode.InvalidApiName],
|
|
43
|
+
recoverySuggestion: `Please make sure the REST endpoint URL is a valid URL string. Got ${urlStr}`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.resolveApiUrl = resolveApiUrl;
|
|
48
|
+
//# sourceMappingURL=resolveApiUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveApiUrl.js","sources":["../../../src/utils/resolveApiUrl.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveApiUrl = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst errors_1 = require(\"../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 */\nconst resolveApiUrl = (amplify, apiName, path, queryParams) => {\n const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;\n (0, errors_1.assertValidationError)(!!urlStr, errors_1.RestApiValidationErrorCode.InvalidApiName);\n try {\n let url;\n if (utils_1.AmplifyUrl.canParse(urlStr + path)) {\n url = new utils_1.AmplifyUrl(urlStr + path);\n }\n else {\n url = new utils_1.AmplifyUrl(urlStr + path, location?.origin);\n }\n if (queryParams) {\n const mergedQueryParams = new utils_1.AmplifyUrlSearchParams(url.searchParams);\n Object.entries(queryParams).forEach(([key, value]) => {\n mergedQueryParams.set(key, value);\n });\n url.search = new utils_1.AmplifyUrlSearchParams(mergedQueryParams).toString();\n }\n return url;\n }\n catch (error) {\n throw new errors_1.RestApiError({\n name: errors_1.RestApiValidationErrorCode.InvalidApiName,\n ...errors_1.validationErrorMap[errors_1.RestApiValidationErrorCode.InvalidApiName],\n recoverySuggestion: `Please make sure the REST endpoint URL is a valid URL string. Got ${urlStr}`,\n });\n }\n};\nexports.resolveApiUrl = resolveApiUrl;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,aAAa,GAAG,MAAM;AAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC;AAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK;AAC/D,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,EAAE,QAAQ;AACtE,IAAI,IAAI,QAAQ,CAAC,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,0BAA0B,CAAC,cAAc,CAAC;AACrG,IAAI,IAAI;AACR,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;AACxD,YAAY,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC;AACvD,QAAQ;AACR,aAAa;AACb,YAAY,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC;AACzE,QAAQ;AACR,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,MAAM,iBAAiB,GAAG,IAAI,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC;AAC1F,YAAY,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAClE,gBAAgB,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACjD,YAAY,CAAC,CAAC;AACd,YAAY,GAAG,CAAC,MAAM,GAAG,IAAI,OAAO,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;AACzF,QAAQ;AACR,QAAQ,OAAO,GAAG;AAClB,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,MAAM,IAAI,QAAQ,CAAC,YAAY,CAAC;AACxC,YAAY,IAAI,EAAE,QAAQ,CAAC,0BAA0B,CAAC,cAAc;AACpE,YAAY,GAAG,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,0BAA0B,CAAC,cAAc,CAAC;AAC9F,YAAY,kBAAkB,EAAE,CAAC,kEAAkE,EAAE,MAAM,CAAC,CAAC;AAC7G,SAAS,CAAC;AACV,IAAI;AACJ,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveHeaders = void 0;
|
|
7
|
+
const resolveHeaders = (headers, body) => {
|
|
8
|
+
const normalizedHeaders = {};
|
|
9
|
+
for (const key in headers) {
|
|
10
|
+
normalizedHeaders[key.toLowerCase()] = headers[key];
|
|
11
|
+
}
|
|
12
|
+
if (body) {
|
|
13
|
+
const contentType = normalizedHeaders['content-type'];
|
|
14
|
+
const isJsonCompatible = contentType &&
|
|
15
|
+
(contentType.startsWith('application/json') ||
|
|
16
|
+
(contentType.startsWith('application/') &&
|
|
17
|
+
contentType.includes('+json')));
|
|
18
|
+
if (!isJsonCompatible) {
|
|
19
|
+
normalizedHeaders['content-type'] = 'application/json; charset=UTF-8';
|
|
20
|
+
}
|
|
21
|
+
if (body instanceof FormData) {
|
|
22
|
+
/**
|
|
23
|
+
* If body is a FormData we should not allow setting content-type.
|
|
24
|
+
* It's because runtime HTTP handlers(xhr, fetch, undici, node-fetch,
|
|
25
|
+
* etc.) will modify the content-type value when setting multipart
|
|
26
|
+
* boundary.
|
|
27
|
+
*/
|
|
28
|
+
delete normalizedHeaders['content-type'];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return normalizedHeaders;
|
|
32
|
+
};
|
|
33
|
+
exports.resolveHeaders = resolveHeaders;
|
|
34
|
+
//# sourceMappingURL=resolveHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveHeaders.js","sources":["../../../src/utils/resolveHeaders.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveHeaders = void 0;\nconst resolveHeaders = (headers, body) => {\n const normalizedHeaders = {};\n for (const key in headers) {\n normalizedHeaders[key.toLowerCase()] = headers[key];\n }\n if (body) {\n const contentType = normalizedHeaders['content-type'];\n const isJsonCompatible = contentType &&\n (contentType.startsWith('application/json') ||\n (contentType.startsWith('application/') &&\n contentType.includes('+json')));\n if (!isJsonCompatible) {\n normalizedHeaders['content-type'] = 'application/json; charset=UTF-8';\n }\n if (body instanceof FormData) {\n /**\n * If body is a FormData we should not allow setting content-type.\n * It's because runtime HTTP handlers(xhr, fetch, undici, node-fetch,\n * etc.) will modify the content-type value when setting multipart\n * boundary.\n */\n delete normalizedHeaders['content-type'];\n }\n }\n return normalizedHeaders;\n};\nexports.resolveHeaders = resolveHeaders;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,cAAc,GAAG,MAAM;AAC/B,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK;AAC1C,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAChC,IAAI,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;AAC/B,QAAQ,iBAAiB,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;AAC3D,IAAI;AACJ,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,CAAC;AAC7D,QAAQ,MAAM,gBAAgB,GAAG,WAAW;AAC5C,aAAa,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC;AACvD,iBAAiB,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC;AACvD,oBAAoB,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACnD,QAAQ,IAAI,CAAC,gBAAgB,EAAE;AAC/B,YAAY,iBAAiB,CAAC,cAAc,CAAC,GAAG,iCAAiC;AACjF,QAAQ;AACR,QAAQ,IAAI,IAAI,YAAY,QAAQ,EAAE;AACtC;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,OAAO,iBAAiB,CAAC,cAAc,CAAC;AACpD,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,iBAAiB;AAC5B,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveLibraryOptions = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const resolveLibraryOptions = (amplify) => {
|
|
11
|
+
const retryStrategy = amplify.libraryOptions?.API?.REST?.retryStrategy;
|
|
12
|
+
const defaultAuthMode = amplify.libraryOptions?.API?.REST?.defaultAuthMode;
|
|
13
|
+
return { retryStrategy, defaultAuthMode };
|
|
14
|
+
};
|
|
15
|
+
exports.resolveLibraryOptions = resolveLibraryOptions;
|
|
16
|
+
//# sourceMappingURL=resolveLibraryOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLibraryOptions.js","sources":["../../../src/utils/resolveLibraryOptions.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveLibraryOptions = void 0;\n/**\n * @internal\n */\nconst resolveLibraryOptions = (amplify) => {\n const retryStrategy = amplify.libraryOptions?.API?.REST?.retryStrategy;\n const defaultAuthMode = amplify.libraryOptions?.API?.REST?.defaultAuthMode;\n return { retryStrategy, defaultAuthMode };\n};\nexports.resolveLibraryOptions = resolveLibraryOptions;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,qBAAqB,GAAG,MAAM;AACtC;AACA;AACA;AACA,MAAM,qBAAqB,GAAG,CAAC,OAAO,KAAK;AAC3C,IAAI,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;AAC1E,IAAI,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,eAAe;AAC9E,IAAI,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE;AAC7C,CAAC;AACD,OAAO,CAAC,qBAAqB,GAAG,qBAAqB;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parseRestApiServiceError = void 0;
|
|
5
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
/**
|
|
8
|
+
* Parses both AWS and non-AWS error responses coming from the users' backend code.
|
|
9
|
+
* * AWS errors generated by the AWS services(e.g. API Gateway, Bedrock). They can be Signature errors,
|
|
10
|
+
* ClockSkew errors, etc. These responses will be parsed to errors with proper name and message from the AWS
|
|
11
|
+
* services.
|
|
12
|
+
* * non-AWS errors thrown by the user code. They can contain any headers or body. Users need to access the
|
|
13
|
+
* error.response to get the headers and body and parse them accordingly. The JS error name and message will
|
|
14
|
+
* be `UnknownError` and `Unknown error` respectively.
|
|
15
|
+
*/
|
|
16
|
+
const parseRestApiServiceError = async (response) => {
|
|
17
|
+
if (!response) {
|
|
18
|
+
// Response is not considered an error.
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const parsedAwsError = await (0, aws_client_utils_1.parseJsonError)(stubErrorResponse(response));
|
|
22
|
+
if (!parsedAwsError) ;
|
|
23
|
+
else {
|
|
24
|
+
const bodyText = await response.body?.text();
|
|
25
|
+
return buildRestApiError(parsedAwsError, {
|
|
26
|
+
statusCode: response.statusCode,
|
|
27
|
+
headers: response.headers,
|
|
28
|
+
body: bodyText,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.parseRestApiServiceError = parseRestApiServiceError;
|
|
33
|
+
/**
|
|
34
|
+
* The response object needs to be stub here because the parseAwsJsonError assumes the response body to be valid JSON.
|
|
35
|
+
* Although this is true for AWS services, it is not true for responses from user's code. Once the response body is
|
|
36
|
+
* unwrapped as JSON(and fail), it cannot be read as text again. Therefore, we need to stub the response body here to
|
|
37
|
+
* make sure we can read the error response body as a JSON, and may fall back to read as text if it is not a valid JSON.
|
|
38
|
+
*/
|
|
39
|
+
const stubErrorResponse = (response) => {
|
|
40
|
+
let bodyTextPromise;
|
|
41
|
+
const bodyProxy = new Proxy(response.body, {
|
|
42
|
+
get(target, prop, receiver) {
|
|
43
|
+
if (prop === 'json') {
|
|
44
|
+
// For potential AWS errors, error parser will try to parse the body as JSON first.
|
|
45
|
+
return async () => {
|
|
46
|
+
if (!bodyTextPromise) {
|
|
47
|
+
bodyTextPromise = target.text();
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(await bodyTextPromise);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// If response body is not a valid JSON, we stub it to be an empty object and eventually parsed
|
|
54
|
+
// as an unknown error
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if (prop === 'text') {
|
|
60
|
+
// For non-AWS errors, users can access the body as a string as a fallback.
|
|
61
|
+
return async () => {
|
|
62
|
+
if (!bodyTextPromise) {
|
|
63
|
+
bodyTextPromise = target.text();
|
|
64
|
+
}
|
|
65
|
+
return bodyTextPromise;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return Reflect.get(target, prop, receiver);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const responseProxy = new Proxy(response, {
|
|
74
|
+
get(target, prop, receiver) {
|
|
75
|
+
if (prop === 'body') {
|
|
76
|
+
return bodyProxy;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return Reflect.get(target, prop, receiver);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return responseProxy;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Utility to create a new RestApiError from a service error.
|
|
87
|
+
*/
|
|
88
|
+
const buildRestApiError = (error, response) => {
|
|
89
|
+
const restApiError = new errors_1.RestApiError({
|
|
90
|
+
name: error?.name,
|
|
91
|
+
message: error.message,
|
|
92
|
+
underlyingError: error,
|
|
93
|
+
response,
|
|
94
|
+
});
|
|
95
|
+
// $metadata is only required for backwards compatibility.
|
|
96
|
+
return Object.assign(restApiError, { $metadata: error.$metadata });
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=serviceError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceError.js","sources":["../../../src/utils/serviceError.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.parseRestApiServiceError = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst errors_1 = require(\"../errors\");\n/**\n * Parses both AWS and non-AWS error responses coming from the users' backend code.\n * * AWS errors generated by the AWS services(e.g. API Gateway, Bedrock). They can be Signature errors,\n * ClockSkew errors, etc. These responses will be parsed to errors with proper name and message from the AWS\n * services.\n * * non-AWS errors thrown by the user code. They can contain any headers or body. Users need to access the\n * error.response to get the headers and body and parse them accordingly. The JS error name and message will\n * be `UnknownError` and `Unknown error` respectively.\n */\nconst parseRestApiServiceError = async (response) => {\n if (!response) {\n // Response is not considered an error.\n return;\n }\n const parsedAwsError = await (0, aws_client_utils_1.parseJsonError)(stubErrorResponse(response));\n if (!parsedAwsError) {\n // Response is not considered an error.\n }\n else {\n const bodyText = await response.body?.text();\n return buildRestApiError(parsedAwsError, {\n statusCode: response.statusCode,\n headers: response.headers,\n body: bodyText,\n });\n }\n};\nexports.parseRestApiServiceError = parseRestApiServiceError;\n/**\n * The response object needs to be stub here because the parseAwsJsonError assumes the response body to be valid JSON.\n * Although this is true for AWS services, it is not true for responses from user's code. Once the response body is\n * unwrapped as JSON(and fail), it cannot be read as text again. Therefore, we need to stub the response body here to\n * make sure we can read the error response body as a JSON, and may fall back to read as text if it is not a valid JSON.\n */\nconst stubErrorResponse = (response) => {\n let bodyTextPromise;\n const bodyProxy = new Proxy(response.body, {\n get(target, prop, receiver) {\n if (prop === 'json') {\n // For potential AWS errors, error parser will try to parse the body as JSON first.\n return async () => {\n if (!bodyTextPromise) {\n bodyTextPromise = target.text();\n }\n try {\n return JSON.parse(await bodyTextPromise);\n }\n catch (error) {\n // If response body is not a valid JSON, we stub it to be an empty object and eventually parsed\n // as an unknown error\n return {};\n }\n };\n }\n else if (prop === 'text') {\n // For non-AWS errors, users can access the body as a string as a fallback.\n return async () => {\n if (!bodyTextPromise) {\n bodyTextPromise = target.text();\n }\n return bodyTextPromise;\n };\n }\n else {\n return Reflect.get(target, prop, receiver);\n }\n },\n });\n const responseProxy = new Proxy(response, {\n get(target, prop, receiver) {\n if (prop === 'body') {\n return bodyProxy;\n }\n else {\n return Reflect.get(target, prop, receiver);\n }\n },\n });\n return responseProxy;\n};\n/**\n * Utility to create a new RestApiError from a service error.\n */\nconst buildRestApiError = (error, response) => {\n const restApiError = new errors_1.RestApiError({\n name: error?.name,\n message: error.message,\n underlyingError: error,\n response,\n });\n // $metadata is only required for backwards compatibility.\n return Object.assign(restApiError, { $metadata: error.$metadata });\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,GAAG,OAAO,QAAQ,KAAK;AACrD,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB;AACA,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG,MAAM,IAAI,kBAAkB,CAAC,cAAc,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACpG,IAAI,IAAI,CAAC,cAAc,EAAE;AAGzB,SAAS;AACT,QAAQ,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE;AACpD,QAAQ,OAAO,iBAAiB,CAAC,cAAc,EAAE;AACjD,YAAY,UAAU,EAAE,QAAQ,CAAC,UAAU;AAC3C,YAAY,OAAO,EAAE,QAAQ,CAAC,OAAO;AACrC,YAAY,IAAI,EAAE,QAAQ;AAC1B,SAAS,CAAC;AACV,IAAI;AACJ,CAAC;AACD,OAAO,CAAC,wBAAwB,GAAG,wBAAwB;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,iBAAiB,GAAG,CAAC,QAAQ,KAAK;AACxC,IAAI,IAAI,eAAe;AACvB,IAAI,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE;AAC/C,QAAQ,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;AACpC,YAAY,IAAI,IAAI,KAAK,MAAM,EAAE;AACjC;AACA,gBAAgB,OAAO,YAAY;AACnC,oBAAoB,IAAI,CAAC,eAAe,EAAE;AAC1C,wBAAwB,eAAe,GAAG,MAAM,CAAC,IAAI,EAAE;AACvD,oBAAoB;AACpB,oBAAoB,IAAI;AACxB,wBAAwB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,eAAe,CAAC;AAChE,oBAAoB;AACpB,oBAAoB,OAAO,KAAK,EAAE;AAClC;AACA;AACA,wBAAwB,OAAO,EAAE;AACjC,oBAAoB;AACpB,gBAAgB,CAAC;AACjB,YAAY;AACZ,iBAAiB,IAAI,IAAI,KAAK,MAAM,EAAE;AACtC;AACA,gBAAgB,OAAO,YAAY;AACnC,oBAAoB,IAAI,CAAC,eAAe,EAAE;AAC1C,wBAAwB,eAAe,GAAG,MAAM,CAAC,IAAI,EAAE;AACvD,oBAAoB;AACpB,oBAAoB,OAAO,eAAe;AAC1C,gBAAgB,CAAC;AACjB,YAAY;AACZ,iBAAiB;AACjB,gBAAgB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC;AAC1D,YAAY;AACZ,QAAQ,CAAC;AACT,KAAK,CAAC;AACN,IAAI,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE;AAC9C,QAAQ,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;AACpC,YAAY,IAAI,IAAI,KAAK,MAAM,EAAE;AACjC,gBAAgB,OAAO,SAAS;AAChC,YAAY;AACZ,iBAAiB;AACjB,gBAAgB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC;AAC1D,YAAY;AACZ,QAAQ,CAAC;AACT,KAAK,CAAC;AACN,IAAI,OAAO,aAAa;AACxB,CAAC;AACD;AACA;AACA;AACA,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK;AAC/C,IAAI,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC;AACnD,QAAQ,IAAI,EAAE,KAAK,EAAE,IAAI;AACzB,QAAQ,OAAO,EAAE,KAAK,CAAC,OAAO;AAC9B,QAAQ,eAAe,EAAE,KAAK;AAC9B,QAAQ,QAAQ;AAChB,KAAK,CAAC;AACN;AACA,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;AACtE,CAAC;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse, RetryOptions, SigningOptions, UserAgentOptions } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const authenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & SigningOptions & import("@aws-amplify/core/internals/aws-client-utils").HttpTransferOptions) => Promise<HttpResponse>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fetchTransferHandler, userAgentMiddlewareFactory, retryMiddlewareFactory, signingMiddlewareFactory } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
|
+
import { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
3
|
+
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
const authenticatedHandler = composeTransferHandler(fetchTransferHandler, [
|
|
10
|
+
userAgentMiddlewareFactory,
|
|
11
|
+
retryMiddlewareFactory,
|
|
12
|
+
signingMiddlewareFactory,
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
export { authenticatedHandler };
|
|
16
|
+
//# sourceMappingURL=authenticatedHandler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedHandler.mjs","sources":["../../../../../src/apis/common/baseHandlers/authenticatedHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { fetchTransferHandler, retryMiddlewareFactory, signingMiddlewareFactory, userAgentMiddlewareFactory, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';\n/**\n * @internal\n */\nexport const authenticatedHandler = composeTransferHandler(fetchTransferHandler, [\n userAgentMiddlewareFactory,\n retryMiddlewareFactory,\n signingMiddlewareFactory,\n]);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACY,MAAC,oBAAoB,GAAG,sBAAsB,CAAC,oBAAoB,EAAE;AACjF,IAAI,0BAA0B;AAC9B,IAAI,sBAAsB;AAC1B,IAAI,wBAAwB;AAC5B,CAAC;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse, RetryOptions, UserAgentOptions } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const unauthenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & import("@aws-amplify/core/internals/aws-client-utils").HttpTransferOptions) => Promise<HttpResponse>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fetchTransferHandler, userAgentMiddlewareFactory, retryMiddlewareFactory } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
|
+
import { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
3
|
+
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
const unauthenticatedHandler = composeTransferHandler(fetchTransferHandler, [userAgentMiddlewareFactory, retryMiddlewareFactory]);
|
|
10
|
+
|
|
11
|
+
export { unauthenticatedHandler };
|
|
12
|
+
//# sourceMappingURL=unauthenticatedHandler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticatedHandler.mjs","sources":["../../../../../src/apis/common/baseHandlers/unauthenticatedHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { fetchTransferHandler, retryMiddlewareFactory, userAgentMiddlewareFactory, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';\n/**\n * @internal\n */\nexport const unauthenticatedHandler = composeTransferHandler(fetchTransferHandler, [userAgentMiddlewareFactory, retryMiddlewareFactory]);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACY,MAAC,sBAAsB,GAAG,sBAAsB,CAAC,oBAAoB,EAAE,CAAC,0BAA0B,EAAE,sBAAsB,CAAC;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { InternalPostInput, RestApiResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
7
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
8
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
9
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
10
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
11
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
12
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
13
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
14
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
15
|
+
*
|
|
16
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
17
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
18
|
+
*
|
|
19
|
+
* @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
|
|
20
|
+
* a context created by `runWithAmplifyServerContext`
|
|
21
|
+
* @param postInput an object of {@link InternalPostInput}
|
|
22
|
+
* @param postInput.url The URL that the POST request sends to
|
|
23
|
+
* @param postInput.options Options of the POST request
|
|
24
|
+
* @param postInput.abortController The abort controller used to cancel the POST request
|
|
25
|
+
* @returns a {@link RestApiResponse}
|
|
26
|
+
*
|
|
27
|
+
* @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
|
|
28
|
+
* of the following reasons:
|
|
29
|
+
* 1. no network connection
|
|
30
|
+
* 2. CORS error
|
|
31
|
+
* @throws a {@link CanceledError} when the ongoing POST request get cancelled
|
|
32
|
+
*/
|
|
33
|
+
export declare const post: (amplify: AmplifyClassV6, { url, options, abortController }: InternalPostInput) => Promise<RestApiResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Cancels a request given the promise returned by `post`.
|
|
36
|
+
* If the request is already completed, this function does nothing.
|
|
37
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
38
|
+
*/
|
|
39
|
+
export declare const cancel: (promise: Promise<RestApiResponse>, message?: string) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
42
|
+
*/
|
|
43
|
+
export declare const updateRequestToBeCancellable: (promise: Promise<any>, controller: AbortController) => void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createCancellableOperation } from '../../utils/createCancellableOperation.mjs';
|
|
2
|
+
import '@aws-amplify/core/internals/aws-client-utils';
|
|
3
|
+
import '@aws-amplify/core/internals/utils';
|
|
4
|
+
import '../../errors/validation.mjs';
|
|
5
|
+
import '../../utils/logger.mjs';
|
|
6
|
+
import { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable.mjs';
|
|
7
|
+
import { transferHandler } from './transferHandler.mjs';
|
|
8
|
+
|
|
9
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
/**
|
|
12
|
+
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
13
|
+
*
|
|
14
|
+
* 1. For every GraphQL POST request, an abort controller is created and supplied to the request.
|
|
15
|
+
* 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.
|
|
16
|
+
* 3. The promise is returned to the external caller.
|
|
17
|
+
* 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.
|
|
18
|
+
* 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.
|
|
19
|
+
* 6. GraphQL POST request will be rejected with the error message provided during cancel.
|
|
20
|
+
* 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
|
|
21
|
+
*/
|
|
22
|
+
const cancelTokenMap = new WeakMap();
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*
|
|
26
|
+
* REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
27
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
28
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
29
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
30
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
31
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
32
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
33
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
34
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
35
|
+
*
|
|
36
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
37
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
38
|
+
*
|
|
39
|
+
* @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
|
|
40
|
+
* a context created by `runWithAmplifyServerContext`
|
|
41
|
+
* @param postInput an object of {@link InternalPostInput}
|
|
42
|
+
* @param postInput.url The URL that the POST request sends to
|
|
43
|
+
* @param postInput.options Options of the POST request
|
|
44
|
+
* @param postInput.abortController The abort controller used to cancel the POST request
|
|
45
|
+
* @returns a {@link RestApiResponse}
|
|
46
|
+
*
|
|
47
|
+
* @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
|
|
48
|
+
* of the following reasons:
|
|
49
|
+
* 1. no network connection
|
|
50
|
+
* 2. CORS error
|
|
51
|
+
* @throws a {@link CanceledError} when the ongoing POST request get cancelled
|
|
52
|
+
*/
|
|
53
|
+
const post = (amplify, { url, options, abortController }) => {
|
|
54
|
+
const controller = abortController ?? new AbortController();
|
|
55
|
+
const responsePromise = createCancellableOperation(async () => {
|
|
56
|
+
const response = transferHandler(amplify, {
|
|
57
|
+
url,
|
|
58
|
+
method: 'POST',
|
|
59
|
+
...options,
|
|
60
|
+
abortSignal: controller.signal,
|
|
61
|
+
retryStrategy: {
|
|
62
|
+
strategy: 'jittered-exponential-backoff',
|
|
63
|
+
},
|
|
64
|
+
}, isIamAuthApplicableForGraphQL, options?.signingServiceInfo);
|
|
65
|
+
return response;
|
|
66
|
+
}, controller, 'internal');
|
|
67
|
+
const responseWithCleanUp = responsePromise.finally(() => {
|
|
68
|
+
cancelTokenMap.delete(responseWithCleanUp);
|
|
69
|
+
});
|
|
70
|
+
return responseWithCleanUp;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Cancels a request given the promise returned by `post`.
|
|
74
|
+
* If the request is already completed, this function does nothing.
|
|
75
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
76
|
+
*/
|
|
77
|
+
const cancel = (promise, message) => {
|
|
78
|
+
const controller = cancelTokenMap.get(promise);
|
|
79
|
+
if (controller) {
|
|
80
|
+
controller.abort(message);
|
|
81
|
+
if (message && controller.signal.reason !== message) {
|
|
82
|
+
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
83
|
+
// @ts-expect-error reason is read-only property.
|
|
84
|
+
controller.signal.reason = message;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
92
|
+
*/
|
|
93
|
+
const updateRequestToBeCancellable = (promise, controller) => {
|
|
94
|
+
cancelTokenMap.set(promise, controller);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { cancel, post, updateRequestToBeCancellable };
|
|
98
|
+
//# sourceMappingURL=internalPost.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalPost.mjs","sources":["../../../../src/apis/common/internalPost.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation } from '../../utils';\nimport { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './transferHandler';\n/**\n * This weak map provides functionality to cancel a request given the promise containing the `post` request.\n *\n * 1. For every GraphQL POST request, an abort controller is created and supplied to the request.\n * 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.\n * 3. The promise is returned to the external caller.\n * 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.\n * 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.\n * 6. GraphQL POST request will be rejected with the error message provided during cancel.\n * 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.\n */\nconst cancelTokenMap = new WeakMap();\n/**\n * @internal\n *\n * REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize\n * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:\n * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM\n * auth. You MUST also set 'input.options.signingServiceInfo' option.\n * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are\n * optional. If omitted, the signing service and region will be inferred from url.\n * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.\n * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.\n * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.\n *\n * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from\n * internal post call and the abort controller supplied to the internal post call.\n *\n * @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within\n * a context created by `runWithAmplifyServerContext`\n * @param postInput an object of {@link InternalPostInput}\n * @param postInput.url The URL that the POST request sends to\n * @param postInput.options Options of the POST request\n * @param postInput.abortController The abort controller used to cancel the POST request\n * @returns a {@link RestApiResponse}\n *\n * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one\n * of the following reasons:\n * 1. no network connection\n * 2. CORS error\n * @throws a {@link CanceledError} when the ongoing POST request get cancelled\n */\nexport const post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = createCancellableOperation(async () => {\n const response = transferHandler(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n retryStrategy: {\n strategy: 'jittered-exponential-backoff',\n },\n }, isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller, 'internal');\n const responseWithCleanUp = responsePromise.finally(() => {\n cancelTokenMap.delete(responseWithCleanUp);\n });\n return responseWithCleanUp;\n};\n/**\n * Cancels a request given the promise returned by `post`.\n * If the request is already completed, this function does nothing.\n * It MUST be used after `updateRequestToBeCancellable` is called.\n */\nexport const cancel = (promise, message) => {\n const controller = cancelTokenMap.get(promise);\n if (controller) {\n controller.abort(message);\n if (message && controller.signal.reason !== message) {\n // In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.\n // @ts-expect-error reason is read-only property.\n controller.signal.reason = message;\n }\n return true;\n }\n return false;\n};\n/**\n * MUST be used to make a promise including internal `post` API call cancellable.\n */\nexport const updateRequestToBeCancellable = (promise, controller) => {\n cancelTokenMap.set(promise, controller);\n};\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK;AACpE,IAAI,MAAM,UAAU,GAAG,eAAe,IAAI,IAAI,eAAe,EAAE;AAC/D,IAAI,MAAM,eAAe,GAAG,0BAA0B,CAAC,YAAY;AACnE,QAAQ,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,EAAE;AAClD,YAAY,GAAG;AACf,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,OAAO;AACtB,YAAY,WAAW,EAAE,UAAU,CAAC,MAAM;AAC1C,YAAY,aAAa,EAAE;AAC3B,gBAAgB,QAAQ,EAAE,8BAA8B;AACxD,aAAa;AACb,SAAS,EAAE,6BAA6B,EAAE,OAAO,EAAE,kBAAkB,CAAC;AACtE,QAAQ,OAAO,QAAQ;AACvB,IAAI,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC;AAC9B,IAAI,MAAM,mBAAmB,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM;AAC9D,QAAQ,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC;AAClD,IAAI,CAAC,CAAC;AACN,IAAI,OAAO,mBAAmB;AAC9B;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AAC5C,IAAI,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;AAClD,IAAI,IAAI,UAAU,EAAE;AACpB,QAAQ,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC;AACjC,QAAQ,IAAI,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE;AAC7D;AACA;AACA,YAAY,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO;AAC9C,QAAQ;AACR,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,KAAK;AAChB;AACA;AACA;AACA;AACY,MAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AACrE,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC;AAC3C;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../../types';
|
|
3
|
+
export declare const get: (amplify: AmplifyClassV6, input: GetInput) => GetOperation;
|
|
4
|
+
export declare const post: (amplify: AmplifyClassV6, input: PostInput) => PostOperation;
|
|
5
|
+
export declare const put: (amplify: AmplifyClassV6, input: PutInput) => PutOperation;
|
|
6
|
+
export declare const del: (amplify: AmplifyClassV6, input: DeleteInput) => DeleteOperation;
|
|
7
|
+
export declare const head: (amplify: AmplifyClassV6, input: HeadInput) => HeadOperation;
|
|
8
|
+
export declare const patch: (amplify: AmplifyClassV6, input: PatchInput) => PatchOperation;
|