@platform-x/hep-push-notification-client 1.0.5 → 1.0.7

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.
@@ -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
+ }
@@ -1,38 +1,58 @@
1
1
  "use strict";
2
- // import { secretManager } from 'hep-secret-access';
3
- // import { DynamicValues } from '../../platform-x/constants';
4
- // import config from '../../config';
5
- // export class SecretKeyServices {
6
- // private ruleCache = new Map<string, any | null>();
7
- // /**
8
- // * Fetches all the secret keys
9
- // */
10
- // public async getSecretKeys() {
11
- // try {
12
- // // Initialize secret manager object
13
- // if (this.ruleCache.has('secret_data')) {
14
- // return this.ruleCache.get('secret_data')!;
15
- // }
16
- // const secretObject = secretManager();
17
- // // If secret mode is ENV – read one by one
18
- // // for local testing
19
- // if (config?.SECRET_MODE === 'env') {
20
- // const keyConfig: Record<any, any> = {};
21
- // for (const key of Object.values(DynamicValues)) {
22
- // // Fetch individual value (existing read() method)
23
- // const value = await secretObject.read(key);
24
- // keyConfig[key] = value;
25
- // }
26
- // this.ruleCache.set('secret_data', keyConfig);
27
- // return keyConfig;
28
- // }
29
- // // else fetch all secrets from GSM
30
- // const data = await secretObject.readAllSecrets();
31
- // this.ruleCache.set('secret_data', data);
32
- // return data;
33
- // } catch (err) {
34
- // return {};
35
- // }
36
- // }
37
- // }
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;
38
58
  //# sourceMappingURL=secretKeyManager.js.map
package/dist/src/index.js CHANGED
@@ -21,7 +21,7 @@ exports.getPushNotificationSecrets = getPushNotificationSecrets;
21
21
  // export const testval = async () => {
22
22
  // let id: any = new pushNotificationManager();
23
23
  // // // .iamAuthenticator('kiwi', false);
24
- // let client = await id.pushNotificationProvider('kiwi');
24
+ // let client = await id.pushNotificationProvider({sitename:"kiwi", provider: "fcm"});
25
25
  // // // getuserdetails
26
26
  // let validate: any = await client.sendNotificationsToTopics(['articles'], {
27
27
  // title: 'Test Title',
@@ -30,6 +30,12 @@ exports.getPushNotificationSecrets = getPushNotificationSecrets;
30
30
  // }
31
31
  // );
32
32
  // console.log('>>>>>>>>>>>>>idd>>>>', validate)
33
+ // let id: any = new pushNotificationManager();
34
+ // // // .iamAuthenticator('kiwi', false);
35
+ // let client = await id.pushNotificationProvider({sitename:"kiwi", provider: "fcm"});
36
+ // // // getuserdetails
37
+ // let validate: any = await client.fetchTopics();
38
+ // console.log('>>>>>>>>>>>>>idd>>>>', validate)
33
39
  // }
34
40
  // testval()
35
41
  //# sourceMappingURL=index.js.map
@@ -7,7 +7,7 @@ export declare class FcmClient implements PushNotifyProvider {
7
7
  sendPushNotification(token: string, notificationMessage: any): Promise<any>;
8
8
  sendChunkedPushNotification(tokens: string[], notificationMessage: string): Promise<unknown>;
9
9
  chunkTokens(tokens: string[], chunkSize: number): Promise<any>;
10
- fetchTopics(): Promise<any>;
10
+ fetchTopics(isArrayRes?: boolean): Promise<any>;
11
11
  /**
12
12
  * Method to send notification based on topics
13
13
  * @param topics
@@ -49,7 +49,7 @@ class FcmClient {
49
49
  auth_provider_x509_cert_url: config_1.default.FCM.AUTH_PROVIDER_X509_CERT_URL,
50
50
  client_x509_cert_url: ((_e = yield (0, commonUtil_1.getDynamicSecretdata)(sitename, constants_1.PROVIDERS.FCM, constants_1.CONFIG_KEYS === null || constants_1.CONFIG_KEYS === void 0 ? void 0 : constants_1.CONFIG_KEYS.FIREBASECLIENTCERTURL)) !== null && _e !== void 0 ? _e : ''),
51
51
  universe_domain: config_1.default.FCM.UNIVERSE_DOMAIN,
52
- private_key: `-----BEGIN PRIVATE KEY-----\n${(yield (0, commonUtil_1.getDynamicSecretdata)(sitename, constants_1.PROVIDERS.FCM, constants_1.CONFIG_KEYS === null || constants_1.CONFIG_KEYS === void 0 ? void 0 : constants_1.CONFIG_KEYS.FIREBASEPRIVATEKEY))}\n-----END PRIVATE KEY-----\n`, // pragma: allowlist secret
52
+ private_key: `-----BEGIN PRIVATE KEY-----\n${(yield (0, commonUtil_1.getDynamicSecretdata)(sitename, constants_1.PROVIDERS.FCM, constants_1.CONFIG_KEYS === null || constants_1.CONFIG_KEYS === void 0 ? void 0 : constants_1.CONFIG_KEYS.FIREBASEPRIVATEKEY)).replace(/\\n/g, '\n')}\n-----END PRIVATE KEY-----\n`, // pragma: allowlist secret
53
53
  };
54
54
  logger_1.Logger.info('FCM-Client>FCMClient: FCM Client Credentials fetched', 'fcmClientObject');
55
55
  return new FcmClient(credentials);
@@ -129,7 +129,7 @@ class FcmClient {
129
129
  }
130
130
  });
131
131
  }
132
- fetchTopics() {
132
+ fetchTopics(isArrayRes) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
134
  try {
135
135
  const db = admin.firestore(); // Use Firestore// Firebase Realtime Database reference
@@ -140,7 +140,12 @@ class FcmClient {
140
140
  }
141
141
  const topics = [];
142
142
  snapshot.forEach((doc) => {
143
- topics.push({ name: doc.data().name }); // Assuming each topic has a 'name' field
143
+ if (isArrayRes) {
144
+ topics.push(doc.data().name); // Assuming each topic has a 'name' field
145
+ }
146
+ else {
147
+ topics.push({ name: doc.data().name }); // Assuming each topic has a 'name' field
148
+ }
144
149
  });
145
150
  return topics;
146
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platform-x/hep-push-notification-client",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "@platform-x/hep-push-notification-client",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",