@iyio/aws 0.0.29 → 0.1.1
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/esm/package.json +3 -0
- package/esm/src/index.d.ts +4 -0
- package/esm/src/index.js +5 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/lib/AwsHttpRequestSigner.d.ts +16 -0
- package/esm/src/lib/AwsHttpRequestSigner.js +61 -0
- package/esm/src/lib/AwsHttpRequestSigner.js.map +1 -0
- package/esm/src/lib/_modules.aws.d.ts +2 -0
- package/esm/src/lib/_modules.aws.js +6 -0
- package/esm/src/lib/_modules.aws.js.map +1 -0
- package/esm/src/lib/_types.aws.d.ts +5 -0
- package/esm/src/lib/_types.aws.js +6 -0
- package/esm/src/lib/_types.aws.js.map +1 -0
- package/esm/src/lib/aws-auth.d.ts +7 -0
- package/esm/src/lib/aws-auth.js +2 -0
- package/esm/src/lib/aws-auth.js.map +1 -0
- package/package.json +6 -4
- package/src/package.json +4 -0
package/esm/package.json
ADDED
package/esm/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/aws/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseHttpRequest, HttpRequestSigner, Scope, TypeDef } from '@iyio/common';
|
|
2
|
+
import { AwsAuthProvider } from './aws-auth';
|
|
3
|
+
export interface AwsHttpRequestSignerOptions {
|
|
4
|
+
awsAuthProviders: TypeDef<AwsAuthProvider>;
|
|
5
|
+
region: string;
|
|
6
|
+
service: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class AwsHttpRequestSigner implements HttpRequestSigner {
|
|
9
|
+
static optionsFromScope(scope: Scope): AwsHttpRequestSignerOptions;
|
|
10
|
+
static fromScope(scope: Scope): AwsHttpRequestSigner;
|
|
11
|
+
private readonly options;
|
|
12
|
+
private signingPair;
|
|
13
|
+
constructor(options: AwsHttpRequestSignerOptions);
|
|
14
|
+
canSign(): boolean;
|
|
15
|
+
sign(request: BaseHttpRequest): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { Sha256 } from '@aws-crypto/sha256-browser';
|
|
3
|
+
import { HttpRequest } from '@aws-sdk/protocol-http';
|
|
4
|
+
import { SignatureV4 } from "@aws-sdk/signature-v4";
|
|
5
|
+
import { AwsAuthProviders, awsHttpSignerServiceParam, awsRegionParam } from './_types.aws';
|
|
6
|
+
export class AwsHttpRequestSigner {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.signingPair = null;
|
|
9
|
+
this.options = Object.assign({}, options);
|
|
10
|
+
}
|
|
11
|
+
static optionsFromScope(scope) {
|
|
12
|
+
return {
|
|
13
|
+
awsAuthProviders: scope.to(AwsAuthProviders),
|
|
14
|
+
region: scope.require(awsRegionParam),
|
|
15
|
+
service: scope.require(awsHttpSignerServiceParam),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
static fromScope(scope) {
|
|
19
|
+
return new AwsHttpRequestSigner(AwsHttpRequestSigner.optionsFromScope(scope));
|
|
20
|
+
}
|
|
21
|
+
canSign() {
|
|
22
|
+
var _a;
|
|
23
|
+
return ((_a = this.options.awsAuthProviders.get()) === null || _a === void 0 ? void 0 : _a.getAuthProvider()) ? true : false;
|
|
24
|
+
}
|
|
25
|
+
sign(request) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const authProvider = this.options.awsAuthProviders.get();
|
|
28
|
+
const credentials = authProvider === null || authProvider === void 0 ? void 0 : authProvider.getAuthProvider();
|
|
29
|
+
if (!credentials) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!this.signingPair || credentials !== this.signingPair.creds) {
|
|
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
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=AwsHttpRequestSigner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AwsHttpRequestSigner.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/AwsHttpRequestSigner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW3F,MAAM,OAAO,oBAAoB;IAmB7B,YAAmB,OAAmC;QAF9C,gBAAW,GAAqC,IAAI,CAAC;QAIzD,IAAI,CAAC,OAAO,qBAAK,OAAO,CAAC,CAAA;IAC7B,CAAC;IAnBM,MA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ACrB;YAED,MAAM,KAAK,GAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACnD,IAAG,CAAC,KAAK,EAAC;gBACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;aAC3C;YAED,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAEjC,MAAM,MAAM,GAAC,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,WAAW,mBACxD,OAAO,EACZ,CAAC,CAAC;YAEJ,IAAG,MAAM,CAAC,OAAO,EAAC;gBACd,OAAO,CAAC,OAAO,GAAC,EAAE,CAAA;gBAClB,KAAI,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,EAAC;oBAC1B,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;iBACxC;aACJ;QACL,CAAC;KAAA;CAEJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HttpRequestSigners } from "@iyio/common";
|
|
2
|
+
import { AwsHttpRequestSigner } from "./AwsHttpRequestSigner";
|
|
3
|
+
export const awsModule = (scope) => {
|
|
4
|
+
scope.addProvider(HttpRequestSigners, scope => AwsHttpRequestSigner.fromScope(scope));
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=_modules.aws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_modules.aws.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/_modules.aws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,CAAC,MAAM,SAAS,GAAC,CAAC,KAAuB,EAAC,EAAE;IAC9C,KAAK,CAAC,WAAW,CAAC,kBAAkB,EAAC,KAAK,CAAA,EAAE,CAAA,oBAAoB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACvF,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AwsAuthProvider } from "./aws-auth";
|
|
2
|
+
export declare const AwsAuthProviders: import("@iyio/common").ProviderTypeDef<AwsAuthProvider>;
|
|
3
|
+
export declare const awsRegionParam: import("@iyio/common").ParamTypeDef<string>;
|
|
4
|
+
export declare const awsProfileParam: import("@iyio/common").ParamTypeDef<string>;
|
|
5
|
+
export declare const awsHttpSignerServiceParam: import("@iyio/common").ParamTypeDef<string>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { defineProvider, defineStringParam } from "@iyio/common";
|
|
2
|
+
export const AwsAuthProviders = defineProvider("AwsAuthProviders");
|
|
3
|
+
export const awsRegionParam = defineStringParam('awsRegion');
|
|
4
|
+
export const awsProfileParam = defineStringParam('aswProfile');
|
|
5
|
+
export const awsHttpSignerServiceParam = defineStringParam('awsHttpSignerService', 'lambda');
|
|
6
|
+
//# sourceMappingURL=_types.aws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_types.aws.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/_types.aws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjE,MAAM,CAAC,MAAM,gBAAgB,GAAC,cAAc,CAAkB,kBAAkB,CAAC,CAAC;AAElF,MAAM,CAAC,MAAM,cAAc,GAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,eAAe,GAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAE7D,MAAM,CAAC,MAAM,yBAAyB,GAAC,iBAAiB,CAAC,sBAAsB,EAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-auth.js","sourceRoot":"","sources":["../../../../../../packages/aws/src/lib/aws-auth.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iyio/aws",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "commonjs",
|
|
3
|
+
"version": "0.1.1",
|
|
5
4
|
"main": "./src/index.js",
|
|
6
5
|
"types": "./src/index.d.ts",
|
|
7
6
|
"dependencies": {},
|
|
8
7
|
"peerDependencies": {
|
|
9
|
-
"@iyio/common": "0.
|
|
8
|
+
"@iyio/common": "0.1.1",
|
|
10
9
|
"rxjs": "^7.5.7",
|
|
10
|
+
"date-fns": "^2.29.3",
|
|
11
11
|
"uuid": "^9.0.0",
|
|
12
12
|
"tslib": "^2.3.0"
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"module": "./esm/src/index.js"
|
|
14
16
|
}
|
package/src/package.json
ADDED