@aws-sdk/s3-request-presigner 3.899.0 → 3.906.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/index.js +123 -177
- package/package.json +10 -10
package/dist-cjs/index.js
CHANGED
|
@@ -1,186 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var index_exports = {};
|
|
23
|
-
__export(index_exports, {
|
|
24
|
-
S3RequestPresigner: () => S3RequestPresigner,
|
|
25
|
-
getSignedUrl: () => getSignedUrl
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
'use strict';
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
3
|
+
var utilFormatUrl = require('@aws-sdk/util-format-url');
|
|
4
|
+
var middlewareEndpoint = require('@smithy/middleware-endpoint');
|
|
5
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
6
|
+
var signatureV4MultiRegion = require('@aws-sdk/signature-v4-multi-region');
|
|
33
7
|
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
|
9
|
+
const SHA256_HEADER = "X-Amz-Content-Sha256";
|
|
36
10
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
constructor(options) {
|
|
48
|
-
const resolvedOptions = {
|
|
49
|
-
// Allow `signingName` because we want to support usecase of supply client's resolved config
|
|
50
|
-
// directly. Where service equals signingName.
|
|
51
|
-
service: options.signingName || options.service || "s3",
|
|
52
|
-
uriEscapePath: options.uriEscapePath || false,
|
|
53
|
-
applyChecksum: options.applyChecksum || false,
|
|
54
|
-
...options
|
|
55
|
-
};
|
|
56
|
-
this.signer = new import_signature_v4_multi_region.SignatureV4MultiRegion(resolvedOptions);
|
|
57
|
-
}
|
|
58
|
-
presign(requestToSign, {
|
|
59
|
-
unsignableHeaders = /* @__PURE__ */ new Set(),
|
|
60
|
-
hoistableHeaders = /* @__PURE__ */ new Set(),
|
|
61
|
-
unhoistableHeaders = /* @__PURE__ */ new Set(),
|
|
62
|
-
...options
|
|
63
|
-
} = {}) {
|
|
64
|
-
this.prepareRequest(requestToSign, {
|
|
65
|
-
unsignableHeaders,
|
|
66
|
-
unhoistableHeaders,
|
|
67
|
-
hoistableHeaders
|
|
68
|
-
});
|
|
69
|
-
return this.signer.presign(requestToSign, {
|
|
70
|
-
expiresIn: 900,
|
|
71
|
-
unsignableHeaders,
|
|
72
|
-
unhoistableHeaders,
|
|
73
|
-
...options
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
presignWithCredentials(requestToSign, credentials, {
|
|
77
|
-
unsignableHeaders = /* @__PURE__ */ new Set(),
|
|
78
|
-
hoistableHeaders = /* @__PURE__ */ new Set(),
|
|
79
|
-
unhoistableHeaders = /* @__PURE__ */ new Set(),
|
|
80
|
-
...options
|
|
81
|
-
} = {}) {
|
|
82
|
-
this.prepareRequest(requestToSign, {
|
|
83
|
-
unsignableHeaders,
|
|
84
|
-
unhoistableHeaders,
|
|
85
|
-
hoistableHeaders
|
|
86
|
-
});
|
|
87
|
-
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
|
88
|
-
expiresIn: 900,
|
|
89
|
-
unsignableHeaders,
|
|
90
|
-
unhoistableHeaders,
|
|
91
|
-
...options
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
prepareRequest(requestToSign, {
|
|
95
|
-
unsignableHeaders = /* @__PURE__ */ new Set(),
|
|
96
|
-
unhoistableHeaders = /* @__PURE__ */ new Set(),
|
|
97
|
-
hoistableHeaders = /* @__PURE__ */ new Set()
|
|
98
|
-
} = {}) {
|
|
99
|
-
unsignableHeaders.add("content-type");
|
|
100
|
-
Object.keys(requestToSign.headers).map((header) => header.toLowerCase()).filter((header) => header.startsWith("x-amz-server-side-encryption")).forEach((header) => {
|
|
101
|
-
if (!hoistableHeaders.has(header)) {
|
|
102
|
-
unhoistableHeaders.add(header);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
|
|
106
|
-
const currentHostHeader = requestToSign.headers.host;
|
|
107
|
-
const port = requestToSign.port;
|
|
108
|
-
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
|
109
|
-
if (!currentHostHeader || currentHostHeader === requestToSign.hostname && requestToSign.port != null) {
|
|
110
|
-
requestToSign.headers.host = expectedHostHeader;
|
|
11
|
+
class S3RequestPresigner {
|
|
12
|
+
signer;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const resolvedOptions = {
|
|
15
|
+
service: options.signingName || options.service || "s3",
|
|
16
|
+
uriEscapePath: options.uriEscapePath || false,
|
|
17
|
+
applyChecksum: options.applyChecksum || false,
|
|
18
|
+
...options,
|
|
19
|
+
};
|
|
20
|
+
this.signer = new signatureV4MultiRegion.SignatureV4MultiRegion(resolvedOptions);
|
|
111
21
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
const authScheme = endpointV2.properties?.authSchemes?.[0];
|
|
126
|
-
if (authScheme?.name === "sigv4a") {
|
|
127
|
-
region = authScheme?.signingRegionSet?.join(",");
|
|
128
|
-
} else {
|
|
129
|
-
region = authScheme?.signingRegion;
|
|
22
|
+
presign(requestToSign, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
|
23
|
+
this.prepareRequest(requestToSign, {
|
|
24
|
+
unsignableHeaders,
|
|
25
|
+
unhoistableHeaders,
|
|
26
|
+
hoistableHeaders,
|
|
27
|
+
});
|
|
28
|
+
return this.signer.presign(requestToSign, {
|
|
29
|
+
expiresIn: 900,
|
|
30
|
+
unsignableHeaders,
|
|
31
|
+
unhoistableHeaders,
|
|
32
|
+
...options,
|
|
33
|
+
});
|
|
130
34
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
35
|
+
presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
|
36
|
+
this.prepareRequest(requestToSign, {
|
|
37
|
+
unsignableHeaders,
|
|
38
|
+
unhoistableHeaders,
|
|
39
|
+
hoistableHeaders,
|
|
40
|
+
});
|
|
41
|
+
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
|
42
|
+
expiresIn: 900,
|
|
43
|
+
unsignableHeaders,
|
|
44
|
+
unhoistableHeaders,
|
|
45
|
+
...options,
|
|
46
|
+
});
|
|
143
47
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
48
|
+
prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), hoistableHeaders = new Set(), } = {}) {
|
|
49
|
+
unsignableHeaders.add("content-type");
|
|
50
|
+
Object.keys(requestToSign.headers)
|
|
51
|
+
.map((header) => header.toLowerCase())
|
|
52
|
+
.filter((header) => header.startsWith("x-amz-server-side-encryption"))
|
|
53
|
+
.forEach((header) => {
|
|
54
|
+
if (!hoistableHeaders.has(header)) {
|
|
55
|
+
unhoistableHeaders.add(header);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
|
|
59
|
+
const currentHostHeader = requestToSign.headers.host;
|
|
60
|
+
const port = requestToSign.port;
|
|
61
|
+
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
|
62
|
+
if (!currentHostHeader || (currentHostHeader === requestToSign.hostname && requestToSign.port != null)) {
|
|
63
|
+
requestToSign.headers.host = expectedHostHeader;
|
|
64
|
+
}
|
|
157
65
|
}
|
|
158
|
-
|
|
159
|
-
// Intercept the middleware stack by returning fake response
|
|
160
|
-
response: {},
|
|
161
|
-
output: {
|
|
162
|
-
$metadata: { httpStatusCode: 200 },
|
|
163
|
-
presigned: presigned2
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
}, "presignInterceptMiddleware");
|
|
167
|
-
const middlewareName = "presignInterceptMiddleware";
|
|
168
|
-
const clientStack = client.middlewareStack.clone();
|
|
169
|
-
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
|
170
|
-
name: middlewareName,
|
|
171
|
-
relation: "before",
|
|
172
|
-
toMiddleware: "awsAuthMiddleware",
|
|
173
|
-
override: true
|
|
174
|
-
});
|
|
175
|
-
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
|
176
|
-
const { output } = await handler({ input: command.input });
|
|
177
|
-
const { presigned } = output;
|
|
178
|
-
return (0, import_util_format_url.formatUrl)(presigned);
|
|
179
|
-
}, "getSignedUrl");
|
|
180
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
}
|
|
181
67
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
68
|
+
const getSignedUrl = async (client, command, options = {}) => {
|
|
69
|
+
let s3Presigner;
|
|
70
|
+
let region;
|
|
71
|
+
if (typeof client.config.endpointProvider === "function") {
|
|
72
|
+
const endpointV2 = await middlewareEndpoint.getEndpointFromInstructions(command.input, command.constructor, client.config);
|
|
73
|
+
const authScheme = endpointV2.properties?.authSchemes?.[0];
|
|
74
|
+
if (authScheme?.name === "sigv4a") {
|
|
75
|
+
region = authScheme?.signingRegionSet?.join(",");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
region = authScheme?.signingRegion;
|
|
79
|
+
}
|
|
80
|
+
s3Presigner = new S3RequestPresigner({
|
|
81
|
+
...client.config,
|
|
82
|
+
signingName: authScheme?.signingName,
|
|
83
|
+
region: async () => region,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
s3Presigner = new S3RequestPresigner(client.config);
|
|
88
|
+
}
|
|
89
|
+
const presignInterceptMiddleware = (next, context) => async (args) => {
|
|
90
|
+
const { request } = args;
|
|
91
|
+
if (!protocolHttp.HttpRequest.isInstance(request)) {
|
|
92
|
+
throw new Error("Request to be presigned is not an valid HTTP request.");
|
|
93
|
+
}
|
|
94
|
+
delete request.headers["amz-sdk-invocation-id"];
|
|
95
|
+
delete request.headers["amz-sdk-request"];
|
|
96
|
+
delete request.headers["x-amz-user-agent"];
|
|
97
|
+
let presigned;
|
|
98
|
+
const presignerOptions = {
|
|
99
|
+
...options,
|
|
100
|
+
signingRegion: options.signingRegion ?? context["signing_region"] ?? region,
|
|
101
|
+
signingService: options.signingService ?? context["signing_service"],
|
|
102
|
+
};
|
|
103
|
+
if (context.s3ExpressIdentity) {
|
|
104
|
+
presigned = await s3Presigner.presignWithCredentials(request, context.s3ExpressIdentity, presignerOptions);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
presigned = await s3Presigner.presign(request, presignerOptions);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
response: {},
|
|
111
|
+
output: {
|
|
112
|
+
$metadata: { httpStatusCode: 200 },
|
|
113
|
+
presigned,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const middlewareName = "presignInterceptMiddleware";
|
|
118
|
+
const clientStack = client.middlewareStack.clone();
|
|
119
|
+
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
|
120
|
+
name: middlewareName,
|
|
121
|
+
relation: "before",
|
|
122
|
+
toMiddleware: "awsAuthMiddleware",
|
|
123
|
+
override: true,
|
|
124
|
+
});
|
|
125
|
+
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
|
126
|
+
const { output } = await handler({ input: command.input });
|
|
127
|
+
const { presigned } = output;
|
|
128
|
+
return utilFormatUrl.formatUrl(presigned);
|
|
129
|
+
};
|
|
186
130
|
|
|
131
|
+
exports.S3RequestPresigner = S3RequestPresigner;
|
|
132
|
+
exports.getSignedUrl = getSignedUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/s3-request-presigner",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.906.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline s3-request-presigner",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@aws-sdk/signature-v4-multi-region": "3.
|
|
27
|
-
"@aws-sdk/types": "3.
|
|
28
|
-
"@aws-sdk/util-format-url": "3.
|
|
29
|
-
"@smithy/middleware-endpoint": "^4.
|
|
30
|
-
"@smithy/protocol-http": "^5.
|
|
31
|
-
"@smithy/smithy-client": "^4.
|
|
32
|
-
"@smithy/types": "^4.
|
|
26
|
+
"@aws-sdk/signature-v4-multi-region": "3.906.0",
|
|
27
|
+
"@aws-sdk/types": "3.901.0",
|
|
28
|
+
"@aws-sdk/util-format-url": "3.901.0",
|
|
29
|
+
"@smithy/middleware-endpoint": "^4.3.0",
|
|
30
|
+
"@smithy/protocol-http": "^5.3.0",
|
|
31
|
+
"@smithy/smithy-client": "^4.7.0",
|
|
32
|
+
"@smithy/types": "^4.6.0",
|
|
33
33
|
"tslib": "^2.6.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@aws-sdk/client-s3": "3.
|
|
37
|
-
"@smithy/hash-node": "^4.
|
|
36
|
+
"@aws-sdk/client-s3": "3.906.0",
|
|
37
|
+
"@smithy/hash-node": "^4.2.0",
|
|
38
38
|
"@tsconfig/recommended": "1.0.1",
|
|
39
39
|
"@types/node": "^18.19.69",
|
|
40
40
|
"concurrently": "7.0.0",
|