@aws-amplify/core 5.5.3-api-v6.2 → 5.5.3-api-v6.23

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 (156) hide show
  1. package/internals/aws-client-utils/composers/package.json +8 -0
  2. package/internals/aws-client-utils/package.json +4 -4
  3. package/lib/Amplify.js +2 -0
  4. package/lib/AwsClients/CognitoIdentity/base.d.ts +1 -1
  5. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +14 -3
  6. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +2 -1
  7. package/lib/AwsClients/CognitoIdentity/getId.d.ts +14 -3
  8. package/lib/AwsClients/CognitoIdentity/getId.js +2 -1
  9. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +13 -3
  10. package/lib/AwsClients/Pinpoint/putEvents.d.ts +13 -3
  11. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +13 -3
  12. package/lib/Credentials.js +2 -0
  13. package/lib/Platform/index.d.ts +2 -2
  14. package/lib/Platform/index.js +5 -2
  15. package/lib/Platform/types.d.ts +4 -0
  16. package/lib/Platform/types.js +0 -2
  17. package/lib/Platform/version.d.ts +1 -1
  18. package/lib/Platform/version.js +1 -1
  19. package/lib/Providers/index.js +2 -0
  20. package/lib/ServiceWorker/ServiceWorker.js +2 -0
  21. package/lib/ServiceWorker/index.js +2 -0
  22. package/lib/UniversalStorage/index.js +2 -0
  23. package/lib/Util/BackgroundProcessManager.js +2 -0
  24. package/lib/Util/DateUtils.js +2 -0
  25. package/lib/Util/Mutex.js +2 -0
  26. package/lib/Util/Reachability.js +2 -0
  27. package/lib/Util/Reachability.native.js +2 -0
  28. package/lib/Util/StringUtils.js +2 -0
  29. package/lib/Util/index.js +2 -0
  30. package/lib/clients/handlers/fetch.js +4 -21
  31. package/lib/clients/index.d.ts +7 -2
  32. package/lib/clients/index.js +17 -4
  33. package/lib/clients/internal/composeServiceApi.d.ts +1 -1
  34. package/lib/clients/internal/composeServiceApi.js +6 -6
  35. package/lib/clients/internal/index.d.ts +7 -0
  36. package/lib/clients/internal/index.js +14 -0
  37. package/lib/clients/middleware/retry/middleware.d.ts +0 -7
  38. package/lib/clients/middleware/retry/middleware.js +37 -26
  39. package/lib/clients/middleware/signing/middleware.d.ts +9 -2
  40. package/lib/clients/middleware/signing/middleware.js +25 -14
  41. package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +2 -0
  42. package/lib/clients/middleware/signing/signer/signatureV4/index.js +3 -1
  43. package/lib/clients/middleware/signing/signer/signatureV4/index.native.d.ts +1 -0
  44. package/lib/clients/middleware/signing/signer/signatureV4/index.native.js +3 -1
  45. package/lib/clients/middleware/signing/signer/signatureV4/types/signer.d.ts +10 -1
  46. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.d.ts +3 -1
  47. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +5 -2
  48. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.d.ts +3 -1
  49. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +9 -2
  50. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.d.ts +1 -1
  51. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +2 -2
  52. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.d.ts +1 -1
  53. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +3 -2
  54. package/lib/clients/serde/responseInfo.js +4 -2
  55. package/lib/clients/types/aws.d.ts +4 -3
  56. package/lib/clients/utils/memoization.d.ts +9 -0
  57. package/lib/clients/utils/memoization.js +26 -0
  58. package/lib/tsconfig.tsbuildinfo +1 -1
  59. package/lib/types/index.js +2 -0
  60. package/lib-esm/Amplify.js +2 -0
  61. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +1 -1
  62. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +14 -3
  63. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +2 -1
  64. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +14 -3
  65. package/lib-esm/AwsClients/CognitoIdentity/getId.js +2 -1
  66. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +13 -3
  67. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +13 -3
  68. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +13 -3
  69. package/lib-esm/Credentials.js +2 -0
  70. package/lib-esm/Platform/index.d.ts +2 -2
  71. package/lib-esm/Platform/index.js +5 -2
  72. package/lib-esm/Platform/types.d.ts +4 -0
  73. package/lib-esm/Platform/types.js +0 -2
  74. package/lib-esm/Platform/version.d.ts +1 -1
  75. package/lib-esm/Platform/version.js +1 -1
  76. package/lib-esm/Providers/index.js +2 -0
  77. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -0
  78. package/lib-esm/ServiceWorker/index.js +2 -0
  79. package/lib-esm/UniversalStorage/index.js +2 -0
  80. package/lib-esm/Util/BackgroundProcessManager.js +2 -0
  81. package/lib-esm/Util/DateUtils.js +2 -0
  82. package/lib-esm/Util/Mutex.js +2 -0
  83. package/lib-esm/Util/Reachability.js +2 -0
  84. package/lib-esm/Util/Reachability.native.js +2 -0
  85. package/lib-esm/Util/StringUtils.js +2 -0
  86. package/lib-esm/Util/index.js +2 -0
  87. package/lib-esm/clients/handlers/fetch.js +1 -18
  88. package/lib-esm/clients/index.d.ts +7 -2
  89. package/lib-esm/clients/index.js +7 -2
  90. package/lib-esm/clients/internal/composeServiceApi.d.ts +1 -1
  91. package/lib-esm/clients/internal/composeServiceApi.js +6 -6
  92. package/lib-esm/clients/internal/index.d.ts +7 -0
  93. package/lib-esm/clients/internal/index.js +9 -0
  94. package/lib-esm/clients/middleware/retry/middleware.d.ts +0 -7
  95. package/lib-esm/clients/middleware/retry/middleware.js +36 -24
  96. package/lib-esm/clients/middleware/signing/middleware.d.ts +9 -2
  97. package/lib-esm/clients/middleware/signing/middleware.js +25 -14
  98. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +2 -0
  99. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +1 -0
  100. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.d.ts +1 -0
  101. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.js +1 -0
  102. package/lib-esm/clients/middleware/signing/signer/signatureV4/types/signer.d.ts +10 -1
  103. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.d.ts +3 -1
  104. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +5 -2
  105. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.d.ts +3 -1
  106. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +9 -2
  107. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.d.ts +1 -1
  108. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +2 -2
  109. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.d.ts +1 -1
  110. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +3 -2
  111. package/lib-esm/clients/serde/responseInfo.js +3 -1
  112. package/lib-esm/clients/types/aws.d.ts +4 -3
  113. package/lib-esm/clients/utils/memoization.d.ts +9 -0
  114. package/lib-esm/clients/utils/memoization.js +22 -0
  115. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  116. package/lib-esm/types/index.js +2 -0
  117. package/package.json +9 -9
  118. package/polyfills/URL/index.ts +2 -0
  119. package/src/Amplify.ts +2 -0
  120. package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +1 -1
  121. package/src/AwsClients/CognitoIdentity/getId.ts +1 -1
  122. package/src/Credentials.ts +2 -0
  123. package/src/Platform/index.ts +8 -3
  124. package/src/Platform/types.ts +8 -0
  125. package/src/Platform/version.ts +1 -1
  126. package/src/Providers/index.ts +2 -0
  127. package/src/ServiceWorker/ServiceWorker.ts +2 -0
  128. package/src/ServiceWorker/index.ts +2 -0
  129. package/src/UniversalStorage/index.ts +2 -0
  130. package/src/Util/BackgroundProcessManager.ts +2 -0
  131. package/src/Util/DateUtils.ts +2 -0
  132. package/src/Util/Mutex.ts +2 -0
  133. package/src/Util/Reachability.native.ts +2 -0
  134. package/src/Util/Reachability.ts +2 -0
  135. package/src/Util/Retry.ts +2 -0
  136. package/src/Util/StringUtils.ts +2 -0
  137. package/src/Util/index.ts +2 -0
  138. package/src/clients/handlers/fetch.ts +1 -19
  139. package/src/clients/index.ts +15 -2
  140. package/src/clients/internal/composeServiceApi.ts +12 -6
  141. package/src/clients/internal/index.ts +10 -0
  142. package/src/clients/middleware/retry/middleware.ts +28 -24
  143. package/src/clients/middleware/signing/middleware.ts +13 -2
  144. package/src/clients/middleware/signing/signer/signatureV4/index.native.ts +1 -0
  145. package/src/clients/middleware/signing/signer/signatureV4/index.ts +2 -0
  146. package/src/clients/middleware/signing/signer/signatureV4/types/signer.ts +14 -1
  147. package/src/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.ts +7 -7
  148. package/src/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.ts +11 -2
  149. package/src/clients/middleware/signing/signer/signatureV4/utils/getSignature.ts +2 -1
  150. package/src/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.ts +2 -0
  151. package/src/clients/serde/responseInfo.ts +4 -2
  152. package/src/clients/types/aws.ts +4 -3
  153. package/src/clients/utils/memoization.ts +23 -0
  154. package/src/parseAWSExports.ts +2 -0
  155. package/src/types/index.ts +2 -0
  156. package/src/types/types.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/core",
3
- "version": "5.5.3-api-v6.2+366313460",
3
+ "version": "5.5.3-api-v6.23+6a0182db2",
4
4
  "description": "Core category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -52,7 +52,6 @@
52
52
  "@react-native-async-storage/async-storage": "1.15.17",
53
53
  "find": "^0.2.7",
54
54
  "genversion": "^2.2.0",
55
- "prepend-file": "^1.3.1",
56
55
  "react-native": "^0.64.1",
57
56
  "typescript": "5.0.2"
58
57
  },
@@ -69,6 +68,7 @@
69
68
  "@aws-sdk/client-cloudwatch-logs": "3.6.1",
70
69
  "@aws-sdk/types": "3.6.1",
71
70
  "@aws-sdk/util-hex-encoding": "3.6.1",
71
+ "@types/node-fetch": "2.6.4",
72
72
  "isomorphic-unfetch": "^3.0.0",
73
73
  "react-native-url-polyfill": "^1.3.0",
74
74
  "tslib": "^1.8.0",
@@ -104,13 +104,13 @@
104
104
  "name": "Core (Credentials)",
105
105
  "path": "./lib-esm/index.js",
106
106
  "import": "{ Credentials }",
107
- "limit": "13.3 kB"
107
+ "limit": "13.33 kB"
108
108
  },
109
109
  {
110
110
  "name": "Core (Signer)",
111
111
  "path": "./lib-esm/index.js",
112
112
  "import": "{ Signer }",
113
- "limit": "7.3 kB"
113
+ "limit": "7.4 kB"
114
114
  },
115
115
  {
116
116
  "name": "Custom clients (fetch handler)",
@@ -128,25 +128,25 @@
128
128
  "name": "Custom clients (retry middleware)",
129
129
  "path": "./lib-esm/clients/middleware/retry/middleware.js",
130
130
  "import": "{ retryMiddleware }",
131
- "limit": "1.24 kB"
131
+ "limit": "1.35 kB"
132
132
  },
133
133
  {
134
134
  "name": "Custom clients (signing middleware)",
135
135
  "path": "./lib-esm/clients/middleware/signing/middleware.js",
136
136
  "import": "{ signingMiddleware }",
137
- "limit": "6.77 kB"
137
+ "limit": "6.85 kB"
138
138
  },
139
139
  {
140
140
  "name": "Custom clients (request signer)",
141
141
  "path": "./lib-esm/clients/middleware/signing/signer/signatureV4/index.js",
142
142
  "import": "{ signRequest }",
143
- "limit": "6.13 kB"
143
+ "limit": "6.2 kB"
144
144
  },
145
145
  {
146
146
  "name": "Custom clients (url presigner)",
147
147
  "path": "./lib-esm/clients/middleware/signing/signer/signatureV4/index.js",
148
148
  "import": "{ presignUrl }",
149
- "limit": "6.25 kB"
149
+ "limit": "6.3 kB"
150
150
  }
151
151
  ],
152
152
  "jest": {
@@ -187,5 +187,5 @@
187
187
  "lib-esm"
188
188
  ]
189
189
  },
190
- "gitHead": "36631346052721682d49a4b3311352631ee8d6ac"
190
+ "gitHead": "6a0182db2a02dd45a2fd2d0c5cf69ffeaf452cc1"
191
191
  }
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /**
2
4
  * TODO: [v6] remove this polyfill.
3
5
  *
package/src/Amplify.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import { ConsoleLogger as LoggerClass } from './Logger';
2
4
 
3
5
  const logger = new LoggerClass('Amplify');
@@ -11,11 +11,11 @@ import {
11
11
  Endpoint,
12
12
  HttpRequest,
13
13
  HttpResponse,
14
- composeServiceApi,
15
14
  parseJsonBody,
16
15
  parseJsonError,
17
16
  parseMetadata,
18
17
  } from '../../clients';
18
+ import { composeServiceApi } from '../../clients/internal';
19
19
  import type {
20
20
  GetCredentialsForIdentityCommandInput as GetCredentialsForIdentityInput,
21
21
  GetCredentialsForIdentityCommandOutput as GetCredentialsForIdentityOutput,
@@ -11,11 +11,11 @@ import {
11
11
  Endpoint,
12
12
  HttpRequest,
13
13
  HttpResponse,
14
- composeServiceApi,
15
14
  parseJsonBody,
16
15
  parseJsonError,
17
16
  parseMetadata,
18
17
  } from '../../clients';
18
+ import { composeServiceApi } from '../../clients/internal';
19
19
  import {
20
20
  GetIdCommandInput as GetIdInput,
21
21
  GetIdCommandOutput as GetIdOutput,
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import { ConsoleLogger as Logger } from './Logger';
2
4
  import { StorageHelper } from './StorageHelper';
3
5
  import { makeQuerablePromise } from './JS';
@@ -4,7 +4,7 @@
4
4
  import { CustomUserAgentDetails, Framework } from './types';
5
5
  import { version } from './version';
6
6
  import { detectFramework, observeFrameworkChanges } from './detectFramework';
7
- import { UserAgent as AWSUserAgent } from '@aws-sdk/types';
7
+ import type { UserAgent as AWSUserAgent } from '@aws-sdk/types';
8
8
 
9
9
  const BASE_USER_AGENT = `aws-amplify`;
10
10
 
@@ -32,12 +32,17 @@ export const getAmplifyUserAgentObject = ({
32
32
  category,
33
33
  action,
34
34
  framework,
35
+ additionalInfo,
35
36
  }: CustomUserAgentDetails = {}): AWSUserAgent => {
36
- const userAgent: AWSUserAgent = [[BASE_USER_AGENT, version]];
37
+ let userAgent: AWSUserAgent = [[BASE_USER_AGENT, version]];
37
38
  if (category) {
38
39
  userAgent.push([category, action]);
39
40
  }
40
- userAgent.push(['framework', detectFramework()]);
41
+ userAgent.push(['framework', framework || detectFramework()]);
42
+
43
+ if (additionalInfo) {
44
+ userAgent = userAgent.concat(additionalInfo);
45
+ }
41
46
 
42
47
  return userAgent;
43
48
  };
@@ -1,5 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import type { UserAgent as AWSUserAgent } from '@aws-sdk/types';
3
4
 
4
5
  export enum Framework {
5
6
  // < 100 - Web frameworks
@@ -143,8 +144,15 @@ type UserAgentDetailsWithCategory<T extends Category> =
143
144
 
144
145
  type CustomUserAgentDetailsBase = {
145
146
  framework?: Framework;
147
+ // DO NOT REMOVE:
148
+ // Used by other Amplify teams to pass information to the custom user agent
149
+ /** Accepts an array of arrays with exactly 1 or 2 values and translates
150
+ those arrays to "item" or "item1/item2" strings on the custom user agent */
151
+ additionalInfo?: AWSUserAgent;
146
152
  };
147
153
 
154
+ // DO NOT MAKE ANY PROP REQUIRED on CustomUserAgentDetails
155
+ // This object is used by other Amplify teams to pass information to the user agent
148
156
  export type CustomUserAgentDetails =
149
157
  | (CustomUserAgentDetailsBase & { category?: never; action?: never })
150
158
  | UserAgentDetailsWithCategory<Category.API>
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '5.3.4-api-v6.2+366313460';
2
+ export const version = '5.3.4-api-v6.23+6a0182db2';
@@ -1 +1,3 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  export { AWSCloudWatchProvider } from './AWSCloudWatchProvider';
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /**
2
4
  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
5
  *
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /**
2
4
  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
5
  *
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import Cookies, { CookieSetOptions } from 'universal-cookie';
2
4
  import { browserOrNode } from '../JS';
3
5
 
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /**
2
4
  * @private For internal Amplify use.
3
5
  *
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /**
2
4
  * Date & time utility functions to abstract the `aws-sdk` away from users.
3
5
  * (v2 => v3 modularization is a breaking change)
package/src/Util/Mutex.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  /*!
2
4
  * The MIT License (MIT)
3
5
  *
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import Observable from 'zen-observable-ts';
2
4
  import { ConsoleLogger as Logger } from '../Logger';
3
5
 
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import { browserOrNode, isWebWorker } from '@aws-amplify/core';
2
4
  import Observable, { ZenObservable } from 'zen-observable-ts';
3
5
 
package/src/Util/Retry.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import { DelayFunction } from '../types';
2
4
  import { ConsoleLogger as Logger } from '../Logger/ConsoleLogger';
3
5
  const logger = new Logger('Util');
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  export function urlSafeEncode(str: string) {
2
4
  return str
3
5
  .split('')
package/src/Util/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  export {
2
4
  NonRetryableError,
3
5
  isNonRetryableError,
@@ -4,6 +4,7 @@
4
4
  import 'isomorphic-unfetch'; // TODO: remove this dependency in v6
5
5
  import { HttpRequest, HttpResponse, HttpTransferOptions } from '../types/http';
6
6
  import { TransferHandler } from '../types/core';
7
+ import { withMemoization } from '../utils/memoization';
7
8
 
8
9
  const shouldSendBody = (method: string) =>
9
10
  !['HEAD', 'GET', 'DELETE'].includes(method.toUpperCase());
@@ -54,22 +55,3 @@ export const fetchTransferHandler: TransferHandler<
54
55
  body: bodyWithMixin,
55
56
  };
56
57
  };
57
-
58
- /**
59
- * Cache the payload of a response body. It allows multiple calls to the body,
60
- * for example, when reading the body in both retry decider and error deserializer.
61
- * Caching body is allowed here because we call the body accessor(blob(), json(),
62
- * etc.) when body is small or streaming implementation is not available(RN).
63
- */
64
- const withMemoization = <T>(payloadAccessor: () => Promise<T>) => {
65
- let cached: Promise<T>;
66
- return () => {
67
- if (!cached) {
68
- // Explicitly not awaiting. Intermediate await would add overhead and
69
- // introduce a possible race in the event that this wrapper is called
70
- // again before the first `payloadAccessor` call resolves.
71
- cached = payloadAccessor();
72
- }
73
- return cached;
74
- };
75
- };
@@ -6,10 +6,23 @@ export { getDnsSuffix } from './endpoints';
6
6
  export { fetchTransferHandler } from './handlers/fetch';
7
7
  export { unauthenticatedHandler } from './handlers/unauthenticated';
8
8
  export { authenticatedHandler } from './handlers/authenticated';
9
- export { composeServiceApi } from './internal/composeServiceApi';
10
9
  export {
11
- signRequest,
10
+ getHashedPayload,
12
11
  presignUrl,
12
+ PresignUrlOptions,
13
+ signRequest,
14
+ SignRequestOptions,
13
15
  } from './middleware/signing/signer/signatureV4';
16
+ export { EMPTY_HASH as EMPTY_SHA256_HASH } from './middleware/signing/signer/signatureV4/constants';
17
+ export { extendedEncodeURIComponent } from './middleware/signing/utils/extendedEncodeURIComponent';
18
+ export { signingMiddleware, SigningOptions } from './middleware/signing';
19
+ export {
20
+ getRetryDecider,
21
+ jitteredBackoff,
22
+ retryMiddleware,
23
+ RetryOptions,
24
+ } from './middleware/retry';
25
+ export { userAgentMiddleware, UserAgentOptions } from './middleware/userAgent';
14
26
  export { parseJsonBody, parseJsonError, parseMetadata } from './serde';
27
+ export { withMemoization } from './utils/memoization';
15
28
  export * from './types';
@@ -16,13 +16,16 @@ export const composeServiceApi = <
16
16
  HttpResponse,
17
17
  TransferHandlerOptions
18
18
  >,
19
- serializer: (input: Input, endpoint: Endpoint) => HttpRequest,
19
+ serializer: (
20
+ input: Input,
21
+ endpoint: Endpoint
22
+ ) => Promise<HttpRequest> | HttpRequest,
20
23
  deserializer: (output: HttpResponse) => Promise<Output>,
21
24
  defaultConfig: DefaultConfig
22
25
  ) => {
23
26
  return async (
24
27
  config: OptionalizeKey<
25
- TransferHandlerOptions & ServiceClientOptions,
28
+ TransferHandlerOptions & ServiceClientOptions & DefaultConfig,
26
29
  keyof DefaultConfig
27
30
  >,
28
31
  input: Input
@@ -31,13 +34,16 @@ export const composeServiceApi = <
31
34
  ...defaultConfig,
32
35
  ...config,
33
36
  } as unknown as TransferHandlerOptions & ServiceClientOptions;
34
- const endpoint = await resolvedConfig.endpointResolver({
35
- region: resolvedConfig.region,
36
- });
37
+ // We may want to allow different endpoints from given config(other than region) and input.
38
+ // Currently S3 supports additional `useAccelerateEndpoint` option to use accelerate endpoint.
39
+ const endpoint = await resolvedConfig.endpointResolver(
40
+ resolvedConfig,
41
+ input
42
+ );
37
43
  // Unlike AWS SDK clients, a serializer should NOT populate the `host` or `content-length` headers.
38
44
  // Both of these headers are prohibited per Spec(https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name).
39
45
  // They will be populated automatically by browser, or node-fetch polyfill.
40
- const request = serializer(input, endpoint);
46
+ const request = await serializer(input, endpoint);
41
47
  const response = await transferHandler(request, {
42
48
  ...resolvedConfig,
43
49
  });
@@ -0,0 +1,10 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * This index should NOT be included in the ../index.ts because the composer functions
6
+ * here requires TypeScript >= 4. Given other scoped packages may use TypeScript < 4,
7
+ * they should not be exposed to upper level index.
8
+ */
9
+ export { composeServiceApi } from './composeServiceApi';
10
+ export { composeTransferHandler } from './composeTransferHandler';
@@ -1,7 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { MetadataBearer } from '@aws-sdk/types';
5
4
  import {
6
5
  MiddlewareContext,
7
6
  MiddlewareHandler,
@@ -60,13 +59,25 @@ export const retryMiddleware = <TInput = Request, TOutput = Response>({
60
59
  let error: Error;
61
60
  let attemptsCount = context.attemptsCount ?? 0;
62
61
  let response: TOutput;
62
+
63
+ // When retry is not needed or max attempts is reached, either error or response will be set. This function handles either cases.
64
+ const handleTerminalErrorOrResponse = () => {
65
+ if (response) {
66
+ addOrIncrementMetadataAttempts(response, attemptsCount);
67
+ return response;
68
+ } else {
69
+ addOrIncrementMetadataAttempts(error, attemptsCount);
70
+ throw error;
71
+ }
72
+ };
73
+
63
74
  while (!abortSignal?.aborted && attemptsCount < maxAttempts) {
64
- error = undefined;
65
- response = undefined;
66
75
  try {
67
76
  response = await next(request);
77
+ error = undefined;
68
78
  } catch (e) {
69
79
  error = e;
80
+ response = undefined;
70
81
  }
71
82
  // context.attemptsCount may be updated after calling next handler which may retry the request by itself.
72
83
  attemptsCount =
@@ -81,17 +92,16 @@ export const retryMiddleware = <TInput = Request, TOutput = Response>({
81
92
  await cancellableSleep(delay, abortSignal);
82
93
  }
83
94
  continue;
84
- } else if (response) {
85
- updateMetadataAttempts(response, attemptsCount);
86
- return response;
87
95
  } else {
88
- updateMetadataAttempts(error, attemptsCount);
89
- throw error;
96
+ return handleTerminalErrorOrResponse();
90
97
  }
91
98
  }
92
- throw abortSignal?.aborted
93
- ? new Error('Request aborted')
94
- : error ?? new Error('Retry attempts exhausted');
99
+
100
+ if (abortSignal?.aborted) {
101
+ throw new Error('Request aborted.');
102
+ } else {
103
+ return handleTerminalErrorOrResponse();
104
+ }
95
105
  };
96
106
  };
97
107
 
@@ -113,21 +123,15 @@ const cancellableSleep = (timeoutMs: number, abortSignal?: AbortSignal) => {
113
123
  return sleepPromise;
114
124
  };
115
125
 
116
- /**
117
- * Check if the response is a contains `$metadata` property.
118
- *
119
- * @internal Amplify internal use only
120
- */
121
- export const isMetadataBearer = (
122
- response: unknown
123
- ): response is MetadataBearer => typeof response?.['$metadata'] === 'object';
124
-
125
- const updateMetadataAttempts = (
126
+ const addOrIncrementMetadataAttempts = (
126
127
  nextHandlerOutput: Object,
127
128
  attempts: number
128
129
  ) => {
129
- if (isMetadataBearer(nextHandlerOutput)) {
130
- nextHandlerOutput.$metadata.attempts = attempts;
130
+ if (Object.prototype.toString.call(nextHandlerOutput) !== '[object Object]') {
131
+ return;
131
132
  }
132
- nextHandlerOutput['$metadata'] = { attempts };
133
+ nextHandlerOutput['$metadata'] = {
134
+ ...(nextHandlerOutput['$metadata'] ?? {}),
135
+ attempts,
136
+ };
133
137
  };
@@ -15,9 +15,17 @@ import { getUpdatedSystemClockOffset } from './utils/getUpdatedSystemClockOffset
15
15
  * Configuration of the signing middleware
16
16
  */
17
17
  export interface SigningOptions {
18
- credentials: Credentials;
18
+ credentials: Credentials | (() => Promise<Credentials>);
19
19
  region: string;
20
20
  service: string;
21
+
22
+ /**
23
+ * Whether to uri encode the path as part of canonical uri. It's used for S3 only where the pathname
24
+ * is already uri encoded, and the signing process is not expected to uri encode it again.
25
+ *
26
+ * @default true
27
+ */
28
+ uriEscapePath?: boolean;
21
29
  }
22
30
 
23
31
  /**
@@ -28,16 +36,19 @@ export const signingMiddleware = ({
28
36
  credentials,
29
37
  region,
30
38
  service,
39
+ uriEscapePath = true,
31
40
  }: SigningOptions) => {
32
41
  let currentSystemClockOffset;
33
42
  return (next: MiddlewareHandler<HttpRequest, HttpResponse>) =>
34
43
  async function signingMiddleware(request: HttpRequest) {
35
44
  currentSystemClockOffset = currentSystemClockOffset ?? 0;
36
45
  const signRequestOptions = {
37
- credentials,
46
+ credentials:
47
+ typeof credentials === 'function' ? await credentials() : credentials,
38
48
  signingDate: getSkewCorrectedDate(currentSystemClockOffset),
39
49
  signingRegion: region,
40
50
  signingService: service,
51
+ uriEscapePath,
41
52
  };
42
53
  const signedRequest = await signRequest(request, signRequestOptions);
43
54
  const response = await next(signedRequest);
@@ -7,3 +7,4 @@ import '@aws-amplify/core/polyfills/URL';
7
7
  export { signRequest } from './signRequest';
8
8
  export { presignUrl } from './presignUrl';
9
9
  export { TOKEN_QUERY_PARAM } from './constants';
10
+ export { getHashedPayload } from './utils/getHashedPayload';
@@ -5,3 +5,5 @@
5
5
  export { signRequest } from './signRequest';
6
6
  export { presignUrl } from './presignUrl';
7
7
  export { TOKEN_QUERY_PARAM } from './constants';
8
+ export { getHashedPayload } from './utils/getHashedPayload';
9
+ export type { SignRequestOptions, PresignUrlOptions } from './types';
@@ -8,6 +8,16 @@ export interface SignRequestOptions {
8
8
  signingDate?: Date;
9
9
  signingRegion: string;
10
10
  signingService: string;
11
+
12
+ /**
13
+ * Whether to uri encode the path as part of canonical uri. It's used for S3 only where the pathname
14
+ * is already uri encoded, and the signing process is not expected to uri encode it again.
15
+ *
16
+ * @default true
17
+ *
18
+ * @see https://github.com/aws/aws-sdk-js-v3/blob/9ba012dfa3a3429aa2db0f90b3b0b3a7a31f9bc3/packages/signature-v4/src/SignatureV4.ts#L76-L83
19
+ */
20
+ uriEscapePath?: boolean;
11
21
  }
12
22
 
13
23
  export interface PresignUrlOptions extends SignRequestOptions {
@@ -26,6 +36,9 @@ export interface FormattedDates {
26
36
  export interface SigningValues
27
37
  extends Credentials,
28
38
  FormattedDates,
29
- Pick<SignRequestOptions, 'signingRegion' | 'signingService'> {
39
+ Pick<
40
+ SignRequestOptions,
41
+ 'signingRegion' | 'signingService' | 'uriEscapePath'
42
+ > {
30
43
  credentialScope: string;
31
44
  }
@@ -12,6 +12,8 @@ import { getSignedHeaders } from './getSignedHeaders';
12
12
  * Returns a canonical request.
13
13
  *
14
14
  * @param request `HttpRequest` from which to create the canonical request from.
15
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
16
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
15
17
  * @returns String created by by concatenating the following strings, separated by newline characters:
16
18
  * - HTTPMethod
17
19
  * - CanonicalUri
@@ -22,15 +24,13 @@ import { getSignedHeaders } from './getSignedHeaders';
22
24
  *
23
25
  * @internal
24
26
  */
25
- export const getCanonicalRequest = ({
26
- body,
27
- headers,
28
- method,
29
- url,
30
- }: HttpRequest): string =>
27
+ export const getCanonicalRequest = (
28
+ { body, headers, method, url }: HttpRequest,
29
+ uriEscapePath = true
30
+ ): string =>
31
31
  [
32
32
  method,
33
- getCanonicalUri(url.pathname),
33
+ getCanonicalUri(url.pathname, uriEscapePath),
34
34
  getCanonicalQueryString(url.searchParams),
35
35
  getCanonicalHeaders(headers),
36
36
  getSignedHeaders(headers),
@@ -5,10 +5,19 @@
5
5
  * Returns a canonical uri.
6
6
  *
7
7
  * @param pathname `pathname` from request url.
8
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
9
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
8
10
  * @returns URI-encoded version of the absolute path component URL (everything between the host and the question mark
9
11
  * character (?) that starts the query string parameters). If the absolute path is empty, a forward slash character (/).
10
12
  *
11
13
  * @internal
12
14
  */
13
- export const getCanonicalUri = (pathname: string): string =>
14
- pathname ? encodeURIComponent(pathname).replace(/%2F/g, '/') : '/';
15
+ export const getCanonicalUri = (
16
+ pathname: string,
17
+ uriEscapePath = true
18
+ ): string =>
19
+ pathname
20
+ ? uriEscapePath
21
+ ? encodeURIComponent(pathname).replace(/%2F/g, '/')
22
+ : pathname
23
+ : '/';
@@ -27,10 +27,11 @@ export const getSignature = (
27
27
  shortDate,
28
28
  signingRegion,
29
29
  signingService,
30
+ uriEscapePath,
30
31
  }: SigningValues
31
32
  ): string => {
32
33
  // step 1: create a canonical request
33
- const canonicalRequest = getCanonicalRequest(request);
34
+ const canonicalRequest = getCanonicalRequest(request, uriEscapePath);
34
35
 
35
36
  // step 2: create a hash of the canonical request
36
37
  const hashedRequest = getHashedDataAsHex(null, canonicalRequest);
@@ -19,6 +19,7 @@ export const getSigningValues = ({
19
19
  signingDate = new Date(),
20
20
  signingRegion,
21
21
  signingService,
22
+ uriEscapePath = true,
22
23
  }: SignRequestOptions): SigningValues => {
23
24
  // get properties from credentials
24
25
  const { accessKeyId, secretAccessKey, sessionToken } = credentials;
@@ -39,5 +40,6 @@ export const getSigningValues = ({
39
40
  shortDate,
40
41
  signingRegion,
41
42
  signingService,
43
+ uriEscapePath,
42
44
  };
43
45
  };
@@ -1,8 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ResponseMetadata } from '@aws-sdk/types';
5
- import { isMetadataBearer } from '../middleware/retry/middleware';
4
+ import { ResponseMetadata, MetadataBearer } from '@aws-sdk/types';
6
5
  import { HttpResponse } from '../types/http';
7
6
 
8
7
  export const parseMetadata = (response: HttpResponse): ResponseMetadata => {
@@ -18,3 +17,6 @@ export const parseMetadata = (response: HttpResponse): ResponseMetadata => {
18
17
  cfId: headers['x-amz-cf-id'],
19
18
  };
20
19
  };
20
+
21
+ const isMetadataBearer = (response: unknown): response is MetadataBearer =>
22
+ typeof response?.['$metadata'] === 'object';