@aws-amplify/storage 5.6.4-api-v6.2 → 5.6.4-api-v6.13

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 (251) 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 +0 -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 +1 -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/lib/.tsbuildinfo +0 -3
  216. package/lib/Storage.js.map +0 -1
  217. package/lib/common/S3ClientUtils.js.map +0 -1
  218. package/lib/common/StorageConstants.js.map +0 -1
  219. package/lib/common/StorageErrorStrings.js.map +0 -1
  220. package/lib/common/StorageUtils.js.map +0 -1
  221. package/lib/index.js.map +0 -1
  222. package/lib/providers/AWSS3Provider.js.map +0 -1
  223. package/lib/providers/AWSS3ProviderManagedUpload.js.map +0 -1
  224. package/lib/providers/AWSS3UploadTask.js.map +0 -1
  225. package/lib/providers/axios-http-handler.d.ts +0 -40
  226. package/lib/providers/axios-http-handler.js +0 -193
  227. package/lib/providers/axios-http-handler.js.map +0 -1
  228. package/lib/providers/index.js.map +0 -1
  229. package/lib/types/AWSS3Provider.js.map +0 -1
  230. package/lib/types/Provider.js.map +0 -1
  231. package/lib/types/Storage.js.map +0 -1
  232. package/lib/types/index.js.map +0 -1
  233. package/lib-esm/.tsbuildinfo +0 -3
  234. package/lib-esm/Storage.js.map +0 -1
  235. package/lib-esm/common/S3ClientUtils.js.map +0 -1
  236. package/lib-esm/common/StorageConstants.js.map +0 -1
  237. package/lib-esm/common/StorageErrorStrings.js.map +0 -1
  238. package/lib-esm/common/StorageUtils.js.map +0 -1
  239. package/lib-esm/index.js.map +0 -1
  240. package/lib-esm/providers/AWSS3Provider.js.map +0 -1
  241. package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +0 -1
  242. package/lib-esm/providers/AWSS3UploadTask.js.map +0 -1
  243. package/lib-esm/providers/axios-http-handler.d.ts +0 -40
  244. package/lib-esm/providers/axios-http-handler.js +0 -191
  245. package/lib-esm/providers/axios-http-handler.js.map +0 -1
  246. package/lib-esm/providers/index.js.map +0 -1
  247. package/lib-esm/types/AWSS3Provider.js.map +0 -1
  248. package/lib-esm/types/Provider.js.map +0 -1
  249. package/lib-esm/types/Storage.js.map +0 -1
  250. package/lib-esm/types/index.js.map +0 -1
  251. package/src/providers/axios-http-handler.ts +0 -242
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { HttpRequest, HttpResponse, TransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
3
+ import type { EventEmitter } from 'events';
4
+ /**
5
+ * @internal
6
+ */
7
+ export interface XhrTransferHandlerOptions {
8
+ responseType: 'text' | 'blob';
9
+ abortSignal?: AbortSignal;
10
+ emitter?: EventEmitter;
11
+ }
12
+ /**
13
+ * Base transfer handler implementation using XMLHttpRequest to support upload and download progress events.
14
+ *
15
+ * @param request - The request object.
16
+ * @param options - The request options.
17
+ * @returns A promise that will be resolved with the response object.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare const xhrTransferHandler: TransferHandler<HttpRequest, HttpResponse, XhrTransferHandlerOptions>;
22
+ export declare const isCancelError: (error: unknown) => boolean;
@@ -0,0 +1,196 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __read = (this && this.__read) || function (o, n) {
4
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5
+ if (!m) return o;
6
+ var i = m.call(o), r, ar = [], e;
7
+ try {
8
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9
+ }
10
+ catch (error) { e = { error: error }; }
11
+ finally {
12
+ try {
13
+ if (r && !r.done && (m = i["return"])) m.call(i);
14
+ }
15
+ finally { if (e) throw e.error; }
16
+ }
17
+ return ar;
18
+ };
19
+ import { withMemoization, } from '@aws-amplify/core/internals/aws-client-utils';
20
+ import { ConsoleLogger as Logger } from '@aws-amplify/core';
21
+ import { SEND_DOWNLOAD_PROGRESS_EVENT, SEND_UPLOAD_PROGRESS_EVENT, ABORT_ERROR_CODE, ABORT_ERROR_MESSAGE, CANCELED_ERROR_CODE, CANCELED_ERROR_MESSAGE, NETWORK_ERROR_CODE, NETWORK_ERROR_MESSAGE, } from './constants';
22
+ var logger = new Logger('xhr-http-handler');
23
+ /**
24
+ * Base transfer handler implementation using XMLHttpRequest to support upload and download progress events.
25
+ *
26
+ * @param request - The request object.
27
+ * @param options - The request options.
28
+ * @returns A promise that will be resolved with the response object.
29
+ *
30
+ * @internal
31
+ */
32
+ export var xhrTransferHandler = function (request, options) {
33
+ var url = request.url, method = request.method, headers = request.headers, body = request.body;
34
+ var emitter = options.emitter, responseType = options.responseType, abortSignal = options.abortSignal;
35
+ return new Promise(function (resolve, reject) {
36
+ var _a;
37
+ var xhr = new XMLHttpRequest();
38
+ xhr.open(method.toUpperCase(), url.toString());
39
+ Object.entries(headers)
40
+ .filter(function (_a) {
41
+ var _b = __read(_a, 1), header = _b[0];
42
+ return !FORBIDDEN_HEADERS.includes(header);
43
+ })
44
+ .forEach(function (_a) {
45
+ var _b = __read(_a, 2), header = _b[0], value = _b[1];
46
+ xhr.setRequestHeader(header, value);
47
+ });
48
+ xhr.responseType = responseType;
49
+ if (emitter) {
50
+ xhr.upload.addEventListener('progress', function (event) {
51
+ emitter.emit(SEND_UPLOAD_PROGRESS_EVENT, event);
52
+ logger.debug(event);
53
+ });
54
+ xhr.addEventListener('progress', function (event) {
55
+ emitter.emit(SEND_DOWNLOAD_PROGRESS_EVENT, event);
56
+ logger.debug(event);
57
+ });
58
+ }
59
+ xhr.addEventListener('error', function () {
60
+ var error = simulateAxiosError(NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE, xhr, options);
61
+ logger.error(NETWORK_ERROR_MESSAGE);
62
+ reject(error);
63
+ xhr = null; // clean up request
64
+ });
65
+ // Handle browser request cancellation (as opposed to a manual cancellation)
66
+ xhr.addEventListener('abort', function () {
67
+ // The abort event can be triggered after the error or load event. So we need to check if the xhr is null.
68
+ if (!xhr || (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted))
69
+ return;
70
+ var error = simulateAxiosError(ABORT_ERROR_MESSAGE, ABORT_ERROR_CODE, xhr, options);
71
+ logger.error(ABORT_ERROR_MESSAGE);
72
+ reject(error);
73
+ xhr = null; // clean up request
74
+ });
75
+ // Skip handling timeout error since we don't have a timeout
76
+ xhr.addEventListener('readystatechange', function () {
77
+ if (!xhr || xhr.readyState !== xhr.DONE) {
78
+ return;
79
+ }
80
+ var onloadend = function () {
81
+ // The load event is triggered after the error/abort/load event. So we need to check if the xhr is null.
82
+ if (!xhr)
83
+ return;
84
+ var responseHeaders = convertResponseHeaders(xhr.getAllResponseHeaders());
85
+ var responseType = xhr.responseType;
86
+ var responseBlob = xhr.response;
87
+ var responseText = responseType === 'text' ? xhr.responseText : '';
88
+ var bodyMixIn = {
89
+ blob: function () { return Promise.resolve(responseBlob); },
90
+ text: withMemoization(function () {
91
+ return responseType === 'blob'
92
+ ? readBlobAsText(responseBlob)
93
+ : Promise.resolve(responseText);
94
+ }),
95
+ json: function () {
96
+ return Promise.reject(
97
+ // S3 does not support JSON response. So fail-fast here with nicer error message.
98
+ new Error('Parsing response to JSON is not implemented. Please use response.text() instead.'));
99
+ },
100
+ };
101
+ var response = {
102
+ statusCode: xhr.status,
103
+ headers: responseHeaders,
104
+ // The xhr.responseType is only set to 'blob' for streaming binary S3 object data. The streaming data is
105
+ // exposed via public interface of Storage.get(). So we need to return the response as a Blob object for
106
+ // backward compatibility. In other cases, the response payload is only used internally, we return it is
107
+ // {@link ResponseBodyMixin}
108
+ body: (xhr.responseType === 'blob'
109
+ ? Object.assign(responseBlob, bodyMixIn)
110
+ : bodyMixIn),
111
+ };
112
+ resolve(response);
113
+ xhr = null; // clean up request
114
+ };
115
+ // readystate handler is calling before onerror or ontimeout handlers,
116
+ // so we should call onloadend on the next 'tick'
117
+ // @see https://github.com/axios/axios/blob/9588fcdec8aca45c3ba2f7968988a5d03f23168c/lib/adapters/xhr.js#L98-L99
118
+ setTimeout(onloadend);
119
+ });
120
+ if (abortSignal) {
121
+ var onCancelled = function () {
122
+ // The abort event is triggered after the error or load event. So we need to check if the xhr is null.
123
+ if (!xhr) {
124
+ return;
125
+ }
126
+ var canceledError = simulateAxiosCanceledError(CANCELED_ERROR_MESSAGE !== null && CANCELED_ERROR_MESSAGE !== void 0 ? CANCELED_ERROR_MESSAGE : abortSignal.reason, CANCELED_ERROR_CODE, xhr, options);
127
+ xhr.abort();
128
+ reject(canceledError);
129
+ xhr = null;
130
+ };
131
+ abortSignal.aborted
132
+ ? onCancelled()
133
+ : abortSignal.addEventListener('abort', onCancelled);
134
+ }
135
+ if (typeof ReadableStream === 'function' &&
136
+ body instanceof ReadableStream) {
137
+ // This does not matter as previous implementation uses Axios which does not support ReadableStream anyway.
138
+ throw new Error('ReadableStream request payload is not supported.');
139
+ }
140
+ xhr.send((_a = body) !== null && _a !== void 0 ? _a : null);
141
+ });
142
+ };
143
+ // TODO: V6 remove this
144
+ var simulateAxiosError = function (message, code, request, config) {
145
+ return Object.assign(new Error(message), {
146
+ code: code,
147
+ config: config,
148
+ request: request,
149
+ });
150
+ };
151
+ var simulateAxiosCanceledError = function (message, code, request, config) {
152
+ var error = simulateAxiosError(message, code, request, config);
153
+ error.name = 'CanceledError';
154
+ error['__CANCEL__'] = true;
155
+ return error;
156
+ };
157
+ export var isCancelError = function (error) {
158
+ return !!(error === null || error === void 0 ? void 0 : error['__CANCEL__']);
159
+ };
160
+ /**
161
+ * Convert xhr.getAllResponseHeaders() string to a Record<string, string>. Note that modern browser already returns
162
+ * header names in lowercase.
163
+ * @param xhrHeaders - string of headers returned from xhr.getAllResponseHeaders()
164
+ */
165
+ var convertResponseHeaders = function (xhrHeaders) {
166
+ if (!xhrHeaders) {
167
+ return {};
168
+ }
169
+ return xhrHeaders
170
+ .split('\r\n')
171
+ .reduce(function (headerMap, line) {
172
+ var parts = line.split(': ');
173
+ var header = parts.shift();
174
+ var value = parts.join(': ');
175
+ headerMap[header.toLowerCase()] = value;
176
+ return headerMap;
177
+ }, {});
178
+ };
179
+ var readBlobAsText = function (blob) {
180
+ var reader = new FileReader();
181
+ return new Promise(function (resolve, reject) {
182
+ reader.onloadend = function () {
183
+ if (reader.readyState !== FileReader.DONE) {
184
+ return;
185
+ }
186
+ resolve(reader.result);
187
+ };
188
+ reader.onerror = function () {
189
+ reject(reader.error);
190
+ };
191
+ reader.readAsText(blob);
192
+ });
193
+ };
194
+ // To add more forbidden headers as found set by S3. Intentionally NOT list all of them here to save bundle size.
195
+ // https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
196
+ var FORBIDDEN_HEADERS = ['host'];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Drop-in replacement for fast-xml-parser's XmlParser class used in the AWS SDK S3 client XML deserializer. This
3
+ * implementation is not tested against the full xml conformance test suite. It is only tested against the XML responses
4
+ * from S3. This implementation requires the `DOMParser` class in the runtime.
5
+ */
6
+ export declare const parser: {
7
+ parse: (xmlStr: string) => any;
8
+ };
@@ -0,0 +1,89 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Drop-in replacement for fast-xml-parser's XmlParser class used in the AWS SDK S3 client XML deserializer. This
5
+ * implementation is not tested against the full xml conformance test suite. It is only tested against the XML responses
6
+ * from S3. This implementation requires the `DOMParser` class in the runtime.
7
+ */
8
+ export var parser = {
9
+ parse: function (xmlStr) {
10
+ var domParser = new DOMParser();
11
+ var xml = domParser.parseFromString(xmlStr, 'text/xml');
12
+ var parsedObj = parseXmlNode(xml);
13
+ var rootKey = Object.keys(parsedObj)[0];
14
+ return parsedObj[rootKey];
15
+ },
16
+ };
17
+ var parseXmlNode = function (node) {
18
+ var _a;
19
+ var _b, _c;
20
+ if (isDocumentNode(node)) {
21
+ return _a = {},
22
+ _a[node.documentElement.nodeName] = parseXmlNode(node.documentElement),
23
+ _a;
24
+ }
25
+ if (node.nodeType === Node.TEXT_NODE) {
26
+ return (_b = node.nodeValue) === null || _b === void 0 ? void 0 : _b.trim();
27
+ }
28
+ if (isElementNode(node)) {
29
+ // Node like <Location>foo</Location> will be converted to { Location: 'foo' }
30
+ // instead of { Location: { '#text': 'foo' } }.
31
+ if (isTextOnlyElementNode(node)) {
32
+ return (_c = node.childNodes[0]) === null || _c === void 0 ? void 0 : _c.nodeValue;
33
+ }
34
+ var nodeValue = {};
35
+ // convert attributes
36
+ for (var i = 0; i < node.attributes.length; i++) {
37
+ var attr = node.attributes[i];
38
+ if (!isNamespaceAttributeName(attr.nodeName)) {
39
+ nodeValue[attr.nodeName] = attr.nodeValue;
40
+ }
41
+ }
42
+ // convert child nodes
43
+ if (node.children.length > 0) {
44
+ for (var i = 0; i < node.children.length; i++) {
45
+ var child = node.children[i];
46
+ var childValue = parseXmlNode(child);
47
+ if (childValue === undefined) {
48
+ continue;
49
+ }
50
+ var childName = child.nodeName;
51
+ if (nodeValue[childName] === undefined) {
52
+ nodeValue[childName] = childValue;
53
+ }
54
+ else if (Array.isArray(nodeValue[childName])) {
55
+ nodeValue[childName].push(childValue);
56
+ }
57
+ else {
58
+ nodeValue[childName] = [nodeValue[childName], childValue];
59
+ }
60
+ }
61
+ }
62
+ // Return empty element node as empty string instead of `{}`, which is the default behavior of fast-xml-parser.
63
+ return Object.keys(nodeValue).length === 0 ? '' : nodeValue;
64
+ }
65
+ };
66
+ var isElementNode = function (node) {
67
+ return node.nodeType === Node.ELEMENT_NODE;
68
+ };
69
+ var isDocumentNode = function (node) {
70
+ return node.nodeType === Node.DOCUMENT_NODE;
71
+ };
72
+ var isTextOnlyElementNode = function (node) {
73
+ var _a;
74
+ return hasOnlyNamespaceAttributes(node) &&
75
+ node.children.length === 0 &&
76
+ ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.nodeType) === Node.TEXT_NODE;
77
+ };
78
+ var hasOnlyNamespaceAttributes = function (node) {
79
+ for (var i = 0; i < node.attributes.length; i++) {
80
+ var attr = node.attributes[i];
81
+ if (!isNamespaceAttributeName(attr.nodeName)) {
82
+ return false;
83
+ }
84
+ }
85
+ return true;
86
+ };
87
+ var isNamespaceAttributeName = function (name) {
88
+ return name === 'xmlns' || name.startsWith('xmlns:');
89
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Pure JS XML parser that can be used in Non-browser environments, like React Native and Node.js. This is the same
3
+ * XML parser implementation as used in AWS SDK S3 client. It depends on pure JavaScript XML parser library
4
+ * `fast-xml-parser`.
5
+ *
6
+ * Ref: https://github.com/aws/aws-sdk-js-v3/blob/1e806ba3f4a83c9e3eb0b41a3a7092da93826b8f/clients/client-s3/src/protocols/Aws_restXml.ts#L12938-L12959
7
+ */
8
+ export declare const parser: {
9
+ parse: (xmlStr: string) => any;
10
+ };
@@ -0,0 +1,54 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { XMLParser } from 'fast-xml-parser';
4
+ /**
5
+ * Pure JS XML parser that can be used in Non-browser environments, like React Native and Node.js. This is the same
6
+ * XML parser implementation as used in AWS SDK S3 client. It depends on pure JavaScript XML parser library
7
+ * `fast-xml-parser`.
8
+ *
9
+ * Ref: https://github.com/aws/aws-sdk-js-v3/blob/1e806ba3f4a83c9e3eb0b41a3a7092da93826b8f/clients/client-s3/src/protocols/Aws_restXml.ts#L12938-L12959
10
+ */
11
+ export var parser = {
12
+ parse: function (xmlStr) {
13
+ var parser = new XMLParser({
14
+ attributeNamePrefix: '',
15
+ htmlEntities: true,
16
+ ignoreAttributes: false,
17
+ ignoreDeclaration: true,
18
+ parseTagValue: false,
19
+ trimValues: false,
20
+ removeNSPrefix: true,
21
+ tagValueProcessor: function (_, val) {
22
+ return val.trim() === '' && val.includes('\n') ? '' : undefined;
23
+ },
24
+ });
25
+ parser.addEntity('#xD', '\r');
26
+ parser.addEntity('#10', '\n');
27
+ var parsedObj = parser.parse(xmlStr);
28
+ var textNodeName = '#text';
29
+ var key = Object.keys(parsedObj)[0];
30
+ var parsedObjToReturn = parsedObj[key];
31
+ if (parsedObjToReturn[textNodeName]) {
32
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
33
+ delete parsedObjToReturn[textNodeName];
34
+ }
35
+ return getValueFromTextNode(parsedObjToReturn);
36
+ },
37
+ };
38
+ /**
39
+ * Recursively parses object and populates value is node from "#text" key if it's available
40
+ *
41
+ * Ref: https://github.com/aws/aws-sdk-js-v3/blob/6b4bde6f338720abf28b931f8a4506613bd64d3f/packages/smithy-client/src/get-value-from-text-node.ts#L1
42
+ */
43
+ var getValueFromTextNode = function (obj) {
44
+ var textNodeName = '#text';
45
+ for (var key in obj) {
46
+ if (obj.hasOwnProperty(key) && obj[key][textNodeName] !== undefined) {
47
+ obj[key] = obj[key][textNodeName];
48
+ }
49
+ else if (typeof obj[key] === 'object' && obj[key] !== null) {
50
+ obj[key] = getValueFromTextNode(obj[key]);
51
+ }
52
+ }
53
+ return obj;
54
+ };