mblabs-roccato-backend-commons 1.0.75 → 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.
@@ -1,8 +1,8 @@
1
- declare const STORAGE: {
1
+ declare const CONTEXT: {
2
2
  KEYS: {
3
3
  TRACE: string;
4
4
  SESSION: string;
5
5
  TENANT: string;
6
6
  };
7
7
  };
8
- export default STORAGE;
8
+ export default CONTEXT;
@@ -5,7 +5,7 @@ const KEYS = {
5
5
  SESSION: 'session',
6
6
  TENANT: 'tenant',
7
7
  };
8
- const STORAGE = {
8
+ const CONTEXT = {
9
9
  KEYS,
10
10
  };
11
- exports.default = STORAGE;
11
+ exports.default = CONTEXT;
@@ -1,4 +1,4 @@
1
+ import CONTEXT from './context';
1
2
  import DATE from './date';
2
3
  import LOCALES from './locales';
3
- import STORAGE from './storage';
4
- export { DATE, LOCALES, STORAGE, };
4
+ export { DATE, LOCALES, CONTEXT, };
@@ -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.STORAGE = exports.LOCALES = exports.DATE = void 0;
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;
@@ -0,0 +1,8 @@
1
+ export default class ContextService {
2
+ private static storage;
3
+ static init(): void;
4
+ static set<T>(key: string, value: T): void;
5
+ static get<T>(key: string): T | undefined;
6
+ static has(key: string): boolean;
7
+ static clear(): void;
8
+ }
@@ -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,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, };
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.75",
3
+ "version": "1.0.76",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,8 +4,8 @@ const KEYS = {
4
4
  TENANT: 'tenant',
5
5
  };
6
6
 
7
- const STORAGE = {
7
+ const CONTEXT = {
8
8
  KEYS,
9
9
  };
10
10
 
11
- export default STORAGE;
11
+ export default CONTEXT;
@@ -1,9 +1,9 @@
1
+ import CONTEXT from './context';
1
2
  import DATE from './date';
2
3
  import LOCALES from './locales';
3
- import STORAGE from './storage';
4
4
 
5
5
  export {
6
6
  DATE,
7
7
  LOCALES,
8
- STORAGE,
8
+ CONTEXT,
9
9
  };
@@ -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
+ }
@@ -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,