@platform-x/hep-push-notification-client 1.0.0

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.
Files changed (34) hide show
  1. package/README.md +10 -0
  2. package/dist/src/PushNotificationManager.d.ts +9 -0
  3. package/dist/src/PushNotificationManager.js +56 -0
  4. package/dist/src/common/util/commonUtil.d.ts +6 -0
  5. package/dist/src/common/util/commonUtil.js +43 -0
  6. package/dist/src/common/util/errorHandler.d.ts +41 -0
  7. package/dist/src/common/util/errorHandler.js +81 -0
  8. package/dist/src/common/util/logger.d.ts +68 -0
  9. package/dist/src/common/util/logger.js +193 -0
  10. package/dist/src/common/util/requestTracer.d.ts +2 -0
  11. package/dist/src/common/util/requestTracer.js +17 -0
  12. package/dist/src/common/util/secretKeyManager.d.ts +7 -0
  13. package/dist/src/common/util/secretKeyManager.js +58 -0
  14. package/dist/src/config/index.d.ts +22 -0
  15. package/dist/src/config/index.js +32 -0
  16. package/dist/src/index.d.ts +4 -0
  17. package/dist/src/index.js +34 -0
  18. package/dist/src/platform-x/constants/index.d.ts +41 -0
  19. package/dist/src/platform-x/constants/index.js +45 -0
  20. package/dist/src/platform-x/database/connection.d.ts +8 -0
  21. package/dist/src/platform-x/database/connection.js +54 -0
  22. package/dist/src/platform-x/database/dao/site_domain.dao.d.ts +10 -0
  23. package/dist/src/platform-x/database/dao/site_domain.dao.js +45 -0
  24. package/dist/src/platform-x/database/index.d.ts +14 -0
  25. package/dist/src/platform-x/database/index.js +10 -0
  26. package/dist/src/platform-x/database/interfaces/site_domain.interface.d.ts +33 -0
  27. package/dist/src/platform-x/database/interfaces/site_domain.interface.js +3 -0
  28. package/dist/src/platform-x/database/models/site_domain.model.d.ts +9 -0
  29. package/dist/src/platform-x/database/models/site_domain.model.js +48 -0
  30. package/dist/src/platform-x/interface/interface.d.ts +4 -0
  31. package/dist/src/platform-x/interface/interface.js +3 -0
  32. package/dist/src/platform-x/services/fcmservices.d.ts +18 -0
  33. package/dist/src/platform-x/services/fcmservices.js +188 -0
  34. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ #@platform-x/hep-push-notification-client
2
+ Provide module to push notifications to the users.
3
+
4
+ How to install and use
5
+
6
+ npm install @platform-x/hep-push-notification-client
7
+
8
+ import the modules and implement.
9
+ const fcmClient: any = new pushNotificationProvider(sitename);
10
+ await fcmClient.fetchTopics(type);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Push Notification Manager - supports multiple providers
3
+ * Currently implemented: FCM
4
+ * Future providers: SAP_EMARSYS
5
+ */
6
+ export declare class pushNotificationManager {
7
+ private notificationProvider;
8
+ pushNotificationProvider(sitename: string): Promise<any>;
9
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.pushNotificationManager = void 0;
16
+ const logger_1 = require("./common/util/logger");
17
+ const constants_1 = require("./platform-x/constants");
18
+ const fcmservices_1 = require("./platform-x/services/fcmservices");
19
+ const site_domain_dao_1 = __importDefault(require("./platform-x/database/dao/site_domain.dao"));
20
+ /**
21
+ * Push Notification Manager - supports multiple providers
22
+ * Currently implemented: FCM
23
+ * Future providers: SAP_EMARSYS
24
+ */
25
+ class pushNotificationManager {
26
+ pushNotificationProvider(sitename) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ var _a, _b, _c;
29
+ try {
30
+ logger_1.Logger.info('pushNotificationManager: Reached pushNotificationProvider', 'pushNotificationProvider');
31
+ let pushConfig = yield new site_domain_dao_1.default().details({ sitename });
32
+ let pushNotifyProvider = (_c = (_b = (_a = pushConfig === null || pushConfig === void 0 ? void 0 : pushConfig.providers) === null || _a === void 0 ? void 0 : _a.notification) === null || _b === void 0 ? void 0 : _b.active) !== null && _c !== void 0 ? _c : constants_1.PROVIDERS.FCM;
33
+ logger_1.Logger.info(`pushNotificationManager: Initializing the provider for client ${sitename}`, '');
34
+ switch (pushNotifyProvider) {
35
+ case constants_1.PROVIDERS.FCM:
36
+ this.notificationProvider = yield fcmservices_1.FcmClient.fcmClientObject(sitename);
37
+ logger_1.Logger.info('pushNotificationManager: Initialized with FCM provider', 'constructor');
38
+ break;
39
+ case constants_1.PROVIDERS.SAP_EMARSYS:
40
+ // Implement the SAP emarsys client initialization here
41
+ logger_1.Logger.info('pushNotificationManager: Initialized with SAP_EMARSYS provider', 'constructor');
42
+ break;
43
+ default:
44
+ throw new Error(`Unsupported provider: ${pushNotifyProvider}. Supported providers: ${Object.values(constants_1.PROVIDERS).join(', ')}`);
45
+ }
46
+ return this.notificationProvider;
47
+ }
48
+ catch (err) {
49
+ logger_1.Logger.error('pushNotificationManager: Error in pushNotificationManager', 'pushNotificationManager', err);
50
+ throw err;
51
+ }
52
+ });
53
+ }
54
+ }
55
+ exports.pushNotificationManager = pushNotificationManager;
56
+ //# sourceMappingURL=PushNotificationManager.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * base64ToString - to convert base64 into string
3
+ * @param {string} toDecode- string base64 request
4
+ */
5
+ export declare const base64ToString: (toDecode: string) => string;
6
+ export declare function getDynamicSecretdata(sitename: any, providerName: any, secretKey: any): Promise<string>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.base64ToString = void 0;
13
+ exports.getDynamicSecretdata = getDynamicSecretdata;
14
+ const __1 = require("../..");
15
+ const constants_1 = require("../../platform-x/constants");
16
+ const logger_1 = require("./logger");
17
+ /**
18
+ * base64ToString - to convert base64 into string
19
+ * @param {string} toDecode- string base64 request
20
+ */
21
+ const base64ToString = (toDecode) => {
22
+ return Buffer.from(toDecode, 'base64').toString('ascii');
23
+ };
24
+ exports.base64ToString = base64ToString;
25
+ function getDynamicSecretdata(sitename, providerName, secretKey) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ logger_1.Logger.info(`commonUtils.ts : getDynamicSecretdata reached ${{ sitename, providerName, secretKey }}`, 'getDynamicSecretdata');
28
+ const secretValue = yield (0, __1.getPushNotificationSecrets)();
29
+ const defaultData = constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.DEFAULT;
30
+ const targetKey = `${sitename}_${providerName}_${secretKey}`.toUpperCase();
31
+ const fallbackKey = `${defaultData}_${providerName}_${secretKey}`.toUpperCase();
32
+ logger_1.Logger.info('Target Key: ', 'getDynamicSecretdata');
33
+ logger_1.Logger.info('Fallback Key: ', 'getDynamicSecretdata');
34
+ let finalValue = secretValue.hasOwnProperty(targetKey) ? secretValue[targetKey] : secretValue[fallbackKey];
35
+ if (!finalValue || finalValue == '') {
36
+ logger_1.Logger.info(`Target Key not found, using fallback key: ${fallbackKey}`, 'getDynamicSecretdata');
37
+ finalValue = secretValue[fallbackKey];
38
+ }
39
+ logger_1.Logger.info('Final Value fetched', 'getDynamicSecretdata');
40
+ return finalValue;
41
+ });
42
+ }
43
+ //# sourceMappingURL=commonUtil.js.map
@@ -0,0 +1,41 @@
1
+ export declare const enum HTTP_STATUS_CODE {
2
+ INTERNAL_SERVER_ERROR = 500
3
+ }
4
+ export declare const HTTP_STATUS_MAP: Map<number, string>;
5
+ export declare const enum HTTP_STATUS_TYPE {
6
+ INTERNAL_SERVER_ERROR = "Internal Server Error"
7
+ }
8
+ export declare class CommonErrorTemplate extends Error {
9
+ code: number;
10
+ type: string;
11
+ constructor(msg: string, code?: number);
12
+ toJSON(): {
13
+ code: number;
14
+ type: string;
15
+ message: string;
16
+ };
17
+ }
18
+ export declare class ApiError extends CommonErrorTemplate {
19
+ constructor(msg: string, code?: number);
20
+ }
21
+ export declare class CustomError {
22
+ code: number | undefined;
23
+ type: string | undefined;
24
+ message: string | undefined;
25
+ stack: string | undefined;
26
+ errorObj: Error | undefined | null;
27
+ constructor(errObj?: any, code?: number, type?: string, message?: string, stack?: string);
28
+ toJSON(): {
29
+ code: number | undefined;
30
+ type: string | undefined;
31
+ message: string | undefined;
32
+ };
33
+ }
34
+ /**
35
+ * errorMapper - to map error object to custom error
36
+ */
37
+ export declare const errorMapper: (err: any, statusCode?: number, type?: string) => any;
38
+ /**
39
+ * throwError - to throw custome error
40
+ */
41
+ export declare const throwError: (err: any, statusCode?: number, type?: string) => never;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwError = exports.errorMapper = exports.CustomError = exports.ApiError = exports.CommonErrorTemplate = exports.HTTP_STATUS_MAP = void 0;
4
+ exports.HTTP_STATUS_MAP = new Map([
5
+ [500, 'Internal Server Error']
6
+ ]);
7
+ class CommonErrorTemplate extends Error {
8
+ constructor(msg, code) {
9
+ super(msg);
10
+ this.code = code || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
11
+ this.type =
12
+ exports.HTTP_STATUS_MAP.get(this.code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
13
+ }
14
+ toJSON() {
15
+ return {
16
+ code: this.code,
17
+ type: this.type,
18
+ message: this.message,
19
+ };
20
+ }
21
+ }
22
+ exports.CommonErrorTemplate = CommonErrorTemplate;
23
+ class ApiError extends CommonErrorTemplate {
24
+ constructor(msg, code) {
25
+ super(msg, code);
26
+ this.name = 'ApiError';
27
+ Error.captureStackTrace(this, ApiError);
28
+ }
29
+ }
30
+ exports.ApiError = ApiError;
31
+ class CustomError {
32
+ constructor(errObj, code, type, message, stack) {
33
+ this.code = code;
34
+ this.type = type;
35
+ this.message = message;
36
+ this.stack = stack;
37
+ this.errorObj = errObj;
38
+ }
39
+ toJSON() {
40
+ // NOSONAR
41
+ return {
42
+ code: this.code,
43
+ type: this.type,
44
+ message: this.message,
45
+ };
46
+ }
47
+ }
48
+ exports.CustomError = CustomError;
49
+ /**
50
+ * errorMapper - to map error object to custom error
51
+ */
52
+ const errorMapper = (err, statusCode, type) => {
53
+ let error;
54
+ let customError;
55
+ let code = statusCode || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
56
+ let errorType = type || exports.HTTP_STATUS_MAP.get(code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
57
+ if (typeof err === 'string') {
58
+ error = new Error(err);
59
+ customError = new CustomError(null, code, errorType, error.message, error.stack);
60
+ return customError;
61
+ }
62
+ else if (err.stack &&
63
+ err.message &&
64
+ !(err instanceof CustomError) &&
65
+ !err.toJSON) {
66
+ customError = new CustomError(null, code, errorType, err.message, err.stack);
67
+ return customError;
68
+ }
69
+ else {
70
+ return err;
71
+ }
72
+ };
73
+ exports.errorMapper = errorMapper;
74
+ /**
75
+ * throwError - to throw custome error
76
+ */
77
+ const throwError = (err, statusCode, type) => {
78
+ throw (0, exports.errorMapper)(err, statusCode, type);
79
+ };
80
+ exports.throwError = throwError;
81
+ //# sourceMappingURL=errorHandler.js.map
@@ -0,0 +1,68 @@
1
+ export interface payLoadInterface {
2
+ statusCode?: number;
3
+ data?: any;
4
+ }
5
+ export interface LoggerInterface {
6
+ info(message: string, method: string): void;
7
+ warn(message: string, method: string, payload?: object): void;
8
+ error(message: string, method: string, payload?: object): void;
9
+ debug(message: string, method: string, payload?: object): void;
10
+ }
11
+ export declare class LoggerClass implements LoggerInterface {
12
+ private logger;
13
+ private infoLevel;
14
+ private debugLevel;
15
+ private errorLevel;
16
+ private warnLevel;
17
+ private blockedKeywords;
18
+ constructor();
19
+ /**
20
+ * It's written to handle JSON.circular error
21
+ * @param obj
22
+ * @returns
23
+ */
24
+ customstringify(obj: any): string;
25
+ /**
26
+ * for info log
27
+ * @param message
28
+ * @param payload
29
+ * @param method
30
+ * @returns
31
+ */
32
+ info(message: string, method: string): void;
33
+ /**
34
+ * for warn log
35
+ * @param message
36
+ * @param payload
37
+ * @param method
38
+ * @returns
39
+ */
40
+ warn(message: string, method: string, payload?: any): void;
41
+ /**
42
+ * for error log
43
+ * @param message
44
+ * @param payload
45
+ * @param method
46
+ * @returns
47
+ */
48
+ error(message: string, method: string, payload?: any): void;
49
+ /**
50
+ * for debug log
51
+ * @param message
52
+ * @param payload
53
+ * @param method
54
+ * @returns
55
+ */
56
+ debug(message: string, method: string, payload?: any): void;
57
+ /**
58
+ * to map log levels and handle from config
59
+ */
60
+ private mapLogLevels;
61
+ /**
62
+ * to sanitize logs from unwanted fields to be shown
63
+ * @param request
64
+ * @returns
65
+ */
66
+ private sanitizeLog;
67
+ }
68
+ export declare const Logger: LoggerClass;
@@ -0,0 +1,193 @@
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
+ exports.Logger = exports.LoggerClass = void 0;
7
+ const bunyan_1 = __importDefault(require("bunyan"));
8
+ const index_1 = __importDefault(require("../../config/index"));
9
+ const bunyan_format_1 = __importDefault(require("bunyan-format"));
10
+ const requestTracer_1 = require("./requestTracer");
11
+ class LoggerClass {
12
+ constructor() {
13
+ this.infoLevel = false;
14
+ this.debugLevel = false;
15
+ this.errorLevel = false;
16
+ this.warnLevel = false;
17
+ this.blockedKeywords = ['currentPassword', 'clientSecret', 'newPassword'];
18
+ this.mapLogLevels();
19
+ this.logger = bunyan_1.default.createLogger({
20
+ name: index_1.default.APP_NAME,
21
+ level: 'trace', // by default enabling all levels, controlled through env separately
22
+ stream: (0, bunyan_format_1.default)({
23
+ outputMode: index_1.default.NODE_ENV === 'development' ? 'short' : 'bunyan',
24
+ levelInString: true,
25
+ color: true,
26
+ }),
27
+ });
28
+ }
29
+ /**
30
+ * It's written to handle JSON.circular error
31
+ * @param obj
32
+ * @returns
33
+ */
34
+ customstringify(obj) {
35
+ let cache = [];
36
+ let str = JSON.stringify(obj, (key, value) => {
37
+ {
38
+ if (typeof value === 'object' && value !== null) {
39
+ if (cache.indexOf(value) !== -1) {
40
+ // Circular reference found, discard key
41
+ return;
42
+ }
43
+ // Store value in our collection
44
+ cache.push(value);
45
+ }
46
+ return value;
47
+ }
48
+ });
49
+ cache = null; // reset the cache
50
+ return str;
51
+ }
52
+ /**
53
+ * for info log
54
+ * @param message
55
+ * @param payload
56
+ * @param method
57
+ * @returns
58
+ */
59
+ info(message, method) {
60
+ if (!this.infoLevel) {
61
+ return;
62
+ }
63
+ let loggerParams = {
64
+ message,
65
+ method,
66
+ traceId: (0, requestTracer_1.getTraceId)(),
67
+ };
68
+ this.logger.info(` start ${JSON.stringify(loggerParams)} ==end`);
69
+ }
70
+ /**
71
+ * for warn log
72
+ * @param message
73
+ * @param payload
74
+ * @param method
75
+ * @returns
76
+ */
77
+ warn(message, method, payload) {
78
+ if (!this.warnLevel) {
79
+ return;
80
+ }
81
+ let loggerParams = {
82
+ message,
83
+ method,
84
+ traceId: (0, requestTracer_1.getTraceId)(),
85
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
86
+ };
87
+ let finalPayload = payload !== undefined ? payload : {};
88
+ this.logger.warn(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
89
+ }
90
+ /**
91
+ * for error log
92
+ * @param message
93
+ * @param payload
94
+ * @param method
95
+ * @returns
96
+ */
97
+ error(message, method, payload) {
98
+ if (!this.errorLevel) {
99
+ return;
100
+ }
101
+ if (payload instanceof Error) {
102
+ payload = {
103
+ message,
104
+ method,
105
+ traceId: (0, requestTracer_1.getTraceId)(),
106
+ stack: payload === null || payload === void 0 ? void 0 : payload.stack,
107
+ };
108
+ }
109
+ let loggerParams = {
110
+ message,
111
+ method,
112
+ traceId: (0, requestTracer_1.getTraceId)(),
113
+ spanId: (0, requestTracer_1.getSpanId)(),
114
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
115
+ };
116
+ let finalPayload = payload !== undefined ? payload : {};
117
+ this.logger.error(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
118
+ }
119
+ /**
120
+ * for debug log
121
+ * @param message
122
+ * @param payload
123
+ * @param method
124
+ * @returns
125
+ */
126
+ debug(message, method, payload) {
127
+ if (!this.debugLevel) {
128
+ return;
129
+ }
130
+ let loggerParams = {
131
+ message,
132
+ method,
133
+ traceId: (0, requestTracer_1.getTraceId)(),
134
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
135
+ };
136
+ let finalPayload = payload !== undefined ? payload : {};
137
+ this.logger.debug(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
138
+ }
139
+ /**
140
+ * to map log levels and handle from config
141
+ */
142
+ mapLogLevels() {
143
+ if (index_1.default.LOG_LEVELS.length) {
144
+ index_1.default.LOG_LEVELS.forEach((element) => {
145
+ const logLevel = element.trim();
146
+ if (logLevel === 'info') {
147
+ this.infoLevel = true;
148
+ }
149
+ else if (logLevel === 'debug') {
150
+ this.debugLevel = true;
151
+ }
152
+ else if (logLevel === 'error') {
153
+ this.errorLevel = true;
154
+ }
155
+ else if (logLevel === 'warn') {
156
+ this.warnLevel = true;
157
+ }
158
+ });
159
+ }
160
+ }
161
+ /**
162
+ * to sanitize logs from unwanted fields to be shown
163
+ * @param request
164
+ * @returns
165
+ */
166
+ sanitizeLog(request) {
167
+ try {
168
+ if (request) {
169
+ Object.keys(request).forEach((key) => {
170
+ let value = request[key];
171
+ if (request[key] === 'options') {
172
+ delete request.options;
173
+ }
174
+ else {
175
+ if (this.blockedKeywords.find((blockedKey) => key.toLowerCase() === blockedKey.toLowerCase())) {
176
+ request[key] = 'XXXXXXXXXX';
177
+ }
178
+ else {
179
+ request[key] = value;
180
+ }
181
+ }
182
+ });
183
+ return request;
184
+ }
185
+ }
186
+ catch (err) {
187
+ this.error('Logger sanitize error', err);
188
+ }
189
+ }
190
+ }
191
+ exports.LoggerClass = LoggerClass;
192
+ exports.Logger = new LoggerClass();
193
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,2 @@
1
+ export declare const getTraceId: () => any;
2
+ export declare const getSpanId: () => any;
@@ -0,0 +1,17 @@
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
+ exports.getSpanId = exports.getTraceId = void 0;
7
+ const cls_hooked_1 = __importDefault(require("cls-hooked"));
8
+ const uuid_1 = require("uuid");
9
+ const nsid = `rtracer:${(0, uuid_1.v4)()}`;
10
+ const ns = cls_hooked_1.default.createNamespace(nsid);
11
+ const traceIdKey = 'traceId';
12
+ const spanIdKey = 'spanId';
13
+ const getTraceId = () => ns.get(traceIdKey);
14
+ exports.getTraceId = getTraceId;
15
+ const getSpanId = () => ns.get(spanIdKey);
16
+ exports.getSpanId = getSpanId;
17
+ //# sourceMappingURL=requestTracer.js.map
@@ -0,0 +1,7 @@
1
+ export declare class SecretKeyServices {
2
+ private ruleCache;
3
+ /**
4
+ * Fetches all the secret keys
5
+ */
6
+ getSecretKeys(): Promise<any>;
7
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SecretKeyServices = void 0;
16
+ const hep_secret_access_1 = require("hep-secret-access");
17
+ const constants_1 = require("../../platform-x/constants");
18
+ const config_1 = __importDefault(require("../../config"));
19
+ class SecretKeyServices {
20
+ constructor() {
21
+ this.ruleCache = new Map();
22
+ }
23
+ /**
24
+ * Fetches all the secret keys
25
+ */
26
+ getSecretKeys() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ // Initialize secret manager object
30
+ if (this.ruleCache.has('secret_data')) {
31
+ return this.ruleCache.get('secret_data');
32
+ }
33
+ const secretObject = (0, hep_secret_access_1.secretManager)();
34
+ // If secret mode is ENV – read one by one
35
+ // for local testing
36
+ if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.SECRET_MODE) === 'env') {
37
+ const keyConfig = {};
38
+ for (const key of Object.values(constants_1.DynamicValues)) {
39
+ // Fetch individual value (existing read() method)
40
+ const value = yield secretObject.read(key);
41
+ keyConfig[key] = value;
42
+ }
43
+ this.ruleCache.set('secret_data', keyConfig);
44
+ return keyConfig;
45
+ }
46
+ // else – fetch all secrets from GSM
47
+ const data = yield secretObject.readAllSecrets();
48
+ this.ruleCache.set('secret_data', data);
49
+ return data;
50
+ }
51
+ catch (err) {
52
+ return {};
53
+ }
54
+ });
55
+ }
56
+ }
57
+ exports.SecretKeyServices = SecretKeyServices;
58
+ //# sourceMappingURL=secretKeyManager.js.map
@@ -0,0 +1,22 @@
1
+ declare const _default: {
2
+ LOG_LEVELS: string[];
3
+ APP_NAME: string;
4
+ NODE_ENV: string | undefined;
5
+ MONGO: {
6
+ HOST: string | undefined;
7
+ PORT: string | undefined;
8
+ DB_NAME: string | undefined;
9
+ USER: string | undefined;
10
+ PASS: string | undefined;
11
+ };
12
+ FCM: {
13
+ PROJECT: string | undefined;
14
+ TYPE: string | undefined;
15
+ AUTH_URI: string | undefined;
16
+ TOKEN_URI: string | undefined;
17
+ AUTH_PROVIDER_X509_CERT_URL: string | undefined;
18
+ UNIVERSE_DOMAIN: string | undefined;
19
+ };
20
+ SECRET_MODE: string;
21
+ };
22
+ export default _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const constants_1 = require("../platform-x/constants");
9
+ dotenv_1.default.config();
10
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
11
+ exports.default = {
12
+ LOG_LEVELS: ((_a = process.env.LOG_LEVELS) === null || _a === void 0 ? void 0 : _a.split(',')) || [],
13
+ APP_NAME: process.env.npm_package_name || constants_1.DEFAULT_APP_NAME,
14
+ NODE_ENV: process.env.NODE_ENV,
15
+ MONGO: {
16
+ HOST: process.env.MONGO_HOST,
17
+ PORT: process.env.MONGO_PORT,
18
+ DB_NAME: process.env.MONGO_DB,
19
+ USER: process.env.MONGO_USER,
20
+ PASS: process.env.MONGO_PASS,
21
+ },
22
+ FCM: {
23
+ PROJECT: process.env.FCM_PROJECT,
24
+ TYPE: process.env.FCM_TYPE,
25
+ AUTH_URI: process.env.FCM_AUTH_URI,
26
+ TOKEN_URI: process.env.FCM_TOKEN_URI,
27
+ AUTH_PROVIDER_X509_CERT_URL: process.env.FCM_AUTH_PROVIDER_X509_CERT_URL,
28
+ UNIVERSE_DOMAIN: process.env.FCM_UNIVERSE_DOMAIN,
29
+ },
30
+ SECRET_MODE: process.env.SECRET_MODE || 'gsm',
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import { pushNotificationManager } from "./PushNotificationManager";
2
+ export declare const initPushNotificationSecrets: (secretServiceIns: any) => void;
3
+ export declare const getPushNotificationSecrets: () => any;
4
+ export { pushNotificationManager };