@aws-amplify/api-rest 4.0.75 → 4.0.76-unstable.b188564.0
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/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 +2 -2
- package/dist/cjs/apis/common/internalPost.js.map +1 -1
- package/dist/cjs/apis/common/publicApis.js +2 -2
- package/dist/cjs/apis/common/publicApis.js.map +1 -1
- package/dist/cjs/apis/common/{handler.js → transferHandler.js} +5 -3
- package/dist/cjs/apis/common/transferHandler.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.mjs +1 -1
- package/dist/esm/apis/common/internalPost.mjs.map +1 -1
- package/dist/esm/apis/common/publicApis.mjs +1 -1
- package/dist/esm/apis/common/publicApis.mjs.map +1 -1
- package/dist/esm/apis/common/{handler.mjs → transferHandler.mjs} +4 -2
- package/dist/esm/apis/common/{handler.mjs.map → transferHandler.mjs.map} +1 -1
- package/package.json +94 -102
- package/src/apis/common/baseHandlers/authenticatedHandler.ts +28 -0
- package/src/apis/common/baseHandlers/unauthenticatedHandler.ts +22 -0
- package/src/apis/common/internalPost.ts +1 -1
- package/src/apis/common/publicApis.ts +1 -1
- package/src/apis/common/{handler.ts → transferHandler.ts} +3 -2
- package/dist/cjs/apis/common/handler.js.map +0 -1
- /package/dist/esm/apis/common/{handler.d.ts → transferHandler.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.authenticatedHandler = void 0;
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
8
|
+
const composers_1 = require("@aws-amplify/core/internals/aws-client-utils/composers");
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.authenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [
|
|
13
|
+
aws_client_utils_1.userAgentMiddlewareFactory,
|
|
14
|
+
aws_client_utils_1.retryMiddlewareFactory,
|
|
15
|
+
aws_client_utils_1.signingMiddlewareFactory,
|
|
16
|
+
]);
|
|
17
|
+
//# sourceMappingURL=authenticatedHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedHandler.js","sources":["../../../../../src/apis/common/baseHandlers/authenticatedHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.authenticatedHandler = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\n/**\n * @internal\n */\nexports.authenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [\n aws_client_utils_1.userAgentMiddlewareFactory,\n aws_client_utils_1.retryMiddlewareFactory,\n aws_client_utils_1.signingMiddlewareFactory,\n]);\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,oBAAoB,GAAG,MAAM;AACrC;AACA;AACA,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC;AACrF;AACA;AACA;AACA,OAAO,CAAC,oBAAoB,GAAG,IAAI,WAAW,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,oBAAoB,EAAE;AAChH,IAAI,kBAAkB,CAAC,0BAA0B;AACjD,IAAI,kBAAkB,CAAC,sBAAsB;AAC7C,IAAI,kBAAkB,CAAC,wBAAwB;AAC/C,CAAC,CAAC;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.unauthenticatedHandler = void 0;
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
8
|
+
const composers_1 = require("@aws-amplify/core/internals/aws-client-utils/composers");
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.unauthenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [aws_client_utils_1.userAgentMiddlewareFactory, aws_client_utils_1.retryMiddlewareFactory]);
|
|
13
|
+
//# sourceMappingURL=unauthenticatedHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticatedHandler.js","sources":["../../../../../src/apis/common/baseHandlers/unauthenticatedHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.unauthenticatedHandler = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\n/**\n * @internal\n */\nexports.unauthenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [aws_client_utils_1.userAgentMiddlewareFactory, aws_client_utils_1.retryMiddlewareFactory]);\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,sBAAsB,GAAG,MAAM;AACvC;AACA;AACA,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC;AACrF;AACA;AACA;AACA,OAAO,CAAC,sBAAsB,GAAG,IAAI,WAAW,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,oBAAoB,EAAE,CAAC,kBAAkB,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;;"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
|
|
9
|
-
const
|
|
9
|
+
const transferHandler_1 = require("./transferHandler");
|
|
10
10
|
/**
|
|
11
11
|
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
12
12
|
*
|
|
@@ -52,7 +52,7 @@ const cancelTokenMap = new WeakMap();
|
|
|
52
52
|
const post = (amplify, { url, options, abortController }) => {
|
|
53
53
|
const controller = abortController ?? new AbortController();
|
|
54
54
|
const responsePromise = (0, utils_1.createCancellableOperation)(async () => {
|
|
55
|
-
const response = (0,
|
|
55
|
+
const response = (0, transferHandler_1.transferHandler)(amplify, {
|
|
56
56
|
url,
|
|
57
57
|
method: 'POST',
|
|
58
58
|
...options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalPost.js","sources":["../../../../src/apis/common/internalPost.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.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst
|
|
1
|
+
{"version":3,"file":"internalPost.js","sources":["../../../../src/apis/common/internalPost.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.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst transferHandler_1 = require(\"./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 */\nconst post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = (0, utils_1.createCancellableOperation)(async () => {\n const response = (0, transferHandler_1.transferHandler)(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n }, isIamAuthApplicable_1.isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller);\n const responseWithCleanUp = responsePromise.finally(() => {\n cancelTokenMap.delete(responseWithCleanUp);\n });\n return responseWithCleanUp;\n};\nexports.post = post;\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 */\nconst 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};\nexports.cancel = cancel;\n/**\n * MUST be used to make a promise including internal `post` API call cancellable.\n */\nconst updateRequestToBeCancellable = (promise, controller) => {\n cancelTokenMap.set(promise, controller);\n};\nexports.updateRequestToBeCancellable = updateRequestToBeCancellable;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM;AAC7E,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;AACtC,MAAM,qBAAqB,GAAG,OAAO,CAAC,iCAAiC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACtD;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;AACA,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK;AAC7D,IAAI,MAAM,UAAU,GAAG,eAAe,IAAI,IAAI,eAAe,EAAE;AAC/D,IAAI,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,0BAA0B,EAAE,YAAY;AAChF,QAAQ,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,eAAe,EAAE,OAAO,EAAE;AACzE,YAAY,GAAG;AACf,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,OAAO;AACtB,YAAY,WAAW,EAAE,UAAU,CAAC,MAAM;AAC1C,SAAS,EAAE,qBAAqB,CAAC,6BAA6B,EAAE,OAAO,EAAE,kBAAkB,CAAC;AAC5F,QAAQ,OAAO,QAAQ;AACvB,KAAK,EAAE,UAAU,CAAC;AAClB,IAAI,MAAM,mBAAmB,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM;AAC9D,QAAQ,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC;AAClD,KAAK,CAAC;AACN,IAAI,OAAO,mBAAmB;AAC9B,CAAC;AACD,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AACrC,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;AACA,QAAQ,OAAO,IAAI;AACnB;AACA,IAAI,OAAO,KAAK;AAChB,CAAC;AACD,OAAO,CAAC,MAAM,GAAG,MAAM;AACvB;AACA;AACA;AACA,MAAM,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AAC9D,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC;AAC3C,CAAC;AACD,OAAO,CAAC,4BAA4B,GAAG,4BAA4B;;"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
|
|
9
|
-
const
|
|
9
|
+
const transferHandler_1 = require("./transferHandler");
|
|
10
10
|
const publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {
|
|
11
11
|
const { apiName, options: apiOptions = {}, path: apiPath } = options;
|
|
12
12
|
const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);
|
|
@@ -24,7 +24,7 @@ const publicHandler = (amplify, options, method) => (0, utils_1.createCancellabl
|
|
|
24
24
|
apiName,
|
|
25
25
|
});
|
|
26
26
|
utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);
|
|
27
|
-
return (0,
|
|
27
|
+
return (0, transferHandler_1.transferHandler)(amplify, {
|
|
28
28
|
...apiOptions,
|
|
29
29
|
url,
|
|
30
30
|
method,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicApis.js","sources":["../../../../src/apis/common/publicApis.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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst
|
|
1
|
+
{"version":3,"file":"publicApis.js","sources":["../../../../src/apis/common/publicApis.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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst transferHandler_1 = require(\"./transferHandler\");\nconst publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {\n amplify,\n apiName,\n });\n utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return (0, transferHandler_1.transferHandler)(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicable_1.isIamAuthApplicableForRest, signingServiceInfo);\n});\nconst get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexports.get = get;\nconst post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexports.post = post;\nconst put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexports.put = put;\nconst del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexports.del = del;\nconst head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexports.head = head;\nconst patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,MAAM;AAC9F,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;AACtC,MAAM,qBAAqB,GAAG,OAAO,CAAC,iCAAiC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACtD,MAAM,aAAa,GAAG,CAAC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AAO,EAAE,KAAK,EAAE,KAAK,CAAC;AACpE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC;AACpE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;AACvE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;AACxE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
|
|
@@ -5,6 +5,8 @@ exports.transferHandler = void 0;
|
|
|
5
5
|
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const resolveHeaders_1 = require("../../utils/resolveHeaders");
|
|
8
|
+
const authenticatedHandler_1 = require("./baseHandlers/authenticatedHandler");
|
|
9
|
+
const unauthenticatedHandler_1 = require("./baseHandlers/unauthenticatedHandler");
|
|
8
10
|
/**
|
|
9
11
|
* Make REST API call with best-effort IAM auth.
|
|
10
12
|
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
@@ -43,7 +45,7 @@ const transferHandler = async (amplify, options, iamAuthApplicable, signingServi
|
|
|
43
45
|
const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);
|
|
44
46
|
const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;
|
|
45
47
|
const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;
|
|
46
|
-
response = await (0,
|
|
48
|
+
response = await (0, authenticatedHandler_1.authenticatedHandler)(request, {
|
|
47
49
|
...baseOptions,
|
|
48
50
|
credentials,
|
|
49
51
|
region: signingRegion,
|
|
@@ -51,7 +53,7 @@ const transferHandler = async (amplify, options, iamAuthApplicable, signingServi
|
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
else {
|
|
54
|
-
response = await (0,
|
|
56
|
+
response = await (0, unauthenticatedHandler_1.unauthenticatedHandler)(request, {
|
|
55
57
|
...baseOptions,
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -75,4 +77,4 @@ const resolveCredentials = async (amplify) => {
|
|
|
75
77
|
}
|
|
76
78
|
return null;
|
|
77
79
|
};
|
|
78
|
-
//# sourceMappingURL=
|
|
80
|
+
//# sourceMappingURL=transferHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferHandler.js","sources":["../../../../src/apis/common/transferHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transferHandler = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"../../utils\");\nconst resolveHeaders_1 = require(\"../../utils/resolveHeaders\");\nconst authenticatedHandler_1 = require(\"./baseHandlers/authenticatedHandler\");\nconst unauthenticatedHandler_1 = require(\"./baseHandlers/unauthenticatedHandler\");\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nconst transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),\n computeDelay: aws_client_utils_1.jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await (0, authenticatedHandler_1.authenticatedHandler)(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await (0, unauthenticatedHandler_1.unauthenticatedHandler)(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nexports.transferHandler = transferHandler;\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n utils_1.logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,eAAe,GAAG,MAAM;AAChC,MAAM,kBAAkB,GAAG,OAA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ttpRequest, 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;;;;"}
|
|
@@ -4,7 +4,7 @@ import '@aws-amplify/core/internals/utils';
|
|
|
4
4
|
import '../../errors/validation.mjs';
|
|
5
5
|
import '../../utils/logger.mjs';
|
|
6
6
|
import { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable.mjs';
|
|
7
|
-
import { transferHandler } from './
|
|
7
|
+
import { transferHandler } from './transferHandler.mjs';
|
|
8
8
|
|
|
9
9
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +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 './
|
|
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 }, isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller);\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,SAAS,EAAE,6BAA6B,EAAE,OAAO,EAAE,kBAAkB,CAAC;AACtE,QAAQ,OAAO,QAAQ;AACvB,KAAK,EAAE,UAAU,CAAC;AAClB,IAAI,MAAM,mBAAmB,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM;AAC9D,QAAQ,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC;AAClD,KAAK,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;AACA,QAAQ,OAAO,IAAI;AACnB;AACA,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;;;;"}
|
|
@@ -6,7 +6,7 @@ import '../../errors/validation.mjs';
|
|
|
6
6
|
import { resolveApiUrl } from '../../utils/resolveApiUrl.mjs';
|
|
7
7
|
import { logger } from '../../utils/logger.mjs';
|
|
8
8
|
import { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable.mjs';
|
|
9
|
-
import { transferHandler } from './
|
|
9
|
+
import { transferHandler } from './transferHandler.mjs';
|
|
10
10
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicApis.mjs","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation, logger, parseSigningInfo, resolveApiUrl, } from '../../utils';\nimport { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './
|
|
1
|
+
{"version":3,"file":"publicApis.mjs","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation, logger, parseSigningInfo, resolveApiUrl, } from '../../utils';\nimport { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './transferHandler';\nconst publicHandler = (amplify, options, method) => createCancellableOperation(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = resolveApiUrl(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = parseSigningInfo(url, {\n amplify,\n apiName,\n });\n logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return transferHandler(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicableForRest, signingServiceInfo);\n});\nexport const get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexport const post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexport const put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexport const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexport const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexport const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,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;AAChE,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK;AAC9D,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ;AACjE,MAAC,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM;AAChE,MAAC,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO;;;;"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { getRetryDecider,
|
|
1
|
+
import { getRetryDecider, jitteredBackoff } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
2
|
import '@aws-amplify/core/internals/utils';
|
|
3
3
|
import '../../errors/validation.mjs';
|
|
4
4
|
import { parseRestApiServiceError } from '../../utils/serviceError.mjs';
|
|
5
5
|
import { logger } from '../../utils/logger.mjs';
|
|
6
6
|
import { parseSigningInfo } from '../../utils/parseSigningInfo.mjs';
|
|
7
7
|
import { resolveHeaders } from '../../utils/resolveHeaders.mjs';
|
|
8
|
+
import { authenticatedHandler } from './baseHandlers/authenticatedHandler.mjs';
|
|
9
|
+
import { unauthenticatedHandler } from './baseHandlers/unauthenticatedHandler.mjs';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Make REST API call with best-effort IAM auth.
|
|
@@ -77,4 +79,4 @@ const resolveCredentials = async (amplify) => {
|
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
export { transferHandler };
|
|
80
|
-
//# sourceMappingURL=
|
|
82
|
+
//# sourceMappingURL=transferHandler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"transferHandler.mjs","sources":["../../../../src/apis/common/transferHandler.ts"],"sourcesContent":["import { getRetryDecider, jitteredBackoff, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { logger, parseRestApiServiceError, parseSigningInfo, } from '../../utils';\nimport { resolveHeaders } from '../../utils/resolveHeaders';\nimport { authenticatedHandler } from './baseHandlers/authenticatedHandler';\nimport { unauthenticatedHandler } from './baseHandlers/unauthenticatedHandler';\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nexport const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = resolveHeaders(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: getRetryDecider(parseRestApiServiceError),\n computeDelay: jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = parseSigningInfo(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await authenticatedHandler(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await unauthenticatedHandler(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;;;;;;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,OAAO,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,KAAK;AAClG,IAAI,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO;AAChF,IAAI,MAAM,YAAY,GAAG;AACzB,UAAU,IAAI,YAAY;AAC1B,cAAc;AACd,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE;AACvC,UAAU,SAAS;AACnB,IAAI,MAAM,eAAe,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC;AACzD,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,GAAG;AACX,QAAQ,OAAO,EAAE,eAAe;AAChC,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK;AACL,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,YAAY,EAAE,eAAe,CAAC,wBAAwB,CAAC;AAC/D,QAAQ,YAAY,EAAE,eAAe;AACrC,QAAQ,0BAA0B,EAAE,eAAe;AACnD,QAAQ,WAAW;AACnB,KAAK;AACL,IAAI,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,CAAC;AAC9E,IAAI,IAAI,QAAQ;AAChB,IAAI,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC;AACzD,IAAI,IAAI,mBAAmB,IAAI,WAAW,EAAE;AAC5C,QAAQ,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAAC;AACxD,QAAQ,MAAM,cAAc,GAAG,kBAAkB,EAAE,OAAO,IAAI,kBAAkB,CAAC,O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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
"name": "API (rest client)",
|
|
98
|
-
"path": "./dist/esm/index.mjs",
|
|
99
|
-
"import": "{ Amplify, RestAPI }",
|
|
100
|
-
"limit": "31.5 kB"
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
"gitHead": "52d159e1d01615d17689ca4710110759e2bb82c8"
|
|
2
|
+
"name": "@aws-amplify/api-rest",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "4.0.76-unstable.b188564.0+b188564",
|
|
5
|
+
"description": "Api-rest category of aws-amplify",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.mjs",
|
|
8
|
+
"typings": "./dist/esm/index.d.ts",
|
|
9
|
+
"react-native": "./src/index.ts",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
|
|
15
|
+
"test:watch": "jest -w 1 --watch",
|
|
16
|
+
"build-with-test": "npm test && npm build",
|
|
17
|
+
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
18
|
+
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
|
|
19
|
+
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
20
|
+
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
|
|
21
|
+
"clean": "npm run clean:size && rimraf dist lib lib-esm",
|
|
22
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
23
|
+
"format": "echo \"Not implemented\"",
|
|
24
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
25
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
26
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 70.0"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/esm/index.d.ts",
|
|
31
|
+
"import": "./dist/esm/index.mjs",
|
|
32
|
+
"require": "./dist/cjs/index.js",
|
|
33
|
+
"react-native": "./src/index.ts"
|
|
34
|
+
},
|
|
35
|
+
"./server": {
|
|
36
|
+
"types": "./dist/esm/server.d.ts",
|
|
37
|
+
"import": "./dist/esm/server.mjs",
|
|
38
|
+
"require": "./dist/cjs/server.js"
|
|
39
|
+
},
|
|
40
|
+
"./internals": {
|
|
41
|
+
"types": "./dist/esm/internals/index.d.ts",
|
|
42
|
+
"import": "./dist/esm/internals/index.mjs",
|
|
43
|
+
"require": "./dist/cjs/internals/index.js",
|
|
44
|
+
"react-native": "./src/internals/index.ts"
|
|
45
|
+
},
|
|
46
|
+
"./internals/server": {
|
|
47
|
+
"types": "./dist/esm/internals/server.d.ts",
|
|
48
|
+
"import": "./dist/esm/internals/server.mjs",
|
|
49
|
+
"require": "./dist/cjs/internals/server.js"
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"typesVersions": {
|
|
54
|
+
">=4.2": {
|
|
55
|
+
"server": [
|
|
56
|
+
"./dist/esm/server.d.ts"
|
|
57
|
+
],
|
|
58
|
+
"internals": [
|
|
59
|
+
"./dist/esm/internals/index.d.ts"
|
|
60
|
+
],
|
|
61
|
+
"internals/server": [
|
|
62
|
+
"./dist/esm/internals/server.d.ts"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
69
|
+
},
|
|
70
|
+
"author": "Amazon Web Services",
|
|
71
|
+
"license": "Apache-2.0",
|
|
72
|
+
"bugs": {
|
|
73
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
74
|
+
},
|
|
75
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
76
|
+
"files": [
|
|
77
|
+
"dist/cjs",
|
|
78
|
+
"dist/esm",
|
|
79
|
+
"src",
|
|
80
|
+
"internals",
|
|
81
|
+
"server"
|
|
82
|
+
],
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"tslib": "^2.5.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@aws-amplify/core": "6.10.7-unstable.b188564.0+b188564"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@aws-amplify/core": "6.10.7-unstable.b188564.0+b188564",
|
|
91
|
+
"@aws-amplify/react-native": "1.1.8-unstable.b188564.0+b188564",
|
|
92
|
+
"@aws-sdk/types": "3.387.0",
|
|
93
|
+
"typescript": "5.0.2"
|
|
94
|
+
},
|
|
95
|
+
"gitHead": "b1885648589e0549c0e7c257e8be5fb4936d5bde"
|
|
104
96
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import {
|
|
4
|
+
HttpRequest,
|
|
5
|
+
HttpResponse,
|
|
6
|
+
RetryOptions,
|
|
7
|
+
SigningOptions,
|
|
8
|
+
UserAgentOptions,
|
|
9
|
+
fetchTransferHandler,
|
|
10
|
+
retryMiddlewareFactory,
|
|
11
|
+
signingMiddlewareFactory,
|
|
12
|
+
userAgentMiddlewareFactory,
|
|
13
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
14
|
+
import { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const authenticatedHandler = composeTransferHandler<
|
|
20
|
+
[UserAgentOptions, RetryOptions<HttpResponse>, SigningOptions],
|
|
21
|
+
HttpRequest,
|
|
22
|
+
HttpResponse,
|
|
23
|
+
typeof fetchTransferHandler
|
|
24
|
+
>(fetchTransferHandler, [
|
|
25
|
+
userAgentMiddlewareFactory,
|
|
26
|
+
retryMiddlewareFactory,
|
|
27
|
+
signingMiddlewareFactory,
|
|
28
|
+
]);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import {
|
|
4
|
+
HttpRequest,
|
|
5
|
+
HttpResponse,
|
|
6
|
+
RetryOptions,
|
|
7
|
+
UserAgentOptions,
|
|
8
|
+
fetchTransferHandler,
|
|
9
|
+
retryMiddlewareFactory,
|
|
10
|
+
userAgentMiddlewareFactory,
|
|
11
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
12
|
+
import { composeTransferHandler } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const unauthenticatedHandler = composeTransferHandler<
|
|
18
|
+
[UserAgentOptions, RetryOptions<HttpResponse>],
|
|
19
|
+
HttpRequest,
|
|
20
|
+
HttpResponse,
|
|
21
|
+
typeof fetchTransferHandler
|
|
22
|
+
>(fetchTransferHandler, [userAgentMiddlewareFactory, retryMiddlewareFactory]);
|
|
@@ -8,7 +8,7 @@ import { createCancellableOperation } from '../../utils';
|
|
|
8
8
|
import { CanceledError } from '../../errors';
|
|
9
9
|
import { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable';
|
|
10
10
|
|
|
11
|
-
import { transferHandler } from './
|
|
11
|
+
import { transferHandler } from './transferHandler';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from '../../utils';
|
|
28
28
|
import { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';
|
|
29
29
|
|
|
30
|
-
import { transferHandler } from './
|
|
30
|
+
import { transferHandler } from './transferHandler';
|
|
31
31
|
|
|
32
32
|
const publicHandler = (
|
|
33
33
|
amplify: AmplifyClassV6,
|
|
@@ -4,10 +4,8 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
4
4
|
import {
|
|
5
5
|
Headers,
|
|
6
6
|
HttpRequest,
|
|
7
|
-
authenticatedHandler,
|
|
8
7
|
getRetryDecider,
|
|
9
8
|
jitteredBackoff,
|
|
10
|
-
unauthenticatedHandler,
|
|
11
9
|
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
12
10
|
import {
|
|
13
11
|
AWSCredentials,
|
|
@@ -22,6 +20,9 @@ import {
|
|
|
22
20
|
import { resolveHeaders } from '../../utils/resolveHeaders';
|
|
23
21
|
import { RestApiResponse, SigningServiceInfo } from '../../types';
|
|
24
22
|
|
|
23
|
+
import { authenticatedHandler } from './baseHandlers/authenticatedHandler';
|
|
24
|
+
import { unauthenticatedHandler } from './baseHandlers/unauthenticatedHandler';
|
|
25
|
+
|
|
25
26
|
type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
|
|
26
27
|
body?: DocumentType | FormData;
|
|
27
28
|
headers?: Headers;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sources":["../../../../src/apis/common/handler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transferHandler = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"../../utils\");\nconst resolveHeaders_1 = require(\"../../utils/resolveHeaders\");\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nconst transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),\n computeDelay: aws_client_utils_1.jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await (0, aws_client_utils_1.authenticatedHandler)(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await (0, aws_client_utils_1.unauthenticatedHandler)(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nexports.transferHandler = transferHandler;\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n utils_1.logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,eAAe,GAAG,MAAM;AAChC,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;AACtC,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,eAAe,GAAG,OAAO,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,KAAK;AAC3F,IAAI,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO;AAChF,IAAI,MAAM,YAAY,GAAG;AACzB,UAAU,IAAI,YAAY;AAC1B,cAAc;AACd,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,IAA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