@aws-sdk/middleware-flexible-checksums
Advanced tools
Comparing version 3.489.0 to 3.495.0
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
module.exports = require("./index.js"); |
@@ -1,18 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM = exports.DEFAULT_CHECKSUM_ALGORITHM = exports.ChecksumLocation = exports.ChecksumAlgorithm = void 0; | ||
var ChecksumAlgorithm; | ||
(function (ChecksumAlgorithm) { | ||
ChecksumAlgorithm["MD5"] = "MD5"; | ||
ChecksumAlgorithm["CRC32"] = "CRC32"; | ||
ChecksumAlgorithm["CRC32C"] = "CRC32C"; | ||
ChecksumAlgorithm["SHA1"] = "SHA1"; | ||
ChecksumAlgorithm["SHA256"] = "SHA256"; | ||
})(ChecksumAlgorithm = exports.ChecksumAlgorithm || (exports.ChecksumAlgorithm = {})); | ||
var ChecksumLocation; | ||
(function (ChecksumLocation) { | ||
ChecksumLocation["HEADER"] = "header"; | ||
ChecksumLocation["TRAILER"] = "trailer"; | ||
})(ChecksumLocation = exports.ChecksumLocation || (exports.ChecksumLocation = {})); | ||
exports.DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.MD5; | ||
exports.S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; | ||
module.exports = require("./index.js"); |
@@ -1,73 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flexibleChecksumsMiddleware = exports.flexibleChecksumsMiddlewareOptions = void 0; | ||
const protocol_http_1 = require("@smithy/protocol-http"); | ||
const getChecksumAlgorithmForRequest_1 = require("./getChecksumAlgorithmForRequest"); | ||
const getChecksumLocationName_1 = require("./getChecksumLocationName"); | ||
const hasHeader_1 = require("./hasHeader"); | ||
const isStreaming_1 = require("./isStreaming"); | ||
const selectChecksumAlgorithmFunction_1 = require("./selectChecksumAlgorithmFunction"); | ||
const stringHasher_1 = require("./stringHasher"); | ||
exports.flexibleChecksumsMiddlewareOptions = { | ||
name: "flexibleChecksumsMiddleware", | ||
step: "build", | ||
tags: ["BODY_CHECKSUM"], | ||
override: true, | ||
}; | ||
const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
if (!protocol_http_1.HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const { request } = args; | ||
const { body: requestBody, headers } = request; | ||
const { base64Encoder, streamHasher } = config; | ||
const { input, requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
const checksumAlgorithm = (0, getChecksumAlgorithmForRequest_1.getChecksumAlgorithmForRequest)(input, { | ||
requestChecksumRequired, | ||
requestAlgorithmMember, | ||
}, !!context.isS3ExpressBucket); | ||
let updatedBody = requestBody; | ||
let updatedHeaders = headers; | ||
if (checksumAlgorithm) { | ||
const checksumLocationName = (0, getChecksumLocationName_1.getChecksumLocationName)(checksumAlgorithm); | ||
const checksumAlgorithmFn = (0, selectChecksumAlgorithmFunction_1.selectChecksumAlgorithmFunction)(checksumAlgorithm, config); | ||
if ((0, isStreaming_1.isStreaming)(requestBody)) { | ||
const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
updatedBody = getAwsChunkedEncodingStream(requestBody, { | ||
base64Encoder, | ||
bodyLengthChecker, | ||
checksumLocationName, | ||
checksumAlgorithmFn, | ||
streamHasher, | ||
}); | ||
updatedHeaders = { | ||
...headers, | ||
"content-encoding": headers["content-encoding"] | ||
? `${headers["content-encoding"]},aws-chunked` | ||
: "aws-chunked", | ||
"transfer-encoding": "chunked", | ||
"x-amz-decoded-content-length": headers["content-length"], | ||
"x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
"x-amz-trailer": checksumLocationName, | ||
}; | ||
delete updatedHeaders["content-length"]; | ||
} | ||
else if (!(0, hasHeader_1.hasHeader)(checksumLocationName, headers)) { | ||
const rawChecksum = await (0, stringHasher_1.stringHasher)(checksumAlgorithmFn, requestBody); | ||
updatedHeaders = { | ||
...headers, | ||
[checksumLocationName]: base64Encoder(rawChecksum), | ||
}; | ||
} | ||
} | ||
const result = await next({ | ||
...args, | ||
request: { | ||
...request, | ||
headers: updatedHeaders, | ||
body: updatedBody, | ||
}, | ||
}); | ||
return result; | ||
}; | ||
exports.flexibleChecksumsMiddleware = flexibleChecksumsMiddleware; | ||
module.exports = require("./index.js"); |
@@ -1,54 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flexibleChecksumsResponseMiddleware = exports.flexibleChecksumsResponseMiddlewareOptions = void 0; | ||
const protocol_http_1 = require("@smithy/protocol-http"); | ||
const getChecksumAlgorithmListForResponse_1 = require("./getChecksumAlgorithmListForResponse"); | ||
const getChecksumLocationName_1 = require("./getChecksumLocationName"); | ||
const isChecksumWithPartNumber_1 = require("./isChecksumWithPartNumber"); | ||
const isStreaming_1 = require("./isStreaming"); | ||
const create_read_stream_on_buffer_1 = require("./streams/create-read-stream-on-buffer"); | ||
const validateChecksumFromResponse_1 = require("./validateChecksumFromResponse"); | ||
exports.flexibleChecksumsResponseMiddlewareOptions = { | ||
name: "flexibleChecksumsResponseMiddleware", | ||
toMiddleware: "deserializerMiddleware", | ||
relation: "after", | ||
tags: ["BODY_CHECKSUM"], | ||
override: true, | ||
}; | ||
const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
if (!protocol_http_1.HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const input = args.input; | ||
const result = await next(args); | ||
const response = result.response; | ||
let collectedStream = undefined; | ||
const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
const { clientName, commandName } = context; | ||
const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && | ||
commandName === "GetObjectCommand" && | ||
(0, getChecksumAlgorithmListForResponse_1.getChecksumAlgorithmListForResponse)(responseAlgorithms).every((algorithm) => { | ||
const responseHeader = (0, getChecksumLocationName_1.getChecksumLocationName)(algorithm); | ||
const checksumFromResponse = response.headers[responseHeader]; | ||
return !checksumFromResponse || (0, isChecksumWithPartNumber_1.isChecksumWithPartNumber)(checksumFromResponse); | ||
}); | ||
if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
return result; | ||
} | ||
const isStreamingBody = (0, isStreaming_1.isStreaming)(response.body); | ||
if (isStreamingBody) { | ||
collectedStream = await config.streamCollector(response.body); | ||
response.body = (0, create_read_stream_on_buffer_1.createReadStreamOnBuffer)(collectedStream); | ||
} | ||
await (0, validateChecksumFromResponse_1.validateChecksumFromResponse)(result.response, { | ||
config, | ||
responseAlgorithms, | ||
}); | ||
if (isStreamingBody && collectedStream) { | ||
response.body = (0, create_read_stream_on_buffer_1.createReadStreamOnBuffer)(collectedStream); | ||
} | ||
} | ||
return result; | ||
}; | ||
exports.flexibleChecksumsResponseMiddleware = flexibleChecksumsResponseMiddleware; | ||
module.exports = require("./index.js"); |
@@ -1,10 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getChecksum = void 0; | ||
const isStreaming_1 = require("./isStreaming"); | ||
const stringHasher_1 = require("./stringHasher"); | ||
const getChecksum = async (body, { streamHasher, checksumAlgorithmFn, base64Encoder }) => { | ||
const digest = (0, isStreaming_1.isStreaming)(body) ? streamHasher(checksumAlgorithmFn, body) : (0, stringHasher_1.stringHasher)(checksumAlgorithmFn, body); | ||
return base64Encoder(await digest); | ||
}; | ||
exports.getChecksum = getChecksum; | ||
module.exports = require("./index.js"); |
@@ -1,18 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getChecksumAlgorithmForRequest = void 0; | ||
const constants_1 = require("./constants"); | ||
const types_1 = require("./types"); | ||
const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember }, isS3Express) => { | ||
const defaultAlgorithm = isS3Express ? constants_1.S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM : constants_1.DEFAULT_CHECKSUM_ALGORITHM; | ||
if (!requestAlgorithmMember || !input[requestAlgorithmMember]) { | ||
return requestChecksumRequired ? defaultAlgorithm : undefined; | ||
} | ||
const checksumAlgorithm = input[requestAlgorithmMember]; | ||
if (!types_1.CLIENT_SUPPORTED_ALGORITHMS.includes(checksumAlgorithm)) { | ||
throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` + | ||
` Select one of ${types_1.CLIENT_SUPPORTED_ALGORITHMS}.`); | ||
} | ||
return checksumAlgorithm; | ||
}; | ||
exports.getChecksumAlgorithmForRequest = getChecksumAlgorithmForRequest; | ||
module.exports = require("./index.js"); |
@@ -1,15 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getChecksumAlgorithmListForResponse = void 0; | ||
const types_1 = require("./types"); | ||
const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => { | ||
const validChecksumAlgorithms = []; | ||
for (const algorithm of types_1.PRIORITY_ORDER_ALGORITHMS) { | ||
if (!responseAlgorithms.includes(algorithm) || !types_1.CLIENT_SUPPORTED_ALGORITHMS.includes(algorithm)) { | ||
continue; | ||
} | ||
validChecksumAlgorithms.push(algorithm); | ||
} | ||
return validChecksumAlgorithms; | ||
}; | ||
exports.getChecksumAlgorithmListForResponse = getChecksumAlgorithmListForResponse; | ||
module.exports = require("./index.js"); |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getChecksumLocationName = void 0; | ||
const constants_1 = require("./constants"); | ||
const getChecksumLocationName = (algorithm) => algorithm === constants_1.ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`; | ||
exports.getChecksumLocationName = getChecksumLocationName; | ||
module.exports = require("./index.js"); |
@@ -1,12 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFlexibleChecksumsPlugin = void 0; | ||
const flexibleChecksumsMiddleware_1 = require("./flexibleChecksumsMiddleware"); | ||
const flexibleChecksumsResponseMiddleware_1 = require("./flexibleChecksumsResponseMiddleware"); | ||
const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({ | ||
applyToStack: (clientStack) => { | ||
clientStack.add((0, flexibleChecksumsMiddleware_1.flexibleChecksumsMiddleware)(config, middlewareConfig), flexibleChecksumsMiddleware_1.flexibleChecksumsMiddlewareOptions); | ||
clientStack.addRelativeTo((0, flexibleChecksumsResponseMiddleware_1.flexibleChecksumsResponseMiddleware)(config, middlewareConfig), flexibleChecksumsResponseMiddleware_1.flexibleChecksumsResponseMiddlewareOptions); | ||
}, | ||
}); | ||
exports.getFlexibleChecksumsPlugin = getFlexibleChecksumsPlugin; | ||
module.exports = require("./index.js"); |
@@ -1,13 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hasHeader = void 0; | ||
const hasHeader = (header, headers) => { | ||
const soughtHeader = header.toLowerCase(); | ||
for (const headerName of Object.keys(headers)) { | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
exports.hasHeader = hasHeader; | ||
module.exports = require("./index.js"); |
@@ -1,6 +0,306 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./constants"), exports); | ||
tslib_1.__exportStar(require("./flexibleChecksumsMiddleware"), exports); | ||
tslib_1.__exportStar(require("./getFlexibleChecksumsPlugin"), exports); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ChecksumAlgorithm: () => ChecksumAlgorithm, | ||
ChecksumLocation: () => ChecksumLocation, | ||
DEFAULT_CHECKSUM_ALGORITHM: () => DEFAULT_CHECKSUM_ALGORITHM, | ||
S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM: () => S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM, | ||
flexibleChecksumsMiddleware: () => flexibleChecksumsMiddleware, | ||
flexibleChecksumsMiddlewareOptions: () => flexibleChecksumsMiddlewareOptions, | ||
getFlexibleChecksumsPlugin: () => getFlexibleChecksumsPlugin | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/constants.ts | ||
var ChecksumAlgorithm = /* @__PURE__ */ ((ChecksumAlgorithm3) => { | ||
ChecksumAlgorithm3["MD5"] = "MD5"; | ||
ChecksumAlgorithm3["CRC32"] = "CRC32"; | ||
ChecksumAlgorithm3["CRC32C"] = "CRC32C"; | ||
ChecksumAlgorithm3["SHA1"] = "SHA1"; | ||
ChecksumAlgorithm3["SHA256"] = "SHA256"; | ||
return ChecksumAlgorithm3; | ||
})(ChecksumAlgorithm || {}); | ||
var ChecksumLocation = /* @__PURE__ */ ((ChecksumLocation2) => { | ||
ChecksumLocation2["HEADER"] = "header"; | ||
ChecksumLocation2["TRAILER"] = "trailer"; | ||
return ChecksumLocation2; | ||
})(ChecksumLocation || {}); | ||
var DEFAULT_CHECKSUM_ALGORITHM = "MD5" /* MD5 */; | ||
var S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM = "CRC32" /* CRC32 */; | ||
// src/flexibleChecksumsMiddleware.ts | ||
var import_protocol_http = require("@smithy/protocol-http"); | ||
// src/types.ts | ||
var CLIENT_SUPPORTED_ALGORITHMS = [ | ||
"CRC32" /* CRC32 */, | ||
"CRC32C" /* CRC32C */, | ||
"SHA1" /* SHA1 */, | ||
"SHA256" /* SHA256 */ | ||
]; | ||
var PRIORITY_ORDER_ALGORITHMS = [ | ||
"CRC32" /* CRC32 */, | ||
"CRC32C" /* CRC32C */, | ||
"SHA1" /* SHA1 */, | ||
"SHA256" /* SHA256 */ | ||
]; | ||
// src/getChecksumAlgorithmForRequest.ts | ||
var getChecksumAlgorithmForRequest = /* @__PURE__ */ __name((input, { requestChecksumRequired, requestAlgorithmMember }, isS3Express) => { | ||
const defaultAlgorithm = isS3Express ? S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM : DEFAULT_CHECKSUM_ALGORITHM; | ||
if (!requestAlgorithmMember || !input[requestAlgorithmMember]) { | ||
return requestChecksumRequired ? defaultAlgorithm : void 0; | ||
} | ||
const checksumAlgorithm = input[requestAlgorithmMember]; | ||
if (!CLIENT_SUPPORTED_ALGORITHMS.includes(checksumAlgorithm)) { | ||
throw new Error( | ||
`The checksum algorithm "${checksumAlgorithm}" is not supported by the client. Select one of ${CLIENT_SUPPORTED_ALGORITHMS}.` | ||
); | ||
} | ||
return checksumAlgorithm; | ||
}, "getChecksumAlgorithmForRequest"); | ||
// src/getChecksumLocationName.ts | ||
var getChecksumLocationName = /* @__PURE__ */ __name((algorithm) => algorithm === "MD5" /* MD5 */ ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`, "getChecksumLocationName"); | ||
// src/hasHeader.ts | ||
var hasHeader = /* @__PURE__ */ __name((header, headers) => { | ||
const soughtHeader = header.toLowerCase(); | ||
for (const headerName of Object.keys(headers)) { | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, "hasHeader"); | ||
// src/isStreaming.ts | ||
var import_is_array_buffer = require("@smithy/is-array-buffer"); | ||
var isStreaming = /* @__PURE__ */ __name((body) => body !== void 0 && typeof body !== "string" && !ArrayBuffer.isView(body) && !(0, import_is_array_buffer.isArrayBuffer)(body), "isStreaming"); | ||
// src/selectChecksumAlgorithmFunction.ts | ||
var import_crc32 = require("@aws-crypto/crc32"); | ||
var import_crc32c = require("@aws-crypto/crc32c"); | ||
var selectChecksumAlgorithmFunction = /* @__PURE__ */ __name((checksumAlgorithm, config) => ({ | ||
["MD5" /* MD5 */]: config.md5, | ||
["CRC32" /* CRC32 */]: import_crc32.AwsCrc32, | ||
["CRC32C" /* CRC32C */]: import_crc32c.AwsCrc32c, | ||
["SHA1" /* SHA1 */]: config.sha1, | ||
["SHA256" /* SHA256 */]: config.sha256 | ||
})[checksumAlgorithm], "selectChecksumAlgorithmFunction"); | ||
// src/stringHasher.ts | ||
var import_util_utf8 = require("@smithy/util-utf8"); | ||
var stringHasher = /* @__PURE__ */ __name((checksumAlgorithmFn, body) => { | ||
const hash = new checksumAlgorithmFn(); | ||
hash.update((0, import_util_utf8.toUint8Array)(body || "")); | ||
return hash.digest(); | ||
}, "stringHasher"); | ||
// src/flexibleChecksumsMiddleware.ts | ||
var flexibleChecksumsMiddlewareOptions = { | ||
name: "flexibleChecksumsMiddleware", | ||
step: "build", | ||
tags: ["BODY_CHECKSUM"], | ||
override: true | ||
}; | ||
var flexibleChecksumsMiddleware = /* @__PURE__ */ __name((config, middlewareConfig) => (next, context) => async (args) => { | ||
if (!import_protocol_http.HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const { request } = args; | ||
const { body: requestBody, headers } = request; | ||
const { base64Encoder, streamHasher } = config; | ||
const { input, requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
const checksumAlgorithm = getChecksumAlgorithmForRequest( | ||
input, | ||
{ | ||
requestChecksumRequired, | ||
requestAlgorithmMember | ||
}, | ||
!!context.isS3ExpressBucket | ||
); | ||
let updatedBody = requestBody; | ||
let updatedHeaders = headers; | ||
if (checksumAlgorithm) { | ||
const checksumLocationName = getChecksumLocationName(checksumAlgorithm); | ||
const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config); | ||
if (isStreaming(requestBody)) { | ||
const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
updatedBody = getAwsChunkedEncodingStream(requestBody, { | ||
base64Encoder, | ||
bodyLengthChecker, | ||
checksumLocationName, | ||
checksumAlgorithmFn, | ||
streamHasher | ||
}); | ||
updatedHeaders = { | ||
...headers, | ||
"content-encoding": headers["content-encoding"] ? `${headers["content-encoding"]},aws-chunked` : "aws-chunked", | ||
"transfer-encoding": "chunked", | ||
"x-amz-decoded-content-length": headers["content-length"], | ||
"x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
"x-amz-trailer": checksumLocationName | ||
}; | ||
delete updatedHeaders["content-length"]; | ||
} else if (!hasHeader(checksumLocationName, headers)) { | ||
const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody); | ||
updatedHeaders = { | ||
...headers, | ||
[checksumLocationName]: base64Encoder(rawChecksum) | ||
}; | ||
} | ||
} | ||
const result = await next({ | ||
...args, | ||
request: { | ||
...request, | ||
headers: updatedHeaders, | ||
body: updatedBody | ||
} | ||
}); | ||
return result; | ||
}, "flexibleChecksumsMiddleware"); | ||
// src/flexibleChecksumsResponseMiddleware.ts | ||
// src/getChecksumAlgorithmListForResponse.ts | ||
var getChecksumAlgorithmListForResponse = /* @__PURE__ */ __name((responseAlgorithms = []) => { | ||
const validChecksumAlgorithms = []; | ||
for (const algorithm of PRIORITY_ORDER_ALGORITHMS) { | ||
if (!responseAlgorithms.includes(algorithm) || !CLIENT_SUPPORTED_ALGORITHMS.includes(algorithm)) { | ||
continue; | ||
} | ||
validChecksumAlgorithms.push(algorithm); | ||
} | ||
return validChecksumAlgorithms; | ||
}, "getChecksumAlgorithmListForResponse"); | ||
// src/isChecksumWithPartNumber.ts | ||
var isChecksumWithPartNumber = /* @__PURE__ */ __name((checksum) => { | ||
const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
if (lastHyphenIndex !== -1) { | ||
const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
if (!numberPart.startsWith("0")) { | ||
const number = parseInt(numberPart, 10); | ||
if (!isNaN(number) && number >= 1 && number <= 1e4) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}, "isChecksumWithPartNumber"); | ||
// src/flexibleChecksumsResponseMiddleware.ts | ||
var import_create_read_stream_on_buffer = require("./streams/create-read-stream-on-buffer"); | ||
// src/getChecksum.ts | ||
var getChecksum = /* @__PURE__ */ __name(async (body, { streamHasher, checksumAlgorithmFn, base64Encoder }) => { | ||
const digest = isStreaming(body) ? streamHasher(checksumAlgorithmFn, body) : stringHasher(checksumAlgorithmFn, body); | ||
return base64Encoder(await digest); | ||
}, "getChecksum"); | ||
// src/validateChecksumFromResponse.ts | ||
var validateChecksumFromResponse = /* @__PURE__ */ __name(async (response, { config, responseAlgorithms }) => { | ||
const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms); | ||
const { body: responseBody, headers: responseHeaders } = response; | ||
for (const algorithm of checksumAlgorithms) { | ||
const responseHeader = getChecksumLocationName(algorithm); | ||
const checksumFromResponse = responseHeaders[responseHeader]; | ||
if (checksumFromResponse) { | ||
const checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config); | ||
const { streamHasher, base64Encoder } = config; | ||
const checksum = await getChecksum(responseBody, { streamHasher, checksumAlgorithmFn, base64Encoder }); | ||
if (checksum === checksumFromResponse) { | ||
break; | ||
} | ||
throw new Error( | ||
`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}" in response header "${responseHeader}".` | ||
); | ||
} | ||
} | ||
}, "validateChecksumFromResponse"); | ||
// src/flexibleChecksumsResponseMiddleware.ts | ||
var flexibleChecksumsResponseMiddlewareOptions = { | ||
name: "flexibleChecksumsResponseMiddleware", | ||
toMiddleware: "deserializerMiddleware", | ||
relation: "after", | ||
tags: ["BODY_CHECKSUM"], | ||
override: true | ||
}; | ||
var flexibleChecksumsResponseMiddleware = /* @__PURE__ */ __name((config, middlewareConfig) => (next, context) => async (args) => { | ||
if (!import_protocol_http.HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const input = args.input; | ||
const result = await next(args); | ||
const response = result.response; | ||
let collectedStream = void 0; | ||
const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
const { clientName, commandName } = context; | ||
const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && commandName === "GetObjectCommand" && getChecksumAlgorithmListForResponse(responseAlgorithms).every((algorithm) => { | ||
const responseHeader = getChecksumLocationName(algorithm); | ||
const checksumFromResponse = response.headers[responseHeader]; | ||
return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); | ||
}); | ||
if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
return result; | ||
} | ||
const isStreamingBody = isStreaming(response.body); | ||
if (isStreamingBody) { | ||
collectedStream = await config.streamCollector(response.body); | ||
response.body = (0, import_create_read_stream_on_buffer.createReadStreamOnBuffer)(collectedStream); | ||
} | ||
await validateChecksumFromResponse(result.response, { | ||
config, | ||
responseAlgorithms | ||
}); | ||
if (isStreamingBody && collectedStream) { | ||
response.body = (0, import_create_read_stream_on_buffer.createReadStreamOnBuffer)(collectedStream); | ||
} | ||
} | ||
return result; | ||
}, "flexibleChecksumsResponseMiddleware"); | ||
// src/getFlexibleChecksumsPlugin.ts | ||
var getFlexibleChecksumsPlugin = /* @__PURE__ */ __name((config, middlewareConfig) => ({ | ||
applyToStack: (clientStack) => { | ||
clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions); | ||
clientStack.addRelativeTo( | ||
flexibleChecksumsResponseMiddleware(config, middlewareConfig), | ||
flexibleChecksumsResponseMiddlewareOptions | ||
); | ||
} | ||
}), "getFlexibleChecksumsPlugin"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ChecksumAlgorithm, | ||
ChecksumLocation, | ||
DEFAULT_CHECKSUM_ALGORITHM, | ||
S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM, | ||
flexibleChecksumsMiddleware, | ||
flexibleChecksumsMiddlewareOptions, | ||
getFlexibleChecksumsPlugin | ||
}); |
@@ -1,17 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isChecksumWithPartNumber = void 0; | ||
const isChecksumWithPartNumber = (checksum) => { | ||
const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
if (lastHyphenIndex !== -1) { | ||
const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
if (!numberPart.startsWith("0")) { | ||
const number = parseInt(numberPart, 10); | ||
if (!isNaN(number) && number >= 1 && number <= 10000) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
exports.isChecksumWithPartNumber = isChecksumWithPartNumber; | ||
module.exports = require("./index.js"); |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isStreaming = void 0; | ||
const is_array_buffer_1 = require("@smithy/is-array-buffer"); | ||
const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !(0, is_array_buffer_1.isArrayBuffer)(body); | ||
exports.isStreaming = isStreaming; | ||
module.exports = require("./index.js"); |
@@ -1,14 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.selectChecksumAlgorithmFunction = void 0; | ||
const crc32_1 = require("@aws-crypto/crc32"); | ||
const crc32c_1 = require("@aws-crypto/crc32c"); | ||
const constants_1 = require("./constants"); | ||
const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => ({ | ||
[constants_1.ChecksumAlgorithm.MD5]: config.md5, | ||
[constants_1.ChecksumAlgorithm.CRC32]: crc32_1.AwsCrc32, | ||
[constants_1.ChecksumAlgorithm.CRC32C]: crc32c_1.AwsCrc32c, | ||
[constants_1.ChecksumAlgorithm.SHA1]: config.sha1, | ||
[constants_1.ChecksumAlgorithm.SHA256]: config.sha256, | ||
}[checksumAlgorithm]); | ||
exports.selectChecksumAlgorithmFunction = selectChecksumAlgorithmFunction; | ||
module.exports = require("./index.js"); |
@@ -1,10 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringHasher = void 0; | ||
const util_utf8_1 = require("@smithy/util-utf8"); | ||
const stringHasher = (checksumAlgorithmFn, body) => { | ||
const hash = new checksumAlgorithmFn(); | ||
hash.update((0, util_utf8_1.toUint8Array)(body || "")); | ||
return hash.digest(); | ||
}; | ||
exports.stringHasher = stringHasher; | ||
module.exports = require("./index.js"); |
@@ -1,16 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PRIORITY_ORDER_ALGORITHMS = exports.CLIENT_SUPPORTED_ALGORITHMS = void 0; | ||
const constants_1 = require("./constants"); | ||
exports.CLIENT_SUPPORTED_ALGORITHMS = [ | ||
constants_1.ChecksumAlgorithm.CRC32, | ||
constants_1.ChecksumAlgorithm.CRC32C, | ||
constants_1.ChecksumAlgorithm.SHA1, | ||
constants_1.ChecksumAlgorithm.SHA256, | ||
]; | ||
exports.PRIORITY_ORDER_ALGORITHMS = [ | ||
constants_1.ChecksumAlgorithm.CRC32, | ||
constants_1.ChecksumAlgorithm.CRC32C, | ||
constants_1.ChecksumAlgorithm.SHA1, | ||
constants_1.ChecksumAlgorithm.SHA256, | ||
]; | ||
module.exports = require("./index.js"); |
@@ -1,26 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateChecksumFromResponse = void 0; | ||
const getChecksum_1 = require("./getChecksum"); | ||
const getChecksumAlgorithmListForResponse_1 = require("./getChecksumAlgorithmListForResponse"); | ||
const getChecksumLocationName_1 = require("./getChecksumLocationName"); | ||
const selectChecksumAlgorithmFunction_1 = require("./selectChecksumAlgorithmFunction"); | ||
const validateChecksumFromResponse = async (response, { config, responseAlgorithms }) => { | ||
const checksumAlgorithms = (0, getChecksumAlgorithmListForResponse_1.getChecksumAlgorithmListForResponse)(responseAlgorithms); | ||
const { body: responseBody, headers: responseHeaders } = response; | ||
for (const algorithm of checksumAlgorithms) { | ||
const responseHeader = (0, getChecksumLocationName_1.getChecksumLocationName)(algorithm); | ||
const checksumFromResponse = responseHeaders[responseHeader]; | ||
if (checksumFromResponse) { | ||
const checksumAlgorithmFn = (0, selectChecksumAlgorithmFunction_1.selectChecksumAlgorithmFunction)(algorithm, config); | ||
const { streamHasher, base64Encoder } = config; | ||
const checksum = await (0, getChecksum_1.getChecksum)(responseBody, { streamHasher, checksumAlgorithmFn, base64Encoder }); | ||
if (checksum === checksumFromResponse) { | ||
break; | ||
} | ||
throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` + | ||
` in response header "${responseHeader}".`); | ||
} | ||
} | ||
}; | ||
exports.validateChecksumFromResponse = validateChecksumFromResponse; | ||
module.exports = require("./index.js"); |
{ | ||
"name": "@aws-sdk/middleware-flexible-checksums", | ||
"version": "3.489.0", | ||
"version": "3.495.0", | ||
"scripts": { | ||
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"build:cjs": "tsc -p tsconfig.cjs.json", | ||
"build:cjs": "node ../../scripts/compilation/inline middleware-flexible-checksums", | ||
"build:es": "tsc -p tsconfig.es.json", | ||
@@ -33,11 +33,11 @@ "build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build", | ||
"@aws-crypto/crc32c": "3.0.0", | ||
"@aws-sdk/types": "3.489.0", | ||
"@smithy/is-array-buffer": "^2.0.0", | ||
"@smithy/protocol-http": "^3.0.12", | ||
"@smithy/types": "^2.8.0", | ||
"@smithy/util-utf8": "^2.0.2", | ||
"@aws-sdk/types": "3.495.0", | ||
"@smithy/is-array-buffer": "^2.1.0", | ||
"@smithy/protocol-http": "^3.1.0", | ||
"@smithy/types": "^2.9.0", | ||
"@smithy/util-utf8": "^2.1.0", | ||
"tslib": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@smithy/node-http-handler": "^2.2.2", | ||
"@smithy/node-http-handler": "^2.3.0", | ||
"concurrently": "7.0.0", | ||
@@ -44,0 +44,0 @@ "downlevel-dts": "0.10.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54170
920
+ Added@aws-sdk/types@3.495.0(transitive)
- Removed@aws-sdk/types@3.489.0(transitive)
Updated@aws-sdk/types@3.495.0
Updated@smithy/protocol-http@^3.1.0
Updated@smithy/types@^2.9.0
Updated@smithy/util-utf8@^2.1.0