@aws-amplify/api-rest 4.0.44 → 4.0.45

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.
Files changed (32) hide show
  1. package/dist/cjs/apis/common/handler.js +2 -2
  2. package/dist/cjs/apis/common/handler.js.map +1 -1
  3. package/dist/cjs/apis/common/internalPost.js +3 -2
  4. package/dist/cjs/apis/common/internalPost.js.map +1 -1
  5. package/dist/cjs/apis/common/publicApis.js +2 -1
  6. package/dist/cjs/apis/common/publicApis.js.map +1 -1
  7. package/dist/cjs/errors/CanceledError.js +3 -0
  8. package/dist/cjs/errors/CanceledError.js.map +1 -1
  9. package/dist/cjs/utils/isIamAuthApplicable.js +39 -0
  10. package/dist/cjs/utils/isIamAuthApplicable.js.map +1 -0
  11. package/dist/esm/apis/common/handler.d.ts +3 -6
  12. package/dist/esm/apis/common/handler.mjs +2 -2
  13. package/dist/esm/apis/common/handler.mjs.map +1 -1
  14. package/dist/esm/apis/common/internalPost.d.ts +1 -1
  15. package/dist/esm/apis/common/internalPost.mjs +3 -2
  16. package/dist/esm/apis/common/internalPost.mjs.map +1 -1
  17. package/dist/esm/apis/common/publicApis.mjs +2 -1
  18. package/dist/esm/apis/common/publicApis.mjs.map +1 -1
  19. package/dist/esm/errors/CanceledError.d.ts +3 -0
  20. package/dist/esm/errors/CanceledError.mjs +3 -0
  21. package/dist/esm/errors/CanceledError.mjs.map +1 -1
  22. package/dist/esm/types/index.d.ts +8 -0
  23. package/dist/esm/utils/isIamAuthApplicable.d.ts +32 -0
  24. package/dist/esm/utils/isIamAuthApplicable.mjs +35 -0
  25. package/dist/esm/utils/isIamAuthApplicable.mjs.map +1 -0
  26. package/package.json +3 -3
  27. package/src/apis/common/handler.ts +7 -11
  28. package/src/apis/common/internalPost.ts +3 -1
  29. package/src/apis/common/publicApis.ts +2 -0
  30. package/src/errors/CanceledError.ts +3 -0
  31. package/src/types/index.ts +9 -0
  32. package/src/utils/isIamAuthApplicable.ts +44 -0
@@ -12,10 +12,11 @@ const resolveHeaders_1 = require("../../utils/resolveHeaders");
12
12
  * @param options Options accepted from public API options when calling the handlers.
13
13
  * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
14
14
  * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
15
+ * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
15
16
  *
16
17
  * @internal
17
18
  */
18
- const transferHandler = async (amplify, options, signingServiceInfo) => {
19
+ const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {
19
20
  const { url, method, headers, body, withCredentials, abortSignal } = options;
20
21
  const resolvedBody = body
21
22
  ? body instanceof FormData
@@ -62,7 +63,6 @@ const transferHandler = async (amplify, options, signingServiceInfo) => {
62
63
  };
63
64
  };
64
65
  exports.transferHandler = transferHandler;
65
- const iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
66
66
  const resolveCredentials = async (amplify) => {
67
67
  try {
68
68
  const { credentials } = await amplify.Auth.fetchAuthSession();
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sources":["../../../../src/apis/common/handler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transferHandler = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"../../utils\");\nconst resolveHeaders_1 = require(\"../../utils/resolveHeaders\");\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n *\n * @internal\n */\nconst transferHandler = async (amplify, options, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),\n computeDelay: aws_client_utils_1.jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await (0, aws_client_utils_1.authenticatedHandler)(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await (0, aws_client_utils_1.unauthenticatedHandler)(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nexports.transferHandler = transferHandler;\nconst iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n utils_1.logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AACnF,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CA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AAO,CAAC,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AACxF,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;;"}
1
+ {"version":3,"file":"handler.js","sources":["../../../../src/apis/common/handler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transferHandler = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"../../utils\");\nconst resolveHeaders_1 = require(\"../../utils/resolveHeaders\");\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nconst transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),\n computeDelay: aws_client_utils_1.jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await (0, aws_client_utils_1.authenticatedHandler)(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await (0, aws_client_utils_1.unauthenticatedHandler)(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nexports.transferHandler = transferHandler;\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n utils_1.logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AACnF,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,eAAe,GAAG,OAAO,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,KAAK;AAC3F,IAAI,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;AACjF,IAAI,MAAM,YAAY,GAAG,IAAI;AAC7B,UAAU,IAAI,YAAY,QAAQ;AAClC,cAAc,IAAI;AAClB,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC;AACxC,UAAU,SAAS,CAAC;AACpB,IAAI,MAAM,eAAe,GAAG,IAAI,gBAAgB,CAAC,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAChF,IAAI,MAAM,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X,QAAQ,UAAU,EAAE,QAAQ,CAAC,UAAU;AACvC,QAAQ,OAAO,EAAE,QAAQ,CAAC,OAAO;AACjC,QAAQ,IAAI,EAAE,QAAQ,CAAC,IAAI;AAC3B,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,eAAe,GAAG,eAAe,CAAC;AAC1C,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK;AAC9C,IAAI,IAAI;AACR,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACtE,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,WAAW,CAAC;AAC/B,SAAS;AACT,KAAK;AACL,IAAI,OAAO,CAAC,EAAE;AACd,QAAQ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AACxF,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;;"}
@@ -5,6 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
7
7
  const utils_1 = require("../../utils");
8
+ const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
8
9
  const handler_1 = require("./handler");
9
10
  /**
10
11
  * This weak map provides functionality to cancel a request given the promise containing the `post` request.
@@ -42,7 +43,7 @@ const cancelTokenMap = new WeakMap();
42
43
  * @param postInput.abortController The abort controller used to cancel the POST request
43
44
  * @returns a {@link RestApiResponse}
44
45
  *
45
- * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
46
+ * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
46
47
  * of the following reasons:
47
48
  * 1. no network connection
48
49
  * 2. CORS error
@@ -56,7 +57,7 @@ const post = (amplify, { url, options, abortController }) => {
56
57
  method: 'POST',
57
58
  ...options,
58
59
  abortSignal: controller.signal,
59
- }, options?.signingServiceInfo);
60
+ }, isIamAuthApplicable_1.isIamAuthApplicableForGraphQL, options?.signingServiceInfo);
60
61
  return response;
61
62
  }, controller);
62
63
  const responseWithCleanUp = responsePromise.finally(() => {
@@ -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 *\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,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AK;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 isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\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 AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one\n * of the following reasons:\n * 1. no network connection\n * 2. CORS error\n * @throws a {@link CanceledError} when the ongoing POST request get cancelled\n */\nconst post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = (0, utils_1.createCancellableOperation)(async () => {\n const response = (0, handler_1.transferHandler)(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n }, isIamAuthApplicable_1.isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller);\n const responseWithCleanUp = responsePromise.finally(() => {\n cancelTokenMap.delete(responseWithCleanUp);\n });\n return responseWithCleanUp;\n};\nexports.post = post;\n/**\n * Cancels a request given the promise returned by `post`.\n * If the request is already completed, this function does nothing.\n * It MUST be used after `updateRequestToBeCancellable` is called.\n */\nconst cancel = (promise, message) => {\n const controller = cancelTokenMap.get(promise);\n if (controller) {\n controller.abort(message);\n if (message && controller.signal.reason !== message) {\n // In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.\n // @ts-expect-error reason is read-only property.\n controller.signal.reason = message;\n }\n return true;\n }\n return false;\n};\nexports.cancel = cancel;\n/**\n * MUST be used to make a promise including internal `post` API call cancellable.\n */\nconst updateRequestToBeCancellable = (promise, controller) => {\n cancelTokenMap.set(promise, controller);\n};\nexports.updateRequestToBeCancellable = updateRequestToBeCancellable;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,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,qBAAqB,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AACzE,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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K;AAC9D,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5C,CAAC,CAAC;AACF,OAAO,CAAC,4BAA4B,GAAG,4BAA4B;;"}
@@ -5,6 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
7
7
  const utils_1 = require("../../utils");
8
+ const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
8
9
  const handler_1 = require("./handler");
9
10
  const publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {
10
11
  const { apiName, options: apiOptions = {}, path: apiPath } = options;
@@ -29,7 +30,7 @@ const publicHandler = (amplify, options, method) => (0, utils_1.createCancellabl
29
30
  method,
30
31
  headers,
31
32
  abortSignal,
32
- }, signingServiceInfo);
33
+ }, isIamAuthApplicable_1.isIamAuthApplicableForRest, signingServiceInfo);
33
34
  });
34
35
  const get = (amplify, input) => publicHandler(amplify, input, 'GET');
35
36
  exports.get = get;
@@ -1 +1 @@
1
- {"version":3,"file":"publicApis.js","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst utils_1 = require(\"../../utils\");\nconst handler_1 = require(\"./handler\");\nconst publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {\n amplify,\n apiName,\n });\n utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return (0, handler_1.transferHandler)(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, signingServiceInfo);\n});\nconst get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexports.get = get;\nconst post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexports.post = post;\nconst put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexports.put = put;\nconst del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexports.del = del;\nconst head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexports.head = head;\nconst patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,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,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,0BAA0B,EAAE,OAAO,WAAW,KAAK;AACnH,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;AACzE,IAAI,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,OAA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,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACrE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACvE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
1
+ {"version":3,"file":"publicApis.js","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst handler_1 = require(\"./handler\");\nconst publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {\n amplify,\n apiName,\n });\n utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return (0, handler_1.transferHandler)(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicable_1.isIamAuthApplicableForRest, signingServiceInfo);\n});\nconst get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexports.get = get;\nconst post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexports.post = post;\nconst put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexports.put = put;\nconst del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexports.del = del;\nconst head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexports.head = head;\nconst patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,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,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,qBAAqB,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AACzE,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,0BAA0B,EAAE,OAAO,WAAW,KAAK;AACnH,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;AACzE,IAAI,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,aAAa,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AC,IAAI,GAAG,IAAI,CAAC;AACpB,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACrE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACvE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
@@ -28,6 +28,9 @@ exports.CanceledError = CanceledError;
28
28
  *
29
29
  * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
30
30
  * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
31
+ *
32
+ * @param {unknown} error The unknown exception to be checked.
33
+ * @returns - A boolean indicating if the error was from an upload cancellation
31
34
  */
32
35
  const isCancelError = (error) => !!error && error instanceof CanceledError;
33
36
  exports.isCancelError = isCancelError;
@@ -1 +1 @@
1
- {"version":3,"file":"CanceledError.js","sources":["../../../src/errors/CanceledError.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.isCancelError = exports.CanceledError = void 0;\nconst RestApiError_1 = require(\"./RestApiError\");\n/**\n * Internal-only class for CanceledError.\n *\n * @internal\n */\nclass CanceledError extends RestApiError_1.RestApiError {\n constructor(params = {}) {\n super({\n name: 'CanceledError',\n message: 'Request is canceled by user',\n ...params,\n });\n // TODO: Delete the following 2 lines after we change the build target to >= es2015\n this.constructor = CanceledError;\n Object.setPrototypeOf(this, CanceledError.prototype);\n }\n}\nexports.CanceledError = CanceledError;\n/**\n * Check if an error is caused by user calling `cancel()` in REST API.\n *\n * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`\n * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.\n */\nconst isCancelError = (error) => !!error && error instanceof CanceledError;\nexports.isCancelError = isCancelError;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AACvD,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,SAAS,cAAc,CAAC,YAAY,CAAC;AACxD,IAAI,WAAW,CAAC,MAAM,GAAG,EAAE,EAAE;AAC7B,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,OAAO,EAAE,6BAA6B;AAClD,YAAY,GAAG,MAAM;AACrB,SAAS,CAAC,CAAC;AACX;AACA,QAAQ,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;AACzC,QAAQ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7D,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,KAAK,YAAY,aAAa,CAAC;AAC3E,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
1
+ {"version":3,"file":"CanceledError.js","sources":["../../../src/errors/CanceledError.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.isCancelError = exports.CanceledError = void 0;\nconst RestApiError_1 = require(\"./RestApiError\");\n/**\n * Internal-only class for CanceledError.\n *\n * @internal\n */\nclass CanceledError extends RestApiError_1.RestApiError {\n constructor(params = {}) {\n super({\n name: 'CanceledError',\n message: 'Request is canceled by user',\n ...params,\n });\n // TODO: Delete the following 2 lines after we change the build target to >= es2015\n this.constructor = CanceledError;\n Object.setPrototypeOf(this, CanceledError.prototype);\n }\n}\nexports.CanceledError = CanceledError;\n/**\n * Check if an error is caused by user calling `cancel()` in REST API.\n *\n * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`\n * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.\n *\n * @param {unknown} error The unknown exception to be checked.\n * @returns - A boolean indicating if the error was from an upload cancellation\n */\nconst isCancelError = (error) => !!error && error instanceof CanceledError;\nexports.isCancelError = isCancelError;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AACvD,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,SAAS,cAAc,CAAC,YAAY,CAAC;AACxD,IAAI,WAAW,CAAC,MAAM,GAAG,EAAE,EAAE;AAC7B,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,OAAO,EAAE,6BAA6B;AAClD,YAAY,GAAG,MAAM;AACrB,SAAS,CAAC,CAAC;AACX;AACA,QAAQ,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;AACzC,QAAQ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7D,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,KAAK,YAAY,aAAa,CAAC;AAC3E,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isIamAuthApplicableForRest = exports.isIamAuthApplicableForGraphQL = void 0;
7
+ /**
8
+ * Determines if IAM authentication should be applied for a GraphQL request.
9
+ *
10
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
11
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
12
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
13
+ *
14
+ * @param request - The HTTP request object containing headers.
15
+ * @param signingServiceInfo - Optional signing service information,
16
+ * including service and region.
17
+ * @returns A boolean `true` if IAM authentication should be applied.
18
+ *
19
+ * @internal
20
+ */
21
+ const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
22
+ exports.isIamAuthApplicableForGraphQL = isIamAuthApplicableForGraphQL;
23
+ /**
24
+ * Determines if IAM authentication should be applied for a REST request.
25
+ *
26
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
27
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
28
+ * header and `signingServiceInfo` is provided.
29
+ *
30
+ * @param request - The HTTP request object containing headers.
31
+ * @param signingServiceInfo - Optional signing service information,
32
+ * including service and region.
33
+ * @returns A boolean `true` if IAM authentication should be applied.
34
+ *
35
+ * @internal
36
+ */
37
+ const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;
38
+ exports.isIamAuthApplicableForRest = isIamAuthApplicableForRest;
39
+ //# sourceMappingURL=isIamAuthApplicable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIamAuthApplicable.js","sources":["../../../src/utils/isIamAuthApplicable.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isIamAuthApplicableForRest = exports.isIamAuthApplicableForGraphQL = void 0;\n/**\n * Determines if IAM authentication should be applied for a GraphQL request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header, no `x-api-key` header, and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nconst isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\nexports.isIamAuthApplicableForGraphQL = isIamAuthApplicableForGraphQL;\n/**\n * Determines if IAM authentication should be applied for a REST request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nconst isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;\nexports.isIamAuthApplicableForRest = isIamAuthApplicableForRest;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,6BAA6B,GAAG,KAAK,CAAC,CAAC;AACpF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,6BAA6B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,kBAAkB,CAAC;AACnJ,OAAO,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,0BAA0B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC,kBAAkB,CAAC;AACvH,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
@@ -1,16 +1,12 @@
1
1
  import { AmplifyClassV6 } from '@aws-amplify/core';
2
2
  import { Headers, HttpRequest } from '@aws-amplify/core/internals/aws-client-utils';
3
3
  import { DocumentType } from '@aws-amplify/core/internals/utils';
4
- import { RestApiResponse } from '../../types';
4
+ import { RestApiResponse, SigningServiceInfo } from '../../types';
5
5
  type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
6
6
  body?: DocumentType | FormData;
7
7
  headers?: Headers;
8
8
  withCredentials?: boolean;
9
9
  };
10
- interface SigningServiceInfo {
11
- service?: string;
12
- region?: string;
13
- }
14
10
  /**
15
11
  * Make REST API call with best-effort IAM auth.
16
12
  * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
@@ -18,10 +14,11 @@ interface SigningServiceInfo {
18
14
  * @param options Options accepted from public API options when calling the handlers.
19
15
  * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
20
16
  * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
17
+ * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
21
18
  *
22
19
  * @internal
23
20
  */
24
21
  export declare const transferHandler: (amplify: AmplifyClassV6, options: HandlerOptions & {
25
22
  abortSignal: AbortSignal;
26
- }, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
23
+ }, iamAuthApplicable: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
27
24
  export {};
@@ -13,10 +13,11 @@ import { resolveHeaders } from '../../utils/resolveHeaders.mjs';
13
13
  * @param options Options accepted from public API options when calling the handlers.
14
14
  * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
15
15
  * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
16
+ * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
16
17
  *
17
18
  * @internal
18
19
  */
19
- const transferHandler = async (amplify, options, signingServiceInfo) => {
20
+ const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {
20
21
  const { url, method, headers, body, withCredentials, abortSignal } = options;
21
22
  const resolvedBody = body
22
23
  ? body instanceof FormData
@@ -62,7 +63,6 @@ const transferHandler = async (amplify, options, signingServiceInfo) => {
62
63
  body: response.body,
63
64
  };
64
65
  };
65
- const iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
66
66
  const resolveCredentials = async (amplify) => {
67
67
  try {
68
68
  const { credentials } = await amplify.Auth.fetchAuthSession();
@@ -1 +1 @@
1
- {"version":3,"file":"handler.mjs","sources":["../../../../src/apis/common/handler.ts"],"sourcesContent":["import { authenticatedHandler, getRetryDecider, jitteredBackoff, unauthenticatedHandler, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { logger, parseRestApiServiceError, parseSigningInfo, } from '../../utils';\nimport { resolveHeaders } from '../../utils/resolveHeaders';\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n *\n * @internal\n */\nexport const transferHandler = async (amplify, options, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = resolveHeaders(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: getRetryDecider(parseRestApiServiceError),\n computeDelay: jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = parseSigningInfo(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await authenticatedHandler(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await unauthenticatedHandler(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nconst iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],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kBAAkB,EAAE,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC;AACtF,QAAQ,QAAQ,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE;AACvD,YAAY,GAAG,WAAW;AAC1B,YAAY,WAAW;AACvB,YAAY,MAAM,EAAE,aAAa;AACjC,YAAY,OAAO,EAAE,cAAc;AACnC,SAAS,CAAC,CAAC;AACX,KAAK;AACL,SAAS;AACT,QAAQ,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,EAAE;AACzD,YAAY,GAAG,WAAW;AAC1B,SAAS,CAAC,CAAC;AACX,KAAK;AACL;AACA,IAAI,OAAO;AACX,QAAQ,UAAU,EAAE,QAAQ,CAAC,UAAU;AACvC,QAAQ,OAAO,EAAE,QAAQ,CAAC,OAAO;AACjC,QAAQ,IAAI,EAAE,QAAQ,CAAC,IAAI;AAC3B,KAAK,CAAC;AACN,EAAE;AACF,MAAM,iBAAiB,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,kBAAkB,CAAC;AACvI,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK;AAC9C,IAAI,IAAI;AACR,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACtE,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,WAAW,CAAC;AAC/B,SAAS;AACT,KAAK;AACL,IAAI,OAAO,CAAC,EAAE;AACd,QAAQ,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAChF,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;;;;"}
1
+ {"version":3,"file":"handler.mjs","sources":["../../../../src/apis/common/handler.ts"],"sourcesContent":["import { authenticatedHandler, getRetryDecider, jitteredBackoff, unauthenticatedHandler, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { logger, parseRestApiServiceError, parseSigningInfo, } from '../../utils';\nimport { resolveHeaders } from '../../utils/resolveHeaders';\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nexport const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = resolveHeaders(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const baseOptions = {\n retryDecider: getRetryDecider(parseRestApiServiceError),\n computeDelay: jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n let response;\n const credentials = await resolveCredentials(amplify);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = parseSigningInfo(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await authenticatedHandler(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await unauthenticatedHandler(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":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,MAAM,aAAa,GAAG,kBAAkB,EAAE,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC;AACtF,QAAQ,QAAQ,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE;AACvD,YAAY,GAAG,WAAW;AAC1B,YAAY,WAAW;AACvB,YAAY,MAAM,EAAE,aAAa;AACjC,YAAY,OAAO,EAAE,cAAc;AACnC,SAAS,CAAC,CAAC;AACX,KAAK;AACL,SAAS;AACT,QAAQ,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,EAAE;AACzD,YAAY,GAAG,WAAW;AAC1B,SAAS,CAAC,CAAC;AACX,KAAK;AACL;AACA,IAAI,OAAO;AACX,QAAQ,UAAU,EAAE,QAAQ,CAAC,UAAU;AACvC,QAAQ,OAAO,EAAE,QAAQ,CAAC,OAAO;AACjC,QAAQ,IAAI,EAAE,QAAQ,CAAC,IAAI;AAC3B,KAAK,CAAC;AACN,EAAE;AACF,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK;AAC9C,IAAI,IAAI;AACR,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACtE,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,WAAW,CAAC;AAC/B,SAAS;AACT,KAAK;AACL,IAAI,OAAO,CAAC,EAAE;AACd,QAAQ,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAChF,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;;;;"}
@@ -24,7 +24,7 @@ import { InternalPostInput, RestApiResponse } from '../../types';
24
24
  * @param postInput.abortController The abort controller used to cancel the POST request
25
25
  * @returns a {@link RestApiResponse}
26
26
  *
27
- * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
27
+ * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
28
28
  * of the following reasons:
29
29
  * 1. no network connection
30
30
  * 2. CORS error
@@ -3,6 +3,7 @@ import '@aws-amplify/core/internals/aws-client-utils';
3
3
  import '@aws-amplify/core/internals/utils';
4
4
  import '../../errors/validation.mjs';
5
5
  import '../../utils/logger.mjs';
6
+ import { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable.mjs';
6
7
  import { transferHandler } from './handler.mjs';
7
8
 
8
9
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -43,7 +44,7 @@ const cancelTokenMap = new WeakMap();
43
44
  * @param postInput.abortController The abort controller used to cancel the POST request
44
45
  * @returns a {@link RestApiResponse}
45
46
  *
46
- * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
47
+ * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
47
48
  * of the following reasons:
48
49
  * 1. no network connection
49
50
  * 2. CORS error
@@ -57,7 +58,7 @@ const post = (amplify, { url, options, abortController }) => {
57
58
  method: 'POST',
58
59
  ...options,
59
60
  abortSignal: controller.signal,
60
- }, options?.signingServiceInfo);
61
+ }, isIamAuthApplicableForGraphQL, options?.signingServiceInfo);
61
62
  return response;
62
63
  }, controller);
63
64
  const responseWithCleanUp = responsePromise.finally(() => {
@@ -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 *\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;;;;"}
1
+ {"version":3,"file":"internalPost.mjs","sources":["../../../../src/apis/common/internalPost.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation } from '../../utils';\nimport { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './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 AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one\n * of the following reasons:\n * 1. no network connection\n * 2. CORS error\n * @throws a {@link CanceledError} when the ongoing POST request get cancelled\n */\nexport const post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = createCancellableOperation(async () => {\n const response = transferHandler(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n }, isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller);\n const responseWithCleanUp = responsePromise.finally(() => {\n cancelTokenMap.delete(responseWithCleanUp);\n });\n return responseWithCleanUp;\n};\n/**\n * Cancels a request given the promise returned by `post`.\n * If the request is already completed, this function does nothing.\n * It MUST be used after `updateRequestToBeCancellable` is called.\n */\nexport const cancel = (promise, message) => {\n const controller = cancelTokenMap.get(promise);\n if (controller) {\n controller.abort(message);\n if (message && controller.signal.reason !== message) {\n // In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.\n // @ts-expect-error reason is read-only property.\n controller.signal.reason = message;\n }\n return true;\n }\n return false;\n};\n/**\n * MUST be used to make a promise including internal `post` API call cancellable.\n */\nexport const updateRequestToBeCancellable = (promise, controller) => {\n cancelTokenMap.set(promise, controller);\n};\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE,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,6BAA6B,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;AACvE,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;;;;"}
@@ -5,6 +5,7 @@ import '@aws-amplify/core/internals/utils';
5
5
  import '../../errors/validation.mjs';
6
6
  import { resolveApiUrl } from '../../utils/resolveApiUrl.mjs';
7
7
  import { logger } from '../../utils/logger.mjs';
8
+ import { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable.mjs';
8
9
  import { transferHandler } from './handler.mjs';
9
10
 
10
11
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -32,7 +33,7 @@ const publicHandler = (amplify, options, method) => createCancellableOperation(a
32
33
  method,
33
34
  headers,
34
35
  abortSignal,
35
- }, signingServiceInfo);
36
+ }, isIamAuthApplicableForRest, signingServiceInfo);
36
37
  });
37
38
  const get = (amplify, input) => publicHandler(amplify, input, 'GET');
38
39
  const post = (amplify, input) => publicHandler(amplify, input, 'POST');
@@ -1 +1 @@
1
- {"version":3,"file":"publicApis.mjs","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation, logger, parseSigningInfo, resolveApiUrl, } from '../../utils';\nimport { transferHandler } from './handler';\nconst publicHandler = (amplify, options, method) => createCancellableOperation(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = resolveApiUrl(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = parseSigningInfo(url, {\n amplify,\n apiName,\n });\n logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return transferHandler(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, signingServiceInfo);\n});\nexport const get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexport const post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexport const put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexport const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexport const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexport const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AAGA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,0BAA0B,CAAC,OAAO,WAAW,KAAK;AACtG,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;AACzE,IAAI,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAClF,IAAI,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE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E,KAAK,EAAE,MAAM,EAAE;AAClE,MAAC,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO;;;;"}
1
+ {"version":3,"file":"publicApis.mjs","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation, logger, parseSigningInfo, resolveApiUrl, } from '../../utils';\nimport { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './handler';\nconst publicHandler = (amplify, options, method) => createCancellableOperation(async (abortSignal) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const url = resolveApiUrl(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = parseSigningInfo(url, {\n amplify,\n apiName,\n });\n logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return transferHandler(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicableForRest, signingServiceInfo);\n});\nexport const get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexport const post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexport const put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexport const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexport const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexport const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,0BAA0B,CAAC,OAAO,WAAW,KAAK;AAC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,MAAM,EAAE;AAClE,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;AAChE,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;AACnE,MAAC,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE;AAClE,MAAC,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO;;;;"}
@@ -13,5 +13,8 @@ export declare class CanceledError extends RestApiError {
13
13
  *
14
14
  * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
15
15
  * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
16
+ *
17
+ * @param {unknown} error The unknown exception to be checked.
18
+ * @returns - A boolean indicating if the error was from an upload cancellation
16
19
  */
17
20
  export declare const isCancelError: (error: unknown) => error is CanceledError;
@@ -24,6 +24,9 @@ class CanceledError extends RestApiError {
24
24
  *
25
25
  * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
26
26
  * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
27
+ *
28
+ * @param {unknown} error The unknown exception to be checked.
29
+ * @returns - A boolean indicating if the error was from an upload cancellation
27
30
  */
28
31
  const isCancelError = (error) => !!error && error instanceof CanceledError;
29
32
 
@@ -1 +1 @@
1
- {"version":3,"file":"CanceledError.mjs","sources":["../../../src/errors/CanceledError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { RestApiError } from './RestApiError';\n/**\n * Internal-only class for CanceledError.\n *\n * @internal\n */\nexport class CanceledError extends RestApiError {\n constructor(params = {}) {\n super({\n name: 'CanceledError',\n message: 'Request is canceled by user',\n ...params,\n });\n // TODO: Delete the following 2 lines after we change the build target to >= es2015\n this.constructor = CanceledError;\n Object.setPrototypeOf(this, CanceledError.prototype);\n }\n}\n/**\n * Check if an error is caused by user calling `cancel()` in REST API.\n *\n * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`\n * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.\n */\nexport const isCancelError = (error) => !!error && error instanceof CanceledError;\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,MAAM,aAAa,SAAS,YAAY,CAAC;AAChD,IAAI,WAAW,CAAC,MAAM,GAAG,EAAE,EAAE;AAC7B,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,OAAO,EAAE,6BAA6B;AAClD,YAAY,GAAG,MAAM;AACrB,SAAS,CAAC,CAAC;AACX;AACA,QAAQ,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;AACzC,QAAQ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7D,KAAK;AACL,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,KAAK,YAAY;;;;"}
1
+ {"version":3,"file":"CanceledError.mjs","sources":["../../../src/errors/CanceledError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { RestApiError } from './RestApiError';\n/**\n * Internal-only class for CanceledError.\n *\n * @internal\n */\nexport class CanceledError extends RestApiError {\n constructor(params = {}) {\n super({\n name: 'CanceledError',\n message: 'Request is canceled by user',\n ...params,\n });\n // TODO: Delete the following 2 lines after we change the build target to >= es2015\n this.constructor = CanceledError;\n Object.setPrototypeOf(this, CanceledError.prototype);\n }\n}\n/**\n * Check if an error is caused by user calling `cancel()` in REST API.\n *\n * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`\n * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.\n *\n * @param {unknown} error The unknown exception to be checked.\n * @returns - A boolean indicating if the error was from an upload cancellation\n */\nexport const isCancelError = (error) => !!error && error instanceof CanceledError;\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,MAAM,aAAa,SAAS,YAAY,CAAC;AAChD,IAAI,WAAW,CAAC,MAAM,GAAG,EAAE,EAAE;AAC7B,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,OAAO,EAAE,6BAA6B;AAClD,YAAY,GAAG,MAAM;AACrB,SAAS,CAAC,CAAC;AACX;AACA,QAAQ,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;AACzC,QAAQ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7D,KAAK;AACL,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,KAAK,YAAY;;;;"}
@@ -100,4 +100,12 @@ export interface InternalPostInput {
100
100
  */
101
101
  abortController?: AbortController;
102
102
  }
103
+ /**
104
+ * Type for signingServiceInfo which enable IAM auth as well as overwrite the IAM signing info.
105
+ * @internal
106
+ */
107
+ export interface SigningServiceInfo {
108
+ service?: string;
109
+ region?: string;
110
+ }
103
111
  export {};
@@ -0,0 +1,32 @@
1
+ import { HttpRequest } from '@aws-amplify/core/internals/aws-client-utils';
2
+ import { SigningServiceInfo } from '../types';
3
+ /**
4
+ * Determines if IAM authentication should be applied for a GraphQL request.
5
+ *
6
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
7
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
8
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
9
+ *
10
+ * @param request - The HTTP request object containing headers.
11
+ * @param signingServiceInfo - Optional signing service information,
12
+ * including service and region.
13
+ * @returns A boolean `true` if IAM authentication should be applied.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare const isIamAuthApplicableForGraphQL: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean;
18
+ /**
19
+ * Determines if IAM authentication should be applied for a REST request.
20
+ *
21
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
22
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
23
+ * header and `signingServiceInfo` is provided.
24
+ *
25
+ * @param request - The HTTP request object containing headers.
26
+ * @param signingServiceInfo - Optional signing service information,
27
+ * including service and region.
28
+ * @returns A boolean `true` if IAM authentication should be applied.
29
+ *
30
+ * @internal
31
+ */
32
+ export declare const isIamAuthApplicableForRest: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean;
@@ -0,0 +1,35 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Determines if IAM authentication should be applied for a GraphQL request.
5
+ *
6
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
7
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
8
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
9
+ *
10
+ * @param request - The HTTP request object containing headers.
11
+ * @param signingServiceInfo - Optional signing service information,
12
+ * including service and region.
13
+ * @returns A boolean `true` if IAM authentication should be applied.
14
+ *
15
+ * @internal
16
+ */
17
+ const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
18
+ /**
19
+ * Determines if IAM authentication should be applied for a REST request.
20
+ *
21
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
22
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
23
+ * header and `signingServiceInfo` is provided.
24
+ *
25
+ * @param request - The HTTP request object containing headers.
26
+ * @param signingServiceInfo - Optional signing service information,
27
+ * including service and region.
28
+ * @returns A boolean `true` if IAM authentication should be applied.
29
+ *
30
+ * @internal
31
+ */
32
+ const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;
33
+
34
+ export { isIamAuthApplicableForGraphQL, isIamAuthApplicableForRest };
35
+ //# sourceMappingURL=isIamAuthApplicable.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIamAuthApplicable.mjs","sources":["../../../src/utils/isIamAuthApplicable.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Determines if IAM authentication should be applied for a GraphQL request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header, no `x-api-key` header, and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nexport const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\n/**\n * Determines if IAM authentication should be applied for a REST request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nexport const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,6BAA6B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,mBAAmB;AAC1J;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;;;;"}
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.44",
4
+ "version": "4.0.45",
5
5
  "description": "Api-rest category of aws-amplify",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/esm/index.mjs",
@@ -87,7 +87,7 @@
87
87
  "@aws-amplify/core": "^6.1.0"
88
88
  },
89
89
  "devDependencies": {
90
- "@aws-amplify/core": "6.3.11",
90
+ "@aws-amplify/core": "6.3.12",
91
91
  "@aws-amplify/react-native": "1.1.4",
92
92
  "typescript": "5.0.2"
93
93
  },
@@ -99,5 +99,5 @@
99
99
  "limit": "31.5 kB"
100
100
  }
101
101
  ],
102
- "gitHead": "733c3bd722f06b87f674736cc3f997d6ba5addda"
102
+ "gitHead": "e2e9c5af8ce2c0a6f89e87e224c16d8551c491bd"
103
103
  }
@@ -20,7 +20,7 @@ import {
20
20
  parseSigningInfo,
21
21
  } from '../../utils';
22
22
  import { resolveHeaders } from '../../utils/resolveHeaders';
23
- import { RestApiResponse } from '../../types';
23
+ import { RestApiResponse, SigningServiceInfo } from '../../types';
24
24
 
25
25
  type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
26
26
  body?: DocumentType | FormData;
@@ -28,11 +28,6 @@ type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
28
28
  withCredentials?: boolean;
29
29
  };
30
30
 
31
- interface SigningServiceInfo {
32
- service?: string;
33
- region?: string;
34
- }
35
-
36
31
  /**
37
32
  * Make REST API call with best-effort IAM auth.
38
33
  * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
@@ -40,12 +35,17 @@ interface SigningServiceInfo {
40
35
  * @param options Options accepted from public API options when calling the handlers.
41
36
  * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
42
37
  * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
38
+ * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
43
39
  *
44
40
  * @internal
45
41
  */
46
42
  export const transferHandler = async (
47
43
  amplify: AmplifyClassV6,
48
44
  options: HandlerOptions & { abortSignal: AbortSignal },
45
+ iamAuthApplicable: (
46
+ { headers }: HttpRequest,
47
+ signingServiceInfo?: SigningServiceInfo,
48
+ ) => boolean,
49
49
  signingServiceInfo?: SigningServiceInfo,
50
50
  ): Promise<RestApiResponse> => {
51
51
  const { url, method, headers, body, withCredentials, abortSignal } = options;
@@ -69,6 +69,7 @@ export const transferHandler = async (
69
69
  };
70
70
 
71
71
  const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
72
+
72
73
  let response: RestApiResponse;
73
74
  const credentials = await resolveCredentials(amplify);
74
75
  if (isIamAuthApplicable && credentials) {
@@ -97,11 +98,6 @@ export const transferHandler = async (
97
98
  };
98
99
  };
99
100
 
100
- const iamAuthApplicable = (
101
- { headers }: HttpRequest,
102
- signingServiceInfo?: SigningServiceInfo,
103
- ) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
104
-
105
101
  const resolveCredentials = async (
106
102
  amplify: AmplifyClassV6,
107
103
  ): Promise<AWSCredentials | null> => {
@@ -6,6 +6,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
6
6
  import { InternalPostInput, RestApiResponse } from '../../types';
7
7
  import { createCancellableOperation } from '../../utils';
8
8
  import { CanceledError } from '../../errors';
9
+ import { isIamAuthApplicableForGraphQL } from '../../utils/isIamAuthApplicable';
9
10
 
10
11
  import { transferHandler } from './handler';
11
12
 
@@ -46,7 +47,7 @@ const cancelTokenMap = new WeakMap<Promise<any>, AbortController>();
46
47
  * @param postInput.abortController The abort controller used to cancel the POST request
47
48
  * @returns a {@link RestApiResponse}
48
49
  *
49
- * @throws an {@link Error} with `Network error` as the `message` when the external resource is unreachable due to one
50
+ * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
50
51
  * of the following reasons:
51
52
  * 1. no network connection
52
53
  * 2. CORS error
@@ -66,6 +67,7 @@ export const post = (
66
67
  ...options,
67
68
  abortSignal: controller.signal,
68
69
  },
70
+ isIamAuthApplicableForGraphQL,
69
71
  options?.signingServiceInfo,
70
72
  );
71
73
 
@@ -25,6 +25,7 @@ import {
25
25
  parseSigningInfo,
26
26
  resolveApiUrl,
27
27
  } from '../../utils';
28
+ import { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';
28
29
 
29
30
  import { transferHandler } from './handler';
30
31
 
@@ -71,6 +72,7 @@ const publicHandler = (
71
72
  headers,
72
73
  abortSignal,
73
74
  },
75
+ isIamAuthApplicableForRest,
74
76
  signingServiceInfo,
75
77
  );
76
78
  });
@@ -29,6 +29,9 @@ export class CanceledError extends RestApiError {
29
29
  *
30
30
  * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
31
31
  * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
32
+ *
33
+ * @param {unknown} error The unknown exception to be checked.
34
+ * @returns - A boolean indicating if the error was from an upload cancellation
32
35
  */
33
36
  export const isCancelError = (error: unknown): error is CanceledError =>
34
37
  !!error && error instanceof CanceledError;
@@ -112,3 +112,12 @@ export interface InternalPostInput {
112
112
  */
113
113
  abortController?: AbortController;
114
114
  }
115
+
116
+ /**
117
+ * Type for signingServiceInfo which enable IAM auth as well as overwrite the IAM signing info.
118
+ * @internal
119
+ */
120
+ export interface SigningServiceInfo {
121
+ service?: string;
122
+ region?: string;
123
+ }
@@ -0,0 +1,44 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { HttpRequest } from '@aws-amplify/core/internals/aws-client-utils';
5
+
6
+ import { SigningServiceInfo } from '../types';
7
+
8
+ /**
9
+ * Determines if IAM authentication should be applied for a GraphQL request.
10
+ *
11
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
12
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
13
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
14
+ *
15
+ * @param request - The HTTP request object containing headers.
16
+ * @param signingServiceInfo - Optional signing service information,
17
+ * including service and region.
18
+ * @returns A boolean `true` if IAM authentication should be applied.
19
+ *
20
+ * @internal
21
+ */
22
+ export const isIamAuthApplicableForGraphQL = (
23
+ { headers }: HttpRequest,
24
+ signingServiceInfo?: SigningServiceInfo,
25
+ ) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
26
+
27
+ /**
28
+ * Determines if IAM authentication should be applied for a REST request.
29
+ *
30
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
31
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
32
+ * header and `signingServiceInfo` is provided.
33
+ *
34
+ * @param request - The HTTP request object containing headers.
35
+ * @param signingServiceInfo - Optional signing service information,
36
+ * including service and region.
37
+ * @returns A boolean `true` if IAM authentication should be applied.
38
+ *
39
+ * @internal
40
+ */
41
+ export const isIamAuthApplicableForRest = (
42
+ { headers }: HttpRequest,
43
+ signingServiceInfo?: SigningServiceInfo,
44
+ ) => !headers.authorization && !!signingServiceInfo;