@aws-amplify/storage 5.6.4-graphql-api-functional-options.1 → 5.6.4-unstable.28bc873.6

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 (252) hide show
  1. package/lib/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
  2. package/lib/AwsClients/S3/abortMultipartUpload.js +85 -0
  3. package/lib/AwsClients/S3/base.d.ts +54 -0
  4. package/lib/AwsClients/S3/base.js +75 -0
  5. package/lib/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
  6. package/lib/AwsClients/S3/completeMultipartUpload.js +162 -0
  7. package/lib/AwsClients/S3/copyObject.d.ts +24 -0
  8. package/lib/AwsClients/S3/copyObject.js +98 -0
  9. package/lib/AwsClients/S3/createMultipartUpload.d.ts +21 -0
  10. package/lib/AwsClients/S3/createMultipartUpload.js +95 -0
  11. package/lib/AwsClients/S3/deleteObject.d.ts +20 -0
  12. package/lib/AwsClients/S3/deleteObject.js +86 -0
  13. package/lib/AwsClients/S3/getObject.d.ts +27 -0
  14. package/lib/AwsClients/S3/getObject.js +216 -0
  15. package/lib/AwsClients/S3/headObject.d.ts +20 -0
  16. package/lib/AwsClients/S3/headObject.js +96 -0
  17. package/lib/AwsClients/S3/index.d.ts +13 -0
  18. package/lib/AwsClients/S3/index.js +30 -0
  19. package/lib/AwsClients/S3/index.native.d.ts +14 -0
  20. package/lib/AwsClients/S3/index.native.js +31 -0
  21. package/lib/AwsClients/S3/listObjectsV2.d.ts +20 -0
  22. package/lib/AwsClients/S3/listObjectsV2.js +146 -0
  23. package/lib/AwsClients/S3/listParts.d.ts +20 -0
  24. package/lib/AwsClients/S3/listParts.js +110 -0
  25. package/lib/AwsClients/S3/putObject.d.ts +23 -0
  26. package/lib/AwsClients/S3/putObject.js +93 -0
  27. package/lib/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
  28. package/lib/AwsClients/S3/runtime/base64/index.browser.js +20 -0
  29. package/lib/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
  30. package/lib/AwsClients/S3/runtime/base64/index.native.js +17 -0
  31. package/lib/AwsClients/S3/runtime/constants.d.ts +9 -0
  32. package/lib/AwsClients/S3/runtime/constants.js +14 -0
  33. package/lib/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
  34. package/lib/AwsClients/S3/runtime/contentSha256middleware.js +70 -0
  35. package/lib/AwsClients/S3/runtime/index.browser.d.ts +5 -0
  36. package/lib/AwsClients/S3/runtime/index.browser.js +20 -0
  37. package/lib/AwsClients/S3/runtime/index.d.ts +5 -0
  38. package/lib/AwsClients/S3/runtime/index.js +21 -0
  39. package/lib/AwsClients/S3/runtime/index.native.d.ts +5 -0
  40. package/lib/AwsClients/S3/runtime/index.native.js +20 -0
  41. package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
  42. package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.js +15 -0
  43. package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
  44. package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.js +21 -0
  45. package/lib/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
  46. package/lib/AwsClients/S3/runtime/xhrTransferHandler.js +201 -0
  47. package/lib/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
  48. package/lib/AwsClients/S3/runtime/xmlParser/dom.js +92 -0
  49. package/lib/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
  50. package/lib/AwsClients/S3/runtime/xmlParser/pureJs.js +57 -0
  51. package/lib/AwsClients/S3/types.d.ts +2857 -0
  52. package/lib/AwsClients/S3/types.js +4 -0
  53. package/lib/AwsClients/S3/uploadPart.d.ts +20 -0
  54. package/lib/AwsClients/S3/uploadPart.js +96 -0
  55. package/lib/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
  56. package/lib/AwsClients/S3/utils/deserializeHelpers.js +153 -0
  57. package/lib/AwsClients/S3/utils/index.d.ts +5 -0
  58. package/lib/AwsClients/S3/utils/index.js +30 -0
  59. package/lib/AwsClients/S3/utils/parsePayload.d.ts +3 -0
  60. package/lib/AwsClients/S3/utils/parsePayload.js +96 -0
  61. package/lib/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
  62. package/lib/AwsClients/S3/utils/serializeHelpers.js +183 -0
  63. package/lib/Storage.d.ts +5 -5
  64. package/lib/Storage.js +60 -31
  65. package/lib/common/S3ClientUtils.d.ts +24 -15
  66. package/lib/common/S3ClientUtils.js +83 -95
  67. package/lib/common/StorageConstants.d.ts +0 -1
  68. package/lib/common/StorageConstants.js +3 -2
  69. package/lib/common/StorageErrorStrings.js +3 -1
  70. package/lib/common/StorageUtils.js +12 -6
  71. package/lib/index.js +19 -4
  72. package/lib/providers/AWSS3Provider.d.ts +4 -8
  73. package/lib/providers/AWSS3Provider.js +210 -139
  74. package/lib/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
  75. package/lib/providers/AWSS3ProviderManagedUpload.js +184 -98
  76. package/lib/providers/AWSS3UploadTask.d.ts +8 -8
  77. package/lib/providers/AWSS3UploadTask.js +226 -129
  78. package/lib/providers/index.js +4 -2
  79. package/lib/tsconfig.tsbuildinfo +1 -0
  80. package/lib/types/AWSS3Provider.d.ts +62 -62
  81. package/lib/types/AWSS3Provider.js +0 -1
  82. package/lib/types/Provider.d.ts +1 -1
  83. package/lib/types/Provider.js +2 -1
  84. package/lib/types/Storage.d.ts +23 -23
  85. package/lib/types/Storage.js +0 -1
  86. package/lib/types/index.js +17 -1
  87. package/lib-esm/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
  88. package/lib-esm/AwsClients/S3/abortMultipartUpload.js +82 -0
  89. package/lib-esm/AwsClients/S3/base.d.ts +54 -0
  90. package/lib-esm/AwsClients/S3/base.js +71 -0
  91. package/lib-esm/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
  92. package/lib-esm/AwsClients/S3/completeMultipartUpload.js +159 -0
  93. package/lib-esm/AwsClients/S3/copyObject.d.ts +24 -0
  94. package/lib-esm/AwsClients/S3/copyObject.js +95 -0
  95. package/lib-esm/AwsClients/S3/createMultipartUpload.d.ts +21 -0
  96. package/lib-esm/AwsClients/S3/createMultipartUpload.js +92 -0
  97. package/lib-esm/AwsClients/S3/deleteObject.d.ts +20 -0
  98. package/lib-esm/AwsClients/S3/deleteObject.js +83 -0
  99. package/lib-esm/AwsClients/S3/getObject.d.ts +27 -0
  100. package/lib-esm/AwsClients/S3/getObject.js +212 -0
  101. package/lib-esm/AwsClients/S3/headObject.d.ts +20 -0
  102. package/lib-esm/AwsClients/S3/headObject.js +93 -0
  103. package/lib-esm/AwsClients/S3/index.d.ts +13 -0
  104. package/lib-esm/AwsClients/S3/index.js +14 -0
  105. package/lib-esm/AwsClients/S3/index.native.d.ts +14 -0
  106. package/lib-esm/AwsClients/S3/index.native.js +15 -0
  107. package/lib-esm/AwsClients/S3/listObjectsV2.d.ts +20 -0
  108. package/lib-esm/AwsClients/S3/listObjectsV2.js +143 -0
  109. package/lib-esm/AwsClients/S3/listParts.d.ts +20 -0
  110. package/lib-esm/AwsClients/S3/listParts.js +107 -0
  111. package/lib-esm/AwsClients/S3/putObject.d.ts +23 -0
  112. package/lib-esm/AwsClients/S3/putObject.js +90 -0
  113. package/lib-esm/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
  114. package/lib-esm/AwsClients/S3/runtime/base64/index.browser.js +15 -0
  115. package/lib-esm/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
  116. package/lib-esm/AwsClients/S3/runtime/base64/index.native.js +12 -0
  117. package/lib-esm/AwsClients/S3/runtime/constants.d.ts +9 -0
  118. package/lib-esm/AwsClients/S3/runtime/constants.js +11 -0
  119. package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
  120. package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.js +66 -0
  121. package/lib-esm/AwsClients/S3/runtime/index.browser.d.ts +5 -0
  122. package/lib-esm/AwsClients/S3/runtime/index.browser.js +8 -0
  123. package/lib-esm/AwsClients/S3/runtime/index.d.ts +5 -0
  124. package/lib-esm/AwsClients/S3/runtime/index.js +9 -0
  125. package/lib-esm/AwsClients/S3/runtime/index.native.d.ts +5 -0
  126. package/lib-esm/AwsClients/S3/runtime/index.native.js +8 -0
  127. package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
  128. package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.js +12 -0
  129. package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
  130. package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.js +18 -0
  131. package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
  132. package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.js +196 -0
  133. package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
  134. package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.js +89 -0
  135. package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
  136. package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.js +54 -0
  137. package/lib-esm/AwsClients/S3/types.d.ts +2857 -0
  138. package/lib-esm/AwsClients/S3/types.js +3 -0
  139. package/lib-esm/AwsClients/S3/uploadPart.d.ts +20 -0
  140. package/lib-esm/AwsClients/S3/uploadPart.js +93 -0
  141. package/lib-esm/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
  142. package/lib-esm/AwsClients/S3/utils/deserializeHelpers.js +144 -0
  143. package/lib-esm/AwsClients/S3/utils/index.d.ts +5 -0
  144. package/lib-esm/AwsClients/S3/utils/index.js +7 -0
  145. package/lib-esm/AwsClients/S3/utils/parsePayload.d.ts +3 -0
  146. package/lib-esm/AwsClients/S3/utils/parsePayload.js +91 -0
  147. package/lib-esm/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
  148. package/lib-esm/AwsClients/S3/utils/serializeHelpers.js +176 -0
  149. package/lib-esm/Storage.d.ts +5 -5
  150. package/lib-esm/Storage.js +53 -25
  151. package/lib-esm/common/S3ClientUtils.d.ts +24 -15
  152. package/lib-esm/common/S3ClientUtils.js +76 -93
  153. package/lib-esm/common/StorageConstants.d.ts +0 -1
  154. package/lib-esm/common/StorageConstants.js +2 -2
  155. package/lib-esm/common/StorageErrorStrings.js +2 -1
  156. package/lib-esm/common/StorageUtils.js +2 -1
  157. package/lib-esm/index.js +1 -1
  158. package/lib-esm/providers/AWSS3Provider.d.ts +4 -8
  159. package/lib-esm/providers/AWSS3Provider.js +162 -115
  160. package/lib-esm/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
  161. package/lib-esm/providers/AWSS3ProviderManagedUpload.js +172 -87
  162. package/lib-esm/providers/AWSS3UploadTask.d.ts +8 -8
  163. package/lib-esm/providers/AWSS3UploadTask.js +202 -106
  164. package/lib-esm/providers/index.js +2 -1
  165. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  166. package/lib-esm/types/AWSS3Provider.d.ts +62 -62
  167. package/lib-esm/types/AWSS3Provider.js +1 -1
  168. package/lib-esm/types/Provider.d.ts +1 -1
  169. package/lib-esm/types/Provider.js +3 -1
  170. package/lib-esm/types/Storage.d.ts +23 -23
  171. package/lib-esm/types/Storage.js +1 -1
  172. package/lib-esm/types/index.js +3 -1
  173. package/package.json +21 -26
  174. package/src/AwsClients/S3/abortMultipartUpload.ts +62 -0
  175. package/src/AwsClients/S3/base.ts +109 -0
  176. package/src/AwsClients/S3/completeMultipartUpload.ts +154 -0
  177. package/src/AwsClients/S3/copyObject.ts +90 -0
  178. package/src/AwsClients/S3/createMultipartUpload.ts +75 -0
  179. package/src/AwsClients/S3/deleteObject.ts +69 -0
  180. package/src/AwsClients/S3/getObject.ts +173 -0
  181. package/src/AwsClients/S3/headObject.ts +91 -0
  182. package/src/AwsClients/S3/index.native.ts +42 -0
  183. package/src/AwsClients/S3/index.ts +41 -0
  184. package/src/AwsClients/S3/listObjectsV2.ts +130 -0
  185. package/src/AwsClients/S3/listParts.ts +97 -0
  186. package/src/AwsClients/S3/putObject.ts +94 -0
  187. package/src/AwsClients/S3/runtime/base64/index.browser.ts +21 -0
  188. package/src/AwsClients/S3/runtime/base64/index.native.ts +16 -0
  189. package/src/AwsClients/S3/runtime/constants.ts +16 -0
  190. package/src/AwsClients/S3/runtime/contentSha256middleware.ts +29 -0
  191. package/src/AwsClients/S3/runtime/index.browser.ts +14 -0
  192. package/src/AwsClients/S3/runtime/index.native.ts +14 -0
  193. package/src/AwsClients/S3/runtime/index.ts +15 -0
  194. package/src/AwsClients/S3/runtime/s3TransferHandler/fetch.ts +23 -0
  195. package/src/AwsClients/S3/runtime/s3TransferHandler/xhr.ts +35 -0
  196. package/src/AwsClients/S3/runtime/xhrTransferHandler.ts +254 -0
  197. package/src/AwsClients/S3/runtime/xmlParser/dom.ts +92 -0
  198. package/src/AwsClients/S3/runtime/xmlParser/pureJs.ts +55 -0
  199. package/src/AwsClients/S3/types.ts +2877 -0
  200. package/src/AwsClients/S3/uploadPart.ts +83 -0
  201. package/src/AwsClients/S3/utils/deserializeHelpers.ts +136 -0
  202. package/src/AwsClients/S3/utils/index.ts +27 -0
  203. package/src/AwsClients/S3/utils/parsePayload.ts +45 -0
  204. package/src/AwsClients/S3/utils/serializeHelpers.ts +112 -0
  205. package/src/Storage.ts +30 -27
  206. package/src/common/S3ClientUtils.ts +57 -113
  207. package/src/common/StorageConstants.ts +2 -2
  208. package/src/common/StorageErrorStrings.ts +2 -0
  209. package/src/common/StorageUtils.ts +2 -0
  210. package/src/providers/AWSS3Provider.ts +80 -100
  211. package/src/providers/AWSS3ProviderManagedUpload.ts +56 -63
  212. package/src/providers/AWSS3UploadTask.ts +86 -87
  213. package/src/providers/index.ts +2 -0
  214. package/src/types/AWSS3Provider.ts +55 -49
  215. package/src/types/Provider.ts +7 -2
  216. package/lib/.tsbuildinfo +0 -3
  217. package/lib/Storage.js.map +0 -1
  218. package/lib/common/S3ClientUtils.js.map +0 -1
  219. package/lib/common/StorageConstants.js.map +0 -1
  220. package/lib/common/StorageErrorStrings.js.map +0 -1
  221. package/lib/common/StorageUtils.js.map +0 -1
  222. package/lib/index.js.map +0 -1
  223. package/lib/providers/AWSS3Provider.js.map +0 -1
  224. package/lib/providers/AWSS3ProviderManagedUpload.js.map +0 -1
  225. package/lib/providers/AWSS3UploadTask.js.map +0 -1
  226. package/lib/providers/axios-http-handler.d.ts +0 -40
  227. package/lib/providers/axios-http-handler.js +0 -193
  228. package/lib/providers/axios-http-handler.js.map +0 -1
  229. package/lib/providers/index.js.map +0 -1
  230. package/lib/types/AWSS3Provider.js.map +0 -1
  231. package/lib/types/Provider.js.map +0 -1
  232. package/lib/types/Storage.js.map +0 -1
  233. package/lib/types/index.js.map +0 -1
  234. package/lib-esm/.tsbuildinfo +0 -3
  235. package/lib-esm/Storage.js.map +0 -1
  236. package/lib-esm/common/S3ClientUtils.js.map +0 -1
  237. package/lib-esm/common/StorageConstants.js.map +0 -1
  238. package/lib-esm/common/StorageErrorStrings.js.map +0 -1
  239. package/lib-esm/common/StorageUtils.js.map +0 -1
  240. package/lib-esm/index.js.map +0 -1
  241. package/lib-esm/providers/AWSS3Provider.js.map +0 -1
  242. package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +0 -1
  243. package/lib-esm/providers/AWSS3UploadTask.js.map +0 -1
  244. package/lib-esm/providers/axios-http-handler.d.ts +0 -40
  245. package/lib-esm/providers/axios-http-handler.js +0 -191
  246. package/lib-esm/providers/axios-http-handler.js.map +0 -1
  247. package/lib-esm/providers/index.js.map +0 -1
  248. package/lib-esm/types/AWSS3Provider.js.map +0 -1
  249. package/lib-esm/types/Provider.js.map +0 -1
  250. package/lib-esm/types/Storage.js.map +0 -1
  251. package/lib-esm/types/index.js.map +0 -1
  252. package/src/providers/axios-http-handler.ts +0 -242
@@ -1,32 +1,22 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import {
2
4
  Category,
3
5
  Credentials,
4
- CustomUserAgentDetails,
5
6
  ICredentials,
6
7
  Logger,
7
8
  StorageAction,
8
- getAmplifyUserAgentObject,
9
+ getAmplifyUserAgent,
9
10
  } from '@aws-amplify/core';
11
+ import type { Credentials as AwsCredentials } from '@aws-sdk/types';
12
+ import type { EventEmitter } from 'events';
13
+
10
14
  import { StorageAccessLevel, CustomPrefix } from '../types';
11
- import {
12
- InitializeMiddleware,
13
- InitializeHandlerOptions,
14
- FinalizeRequestHandlerOptions,
15
- FinalizeRequestMiddleware,
16
- HandlerExecutionContext,
17
- } from '@aws-sdk/types';
18
- import { S3ClientConfig, S3Client } from '@aws-sdk/client-s3';
19
- import { CancelTokenSource } from 'axios';
20
- import * as events from 'events';
21
- import { AxiosHttpHandler } from '../providers/axios-http-handler';
22
- import {
23
- localTestingStorageEndpoint,
24
- SET_CONTENT_LENGTH_HEADER,
25
- } from './StorageConstants';
15
+ import { localTestingStorageEndpoint } from './StorageConstants';
26
16
 
27
17
  const logger = new Logger('S3ClientUtils');
28
18
  // placeholder credentials in order to satisfy type requirement, always results in 403 when used
29
- const INVALID_CRED = { accessKeyId: '', secretAccessKey: '' };
19
+ const INVALID_CRED = { accessKeyId: '', secretAccessKey: '' } as ICredentials;
30
20
 
31
21
  export const getPrefix = (config: {
32
22
  credentials: ICredentials;
@@ -65,57 +55,6 @@ export const getPrefix = (config: {
65
55
  }
66
56
  };
67
57
 
68
- export const createPrefixMiddleware =
69
- (opt: Record<string, any>, key: string): InitializeMiddleware<any, any> =>
70
- (next, _context) =>
71
- async args => {
72
- const credentials = await Credentials.get();
73
- const cred = Credentials.shear(credentials);
74
- const prefix = getPrefix({ ...opt, credentials: cred });
75
- const clonedInput = Object.assign({}, args.input);
76
- if (Object.prototype.hasOwnProperty.call(args.input, 'Key')) {
77
- clonedInput.Key = prefix + key;
78
- args.input = clonedInput;
79
- } else if (Object.prototype.hasOwnProperty.call(args.input, 'Prefix')) {
80
- clonedInput.Prefix = prefix + key;
81
- args.input = clonedInput;
82
- }
83
- const result = next(args);
84
- return result;
85
- };
86
-
87
- const isTimeSkewedError = (err: any): boolean =>
88
- err.ServerTime &&
89
- typeof err.Code === 'string' &&
90
- err.Code === 'RequestTimeTooSkewed';
91
-
92
- // we want to take the S3Client config in parameter so we can modify it's systemClockOffset
93
- export const autoAdjustClockskewMiddleware =
94
- (config: S3ClientConfig): FinalizeRequestMiddleware<any, any> =>
95
- (next, _context: HandlerExecutionContext) =>
96
- async args => {
97
- try {
98
- return await next(args);
99
- } catch (err) {
100
- if (isTimeSkewedError(err)) {
101
- const serverDate = new Date(err.ServerTime);
102
- config.systemClockOffset = serverDate.getTime() - Date.now();
103
- }
104
- throw err;
105
- }
106
- };
107
-
108
- export const autoAdjustClockskewMiddlewareOptions: FinalizeRequestHandlerOptions =
109
- {
110
- step: 'finalizeRequest',
111
- name: 'autoAdjustClockskewMiddleware',
112
- };
113
-
114
- export const prefixMiddlewareOptions: InitializeHandlerOptions = {
115
- step: 'initialize',
116
- name: 'addPrefixMiddleware',
117
- };
118
-
119
58
  export const credentialsProvider = async () => {
120
59
  try {
121
60
  const credentials = await Credentials.get();
@@ -129,56 +68,61 @@ export const credentialsProvider = async () => {
129
68
  }
130
69
  };
131
70
 
132
- export const createS3Client = (
133
- config: {
134
- region?: string;
135
- cancelTokenSource?: CancelTokenSource;
136
- dangerouslyConnectToHttpEndpointForTesting?: boolean;
137
- useAccelerateEndpoint?: boolean;
138
- },
139
- storageAction: StorageAction,
140
- emitter?: events.EventEmitter
141
- ): S3Client => {
142
- const {
143
- region,
144
- cancelTokenSource,
145
- dangerouslyConnectToHttpEndpointForTesting,
146
- useAccelerateEndpoint,
147
- } = config;
148
- let localTestingConfig = {};
149
-
150
- if (dangerouslyConnectToHttpEndpointForTesting) {
151
- localTestingConfig = {
152
- endpoint: localTestingStorageEndpoint,
153
- tls: false,
154
- bucketEndpoint: false,
155
- forcePathStyle: true,
156
- };
71
+ interface S3InputConfig {
72
+ credentials?: AwsCredentials;
73
+ region?: string;
74
+ useAccelerateEndpoint?: boolean;
75
+ abortSignal?: AbortSignal;
76
+ emitter?: EventEmitter;
77
+ storageAction: StorageAction;
78
+ dangerouslyConnectToHttpEndpointForTesting?: boolean;
79
+ }
80
+
81
+ export interface S3ResolvedConfig
82
+ extends Omit<S3InputConfig, 'region' | 'credentials'> {
83
+ region: string;
84
+ userAgentValue?: string;
85
+ credentials: () => Promise<AwsCredentials>;
86
+ customEndpoint?: string;
87
+ forcePathStyle?: boolean;
88
+ }
89
+
90
+ /**
91
+ * A function that persists the s3 configs, so we don't need to
92
+ * assign each config parameter for every s3 API call.
93
+ *
94
+ * @inernal
95
+ */
96
+ export const loadS3Config = (config: S3InputConfig): S3ResolvedConfig => {
97
+ if (!config.region) {
98
+ // Same error thrown by aws-sdk
99
+ throw new Error('Region is missing.');
157
100
  }
158
-
159
- const s3client = new S3Client({
160
- region,
161
- // Using provider instead of a static credentials, so that if an upload task was in progress, but credentials gets
162
- // changed or invalidated (e.g user signed out), the subsequent requests will fail.
163
- credentials: credentialsProvider,
164
- customUserAgent: getAmplifyUserAgentObject({
101
+ return {
102
+ ...config,
103
+ region: config.region,
104
+ credentials: config.credentials
105
+ ? () => Promise.resolve(config.credentials!)
106
+ : credentialsProvider,
107
+ userAgentValue: getAmplifyUserAgent({
165
108
  category: Category.Storage,
166
- action: storageAction,
109
+ action: config.storageAction,
167
110
  }),
168
- ...localTestingConfig,
169
- requestHandler: new AxiosHttpHandler({}, emitter, cancelTokenSource),
170
- useAccelerateEndpoint,
171
- });
172
- s3client.middlewareStack.remove(SET_CONTENT_LENGTH_HEADER);
173
- return s3client;
111
+ ...(config.dangerouslyConnectToHttpEndpointForTesting
112
+ ? {
113
+ customEndpoint: localTestingStorageEndpoint,
114
+ forcePathStyle: true,
115
+ }
116
+ : {}),
117
+ };
174
118
  };
175
119
 
176
- const MB = 1024 * 1024;
177
- const GB = 1024 * MB;
178
- const TB = 1024 * GB;
120
+ const MiB = 1024 * 1024;
121
+ const GiB = 1024 * MiB;
122
+ const TiB = 1024 * GiB;
179
123
 
180
- export const DEFAULT_PART_SIZE = 5 * MB;
181
- export const MAX_OBJECT_SIZE = 5 * TB;
124
+ export const DEFAULT_PART_SIZE = 5 * MiB;
125
+ export const MAX_OBJECT_SIZE = 5 * TiB;
182
126
  export const MAX_PARTS_COUNT = 10000;
183
127
  export const DEFAULT_QUEUE_SIZE = 4;
184
128
 
@@ -1,11 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  export const AMPLIFY_SYMBOL = (
2
4
  typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
3
5
  ? Symbol.for('amplify_default')
4
6
  : '@@amplify_default'
5
7
  ) as Symbol;
6
8
 
7
- export const SET_CONTENT_LENGTH_HEADER = 'contentLengthMiddleware';
8
-
9
9
  export const localTestingStorageEndpoint = 'http://localhost:20005';
10
10
 
11
11
  export const UPLOADS_STORAGE_KEY = '__uploadInProgress';
@@ -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 enum StorageErrorStrings {
2
4
  NO_CREDENTIALS = 'No credentials',
3
5
  NO_SRC_KEY = 'source param should be an object with the property "key" with value of type string',
@@ -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 { Hub } from '@aws-amplify/core';
2
4
  import { AMPLIFY_SYMBOL } from './StorageConstants';
3
5
 
@@ -10,27 +10,25 @@ import {
10
10
  StorageAction,
11
11
  } from '@aws-amplify/core';
12
12
  import {
13
- S3Client,
14
- GetObjectCommand,
15
- DeleteObjectCommand,
16
- ListObjectsV2Command,
17
- GetObjectCommandOutput,
18
- DeleteObjectCommandInput,
19
- CopyObjectCommandInput,
20
- CopyObjectCommand,
21
- PutObjectCommandInput,
22
- GetObjectCommandInput,
23
- ListObjectsV2Request,
24
- HeadObjectCommand,
25
- HeadObjectCommandInput,
26
- } from '@aws-sdk/client-s3';
27
- import { formatUrl } from '@aws-sdk/util-format-url';
28
- import { createRequest } from '@aws-sdk/util-create-request';
29
- import { S3RequestPresigner } from '@aws-sdk/s3-request-presigner';
13
+ copyObject,
14
+ CopyObjectInput,
15
+ getObject,
16
+ GetObjectInput,
17
+ GetObjectOutput,
18
+ getPresignedGetObjectUrl,
19
+ PutObjectInput,
20
+ headObject,
21
+ DeleteObjectInput,
22
+ deleteObject,
23
+ ListObjectsV2Input,
24
+ listObjectsV2,
25
+ SERVICE_NAME as S3_SERVICE_NAME,
26
+ HeadObjectInput,
27
+ } from '../AwsClients/S3';
30
28
  import {
31
29
  SEND_DOWNLOAD_PROGRESS_EVENT,
32
30
  SEND_UPLOAD_PROGRESS_EVENT,
33
- } from './axios-http-handler';
31
+ } from '../AwsClients/S3/utils';
34
32
  import {
35
33
  StorageOptions,
36
34
  StorageProvider,
@@ -51,24 +49,20 @@ import {
51
49
  UploadTask,
52
50
  S3ClientOptions,
53
51
  S3ProviderListOutput,
54
- S3ProviderGetPropertiesOutput,
55
52
  S3ProviderGetPropertiesConfig,
53
+ S3ProviderGetPropertiesOutput,
56
54
  } from '../types';
57
55
  import { StorageErrorStrings } from '../common/StorageErrorStrings';
58
56
  import { dispatchStorageEvent } from '../common/StorageUtils';
59
57
  import {
60
- createPrefixMiddleware,
61
- prefixMiddlewareOptions,
62
58
  getPrefix,
63
- autoAdjustClockskewMiddleware,
64
- autoAdjustClockskewMiddlewareOptions,
65
- createS3Client,
59
+ S3ResolvedConfig,
60
+ loadS3Config,
66
61
  } from '../common/S3ClientUtils';
67
62
  import { AWSS3ProviderManagedUpload } from './AWSS3ProviderManagedUpload';
68
63
  import { AWSS3UploadTask, TaskEvents } from './AWSS3UploadTask';
69
64
  import { UPLOADS_STORAGE_KEY } from '../common/StorageConstants';
70
65
  import * as events from 'events';
71
- import { CancelTokenSource } from 'axios';
72
66
 
73
67
  const logger = new Logger('AWSS3Provider');
74
68
 
@@ -81,8 +75,8 @@ interface AddTaskInput {
81
75
  bucket: string;
82
76
  emitter: events.EventEmitter;
83
77
  key: string;
84
- s3Client: S3Client;
85
- params?: PutObjectCommandInput;
78
+ s3Config: S3ResolvedConfig;
79
+ params?: PutObjectInput;
86
80
  }
87
81
 
88
82
  /**
@@ -144,7 +138,7 @@ export class AWSS3Provider implements StorageProvider {
144
138
  addTaskInput: AddTaskInput,
145
139
  config: S3ProviderPutConfig & ResumableUploadConfig
146
140
  ): UploadTask {
147
- const { s3Client, emitter, key, file, params } = addTaskInput;
141
+ const { s3Config, emitter, key, file, params } = addTaskInput;
148
142
  const {
149
143
  progressCallback,
150
144
  completeCallback,
@@ -200,16 +194,17 @@ export class AWSS3Provider implements StorageProvider {
200
194
  const cred = Credentials.shear(credentials);
201
195
  return getPrefix({
202
196
  ...config,
197
+ level: addTaskInput.accessLevel,
203
198
  credentials: cred,
204
199
  });
205
200
  }
206
201
  );
207
202
 
208
203
  const task = new AWSS3UploadTask({
209
- s3Client,
204
+ s3Config,
210
205
  file,
211
206
  emitter,
212
- level: config.level,
207
+ level: addTaskInput.accessLevel,
213
208
  storage: this._storage,
214
209
  params,
215
210
  prefixPromise,
@@ -288,7 +283,7 @@ export class AWSS3Provider implements StorageProvider {
288
283
  const finalDestKey = `${destPrefix}${destKey}`;
289
284
  logger.debug(`copying ${finalSrcKey} to ${finalDestKey}`);
290
285
 
291
- const params: CopyObjectCommandInput = {
286
+ const params: CopyObjectInput = {
292
287
  Bucket: bucket,
293
288
  CopySource: finalSrcKey,
294
289
  Key: finalDestKey,
@@ -315,9 +310,14 @@ export class AWSS3Provider implements StorageProvider {
315
310
  }
316
311
  if (acl) params.ACL = acl;
317
312
 
318
- const s3 = this._createNewS3Client(opt, StorageAction.Copy);
319
313
  try {
320
- await s3.send(new CopyObjectCommand(params));
314
+ await copyObject(
315
+ loadS3Config({
316
+ ...opt,
317
+ storageAction: StorageAction.Copy,
318
+ }),
319
+ params
320
+ );
321
321
  dispatchStorageEvent(
322
322
  track,
323
323
  'copy',
@@ -351,7 +351,7 @@ export class AWSS3Provider implements StorageProvider {
351
351
  *
352
352
  * @param {string} key - key of the object
353
353
  * @param {S3ProviderGetConfig} [config] - Optional configuration for the underlying S3 command
354
- * @return {Promise<string | GetObjectCommandOutput>} - A promise resolves to Amazon S3 presigned URL or the
354
+ * @return {Promise<string | GetObjectOutput>} - A promise resolves to Amazon S3 presigned URL or the
355
355
  * GetObjectCommandOutput if download is set to true on success
356
356
  */
357
357
  public async get<T extends S3ProviderGetConfig & StorageOptions>(
@@ -361,7 +361,7 @@ export class AWSS3Provider implements StorageProvider {
361
361
  public async get(
362
362
  key: string,
363
363
  config?: S3ProviderGetConfig
364
- ): Promise<string | GetObjectCommandOutput> {
364
+ ): Promise<string | GetObjectOutput> {
365
365
  const credentialsOK = await this._ensureCredentials();
366
366
  if (!credentialsOK || !this._isWithCredentials(this._config)) {
367
367
  throw new Error(StorageErrorStrings.NO_CREDENTIALS);
@@ -386,10 +386,14 @@ export class AWSS3Provider implements StorageProvider {
386
386
  const prefix = this._prefix(opt);
387
387
  const final_key = prefix + key;
388
388
  const emitter = new events.EventEmitter();
389
- const s3 = this._createNewS3Client(opt, StorageAction.Get, emitter);
389
+ const s3Config = loadS3Config({
390
+ ...opt,
391
+ emitter,
392
+ storageAction: StorageAction.Get,
393
+ });
390
394
  logger.debug('get ' + key + ' from ' + final_key);
391
395
 
392
- const params: GetObjectCommandInput = {
396
+ const params: GetObjectInput = {
393
397
  Bucket: bucket,
394
398
  Key: final_key,
395
399
  };
@@ -411,7 +415,6 @@ export class AWSS3Provider implements StorageProvider {
411
415
  }
412
416
 
413
417
  if (download === true) {
414
- const getObjectCommand = new GetObjectCommand(params);
415
418
  try {
416
419
  if (progressCallback) {
417
420
  if (typeof progressCallback === 'function') {
@@ -425,7 +428,7 @@ export class AWSS3Provider implements StorageProvider {
425
428
  );
426
429
  }
427
430
  }
428
- const response = await s3.send(getObjectCommand);
431
+ const response = await getObject(s3Config, params);
429
432
  emitter.removeAllListeners(SEND_DOWNLOAD_PROGRESS_EVENT);
430
433
  dispatchStorageEvent(
431
434
  track,
@@ -452,10 +455,8 @@ export class AWSS3Provider implements StorageProvider {
452
455
  }
453
456
  }
454
457
  if (validateObjectExistence) {
455
- const headObjectCommand = new HeadObjectCommand(params);
456
-
457
458
  try {
458
- await s3.send(headObjectCommand);
459
+ await headObject(s3Config, params);
459
460
  } catch (error) {
460
461
  if (error.$metadata?.httpStatusCode === 404) {
461
462
  dispatchStorageEvent(
@@ -473,13 +474,15 @@ export class AWSS3Provider implements StorageProvider {
473
474
  }
474
475
  }
475
476
  try {
476
- const signer = new S3RequestPresigner({ ...s3.config });
477
- const request = await createRequest(s3, new GetObjectCommand(params));
478
- // Default is 15 mins as defined in V2 AWS SDK
479
- const url = formatUrl(
480
- await signer.presign(request, {
481
- expiresIn: expires || DEFAULT_PRESIGN_EXPIRATION,
482
- })
477
+ const url = await getPresignedGetObjectUrl(
478
+ {
479
+ ...s3Config,
480
+ expiration: expires || DEFAULT_PRESIGN_EXPIRATION,
481
+ credentials: await s3Config.credentials(),
482
+ signingRegion: s3Config.region,
483
+ signingService: S3_SERVICE_NAME,
484
+ },
485
+ params
483
486
  );
484
487
  dispatchStorageEvent(
485
488
  track,
@@ -528,15 +531,13 @@ export class AWSS3Provider implements StorageProvider {
528
531
  } = opt;
529
532
  const prefix = this._prefix(opt);
530
533
  const final_key = prefix + key;
531
- const emitter = new events.EventEmitter();
532
- const s3 = this._createNewS3Client(
533
- opt,
534
- StorageAction.GetProperties,
535
- emitter
536
- );
537
534
  logger.debug(`getProperties ${key} from ${final_key}`);
538
535
 
539
- const params: HeadObjectCommandInput = {
536
+ const s3Config = loadS3Config({
537
+ ...opt,
538
+ storageAction: StorageAction.GetProperties,
539
+ });
540
+ const params: HeadObjectInput = {
540
541
  Bucket: bucket,
541
542
  Key: final_key,
542
543
  };
@@ -550,11 +551,9 @@ export class AWSS3Provider implements StorageProvider {
550
551
  if (SSECustomerKeyMD5) {
551
552
  params.SSECustomerKeyMD5 = SSECustomerKeyMD5;
552
553
  }
553
- // See: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/headobjectcommand.html
554
554
 
555
- const headObjectCommand = new HeadObjectCommand(params);
556
555
  try {
557
- const response = await s3.send(headObjectCommand);
556
+ const response = await headObject(s3Config, params);
558
557
  const getPropertiesResponse: S3ProviderGetPropertiesOutput = {
559
558
  contentLength: response.ContentLength,
560
559
  contentType: response.ContentType,
@@ -597,7 +596,7 @@ export class AWSS3Provider implements StorageProvider {
597
596
  */
598
597
  public put<T extends S3ProviderPutConfig>(
599
598
  key: string,
600
- object: PutObjectCommandInput['Body'],
599
+ object: PutObjectInput['Body'],
601
600
  config?: T
602
601
  ): S3ProviderPutOutput<T> {
603
602
  const opt = Object.assign({}, this._config, config);
@@ -621,7 +620,7 @@ export class AWSS3Provider implements StorageProvider {
621
620
  } = opt;
622
621
  const type = contentType ? contentType : 'binary/octet-stream';
623
622
 
624
- const params: PutObjectCommandInput = {
623
+ const params: PutObjectInput = {
625
624
  Bucket: bucket,
626
625
  Key: key,
627
626
  Body: object,
@@ -669,17 +668,14 @@ export class AWSS3Provider implements StorageProvider {
669
668
  }
670
669
 
671
670
  if (resumable === true) {
672
- const s3Client = this._createNewS3Client(opt, StorageAction.Put);
673
- // we are using aws sdk middleware to inject the prefix to key, this way we don't have to call
674
- // this._ensureCredentials() which allows us to make this function sync so we can return non-Promise like UploadTask
675
- s3Client.middlewareStack.add(
676
- createPrefixMiddleware(opt, key),
677
- prefixMiddlewareOptions
678
- );
671
+ const s3Config = loadS3Config({
672
+ ...opt,
673
+ storageAction: StorageAction.Put,
674
+ });
679
675
  const addTaskInput: AddTaskInput = {
680
676
  bucket,
681
677
  key,
682
- s3Client,
678
+ s3Config,
683
679
  file: object as Blob,
684
680
  emitter,
685
681
  accessLevel: level,
@@ -749,18 +745,19 @@ export class AWSS3Provider implements StorageProvider {
749
745
 
750
746
  const prefix = this._prefix(opt);
751
747
  const final_key = prefix + key;
752
- const s3 = this._createNewS3Client(opt, StorageAction.Remove);
753
748
  logger.debug('remove ' + key + ' from ' + final_key);
754
749
 
755
- const params: DeleteObjectCommandInput = {
750
+ const params: DeleteObjectInput = {
756
751
  Bucket: bucket,
757
752
  Key: final_key,
758
753
  };
759
754
 
760
- const deleteObjectCommand = new DeleteObjectCommand(params);
761
-
755
+ const s3Config = loadS3Config({
756
+ ...opt,
757
+ storageAction: StorageAction.Remove,
758
+ });
762
759
  try {
763
- const response = await s3.send(deleteObjectCommand);
760
+ const response = await deleteObject(s3Config, params);
764
761
  dispatchStorageEvent(
765
762
  track,
766
763
  'delete',
@@ -781,7 +778,7 @@ export class AWSS3Provider implements StorageProvider {
781
778
  }
782
779
  }
783
780
  private async _list(
784
- params: ListObjectsV2Request,
781
+ params: ListObjectsV2Input,
785
782
  opt: S3ClientOptions,
786
783
  prefix: string
787
784
  ): Promise<S3ProviderListOutput> {
@@ -789,9 +786,13 @@ export class AWSS3Provider implements StorageProvider {
789
786
  results: [],
790
787
  hasNextToken: false,
791
788
  };
792
- const s3 = this._createNewS3Client(opt, StorageAction.List);
793
- const listObjectsV2Command = new ListObjectsV2Command({ ...params });
794
- const response = await s3.send(listObjectsV2Command);
789
+ const response = await listObjectsV2(
790
+ loadS3Config({
791
+ ...opt,
792
+ storageAction: StorageAction.List,
793
+ }),
794
+ { ...params }
795
+ );
795
796
  if (response && response.Contents) {
796
797
  list.results = response.Contents.map(item => {
797
798
  return {
@@ -834,7 +835,7 @@ export class AWSS3Provider implements StorageProvider {
834
835
  };
835
836
  const MAX_PAGE_SIZE = 1000;
836
837
  let listResult: S3ProviderListOutput;
837
- const params: ListObjectsV2Request = {
838
+ const params: ListObjectsV2Input = {
838
839
  Bucket: bucket,
839
840
  Prefix: final_path,
840
841
  MaxKeys: MAX_PAGE_SIZE,
@@ -936,25 +937,4 @@ export class AWSS3Provider implements StorageProvider {
936
937
  return publicPath;
937
938
  }
938
939
  }
939
-
940
- /**
941
- * Creates an S3 client with new V3 aws sdk
942
- */
943
- private _createNewS3Client(
944
- config: {
945
- region?: string;
946
- cancelTokenSource?: CancelTokenSource;
947
- dangerouslyConnectToHttpEndpointForTesting?: boolean;
948
- useAccelerateEndpoint?: boolean;
949
- },
950
- storageAction: StorageAction,
951
- emitter?: events.EventEmitter
952
- ): S3Client {
953
- const s3client = createS3Client(config, storageAction, emitter);
954
- s3client.middlewareStack.add(
955
- autoAdjustClockskewMiddleware(s3client.config),
956
- autoAdjustClockskewMiddlewareOptions
957
- );
958
- return s3client;
959
- }
960
940
  }