@aws-amplify/api-rest 4.0.17 → 4.0.18-experimental-lerna-test.d2b0b08.55
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/internalPost.js +27 -0
- package/dist/cjs/apis/common/internalPost.js.map +1 -1
- package/dist/cjs/apis/index.js +4 -4
- package/dist/cjs/apis/index.js.map +1 -1
- package/dist/cjs/internals/index.js +2 -18
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/utils/createCancellableOperation.js +1 -0
- package/dist/cjs/utils/createCancellableOperation.js.map +1 -1
- package/dist/esm/apis/common/internalPost.d.ts +27 -0
- package/dist/esm/apis/common/internalPost.mjs +27 -0
- package/dist/esm/apis/common/internalPost.mjs.map +1 -1
- package/dist/esm/apis/index.d.ts +4 -4
- package/dist/esm/apis/index.mjs +4 -4
- package/dist/esm/apis/index.mjs.map +1 -1
- package/dist/esm/internals/index.d.ts +1 -17
- package/dist/esm/internals/index.mjs +1 -24
- package/dist/esm/internals/index.mjs.map +1 -1
- package/dist/esm/utils/createCancellableOperation.mjs +1 -0
- package/dist/esm/utils/createCancellableOperation.mjs.map +1 -1
- package/package.json +101 -101
- package/src/apis/common/internalPost.ts +28 -0
- package/src/apis/index.ts +4 -4
- package/src/internals/index.ts +1 -20
- package/src/utils/createCancellableOperation.ts +2 -0
|
@@ -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 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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,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,OAAO,CAAC,0BAA0B,EAAE,YAAY;AAChF,QAAQ,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,eAAe,EAAE,OAAO,EAAE;AACjE,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,CAAC,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;;"}
|
package/dist/cjs/apis/index.js
CHANGED
|
@@ -37,7 +37,7 @@ const publicApis_1 = require("./common/publicApis");
|
|
|
37
37
|
* cancel(message);
|
|
38
38
|
* try {
|
|
39
39
|
* await response;
|
|
40
|
-
* }
|
|
40
|
+
* } catch (e) {
|
|
41
41
|
* if (isCancelError(e)) {
|
|
42
42
|
* // handle request cancellation
|
|
43
43
|
* }
|
|
@@ -78,7 +78,7 @@ exports.get = get;
|
|
|
78
78
|
* cancel(message);
|
|
79
79
|
* try {
|
|
80
80
|
* await response;
|
|
81
|
-
* }
|
|
81
|
+
* } catch (e) {
|
|
82
82
|
* if (isCancelError(e)) {
|
|
83
83
|
* // handle request cancellation
|
|
84
84
|
* }
|
|
@@ -118,7 +118,7 @@ exports.post = post;
|
|
|
118
118
|
* cancel(message);
|
|
119
119
|
* try {
|
|
120
120
|
* await response;
|
|
121
|
-
* }
|
|
121
|
+
* } catch (e) {
|
|
122
122
|
* if (isCancelError(e)) {
|
|
123
123
|
* // handle request cancellation
|
|
124
124
|
* }
|
|
@@ -204,7 +204,7 @@ exports.head = head;
|
|
|
204
204
|
* cancel(message);
|
|
205
205
|
* try {
|
|
206
206
|
* await response;
|
|
207
|
-
* }
|
|
207
|
+
* } catch (e) {
|
|
208
208
|
* if (isCancelError(e)) {
|
|
209
209
|
* // handle request cancellation
|
|
210
210
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/apis/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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst publicApis_1 = require(\"./common/publicApis\");\n/**\n * GET HTTP request\n * @param {GetInput} input - Input for GET operation\n * @returns {GetOperation} Operation for GET request\n * @throws - {@link RestApiError}\n * @example\n * Send a GET request\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await get({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a GET request\n *\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = get({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * }
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/apis/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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst publicApis_1 = require(\"./common/publicApis\");\n/**\n * GET HTTP request\n * @param {GetInput} input - Input for GET operation\n * @returns {GetOperation} Operation for GET request\n * @throws - {@link RestApiError}\n * @example\n * Send a GET request\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await get({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a GET request\n *\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = get({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);\nexports.get = get;\n/**\n * POST HTTP request\n * @param {PostInput} input - Input for POST operation\n * @returns {PostOperation} Operation for POST request\n * @throws - {@link RestApiError}\n * @example\n * Send a POST request\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await post({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a POST request\n *\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = post({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);\nexports.post = post;\n/**\n * PUT HTTP request\n * @param {PutInput} input - Input for PUT operation\n * @returns {PutOperation} Operation for PUT request\n * @throws - {@link RestApiError}\n * @example\n * Send a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await put({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = put({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);\nexports.put = put;\n/**\n * DELETE HTTP request\n * @param {DeleteInput} input - Input for DELETE operation\n * @returns {DeleteOperation} Operation for DELETE request\n * @throws - {@link RestApiError}\n * @example\n * Send a DELETE request\n * ```js\n * import { del } from '@aws-amplify/api';\n *\n * const { statusCode } = await del({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * ```\n */\nconst del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);\nexports.del = del;\n/**\n * HEAD HTTP request\n * @param {HeadInput} input - Input for HEAD operation\n * @returns {HeadOperation} Operation for HEAD request\n * @throws - {@link RestApiError}\n * @example\n * Send a HEAD request\n * ```js\n * import { head, isCancelError } from '@aws-amplify/api';\n *\n * const { headers, statusCode } = await head({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }),response;\n * ```\n *\n */\nconst head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);\nexports.head = head;\n/**\n * PATCH HTTP request\n * @param {PatchInput} input - Input for PATCH operation\n * @returns {PatchOperation} Operation for PATCH request\n * @throws - {@link RestApiError}\n * @example\n * Send a PATCH request\n * ```js\n * import { patch } from '@aws-amplify/api';\n *\n * const { body } = await patch({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n *\n * @example\n * Cancel a PATCH request\n * ```js\n * import { patch, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = patch({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;AAC/F,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACpD;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB;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,KAAK,KAAK,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,KAAK,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACxE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
|
|
@@ -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
|
-
|
|
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;\
|
|
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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AAC1C,iBAAiB,CAAC,CAAC;AACnB,gBAAgB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7C,gBAAgB,MAAM,aAAa,CAAC;AACpC,aAAa;AACb,YAAY,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzC,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,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,S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M,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7C,gBAAgB,MAAM,aAAa,CAAC;AACpC,aAAa;AACb,YAAY,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzC,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,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,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/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;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,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;;;;"}
|
package/dist/esm/apis/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOp
|
|
|
30
30
|
* cancel(message);
|
|
31
31
|
* try {
|
|
32
32
|
* await response;
|
|
33
|
-
* }
|
|
33
|
+
* } catch (e) {
|
|
34
34
|
* if (isCancelError(e)) {
|
|
35
35
|
* // handle request cancellation
|
|
36
36
|
* }
|
|
@@ -70,7 +70,7 @@ export declare const get: (input: GetInput) => GetOperation;
|
|
|
70
70
|
* cancel(message);
|
|
71
71
|
* try {
|
|
72
72
|
* await response;
|
|
73
|
-
* }
|
|
73
|
+
* } catch (e) {
|
|
74
74
|
* if (isCancelError(e)) {
|
|
75
75
|
* // handle request cancellation
|
|
76
76
|
* }
|
|
@@ -109,7 +109,7 @@ export declare const post: (input: PostInput) => PostOperation;
|
|
|
109
109
|
* cancel(message);
|
|
110
110
|
* try {
|
|
111
111
|
* await response;
|
|
112
|
-
* }
|
|
112
|
+
* } catch (e) {
|
|
113
113
|
* if (isCancelError(e)) {
|
|
114
114
|
* // handle request cancellation
|
|
115
115
|
* }
|
|
@@ -192,7 +192,7 @@ export declare const head: (input: HeadInput) => HeadOperation;
|
|
|
192
192
|
* cancel(message);
|
|
193
193
|
* try {
|
|
194
194
|
* await response;
|
|
195
|
-
* }
|
|
195
|
+
* } catch (e) {
|
|
196
196
|
* if (isCancelError(e)) {
|
|
197
197
|
* // handle request cancellation
|
|
198
198
|
* }
|
package/dist/esm/apis/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ import { get as get$1, post as post$1, put as put$1, del as del$1, head as head$
|
|
|
34
34
|
* cancel(message);
|
|
35
35
|
* try {
|
|
36
36
|
* await response;
|
|
37
|
-
* }
|
|
37
|
+
* } catch (e) {
|
|
38
38
|
* if (isCancelError(e)) {
|
|
39
39
|
* // handle request cancellation
|
|
40
40
|
* }
|
|
@@ -74,7 +74,7 @@ const get = (input) => get$1(Amplify, input);
|
|
|
74
74
|
* cancel(message);
|
|
75
75
|
* try {
|
|
76
76
|
* await response;
|
|
77
|
-
* }
|
|
77
|
+
* } catch (e) {
|
|
78
78
|
* if (isCancelError(e)) {
|
|
79
79
|
* // handle request cancellation
|
|
80
80
|
* }
|
|
@@ -113,7 +113,7 @@ const post = (input) => post$1(Amplify, input);
|
|
|
113
113
|
* cancel(message);
|
|
114
114
|
* try {
|
|
115
115
|
* await response;
|
|
116
|
-
* }
|
|
116
|
+
* } catch (e) {
|
|
117
117
|
* if (isCancelError(e)) {
|
|
118
118
|
* // handle request cancellation
|
|
119
119
|
* }
|
|
@@ -196,7 +196,7 @@ const head = (input) => head$1(Amplify, input);
|
|
|
196
196
|
* cancel(message);
|
|
197
197
|
* try {
|
|
198
198
|
* await response;
|
|
199
|
-
* }
|
|
199
|
+
* } catch (e) {
|
|
200
200
|
* if (isCancelError(e)) {
|
|
201
201
|
* // handle request cancellation
|
|
202
202
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/apis/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { del as commonDel, get as commonGet, head as commonHead, patch as commonPatch, post as commonPost, put as commonPut, } from './common/publicApis';\n/**\n * GET HTTP request\n * @param {GetInput} input - Input for GET operation\n * @returns {GetOperation} Operation for GET request\n * @throws - {@link RestApiError}\n * @example\n * Send a GET request\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await get({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a GET request\n *\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = get({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * }
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/apis/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { del as commonDel, get as commonGet, head as commonHead, patch as commonPatch, post as commonPost, put as commonPut, } from './common/publicApis';\n/**\n * GET HTTP request\n * @param {GetInput} input - Input for GET operation\n * @returns {GetOperation} Operation for GET request\n * @throws - {@link RestApiError}\n * @example\n * Send a GET request\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await get({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a GET request\n *\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = get({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nexport const get = (input) => commonGet(Amplify, input);\n/**\n * POST HTTP request\n * @param {PostInput} input - Input for POST operation\n * @returns {PostOperation} Operation for POST request\n * @throws - {@link RestApiError}\n * @example\n * Send a POST request\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await post({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a POST request\n *\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = post({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nexport const post = (input) => commonPost(Amplify, input);\n/**\n * PUT HTTP request\n * @param {PutInput} input - Input for PUT operation\n * @returns {PutOperation} Operation for PUT request\n * @throws - {@link RestApiError}\n * @example\n * Send a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await put({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = put({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nexport const put = (input) => commonPut(Amplify, input);\n/**\n * DELETE HTTP request\n * @param {DeleteInput} input - Input for DELETE operation\n * @returns {DeleteOperation} Operation for DELETE request\n * @throws - {@link RestApiError}\n * @example\n * Send a DELETE request\n * ```js\n * import { del } from '@aws-amplify/api';\n *\n * const { statusCode } = await del({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * ```\n */\nexport const del = (input) => commonDel(Amplify, input);\n/**\n * HEAD HTTP request\n * @param {HeadInput} input - Input for HEAD operation\n * @returns {HeadOperation} Operation for HEAD request\n * @throws - {@link RestApiError}\n * @example\n * Send a HEAD request\n * ```js\n * import { head, isCancelError } from '@aws-amplify/api';\n *\n * const { headers, statusCode } = await head({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }),response;\n * ```\n *\n */\nexport const head = (input) => commonHead(Amplify, input);\n/**\n * PATCH HTTP request\n * @param {PatchInput} input - Input for PATCH operation\n * @returns {PatchOperation} Operation for PATCH request\n * @throws - {@link RestApiError}\n * @example\n * Send a PATCH request\n * ```js\n * import { patch } from '@aws-amplify/api';\n *\n * const { body } = await patch({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n *\n * @example\n * Cancel a PATCH request\n * ```js\n * import { patch, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = patch({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nexport const patch = (input) => commonPatch(Amplify, input);\n"],"names":["commonGet","commonPost","commonPut","commonDel","commonHead","commonPatch"],"mappings":";;;AAAA;AACA;AAGA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKA,KAAS,CAAC,OAAO,EAAE,KAAK,EAAE;AACxD;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,KAAK,KAAKC,MAAU,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKC,KAAS,CAAC,OAAO,EAAE,KAAK,EAAE;AACxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKC,KAAS,CAAC,OAAO,EAAE,KAAK,EAAE;AACxD;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,KAAK,KAAKC,MAAU,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,KAAK,KAAKC,OAAW,CAAC,OAAO,EAAE,KAAK;;;;"}
|
|
@@ -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
|
-
|
|
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":[
|
|
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,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,q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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
2
|
+
"name": "@aws-amplify/api-rest",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "4.0.18-experimental-lerna-test.d2b0b08.55+d2b0b087b",
|
|
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": "tslint 'src/**/*.ts' && 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 -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.0.18-experimental-lerna-test.d2b0b08.55+d2b0b087b"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@aws-amplify/core": "6.0.18-experimental-lerna-test.d2b0b08.55+d2b0b087b",
|
|
91
|
+
"@aws-amplify/react-native": "1.0.18-experimental-lerna-test.d2b0b08.55+d2b0b087b",
|
|
92
|
+
"typescript": "5.0.2"
|
|
93
|
+
},
|
|
94
|
+
"size-limit": [
|
|
95
|
+
{
|
|
96
|
+
"name": "API (rest client)",
|
|
97
|
+
"path": "./dist/esm/index.mjs",
|
|
98
|
+
"import": "{ Amplify, RestAPI }",
|
|
99
|
+
"limit": "31.5 kB"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"gitHead": "d2b0b087bdaa4db452916b53afff3d664c29cca0"
|
|
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,
|
package/src/apis/index.ts
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
* cancel(message);
|
|
60
60
|
* try {
|
|
61
61
|
* await response;
|
|
62
|
-
* }
|
|
62
|
+
* } catch (e) {
|
|
63
63
|
* if (isCancelError(e)) {
|
|
64
64
|
* // handle request cancellation
|
|
65
65
|
* }
|
|
@@ -100,7 +100,7 @@ export const get = (input: GetInput): GetOperation => commonGet(Amplify, input);
|
|
|
100
100
|
* cancel(message);
|
|
101
101
|
* try {
|
|
102
102
|
* await response;
|
|
103
|
-
* }
|
|
103
|
+
* } catch (e) {
|
|
104
104
|
* if (isCancelError(e)) {
|
|
105
105
|
* // handle request cancellation
|
|
106
106
|
* }
|
|
@@ -141,7 +141,7 @@ export const post = (input: PostInput): PostOperation =>
|
|
|
141
141
|
* cancel(message);
|
|
142
142
|
* try {
|
|
143
143
|
* await response;
|
|
144
|
-
* }
|
|
144
|
+
* } catch (e) {
|
|
145
145
|
* if (isCancelError(e)) {
|
|
146
146
|
* // handle request cancellation
|
|
147
147
|
* }
|
|
@@ -229,7 +229,7 @@ export const head = (input: HeadInput): HeadOperation =>
|
|
|
229
229
|
* cancel(message);
|
|
230
230
|
* try {
|
|
231
231
|
* await response;
|
|
232
|
-
* }
|
|
232
|
+
* } catch (e) {
|
|
233
233
|
* if (isCancelError(e)) {
|
|
234
234
|
* // handle request cancellation
|
|
235
235
|
* }
|
package/src/internals/index.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|