@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
@@ -0,0 +1,83 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ Endpoint,
6
+ HttpRequest,
7
+ HttpResponse,
8
+ parseMetadata,
9
+ } from '@aws-amplify/core/internals/aws-client-utils';
10
+ import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
11
+
12
+ import { defaultConfig } from './base';
13
+ import type { UploadPartCommandInput, UploadPartCommandOutput } from './types';
14
+ import {
15
+ map,
16
+ parseXmlError,
17
+ s3TransferHandler,
18
+ serializeObjectSsecOptionsToHeaders,
19
+ serializePathnameObjectKey,
20
+ } from './utils';
21
+
22
+ // Content-length is ignored here because it's forbidden header
23
+ // and will be set by browser or fetch polyfill.
24
+ export type UploadPartInput = Pick<
25
+ UploadPartCommandInput,
26
+ | 'PartNumber'
27
+ | 'Body'
28
+ | 'UploadId'
29
+ | 'Bucket'
30
+ | 'Key'
31
+ | 'SSECustomerAlgorithm'
32
+ | 'SSECustomerKey'
33
+ // TODO(AllanZhengYP): remove in V6.
34
+ | 'SSECustomerKeyMD5'
35
+ >;
36
+
37
+ export type UploadPartOutput = Pick<
38
+ UploadPartCommandOutput,
39
+ '$metadata' | 'ETag'
40
+ >;
41
+
42
+ const uploadPartSerializer = async (
43
+ input: UploadPartInput,
44
+ endpoint: Endpoint
45
+ ): Promise<HttpRequest> => {
46
+ const headers = await serializeObjectSsecOptionsToHeaders(input);
47
+ headers['content-type'] = 'application/octet-stream';
48
+ const url = new URL(endpoint.url.toString());
49
+ url.pathname = serializePathnameObjectKey(url, input.Key);
50
+ url.search = new URLSearchParams({
51
+ partNumber: input.PartNumber + '',
52
+ uploadId: input.UploadId,
53
+ }).toString();
54
+ return {
55
+ method: 'PUT',
56
+ headers,
57
+ url,
58
+ body: input.Body,
59
+ };
60
+ };
61
+
62
+ const uploadPartDeserializer = async (
63
+ response: HttpResponse
64
+ ): Promise<UploadPartOutput> => {
65
+ if (response.statusCode >= 300) {
66
+ const error = await parseXmlError(response);
67
+ throw error;
68
+ } else {
69
+ return {
70
+ ...map(response.headers, {
71
+ ETag: 'etag',
72
+ }),
73
+ $metadata: parseMetadata(response),
74
+ };
75
+ }
76
+ };
77
+
78
+ export const uploadPart = composeServiceApi(
79
+ s3TransferHandler,
80
+ uploadPartSerializer,
81
+ uploadPartDeserializer,
82
+ { ...defaultConfig, responseType: 'text' }
83
+ );
@@ -0,0 +1,136 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Headers } from '@aws-amplify/core/internals/aws-client-utils';
5
+
6
+ type PropertyNameWithStringValue = string;
7
+ type PropertyNameWithSubsequentDeserializer<T> = [string, (any) => T];
8
+ type Instruction<T> =
9
+ | PropertyNameWithStringValue
10
+ | PropertyNameWithSubsequentDeserializer<T>;
11
+
12
+ type InferInstructionResultType<T extends Instruction<any>> =
13
+ | (T extends PropertyNameWithSubsequentDeserializer<infer R> ? R : string)
14
+ | undefined;
15
+
16
+ /**
17
+ * Maps an object to a new object using the provided instructions.
18
+ * The instructions are a map of the returning mapped object's property names to a single instruction of how to map the
19
+ * value from the original object to the new object. There are two types of instructions:
20
+ *
21
+ * 1. A string representing the property name of the original object to map to the new object. The value mapped from
22
+ * the original object will be the same as the value in the new object, and it can ONLY be string.
23
+ *
24
+ * 2. An array of two elements. The first element is the property name of the original object to map to the new object.
25
+ * The second element is a function that takes the value from the original object and returns the value to be mapped to
26
+ * the new object. The function can return any type.
27
+ *
28
+ * Example:
29
+ * ```typescript
30
+ * const input = {
31
+ * Foo: 'foo',
32
+ * BarList: [{value: 'bar1'}, {value: 'bar2'}]
33
+ * }
34
+ * const output = map(input, {
35
+ * someFoo: 'Foo',
36
+ * bar: ['BarList', (barList) => barList.map(bar => bar.value)]
37
+ * baz: 'Baz' // Baz does not exist in input, so it will not be in the output.
38
+ * });
39
+ * // output = { someFoo: 'foo', bar: ['bar1', 'bar2'] }
40
+ * ```
41
+ *
42
+ * @param obj The object containing the data to compose mapped object.
43
+ * @param instructions The instructions mapping the object values to the new object.
44
+ * @returns A new object with the mapped values.
45
+ *
46
+ * @internal
47
+ */
48
+ export const map = <Instructions extends { [key: string]: Instruction<any> }>(
49
+ obj: Record<string, any>,
50
+ instructions: Instructions
51
+ ): {
52
+ [K in keyof Instructions]: InferInstructionResultType<Instructions[K]>;
53
+ } => {
54
+ const result = {} as Record<keyof Instructions, any>;
55
+ for (const [key, instruction] of Object.entries(instructions)) {
56
+ const [accessor, deserializer] = Array.isArray(instruction)
57
+ ? instruction
58
+ : [instruction];
59
+ if (obj.hasOwnProperty(accessor)) {
60
+ result[key as keyof Instructions] = deserializer
61
+ ? deserializer(obj[accessor])
62
+ : String(obj[accessor]);
63
+ }
64
+ }
65
+ return result;
66
+ };
67
+
68
+ /**
69
+ * Deserializes a string to a number. Returns undefined if input is undefined.
70
+ *
71
+ * @internal
72
+ */
73
+ export const deserializeNumber = (value?: string): number => {
74
+ return value ? Number(value) : undefined;
75
+ };
76
+
77
+ /**
78
+ * Deserializes a string to a boolean. Returns undefined if input is undefined. Returns true if input is 'true',
79
+ * otherwise false.
80
+ *
81
+ * @internal
82
+ */
83
+ export const deserializeBoolean = (value?: string): boolean | undefined => {
84
+ return value ? value === 'true' : undefined;
85
+ };
86
+
87
+ /**
88
+ * Deserializes a string to a Date. Returns undefined if input is undefined.
89
+ * It supports epoch timestamp; rfc3339(cannot have a UTC, fractional precision supported); rfc7231(section 7.1.1.1)
90
+ *
91
+ * @see https://www.epoch101.com/
92
+ * @see https://datatracker.ietf.org/doc/html/rfc3339.html#section-5.6
93
+ * @see https://datatracker.ietf.org/doc/html/rfc7231.html#section-7.1.1.1
94
+ *
95
+ * @note For bundle size consideration, we use Date constructor to parse the timestamp string. There might be slight
96
+ * difference among browsers.
97
+ *
98
+ * @internal
99
+ */
100
+ export const deserializeTimestamp = (value: string): Date | undefined => {
101
+ return value ? new Date(value) : undefined;
102
+ };
103
+
104
+ /**
105
+ * Function that makes sure the deserializer receives non-empty array.
106
+ *
107
+ * @internal
108
+ */
109
+ export const emptyArrayGuard = <T extends Array<any>>(
110
+ value: any,
111
+ deserializer: (value: any[]) => T
112
+ ): T => {
113
+ if (value === '') {
114
+ return [] as T;
115
+ }
116
+ const valueArray = (Array.isArray(value) ? value : [value]).filter(
117
+ e => e != null
118
+ );
119
+ return deserializer(valueArray);
120
+ };
121
+
122
+ /**
123
+ * @internal
124
+ */
125
+ export const deserializeMetadata = (
126
+ headers: Headers
127
+ ): Record<string, string> => {
128
+ const objectMetadataHeaderPrefix = 'x-amz-meta-';
129
+ const deserialized = Object.keys(headers)
130
+ .filter(header => header.startsWith(objectMetadataHeaderPrefix))
131
+ .reduce((acc, header) => {
132
+ acc[header.replace(objectMetadataHeaderPrefix, '')] = headers[header];
133
+ return acc;
134
+ }, {} as any);
135
+ return Object.keys(deserialized).length > 0 ? deserialized : undefined;
136
+ };
@@ -0,0 +1,27 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { parseXmlBody, parseXmlError } from './parsePayload';
5
+ export {
6
+ SEND_DOWNLOAD_PROGRESS_EVENT,
7
+ SEND_UPLOAD_PROGRESS_EVENT,
8
+ s3TransferHandler,
9
+ CANCELED_ERROR_MESSAGE,
10
+ isCancelError,
11
+ CONTENT_SHA256_HEADER,
12
+ } from '../runtime';
13
+ export {
14
+ deserializeBoolean,
15
+ deserializeMetadata,
16
+ deserializeNumber,
17
+ deserializeTimestamp,
18
+ emptyArrayGuard,
19
+ map,
20
+ } from './deserializeHelpers';
21
+ export {
22
+ assignStringVariables,
23
+ serializeObjectConfigsToHeaders,
24
+ serializePathnameObjectKey,
25
+ serializeObjectSsecOptionsToHeaders,
26
+ } from './serializeHelpers';
27
+ export { toBase64, utf8Encode } from '../runtime';
@@ -0,0 +1,45 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ ErrorParser,
6
+ HttpResponse,
7
+ parseMetadata,
8
+ } from '@aws-amplify/core/internals/aws-client-utils';
9
+
10
+ import { parser } from '../runtime';
11
+
12
+ export const parseXmlError: ErrorParser = async (response?: HttpResponse) => {
13
+ if (!response || response.statusCode < 300) {
14
+ return;
15
+ }
16
+ const { statusCode } = response;
17
+ const body = await parseXmlBody(response);
18
+ const code = body?.['Code']
19
+ ? (body.Code as string)
20
+ : statusCode === 404
21
+ ? 'NotFound'
22
+ : statusCode.toString();
23
+ const message = body?.['message'] ?? body?.['Message'] ?? code;
24
+ const error = new Error(message);
25
+ return Object.assign(error, {
26
+ name: code,
27
+ $metadata: parseMetadata(response),
28
+ });
29
+ };
30
+
31
+ export const parseXmlBody = async (response: HttpResponse): Promise<any> => {
32
+ if (!response.body) {
33
+ // S3 can return 200 without a body indicating failure.
34
+ throw new Error('S3 aborted request.');
35
+ }
36
+ const data = await response.body.text();
37
+ if (data?.length > 0) {
38
+ try {
39
+ return parser.parse(data);
40
+ } catch (error) {
41
+ throw new Error('Failed to parse XML response.');
42
+ }
43
+ }
44
+ return {};
45
+ };
@@ -0,0 +1,112 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Md5 } from '@aws-sdk/md5-js';
4
+ import { extendedEncodeURIComponent } from '@aws-amplify/core/internals/aws-client-utils';
5
+ import { toBase64, utf8Encode } from '../utils';
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const assignStringVariables = (
11
+ values: Record<string, { toString: () => string } | undefined>
12
+ ): Record<string, string> => {
13
+ const queryParams = {};
14
+ for (const [key, value] of Object.entries(values)) {
15
+ if (value != null) {
16
+ queryParams[key] = value.toString();
17
+ }
18
+ }
19
+ return queryParams;
20
+ };
21
+
22
+ // Server-side encryption options
23
+ interface ObjectSsecOptions {
24
+ SSECustomerAlgorithm?: string;
25
+ SSECustomerKey?: string;
26
+ SSECustomerKeyMD5?: string;
27
+ }
28
+
29
+ export const serializeObjectSsecOptionsToHeaders = async (
30
+ input: ObjectSsecOptions
31
+ ) => {
32
+ const getMd5Digest = async (content: any) => {
33
+ const md5Hasher = new Md5();
34
+ md5Hasher.update(utf8Encode(content));
35
+ return md5Hasher.digest();
36
+ };
37
+
38
+ return assignStringVariables({
39
+ 'x-amz-server-side-encryption-customer-algorithm':
40
+ input.SSECustomerAlgorithm,
41
+ // base64 encoded is need
42
+ // see: https://docs.aws.amazon.com/AmazonS3/latest/userguide/ServerSideEncryptionCustomerKeys.html#specifying-s3-c-encryption
43
+ 'x-amz-server-side-encryption-customer-key':
44
+ input.SSECustomerKey && toBase64(input.SSECustomerKey),
45
+ // Calculate the md5 digest of the the SSE-C key, for compatibility with AWS SDK
46
+ // see: https://github.com/aws/aws-sdk-js-v3/blob/91fc83307c38cc9cbe0b3acd919557d5b5b831d6/packages/middleware-ssec/src/index.ts#L36
47
+ 'x-amz-server-side-encryption-customer-key-md5':
48
+ input.SSECustomerKey &&
49
+ toBase64(await getMd5Digest(input.SSECustomerKey)),
50
+ });
51
+ };
52
+
53
+ // Object configuration options when uploading an object.
54
+ interface ObjectConfigs extends ObjectSsecOptions {
55
+ ServerSideEncryption?: string;
56
+ SSEKMSKeyId?: string;
57
+ ACL?: string;
58
+ CacheControl?: string;
59
+ ContentDisposition?: string;
60
+ ContentEncoding?: string;
61
+ ContentLanguage?: string;
62
+ ContentType?: string;
63
+ Expires?: Date;
64
+ Tagging?: string;
65
+ Metadata?: Record<string, string>;
66
+ }
67
+
68
+ /**
69
+ * Serailize the parameters for configuring the S3 object. Currently used by
70
+ * `putObject` and `createMultipartUpload` API.
71
+ *
72
+ * @internal
73
+ */
74
+ export const serializeObjectConfigsToHeaders = async (
75
+ input: ObjectConfigs
76
+ ) => ({
77
+ ...(await serializeObjectSsecOptionsToHeaders(input)),
78
+ ...assignStringVariables({
79
+ 'x-amz-server-side-encryption': input.ServerSideEncryption,
80
+ 'x-amz-server-side-encryption-aws-kms-key-id': input.SSEKMSKeyId,
81
+ 'x-amz-acl': input.ACL,
82
+ 'cache-control': input.CacheControl,
83
+ 'content-disposition': input.ContentDisposition,
84
+ 'content-language': input.ContentLanguage,
85
+ 'content-encoding': input.ContentEncoding,
86
+ 'content-type': input.ContentType,
87
+ expires: input.Expires?.toUTCString(),
88
+ 'x-amz-tagging': input.Tagging,
89
+ ...serializeMetadata(input.Metadata),
90
+ }),
91
+ });
92
+
93
+ const serializeMetadata = (
94
+ metadata: Record<string, string> = {}
95
+ ): Record<string, string> =>
96
+ Object.keys(metadata).reduce((acc: any, suffix: string) => {
97
+ acc[`x-amz-meta-${suffix.toLowerCase()}`] = metadata[suffix];
98
+ return acc;
99
+ }, {});
100
+
101
+ /**
102
+ * Serialize the object key to a URL pathname.
103
+ * @see https://github.com/aws/aws-sdk-js-v3/blob/7ed7101dcc4e81038b6c7f581162b959e6b33a04/clients/client-s3/src/protocols/Aws_restXml.ts#L1108
104
+ *
105
+ * @internal
106
+ */
107
+ export const serializePathnameObjectKey = (url: URL, key: string) => {
108
+ return (
109
+ url.pathname.replace(/\/$/, '') +
110
+ `/${key.split('/').map(extendedEncodeURIComponent).join('/')}`
111
+ );
112
+ };
package/src/Storage.ts CHANGED
@@ -26,8 +26,8 @@ import {
26
26
  StorageGetPropertiesConfig,
27
27
  StorageGetPropertiesOutput,
28
28
  } from './types';
29
- import axios, { CancelTokenSource } from 'axios';
30
- import { PutObjectCommandInput } from '@aws-sdk/client-s3';
29
+ import { PutObjectInput } from './AwsClients/S3';
30
+ import { isCancelError } from './AwsClients/S3/utils';
31
31
  import { AWSS3UploadTask } from './providers/AWSS3UploadTask';
32
32
 
33
33
  const logger = new Logger('StorageClass');
@@ -46,11 +46,11 @@ export class Storage {
46
46
 
47
47
  /**
48
48
  * Similar to the API module. This weak map allows users to cancel their in-flight request made using the Storage
49
- * module. For every get or put request, a unique cancel token will be generated and injected to it's underlying
50
- * AxiosHttpHandler. This map maintains a mapping of Request to CancelTokenSource. When .cancel is invoked, it will
51
- * attempt to retrieve it's corresponding cancelTokenSource and cancel the in-flight request.
49
+ * module. For every get or put request, a unique AbortConttroller will be generated and injected to it's underlying
50
+ * Xhr HTTP handler. This map maintains a mapping of Request to AbortController. When .cancel is invoked, it will
51
+ * attempt to retrieve it's corresponding abortController and cancel the in-flight request.
52
52
  */
53
- private _cancelTokenSourceMap: WeakMap<Promise<any>, CancelTokenSource>;
53
+ private _abortControllerMap: WeakMap<Promise<any>, AbortController>;
54
54
 
55
55
  /**
56
56
  * @public
@@ -64,7 +64,7 @@ export class Storage {
64
64
  constructor() {
65
65
  this._config = {};
66
66
  this._pluggables = [];
67
- this._cancelTokenSourceMap = new WeakMap<Promise<any>, CancelTokenSource>();
67
+ this._abortControllerMap = new WeakMap<Promise<any>, AbortController>();
68
68
  logger.debug('Storage Options', this._config);
69
69
 
70
70
  this.get = this.get.bind(this);
@@ -139,6 +139,7 @@ export class Storage {
139
139
  'serverSideEncryption',
140
140
  'SSECustomerAlgorithm',
141
141
  'SSECustomerKey',
142
+ // TODO(AllanZhengYP): remove in V6.
142
143
  'SSECustomerKeyMD5',
143
144
  'SSEKMSKeyId',
144
145
  ];
@@ -185,15 +186,15 @@ export class Storage {
185
186
  return this._config;
186
187
  }
187
188
 
188
- private getCancellableTokenSource(): CancelTokenSource {
189
- return axios.CancelToken.source();
189
+ private getAbortController(): AbortController {
190
+ return new AbortController();
190
191
  }
191
192
 
192
193
  private updateRequestToBeCancellable(
193
194
  request: Promise<any>,
194
- cancelTokenSource: CancelTokenSource
195
+ abortController: AbortController
195
196
  ) {
196
- this._cancelTokenSourceMap.set(request, cancelTokenSource);
197
+ this._abortControllerMap.set(request, abortController);
197
198
  }
198
199
 
199
200
  private isUploadTask(x: unknown): x is UploadTask {
@@ -219,11 +220,13 @@ export class Storage {
219
220
  if (request instanceof AWSS3UploadTask) {
220
221
  return request._cancel();
221
222
  }
222
- const cancelTokenSource = this._cancelTokenSourceMap.get(
223
+ const abortController = this._abortControllerMap.get(
223
224
  request as Promise<any>
224
225
  );
225
- if (cancelTokenSource) {
226
- cancelTokenSource.cancel(message);
226
+ if (abortController) {
227
+ // TODO: [v6] clean up the aborted promise in the weak map.
228
+ // Not doing it yet to avoid breaking changes when users may abort a request twice.
229
+ abortController.abort(message);
227
230
  } else {
228
231
  logger.debug('The request does not map to any cancel token');
229
232
  }
@@ -257,7 +260,7 @@ export class Storage {
257
260
  'No plugin found in Storage for the provider'
258
261
  ) as StorageCopyOutput<T>;
259
262
  }
260
- const cancelTokenSource = this.getCancellableTokenSource();
263
+ const abortController = this.getAbortController();
261
264
  if (typeof plugin.copy !== 'function') {
262
265
  return Promise.reject(
263
266
  `.copy is not implemented on provider ${plugin.getProviderName()}`
@@ -265,9 +268,9 @@ export class Storage {
265
268
  }
266
269
  const responsePromise = plugin.copy(src, dest, {
267
270
  ...config,
268
- cancelTokenSource,
271
+ abortSignal: abortController.signal,
269
272
  });
270
- this.updateRequestToBeCancellable(responsePromise, cancelTokenSource);
273
+ this.updateRequestToBeCancellable(responsePromise, abortController);
271
274
  return responsePromise as StorageCopyOutput<T>;
272
275
  }
273
276
 
@@ -296,17 +299,17 @@ export class Storage {
296
299
  'No plugin found in Storage for the provider'
297
300
  ) as StorageGetOutput<T>;
298
301
  }
299
- const cancelTokenSource = this.getCancellableTokenSource();
302
+ const abortController = this.getAbortController();
300
303
  const responsePromise = plugin.get(key, {
301
304
  ...config,
302
- cancelTokenSource,
305
+ abortSignal: abortController.signal,
303
306
  });
304
- this.updateRequestToBeCancellable(responsePromise, cancelTokenSource);
307
+ this.updateRequestToBeCancellable(responsePromise, abortController);
305
308
  return responsePromise as StorageGetOutput<T>;
306
309
  }
307
310
 
308
311
  public isCancelError(error: any) {
309
- return axios.isCancel(error);
312
+ return isCancelError(error);
310
313
  }
311
314
 
312
315
  public getProperties<T extends StorageProvider | { [key: string]: any }>(
@@ -321,7 +324,7 @@ export class Storage {
321
324
  logger.debug('No plugin found with providerName', provider);
322
325
  throw new Error('No plugin found with providerName');
323
326
  }
324
- const cancelTokenSource = this.getCancellableTokenSource();
327
+ const abortController = this.getAbortController();
325
328
  if (typeof plugin.getProperties !== 'function') {
326
329
  return Promise.reject(
327
330
  `.getProperties is not implemented on provider ${plugin.getProviderName()}`
@@ -330,7 +333,7 @@ export class Storage {
330
333
  const responsePromise = plugin?.getProperties(key, {
331
334
  ...config,
332
335
  });
333
- this.updateRequestToBeCancellable(responsePromise, cancelTokenSource);
336
+ this.updateRequestToBeCancellable(responsePromise, abortController);
334
337
  return responsePromise as StorageGetPropertiesOutput<T>;
335
338
  }
336
339
  /**
@@ -348,7 +351,7 @@ export class Storage {
348
351
  ): StoragePutOutput<T>;
349
352
  public put<T extends StorageProvider = AWSS3Provider>(
350
353
  key: string,
351
- object: Omit<PutObjectCommandInput['Body'], 'ReadableStream' | 'Readable'>,
354
+ object: Omit<PutObjectInput['Body'], 'ReadableStream' | 'Readable'>,
352
355
  config?: StoragePutConfig<T>
353
356
  ): StoragePutOutput<T> {
354
357
  const provider = config?.provider || DEFAULT_PROVIDER;
@@ -361,13 +364,13 @@ export class Storage {
361
364
  'No plugin found in Storage for the provider'
362
365
  ) as StoragePutOutput<T>;
363
366
  }
364
- const cancelTokenSource = this.getCancellableTokenSource();
367
+ const abortController = this.getAbortController();
365
368
  const response = plugin.put(key, object, {
366
369
  ...config,
367
- cancelTokenSource,
370
+ abortSignal: abortController.signal,
368
371
  });
369
372
  if (!this.isUploadTask(response)) {
370
- this.updateRequestToBeCancellable(response, cancelTokenSource);
373
+ this.updateRequestToBeCancellable(response, abortController);
371
374
  }
372
375
  return response as StoragePutOutput<T>;
373
376
  }