@aws-sdk/s3-presigned-post 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 +16 -0
- package/dist-es/constants.js +6 -6
- package/dist-es/createPresignedPost.js +54 -68
- package/package.json +9 -9
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-presigned-post
|
|
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-presigned-post
|
|
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-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 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
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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.
|
|
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,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.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.
|
|
32
|
-
"@aws-sdk/hash-node": "3.
|
|
33
|
-
"@aws-sdk/protocol-http": "3.
|
|
31
|
+
"@aws-sdk/client-s3": "3.185.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",
|