mblabs-roccato-backend-commons 1.0.72 → 1.0.74
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/interfaces/elastic-apm.d.ts +11 -1
- package/dist/services/elastic-apm.d.ts +3 -1
- package/dist/services/elastic-apm.js +24 -2
- package/dist/services/i18n.d.ts +1 -1
- package/dist/services/i18n.js +4 -4
- package/package.json +1 -1
- package/src/interfaces/elastic-apm.ts +12 -1
- package/src/services/elastic-apm.ts +27 -2
- package/src/services/i18n.ts +4 -4
|
@@ -5,9 +5,18 @@ interface Credentials {
|
|
|
5
5
|
secretToken: string;
|
|
6
6
|
}
|
|
7
7
|
export declare namespace ElasticAPM {
|
|
8
|
+
namespace Init {
|
|
9
|
+
interface Request {
|
|
10
|
+
data: {
|
|
11
|
+
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
12
|
+
};
|
|
13
|
+
credentials: Credentials;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
8
16
|
namespace CaptureError {
|
|
9
17
|
interface Request {
|
|
10
18
|
data: {
|
|
19
|
+
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
11
20
|
error: Error | string;
|
|
12
21
|
};
|
|
13
22
|
credentials: Credentials;
|
|
@@ -15,6 +24,7 @@ export declare namespace ElasticAPM {
|
|
|
15
24
|
}
|
|
16
25
|
}
|
|
17
26
|
export interface IElasticAPMService {
|
|
18
|
-
|
|
27
|
+
init(req: ElasticAPM.Init.Request): void;
|
|
28
|
+
captureError(req: ElasticAPM.CaptureError.Request): void;
|
|
19
29
|
}
|
|
20
30
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
2
2
|
declare class ElasticAPMService implements IElasticAPMService {
|
|
3
|
-
|
|
3
|
+
private self;
|
|
4
|
+
init({ credentials, data }: ElasticAPM.Init.Request): void;
|
|
5
|
+
captureError({ data, credentials }: ElasticAPM.CaptureError.Request): void;
|
|
4
6
|
}
|
|
5
7
|
declare const _default: ElasticAPMService;
|
|
6
8
|
export default _default;
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
|
|
7
|
+
const utils_1 = require("../utils");
|
|
3
8
|
class ElasticAPMService {
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
self = null;
|
|
10
|
+
init({ credentials, data }) {
|
|
11
|
+
this.self = elastic_apm_node_1.default.start({
|
|
12
|
+
serviceName: credentials.service,
|
|
13
|
+
serverUrl: credentials.server,
|
|
14
|
+
environment: credentials.environment,
|
|
15
|
+
secretToken: credentials.secretToken,
|
|
16
|
+
captureBody: 'all',
|
|
17
|
+
logLevel: data.type ?? 'off',
|
|
18
|
+
active: true,
|
|
19
|
+
verifyServerCert: false,
|
|
20
|
+
ignoreUrls: ['/docs', '/health'],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
captureError({ data, credentials }) {
|
|
24
|
+
if (!this.self) {
|
|
25
|
+
this.init({ credentials, data: { type: data.type } });
|
|
26
|
+
}
|
|
27
|
+
this.self.captureError((0, utils_1.safeStringify)(data.error));
|
|
6
28
|
}
|
|
7
29
|
}
|
|
8
30
|
exports.default = new ElasticAPMService();
|
package/dist/services/i18n.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I18n, II18nService } from '../interfaces';
|
|
2
2
|
declare class I18nService implements II18nService {
|
|
3
|
-
private
|
|
3
|
+
private self;
|
|
4
4
|
constructor();
|
|
5
5
|
init({ data }: I18n.Init.Request): void;
|
|
6
6
|
translate({ data, config }: I18n.Translate.Request): I18n.Translate.Response;
|
package/dist/services/i18n.js
CHANGED
|
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const i18next_1 = __importDefault(require("i18next"));
|
|
7
7
|
class I18nService {
|
|
8
|
-
|
|
8
|
+
self = false;
|
|
9
9
|
constructor() { }
|
|
10
10
|
init({ data }) {
|
|
11
|
-
if (this.
|
|
11
|
+
if (this.self)
|
|
12
12
|
return;
|
|
13
13
|
i18next_1.default.init({
|
|
14
14
|
fallbackLng: data.defaultLocale ?? 'pt-BR',
|
|
@@ -17,10 +17,10 @@ class I18nService {
|
|
|
17
17
|
initAsync: false,
|
|
18
18
|
supportedLngs: data.supportedLocales ?? ['en-US', 'pt-BR'],
|
|
19
19
|
});
|
|
20
|
-
this.
|
|
20
|
+
this.self = true;
|
|
21
21
|
}
|
|
22
22
|
translate({ data, config }) {
|
|
23
|
-
if (!this.
|
|
23
|
+
if (!this.self) {
|
|
24
24
|
this.init({ data: config });
|
|
25
25
|
}
|
|
26
26
|
const message = i18next_1.default.t(data.key, {
|
package/package.json
CHANGED
|
@@ -6,9 +6,19 @@ interface Credentials {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export namespace ElasticAPM {
|
|
9
|
+
export namespace Init {
|
|
10
|
+
export interface Request {
|
|
11
|
+
data: {
|
|
12
|
+
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
13
|
+
};
|
|
14
|
+
credentials: Credentials;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
export namespace CaptureError {
|
|
10
19
|
export interface Request {
|
|
11
20
|
data: {
|
|
21
|
+
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
12
22
|
error: Error | string;
|
|
13
23
|
};
|
|
14
24
|
credentials: Credentials;
|
|
@@ -17,5 +27,6 @@ export namespace ElasticAPM {
|
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
export interface IElasticAPMService {
|
|
20
|
-
|
|
30
|
+
init (req: ElasticAPM.Init.Request): void;
|
|
31
|
+
captureError (req: ElasticAPM.CaptureError.Request): void;
|
|
21
32
|
}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
+
import APM from 'elastic-apm-node';
|
|
2
|
+
|
|
1
3
|
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
4
|
+
import { safeStringify } from '../utils';
|
|
2
5
|
|
|
3
6
|
class ElasticAPMService implements IElasticAPMService {
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
private self: typeof APM | null = null;
|
|
8
|
+
|
|
9
|
+
init ({ credentials, data }: ElasticAPM.Init.Request): void {
|
|
10
|
+
this.self = APM.start({
|
|
11
|
+
serviceName: credentials.service,
|
|
12
|
+
serverUrl: credentials.server,
|
|
13
|
+
environment: credentials.environment,
|
|
14
|
+
secretToken: credentials.secretToken,
|
|
15
|
+
captureBody: 'all',
|
|
16
|
+
logLevel: data.type ?? 'off',
|
|
17
|
+
active: true,
|
|
18
|
+
verifyServerCert: false,
|
|
19
|
+
ignoreUrls: [ '/docs', '/health' ],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
captureError ({ data, credentials }: ElasticAPM.CaptureError.Request): void {
|
|
24
|
+
if (!this.self) {
|
|
25
|
+
this.init({ credentials, data: { type: data.type } });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.self.captureError(
|
|
29
|
+
safeStringify(data.error)
|
|
30
|
+
);
|
|
6
31
|
}
|
|
7
32
|
}
|
|
8
33
|
|
package/src/services/i18n.ts
CHANGED
|
@@ -3,12 +3,12 @@ import I18Next from 'i18next';
|
|
|
3
3
|
import { I18n, II18nService } from '../interfaces';
|
|
4
4
|
|
|
5
5
|
class I18nService implements II18nService {
|
|
6
|
-
private
|
|
6
|
+
private self = false;
|
|
7
7
|
|
|
8
8
|
constructor () {}
|
|
9
9
|
|
|
10
10
|
init ({ data }: I18n.Init.Request): void {
|
|
11
|
-
if (this.
|
|
11
|
+
if (this.self) return;
|
|
12
12
|
|
|
13
13
|
I18Next.init({
|
|
14
14
|
fallbackLng: data.defaultLocale ?? 'pt-BR',
|
|
@@ -18,11 +18,11 @@ class I18nService implements II18nService {
|
|
|
18
18
|
supportedLngs: data.supportedLocales ?? [ 'en-US', 'pt-BR' ],
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
this.
|
|
21
|
+
this.self = true;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
translate ({ data, config }: I18n.Translate.Request): I18n.Translate.Response {
|
|
25
|
-
if (!this.
|
|
25
|
+
if (!this.self) {
|
|
26
26
|
this.init({ data: config });
|
|
27
27
|
}
|
|
28
28
|
|