@aws-amplify/core 6.5.0 → 6.5.1-storage-browser-integrity.4892fe9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/cjs/Platform/types.js +2 -0
  2. package/dist/cjs/Platform/types.js.map +1 -1
  3. package/dist/cjs/Platform/version.js +1 -1
  4. package/dist/cjs/Platform/version.js.map +1 -1
  5. package/dist/cjs/clients/middleware/retry/defaultRetryDecider.js +5 -2
  6. package/dist/cjs/clients/middleware/retry/defaultRetryDecider.js.map +1 -1
  7. package/dist/cjs/clients/middleware/retry/middleware.js +4 -1
  8. package/dist/cjs/clients/middleware/retry/middleware.js.map +1 -1
  9. package/dist/cjs/clients/middleware/retry/types.js +6 -0
  10. package/dist/cjs/clients/middleware/retry/types.js.map +1 -0
  11. package/dist/cjs/clients/middleware/signing/middleware.js +6 -2
  12. package/dist/cjs/clients/middleware/signing/middleware.js.map +1 -1
  13. package/dist/cjs/parseAmplifyOutputs.js +4 -2
  14. package/dist/cjs/parseAmplifyOutputs.js.map +1 -1
  15. package/dist/esm/Platform/types.d.ts +3 -1
  16. package/dist/esm/Platform/types.mjs +2 -0
  17. package/dist/esm/Platform/types.mjs.map +1 -1
  18. package/dist/esm/Platform/version.d.ts +1 -1
  19. package/dist/esm/Platform/version.mjs +1 -1
  20. package/dist/esm/Platform/version.mjs.map +1 -1
  21. package/dist/esm/awsClients/cognitoIdentity/base.d.ts +1 -1
  22. package/dist/esm/awsClients/cognitoIdentity/getCredentialsForIdentity.d.ts +1 -1
  23. package/dist/esm/awsClients/cognitoIdentity/getId.d.ts +1 -1
  24. package/dist/esm/awsClients/pinpoint/base.d.ts +1 -1
  25. package/dist/esm/awsClients/pinpoint/getInAppMessages.d.ts +2 -2
  26. package/dist/esm/awsClients/pinpoint/putEvents.d.ts +2 -2
  27. package/dist/esm/awsClients/pinpoint/updateEndpoint.d.ts +2 -2
  28. package/dist/esm/clients/index.d.ts +2 -2
  29. package/dist/esm/clients/middleware/retry/defaultRetryDecider.d.ts +2 -1
  30. package/dist/esm/clients/middleware/retry/defaultRetryDecider.mjs +5 -2
  31. package/dist/esm/clients/middleware/retry/defaultRetryDecider.mjs.map +1 -1
  32. package/dist/esm/clients/middleware/retry/index.d.ts +1 -0
  33. package/dist/esm/clients/middleware/retry/middleware.d.ts +3 -1
  34. package/dist/esm/clients/middleware/retry/middleware.mjs +4 -1
  35. package/dist/esm/clients/middleware/retry/middleware.mjs.map +1 -1
  36. package/dist/esm/clients/middleware/retry/types.d.ts +4 -0
  37. package/dist/esm/clients/middleware/retry/types.mjs +2 -0
  38. package/dist/esm/clients/middleware/retry/types.mjs.map +1 -0
  39. package/dist/esm/clients/middleware/signing/index.d.ts +1 -1
  40. package/dist/esm/clients/middleware/signing/middleware.d.ts +10 -2
  41. package/dist/esm/clients/middleware/signing/middleware.mjs +6 -2
  42. package/dist/esm/clients/middleware/signing/middleware.mjs.map +1 -1
  43. package/dist/esm/clients/types/core.d.ts +5 -0
  44. package/dist/esm/clients/types/index.d.ts +1 -1
  45. package/dist/esm/parseAmplifyOutputs.mjs +4 -2
  46. package/dist/esm/parseAmplifyOutputs.mjs.map +1 -1
  47. package/dist/esm/singleton/AmplifyOutputs/types.d.ts +6 -0
  48. package/dist/esm/singleton/Auth/types.d.ts +4 -0
  49. package/dist/esm/singleton/Storage/types.d.ts +2 -0
  50. package/package.json +3 -3
  51. package/src/Platform/types.ts +2 -0
  52. package/src/Platform/version.ts +1 -1
  53. package/src/clients/index.ts +6 -1
  54. package/src/clients/middleware/retry/defaultRetryDecider.ts +11 -4
  55. package/src/clients/middleware/retry/index.ts +1 -0
  56. package/src/clients/middleware/retry/middleware.ts +16 -2
  57. package/src/clients/middleware/retry/types.ts +7 -0
  58. package/src/clients/middleware/signing/index.ts +5 -1
  59. package/src/clients/middleware/signing/middleware.ts +21 -3
  60. package/src/clients/types/core.ts +5 -0
  61. package/src/clients/types/index.ts +1 -0
  62. package/src/parseAmplifyOutputs.ts +17 -12
  63. package/src/singleton/AmplifyOutputs/types.ts +5 -1
  64. package/src/singleton/Auth/types.ts +5 -0
  65. package/src/singleton/Storage/types.ts +2 -0
@@ -13,10 +13,13 @@ const getRetryDecider = (errorParser) => async (response, error) => {
13
13
  undefined;
14
14
  const errorCode = parsedError?.code || parsedError?.name;
15
15
  const statusCode = response?.statusCode;
16
- return (isConnectionError(error) ||
16
+ const isRetryable = isConnectionError(error) ||
17
17
  isThrottlingError(statusCode, errorCode) ||
18
18
  isClockSkewError(errorCode) ||
19
- isServerSideError(statusCode, errorCode));
19
+ isServerSideError(statusCode, errorCode);
20
+ return {
21
+ retryable: isRetryable,
22
+ };
20
23
  };
21
24
  // reference: https://github.com/aws/aws-sdk-js-v3/blob/ab0e7be36e7e7f8a0c04834357aaad643c7912c3/packages/service-error-classification/src/constants.ts#L22-L37
22
25
  const THROTTLING_ERROR_CODES = [
@@ -1 +1 @@
1
- {"version":3,"file":"defaultRetryDecider.mjs","sources":["../../../../../src/clients/middleware/retry/defaultRetryDecider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyErrorCode } from '../../../types';\nimport { isClockSkewError } from './isClockSkewError';\n/**\n * Get retry decider function\n * @param errorParser Function to load JavaScript error from HTTP response\n */\nexport const getRetryDecider = (errorParser) => async (response, error) => {\n const parsedError = error ??\n (await errorParser(response)) ??\n undefined;\n const errorCode = parsedError?.code || parsedError?.name;\n const statusCode = response?.statusCode;\n return (isConnectionError(error) ||\n isThrottlingError(statusCode, errorCode) ||\n isClockSkewError(errorCode) ||\n isServerSideError(statusCode, errorCode));\n};\n// reference: https://github.com/aws/aws-sdk-js-v3/blob/ab0e7be36e7e7f8a0c04834357aaad643c7912c3/packages/service-error-classification/src/constants.ts#L22-L37\nconst THROTTLING_ERROR_CODES = [\n 'BandwidthLimitExceeded',\n 'EC2ThrottledException',\n 'LimitExceededException',\n 'PriorRequestNotComplete',\n 'ProvisionedThroughputExceededException',\n 'RequestLimitExceeded',\n 'RequestThrottled',\n 'RequestThrottledException',\n 'SlowDown',\n 'ThrottledException',\n 'Throttling',\n 'ThrottlingException',\n 'TooManyRequestsException',\n];\nconst TIMEOUT_ERROR_CODES = [\n 'TimeoutError',\n 'RequestTimeout',\n 'RequestTimeoutException',\n];\nconst isThrottlingError = (statusCode, errorCode) => statusCode === 429 ||\n (!!errorCode && THROTTLING_ERROR_CODES.includes(errorCode));\nconst isConnectionError = (error) => [\n AmplifyErrorCode.NetworkError,\n // TODO(vNext): unify the error code `ERR_NETWORK` used by the Storage XHR handler\n 'ERR_NETWORK',\n].includes(error?.name);\nconst isServerSideError = (statusCode, errorCode) => (!!statusCode && [500, 502, 503, 504].includes(statusCode)) ||\n (!!errorCode && TIMEOUT_ERROR_CODES.includes(errorCode));\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,WAAW,KAAK,OAAO,QAAQ,EAAE,KAAK,KAAK;AAC3E,IAAI,MAAM,WAAW,GAAG,KAAK;AAC7B,SAAS,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;AACrC,QAAQ,SAAS,CAAC;AAClB,IAAI,MAAM,SAAS,GAAG,WAAW,EAAE,IAAI,IAAI,WAAW,EAAE,IAAI,CAAC;AAC7D,IAAI,MAAM,UAAU,GAAG,QAAQ,EAAE,UAAU,CAAC;AAC5C,IAAI,QAAQ,iBAAiB,CAAC,KAAK,CAAC;AACpC,QAAQ,iBAAiB,CAAC,UAAU,EAAE,SAAS,CAAC;AAChD,QAAQ,gBAAgB,CAAC,SAAS,CAAC;AACnC,QAAQ,iBAAiB,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE;AAClD,EAAE;AACF;AACA,MAAM,sBAAsB,GAAG;AAC/B,IAAI,wBAAwB;AAC5B,IAAI,uBAAuB;AAC3B,IAAI,wBAAwB;AAC5B,IAAI,yBAAyB;AAC7B,IAAI,wCAAwC;AAC5C,IAAI,sBAAsB;AAC1B,IAAI,kBAAkB;AACtB,IAAI,2BAA2B;AAC/B,IAAI,UAAU;AACd,IAAI,oBAAoB;AACxB,IAAI,YAAY;AAChB,IAAI,qBAAqB;AACzB,IAAI,0BAA0B;AAC9B,CAAC,CAAC;AACF,MAAM,mBAAmB,GAAG;AAC5B,IAAI,cAAc;AAClB,IAAI,gBAAgB;AACpB,IAAI,yBAAyB;AAC7B,CAAC,CAAC;AACF,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,SAAS,KAAK,UAAU,KAAK,GAAG;AACvE,KAAK,CAAC,CAAC,SAAS,IAAI,sBAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;AAChE,MAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK;AACrC,IAAI,gBAAgB,CAAC,YAAY;AACjC;AACA,IAAI,aAAa;AACjB,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACxB,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;AAC/G,KAAK,CAAC,CAAC,SAAS,IAAI,mBAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"defaultRetryDecider.mjs","sources":["../../../../../src/clients/middleware/retry/defaultRetryDecider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyErrorCode } from '../../../types';\nimport { isClockSkewError } from './isClockSkewError';\n/**\n * Get retry decider function\n * @param errorParser Function to load JavaScript error from HTTP response\n */\nexport const getRetryDecider = (errorParser) => async (response, error) => {\n const parsedError = error ??\n (await errorParser(response)) ??\n undefined;\n const errorCode = parsedError?.code || parsedError?.name;\n const statusCode = response?.statusCode;\n const isRetryable = isConnectionError(error) ||\n isThrottlingError(statusCode, errorCode) ||\n isClockSkewError(errorCode) ||\n isServerSideError(statusCode, errorCode);\n return {\n retryable: isRetryable,\n };\n};\n// reference: https://github.com/aws/aws-sdk-js-v3/blob/ab0e7be36e7e7f8a0c04834357aaad643c7912c3/packages/service-error-classification/src/constants.ts#L22-L37\nconst THROTTLING_ERROR_CODES = [\n 'BandwidthLimitExceeded',\n 'EC2ThrottledException',\n 'LimitExceededException',\n 'PriorRequestNotComplete',\n 'ProvisionedThroughputExceededException',\n 'RequestLimitExceeded',\n 'RequestThrottled',\n 'RequestThrottledException',\n 'SlowDown',\n 'ThrottledException',\n 'Throttling',\n 'ThrottlingException',\n 'TooManyRequestsException',\n];\nconst TIMEOUT_ERROR_CODES = [\n 'TimeoutError',\n 'RequestTimeout',\n 'RequestTimeoutException',\n];\nconst isThrottlingError = (statusCode, errorCode) => statusCode === 429 ||\n (!!errorCode && THROTTLING_ERROR_CODES.includes(errorCode));\nconst isConnectionError = (error) => [\n AmplifyErrorCode.NetworkError,\n // TODO(vNext): unify the error code `ERR_NETWORK` used by the Storage XHR handler\n 'ERR_NETWORK',\n].includes(error?.name);\nconst isServerSideError = (statusCode, errorCode) => (!!statusCode && [500, 502, 503, 504].includes(statusCode)) ||\n (!!errorCode && TIMEOUT_ERROR_CODES.includes(errorCode));\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,WAAW,KAAK,OAAO,QAAQ,EAAE,KAAK,KAAK;AAC3E,IAAI,MAAM,WAAW,GAAG,KAAK;AAC7B,SAAS,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;AACrC,QAAQ,SAAS,CAAC;AAClB,IAAI,MAAM,SAAS,GAAG,WAAW,EAAE,IAAI,IAAI,WAAW,EAAE,IAAI,CAAC;AAC7D,IAAI,MAAM,UAAU,GAAG,QAA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KAAK,CAAC,CAAC,SAAS,IAAI,mBAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;;;;"}
@@ -1,3 +1,4 @@
1
1
  export { RetryOptions, retryMiddlewareFactory } from './middleware';
2
2
  export { jitteredBackoff } from './jitteredBackoff';
3
3
  export { getRetryDecider } from './defaultRetryDecider';
4
+ export { RetryDeciderOutput } from './types';
@@ -1,4 +1,5 @@
1
1
  import { MiddlewareContext, MiddlewareHandler, Request, Response } from '../../types/core';
2
+ import { RetryDeciderOutput } from './types';
2
3
  /**
3
4
  * Configuration of the retry middleware
4
5
  */
@@ -8,9 +9,10 @@ export interface RetryOptions<TResponse = Response> {
8
9
  *
9
10
  * @param response Optional response of the request.
10
11
  * @param error Optional error thrown from previous attempts.
12
+ * @param middlewareContext Optional context object to store data between retries.
11
13
  * @returns True if the request should be retried.
12
14
  */
13
- retryDecider(response?: TResponse, error?: unknown): Promise<boolean>;
15
+ retryDecider(response?: TResponse, error?: unknown, middlewareContext?: MiddlewareContext): Promise<RetryDeciderOutput>;
14
16
  /**
15
17
  * Function to compute the delay in milliseconds before the next retry based
16
18
  * on the number of attempts.
@@ -38,7 +38,10 @@ const retryMiddlewareFactory = ({ maxAttempts = DEFAULT_RETRY_ATTEMPTS, retryDec
38
38
  ? (context.attemptsCount ?? 0)
39
39
  : attemptsCount + 1;
40
40
  context.attemptsCount = attemptsCount;
41
- if (await retryDecider(response, error)) {
41
+ const { isCredentialsExpiredError, retryable } = await retryDecider(response, error, context);
42
+ if (retryable) {
43
+ // Setting isCredentialsInvalid flag to notify signing middleware to forceRefresh credentials provider.
44
+ context.isCredentialsExpired = !!isCredentialsExpiredError;
42
45
  if (!abortSignal?.aborted && attemptsCount < maxAttempts) {
43
46
  // prevent sleep for last attempt or cancelled request;
44
47
  const delay = computeDelay(attemptsCount);
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.mjs","sources":["../../../../../src/clients/middleware/retry/middleware.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst DEFAULT_RETRY_ATTEMPTS = 3;\n/**\n * Retry middleware\n */\nexport const retryMiddlewareFactory = ({ maxAttempts = DEFAULT_RETRY_ATTEMPTS, retryDecider, computeDelay, abortSignal, }) => {\n if (maxAttempts < 1) {\n throw new Error('maxAttempts must be greater than 0');\n }\n return (next, context) => async function retryMiddleware(request) {\n let error;\n let attemptsCount = context.attemptsCount ?? 0;\n let response;\n // When retry is not needed or max attempts is reached, either error or response will be set. This function handles either cases.\n const handleTerminalErrorOrResponse = () => {\n if (response) {\n addOrIncrementMetadataAttempts(response, attemptsCount);\n return response;\n }\n else {\n addOrIncrementMetadataAttempts(error, attemptsCount);\n throw error;\n }\n };\n while (!abortSignal?.aborted && attemptsCount < maxAttempts) {\n try {\n response = await next(request);\n error = undefined;\n }\n catch (e) {\n error = e;\n response = undefined;\n }\n // context.attemptsCount may be updated after calling next handler which may retry the request by itself.\n attemptsCount =\n (context.attemptsCount ?? 0) > attemptsCount\n ? (context.attemptsCount ?? 0)\n : attemptsCount + 1;\n context.attemptsCount = attemptsCount;\n if (await retryDecider(response, error)) {\n if (!abortSignal?.aborted && attemptsCount < maxAttempts) {\n // prevent sleep for last attempt or cancelled request;\n const delay = computeDelay(attemptsCount);\n await cancellableSleep(delay, abortSignal);\n }\n continue;\n }\n else {\n return handleTerminalErrorOrResponse();\n }\n }\n if (abortSignal?.aborted) {\n throw new Error('Request aborted.');\n }\n else {\n return handleTerminalErrorOrResponse();\n }\n };\n};\nconst cancellableSleep = (timeoutMs, abortSignal) => {\n if (abortSignal?.aborted) {\n return Promise.resolve();\n }\n let timeoutId;\n let sleepPromiseResolveFn;\n const sleepPromise = new Promise(resolve => {\n sleepPromiseResolveFn = resolve;\n timeoutId = setTimeout(resolve, timeoutMs);\n });\n abortSignal?.addEventListener('abort', function cancelSleep(_) {\n clearTimeout(timeoutId);\n abortSignal?.removeEventListener('abort', cancelSleep);\n sleepPromiseResolveFn();\n });\n return sleepPromise;\n};\nconst addOrIncrementMetadataAttempts = (nextHandlerOutput, attempts) => {\n if (Object.prototype.toString.call(nextHandlerOutput) !== '[object Object]') {\n return;\n }\n nextHandlerOutput.$metadata = {\n ...(nextHandlerOutput.$metadata ?? {}),\n attempts,\n };\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC;AACA;AACA;AACY,MAAC,sBAAsB,GAAG,CAAC,EAAE,WAAW,GAAG,sBAAsB,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,GAAG,KAAK;AAC9H,IAAI,IAAI,WAAW,GAAG,CAAC,EAAE;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AAC9D,KAAK;AACL,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,KAAK,eAAe,eAAe,CAAC,OAAO,EAAE;AACtE,QAAQ,IAAI,KAAK,CAAC;AAClB,QAAQ,IAAI,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;AACvD,QAAQ,IAAI,QAAQ,CAAC;AACrB;AACA,QAAQ,MAAM,6BAA6B,GAAG,MAAM;AACpD,YAAY,IAAI,QAAQ,EAAE;AAC1B,gBAAgB,8BAA8B,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AACxE,gBAAgB,OAAO,QAAQ,CAAC;AAChC,aAAa;AACb,iBAAiB;AACjB,gBAAgB,8BAA8B,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AACrE,gBAAgB,MAAM,KAAK,CAAC;AAC5B,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,CAAC,WAAW,EAAE,OAAO,IAAI,aAAa,GAAG,WAAW,EAAE;AACrE,YAAY,IAAI;AAChB,gBAAgB,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/C,gBAAgB,KAAK,GAAG,SAAS,CAAC;AAClC,aAAa;AACb,YA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B,GAAG,OAAO,CAAC;AACxC,QAAQ,SAAS,GAAG,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACnD,KAAK,CAAC,CAAC;AACP,IAAI,WAAW,EAAE,gBAAgB,CAAC,OAAO,EAAE,SAAS,WAAW,CAAC,CAAC,EAAE;AACnE,QAAQ,YAAY,CAAC,SAAS,CAAC,CAAC;AAChC,QAAQ,WAAW,EAAE,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC/D,QAAQ,qBAAqB,EAAE,CAAC;AAChC,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,YAAY,CAAC;AACxB,CAAC,CAAC;AACF,MAAM,8BAA8B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,KAAK;AACxE,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,iBAAiB,EAAE;AACjF,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,iBAAiB,CAAC,SAAS,GAAG;AAClC,QAAQ,IAAI,iBAAiB,CAAC,SAAS,IAAI,EAAE,CAAC;AAC9C,QAAQ,QAAQ;AAChB,KAAK,CAAC;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"middleware.mjs","sources":["../../../../../src/clients/middleware/retry/middleware.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst DEFAULT_RETRY_ATTEMPTS = 3;\n/**\n * Retry middleware\n */\nexport const retryMiddlewareFactory = ({ maxAttempts = DEFAULT_RETRY_ATTEMPTS, retryDecider, computeDelay, abortSignal, }) => {\n if (maxAttempts < 1) {\n throw new Error('maxAttempts must be greater than 0');\n }\n return (next, context) => async function retryMiddleware(request) {\n let error;\n let attemptsCount = context.attemptsCount ?? 0;\n let response;\n // When retry is not needed or max attempts is reached, either error or response will be set. This function handles either cases.\n const handleTerminalErrorOrResponse = () => {\n if (response) {\n addOrIncrementMetadataAttempts(response, attemptsCount);\n return response;\n }\n else {\n addOrIncrementMetadataAttempts(error, attemptsCount);\n throw error;\n }\n };\n while (!abortSignal?.aborted && attemptsCount < maxAttempts) {\n try {\n response = await next(request);\n error = undefined;\n }\n catch (e) {\n error = e;\n response = undefined;\n }\n // context.attemptsCount may be updated after calling next handler which may retry the request by itself.\n attemptsCount =\n (context.attemptsCount ?? 0) > attemptsCount\n ? (context.attemptsCount ?? 0)\n : attemptsCount + 1;\n context.attemptsCount = attemptsCount;\n const { isCredentialsExpiredError, retryable } = await retryDecider(response, error, context);\n if (retryable) {\n // Setting isCredentialsInvalid flag to notify signing middleware to forceRefresh credentials provider.\n context.isCredentialsExpired = !!isCredentialsExpiredError;\n if (!abortSignal?.aborted && attemptsCount < maxAttempts) {\n // prevent sleep for last attempt or cancelled request;\n const delay = computeDelay(attemptsCount);\n await cancellableSleep(delay, abortSignal);\n }\n continue;\n }\n else {\n return handleTerminalErrorOrResponse();\n }\n }\n if (abortSignal?.aborted) {\n throw new Error('Request aborted.');\n }\n else {\n return handleTerminalErrorOrResponse();\n }\n };\n};\nconst cancellableSleep = (timeoutMs, abortSignal) => {\n if (abortSignal?.aborted) {\n return Promise.resolve();\n }\n let timeoutId;\n let sleepPromiseResolveFn;\n const sleepPromise = new Promise(resolve => {\n sleepPromiseResolveFn = resolve;\n timeoutId = setTimeout(resolve, timeoutMs);\n });\n abortSignal?.addEventListener('abort', function cancelSleep(_) {\n clearTimeout(timeoutId);\n abortSignal?.removeEventListener('abort', cancelSleep);\n sleepPromiseResolveFn();\n });\n return sleepPromise;\n};\nconst addOrIncrementMetadataAttempts = (nextHandlerOutput, attempts) => {\n if (Object.prototype.toString.call(nextHandlerOutput) !== '[object Object]') {\n return;\n }\n nextHandlerOutput.$metadata = {\n ...(nextHandlerOutput.$metadata ?? {}),\n attempts,\n };\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC;AACA;AACA;AACY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I,WAAW,EAAE,gBAAgB,CAAC,OAAO,EAAE,SAAS,WAAW,CAAC,CAAC,EAAE;AACnE,QAAQ,YAAY,CAAC,SAAS,CAAC,CAAC;AAChC,QAAQ,WAAW,EAAE,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC/D,QAAQ,qBAAqB,EAAE,CAAC;AAChC,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,YAAY,CAAC;AACxB,CAAC,CAAC;AACF,MAAM,8BAA8B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,KAAK;AACxE,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,iBAAiB,EAAE;AACjF,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,iBAAiB,CAAC,SAAS,GAAG;AAClC,QAAQ,IAAI,iBAAiB,CAAC,SAAS,IAAI,EAAE,CAAC;AAC9C,QAAQ,QAAQ;AAChB,KAAK,CAAC;AACN,CAAC;;;;"}
@@ -0,0 +1,4 @@
1
+ export interface RetryDeciderOutput {
2
+ retryable: boolean;
3
+ isCredentialsExpiredError?: boolean;
4
+ }
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +1 @@
1
- export { signingMiddlewareFactory, SigningOptions } from './middleware';
1
+ export { signingMiddlewareFactory, SigningOptions, CredentialsProviderOptions, } from './middleware';
@@ -1,9 +1,17 @@
1
1
  import { Credentials, HttpRequest, HttpResponse, MiddlewareHandler } from '../../types';
2
+ import { MiddlewareContext } from '../../types/core';
3
+ /**
4
+ * Options type for the async callback function returning aws credentials. This
5
+ * function is used by SigV4 signer to resolve the aws credentials
6
+ */
7
+ export interface CredentialsProviderOptions {
8
+ forceRefresh?: boolean;
9
+ }
2
10
  /**
3
11
  * Configuration of the signing middleware
4
12
  */
5
13
  export interface SigningOptions {
6
- credentials: Credentials | (() => Promise<Credentials>);
14
+ credentials: Credentials | ((options?: CredentialsProviderOptions) => Promise<Credentials>);
7
15
  region: string;
8
16
  service: string;
9
17
  /**
@@ -18,4 +26,4 @@ export interface SigningOptions {
18
26
  * Middleware that SigV4 signs request with AWS credentials, and correct system clock offset.
19
27
  * This middleware is expected to be placed after retry middleware.
20
28
  */
21
- export declare const signingMiddlewareFactory: ({ credentials, region, service, uriEscapePath, }: SigningOptions) => (next: MiddlewareHandler<HttpRequest, HttpResponse>) => (request: HttpRequest) => Promise<HttpResponse>;
29
+ export declare const signingMiddlewareFactory: ({ credentials, region, service, uriEscapePath, }: SigningOptions) => (next: MiddlewareHandler<HttpRequest, HttpResponse>, context: MiddlewareContext) => (request: HttpRequest) => Promise<HttpResponse>;
@@ -12,10 +12,14 @@ import { getUpdatedSystemClockOffset } from './utils/getUpdatedSystemClockOffset
12
12
  */
13
13
  const signingMiddlewareFactory = ({ credentials, region, service, uriEscapePath = true, }) => {
14
14
  let currentSystemClockOffset;
15
- return (next) => async function signingMiddleware(request) {
15
+ return (next, context) => async function signingMiddleware(request) {
16
16
  currentSystemClockOffset = currentSystemClockOffset ?? 0;
17
17
  const signRequestOptions = {
18
- credentials: typeof credentials === 'function' ? await credentials() : credentials,
18
+ credentials: typeof credentials === 'function'
19
+ ? await credentials({
20
+ forceRefresh: !!context?.isCredentialsExpired,
21
+ })
22
+ : credentials,
19
23
  signingDate: getSkewCorrectedDate(currentSystemClockOffset),
20
24
  signingRegion: region,
21
25
  signingService: service,
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.mjs","sources":["../../../../../src/clients/middleware/signing/middleware.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { signRequest } from './signer/signatureV4';\nimport { getSkewCorrectedDate } from './utils/getSkewCorrectedDate';\nimport { getUpdatedSystemClockOffset } from './utils/getUpdatedSystemClockOffset';\n/**\n * Middleware that SigV4 signs request with AWS credentials, and correct system clock offset.\n * This middleware is expected to be placed after retry middleware.\n */\nexport const signingMiddlewareFactory = ({ credentials, region, service, uriEscapePath = true, }) => {\n let currentSystemClockOffset;\n return (next) => async function signingMiddleware(request) {\n currentSystemClockOffset = currentSystemClockOffset ?? 0;\n const signRequestOptions = {\n credentials: typeof credentials === 'function' ? await credentials() : credentials,\n signingDate: getSkewCorrectedDate(currentSystemClockOffset),\n signingRegion: region,\n signingService: service,\n uriEscapePath,\n };\n const signedRequest = await signRequest(request, signRequestOptions);\n const response = await next(signedRequest);\n // Update system clock offset if response contains date header, regardless of the status code.\n // non-2xx response will still be returned from next handler instead of thrown, because it's\n // only thrown by the retry middleware.\n const dateString = getDateHeader(response);\n if (dateString) {\n currentSystemClockOffset = getUpdatedSystemClockOffset(Date.parse(dateString), currentSystemClockOffset);\n }\n return response;\n };\n};\nconst getDateHeader = ({ headers } = {}) => headers?.date ?? headers?.Date ?? headers?.['x-amz-date'];\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACY,MAAC,wBAAwB,GAAG,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,KAAK;AACrG,IAAI,IAAI,wBAAwB,CAAC;AACjC,IAAI,OAAO,CAAC,IAAI,KAAK,eAAe,iBAAiB,CAAC,OAAO,EAAE;AAC/D,QAAQ,wBAAwB,GAAG,wBAAwB,IAAI,CAAC,CAAC;AACjE,QAAQ,MAAM,kBAAkB,GAAG;AACnC,YAAY,WAAW,EAAE,OAAO,WAAW,KAAK,UAAU,GAAG,MAAM,WAAW,EAAE,GAAG,WAAW;AAC9F,YAAY,WAAW,EAAE,oBAAoB,CAAC,wBAAwB,CAAC;AACvE,YAAY,aAAa,EAAE,MAAM;AACjC,YAAY,cAAc,EAAE,OAAO;AACnC,YAAY,aAAa;AACzB,SAAS,CAAC;AACV,QAAQ,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAC7E,QAAQ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;AACnD;AACA;AACA;AACA,QAAQ,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;AACnD,QAAQ,IAAI,UAAU,EAAE;AACxB,YAAY,wBAAwB,GAAG,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACrH,SAAS;AACT,QAAQ,OAAO,QAAQ,CAAC;AACxB,KAAK,CAAC;AACN,EAAE;AACF,MAAM,aAAa,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI,IAAI,OAAO,GAAG,YAAY,CAAC;;;;"}
1
+ {"version":3,"file":"middleware.mjs","sources":["../../../../../src/clients/middleware/signing/middleware.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { signRequest } from './signer/signatureV4';\nimport { getSkewCorrectedDate } from './utils/getSkewCorrectedDate';\nimport { getUpdatedSystemClockOffset } from './utils/getUpdatedSystemClockOffset';\n/**\n * Middleware that SigV4 signs request with AWS credentials, and correct system clock offset.\n * This middleware is expected to be placed after retry middleware.\n */\nexport const signingMiddlewareFactory = ({ credentials, region, service, uriEscapePath = true, }) => {\n let currentSystemClockOffset;\n return (next, context) => async function signingMiddleware(request) {\n currentSystemClockOffset = currentSystemClockOffset ?? 0;\n const signRequestOptions = {\n credentials: typeof credentials === 'function'\n ? await credentials({\n forceRefresh: !!context?.isCredentialsExpired,\n })\n : credentials,\n signingDate: getSkewCorrectedDate(currentSystemClockOffset),\n signingRegion: region,\n signingService: service,\n uriEscapePath,\n };\n const signedRequest = await signRequest(request, signRequestOptions);\n const response = await next(signedRequest);\n // Update system clock offset if response contains date header, regardless of the status code.\n // non-2xx response will still be returned from next handler instead of thrown, because it's\n // only thrown by the retry middleware.\n const dateString = getDateHeader(response);\n if (dateString) {\n currentSystemClockOffset = getUpdatedSystemClockOffset(Date.parse(dateString), currentSystemClockOffset);\n }\n return response;\n };\n};\nconst getDateHeader = ({ headers } = {}) => headers?.date ?? headers?.Date ?? headers?.['x-amz-date'];\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACY,MAAC,wBAAwB,GAAG,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,KAAK;AACrG,IAAI,IAAI,wBAAwB,CAAC;AACjC,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,KAAK,eAAe,iBAAiB,CAAC,OAAO,EAAE;AACxE,QAAQ,wBAAwB,GAAG,wBAAwB,IAAI,CAAC,CAAC;AACjE,QAAQ,MAAM,kBAAkB,GAAG;AACnC,YAAY,WAAW,EAAE,OAAO,WAAW,KAAK,UAAU;AAC1D,kBAAkB,MAAM,WAAW,CAAC;AACpC,oBAAoB,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,oBAAoB;AACjE,iBAAiB,CAAC;AAClB,kBAAkB,WAAW;AAC7B,YAAY,WAAW,EAAE,oBAAoB,CAAC,wBAAwB,CAAC;AACvE,YAAY,aAAa,EAAE,MAAM;AACjC,YAAY,cAAc,EAAE,OAAO;AACnC,YAAY,aAAa;AACzB,SAAS,CAAC;AACV,QAAQ,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAC7E,QAAQ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;AACnD;AACA;AACA;AACA,QAAQ,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;AACnD,QAAQ,IAAI,UAAU,EAAE;AACxB,YAAY,wBAAwB,GAAG,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACrH,SAAS;AACT,QAAQ,OAAO,QAAQ,CAAC;AACxB,KAAK,CAAC;AACN,EAAE;AACF,MAAM,aAAa,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI,IAAI,OAAO,GAAG,YAAY,CAAC;;;;"}
@@ -17,6 +17,11 @@ export type MiddlewareHandler<Input, Output> = (request: Input) => Promise<Outpu
17
17
  * The context object to store states across the middleware chain.
18
18
  */
19
19
  export interface MiddlewareContext {
20
+ /**
21
+ * Whether an error indicating expired credentials has been returned from server-side.
22
+ * This is set by the retry middleware.
23
+ */
24
+ isCredentialsExpired?: boolean;
20
25
  /**
21
26
  * The number of times the request has been attempted. This is set by retry middleware
22
27
  */
@@ -1,3 +1,3 @@
1
- export { Middleware, MiddlewareHandler, Request, Response, TransferHandler, Endpoint, } from './core';
1
+ export { Middleware, MiddlewareHandler, MiddlewareContext, Request, Response, TransferHandler, Endpoint, } from './core';
2
2
  export { Headers, HttpRequest, HttpResponse, HttpTransferHandler, HttpTransferOptions, ResponseBodyMixin, } from './http';
3
3
  export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, } from './aws';
@@ -25,11 +25,12 @@ function parseAuth(amplifyOutputsAuthProperties) {
25
25
  if (!amplifyOutputsAuthProperties) {
26
26
  return undefined;
27
27
  }
28
- const { user_pool_id, user_pool_client_id, identity_pool_id, password_policy, mfa_configuration, mfa_methods, unauthenticated_identities_enabled, oauth, username_attributes, standard_required_attributes, } = amplifyOutputsAuthProperties;
28
+ const { user_pool_id, user_pool_client_id, identity_pool_id, password_policy, mfa_configuration, mfa_methods, unauthenticated_identities_enabled, oauth, username_attributes, standard_required_attributes, groups, } = amplifyOutputsAuthProperties;
29
29
  const authConfig = {
30
30
  Cognito: {
31
31
  userPoolId: user_pool_id,
32
32
  userPoolClientId: user_pool_client_id,
33
+ groups,
33
34
  },
34
35
  };
35
36
  if (identity_pool_id) {
@@ -231,13 +232,14 @@ function getMfaStatus(mfaConfiguration) {
231
232
  }
232
233
  function createBucketInfoMap(buckets) {
233
234
  const mappedBuckets = {};
234
- buckets.forEach(({ name, bucket_name: bucketName, aws_region: region }) => {
235
+ buckets.forEach(({ name, bucket_name: bucketName, aws_region: region, paths }) => {
235
236
  if (name in mappedBuckets) {
236
237
  throw new Error(`Duplicate friendly name found: ${name}. Name must be unique.`);
237
238
  }
238
239
  mappedBuckets[name] = {
239
240
  bucketName,
240
241
  region,
242
+ paths,
241
243
  };
242
244
  });
243
245
  return mappedBuckets;
@@ -1 +1 @@
1
- {"version":3,"file":"parseAmplifyOutputs.mjs","sources":["../../src/parseAmplifyOutputs.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isAmplifyOutputs(config) {\n // version format initially will be '1' but is expected to be something like x.y where x is major and y minor version\n const { version } = config;\n if (!version) {\n return false;\n }\n return version.startsWith('1');\n}\nfunction parseStorage(amplifyOutputsStorageProperties) {\n if (!amplifyOutputsStorageProperties) {\n return undefined;\n }\n const { bucket_name, aws_region, buckets } = amplifyOutputsStorageProperties;\n return {\n S3: {\n bucket: bucket_name,\n region: aws_region,\n buckets: buckets && createBucketInfoMap(buckets),\n },\n };\n}\nfunction parseAuth(amplifyOutputsAuthProperties) {\n if (!amplifyOutputsAuthProperties) {\n return undefined;\n }\n const { user_pool_id, user_pool_client_id, identity_pool_id, password_policy, mfa_configuration, mfa_methods, unauthenticated_identities_enabled, oauth, username_attributes, standard_required_attributes, } = amplifyOutputsAuthProperties;\n const authConfig = {\n Cognito: {\n userPoolId: user_pool_id,\n userPoolClientId: user_pool_client_id,\n },\n };\n if (identity_pool_id) {\n authConfig.Cognito = {\n ...authConfig.Cognito,\n identityPoolId: identity_pool_id,\n };\n }\n if (password_policy) {\n authConfig.Cognito.passwordFormat = {\n requireLowercase: password_policy.require_lowercase,\n requireNumbers: password_policy.require_numbers,\n requireUppercase: password_policy.require_uppercase,\n requireSpecialCharacters: password_policy.require_symbols,\n minLength: password_policy.min_length ?? 6,\n };\n }\n if (mfa_configuration) {\n authConfig.Cognito.mfa = {\n status: getMfaStatus(mfa_configuration),\n smsEnabled: mfa_methods?.includes('SMS'),\n totpEnabled: mfa_methods?.includes('TOTP'),\n };\n }\n if (unauthenticated_identities_enabled) {\n authConfig.Cognito.allowGuestAccess = unauthenticated_identities_enabled;\n }\n if (oauth) {\n authConfig.Cognito.loginWith = {\n oauth: {\n domain: oauth.domain,\n redirectSignIn: oauth.redirect_sign_in_uri,\n redirectSignOut: oauth.redirect_sign_out_uri,\n responseType: oauth.response_type === 'token' ? 'token' : 'code',\n scopes: oauth.scopes,\n providers: getOAuthProviders(oauth.identity_providers),\n },\n };\n }\n if (username_attributes) {\n authConfig.Cognito.loginWith = {\n ...authConfig.Cognito.loginWith,\n email: username_attributes.includes('email'),\n phone: username_attributes.includes('phone_number'),\n // Signing in with a username is not currently supported in Gen2, this should always evaluate to false\n username: username_attributes.includes('username'),\n };\n }\n if (standard_required_attributes) {\n authConfig.Cognito.userAttributes = standard_required_attributes.reduce((acc, curr) => ({ ...acc, [curr]: { required: true } }), {});\n }\n return authConfig;\n}\nexport function parseAnalytics(amplifyOutputsAnalyticsProperties) {\n if (!amplifyOutputsAnalyticsProperties?.amazon_pinpoint) {\n return undefined;\n }\n const { amazon_pinpoint } = amplifyOutputsAnalyticsProperties;\n return {\n Pinpoint: {\n appId: amazon_pinpoint.app_id,\n region: amazon_pinpoint.aws_region,\n },\n };\n}\nfunction parseGeo(amplifyOutputsAnalyticsProperties) {\n if (!amplifyOutputsAnalyticsProperties) {\n return undefined;\n }\n const { aws_region, geofence_collections, maps, search_indices } = amplifyOutputsAnalyticsProperties;\n return {\n LocationService: {\n region: aws_region,\n searchIndices: search_indices,\n geofenceCollections: geofence_collections,\n maps,\n },\n };\n}\nfunction parseData(amplifyOutputsDataProperties) {\n if (!amplifyOutputsDataProperties) {\n return undefined;\n }\n const { aws_region, default_authorization_type, url, api_key, model_introspection, } = amplifyOutputsDataProperties;\n const GraphQL = {\n endpoint: url,\n defaultAuthMode: getGraphQLAuthMode(default_authorization_type),\n region: aws_region,\n apiKey: api_key,\n modelIntrospection: model_introspection,\n };\n return {\n GraphQL,\n };\n}\nfunction parseCustom(amplifyOutputsCustomProperties) {\n if (!amplifyOutputsCustomProperties?.events) {\n return undefined;\n }\n const { url, aws_region, api_key, default_authorization_type } = amplifyOutputsCustomProperties.events;\n const Events = {\n endpoint: url,\n defaultAuthMode: getGraphQLAuthMode(default_authorization_type),\n region: aws_region,\n apiKey: api_key,\n };\n return {\n Events,\n };\n}\nfunction parseNotifications(amplifyOutputsNotificationsProperties) {\n if (!amplifyOutputsNotificationsProperties) {\n return undefined;\n }\n const { aws_region, channels, amazon_pinpoint_app_id } = amplifyOutputsNotificationsProperties;\n const hasInAppMessaging = channels.includes('IN_APP_MESSAGING');\n const hasPushNotification = channels.includes('APNS') || channels.includes('FCM');\n if (!(hasInAppMessaging || hasPushNotification)) {\n return undefined;\n }\n // At this point, we know the Amplify outputs contains at least one supported channel\n const notificationsConfig = {};\n if (hasInAppMessaging) {\n notificationsConfig.InAppMessaging = {\n Pinpoint: {\n appId: amazon_pinpoint_app_id,\n region: aws_region,\n },\n };\n }\n if (hasPushNotification) {\n notificationsConfig.PushNotification = {\n Pinpoint: {\n appId: amazon_pinpoint_app_id,\n region: aws_region,\n },\n };\n }\n return notificationsConfig;\n}\nexport function parseAmplifyOutputs(amplifyOutputs) {\n const resourcesConfig = {};\n if (amplifyOutputs.storage) {\n resourcesConfig.Storage = parseStorage(amplifyOutputs.storage);\n }\n if (amplifyOutputs.auth) {\n resourcesConfig.Auth = parseAuth(amplifyOutputs.auth);\n }\n if (amplifyOutputs.analytics) {\n resourcesConfig.Analytics = parseAnalytics(amplifyOutputs.analytics);\n }\n if (amplifyOutputs.geo) {\n resourcesConfig.Geo = parseGeo(amplifyOutputs.geo);\n }\n if (amplifyOutputs.data) {\n resourcesConfig.API = parseData(amplifyOutputs.data);\n }\n if (amplifyOutputs.custom) {\n const customConfig = parseCustom(amplifyOutputs.custom);\n if (customConfig && 'Events' in customConfig) {\n resourcesConfig.API = { ...resourcesConfig.API, ...customConfig };\n }\n }\n if (amplifyOutputs.notifications) {\n resourcesConfig.Notifications = parseNotifications(amplifyOutputs.notifications);\n }\n return resourcesConfig;\n}\nconst authModeNames = {\n AMAZON_COGNITO_USER_POOLS: 'userPool',\n API_KEY: 'apiKey',\n AWS_IAM: 'iam',\n AWS_LAMBDA: 'lambda',\n OPENID_CONNECT: 'oidc',\n};\nfunction getGraphQLAuthMode(authType) {\n return authModeNames[authType];\n}\nconst providerNames = {\n GOOGLE: 'Google',\n LOGIN_WITH_AMAZON: 'Amazon',\n FACEBOOK: 'Facebook',\n SIGN_IN_WITH_APPLE: 'Apple',\n};\nfunction getOAuthProviders(providers = []) {\n return providers.reduce((oAuthProviders, provider) => {\n if (providerNames[provider] !== undefined) {\n oAuthProviders.push(providerNames[provider]);\n }\n return oAuthProviders;\n }, []);\n}\nfunction getMfaStatus(mfaConfiguration) {\n if (mfaConfiguration === 'OPTIONAL')\n return 'optional';\n if (mfaConfiguration === 'REQUIRED')\n return 'on';\n return 'off';\n}\nfunction createBucketInfoMap(buckets) {\n const mappedBuckets = {};\n buckets.forEach(({ name, bucket_name: bucketName, aws_region: region }) => {\n if (name in mappedBuckets) {\n throw new Error(`Duplicate friendly name found: ${name}. Name must be unique.`);\n }\n mappedBuckets[name] = {\n bucketName,\n region,\n };\n });\n return mappedBuckets;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC;AACA,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AAC/B,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,O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Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isAmplifyOutputs(config) {\n // version format initially will be '1' but is expected to be something like x.y where x is major and y minor version\n const { version } = config;\n if (!version) {\n return false;\n }\n return version.startsWith('1');\n}\nfunction parseStorage(amplifyOutputsStorageProperties) {\n if (!amplifyOutputsStorageProperties) {\n return undefined;\n }\n const { bucket_name, aws_region, buckets } = amplifyOutputsStorageProperties;\n return {\n S3: {\n bucket: bucket_name,\n region: aws_region,\n buckets: buckets && createBucketInfoMap(buckets),\n },\n };\n}\nfunction parseAuth(amplifyOutputsAuthProperties) {\n if (!amplifyOutputsAuthProperties) {\n return undefined;\n }\n const { user_pool_id, user_pool_client_id, identity_pool_id, password_policy, mfa_configuration, mfa_methods, unauthenticated_identities_enabled, oauth, username_attributes, standard_required_attributes, groups, } = amplifyOutputsAuthProperties;\n const authConfig = {\n Cognito: {\n userPoolId: user_pool_id,\n userPoolClientId: user_pool_client_id,\n groups,\n },\n };\n if (identity_pool_id) {\n authConfig.Cognito = {\n ...authConfig.Cognito,\n identityPoolId: identity_pool_id,\n };\n }\n if (password_policy) {\n authConfig.Cognito.passwordFormat = {\n requireLowercase: password_policy.require_lowercase,\n requireNumbers: password_policy.require_numbers,\n requireUppercase: password_policy.require_uppercase,\n requireSpecialCharacters: password_policy.require_symbols,\n minLength: password_policy.min_length ?? 6,\n };\n }\n if (mfa_configuration) {\n authConfig.Cognito.mfa = {\n status: getMfaStatus(mfa_configuration),\n smsEnabled: mfa_methods?.includes('SMS'),\n totpEnabled: mfa_methods?.includes('TOTP'),\n };\n }\n if (unauthenticated_identities_enabled) {\n authConfig.Cognito.allowGuestAccess = unauthenticated_identities_enabled;\n }\n if (oauth) {\n authConfig.Cognito.loginWith = {\n oauth: {\n domain: oauth.domain,\n redirectSignIn: oauth.redirect_sign_in_uri,\n redirectSignOut: oauth.redirect_sign_out_uri,\n responseType: oauth.response_type === 'token' ? 'token' : 'code',\n scopes: oauth.scopes,\n providers: getOAuthProviders(oauth.identity_providers),\n },\n };\n }\n if (username_attributes) {\n authConfig.Cognito.loginWith = {\n ...authConfig.Cognito.loginWith,\n email: username_attributes.includes('email'),\n phone: username_attributes.includes('phone_number'),\n // Signing in with a username is not currently supported in Gen2, this should always evaluate to false\n username: username_attributes.includes('username'),\n };\n }\n if (standard_required_attributes) {\n authConfig.Cognito.userAttributes = standard_required_attributes.reduce((acc, curr) => ({ ...acc, [curr]: { required: true } }), {});\n }\n return authConfig;\n}\nexport function parseAnalytics(amplifyOutputsAnalyticsProperties) {\n if (!amplifyOutputsAnalyticsProperties?.amazon_pinpoint) {\n return undefined;\n }\n const { amazon_pinpoint } = amplifyOutputsAnalyticsProperties;\n return {\n Pinpoint: {\n appId: amazon_pinpoint.app_id,\n region: amazon_pinpoint.aws_region,\n },\n };\n}\nfunction parseGeo(amplifyOutputsAnalyticsProperties) {\n if (!amplifyOutputsAnalyticsProperties) {\n return undefined;\n }\n const { aws_region, geofence_collections, maps, search_indices } = amplifyOutputsAnalyticsProperties;\n return {\n LocationService: {\n region: aws_region,\n searchIndices: search_indices,\n geofenceCollections: geofence_collections,\n maps,\n },\n };\n}\nfunction parseData(amplifyOutputsDataProperties) {\n if (!amplifyOutputsDataProperties) {\n return undefined;\n }\n const { aws_region, default_authorization_type, url, api_key, model_introspection, } = amplifyOutputsDataProperties;\n const GraphQL = {\n endpoint: url,\n defaultAuthMode: getGraphQLAuthMode(default_authorization_type),\n region: aws_region,\n apiKey: api_key,\n modelIntrospection: model_introspection,\n };\n return {\n GraphQL,\n };\n}\nfunction parseCustom(amplifyOutputsCustomProperties) {\n if (!amplifyOutputsCustomProperties?.events) {\n return undefined;\n }\n const { url, aws_region, api_key, default_authorization_type } = amplifyOutputsCustomProperties.events;\n const Events = {\n endpoint: url,\n defaultAuthMode: getGraphQLAuthMode(default_authorization_type),\n region: aws_region,\n apiKey: api_key,\n };\n return {\n Events,\n };\n}\nfunction parseNotifications(amplifyOutputsNotificationsProperties) {\n if (!amplifyOutputsNotificationsProperties) {\n return undefined;\n }\n const { aws_region, channels, amazon_pinpoint_app_id } = amplifyOutputsNotificationsProperties;\n const hasInAppMessaging = channels.includes('IN_APP_MESSAGING');\n const hasPushNotification = channels.includes('APNS') || channels.includes('FCM');\n if (!(hasInAppMessaging || hasPushNotification)) {\n return undefined;\n }\n // At this point, we know the Amplify outputs contains at least one supported channel\n const notificationsConfig = {};\n if (hasInAppMessaging) {\n notificationsConfig.InAppMessaging = {\n Pinpoint: {\n appId: amazon_pinpoint_app_id,\n region: aws_region,\n },\n };\n }\n if (hasPushNotification) {\n notificationsConfig.PushNotification = {\n Pinpoint: {\n appId: amazon_pinpoint_app_id,\n region: aws_region,\n },\n };\n }\n return notificationsConfig;\n}\nexport function parseAmplifyOutputs(amplifyOutputs) {\n const resourcesConfig = {};\n if (amplifyOutputs.storage) {\n resourcesConfig.Storage = parseStorage(amplifyOutputs.storage);\n }\n if (amplifyOutputs.auth) {\n resourcesConfig.Auth = parseAuth(amplifyOutputs.auth);\n }\n if (amplifyOutputs.analytics) {\n resourcesConfig.Analytics = parseAnalytics(amplifyOutputs.analytics);\n }\n if (amplifyOutputs.geo) {\n resourcesConfig.Geo = parseGeo(amplifyOutputs.geo);\n }\n if (amplifyOutputs.data) {\n resourcesConfig.API = parseData(amplifyOutputs.data);\n }\n if (amplifyOutputs.custom) {\n const customConfig = parseCustom(amplifyOutputs.custom);\n if (customConfig && 'Events' in customConfig) {\n resourcesConfig.API = { ...resourcesConfig.API, ...customConfig };\n }\n }\n if (amplifyOutputs.notifications) {\n resourcesConfig.Notifications = parseNotifications(amplifyOutputs.notifications);\n }\n return resourcesConfig;\n}\nconst authModeNames = {\n AMAZON_COGNITO_USER_POOLS: 'userPool',\n API_KEY: 'apiKey',\n AWS_IAM: 'iam',\n AWS_LAMBDA: 'lambda',\n OPENID_CONNECT: 'oidc',\n};\nfunction getGraphQLAuthMode(authType) {\n return authModeNames[authType];\n}\nconst providerNames = {\n GOOGLE: 'Google',\n LOGIN_WITH_AMAZON: 'Amazon',\n FACEBOOK: 'Facebook',\n SIGN_IN_WITH_APPLE: 'Apple',\n};\nfunction getOAuthProviders(providers = []) {\n return providers.reduce((oAuthProviders, provider) => {\n if (providerNames[provider] !== undefined) {\n oAuthProviders.push(providerNames[provider]);\n }\n return oAuthProviders;\n }, []);\n}\nfunction getMfaStatus(mfaConfiguration) {\n if (mfaConfiguration === 'OPTIONAL')\n return 'optional';\n if (mfaConfiguration === 'REQUIRED')\n return 'on';\n return 'off';\n}\nfunction createBucketInfoMap(buckets) {\n const mappedBuckets = {};\n buckets.forEach(({ name, bucket_name: bucketName, aws_region: region, paths }) => {\n if (name in mappedBuckets) {\n throw new Error(`Duplicate friendly name found: ${name}. Name must be unique.`);\n }\n mappedBuckets[name] = {\n bucketName,\n region,\n paths,\n };\n });\n return mappedBuckets;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC;AACA,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AAC/B,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AACD,SAAS,YAAY,CAAC,+BAA+B,EAAE;AACvD,IAAI,IAAI,CAAC,+BAA+B,EAAE;AAC1C,QAAQ,OAAO,SAAS,CAAC;AACzB,KAAK;AACL,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,+BAA+B,CAAC;AACjF,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE;AACZ,YAAY,MAAM,EAAE,WAAW;AAC/B,YAAY,MAAM,EAAE,UAAU;AAC9B,YAAY,OAAO,EAAE,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC;AAC5D,SAAS;AACT,KAAK,CAAC;AACN,CAAC;AACD,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,gBAAgB,EAAE;AACxC,IAAI,IAAI,gBAAgB,KAAK,UAAU;AACvC,QAAQ,OAAO,UAAU,CAAC;AAC1B,IAAI,IAAI,gBAAgB,KAAK,UAAU;AACvC,QAAQ,OAAO,IAAI,CAAC;AACpB,IAAI,OAAO,KAAK,CAAC;AACjB,CAAC;AACD,SAAS,mBAAmB,CAAC,OAAO,EAAE;AACtC,IAAI,MAAM,aAAa,GAAG,EAAE,CAAC;AAC7B,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;AACtF,QAAQ,IAAI,IAAI,IAAI,aAAa,EAAE;AACnC,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,+BAA+B,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAC5F,SAAS;AACT,QAAQ,aAAa,CAAC,IAAI,CAAC,GAAG;AAC9B,YAAY,UAAU;AACtB,YAAY,MAAM;AAClB,YAAY,KAAK;AACjB,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,aAAa,CAAC;AACzB;;;;"}
@@ -1,6 +1,8 @@
1
1
  export type AmplifyOutputsOAuthIdentityProvider = 'GOOGLE' | 'FACEBOOK' | 'LOGIN_WITH_AMAZON' | 'SIGN_IN_WITH_APPLE';
2
2
  export type AmplifyOutputsAuthMFAConfiguration = 'OPTIONAL' | 'REQUIRED' | 'NONE';
3
3
  export type AmplifyOutputsAuthMFAMethod = 'SMS' | 'TOTP';
4
+ type UserGroupName = string;
5
+ type UserGroupPrecedence = Record<string, number>;
4
6
  export interface AmplifyOutputsAuthProperties {
5
7
  aws_region: string;
6
8
  authentication_flow_type?: 'USER_SRP_AUTH' | 'CUSTOM_AUTH';
@@ -28,6 +30,7 @@ export interface AmplifyOutputsAuthProperties {
28
30
  unauthenticated_identities_enabled?: boolean;
29
31
  mfa_configuration?: string;
30
32
  mfa_methods?: string[];
33
+ groups?: Record<UserGroupName, UserGroupPrecedence>[];
31
34
  }
32
35
  export interface AmplifyOutputsStorageBucketProperties {
33
36
  /** Friendly bucket name provided in Amplify Outputs */
@@ -36,6 +39,8 @@ export interface AmplifyOutputsStorageBucketProperties {
36
39
  bucket_name: string;
37
40
  /** Region for the bucket */
38
41
  aws_region: string;
42
+ /** Paths to object with access permissions */
43
+ paths?: Record<string, Record<string, string[] | undefined>>;
39
44
  }
40
45
  export interface AmplifyOutputsStorageProperties {
41
46
  /** Default region for Storage */
@@ -100,3 +105,4 @@ export interface AmplifyOutputs {
100
105
  custom?: AmplifyOutputsCustomProperties;
101
106
  notifications?: AmplifyOutputsNotificationsProperties;
102
107
  }
108
+ export {};
@@ -61,6 +61,8 @@ export interface AuthTokens {
61
61
  export type AuthStandardAttributeKey = 'address' | 'birthdate' | 'email_verified' | 'family_name' | 'gender' | 'given_name' | 'locale' | 'middle_name' | 'name' | 'nickname' | 'phone_number_verified' | 'picture' | 'preferred_username' | 'profile' | 'sub' | 'updated_at' | 'website' | 'zoneinfo' | AuthVerifiableAttributeKey;
62
62
  export type LegacyUserAttributeKey = Uppercase<AuthStandardAttributeKey>;
63
63
  export type AuthVerifiableAttributeKey = 'email' | 'phone_number';
64
+ type UserGroupName = string;
65
+ type UserGroupPrecedence = Record<string, number>;
64
66
  export type AuthConfigUserAttributes = Partial<Record<AuthStandardAttributeKey, {
65
67
  required: boolean;
66
68
  }>>;
@@ -76,6 +78,7 @@ export interface AuthIdentityPoolConfig {
76
78
  userAttributes?: never;
77
79
  mfa?: never;
78
80
  passwordFormat?: never;
81
+ groups?: never;
79
82
  };
80
83
  }
81
84
  export interface CognitoIdentityPoolConfig {
@@ -113,6 +116,7 @@ export interface CognitoUserPoolConfig {
113
116
  requireNumbers?: boolean;
114
117
  requireSpecialCharacters?: boolean;
115
118
  };
119
+ groups?: Record<UserGroupName, UserGroupPrecedence>[];
116
120
  }
117
121
  export interface OAuthConfig {
118
122
  domain: string;
@@ -7,6 +7,8 @@ export interface BucketInfo {
7
7
  bucketName: string;
8
8
  /** Region of the bucket */
9
9
  region: string;
10
+ /** Paths to object with access permissions */
11
+ paths?: Record<string, Record<string, string[] | undefined>>;
10
12
  }
11
13
  export interface S3ProviderConfig {
12
14
  S3: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/core",
3
- "version": "6.5.0",
3
+ "version": "6.5.1-storage-browser-integrity.4892fe9.0+4892fe9",
4
4
  "description": "Core category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -60,7 +60,7 @@
60
60
  "uuid": "^9.0.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@aws-amplify/react-native": "1.1.6",
63
+ "@aws-amplify/react-native": "1.1.7-storage-browser-integrity.4892fe9.0+4892fe9",
64
64
  "@types/js-cookie": "3.0.2",
65
65
  "genversion": "^2.2.0",
66
66
  "typescript": "5.0.2"
@@ -192,5 +192,5 @@
192
192
  ]
193
193
  }
194
194
  },
195
- "gitHead": "51138ecfe8509cd0d5486f2e583cc506093ebd9d"
195
+ "gitHead": "4892fe912e86c5e38de88f5714cfb3d5e7b4637d"
196
196
  }
@@ -133,6 +133,8 @@ export enum StorageAction {
133
133
  Remove = '5',
134
134
  GetProperties = '6',
135
135
  GetUrl = '7',
136
+ GetDataAccess = '8',
137
+ ListCallerAccessGrants = '9',
136
138
  }
137
139
 
138
140
  interface ActionMap {
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.7.0';
2
+ export const version = '6.7.1-storage-browser-integrity.4892fe9.0+4892fe9';
@@ -15,9 +15,14 @@ export {
15
15
  } from './middleware/signing/signer/signatureV4';
16
16
  export { EMPTY_HASH as EMPTY_SHA256_HASH } from './middleware/signing/signer/signatureV4/constants';
17
17
  export { extendedEncodeURIComponent } from './middleware/signing/utils/extendedEncodeURIComponent';
18
- export { signingMiddlewareFactory, SigningOptions } from './middleware/signing';
18
+ export {
19
+ signingMiddlewareFactory,
20
+ SigningOptions,
21
+ CredentialsProviderOptions,
22
+ } from './middleware/signing';
19
23
  export {
20
24
  getRetryDecider,
25
+ RetryDeciderOutput,
21
26
  jitteredBackoff,
22
27
  retryMiddlewareFactory,
23
28
  RetryOptions,
@@ -5,6 +5,7 @@ import { AmplifyErrorCode } from '../../../types';
5
5
  import { ErrorParser, HttpResponse } from '../../types';
6
6
 
7
7
  import { isClockSkewError } from './isClockSkewError';
8
+ import { RetryDeciderOutput } from './types';
8
9
 
9
10
  /**
10
11
  * Get retry decider function
@@ -12,7 +13,10 @@ import { isClockSkewError } from './isClockSkewError';
12
13
  */
13
14
  export const getRetryDecider =
14
15
  (errorParser: ErrorParser) =>
15
- async (response?: HttpResponse, error?: unknown): Promise<boolean> => {
16
+ async (
17
+ response?: HttpResponse,
18
+ error?: unknown,
19
+ ): Promise<RetryDeciderOutput> => {
16
20
  const parsedError =
17
21
  (error as Error & { code: string }) ??
18
22
  (await errorParser(response)) ??
@@ -20,12 +24,15 @@ export const getRetryDecider =
20
24
  const errorCode = parsedError?.code || parsedError?.name;
21
25
  const statusCode = response?.statusCode;
22
26
 
23
- return (
27
+ const isRetryable =
24
28
  isConnectionError(error) ||
25
29
  isThrottlingError(statusCode, errorCode) ||
26
30
  isClockSkewError(errorCode) ||
27
- isServerSideError(statusCode, errorCode)
28
- );
31
+ isServerSideError(statusCode, errorCode);
32
+
33
+ return {
34
+ retryable: isRetryable,
35
+ };
29
36
  };
30
37
 
31
38
  // reference: https://github.com/aws/aws-sdk-js-v3/blob/ab0e7be36e7e7f8a0c04834357aaad643c7912c3/packages/service-error-classification/src/constants.ts#L22-L37
@@ -4,3 +4,4 @@
4
4
  export { RetryOptions, retryMiddlewareFactory } from './middleware';
5
5
  export { jitteredBackoff } from './jitteredBackoff';
6
6
  export { getRetryDecider } from './defaultRetryDecider';
7
+ export { RetryDeciderOutput } from './types';
@@ -8,6 +8,8 @@ import {
8
8
  Response,
9
9
  } from '../../types/core';
10
10
 
11
+ import { RetryDeciderOutput } from './types';
12
+
11
13
  const DEFAULT_RETRY_ATTEMPTS = 3;
12
14
 
13
15
  /**
@@ -19,9 +21,14 @@ export interface RetryOptions<TResponse = Response> {
19
21
  *
20
22
  * @param response Optional response of the request.
21
23
  * @param error Optional error thrown from previous attempts.
24
+ * @param middlewareContext Optional context object to store data between retries.
22
25
  * @returns True if the request should be retried.
23
26
  */
24
- retryDecider(response?: TResponse, error?: unknown): Promise<boolean>;
27
+ retryDecider(
28
+ response?: TResponse,
29
+ error?: unknown,
30
+ middlewareContext?: MiddlewareContext,
31
+ ): Promise<RetryDeciderOutput>;
25
32
  /**
26
33
  * Function to compute the delay in milliseconds before the next retry based
27
34
  * on the number of attempts.
@@ -87,7 +94,14 @@ export const retryMiddlewareFactory = <TInput = Request, TOutput = Response>({
87
94
  ? (context.attemptsCount ?? 0)
88
95
  : attemptsCount + 1;
89
96
  context.attemptsCount = attemptsCount;
90
- if (await retryDecider(response, error)) {
97
+ const { isCredentialsExpiredError, retryable } = await retryDecider(
98
+ response,
99
+ error,
100
+ context,
101
+ );
102
+ if (retryable) {
103
+ // Setting isCredentialsInvalid flag to notify signing middleware to forceRefresh credentials provider.
104
+ context.isCredentialsExpired = !!isCredentialsExpiredError;
91
105
  if (!abortSignal?.aborted && attemptsCount < maxAttempts) {
92
106
  // prevent sleep for last attempt or cancelled request;
93
107
  const delay = computeDelay(attemptsCount);
@@ -0,0 +1,7 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export interface RetryDeciderOutput {
5
+ retryable: boolean;
6
+ isCredentialsExpiredError?: boolean;
7
+ }
@@ -1,4 +1,8 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export { signingMiddlewareFactory, SigningOptions } from './middleware';
4
+ export {
5
+ signingMiddlewareFactory,
6
+ SigningOptions,
7
+ CredentialsProviderOptions,
8
+ } from './middleware';
@@ -7,16 +7,27 @@ import {
7
7
  HttpResponse,
8
8
  MiddlewareHandler,
9
9
  } from '../../types';
10
+ import { MiddlewareContext } from '../../types/core';
10
11
 
11
12
  import { signRequest } from './signer/signatureV4';
12
13
  import { getSkewCorrectedDate } from './utils/getSkewCorrectedDate';
13
14
  import { getUpdatedSystemClockOffset } from './utils/getUpdatedSystemClockOffset';
14
15
 
16
+ /**
17
+ * Options type for the async callback function returning aws credentials. This
18
+ * function is used by SigV4 signer to resolve the aws credentials
19
+ */
20
+ export interface CredentialsProviderOptions {
21
+ forceRefresh?: boolean;
22
+ }
23
+
15
24
  /**
16
25
  * Configuration of the signing middleware
17
26
  */
18
27
  export interface SigningOptions {
19
- credentials: Credentials | (() => Promise<Credentials>);
28
+ credentials:
29
+ | Credentials
30
+ | ((options?: CredentialsProviderOptions) => Promise<Credentials>);
20
31
  region: string;
21
32
  service: string;
22
33
 
@@ -41,12 +52,19 @@ export const signingMiddlewareFactory = ({
41
52
  }: SigningOptions) => {
42
53
  let currentSystemClockOffset: number;
43
54
 
44
- return (next: MiddlewareHandler<HttpRequest, HttpResponse>) =>
55
+ return (
56
+ next: MiddlewareHandler<HttpRequest, HttpResponse>,
57
+ context: MiddlewareContext,
58
+ ) =>
45
59
  async function signingMiddleware(request: HttpRequest) {
46
60
  currentSystemClockOffset = currentSystemClockOffset ?? 0;
47
61
  const signRequestOptions = {
48
62
  credentials:
49
- typeof credentials === 'function' ? await credentials() : credentials,
63
+ typeof credentials === 'function'
64
+ ? await credentials({
65
+ forceRefresh: !!context?.isCredentialsExpired,
66
+ })
67
+ : credentials,
50
68
  signingDate: getSkewCorrectedDate(currentSystemClockOffset),
51
69
  signingRegion: region,
52
70
  signingService: service,
@@ -30,6 +30,11 @@ export type MiddlewareHandler<Input, Output> = (
30
30
  * The context object to store states across the middleware chain.
31
31
  */
32
32
  export interface MiddlewareContext {
33
+ /**
34
+ * Whether an error indicating expired credentials has been returned from server-side.
35
+ * This is set by the retry middleware.
36
+ */
37
+ isCredentialsExpired?: boolean;
33
38
  /**
34
39
  * The number of times the request has been attempted. This is set by retry middleware
35
40
  */
@@ -4,6 +4,7 @@
4
4
  export {
5
5
  Middleware,
6
6
  MiddlewareHandler,
7
+ MiddlewareContext,
7
8
  Request,
8
9
  Response,
9
10
  TransferHandler,