mblabs-roccato-backend-commons 1.0.71 → 1.0.73
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 +30 -0
- package/dist/interfaces/elastic-apm.js +2 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/services/elastic-apm.d.ts +8 -0
- package/dist/services/elastic-apm.js +29 -0
- package/dist/services/i18n.d.ts +1 -1
- package/dist/services/i18n.js +4 -4
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +3 -1
- package/package.json +1 -1
- package/src/interfaces/elastic-apm.ts +32 -0
- package/src/interfaces/index.ts +1 -0
- package/src/services/elastic-apm.ts +33 -0
- package/src/services/i18n.ts +4 -4
- package/src/services/index.ts +2 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface Credentials {
|
|
2
|
+
service: string;
|
|
3
|
+
server: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
secretToken: string;
|
|
6
|
+
}
|
|
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
|
+
}
|
|
16
|
+
namespace CaptureError {
|
|
17
|
+
interface Request {
|
|
18
|
+
data: {
|
|
19
|
+
type: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
20
|
+
error: Error | string;
|
|
21
|
+
};
|
|
22
|
+
credentials: Credentials;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export interface IElasticAPMService {
|
|
27
|
+
init(req: ElasticAPM.Init.Request): void;
|
|
28
|
+
captureError(req: ElasticAPM.CaptureError.Request): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/dist/interfaces/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./aws"), exports);
|
|
18
18
|
__exportStar(require("./azure"), exports);
|
|
19
|
+
__exportStar(require("./elastic-apm"), exports);
|
|
19
20
|
__exportStar(require("./firebase"), exports);
|
|
20
21
|
__exportStar(require("./gcp"), exports);
|
|
21
22
|
__exportStar(require("./grafana"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
2
|
+
declare class ElasticAPMService implements IElasticAPMService {
|
|
3
|
+
private self;
|
|
4
|
+
init({ credentials, data }: ElasticAPM.Init.Request): void;
|
|
5
|
+
captureError({ data, credentials }: ElasticAPM.CaptureError.Request): void;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: ElasticAPMService;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
class ElasticAPMService {
|
|
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,
|
|
18
|
+
active: true,
|
|
19
|
+
verifyServerCert: false,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
captureError({ data, credentials }) {
|
|
23
|
+
if (!this.self) {
|
|
24
|
+
this.init({ credentials, data: { type: data.type } });
|
|
25
|
+
}
|
|
26
|
+
this.self.captureError((0, utils_1.safeStringify)(data.error));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
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/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService } from './aws';
|
|
2
2
|
import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
|
|
3
3
|
import DateService from './date';
|
|
4
|
+
import ElasticAPMService from './elastic-apm';
|
|
4
5
|
import FileService from './file';
|
|
5
6
|
import FirebaseService from './firebase';
|
|
6
7
|
import { GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService } from './gcp';
|
|
@@ -12,4 +13,4 @@ import NodeMailerService from './nodemailer';
|
|
|
12
13
|
import RabbitMQService from './rabbit';
|
|
13
14
|
import RedisService from './redis';
|
|
14
15
|
import SendgridService from './sendgrid';
|
|
15
|
-
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
|
16
|
+
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, ElasticAPMService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
package/dist/services/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
6
|
+
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.ElasticAPMService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
7
7
|
const aws_1 = require("./aws");
|
|
8
8
|
Object.defineProperty(exports, "AmazonCloudwatchService", { enumerable: true, get: function () { return aws_1.AmazonCloudwatchService; } });
|
|
9
9
|
Object.defineProperty(exports, "AmazonPinpointService", { enumerable: true, get: function () { return aws_1.AmazonPinpointService; } });
|
|
@@ -19,6 +19,8 @@ Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get:
|
|
|
19
19
|
Object.defineProperty(exports, "AzureStorageBlobService", { enumerable: true, get: function () { return azure_1.AzureStorageBlobService; } });
|
|
20
20
|
const date_1 = __importDefault(require("./date"));
|
|
21
21
|
exports.DateService = date_1.default;
|
|
22
|
+
const elastic_apm_1 = __importDefault(require("./elastic-apm"));
|
|
23
|
+
exports.ElasticAPMService = elastic_apm_1.default;
|
|
22
24
|
const file_1 = __importDefault(require("./file"));
|
|
23
25
|
exports.FileService = file_1.default;
|
|
24
26
|
const firebase_1 = __importDefault(require("./firebase"));
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface Credentials {
|
|
2
|
+
service: string;
|
|
3
|
+
server: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
secretToken: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
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
|
+
|
|
18
|
+
export namespace CaptureError {
|
|
19
|
+
export interface Request {
|
|
20
|
+
data: {
|
|
21
|
+
type: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
22
|
+
error: Error | string;
|
|
23
|
+
};
|
|
24
|
+
credentials: Credentials;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IElasticAPMService {
|
|
30
|
+
init (req: ElasticAPM.Init.Request): void;
|
|
31
|
+
captureError (req: ElasticAPM.CaptureError.Request): void;
|
|
32
|
+
}
|
package/src/interfaces/index.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import APM from 'elastic-apm-node';
|
|
2
|
+
|
|
3
|
+
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
4
|
+
import { safeStringify } from '../utils';
|
|
5
|
+
|
|
6
|
+
class ElasticAPMService implements IElasticAPMService {
|
|
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,
|
|
17
|
+
active: true,
|
|
18
|
+
verifyServerCert: false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
captureError ({ data, credentials }: ElasticAPM.CaptureError.Request): void {
|
|
23
|
+
if (!this.self) {
|
|
24
|
+
this.init({ credentials, data: { type: data.type } });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.self.captureError(
|
|
28
|
+
safeStringify(data.error)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default new ElasticAPMService();
|
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
|
|
package/src/services/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
AzureStorageBlobService,
|
|
15
15
|
} from './azure';
|
|
16
16
|
import DateService from './date';
|
|
17
|
+
import ElasticAPMService from './elastic-apm';
|
|
17
18
|
import FileService from './file';
|
|
18
19
|
import FirebaseService from './firebase';
|
|
19
20
|
import {
|
|
@@ -46,6 +47,7 @@ export {
|
|
|
46
47
|
AzureKeyVaultService,
|
|
47
48
|
AzureStorageBlobService,
|
|
48
49
|
DateService,
|
|
50
|
+
ElasticAPMService,
|
|
49
51
|
FileService,
|
|
50
52
|
FirebaseService,
|
|
51
53
|
GoogleAuthService,
|