@aws-sdk/s3-presigned-post 3.490.0 → 3.496.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/dist-cjs/constants.js +1 -9
- package/dist-cjs/createPresignedPost.js +1 -71
- package/dist-cjs/index.js +119 -4
- package/dist-cjs/types.js +1 -2
- package/package.json +10 -10
package/dist-cjs/constants.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALGORITHM_IDENTIFIER = exports.SIGNATURE_QUERY_PARAM = exports.TOKEN_QUERY_PARAM = exports.AMZ_DATE_QUERY_PARAM = exports.CREDENTIAL_QUERY_PARAM = exports.ALGORITHM_QUERY_PARAM = void 0;
|
|
4
|
-
exports.ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
|
5
|
-
exports.CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
|
6
|
-
exports.AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
|
7
|
-
exports.TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
|
|
8
|
-
exports.SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
|
|
9
|
-
exports.ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
|
1
|
+
module.exports = require("./index.js");
|
|
@@ -1,71 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPresignedPost = void 0;
|
|
4
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
-
const util_format_url_1 = require("@aws-sdk/util-format-url");
|
|
6
|
-
const middleware_endpoint_1 = require("@smithy/middleware-endpoint");
|
|
7
|
-
const signature_v4_1 = require("@smithy/signature-v4");
|
|
8
|
-
const util_hex_encoding_1 = require("@smithy/util-hex-encoding");
|
|
9
|
-
const util_utf8_1 = require("@smithy/util-utf8");
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
|
-
const createPresignedPost = async (client, { Bucket, Key, Conditions = [], Fields = {}, Expires = 3600 }) => {
|
|
12
|
-
const { systemClockOffset, base64Encoder, utf8Decoder, sha256 } = client.config;
|
|
13
|
-
const now = new Date(Date.now() + systemClockOffset);
|
|
14
|
-
const signingDate = iso8601(now).replace(/[\-:]/g, "");
|
|
15
|
-
const shortDate = signingDate.slice(0, 8);
|
|
16
|
-
const clientRegion = await client.config.region();
|
|
17
|
-
const credentialScope = (0, signature_v4_1.createScope)(shortDate, clientRegion, "s3");
|
|
18
|
-
const clientCredentials = await client.config.credentials();
|
|
19
|
-
const credential = `${clientCredentials.accessKeyId}/${credentialScope}`;
|
|
20
|
-
const fields = {
|
|
21
|
-
...Fields,
|
|
22
|
-
bucket: Bucket,
|
|
23
|
-
[constants_1.ALGORITHM_QUERY_PARAM]: constants_1.ALGORITHM_IDENTIFIER,
|
|
24
|
-
[constants_1.CREDENTIAL_QUERY_PARAM]: credential,
|
|
25
|
-
[constants_1.AMZ_DATE_QUERY_PARAM]: signingDate,
|
|
26
|
-
...(clientCredentials.sessionToken ? { [constants_1.TOKEN_QUERY_PARAM]: clientCredentials.sessionToken } : {}),
|
|
27
|
-
};
|
|
28
|
-
const expiration = new Date(now.valueOf() + Expires * 1000);
|
|
29
|
-
const conditionsSet = new Set();
|
|
30
|
-
for (const condition of Conditions) {
|
|
31
|
-
const stringifiedCondition = JSON.stringify(condition);
|
|
32
|
-
conditionsSet.add(stringifiedCondition);
|
|
33
|
-
}
|
|
34
|
-
for (const [k, v] of Object.entries(fields)) {
|
|
35
|
-
conditionsSet.add(JSON.stringify({ [k]: v }));
|
|
36
|
-
}
|
|
37
|
-
if (Key.endsWith("${filename}")) {
|
|
38
|
-
conditionsSet.add(JSON.stringify(["starts-with", "$key", Key.substring(0, Key.lastIndexOf("${filename}"))]));
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
conditionsSet.add(JSON.stringify({ key: Key }));
|
|
42
|
-
}
|
|
43
|
-
const conditions = Array.from(conditionsSet).map((item) => JSON.parse(item));
|
|
44
|
-
const encodedPolicy = base64Encoder(utf8Decoder(JSON.stringify({
|
|
45
|
-
expiration: iso8601(expiration),
|
|
46
|
-
conditions,
|
|
47
|
-
})));
|
|
48
|
-
const signingKey = await (0, signature_v4_1.getSigningKey)(sha256, clientCredentials, shortDate, clientRegion, "s3");
|
|
49
|
-
const signature = await hmac(sha256, signingKey, encodedPolicy);
|
|
50
|
-
const endpoint = (0, middleware_endpoint_1.toEndpointV1)(await (0, middleware_endpoint_1.getEndpointFromInstructions)({ Bucket, Key }, client_s3_1.PutObjectCommand, {
|
|
51
|
-
...client.config,
|
|
52
|
-
}, {
|
|
53
|
-
logger: client.config.logger,
|
|
54
|
-
}));
|
|
55
|
-
return {
|
|
56
|
-
url: (0, util_format_url_1.formatUrl)(endpoint),
|
|
57
|
-
fields: {
|
|
58
|
-
...fields,
|
|
59
|
-
key: Key,
|
|
60
|
-
Policy: encodedPolicy,
|
|
61
|
-
[constants_1.SIGNATURE_QUERY_PARAM]: (0, util_hex_encoding_1.toHex)(signature),
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.createPresignedPost = createPresignedPost;
|
|
66
|
-
const iso8601 = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
67
|
-
const hmac = (ctor, secret, data) => {
|
|
68
|
-
const hash = new ctor(secret);
|
|
69
|
-
hash.update((0, util_utf8_1.toUint8Array)(data));
|
|
70
|
-
return hash.digest();
|
|
71
|
-
};
|
|
1
|
+
module.exports = require("./index.js");
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,4 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
createPresignedPost: () => createPresignedPost
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/createPresignedPost.ts
|
|
28
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
29
|
+
var import_util_format_url = require("@aws-sdk/util-format-url");
|
|
30
|
+
var import_middleware_endpoint = require("@smithy/middleware-endpoint");
|
|
31
|
+
var import_signature_v4 = require("@smithy/signature-v4");
|
|
32
|
+
var import_util_hex_encoding = require("@smithy/util-hex-encoding");
|
|
33
|
+
var import_util_utf8 = require("@smithy/util-utf8");
|
|
34
|
+
|
|
35
|
+
// src/constants.ts
|
|
36
|
+
var ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
|
37
|
+
var CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
|
38
|
+
var AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
|
39
|
+
var TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
|
|
40
|
+
var SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
|
|
41
|
+
var ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
|
42
|
+
|
|
43
|
+
// src/createPresignedPost.ts
|
|
44
|
+
var createPresignedPost = /* @__PURE__ */ __name(async (client, { Bucket, Key, Conditions = [], Fields = {}, Expires = 3600 }) => {
|
|
45
|
+
const { systemClockOffset, base64Encoder, utf8Decoder, sha256 } = client.config;
|
|
46
|
+
const now = new Date(Date.now() + systemClockOffset);
|
|
47
|
+
const signingDate = iso8601(now).replace(/[\-:]/g, "");
|
|
48
|
+
const shortDate = signingDate.slice(0, 8);
|
|
49
|
+
const clientRegion = await client.config.region();
|
|
50
|
+
const credentialScope = (0, import_signature_v4.createScope)(shortDate, clientRegion, "s3");
|
|
51
|
+
const clientCredentials = await client.config.credentials();
|
|
52
|
+
const credential = `${clientCredentials.accessKeyId}/${credentialScope}`;
|
|
53
|
+
const fields = {
|
|
54
|
+
...Fields,
|
|
55
|
+
bucket: Bucket,
|
|
56
|
+
[ALGORITHM_QUERY_PARAM]: ALGORITHM_IDENTIFIER,
|
|
57
|
+
[CREDENTIAL_QUERY_PARAM]: credential,
|
|
58
|
+
[AMZ_DATE_QUERY_PARAM]: signingDate,
|
|
59
|
+
...clientCredentials.sessionToken ? { [TOKEN_QUERY_PARAM]: clientCredentials.sessionToken } : {}
|
|
60
|
+
};
|
|
61
|
+
const expiration = new Date(now.valueOf() + Expires * 1e3);
|
|
62
|
+
const conditionsSet = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const condition of Conditions) {
|
|
64
|
+
const stringifiedCondition = JSON.stringify(condition);
|
|
65
|
+
conditionsSet.add(stringifiedCondition);
|
|
66
|
+
}
|
|
67
|
+
for (const [k, v] of Object.entries(fields)) {
|
|
68
|
+
conditionsSet.add(JSON.stringify({ [k]: v }));
|
|
69
|
+
}
|
|
70
|
+
if (Key.endsWith("${filename}")) {
|
|
71
|
+
conditionsSet.add(JSON.stringify(["starts-with", "$key", Key.substring(0, Key.lastIndexOf("${filename}"))]));
|
|
72
|
+
} else {
|
|
73
|
+
conditionsSet.add(JSON.stringify({ key: Key }));
|
|
74
|
+
}
|
|
75
|
+
const conditions = Array.from(conditionsSet).map((item) => JSON.parse(item));
|
|
76
|
+
const encodedPolicy = base64Encoder(
|
|
77
|
+
utf8Decoder(
|
|
78
|
+
JSON.stringify({
|
|
79
|
+
expiration: iso8601(expiration),
|
|
80
|
+
conditions
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
const signingKey = await (0, import_signature_v4.getSigningKey)(sha256, clientCredentials, shortDate, clientRegion, "s3");
|
|
85
|
+
const signature = await hmac(sha256, signingKey, encodedPolicy);
|
|
86
|
+
const endpoint = (0, import_middleware_endpoint.toEndpointV1)(
|
|
87
|
+
await (0, import_middleware_endpoint.getEndpointFromInstructions)(
|
|
88
|
+
{ Bucket, Key },
|
|
89
|
+
import_client_s3.PutObjectCommand,
|
|
90
|
+
{
|
|
91
|
+
...client.config
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
logger: client.config.logger
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
return {
|
|
99
|
+
url: (0, import_util_format_url.formatUrl)(endpoint),
|
|
100
|
+
fields: {
|
|
101
|
+
...fields,
|
|
102
|
+
key: Key,
|
|
103
|
+
Policy: encodedPolicy,
|
|
104
|
+
[SIGNATURE_QUERY_PARAM]: (0, import_util_hex_encoding.toHex)(signature)
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}, "createPresignedPost");
|
|
108
|
+
var iso8601 = /* @__PURE__ */ __name((date) => date.toISOString().replace(/\.\d{3}Z$/, "Z"), "iso8601");
|
|
109
|
+
var hmac = /* @__PURE__ */ __name((ctor, secret, data) => {
|
|
110
|
+
const hash = new ctor(secret);
|
|
111
|
+
hash.update((0, import_util_utf8.toUint8Array)(data));
|
|
112
|
+
return hash.digest();
|
|
113
|
+
}, "hmac");
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
createPresignedPost
|
|
118
|
+
});
|
|
119
|
+
|
package/dist-cjs/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
module.exports = require("./index.js");
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/s3-presigned-post",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.496.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
|
-
"build:cjs": "
|
|
6
|
+
"build:cjs": "node ../../scripts/compilation/inline s3-presigned-post",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
8
|
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
|
|
9
9
|
"build:types": "tsc -p tsconfig.types.json",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aws-sdk/client-s3": "3.
|
|
26
|
-
"@aws-sdk/types": "3.
|
|
27
|
-
"@aws-sdk/util-format-url": "3.
|
|
28
|
-
"@smithy/middleware-endpoint": "^2.
|
|
29
|
-
"@smithy/signature-v4": "^2.
|
|
30
|
-
"@smithy/types": "^2.
|
|
31
|
-
"@smithy/util-hex-encoding": "^2.
|
|
32
|
-
"@smithy/util-utf8": "^2.
|
|
25
|
+
"@aws-sdk/client-s3": "3.496.0",
|
|
26
|
+
"@aws-sdk/types": "3.496.0",
|
|
27
|
+
"@aws-sdk/util-format-url": "3.496.0",
|
|
28
|
+
"@smithy/middleware-endpoint": "^2.4.1",
|
|
29
|
+
"@smithy/signature-v4": "^2.1.1",
|
|
30
|
+
"@smithy/types": "^2.9.1",
|
|
31
|
+
"@smithy/util-hex-encoding": "^2.1.1",
|
|
32
|
+
"@smithy/util-utf8": "^2.1.1",
|
|
33
33
|
"tslib": "^2.5.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|