@aws-sdk/s3-request-presigner 3.182.0 → 3.185.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.185.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.184.0...v3.185.0) (2022-10-05)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/s3-request-presigner
9
+
10
+
11
+
12
+
13
+
14
+ # [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
15
+
16
+ **Note:** Version bump only for package @aws-sdk/s3-request-presigner
17
+
18
+
19
+
20
+
21
+
6
22
  # [3.182.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.181.0...v3.182.0) (2022-09-30)
7
23
 
8
24
  **Note:** Version bump only for package @aws-sdk/s3-request-presigner
@@ -1,9 +1,9 @@
1
- export var UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
2
- export var SHA256_HEADER = "X-Amz-Content-Sha256";
3
- export var ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
4
- export var CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
5
- export var AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
6
- export var SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
7
- export var EXPIRES_QUERY_PARAM = "X-Amz-Expires";
8
- export var HOST_HEADER = "host";
9
- export var ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
1
+ export const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
2
+ export const SHA256_HEADER = "X-Amz-Content-Sha256";
3
+ export const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
4
+ export const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
5
+ export const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
6
+ export const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
7
+ export const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
8
+ export const HOST_HEADER = "host";
9
+ export const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
@@ -1,70 +1,52 @@
1
- import { __assign, __awaiter, __generator } from "tslib";
2
1
  import { getEndpointFromInstructions } from "@aws-sdk/middleware-endpoint";
3
2
  import { HttpRequest } from "@aws-sdk/protocol-http";
4
3
  import { formatUrl } from "@aws-sdk/util-format-url";
5
4
  import { S3RequestPresigner } from "./presigner";
6
- export var getSignedUrl = function (client, command, options) {
7
- if (options === void 0) { options = {}; }
8
- return __awaiter(void 0, void 0, void 0, function () {
9
- var s3Presigner, endpointV2, authScheme_1, presignInterceptMiddleware, middlewareName, clientStack, handler, output, presigned;
10
- var _a, _b;
11
- return __generator(this, function (_c) {
12
- switch (_c.label) {
13
- case 0:
14
- if (!(typeof client.config.endpointProvider === "function")) return [3, 2];
15
- return [4, getEndpointFromInstructions(command.input, command.constructor, client.config)];
16
- case 1:
17
- endpointV2 = _c.sent();
18
- authScheme_1 = (_b = (_a = endpointV2.properties) === null || _a === void 0 ? void 0 : _a.authSchemes) === null || _b === void 0 ? void 0 : _b[0];
19
- s3Presigner = new S3RequestPresigner(__assign(__assign({}, client.config), { signingName: authScheme_1 === null || authScheme_1 === void 0 ? void 0 : authScheme_1.signingName, region: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
20
- return [2, authScheme_1 === null || authScheme_1 === void 0 ? void 0 : authScheme_1.signingScope];
21
- }); }); } }));
22
- return [3, 3];
23
- case 2:
24
- s3Presigner = new S3RequestPresigner(client.config);
25
- _c.label = 3;
26
- case 3:
27
- presignInterceptMiddleware = function (next, context) { return function (args) { return __awaiter(void 0, void 0, void 0, function () {
28
- var request, presigned;
29
- var _a, _b;
30
- return __generator(this, function (_c) {
31
- switch (_c.label) {
32
- case 0:
33
- request = args.request;
34
- if (!HttpRequest.isInstance(request)) {
35
- throw new Error("Request to be presigned is not an valid HTTP request.");
36
- }
37
- delete request.headers["amz-sdk-invocation-id"];
38
- delete request.headers["amz-sdk-request"];
39
- delete request.headers["x-amz-user-agent"];
40
- return [4, s3Presigner.presign(request, __assign(__assign({}, options), { signingRegion: (_a = options.signingRegion) !== null && _a !== void 0 ? _a : context["signing_region"], signingService: (_b = options.signingService) !== null && _b !== void 0 ? _b : context["signing_service"] }))];
41
- case 1:
42
- presigned = _c.sent();
43
- return [2, {
44
- response: {},
45
- output: {
46
- $metadata: { httpStatusCode: 200 },
47
- presigned: presigned,
48
- },
49
- }];
50
- }
51
- });
52
- }); }; };
53
- middlewareName = "presignInterceptMiddleware";
54
- clientStack = client.middlewareStack.clone();
55
- clientStack.addRelativeTo(presignInterceptMiddleware, {
56
- name: middlewareName,
57
- relation: "before",
58
- toMiddleware: "awsAuthMiddleware",
59
- override: true,
60
- });
61
- handler = command.resolveMiddleware(clientStack, client.config, {});
62
- return [4, handler({ input: command.input })];
63
- case 4:
64
- output = (_c.sent()).output;
65
- presigned = output.presigned;
66
- return [2, formatUrl(presigned)];
67
- }
5
+ export const getSignedUrl = async (client, command, options = {}) => {
6
+ let s3Presigner;
7
+ if (typeof client.config.endpointProvider === "function") {
8
+ const endpointV2 = await getEndpointFromInstructions(command.input, command.constructor, client.config);
9
+ const authScheme = endpointV2.properties?.authSchemes?.[0];
10
+ s3Presigner = new S3RequestPresigner({
11
+ ...client.config,
12
+ signingName: authScheme?.signingName,
13
+ region: async () => authScheme?.signingScope,
68
14
  });
15
+ }
16
+ else {
17
+ s3Presigner = new S3RequestPresigner(client.config);
18
+ }
19
+ const presignInterceptMiddleware = (next, context) => async (args) => {
20
+ const { request } = args;
21
+ if (!HttpRequest.isInstance(request)) {
22
+ throw new Error("Request to be presigned is not an valid HTTP request.");
23
+ }
24
+ delete request.headers["amz-sdk-invocation-id"];
25
+ delete request.headers["amz-sdk-request"];
26
+ delete request.headers["x-amz-user-agent"];
27
+ const presigned = await s3Presigner.presign(request, {
28
+ ...options,
29
+ signingRegion: options.signingRegion ?? context["signing_region"],
30
+ signingService: options.signingService ?? context["signing_service"],
31
+ });
32
+ return {
33
+ response: {},
34
+ output: {
35
+ $metadata: { httpStatusCode: 200 },
36
+ presigned,
37
+ },
38
+ };
39
+ };
40
+ const middlewareName = "presignInterceptMiddleware";
41
+ const clientStack = client.middlewareStack.clone();
42
+ clientStack.addRelativeTo(presignInterceptMiddleware, {
43
+ name: middlewareName,
44
+ relation: "before",
45
+ toMiddleware: "awsAuthMiddleware",
46
+ override: true,
69
47
  });
48
+ const handler = command.resolveMiddleware(clientStack, client.config, {});
49
+ const { output } = await handler({ input: command.input });
50
+ const { presigned } = output;
51
+ return formatUrl(presigned);
70
52
  };
@@ -1,30 +1,35 @@
1
- import { __assign, __rest } from "tslib";
2
1
  import { SignatureV4MultiRegion } from "@aws-sdk/signature-v4-multi-region";
3
2
  import { SHA256_HEADER, UNSIGNED_PAYLOAD } from "./constants";
4
- var S3RequestPresigner = (function () {
5
- function S3RequestPresigner(options) {
6
- var resolvedOptions = __assign({ service: options.signingName || options.service || "s3", uriEscapePath: options.uriEscapePath || false, applyChecksum: options.applyChecksum || false }, options);
3
+ export class S3RequestPresigner {
4
+ constructor(options) {
5
+ const resolvedOptions = {
6
+ service: options.signingName || options.service || "s3",
7
+ uriEscapePath: options.uriEscapePath || false,
8
+ applyChecksum: options.applyChecksum || false,
9
+ ...options,
10
+ };
7
11
  this.signer = new SignatureV4MultiRegion(resolvedOptions);
8
12
  }
9
- S3RequestPresigner.prototype.presign = function (requestToSign, _a) {
10
- if (_a === void 0) { _a = {}; }
11
- var _b = _a.unsignableHeaders, unsignableHeaders = _b === void 0 ? new Set() : _b, _c = _a.unhoistableHeaders, unhoistableHeaders = _c === void 0 ? new Set() : _c, options = __rest(_a, ["unsignableHeaders", "unhoistableHeaders"]);
13
+ presign(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
12
14
  unsignableHeaders.add("content-type");
13
15
  Object.keys(requestToSign.headers)
14
- .map(function (header) { return header.toLowerCase(); })
15
- .filter(function (header) { return header.startsWith("x-amz-server-side-encryption"); })
16
- .forEach(function (header) {
16
+ .map((header) => header.toLowerCase())
17
+ .filter((header) => header.startsWith("x-amz-server-side-encryption"))
18
+ .forEach((header) => {
17
19
  unhoistableHeaders.add(header);
18
20
  });
19
21
  requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
20
- var currentHostHeader = requestToSign.headers.host;
21
- var port = requestToSign.port;
22
- var expectedHostHeader = "".concat(requestToSign.hostname).concat(requestToSign.port != null ? ":" + port : "");
22
+ const currentHostHeader = requestToSign.headers.host;
23
+ const port = requestToSign.port;
24
+ const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
23
25
  if (!currentHostHeader || (currentHostHeader === requestToSign.hostname && requestToSign.port != null)) {
24
26
  requestToSign.headers.host = expectedHostHeader;
25
27
  }
26
- return this.signer.presign(requestToSign, __assign({ expiresIn: 900, unsignableHeaders: unsignableHeaders, unhoistableHeaders: unhoistableHeaders }, options));
27
- };
28
- return S3RequestPresigner;
29
- }());
30
- export { S3RequestPresigner };
28
+ return this.signer.presign(requestToSign, {
29
+ expiresIn: 900,
30
+ unsignableHeaders,
31
+ unhoistableHeaders,
32
+ ...options,
33
+ });
34
+ }
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/s3-request-presigner",
3
- "version": "3.182.0",
3
+ "version": "3.185.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -20,19 +20,19 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@aws-sdk/middleware-endpoint": "3.182.0",
24
- "@aws-sdk/middleware-sdk-s3": "3.178.0",
25
- "@aws-sdk/protocol-http": "3.178.0",
26
- "@aws-sdk/signature-v4-multi-region": "3.180.0",
27
- "@aws-sdk/smithy-client": "3.180.0",
28
- "@aws-sdk/types": "3.178.0",
29
- "@aws-sdk/util-create-request": "3.180.0",
30
- "@aws-sdk/util-format-url": "3.178.0",
23
+ "@aws-sdk/middleware-endpoint": "3.183.0",
24
+ "@aws-sdk/middleware-sdk-s3": "3.183.0",
25
+ "@aws-sdk/protocol-http": "3.183.0",
26
+ "@aws-sdk/signature-v4-multi-region": "3.183.0",
27
+ "@aws-sdk/smithy-client": "3.183.0",
28
+ "@aws-sdk/types": "3.183.0",
29
+ "@aws-sdk/util-create-request": "3.183.0",
30
+ "@aws-sdk/util-format-url": "3.183.0",
31
31
  "tslib": "^2.3.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@aws-sdk/client-s3": "3.181.0",
35
- "@aws-sdk/hash-node": "3.178.0",
34
+ "@aws-sdk/client-s3": "3.185.0",
35
+ "@aws-sdk/hash-node": "3.183.0",
36
36
  "@tsconfig/recommended": "1.0.1",
37
37
  "@types/node": "^12.0.2",
38
38
  "concurrently": "7.0.0",