@aws-amplify/api-rest 4.0.26 → 4.0.27

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.
@@ -20,6 +20,33 @@ const handler_1 = require("./handler");
20
20
  const cancelTokenMap = new WeakMap();
21
21
  /**
22
22
  * @internal
23
+ *
24
+ * REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
25
+ * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
26
+ * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
27
+ * auth. You MUST also set 'input.options.signingServiceInfo' option.
28
+ * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
29
+ * optional. If omitted, the signing service and region will be inferred from url.
30
+ * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
31
+ * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
32
+ * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
33
+ *
34
+ * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
35
+ * internal post call and the abort controller supplied to the internal post call.
36
+ *
37
+ * @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
38
+ * a context created by `runWithAmplifyServerContext`
39
+ * @param postInput an object of {@link InternalPostInput}
40
+ * @param postInput.url The URL that the POST request sends to
41
+ * @param postInput.options Options of the POST request
42
+ * @param postInput.abortController The abort controller used to cancel the POST request
43
+ * @returns a {@link RestApiResponse}
44
+ *
45
+ * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
46
+ * of the following reasons:
47
+ * 1. no network connection
48
+ * 2. CORS error
49
+ * @throws a {@link CanceledError} when the ongoing POST request get cancelled
23
50
  */
24
51
  const post = (amplify, { url, options, abortController }) => {
25
52
  const controller = abortController ?? new AbortController();
@@ -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 handler_1 = require(\"./handler\");\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 */\nconst post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = (0, utils_1.createCancellableOperation)(async () => {\n const response = (0, handler_1.transferHandler)(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n }, 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 cancel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CAAC;AACF,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AACrC,IAAI,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnD,IAAI,IAAI,UAAU,EAAE;AACpB,QAAQ,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAClC,QAAQ,IAAI,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE;AAC7D;AACA;AACA,YAAY,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;AAC/C,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AACF,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;AACxB;AACA;AACA;AACA,MAAM,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AAC9D,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5C,CAAC,CAAC;AACF,OAAO,CAAC,4BAA4B,GAAG,4BAA4B;;"}
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 handler_1 = require(\"./handler\");\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 Error} 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, handler_1.transferHandler)(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n }, 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,CAAC;AAC9D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAC9E,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE,CAAC;AACrC;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,CAAC;AAChE,IAAI,MAAM,eAAe,GAAG,IAAI,O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,CAAC,CAAC;AAC5C,CAAC,CAAC;AACF,OAAO,CAAC,4BAA4B,GAAG,4BAA4B;;"}
@@ -4,24 +4,8 @@
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
7
- const internalPost_1 = require("../apis/common/internalPost");
8
- /**
9
- * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
10
- * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
11
- * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
12
- * auth. You MUST also set 'input.options.signingServiceInfo' option.
13
- * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
14
- * optional. If omitted, the signing service and region will be inferred from url.
15
- * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
16
- * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
17
- * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
18
- *
19
- * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
20
- * internal post call and the abort controller supplied to the internal post call.
21
- *
22
- * @internal
23
- */
24
- exports.post = internalPost_1.post;
7
+ var internalPost_1 = require("../apis/common/internalPost");
8
+ Object.defineProperty(exports, "post", { enumerable: true, get: function () { return internalPost_1.post; } });
25
9
  var internalPost_2 = require("../apis/common/internalPost");
26
10
  Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return internalPost_2.cancel; } });
27
11
  Object.defineProperty(exports, "updateRequestToBeCancellable", { enumerable: true, get: function () { return internalPost_2.updateRequestToBeCancellable; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/internals/index.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 internalPost_1 = require(\"../apis/common/internalPost\");\n/**\n * Internal-only 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 * @internal\n */\nexports.post = internalPost_1.post;\nvar internalPost_2 = require(\"../apis/common/internalPost\");\nObject.defineProperty(exports, \"cancel\", { enumerable: true, get: function () { return internalPost_2.cancel; } });\nObject.defineProperty(exports, \"updateRequestToBeCancellable\", { enumerable: true, get: function () { return internalPost_2.updateRequestToBeCancellable; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAC9E,MAAM,cAAc,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;AACnC,IAAI,cAAc,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC5D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;AACnH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,8BAA8B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,4BAA4B,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/internals/index.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;\nvar internalPost_1 = require(\"../apis/common/internalPost\");\nObject.defineProperty(exports, \"post\", { enumerable: true, get: function () { return internalPost_1.post; } });\nvar internalPost_2 = require(\"../apis/common/internalPost\");\nObject.defineProperty(exports, \"cancel\", { enumerable: true, get: function () { return internalPost_2.cancel; } });\nObject.defineProperty(exports, \"updateRequestToBeCancellable\", { enumerable: true, get: function () { return internalPost_2.updateRequestToBeCancellable; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAC9E,IAAI,cAAc,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC5D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/G,IAAI,cAAc,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC5D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;AACnH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,8BAA8B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,cAAc,CAAC,4BAA4B,CAAC,EAAE,EAAE,CAAC;;"}
@@ -36,6 +36,7 @@ function createCancellableOperation(handler, abortController) {
36
36
  const canceledError = new errors_1.CanceledError({
37
37
  ...(message && { message }),
38
38
  underlyingError: error,
39
+ recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',
39
40
  });
40
41
  logger_1.logger.debug(error);
41
42
  throw canceledError;
@@ -1 +1 @@
1
- {"version":3,"file":"createCancellableOperation.js","sources":["../../../src/utils/createCancellableOperation.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.createCancellableOperation = void 0;\nconst errors_1 = require(\"../errors\");\nconst serviceError_1 = require(\"./serviceError\");\nconst logger_1 = require(\"./logger\");\n/**\n * @internal\n */\nfunction createCancellableOperation(handler, abortController) {\n const isInternalPost = (targetHandler) => !!abortController;\n // For creating a cancellable operation for public REST APIs, we need to create an AbortController\n // internally. Whereas for internal POST APIs, we need to accept in the AbortController from the\n // callers.\n const publicApisAbortController = new AbortController();\n const publicApisAbortSignal = publicApisAbortController.signal;\n const internalPostAbortSignal = abortController?.signal;\n let abortReason;\n const job = async () => {\n try {\n const response = await (isInternalPost(handler)\n ? handler()\n : handler(publicApisAbortSignal));\n if (response.statusCode >= 300) {\n throw await (0, serviceError_1.parseRestApiServiceError)(response);\n }\n return response;\n }\n catch (error) {\n const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal;\n const message = abortReason ?? abortSignal.reason;\n if (error.name === 'AbortError' || abortSignal?.aborted === true) {\n const canceledError = new errors_1.CanceledError({\n ...(message && { message }),\n underlyingError: error,\n });\n logger_1.logger.debug(error);\n throw canceledError;\n }\n logger_1.logger.debug(error);\n throw error;\n }\n };\n if (isInternalPost(handler)) {\n return job();\n }\n else {\n const cancel = (abortMessage) => {\n if (publicApisAbortSignal.aborted === true) {\n return;\n }\n publicApisAbortController.abort(abortMessage);\n // If abort reason is not supported, set a scoped reasons instead. The reason property inside an\n // AbortSignal is a readonly property and trying to set it would throw an error.\n if (abortMessage && publicApisAbortSignal.reason !== abortMessage) {\n abortReason = abortMessage;\n }\n };\n return { response: job(), cancel };\n }\n}\nexports.createCancellableOperation = createCancellableOperation;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACtC,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC;AACA;AACA;AACA,SAAS,0BAA0B,CAAC,OAAO,EAAE,eAAe,EAAE;AAC9D,IAAI,MAAM,cAAc,GAAG,CAAC,aAAa,KAAK,CAAC,CAAC,eAAe,CAAC;AAChE;AACA;AACA;AACA,IAAI,MAAM,yBAAyB,GAAG,IAAI,eAAe,EAAE,CAAC;AAC5D,IAAI,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AACnE,IAAI,MAAM,uBAAuB,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T,QAAQ,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK;AACzC,YAAY,IAAI,qBAAqB,CAAC,OAAO,KAAK,IAAI,EAAE;AACxD,gBAAgB,OAAO;AACvB,aAAa;AACb,YAAY,yBAAyB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D;AACA;AACA,YAAY,IAAI,YAAY,IAAI,qBAAqB,CAAC,MAAM,KAAK,YAAY,EAAE;AAC/E,gBAAgB,WAAW,GAAG,YAAY,CAAC;AAC3C,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;AAC3C,KAAK;AACL,CAAC;AACD,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
1
+ {"version":3,"file":"createCancellableOperation.js","sources":["../../../src/utils/createCancellableOperation.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.createCancellableOperation = void 0;\nconst errors_1 = require(\"../errors\");\nconst serviceError_1 = require(\"./serviceError\");\nconst logger_1 = require(\"./logger\");\n/**\n * @internal\n */\nfunction createCancellableOperation(handler, abortController) {\n const isInternalPost = (targetHandler) => !!abortController;\n // For creating a cancellable operation for public REST APIs, we need to create an AbortController\n // internally. Whereas for internal POST APIs, we need to accept in the AbortController from the\n // callers.\n const publicApisAbortController = new AbortController();\n const publicApisAbortSignal = publicApisAbortController.signal;\n const internalPostAbortSignal = abortController?.signal;\n let abortReason;\n const job = async () => {\n try {\n const response = await (isInternalPost(handler)\n ? handler()\n : handler(publicApisAbortSignal));\n if (response.statusCode >= 300) {\n throw await (0, serviceError_1.parseRestApiServiceError)(response);\n }\n return response;\n }\n catch (error) {\n const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal;\n const message = abortReason ?? abortSignal.reason;\n if (error.name === 'AbortError' || abortSignal?.aborted === true) {\n const canceledError = new errors_1.CanceledError({\n ...(message && { message }),\n underlyingError: error,\n recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',\n });\n logger_1.logger.debug(error);\n throw canceledError;\n }\n logger_1.logger.debug(error);\n throw error;\n }\n };\n if (isInternalPost(handler)) {\n return job();\n }\n else {\n const cancel = (abortMessage) => {\n if (publicApisAbortSignal.aborted === true) {\n return;\n }\n publicApisAbortController.abort(abortMessage);\n // If abort reason is not supported, set a scoped reasons instead. The reason property inside an\n // AbortSignal is a readonly property and trying to set it would throw an error.\n if (abortMessage && publicApisAbortSignal.reason !== abortMessage) {\n abortReason = abortMessage;\n }\n };\n return { response: job(), cancel };\n }\n}\nexports.createCancellableOperation = createCancellableOperation;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACtC,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC;AACA;AACA;AACA,SAAS,0BAA0B,CAAC,OAAO,EAAE,eAAe,EAAE;AAC9D,IAAI,MAAM,cAAc,GAAG,CAAC,aAAa,KAAK,CAAC,CAAC,eAAe,CAAC;AAChE;AACA;AACA;AACA,IAAI,MAAM,yBAAyB,GAAG,IAAI,eAAe,EAAE,CAAC;AAC5D,IAAI,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AACnE,IAAI,MAAM,uBAAuB,GAAG,eAAe,EAAE,MAAM,CAAC;AAC5D,IAAI,IAAI,WAAW,CAAC;AACpB,IAAI,MAAM,GAAG,GAAG,YAAY;AAC5B,Q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AAqB,CAAC,OAAO,KAAK,IAAI,EAAE;AACxD,gBAAgB,OAAO;AACvB,aAAa;AACb,YAAY,yBAAyB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D;AACA;AACA,YAAY,IAAI,YAAY,IAAI,qBAAqB,CAAC,MAAM,KAAK,YAAY,EAAE;AAC/E,gBAAgB,WAAW,GAAG,YAAY,CAAC;AAC3C,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;AAC3C,KAAK;AACL,CAAC;AACD,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
@@ -2,6 +2,33 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
2
2
  import { InternalPostInput, RestApiResponse } from '../../types';
3
3
  /**
4
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 Error} 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
5
32
  */
6
33
  export declare const post: (amplify: AmplifyClassV6, { url, options, abortController }: InternalPostInput) => Promise<RestApiResponse>;
7
34
  /**
@@ -21,6 +21,33 @@ import { transferHandler } from './handler.mjs';
21
21
  const cancelTokenMap = new WeakMap();
22
22
  /**
23
23
  * @internal
24
+ *
25
+ * REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
26
+ * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
27
+ * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
28
+ * auth. You MUST also set 'input.options.signingServiceInfo' option.
29
+ * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
30
+ * optional. If omitted, the signing service and region will be inferred from url.
31
+ * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
32
+ * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
33
+ * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
34
+ *
35
+ * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
36
+ * internal post call and the abort controller supplied to the internal post call.
37
+ *
38
+ * @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
39
+ * a context created by `runWithAmplifyServerContext`
40
+ * @param postInput an object of {@link InternalPostInput}
41
+ * @param postInput.url The URL that the POST request sends to
42
+ * @param postInput.options Options of the POST request
43
+ * @param postInput.abortController The abort controller used to cancel the POST request
44
+ * @returns a {@link RestApiResponse}
45
+ *
46
+ * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
47
+ * of the following reasons:
48
+ * 1. no network connection
49
+ * 2. CORS error
50
+ * @throws a {@link CanceledError} when the ongoing POST request get cancelled
24
51
  */
25
52
  const post = (amplify, { url, options, abortController }) => {
26
53
  const controller = abortController ?? new AbortController();
@@ -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 { transferHandler } from './handler';\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 */\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 }, 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;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE,CAAC;AACrC;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,CAAC;AAChE,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,OAAO,EAAE,kBAAkB,CAAC,CAAC;AACxC,QAAQ,OAAO,QAAQ,CAAC;AACxB,KAAK,EAAE,UAAU,CAAC,CAAC;AACnB,IAAI,MAAM,mBAAmB,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM;AAC9D,QAAQ,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACnD,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,mBAAmB,CAAC;AAC/B,EAAE;AACF;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AAC5C,IAAI,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnD,IAAI,IAAI,UAAU,EAAE;AACpB,QAAQ,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAClC,QAAQ,IAAI,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE;AAC7D;AACA;AACA,YAAY,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;AAC/C,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB,EAAE;AACF;AACA;AACA;AACY,MAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AACrE,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5C;;;;"}
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 { transferHandler } from './handler';\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 Error} 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 }, 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;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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;AACL,IAAI,OAAO,KAAK,CAAC;AACjB,EAAE;AACF;AACA;AACA;AACY,MAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AACrE,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5C;;;;"}
@@ -1,18 +1,2 @@
1
- /**
2
- * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
3
- * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
4
- * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
5
- * auth. You MUST also set 'input.options.signingServiceInfo' option.
6
- * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
7
- * optional. If omitted, the signing service and region will be inferred from url.
8
- * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
9
- * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
10
- * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
11
- *
12
- * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
13
- * internal post call and the abort controller supplied to the internal post call.
14
- *
15
- * @internal
16
- */
17
- export declare const post: (amplify: import("@aws-amplify/core").AmplifyClassV6, { url, options, abortController }: import("../types").InternalPostInput) => Promise<import("../types").RestApiResponse>;
1
+ export { post } from '../apis/common/internalPost';
18
2
  export { cancel, updateRequestToBeCancellable, } from '../apis/common/internalPost';
@@ -1,25 +1,2 @@
1
- import { post as post$1 } from '../apis/common/internalPost.mjs';
2
- export { cancel, updateRequestToBeCancellable } from '../apis/common/internalPost.mjs';
3
-
4
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
8
- * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
9
- * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
10
- * auth. You MUST also set 'input.options.signingServiceInfo' option.
11
- * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
12
- * optional. If omitted, the signing service and region will be inferred from url.
13
- * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
14
- * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
15
- * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
16
- *
17
- * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
18
- * internal post call and the abort controller supplied to the internal post call.
19
- *
20
- * @internal
21
- */
22
- const post = post$1;
23
-
24
- export { post };
1
+ export { cancel, post, updateRequestToBeCancellable } from '../apis/common/internalPost.mjs';
25
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/internals/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { post as internalPost } from '../apis/common/internalPost';\n/**\n * Internal-only 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 * @internal\n */\nexport const post = internalPost;\nexport { cancel, updateRequestToBeCancellable, } from '../apis/common/internalPost';\n"],"names":["internalPost"],"mappings":";;;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAGA;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -35,6 +35,7 @@ function createCancellableOperation(handler, abortController) {
35
35
  const canceledError = new CanceledError({
36
36
  ...(message && { message }),
37
37
  underlyingError: error,
38
+ recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',
38
39
  });
39
40
  logger.debug(error);
40
41
  throw canceledError;
@@ -1 +1 @@
1
- {"version":3,"file":"createCancellableOperation.mjs","sources":["../../../src/utils/createCancellableOperation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CanceledError } from '../errors';\nimport { parseRestApiServiceError } from './serviceError';\nimport { logger } from './logger';\n/**\n * @internal\n */\nexport function createCancellableOperation(handler, abortController) {\n const isInternalPost = (targetHandler) => !!abortController;\n // For creating a cancellable operation for public REST APIs, we need to create an AbortController\n // internally. Whereas for internal POST APIs, we need to accept in the AbortController from the\n // callers.\n const publicApisAbortController = new AbortController();\n const publicApisAbortSignal = publicApisAbortController.signal;\n const internalPostAbortSignal = abortController?.signal;\n let abortReason;\n const job = async () => {\n try {\n const response = await (isInternalPost(handler)\n ? handler()\n : handler(publicApisAbortSignal));\n if (response.statusCode >= 300) {\n throw await parseRestApiServiceError(response);\n }\n return response;\n }\n catch (error) {\n const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal;\n const message = abortReason ?? abortSignal.reason;\n if (error.name === 'AbortError' || abortSignal?.aborted === true) {\n const canceledError = new CanceledError({\n ...(message && { message }),\n underlyingError: error,\n });\n logger.debug(error);\n throw canceledError;\n }\n logger.debug(error);\n throw error;\n }\n };\n if (isInternalPost(handler)) {\n return job();\n }\n else {\n const cancel = (abortMessage) => {\n if (publicApisAbortSignal.aborted === true) {\n return;\n }\n publicApisAbortController.abort(abortMessage);\n // If abort reason is not supported, set a scoped reasons instead. The reason property inside an\n // AbortSignal is a readonly property and trying to set it would throw an error.\n if (abortMessage && publicApisAbortSignal.reason !== abortMessage) {\n abortReason = abortMessage;\n }\n };\n return { response: job(), cancel };\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,OAAO,EAAE,eAAe,EAAE;AACrE,IAAI,MAAM,cAAc,GAAG,CAAC,aAAa,KAAK,CAAC,CAAC,eAAe,CAAC;AAChE;AACA;AACA;AACA,IAAI,MAAM,yBAAyB,GAAG,IAAI,eAAe,EAAE,CAAC;AAC5D,IAAI,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AACnE,IAAI,MAAM,uBAAuB,GAAG,eAAe,EAAE,MAAM,CAAC;AAC5D,IAAI,IAAI,WAAW,CAAC;AACpB,IAAI,MAAM,GAAG,GAAG,YAAY;AAC5B,QAAQ,IAAI;AACZ,YAAY,MAAM,QAAQ,GAAG,OAAO,cAAc,CAAC,OAAO,CAAC;AAC3D,kBAAkB,OAAO,EAAE;AAC3B,kBAAkB,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;AAClD,YAAY,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAE;AAC5C,gBAAgB,MAAM,MAAM,wBAAwB,CAAC,QAAQ,CAAC,CAAC;AAC/D,aAAa;AACb,YAAY,OAAO,QAAQ,CAAC;AAC5B,SAAS;AACT,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,MAAM,WAAW,GAAG,uBAAuB,IAAI,qBAAqB,CAAC;AACjF,YAAY,MAAM,OAAO,GAAG,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC;AAC9D,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,WAAW,EAAE,OAAO,KAAK,IAAI,EAAE;AAC9E,gBAAgB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;AACxD,oBAAoB,IAAI,OAAO,IAAI,EAAE,OAAO,EAAE;AAC9C,oBAAoB,eAAe,EAAE,KAAK;AAC1C,iBAAiB,CAAC,CAAC;AACnB,gBAAgB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACpC,gBAAgB,MAAM,aAAa,CAAC;AACpC,aAAa;AACb,YAAY,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAChC,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK,CAAC;AACN,IAAI,IAAI,cAAc,CAAQ,CAAC,EAAE;AACjC,QAAQ,OAAO,GAAG,EAAE,CAAC;AACrB,KAAK;AACL,SAAS;AACT,QAAQ,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK;AACzC,YAAY,IAAI,qBAAqB,CAAC,OAAO,KAAK,IAAI,EAAE;AACxD,gBAAgB,OAAO;AACvB,aAAa;AACb,YAAY,yBAAyB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D;AACA;AACA,YAAY,IAAI,YAAY,IAAI,qBAAqB,CAAC,MAAM,KAAK,YAAY,EAAE;AAC/E,gBAAgB,WAAW,GAAG,YAAY,CAAC;AAC3C,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;AAC3C,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"createCancellableOperation.mjs","sources":["../../../src/utils/createCancellableOperation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CanceledError } from '../errors';\nimport { parseRestApiServiceError } from './serviceError';\nimport { logger } from './logger';\n/**\n * @internal\n */\nexport function createCancellableOperation(handler, abortController) {\n const isInternalPost = (targetHandler) => !!abortController;\n // For creating a cancellable operation for public REST APIs, we need to create an AbortController\n // internally. Whereas for internal POST APIs, we need to accept in the AbortController from the\n // callers.\n const publicApisAbortController = new AbortController();\n const publicApisAbortSignal = publicApisAbortController.signal;\n const internalPostAbortSignal = abortController?.signal;\n let abortReason;\n const job = async () => {\n try {\n const response = await (isInternalPost(handler)\n ? handler()\n : handler(publicApisAbortSignal));\n if (response.statusCode >= 300) {\n throw await parseRestApiServiceError(response);\n }\n return response;\n }\n catch (error) {\n const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal;\n const message = abortReason ?? abortSignal.reason;\n if (error.name === 'AbortError' || abortSignal?.aborted === true) {\n const canceledError = new CanceledError({\n ...(message && { message }),\n underlyingError: error,\n recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',\n });\n logger.debug(error);\n throw canceledError;\n }\n logger.debug(error);\n throw error;\n }\n };\n if (isInternalPost(handler)) {\n return job();\n }\n else {\n const cancel = (abortMessage) => {\n if (publicApisAbortSignal.aborted === true) {\n return;\n }\n publicApisAbortController.abort(abortMessage);\n // If abort reason is not supported, set a scoped reasons instead. The reason property inside an\n // AbortSignal is a readonly property and trying to set it would throw an error.\n if (abortMessage && publicApisAbortSignal.reason !== abortMessage) {\n abortReason = abortMessage;\n }\n };\n return { response: job(), cancel };\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,OAAO,EAAE,eAAe,EAAE;AACrE,IAAI,MAAM,cAAc,GAAG,CAAC,aAAa,KAAK,CAAC,CAAC,eAAe,CAAC;AAChE;AACA;AACA;AACA,IAAI,MAAM,yBAAyB,GAAG,IAAI,eAAe,EAAE,CAAC;AAC5D,IAAI,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AACnE,IAAI,MAAM,uBAAuB,GAAG,eAAe,EAAE,MAAM,CAAC;AAC5D,IAAI,IAAI,WAAW,CAAC;AACpB,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AAE;AACxD,gBAAgB,OAAO;AACvB,aAAa;AACb,YAAY,yBAAyB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D;AACA;AACA,YAAY,IAAI,YAAY,IAAI,qBAAqB,CAAC,MAAM,KAAK,YAAY,EAAE;AAC/E,gBAAgB,WAAW,GAAG,YAAY,CAAC;AAC3C,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;AAC3C,KAAK;AACL;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-rest",
3
3
  "private": false,
4
- "version": "4.0.26",
4
+ "version": "4.0.27",
5
5
  "description": "Api-rest category of aws-amplify",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/esm/index.mjs",
@@ -87,8 +87,8 @@
87
87
  "@aws-amplify/core": "^6.0.0"
88
88
  },
89
89
  "devDependencies": {
90
- "@aws-amplify/core": "6.0.26",
91
- "@aws-amplify/react-native": "1.0.27",
90
+ "@aws-amplify/core": "6.0.27",
91
+ "@aws-amplify/react-native": "1.0.28",
92
92
  "typescript": "5.0.2"
93
93
  },
94
94
  "size-limit": [
@@ -99,5 +99,5 @@
99
99
  "limit": "31.5 kB"
100
100
  }
101
101
  ],
102
- "gitHead": "b9d7870da178fbe7d4e4bd9a21207190baac557f"
102
+ "gitHead": "39ac7cccb432a3e920e1ed0378bf5fd1cc50c47a"
103
103
  }
@@ -5,6 +5,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
 
6
6
  import { InternalPostInput, RestApiResponse } from '../../types';
7
7
  import { createCancellableOperation } from '../../utils';
8
+ import { CanceledError } from '../../errors';
8
9
 
9
10
  import { transferHandler } from './handler';
10
11
 
@@ -23,6 +24,33 @@ const cancelTokenMap = new WeakMap<Promise<any>, AbortController>();
23
24
 
24
25
  /**
25
26
  * @internal
27
+ *
28
+ * REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
29
+ * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
30
+ * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
31
+ * auth. You MUST also set 'input.options.signingServiceInfo' option.
32
+ * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
33
+ * optional. If omitted, the signing service and region will be inferred from url.
34
+ * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
35
+ * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
36
+ * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
37
+ *
38
+ * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
39
+ * internal post call and the abort controller supplied to the internal post call.
40
+ *
41
+ * @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
42
+ * a context created by `runWithAmplifyServerContext`
43
+ * @param postInput an object of {@link InternalPostInput}
44
+ * @param postInput.url The URL that the POST request sends to
45
+ * @param postInput.options Options of the POST request
46
+ * @param postInput.abortController The abort controller used to cancel the POST request
47
+ * @returns a {@link RestApiResponse}
48
+ *
49
+ * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
50
+ * of the following reasons:
51
+ * 1. no network connection
52
+ * 2. CORS error
53
+ * @throws a {@link CanceledError} when the ongoing POST request get cancelled
26
54
  */
27
55
  export const post = (
28
56
  amplify: AmplifyClassV6,
@@ -1,26 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { post as internalPost } from '../apis/common/internalPost';
5
-
6
- /**
7
- * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
8
- * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
9
- * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
10
- * auth. You MUST also set 'input.options.signingServiceInfo' option.
11
- * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
12
- * optional. If omitted, the signing service and region will be inferred from url.
13
- * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
14
- * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
15
- * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
16
- *
17
- * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
18
- * internal post call and the abort controller supplied to the internal post call.
19
- *
20
- * @internal
21
- */
22
- export const post = internalPost;
23
-
4
+ export { post } from '../apis/common/internalPost';
24
5
  export {
25
6
  cancel,
26
7
  updateRequestToBeCancellable,
@@ -67,6 +67,8 @@ export function createCancellableOperation(
67
67
  const canceledError = new CanceledError({
68
68
  ...(message && { message }),
69
69
  underlyingError: error,
70
+ recoverySuggestion:
71
+ 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',
70
72
  });
71
73
  logger.debug(error);
72
74
  throw canceledError;