@cryptexlabs/codex-nodejs-common 0.9.1 → 0.9.3
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/lib/package.json +3 -1
- package/lib/src/auth/authf-authenticator.d.ts +10 -0
- package/lib/src/auth/authf-authenticator.js +43 -0
- package/lib/src/auth/authf-authenticator.js.map +1 -0
- package/lib/src/auth/authf-authenticator.options.interface.d.ts +3 -0
- package/lib/src/auth/authf-authenticator.options.interface.js +3 -0
- package/lib/src/auth/authf-authenticator.options.interface.js.map +1 -0
- package/lib/src/auth/index.d.ts +2 -0
- package/lib/src/auth/index.js +2 -0
- package/lib/src/auth/index.js.map +1 -1
- package/lib/src/context/context.builder.d.ts +3 -5
- package/lib/src/context/context.builder.js +5 -7
- package/lib/src/context/context.builder.js.map +1 -1
- package/package.json +3 -1
- package/src/auth/authf-authenticator.options.interface.ts +3 -0
- package/src/auth/authf-authenticator.ts +44 -0
- package/src/auth/index.ts +2 -0
- package/src/context/context.builder.ts +3 -6
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Common code for Assistant applications",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"@nestjs/platform-ws": "8.0.6",
|
|
23
23
|
"@nestjs/swagger": "5.0.9",
|
|
24
24
|
"@nestjs/websockets": "8.0.6",
|
|
25
|
+
"axios": "0.19.0",
|
|
25
26
|
"rxjs": "^7.1.0"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
29
|
+
"@cryptexlabs/authf-data-model": "^0.9.9",
|
|
28
30
|
"@types/express": "4.17.8",
|
|
29
31
|
"@types/express-serve-static-core": "4.17.24",
|
|
30
32
|
"@types/i18n": "0.12.0",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthenticatorInterface } from "./authenticator.interface";
|
|
2
|
+
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
3
|
+
import { AuthfAuthenticatorOptionsInterface } from "./authf-authenticator.options.interface";
|
|
4
|
+
export declare class AuthfAuthenticator implements AuthenticatorInterface {
|
|
5
|
+
private readonly authfUrl;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly options?;
|
|
8
|
+
constructor(authfUrl: string, client: ClientInterface, options?: AuthfAuthenticatorOptionsInterface);
|
|
9
|
+
authenticate(token: string): Promise<boolean>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthfAuthenticator = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
class AuthfAuthenticator {
|
|
7
|
+
constructor(authfUrl, client, options) {
|
|
8
|
+
this.authfUrl = authfUrl;
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async authenticate(token) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.authEnabled) === false) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const now = new Date();
|
|
18
|
+
try {
|
|
19
|
+
await axios_1.default.get(`/api/v1/authenticated`, {
|
|
20
|
+
baseURL: this.authfUrl,
|
|
21
|
+
headers: {
|
|
22
|
+
"X-Correlation-Id": uuid_1.v4(),
|
|
23
|
+
"Accept-Language": "en-US",
|
|
24
|
+
"X-Started": now.toISOString(),
|
|
25
|
+
"X-Created": now.toISOString(),
|
|
26
|
+
"X-Context-Category": "default",
|
|
27
|
+
"X-Context-Id": "none",
|
|
28
|
+
"X-Client-Name": this.client.name,
|
|
29
|
+
"X-Client-Version": this.client.version,
|
|
30
|
+
"X-Client-Variant": this.client.variant,
|
|
31
|
+
"X-Client-Id": this.client.id,
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.AuthfAuthenticator = AuthfAuthenticator;
|
|
43
|
+
//# sourceMappingURL=authf-authenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authf-authenticator.js","sourceRoot":"","sources":["../../../src/auth/authf-authenticator.ts"],"names":[],"mappings":";;;AAGA,iCAA0B;AAC1B,+BAAoC;AAEpC,MAAa,kBAAkB;IAC7B,YACmB,QAAgB,EAChB,MAAuB,EACvB,OAA4C;QAF5C,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAiB;QACvB,YAAO,GAAP,OAAO,CAAqC;IAC5D,CAAC;IAEG,KAAK,CAAC,YAAY,CAAC,KAAa;;QACrC,IAAI,OAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,MAAK,KAAK,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,IAAI;YACF,MAAM,eAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE;gBACvC,OAAO,EAAE,IAAI,CAAC,QAAQ;gBACtB,OAAO,EAAE;oBACP,kBAAkB,EAAE,SAAM,EAAE;oBAC5B,iBAAiB,EAAE,OAAO;oBAC1B,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE;oBAC9B,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE;oBAC9B,oBAAoB,EAAE,SAAS;oBAC/B,cAAc,EAAE,MAAM;oBACtB,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;oBACjC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;oBACvC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;oBACvC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;oBAC7B,aAAa,EAAE,UAAU,KAAK,EAAE;iBACjC;aACF,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF;AArCD,gDAqCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authf-authenticator.options.interface.js","sourceRoot":"","sources":["../../../src/auth/authf-authenticator.options.interface.ts"],"names":[],"mappings":""}
|
package/lib/src/auth/index.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export * from "./http-authz.attach-objects.guard.util";
|
|
|
6
6
|
export * from "./http-authz.detach-objects.guard.util";
|
|
7
7
|
export * from "./http-authz.action-to-sub-objects.guard.util";
|
|
8
8
|
export * from "./http-authz.list-sub-objects.guard.util";
|
|
9
|
+
export * from "./authf-authenticator";
|
|
10
|
+
export * from "./authf-authenticator.options.interface";
|
package/lib/src/auth/index.js
CHANGED
|
@@ -18,4 +18,6 @@ __exportStar(require("./http-authz.attach-objects.guard.util"), exports);
|
|
|
18
18
|
__exportStar(require("./http-authz.detach-objects.guard.util"), exports);
|
|
19
19
|
__exportStar(require("./http-authz.action-to-sub-objects.guard.util"), exports);
|
|
20
20
|
__exportStar(require("./http-authz.list-sub-objects.guard.util"), exports);
|
|
21
|
+
__exportStar(require("./authf-authenticator"), exports);
|
|
22
|
+
__exportStar(require("./authf-authenticator.options.interface"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,yEAAuD;AACvD,yEAAuD;AACvD,gFAA8D;AAC9D,2EAAyD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,yEAAuD;AACvD,yEAAuD;AACvD,gFAA8D;AAC9D,2EAAyD;AACzD,wDAAsC;AACtC,0EAAwD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="i18n" />
|
|
2
1
|
import { LoggerService } from "@nestjs/common";
|
|
3
2
|
import { ApiMetaHeadersInterface, ClientInterface, LocaleInterface, MessageContextInterface, MessageMetaInterface } from "@cryptexlabs/codex-data-model";
|
|
4
3
|
import { DefaultConfig } from "../config";
|
|
@@ -8,14 +7,13 @@ export declare class ContextBuilder {
|
|
|
8
7
|
private readonly config;
|
|
9
8
|
client: ClientInterface;
|
|
10
9
|
private readonly messageContext;
|
|
11
|
-
private
|
|
10
|
+
private i18nDir?;
|
|
12
11
|
private locale;
|
|
13
|
-
private i18nDir;
|
|
14
12
|
private correlationId;
|
|
15
13
|
private started;
|
|
16
|
-
constructor(logger: LoggerService, config: DefaultConfig, client: ClientInterface, messageContext: MessageContextInterface,
|
|
14
|
+
constructor(logger: LoggerService, config: DefaultConfig, client: ClientInterface, messageContext: MessageContextInterface, i18nDir?: string);
|
|
17
15
|
build(): ContextBuilder;
|
|
18
|
-
|
|
16
|
+
setI18nDir(i18nDir: string): this;
|
|
19
17
|
setMetaFromHeaders(headers: ApiMetaHeadersInterface): this;
|
|
20
18
|
setMetaFromHeadersForNewMessage(headers: ApiMetaHeadersInterface): this;
|
|
21
19
|
setMeta(meta: MessageMetaInterface): this;
|
|
@@ -19,18 +19,17 @@ const uuid_1 = require("uuid");
|
|
|
19
19
|
const util_1 = require("../util");
|
|
20
20
|
const i18n_1 = require("i18n");
|
|
21
21
|
let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
22
|
-
constructor(logger, config, client, messageContext,
|
|
22
|
+
constructor(logger, config, client, messageContext, i18nDir) {
|
|
23
23
|
this.logger = logger;
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.client = client;
|
|
26
26
|
this.messageContext = messageContext;
|
|
27
|
-
this.
|
|
27
|
+
this.i18nDir = i18nDir;
|
|
28
28
|
}
|
|
29
29
|
build() {
|
|
30
|
-
return new ContextBuilder_1(this.logger, this.config, Object.assign({}, this.client), Object.assign({}, this.messageContext), this.
|
|
30
|
+
return new ContextBuilder_1(this.logger, this.config, Object.assign({}, this.client), Object.assign({}, this.messageContext), this.i18nDir);
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
this.i18nApi = i18nApi;
|
|
32
|
+
setI18nDir(i18nDir) {
|
|
34
33
|
this.i18nDir = i18nDir;
|
|
35
34
|
return this;
|
|
36
35
|
}
|
|
@@ -99,7 +98,6 @@ let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
|
99
98
|
const local = this._getLocale();
|
|
100
99
|
i18nInstance.configure({
|
|
101
100
|
locales: [local.i18n],
|
|
102
|
-
register: this.i18nApi,
|
|
103
101
|
directory: this.i18nDir,
|
|
104
102
|
defaultLocale: local.i18n,
|
|
105
103
|
});
|
|
@@ -109,7 +107,7 @@ let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
|
109
107
|
ContextBuilder = ContextBuilder_1 = __decorate([
|
|
110
108
|
common_1.Injectable(),
|
|
111
109
|
__metadata("design:paramtypes", [Object, config_1.DefaultConfig,
|
|
112
|
-
codex_data_model_1.ClientInterface, Object,
|
|
110
|
+
codex_data_model_1.ClientInterface, Object, String])
|
|
113
111
|
], ContextBuilder);
|
|
114
112
|
exports.ContextBuilder = ContextBuilder;
|
|
115
113
|
//# sourceMappingURL=context.builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.builder.js","sourceRoot":"","sources":["../../../src/context/context.builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,oEAQuC;AACvC,sCAA0C;AAC1C,uCAAoC;AACpC,+BAAoC;AACpC,kCAAqC;AACrC,+BAA4B;AAG5B,IAAa,cAAc,sBAA3B,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"context.builder.js","sourceRoot":"","sources":["../../../src/context/context.builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,oEAQuC;AACvC,sCAA0C;AAC1C,uCAAoC;AACpC,+BAAoC;AACpC,kCAAqC;AACrC,+BAA4B;AAG5B,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAKzB,YACmB,MAAqB,EACrB,MAAqB,EAC/B,MAAuB,EACb,cAAuC,EAChD,OAAgB;QAJP,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAe;QAC/B,WAAM,GAAN,MAAM,CAAiB;QACb,mBAAc,GAAd,cAAc,CAAyB;QAChD,YAAO,GAAP,OAAO,CAAS;IACvB,CAAC;IAEG,KAAK;QACV,OAAO,IAAI,gBAAc,CACvB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,oBACN,IAAI,CAAC,MAAM,qBACX,IAAI,CAAC,cAAc,GACxB,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;IAEM,UAAU,CAAC,OAAe;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,kBAAkB,CAAC,OAAgC;QACxD,IAAI,CAAC,+BAA+B,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,OAAO,CAAC,kBAAkB,CAAC,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACnD;QACD,IAAI,OAAO,CAAC,aAAa,CAAC,EAAE;YAC1B,IAAI,CAAC,MAAM,C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EACnB,IAAI,CAAC,WAAW,EAAE,EAClB,YAAY,CACb,CAAC;IACJ,CAAC;CACF,CAAA;AArHY,cAAc;IAD1B,mBAAU,EAAE;6CAQgB,sBAAa;QACvB,kCAAe;GARrB,cAAc,CAqH1B;AArHY,wCAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Common code for Assistant applications",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"@nestjs/platform-ws": "8.0.6",
|
|
23
23
|
"@nestjs/swagger": "5.0.9",
|
|
24
24
|
"@nestjs/websockets": "8.0.6",
|
|
25
|
+
"axios": "0.19.0",
|
|
25
26
|
"rxjs": "^7.1.0"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
29
|
+
"@cryptexlabs/authf-data-model": "^0.9.9",
|
|
28
30
|
"@types/express": "4.17.8",
|
|
29
31
|
"@types/express-serve-static-core": "4.17.24",
|
|
30
32
|
"@types/i18n": "0.12.0",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AuthenticatorInterface } from "./authenticator.interface";
|
|
2
|
+
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
3
|
+
import { AuthfAuthenticatorOptionsInterface } from "./authf-authenticator.options.interface";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
|
|
7
|
+
export class AuthfAuthenticator implements AuthenticatorInterface {
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly authfUrl: string,
|
|
10
|
+
private readonly client: ClientInterface,
|
|
11
|
+
private readonly options?: AuthfAuthenticatorOptionsInterface
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
public async authenticate(token: string): Promise<boolean> {
|
|
15
|
+
if (this.options?.authEnabled === false) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const now = new Date();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await axios.get(`/api/v1/authenticated`, {
|
|
23
|
+
baseURL: this.authfUrl,
|
|
24
|
+
headers: {
|
|
25
|
+
"X-Correlation-Id": uuidv4(),
|
|
26
|
+
"Accept-Language": "en-US",
|
|
27
|
+
"X-Started": now.toISOString(),
|
|
28
|
+
"X-Created": now.toISOString(),
|
|
29
|
+
"X-Context-Category": "default",
|
|
30
|
+
"X-Context-Id": "none",
|
|
31
|
+
"X-Client-Name": this.client.name,
|
|
32
|
+
"X-Client-Version": this.client.version,
|
|
33
|
+
"X-Client-Variant": this.client.variant,
|
|
34
|
+
"X-Client-Id": this.client.id,
|
|
35
|
+
Authorization: `Bearer ${token}`,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/auth/index.ts
CHANGED
|
@@ -6,3 +6,5 @@ export * from "./http-authz.attach-objects.guard.util";
|
|
|
6
6
|
export * from "./http-authz.detach-objects.guard.util";
|
|
7
7
|
export * from "./http-authz.action-to-sub-objects.guard.util";
|
|
8
8
|
export * from "./http-authz.list-sub-objects.guard.util";
|
|
9
|
+
export * from "./authf-authenticator";
|
|
10
|
+
export * from "./authf-authenticator.options.interface";
|
|
@@ -17,7 +17,6 @@ import { I18n } from "i18n";
|
|
|
17
17
|
@Injectable()
|
|
18
18
|
export class ContextBuilder {
|
|
19
19
|
private locale: LocaleI18nInterface;
|
|
20
|
-
private i18nDir: string;
|
|
21
20
|
private correlationId: string;
|
|
22
21
|
private started: Date;
|
|
23
22
|
|
|
@@ -26,7 +25,7 @@ export class ContextBuilder {
|
|
|
26
25
|
private readonly config: DefaultConfig,
|
|
27
26
|
public client: ClientInterface,
|
|
28
27
|
private readonly messageContext: MessageContextInterface,
|
|
29
|
-
private
|
|
28
|
+
private i18nDir?: string
|
|
30
29
|
) {}
|
|
31
30
|
|
|
32
31
|
public build() {
|
|
@@ -35,12 +34,11 @@ export class ContextBuilder {
|
|
|
35
34
|
this.config,
|
|
36
35
|
{ ...this.client },
|
|
37
36
|
{ ...this.messageContext },
|
|
38
|
-
this.
|
|
37
|
+
this.i18nDir
|
|
39
38
|
);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
public
|
|
43
|
-
this.i18nApi = i18nApi;
|
|
41
|
+
public setI18nDir(i18nDir: string) {
|
|
44
42
|
this.i18nDir = i18nDir;
|
|
45
43
|
return this;
|
|
46
44
|
}
|
|
@@ -119,7 +117,6 @@ export class ContextBuilder {
|
|
|
119
117
|
const local = this._getLocale();
|
|
120
118
|
i18nInstance.configure({
|
|
121
119
|
locales: [local.i18n],
|
|
122
|
-
register: this.i18nApi,
|
|
123
120
|
directory: this.i18nDir,
|
|
124
121
|
defaultLocale: local.i18n,
|
|
125
122
|
});
|