@aws-amplify/storage 6.4.7 → 6.4.8-multi-bucket.043d913.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.
@@ -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,GAAG,mBAAmB,CAAC;AAC1E,IAAI,0BAA0B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AACxD,IAAI,0BAA0B,CAAC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C,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,GAAG,cAAc,CAAC;AAChE,IAAI,0BAA0B,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;AAC1E,IAAI,0BAA0B,CAAC,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AQ,OAAO,EAAE,uCAAuC;AACxD,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,iBAAiB,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,IAAI,CAAC,0BAA0B,CAAC,oBAAoB,GAAG;AACvD,QAAQ,OAAO,EAAE,sEAAsE;AACvF,KAAK;AACL,IAAI,CAAC,0BAA0B,CAAC,iCAAiC,GAAG;AACpE,QAAQ,OAAO,EAAE,wDAAwD;AACzE,KAAK;AACL,CAAC;;"}
@@ -12,6 +12,16 @@ const client_1 = require("../../utils/client");
12
12
  const userAgent_1 = require("../../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,GAAG,KAAK,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG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C,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: dest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,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,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,eAAe,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC;AACvF,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,CAAC,CAAC;AACF,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;AAClC,MAAM,WAAW,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAG,KAAK;AAC1E,IAAI,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE;AACnC,QAAQ,GAAG,QAAQ;AACnB,QAAQ,cAAc,EAAE,IAAI,WAAW,CAAC,wBAAwB,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;AAC7F,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;;"}
@@ -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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,oBAAoB;AACtG;AACA,QAAQ,gBAAgB,EAAE,UAAU,EAAE,WAAW,KAAK,WAAW;AACjE,cAAc,UAAU,EAAE,gBAAgB,IAAI,UAAU;AACxD,cAAc,UAAU;AACxB,KAAK,CAAC,CAAC;AACP,IAAI,OAAO;AACX,QAAQ,QAAQ,EAAE;AAClB,YAAY,WAAW,EAAE,mBAAmB;AAC5C,YAAY,MAAM;AAClB,YAAY,qBAAqB,EAAE,UAAU,EAAE,qBAAqB;AACpE,YAAY,IAAI,0CAA0C;AAC1D,kBAAkB;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":[],"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,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;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Bucket = "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,yB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B,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;;;;"}
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,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,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;AAChF,IAAI,0BAA0B,CAAC,mCAAmC,CAAC,GAAG,mCAAmC,CAAC;AAC1G,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,0BA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C/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,IAAI,CAAC,0BAA0B,CAAC,oBAAoB,GAAG;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,C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G,EAAE,cAAc;AAC3B,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;;;;"}
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,UAAU,KAAK;AAC7D;AACA;AACA;AACA,IAAI,qBAAqB;AACzB;AACA,IAAI,CAAC,YAAY,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS;AAC3D;AACA,SAAS,CAAC,UAAU,IAAI,CAAC,YAAY,CAAC,EAAE,0BAA0B,CAAC,iCAAiC,CAAC,CAAC;AACtG,CAAC,CAAC;AACU,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,CAAC;AAC1C,IAAI,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;AAC9D,IAAI,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AACtG,IAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC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AM;AAC1B,QAAQ,GAAG,EAAE,WAAW;AACxB,QAAQ,iBAAiB,EAAE,MAAM;AACjC,KAAK,CAAC,CAAC;AACP,CAAC;;;;"}
@@ -1,4 +1,4 @@
1
- export { GetUrlOptionsWithKey, GetUrlOptionsWithPath, UploadDataOptionsWithPath, UploadDataOptionsWithKey, GetPropertiesOptionsWithKey, GetPropertiesOptionsWithPath, ListAllOptionsWithPrefix, ListPaginateOptionsWithPrefix, ListAllOptionsWithPath, ListPaginateOptionsWithPath, RemoveOptions, DownloadDataOptionsWithPath, DownloadDataOptionsWithKey, CopyDestinationOptionsWithKey, CopySourceOptionsWithKey, } from './options';
1
+ export { GetUrlOptionsWithKey, GetUrlOptionsWithPath, UploadDataOptionsWithPath, UploadDataOptionsWithKey, GetPropertiesOptionsWithKey, GetPropertiesOptionsWithPath, ListAllOptionsWithPrefix, ListPaginateOptionsWithPrefix, ListAllOptionsWithPath, ListPaginateOptionsWithPath, RemoveOptions, DownloadDataOptionsWithPath, DownloadDataOptionsWithKey, CopyDestinationOptionsWithKey, CopySourceOptionsWithKey, CopyWithPathSourceOptions, CopyWithPathDestinationOptions, } from './options';
2
2
  export { UploadDataOutput, UploadDataWithPathOutput, DownloadDataOutput, DownloadDataWithPathOutput, RemoveOutput, RemoveWithPathOutput, ListAllOutput, ListAllWithPathOutput, ListPaginateOutput, ListPaginateWithPathOutput, GetPropertiesOutput, GetPropertiesWithPathOutput, CopyOutput, CopyWithPathOutput, GetUrlOutput, GetUrlWithPathOutput, ListOutputItem, ListOutputItemWithPath, } from './outputs';
3
3
  export { CopyInput, CopyWithPathInput, GetPropertiesInput, GetPropertiesWithPathInput, GetUrlInput, GetUrlWithPathInput, RemoveWithPathInput, RemoveInput, DownloadDataInput, DownloadDataWithPathInput, UploadDataInput, UploadDataWithPathInput, ListAllInput, ListPaginateInput, ListAllWithPathInput, ListPaginateWithPathInput, } from './inputs';
4
4
  export { S3Exception } from './errors';
@@ -1,5 +1,5 @@
1
1
  import { StorageCopyInputWithKey, StorageCopyInputWithPath, StorageDownloadDataInputWithKey, StorageDownloadDataInputWithPath, StorageGetPropertiesInputWithKey, StorageGetPropertiesInputWithPath, StorageGetUrlInputWithKey, StorageGetUrlInputWithPath, StorageListInputWithPath, StorageListInputWithPrefix, StorageRemoveInputWithKey, StorageRemoveInputWithPath, StorageUploadDataInputWithKey, StorageUploadDataInputWithPath } from '../../../types';
2
- import { CopyDestinationOptionsWithKey, CopySourceOptionsWithKey, DownloadDataOptionsWithKey, DownloadDataOptionsWithPath, GetPropertiesOptionsWithKey, GetPropertiesOptionsWithPath, GetUrlOptionsWithKey, GetUrlOptionsWithPath, ListAllOptionsWithPath, ListAllOptionsWithPrefix, ListPaginateOptionsWithPath, ListPaginateOptionsWithPrefix, RemoveOptions, UploadDataOptionsWithKey, UploadDataOptionsWithPath } from '../types';
2
+ import { CopyDestinationOptionsWithKey, CopySourceOptionsWithKey, CopyWithPathDestinationOptions, CopyWithPathSourceOptions, DownloadDataOptionsWithKey, DownloadDataOptionsWithPath, GetPropertiesOptionsWithKey, GetPropertiesOptionsWithPath, GetUrlOptionsWithKey, GetUrlOptionsWithPath, ListAllOptionsWithPath, ListAllOptionsWithPrefix, ListPaginateOptionsWithPath, ListPaginateOptionsWithPrefix, RemoveOptions, UploadDataOptionsWithKey, UploadDataOptionsWithPath } from '../types';
3
3
  /**
4
4
  * @deprecated Use {@link CopyWithPathInput} instead.
5
5
  * Input type for S3 copy API.
@@ -8,7 +8,7 @@ export type CopyInput = StorageCopyInputWithKey<CopySourceOptionsWithKey, CopyDe
8
8
  /**
9
9
  * Input type with path for S3 copy API.
10
10
  */
11
- export type CopyWithPathInput = StorageCopyInputWithPath;
11
+ export type CopyWithPathInput = StorageCopyInputWithPath<CopyWithPathSourceOptions, CopyWithPathDestinationOptions>;
12
12
  /**
13
13
  * @deprecated Use {@link GetPropertiesWithPathInput} instead.
14
14
  * Input type for S3 getProperties API.
@@ -2,12 +2,18 @@ import { StorageAccessLevel } from '@aws-amplify/core';
2
2
  import { SigningOptions } from '@aws-amplify/core/internals/aws-client-utils';
3
3
  import { TransferProgressEvent } from '../../../types';
4
4
  import { StorageListAllOptions, StorageListPaginateOptions } from '../../../types/options';
5
+ export interface BucketInfo {
6
+ bucketName: string;
7
+ region: string;
8
+ }
9
+ export type StorageBucket = string | BucketInfo;
5
10
  interface CommonOptions {
6
11
  /**
7
12
  * Whether to use accelerate endpoint.
8
13
  * @default false
9
14
  */
10
15
  useAccelerateEndpoint?: boolean;
16
+ bucket?: StorageBucket;
11
17
  }
12
18
  /** @deprecated This may be removed in the next major version. */
13
19
  type ReadOptions = {
@@ -121,12 +127,20 @@ export type UploadDataOptionsWithPath = UploadDataOptions;
121
127
  export type CopySourceOptionsWithKey = ReadOptions & {
122
128
  /** @deprecated This may be removed in the next major version. */
123
129
  key: string;
130
+ bucket?: StorageBucket;
124
131
  };
125
132
  /** @deprecated This may be removed in the next major version. */
126
133
  export type CopyDestinationOptionsWithKey = WriteOptions & {
127
134
  /** @deprecated This may be removed in the next major version. */
128
135
  key: string;
136
+ bucket?: StorageBucket;
129
137
  };
138
+ export interface CopyWithPathSourceOptions {
139
+ bucket?: StorageBucket;
140
+ }
141
+ export interface CopyWithPathDestinationOptions {
142
+ bucket?: StorageBucket;
143
+ }
130
144
  /**
131
145
  * Internal only type for S3 API handlers' config parameter.
132
146
  *
@@ -1,9 +1,10 @@
1
1
  import { AmplifyClassV6, StorageAccessLevel } from '@aws-amplify/core';
2
- import { ResolvedS3Config } from '../types/options';
2
+ import { ResolvedS3Config, StorageBucket } from '../types/options';
3
3
  interface S3ApiOptions {
4
4
  accessLevel?: StorageAccessLevel;
5
5
  targetIdentityId?: string;
6
6
  useAccelerateEndpoint?: boolean;
7
+ bucket?: StorageBucket;
7
8
  }
8
9
  interface ResolvedS3ConfigAndInput {
9
10
  s3Config: ResolvedS3Config;
@@ -34,17 +34,16 @@ const resolveS3ConfigAndInput = async (amplify, apiOptions) => {
34
34
  assertValidationError(!!credentials, StorageValidationErrorCode.NoCredentials);
35
35
  return credentials;
36
36
  };
37
- const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } = amplify.getConfig()?.Storage?.S3 ?? {};
37
+ const { bucket: defaultBucket, region: defaultRegion, dangerouslyConnectToHttpEndpointForTesting, buckets, } = amplify.getConfig()?.Storage?.S3 ?? {};
38
+ const { bucket = defaultBucket, region = defaultRegion } = (apiOptions?.bucket && resolveBucketConfig(apiOptions, buckets)) || {};
38
39
  assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);
39
40
  assertValidationError(!!region, StorageValidationErrorCode.NoRegion);
40
41
  const { defaultAccessLevel, prefixResolver = resolvePrefix, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};
41
- const keyPrefix = await prefixResolver({
42
- accessLevel: apiOptions?.accessLevel ?? defaultAccessLevel ?? DEFAULT_ACCESS_LEVEL,
43
- // use conditional assign to make tsc happy because StorageOptions is a union type that may not have targetIdentityId
44
- targetIdentityId: apiOptions?.accessLevel === 'protected'
45
- ? apiOptions?.targetIdentityId ?? identityId
46
- : identityId,
47
- });
42
+ const accessLevel = apiOptions?.accessLevel ?? defaultAccessLevel ?? DEFAULT_ACCESS_LEVEL;
43
+ const targetIdentityId = accessLevel === 'protected'
44
+ ? apiOptions?.targetIdentityId ?? identityId
45
+ : identityId;
46
+ const keyPrefix = await prefixResolver({ accessLevel, targetIdentityId });
48
47
  return {
49
48
  s3Config: {
50
49
  credentials: credentialsProvider,
@@ -63,6 +62,19 @@ const resolveS3ConfigAndInput = async (amplify, apiOptions) => {
63
62
  isObjectLockEnabled,
64
63
  };
65
64
  };
65
+ const resolveBucketConfig = (apiOptions, buckets) => {
66
+ if (typeof apiOptions.bucket === 'string') {
67
+ const bucketConfig = buckets?.[apiOptions.bucket];
68
+ assertValidationError(!!bucketConfig, StorageValidationErrorCode.InvalidStorageBucket);
69
+ return { bucket: bucketConfig.bucketName, region: bucketConfig.region };
70
+ }
71
+ if (typeof apiOptions.bucket === 'object') {
72
+ return {
73
+ bucket: apiOptions.bucket.bucketName,
74
+ region: apiOptions.bucket.region,
75
+ };
76
+ }
77
+ };
66
78
 
67
79
  export { resolveS3ConfigAndInput };
68
80
  //# sourceMappingURL=resolveS3ConfigAndInput.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveS3ConfigAndInput.mjs","sources":["../../../../../src/providers/s3/utils/resolveS3ConfigAndInput.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { StorageValidationErrorCode } from '../../../errors/types/validation';\nimport { resolvePrefix as defaultPrefixResolver } from '../../../utils/resolvePrefix';\nimport { DEFAULT_ACCESS_LEVEL, LOCAL_TESTING_S3_ENDPOINT } from './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 */\nexport const 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 assertValidationError(!!identityId, 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 assertValidationError(!!credentials, StorageValidationErrorCode.NoCredentials);\n return credentials;\n };\n const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } = amplify.getConfig()?.Storage?.S3 ?? {};\n assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);\n assertValidationError(!!region, StorageValidationErrorCode.NoRegion);\n const { defaultAccessLevel, prefixResolver = defaultPrefixResolver, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};\n const keyPrefix = await prefixResolver({\n accessLevel: apiOptions?.accessLevel ?? defaultAccessLevel ?? 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: LOCAL_TESTING_S3_ENDPOINT,\n forcePathStyle: true,\n }\n : {}),\n },\n bucket,\n keyPrefix,\n identityId,\n isObjectLockEnabled,\n };\n};\n"],"names":["defaultPrefixResolver"],"mappings":";;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,uBAAuB,GAAG,OAAO,OAAO,EAAE,UAAU,KAAK;AACtE;AACA;AACA;AACA;AACA,IAAI,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACjE,IAAI,qBAAqB,CAAC,CAAC,CAAC,UAAU,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;AACjF;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,mBAAmB,GAAG,YAAY;AAC5C,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACtE,QAAQ,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC;AACvF,QAAQ,OAAO,WAAW,CAAC;AA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cesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { StorageValidationErrorCode } from '../../../errors/types/validation';\nimport { resolvePrefix as defaultPrefixResolver } from '../../../utils/resolvePrefix';\nimport { DEFAULT_ACCESS_LEVEL, LOCAL_TESTING_S3_ENDPOINT } from './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 */\nexport const 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 assertValidationError(!!identityId, 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 assertValidationError(!!credentials, 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 assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);\n assertValidationError(!!region, StorageValidationErrorCode.NoRegion);\n const { defaultAccessLevel, prefixResolver = defaultPrefixResolver, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};\n const accessLevel = apiOptions?.accessLevel ?? defaultAccessLevel ?? 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: LOCAL_TESTING_S3_ENDPOINT,\n forcePathStyle: true,\n }\n : {}),\n },\n bucket,\n keyPrefix,\n identityId,\n isObjectLockEnabled,\n };\n};\nconst resolveBucketConfig = (apiOptions, buckets) => {\n if (typeof apiOptions.bucket === 'string') {\n const bucketConfig = buckets?.[apiOptions.bucket];\n assertValidationError(!!bucketConfig, 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":["defaultPrefixResolver"],"mappings":";;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,uBAAuB,GAAG,OAAO,OAAO,EAAE,UAAU,KAAK;AACtE;AACA;AACA;AACA;AACA,IAAI,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACjE,IAAI,qBAAqB,CAAC,CAAC,CAAC,UAAU,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;AACjF;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,mBAAmB,GAAG,YAAY;AAC5C,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACtE,QAAQ,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,0BAA0B,CAA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AAyB;AAC7D,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,EAAE;AACF,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,qBAAqB,CAAC,CAAC,CAAC,YAAY,EAAE,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;AAC/F,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;;;;"}
@@ -42,9 +42,9 @@ export interface StorageCopyInputWithKey<SourceOptions extends StorageOptions, D
42
42
  source: SourceOptions;
43
43
  destination: DestinationOptions;
44
44
  }
45
- export interface StorageCopyInputWithPath {
46
- source: StorageOperationInputWithPath;
47
- destination: StorageOperationInputWithPath;
45
+ export interface StorageCopyInputWithPath<SourceOptions, DestinationOptions> {
46
+ source: StorageOperationInputWithPath & SourceOptions;
47
+ destination: StorageOperationInputWithPath & DestinationOptions;
48
48
  }
49
49
  /**
50
50
  * The data payload type for upload operation.
package/package.json CHANGED
@@ -1,109 +1,109 @@
1
1
  {
2
- "name": "@aws-amplify/storage",
3
- "version": "6.4.7",
4
- "description": "Storage category of aws-amplify",
5
- "main": "./dist/cjs/index.js",
6
- "module": "./dist/esm/index.mjs",
7
- "react-native": {
8
- "./dist/cjs/index": "./src/index.ts",
9
- "fast-xml-parser": "fast-xml-parser",
10
- "buffer": "buffer"
11
- },
12
- "typings": "./dist/esm/index.d.ts",
13
- "browser": {
14
- "./dist/esm/providers/s3/utils/client/runtime/base64/index.native.mjs": "./dist/esm/providers/s3/utils/client/runtime/base64/index.browser.mjs",
15
- "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/fetch.mjs": "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/xhr.mjs",
16
- "./dist/esm/providers/s3/utils/client/runtime/xmlParser/pureJs.mjs": "./dist/esm/providers/s3/utils/client/runtime/xmlParser/dom.mjs",
17
- "fast-xml-parser": false,
18
- "buffer": false
19
- },
20
- "sideEffects": false,
21
- "publishConfig": {
22
- "access": "public"
23
- },
24
- "scripts": {
25
- "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
26
- "build-with-test": "npm test && npm run build",
27
- "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
28
- "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
29
- "build:watch": "npm run build:esm-cjs -- --watch",
30
- "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
31
- "clean": "npm run clean:size && rimraf lib-esm lib dist",
32
- "clean:size": "rimraf dual-publish-tmp tmp*",
33
- "format": "echo \"Not implemented\"",
34
- "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
35
- "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
36
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
37
- },
38
- "typesVersions": {
39
- ">=4.2": {
40
- "s3": [
41
- "./dist/esm/providers/s3/index.d.ts"
42
- ],
43
- "server": [
44
- "./dist/esm/server.d.ts"
45
- ],
46
- "s3/server": [
47
- "./dist/esm/providers/s3/server.d.ts"
48
- ]
49
- }
50
- },
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/aws-amplify/amplify-js.git"
54
- },
55
- "author": "Amazon Web Services",
56
- "license": "Apache-2.0",
57
- "bugs": {
58
- "url": "https://github.com/aws/aws-amplify/issues"
59
- },
60
- "homepage": "https://aws-amplify.github.io/",
61
- "files": [
62
- "dist/cjs",
63
- "dist/esm",
64
- "src",
65
- "server",
66
- "s3"
67
- ],
68
- "dependencies": {
69
- "@aws-sdk/types": "3.398.0",
70
- "@smithy/md5-js": "2.0.7",
71
- "buffer": "4.9.2",
72
- "fast-xml-parser": "^4.2.5",
73
- "tslib": "^2.5.0"
74
- },
75
- "exports": {
76
- ".": {
77
- "types": "./dist/esm/index.d.ts",
78
- "import": "./dist/esm/index.mjs",
79
- "require": "./dist/cjs/index.js",
80
- "react-native": "./src/index.ts"
81
- },
82
- "./server": {
83
- "types": "./dist/esm/server.d.ts",
84
- "import": "./dist/esm/server.mjs",
85
- "require": "./dist/cjs/server.js"
86
- },
87
- "./s3": {
88
- "types": "./dist/esm/providers/s3/index.d.ts",
89
- "import": "./dist/esm/providers/s3/index.mjs",
90
- "require": "./dist/cjs/providers/s3/index.js",
91
- "react-native": "./src/providers/s3/index.ts"
92
- },
93
- "./s3/server": {
94
- "types": "./dist/esm/providers/s3/server.d.ts",
95
- "import": "./dist/esm/providers/s3/server.mjs",
96
- "require": "./dist/cjs/providers/s3/server.js"
97
- },
98
- "./package.json": "./package.json"
99
- },
100
- "peerDependencies": {
101
- "@aws-amplify/core": "^6.1.0"
102
- },
103
- "devDependencies": {
104
- "@aws-amplify/core": "6.3.3",
105
- "@aws-amplify/react-native": "1.1.1",
106
- "typescript": "5.0.2"
107
- },
108
- "gitHead": "937771cfbf566d85e680112acef0bf428c24a1df"
2
+ "name": "@aws-amplify/storage",
3
+ "version": "6.4.8-multi-bucket.043d913.0+043d913",
4
+ "description": "Storage category of aws-amplify",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.mjs",
7
+ "react-native": {
8
+ "./dist/cjs/index": "./src/index.ts",
9
+ "fast-xml-parser": "fast-xml-parser",
10
+ "buffer": "buffer"
11
+ },
12
+ "typings": "./dist/esm/index.d.ts",
13
+ "browser": {
14
+ "./dist/esm/providers/s3/utils/client/runtime/base64/index.native.mjs": "./dist/esm/providers/s3/utils/client/runtime/base64/index.browser.mjs",
15
+ "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/fetch.mjs": "./dist/esm/providers/s3/utils/client/runtime/s3TransferHandler/xhr.mjs",
16
+ "./dist/esm/providers/s3/utils/client/runtime/xmlParser/pureJs.mjs": "./dist/esm/providers/s3/utils/client/runtime/xmlParser/dom.mjs",
17
+ "fast-xml-parser": false,
18
+ "buffer": false
19
+ },
20
+ "sideEffects": false,
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
26
+ "build-with-test": "npm test && npm run build",
27
+ "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
28
+ "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
29
+ "build:watch": "npm run build:esm-cjs -- --watch",
30
+ "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
31
+ "clean": "npm run clean:size && rimraf lib-esm lib dist",
32
+ "clean:size": "rimraf dual-publish-tmp tmp*",
33
+ "format": "echo \"Not implemented\"",
34
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
35
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
36
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
37
+ },
38
+ "typesVersions": {
39
+ ">=4.2": {
40
+ "s3": [
41
+ "./dist/esm/providers/s3/index.d.ts"
42
+ ],
43
+ "server": [
44
+ "./dist/esm/server.d.ts"
45
+ ],
46
+ "s3/server": [
47
+ "./dist/esm/providers/s3/server.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/aws-amplify/amplify-js.git"
54
+ },
55
+ "author": "Amazon Web Services",
56
+ "license": "Apache-2.0",
57
+ "bugs": {
58
+ "url": "https://github.com/aws/aws-amplify/issues"
59
+ },
60
+ "homepage": "https://aws-amplify.github.io/",
61
+ "files": [
62
+ "dist/cjs",
63
+ "dist/esm",
64
+ "src",
65
+ "server",
66
+ "s3"
67
+ ],
68
+ "dependencies": {
69
+ "@aws-sdk/types": "3.398.0",
70
+ "@smithy/md5-js": "2.0.7",
71
+ "buffer": "4.9.2",
72
+ "fast-xml-parser": "^4.2.5",
73
+ "tslib": "^2.5.0"
74
+ },
75
+ "exports": {
76
+ ".": {
77
+ "types": "./dist/esm/index.d.ts",
78
+ "import": "./dist/esm/index.mjs",
79
+ "require": "./dist/cjs/index.js",
80
+ "react-native": "./src/index.ts"
81
+ },
82
+ "./server": {
83
+ "types": "./dist/esm/server.d.ts",
84
+ "import": "./dist/esm/server.mjs",
85
+ "require": "./dist/cjs/server.js"
86
+ },
87
+ "./s3": {
88
+ "types": "./dist/esm/providers/s3/index.d.ts",
89
+ "import": "./dist/esm/providers/s3/index.mjs",
90
+ "require": "./dist/cjs/providers/s3/index.js",
91
+ "react-native": "./src/providers/s3/index.ts"
92
+ },
93
+ "./s3/server": {
94
+ "types": "./dist/esm/providers/s3/server.d.ts",
95
+ "import": "./dist/esm/providers/s3/server.mjs",
96
+ "require": "./dist/cjs/providers/s3/server.js"
97
+ },
98
+ "./package.json": "./package.json"
99
+ },
100
+ "peerDependencies": {
101
+ "@aws-amplify/core": "6.3.4-multi-bucket.043d913.0+043d913"
102
+ },
103
+ "devDependencies": {
104
+ "@aws-amplify/core": "6.3.4-multi-bucket.043d913.0+043d913",
105
+ "@aws-amplify/react-native": "1.1.2-multi-bucket.043d913.0+043d913",
106
+ "typescript": "5.0.2"
107
+ },
108
+ "gitHead": "043d913f0702a6c86b30c154c826d2f03b760ed7"
109
109
  }
@@ -13,6 +13,8 @@ export enum StorageValidationErrorCode {
13
13
  NoDestinationPath = 'NoDestinationPath',
14
14
  NoBucket = 'NoBucket',
15
15
  NoRegion = 'NoRegion',
16
+ InvalidStorageBucket = 'InvalidStorageBucket',
17
+ InvalidCopyOperationStorageBucket = 'InvalidCopyOperationStorageBucket',
16
18
  InvalidStorageOperationPrefixInput = 'InvalidStorageOperationPrefixInput',
17
19
  InvalidStorageOperationInput = 'InvalidStorageOperationInput',
18
20
  InvalidStoragePathInput = 'InvalidStoragePathInput',
@@ -70,4 +72,11 @@ export const validationErrorMap: AmplifyErrorMap<StorageValidationErrorCode> = {
70
72
  [StorageValidationErrorCode.InvalidStoragePathInput]: {
71
73
  message: 'Input `path` does not allow a leading slash (/).',
72
74
  },
75
+ [StorageValidationErrorCode.InvalidStorageBucket]: {
76
+ message:
77
+ 'Unable to lookup bucket from provided name in Amplify configuration.',
78
+ },
79
+ [StorageValidationErrorCode.InvalidCopyOperationStorageBucket]: {
80
+ message: 'Missing bucket option in either source or destination.',
81
+ },
73
82
  };
@@ -10,7 +10,7 @@ import {
10
10
  CopyWithPathInput,
11
11
  CopyWithPathOutput,
12
12
  } from '../../types';
13
- import { ResolvedS3Config } from '../../types/options';
13
+ import { ResolvedS3Config, StorageBucket } from '../../types/options';
14
14
  import {
15
15
  isInputWithPath,
16
16
  resolveS3ConfigAndInput,
@@ -26,6 +26,22 @@ const isCopyInputWithPath = (
26
26
  input: CopyInput | CopyWithPathInput,
27
27
  ): input is CopyWithPathInput => isInputWithPath(input.source);
28
28
 
29
+ const storageBucketAssertion = (
30
+ sourceBucket?: StorageBucket,
31
+ destBucket?: StorageBucket,
32
+ ) => {
33
+ /** For multi-bucket, both source and destination bucket needs to be passed in
34
+ * or both can be undefined and we fallback to singleton's default value
35
+ */
36
+ assertValidationError(
37
+ // Both src & dest bucket option is present is acceptable
38
+ (sourceBucket !== undefined && destBucket !== undefined) ||
39
+ // or both are undefined is also acceptable
40
+ (!destBucket && !sourceBucket),
41
+ StorageValidationErrorCode.InvalidCopyOperationStorageBucket,
42
+ );
43
+ };
44
+
29
45
  export const copy = async (
30
46
  amplify: AmplifyClassV6,
31
47
  input: CopyInput | CopyWithPathInput,
@@ -40,8 +56,18 @@ const copyWithPath = async (
40
56
  input: CopyWithPathInput,
41
57
  ): Promise<CopyWithPathOutput> => {
42
58
  const { source, destination } = input;
43
- const { s3Config, bucket, identityId } =
44
- await resolveS3ConfigAndInput(amplify);
59
+
60
+ storageBucketAssertion(source.bucket, destination.bucket);
61
+
62
+ const { bucket: sourceBucket, identityId } = await resolveS3ConfigAndInput(
63
+ amplify,
64
+ input.source,
65
+ );
66
+
67
+ const { s3Config, bucket: destBucket } = await resolveS3ConfigAndInput(
68
+ amplify,
69
+ input.destination,
70
+ ); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
45
71
 
46
72
  assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);
47
73
  assertValidationError(
@@ -58,14 +84,14 @@ const copyWithPath = async (
58
84
  identityId,
59
85
  );
60
86
 
61
- const finalCopySource = `${bucket}/${sourcePath}`;
87
+ const finalCopySource = `${sourceBucket}/${sourcePath}`;
62
88
  const finalCopyDestination = destinationPath;
63
89
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
64
90
 
65
91
  await serviceCopy({
66
92
  source: finalCopySource,
67
93
  destination: finalCopyDestination,
68
- bucket,
94
+ bucket: destBucket,
69
95
  s3Config,
70
96
  });
71
97
 
@@ -77,41 +103,39 @@ export const copyWithKey = async (
77
103
  amplify: AmplifyClassV6,
78
104
  input: CopyInput,
79
105
  ): Promise<CopyOutput> => {
80
- const {
81
- source: { key: sourceKey },
82
- destination: { key: destinationKey },
83
- } = input;
106
+ const { source, destination } = input;
107
+
108
+ storageBucketAssertion(source.bucket, destination.bucket);
84
109
 
85
- assertValidationError(!!sourceKey, StorageValidationErrorCode.NoSourceKey);
110
+ assertValidationError(!!source.key, StorageValidationErrorCode.NoSourceKey);
86
111
  assertValidationError(
87
- !!destinationKey,
112
+ !!destination.key,
88
113
  StorageValidationErrorCode.NoDestinationKey,
89
114
  );
90
115
 
116
+ const { bucket: sourceBucket, keyPrefix: sourceKeyPrefix } =
117
+ await resolveS3ConfigAndInput(amplify, source);
118
+
91
119
  const {
92
120
  s3Config,
93
- bucket,
94
- keyPrefix: sourceKeyPrefix,
95
- } = await resolveS3ConfigAndInput(amplify, input.source);
96
- const { keyPrefix: destinationKeyPrefix } = await resolveS3ConfigAndInput(
97
- amplify,
98
- input.destination,
99
- ); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
121
+ bucket: destBucket,
122
+ keyPrefix: destinationKeyPrefix,
123
+ } = await resolveS3ConfigAndInput(amplify, destination); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly.
100
124
 
101
125
  // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is "protected", currently it's ${srcLevel}`
102
- const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
103
- const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
126
+ const finalCopySource = `${sourceBucket}/${sourceKeyPrefix}${source.key}`;
127
+ const finalCopyDestination = `${destinationKeyPrefix}${destination.key}`;
104
128
  logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
105
129
 
106
130
  await serviceCopy({
107
131
  source: finalCopySource,
108
132
  destination: finalCopyDestination,
109
- bucket,
133
+ bucket: destBucket,
110
134
  s3Config,
111
135
  });
112
136
 
113
137
  return {
114
- key: destinationKey,
138
+ key: destination.key,
115
139
  };
116
140
  };
117
141
 
@@ -17,6 +17,8 @@ export {
17
17
  DownloadDataOptionsWithKey,
18
18
  CopyDestinationOptionsWithKey,
19
19
  CopySourceOptionsWithKey,
20
+ CopyWithPathSourceOptions,
21
+ CopyWithPathDestinationOptions,
20
22
  } from './options';
21
23
  export {
22
24
  UploadDataOutput,
@@ -20,6 +20,8 @@ import {
20
20
  import {
21
21
  CopyDestinationOptionsWithKey,
22
22
  CopySourceOptionsWithKey,
23
+ CopyWithPathDestinationOptions,
24
+ CopyWithPathSourceOptions,
23
25
  DownloadDataOptionsWithKey,
24
26
  DownloadDataOptionsWithPath,
25
27
  GetPropertiesOptionsWithKey,
@@ -47,7 +49,10 @@ export type CopyInput = StorageCopyInputWithKey<
47
49
  /**
48
50
  * Input type with path for S3 copy API.
49
51
  */
50
- export type CopyWithPathInput = StorageCopyInputWithPath;
52
+ export type CopyWithPathInput = StorageCopyInputWithPath<
53
+ CopyWithPathSourceOptions,
54
+ CopyWithPathDestinationOptions
55
+ >;
51
56
 
52
57
  /**
53
58
  * @deprecated Use {@link GetPropertiesWithPathInput} instead.
@@ -10,12 +10,19 @@ import {
10
10
  StorageListPaginateOptions,
11
11
  } from '../../../types/options';
12
12
 
13
+ export interface BucketInfo {
14
+ bucketName: string;
15
+ region: string;
16
+ }
17
+
18
+ export type StorageBucket = string | BucketInfo;
13
19
  interface CommonOptions {
14
20
  /**
15
21
  * Whether to use accelerate endpoint.
16
22
  * @default false
17
23
  */
18
24
  useAccelerateEndpoint?: boolean;
25
+ bucket?: StorageBucket;
19
26
  }
20
27
 
21
28
  /** @deprecated This may be removed in the next major version. */
@@ -163,14 +170,23 @@ export type UploadDataOptionsWithPath = UploadDataOptions;
163
170
  export type CopySourceOptionsWithKey = ReadOptions & {
164
171
  /** @deprecated This may be removed in the next major version. */
165
172
  key: string;
173
+ bucket?: StorageBucket;
166
174
  };
167
175
 
168
176
  /** @deprecated This may be removed in the next major version. */
169
177
  export type CopyDestinationOptionsWithKey = WriteOptions & {
170
178
  /** @deprecated This may be removed in the next major version. */
171
179
  key: string;
180
+ bucket?: StorageBucket;
172
181
  };
173
182
 
183
+ export interface CopyWithPathSourceOptions {
184
+ bucket?: StorageBucket;
185
+ }
186
+ export interface CopyWithPathDestinationOptions {
187
+ bucket?: StorageBucket;
188
+ }
189
+
174
190
  /**
175
191
  * Internal only type for S3 API handlers' config parameter.
176
192
  *
@@ -6,7 +6,7 @@ import { AmplifyClassV6, StorageAccessLevel } from '@aws-amplify/core';
6
6
  import { assertValidationError } from '../../../errors/utils/assertValidationError';
7
7
  import { StorageValidationErrorCode } from '../../../errors/types/validation';
8
8
  import { resolvePrefix as defaultPrefixResolver } from '../../../utils/resolvePrefix';
9
- import { ResolvedS3Config } from '../types/options';
9
+ import { BucketInfo, ResolvedS3Config, StorageBucket } from '../types/options';
10
10
 
11
11
  import { DEFAULT_ACCESS_LEVEL, LOCAL_TESTING_S3_ENDPOINT } from './constants';
12
12
 
@@ -14,6 +14,7 @@ interface S3ApiOptions {
14
14
  accessLevel?: StorageAccessLevel;
15
15
  targetIdentityId?: string;
16
16
  useAccelerateEndpoint?: boolean;
17
+ bucket?: StorageBucket;
17
18
  }
18
19
 
19
20
  interface ResolvedS3ConfigAndInput {
@@ -62,8 +63,16 @@ export const resolveS3ConfigAndInput = async (
62
63
  return credentials;
63
64
  };
64
65
 
65
- const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } =
66
- amplify.getConfig()?.Storage?.S3 ?? {};
66
+ const {
67
+ bucket: defaultBucket,
68
+ region: defaultRegion,
69
+ dangerouslyConnectToHttpEndpointForTesting,
70
+ buckets,
71
+ } = amplify.getConfig()?.Storage?.S3 ?? {};
72
+
73
+ const { bucket = defaultBucket, region = defaultRegion } =
74
+ (apiOptions?.bucket && resolveBucketConfig(apiOptions, buckets)) || {};
75
+
67
76
  assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);
68
77
  assertValidationError(!!region, StorageValidationErrorCode.NoRegion);
69
78
 
@@ -73,15 +82,14 @@ export const resolveS3ConfigAndInput = async (
73
82
  isObjectLockEnabled,
74
83
  } = amplify.libraryOptions?.Storage?.S3 ?? {};
75
84
 
76
- const keyPrefix = await prefixResolver({
77
- accessLevel:
78
- apiOptions?.accessLevel ?? defaultAccessLevel ?? DEFAULT_ACCESS_LEVEL,
79
- // use conditional assign to make tsc happy because StorageOptions is a union type that may not have targetIdentityId
80
- targetIdentityId:
81
- apiOptions?.accessLevel === 'protected'
82
- ? apiOptions?.targetIdentityId ?? identityId
83
- : identityId,
84
- });
85
+ const accessLevel =
86
+ apiOptions?.accessLevel ?? defaultAccessLevel ?? DEFAULT_ACCESS_LEVEL;
87
+ const targetIdentityId =
88
+ accessLevel === 'protected'
89
+ ? apiOptions?.targetIdentityId ?? identityId
90
+ : identityId;
91
+
92
+ const keyPrefix = await prefixResolver({ accessLevel, targetIdentityId });
85
93
 
86
94
  return {
87
95
  s3Config: {
@@ -101,3 +109,25 @@ export const resolveS3ConfigAndInput = async (
101
109
  isObjectLockEnabled,
102
110
  };
103
111
  };
112
+
113
+ const resolveBucketConfig = (
114
+ apiOptions: S3ApiOptions,
115
+ buckets: Record<string, BucketInfo> | undefined,
116
+ ): { bucket: string; region: string } | undefined => {
117
+ if (typeof apiOptions.bucket === 'string') {
118
+ const bucketConfig = buckets?.[apiOptions.bucket];
119
+ assertValidationError(
120
+ !!bucketConfig,
121
+ StorageValidationErrorCode.InvalidStorageBucket,
122
+ );
123
+
124
+ return { bucket: bucketConfig.bucketName, region: bucketConfig.region };
125
+ }
126
+
127
+ if (typeof apiOptions.bucket === 'object') {
128
+ return {
129
+ bucket: apiOptions.bucket.bucketName,
130
+ region: apiOptions.bucket.region,
131
+ };
132
+ }
133
+ };
@@ -90,9 +90,9 @@ export interface StorageCopyInputWithKey<
90
90
  destination: DestinationOptions;
91
91
  }
92
92
 
93
- export interface StorageCopyInputWithPath {
94
- source: StorageOperationInputWithPath;
95
- destination: StorageOperationInputWithPath;
93
+ export interface StorageCopyInputWithPath<SourceOptions, DestinationOptions> {
94
+ source: StorageOperationInputWithPath & SourceOptions;
95
+ destination: StorageOperationInputWithPath & DestinationOptions;
96
96
  }
97
97
 
98
98
  /**