@aws-amplify/storage 6.0.20 → 6.0.21-gen2-storage.7da2b89.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 (132) hide show
  1. package/dist/cjs/errors/types/validation.js +18 -2
  2. package/dist/cjs/errors/types/validation.js.map +1 -1
  3. package/dist/cjs/providers/s3/apis/copy.js +1 -13
  4. package/dist/cjs/providers/s3/apis/copy.js.map +1 -1
  5. package/dist/cjs/providers/s3/apis/downloadData.js +11 -36
  6. package/dist/cjs/providers/s3/apis/downloadData.js.map +1 -1
  7. package/dist/cjs/providers/s3/apis/getProperties.js +1 -12
  8. package/dist/cjs/providers/s3/apis/getProperties.js.map +1 -1
  9. package/dist/cjs/providers/s3/apis/getUrl.js +1 -19
  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 +13 -6
  16. package/dist/cjs/providers/s3/apis/internal/getUrl.js.map +1 -1
  17. package/dist/cjs/providers/s3/apis/internal/remove.js +20 -7
  18. package/dist/cjs/providers/s3/apis/internal/remove.js.map +1 -1
  19. package/dist/cjs/providers/s3/apis/remove.js +1 -10
  20. package/dist/cjs/providers/s3/apis/remove.js.map +1 -1
  21. package/dist/cjs/providers/s3/apis/server/copy.js +3 -5
  22. package/dist/cjs/providers/s3/apis/server/copy.js.map +1 -1
  23. package/dist/cjs/providers/s3/apis/server/getProperties.js +1 -3
  24. package/dist/cjs/providers/s3/apis/server/getProperties.js.map +1 -1
  25. package/dist/cjs/providers/s3/apis/server/getUrl.js +1 -3
  26. package/dist/cjs/providers/s3/apis/server/getUrl.js.map +1 -1
  27. package/dist/cjs/providers/s3/apis/server/remove.js +1 -3
  28. package/dist/cjs/providers/s3/apis/server/remove.js.map +1 -1
  29. package/dist/cjs/providers/s3/utils/constants.js +3 -1
  30. package/dist/cjs/providers/s3/utils/constants.js.map +1 -1
  31. package/dist/cjs/providers/s3/utils/index.js +5 -1
  32. package/dist/cjs/providers/s3/utils/index.js.map +1 -1
  33. package/dist/cjs/providers/s3/utils/isInputWithPath.js +11 -0
  34. package/dist/cjs/providers/s3/utils/isInputWithPath.js.map +1 -0
  35. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js +2 -1
  36. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js.map +1 -1
  37. package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js +31 -0
  38. package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js.map +1 -0
  39. package/dist/esm/errors/types/validation.d.ts +6 -2
  40. package/dist/esm/errors/types/validation.mjs +18 -2
  41. package/dist/esm/errors/types/validation.mjs.map +1 -1
  42. package/dist/esm/providers/s3/apis/copy.d.ts +29 -12
  43. package/dist/esm/providers/s3/apis/copy.mjs +1 -13
  44. package/dist/esm/providers/s3/apis/copy.mjs.map +1 -1
  45. package/dist/esm/providers/s3/apis/downloadData.d.ts +70 -32
  46. package/dist/esm/providers/s3/apis/downloadData.mjs +12 -36
  47. package/dist/esm/providers/s3/apis/downloadData.mjs.map +1 -1
  48. package/dist/esm/providers/s3/apis/getProperties.d.ts +28 -11
  49. package/dist/esm/providers/s3/apis/getProperties.mjs +1 -12
  50. package/dist/esm/providers/s3/apis/getProperties.mjs.map +1 -1
  51. package/dist/esm/providers/s3/apis/getUrl.d.ts +42 -18
  52. package/dist/esm/providers/s3/apis/getUrl.mjs +1 -19
  53. package/dist/esm/providers/s3/apis/getUrl.mjs.map +1 -1
  54. package/dist/esm/providers/s3/apis/internal/copy.d.ts +3 -1
  55. package/dist/esm/providers/s3/apis/internal/copy.mjs +41 -6
  56. package/dist/esm/providers/s3/apis/internal/copy.mjs.map +1 -1
  57. package/dist/esm/providers/s3/apis/internal/getProperties.mjs +11 -6
  58. package/dist/esm/providers/s3/apis/internal/getProperties.mjs.map +1 -1
  59. package/dist/esm/providers/s3/apis/internal/getUrl.mjs +15 -7
  60. package/dist/esm/providers/s3/apis/internal/getUrl.mjs.map +1 -1
  61. package/dist/esm/providers/s3/apis/internal/remove.mjs +21 -7
  62. package/dist/esm/providers/s3/apis/internal/remove.mjs.map +1 -1
  63. package/dist/esm/providers/s3/apis/remove.d.ts +26 -9
  64. package/dist/esm/providers/s3/apis/remove.mjs +1 -10
  65. package/dist/esm/providers/s3/apis/remove.mjs.map +1 -1
  66. package/dist/esm/providers/s3/apis/server/copy.d.ts +31 -2
  67. package/dist/esm/providers/s3/apis/server/copy.mjs +1 -3
  68. package/dist/esm/providers/s3/apis/server/copy.mjs.map +1 -1
  69. package/dist/esm/providers/s3/apis/server/getProperties.d.ts +30 -2
  70. package/dist/esm/providers/s3/apis/server/getProperties.mjs +1 -3
  71. package/dist/esm/providers/s3/apis/server/getProperties.mjs.map +1 -1
  72. package/dist/esm/providers/s3/apis/server/getUrl.d.ts +44 -2
  73. package/dist/esm/providers/s3/apis/server/getUrl.mjs +1 -3
  74. package/dist/esm/providers/s3/apis/server/getUrl.mjs.map +1 -1
  75. package/dist/esm/providers/s3/apis/server/remove.d.ts +28 -2
  76. package/dist/esm/providers/s3/apis/server/remove.mjs +1 -3
  77. package/dist/esm/providers/s3/apis/server/remove.mjs.map +1 -1
  78. package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.d.ts +1 -1
  79. package/dist/esm/providers/s3/apis/uploadData/putObjectJob.d.ts +1 -1
  80. package/dist/esm/providers/s3/types/index.d.ts +3 -3
  81. package/dist/esm/providers/s3/types/inputs.d.ts +29 -7
  82. package/dist/esm/providers/s3/types/options.d.ts +23 -5
  83. package/dist/esm/providers/s3/types/outputs.d.ts +33 -10
  84. package/dist/esm/providers/s3/utils/constants.d.ts +2 -0
  85. package/dist/esm/providers/s3/utils/constants.mjs +3 -1
  86. package/dist/esm/providers/s3/utils/constants.mjs.map +1 -1
  87. package/dist/esm/providers/s3/utils/index.d.ts +2 -0
  88. package/dist/esm/providers/s3/utils/index.mjs +2 -0
  89. package/dist/esm/providers/s3/utils/index.mjs.map +1 -1
  90. package/dist/esm/providers/s3/utils/isInputWithPath.d.ts +2 -0
  91. package/dist/esm/providers/s3/utils/isInputWithPath.mjs +8 -0
  92. package/dist/esm/providers/s3/utils/isInputWithPath.mjs.map +1 -0
  93. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.d.ts +2 -1
  94. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs +2 -1
  95. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs.map +1 -1
  96. package/dist/esm/providers/s3/utils/validateStorageOperationInput.d.ts +5 -0
  97. package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs +29 -0
  98. package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs.map +1 -0
  99. package/dist/esm/types/index.d.ts +2 -2
  100. package/dist/esm/types/inputs.d.ts +42 -8
  101. package/dist/esm/types/options.d.ts +1 -0
  102. package/dist/esm/types/outputs.d.ts +22 -6
  103. package/package.json +107 -107
  104. package/src/errors/types/validation.ts +19 -2
  105. package/src/providers/s3/apis/copy.ts +38 -15
  106. package/src/providers/s3/apis/downloadData.ts +105 -47
  107. package/src/providers/s3/apis/getProperties.ts +38 -15
  108. package/src/providers/s3/apis/getUrl.ts +48 -22
  109. package/src/providers/s3/apis/internal/copy.ts +90 -8
  110. package/src/providers/s3/apis/internal/getProperties.ts +19 -9
  111. package/src/providers/s3/apis/internal/getUrl.ts +29 -11
  112. package/src/providers/s3/apis/internal/remove.ts +28 -10
  113. package/src/providers/s3/apis/remove.ts +35 -12
  114. package/src/providers/s3/apis/server/copy.ts +49 -6
  115. package/src/providers/s3/apis/server/getProperties.ts +48 -6
  116. package/src/providers/s3/apis/server/getUrl.ts +56 -5
  117. package/src/providers/s3/apis/server/remove.ts +46 -5
  118. package/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +1 -1
  119. package/src/providers/s3/apis/uploadData/putObjectJob.ts +1 -1
  120. package/src/providers/s3/types/index.ts +26 -5
  121. package/src/providers/s3/types/inputs.ts +64 -18
  122. package/src/providers/s3/types/options.ts +44 -21
  123. package/src/providers/s3/types/outputs.ts +47 -10
  124. package/src/providers/s3/utils/constants.ts +3 -0
  125. package/src/providers/s3/utils/index.ts +2 -0
  126. package/src/providers/s3/utils/isInputWithPath.ts +13 -0
  127. package/src/providers/s3/utils/resolveS3ConfigAndInput.ts +3 -2
  128. package/src/providers/s3/utils/validateStorageOperationInput.ts +39 -0
  129. package/src/types/index.ts +12 -5
  130. package/src/types/inputs.ts +61 -11
  131. package/src/types/options.ts +1 -0
  132. package/src/types/outputs.ts +25 -6
@@ -1,25 +1,59 @@
1
+ import { StrictUnion } from '@aws-amplify/core/internals/utils';
1
2
  import { StorageListAllOptions, StorageListPaginateOptions, StorageOptions } from './options';
2
- export interface StorageOperationInput<Options extends StorageOptions> {
3
+ export type StorageOperationInputType = StrictUnion<StorageOperationInputKey | StorageOperationInputPath>;
4
+ /** @deprecated Use {@link StorageOperationInputPath} instead. */
5
+ export interface StorageOperationInputKey {
6
+ /** @deprecated Use `path` instead. */
3
7
  key: string;
8
+ }
9
+ export interface StorageOperationInputPath {
10
+ path: string | (({ identityId }: {
11
+ identityId?: string;
12
+ }) => string);
13
+ }
14
+ export interface StorageOperationOptionsInput<Options> {
4
15
  options?: Options;
5
16
  }
6
- export type StorageGetPropertiesInput<Options extends StorageOptions> = StorageOperationInput<Options>;
7
- export interface StorageRemoveInput<Options extends StorageOptions> {
17
+ /** @deprecated Use {@link StorageDownloadDataInputPath} instead. */
18
+ export type StorageDownloadDataInputKey<Options extends StorageOptions> = StorageOperationInputKey & StorageOperationOptionsInput<Options>;
19
+ export type StorageDownloadDataInputPath<Options> = StorageOperationInputPath & StorageOperationOptionsInput<Options>;
20
+ export interface StorageOperationInput<Options extends StorageOptions> {
8
21
  key: string;
9
22
  options?: Options;
10
23
  }
24
+ /** @deprecated Use {@link StorageGetPropertiesInputPath} instead. */
25
+ export type StorageGetPropertiesInputKey<Options extends StorageOptions> = StorageOperationInputKey & StorageOperationInput<Options>;
26
+ export type StorageGetPropertiesInputPath<Options> = StorageOperationInputPath & StorageOperationOptionsInput<Options>;
27
+ export type StorageRemoveInputKey<Options> = StorageOperationInputKey & StorageOperationOptionsInput<Options>;
28
+ export type StorageRemoveInputPath<Options> = StorageOperationInputPath & StorageOperationOptionsInput<Options>;
11
29
  export interface StorageListInput<Options extends StorageListAllOptions | StorageListPaginateOptions> {
12
30
  prefix?: string;
13
31
  options?: Options;
14
32
  }
15
- export type StorageGetUrlInput<Options extends StorageOptions> = StorageOperationInput<Options>;
16
- export type StorageDownloadDataInput<Options extends StorageOptions> = StorageOperationInput<Options>;
33
+ /** @deprecated Use {@link StorageGetUrlInputPath} instead. */
34
+ export type StorageGetUrlInputKey<Options extends StorageOptions> = StorageOperationInputKey & StorageOperationInput<Options>;
35
+ export type StorageGetUrlInputPath<Options> = StorageOperationInputPath & StorageOperationOptionsInput<Options>;
17
36
  export type StorageUploadDataInput<Options extends StorageOptions> = StorageOperationInput<Options> & {
18
37
  data: StorageUploadDataPayload;
19
38
  };
20
- export interface StorageCopyInput<SourceOptions extends StorageOptions, DestinationOptions extends StorageOptions> {
21
- source: SourceOptions;
22
- destination: DestinationOptions;
39
+ /** @deprecated Use {@link StorageCopyInputPath} instead. */
40
+ export interface StorageCopyInputKey<SourceOptions extends StorageOptions, DestinationOptions extends StorageOptions> {
41
+ source: SourceOptions & {
42
+ path?: never;
43
+ };
44
+ destination: DestinationOptions & {
45
+ path?: never;
46
+ };
47
+ }
48
+ export interface StorageCopyInputPath {
49
+ source: StorageOperationInputPath & {
50
+ /** @deprecated Use path instead. */
51
+ key?: never;
52
+ };
53
+ destination: StorageOperationInputPath & {
54
+ /** @deprecated Use path instead. */
55
+ key?: never;
56
+ };
23
57
  }
24
58
  /**
25
59
  * The data payload type for upload operation.
@@ -1,5 +1,6 @@
1
1
  import { StorageAccessLevel } from '@aws-amplify/core';
2
2
  export interface StorageOptions {
3
+ /** @deprecated This may be removed in the next major version. */
3
4
  accessLevel?: StorageAccessLevel;
4
5
  }
5
6
  export type StorageListAllOptions = StorageOptions & {
@@ -1,9 +1,8 @@
1
1
  import { ResponseBodyMixin } from '@aws-amplify/core/internals/aws-client-utils';
2
- export interface StorageItem {
3
- /**
4
- * Key of the object
5
- */
6
- key: string;
2
+ /**
3
+ * Base type for a storage item.
4
+ */
5
+ export interface StorageItemBase {
7
6
  /**
8
7
  * Creation date of the object.
9
8
  */
@@ -23,7 +22,24 @@ export interface StorageItem {
23
22
  */
24
23
  metadata?: Record<string, string>;
25
24
  }
26
- export type StorageDownloadDataOutput<T extends StorageItem> = T & {
25
+ /** @deprecated Use {@link StorageItemPath} instead. */
26
+ export type StorageItemKey = StorageItemBase & {
27
+ /**
28
+ * Key of the object.
29
+ */
30
+ key: string;
31
+ };
32
+ export type StorageItemPath = StorageItemBase & {
33
+ /**
34
+ * Path of the object.
35
+ */
36
+ path: string;
37
+ };
38
+ /**
39
+ * A storage item can be identified either by a key or a path.
40
+ */
41
+ export type StorageItem = StorageItemKey | StorageItemPath;
42
+ export type StorageDownloadDataOutput<Item extends StorageItem> = Item & {
27
43
  body: ResponseBodyMixin;
28
44
  };
29
45
  export interface StorageGetUrlOutput {
package/package.json CHANGED
@@ -1,109 +1,109 @@
1
1
  {
2
- "name": "@aws-amplify/storage",
3
- "version": "6.0.20",
4
- "description": "Storage category of aws-amplify",
5
- "main": "./dist/cjs/index.js",
6
- "module": "./dist/esm/index.mjs",
7
- "react-native": {
8
- "./dist/cjs/index": "./src/index.ts",
9
- "fast-xml-parser": "fast-xml-parser",
10
- "buffer": "buffer"
11
- },
12
- "typings": "./dist/esm/index.d.ts",
13
- "browser": {
14
- "./dist/esm/providers/s3/utils/client/runtime/base64/index.native.mjs": "./dist/esm/providers/s3/utils/client/runtime/base64/index.browser.mjs",
15
- "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/fetch.mjs": "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/xhr.mjs",
16
- "./dist/esm/providers/s3/utils/client/runtime/xmlParser/pureJs.mjs": "./dist/esm/providers/s3/utils/client/runtime/xmlParser/dom.mjs",
17
- "fast-xml-parser": false,
18
- "buffer": false
19
- },
20
- "sideEffects": false,
21
- "publishConfig": {
22
- "access": "public"
23
- },
24
- "scripts": {
25
- "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
26
- "build-with-test": "npm test && npm run build",
27
- "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
28
- "build:esm-cjs": "rollup -c rollup.config.mjs",
29
- "build:watch": "npm run build:esm-cjs -- --watch",
30
- "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
31
- "clean": "npm run clean:size && rimraf lib-esm lib dist",
32
- "clean:size": "rimraf dual-publish-tmp tmp*",
33
- "format": "echo \"Not implemented\"",
34
- "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
35
- "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
36
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
37
- },
38
- "typesVersions": {
39
- ">=4.2": {
40
- "s3": [
41
- "./dist/esm/providers/s3/index.d.ts"
42
- ],
43
- "server": [
44
- "./dist/esm/server.d.ts"
45
- ],
46
- "s3/server": [
47
- "./dist/esm/providers/s3/server.d.ts"
48
- ]
49
- }
50
- },
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/aws-amplify/amplify-js.git"
54
- },
55
- "author": "Amazon Web Services",
56
- "license": "Apache-2.0",
57
- "bugs": {
58
- "url": "https://github.com/aws/aws-amplify/issues"
59
- },
60
- "homepage": "https://aws-amplify.github.io/",
61
- "files": [
62
- "dist/cjs",
63
- "dist/esm",
64
- "src",
65
- "server",
66
- "s3"
67
- ],
68
- "dependencies": {
69
- "@aws-sdk/types": "3.398.0",
70
- "@smithy/md5-js": "2.0.7",
71
- "buffer": "4.9.2",
72
- "fast-xml-parser": "^4.2.5",
73
- "tslib": "^2.5.0"
74
- },
75
- "exports": {
76
- ".": {
77
- "types": "./dist/esm/index.d.ts",
78
- "import": "./dist/esm/index.mjs",
79
- "require": "./dist/cjs/index.js",
80
- "react-native": "./src/index.ts"
81
- },
82
- "./server": {
83
- "types": "./dist/esm/server.d.ts",
84
- "import": "./dist/esm/server.mjs",
85
- "require": "./dist/cjs/server.js"
86
- },
87
- "./s3": {
88
- "types": "./dist/esm/providers/s3/index.d.ts",
89
- "import": "./dist/esm/providers/s3/index.mjs",
90
- "require": "./dist/cjs/providers/s3/index.js",
91
- "react-native": "./src/providers/s3/index.ts"
92
- },
93
- "./s3/server": {
94
- "types": "./dist/esm/providers/s3/server.d.ts",
95
- "import": "./dist/esm/providers/s3/server.mjs",
96
- "require": "./dist/cjs/providers/s3/server.js"
97
- },
98
- "./package.json": "./package.json"
99
- },
100
- "peerDependencies": {
101
- "@aws-amplify/core": "^6.0.0"
102
- },
103
- "devDependencies": {
104
- "@aws-amplify/core": "6.0.20",
105
- "@aws-amplify/react-native": "1.0.20",
106
- "typescript": "5.0.2"
107
- },
108
- "gitHead": "bb280d64e6b5aa7679a2a6461dceeb27953ccdb1"
2
+ "name": "@aws-amplify/storage",
3
+ "version": "6.0.21-gen2-storage.7da2b89.0+7da2b89",
4
+ "description": "Storage category of aws-amplify",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.mjs",
7
+ "react-native": {
8
+ "./dist/cjs/index": "./src/index.ts",
9
+ "fast-xml-parser": "fast-xml-parser",
10
+ "buffer": "buffer"
11
+ },
12
+ "typings": "./dist/esm/index.d.ts",
13
+ "browser": {
14
+ "./dist/esm/providers/s3/utils/client/runtime/base64/index.native.mjs": "./dist/esm/providers/s3/utils/client/runtime/base64/index.browser.mjs",
15
+ "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/fetch.mjs": "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/xhr.mjs",
16
+ "./dist/esm/providers/s3/utils/client/runtime/xmlParser/pureJs.mjs": "./dist/esm/providers/s3/utils/client/runtime/xmlParser/dom.mjs",
17
+ "fast-xml-parser": false,
18
+ "buffer": false
19
+ },
20
+ "sideEffects": false,
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
26
+ "build-with-test": "npm test && npm run build",
27
+ "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
28
+ "build:esm-cjs": "rollup -c rollup.config.mjs",
29
+ "build:watch": "npm run build:esm-cjs -- --watch",
30
+ "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
31
+ "clean": "npm run clean:size && rimraf lib-esm lib dist",
32
+ "clean:size": "rimraf dual-publish-tmp tmp*",
33
+ "format": "echo \"Not implemented\"",
34
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
35
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
36
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
37
+ },
38
+ "typesVersions": {
39
+ ">=4.2": {
40
+ "s3": [
41
+ "./dist/esm/providers/s3/index.d.ts"
42
+ ],
43
+ "server": [
44
+ "./dist/esm/server.d.ts"
45
+ ],
46
+ "s3/server": [
47
+ "./dist/esm/providers/s3/server.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/aws-amplify/amplify-js.git"
54
+ },
55
+ "author": "Amazon Web Services",
56
+ "license": "Apache-2.0",
57
+ "bugs": {
58
+ "url": "https://github.com/aws/aws-amplify/issues"
59
+ },
60
+ "homepage": "https://aws-amplify.github.io/",
61
+ "files": [
62
+ "dist/cjs",
63
+ "dist/esm",
64
+ "src",
65
+ "server",
66
+ "s3"
67
+ ],
68
+ "dependencies": {
69
+ "@aws-sdk/types": "3.398.0",
70
+ "@smithy/md5-js": "2.0.7",
71
+ "buffer": "4.9.2",
72
+ "fast-xml-parser": "^4.2.5",
73
+ "tslib": "^2.5.0"
74
+ },
75
+ "exports": {
76
+ ".": {
77
+ "types": "./dist/esm/index.d.ts",
78
+ "import": "./dist/esm/index.mjs",
79
+ "require": "./dist/cjs/index.js",
80
+ "react-native": "./src/index.ts"
81
+ },
82
+ "./server": {
83
+ "types": "./dist/esm/server.d.ts",
84
+ "import": "./dist/esm/server.mjs",
85
+ "require": "./dist/cjs/server.js"
86
+ },
87
+ "./s3": {
88
+ "types": "./dist/esm/providers/s3/index.d.ts",
89
+ "import": "./dist/esm/providers/s3/index.mjs",
90
+ "require": "./dist/cjs/providers/s3/index.js",
91
+ "react-native": "./src/providers/s3/index.ts"
92
+ },
93
+ "./s3/server": {
94
+ "types": "./dist/esm/providers/s3/server.d.ts",
95
+ "import": "./dist/esm/providers/s3/server.mjs",
96
+ "require": "./dist/cjs/providers/s3/server.js"
97
+ },
98
+ "./package.json": "./package.json"
99
+ },
100
+ "peerDependencies": {
101
+ "@aws-amplify/core": "6.0.21-gen2-storage.7da2b89.0+7da2b89"
102
+ },
103
+ "devDependencies": {
104
+ "@aws-amplify/core": "6.0.21-gen2-storage.7da2b89.0+7da2b89",
105
+ "@aws-amplify/react-native": "1.0.21-gen2-storage.7da2b89.0+7da2b89",
106
+ "typescript": "5.0.2"
107
+ },
108
+ "gitHead": "7da2b89404ba47b1a3f774a4b799e591b8cbebfb"
109
109
  }
@@ -9,11 +9,15 @@ export enum StorageValidationErrorCode {
9
9
  NoKey = 'NoKey',
10
10
  NoSourceKey = 'NoSourceKey',
11
11
  NoDestinationKey = 'NoDestinationKey',
12
+ NoSourcePath = 'NoSourcePath',
13
+ NoDestinationPath = 'NoDestinationPath',
12
14
  NoBucket = 'NoBucket',
13
15
  NoRegion = 'NoRegion',
14
- UrlExpirationMaxLimitExceed = 'UrlExpirationMaxLimitExceed',
15
- ObjectIsTooLarge = 'ObjectIsTooLarge',
16
+ InvalidStorageOperationInput = 'InvalidStorageOperationInput',
17
+ InvalidStoragePathInput = 'InvalidStoragePathInput',
16
18
  InvalidUploadSource = 'InvalidUploadSource',
19
+ ObjectIsTooLarge = 'ObjectIsTooLarge',
20
+ UrlExpirationMaxLimitExceed = 'UrlExpirationMaxLimitExceed',
17
21
  }
18
22
 
19
23
  export const validationErrorMap: AmplifyErrorMap<StorageValidationErrorCode> = {
@@ -33,6 +37,12 @@ export const validationErrorMap: AmplifyErrorMap<StorageValidationErrorCode> = {
33
37
  [StorageValidationErrorCode.NoDestinationKey]: {
34
38
  message: 'Missing destination key in copy api call.',
35
39
  },
40
+ [StorageValidationErrorCode.NoSourcePath]: {
41
+ message: 'Missing source path in copy api call.',
42
+ },
43
+ [StorageValidationErrorCode.NoDestinationPath]: {
44
+ message: 'Missing destination path in copy api call.',
45
+ },
36
46
  [StorageValidationErrorCode.NoBucket]: {
37
47
  message: 'Missing bucket name while accessing object.',
38
48
  },
@@ -49,4 +59,11 @@ export const validationErrorMap: AmplifyErrorMap<StorageValidationErrorCode> = {
49
59
  message:
50
60
  'Upload source type can only be a `Blob`, `File`, `ArrayBuffer`, or `string`.',
51
61
  },
62
+ [StorageValidationErrorCode.InvalidStorageOperationInput]: {
63
+ message:
64
+ 'Path or key parameter must be specified in the input. Both can not be specified at the same time.',
65
+ },
66
+ [StorageValidationErrorCode.InvalidStoragePathInput]: {
67
+ message: 'Input `path` does not allow a leading slash (/).',
68
+ },
52
69
  };
@@ -3,21 +3,44 @@
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
+ CopyInputKey,
9
+ CopyInputPath,
10
+ CopyOutput,
11
+ CopyOutputKey,
12
+ CopyOutputPath,
13
+ } from '../types';
8
14
 
9
15
  import { copy as copyInternal } from './internal/copy';
10
16
 
11
- /**
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').
14
- *
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.
20
- */
21
- export const copy = async (input: CopyInput): Promise<CopyOutput> => {
22
- return copyInternal(Amplify, input);
23
- };
17
+ interface Copy {
18
+ /**
19
+ * Copy an object from a source to a destination object within the same bucket.
20
+ *
21
+ * @param input - The CopyInputPath object.
22
+ * @returns Output containing the destination object path.
23
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
24
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
25
+ * source or destination path is not defined.
26
+ */
27
+ (input: CopyInputPath): Promise<CopyOutputPath>;
28
+ /**
29
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
30
+ * Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/copy | path} instead.
31
+ *
32
+ * Copy an object from a source to a destination object within the same bucket. Can optionally copy files across
33
+ * different accessLevel or identityId (if source object's accessLevel is 'protected').
34
+ *
35
+ * @param input - The CopyInputKey object.
36
+ * @returns Output containing the destination object key.
37
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
38
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
39
+ * source or destination key is not defined.
40
+ */
41
+ (input: CopyInputKey): Promise<CopyOutputKey>;
42
+ }
43
+
44
+ export const copy: Copy = <Output extends CopyOutput>(
45
+ input: CopyInput,
46
+ ): Promise<Output> => copyInternal(Amplify, input) as Promise<Output>;
@@ -4,45 +4,97 @@
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
+ DownloadDataInputKey,
10
+ DownloadDataInputPath,
11
+ DownloadDataOutput,
12
+ DownloadDataOutputKey,
13
+ DownloadDataOutputPath,
14
+ } from '../types';
8
15
  import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput';
9
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
10
- import { createDownloadTask } from '../utils';
16
+ import { createDownloadTask, validateStorageOperationInput } from '../utils';
11
17
  import { getObject } from '../utils/client';
12
18
  import { getStorageUserAgentValue } from '../utils/userAgent';
13
19
  import { logger } from '../../../utils';
20
+ import {
21
+ StorageDownloadDataOutput,
22
+ StorageItemKey,
23
+ StorageItemPath,
24
+ } from '../../../types';
25
+ import { STORAGE_INPUT_KEY } from '../utils/constants';
14
26
 
15
- /**
16
- * Download S3 object data to memory
17
- *
18
- * @param input - The DownloadDataInput object.
19
- * @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
22
- *
23
- * @example
24
- * ```ts
25
- * // Download a file from s3 bucket
26
- * const { body, eTag } = await downloadData({ key, data: file, options: {
27
- * onProgress, // Optional progress callback.
28
- * } }).result;
29
- * ```
30
- * @example
31
- * ```ts
32
- * // Cancel a task
33
- * const downloadTask = downloadData({ key, data: file });
34
- * //...
35
- * downloadTask.cancel();
36
- * try {
37
- * await downloadTask.result;
38
- * } catch (error) {
39
- * if(isCancelError(error)) {
40
- * // Handle error thrown by task cancelation.
41
- * }
42
- * }
43
- *```
44
- */
45
- export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
27
+ interface DownloadData {
28
+ /**
29
+ * Download S3 object data to memory
30
+ *
31
+ * @param input - The DownloadDataInputPath object.
32
+ * @returns A cancelable task exposing result promise from `result` property.
33
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
34
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * // Download a file from s3 bucket
39
+ * const { body, eTag } = await downloadData({ path, options: {
40
+ * onProgress, // Optional progress callback.
41
+ * } }).result;
42
+ * ```
43
+ * @example
44
+ * ```ts
45
+ * // Cancel a task
46
+ * const downloadTask = downloadData({ path });
47
+ * //...
48
+ * downloadTask.cancel();
49
+ * try {
50
+ * await downloadTask.result;
51
+ * } catch (error) {
52
+ * if(isCancelError(error)) {
53
+ * // Handle error thrown by task cancelation.
54
+ * }
55
+ * }
56
+ *```
57
+ */
58
+ (input: DownloadDataInputPath): DownloadDataOutputPath;
59
+ /**
60
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
61
+ * Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/download/#downloaddata | path} instead.
62
+ *
63
+ * Download S3 object data to memory
64
+ *
65
+ * @param input - The DownloadDataInputKey object.
66
+ * @returns A cancelable task exposing result promise from `result` property.
67
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
68
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * // Download a file from s3 bucket
73
+ * const { body, eTag } = await downloadData({ key, options: {
74
+ * onProgress, // Optional progress callback.
75
+ * } }).result;
76
+ * ```
77
+ * @example
78
+ * ```ts
79
+ * // Cancel a task
80
+ * const downloadTask = downloadData({ key });
81
+ * //...
82
+ * downloadTask.cancel();
83
+ * try {
84
+ * await downloadTask.result;
85
+ * } catch (error) {
86
+ * if(isCancelError(error)) {
87
+ * // Handle error thrown by task cancelation.
88
+ * }
89
+ * }
90
+ *```
91
+ */
92
+ (input: DownloadDataInputKey): DownloadDataOutputKey;
93
+ }
94
+
95
+ export const downloadData: DownloadData = <Output extends DownloadDataOutput>(
96
+ input: DownloadDataInput,
97
+ ): Output => {
46
98
  const abortController = new AbortController();
47
99
 
48
100
  const downloadTask = createDownloadTask({
@@ -52,22 +104,25 @@ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
52
104
  },
53
105
  });
54
106
 
55
- return downloadTask;
107
+ return downloadTask as Output;
56
108
  };
57
109
 
58
110
  const downloadDataJob =
59
- (
60
- { options: downloadDataOptions, key }: DownloadDataInput,
61
- abortSignal: AbortSignal,
62
- ) =>
63
- async () => {
64
- const { bucket, keyPrefix, s3Config } = await resolveS3ConfigAndInput(
65
- Amplify,
66
- downloadDataOptions,
111
+ (downloadDataInput: DownloadDataInput, abortSignal: AbortSignal) =>
112
+ async (): Promise<
113
+ StorageDownloadDataOutput<StorageItemKey | StorageItemPath>
114
+ > => {
115
+ const { options: downloadDataOptions } = downloadDataInput;
116
+ const { bucket, keyPrefix, s3Config, identityId } =
117
+ await resolveS3ConfigAndInput(Amplify, downloadDataOptions);
118
+ const { inputType, objectKey } = validateStorageOperationInput(
119
+ downloadDataInput,
120
+ identityId,
67
121
  );
68
- const finalKey = keyPrefix + key;
122
+ const finalKey =
123
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
69
124
 
70
- logger.debug(`download ${key} from ${finalKey}.`);
125
+ logger.debug(`download ${objectKey} from ${finalKey}.`);
71
126
 
72
127
  const {
73
128
  Body: body,
@@ -93,8 +148,7 @@ const downloadDataJob =
93
148
  },
94
149
  );
95
150
 
96
- return {
97
- key,
151
+ const result = {
98
152
  body,
99
153
  lastModified,
100
154
  size,
@@ -103,4 +157,8 @@ const downloadDataJob =
103
157
  metadata,
104
158
  versionId,
105
159
  };
160
+
161
+ return inputType === STORAGE_INPUT_KEY
162
+ ? { key: objectKey, ...result }
163
+ : { path: finalKey, ...result };
106
164
  };