@aws-amplify/storage 6.5.2 → 6.5.3-multi-bucket.381ca11.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 (35) hide show
  1. package/dist/cjs/errors/types/validation.js +8 -0
  2. package/dist/cjs/errors/types/validation.js.map +1 -1
  3. package/dist/cjs/providers/s3/apis/internal/copy.js +25 -12
  4. package/dist/cjs/providers/s3/apis/internal/copy.js.map +1 -1
  5. package/dist/cjs/providers/s3/apis/internal/list.js +4 -4
  6. package/dist/cjs/providers/s3/apis/internal/list.js.map +1 -1
  7. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js +20 -8
  8. package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js.map +1 -1
  9. package/dist/esm/errors/types/validation.d.ts +2 -0
  10. package/dist/esm/errors/types/validation.mjs +8 -0
  11. package/dist/esm/errors/types/validation.mjs.map +1 -1
  12. package/dist/esm/providers/s3/apis/internal/copy.mjs +25 -12
  13. package/dist/esm/providers/s3/apis/internal/copy.mjs.map +1 -1
  14. package/dist/esm/providers/s3/apis/internal/list.mjs +4 -4
  15. package/dist/esm/providers/s3/apis/internal/list.mjs.map +1 -1
  16. package/dist/esm/providers/s3/types/index.d.ts +1 -1
  17. package/dist/esm/providers/s3/types/inputs.d.ts +2 -2
  18. package/dist/esm/providers/s3/types/options.d.ts +21 -3
  19. package/dist/esm/providers/s3/types/outputs.d.ts +2 -2
  20. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.d.ts +2 -1
  21. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs +20 -8
  22. package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs.map +1 -1
  23. package/dist/esm/types/inputs.d.ts +3 -3
  24. package/dist/esm/types/options.d.ts +0 -2
  25. package/package.json +107 -107
  26. package/src/errors/types/validation.ts +9 -0
  27. package/src/providers/s3/apis/internal/copy.ts +46 -22
  28. package/src/providers/s3/apis/internal/list.ts +10 -6
  29. package/src/providers/s3/types/index.ts +2 -0
  30. package/src/providers/s3/types/inputs.ts +6 -1
  31. package/src/providers/s3/types/options.ts +23 -2
  32. package/src/providers/s3/types/outputs.ts +8 -2
  33. package/src/providers/s3/utils/resolveS3ConfigAndInput.ts +42 -12
  34. package/src/types/inputs.ts +3 -3
  35. package/src/types/options.ts +0 -2
@@ -15,6 +15,8 @@ var StorageValidationErrorCode;
15
15
  StorageValidationErrorCode["NoDestinationPath"] = "NoDestinationPath";
16
16
  StorageValidationErrorCode["NoBucket"] = "NoBucket";
17
17
  StorageValidationErrorCode["NoRegion"] = "NoRegion";
18
+ StorageValidationErrorCode["InvalidStorageBucket"] = "InvalidStorageBucket";
19
+ StorageValidationErrorCode["InvalidCopyOperationStorageBucket"] = "InvalidCopyOperationStorageBucket";
18
20
  StorageValidationErrorCode["InvalidStorageOperationPrefixInput"] = "InvalidStorageOperationPrefixInput";
19
21
  StorageValidationErrorCode["InvalidStorageOperationInput"] = "InvalidStorageOperationInput";
20
22
  StorageValidationErrorCode["InvalidStoragePathInput"] = "InvalidStoragePathInput";
@@ -68,5 +70,11 @@ exports.validationErrorMap = {
68
70
  [StorageValidationErrorCode.InvalidStoragePathInput]: {
69
71
  message: 'Input `path` does not allow a leading slash (/).',
70
72
  },
73
+ [StorageValidationErrorCode.InvalidStorageBucket]: {
74
+ message: 'Unable to lookup bucket from provided name in Amplify configuration.',
75
+ },
76
+ [StorageValidationErrorCode.InvalidCopyOperationStorageBucket]: {
77
+ message: 'Missing bucket option in either source or destination.',
78
+ },
71
79
  };
72
80
  //# sourceMappingURL=validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sources":["../../../../src/errors/types/validation.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.validationErrorMap = exports.StorageValidationErrorCode = void 0;\nvar StorageValidationErrorCode;\n(function (StorageValidationErrorCode) {\n StorageValidationErrorCode[\"NoCredentials\"] = \"NoCredentials\";\n StorageValidationErrorCode[\"NoIdentityId\"] = \"NoIdentityId\";\n StorageValidationErrorCode[\"NoKey\"] = \"NoKey\";\n StorageValidationErrorCode[\"NoSourceKey\"] = \"NoSourceKey\";\n StorageValidationErrorCode[\"NoDestinationKey\"] = \"NoDestinationKey\";\n StorageValidationErrorCode[\"NoSourcePath\"] = \"NoSourcePath\";\n StorageValidationErrorCode[\"NoDestinationPath\"] = \"NoDestinationPath\";\n StorageValidationErrorCode[\"NoBucket\"] = \"NoBucket\";\n StorageValidationErrorCode[\"NoRegion\"] = \"NoRegion\";\n StorageValidationErrorCode[\"InvalidStorageOperationPrefixInput\"] = \"InvalidStorageOperationPrefixInput\";\n StorageValidationErrorCode[\"InvalidStorageOperationInput\"] = \"InvalidStorageOperationInput\";\n StorageValidationErrorCode[\"InvalidStoragePathInput\"] = \"InvalidStoragePathInput\";\n StorageValidationErrorCode[\"InvalidUploadSource\"] = \"InvalidUploadSource\";\n StorageValidationErrorCode[\"ObjectIsTooLarge\"] = \"ObjectIsTooLarge\";\n StorageValidationErrorCode[\"UrlExpirationMaxLimitExceed\"] = \"UrlExpirationMaxLimitExceed\";\n})(StorageValidationErrorCode = exports.StorageValidationErrorCode || (exports.StorageValidationErrorCode = {}));\nexports.validationErrorMap = {\n [StorageValidationErrorCode.NoCredentials]: {\n message: 'Credentials should not be empty.',\n },\n [StorageValidationErrorCode.NoIdentityId]: {\n message: 'Missing identity ID when accessing objects in protected or private access level.',\n },\n [StorageValidationErrorCode.NoKey]: {\n message: 'Missing key in api call.',\n },\n [StorageValidationErrorCode.NoSourceKey]: {\n message: 'Missing source key in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationKey]: {\n message: 'Missing destination key in copy api call.',\n },\n [StorageValidationErrorCode.NoSourcePath]: {\n message: 'Missing source path in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationPath]: {\n message: 'Missing destination path in copy api call.',\n },\n [StorageValidationErrorCode.NoBucket]: {\n message: 'Missing bucket name while accessing object.',\n },\n [StorageValidationErrorCode.NoRegion]: {\n message: 'Missing region while accessing object.',\n },\n [StorageValidationErrorCode.UrlExpirationMaxLimitExceed]: {\n message: 'Url Expiration can not be greater than 7 Days.',\n },\n [StorageValidationErrorCode.ObjectIsTooLarge]: {\n message: 'Object size cannot not be greater than 5TB.',\n },\n [StorageValidationErrorCode.InvalidUploadSource]: {\n message: 'Upload source type can only be a `Blob`, `File`, `ArrayBuffer`, or `string`.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationInput]: {\n message: 'Path or key parameter must be specified in the input. Both can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationPrefixInput]: {\n message: 'Both path and prefix can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStoragePathInput]: {\n message: 'Input `path` does not allow a leading slash (/).',\n },\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AACzE,IAAI,0BAA0B,CAAC;AAC/B,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAClE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAClD,IAAI,0BAA0B,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC;AAC9D,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACxE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,mBAAmB,CAAC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B,GAAG;AACpD,QAAQ,OAAO,EAAE,4CAA4C;AAC7D,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,QAAQ,GAAG;AAC3C,QAAQ,OAAO,EAAE,6CAA6C;AAC9D,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,QAAQ,GAAG;AAC3C,QAAQ,OAAO,EAAE,wCAAwC;AACzD,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,2BAA2B,GAAG;AAC9D,QAAQ,OAAO,EAAE,gDAAgD;AACjE,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,gBAAgB,GAAG;AACnD,QAAQ,OAAO,EAAE,6CAA6C;AAC9D,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,mBAAmB,GAAG;AACtD,QAAQ,OAAO,EAAE,8EAA8E;AAC/F,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,4BAA4B,GAAG;AAC/D,QAAQ,OAAO,EAAE,mGAAmG;AACpH,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,kCAAkC,GAAG;AACrE,QAAQ,OAAO,EAAE,6DAA6D;AAC9E,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,uBAAuB,GAAG;AAC1D,QAAQ,OAAO,EAAE,kDAAkD;AACnE,KAAK;AACL,CAAC;;"}
1
+ {"version":3,"file":"validation.js","sources":["../../../../src/errors/types/validation.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.validationErrorMap = exports.StorageValidationErrorCode = void 0;\nvar StorageValidationErrorCode;\n(function (StorageValidationErrorCode) {\n StorageValidationErrorCode[\"NoCredentials\"] = \"NoCredentials\";\n StorageValidationErrorCode[\"NoIdentityId\"] = \"NoIdentityId\";\n StorageValidationErrorCode[\"NoKey\"] = \"NoKey\";\n StorageValidationErrorCode[\"NoSourceKey\"] = \"NoSourceKey\";\n StorageValidationErrorCode[\"NoDestinationKey\"] = \"NoDestinationKey\";\n StorageValidationErrorCode[\"NoSourcePath\"] = \"NoSourcePath\";\n StorageValidationErrorCode[\"NoDestinationPath\"] = \"NoDestinationPath\";\n StorageValidationErrorCode[\"NoBucket\"] = \"NoBucket\";\n StorageValidationErrorCode[\"NoRegion\"] = \"NoRegion\";\n StorageValidationErrorCode[\"InvalidStorageBucket\"] = \"InvalidStorageBucket\";\n StorageValidationErrorCode[\"InvalidCopyOperationStorageBucket\"] = \"InvalidCopyOperationStorageBucket\";\n StorageValidationErrorCode[\"InvalidStorageOperationPrefixInput\"] = \"InvalidStorageOperationPrefixInput\";\n StorageValidationErrorCode[\"InvalidStorageOperationInput\"] = \"InvalidStorageOperationInput\";\n StorageValidationErrorCode[\"InvalidStoragePathInput\"] = \"InvalidStoragePathInput\";\n StorageValidationErrorCode[\"InvalidUploadSource\"] = \"InvalidUploadSource\";\n StorageValidationErrorCode[\"ObjectIsTooLarge\"] = \"ObjectIsTooLarge\";\n StorageValidationErrorCode[\"UrlExpirationMaxLimitExceed\"] = \"UrlExpirationMaxLimitExceed\";\n})(StorageValidationErrorCode = exports.StorageValidationErrorCode || (exports.StorageValidationErrorCode = {}));\nexports.validationErrorMap = {\n [StorageValidationErrorCode.NoCredentials]: {\n message: 'Credentials should not be empty.',\n },\n [StorageValidationErrorCode.NoIdentityId]: {\n message: 'Missing identity ID when accessing objects in protected or private access level.',\n },\n [StorageValidationErrorCode.NoKey]: {\n message: 'Missing key in api call.',\n },\n [StorageValidationErrorCode.NoSourceKey]: {\n message: 'Missing source key in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationKey]: {\n message: 'Missing destination key in copy api call.',\n },\n [StorageValidationErrorCode.NoSourcePath]: {\n message: 'Missing source path in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationPath]: {\n message: 'Missing destination path in copy api call.',\n },\n [StorageValidationErrorCode.NoBucket]: {\n message: 'Missing bucket name while accessing object.',\n },\n [StorageValidationErrorCode.NoRegion]: {\n message: 'Missing region while accessing object.',\n },\n [StorageValidationErrorCode.UrlExpirationMaxLimitExceed]: {\n message: 'Url Expiration can not be greater than 7 Days.',\n },\n [StorageValidationErrorCode.ObjectIsTooLarge]: {\n message: 'Object size cannot not be greater than 5TB.',\n },\n [StorageValidationErrorCode.InvalidUploadSource]: {\n message: 'Upload source type can only be a `Blob`, `File`, `ArrayBuffer`, or `string`.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationInput]: {\n message: 'Path or key parameter must be specified in the input. Both can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationPrefixInput]: {\n message: 'Both path and prefix can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStoragePathInput]: {\n message: 'Input `path` does not allow a leading slash (/).',\n },\n [StorageValidationErrorCode.InvalidStorageBucket]: {\n message: 'Unable to lookup bucket from provided name in Amplify configuration.',\n },\n [StorageValidationErrorCode.InvalidCopyOperationStorageBucket]: {\n message: 'Missing bucket option in either source or destination.',\n },\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AACzE,IAAI,0BAA0B,CAAC;AAC/B,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAClE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAClD,IAAI,0BAA0B,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC;AAC9D,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACxE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GA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../utils/userAgent");
13
13
  const utils_3 = require("../../../../utils");
14
14
  const isCopyInputWithPath = (input) => (0, utils_2.isInputWithPath)(input.source);
15
+ const storageBucketAssertion = (sourceBucket, destBucket) => {
16
+ /** For multi-bucket, both source and destination bucket needs to be passed in
17
+ * or both can be undefined and we fallback to singleton's default value
18
+ */
19
+ (0, assertValidationError_1.assertValidationError)(
20
+ // Both src & dest bucket option is present is acceptable
21
+ (sourceBucket !== undefined && destBucket !== undefined) ||
22
+ // or both are undefined is also acceptable
23
+ (!destBucket && !sourceBucket), validation_1.StorageValidationErrorCode.InvalidCopyOperationStorageBucket);
24
+ };
15
25
  const copy = async (amplify, input) => {
16
26
  return isCopyInputWithPath(input)
17
27
  ? copyWithPath(amplify, input)
@@ -20,41 +30,44 @@ const copy = async (amplify, input) => {
20
30
  exports.copy = copy;
21
31
  const copyWithPath = async (amplify, input) => {
22
32
  const { source, destination } = input;
23
- const { s3Config, bucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify);
33
+ storageBucketAssertion(source.bucket, destination.bucket);
34
+ const { bucket: sourceBucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.source);
35
+ const { s3Config, bucket: destBucket } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
24
36
  (0, assertValidationError_1.assertValidationError)(!!source.path, validation_1.StorageValidationErrorCode.NoSourcePath);
25
37
  (0, assertValidationError_1.assertValidationError)(!!destination.path, validation_1.StorageValidationErrorCode.NoDestinationPath);
26
38
  const { objectKey: sourcePath } = (0, utils_2.validateStorageOperationInput)(source, identityId);
27
39
  const { objectKey: destinationPath } = (0, utils_2.validateStorageOperationInput)(destination, identityId);
28
- const finalCopySource = `${bucket}/${sourcePath}`;
40
+ const finalCopySource = `${sourceBucket}/${sourcePath}`;
29
41
  const finalCopyDestination = destinationPath;
30
42
  utils_3.logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
31
43
  await serviceCopy({
32
44
  source: finalCopySource,
33
45
  destination: finalCopyDestination,
34
- bucket,
46
+ bucket: destBucket,
35
47
  s3Config,
36
48
  });
37
49
  return { path: finalCopyDestination };
38
50
  };
39
51
  /** @deprecated Use {@link copyWithPath} instead. */
40
52
  const copyWithKey = async (amplify, input) => {
41
- const { source: { key: sourceKey }, destination: { key: destinationKey }, } = input;
42
- (0, assertValidationError_1.assertValidationError)(!!sourceKey, validation_1.StorageValidationErrorCode.NoSourceKey);
43
- (0, assertValidationError_1.assertValidationError)(!!destinationKey, validation_1.StorageValidationErrorCode.NoDestinationKey);
44
- const { s3Config, bucket, keyPrefix: sourceKeyPrefix, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.source);
45
- const { keyPrefix: destinationKeyPrefix } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
53
+ const { source, destination } = input;
54
+ storageBucketAssertion(source.bucket, destination.bucket);
55
+ (0, assertValidationError_1.assertValidationError)(!!source.key, validation_1.StorageValidationErrorCode.NoSourceKey);
56
+ (0, assertValidationError_1.assertValidationError)(!!destination.key, validation_1.StorageValidationErrorCode.NoDestinationKey);
57
+ const { bucket: sourceBucket, keyPrefix: sourceKeyPrefix } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, source);
58
+ const { s3Config, bucket: destBucket, keyPrefix: destinationKeyPrefix, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
46
59
  // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is "protected", currently it's ${srcLevel}`
47
- const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
48
- const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
60
+ const finalCopySource = `${sourceBucket}/${sourceKeyPrefix}${source.key}`;
61
+ const finalCopyDestination = `${destinationKeyPrefix}${destination.key}`;
49
62
  utils_3.logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
50
63
  await serviceCopy({
51
64
  source: finalCopySource,
52
65
  destination: finalCopyDestination,
53
- bucket,
66
+ bucket: destBucket,
54
67
  s3Config,
55
68
  });
56
69
  return {
57
- key: destinationKey,
70
+ key: destination.key,
58
71
  };
59
72
  };
60
73
  exports.copyWithKey = copyWithKey;
@@ -1 +1 @@
1
- {"version":3,"file":"copy.js","sources":["../../../../../../src/providers/s3/apis/internal/copy.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.copyWithKey = exports.copy = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst utils_2 = require(\"../../utils\");\nconst validation_1 = require(\"../../../../errors/types/validation\");\nconst assertValidationError_1 = require(\"../../../../errors/utils/assertValidationError\");\nconst client_1 = require(\"../../utils/client\");\nconst userAgent_1 = require(\"../../utils/userAgent\");\nconst utils_3 = require(\"../../../../utils\");\nconst isCopyInputWithPath = (input) => (0, utils_2.isInputWithPath)(input.source);\nconst copy = async (amplify, input) => {\n return isCopyInputWithPath(input)\n ? copyWithPath(amplify, input)\n : (0, exports.copyWithKey)(amplify, input);\n};\nexports.copy = copy;\nconst copyWithPath = async (amplify, input) => {\n const { source, destination } = input;\n const { s3Config, bucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify);\n (0, assertValidationError_1.assertValidationError)(!!source.path, validation_1.StorageValidationErrorCode.NoSourcePath);\n (0, assertValidationError_1.assertValidationError)(!!destination.path, validation_1.StorageValidationErrorCode.NoDestinationPath);\n const { objectKey: sourcePath } = (0, utils_2.validateStorageOperationInput)(source, identityId);\n const { objectKey: destinationPath } = (0, utils_2.validateStorageOperationInput)(destination, identityId);\n const finalCopySource = `${bucket}/${sourcePath}`;\n const finalCopyDestination = destinationPath;\n utils_3.logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket,\n s3Config,\n });\n return { path: finalCopyDestination };\n};\n/** @deprecated Use {@link copyWithPath} instead. */\nconst copyWithKey = async (amplify, input) => {\n const { source: { key: sourceKey }, destination: { key: destinationKey }, } = input;\n (0, assertValidationError_1.assertValidationError)(!!sourceKey, validation_1.StorageValidationErrorCode.NoSourceKey);\n (0, assertValidationError_1.assertValidationError)(!!destinationKey, validation_1.StorageValidationErrorCode.NoDestinationKey);\n const { s3Config, bucket, keyPrefix: sourceKeyPrefix, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.source);\n const { keyPrefix: destinationKeyPrefix } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is \"protected\", currently it's ${srcLevel}`\n const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;\n const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;\n utils_3.logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket,\n s3Config,\n });\n return {\n key: destinationKey,\n };\n};\nexports.copyWithKey = copyWithKey;\nconst serviceCopy = async ({ source, destination, bucket, s3Config, }) => {\n await (0, client_1.copyObject)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.Copy),\n }, {\n Bucket: bucket,\n CopySource: source,\n Key: destination,\n MetadataDirective: 'COPY', // Copies over metadata like contentType as well\n });\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,G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AM;AACtB,QAAQ,UAAU,EAAE,MAAM;AAC1B,QAAQ,GAAG,EAAE,WAAW;AACxB,QAAQ,iBAAiB,EAAE,MAAM;AACjC,KAAK,CAAC,CAAC;AACP,CAAC;;"}
1
+ {"version":3,"file":"copy.js","sources":["../../../../../../src/providers/s3/apis/internal/copy.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.copyWithKey = exports.copy = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst utils_2 = require(\"../../utils\");\nconst validation_1 = require(\"../../../../errors/types/validation\");\nconst assertValidationError_1 = require(\"../../../../errors/utils/assertValidationError\");\nconst client_1 = require(\"../../utils/client\");\nconst userAgent_1 = require(\"../../utils/userAgent\");\nconst utils_3 = require(\"../../../../utils\");\nconst isCopyInputWithPath = (input) => (0, utils_2.isInputWithPath)(input.source);\nconst storageBucketAssertion = (sourceBucket, destBucket) => {\n /** For multi-bucket, both source and destination bucket needs to be passed in\n * or both can be undefined and we fallback to singleton's default value\n */\n (0, assertValidationError_1.assertValidationError)(\n // Both src & dest bucket option is present is acceptable\n (sourceBucket !== undefined && destBucket !== undefined) ||\n // or both are undefined is also acceptable\n (!destBucket && !sourceBucket), validation_1.StorageValidationErrorCode.InvalidCopyOperationStorageBucket);\n};\nconst copy = async (amplify, input) => {\n return isCopyInputWithPath(input)\n ? copyWithPath(amplify, input)\n : (0, exports.copyWithKey)(amplify, input);\n};\nexports.copy = copy;\nconst copyWithPath = async (amplify, input) => {\n const { source, destination } = input;\n storageBucketAssertion(source.bucket, destination.bucket);\n const { bucket: sourceBucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.source);\n const { s3Config, bucket: destBucket } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n (0, assertValidationError_1.assertValidationError)(!!source.path, validation_1.StorageValidationErrorCode.NoSourcePath);\n (0, assertValidationError_1.assertValidationError)(!!destination.path, validation_1.StorageValidationErrorCode.NoDestinationPath);\n const { objectKey: sourcePath } = (0, utils_2.validateStorageOperationInput)(source, identityId);\n const { objectKey: destinationPath } = (0, utils_2.validateStorageOperationInput)(destination, identityId);\n const finalCopySource = `${sourceBucket}/${sourcePath}`;\n const finalCopyDestination = destinationPath;\n utils_3.logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket: destBucket,\n s3Config,\n });\n return { path: finalCopyDestination };\n};\n/** @deprecated Use {@link copyWithPath} instead. */\nconst copyWithKey = async (amplify, input) => {\n const { source, destination } = input;\n storageBucketAssertion(source.bucket, destination.bucket);\n (0, assertValidationError_1.assertValidationError)(!!source.key, validation_1.StorageValidationErrorCode.NoSourceKey);\n (0, assertValidationError_1.assertValidationError)(!!destination.key, validation_1.StorageValidationErrorCode.NoDestinationKey);\n const { bucket: sourceBucket, keyPrefix: sourceKeyPrefix } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, source);\n const { s3Config, bucket: destBucket, keyPrefix: destinationKeyPrefix, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is \"protected\", currently it's ${srcLevel}`\n const finalCopySource = `${sourceBucket}/${sourceKeyPrefix}${source.key}`;\n const finalCopyDestination = `${destinationKeyPrefix}${destination.key}`;\n utils_3.logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket: destBucket,\n s3Config,\n });\n return {\n key: destination.key,\n };\n};\nexports.copyWithKey = copyWithKey;\nconst serviceCopy = async ({ source, destination, bucket, s3Config, }) => {\n await (0, client_1.copyObject)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.Copy),\n }, {\n Bucket: bucket,\n CopySource: source,\n Key: destination,\n MetadataDirective: 'COPY', // Copies over metadata like contentType as well\n });\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,YAAY,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACpE,MAAM,uBAAuB,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC1F,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC7C,MAAM,mBAAmB,GAAG,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AAClF,MAAM,sBAAsB,GAAG,CAAC,YAAY,EAAE,UAAU,KAAK;AAC7D;AACA;AACA;AACA,IAAI,IAAI,uBAAuB,CAAC,qBAAqB;AACrD;AACA,IAAI,CAAC,YAAY,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS;AAC3D;AACA,SAAS,CAAC,UAAU,IAAI,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,CAAC;AACnH,CAAC,CAAC;AACF,MAAM,IAAI,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AACvC,IAAI,OAAO,mB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
  MaxKeys: options?.listAll ? undefined : options?.pageSize,
28
28
  ContinuationToken: options?.listAll ? undefined : options?.nextToken,
29
- Delimiter: getDelimiter(options.subpathStrategy),
29
+ Delimiter: getDelimiter(options),
30
30
  };
31
31
  utils_3.logger.debug(`listing items from "${listParams.Prefix}"`);
32
32
  const listInputArgs = {
@@ -161,9 +161,9 @@ const mapCommonPrefixesToExcludedSubpaths = (commonPrefixes) => {
161
161
  return mappedSubpaths;
162
162
  }, []);
163
163
  };
164
- const getDelimiter = (subpathStrategy) => {
165
- if (subpathStrategy?.strategy === 'exclude') {
166
- return subpathStrategy?.delimiter ?? constants_1.DEFAULT_DELIMITER;
164
+ const getDelimiter = (options) => {
165
+ if (options?.subpathStrategy?.strategy === 'exclude') {
166
+ return options?.subpathStrategy?.delimiter ?? constants_1.DEFAULT_DELIMITER;
167
167
  }
168
168
  };
169
169
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sources":["../../../../../../src/providers/s3/apis/internal/list.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.list = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst utils_2 = require(\"../../utils\");\nconst client_1 = require(\"../../utils/client\");\nconst userAgent_1 = require(\"../../utils/userAgent\");\nconst utils_3 = require(\"../../../../utils\");\nconst constants_1 = require(\"../../utils/constants\");\nconst MAX_PAGE_SIZE = 1000;\nconst list = async (amplify, input) => {\n const { options = {} } = input;\n const { s3Config, bucket, keyPrefix: generatedPrefix, identityId, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, options);\n const { inputType, objectKey } = (0, utils_2.validateStorageOperationInputWithPrefix)(input, identityId);\n const isInputWithPrefix = inputType === constants_1.STORAGE_INPUT_PREFIX;\n // @ts-expect-error pageSize and nextToken should not coexist with listAll\n if (options?.listAll && (options?.pageSize || options?.nextToken)) {\n const anyOptions = options;\n utils_3.logger.debug(`listAll is set to true, ignoring ${anyOptions?.pageSize ? `pageSize: ${anyOptions?.pageSize}` : ''} ${anyOptions?.nextToken ? `nextToken: ${anyOptions?.nextToken}` : ''}.`);\n }\n const listParams = {\n Bucket: bucket,\n Prefix: isInputWithPrefix ? `${generatedPrefix}${objectKey}` : objectKey,\n MaxKeys: options?.listAll ? undefined : options?.pageSize,\n ContinuationToken: options?.listAll ? undefined : options?.nextToken,\n Delimiter: getDelimiter(options.subpathStrategy),\n };\n utils_3.logger.debug(`listing items from \"${listParams.Prefix}\"`);\n const listInputArgs = {\n s3Config,\n listParams,\n };\n if (options.listAll) {\n if (isInputWithPrefix) {\n return _listAllWithPrefix({\n ...listInputArgs,\n generatedPrefix,\n });\n }\n else {\n return _listAllWithPath(listInputArgs);\n }\n }\n else {\n if (isInputWithPrefix) {\n return _listWithPrefix({ ...listInputArgs, generatedPrefix });\n }\n else {\n return _listWithPath(listInputArgs);\n }\n }\n};\nexports.list = list;\n/** @deprecated Use {@link _listAllWithPath} instead. */\nconst _listAllWithPrefix = async ({ s3Config, listParams, generatedPrefix, }) => {\n const listResult = [];\n let continuationToken = listParams.ContinuationToken;\n do {\n const { items: pageResults, nextToken: pageNextToken } = await _listWithPrefix({\n generatedPrefix,\n s3Config,\n listParams: {\n ...listParams,\n ContinuationToken: continuationToken,\n MaxKeys: MAX_PAGE_SIZE,\n },\n });\n listResult.push(...pageResults);\n continuationToken = pageNextToken;\n } while (continuationToken);\n return {\n items: listResult,\n };\n};\n/** @deprecated Use {@link _listWithPath} instead. */\nconst _listWithPrefix = async ({ s3Config, listParams, generatedPrefix, }) => {\n const listParamsClone = { ...listParams };\n if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {\n utils_3.logger.debug(`defaulting pageSize to ${MAX_PAGE_SIZE}.`);\n listParamsClone.MaxKeys = MAX_PAGE_SIZE;\n }\n const response = await (0, client_1.listObjectsV2)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.List),\n }, listParamsClone);\n if (!response?.Contents) {\n return {\n items: [],\n };\n }\n return {\n items: response.Contents.map(item => ({\n key: generatedPrefix\n ? item.Key.substring(generatedPrefix.length)\n : item.Key,\n eTag: item.ETag,\n lastModified: item.LastModified,\n size: item.Size,\n })),\n nextToken: response.NextContinuationToken,\n };\n};\nconst _listAllWithPath = async ({ s3Config, listParams, }) => {\n const listResult = [];\n const excludedSubpaths = [];\n let continuationToken = listParams.ContinuationToken;\n do {\n const { items: pageResults, excludedSubpaths: pageExcludedSubpaths, nextToken: pageNextToken, } = await _listWithPath({\n s3Config,\n listParams: {\n ...listParams,\n ContinuationToken: continuationToken,\n MaxKeys: MAX_PAGE_SIZE,\n },\n });\n listResult.push(...pageResults);\n excludedSubpaths.push(...(pageExcludedSubpaths ?? []));\n continuationToken = pageNextToken;\n } while (continuationToken);\n return {\n items: listResult,\n excludedSubpaths,\n };\n};\nconst _listWithPath = async ({ s3Config, listParams, }) => {\n const listParamsClone = { ...listParams };\n if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {\n utils_3.logger.debug(`defaulting pageSize to ${MAX_PAGE_SIZE}.`);\n listParamsClone.MaxKeys = MAX_PAGE_SIZE;\n }\n const { Contents: contents, NextContinuationToken: nextContinuationToken, CommonPrefixes: commonPrefixes, } = await (0, client_1.listObjectsV2)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.List),\n }, listParamsClone);\n const excludedSubpaths = commonPrefixes && mapCommonPrefixesToExcludedSubpaths(commonPrefixes);\n if (!contents) {\n return {\n items: [],\n excludedSubpaths,\n };\n }\n return {\n items: contents.map(item => ({\n path: item.Key,\n eTag: item.ETag,\n lastModified: item.LastModified,\n size: item.Size,\n })),\n nextToken: nextContinuationToken,\n excludedSubpaths,\n };\n};\nconst mapCommonPrefixesToExcludedSubpaths = (commonPrefixes) => {\n return commonPrefixes.reduce((mappedSubpaths, { Prefix }) => {\n if (Prefix) {\n mappedSubpaths.push(Prefix);\n }\n return mappedSubpaths;\n }, []);\n};\nconst getDelimiter = (subpathStrategy) => {\n if (subpathStrategy?.strategy === 'exclude') {\n return subpathStrategy?.delimiter ?? constants_1.DEFAULT_DELIMITER;\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AACtB,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACrD,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,IAAI,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AACvC,IAAI,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;AACnC,IAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,GAAG,GAAG,MAAM,IAAI,OAAO,CAAC,uBAAuB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACvI,IAAI,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,OAAO,CAAC,uCAAuC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAC7G,IAAI,MAAM,iBAAiB,GAAG,SAAS,KAAK,WAAW,CA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KAAK;AACL,CAAC;;"}
1
+ {"version":3,"file":"list.js","sources":["../../../../../../src/providers/s3/apis/internal/list.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.list = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst utils_2 = require(\"../../utils\");\nconst client_1 = require(\"../../utils/client\");\nconst userAgent_1 = require(\"../../utils/userAgent\");\nconst utils_3 = require(\"../../../../utils\");\nconst constants_1 = require(\"../../utils/constants\");\nconst MAX_PAGE_SIZE = 1000;\nconst list = async (amplify, input) => {\n const { options = {} } = input;\n const { s3Config, bucket, keyPrefix: generatedPrefix, identityId, } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, options);\n const { inputType, objectKey } = (0, utils_2.validateStorageOperationInputWithPrefix)(input, identityId);\n const isInputWithPrefix = inputType === constants_1.STORAGE_INPUT_PREFIX;\n // @ts-expect-error pageSize and nextToken should not coexist with listAll\n if (options?.listAll && (options?.pageSize || options?.nextToken)) {\n const anyOptions = options;\n utils_3.logger.debug(`listAll is set to true, ignoring ${anyOptions?.pageSize ? `pageSize: ${anyOptions?.pageSize}` : ''} ${anyOptions?.nextToken ? `nextToken: ${anyOptions?.nextToken}` : ''}.`);\n }\n const listParams = {\n Bucket: bucket,\n Prefix: isInputWithPrefix ? `${generatedPrefix}${objectKey}` : objectKey,\n MaxKeys: options?.listAll ? undefined : options?.pageSize,\n ContinuationToken: options?.listAll ? undefined : options?.nextToken,\n Delimiter: getDelimiter(options),\n };\n utils_3.logger.debug(`listing items from \"${listParams.Prefix}\"`);\n const listInputArgs = {\n s3Config,\n listParams,\n };\n if (options.listAll) {\n if (isInputWithPrefix) {\n return _listAllWithPrefix({\n ...listInputArgs,\n generatedPrefix,\n });\n }\n else {\n return _listAllWithPath(listInputArgs);\n }\n }\n else {\n if (isInputWithPrefix) {\n return _listWithPrefix({ ...listInputArgs, generatedPrefix });\n }\n else {\n return _listWithPath(listInputArgs);\n }\n }\n};\nexports.list = list;\n/** @deprecated Use {@link _listAllWithPath} instead. */\nconst _listAllWithPrefix = async ({ s3Config, listParams, generatedPrefix, }) => {\n const listResult = [];\n let continuationToken = listParams.ContinuationToken;\n do {\n const { items: pageResults, nextToken: pageNextToken } = await _listWithPrefix({\n generatedPrefix,\n s3Config,\n listParams: {\n ...listParams,\n ContinuationToken: continuationToken,\n MaxKeys: MAX_PAGE_SIZE,\n },\n });\n listResult.push(...pageResults);\n continuationToken = pageNextToken;\n } while (continuationToken);\n return {\n items: listResult,\n };\n};\n/** @deprecated Use {@link _listWithPath} instead. */\nconst _listWithPrefix = async ({ s3Config, listParams, generatedPrefix, }) => {\n const listParamsClone = { ...listParams };\n if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {\n utils_3.logger.debug(`defaulting pageSize to ${MAX_PAGE_SIZE}.`);\n listParamsClone.MaxKeys = MAX_PAGE_SIZE;\n }\n const response = await (0, client_1.listObjectsV2)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.List),\n }, listParamsClone);\n if (!response?.Contents) {\n return {\n items: [],\n };\n }\n return {\n items: response.Contents.map(item => ({\n key: generatedPrefix\n ? item.Key.substring(generatedPrefix.length)\n : item.Key,\n eTag: item.ETag,\n lastModified: item.LastModified,\n size: item.Size,\n })),\n nextToken: response.NextContinuationToken,\n };\n};\nconst _listAllWithPath = async ({ s3Config, listParams, }) => {\n const listResult = [];\n const excludedSubpaths = [];\n let continuationToken = listParams.ContinuationToken;\n do {\n const { items: pageResults, excludedSubpaths: pageExcludedSubpaths, nextToken: pageNextToken, } = await _listWithPath({\n s3Config,\n listParams: {\n ...listParams,\n ContinuationToken: continuationToken,\n MaxKeys: MAX_PAGE_SIZE,\n },\n });\n listResult.push(...pageResults);\n excludedSubpaths.push(...(pageExcludedSubpaths ?? []));\n continuationToken = pageNextToken;\n } while (continuationToken);\n return {\n items: listResult,\n excludedSubpaths,\n };\n};\nconst _listWithPath = async ({ s3Config, listParams, }) => {\n const listParamsClone = { ...listParams };\n if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {\n utils_3.logger.debug(`defaulting pageSize to ${MAX_PAGE_SIZE}.`);\n listParamsClone.MaxKeys = MAX_PAGE_SIZE;\n }\n const { Contents: contents, NextContinuationToken: nextContinuationToken, CommonPrefixes: commonPrefixes, } = await (0, client_1.listObjectsV2)({\n ...s3Config,\n userAgentValue: (0, userAgent_1.getStorageUserAgentValue)(utils_1.StorageAction.List),\n }, listParamsClone);\n const excludedSubpaths = commonPrefixes && mapCommonPrefixesToExcludedSubpaths(commonPrefixes);\n if (!contents) {\n return {\n items: [],\n excludedSubpaths,\n };\n }\n return {\n items: contents.map(item => ({\n path: item.Key,\n eTag: item.ETag,\n lastModified: item.LastModified,\n size: item.Size,\n })),\n nextToken: nextContinuationToken,\n excludedSubpaths,\n };\n};\nconst mapCommonPrefixesToExcludedSubpaths = (commonPrefixes) => {\n return commonPrefixes.reduce((mappedSubpaths, { Prefix }) => {\n if (Prefix) {\n mappedSubpaths.push(Prefix);\n }\n return mappedSubpaths;\n }, []);\n};\nconst getDelimiter = (options) => {\n if (options?.subpathStrategy?.strategy === 'exclude') {\n return options?.subpathStrategy?.delimiter ?? constants_1.DEFAULT_DELIMITER;\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AACtB,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,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,CAAC,YAAY;AAC3C,YAAY,IAAI,EAAE,IAAI,CAAC,IAAI;AAC3B,SAAS,CAAC,CAAC;AACX,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,gBAAgB;AACxB,KAAK,CAAC;AACN,CAAC,CAAC;AACF,MAAM,mCAAmC,GAAG,CAAC,cAAc,KAAK;AAChE,IAAI,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,KAAK;AACjE,QAAQ,IAAI,MAAM,EAAE;AACpB,YAAY,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACxC,SAAS;AACT,QAAQ,OAAO,cAAc,CAAC;AAC9B,KAAK,EAAE,EAAE,CAAC,CAAC;AACX,CAAC,CAAC;AACF,MAAM,YAAY,GAAG,CAAC,OAAO,KAAK;AAClC,IAAI,IAAI,OAAO,EAAE,eAAe,EAAE,QAAQ,KAAK,SAAS,EAAE;AAC1D,QAAQ,OAAO,OAAO,EAAE,eAAe,EAAE,SAAS,IAAI,WAAW,CAAC,iBAAiB,CAAC;AACpF,KAAK;AACL,CAAC;;"}
@@ -37,17 +37,16 @@ const resolveS3ConfigAndInput = async (amplify, apiOptions) => {
37
37
  (0, assertValidationError_1.assertValidationError)(!!credentials, validation_1.StorageValidationErrorCode.NoCredentials);
38
38
  return credentials;
39
39
  };
40
- const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } = amplify.getConfig()?.Storage?.S3 ?? {};
40
+ const { bucket: defaultBucket, region: defaultRegion, dangerouslyConnectToHttpEndpointForTesting, buckets, } = amplify.getConfig()?.Storage?.S3 ?? {};
41
+ const { bucket = defaultBucket, region = defaultRegion } = (apiOptions?.bucket && resolveBucketConfig(apiOptions, buckets)) || {};
41
42
  (0, assertValidationError_1.assertValidationError)(!!bucket, validation_1.StorageValidationErrorCode.NoBucket);
42
43
  (0, assertValidationError_1.assertValidationError)(!!region, validation_1.StorageValidationErrorCode.NoRegion);
43
44
  const { defaultAccessLevel, prefixResolver = resolvePrefix_1.resolvePrefix, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};
44
- const keyPrefix = await prefixResolver({
45
- accessLevel: apiOptions?.accessLevel ?? defaultAccessLevel ?? constants_1.DEFAULT_ACCESS_LEVEL,
46
- // use conditional assign to make tsc happy because StorageOptions is a union type that may not have targetIdentityId
47
- targetIdentityId: apiOptions?.accessLevel === 'protected'
48
- ? apiOptions?.targetIdentityId ?? identityId
49
- : identityId,
50
- });
45
+ const accessLevel = apiOptions?.accessLevel ?? defaultAccessLevel ?? constants_1.DEFAULT_ACCESS_LEVEL;
46
+ const targetIdentityId = accessLevel === 'protected'
47
+ ? apiOptions?.targetIdentityId ?? identityId
48
+ : identityId;
49
+ const keyPrefix = await prefixResolver({ accessLevel, targetIdentityId });
51
50
  return {
52
51
  s3Config: {
53
52
  credentials: credentialsProvider,
@@ -67,4 +66,17 @@ const resolveS3ConfigAndInput = async (amplify, apiOptions) => {
67
66
  };
68
67
  };
69
68
  exports.resolveS3ConfigAndInput = resolveS3ConfigAndInput;
69
+ const resolveBucketConfig = (apiOptions, buckets) => {
70
+ if (typeof apiOptions.bucket === 'string') {
71
+ const bucketConfig = buckets?.[apiOptions.bucket];
72
+ (0, assertValidationError_1.assertValidationError)(!!bucketConfig, validation_1.StorageValidationErrorCode.InvalidStorageBucket);
73
+ return { bucket: bucketConfig.bucketName, region: bucketConfig.region };
74
+ }
75
+ if (typeof apiOptions.bucket === 'object') {
76
+ return {
77
+ bucket: apiOptions.bucket.bucketName,
78
+ region: apiOptions.bucket.region,
79
+ };
80
+ }
81
+ };
70
82
  //# sourceMappingURL=resolveS3ConfigAndInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveS3ConfigAndInput.js","sources":["../../../../../src/providers/s3/utils/resolveS3ConfigAndInput.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveS3ConfigAndInput = void 0;\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst resolvePrefix_1 = require(\"../../../utils/resolvePrefix\");\nconst constants_1 = require(\"./constants\");\n/**\n * resolve the common input options for S3 API handlers from Amplify configuration and library options.\n *\n * @param {AmplifyClassV6} amplify The Amplify instance.\n * @param {S3ApiOptions} apiOptions The input options for S3 provider.\n * @returns {Promise<ResolvedS3ConfigAndInput>} The resolved common input options for S3 API handlers.\n * @throws A `StorageError` with `error.name` from `StorageValidationErrorCode` indicating invalid\n * configurations or Amplify library options.\n *\n * @internal\n */\nconst resolveS3ConfigAndInput = async (amplify, apiOptions) => {\n /**\n * IdentityId is always cached in memory so we can safely make calls here. It\n * should be stable even for unauthenticated users, regardless of credentials.\n */\n const { identityId } = await amplify.Auth.fetchAuthSession();\n (0, assertValidationError_1.assertValidationError)(!!identityId, validation_1.StorageValidationErrorCode.NoIdentityId);\n /**\n * A credentials provider function instead of a static credentials object is\n * used because the long-running tasks like multipart upload may span over the\n * credentials expiry. Auth.fetchAuthSession() automatically refreshes the\n * credentials if they are expired.\n */\n const credentialsProvider = async () => {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n (0, assertValidationError_1.assertValidationError)(!!credentials, validation_1.StorageValidationErrorCode.NoCredentials);\n return credentials;\n };\n const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } = amplify.getConfig()?.Storage?.S3 ?? {};\n (0, assertValidationError_1.assertValidationError)(!!bucket, validation_1.StorageValidationErrorCode.NoBucket);\n (0, assertValidationError_1.assertValidationError)(!!region, validation_1.StorageValidationErrorCode.NoRegion);\n const { defaultAccessLevel, prefixResolver = resolvePrefix_1.resolvePrefix, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};\n const keyPrefix = await prefixResolver({\n accessLevel: apiOptions?.accessLevel ?? defaultAccessLevel ?? constants_1.DEFAULT_ACCESS_LEVEL,\n // use conditional assign to make tsc happy because StorageOptions is a union type that may not have targetIdentityId\n targetIdentityId: apiOptions?.accessLevel === 'protected'\n ? apiOptions?.targetIdentityId ?? identityId\n : identityId,\n });\n return {\n s3Config: {\n credentials: credentialsProvider,\n region,\n useAccelerateEndpoint: apiOptions?.useAccelerateEndpoint,\n ...(dangerouslyConnectToHttpEndpointForTesting\n ? {\n customEndpoint: constants_1.LOCAL_TESTING_S3_ENDPOINT,\n forcePathStyle: true,\n }\n : {}),\n },\n bucket,\n keyPrefix,\n identityId,\n isObjectLockEnabled,\n };\n};\nexports.resolveS3ConfigAndInput = resolveS3ConfigAndInput;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC,CAAC;AACzC,MAAM,uBAAuB,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AACvF,MAAM,YAAY,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AACjE,MAAM,eAAe,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAChE,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,uBAAuB,GAAG,OAAO,OAAO,EAAE,UAAU,KAAK;AAC/D;AACA;AACA;AACA;AACA,IAAI,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACjE,IAAI,IAAI,uBAAuB,CAAC,qBAAqB,EAAE,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC;AAC3H;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,mBAAmB,GAAG,YAAY;AAC5C,QAAQ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BAAkB;AAClB,oBAAoB,cAAc,EAAE,WAAW,CAAC,yBAAyB;AACzE,oBAAoB,cAAc,EAAE,IAAI;AACxC,iBAAiB;AACjB,kBAAkB,EAAE;AACpB,SAAS;AACT,QAAQ,MAAM;AACd,QAAQ,SAAS;AACjB,QAAQ,UAAU;AAClB,QAAQ,mBAAmB;AAC3B,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,uBAAuB,GAAG,uBAAuB;;"}
1
+ {"version":3,"file":"resolveS3ConfigAndInput.js","sources":["../../../../../src/providers/s3/utils/resolveS3ConfigAndInput.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveS3ConfigAndInput = void 0;\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst resolvePrefix_1 = require(\"../../../utils/resolvePrefix\");\nconst constants_1 = require(\"./constants\");\n/**\n * resolve the common input options for S3 API handlers from Amplify configuration and library options.\n *\n * @param {AmplifyClassV6} amplify The Amplify instance.\n * @param {S3ApiOptions} apiOptions The input options for S3 provider.\n * @returns {Promise<ResolvedS3ConfigAndInput>} The resolved common input options for S3 API handlers.\n * @throws A `StorageError` with `error.name` from `StorageValidationErrorCode` indicating invalid\n * configurations or Amplify library options.\n *\n * @internal\n */\nconst resolveS3ConfigAndInput = async (amplify, apiOptions) => {\n /**\n * IdentityId is always cached in memory so we can safely make calls here. It\n * should be stable even for unauthenticated users, regardless of credentials.\n */\n const { identityId } = await amplify.Auth.fetchAuthSession();\n (0, assertValidationError_1.assertValidationError)(!!identityId, validation_1.StorageValidationErrorCode.NoIdentityId);\n /**\n * A credentials provider function instead of a static credentials object is\n * used because the long-running tasks like multipart upload may span over the\n * credentials expiry. Auth.fetchAuthSession() automatically refreshes the\n * credentials if they are expired.\n */\n const credentialsProvider = async () => {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n (0, assertValidationError_1.assertValidationError)(!!credentials, validation_1.StorageValidationErrorCode.NoCredentials);\n return credentials;\n };\n const { bucket: defaultBucket, region: defaultRegion, dangerouslyConnectToHttpEndpointForTesting, buckets, } = amplify.getConfig()?.Storage?.S3 ?? {};\n const { bucket = defaultBucket, region = defaultRegion } = (apiOptions?.bucket && resolveBucketConfig(apiOptions, buckets)) || {};\n (0, assertValidationError_1.assertValidationError)(!!bucket, validation_1.StorageValidationErrorCode.NoBucket);\n (0, assertValidationError_1.assertValidationError)(!!region, validation_1.StorageValidationErrorCode.NoRegion);\n const { defaultAccessLevel, prefixResolver = resolvePrefix_1.resolvePrefix, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};\n const accessLevel = apiOptions?.accessLevel ?? defaultAccessLevel ?? constants_1.DEFAULT_ACCESS_LEVEL;\n const targetIdentityId = accessLevel === 'protected'\n ? apiOptions?.targetIdentityId ?? identityId\n : identityId;\n const keyPrefix = await prefixResolver({ accessLevel, targetIdentityId });\n return {\n s3Config: {\n credentials: credentialsProvider,\n region,\n useAccelerateEndpoint: apiOptions?.useAccelerateEndpoint,\n ...(dangerouslyConnectToHttpEndpointForTesting\n ? {\n customEndpoint: constants_1.LOCAL_TESTING_S3_ENDPOINT,\n forcePathStyle: true,\n }\n : {}),\n },\n bucket,\n keyPrefix,\n identityId,\n isObjectLockEnabled,\n };\n};\nexports.resolveS3ConfigAndInput = resolveS3ConfigAndInput;\nconst resolveBucketConfig = (apiOptions, buckets) => {\n if (typeof apiOptions.bucket === 'string') {\n const bucketConfig = buckets?.[apiOptions.bucket];\n (0, assertValidationError_1.assertValidationError)(!!bucketConfig, validation_1.StorageValidationErrorCode.InvalidStorageBucket);\n return { bucket: bucketConfig.bucketName, region: bucketConfig.region };\n }\n if (typeof apiOptions.bucket === 'object') {\n return {\n bucket: apiOptions.bucket.bucketName,\n region: apiOptions.bucket.region,\n };\n }\n};\n"],"names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;AAClB,QAAQ,mBAAmB;AAC3B,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,OAAO,KAAK;AACrD,IAAI,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE;AAC/C,QAAQ,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAC1D,QAAQ,IAAI,uBAAuB,CAAC,qBAAqB,EAAE,CAAC,CAAC,YAAY,EAAE,YAAY,CAAC,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;AACzI,QAAQ,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC;AAChF,KAAK;AACL,IAAI,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE;AAC/C,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU;AAChD,YAAY,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM;AAC5C,SAAS,CAAC;AACV,KAAK;AACL,CAAC;;"}
@@ -9,6 +9,8 @@ export declare enum StorageValidationErrorCode {
9
9
  NoDestinationPath = "NoDestinationPath",
10
10
  NoBucket = "NoBucket",
11
11
  NoRegion = "NoRegion",
12
+ InvalidStorageBucket = "InvalidStorageBucket",
13
+ InvalidCopyOperationStorageBucket = "InvalidCopyOperationStorageBucket",
12
14
  InvalidStorageOperationPrefixInput = "InvalidStorageOperationPrefixInput",
13
15
  InvalidStorageOperationInput = "InvalidStorageOperationInput",
14
16
  InvalidStoragePathInput = "InvalidStoragePathInput",
@@ -11,6 +11,8 @@ var StorageValidationErrorCode;
11
11
  StorageValidationErrorCode["NoDestinationPath"] = "NoDestinationPath";
12
12
  StorageValidationErrorCode["NoBucket"] = "NoBucket";
13
13
  StorageValidationErrorCode["NoRegion"] = "NoRegion";
14
+ StorageValidationErrorCode["InvalidStorageBucket"] = "InvalidStorageBucket";
15
+ StorageValidationErrorCode["InvalidCopyOperationStorageBucket"] = "InvalidCopyOperationStorageBucket";
14
16
  StorageValidationErrorCode["InvalidStorageOperationPrefixInput"] = "InvalidStorageOperationPrefixInput";
15
17
  StorageValidationErrorCode["InvalidStorageOperationInput"] = "InvalidStorageOperationInput";
16
18
  StorageValidationErrorCode["InvalidStoragePathInput"] = "InvalidStoragePathInput";
@@ -64,6 +66,12 @@ const validationErrorMap = {
64
66
  [StorageValidationErrorCode.InvalidStoragePathInput]: {
65
67
  message: 'Input `path` does not allow a leading slash (/).',
66
68
  },
69
+ [StorageValidationErrorCode.InvalidStorageBucket]: {
70
+ message: 'Unable to lookup bucket from provided name in Amplify configuration.',
71
+ },
72
+ [StorageValidationErrorCode.InvalidCopyOperationStorageBucket]: {
73
+ message: 'Missing bucket option in either source or destination.',
74
+ },
67
75
  };
68
76
 
69
77
  export { StorageValidationErrorCode, validationErrorMap };
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","sources":["../../../../src/errors/types/validation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport var StorageValidationErrorCode;\n(function (StorageValidationErrorCode) {\n StorageValidationErrorCode[\"NoCredentials\"] = \"NoCredentials\";\n StorageValidationErrorCode[\"NoIdentityId\"] = \"NoIdentityId\";\n StorageValidationErrorCode[\"NoKey\"] = \"NoKey\";\n StorageValidationErrorCode[\"NoSourceKey\"] = \"NoSourceKey\";\n StorageValidationErrorCode[\"NoDestinationKey\"] = \"NoDestinationKey\";\n StorageValidationErrorCode[\"NoSourcePath\"] = \"NoSourcePath\";\n StorageValidationErrorCode[\"NoDestinationPath\"] = \"NoDestinationPath\";\n StorageValidationErrorCode[\"NoBucket\"] = \"NoBucket\";\n StorageValidationErrorCode[\"NoRegion\"] = \"NoRegion\";\n StorageValidationErrorCode[\"InvalidStorageOperationPrefixInput\"] = \"InvalidStorageOperationPrefixInput\";\n StorageValidationErrorCode[\"InvalidStorageOperationInput\"] = \"InvalidStorageOperationInput\";\n StorageValidationErrorCode[\"InvalidStoragePathInput\"] = \"InvalidStoragePathInput\";\n StorageValidationErrorCode[\"InvalidUploadSource\"] = \"InvalidUploadSource\";\n StorageValidationErrorCode[\"ObjectIsTooLarge\"] = \"ObjectIsTooLarge\";\n StorageValidationErrorCode[\"UrlExpirationMaxLimitExceed\"] = \"UrlExpirationMaxLimitExceed\";\n})(StorageValidationErrorCode || (StorageValidationErrorCode = {}));\nexport const validationErrorMap = {\n [StorageValidationErrorCode.NoCredentials]: {\n message: 'Credentials should not be empty.',\n },\n [StorageValidationErrorCode.NoIdentityId]: {\n message: 'Missing identity ID when accessing objects in protected or private access level.',\n },\n [StorageValidationErrorCode.NoKey]: {\n message: 'Missing key in api call.',\n },\n [StorageValidationErrorCode.NoSourceKey]: {\n message: 'Missing source key in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationKey]: {\n message: 'Missing destination key in copy api call.',\n },\n [StorageValidationErrorCode.NoSourcePath]: {\n message: 'Missing source path in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationPath]: {\n message: 'Missing destination path in copy api call.',\n },\n [StorageValidationErrorCode.NoBucket]: {\n message: 'Missing bucket name while accessing object.',\n },\n [StorageValidationErrorCode.NoRegion]: {\n message: 'Missing region while accessing object.',\n },\n [StorageValidationErrorCode.UrlExpirationMaxLimitExceed]: {\n message: 'Url Expiration can not be greater than 7 Days.',\n },\n [StorageValidationErrorCode.ObjectIsTooLarge]: {\n message: 'Object size cannot not be greater than 5TB.',\n },\n [StorageValidationErrorCode.InvalidUploadSource]: {\n message: 'Upload source type can only be a `Blob`, `File`, `ArrayBuffer`, or `string`.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationInput]: {\n message: 'Path or key parameter must be specified in the input. Both can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationPrefixInput]: {\n message: 'Both path and prefix can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStoragePathInput]: {\n message: 'Input `path` does not allow a leading slash (/).',\n },\n};\n"],"names":[],"mappings":"AAAA;AACA;AACU,IAAC,2BAA2B;AACtC,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAClE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAClD,IAAI,0BAA0B,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC;AAC9D,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACxE,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;AAC1E,IAAI,0BAA0B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AACxD,IAAI,0BAA0B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AACxD,IAAI,0BAA0B,CAAC,oCAAoC,CAAC,GAAG,oCAAoC,CAAC;AAC5G,IAAI,0BAA0B,CAAC,8BAA8B,CAAC,GAAG,8BAA8B,CAAC;AAChG,IAAI,0BAA0B,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;AACtF,IAAI,0BAA0B,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC;AAC9E,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACxE,IAAI,0BAA0B,CAAC,6BAA6B,CAAC,GAAG,6BAA6B,CAAC;AAC9F,CAAC,EAAE,0BAA0B,KAAK,0BAA0B,GAAG,EAAE,CAAC,CAAC,CAAC;AACxD,MAAC,kBAAkB,GAAG;AAClC,IAAI,CAAC,0BAA0B,CAAC,aAAa,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AAC9E,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,uBAAuB,GAAG;AAC1D,QAAQ,OAAO,EAAE,kDAAkD;AACnE,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"validation.mjs","sources":["../../../../src/errors/types/validation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport var StorageValidationErrorCode;\n(function (StorageValidationErrorCode) {\n StorageValidationErrorCode[\"NoCredentials\"] = \"NoCredentials\";\n StorageValidationErrorCode[\"NoIdentityId\"] = \"NoIdentityId\";\n StorageValidationErrorCode[\"NoKey\"] = \"NoKey\";\n StorageValidationErrorCode[\"NoSourceKey\"] = \"NoSourceKey\";\n StorageValidationErrorCode[\"NoDestinationKey\"] = \"NoDestinationKey\";\n StorageValidationErrorCode[\"NoSourcePath\"] = \"NoSourcePath\";\n StorageValidationErrorCode[\"NoDestinationPath\"] = \"NoDestinationPath\";\n StorageValidationErrorCode[\"NoBucket\"] = \"NoBucket\";\n StorageValidationErrorCode[\"NoRegion\"] = \"NoRegion\";\n StorageValidationErrorCode[\"InvalidStorageBucket\"] = \"InvalidStorageBucket\";\n StorageValidationErrorCode[\"InvalidCopyOperationStorageBucket\"] = \"InvalidCopyOperationStorageBucket\";\n StorageValidationErrorCode[\"InvalidStorageOperationPrefixInput\"] = \"InvalidStorageOperationPrefixInput\";\n StorageValidationErrorCode[\"InvalidStorageOperationInput\"] = \"InvalidStorageOperationInput\";\n StorageValidationErrorCode[\"InvalidStoragePathInput\"] = \"InvalidStoragePathInput\";\n StorageValidationErrorCode[\"InvalidUploadSource\"] = \"InvalidUploadSource\";\n StorageValidationErrorCode[\"ObjectIsTooLarge\"] = \"ObjectIsTooLarge\";\n StorageValidationErrorCode[\"UrlExpirationMaxLimitExceed\"] = \"UrlExpirationMaxLimitExceed\";\n})(StorageValidationErrorCode || (StorageValidationErrorCode = {}));\nexport const validationErrorMap = {\n [StorageValidationErrorCode.NoCredentials]: {\n message: 'Credentials should not be empty.',\n },\n [StorageValidationErrorCode.NoIdentityId]: {\n message: 'Missing identity ID when accessing objects in protected or private access level.',\n },\n [StorageValidationErrorCode.NoKey]: {\n message: 'Missing key in api call.',\n },\n [StorageValidationErrorCode.NoSourceKey]: {\n message: 'Missing source key in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationKey]: {\n message: 'Missing destination key in copy api call.',\n },\n [StorageValidationErrorCode.NoSourcePath]: {\n message: 'Missing source path in copy api call.',\n },\n [StorageValidationErrorCode.NoDestinationPath]: {\n message: 'Missing destination path in copy api call.',\n },\n [StorageValidationErrorCode.NoBucket]: {\n message: 'Missing bucket name while accessing object.',\n },\n [StorageValidationErrorCode.NoRegion]: {\n message: 'Missing region while accessing object.',\n },\n [StorageValidationErrorCode.UrlExpirationMaxLimitExceed]: {\n message: 'Url Expiration can not be greater than 7 Days.',\n },\n [StorageValidationErrorCode.ObjectIsTooLarge]: {\n message: 'Object size cannot not be greater than 5TB.',\n },\n [StorageValidationErrorCode.InvalidUploadSource]: {\n message: 'Upload source type can only be a `Blob`, `File`, `ArrayBuffer`, or `string`.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationInput]: {\n message: 'Path or key parameter must be specified in the input. Both can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStorageOperationPrefixInput]: {\n message: 'Both path and prefix can not be specified at the same time.',\n },\n [StorageValidationErrorCode.InvalidStoragePathInput]: {\n message: 'Input `path` does not allow a leading slash (/).',\n },\n [StorageValidationErrorCode.InvalidStorageBucket]: {\n message: 'Unable to lookup bucket from provided name in Amplify configuration.',\n },\n [StorageValidationErrorCode.InvalidCopyOperationStorageBucket]: {\n message: 'Missing bucket option in either source or destination.',\n },\n};\n"],"names":[],"mappings":"AAAA;AACA;AACU,IAAC,2BAA2B;AACtC,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAClE,IAAI,0BA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AACvD,QAAQ,OAAO,EAAE,sEAAsE;AACvF,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,iCAAiC,GAAG;AACpE,QAAQ,OAAO,EAAE,wDAAwD;AACzE,KAAK;AACL;;;;"}
@@ -28,6 +28,16 @@ import { getStorageUserAgentValue } from '../../utils/userAgent.mjs';
28
28
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
29
29
  // SPDX-License-Identifier: Apache-2.0
30
30
  const isCopyInputWithPath = (input) => isInputWithPath(input.source);
31
+ const storageBucketAssertion = (sourceBucket, destBucket) => {
32
+ /** For multi-bucket, both source and destination bucket needs to be passed in
33
+ * or both can be undefined and we fallback to singleton's default value
34
+ */
35
+ assertValidationError(
36
+ // Both src & dest bucket option is present is acceptable
37
+ (sourceBucket !== undefined && destBucket !== undefined) ||
38
+ // or both are undefined is also acceptable
39
+ (!destBucket && !sourceBucket), StorageValidationErrorCode.InvalidCopyOperationStorageBucket);
40
+ };
31
41
  const copy = async (amplify, input) => {
32
42
  return isCopyInputWithPath(input)
33
43
  ? copyWithPath(amplify, input)
@@ -35,41 +45,44 @@ const copy = async (amplify, input) => {
35
45
  };
36
46
  const copyWithPath = async (amplify, input) => {
37
47
  const { source, destination } = input;
38
- const { s3Config, bucket, identityId } = await resolveS3ConfigAndInput(amplify);
48
+ storageBucketAssertion(source.bucket, destination.bucket);
49
+ const { bucket: sourceBucket, identityId } = await resolveS3ConfigAndInput(amplify, input.source);
50
+ const { s3Config, bucket: destBucket } = await resolveS3ConfigAndInput(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
39
51
  assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);
40
52
  assertValidationError(!!destination.path, StorageValidationErrorCode.NoDestinationPath);
41
53
  const { objectKey: sourcePath } = validateStorageOperationInput(source, identityId);
42
54
  const { objectKey: destinationPath } = validateStorageOperationInput(destination, identityId);
43
- const finalCopySource = `${bucket}/${sourcePath}`;
55
+ const finalCopySource = `${sourceBucket}/${sourcePath}`;
44
56
  const finalCopyDestination = destinationPath;
45
57
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
46
58
  await serviceCopy({
47
59
  source: finalCopySource,
48
60
  destination: finalCopyDestination,
49
- bucket,
61
+ bucket: destBucket,
50
62
  s3Config,
51
63
  });
52
64
  return { path: finalCopyDestination };
53
65
  };
54
66
  /** @deprecated Use {@link copyWithPath} instead. */
55
67
  const copyWithKey = async (amplify, input) => {
56
- const { source: { key: sourceKey }, destination: { key: destinationKey }, } = input;
57
- assertValidationError(!!sourceKey, StorageValidationErrorCode.NoSourceKey);
58
- assertValidationError(!!destinationKey, StorageValidationErrorCode.NoDestinationKey);
59
- const { s3Config, bucket, keyPrefix: sourceKeyPrefix, } = await resolveS3ConfigAndInput(amplify, input.source);
60
- const { keyPrefix: destinationKeyPrefix } = await resolveS3ConfigAndInput(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
68
+ const { source, destination } = input;
69
+ storageBucketAssertion(source.bucket, destination.bucket);
70
+ assertValidationError(!!source.key, StorageValidationErrorCode.NoSourceKey);
71
+ assertValidationError(!!destination.key, StorageValidationErrorCode.NoDestinationKey);
72
+ const { bucket: sourceBucket, keyPrefix: sourceKeyPrefix } = await resolveS3ConfigAndInput(amplify, source);
73
+ const { s3Config, bucket: destBucket, keyPrefix: destinationKeyPrefix, } = await resolveS3ConfigAndInput(amplify, destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
61
74
  // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is "protected", currently it's ${srcLevel}`
62
- const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
63
- const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
75
+ const finalCopySource = `${sourceBucket}/${sourceKeyPrefix}${source.key}`;
76
+ const finalCopyDestination = `${destinationKeyPrefix}${destination.key}`;
64
77
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
65
78
  await serviceCopy({
66
79
  source: finalCopySource,
67
80
  destination: finalCopyDestination,
68
- bucket,
81
+ bucket: destBucket,
69
82
  s3Config,
70
83
  });
71
84
  return {
72
- key: destinationKey,
85
+ key: destination.key,
73
86
  };
74
87
  };
75
88
  const serviceCopy = async ({ source, destination, bucket, s3Config, }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"copy.mjs","sources":["../../../../../../src/providers/s3/apis/internal/copy.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { StorageAction } from '@aws-amplify/core/internals/utils';\nimport { isInputWithPath, resolveS3ConfigAndInput, validateStorageOperationInput, } from '../../utils';\nimport { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { copyObject } from '../../utils/client';\nimport { getStorageUserAgentValue } from '../../utils/userAgent';\nimport { logger } from '../../../../utils';\nconst isCopyInputWithPath = (input) => isInputWithPath(input.source);\nexport const copy = async (amplify, input) => {\n return isCopyInputWithPath(input)\n ? copyWithPath(amplify, input)\n : copyWithKey(amplify, input);\n};\nconst copyWithPath = async (amplify, input) => {\n const { source, destination } = input;\n const { s3Config, bucket, identityId } = await resolveS3ConfigAndInput(amplify);\n assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);\n assertValidationError(!!destination.path, StorageValidationErrorCode.NoDestinationPath);\n const { objectKey: sourcePath } = validateStorageOperationInput(source, identityId);\n const { objectKey: destinationPath } = validateStorageOperationInput(destination, identityId);\n const finalCopySource = `${bucket}/${sourcePath}`;\n const finalCopyDestination = destinationPath;\n logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket,\n s3Config,\n });\n return { path: finalCopyDestination };\n};\n/** @deprecated Use {@link copyWithPath} instead. */\nexport const copyWithKey = async (amplify, input) => {\n const { source: { key: sourceKey }, destination: { key: destinationKey }, } = input;\n assertValidationError(!!sourceKey, StorageValidationErrorCode.NoSourceKey);\n assertValidationError(!!destinationKey, StorageValidationErrorCode.NoDestinationKey);\n const { s3Config, bucket, keyPrefix: sourceKeyPrefix, } = await resolveS3ConfigAndInput(amplify, input.source);\n const { keyPrefix: destinationKeyPrefix } = await resolveS3ConfigAndInput(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is \"protected\", currently it's ${srcLevel}`\n const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;\n const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;\n logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket,\n s3Config,\n });\n return {\n key: destinationKey,\n };\n};\nconst serviceCopy = async ({ source, destination, bucket, s3Config, }) => {\n await copyObject({\n ...s3Config,\n userAgentValue: getStorageUserAgentValue(StorageAction.Copy),\n }, {\n Bucket: bucket,\n CopySource: source,\n Key: destination,\n MetadataDirective: 'COPY', // Copies over metadata like contentType as well\n });\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAQA,MAAM,mBAAmB,GAAG,CAAC,KAAK,KAAK,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACzD,MAAC,IAAI,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AAC9C,IAAI,OAAO,mBAAmB,CAAC,KAAK,CAAC;AACrC,UAAU,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;AACtC,UAAU,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtC,EAAE;AACF,MAAM,YAAY,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AAC/C,IAAI,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,C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;AAC1B,QAAQ,GAAG,EAAE,WAAW;AACxB,QAAQ,iBAAiB,EAAE,MAAM;AACjC,KAAK,CAAC,CAAC;AACP,CAAC;;;;"}
1
+ {"version":3,"file":"copy.mjs","sources":["../../../../../../src/providers/s3/apis/internal/copy.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { StorageAction } from '@aws-amplify/core/internals/utils';\nimport { isInputWithPath, resolveS3ConfigAndInput, validateStorageOperationInput, } from '../../utils';\nimport { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { copyObject } from '../../utils/client';\nimport { getStorageUserAgentValue } from '../../utils/userAgent';\nimport { logger } from '../../../../utils';\nconst isCopyInputWithPath = (input) => isInputWithPath(input.source);\nconst storageBucketAssertion = (sourceBucket, destBucket) => {\n /** For multi-bucket, both source and destination bucket needs to be passed in\n * or both can be undefined and we fallback to singleton's default value\n */\n assertValidationError(\n // Both src & dest bucket option is present is acceptable\n (sourceBucket !== undefined && destBucket !== undefined) ||\n // or both are undefined is also acceptable\n (!destBucket && !sourceBucket), StorageValidationErrorCode.InvalidCopyOperationStorageBucket);\n};\nexport const copy = async (amplify, input) => {\n return isCopyInputWithPath(input)\n ? copyWithPath(amplify, input)\n : copyWithKey(amplify, input);\n};\nconst copyWithPath = async (amplify, input) => {\n const { source, destination } = input;\n storageBucketAssertion(source.bucket, destination.bucket);\n const { bucket: sourceBucket, identityId } = await resolveS3ConfigAndInput(amplify, input.source);\n const { s3Config, bucket: destBucket } = await resolveS3ConfigAndInput(amplify, input.destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);\n assertValidationError(!!destination.path, StorageValidationErrorCode.NoDestinationPath);\n const { objectKey: sourcePath } = validateStorageOperationInput(source, identityId);\n const { objectKey: destinationPath } = validateStorageOperationInput(destination, identityId);\n const finalCopySource = `${sourceBucket}/${sourcePath}`;\n const finalCopyDestination = destinationPath;\n logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket: destBucket,\n s3Config,\n });\n return { path: finalCopyDestination };\n};\n/** @deprecated Use {@link copyWithPath} instead. */\nexport const copyWithKey = async (amplify, input) => {\n const { source, destination } = input;\n storageBucketAssertion(source.bucket, destination.bucket);\n assertValidationError(!!source.key, StorageValidationErrorCode.NoSourceKey);\n assertValidationError(!!destination.key, StorageValidationErrorCode.NoDestinationKey);\n const { bucket: sourceBucket, keyPrefix: sourceKeyPrefix } = await resolveS3ConfigAndInput(amplify, source);\n const { s3Config, bucket: destBucket, keyPrefix: destinationKeyPrefix, } = await resolveS3ConfigAndInput(amplify, destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.\n // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is \"protected\", currently it's ${srcLevel}`\n const finalCopySource = `${sourceBucket}/${sourceKeyPrefix}${source.key}`;\n const finalCopyDestination = `${destinationKeyPrefix}${destination.key}`;\n logger.debug(`copying \"${finalCopySource}\" to \"${finalCopyDestination}\".`);\n await serviceCopy({\n source: finalCopySource,\n destination: finalCopyDestination,\n bucket: destBucket,\n s3Config,\n });\n return {\n key: destination.key,\n };\n};\nconst serviceCopy = async ({ source, destination, bucket, s3Config, }) => {\n await copyObject({\n ...s3Config,\n userAgentValue: getStorageUserAgentValue(StorageAction.Copy),\n }, {\n Bucket: bucket,\n CopySource: source,\n Key: destination,\n MetadataDirective: 'COPY', // Copies over metadata like contentType as well\n });\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAQA,MAAM,mBAAmB,GAAG,CAAC,KAAK,KAAK,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACrE,MAAM,sBAAsB,GAAG,CAAC,YAAY,EAAE,UA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;AACnI;AACA,IAAI,MAAM,eAAe,GAAG,CAAC,EAAE,YAAY,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,IAAI,MAAM,oBAAoB,GAAG,CAAC,EAAE,oBAAoB,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7E,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,eAAe,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/E,IAAI,MAAM,WAAW,CAAC;AACtB,QAAQ,MAAM,EAAE,eAAe;AAC/B,QAAQ,WAAW,EAAE,oBAAoB;AACzC,QAAQ,MAAM,EAAE,UAAU;AAC1B,QAAQ,QAAQ;AAChB,KAAK,CAAC,CAAC;AACP,IAAI,OAAO;AACX,QAAQ,GAAG,EAAE,WAAW,CAAC,GAAG;AAC5B,KAAK,CAAC;AACN,EAAE;AACF,MAAM,WAAW,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAG,KAAK;AAC1E,IAAI,MAAM,UAAU,CAAC;AACrB,QAAQ,GAAG,QAAQ;AACnB,QAAQ,cAAc,EAAE,wBAAwB,CAAC,aAAa,CAAC,IAAI,CAAC;AACpE,KAAK,EAAE;AACP,QAAQ,MAAM,EAAE,MAAM;AACtB,QAAQ,UAAU,EAAE,MAAM;AAC1B,QAAQ,GAAG,EAAE,WAAW;AACxB,QAAQ,iBAAiB,EAAE,MAAM;AACjC,KAAK,CAAC,CAAC;AACP,CAAC;;;;"}
@@ -42,7 +42,7 @@ const list = async (amplify, input) => {
42
42
  Prefix: isInputWithPrefix ? `${generatedPrefix}${objectKey}` : objectKey,
43
43
  MaxKeys: options?.listAll ? undefined : options?.pageSize,
44
44
  ContinuationToken: options?.listAll ? undefined : options?.nextToken,
45
- Delimiter: getDelimiter(options.subpathStrategy),
45
+ Delimiter: getDelimiter(options),
46
46
  };
47
47
  logger.debug(`listing items from "${listParams.Prefix}"`);
48
48
  const listInputArgs = {
@@ -176,9 +176,9 @@ const mapCommonPrefixesToExcludedSubpaths = (commonPrefixes) => {
176
176
  return mappedSubpaths;
177
177
  }, []);
178
178
  };
179
- const getDelimiter = (subpathStrategy) => {
180
- if (subpathStrategy?.strategy === 'exclude') {
181
- return subpathStrategy?.delimiter ?? DEFAULT_DELIMITER;
179
+ const getDelimiter = (options) => {
180
+ if (options?.subpathStrategy?.strategy === 'exclude') {
181
+ return options?.subpathStrategy?.delimiter ?? DEFAULT_DELIMITER;
182
182
  }
183
183
  };
184
184