@optimiser/common 1.0.356 → 1.0.358

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.
@@ -6,6 +6,7 @@ import { GlobalNotificationData } from "../modals/globalNotification.modal";
6
6
  export declare class Event {
7
7
  private sqs;
8
8
  private queueURL;
9
+ private FCMMobileServiceAccountKey;
9
10
  constructor(eventConfig: SQSConfig);
10
11
  /**
11
12
  * @param userId
package/dist/lib/event.js CHANGED
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -40,6 +59,7 @@ exports.Event = void 0;
40
59
  var aws_sdk_1 = require("aws-sdk");
41
60
  var uuid_1 = require("uuid");
42
61
  var mongodb_1 = require("mongodb");
62
+ var admin = __importStar(require("firebase-admin"));
43
63
  var Event = /** @class */ (function () {
44
64
  function Event(eventConfig) {
45
65
  var _this = this;
@@ -52,11 +72,12 @@ var Event = /** @class */ (function () {
52
72
  var _this = this;
53
73
  return __generator(this, function (_a) {
54
74
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
55
- var userObj, uniqueID, params;
75
+ var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
56
76
  return __generator(this, function (_a) {
57
77
  switch (_a.label) {
58
78
  case 0:
59
- if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 2];
79
+ if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 8];
80
+ notificationDataObj = data.PushNotificationObj;
60
81
  return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
61
82
  case 1:
62
83
  userObj = _a.sent();
@@ -67,8 +88,50 @@ var Event = /** @class */ (function () {
67
88
  else {
68
89
  delete data.PushNotificationObj;
69
90
  }
70
- _a.label = 2;
91
+ if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 7];
92
+ return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
71
93
  case 2:
94
+ userDeviceInfoObj = _a.sent();
95
+ if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 6];
96
+ message = {
97
+ token: userDeviceInfoObj.deviceToken,
98
+ notification: {
99
+ title: notificationDataObj.title,
100
+ body: notificationDataObj.message,
101
+ sound: 'default' // added by komal, default sound added for quit mode of app
102
+ },
103
+ android: {
104
+ priority: 'high' // You can set the priority to 'high' or 'normal' for Android
105
+ },
106
+ apns: {
107
+ payload: {
108
+ aps: {
109
+ contentAvailable: true // For iOS, setting contentAvailable to true makes the message a silent notification
110
+ }
111
+ }
112
+ },
113
+ data: {
114
+ title: notificationDataObj.title,
115
+ body: notificationDataObj.message
116
+ }
117
+ };
118
+ _a.label = 3;
119
+ case 3:
120
+ _a.trys.push([3, 5, , 6]);
121
+ return [4 /*yield*/, admin.messaging().send(message)];
122
+ case 4:
123
+ response = _a.sent();
124
+ console.log('Successfully sent FCM notify(Mobile) message:', response);
125
+ return [3 /*break*/, 6];
126
+ case 5:
127
+ error_1 = _a.sent();
128
+ console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
129
+ return [3 /*break*/, 6];
130
+ case 6: return [3 /*break*/, 8];
131
+ case 7:
132
+ console.log('Not able to INITIALISE THE FIREBASE ADMIN APP--');
133
+ _a.label = 8;
134
+ case 8:
72
135
  // if (userId && data.SocketObj && !data.SocketObj.userId) {
73
136
  //QPC-7064, Ankush changes added
74
137
  if (userId && data.SocketObj && data.SocketObj.userId != userId) {
@@ -165,6 +228,15 @@ var Event = /** @class */ (function () {
165
228
  accessKeyId: eventConfig.SQS_ACCESSKEY_ID,
166
229
  secretAccessKey: eventConfig.SQS_SECRET_KEY
167
230
  });
231
+ this.FCMMobileServiceAccountKey = eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY;
232
+ try {
233
+ admin.initializeApp({
234
+ credential: admin.credential.cert(this.FCMMobileServiceAccountKey)
235
+ });
236
+ }
237
+ catch (error) {
238
+ console.log('Error while INITIALIZING FIREBASE ADMIN APP\n Please check service-accountKey.JSON file.\n This will impact mobile app notifications -----', error);
239
+ }
168
240
  }
169
241
  return Event;
170
242
  }());
@@ -4,4 +4,5 @@ export interface SQSConfig {
4
4
  SQS_REGION: string;
5
5
  SQS_ACCESSKEY_ID: string;
6
6
  SQS_SECRET_KEY: string;
7
+ FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY: string;
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.356",
3
+ "version": "1.0.358",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,6 +25,7 @@
25
25
  "exceljs": "^4.3.0",
26
26
  "express": "^4.17.1",
27
27
  "express-validator": "^6.9.2",
28
+ "firebase-admin": "^12.0.0",
28
29
  "geoip-lite": "^1.4.2",
29
30
  "google-libphonenumber": "^3.2.30",
30
31
  "ioredis": "^4.17.3",