mblabs-roccato-backend-commons 1.0.74 → 1.0.76
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/constants/{storage.d.ts → context.d.ts} +2 -2
- package/dist/constants/{storage.js → context.js} +2 -2
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +3 -3
- package/dist/interfaces/elastic-apm.d.ts +1 -4
- package/dist/services/context.d.ts +8 -0
- package/dist/services/context.js +30 -0
- package/dist/services/elastic-apm.d.ts +2 -1
- package/dist/services/elastic-apm.js +6 -4
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +3 -1
- package/package.json +1 -1
- package/src/constants/{storage.ts → context.ts} +2 -2
- package/src/constants/index.ts +2 -2
- package/src/interfaces/elastic-apm.ts +1 -4
- package/src/services/context.ts +35 -0
- package/src/services/elastic-apm.ts +6 -4
- package/src/services/index.ts +2 -0
package/dist/constants/index.js
CHANGED
|
@@ -3,10 +3,10 @@ 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.
|
|
6
|
+
exports.CONTEXT = exports.LOCALES = exports.DATE = void 0;
|
|
7
|
+
const context_1 = __importDefault(require("./context"));
|
|
8
|
+
exports.CONTEXT = context_1.default;
|
|
7
9
|
const date_1 = __importDefault(require("./date"));
|
|
8
10
|
exports.DATE = date_1.default;
|
|
9
11
|
const locales_1 = __importDefault(require("./locales"));
|
|
10
12
|
exports.LOCALES = locales_1.default;
|
|
11
|
-
const storage_1 = __importDefault(require("./storage"));
|
|
12
|
-
exports.STORAGE = storage_1.default;
|
|
@@ -7,16 +7,12 @@ interface Credentials {
|
|
|
7
7
|
export declare namespace ElasticAPM {
|
|
8
8
|
namespace Init {
|
|
9
9
|
interface Request {
|
|
10
|
-
data: {
|
|
11
|
-
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
12
|
-
};
|
|
13
10
|
credentials: Credentials;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
namespace CaptureError {
|
|
17
14
|
interface Request {
|
|
18
15
|
data: {
|
|
19
|
-
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
20
16
|
error: Error | string;
|
|
21
17
|
};
|
|
22
18
|
credentials: Credentials;
|
|
@@ -26,5 +22,6 @@ export declare namespace ElasticAPM {
|
|
|
26
22
|
export interface IElasticAPMService {
|
|
27
23
|
init(req: ElasticAPM.Init.Request): void;
|
|
28
24
|
captureError(req: ElasticAPM.CaptureError.Request): void;
|
|
25
|
+
shutdown(): Promise<void>;
|
|
29
26
|
}
|
|
30
27
|
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const async_hooks_1 = require("async_hooks");
|
|
4
|
+
class ContextService {
|
|
5
|
+
static storage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
static init() {
|
|
7
|
+
this.storage.enterWith(new Map());
|
|
8
|
+
}
|
|
9
|
+
static set(key, value) {
|
|
10
|
+
const store = this.storage.getStore();
|
|
11
|
+
if (store) {
|
|
12
|
+
store.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static get(key) {
|
|
16
|
+
const store = this.storage.getStore();
|
|
17
|
+
return store?.get(key);
|
|
18
|
+
}
|
|
19
|
+
static has(key) {
|
|
20
|
+
const store = this.storage.getStore();
|
|
21
|
+
return store?.has(key) ?? false;
|
|
22
|
+
}
|
|
23
|
+
static clear() {
|
|
24
|
+
const store = this.storage.getStore();
|
|
25
|
+
if (store) {
|
|
26
|
+
store.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = ContextService;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
2
2
|
declare class ElasticAPMService implements IElasticAPMService {
|
|
3
3
|
private self;
|
|
4
|
-
init({ credentials
|
|
4
|
+
init({ credentials }: ElasticAPM.Init.Request): void;
|
|
5
5
|
captureError({ data, credentials }: ElasticAPM.CaptureError.Request): void;
|
|
6
|
+
shutdown(): Promise<void>;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: ElasticAPMService;
|
|
8
9
|
export default _default;
|
|
@@ -7,14 +7,12 @@ const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
|
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
class ElasticAPMService {
|
|
9
9
|
self = null;
|
|
10
|
-
init({ credentials
|
|
10
|
+
init({ credentials }) {
|
|
11
11
|
this.self = elastic_apm_node_1.default.start({
|
|
12
12
|
serviceName: credentials.service,
|
|
13
13
|
serverUrl: credentials.server,
|
|
14
14
|
environment: credentials.environment,
|
|
15
15
|
secretToken: credentials.secretToken,
|
|
16
|
-
captureBody: 'all',
|
|
17
|
-
logLevel: data.type ?? 'off',
|
|
18
16
|
active: true,
|
|
19
17
|
verifyServerCert: false,
|
|
20
18
|
ignoreUrls: ['/docs', '/health'],
|
|
@@ -22,9 +20,13 @@ class ElasticAPMService {
|
|
|
22
20
|
}
|
|
23
21
|
captureError({ data, credentials }) {
|
|
24
22
|
if (!this.self) {
|
|
25
|
-
this.init({ credentials
|
|
23
|
+
this.init({ credentials });
|
|
26
24
|
}
|
|
27
25
|
this.self.captureError((0, utils_1.safeStringify)(data.error));
|
|
28
26
|
}
|
|
27
|
+
async shutdown() {
|
|
28
|
+
if (this.self)
|
|
29
|
+
await this.self.flush();
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
exports.default = new ElasticAPMService();
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService } from './aws';
|
|
2
2
|
import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
|
|
3
|
+
import ContextService from './context';
|
|
3
4
|
import DateService from './date';
|
|
4
5
|
import ElasticAPMService from './elastic-apm';
|
|
5
6
|
import FileService from './file';
|
|
@@ -13,4 +14,4 @@ import NodeMailerService from './nodemailer';
|
|
|
13
14
|
import RabbitMQService from './rabbit';
|
|
14
15
|
import RedisService from './redis';
|
|
15
16
|
import SendgridService from './sendgrid';
|
|
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, };
|
|
17
|
+
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, ContextService, 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.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;
|
|
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.ContextService = 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; } });
|
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "AzureCalendarService", { enumerable: true, get:
|
|
|
17
17
|
Object.defineProperty(exports, "AzureCommunicationService", { enumerable: true, get: function () { return azure_1.AzureCommunicationService; } });
|
|
18
18
|
Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get: function () { return azure_1.AzureKeyVaultService; } });
|
|
19
19
|
Object.defineProperty(exports, "AzureStorageBlobService", { enumerable: true, get: function () { return azure_1.AzureStorageBlobService; } });
|
|
20
|
+
const context_1 = __importDefault(require("./context"));
|
|
21
|
+
exports.ContextService = context_1.default;
|
|
20
22
|
const date_1 = __importDefault(require("./date"));
|
|
21
23
|
exports.DateService = date_1.default;
|
|
22
24
|
const elastic_apm_1 = __importDefault(require("./elastic-apm"));
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -8,9 +8,6 @@ interface Credentials {
|
|
|
8
8
|
export namespace ElasticAPM {
|
|
9
9
|
export namespace Init {
|
|
10
10
|
export interface Request {
|
|
11
|
-
data: {
|
|
12
|
-
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
13
|
-
};
|
|
14
11
|
credentials: Credentials;
|
|
15
12
|
}
|
|
16
13
|
}
|
|
@@ -18,7 +15,6 @@ export namespace ElasticAPM {
|
|
|
18
15
|
export namespace CaptureError {
|
|
19
16
|
export interface Request {
|
|
20
17
|
data: {
|
|
21
|
-
type?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | 'fatal' | 'critical' | 'off';
|
|
22
18
|
error: Error | string;
|
|
23
19
|
};
|
|
24
20
|
credentials: Credentials;
|
|
@@ -29,4 +25,5 @@ export namespace ElasticAPM {
|
|
|
29
25
|
export interface IElasticAPMService {
|
|
30
26
|
init (req: ElasticAPM.Init.Request): void;
|
|
31
27
|
captureError (req: ElasticAPM.CaptureError.Request): void;
|
|
28
|
+
shutdown (): Promise<void>;
|
|
32
29
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
|
|
3
|
+
export default class ContextService {
|
|
4
|
+
private static storage = new AsyncLocalStorage<Map<string, unknown>>();
|
|
5
|
+
|
|
6
|
+
public static init () {
|
|
7
|
+
this.storage.enterWith(new Map());
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static set<T> (key: string, value: T): void {
|
|
11
|
+
const store = this.storage.getStore();
|
|
12
|
+
|
|
13
|
+
if (store) {
|
|
14
|
+
store.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static get<T> (key: string): T | undefined {
|
|
19
|
+
const store = this.storage.getStore();
|
|
20
|
+
return store?.get(key) as T | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static has (key: string): boolean {
|
|
24
|
+
const store = this.storage.getStore();
|
|
25
|
+
return store?.has(key) ?? false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static clear (): void {
|
|
29
|
+
const store = this.storage.getStore();
|
|
30
|
+
|
|
31
|
+
if (store) {
|
|
32
|
+
store.clear();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -6,14 +6,12 @@ import { safeStringify } from '../utils';
|
|
|
6
6
|
class ElasticAPMService implements IElasticAPMService {
|
|
7
7
|
private self: typeof APM | null = null;
|
|
8
8
|
|
|
9
|
-
init ({ credentials
|
|
9
|
+
init ({ credentials }: ElasticAPM.Init.Request): void {
|
|
10
10
|
this.self = APM.start({
|
|
11
11
|
serviceName: credentials.service,
|
|
12
12
|
serverUrl: credentials.server,
|
|
13
13
|
environment: credentials.environment,
|
|
14
14
|
secretToken: credentials.secretToken,
|
|
15
|
-
captureBody: 'all',
|
|
16
|
-
logLevel: data.type ?? 'off',
|
|
17
15
|
active: true,
|
|
18
16
|
verifyServerCert: false,
|
|
19
17
|
ignoreUrls: [ '/docs', '/health' ],
|
|
@@ -22,13 +20,17 @@ class ElasticAPMService implements IElasticAPMService {
|
|
|
22
20
|
|
|
23
21
|
captureError ({ data, credentials }: ElasticAPM.CaptureError.Request): void {
|
|
24
22
|
if (!this.self) {
|
|
25
|
-
this.init({ credentials
|
|
23
|
+
this.init({ credentials });
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
this.self.captureError(
|
|
29
27
|
safeStringify(data.error)
|
|
30
28
|
);
|
|
31
29
|
}
|
|
30
|
+
|
|
31
|
+
async shutdown () {
|
|
32
|
+
if (this.self) await this.self.flush();
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export default new ElasticAPMService();
|
package/src/services/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
AzureKeyVaultService,
|
|
14
14
|
AzureStorageBlobService,
|
|
15
15
|
} from './azure';
|
|
16
|
+
import ContextService from './context';
|
|
16
17
|
import DateService from './date';
|
|
17
18
|
import ElasticAPMService from './elastic-apm';
|
|
18
19
|
import FileService from './file';
|
|
@@ -46,6 +47,7 @@ export {
|
|
|
46
47
|
AzureCommunicationService,
|
|
47
48
|
AzureKeyVaultService,
|
|
48
49
|
AzureStorageBlobService,
|
|
50
|
+
ContextService,
|
|
49
51
|
DateService,
|
|
50
52
|
ElasticAPMService,
|
|
51
53
|
FileService,
|