@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
@@ -3,22 +3,45 @@
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
+ GetPropertiesInputKey,
9
+ GetPropertiesInputPath,
10
+ GetPropertiesOutput,
11
+ GetPropertiesOutputKey,
12
+ GetPropertiesOutputPath,
13
+ } from '../types';
8
14
 
9
15
  import { getProperties as getPropertiesInternal } from './internal/getProperties';
10
16
 
11
- /**
12
- * Gets the properties of a file. The properties include S3 system metadata and
13
- * the user metadata that was provided when uploading the file.
14
- *
15
- * @param input - The GetPropertiesInput object.
16
- * @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.
19
- */
20
- export const getProperties = (
17
+ interface GetProperties {
18
+ /**
19
+ * Gets the properties of a file. The properties include S3 system metadata and
20
+ * the user metadata that was provided when uploading the file.
21
+ *
22
+ * @param input - The `GetPropertiesInputPath` object.
23
+ * @returns Requested object properties.
24
+ * @throws An `S3Exception` when the underlying S3 service returned error.
25
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
26
+ */
27
+ (input: GetPropertiesInputPath): Promise<GetPropertiesOutputPath>;
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/javascript/build-a-backend/storage/get-properties/ | path} instead.
31
+ *
32
+ * Gets the properties of a file. The properties include S3 system metadata and
33
+ * the user metadata that was provided when uploading the file.
34
+ *
35
+ * @param input - The `GetPropertiesInputKey` object.
36
+ * @returns Requested object properties.
37
+ * @throws An `S3Exception` when the underlying S3 service returned error.
38
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
39
+ */
40
+ (input: GetPropertiesInputKey): Promise<GetPropertiesOutputKey>;
41
+ }
42
+
43
+ export const getProperties: GetProperties = <
44
+ Output extends GetPropertiesOutput,
45
+ >(
21
46
  input: GetPropertiesInput,
22
- ): Promise<GetPropertiesOutput> => {
23
- return getPropertiesInternal(Amplify, input);
24
- };
47
+ ): Promise<Output> => getPropertiesInternal(Amplify, input) as Promise<Output>;
@@ -3,28 +3,54 @@
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
+ GetUrlInputKey,
9
+ GetUrlInputPath,
10
+ GetUrlOutput,
11
+ } from '../types';
9
12
 
10
13
  import { getUrl as getUrlInternal } from './internal/getUrl';
11
14
 
12
- /**
13
- * Get a temporary presigned URL to download the specified S3 object.
14
- * The presigned URL expires when the associated role used to sign the request expires or
15
- * the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
16
- *
17
- * By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
18
- * 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.
20
- *
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
25
- * thrown either username or key are not defined.
26
- *
27
- */
28
- export const getUrl = (input: GetUrlInput): Promise<GetUrlOutput> => {
29
- return getUrlInternal(Amplify, input);
30
- };
15
+ interface GetUrl {
16
+ /**
17
+ * Get a temporary presigned URL to download the specified S3 object.
18
+ * The presigned URL expires when the associated role used to sign the request expires or
19
+ * the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
20
+ *
21
+ * By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
22
+ * to true, this method will verify the given object already exists in S3 before returning a presigned
23
+ * URL, and will throw `StorageError` if the object does not exist.
24
+ *
25
+ * @param input - The `GetUrlInputPath` object.
26
+ * @returns Presigned URL and timestamp when the URL MAY expire.
27
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
28
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
29
+ * thrown either username or key are not defined.
30
+ *
31
+ */
32
+ (input: GetUrlInputPath): Promise<GetUrlOutput>;
33
+ /**
34
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
35
+ * Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/download/#generate-a-download-url | path} instead.
36
+ *
37
+ * Get a temporary presigned URL to download the specified S3 object.
38
+ * The presigned URL expires when the associated role used to sign the request expires or
39
+ * the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
40
+ *
41
+ * By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
42
+ * to true, this method will verify the given object already exists in S3 before returning a presigned
43
+ * URL, and will throw `StorageError` if the object does not exist.
44
+ *
45
+ * @param input - The `GetUrlInputKey` object.
46
+ * @returns Presigned URL and timestamp when the URL MAY expire.
47
+ * @throws service: `S3Exception` - thrown when checking for existence of the object
48
+ * @throws validation: `StorageValidationErrorCode` - Validation errors
49
+ * thrown either username or key are not defined.
50
+ *
51
+ */
52
+ (input: GetUrlInputKey): Promise<GetUrlOutput>;
53
+ }
54
+
55
+ export const getUrl: GetUrl = (input: GetUrlInput): Promise<GetUrlOutput> =>
56
+ getUrlInternal(Amplify, input);
@@ -4,18 +4,80 @@
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
+ CopyInputKey,
10
+ CopyInputPath,
11
+ CopyOutput,
12
+ CopyOutputKey,
13
+ CopyOutputPath,
14
+ } from '../../types';
15
+ import { ResolvedS3Config } from '../../types/options';
16
+ import {
17
+ isInputWithPath,
18
+ resolveS3ConfigAndInput,
19
+ validateStorageOperationInput,
20
+ } from '../../utils';
9
21
  import { StorageValidationErrorCode } from '../../../../errors/types/validation';
10
22
  import { assertValidationError } from '../../../../errors/utils/assertValidationError';
11
23
  import { copyObject } from '../../utils/client';
12
24
  import { getStorageUserAgentValue } from '../../utils/userAgent';
13
25
  import { logger } from '../../../../utils';
14
26
 
27
+ const isCopyInputWithPath = (input: CopyInput): input is CopyInputPath =>
28
+ isInputWithPath(input.source);
29
+
15
30
  export const copy = async (
16
31
  amplify: AmplifyClassV6,
17
32
  input: CopyInput,
18
33
  ): Promise<CopyOutput> => {
34
+ return isCopyInputWithPath(input)
35
+ ? copyWithPath(amplify, input)
36
+ : copyWithKey(amplify, input);
37
+ };
38
+
39
+ const copyWithPath = async (
40
+ amplify: AmplifyClassV6,
41
+ input: CopyInputPath,
42
+ ): Promise<CopyOutputPath> => {
43
+ const { source, destination } = input;
44
+ const { s3Config, bucket, identityId } =
45
+ await resolveS3ConfigAndInput(amplify);
46
+
47
+ assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);
48
+ assertValidationError(
49
+ !!destination.path,
50
+ StorageValidationErrorCode.NoDestinationPath,
51
+ );
52
+
53
+ const { objectKey: sourcePath } = validateStorageOperationInput(
54
+ source,
55
+ identityId,
56
+ );
57
+ const { objectKey: destinationPath } = validateStorageOperationInput(
58
+ destination,
59
+ identityId,
60
+ );
61
+
62
+ const finalCopySource = `${bucket}/${sourcePath}`;
63
+ const finalCopyDestination = destinationPath;
64
+ logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
65
+
66
+ await serviceCopy({
67
+ source: finalCopySource,
68
+ destination: finalCopyDestination,
69
+ bucket,
70
+ s3Config,
71
+ });
72
+
73
+ return { path: finalCopyDestination };
74
+ };
75
+
76
+ /** @deprecated Use {@link copyWithPath} instead. */
77
+ export const copyWithKey = async (
78
+ amplify: AmplifyClassV6,
79
+ input: CopyInputKey,
80
+ ): Promise<CopyOutputKey> => {
19
81
  const {
20
82
  source: { key: sourceKey },
21
83
  destination: { key: destinationKey },
@@ -41,6 +103,30 @@ export const copy = async (
41
103
  const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
42
104
  const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
43
105
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
106
+
107
+ await serviceCopy({
108
+ source: finalCopySource,
109
+ destination: finalCopyDestination,
110
+ bucket,
111
+ s3Config,
112
+ });
113
+
114
+ return {
115
+ key: destinationKey,
116
+ };
117
+ };
118
+
119
+ const serviceCopy = async ({
120
+ source,
121
+ destination,
122
+ bucket,
123
+ s3Config,
124
+ }: {
125
+ source: string;
126
+ destination: string;
127
+ bucket: string;
128
+ s3Config: ResolvedS3Config;
129
+ }) => {
44
130
  await copyObject(
45
131
  {
46
132
  ...s3Config,
@@ -48,13 +134,9 @@ export const copy = async (
48
134
  },
49
135
  {
50
136
  Bucket: bucket,
51
- CopySource: finalCopySource,
52
- Key: finalCopyDestination,
137
+ CopySource: source,
138
+ Key: destination,
53
139
  MetadataDirective: 'COPY', // Copies over metadata like contentType as well
54
140
  },
55
141
  );
56
-
57
- return {
58
- key: destinationKey,
59
- };
60
142
  };
@@ -5,24 +5,31 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
7
  import { GetPropertiesInput, GetPropertiesOutput } from '../../types';
8
- import { resolveS3ConfigAndInput } from '../../utils';
8
+ import {
9
+ resolveS3ConfigAndInput,
10
+ validateStorageOperationInput,
11
+ } from '../../utils';
9
12
  import { headObject } from '../../utils/client';
10
13
  import { getStorageUserAgentValue } from '../../utils/userAgent';
11
14
  import { logger } from '../../../../utils';
15
+ import { STORAGE_INPUT_KEY } from '../../utils/constants';
12
16
 
13
17
  export const getProperties = async (
14
18
  amplify: AmplifyClassV6,
15
19
  input: GetPropertiesInput,
16
20
  action?: StorageAction,
17
21
  ): Promise<GetPropertiesOutput> => {
18
- const { key, options } = input;
19
- const { s3Config, bucket, keyPrefix } = await resolveS3ConfigAndInput(
20
- amplify,
21
- options,
22
+ const { options: getPropertiesOptions } = input;
23
+ const { s3Config, bucket, keyPrefix, identityId } =
24
+ await resolveS3ConfigAndInput(amplify, getPropertiesOptions);
25
+ const { inputType, objectKey } = validateStorageOperationInput(
26
+ input,
27
+ identityId,
22
28
  );
23
- const finalKey = `${keyPrefix}${key}`;
29
+ const finalKey =
30
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
24
31
 
25
- logger.debug(`get properties of ${key} from ${finalKey}`);
32
+ logger.debug(`get properties of ${objectKey} from ${finalKey}`);
26
33
  const response = await headObject(
27
34
  {
28
35
  ...s3Config,
@@ -36,8 +43,7 @@ export const getProperties = async (
36
43
  },
37
44
  );
38
45
 
39
- return {
40
- key,
46
+ const result = {
41
47
  contentType: response.ContentType,
42
48
  size: response.ContentLength,
43
49
  eTag: response.ETag,
@@ -45,4 +51,8 @@ export const getProperties = async (
45
51
  metadata: response.Metadata,
46
52
  versionId: response.VersionId,
47
53
  };
54
+
55
+ return inputType === STORAGE_INPUT_KEY
56
+ ? { key: objectKey, ...result }
57
+ : { path: objectKey, ...result };
48
58
  };
@@ -7,11 +7,15 @@ import { StorageAction } from '@aws-amplify/core/internals/utils';
7
7
  import { GetUrlInput, GetUrlOutput } from '../../types';
8
8
  import { StorageValidationErrorCode } from '../../../../errors/types/validation';
9
9
  import { getPresignedGetObjectUrl } from '../../utils/client';
10
- import { resolveS3ConfigAndInput } from '../../utils';
10
+ import {
11
+ resolveS3ConfigAndInput,
12
+ validateStorageOperationInput,
13
+ } from '../../utils';
11
14
  import { assertValidationError } from '../../../../errors/utils/assertValidationError';
12
15
  import {
13
16
  DEFAULT_PRESIGN_EXPIRATION,
14
17
  MAX_URL_EXPIRATION,
18
+ STORAGE_INPUT_KEY,
15
19
  } from '../../utils/constants';
16
20
 
17
21
  import { getProperties } from './getProperties';
@@ -20,18 +24,32 @@ export const getUrl = async (
20
24
  amplify: AmplifyClassV6,
21
25
  input: GetUrlInput,
22
26
  ): Promise<GetUrlOutput> => {
23
- const { key, options } = input;
27
+ const { options: getUrlOptions } = input;
28
+ const { s3Config, keyPrefix, bucket, identityId } =
29
+ await resolveS3ConfigAndInput(amplify, getUrlOptions);
30
+ const { inputType, objectKey } = validateStorageOperationInput(
31
+ input,
32
+ identityId,
33
+ );
24
34
 
25
- if (options?.validateObjectExistence) {
26
- await getProperties(amplify, { key, options }, StorageAction.GetUrl);
27
- }
35
+ const finalKey =
36
+ inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
28
37
 
29
- const { s3Config, keyPrefix, bucket } = await resolveS3ConfigAndInput(
30
- amplify,
31
- options,
32
- );
38
+ if (getUrlOptions?.validateObjectExistence) {
39
+ await getProperties(
40
+ amplify,
41
+ {
42
+ options: getUrlOptions,
43
+ ...((inputType === STORAGE_INPUT_KEY
44
+ ? { key: input.key }
45
+ : { path: input.path }) as GetUrlInput),
46
+ },
47
+ StorageAction.GetUrl,
48
+ );
49
+ }
33
50
 
34
- let urlExpirationInSec = options?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;
51
+ let urlExpirationInSec =
52
+ getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;
35
53
  const awsCredExpiration = s3Config.credentials?.expiration;
36
54
  if (awsCredExpiration) {
37
55
  const awsCredExpirationInSec = Math.floor(
@@ -54,7 +72,7 @@ export const getUrl = async (
54
72
  },
55
73
  {
56
74
  Bucket: bucket,
57
- Key: `${keyPrefix}${key}`,
75
+ Key: finalKey,
58
76
  },
59
77
  ),
60
78
  expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),
@@ -5,23 +5,37 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { StorageAction } from '@aws-amplify/core/internals/utils';
6
6
 
7
7
  import { RemoveInput, RemoveOutput } from '../../types';
8
- import { resolveS3ConfigAndInput } from '../../utils';
8
+ import {
9
+ resolveS3ConfigAndInput,
10
+ validateStorageOperationInput,
11
+ } from '../../utils';
9
12
  import { deleteObject } from '../../utils/client';
10
13
  import { getStorageUserAgentValue } from '../../utils/userAgent';
11
14
  import { logger } from '../../../../utils';
15
+ import { STORAGE_INPUT_KEY } from '../../utils/constants';
12
16
 
13
17
  export const remove = async (
14
18
  amplify: AmplifyClassV6,
15
19
  input: RemoveInput,
16
20
  ): Promise<RemoveOutput> => {
17
- const { key, options = {} } = input;
18
- const { s3Config, keyPrefix, bucket } = await resolveS3ConfigAndInput(
19
- amplify,
20
- options,
21
+ const { options = {} } = input ?? {};
22
+ const { s3Config, keyPrefix, bucket, identityId } =
23
+ await resolveS3ConfigAndInput(amplify, options);
24
+
25
+ const { inputType, objectKey } = validateStorageOperationInput(
26
+ input,
27
+ identityId,
21
28
  );
22
29
 
23
- const finalKey = `${keyPrefix}${key}`;
24
- logger.debug(`remove "${key}" from "${finalKey}".`);
30
+ let finalKey;
31
+ if (inputType === STORAGE_INPUT_KEY) {
32
+ finalKey = `${keyPrefix}${objectKey}`;
33
+ logger.debug(`remove "${objectKey}" from "${finalKey}".`);
34
+ } else {
35
+ finalKey = objectKey;
36
+ logger.debug(`removing object in path "${finalKey}"`);
37
+ }
38
+
25
39
  await deleteObject(
26
40
  {
27
41
  ...s3Config,
@@ -33,7 +47,11 @@ export const remove = async (
33
47
  },
34
48
  );
35
49
 
36
- return {
37
- key,
38
- };
50
+ return inputType === STORAGE_INPUT_KEY
51
+ ? {
52
+ key: objectKey,
53
+ }
54
+ : {
55
+ path: objectKey,
56
+ };
39
57
  };
@@ -3,18 +3,41 @@
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
5
 
6
- import { RemoveInput, RemoveOutput, S3Exception } from '../types';
7
- import { StorageValidationErrorCode } from '../../../errors/types/validation';
6
+ import {
7
+ RemoveInput,
8
+ RemoveInputKey,
9
+ RemoveInputPath,
10
+ RemoveOutput,
11
+ RemoveOutputKey,
12
+ RemoveOutputPath,
13
+ } from '../types';
8
14
 
9
15
  import { remove as removeInternal } from './internal/remove';
10
16
 
11
- /**
12
- * Remove a file from your S3 bucket.
13
- * @param input - The RemoveInput object.
14
- * @return Output containing the removed object key
15
- * @throws service: {@link S3Exception} - S3 service errors thrown while getting properties
16
- * @throws validation: {@link StorageValidationErrorCode } - Validation errors thrown
17
- */
18
- export const remove = (input: RemoveInput): Promise<RemoveOutput> => {
19
- return removeInternal(Amplify, input);
20
- };
17
+ interface RemoveApi {
18
+ /**
19
+ * Remove a file from your S3 bucket.
20
+ * @param input - The `RemoveInputPath` object.
21
+ * @return Output containing the removed object path.
22
+ * @throws service: `S3Exception` - S3 service errors thrown while while removing the object.
23
+ * @throws validation: `StorageValidationErrorCode` - Validation errors thrown
24
+ * when there is no path or path is empty or path has a leading slash.
25
+ */
26
+ (input: RemoveInputPath): Promise<RemoveOutputPath>;
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/react/build-a-backend/storage/remove | path} instead.
30
+ *
31
+ * Remove a file from your S3 bucket.
32
+ * @param input - The `RemoveInputKey` object.
33
+ * @return Output containing the removed object key
34
+ * @throws service: `S3Exception` - S3 service errors thrown while while removing the object
35
+ * @throws validation: `StorageValidationErrorCode` - Validation errors thrown
36
+ * when there is no key or its empty.
37
+ */
38
+ (input: RemoveInputKey): Promise<RemoveOutputKey>;
39
+ }
40
+
41
+ export const remove: RemoveApi = <Output extends RemoveOutput>(
42
+ input: RemoveInput,
43
+ ): Promise<Output> => removeInternal(Amplify, input) as Promise<Output>;
@@ -1,17 +1,60 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
4
3
  import {
5
4
  AmplifyServer,
6
5
  getAmplifyServerContext,
7
6
  } from '@aws-amplify/core/internals/adapter-core';
8
7
 
9
- import { CopyInput, CopyOutput } from '../../types';
8
+ import {
9
+ CopyInput,
10
+ CopyInputKey,
11
+ CopyInputPath,
12
+ CopyOutput,
13
+ CopyOutputKey,
14
+ CopyOutputPath,
15
+ } from '../../types';
10
16
  import { copy as copyInternal } from '../internal/copy';
11
17
 
12
- export const copy = async (
18
+ interface Copy {
19
+ /**
20
+ * Copy an object from a source to a destination object within the same bucket.
21
+ *
22
+ * @param contextSpec - The isolated server context.
23
+ * @param input - The CopyInputPath object.
24
+ * @returns Output containing the destination object path.
25
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
26
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
27
+ * source or destination path is not defined.
28
+ */
29
+ (
30
+ contextSpec: AmplifyServer.ContextSpec,
31
+ input: CopyInputPath,
32
+ ): Promise<CopyOutputPath>;
33
+ /**
34
+ * @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
35
+ * Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/copy | path} instead.
36
+ *
37
+ * Copy an object from a source to a destination object within the same bucket. Can optionally copy files across
38
+ * different accessLevel or identityId (if source object's accessLevel is 'protected').
39
+ *
40
+ * @param contextSpec - The isolated server context.
41
+ * @param input - The CopyInputKey object.
42
+ * @returns Output containing the destination object key.
43
+ * @throws service: `S3Exception` - Thrown when checking for existence of the object
44
+ * @throws validation: `StorageValidationErrorCode` - Thrown when
45
+ * source or destination key is not defined.
46
+ */
47
+ (
48
+ contextSpec: AmplifyServer.ContextSpec,
49
+ input: CopyInputKey,
50
+ ): Promise<CopyOutputKey>;
51
+ }
52
+
53
+ export const copy: Copy = <Output extends CopyOutput>(
13
54
  contextSpec: AmplifyServer.ContextSpec,
14
55
  input: CopyInput,
15
- ): Promise<CopyOutput> => {
16
- return copyInternal(getAmplifyServerContext(contextSpec).amplify, input);
17
- };
56
+ ): Promise<Output> =>
57
+ copyInternal(
58
+ getAmplifyServerContext(contextSpec).amplify,
59
+ input,
60
+ ) as Promise<Output>;
@@ -6,15 +6,57 @@ import {
6
6
  getAmplifyServerContext,
7
7
  } from '@aws-amplify/core/internals/adapter-core';
8
8
 
9
- import { GetPropertiesInput, GetPropertiesOutput } from '../../types';
9
+ import {
10
+ GetPropertiesInput,
11
+ GetPropertiesInputKey,
12
+ GetPropertiesInputPath,
13
+ GetPropertiesOutput,
14
+ GetPropertiesOutputKey,
15
+ GetPropertiesOutputPath,
16
+ } from '../../types';
10
17
  import { getProperties as getPropertiesInternal } from '../internal/getProperties';
11
18
 
12
- export const getProperties = (
19
+ interface GetProperties {
20
+ /**
21
+ * Gets the properties of a file. The properties include S3 system metadata and
22
+ * the user metadata that was provided when uploading the file.
23
+ *
24
+ * @param contextSpec - The isolated server context.
25
+ * @param input - The `GetPropertiesInputPath` object.
26
+ * @returns Requested object properties.
27
+ * @throws An `S3Exception` when the underlying S3 service returned error.
28
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
29
+ */
30
+ (
31
+ contextSpec: AmplifyServer.ContextSpec,
32
+ input: GetPropertiesInputPath,
33
+ ): Promise<GetPropertiesOutputPath>;
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/get-properties/ | path} instead.
37
+ *
38
+ * Gets the properties of a file. The properties include S3 system metadata and
39
+ * the user metadata that was provided when uploading the file.
40
+ *
41
+ * @param contextSpec - The isolated server context.
42
+ * @param input - The `GetPropertiesInputKey` object.
43
+ * @returns Requested object properties.
44
+ * @throws An `S3Exception` when the underlying S3 service returned error.
45
+ * @throws A `StorageValidationErrorCode` when API call parameters are invalid.
46
+ */
47
+ (
48
+ contextSpec: AmplifyServer.ContextSpec,
49
+ input: GetPropertiesInputKey,
50
+ ): Promise<GetPropertiesOutputKey>;
51
+ }
52
+
53
+ export const getProperties: GetProperties = <
54
+ Output extends GetPropertiesOutput,
55
+ >(
13
56
  contextSpec: AmplifyServer.ContextSpec,
14
57
  input: GetPropertiesInput,
15
- ): Promise<GetPropertiesOutput> => {
16
- return getPropertiesInternal(
58
+ ): Promise<Output> =>
59
+ getPropertiesInternal(
17
60
  getAmplifyServerContext(contextSpec).amplify,
18
61
  input,
19
- );
20
- };
62
+ ) as Promise<Output>;