@iyio/aws 0.7.0 → 0.7.5
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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { Sha256 } from '@aws-crypto/sha256-browser';
|
|
3
2
|
import { HttpRequest } from '@smithy/protocol-http';
|
|
4
3
|
import { SignatureV4 } from "@smithy/signature-v4";
|
|
@@ -16,46 +15,45 @@ export class AwsHttpRequestSigner {
|
|
|
16
15
|
}
|
|
17
16
|
constructor(options) {
|
|
18
17
|
this.signingPair = null;
|
|
19
|
-
this.options =
|
|
18
|
+
this.options = { ...options };
|
|
20
19
|
}
|
|
21
20
|
canSign() {
|
|
22
|
-
|
|
23
|
-
return ((_a = this.options.awsAuthProviders.get()) === null || _a === void 0 ? void 0 : _a.getAuthProvider()) ? true : false;
|
|
21
|
+
return this.options.awsAuthProviders.get()?.getAuthProvider() ? true : false;
|
|
24
22
|
}
|
|
25
|
-
sign(request) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
async sign(request) {
|
|
24
|
+
const authProvider = this.options.awsAuthProviders.get();
|
|
25
|
+
const credentials = authProvider?.getAuthProvider();
|
|
26
|
+
if (!credentials) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!this.signingPair || credentials !== this.signingPair.creds) {
|
|
30
|
+
this.signingPair = {
|
|
31
|
+
signer: new SignatureV4({
|
|
32
|
+
credentials: credentials,
|
|
33
|
+
region: this.options.region,
|
|
34
|
+
service: this.options.service,
|
|
35
|
+
sha256: Sha256
|
|
36
|
+
}),
|
|
37
|
+
creds: credentials
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!request.headers) {
|
|
41
|
+
request.headers = {};
|
|
42
|
+
}
|
|
43
|
+
const parts = /https?:\/\/([^/]*)/.exec(request.uri);
|
|
44
|
+
if (!parts) {
|
|
45
|
+
throw new Error('url contains no host');
|
|
46
|
+
}
|
|
47
|
+
request.headers['host'] = parts[1];
|
|
48
|
+
const signed = await this.signingPair.signer.sign(new HttpRequest({
|
|
49
|
+
...request,
|
|
50
|
+
}));
|
|
51
|
+
if (signed.headers) {
|
|
52
|
+
request.headers = {};
|
|
53
|
+
for (const e in signed.headers) {
|
|
54
|
+
request.headers[e] = signed.headers[e];
|
|
31
55
|
}
|
|
32
|
-
|
|
33
|
-
this.signingPair = {
|
|
34
|
-
signer: new SignatureV4({
|
|
35
|
-
credentials: credentials,
|
|
36
|
-
region: this.options.region,
|
|
37
|
-
service: this.options.service,
|
|
38
|
-
sha256: Sha256
|
|
39
|
-
}),
|
|
40
|
-
creds: credentials
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (!request.headers) {
|
|
44
|
-
request.headers = {};
|
|
45
|
-
}
|
|
46
|
-
const parts = /https?:\/\/([^/]*)/.exec(request.uri);
|
|
47
|
-
if (!parts) {
|
|
48
|
-
throw new Error('url contains no host');
|
|
49
|
-
}
|
|
50
|
-
request.headers['host'] = parts[1];
|
|
51
|
-
const signed = yield this.signingPair.signer.sign(new HttpRequest(Object.assign({}, request)));
|
|
52
|
-
if (signed.headers) {
|
|
53
|
-
request.headers = {};
|
|
54
|
-
for (const e in signed.headers) {
|
|
55
|
-
request.headers[e] = signed.headers[e];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
56
|
+
}
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
//# sourceMappingURL=AwsHttpRequestSigner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AwsHttpRequestSigner.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/AwsHttpRequestSigner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AwsHttpRequestSigner.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/AwsHttpRequestSigner.ts"],"names":[],"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false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-crypto/sha256-browser": ">=5.2.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"zod": ">=3.21.4"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@iyio/common": "^0.7.
|
|
16
|
+
"@iyio/common": "^0.7.5"
|
|
17
17
|
},
|
|
18
18
|
"main": "./src/index.js",
|
|
19
19
|
"module": "./esm/src/index.js"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AwsHttpRequestSigner = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const sha256_browser_1 = require("@aws-crypto/sha256-browser");
|
|
6
5
|
const protocol_http_1 = require("@smithy/protocol-http");
|
|
7
6
|
const signature_v4_1 = require("@smithy/signature-v4");
|
|
@@ -19,46 +18,45 @@ class AwsHttpRequestSigner {
|
|
|
19
18
|
}
|
|
20
19
|
constructor(options) {
|
|
21
20
|
this.signingPair = null;
|
|
22
|
-
this.options =
|
|
21
|
+
this.options = { ...options };
|
|
23
22
|
}
|
|
24
23
|
canSign() {
|
|
25
|
-
|
|
26
|
-
return ((_a = this.options.awsAuthProviders.get()) === null || _a === void 0 ? void 0 : _a.getAuthProvider()) ? true : false;
|
|
24
|
+
return this.options.awsAuthProviders.get()?.getAuthProvider() ? true : false;
|
|
27
25
|
}
|
|
28
|
-
sign(request) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
async sign(request) {
|
|
27
|
+
const authProvider = this.options.awsAuthProviders.get();
|
|
28
|
+
const credentials = authProvider?.getAuthProvider();
|
|
29
|
+
if (!credentials) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!this.signingPair || credentials !== this.signingPair.creds) {
|
|
33
|
+
this.signingPair = {
|
|
34
|
+
signer: new signature_v4_1.SignatureV4({
|
|
35
|
+
credentials: credentials,
|
|
36
|
+
region: this.options.region,
|
|
37
|
+
service: this.options.service,
|
|
38
|
+
sha256: sha256_browser_1.Sha256
|
|
39
|
+
}),
|
|
40
|
+
creds: credentials
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (!request.headers) {
|
|
44
|
+
request.headers = {};
|
|
45
|
+
}
|
|
46
|
+
const parts = /https?:\/\/([^/]*)/.exec(request.uri);
|
|
47
|
+
if (!parts) {
|
|
48
|
+
throw new Error('url contains no host');
|
|
49
|
+
}
|
|
50
|
+
request.headers['host'] = parts[1];
|
|
51
|
+
const signed = await this.signingPair.signer.sign(new protocol_http_1.HttpRequest({
|
|
52
|
+
...request,
|
|
53
|
+
}));
|
|
54
|
+
if (signed.headers) {
|
|
55
|
+
request.headers = {};
|
|
56
|
+
for (const e in signed.headers) {
|
|
57
|
+
request.headers[e] = signed.headers[e];
|
|
34
58
|
}
|
|
35
|
-
|
|
36
|
-
this.signingPair = {
|
|
37
|
-
signer: new signature_v4_1.SignatureV4({
|
|
38
|
-
credentials: credentials,
|
|
39
|
-
region: this.options.region,
|
|
40
|
-
service: this.options.service,
|
|
41
|
-
sha256: sha256_browser_1.Sha256
|
|
42
|
-
}),
|
|
43
|
-
creds: credentials
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (!request.headers) {
|
|
47
|
-
request.headers = {};
|
|
48
|
-
}
|
|
49
|
-
const parts = /https?:\/\/([^/]*)/.exec(request.uri);
|
|
50
|
-
if (!parts) {
|
|
51
|
-
throw new Error('url contains no host');
|
|
52
|
-
}
|
|
53
|
-
request.headers['host'] = parts[1];
|
|
54
|
-
const signed = yield this.signingPair.signer.sign(new protocol_http_1.HttpRequest(Object.assign({}, request)));
|
|
55
|
-
if (signed.headers) {
|
|
56
|
-
request.headers = {};
|
|
57
|
-
for (const e in signed.headers) {
|
|
58
|
-
request.headers[e] = signed.headers[e];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
59
|
+
}
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
exports.AwsHttpRequestSigner = AwsHttpRequestSigner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AwsHttpRequestSigner.js","sourceRoot":"","sources":["../../../../../packages/aws/src/lib/AwsHttpRequestSigner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AwsHttpRequestSigner.js","sourceRoot":"","sources":["../../../../../packages/aws/src/lib/AwsHttpRequestSigner.ts"],"names":[],"mappings":";;;AAAA,+DAAoD;AAEpD,yDAAoD;AACpD,uDAAmD;AACnD,6CAA2F;AAY3F,MAAa,oBAAoB;IAGtB,MAAM,CAAC,gBAAgB,CAAC,KAAW;QACtC,OAAO;YACH,gBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC,6BAAgB,CAAC;YAC3C,MAAM,EAAC,KAAK,CAAC,OAAO,CAAC,2BAAc,CAAC;YACpC,OAAO,EAAC,KAAK,CAAC,OAAO,CAAC,sCAAyB,CAAC;SACnD,CAAA;IACL,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,KAAW;QAC/B,OAAO,IAAI,oBAAoB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAClF,CAAC;IAMD,YAAmB,OAAmC;QAF9C,gBAAW,GAAqC,IAAI,CAAC;QAIzD,IAAI,CAAC,OAAO,GAAC,EAAC,GAAG,OAAO,EAAC,CAAA;IAC7B,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,CAAA,CAAC,CAAA,IAAI,CAAA,CAAC,CAAA,KAAK,CAAC;IAC7E,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAwB;QAEtC,MAAM,YAAY,GAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC;QACvD,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