@aws-sdk/s3-request-presigner 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 -12
- package/dist-cjs/getSignedUrl.js +1 -65
- package/dist-cjs/index.js +160 -5
- package/dist-cjs/presigner.js +1 -57
- package/package.json +11 -11
package/dist-cjs/constants.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALGORITHM_IDENTIFIER = exports.HOST_HEADER = exports.EXPIRES_QUERY_PARAM = exports.SIGNED_HEADERS_QUERY_PARAM = exports.AMZ_DATE_QUERY_PARAM = exports.CREDENTIAL_QUERY_PARAM = exports.ALGORITHM_QUERY_PARAM = exports.SHA256_HEADER = exports.UNSIGNED_PAYLOAD = void 0;
|
|
4
|
-
exports.UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
|
5
|
-
exports.SHA256_HEADER = "X-Amz-Content-Sha256";
|
|
6
|
-
exports.ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
|
7
|
-
exports.CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
|
8
|
-
exports.AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
|
9
|
-
exports.SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
|
|
10
|
-
exports.EXPIRES_QUERY_PARAM = "X-Amz-Expires";
|
|
11
|
-
exports.HOST_HEADER = "host";
|
|
12
|
-
exports.ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
|
1
|
+
module.exports = require("./index.js");
|
package/dist-cjs/getSignedUrl.js
CHANGED
|
@@ -1,65 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSignedUrl = void 0;
|
|
4
|
-
const util_format_url_1 = require("@aws-sdk/util-format-url");
|
|
5
|
-
const middleware_endpoint_1 = require("@smithy/middleware-endpoint");
|
|
6
|
-
const protocol_http_1 = require("@smithy/protocol-http");
|
|
7
|
-
const presigner_1 = require("./presigner");
|
|
8
|
-
const getSignedUrl = async (client, command, options = {}) => {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
let s3Presigner;
|
|
11
|
-
if (typeof client.config.endpointProvider === "function") {
|
|
12
|
-
const endpointV2 = await (0, middleware_endpoint_1.getEndpointFromInstructions)(command.input, command.constructor, client.config);
|
|
13
|
-
const authScheme = (_b = (_a = endpointV2.properties) === null || _a === void 0 ? void 0 : _a.authSchemes) === null || _b === void 0 ? void 0 : _b[0];
|
|
14
|
-
s3Presigner = new presigner_1.S3RequestPresigner({
|
|
15
|
-
...client.config,
|
|
16
|
-
signingName: authScheme === null || authScheme === void 0 ? void 0 : authScheme.signingName,
|
|
17
|
-
region: async () => authScheme === null || authScheme === void 0 ? void 0 : authScheme.signingRegion,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
s3Presigner = new presigner_1.S3RequestPresigner(client.config);
|
|
22
|
-
}
|
|
23
|
-
const presignInterceptMiddleware = (next, context) => async (args) => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
const { request } = args;
|
|
26
|
-
if (!protocol_http_1.HttpRequest.isInstance(request)) {
|
|
27
|
-
throw new Error("Request to be presigned is not an valid HTTP request.");
|
|
28
|
-
}
|
|
29
|
-
delete request.headers["amz-sdk-invocation-id"];
|
|
30
|
-
delete request.headers["amz-sdk-request"];
|
|
31
|
-
delete request.headers["x-amz-user-agent"];
|
|
32
|
-
let presigned;
|
|
33
|
-
const presignerOptions = {
|
|
34
|
-
...options,
|
|
35
|
-
signingRegion: (_a = options.signingRegion) !== null && _a !== void 0 ? _a : context["signing_region"],
|
|
36
|
-
signingService: (_b = options.signingService) !== null && _b !== void 0 ? _b : context["signing_service"],
|
|
37
|
-
};
|
|
38
|
-
if (context.s3ExpressIdentity) {
|
|
39
|
-
presigned = await s3Presigner.presignWithCredentials(request, context.s3ExpressIdentity, presignerOptions);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
presigned = await s3Presigner.presign(request, presignerOptions);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
response: {},
|
|
46
|
-
output: {
|
|
47
|
-
$metadata: { httpStatusCode: 200 },
|
|
48
|
-
presigned,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const middlewareName = "presignInterceptMiddleware";
|
|
53
|
-
const clientStack = client.middlewareStack.clone();
|
|
54
|
-
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
|
55
|
-
name: middlewareName,
|
|
56
|
-
relation: "before",
|
|
57
|
-
toMiddleware: "awsAuthMiddleware",
|
|
58
|
-
override: true,
|
|
59
|
-
});
|
|
60
|
-
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
|
61
|
-
const { output } = await handler({ input: command.input });
|
|
62
|
-
const { presigned } = output;
|
|
63
|
-
return (0, util_format_url_1.formatUrl)(presigned);
|
|
64
|
-
};
|
|
65
|
-
exports.getSignedUrl = getSignedUrl;
|
|
1
|
+
module.exports = require("./index.js");
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,5 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
S3RequestPresigner: () => S3RequestPresigner,
|
|
24
|
+
getSignedUrl: () => getSignedUrl
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/getSignedUrl.ts
|
|
29
|
+
var import_util_format_url = require("@aws-sdk/util-format-url");
|
|
30
|
+
var import_middleware_endpoint = require("@smithy/middleware-endpoint");
|
|
31
|
+
var import_protocol_http = require("@smithy/protocol-http");
|
|
32
|
+
|
|
33
|
+
// src/presigner.ts
|
|
34
|
+
var import_signature_v4_multi_region = require("@aws-sdk/signature-v4-multi-region");
|
|
35
|
+
|
|
36
|
+
// src/constants.ts
|
|
37
|
+
var UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
|
38
|
+
var SHA256_HEADER = "X-Amz-Content-Sha256";
|
|
39
|
+
|
|
40
|
+
// src/presigner.ts
|
|
41
|
+
var _S3RequestPresigner = class _S3RequestPresigner {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
const resolvedOptions = {
|
|
44
|
+
// Allow `signingName` because we want to support usecase of supply client's resolved config
|
|
45
|
+
// directly. Where service equals signingName.
|
|
46
|
+
service: options.signingName || options.service || "s3",
|
|
47
|
+
uriEscapePath: options.uriEscapePath || false,
|
|
48
|
+
applyChecksum: options.applyChecksum || false,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
this.signer = new import_signature_v4_multi_region.SignatureV4MultiRegion(resolvedOptions);
|
|
52
|
+
}
|
|
53
|
+
presign(requestToSign, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set(), ...options } = {}) {
|
|
54
|
+
this.prepareRequest(requestToSign, {
|
|
55
|
+
unsignableHeaders,
|
|
56
|
+
unhoistableHeaders
|
|
57
|
+
});
|
|
58
|
+
return this.signer.presign(requestToSign, {
|
|
59
|
+
expiresIn: 900,
|
|
60
|
+
unsignableHeaders,
|
|
61
|
+
unhoistableHeaders,
|
|
62
|
+
...options
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
presignWithCredentials(requestToSign, credentials, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set(), ...options } = {}) {
|
|
66
|
+
this.prepareRequest(requestToSign, {
|
|
67
|
+
unsignableHeaders,
|
|
68
|
+
unhoistableHeaders
|
|
69
|
+
});
|
|
70
|
+
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
|
71
|
+
expiresIn: 900,
|
|
72
|
+
unsignableHeaders,
|
|
73
|
+
unhoistableHeaders,
|
|
74
|
+
...options
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
prepareRequest(requestToSign, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set() } = {}) {
|
|
78
|
+
unsignableHeaders.add("content-type");
|
|
79
|
+
Object.keys(requestToSign.headers).map((header) => header.toLowerCase()).filter((header) => header.startsWith("x-amz-server-side-encryption")).forEach((header) => {
|
|
80
|
+
unhoistableHeaders.add(header);
|
|
81
|
+
});
|
|
82
|
+
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
|
|
83
|
+
const currentHostHeader = requestToSign.headers.host;
|
|
84
|
+
const port = requestToSign.port;
|
|
85
|
+
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
|
86
|
+
if (!currentHostHeader || currentHostHeader === requestToSign.hostname && requestToSign.port != null) {
|
|
87
|
+
requestToSign.headers.host = expectedHostHeader;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
__name(_S3RequestPresigner, "S3RequestPresigner");
|
|
92
|
+
var S3RequestPresigner = _S3RequestPresigner;
|
|
93
|
+
|
|
94
|
+
// src/getSignedUrl.ts
|
|
95
|
+
var getSignedUrl = /* @__PURE__ */ __name(async (client, command, options = {}) => {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
let s3Presigner;
|
|
98
|
+
if (typeof client.config.endpointProvider === "function") {
|
|
99
|
+
const endpointV2 = await (0, import_middleware_endpoint.getEndpointFromInstructions)(
|
|
100
|
+
command.input,
|
|
101
|
+
command.constructor,
|
|
102
|
+
client.config
|
|
103
|
+
);
|
|
104
|
+
const authScheme = (_b = (_a = endpointV2.properties) == null ? void 0 : _a.authSchemes) == null ? void 0 : _b[0];
|
|
105
|
+
s3Presigner = new S3RequestPresigner({
|
|
106
|
+
...client.config,
|
|
107
|
+
signingName: authScheme == null ? void 0 : authScheme.signingName,
|
|
108
|
+
region: async () => authScheme == null ? void 0 : authScheme.signingRegion
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
s3Presigner = new S3RequestPresigner(client.config);
|
|
112
|
+
}
|
|
113
|
+
const presignInterceptMiddleware = /* @__PURE__ */ __name((next, context) => async (args) => {
|
|
114
|
+
const { request } = args;
|
|
115
|
+
if (!import_protocol_http.HttpRequest.isInstance(request)) {
|
|
116
|
+
throw new Error("Request to be presigned is not an valid HTTP request.");
|
|
117
|
+
}
|
|
118
|
+
delete request.headers["amz-sdk-invocation-id"];
|
|
119
|
+
delete request.headers["amz-sdk-request"];
|
|
120
|
+
delete request.headers["x-amz-user-agent"];
|
|
121
|
+
let presigned2;
|
|
122
|
+
const presignerOptions = {
|
|
123
|
+
...options,
|
|
124
|
+
signingRegion: options.signingRegion ?? context["signing_region"],
|
|
125
|
+
signingService: options.signingService ?? context["signing_service"]
|
|
126
|
+
};
|
|
127
|
+
if (context.s3ExpressIdentity) {
|
|
128
|
+
presigned2 = await s3Presigner.presignWithCredentials(request, context.s3ExpressIdentity, presignerOptions);
|
|
129
|
+
} else {
|
|
130
|
+
presigned2 = await s3Presigner.presign(request, presignerOptions);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
// Intercept the middleware stack by returning fake response
|
|
134
|
+
response: {},
|
|
135
|
+
output: {
|
|
136
|
+
$metadata: { httpStatusCode: 200 },
|
|
137
|
+
presigned: presigned2
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}, "presignInterceptMiddleware");
|
|
141
|
+
const middlewareName = "presignInterceptMiddleware";
|
|
142
|
+
const clientStack = client.middlewareStack.clone();
|
|
143
|
+
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
|
144
|
+
name: middlewareName,
|
|
145
|
+
relation: "before",
|
|
146
|
+
toMiddleware: "awsAuthMiddleware",
|
|
147
|
+
override: true
|
|
148
|
+
});
|
|
149
|
+
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
|
150
|
+
const { output } = await handler({ input: command.input });
|
|
151
|
+
const { presigned } = output;
|
|
152
|
+
return (0, import_util_format_url.formatUrl)(presigned);
|
|
153
|
+
}, "getSignedUrl");
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
S3RequestPresigner,
|
|
158
|
+
getSignedUrl
|
|
159
|
+
});
|
|
160
|
+
|
package/dist-cjs/presigner.js
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.S3RequestPresigner = void 0;
|
|
4
|
-
const signature_v4_multi_region_1 = require("@aws-sdk/signature-v4-multi-region");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
class S3RequestPresigner {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
const resolvedOptions = {
|
|
9
|
-
service: options.signingName || options.service || "s3",
|
|
10
|
-
uriEscapePath: options.uriEscapePath || false,
|
|
11
|
-
applyChecksum: options.applyChecksum || false,
|
|
12
|
-
...options,
|
|
13
|
-
};
|
|
14
|
-
this.signer = new signature_v4_multi_region_1.SignatureV4MultiRegion(resolvedOptions);
|
|
15
|
-
}
|
|
16
|
-
presign(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
|
17
|
-
this.prepareRequest(requestToSign, {
|
|
18
|
-
unsignableHeaders,
|
|
19
|
-
unhoistableHeaders,
|
|
20
|
-
});
|
|
21
|
-
return this.signer.presign(requestToSign, {
|
|
22
|
-
expiresIn: 900,
|
|
23
|
-
unsignableHeaders,
|
|
24
|
-
unhoistableHeaders,
|
|
25
|
-
...options,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
|
29
|
-
this.prepareRequest(requestToSign, {
|
|
30
|
-
unsignableHeaders,
|
|
31
|
-
unhoistableHeaders,
|
|
32
|
-
});
|
|
33
|
-
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
|
34
|
-
expiresIn: 900,
|
|
35
|
-
unsignableHeaders,
|
|
36
|
-
unhoistableHeaders,
|
|
37
|
-
...options,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set() } = {}) {
|
|
41
|
-
unsignableHeaders.add("content-type");
|
|
42
|
-
Object.keys(requestToSign.headers)
|
|
43
|
-
.map((header) => header.toLowerCase())
|
|
44
|
-
.filter((header) => header.startsWith("x-amz-server-side-encryption"))
|
|
45
|
-
.forEach((header) => {
|
|
46
|
-
unhoistableHeaders.add(header);
|
|
47
|
-
});
|
|
48
|
-
requestToSign.headers[constants_1.SHA256_HEADER] = constants_1.UNSIGNED_PAYLOAD;
|
|
49
|
-
const currentHostHeader = requestToSign.headers.host;
|
|
50
|
-
const port = requestToSign.port;
|
|
51
|
-
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
|
52
|
-
if (!currentHostHeader || (currentHostHeader === requestToSign.hostname && requestToSign.port != null)) {
|
|
53
|
-
requestToSign.headers.host = expectedHostHeader;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.S3RequestPresigner = S3RequestPresigner;
|
|
1
|
+
module.exports = require("./index.js");
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/s3-request-presigner",
|
|
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-request-presigner",
|
|
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",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@aws-sdk/signature-v4-multi-region": "3.
|
|
25
|
-
"@aws-sdk/types": "3.
|
|
26
|
-
"@aws-sdk/util-format-url": "3.
|
|
27
|
-
"@smithy/middleware-endpoint": "^2.
|
|
28
|
-
"@smithy/protocol-http": "^3.
|
|
29
|
-
"@smithy/smithy-client": "^2.
|
|
30
|
-
"@smithy/types": "^2.
|
|
24
|
+
"@aws-sdk/signature-v4-multi-region": "3.496.0",
|
|
25
|
+
"@aws-sdk/types": "3.496.0",
|
|
26
|
+
"@aws-sdk/util-format-url": "3.496.0",
|
|
27
|
+
"@smithy/middleware-endpoint": "^2.4.1",
|
|
28
|
+
"@smithy/protocol-http": "^3.1.1",
|
|
29
|
+
"@smithy/smithy-client": "^2.3.1",
|
|
30
|
+
"@smithy/types": "^2.9.1",
|
|
31
31
|
"tslib": "^2.5.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@aws-sdk/client-s3": "3.
|
|
35
|
-
"@smithy/hash-node": "^2.
|
|
34
|
+
"@aws-sdk/client-s3": "3.496.0",
|
|
35
|
+
"@smithy/hash-node": "^2.1.1",
|
|
36
36
|
"@tsconfig/recommended": "1.0.1",
|
|
37
37
|
"@types/node": "^14.14.31",
|
|
38
38
|
"concurrently": "7.0.0",
|