@aws-amplify/storage 6.6.4-server-upload.2bbdb67.0 → 6.6.4-server-upload.1e86212.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.
- package/dist/cjs/providers/s3/apis/internal/getUrl.js +1 -0
- package/dist/cjs/providers/s3/apis/internal/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/utils/client/getObject.js +18 -1
- package/dist/cjs/providers/s3/utils/client/getObject.js.map +1 -1
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs +1 -0
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/client/getObject.mjs +19 -2
- package/dist/esm/providers/s3/utils/client/getObject.mjs.map +1 -1
- package/package.json +10 -6
- package/src/providers/s3/apis/internal/getUrl.ts +1 -0
- package/src/providers/s3/utils/client/getObject.ts +20 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUrl.js","sources":["../../../../../../src/providers/s3/apis/internal/getUrl.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.getUrl = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../../errors/types/validation\");\nconst client_1 = require(\"../../utils/client\");\nconst utils_2 = require(\"../../utils\");\nconst assertValidationError_1 = require(\"../../../../errors/utils/assertValidationError\");\nconst constants_1 = require(\"../../utils/constants\");\nconst constructContentDisposition_1 = require(\"../../utils/constructContentDisposition\");\nconst getProperties_1 = require(\"./getProperties\");\nconst getUrl = async (amplify, input) => {\n const { options: getUrlOptions } = input;\n const { s3Config, keyPrefix, bucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, getUrlOptions);\n const { inputType, objectKey } = (0, utils_2.validateStorageOperationInput)(input, identityId);\n const finalKey = inputType === constants_1.STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;\n if (getUrlOptions?.validateObjectExistence) {\n await (0, getProperties_1.getProperties)(amplify, input, utils_1.StorageAction.GetUrl);\n }\n let urlExpirationInSec = getUrlOptions?.expiresIn ?? constants_1.DEFAULT_PRESIGN_EXPIRATION;\n const resolvedCredential = typeof s3Config.credentials === 'function'\n ? await s3Config.credentials()\n : s3Config.credentials;\n const awsCredExpiration = resolvedCredential.expiration;\n if (awsCredExpiration) {\n const awsCredExpirationInSec = Math.floor((awsCredExpiration.getTime() - Date.now()) / 1000);\n urlExpirationInSec = Math.min(awsCredExpirationInSec, urlExpirationInSec);\n }\n const maxUrlExpirationInSec = constants_1.MAX_URL_EXPIRATION / 1000;\n (0, assertValidationError_1.assertValidationError)(urlExpirationInSec <= maxUrlExpirationInSec, validation_1.StorageValidationErrorCode.UrlExpirationMaxLimitExceed);\n // expiresAt is the minimum of credential expiration and url expiration\n return {\n url: await (0, client_1.getPresignedGetObjectUrl)({\n ...s3Config,\n credentials: resolvedCredential,\n expiration: urlExpirationInSec,\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(getUrlOptions?.contentDisposition && {\n ResponseContentDisposition: (0, constructContentDisposition_1.constructContentDisposition)(getUrlOptions.contentDisposition),\n }),\n ...(getUrlOptions?.contentType && {\n ResponseContentType: getUrlOptions.contentType,\n }),\n }),\n expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),\n };\n};\nexports.getUrl = getUrl;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AACxB,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACpE,MAAM,QAAQ,GAAG,OAAO,C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+
{"version":3,"file":"getUrl.js","sources":["../../../../../../src/providers/s3/apis/internal/getUrl.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.getUrl = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../../errors/types/validation\");\nconst client_1 = require(\"../../utils/client\");\nconst utils_2 = require(\"../../utils\");\nconst assertValidationError_1 = require(\"../../../../errors/utils/assertValidationError\");\nconst constants_1 = require(\"../../utils/constants\");\nconst constructContentDisposition_1 = require(\"../../utils/constructContentDisposition\");\nconst getProperties_1 = require(\"./getProperties\");\nconst getUrl = async (amplify, input) => {\n const { options: getUrlOptions } = input;\n const { s3Config, keyPrefix, bucket, identityId } = await (0, utils_2.resolveS3ConfigAndInput)(amplify, getUrlOptions);\n const { inputType, objectKey } = (0, utils_2.validateStorageOperationInput)(input, identityId);\n const finalKey = inputType === constants_1.STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;\n if (getUrlOptions?.validateObjectExistence) {\n await (0, getProperties_1.getProperties)(amplify, input, utils_1.StorageAction.GetUrl);\n }\n let urlExpirationInSec = getUrlOptions?.expiresIn ?? constants_1.DEFAULT_PRESIGN_EXPIRATION;\n const resolvedCredential = typeof s3Config.credentials === 'function'\n ? await s3Config.credentials()\n : s3Config.credentials;\n const awsCredExpiration = resolvedCredential.expiration;\n if (awsCredExpiration) {\n const awsCredExpirationInSec = Math.floor((awsCredExpiration.getTime() - Date.now()) / 1000);\n urlExpirationInSec = Math.min(awsCredExpirationInSec, urlExpirationInSec);\n }\n const maxUrlExpirationInSec = constants_1.MAX_URL_EXPIRATION / 1000;\n (0, assertValidationError_1.assertValidationError)(urlExpirationInSec <= maxUrlExpirationInSec, validation_1.StorageValidationErrorCode.UrlExpirationMaxLimitExceed);\n // expiresAt is the minimum of credential expiration and url expiration\n return {\n url: await (0, client_1.getPresignedGetObjectUrl)({\n ...s3Config,\n credentials: resolvedCredential,\n expiration: urlExpirationInSec,\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(getUrlOptions?.contentDisposition && {\n ResponseContentDisposition: (0, constructContentDisposition_1.constructContentDisposition)(getUrlOptions.contentDisposition),\n }),\n ...(getUrlOptions?.contentType && {\n ResponseContentType: getUrlOptions.contentType,\n }),\n method: input.options?.method,\n }),\n expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),\n };\n};\nexports.getUrl = getUrl;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AACxB,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACpE,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,uBAAuB,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC1F,MAAM,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACrD,MAAM,6BAA6B,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACzF,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD,MAAM,MAAM,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AACzC,IAAI,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;AAC7C,IAAI,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,OAAO,CAAC,uBAAuB,EAAE,OAAO,EAAE,aAAa,CAAC,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CAAC,wBAAwB,EAAE;AAC1D,YAAY,GAAG,QAAQ;AACvB,YAAY,WAAW,EAAE,kBAAkB;AAC3C,YAAY,UAAU,EAAE,kBAAkB;AAC1C,SAAS,EAAE;AACX,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,EAAE,QAAQ;AACzB,YAAY,IAAI,aAAa,EAAE,kBAAkB,IAAI;AACrD,gBAAgB,0BAA0B,EAAE,IAAI,6BAA6B,CAAC,2BAA2B,EAAE,aAAa,CAAC,kBAAkB,CAAC;AAC5I,aAAa,CAAC;AACd,YAAY,IAAI,aAAa,EAAE,WAAW,IAAI;AAC9C,gBAAgB,mBAAmB,EAAE,aAAa,CAAC,WAAW;AAC9D,aAAa,CAAC;AACd,YAAY,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM;AACzC,SAAS,CAAC;AACV,QAAQ,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,kBAAkB,GAAG,IAAI,CAAC;AACnE,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,MAAM,GAAG,MAAM;;"}
|
|
@@ -7,6 +7,10 @@ exports.getPresignedGetObjectUrl = exports.getObject = void 0;
|
|
|
7
7
|
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
8
8
|
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
9
9
|
const composers_1 = require("@aws-amplify/core/internals/aws-client-utils/composers");
|
|
10
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
11
|
+
const hash_node_1 = require("@smithy/hash-node");
|
|
12
|
+
const util_format_url_1 = require("@aws-sdk/util-format-url");
|
|
13
|
+
const url_parser_1 = require("@smithy/url-parser");
|
|
10
14
|
const base_1 = require("./base");
|
|
11
15
|
const utils_2 = require("./utils");
|
|
12
16
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
@@ -88,10 +92,23 @@ exports.getObject = (0, composers_1.composeServiceApi)(utils_2.s3TransferHandler
|
|
|
88
92
|
const getPresignedGetObjectUrl = async (config, input) => {
|
|
89
93
|
const endpoint = base_1.defaultConfig.endpointResolver(config, input);
|
|
90
94
|
const { url, headers, method } = await getObjectSerializer(input, endpoint);
|
|
95
|
+
if (input.method === 'PUT') {
|
|
96
|
+
const presigner = new s3_request_presigner_1.S3RequestPresigner({
|
|
97
|
+
credentials: config.credentials,
|
|
98
|
+
region: config.region,
|
|
99
|
+
sha256: hash_node_1.Hash.bind(null, 'sha256'),
|
|
100
|
+
});
|
|
101
|
+
const signedUrlObject = await presigner.presign({
|
|
102
|
+
...(0, url_parser_1.parseUrl)(url.toString()),
|
|
103
|
+
headers,
|
|
104
|
+
method,
|
|
105
|
+
});
|
|
106
|
+
return new utils_1.AmplifyUrl((0, util_format_url_1.formatUrl)(signedUrlObject));
|
|
107
|
+
}
|
|
91
108
|
// TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.
|
|
92
109
|
// It requires changes in presignUrl. Without this change, the generated url still works,
|
|
93
110
|
// but not the same as other tools like AWS SDK and CLI.
|
|
94
|
-
url.searchParams.append(utils_2.CONTENT_SHA256_HEADER,
|
|
111
|
+
url.searchParams.append(utils_2.CONTENT_SHA256_HEADER, 'UNSIGNED-PAYLOAD');
|
|
95
112
|
if (config.userAgentValue) {
|
|
96
113
|
url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);
|
|
97
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getObject.js","sources":["../../../../../../src/providers/s3/utils/client/getObject.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.getPresignedGetObjectUrl = exports.getObject = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\nconst base_1 = require(\"./base\");\nconst utils_2 = require(\"./utils\");\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst getObjectSerializer = async (input, endpoint) => {\n const url = new utils_1.AmplifyUrl(endpoint.url.toString());\n (0, utils_2.validateS3RequiredParameter)(!!input.Key, 'Key');\n url.pathname = (0, utils_2.serializePathnameObjectKey)(url, input.Key);\n return {\n method: input.method ?? 'GET',\n headers: {\n ...(input.Range && { Range: input.Range }),\n },\n url,\n };\n};\nconst getObjectDeserializer = async (response) => {\n if (response.statusCode >= 300) {\n const error = (await (0, utils_2.parseXmlError)(response));\n throw (0, utils_2.buildStorageServiceError)(error, response.statusCode);\n }\n else {\n return {\n ...(0, utils_2.map)(response.headers, {\n DeleteMarker: ['x-amz-delete-marker', utils_2.deserializeBoolean],\n AcceptRanges: 'accept-ranges',\n Expiration: 'x-amz-expiration',\n Restore: 'x-amz-restore',\n LastModified: ['last-modified', utils_2.deserializeTimestamp],\n ContentLength: ['content-length', utils_2.deserializeNumber],\n ETag: 'etag',\n ChecksumCRC32: 'x-amz-checksum-crc32',\n ChecksumCRC32C: 'x-amz-checksum-crc32c',\n ChecksumSHA1: 'x-amz-checksum-sha1',\n ChecksumSHA256: 'x-amz-checksum-sha256',\n MissingMeta: ['x-amz-missing-meta', utils_2.deserializeNumber],\n VersionId: 'x-amz-version-id',\n CacheControl: 'cache-control',\n ContentDisposition: 'content-disposition',\n ContentEncoding: 'content-encoding',\n ContentLanguage: 'content-language',\n ContentRange: 'content-range',\n ContentType: 'content-type',\n Expires: ['expires', utils_2.deserializeTimestamp],\n WebsiteRedirectLocation: 'x-amz-website-redirect-location',\n ServerSideEncryption: 'x-amz-server-side-encryption',\n SSECustomerAlgorithm: 'x-amz-server-side-encryption-customer-algorithm',\n SSECustomerKeyMD5: 'x-amz-server-side-encryption-customer-key-md5',\n SSEKMSKeyId: 'x-amz-server-side-encryption-aws-kms-key-id',\n BucketKeyEnabled: [\n 'x-amz-server-side-encryption-bucket-key-enabled',\n utils_2.deserializeBoolean,\n ],\n StorageClass: 'x-amz-storage-class',\n RequestCharged: 'x-amz-request-charged',\n ReplicationStatus: 'x-amz-replication-status',\n PartsCount: ['x-amz-mp-parts-count', utils_2.deserializeNumber],\n TagCount: ['x-amz-tagging-count', utils_2.deserializeNumber],\n ObjectLockMode: 'x-amz-object-lock-mode',\n ObjectLockRetainUntilDate: [\n 'x-amz-object-lock-retain-until-date',\n utils_2.deserializeTimestamp,\n ],\n ObjectLockLegalHoldStatus: 'x-amz-object-lock-legal-hold',\n }),\n Metadata: (0, utils_2.deserializeMetadata)(response.headers),\n $metadata: (0, aws_client_utils_1.parseMetadata)(response),\n // @ts-expect-error The body is a CompatibleHttpResponse type because the lower-level handler is XHR instead of\n // fetch, which represents payload in Blob instread of ReadableStream.\n Body: response.body,\n };\n }\n};\nexports.getObject = (0, composers_1.composeServiceApi)(utils_2.s3TransferHandler, getObjectSerializer, getObjectDeserializer, { ...base_1.defaultConfig, responseType: 'blob' });\n/**\n * Get a presigned URL for the `getObject` API.\n *\n * @internal\n */\nconst getPresignedGetObjectUrl = async (config, input) => {\n const endpoint = base_1.defaultConfig.endpointResolver(config, input);\n const { url, headers, method } = await getObjectSerializer(input, endpoint);\n // TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.\n // It requires changes in presignUrl. Without this change, the generated url still works,\n // but not the same as other tools like AWS SDK and CLI.\n url.searchParams.append(utils_2.CONTENT_SHA256_HEADER, aws_client_utils_1.EMPTY_SHA256_HASH);\n if (config.userAgentValue) {\n url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);\n }\n if (input.ResponseContentType) {\n url.searchParams.append('response-content-type', input.ResponseContentType);\n }\n if (input.ResponseContentDisposition) {\n url.searchParams.append('response-content-disposition', input.ResponseContentDisposition);\n }\n for (const [headerName, value] of Object.entries(headers).sort(([key1], [key2]) => key1.localeCompare(key2))) {\n url.searchParams.append(headerName, value);\n }\n return (0, aws_client_utils_1.presignUrl)({ method, url, body: undefined }, {\n signingService: base_1.defaultConfig.service,\n signingRegion: config.region,\n ...base_1.defaultConfig,\n ...config,\n });\n};\nexports.getPresignedGetObjectUrl = getPresignedGetObjectUrl;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,wBAAwB,GAAG,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;AAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AACnF,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC,CAAC;AACtF,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,mBAAmB,GAAG,OAAO,KAAK,EAAE,QAAQ,KAAK;AACvD,IAAI,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChE,IAAI,IAAI,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACjE,IAAI,GAAG,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,0BAA0B,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AAC3E,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,KAAK;AACrC,QAAQ,OAAO,EAAE;AACjB,YAAY,IAAI,KAAK,CAAC,KAAK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,EAAE;AAClH,QAAQ,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,OAAO,IAAI,kBAAkB,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;AAChF,QAAQ,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,OAAO;AACpD,QAAQ,aAAa,EAAE,MAAM,CAAC,MAAM;AACpC,QAAQ,GAAG,MAAM,CAAC,aAAa;AAC/B,QAAQ,GAAG,MAAM;AACjB,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,wBAAwB,GAAG,wBAAwB;;"}
|
|
1
|
+
{"version":3,"file":"getObject.js","sources":["../../../../../../src/providers/s3/utils/client/getObject.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.getPresignedGetObjectUrl = exports.getObject = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\nconst s3_request_presigner_1 = require(\"@aws-sdk/s3-request-presigner\");\nconst hash_node_1 = require(\"@smithy/hash-node\");\nconst util_format_url_1 = require(\"@aws-sdk/util-format-url\");\nconst url_parser_1 = require(\"@smithy/url-parser\");\nconst base_1 = require(\"./base\");\nconst utils_2 = require(\"./utils\");\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst getObjectSerializer = async (input, endpoint) => {\n const url = new utils_1.AmplifyUrl(endpoint.url.toString());\n (0, utils_2.validateS3RequiredParameter)(!!input.Key, 'Key');\n url.pathname = (0, utils_2.serializePathnameObjectKey)(url, input.Key);\n return {\n method: input.method ?? 'GET',\n headers: {\n ...(input.Range && { Range: input.Range }),\n },\n url,\n };\n};\nconst getObjectDeserializer = async (response) => {\n if (response.statusCode >= 300) {\n const error = (await (0, utils_2.parseXmlError)(response));\n throw (0, utils_2.buildStorageServiceError)(error, response.statusCode);\n }\n else {\n return {\n ...(0, utils_2.map)(response.headers, {\n DeleteMarker: ['x-amz-delete-marker', utils_2.deserializeBoolean],\n AcceptRanges: 'accept-ranges',\n Expiration: 'x-amz-expiration',\n Restore: 'x-amz-restore',\n LastModified: ['last-modified', utils_2.deserializeTimestamp],\n ContentLength: ['content-length', utils_2.deserializeNumber],\n ETag: 'etag',\n ChecksumCRC32: 'x-amz-checksum-crc32',\n ChecksumCRC32C: 'x-amz-checksum-crc32c',\n ChecksumSHA1: 'x-amz-checksum-sha1',\n ChecksumSHA256: 'x-amz-checksum-sha256',\n MissingMeta: ['x-amz-missing-meta', utils_2.deserializeNumber],\n VersionId: 'x-amz-version-id',\n CacheControl: 'cache-control',\n ContentDisposition: 'content-disposition',\n ContentEncoding: 'content-encoding',\n ContentLanguage: 'content-language',\n ContentRange: 'content-range',\n ContentType: 'content-type',\n Expires: ['expires', utils_2.deserializeTimestamp],\n WebsiteRedirectLocation: 'x-amz-website-redirect-location',\n ServerSideEncryption: 'x-amz-server-side-encryption',\n SSECustomerAlgorithm: 'x-amz-server-side-encryption-customer-algorithm',\n SSECustomerKeyMD5: 'x-amz-server-side-encryption-customer-key-md5',\n SSEKMSKeyId: 'x-amz-server-side-encryption-aws-kms-key-id',\n BucketKeyEnabled: [\n 'x-amz-server-side-encryption-bucket-key-enabled',\n utils_2.deserializeBoolean,\n ],\n StorageClass: 'x-amz-storage-class',\n RequestCharged: 'x-amz-request-charged',\n ReplicationStatus: 'x-amz-replication-status',\n PartsCount: ['x-amz-mp-parts-count', utils_2.deserializeNumber],\n TagCount: ['x-amz-tagging-count', utils_2.deserializeNumber],\n ObjectLockMode: 'x-amz-object-lock-mode',\n ObjectLockRetainUntilDate: [\n 'x-amz-object-lock-retain-until-date',\n utils_2.deserializeTimestamp,\n ],\n ObjectLockLegalHoldStatus: 'x-amz-object-lock-legal-hold',\n }),\n Metadata: (0, utils_2.deserializeMetadata)(response.headers),\n $metadata: (0, aws_client_utils_1.parseMetadata)(response),\n // @ts-expect-error The body is a CompatibleHttpResponse type because the lower-level handler is XHR instead of\n // fetch, which represents payload in Blob instread of ReadableStream.\n Body: response.body,\n };\n }\n};\nexports.getObject = (0, composers_1.composeServiceApi)(utils_2.s3TransferHandler, getObjectSerializer, getObjectDeserializer, { ...base_1.defaultConfig, responseType: 'blob' });\n/**\n * Get a presigned URL for the `getObject` API.\n *\n * @internal\n */\nconst getPresignedGetObjectUrl = async (config, input) => {\n const endpoint = base_1.defaultConfig.endpointResolver(config, input);\n const { url, headers, method } = await getObjectSerializer(input, endpoint);\n if (input.method === 'PUT') {\n const presigner = new s3_request_presigner_1.S3RequestPresigner({\n credentials: config.credentials,\n region: config.region,\n sha256: hash_node_1.Hash.bind(null, 'sha256'),\n });\n const signedUrlObject = await presigner.presign({\n ...(0, url_parser_1.parseUrl)(url.toString()),\n headers,\n method,\n });\n return new utils_1.AmplifyUrl((0, util_format_url_1.formatUrl)(signedUrlObject));\n }\n // TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.\n // It requires changes in presignUrl. Without this change, the generated url still works,\n // but not the same as other tools like AWS SDK and CLI.\n url.searchParams.append(utils_2.CONTENT_SHA256_HEADER, 'UNSIGNED-PAYLOAD');\n if (config.userAgentValue) {\n url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);\n }\n if (input.ResponseContentType) {\n url.searchParams.append('response-content-type', input.ResponseContentType);\n }\n if (input.ResponseContentDisposition) {\n url.searchParams.append('response-content-disposition', input.ResponseContentDisposition);\n }\n for (const [headerName, value] of Object.entries(headers).sort(([key1], [key2]) => key1.localeCompare(key2))) {\n url.searchParams.append(headerName, value);\n }\n return (0, aws_client_utils_1.presignUrl)({ method, url, body: undefined }, {\n signingService: base_1.defaultConfig.service,\n signingRegion: config.region,\n ...base_1.defaultConfig,\n ...config,\n });\n};\nexports.getPresignedGetObjectUrl = getPresignedGetObjectUrl;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,wBAAwB,GAAG,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;AAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AACnF,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC,CAAC;AACtF,MAAM,sBAAsB,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AACxE,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACjD,MAAM,iBAAiB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,mBAAmB,GAAG,OAAO,KAAK,EAAE,QAAQ,KAAK;AACvD,IAAI,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChE,IAAI,IAAI,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACjE,IAAI,GAAG,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,0BAA0B,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAA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|
|
1
|
-
{"version":3,"file":"getUrl.mjs","sources":["../../../../../../src/providers/s3/apis/internal/getUrl.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 { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { getPresignedGetObjectUrl } from '../../utils/client';\nimport { resolveS3ConfigAndInput, validateStorageOperationInput, } from '../../utils';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { DEFAULT_PRESIGN_EXPIRATION, MAX_URL_EXPIRATION, STORAGE_INPUT_KEY, } from '../../utils/constants';\nimport { constructContentDisposition } from '../../utils/constructContentDisposition';\nimport { getProperties } from './getProperties';\nexport const getUrl = async (amplify, input) => {\n const { options: getUrlOptions } = input;\n const { s3Config, keyPrefix, bucket, identityId } = await resolveS3ConfigAndInput(amplify, getUrlOptions);\n const { inputType, objectKey } = validateStorageOperationInput(input, identityId);\n const finalKey = inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;\n if (getUrlOptions?.validateObjectExistence) {\n await getProperties(amplify, input, StorageAction.GetUrl);\n }\n let urlExpirationInSec = getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;\n const resolvedCredential = typeof s3Config.credentials === 'function'\n ? await s3Config.credentials()\n : s3Config.credentials;\n const awsCredExpiration = resolvedCredential.expiration;\n if (awsCredExpiration) {\n const awsCredExpirationInSec = Math.floor((awsCredExpiration.getTime() - Date.now()) / 1000);\n urlExpirationInSec = Math.min(awsCredExpirationInSec, urlExpirationInSec);\n }\n const maxUrlExpirationInSec = MAX_URL_EXPIRATION / 1000;\n assertValidationError(urlExpirationInSec <= maxUrlExpirationInSec, StorageValidationErrorCode.UrlExpirationMaxLimitExceed);\n // expiresAt is the minimum of credential expiration and url expiration\n return {\n url: await getPresignedGetObjectUrl({\n ...s3Config,\n credentials: resolvedCredential,\n expiration: urlExpirationInSec,\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(getUrlOptions?.contentDisposition && {\n ResponseContentDisposition: constructContentDisposition(getUrlOptions.contentDisposition),\n }),\n ...(getUrlOptions?.contentType && {\n ResponseContentType: getUrlOptions.contentType,\n }),\n }),\n expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AASY,MAAC,MAAM,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AAChD,IAAI,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;AAC7C,IAAI,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAC9G,IAAI,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,6BAA6B,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACtF,IAAI,MAAM,QAAQ,GAAG,SAAS,KAAK,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AACzF,IAAI,IAAI,aAAa,EAAE,uBAAuB,EAAE;AAChD,QAAQ,MAAM,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;AAClE,KAAK;AACL,IAAI,IAAI,kBAAkB,GAAG,aAAa,EAAE,SAAS,IAAI,0BAA0B,CAAC;AACpF,IAAI,MAAM,kBAAkB,GAAG,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU;AACzE,UAAU,MAAM,QAAQ,CAAC,WAAW,EAAE;AACtC,UAAU,QAAQ,CAAC,WAAW,CAAC;AAC/B,IAAI,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,CAAC;AAC5D,IAAI,IAAI,iBAAiB,EAAE;AAC3B,QAAQ,MAAM,sBAAsB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC;AACrG,QAAQ,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAC;AAClF,KAAK;AACL,IAAI,MAAM,qBAAqB,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAC5D,IAAI,qBAAqB,CAAC,kBAAkB,IAAI,qBAAqB,EAAE,0BAA0B,CAAC,2BAA2B,CAAC,CAAC;AAC/H;AACA,IAAI,OAAO;AACX,QAAQ,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC5C,YAAY,GAAG,QAAQ;AACvB,YAAY,WAAW,EAAE,kBAAkB;AAC3C,YAAY,UAAU,EAAE,kBAAkB;AAC1C,SAAS,EAAE;AACX,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,EAAE,QAAQ;AACzB,YAAY,IAAI,aAAa,EAAE,kBAAkB,IAAI;AACrD,gBAAgB,0BAA0B,EAAE,2BAA2B,CAAC,aAAa,CAAC,kBAAkB,CAAC;AACzG,aAAa,CAAC;AACd,YAAY,IAAI,aAAa,EAAE,WAAW,IAAI;AAC9C,gBAAgB,mBAAmB,EAAE,aAAa,CAAC,WAAW;AAC9D,aAAa,CAAC;AACd,SAAS,CAAC;AACV,QAAQ,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,kBAAkB,GAAG,IAAI,CAAC;AACnE,KAAK,CAAC;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"getUrl.mjs","sources":["../../../../../../src/providers/s3/apis/internal/getUrl.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 { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { getPresignedGetObjectUrl } from '../../utils/client';\nimport { resolveS3ConfigAndInput, validateStorageOperationInput, } from '../../utils';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { DEFAULT_PRESIGN_EXPIRATION, MAX_URL_EXPIRATION, STORAGE_INPUT_KEY, } from '../../utils/constants';\nimport { constructContentDisposition } from '../../utils/constructContentDisposition';\nimport { getProperties } from './getProperties';\nexport const getUrl = async (amplify, input) => {\n const { options: getUrlOptions } = input;\n const { s3Config, keyPrefix, bucket, identityId } = await resolveS3ConfigAndInput(amplify, getUrlOptions);\n const { inputType, objectKey } = validateStorageOperationInput(input, identityId);\n const finalKey = inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;\n if (getUrlOptions?.validateObjectExistence) {\n await getProperties(amplify, input, StorageAction.GetUrl);\n }\n let urlExpirationInSec = getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;\n const resolvedCredential = typeof s3Config.credentials === 'function'\n ? await s3Config.credentials()\n : s3Config.credentials;\n const awsCredExpiration = resolvedCredential.expiration;\n if (awsCredExpiration) {\n const awsCredExpirationInSec = Math.floor((awsCredExpiration.getTime() - Date.now()) / 1000);\n urlExpirationInSec = Math.min(awsCredExpirationInSec, urlExpirationInSec);\n }\n const maxUrlExpirationInSec = MAX_URL_EXPIRATION / 1000;\n assertValidationError(urlExpirationInSec <= maxUrlExpirationInSec, StorageValidationErrorCode.UrlExpirationMaxLimitExceed);\n // expiresAt is the minimum of credential expiration and url expiration\n return {\n url: await getPresignedGetObjectUrl({\n ...s3Config,\n credentials: resolvedCredential,\n expiration: urlExpirationInSec,\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(getUrlOptions?.contentDisposition && {\n ResponseContentDisposition: constructContentDisposition(getUrlOptions.contentDisposition),\n }),\n ...(getUrlOptions?.contentType && {\n ResponseContentType: getUrlOptions.contentType,\n }),\n method: input.options?.method,\n }),\n expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;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5D,IAAI,qBAAqB,CAAC,kBAAkB,IAAI,qBAAqB,EAAE,0BAA0B,CAAC,2BAA2B,CAAC,CAAC;AAC/H;AACA,IAAI,OAAO;AACX,QAAQ,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC5C,YAAY,GAAG,QAAQ;AACvB,YAAY,WAAW,EAAE,kBAAkB;AAC3C,YAAY,UAAU,EAAE,kBAAkB;AAC1C,SAAS,EAAE;AACX,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,EAAE,QAAQ;AACzB,YAAY,IAAI,aAAa,EAAE,kBAAkB,IAAI;AACrD,gBAAgB,0BAA0B,EAAE,2BAA2B,CAAC,aAAa,CAAC,kBAAkB,CAAC;AACzG,aAAa,CAAC;AACd,YAAY,IAAI,aAAa,EAAE,WAAW,IAAI;AAC9C,gBAAgB,mBAAmB,EAAE,aAAa,CAAC,WAAW;AAC9D,aAAa,CAAC;AACd,YAAY,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM;AACzC,SAAS,CAAC;AACV,QAAQ,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,kBAAkB,GAAG,IAAI,CAAC;AACnE,KAAK,CAAC;AACN;;;;"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { parseMetadata,
|
|
1
|
+
import { parseMetadata, presignUrl } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
2
|
import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
4
|
+
import { S3RequestPresigner } from '@aws-sdk/s3-request-presigner';
|
|
5
|
+
import { Hash } from '@smithy/hash-node';
|
|
6
|
+
import { formatUrl } from '@aws-sdk/util-format-url';
|
|
7
|
+
import { parseUrl } from '@smithy/url-parser';
|
|
4
8
|
import { defaultConfig } from './base.mjs';
|
|
5
9
|
import { parseXmlError } from './utils/parsePayload.mjs';
|
|
6
10
|
import { CONTENT_SHA256_HEADER } from './runtime/constants.mjs';
|
|
@@ -92,10 +96,23 @@ const getObject = composeServiceApi(s3TransferHandler, getObjectSerializer, getO
|
|
|
92
96
|
const getPresignedGetObjectUrl = async (config, input) => {
|
|
93
97
|
const endpoint = defaultConfig.endpointResolver(config, input);
|
|
94
98
|
const { url, headers, method } = await getObjectSerializer(input, endpoint);
|
|
99
|
+
if (input.method === 'PUT') {
|
|
100
|
+
const presigner = new S3RequestPresigner({
|
|
101
|
+
credentials: config.credentials,
|
|
102
|
+
region: config.region,
|
|
103
|
+
sha256: Hash.bind(null, 'sha256'),
|
|
104
|
+
});
|
|
105
|
+
const signedUrlObject = await presigner.presign({
|
|
106
|
+
...parseUrl(url.toString()),
|
|
107
|
+
headers,
|
|
108
|
+
method,
|
|
109
|
+
});
|
|
110
|
+
return new AmplifyUrl(formatUrl(signedUrlObject));
|
|
111
|
+
}
|
|
95
112
|
// TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.
|
|
96
113
|
// It requires changes in presignUrl. Without this change, the generated url still works,
|
|
97
114
|
// but not the same as other tools like AWS SDK and CLI.
|
|
98
|
-
url.searchParams.append(CONTENT_SHA256_HEADER,
|
|
115
|
+
url.searchParams.append(CONTENT_SHA256_HEADER, 'UNSIGNED-PAYLOAD');
|
|
99
116
|
if (config.userAgentValue) {
|
|
100
117
|
url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);
|
|
101
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getObject.mjs","sources":["../../../../../../src/providers/s3/utils/client/getObject.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { EMPTY_SHA256_HASH, parseMetadata, presignUrl, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nimport { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';\nimport { defaultConfig } from './base';\nimport { CONTENT_SHA256_HEADER, buildStorageServiceError, deserializeBoolean, deserializeMetadata, deserializeNumber, deserializeTimestamp, map, parseXmlError, s3TransferHandler, serializePathnameObjectKey, validateS3RequiredParameter, } from './utils';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst getObjectSerializer = async (input, endpoint) => {\n const url = new AmplifyUrl(endpoint.url.toString());\n validateS3RequiredParameter(!!input.Key, 'Key');\n url.pathname = serializePathnameObjectKey(url, input.Key);\n return {\n method: input.method ?? 'GET',\n headers: {\n ...(input.Range && { Range: input.Range }),\n },\n url,\n };\n};\nconst getObjectDeserializer = async (response) => {\n if (response.statusCode >= 300) {\n const error = (await parseXmlError(response));\n throw buildStorageServiceError(error, response.statusCode);\n }\n else {\n return {\n ...map(response.headers, {\n DeleteMarker: ['x-amz-delete-marker', deserializeBoolean],\n AcceptRanges: 'accept-ranges',\n Expiration: 'x-amz-expiration',\n Restore: 'x-amz-restore',\n LastModified: ['last-modified', deserializeTimestamp],\n ContentLength: ['content-length', deserializeNumber],\n ETag: 'etag',\n ChecksumCRC32: 'x-amz-checksum-crc32',\n ChecksumCRC32C: 'x-amz-checksum-crc32c',\n ChecksumSHA1: 'x-amz-checksum-sha1',\n ChecksumSHA256: 'x-amz-checksum-sha256',\n MissingMeta: ['x-amz-missing-meta', deserializeNumber],\n VersionId: 'x-amz-version-id',\n CacheControl: 'cache-control',\n ContentDisposition: 'content-disposition',\n ContentEncoding: 'content-encoding',\n ContentLanguage: 'content-language',\n ContentRange: 'content-range',\n ContentType: 'content-type',\n Expires: ['expires', deserializeTimestamp],\n WebsiteRedirectLocation: 'x-amz-website-redirect-location',\n ServerSideEncryption: 'x-amz-server-side-encryption',\n SSECustomerAlgorithm: 'x-amz-server-side-encryption-customer-algorithm',\n SSECustomerKeyMD5: 'x-amz-server-side-encryption-customer-key-md5',\n SSEKMSKeyId: 'x-amz-server-side-encryption-aws-kms-key-id',\n BucketKeyEnabled: [\n 'x-amz-server-side-encryption-bucket-key-enabled',\n deserializeBoolean,\n ],\n StorageClass: 'x-amz-storage-class',\n RequestCharged: 'x-amz-request-charged',\n ReplicationStatus: 'x-amz-replication-status',\n PartsCount: ['x-amz-mp-parts-count', deserializeNumber],\n TagCount: ['x-amz-tagging-count', deserializeNumber],\n ObjectLockMode: 'x-amz-object-lock-mode',\n ObjectLockRetainUntilDate: [\n 'x-amz-object-lock-retain-until-date',\n deserializeTimestamp,\n ],\n ObjectLockLegalHoldStatus: 'x-amz-object-lock-legal-hold',\n }),\n Metadata: deserializeMetadata(response.headers),\n $metadata: parseMetadata(response),\n // @ts-expect-error The body is a CompatibleHttpResponse type because the lower-level handler is XHR instead of\n // fetch, which represents payload in Blob instread of ReadableStream.\n Body: response.body,\n };\n }\n};\nexport const getObject = composeServiceApi(s3TransferHandler, getObjectSerializer, getObjectDeserializer, { ...defaultConfig, responseType: 'blob' });\n/**\n * Get a presigned URL for the `getObject` API.\n *\n * @internal\n */\nexport const getPresignedGetObjectUrl = async (config, input) => {\n const endpoint = defaultConfig.endpointResolver(config, input);\n const { url, headers, method } = await getObjectSerializer(input, endpoint);\n // TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.\n // It requires changes in presignUrl. Without this change, the generated url still works,\n // but not the same as other tools like AWS SDK and CLI.\n url.searchParams.append(CONTENT_SHA256_HEADER, EMPTY_SHA256_HASH);\n if (config.userAgentValue) {\n url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);\n }\n if (input.ResponseContentType) {\n url.searchParams.append('response-content-type', input.ResponseContentType);\n }\n if (input.ResponseContentDisposition) {\n url.searchParams.append('response-content-disposition', input.ResponseContentDisposition);\n }\n for (const [headerName, value] of Object.entries(headers).sort(([key1], [key2]) => key1.localeCompare(key2))) {\n url.searchParams.append(headerName, value);\n }\n return presignUrl({ method, url, body: undefined }, {\n signingService: defaultConfig.service,\n signingRegion: config.region,\n ...defaultConfig,\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AA8B,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAClG,KAAK;AACL,IAAI,KAAK,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE;AAClH,QAAQ,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,OAAO,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;AACxD,QAAQ,cAAc,EAAE,aAAa,CAAC,OAAO;AAC7C,QAAQ,aAAa,EAAE,MAAM,CAAC,MAAM;AACpC,QAAQ,GAAG,aAAa;AACxB,QAAQ,GAAG,MAAM;AACjB,KAAK,CAAC,CAAC;AACP;;;;"}
|
|
1
|
+
{"version":3,"file":"getObject.mjs","sources":["../../../../../../src/providers/s3/utils/client/getObject.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parseMetadata, presignUrl, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nimport { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';\nimport { S3RequestPresigner } from '@aws-sdk/s3-request-presigner';\nimport { Hash } from '@smithy/hash-node';\nimport { formatUrl } from '@aws-sdk/util-format-url';\nimport { parseUrl } from '@smithy/url-parser';\nimport { defaultConfig } from './base';\nimport { CONTENT_SHA256_HEADER, buildStorageServiceError, deserializeBoolean, deserializeMetadata, deserializeNumber, deserializeTimestamp, map, parseXmlError, s3TransferHandler, serializePathnameObjectKey, validateS3RequiredParameter, } from './utils';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst getObjectSerializer = async (input, endpoint) => {\n const url = new AmplifyUrl(endpoint.url.toString());\n validateS3RequiredParameter(!!input.Key, 'Key');\n url.pathname = serializePathnameObjectKey(url, input.Key);\n return {\n method: input.method ?? 'GET',\n headers: {\n ...(input.Range && { Range: input.Range }),\n },\n url,\n };\n};\nconst getObjectDeserializer = async (response) => {\n if (response.statusCode >= 300) {\n const error = (await parseXmlError(response));\n throw buildStorageServiceError(error, response.statusCode);\n }\n else {\n return {\n ...map(response.headers, {\n DeleteMarker: ['x-amz-delete-marker', deserializeBoolean],\n AcceptRanges: 'accept-ranges',\n Expiration: 'x-amz-expiration',\n Restore: 'x-amz-restore',\n LastModified: ['last-modified', deserializeTimestamp],\n ContentLength: ['content-length', deserializeNumber],\n ETag: 'etag',\n ChecksumCRC32: 'x-amz-checksum-crc32',\n ChecksumCRC32C: 'x-amz-checksum-crc32c',\n ChecksumSHA1: 'x-amz-checksum-sha1',\n ChecksumSHA256: 'x-amz-checksum-sha256',\n MissingMeta: ['x-amz-missing-meta', deserializeNumber],\n VersionId: 'x-amz-version-id',\n CacheControl: 'cache-control',\n ContentDisposition: 'content-disposition',\n ContentEncoding: 'content-encoding',\n ContentLanguage: 'content-language',\n ContentRange: 'content-range',\n ContentType: 'content-type',\n Expires: ['expires', deserializeTimestamp],\n WebsiteRedirectLocation: 'x-amz-website-redirect-location',\n ServerSideEncryption: 'x-amz-server-side-encryption',\n SSECustomerAlgorithm: 'x-amz-server-side-encryption-customer-algorithm',\n SSECustomerKeyMD5: 'x-amz-server-side-encryption-customer-key-md5',\n SSEKMSKeyId: 'x-amz-server-side-encryption-aws-kms-key-id',\n BucketKeyEnabled: [\n 'x-amz-server-side-encryption-bucket-key-enabled',\n deserializeBoolean,\n ],\n StorageClass: 'x-amz-storage-class',\n RequestCharged: 'x-amz-request-charged',\n ReplicationStatus: 'x-amz-replication-status',\n PartsCount: ['x-amz-mp-parts-count', deserializeNumber],\n TagCount: ['x-amz-tagging-count', deserializeNumber],\n ObjectLockMode: 'x-amz-object-lock-mode',\n ObjectLockRetainUntilDate: [\n 'x-amz-object-lock-retain-until-date',\n deserializeTimestamp,\n ],\n ObjectLockLegalHoldStatus: 'x-amz-object-lock-legal-hold',\n }),\n Metadata: deserializeMetadata(response.headers),\n $metadata: parseMetadata(response),\n // @ts-expect-error The body is a CompatibleHttpResponse type because the lower-level handler is XHR instead of\n // fetch, which represents payload in Blob instread of ReadableStream.\n Body: response.body,\n };\n }\n};\nexport const getObject = composeServiceApi(s3TransferHandler, getObjectSerializer, getObjectDeserializer, { ...defaultConfig, responseType: 'blob' });\n/**\n * Get a presigned URL for the `getObject` API.\n *\n * @internal\n */\nexport const getPresignedGetObjectUrl = async (config, input) => {\n const endpoint = defaultConfig.endpointResolver(config, input);\n const { url, headers, method } = await getObjectSerializer(input, endpoint);\n if (input.method === 'PUT') {\n const presigner = new S3RequestPresigner({\n credentials: config.credentials,\n region: config.region,\n sha256: Hash.bind(null, 'sha256'),\n });\n const signedUrlObject = await presigner.presign({\n ...parseUrl(url.toString()),\n headers,\n method,\n });\n return new AmplifyUrl(formatUrl(signedUrlObject));\n }\n // TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.\n // It requires changes in presignUrl. Without this change, the generated url still works,\n // but not the same as other tools like AWS SDK and CLI.\n url.searchParams.append(CONTENT_SHA256_HEADER, 'UNSIGNED-PAYLOAD');\n if (config.userAgentValue) {\n url.searchParams.append(config.userAgentHeader ?? USER_AGENT_HEADER, config.userAgentValue);\n }\n if (input.ResponseContentType) {\n url.searchParams.append('response-content-type', input.ResponseContentType);\n }\n if (input.ResponseContentDisposition) {\n url.searchParams.append('response-content-disposition', input.ResponseContentDisposition);\n }\n for (const [headerName, value] of Object.entries(headers).sort(([key1], [key2]) => key1.localeCompare(key2))) {\n url.searchParams.append(headerName, value);\n }\n return presignUrl({ method, url, body: undefined }, {\n signingService: defaultConfig.service,\n signingRegion: config.region,\n ...defaultConfig,\n ...config,\n });\n};\n"],"names":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|
"name": "@aws-amplify/storage",
|
|
3
|
-
"version": "6.6.4-server-upload.
|
|
3
|
+
"version": "6.6.4-server-upload.1e86212.0+1e86212",
|
|
4
4
|
"description": "Storage category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
28
28
|
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
|
|
29
29
|
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
30
|
-
"build": "npm run clean && npm run build:esm-cjs
|
|
30
|
+
"build": "npm run clean && npm run build:esm-cjs",
|
|
31
31
|
"clean": "npm run clean:size && rimraf lib-esm lib dist",
|
|
32
32
|
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
33
33
|
"format": "echo \"Not implemented\"",
|
|
@@ -66,8 +66,12 @@
|
|
|
66
66
|
"s3"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
+
"@aws-sdk/s3-request-presigner": "3.637.0",
|
|
69
70
|
"@aws-sdk/types": "3.398.0",
|
|
71
|
+
"@aws-sdk/util-format-url": "3.609.0",
|
|
72
|
+
"@smithy/hash-node": "3.0.3",
|
|
70
73
|
"@smithy/md5-js": "2.0.7",
|
|
74
|
+
"@smithy/url-parser": "3.0.3",
|
|
71
75
|
"buffer": "4.9.2",
|
|
72
76
|
"fast-xml-parser": "^4.4.1",
|
|
73
77
|
"tslib": "^2.5.0"
|
|
@@ -98,12 +102,12 @@
|
|
|
98
102
|
"./package.json": "./package.json"
|
|
99
103
|
},
|
|
100
104
|
"peerDependencies": {
|
|
101
|
-
"@aws-amplify/core": "6.3.13-server-upload.
|
|
105
|
+
"@aws-amplify/core": "6.3.13-server-upload.1e86212.0+1e86212"
|
|
102
106
|
},
|
|
103
107
|
"devDependencies": {
|
|
104
|
-
"@aws-amplify/core": "6.3.13-server-upload.
|
|
105
|
-
"@aws-amplify/react-native": "1.1.5-server-upload.
|
|
108
|
+
"@aws-amplify/core": "6.3.13-server-upload.1e86212.0+1e86212",
|
|
109
|
+
"@aws-amplify/react-native": "1.1.5-server-upload.1e86212.0+1e86212",
|
|
106
110
|
"typescript": "5.0.2"
|
|
107
111
|
},
|
|
108
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "1e86212efbdf140bba71be8f0be3d142dfd0012e"
|
|
109
113
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
EMPTY_SHA256_HASH,
|
|
6
5
|
Endpoint,
|
|
7
6
|
HttpRequest,
|
|
8
7
|
HttpResponse,
|
|
@@ -13,6 +12,10 @@ import {
|
|
|
13
12
|
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
14
13
|
import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
|
|
15
14
|
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
15
|
+
import { S3RequestPresigner } from '@aws-sdk/s3-request-presigner';
|
|
16
|
+
import { Hash } from '@smithy/hash-node';
|
|
17
|
+
import { formatUrl } from '@aws-sdk/util-format-url';
|
|
18
|
+
import { parseUrl } from '@smithy/url-parser';
|
|
16
19
|
|
|
17
20
|
import { S3EndpointResolverOptions, defaultConfig } from './base';
|
|
18
21
|
import type {
|
|
@@ -150,10 +153,25 @@ export const getPresignedGetObjectUrl = async (
|
|
|
150
153
|
const endpoint = defaultConfig.endpointResolver(config, input);
|
|
151
154
|
const { url, headers, method } = await getObjectSerializer(input, endpoint);
|
|
152
155
|
|
|
156
|
+
if (input.method === 'PUT') {
|
|
157
|
+
const presigner = new S3RequestPresigner({
|
|
158
|
+
credentials: config.credentials,
|
|
159
|
+
region: config.region,
|
|
160
|
+
sha256: Hash.bind(null, 'sha256'),
|
|
161
|
+
});
|
|
162
|
+
const signedUrlObject = await presigner.presign({
|
|
163
|
+
...parseUrl(url.toString()),
|
|
164
|
+
headers,
|
|
165
|
+
method,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return new AmplifyUrl(formatUrl(signedUrlObject));
|
|
169
|
+
}
|
|
170
|
+
|
|
153
171
|
// TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD instead of empty hash.
|
|
154
172
|
// It requires changes in presignUrl. Without this change, the generated url still works,
|
|
155
173
|
// but not the same as other tools like AWS SDK and CLI.
|
|
156
|
-
url.searchParams.append(CONTENT_SHA256_HEADER,
|
|
174
|
+
url.searchParams.append(CONTENT_SHA256_HEADER, 'UNSIGNED-PAYLOAD');
|
|
157
175
|
if (config.userAgentValue) {
|
|
158
176
|
url.searchParams.append(
|
|
159
177
|
config.userAgentHeader ?? USER_AGENT_HEADER,
|