@cryptexlabs/codex-nodejs-common 0.8.11 → 0.9.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/lib/package.json +1 -1
- package/lib/src/context/context.builder.d.ts +2 -1
- package/lib/src/context/context.builder.js +12 -2
- package/lib/src/context/context.builder.js.map +1 -1
- package/lib/src/context/context.d.ts +3 -3
- package/lib/src/context/context.js +2 -2
- package/lib/src/context/context.js.map +1 -1
- package/lib/src/response/contextual-http.response.d.ts +2 -2
- package/lib/src/response/contextual-http.response.js +2 -2
- package/lib/src/response/contextual-http.response.js.map +1 -1
- package/lib/src/response/simple-http.response.js +1 -1
- package/lib/src/response/simple-http.response.js.map +1 -1
- package/package.json +1 -1
- package/src/context/context.builder.ts +14 -2
- package/src/context/context.ts +2 -1
- package/src/response/contextual-http.response.ts +3 -2
- package/src/response/simple-http.response.ts +1 -1
package/lib/package.json
CHANGED
|
@@ -10,11 +10,12 @@ export declare class ContextBuilder {
|
|
|
10
10
|
private readonly messageContext;
|
|
11
11
|
private i18nApi?;
|
|
12
12
|
private locale;
|
|
13
|
+
private i18nDir;
|
|
13
14
|
private correlationId;
|
|
14
15
|
private started;
|
|
15
16
|
constructor(logger: LoggerService, config: DefaultConfig, client: ClientInterface, messageContext: MessageContextInterface, i18nApi?: i18nAPI);
|
|
16
17
|
build(): ContextBuilder;
|
|
17
|
-
setI18nApi(i18nApi: i18nAPI): this;
|
|
18
|
+
setI18nApi(i18nApi: i18nAPI, i18nDir: string): this;
|
|
18
19
|
setMetaFromHeaders(headers: ApiMetaHeadersInterface): this;
|
|
19
20
|
setMetaFromHeadersForNewMessage(headers: ApiMetaHeadersInterface): this;
|
|
20
21
|
setMeta(meta: MessageMetaInterface): this;
|
|
@@ -17,6 +17,7 @@ const config_1 = require("../config");
|
|
|
17
17
|
const context_1 = require("./context");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
19
|
const util_1 = require("../util");
|
|
20
|
+
const i18n_1 = require("i18n");
|
|
20
21
|
let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
21
22
|
constructor(logger, config, client, messageContext, i18nApi) {
|
|
22
23
|
this.logger = logger;
|
|
@@ -28,8 +29,9 @@ let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
|
28
29
|
build() {
|
|
29
30
|
return new ContextBuilder_1(this.logger, this.config, Object.assign({}, this.client), Object.assign({}, this.messageContext), this.i18nApi);
|
|
30
31
|
}
|
|
31
|
-
setI18nApi(i18nApi) {
|
|
32
|
+
setI18nApi(i18nApi, i18nDir) {
|
|
32
33
|
this.i18nApi = i18nApi;
|
|
34
|
+
this.i18nDir = i18nDir;
|
|
33
35
|
return this;
|
|
34
36
|
}
|
|
35
37
|
setMetaFromHeaders(headers) {
|
|
@@ -93,7 +95,15 @@ let ContextBuilder = ContextBuilder_1 = class ContextBuilder {
|
|
|
93
95
|
return this.locale || new codex_data_model_1.Locale("en", "US");
|
|
94
96
|
}
|
|
95
97
|
getResult() {
|
|
96
|
-
|
|
98
|
+
const i18nInstance = new i18n_1.I18n();
|
|
99
|
+
const local = this._getLocale();
|
|
100
|
+
i18nInstance.configure({
|
|
101
|
+
locales: [local.i18n],
|
|
102
|
+
register: this.i18nApi,
|
|
103
|
+
directory: this.i18nDir,
|
|
104
|
+
defaultLocale: local.i18n,
|
|
105
|
+
});
|
|
106
|
+
return new context_1.Context(this._getCorrelationId(), this.logger, this.config, this.client, this._getLocale(), this.messageContext, this._getStarted(), i18nInstance);
|
|
97
107
|
}
|
|
98
108
|
};
|
|
99
109
|
ContextBuilder = ContextBuilder_1 = __decorate([
|
|
@@ -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;
|
|
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;IAMzB,YACmB,MAAqB,EACrB,MAAqB,EAC/B,MAAuB,EACb,cAAuC,EAChD,OAAiB;QAJR,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAe;QAC/B,WAAM,GAAN,MAAM,CAAiB;QACb,mBAAc,GAAd,cAAc,CAAyB;QAChD,YAAO,GAAP,OAAO,CAAU;IACxB,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,OAAgB,EAAE,OAAe;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,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,CAAC,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;SACzC;QACD,IAAI,OAAO,CAAC,eAAe,CAAC,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,eAAe,CAA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a;QACvB,kCAAe;GATrB,cAAc,CAwH1B;AAxHY,wCAAc"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/// <reference types="i18n" />
|
|
2
1
|
import { ClientInterface, LocaleI18nInterface, MessageContextInterface, MessageMetaInterface } from "@cryptexlabs/codex-data-model";
|
|
3
2
|
import { LoggerService } from "@nestjs/common";
|
|
4
3
|
import { DefaultConfig } from "../config";
|
|
4
|
+
import { I18n } from "i18n";
|
|
5
5
|
export declare class Context {
|
|
6
6
|
correlationId: string;
|
|
7
7
|
config: DefaultConfig;
|
|
8
8
|
client: ClientInterface;
|
|
9
9
|
readonly locale: LocaleI18nInterface;
|
|
10
10
|
readonly messageContext: MessageContextInterface;
|
|
11
|
-
readonly
|
|
11
|
+
readonly i18n?: I18n;
|
|
12
12
|
readonly logger: LoggerService;
|
|
13
13
|
started: Date;
|
|
14
|
-
constructor(correlationId: string, logger: LoggerService, config: DefaultConfig, client: ClientInterface, locale: LocaleI18nInterface, messageContext: MessageContextInterface, started?: Date,
|
|
14
|
+
constructor(correlationId: string, logger: LoggerService, config: DefaultConfig, client: ClientInterface, locale: LocaleI18nInterface, messageContext: MessageContextInterface, started?: Date, i18n?: I18n);
|
|
15
15
|
getMessageMeta(type: string): MessageMetaInterface;
|
|
16
16
|
}
|
|
@@ -4,13 +4,13 @@ exports.Context = void 0;
|
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const message_1 = require("../message");
|
|
6
6
|
class Context {
|
|
7
|
-
constructor(correlationId, logger, config, client, locale, messageContext, started,
|
|
7
|
+
constructor(correlationId, logger, config, client, locale, messageContext, started, i18n) {
|
|
8
8
|
this.correlationId = correlationId;
|
|
9
9
|
this.config = config;
|
|
10
10
|
this.client = client;
|
|
11
11
|
this.locale = locale;
|
|
12
12
|
this.messageContext = messageContext;
|
|
13
|
-
this.
|
|
13
|
+
this.i18n = i18n;
|
|
14
14
|
this.logger = new logger_1.ContextLogger(correlationId, config, client, logger);
|
|
15
15
|
this.started = started || new Date(Date.now());
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/context/context.ts"],"names":[],"mappings":";;;AAQA,sCAA0C;AAC1C,wCAAyC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/context/context.ts"],"names":[],"mappings":";;;AAQA,sCAA0C;AAC1C,wCAAyC;AAGzC,MAAa,OAAO;IAIlB,YACS,aAAqB,EAC5B,MAAqB,EACd,MAAqB,EACrB,MAAuB,EACd,MAA2B,EAC3B,cAAuC,EACvD,OAAc,EACE,IAAW;QAPpB,kBAAa,GAAb,aAAa,CAAQ;QAErB,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAiB;QACd,WAAM,GAAN,MAAM,CAAqB;QAC3B,mBAAc,GAAd,cAAc,CAAyB;QAEvC,SAAI,GAAJ,IAAI,CAAO;QAE3B,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAa,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,cAAc,CAAC,IAAY;QACzB,OAAO,IAAI,qBAAW,CACpB,IAAI,EACJ,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;CACF;AA3BD,0BA2BC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="i18n" />
|
|
2
1
|
import { HttpResponse } from "./http-response";
|
|
3
2
|
import { HttpStatus } from "@nestjs/common";
|
|
4
3
|
import { JsonSerializableInterface } from "../message";
|
|
5
4
|
import { MessageInterface } from "@cryptexlabs/codex-data-model";
|
|
6
5
|
import { Context } from "../context";
|
|
6
|
+
import { I18n } from "i18n";
|
|
7
7
|
export declare class ContextualHttpResponse<T> extends HttpResponse<T> implements JsonSerializableInterface<MessageInterface<T>> {
|
|
8
8
|
private readonly _message;
|
|
9
|
-
constructor(context: Context, status: HttpStatus,
|
|
9
|
+
constructor(context: Context, status: HttpStatus, i18nInstance: I18n, phraseKey: string);
|
|
10
10
|
get data(): string;
|
|
11
11
|
}
|
|
@@ -4,12 +4,12 @@ exports.ContextualHttpResponse = void 0;
|
|
|
4
4
|
const http_response_1 = require("./http-response");
|
|
5
5
|
const codex_data_model_1 = require("@cryptexlabs/codex-data-model");
|
|
6
6
|
class ContextualHttpResponse extends http_response_1.HttpResponse {
|
|
7
|
-
constructor(context, status,
|
|
7
|
+
constructor(context, status, i18nInstance, phraseKey) {
|
|
8
8
|
super(status, context.config.getMetaType(codex_data_model_1.CodexMetaTypeEnum.NA_HTTP_SIMPLE), context.locale, context.config, context.correlationId, context.started);
|
|
9
9
|
this.meta.context = context.messageContext
|
|
10
10
|
? context.messageContext
|
|
11
11
|
: this.meta.context;
|
|
12
|
-
this._message =
|
|
12
|
+
this._message = i18nInstance.__({
|
|
13
13
|
phrase: phraseKey,
|
|
14
14
|
locale: context.locale.i18n,
|
|
15
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextual-http.response.js","sourceRoot":"","sources":["../../../src/response/contextual-http.response.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAG/C,oEAGuC;
|
|
1
|
+
{"version":3,"file":"contextual-http.response.js","sourceRoot":"","sources":["../../../src/response/contextual-http.response.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAG/C,oEAGuC;AAIvC,MAAa,sBACX,SAAQ,4BAAe;IAIvB,YACE,OAAgB,EAChB,MAAkB,EAClB,YAAkB,EAClB,SAAiB;QAEjB,KAAK,CACH,MAAM,EACN,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,oCAAiB,CAAC,cAAc,CAAC,EAC5D,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,OAAO,CAChB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc;YACxC,CAAC,CAAC,OAAO,CAAC,cAAc;YACxB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAC;YAC9B,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA/BD,wDA+BC"}
|
|
@@ -4,7 +4,7 @@ exports.SimpleHttpResponse = void 0;
|
|
|
4
4
|
const contextual_http_response_1 = require("./contextual-http.response");
|
|
5
5
|
class SimpleHttpResponse extends contextual_http_response_1.ContextualHttpResponse {
|
|
6
6
|
constructor(context, httpStatus, phraseKey) {
|
|
7
|
-
super(context, httpStatus, context.
|
|
7
|
+
super(context, httpStatus, context.i18n, phraseKey);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.SimpleHttpResponse = SimpleHttpResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-http.response.js","sourceRoot":"","sources":["../../../src/response/simple-http.response.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AAKpE,MAAa,kBACX,SAAQ,iDAA8B;IAEtC,YAAY,OAAgB,EAAE,UAAsB,EAAE,SAAiB;QACrE,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"simple-http.response.js","sourceRoot":"","sources":["../../../src/response/simple-http.response.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AAKpE,MAAa,kBACX,SAAQ,iDAA8B;IAEtC,YAAY,OAAgB,EAAE,UAAsB,EAAE,SAAiB;QACrE,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAND,gDAMC"}
|
package/package.json
CHANGED
|
@@ -12,10 +12,12 @@ import { DefaultConfig } from "../config";
|
|
|
12
12
|
import { Context } from "./context";
|
|
13
13
|
import { v4 as uuidv4 } from "uuid";
|
|
14
14
|
import { LocaleUtil } from "../util";
|
|
15
|
+
import { I18n } from "i18n";
|
|
15
16
|
|
|
16
17
|
@Injectable()
|
|
17
18
|
export class ContextBuilder {
|
|
18
19
|
private locale: LocaleI18nInterface;
|
|
20
|
+
private i18nDir: string;
|
|
19
21
|
private correlationId: string;
|
|
20
22
|
private started: Date;
|
|
21
23
|
|
|
@@ -37,8 +39,9 @@ export class ContextBuilder {
|
|
|
37
39
|
);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
public setI18nApi(i18nApi: i18nAPI) {
|
|
42
|
+
public setI18nApi(i18nApi: i18nAPI, i18nDir: string) {
|
|
41
43
|
this.i18nApi = i18nApi;
|
|
44
|
+
this.i18nDir = i18nDir;
|
|
42
45
|
return this;
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -112,6 +115,15 @@ export class ContextBuilder {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
public getResult(): Context {
|
|
118
|
+
const i18nInstance = new I18n();
|
|
119
|
+
const local = this._getLocale();
|
|
120
|
+
i18nInstance.configure({
|
|
121
|
+
locales: [local.i18n],
|
|
122
|
+
register: this.i18nApi,
|
|
123
|
+
directory: this.i18nDir,
|
|
124
|
+
defaultLocale: local.i18n,
|
|
125
|
+
});
|
|
126
|
+
|
|
115
127
|
return new Context(
|
|
116
128
|
this._getCorrelationId(),
|
|
117
129
|
this.logger,
|
|
@@ -120,7 +132,7 @@ export class ContextBuilder {
|
|
|
120
132
|
this._getLocale(),
|
|
121
133
|
this.messageContext,
|
|
122
134
|
this._getStarted(),
|
|
123
|
-
|
|
135
|
+
i18nInstance
|
|
124
136
|
);
|
|
125
137
|
}
|
|
126
138
|
}
|
package/src/context/context.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { LoggerService } from "@nestjs/common";
|
|
|
8
8
|
import { DefaultConfig } from "../config";
|
|
9
9
|
import { ContextLogger } from "../logger";
|
|
10
10
|
import { MessageMeta } from "../message";
|
|
11
|
+
import { I18n } from "i18n";
|
|
11
12
|
|
|
12
13
|
export class Context {
|
|
13
14
|
public readonly logger: LoggerService;
|
|
@@ -21,7 +22,7 @@ export class Context {
|
|
|
21
22
|
public readonly locale: LocaleI18nInterface,
|
|
22
23
|
public readonly messageContext: MessageContextInterface,
|
|
23
24
|
started?: Date,
|
|
24
|
-
public readonly
|
|
25
|
+
public readonly i18n?: I18n
|
|
25
26
|
) {
|
|
26
27
|
this.logger = new ContextLogger(correlationId, config, client, logger);
|
|
27
28
|
this.started = started || new Date(Date.now());
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
MessageInterface,
|
|
7
7
|
} from "@cryptexlabs/codex-data-model";
|
|
8
8
|
import { Context } from "../context";
|
|
9
|
+
import { I18n } from "i18n";
|
|
9
10
|
|
|
10
11
|
export class ContextualHttpResponse<T>
|
|
11
12
|
extends HttpResponse<T>
|
|
@@ -15,7 +16,7 @@ export class ContextualHttpResponse<T>
|
|
|
15
16
|
constructor(
|
|
16
17
|
context: Context,
|
|
17
18
|
status: HttpStatus,
|
|
18
|
-
|
|
19
|
+
i18nInstance: I18n,
|
|
19
20
|
phraseKey: string
|
|
20
21
|
) {
|
|
21
22
|
super(
|
|
@@ -29,7 +30,7 @@ export class ContextualHttpResponse<T>
|
|
|
29
30
|
this.meta.context = context.messageContext
|
|
30
31
|
? context.messageContext
|
|
31
32
|
: this.meta.context;
|
|
32
|
-
this._message =
|
|
33
|
+
this._message = i18nInstance.__({
|
|
33
34
|
phrase: phraseKey,
|
|
34
35
|
locale: context.locale.i18n,
|
|
35
36
|
});
|
|
@@ -7,6 +7,6 @@ export class SimpleHttpResponse
|
|
|
7
7
|
extends ContextualHttpResponse<string>
|
|
8
8
|
implements JsonSerializableInterface<any> {
|
|
9
9
|
constructor(context: Context, httpStatus: HttpStatus, phraseKey: string) {
|
|
10
|
-
super(context, httpStatus, context.
|
|
10
|
+
super(context, httpStatus, context.i18n, phraseKey);
|
|
11
11
|
}
|
|
12
12
|
}
|