@aws-amplify/storage 6.0.28 → 6.0.29-gen2-storage.e54bfa9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/cjs/errors/types/validation.js +22 -2
  2. package/dist/cjs/errors/types/validation.js.map +1 -1
  3. package/dist/cjs/providers/s3/apis/copy.js +2 -12
  4. package/dist/cjs/providers/s3/apis/copy.js.map +1 -1
  5. package/dist/cjs/providers/s3/apis/downloadData.js +13 -38
  6. package/dist/cjs/providers/s3/apis/downloadData.js.map +1 -1
  7. package/dist/cjs/providers/s3/apis/getProperties.js +2 -11
  8. package/dist/cjs/providers/s3/apis/getProperties.js.map +1 -1
  9. package/dist/cjs/providers/s3/apis/getUrl.js +2 -18
  10. package/dist/cjs/providers/s3/apis/getUrl.js.map +1 -1
  11. package/dist/cjs/providers/s3/apis/internal/copy.js +41 -7
  12. package/dist/cjs/providers/s3/apis/internal/copy.js.map +1 -1
  13. package/dist/cjs/providers/s3/apis/internal/getProperties.js +10 -6
  14. package/dist/cjs/providers/s3/apis/internal/getProperties.js.map +1 -1
  15. package/dist/cjs/providers/s3/apis/internal/getUrl.js +8 -6
  16. package/dist/cjs/providers/s3/apis/internal/getUrl.js.map +1 -1
  17. package/dist/cjs/providers/s3/apis/internal/list.js +86 -16
  18. package/dist/cjs/providers/s3/apis/internal/list.js.map +1 -1
  19. package/dist/cjs/providers/s3/apis/internal/remove.js +20 -7
  20. package/dist/cjs/providers/s3/apis/internal/remove.js.map +1 -1
  21. package/dist/cjs/providers/s3/apis/list.js +4 -4
  22. package/dist/cjs/providers/s3/apis/list.js.map +1 -1
  23. package/dist/cjs/providers/s3/apis/remove.js +2 -9
  24. package/dist/cjs/providers/s3/apis/remove.js.map +1 -1
  25. package/dist/cjs/providers/s3/apis/server/copy.js +4 -4
  26. package/dist/cjs/providers/s3/apis/server/copy.js.map +1 -1
  27. package/dist/cjs/providers/s3/apis/server/getProperties.js +2 -2
  28. package/dist/cjs/providers/s3/apis/server/getProperties.js.map +1 -1
  29. package/dist/cjs/providers/s3/apis/server/getUrl.js +2 -2
  30. package/dist/cjs/providers/s3/apis/server/getUrl.js.map +1 -1
  31. package/dist/cjs/providers/s3/apis/server/list.js +4 -4
  32. package/dist/cjs/providers/s3/apis/server/list.js.map +1 -1
  33. package/dist/cjs/providers/s3/apis/server/remove.js +2 -2
  34. package/dist/cjs/providers/s3/apis/server/remove.js.map +1 -1
  35. package/dist/cjs/providers/s3/apis/uploadData/index.js +4 -50
  36. package/dist/cjs/providers/s3/apis/uploadData/index.js.map +1 -1
  37. package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js +1 -1
  38. package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js.map +1 -1
  39. package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js +8 -1
  40. package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js.map +1 -1
  41. package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js +28 -13
  42. package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js.map +1 -1
  43. package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js +10 -5
  44. package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js.map +1 -1
  45. package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js +1 -1
  46. package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js.map +1 -1
  47. package/dist/cjs/providers/s3/utils/constants.js +4 -1
  48. package/dist/cjs/providers/s3/utils/constants.js.map +1 -1
  49. package/dist/cjs/providers/s3/utils/index.js +7 -1
  50. package/dist/cjs/providers/s3/utils/index.js.map +1 -1
  51. package/dist/cjs/providers/s3/utils/isInputWithPath.js +11 -0
  52. package/dist/cjs/providers/s3/utils/isInputWithPath.js.map +1 -0
  53. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js +2 -1
  54. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js.map +1 -1
  55. package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js +31 -0
  56. package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js.map +1 -0
  57. package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js +32 -0
  58. package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js.map +1 -0
  59. package/dist/esm/errors/types/validation.d.ts +7 -2
  60. package/dist/esm/errors/types/validation.mjs +22 -2
  61. package/dist/esm/errors/types/validation.mjs.map +1 -1
  62. package/dist/esm/index.d.ts +2 -2
  63. package/dist/esm/providers/s3/apis/copy.d.ts +22 -9
  64. package/dist/esm/providers/s3/apis/copy.mjs +2 -12
  65. package/dist/esm/providers/s3/apis/copy.mjs.map +1 -1
  66. package/dist/esm/providers/s3/apis/downloadData.d.ts +41 -7
  67. package/dist/esm/providers/s3/apis/downloadData.mjs +15 -39
  68. package/dist/esm/providers/s3/apis/downloadData.mjs.map +1 -1
  69. package/dist/esm/providers/s3/apis/getProperties.d.ts +18 -5
  70. package/dist/esm/providers/s3/apis/getProperties.mjs +2 -11
  71. package/dist/esm/providers/s3/apis/getProperties.mjs.map +1 -1
  72. package/dist/esm/providers/s3/apis/getUrl.d.ts +27 -7
  73. package/dist/esm/providers/s3/apis/getUrl.mjs +2 -18
  74. package/dist/esm/providers/s3/apis/getUrl.mjs.map +1 -1
  75. package/dist/esm/providers/s3/apis/internal/copy.d.ts +4 -2
  76. package/dist/esm/providers/s3/apis/internal/copy.mjs +41 -6
  77. package/dist/esm/providers/s3/apis/internal/copy.mjs.map +1 -1
  78. package/dist/esm/providers/s3/apis/internal/getProperties.d.ts +2 -2
  79. package/dist/esm/providers/s3/apis/internal/getProperties.mjs +11 -6
  80. package/dist/esm/providers/s3/apis/internal/getProperties.mjs.map +1 -1
  81. package/dist/esm/providers/s3/apis/internal/getUrl.d.ts +2 -2
  82. package/dist/esm/providers/s3/apis/internal/getUrl.mjs +10 -7
  83. package/dist/esm/providers/s3/apis/internal/getUrl.mjs.map +1 -1
  84. package/dist/esm/providers/s3/apis/internal/list.d.ts +2 -2
  85. package/dist/esm/providers/s3/apis/internal/list.mjs +87 -16
  86. package/dist/esm/providers/s3/apis/internal/list.mjs.map +1 -1
  87. package/dist/esm/providers/s3/apis/internal/remove.d.ts +2 -2
  88. package/dist/esm/providers/s3/apis/internal/remove.mjs +21 -7
  89. package/dist/esm/providers/s3/apis/internal/remove.mjs.map +1 -1
  90. package/dist/esm/providers/s3/apis/list.d.ts +39 -22
  91. package/dist/esm/providers/s3/apis/list.mjs +2 -2
  92. package/dist/esm/providers/s3/apis/list.mjs.map +1 -1
  93. package/dist/esm/providers/s3/apis/remove.d.ts +18 -5
  94. package/dist/esm/providers/s3/apis/remove.mjs +2 -9
  95. package/dist/esm/providers/s3/apis/remove.mjs.map +1 -1
  96. package/dist/esm/providers/s3/apis/server/copy.d.ts +27 -2
  97. package/dist/esm/providers/s3/apis/server/copy.mjs +2 -2
  98. package/dist/esm/providers/s3/apis/server/copy.mjs.map +1 -1
  99. package/dist/esm/providers/s3/apis/server/getProperties.d.ts +26 -2
  100. package/dist/esm/providers/s3/apis/server/getProperties.mjs +2 -2
  101. package/dist/esm/providers/s3/apis/server/getProperties.mjs.map +1 -1
  102. package/dist/esm/providers/s3/apis/server/getUrl.d.ts +40 -2
  103. package/dist/esm/providers/s3/apis/server/getUrl.mjs +2 -2
  104. package/dist/esm/providers/s3/apis/server/getUrl.mjs.map +1 -1
  105. package/dist/esm/providers/s3/apis/server/list.d.ts +41 -22
  106. package/dist/esm/providers/s3/apis/server/list.mjs +2 -2
  107. package/dist/esm/providers/s3/apis/server/list.mjs.map +1 -1
  108. package/dist/esm/providers/s3/apis/server/remove.d.ts +24 -2
  109. package/dist/esm/providers/s3/apis/server/remove.mjs +2 -2
  110. package/dist/esm/providers/s3/apis/server/remove.mjs.map +1 -1
  111. package/dist/esm/providers/s3/apis/uploadData/index.d.ts +64 -7
  112. package/dist/esm/providers/s3/apis/uploadData/index.mjs +4 -50
  113. package/dist/esm/providers/s3/apis/uploadData/index.mjs.map +1 -1
  114. package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.d.ts +2 -2
  115. package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs +1 -1
  116. package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs.map +1 -1
  117. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.d.ts +1 -1
  118. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs +8 -1
  119. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs.map +1 -1
  120. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.d.ts +4 -4
  121. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs +30 -14
  122. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs.map +1 -1
  123. package/dist/esm/providers/s3/apis/uploadData/putObjectJob.d.ts +3 -3
  124. package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs +11 -5
  125. package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs.map +1 -1
  126. package/dist/esm/providers/s3/index.d.ts +2 -2
  127. package/dist/esm/providers/s3/types/index.d.ts +3 -3
  128. package/dist/esm/providers/s3/types/inputs.d.ts +51 -11
  129. package/dist/esm/providers/s3/types/options.d.ts +41 -10
  130. package/dist/esm/providers/s3/types/outputs.d.ts +68 -13
  131. package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs +1 -1
  132. package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs.map +1 -1
  133. package/dist/esm/providers/s3/utils/constants.d.ts +3 -0
  134. package/dist/esm/providers/s3/utils/constants.mjs +4 -1
  135. package/dist/esm/providers/s3/utils/constants.mjs.map +1 -1
  136. package/dist/esm/providers/s3/utils/index.d.ts +3 -0
  137. package/dist/esm/providers/s3/utils/index.mjs +3 -0
  138. package/dist/esm/providers/s3/utils/index.mjs.map +1 -1
  139. package/dist/esm/providers/s3/utils/isInputWithPath.d.ts +2 -0
  140. package/dist/esm/providers/s3/utils/isInputWithPath.mjs +8 -0
  141. package/dist/esm/providers/s3/utils/isInputWithPath.mjs.map +1 -0
  142. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.d.ts +2 -1
  143. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs +2 -1
  144. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs.map +1 -1
  145. package/dist/esm/providers/s3/utils/validateStorageOperationInput.d.ts +5 -0
  146. package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs +29 -0
  147. package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs.map +1 -0
  148. package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.d.ts +5 -0
  149. package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs +30 -0
  150. package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs.map +1 -0
  151. package/dist/esm/types/index.d.ts +2 -2
  152. package/dist/esm/types/inputs.d.ts +41 -13
  153. package/dist/esm/types/options.d.ts +1 -0
  154. package/dist/esm/types/outputs.d.ts +26 -6
  155. package/package.json +107 -107
  156. package/src/errors/types/validation.ts +23 -2
  157. package/src/index.ts +16 -0
  158. package/src/providers/s3/apis/copy.ts +30 -11
  159. package/src/providers/s3/apis/downloadData.ts +78 -19
  160. package/src/providers/s3/apis/getProperties.ts +31 -8
  161. package/src/providers/s3/apis/getUrl.ts +37 -10
  162. package/src/providers/s3/apis/internal/copy.ts +89 -8
  163. package/src/providers/s3/apis/internal/getProperties.ts +27 -12
  164. package/src/providers/s3/apis/internal/getUrl.ts +28 -14
  165. package/src/providers/s3/apis/internal/list.ts +135 -29
  166. package/src/providers/s3/apis/internal/remove.ts +36 -13
  167. package/src/providers/s3/apis/list.ts +54 -26
  168. package/src/providers/s3/apis/remove.ts +28 -7
  169. package/src/providers/s3/apis/server/copy.ts +42 -5
  170. package/src/providers/s3/apis/server/getProperties.ts +41 -4
  171. package/src/providers/s3/apis/server/getUrl.ts +55 -4
  172. package/src/providers/s3/apis/server/list.ts +64 -32
  173. package/src/providers/s3/apis/server/remove.ts +39 -4
  174. package/src/providers/s3/apis/uploadData/index.ts +77 -8
  175. package/src/providers/s3/apis/uploadData/multipart/initialUpload.ts +4 -3
  176. package/src/providers/s3/apis/uploadData/multipart/uploadCache.ts +11 -2
  177. package/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +50 -20
  178. package/src/providers/s3/apis/uploadData/putObjectJob.ts +23 -9
  179. package/src/providers/s3/index.ts +16 -0
  180. package/src/providers/s3/types/index.ts +37 -14
  181. package/src/providers/s3/types/inputs.ts +95 -26
  182. package/src/providers/s3/types/options.ts +73 -27
  183. package/src/providers/s3/types/outputs.ts +80 -13
  184. package/src/providers/s3/utils/client/utils/parsePayload.ts +1 -1
  185. package/src/providers/s3/utils/constants.ts +4 -0
  186. package/src/providers/s3/utils/index.ts +3 -0
  187. package/src/providers/s3/utils/isInputWithPath.ts +13 -0
  188. package/src/providers/s3/utils/resolveS3ConfigAndInput.ts +3 -2
  189. package/src/providers/s3/utils/validateStorageOperationInput.ts +39 -0
  190. package/src/providers/s3/utils/validateStorageOperationInputWithPrefix.ts +46 -0
  191. package/src/types/index.ts +16 -8
  192. package/src/types/inputs.ts +73 -20
  193. package/src/types/options.ts +1 -0
  194. package/src/types/outputs.ts +29 -6
package/src/index.ts CHANGED
@@ -13,24 +13,40 @@ export {
13
13
 
14
14
  export {
15
15
  UploadDataInput,
16
+ UploadDataWithPathInput,
16
17
  DownloadDataInput,
18
+ DownloadDataWithPathInput,
17
19
  RemoveInput,
20
+ RemoveWithPathInput,
18
21
  ListAllInput,
22
+ ListAllWithPathInput,
19
23
  ListPaginateInput,
24
+ ListPaginateWithPathInput,
20
25
  GetPropertiesInput,
26
+ GetPropertiesWithPathInput,
21
27
  CopyInput,
28
+ CopyWithPathInput,
22
29
  GetUrlInput,
30
+ GetUrlWithPathInput,
23
31
  } from './providers/s3/types/inputs';
24
32
 
25
33
  export {
26
34
  UploadDataOutput,
35
+ UploadDataWithPathOutput,
27
36
  DownloadDataOutput,
37
+ DownloadDataWithPathOutput,
28
38
  RemoveOutput,
39
+ RemoveWithPathOutput,
29
40
  ListAllOutput,
41
+ ListAllWithPathOutput,
30
42
  ListPaginateOutput,
43
+ ListPaginateWithPathOutput,
31
44
  GetPropertiesOutput,
45
+ GetPropertiesWithPathOutput,
32
46
  CopyOutput,
47
+ CopyWithPathOutput,
33
48
  GetUrlOutput,
49
+ GetUrlWithPathOutput,
34
50
  } from './providers/s3/types/outputs';
35
51
 
36
52
  export { TransferProgressEvent } from './types';
@@ -3,21 +3,40 @@
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
5
 
6
- import { CopyInput, CopyOutput, S3Exception } from '../types';
7
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
6
+ import {
7
+ CopyInput,
8
+ CopyOutput,
9
+ CopyWithPathInput,
10
+ CopyWithPathOutput,
11
+ } from '../types';
8
12
 
9
13
  import { copy as copyInternal } from './internal/copy';
10
14
 
11
15
  /**
12
- * Copy an object from a source object to a new object within the same bucket. Can optionally copy files across
13
- * different level or identityId (if source object's level is 'protected').
16
+ * Copy an object from a source to a destination object within the same bucket.
14
17
  *
15
- * @param input - The CopyInput object.
16
- * @returns Output containing the destination key.
17
- * @throws service: {@link S3Exception} - Thrown when checking for existence of the object
18
- * @throws validation: {@link StorageValidationErrorCode } - Thrown when
19
- * source or destination key are not defined.
18
+ * @param input - The `CopyWithPathInput` object.
19
+ * @returns Output containing the destination object path.
20
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
21
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
22
+ * source or destination path is not defined.
20
23
  */
21
- export const copy = async (input: CopyInput): Promise<CopyOutput> => {
24
+ export function copy(input: CopyWithPathInput): Promise<CopyWithPathOutput>;
25
+ /**
26
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
27
+ * Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/copy | path} instead.
28
+ *
29
+ * Copy an object from a source to a destination object within the same bucket. Can optionally copy files across
30
+ * different accessLevel or identityId (if source object's accessLevel is 'protected').
31
+ *
32
+ * @param input - The `CopyInput` object.
33
+ * @returns Output containing the destination object key.
34
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
35
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
36
+ * source or destination key is not defined.
37
+ */
38
+ export function copy(input: CopyInput): Promise<CopyOutput>;
39
+
40
+ export function copy(input: CopyInput | CopyWithPathInput) {
22
41
  return copyInternal(Amplify, input);
23
- };
42
+ }
@@ -4,33 +4,43 @@
4
4
  import { Amplify } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
- import { DownloadDataInput, DownloadDataOutput, S3Exception } from '../types';
7
+ import {
8
+ DownloadDataInput,
9
+ DownloadDataOutput,
10
+ DownloadDataWithPathInput,
11
+ DownloadDataWithPathOutput,
12
+ } from '../types';
8
13
  import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput';
9
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
10
- import { createDownloadTask } from '../utils';
14
+ import { createDownloadTask, validateStorageOperationInput } from '../utils';
11
15
  import { getObject } from '../utils/client';
12
16
  import { getStorageUserAgentValue } from '../utils/userAgent';
13
17
  import { logger } from '../../../utils';
18
+ import {
19
+ StorageDownloadDataOutput,
20
+ StorageItemWithKey,
21
+ StorageItemWithPath,
22
+ } from '../../../types';
23
+ import { STORAGE_INPUT_KEY } from '../utils/constants';
14
24
 
15
25
  /**
16
26
  * Download S3 object data to memory
17
27
  *
18
- * @param input - The DownloadDataInput object.
28
+ * @param input - The `DownloadDataWithPathInput` object.
19
29
  * @returns A cancelable task exposing result promise from `result` property.
20
- * @throws service: {@link S3Exception} - thrown when checking for existence of the object
21
- * @throws validation: {@link StorageValidationErrorCode } - Validation errors
30
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
31
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
22
32
  *
23
33
  * @example
24
34
  * ```ts
25
35
  * // Download a file from s3 bucket
26
- * const { body, eTag } = await downloadData({ key, data: file, options: {
36
+ * const { body, eTag } = await downloadData({ path, options: {
27
37
  * onProgress, // Optional progress callback.
28
38
  * } }).result;
29
39
  * ```
30
40
  * @example
31
41
  * ```ts
32
42
  * // Cancel a task
33
- * const downloadTask = downloadData({ key, data: file });
43
+ * const downloadTask = downloadData({ path });
34
44
  * //...
35
45
  * downloadTask.cancel();
36
46
  * try {
@@ -42,7 +52,47 @@ import { logger } from '../../../utils';
42
52
  * }
43
53
  *```
44
54
  */
45
- export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
55
+ export function downloadData(
56
+ input: DownloadDataWithPathInput,
57
+ ): DownloadDataWithPathOutput;
58
+ /**
59
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
60
+ * Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/download/#downloaddata | path} instead.
61
+ *
62
+ * Download S3 object data to memory
63
+ *
64
+ * @param input - The `DownloadDataInput` object.
65
+ * @returns A cancelable task exposing result promise from `result` property.
66
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
67
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * // Download a file from s3 bucket
72
+ * const { body, eTag } = await downloadData({ key, options: {
73
+ * onProgress, // Optional progress callback.
74
+ * } }).result;
75
+ * ```
76
+ * @example
77
+ * ```ts
78
+ * // Cancel a task
79
+ * const downloadTask = downloadData({ key });
80
+ * //...
81
+ * downloadTask.cancel();
82
+ * try {
83
+ * await downloadTask.result;
84
+ * } catch (error) {
85
+ * if(isCancelError(error)) {
86
+ * // Handle error thrown by task cancelation.
87
+ * }
88
+ * }
89
+ *```
90
+ */
91
+ export function downloadData(input: DownloadDataInput): DownloadDataOutput;
92
+
93
+ export function downloadData(
94
+ input: DownloadDataInput | DownloadDataWithPathInput,
95
+ ) {
46
96
  const abortController = new AbortController();
47
97
 
48
98
  const downloadTask = createDownloadTask({
@@ -53,21 +103,27 @@ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
53
103
  });
54
104
 
55
105
  return downloadTask;
56
- };
106
+ }
57
107
 
58
108
  const downloadDataJob =
59
109
  (
60
- { options: downloadDataOptions, key }: DownloadDataInput,
110
+ downloadDataInput: DownloadDataInput | DownloadDataWithPathInput,
61
111
  abortSignal: AbortSignal,
62
112
  ) =>
63
- async () => {
64
- const { bucket, keyPrefix, s3Config } = await resolveS3ConfigAndInput(
65
- Amplify,
66
- downloadDataOptions,
113
+ async (): Promise<
114
+ StorageDownloadDataOutput<StorageItemWithKey | StorageItemWithPath>
115
+ > => {
116
+ const { options: downloadDataOptions } = downloadDataInput;
117
+ const { bucket, keyPrefix, s3Config, identityId } =
118
+ await resolveS3ConfigAndInput(Amplify, downloadDataOptions);
119
+ const { inputType, objectKey } = validateStorageOperationInput(
120
+ downloadDataInput,
121
+ identityId,
67
122
  );
68
- const finalKey = keyPrefix + key;
123
+ const finalKey =
124
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
69
125
 
70
- logger.debug(`download ${key} from ${finalKey}.`);
126
+ logger.debug(`download ${objectKey} from ${finalKey}.`);
71
127
 
72
128
  const {
73
129
  Body: body,
@@ -93,8 +149,7 @@ const downloadDataJob =
93
149
  },
94
150
  );
95
151
 
96
- return {
97
- key,
152
+ const result = {
98
153
  body,
99
154
  lastModified,
100
155
  size,
@@ -103,4 +158,8 @@ const downloadDataJob =
103
158
  metadata,
104
159
  versionId,
105
160
  };
161
+
162
+ return inputType === STORAGE_INPUT_KEY
163
+ ? { key: objectKey, ...result }
164
+ : { path: objectKey, ...result };
106
165
  };
@@ -3,8 +3,12 @@
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
5
 
6
- import { GetPropertiesInput, GetPropertiesOutput, S3Exception } from '../types';
7
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
6
+ import {
7
+ GetPropertiesInput,
8
+ GetPropertiesOutput,
9
+ GetPropertiesWithPathInput,
10
+ GetPropertiesWithPathOutput,
11
+ } from '../types';
8
12
 
9
13
  import { getProperties as getPropertiesInternal } from './internal/getProperties';
10
14
 
@@ -12,13 +16,32 @@ import { getProperties as getPropertiesInternal } from './internal/getProperties
12
16
  * Gets the properties of a file. The properties include S3 system metadata and
13
17
  * the user metadata that was provided when uploading the file.
14
18
  *
15
- * @param input - The GetPropertiesInput object.
19
+ * @param input - The `GetPropertiesWithPathInput` object.
16
20
  * @returns Requested object properties.
17
- * @throws A {@link S3Exception} when the underlying S3 service returned error.
18
- * @throws A {@link StorageValidationErrorCode} when API call parameters are invalid.
21
+ * @throws An `S3Exception` when the underlying S3 service returned error.
22
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
19
23
  */
20
- export const getProperties = (
24
+ export function getProperties(
25
+ input: GetPropertiesWithPathInput,
26
+ ): Promise<GetPropertiesWithPathOutput>;
27
+ /**
28
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
29
+ * Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/get-properties/ | path} instead.
30
+ *
31
+ * Gets the properties of a file. The properties include S3 system metadata and
32
+ * the user metadata that was provided when uploading the file.
33
+ *
34
+ * @param input - The `GetPropertiesInput` object.
35
+ * @returns Requested object properties.
36
+ * @throws An `S3Exception` when the underlying S3 service returned error.
37
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
38
+ */
39
+ export function getProperties(
21
40
  input: GetPropertiesInput,
22
- ): Promise<GetPropertiesOutput> => {
41
+ ): Promise<GetPropertiesOutput>;
42
+
43
+ export function getProperties(
44
+ input: GetPropertiesInput | GetPropertiesWithPathInput,
45
+ ) {
23
46
  return getPropertiesInternal(Amplify, input);
24
- };
47
+ }
@@ -3,9 +3,12 @@
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
5
 
6
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
7
- import { GetUrlInput, GetUrlOutput, S3Exception } from '../types';
8
- import { StorageError } from '../../../errors/StorageError';
6
+ import {
7
+ GetUrlInput,
8
+ GetUrlOutput,
9
+ GetUrlWithPathInput,
10
+ GetUrlWithPathOutput,
11
+ } from '../types';
9
12
 
10
13
  import { getUrl as getUrlInternal } from './internal/getUrl';
11
14
 
@@ -16,15 +19,39 @@ import { getUrl as getUrlInternal } from './internal/getUrl';
16
19
  *
17
20
  * By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
18
21
  * to true, this method will verify the given object already exists in S3 before returning a presigned
19
- * URL, and will throw {@link StorageError} if the object does not exist.
22
+ * URL, and will throw `StorageError` if the object does not exist.
20
23
  *
21
- * @param input - The GetUrlInput object.
22
- * @returns Presigned URL and timestamp when the URL MAY expire.
23
- * @throws service: {@link S3Exception} - thrown when checking for existence of the object
24
- * @throws validation: {@link StorageValidationErrorCode } - Validation errors
24
+ * @param input - The `GetUrlWithPathInput` object.
25
+ * @returns Presigned URL and timestamp when the URL may expire.
26
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
27
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
25
28
  * thrown either username or key are not defined.
26
29
  *
27
30
  */
28
- export const getUrl = (input: GetUrlInput): Promise<GetUrlOutput> => {
31
+ export function getUrl(
32
+ input: GetUrlWithPathInput,
33
+ ): Promise<GetUrlWithPathOutput>;
34
+ /**
35
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
36
+ * Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/download/#generate-a-download-url | path} instead.
37
+ *
38
+ * Get a temporary presigned URL to download the specified S3 object.
39
+ * The presigned URL expires when the associated role used to sign the request expires or
40
+ * the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
41
+ *
42
+ * By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
43
+ * to true, this method will verify the given object already exists in S3 before returning a presigned
44
+ * URL, and will throw `StorageError` if the object does not exist.
45
+ *
46
+ * @param input - The `GetUrlInput` object.
47
+ * @returns Presigned URL and timestamp when the URL may expire.
48
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
49
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
50
+ * thrown either username or key are not defined.
51
+ *
52
+ */
53
+ export function getUrl(input: GetUrlInput): Promise<GetUrlOutput>;
54
+
55
+ export function getUrl(input: GetUrlInput | GetUrlWithPathInput) {
29
56
  return getUrlInternal(Amplify, input);
30
- };
57
+ }
@@ -4,15 +4,76 @@
4
4
  import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
- import { CopyInput, CopyOutput } from '../../types';
8
- import { resolveS3ConfigAndInput } from '../../utils';
7
+ import {
8
+ CopyInput,
9
+ CopyOutput,
10
+ CopyWithPathInput,
11
+ CopyWithPathOutput,
12
+ } from '../../types';
13
+ import { ResolvedS3Config } from '../../types/options';
14
+ import {
15
+ isInputWithPath,
16
+ resolveS3ConfigAndInput,
17
+ validateStorageOperationInput,
18
+ } from '../../utils';
9
19
  import { StorageValidationErrorCode } from '../../../../errors/types/validation';
10
20
  import { assertValidationError } from '../../../../errors/utils/assertValidationError';
11
21
  import { copyObject } from '../../utils/client';
12
22
  import { getStorageUserAgentValue } from '../../utils/userAgent';
13
23
  import { logger } from '../../../../utils';
14
24
 
25
+ const isCopyInputWithPath = (
26
+ input: CopyInput | CopyWithPathInput,
27
+ ): input is CopyWithPathInput => isInputWithPath(input.source);
28
+
15
29
  export const copy = async (
30
+ amplify: AmplifyClassV6,
31
+ input: CopyInput | CopyWithPathInput,
32
+ ): Promise<CopyOutput | CopyWithPathOutput> => {
33
+ return isCopyInputWithPath(input)
34
+ ? copyWithPath(amplify, input)
35
+ : copyWithKey(amplify, input);
36
+ };
37
+
38
+ const copyWithPath = async (
39
+ amplify: AmplifyClassV6,
40
+ input: CopyWithPathInput,
41
+ ): Promise<CopyWithPathOutput> => {
42
+ const { source, destination } = input;
43
+ const { s3Config, bucket, identityId } =
44
+ await resolveS3ConfigAndInput(amplify);
45
+
46
+ assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);
47
+ assertValidationError(
48
+ !!destination.path,
49
+ StorageValidationErrorCode.NoDestinationPath,
50
+ );
51
+
52
+ const { objectKey: sourcePath } = validateStorageOperationInput(
53
+ source,
54
+ identityId,
55
+ );
56
+ const { objectKey: destinationPath } = validateStorageOperationInput(
57
+ destination,
58
+ identityId,
59
+ );
60
+
61
+ const finalCopySource = `${bucket}/${sourcePath}`;
62
+ const finalCopyDestination = destinationPath;
63
+ logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
64
+
65
+ await serviceCopy({
66
+ source: finalCopySource,
67
+ destination: finalCopyDestination,
68
+ bucket,
69
+ s3Config,
70
+ });
71
+
72
+ return { path: finalCopyDestination };
73
+ };
74
+
75
+ /** @deprecated Use {@link copyWithPath} instead. */
76
+ export const copyWithKey = async (
16
77
  amplify: AmplifyClassV6,
17
78
  input: CopyInput,
18
79
  ): Promise<CopyOutput> => {
@@ -41,6 +102,30 @@ export const copy = async (
41
102
  const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
42
103
  const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
43
104
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
105
+
106
+ await serviceCopy({
107
+ source: finalCopySource,
108
+ destination: finalCopyDestination,
109
+ bucket,
110
+ s3Config,
111
+ });
112
+
113
+ return {
114
+ key: destinationKey,
115
+ };
116
+ };
117
+
118
+ const serviceCopy = async ({
119
+ source,
120
+ destination,
121
+ bucket,
122
+ s3Config,
123
+ }: {
124
+ source: string;
125
+ destination: string;
126
+ bucket: string;
127
+ s3Config: ResolvedS3Config;
128
+ }) => {
44
129
  await copyObject(
45
130
  {
46
131
  ...s3Config,
@@ -48,13 +133,9 @@ export const copy = async (
48
133
  },
49
134
  {
50
135
  Bucket: bucket,
51
- CopySource: finalCopySource,
52
- Key: finalCopyDestination,
136
+ CopySource: source,
137
+ Key: destination,
53
138
  MetadataDirective: 'COPY', // Copies over metadata like contentType as well
54
139
  },
55
140
  );
56
-
57
- return {
58
- key: destinationKey,
59
- };
60
141
  };
@@ -4,25 +4,37 @@
4
4
  import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
- import { GetPropertiesInput, GetPropertiesOutput } from '../../types';
8
- import { resolveS3ConfigAndInput } from '../../utils';
7
+ import {
8
+ GetPropertiesInput,
9
+ GetPropertiesOutput,
10
+ GetPropertiesWithPathInput,
11
+ GetPropertiesWithPathOutput,
12
+ } from '../../types';
13
+ import {
14
+ resolveS3ConfigAndInput,
15
+ validateStorageOperationInput,
16
+ } from '../../utils';
9
17
  import { headObject } from '../../utils/client';
10
18
  import { getStorageUserAgentValue } from '../../utils/userAgent';
11
19
  import { logger } from '../../../../utils';
20
+ import { STORAGE_INPUT_KEY } from '../../utils/constants';
12
21
 
13
22
  export const getProperties = async (
14
23
  amplify: AmplifyClassV6,
15
- input: GetPropertiesInput,
24
+ input: GetPropertiesInput | GetPropertiesWithPathInput,
16
25
  action?: StorageAction,
17
- ): Promise<GetPropertiesOutput> => {
18
- const { key, options } = input;
19
- const { s3Config, bucket, keyPrefix } = await resolveS3ConfigAndInput(
20
- amplify,
21
- options,
26
+ ): Promise<GetPropertiesOutput | GetPropertiesWithPathOutput> => {
27
+ const { options: getPropertiesOptions } = input;
28
+ const { s3Config, bucket, keyPrefix, identityId } =
29
+ await resolveS3ConfigAndInput(amplify, getPropertiesOptions);
30
+ const { inputType, objectKey } = validateStorageOperationInput(
31
+ input,
32
+ identityId,
22
33
  );
23
- const finalKey = `${keyPrefix}${key}`;
34
+ const finalKey =
35
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
24
36
 
25
- logger.debug(`get properties of ${key} from ${finalKey}`);
37
+ logger.debug(`get properties of ${objectKey} from ${finalKey}`);
26
38
  const response = await headObject(
27
39
  {
28
40
  ...s3Config,
@@ -36,8 +48,7 @@ export const getProperties = async (
36
48
  },
37
49
  );
38
50
 
39
- return {
40
- key,
51
+ const result = {
41
52
  contentType: response.ContentType,
42
53
  size: response.ContentLength,
43
54
  eTag: response.ETag,
@@ -45,4 +56,8 @@ export const getProperties = async (
45
56
  metadata: response.Metadata,
46
57
  versionId: response.VersionId,
47
58
  };
59
+
60
+ return inputType === STORAGE_INPUT_KEY
61
+ ? { key: objectKey, ...result }
62
+ : { path: objectKey, ...result };
48
63
  };
@@ -4,34 +4,48 @@
4
4
  import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
- import { GetUrlInput, GetUrlOutput } from '../../types';
7
+ import {
8
+ GetUrlInput,
9
+ GetUrlOutput,
10
+ GetUrlWithPathInput,
11
+ GetUrlWithPathOutput,
12
+ } from '../../types';
8
13
  import { StorageValidationErrorCode } from '../../../../errors/types/validation';
9
14
  import { getPresignedGetObjectUrl } from '../../utils/client';
10
- import { resolveS3ConfigAndInput } from '../../utils';
15
+ import {
16
+ resolveS3ConfigAndInput,
17
+ validateStorageOperationInput,
18
+ } from '../../utils';
11
19
  import { assertValidationError } from '../../../../errors/utils/assertValidationError';
12
20
  import {
13
21
  DEFAULT_PRESIGN_EXPIRATION,
14
22
  MAX_URL_EXPIRATION,
23
+ STORAGE_INPUT_KEY,
15
24
  } from '../../utils/constants';
16
25
 
17
26
  import { getProperties } from './getProperties';
18
27
 
19
28
  export const getUrl = async (
20
29
  amplify: AmplifyClassV6,
21
- input: GetUrlInput,
22
- ): Promise<GetUrlOutput> => {
23
- const { key, options } = input;
30
+ input: GetUrlInput | GetUrlWithPathInput,
31
+ ): Promise<GetUrlOutput | GetUrlWithPathOutput> => {
32
+ const { options: getUrlOptions } = input;
33
+ const { s3Config, keyPrefix, bucket, identityId } =
34
+ await resolveS3ConfigAndInput(amplify, getUrlOptions);
35
+ const { inputType, objectKey } = validateStorageOperationInput(
36
+ input,
37
+ identityId,
38
+ );
24
39
 
25
- if (options?.validateObjectExistence) {
26
- await getProperties(amplify, { key, options }, StorageAction.GetUrl);
27
- }
40
+ const finalKey =
41
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
28
42
 
29
- const { s3Config, keyPrefix, bucket } = await resolveS3ConfigAndInput(
30
- amplify,
31
- options,
32
- );
43
+ if (getUrlOptions?.validateObjectExistence) {
44
+ await getProperties(amplify, input, StorageAction.GetUrl);
45
+ }
33
46
 
34
- let urlExpirationInSec = options?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;
47
+ let urlExpirationInSec =
48
+ getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;
35
49
  const awsCredExpiration = s3Config.credentials?.expiration;
36
50
  if (awsCredExpiration) {
37
51
  const awsCredExpirationInSec = Math.floor(
@@ -54,7 +68,7 @@ export const getUrl = async (
54
68
  },
55
69
  {
56
70
  Bucket: bucket,
57
- Key: `${keyPrefix}${key}`,
71
+ Key: finalKey,
58
72
  },
59
73
  ),
60
74
  expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),