@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.
- package/README.md +10 -0
- package/dist/src/PushNotificationManager.d.ts +9 -0
- package/dist/src/PushNotificationManager.js +56 -0
- package/dist/src/common/util/commonUtil.d.ts +6 -0
- package/dist/src/common/util/commonUtil.js +43 -0
- package/dist/src/common/util/errorHandler.d.ts +41 -0
- package/dist/src/common/util/errorHandler.js +81 -0
- package/dist/src/common/util/logger.d.ts +68 -0
- package/dist/src/common/util/logger.js +193 -0
- package/dist/src/common/util/requestTracer.d.ts +2 -0
- package/dist/src/common/util/requestTracer.js +17 -0
- package/dist/src/common/util/secretKeyManager.d.ts +7 -0
- package/dist/src/common/util/secretKeyManager.js +58 -0
- package/dist/src/config/index.d.ts +22 -0
- package/dist/src/config/index.js +32 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +34 -0
- package/dist/src/platform-x/constants/index.d.ts +41 -0
- package/dist/src/platform-x/constants/index.js +45 -0
- package/dist/src/platform-x/database/connection.d.ts +8 -0
- package/dist/src/platform-x/database/connection.js +54 -0
- package/dist/src/platform-x/database/dao/site_domain.dao.d.ts +10 -0
- package/dist/src/platform-x/database/dao/site_domain.dao.js +45 -0
- package/dist/src/platform-x/database/index.d.ts +14 -0
- package/dist/src/platform-x/database/index.js +10 -0
- package/dist/src/platform-x/database/interfaces/site_domain.interface.d.ts +33 -0
- package/dist/src/platform-x/database/interfaces/site_domain.interface.js +3 -0
- package/dist/src/platform-x/database/models/site_domain.model.d.ts +9 -0
- package/dist/src/platform-x/database/models/site_domain.model.js +48 -0
- package/dist/src/platform-x/interface/interface.d.ts +4 -0
- package/dist/src/platform-x/interface/interface.js +3 -0
- package/dist/src/platform-x/services/fcmservices.d.ts +18 -0
- package/dist/src/platform-x/services/fcmservices.js +188 -0
- package/package.json +51 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pushNotificationManager = exports.getPushNotificationSecrets = exports.initPushNotificationSecrets = void 0;
|
|
4
|
+
const PushNotificationManager_1 = require("./PushNotificationManager");
|
|
5
|
+
Object.defineProperty(exports, "pushNotificationManager", { enumerable: true, get: function () { return PushNotificationManager_1.pushNotificationManager; } });
|
|
6
|
+
let injectedSecretService;
|
|
7
|
+
const initPushNotificationSecrets = (secretServiceIns) => {
|
|
8
|
+
injectedSecretService = secretServiceIns;
|
|
9
|
+
};
|
|
10
|
+
exports.initPushNotificationSecrets = initPushNotificationSecrets;
|
|
11
|
+
const getPushNotificationSecrets = () => {
|
|
12
|
+
if (!injectedSecretService) {
|
|
13
|
+
throw new Error("Push Notification secrets not initialized");
|
|
14
|
+
}
|
|
15
|
+
return injectedSecretService.getSecretKeys(); // returns cached data
|
|
16
|
+
// return new SecretKeyServices().getSecretKeys(); // for localpackage test
|
|
17
|
+
};
|
|
18
|
+
exports.getPushNotificationSecrets = getPushNotificationSecrets;
|
|
19
|
+
// for testing
|
|
20
|
+
// export const testval = async () => {
|
|
21
|
+
// let id: any = new pushNotificationManager();
|
|
22
|
+
// // // .iamAuthenticator('kiwi', false);
|
|
23
|
+
// let client = await id.pushNotificationProvider('kiwi');
|
|
24
|
+
// // // getuserdetails
|
|
25
|
+
// let validate: any = await client.sendNotificationsToTopics(['articles'], {
|
|
26
|
+
// title: 'Test Title',
|
|
27
|
+
// body: 'Test Body',
|
|
28
|
+
// data: { key1: 'value1', key2: 'value2' }
|
|
29
|
+
// }
|
|
30
|
+
// );
|
|
31
|
+
// console.log('>>>>>>>>>>>>>idd>>>>', validate)
|
|
32
|
+
// }
|
|
33
|
+
// testval()
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** HTTP Request related constants */
|
|
2
|
+
export declare const HTTP_CONTENT_TYPE_JSON = "application/json";
|
|
3
|
+
export declare const TRACE_ID_HEADER_NAME = "Platform-X-Trace-Id";
|
|
4
|
+
export declare const DEFAULT_APP_PORT = 8080;
|
|
5
|
+
export declare const DEFAULT_APP_NAME = "api-gateway";
|
|
6
|
+
export declare const DEFAULT_REALM_NAME = "platform-x";
|
|
7
|
+
export declare const PROVIDERS: {
|
|
8
|
+
FCM: string;
|
|
9
|
+
SAP_EMARSYS: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const CONFIG_KEYS: {
|
|
12
|
+
FIREBASETYPE: string;
|
|
13
|
+
FIREBASEPROJECTID: string;
|
|
14
|
+
FIREBASEPRIVATEKEYID: string;
|
|
15
|
+
FIREBASEPRIVATEKEY: string;
|
|
16
|
+
FIREBASECLIENTEMAIL: string;
|
|
17
|
+
FIREBASECLIENTID: string;
|
|
18
|
+
FIREBASECLIENTCERTURL: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const DynamicValues: {
|
|
21
|
+
ANALYTICS_PASSWORD: string;
|
|
22
|
+
AUTH_TENANTS_INFO: string;
|
|
23
|
+
BRCMS_AUTH: string;
|
|
24
|
+
FCM_PRIVATE_KEY_ID: string;
|
|
25
|
+
FCM_PRIVATE_KEY: string;
|
|
26
|
+
FCM_CLIENT_EMAIL: string;
|
|
27
|
+
FCM_CLIENT_ID: string;
|
|
28
|
+
MONGO_PASS: string;
|
|
29
|
+
FCM_CLIENT_X509_CERT_URL: string;
|
|
30
|
+
DEFAULT: string;
|
|
31
|
+
Default_BRIGHTCOVE_userAccountId: string;
|
|
32
|
+
Default_BRIGHTCOVE_clientId: string;
|
|
33
|
+
Default_BRIGHTCOVE_clientSecret: string;
|
|
34
|
+
SECRETS_CRYPTO_KEY: string;
|
|
35
|
+
DEFAULT_FCM_FIREBASEPROJECTID: string;
|
|
36
|
+
DEFAULT_FCM_FIREBASEPRIVATEKEYID: string;
|
|
37
|
+
DEFAULT_FCM_FIREBASEPRIVATEKEY: string;
|
|
38
|
+
DEFAULT_FCM_FIREBASECLIENTEMAIL: string;
|
|
39
|
+
DEFAULT_FCM_FIREBASECLIENTID: string;
|
|
40
|
+
DEFAULT_FCM_FIREBASECLIENTCERTURL: string;
|
|
41
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicValues = exports.CONFIG_KEYS = exports.PROVIDERS = exports.DEFAULT_REALM_NAME = exports.DEFAULT_APP_NAME = exports.DEFAULT_APP_PORT = exports.TRACE_ID_HEADER_NAME = exports.HTTP_CONTENT_TYPE_JSON = void 0;
|
|
4
|
+
/** HTTP Request related constants */
|
|
5
|
+
exports.HTTP_CONTENT_TYPE_JSON = 'application/json';
|
|
6
|
+
exports.TRACE_ID_HEADER_NAME = 'Platform-X-Trace-Id';
|
|
7
|
+
exports.DEFAULT_APP_PORT = 8080;
|
|
8
|
+
exports.DEFAULT_APP_NAME = 'api-gateway';
|
|
9
|
+
exports.DEFAULT_REALM_NAME = 'platform-x';
|
|
10
|
+
exports.PROVIDERS = {
|
|
11
|
+
FCM: 'fcm',
|
|
12
|
+
SAP_EMARSYS: 'SAP_EMARSYS',
|
|
13
|
+
};
|
|
14
|
+
exports.CONFIG_KEYS = {
|
|
15
|
+
FIREBASETYPE: 'FIREBASETYPE',
|
|
16
|
+
FIREBASEPROJECTID: 'FIREBASEPROJECTID',
|
|
17
|
+
FIREBASEPRIVATEKEYID: 'FIREBASEPRIVATEKEYID',
|
|
18
|
+
FIREBASEPRIVATEKEY: 'FIREBASEPRIVATEKEY',
|
|
19
|
+
FIREBASECLIENTEMAIL: 'FIREBASECLIENTEMAIL',
|
|
20
|
+
FIREBASECLIENTID: 'FIREBASECLIENTID',
|
|
21
|
+
FIREBASECLIENTCERTURL: 'FIREBASECLIENTCERTURL'
|
|
22
|
+
};
|
|
23
|
+
exports.DynamicValues = {
|
|
24
|
+
ANALYTICS_PASSWORD: 'ANALYTICS_PASSWORD',
|
|
25
|
+
AUTH_TENANTS_INFO: 'AUTH_TENANTS_INFO',
|
|
26
|
+
BRCMS_AUTH: 'BRCMS_AUTH',
|
|
27
|
+
FCM_PRIVATE_KEY_ID: 'FCM_PRIVATE_KEY_ID',
|
|
28
|
+
FCM_PRIVATE_KEY: 'FCM_PRIVATE_KEY',
|
|
29
|
+
FCM_CLIENT_EMAIL: 'FCM_CLIENT_EMAIL',
|
|
30
|
+
FCM_CLIENT_ID: 'FCM_CLIENT_ID',
|
|
31
|
+
MONGO_PASS: 'MONGO_PASS',
|
|
32
|
+
FCM_CLIENT_X509_CERT_URL: 'FCM_CLIENT_X509_CERT_URL',
|
|
33
|
+
DEFAULT: 'Default',
|
|
34
|
+
Default_BRIGHTCOVE_userAccountId: 'Default_BRIGHTCOVE_userAccountId',
|
|
35
|
+
Default_BRIGHTCOVE_clientId: 'Default_BRIGHTCOVE_clientId',
|
|
36
|
+
Default_BRIGHTCOVE_clientSecret: 'Default_BRIGHTCOVE_clientSecret',
|
|
37
|
+
SECRETS_CRYPTO_KEY: 'SECRETS_CRYPTO_KEY',
|
|
38
|
+
DEFAULT_FCM_FIREBASEPROJECTID: 'DEFAULT_FCM_FIREBASEPROJECTID',
|
|
39
|
+
DEFAULT_FCM_FIREBASEPRIVATEKEYID: 'DEFAULT_FCM_FIREBASEPRIVATEKEYID',
|
|
40
|
+
DEFAULT_FCM_FIREBASEPRIVATEKEY: 'DEFAULT_FCM_FIREBASEPRIVATEKEY',
|
|
41
|
+
DEFAULT_FCM_FIREBASECLIENTEMAIL: 'DEFAULT_FCM_FIREBASECLIENTEMAIL',
|
|
42
|
+
DEFAULT_FCM_FIREBASECLIENTID: 'DEFAULT_FCM_FIREBASECLIENTID',
|
|
43
|
+
DEFAULT_FCM_FIREBASECLIENTCERTURL: 'DEFAULT_FCM_FIREBASECLIENTCERTURL',
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
16
|
+
const logger_1 = require("../../common/util/logger");
|
|
17
|
+
const index_1 = __importDefault(require("../../config/index"));
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const __1 = require("../..");
|
|
20
|
+
let database = mongoose_1.default.connection;
|
|
21
|
+
// Exit on error
|
|
22
|
+
mongoose_1.default.connection.on('error', (err) => {
|
|
23
|
+
logger_1.Logger.info(`MongoDB connection error: ${err}`, 'mongoose');
|
|
24
|
+
process.exit(-1);
|
|
25
|
+
});
|
|
26
|
+
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (database.readyState) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const secrets = yield (0, __1.getPushNotificationSecrets)();
|
|
31
|
+
mongoose_1.default.connect(`mongodb://${index_1.default.MONGO.USER}:${secrets === null || secrets === void 0 ? void 0 : secrets[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.MONGO_PASS]}@${index_1.default.MONGO.HOST}:${index_1.default.MONGO.PORT}/${index_1.default.MONGO.DB_NAME}?directConnection=true&authMechanism=DEFAULT&authSource=${index_1.default.MONGO.DB_NAME}`);
|
|
32
|
+
database = mongoose_1.default.connection;
|
|
33
|
+
database.once('open', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
logger_1.Logger.info(`[Server] connected to MongoDB`, 'connect');
|
|
35
|
+
}));
|
|
36
|
+
database.on('error', (err = {}) => {
|
|
37
|
+
logger_1.Logger.error(`[Server] error connecting to MongoDB`, 'connect', err);
|
|
38
|
+
process.exit(-1);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
const disconnect = () => {
|
|
42
|
+
if (!database) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
logger_1.Logger.info(`Disconnected to MongoDB`, 'disconnect');
|
|
46
|
+
mongoose_1.default.disconnect();
|
|
47
|
+
};
|
|
48
|
+
exports.default = {
|
|
49
|
+
database,
|
|
50
|
+
mongoose: mongoose_1.default,
|
|
51
|
+
connect,
|
|
52
|
+
disconnect,
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default class SiteDomainDao {
|
|
2
|
+
/**
|
|
3
|
+
* get domain details
|
|
4
|
+
* @param request
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
details(filter: any, condition?: any): Promise<(import("mongoose").Document<unknown, {}, import("../interfaces/site_domain.interface").SiteDomain> & Omit<import("../interfaces/site_domain.interface").SiteDomain & {
|
|
8
|
+
_id: import("mongoose").Types.ObjectId;
|
|
9
|
+
}, never>) | null>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const logger_1 = require("../../../common/util/logger");
|
|
16
|
+
const index_1 = __importDefault(require("../index"));
|
|
17
|
+
const { SiteDomainModel } = index_1.default;
|
|
18
|
+
class SiteDomainDao {
|
|
19
|
+
/**
|
|
20
|
+
* get domain details
|
|
21
|
+
* @param request
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
details(filter, condition) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
logger_1.Logger.info('SiteDomainDao: Reached details', 'details');
|
|
28
|
+
if (!filter || Object.keys(filter).length === 0) {
|
|
29
|
+
throw new Error('Condition for details cannot be empty');
|
|
30
|
+
}
|
|
31
|
+
if (condition) {
|
|
32
|
+
filter = Object.assign(Object.assign({}, condition), filter);
|
|
33
|
+
}
|
|
34
|
+
logger_1.Logger.debug('SiteDomainDao: details', 'details', filter);
|
|
35
|
+
return yield SiteDomainModel.findOne(filter).exec();
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
logger_1.Logger.error('SiteDomainDao: Error in details', 'details', err);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = SiteDomainDao;
|
|
45
|
+
//# sourceMappingURL=site_domain.dao.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const db: {
|
|
2
|
+
SiteDomainModel: import("mongoose").Model<import("./interfaces/site_domain.interface").SiteDomain, {}, {}, {}, import("mongoose").Document<unknown, {}, import("./interfaces/site_domain.interface").SiteDomain> & Omit<import("./interfaces/site_domain.interface").SiteDomain & {
|
|
3
|
+
_id: import("mongoose").Types.ObjectId;
|
|
4
|
+
}, never>, import("mongoose").Schema<import("./interfaces/site_domain.interface").SiteDomain, import("mongoose").Model<import("./interfaces/site_domain.interface").SiteDomain, any, any, any, import("mongoose").Document<unknown, any, import("./interfaces/site_domain.interface").SiteDomain> & Omit<import("./interfaces/site_domain.interface").SiteDomain & {
|
|
5
|
+
_id: import("mongoose").Types.ObjectId;
|
|
6
|
+
}, never>, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, import("./interfaces/site_domain.interface").SiteDomain, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<import("./interfaces/site_domain.interface").SiteDomain>> & Omit<import("mongoose").FlatRecord<import("./interfaces/site_domain.interface").SiteDomain> & {
|
|
7
|
+
_id: import("mongoose").Types.ObjectId;
|
|
8
|
+
}, never>>>;
|
|
9
|
+
database: import("mongoose").Connection;
|
|
10
|
+
mongoose: typeof import("mongoose");
|
|
11
|
+
connect: () => Promise<void>;
|
|
12
|
+
disconnect: () => void;
|
|
13
|
+
};
|
|
14
|
+
export default db;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
const connection_1 = __importDefault(require("./connection"));
|
|
7
|
+
const site_domain_model_1 = __importDefault(require("./models/site_domain.model"));
|
|
8
|
+
const db = Object.assign(Object.assign({}, connection_1.default), { SiteDomainModel: site_domain_model_1.default });
|
|
9
|
+
exports.default = db;
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface EmailTemplate {
|
|
2
|
+
default_email_template: string;
|
|
3
|
+
site_email_template: string;
|
|
4
|
+
}
|
|
5
|
+
type ProviderKeys = Record<string, {
|
|
6
|
+
name: string;
|
|
7
|
+
mask?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export interface ProviderConfig {
|
|
10
|
+
is_enabled?: boolean;
|
|
11
|
+
keys?: ProviderKeys;
|
|
12
|
+
}
|
|
13
|
+
export interface ProvidersByType {
|
|
14
|
+
[providerType: string]: {
|
|
15
|
+
active?: string;
|
|
16
|
+
[providerName: string]: ProviderConfig | string | boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface SiteDomain {
|
|
20
|
+
id?: string;
|
|
21
|
+
domain?: string;
|
|
22
|
+
sitename?: string;
|
|
23
|
+
olTenantId?: string;
|
|
24
|
+
olTenantName?: string;
|
|
25
|
+
staticSiteStatus: string;
|
|
26
|
+
isBackupRestored: boolean;
|
|
27
|
+
isStaticSiteBackup: boolean;
|
|
28
|
+
supportMail: string;
|
|
29
|
+
userInfo?: any;
|
|
30
|
+
emailTemplates?: EmailTemplate[];
|
|
31
|
+
providers?: ProvidersByType;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SiteDomain } from '../interfaces/site_domain.interface';
|
|
2
|
+
declare const _default: import("mongoose").Model<SiteDomain, {}, {}, {}, import("mongoose").Document<unknown, {}, SiteDomain> & Omit<SiteDomain & {
|
|
3
|
+
_id: import("mongoose").Types.ObjectId;
|
|
4
|
+
}, never>, import("mongoose").Schema<SiteDomain, import("mongoose").Model<SiteDomain, any, any, any, import("mongoose").Document<unknown, any, SiteDomain> & Omit<SiteDomain & {
|
|
5
|
+
_id: import("mongoose").Types.ObjectId;
|
|
6
|
+
}, never>, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, SiteDomain, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<SiteDomain>> & Omit<import("mongoose").FlatRecord<SiteDomain> & {
|
|
7
|
+
_id: import("mongoose").Types.ObjectId;
|
|
8
|
+
}, never>>>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const connection_1 = __importDefault(require("../connection"));
|
|
7
|
+
const { mongoose } = connection_1.default;
|
|
8
|
+
const { Schema, model } = mongoose;
|
|
9
|
+
const siteDomainSchema = new Schema({
|
|
10
|
+
id: Schema.Types.ObjectId,
|
|
11
|
+
domain: String,
|
|
12
|
+
sitename: String,
|
|
13
|
+
olTenantId: String,
|
|
14
|
+
olTenantName: String,
|
|
15
|
+
userInfo: {
|
|
16
|
+
type: Schema.Types.Mixed,
|
|
17
|
+
default: {},
|
|
18
|
+
},
|
|
19
|
+
staticSiteStatus: {
|
|
20
|
+
type: String,
|
|
21
|
+
enum: ['NOT_CREATED', 'INPROGRESS', 'SUCCESS', 'FAILED'],
|
|
22
|
+
default: 'NOT_CREATED',
|
|
23
|
+
},
|
|
24
|
+
isBackupRestored: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false,
|
|
27
|
+
},
|
|
28
|
+
isStaticSiteBackup: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false,
|
|
31
|
+
},
|
|
32
|
+
supportMail: String,
|
|
33
|
+
emailTemplates: [
|
|
34
|
+
{
|
|
35
|
+
default_email_template: String,
|
|
36
|
+
site_email_template: String,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
providers: {
|
|
40
|
+
type: Schema.Types.Mixed,
|
|
41
|
+
default: {}
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
timestamps: true,
|
|
45
|
+
minimize: false,
|
|
46
|
+
});
|
|
47
|
+
exports.default = model('site_domains', siteDomainSchema);
|
|
48
|
+
//# sourceMappingURL=site_domain.model.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PushNotifyProvider } from '../interface/interface';
|
|
2
|
+
export declare class FcmClient implements PushNotifyProvider {
|
|
3
|
+
readonly authorizedClient: any;
|
|
4
|
+
private constructor();
|
|
5
|
+
static fcmClientObject(sitename: string): Promise<FcmClient>;
|
|
6
|
+
sendPushNotifications(token: string, notificationMessage: any): Promise<any>;
|
|
7
|
+
sendPushNotification(token: string, notificationMessage: any): Promise<any>;
|
|
8
|
+
sendChunkedPushNotification(tokens: string[], notificationMessage: string): Promise<unknown>;
|
|
9
|
+
chunkTokens(tokens: string[], chunkSize: number): Promise<any>;
|
|
10
|
+
fetchTopics(): Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Method to send notification based on topics
|
|
13
|
+
* @param topics
|
|
14
|
+
* @param notification
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
sendNotificationsToTopics(topics: string[], notification: any): Promise<any>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
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.FcmClient = void 0;
|
|
16
|
+
/* eslint-disable max-len */
|
|
17
|
+
const commonUtil_1 = require("../../common/util/commonUtil");
|
|
18
|
+
const logger_1 = require("../../common/util/logger");
|
|
19
|
+
const config_1 = __importDefault(require("../../config"));
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
const admin = require('firebase-admin');
|
|
22
|
+
class FcmClient {
|
|
23
|
+
constructor(credentials) {
|
|
24
|
+
this.authorizedClient = {};
|
|
25
|
+
if (!admin.apps.length) {
|
|
26
|
+
// Initialize default app
|
|
27
|
+
admin.initializeApp({
|
|
28
|
+
credential: admin.credential.cert(credentials),
|
|
29
|
+
databaseURL: `https://${credentials.project_id}.firebaseio.com`, // For Realtime DB, remove if not using
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// If default app already exists, skip initializing again
|
|
34
|
+
logger_1.Logger.info('FCM Client', 'Firebase app already initialized, skipping initialization');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static fcmClientObject(sitename) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a, _b, _c, _d, _e;
|
|
40
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached fcmClientObject', 'fcmClientObject');
|
|
41
|
+
const credentials = {
|
|
42
|
+
type: config_1.default.FCM.TYPE,
|
|
43
|
+
project_id: ((_a = 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.FIREBASEPROJECTID)) !== null && _a !== void 0 ? _a : ''),
|
|
44
|
+
private_key_id: ((_b = 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)) !== null && _b !== void 0 ? _b : ''),
|
|
45
|
+
client_email: ((_c = 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.FIREBASECLIENTEMAIL)) !== null && _c !== void 0 ? _c : ''),
|
|
46
|
+
client_id: ((_d = 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.FIREBASECLIENTID)) !== null && _d !== void 0 ? _d : ''),
|
|
47
|
+
auth_uri: config_1.default.FCM.AUTH_URI,
|
|
48
|
+
token_uri: config_1.default.FCM.TOKEN_URI,
|
|
49
|
+
auth_provider_x509_cert_url: config_1.default.FCM.AUTH_PROVIDER_X509_CERT_URL,
|
|
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
|
+
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
|
|
53
|
+
};
|
|
54
|
+
logger_1.Logger.info('FCM-Client>FCMClient: FCM Client Credentials fetched', 'fcmClientObject');
|
|
55
|
+
return new FcmClient(credentials);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
sendPushNotifications(token, notificationMessage) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached authorize', 'sendPushNotifications');
|
|
62
|
+
const pushnotificationRes = yield this.sendPushNotification(token, notificationMessage);
|
|
63
|
+
return pushnotificationRes;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in sendPushNotifications', 'sendPushNotifications', err);
|
|
67
|
+
return err;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
sendPushNotification(token, notificationMessage) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached sendPushNotification', 'sendPushNotification');
|
|
75
|
+
const message = {
|
|
76
|
+
notification: {
|
|
77
|
+
title: notificationMessage.title,
|
|
78
|
+
body: notificationMessage.body,
|
|
79
|
+
},
|
|
80
|
+
token,
|
|
81
|
+
};
|
|
82
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached sendPushNotification', 'sendPushNotification');
|
|
83
|
+
let notificationRes = yield admin.messaging().send(message);
|
|
84
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached sendPushNotification', 'sendPushNotification');
|
|
85
|
+
return notificationRes;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in sendPushNotifications', 'sendPushNotifications', err);
|
|
89
|
+
return err;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
sendChunkedPushNotification(tokens, notificationMessage) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
try {
|
|
96
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached sendPushNotification', 'sendPushNotification');
|
|
97
|
+
// Get the FCM tokens for this segment and chunk them
|
|
98
|
+
const CHUNK_SIZE = 1000;
|
|
99
|
+
const chunkedTokens = this.chunkTokens(tokens, CHUNK_SIZE);
|
|
100
|
+
// Send the notification to each chunk
|
|
101
|
+
for (const chunk of chunkedTokens) {
|
|
102
|
+
// Send notifications for the current chunk
|
|
103
|
+
for (const token of chunk) {
|
|
104
|
+
yield this.sendPushNotifications(token, notificationMessage);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in sendPushNotifications', 'sendPushNotifications', err);
|
|
111
|
+
return err;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
chunkTokens(tokens, chunkSize) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
try {
|
|
118
|
+
logger_1.Logger.info('FCM-Client>FCMClient: Reached chunkTokens', 'chunkTokens');
|
|
119
|
+
// Maximum number of tokens to send in one chunk (FCM allows a max of 1000 tokens per request)
|
|
120
|
+
const chunks = [];
|
|
121
|
+
for (let i = 0; i < tokens.length; i += chunkSize) {
|
|
122
|
+
chunks.push(tokens.slice(i, i + chunkSize));
|
|
123
|
+
}
|
|
124
|
+
return chunks;
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in chunkTokens', 'chunkTokens', err);
|
|
128
|
+
return err;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
fetchTopics() {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
try {
|
|
135
|
+
const db = admin.firestore(); // Use Firestore// Firebase Realtime Database reference
|
|
136
|
+
const snapshot = yield db.collection('topics').get(); // Correct method for Firestore
|
|
137
|
+
if (snapshot.empty) {
|
|
138
|
+
logger_1.Logger.debug('FCM client', 'fetchTopics', 'No Topics Found');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const topics = [];
|
|
142
|
+
snapshot.forEach((doc) => {
|
|
143
|
+
topics.push({ name: doc.data().name }); // Assuming each topic has a 'name' field
|
|
144
|
+
});
|
|
145
|
+
return topics;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in fetchTopics', 'fetchTopics', error);
|
|
149
|
+
return error;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Method to send notification based on topics
|
|
155
|
+
* @param topics
|
|
156
|
+
* @param notification
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
sendNotificationsToTopics(topics, notification) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
try {
|
|
162
|
+
if (Array.isArray(topics) && topics.length > 0) {
|
|
163
|
+
const topicsStr = topics.map(t => `'${t}' in topics`).join(' || ');
|
|
164
|
+
logger_1.Logger.debug('FCM-Client>FCMClient: Reached sendNotificationsToTopics', 'sendNotificationsToTopics', { topicsStr });
|
|
165
|
+
const message = {
|
|
166
|
+
notification: {
|
|
167
|
+
title: notification.title,
|
|
168
|
+
body: notification.body,
|
|
169
|
+
},
|
|
170
|
+
data: notification.data,
|
|
171
|
+
// Using the "condition" field to target multiple topics
|
|
172
|
+
condition: `${topicsStr}`,
|
|
173
|
+
};
|
|
174
|
+
logger_1.Logger.debug('FCM-Client>FCMClient: Reached sendNotificationsToTopics', 'sendNotificationsToTopics', message);
|
|
175
|
+
const response = yield admin.messaging().send(message);
|
|
176
|
+
logger_1.Logger.debug('FCM-Client>FCMClient: Reached after sendNotificationsToTopics', 'sendNotificationsToTopics', { response });
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
logger_1.Logger.error('FCM-Client>FCMClient: Error in sendNotificationsToTopics', 'sendNotificationsToTopics', error);
|
|
182
|
+
return error;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.FcmClient = FcmClient;
|
|
188
|
+
//# sourceMappingURL=fcmservices.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@platform-x/hep-push-notification-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "@platform-x/hep-push-notification-client",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"devstart": "npm run build && tsc-watch --onSuccess \"node ./dist/src/index.js\"",
|
|
10
|
+
"start": "node ./dist/src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^22.15.3",
|
|
16
|
+
"@types/uuid": "^10.0.0",
|
|
17
|
+
"ts-node": "^10.9.2",
|
|
18
|
+
"typescript": "^5.8.3"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@alloc/quick-lru": "^5.2.0",
|
|
22
|
+
"@sendgrid/helpers": "7.7.0",
|
|
23
|
+
"@types/bunyan": "^1.8.6",
|
|
24
|
+
"@types/bunyan-format": "^0.2.3",
|
|
25
|
+
"@types/cls-hooked": "^4.3.3",
|
|
26
|
+
"@types/express": "^4.17.12",
|
|
27
|
+
"@types/lodash": "^4.14.171",
|
|
28
|
+
"@types/node": "^15.12.2",
|
|
29
|
+
"apollo-server-caching": "^3.3.0",
|
|
30
|
+
"axios": "0.21.4",
|
|
31
|
+
"bunyan": "^1.8.15",
|
|
32
|
+
"bunyan-format": "^0.2.1",
|
|
33
|
+
"cls-hooked": "^4.2.2",
|
|
34
|
+
"dataloader": "^2.0.0",
|
|
35
|
+
"dotenv": "^10.0.0",
|
|
36
|
+
"express": "^4.17.1",
|
|
37
|
+
"firebase-admin": "^13.5.0",
|
|
38
|
+
"hep-secret-access": "1.3.4",
|
|
39
|
+
"lodash": "4.17.21",
|
|
40
|
+
"mongodb": "5.9.2",
|
|
41
|
+
"mongoose": "7.0.3",
|
|
42
|
+
"mysql2": "2.3.3",
|
|
43
|
+
"node-html-parser": "5.1.0",
|
|
44
|
+
"request-ip": "2.1.3",
|
|
45
|
+
"uuid": "8.3.2"
|
|
46
|
+
},
|
|
47
|
+
"private": false,
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|