@aws-sdk/s3-presigned-post 3.185.0 → 3.186.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 +8 -0
- package/dist-es/constants.js +6 -6
- package/dist-es/createPresignedPost.js +68 -54
- package/package.json +9 -9
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.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/s3-presigned-post
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.185.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.184.0...v3.185.0) (2022-10-05)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-sdk/s3-presigned-post
|
package/dist-es/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
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,64 +1,78 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
1
2
|
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
|
2
3
|
import { getEndpointFromInstructions, toEndpointV1, } from "@aws-sdk/middleware-endpoint";
|
|
3
4
|
import { createScope, getSigningKey } from "@aws-sdk/signature-v4";
|
|
4
5
|
import { formatUrl } from "@aws-sdk/util-format-url";
|
|
5
6
|
import { toHex } from "@aws-sdk/util-hex-encoding";
|
|
6
7
|
import { ALGORITHM_IDENTIFIER, ALGORITHM_QUERY_PARAM, AMZ_DATE_QUERY_PARAM, CREDENTIAL_QUERY_PARAM, SIGNATURE_QUERY_PARAM, TOKEN_QUERY_PARAM, } from "./constants";
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
});
|
|
58
72
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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);
|
|
62
76
|
hash.update(data);
|
|
63
77
|
return hash.digest();
|
|
64
78
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/s3-presigned-post",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.186.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.
|
|
24
|
-
"@aws-sdk/signature-v4": "3.
|
|
25
|
-
"@aws-sdk/types": "3.
|
|
26
|
-
"@aws-sdk/util-format-url": "3.
|
|
27
|
-
"@aws-sdk/util-hex-encoding": "3.
|
|
23
|
+
"@aws-sdk/middleware-endpoint": "3.186.0",
|
|
24
|
+
"@aws-sdk/signature-v4": "3.186.0",
|
|
25
|
+
"@aws-sdk/types": "3.186.0",
|
|
26
|
+
"@aws-sdk/util-format-url": "3.186.0",
|
|
27
|
+
"@aws-sdk/util-hex-encoding": "3.186.0",
|
|
28
28
|
"tslib": "^2.3.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@aws-sdk/client-s3": "3.
|
|
32
|
-
"@aws-sdk/hash-node": "3.
|
|
33
|
-
"@aws-sdk/protocol-http": "3.
|
|
31
|
+
"@aws-sdk/client-s3": "3.186.0",
|
|
32
|
+
"@aws-sdk/hash-node": "3.186.0",
|
|
33
|
+
"@aws-sdk/protocol-http": "3.186.0",
|
|
34
34
|
"@tsconfig/recommended": "1.0.1",
|
|
35
35
|
"@types/node": "^12.0.2",
|
|
36
36
|
"concurrently": "7.0.0",
|