@aws-sdk/s3-presigned-post 3.182.0 → 3.183.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,14 @@
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.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/s3-presigned-post
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.182.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.181.0...v3.182.0) (2022-09-30)
7
15
 
8
16
  **Note:** Version bump only for package @aws-sdk/s3-presigned-post
@@ -1,6 +1,6 @@
1
- export var ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
2
- export var CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
3
- export var AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
4
- export var TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
5
- export var SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
6
- export var ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
1
+ export const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
2
+ export const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
3
+ export const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
4
+ export const TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
5
+ export const SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
6
+ export const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
@@ -1,78 +1,64 @@
1
- import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib";
2
1
  import { PutObjectCommand } from "@aws-sdk/client-s3";
3
2
  import { getEndpointFromInstructions, toEndpointV1, } from "@aws-sdk/middleware-endpoint";
4
3
  import { createScope, getSigningKey } from "@aws-sdk/signature-v4";
5
4
  import { formatUrl } from "@aws-sdk/util-format-url";
6
5
  import { toHex } from "@aws-sdk/util-hex-encoding";
7
6
  import { ALGORITHM_IDENTIFIER, ALGORITHM_QUERY_PARAM, AMZ_DATE_QUERY_PARAM, CREDENTIAL_QUERY_PARAM, SIGNATURE_QUERY_PARAM, TOKEN_QUERY_PARAM, } from "./constants";
8
- export var createPresignedPost = function (client, _a) {
9
- var Bucket = _a.Bucket, Key = _a.Key, _b = _a.Conditions, Conditions = _b === void 0 ? [] : _b, _c = _a.Fields, Fields = _c === void 0 ? {} : _c, _d = _a.Expires, Expires = _d === void 0 ? 3600 : _d;
10
- return __awaiter(void 0, void 0, void 0, function () {
11
- var _e, systemClockOffset, base64Encoder, utf8Decoder, sha256, now, signingDate, shortDate, clientRegion, credentialScope, clientCredentials, credential, fields, expiration, conditions, encodedPolicy, signingKey, signature, endpoint, isEndpointV2, _f;
12
- var _g, _h, _j;
13
- var _k, _l;
14
- return __generator(this, function (_m) {
15
- switch (_m.label) {
16
- case 0:
17
- _e = client.config, systemClockOffset = _e.systemClockOffset, base64Encoder = _e.base64Encoder, utf8Decoder = _e.utf8Decoder, sha256 = _e.sha256;
18
- now = new Date(Date.now() + systemClockOffset);
19
- signingDate = iso8601(now).replace(/[\-:]/g, "");
20
- shortDate = signingDate.slice(0, 8);
21
- return [4, client.config.region()];
22
- case 1:
23
- clientRegion = _m.sent();
24
- credentialScope = createScope(shortDate, clientRegion, "s3");
25
- return [4, client.config.credentials()];
26
- case 2:
27
- clientCredentials = _m.sent();
28
- credential = "".concat(clientCredentials.accessKeyId, "/").concat(credentialScope);
29
- fields = __assign(__assign(__assign({}, Fields), (_g = { bucket: Bucket }, _g[ALGORITHM_QUERY_PARAM] = ALGORITHM_IDENTIFIER, _g[CREDENTIAL_QUERY_PARAM] = credential, _g[AMZ_DATE_QUERY_PARAM] = signingDate, _g)), (clientCredentials.sessionToken ? (_h = {}, _h[TOKEN_QUERY_PARAM] = clientCredentials.sessionToken, _h) : {}));
30
- expiration = new Date(now.valueOf() + Expires * 1000);
31
- conditions = __spreadArray(__spreadArray(__spreadArray([], __read(Conditions), false), __read(Object.entries(fields).map(function (_a) {
32
- var _b;
33
- var _c = __read(_a, 2), k = _c[0], v = _c[1];
34
- return (_b = {}, _b[k] = v, _b);
35
- })), false), [
36
- Key.endsWith("${filename}")
37
- ? ["starts-with", "$key", Key.substring(0, Key.lastIndexOf("${filename}"))]
38
- : { key: Key },
39
- ], false);
40
- encodedPolicy = base64Encoder(utf8Decoder(JSON.stringify({
41
- expiration: iso8601(expiration),
42
- conditions: conditions,
43
- })));
44
- return [4, getSigningKey(sha256, clientCredentials, shortDate, clientRegion, "s3")];
45
- case 3:
46
- signingKey = _m.sent();
47
- return [4, hmac(sha256, signingKey, encodedPolicy)];
48
- case 4:
49
- signature = _m.sent();
50
- return [4, ((_l = (_k = client.config) === null || _k === void 0 ? void 0 : _k.endpoint) === null || _l === void 0 ? void 0 : _l.call(_k))];
51
- case 5:
52
- endpoint = _m.sent();
53
- isEndpointV2 = false;
54
- if (!!endpoint) return [3, 7];
55
- isEndpointV2 = true;
56
- _f = toEndpointV1;
57
- return [4, getEndpointFromInstructions({ Bucket: Bucket, Key: Key }, PutObjectCommand, __assign({}, client.config))];
58
- case 6:
59
- endpoint = _f.apply(void 0, [_m.sent()]);
60
- _m.label = 7;
61
- case 7:
62
- if (endpoint && !client.config.isCustomEndpoint && !isEndpointV2) {
63
- endpoint.path = "/".concat(Bucket);
64
- }
65
- return [2, {
66
- url: formatUrl(endpoint),
67
- fields: __assign(__assign({}, fields), (_j = { key: Key, Policy: encodedPolicy }, _j[SIGNATURE_QUERY_PARAM] = toHex(signature), _j)),
68
- }];
69
- }
70
- });
71
- });
7
+ export const createPresignedPost = async (client, { Bucket, Key, Conditions = [], Fields = {}, Expires = 3600 }) => {
8
+ const { systemClockOffset, base64Encoder, utf8Decoder, sha256 } = client.config;
9
+ const now = new Date(Date.now() + systemClockOffset);
10
+ const signingDate = iso8601(now).replace(/[\-:]/g, "");
11
+ const shortDate = signingDate.slice(0, 8);
12
+ const clientRegion = await client.config.region();
13
+ const credentialScope = createScope(shortDate, clientRegion, "s3");
14
+ const clientCredentials = await client.config.credentials();
15
+ const credential = `${clientCredentials.accessKeyId}/${credentialScope}`;
16
+ const fields = {
17
+ ...Fields,
18
+ bucket: Bucket,
19
+ [ALGORITHM_QUERY_PARAM]: ALGORITHM_IDENTIFIER,
20
+ [CREDENTIAL_QUERY_PARAM]: credential,
21
+ [AMZ_DATE_QUERY_PARAM]: signingDate,
22
+ ...(clientCredentials.sessionToken ? { [TOKEN_QUERY_PARAM]: clientCredentials.sessionToken } : {}),
23
+ };
24
+ const expiration = new Date(now.valueOf() + Expires * 1000);
25
+ const conditions = [
26
+ ...Conditions,
27
+ ...Object.entries(fields).map(([k, v]) => ({ [k]: v })),
28
+ Key.endsWith("${filename}")
29
+ ? ["starts-with", "$key", Key.substring(0, Key.lastIndexOf("${filename}"))]
30
+ : { key: Key },
31
+ ];
32
+ const encodedPolicy = base64Encoder(utf8Decoder(JSON.stringify({
33
+ expiration: iso8601(expiration),
34
+ conditions,
35
+ })));
36
+ const signingKey = await getSigningKey(sha256, clientCredentials, shortDate, clientRegion, "s3");
37
+ const signature = await hmac(sha256, signingKey, encodedPolicy);
38
+ let endpoint = await client.config?.endpoint?.();
39
+ let isEndpointV2 = false;
40
+ if (!endpoint) {
41
+ isEndpointV2 = true;
42
+ endpoint = toEndpointV1(await getEndpointFromInstructions({ Bucket, Key }, PutObjectCommand, {
43
+ ...client.config,
44
+ }));
45
+ }
46
+ if (endpoint && !client.config.isCustomEndpoint && !isEndpointV2) {
47
+ endpoint.path = `/${Bucket}`;
48
+ }
49
+ return {
50
+ url: formatUrl(endpoint),
51
+ fields: {
52
+ ...fields,
53
+ key: Key,
54
+ Policy: encodedPolicy,
55
+ [SIGNATURE_QUERY_PARAM]: toHex(signature),
56
+ },
57
+ };
72
58
  };
73
- var iso8601 = function (date) { return date.toISOString().replace(/\.\d{3}Z$/, "Z"); };
74
- var hmac = function (ctor, secret, data) {
75
- var hash = new ctor(secret);
59
+ const iso8601 = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
60
+ const hmac = (ctor, secret, data) => {
61
+ const hash = new ctor(secret);
76
62
  hash.update(data);
77
63
  return hash.digest();
78
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/s3-presigned-post",
3
- "version": "3.182.0",
3
+ "version": "3.183.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,17 +20,17 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@aws-sdk/middleware-endpoint": "3.182.0",
24
- "@aws-sdk/signature-v4": "3.178.0",
25
- "@aws-sdk/types": "3.178.0",
26
- "@aws-sdk/util-format-url": "3.178.0",
27
- "@aws-sdk/util-hex-encoding": "3.170.0",
23
+ "@aws-sdk/middleware-endpoint": "3.183.0",
24
+ "@aws-sdk/signature-v4": "3.183.0",
25
+ "@aws-sdk/types": "3.183.0",
26
+ "@aws-sdk/util-format-url": "3.183.0",
27
+ "@aws-sdk/util-hex-encoding": "3.183.0",
28
28
  "tslib": "^2.3.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@aws-sdk/client-s3": "3.181.0",
32
- "@aws-sdk/hash-node": "3.178.0",
33
- "@aws-sdk/protocol-http": "3.178.0",
31
+ "@aws-sdk/client-s3": "3.183.0",
32
+ "@aws-sdk/hash-node": "3.183.0",
33
+ "@aws-sdk/protocol-http": "3.183.0",
34
34
  "@tsconfig/recommended": "1.0.1",
35
35
  "@types/node": "^12.0.2",
36
36
  "concurrently": "7.0.0",