podverse-external-services 5.1.15-alpha.0 → 5.1.16-alpha.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 (46) hide show
  1. package/dist/config/index.d.ts +14 -0
  2. package/dist/config/index.d.ts.map +1 -0
  3. package/dist/config/index.js +16 -0
  4. package/dist/config/web.d.ts +4 -0
  5. package/dist/config/web.d.ts.map +1 -0
  6. package/dist/config/web.js +17 -0
  7. package/dist/services/google/firebase/firebaseAdmin.d.ts +3 -0
  8. package/dist/services/google/firebase/firebaseAdmin.d.ts.map +1 -0
  9. package/dist/services/google/firebase/firebaseAdmin.js +31 -0
  10. package/dist/services/google/firebase/firebaseHelpers.d.ts +3 -0
  11. package/dist/services/google/firebase/firebaseHelpers.d.ts.map +1 -0
  12. package/dist/services/google/firebase/firebaseHelpers.js +16 -0
  13. package/dist/services/google/firebase/firebaseNotificationAndroid.d.ts +11 -0
  14. package/dist/services/google/firebase/firebaseNotificationAndroid.d.ts.map +1 -0
  15. package/dist/services/google/firebase/firebaseNotificationAndroid.js +48 -0
  16. package/dist/services/google/firebase/firebaseNotificationGeneric.d.ts +15 -0
  17. package/dist/services/google/firebase/firebaseNotificationGeneric.d.ts.map +1 -0
  18. package/dist/services/google/firebase/firebaseNotificationGeneric.js +60 -0
  19. package/dist/services/google/firebase/firebaseNotificationIOS.d.ts +12 -0
  20. package/dist/services/google/firebase/firebaseNotificationIOS.d.ts.map +1 -0
  21. package/dist/services/google/firebase/firebaseNotificationIOS.js +47 -0
  22. package/dist/services/google/firebase/firebaseNotificationOrchestrator.d.ts +15 -0
  23. package/dist/services/google/firebase/firebaseNotificationOrchestrator.d.ts.map +1 -0
  24. package/dist/services/google/firebase/firebaseNotificationOrchestrator.js +68 -0
  25. package/dist/services/google/firebase/firebaseNotificationWeb.d.ts +12 -0
  26. package/dist/services/google/firebase/firebaseNotificationWeb.d.ts.map +1 -0
  27. package/dist/services/google/firebase/firebaseNotificationWeb.js +59 -0
  28. package/dist/services/index.d.ts +1 -3
  29. package/dist/services/index.d.ts.map +1 -1
  30. package/dist/services/index.js +16 -9
  31. package/dist/services/notifications/i18nNotifications.d.ts +4 -0
  32. package/dist/services/notifications/i18nNotifications.d.ts.map +1 -0
  33. package/dist/services/notifications/i18nNotifications.js +49 -0
  34. package/dist/services/notifications/index.d.ts +2 -24
  35. package/dist/services/notifications/index.d.ts.map +1 -1
  36. package/dist/services/notifications/index.js +15 -35
  37. package/dist/services/notifications/notificationOrchestrator.d.ts +20 -0
  38. package/dist/services/notifications/notificationOrchestrator.d.ts.map +1 -0
  39. package/dist/services/notifications/notificationOrchestrator.js +96 -0
  40. package/package.json +4 -4
  41. package/dist/services/google/fcm.d.ts +0 -21
  42. package/dist/services/google/fcm.d.ts.map +0 -1
  43. package/dist/services/google/fcm.js +0 -114
  44. package/dist/services/google/firebaseAccessTokenService.d.ts +0 -9
  45. package/dist/services/google/firebaseAccessTokenService.d.ts.map +0 -1
  46. package/dist/services/google/firebaseAccessTokenService.js +0 -67
@@ -0,0 +1,14 @@
1
+ export declare const config: {
2
+ google: {
3
+ firebase: {
4
+ notifications_enabled: boolean;
5
+ admin_json_key_path: string;
6
+ };
7
+ };
8
+ web: {
9
+ protocol: string;
10
+ host: string;
11
+ icon_image_url: string;
12
+ };
13
+ };
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;CAYlB,CAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = void 0;
4
+ exports.config = {
5
+ google: {
6
+ firebase: {
7
+ notifications_enabled: process.env.GOOGLE_FIREBASE_NOTIFICATIONS_ENABLED === "true",
8
+ admin_json_key_path: process.env.GOOGLE_FIREBASE_ADMIN_JSON_KEY_PATH || "",
9
+ }
10
+ },
11
+ web: {
12
+ protocol: process.env.WEB_PROTOCOL || "http",
13
+ host: process.env.WEB_DOMAIN || "localhost",
14
+ icon_image_url: process.env.WEB_ICON_IMAGE_PATH || ""
15
+ }
16
+ };
@@ -0,0 +1,4 @@
1
+ export declare const getWebBaseUrl: () => string;
2
+ export declare const getWebBaseUrlWithPath: (path: string) => string;
3
+ export declare const getWebIconImageUrl: () => string;
4
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/config/web.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,QAAO,MAEhC,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,MAGpD,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAO,MAErC,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebIconImageUrl = exports.getWebBaseUrlWithPath = exports.getWebBaseUrl = void 0;
4
+ const index_1 = require("./index");
5
+ const getWebBaseUrl = () => {
6
+ return `${index_1.config.web.protocol}://${index_1.config.web.host}`;
7
+ };
8
+ exports.getWebBaseUrl = getWebBaseUrl;
9
+ const getWebBaseUrlWithPath = (path) => {
10
+ const baseUrl = (0, exports.getWebBaseUrl)();
11
+ return `${baseUrl}${path}`;
12
+ };
13
+ exports.getWebBaseUrlWithPath = getWebBaseUrlWithPath;
14
+ const getWebIconImageUrl = () => {
15
+ return `${(0, exports.getWebBaseUrl)()}/${index_1.config.web.icon_image_url}`;
16
+ };
17
+ exports.getWebIconImageUrl = getWebIconImageUrl;
@@ -0,0 +1,3 @@
1
+ import admin from "firebase-admin";
2
+ export declare const firebaseAdmin: typeof admin | null;
3
+ //# sourceMappingURL=firebaseAdmin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseAdmin.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseAdmin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,gBAAgB,CAAC;AA6BnC,eAAO,MAAM,aAAa,qBAAqB,CAAC"}
@@ -0,0 +1,31 @@
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.firebaseAdmin = void 0;
7
+ const firebase_admin_1 = __importDefault(require("firebase-admin"));
8
+ const config_1 = require("../../../config");
9
+ let firebaseAdminLocal = null;
10
+ if (!config_1.config.google.firebase.notifications_enabled) {
11
+ console.warn("Firebase notifications are disabled in the configuration.");
12
+ }
13
+ else {
14
+ console.log("Firebase notifications are enabled in the configuration.");
15
+ try {
16
+ const settings = require(config_1.config.google.firebase.admin_json_key_path);
17
+ const serviceAccount = settings;
18
+ if (!firebase_admin_1.default.apps.length) {
19
+ firebase_admin_1.default.initializeApp({
20
+ credential: firebase_admin_1.default.credential.cert(serviceAccount),
21
+ });
22
+ console.log("Firebase Admin Initialized Successfully");
23
+ }
24
+ firebaseAdminLocal = firebase_admin_1.default;
25
+ }
26
+ catch (error) {
27
+ console.error("Firebase Admin Initialization Failed:", error);
28
+ firebaseAdminLocal = null;
29
+ }
30
+ }
31
+ exports.firebaseAdmin = firebaseAdminLocal;
@@ -0,0 +1,3 @@
1
+ export declare function stringifyData(data?: Record<string, any>): Record<string, string>;
2
+ export declare function chunkArray<T>(arr: T[], size?: number): T[][];
3
+ //# sourceMappingURL=firebaseHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseHelpers.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseHelpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKhF;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,SAAM,GAAG,CAAC,EAAE,EAAE,CAMzD"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyData = stringifyData;
4
+ exports.chunkArray = chunkArray;
5
+ function stringifyData(data) {
6
+ if (!data)
7
+ return {};
8
+ return Object.fromEntries(Object.entries(data).map(([k, v]) => [k, typeof v === "string" ? v : JSON.stringify(v)]));
9
+ }
10
+ function chunkArray(arr, size = 500) {
11
+ const chunks = [];
12
+ for (let i = 0; i < arr.length; i += size) {
13
+ chunks.push(arr.slice(i, i + size));
14
+ }
15
+ return chunks;
16
+ }
@@ -0,0 +1,11 @@
1
+ type AndroidPayload = {
2
+ fcmToken: string;
3
+ title: string;
4
+ body?: string;
5
+ channelId?: string;
6
+ image?: string;
7
+ data?: Record<string, any>;
8
+ };
9
+ export declare function sendFirebaseNotificationBatchAndroid(tokens: string[], payload: Omit<AndroidPayload, 'fcmToken'>): Promise<any[]>;
10
+ export {};
11
+ //# sourceMappingURL=firebaseNotificationAndroid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseNotificationAndroid.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseNotificationAndroid.ts"],"names":[],"mappings":"AAKA,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAsB,oCAAoC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,kBA+BrH"}
@@ -0,0 +1,48 @@
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.sendFirebaseNotificationBatchAndroid = sendFirebaseNotificationBatchAndroid;
13
+ const web_1 = require("@external-services/config/web");
14
+ const firebaseAdmin_1 = require("./firebaseAdmin");
15
+ const firebaseHelpers_1 = require("./firebaseHelpers");
16
+ const firebaseHelpers_2 = require("./firebaseHelpers");
17
+ function sendFirebaseNotificationBatchAndroid(tokens, payload) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ if (!firebaseAdmin_1.firebaseAdmin)
20
+ throw new Error("Firebase Admin is not initialized");
21
+ const chunks = (0, firebaseHelpers_2.chunkArray)(tokens, 500);
22
+ const results = [];
23
+ for (const chunk of chunks) {
24
+ const multicastMessage = {
25
+ tokens: chunk,
26
+ android: {
27
+ priority: "high",
28
+ notification: {
29
+ title: payload.title,
30
+ body: payload.body,
31
+ channelId: payload.channelId || "default",
32
+ image: payload.image || (0, web_1.getWebIconImageUrl)(),
33
+ },
34
+ },
35
+ data: (0, firebaseHelpers_1.stringifyData)(payload.data),
36
+ };
37
+ try {
38
+ const resp = yield firebaseAdmin_1.firebaseAdmin.messaging().sendEachForMulticast(multicastMessage);
39
+ results.push(resp);
40
+ }
41
+ catch (err) {
42
+ console.error("sendFirebaseNotificationBatchAndroid chunk error:", err);
43
+ throw err;
44
+ }
45
+ }
46
+ return results;
47
+ });
48
+ }
@@ -0,0 +1,15 @@
1
+ type GenericPayload = {
2
+ fcmToken: string;
3
+ title: string;
4
+ body?: string;
5
+ icon?: string;
6
+ image?: string;
7
+ link?: string;
8
+ badge?: number;
9
+ channelId?: string;
10
+ sound?: string;
11
+ data?: Record<string, any>;
12
+ };
13
+ export declare function sendFirebaseNotificationBatchGeneric(tokens: string[], payload: Omit<GenericPayload, 'fcmToken'>): Promise<any[]>;
14
+ export {};
15
+ //# sourceMappingURL=firebaseNotificationGeneric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseNotificationGeneric.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseNotificationGeneric.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAsB,oCAAoC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,kBAuDrH"}
@@ -0,0 +1,60 @@
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.sendFirebaseNotificationBatchGeneric = sendFirebaseNotificationBatchGeneric;
13
+ const firebaseAdmin_1 = require("./firebaseAdmin");
14
+ const web_1 = require("@external-services/config/web");
15
+ const firebaseHelpers_1 = require("./firebaseHelpers");
16
+ function sendFirebaseNotificationBatchGeneric(tokens, payload) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (!firebaseAdmin_1.firebaseAdmin)
19
+ throw new Error("Firebase Admin is not initialized");
20
+ const chunks = (0, firebaseHelpers_1.chunkArray)(tokens, 500);
21
+ const results = [];
22
+ for (const chunk of chunks) {
23
+ const multicastMessage = {
24
+ tokens: chunk,
25
+ webpush: {
26
+ headers: { Urgency: "normal" },
27
+ data: Object.assign({ title: payload.title, body: payload.body || "", icon: payload.icon || (0, web_1.getWebIconImageUrl)(), image: payload.image || undefined, link: payload.link ? (0, web_1.getWebBaseUrlWithPath)(payload.link) : (0, web_1.getWebBaseUrl)() }, (0, firebaseHelpers_1.stringifyData)(payload.data)),
28
+ },
29
+ android: {
30
+ priority: "high",
31
+ notification: {
32
+ title: payload.title,
33
+ body: payload.body,
34
+ channelId: payload.channelId || "default",
35
+ image: payload.image || (0, web_1.getWebIconImageUrl)(),
36
+ },
37
+ },
38
+ apns: {
39
+ headers: { "apns-priority": "10" },
40
+ payload: Object.assign(Object.assign({ aps: {
41
+ alert: { title: payload.title, body: payload.body },
42
+ badge: payload.badge,
43
+ sound: payload.sound || "default",
44
+ "mutable-content": 1,
45
+ } }, (payload.data || {})), { image: payload.image || (0, web_1.getWebIconImageUrl)() }),
46
+ },
47
+ data: (0, firebaseHelpers_1.stringifyData)(payload.data),
48
+ };
49
+ try {
50
+ const resp = yield firebaseAdmin_1.firebaseAdmin.messaging().sendEachForMulticast(multicastMessage);
51
+ results.push(resp);
52
+ }
53
+ catch (err) {
54
+ console.error("sendFirebaseNotificationBatchGeneric chunk error:", err);
55
+ throw err;
56
+ }
57
+ }
58
+ return results;
59
+ });
60
+ }
@@ -0,0 +1,12 @@
1
+ type IOSPayload = {
2
+ fcmToken: string;
3
+ title: string;
4
+ body?: string;
5
+ badge?: number;
6
+ sound?: string;
7
+ image?: string;
8
+ data?: Record<string, any>;
9
+ };
10
+ export declare function sendFirebaseNotificationBatchIOS(tokens: string[], payload: Omit<IOSPayload, 'fcmToken'>): Promise<any[]>;
11
+ export {};
12
+ //# sourceMappingURL=firebaseNotificationIOS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseNotificationIOS.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseNotificationIOS.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAsB,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,kBAmC7G"}
@@ -0,0 +1,47 @@
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.sendFirebaseNotificationBatchIOS = sendFirebaseNotificationBatchIOS;
13
+ const web_1 = require("@external-services/config/web");
14
+ const firebaseAdmin_1 = require("./firebaseAdmin");
15
+ const firebaseHelpers_1 = require("./firebaseHelpers");
16
+ function sendFirebaseNotificationBatchIOS(tokens, payload) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (!firebaseAdmin_1.firebaseAdmin)
19
+ throw new Error("Firebase Admin is not initialized");
20
+ const chunks = (0, firebaseHelpers_1.chunkArray)(tokens, 500);
21
+ const results = [];
22
+ for (const chunk of chunks) {
23
+ const multicastMessage = {
24
+ tokens: chunk,
25
+ apns: {
26
+ headers: { "apns-priority": "10" },
27
+ payload: Object.assign(Object.assign({ aps: {
28
+ alert: { title: payload.title, body: payload.body },
29
+ badge: payload.badge,
30
+ sound: payload.sound || "default",
31
+ "mutable-content": 1,
32
+ } }, (payload.data || {})), { image: payload.image || (0, web_1.getWebIconImageUrl)() }),
33
+ },
34
+ data: (0, firebaseHelpers_1.stringifyData)(payload.data),
35
+ };
36
+ try {
37
+ const resp = yield firebaseAdmin_1.firebaseAdmin.messaging().sendEachForMulticast(multicastMessage);
38
+ results.push(resp);
39
+ }
40
+ catch (err) {
41
+ console.error("sendFirebaseNotificationBatchIOS chunk error:", err);
42
+ throw err;
43
+ }
44
+ }
45
+ return results;
46
+ });
47
+ }
@@ -0,0 +1,15 @@
1
+ type NotificationPlatform = 'web' | 'android' | 'ios' | 'generic';
2
+ type OrchestratorParams = {
3
+ tokens: string[];
4
+ finalText: string;
5
+ platform: NotificationPlatform;
6
+ icon?: string;
7
+ link?: string;
8
+ channelId?: string;
9
+ badge?: number;
10
+ sound?: string;
11
+ data?: Record<string, any>;
12
+ };
13
+ export declare function firebaseNotificationBatchOrchestrator(params: OrchestratorParams): Promise<any[]>;
14
+ export {};
15
+ //# sourceMappingURL=firebaseNotificationOrchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseNotificationOrchestrator.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseNotificationOrchestrator.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;AAElE,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,oBAAoB,CAAC;IAE/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,kBAAkB,kBAsDrF"}
@@ -0,0 +1,68 @@
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.firebaseNotificationBatchOrchestrator = firebaseNotificationBatchOrchestrator;
13
+ const firebaseNotificationWeb_1 = require("./firebaseNotificationWeb");
14
+ const firebaseNotificationAndroid_1 = require("./firebaseNotificationAndroid");
15
+ const firebaseNotificationIOS_1 = require("./firebaseNotificationIOS");
16
+ const firebaseNotificationGeneric_1 = require("./firebaseNotificationGeneric");
17
+ function firebaseNotificationBatchOrchestrator(params) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const { tokens, finalText, platform } = params;
20
+ switch (platform) {
21
+ case 'web': {
22
+ const payload = {
23
+ title: finalText,
24
+ body: '',
25
+ icon: params.icon,
26
+ link: params.link,
27
+ data: params.data,
28
+ };
29
+ console.log(`Sending web notification with payload: ${JSON.stringify(payload)}`);
30
+ return yield (0, firebaseNotificationWeb_1.sendFirebaseNotificationBatchWeb)(tokens, payload);
31
+ }
32
+ case 'android': {
33
+ const payload = {
34
+ title: finalText,
35
+ body: '',
36
+ channelId: params.channelId,
37
+ data: params.data,
38
+ };
39
+ return yield (0, firebaseNotificationAndroid_1.sendFirebaseNotificationBatchAndroid)(tokens, payload);
40
+ }
41
+ case 'ios': {
42
+ const payload = {
43
+ title: finalText,
44
+ body: '',
45
+ badge: params.badge,
46
+ sound: params.sound,
47
+ data: params.data,
48
+ };
49
+ return yield (0, firebaseNotificationIOS_1.sendFirebaseNotificationBatchIOS)(tokens, payload);
50
+ }
51
+ case 'generic': {
52
+ const payload = {
53
+ title: finalText,
54
+ body: '',
55
+ icon: params.icon,
56
+ link: params.link,
57
+ badge: params.badge,
58
+ channelId: params.channelId,
59
+ sound: params.sound,
60
+ data: params.data,
61
+ };
62
+ return yield (0, firebaseNotificationGeneric_1.sendFirebaseNotificationBatchGeneric)(tokens, payload);
63
+ }
64
+ default:
65
+ throw new Error(`Unsupported platform: ${platform}`);
66
+ }
67
+ });
68
+ }
@@ -0,0 +1,12 @@
1
+ type NotificationPayload = {
2
+ fcmToken: string;
3
+ title: string;
4
+ body?: string;
5
+ icon?: string;
6
+ image?: string;
7
+ link?: string;
8
+ data?: Record<string, string>;
9
+ };
10
+ export declare function sendFirebaseNotificationBatchWeb(tokens: string[], payload: Omit<NotificationPayload, 'fcmToken'>): Promise<any[]>;
11
+ export {};
12
+ //# sourceMappingURL=firebaseNotificationWeb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseNotificationWeb.d.ts","sourceRoot":"","sources":["../../../../src/services/google/firebase/firebaseNotificationWeb.ts"],"names":[],"mappings":"AAIA,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,wBAAsB,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,kBA8CtH"}
@@ -0,0 +1,59 @@
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.sendFirebaseNotificationBatchWeb = sendFirebaseNotificationBatchWeb;
13
+ const firebaseAdmin_1 = require("./firebaseAdmin");
14
+ const web_1 = require("@external-services/config/web");
15
+ const firebaseHelpers_1 = require("./firebaseHelpers");
16
+ function sendFirebaseNotificationBatchWeb(tokens, payload) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (!firebaseAdmin_1.firebaseAdmin)
19
+ throw new Error("Firebase Admin is not initialized");
20
+ const chunks = (0, firebaseHelpers_1.chunkArray)(tokens, 500);
21
+ const results = [];
22
+ for (const chunk of chunks) {
23
+ const data = {
24
+ title: payload.title,
25
+ body: payload.body || "",
26
+ icon: payload.icon || (0, web_1.getWebIconImageUrl)(),
27
+ link: payload.link ? (0, web_1.getWebBaseUrlWithPath)(payload.link) : (0, web_1.getWebBaseUrl)(),
28
+ };
29
+ // Only add image if it has a value (FCM data values must be strings, not undefined)
30
+ if (payload.image) {
31
+ data.image = payload.image;
32
+ }
33
+ // Spread additional data, filtering out undefined values
34
+ if (payload.data) {
35
+ for (const [key, value] of Object.entries(payload.data)) {
36
+ if (value !== undefined && value !== null) {
37
+ data[key] = String(value);
38
+ }
39
+ }
40
+ }
41
+ const multicastMessage = {
42
+ tokens: chunk,
43
+ webpush: {
44
+ headers: { Urgency: "normal" },
45
+ data,
46
+ },
47
+ };
48
+ try {
49
+ const resp = yield firebaseAdmin_1.firebaseAdmin.messaging().sendEachForMulticast(multicastMessage);
50
+ results.push(resp);
51
+ }
52
+ catch (err) {
53
+ console.error("sendFirebaseNotificationBatchWeb chunk error:", err);
54
+ throw err;
55
+ }
56
+ }
57
+ return results;
58
+ });
59
+ }
@@ -1,6 +1,4 @@
1
- export { GoogleFCMService } from './google/fcm';
2
- export { FirebaseAccessTokenService } from './google/firebaseAccessTokenService';
3
- export { NotificationsService, SendNotificationOptions } from './notifications';
1
+ export * from './notifications';
4
2
  export { PayPalService } from './paypal';
5
3
  export { PodcastIndexService } from './podcast-index';
6
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,15 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PodcastIndexService = exports.PayPalService = exports.NotificationsService = exports.FirebaseAccessTokenService = exports.GoogleFCMService = void 0;
4
- // export { AWSS3Service, AWSSQSService } from './aws'
5
- var fcm_1 = require("./google/fcm");
6
- Object.defineProperty(exports, "GoogleFCMService", { enumerable: true, get: function () { return fcm_1.GoogleFCMService; } });
7
- var firebaseAccessTokenService_1 = require("./google/firebaseAccessTokenService");
8
- Object.defineProperty(exports, "FirebaseAccessTokenService", { enumerable: true, get: function () { return firebaseAccessTokenService_1.FirebaseAccessTokenService; } });
9
- var notifications_1 = require("./notifications");
10
- Object.defineProperty(exports, "NotificationsService", { enumerable: true, get: function () { return notifications_1.NotificationsService; } });
17
+ exports.PodcastIndexService = exports.PayPalService = void 0;
18
+ __exportStar(require("./notifications"), exports);
11
19
  var paypal_1 = require("./paypal");
12
20
  Object.defineProperty(exports, "PayPalService", { enumerable: true, get: function () { return paypal_1.PayPalService; } });
13
21
  var podcast_index_1 = require("./podcast-index");
14
22
  Object.defineProperty(exports, "PodcastIndexService", { enumerable: true, get: function () { return podcast_index_1.PodcastIndexService; } });
15
- // export { UnifiedPushService } from './unifiedpush'
@@ -0,0 +1,4 @@
1
+ export type NotificationMessageType = 'new' | 'new-episode' | 'new-podcast' | 'new-video' | 'new-video-channel' | 'new-track' | 'new-album' | 'livestream-started' | 'livestream-scheduled';
2
+ export type NotificationLocaleMap = Record<NotificationMessageType, string>;
3
+ export declare const i18nNotifications: Record<string, NotificationLocaleMap>;
4
+ //# sourceMappingURL=i18nNotifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nNotifications.d.ts","sourceRoot":"","sources":["../../../src/services/notifications/i18nNotifications.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,KAAK,GACvC,aAAa,GAAG,aAAa,GAC7B,WAAW,GAAG,mBAAmB,GACjC,WAAW,GAAG,WAAW,GACzB,oBAAoB,GAAG,sBAAsB,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AAE5E,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CA6CnE,CAAA"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18nNotifications = void 0;
4
+ exports.i18nNotifications = {
5
+ "en": {
6
+ "new": "",
7
+ "new-episode": "",
8
+ "new-podcast": "",
9
+ "new-video": "",
10
+ "new-video-channel": "",
11
+ "new-track": "",
12
+ "new-album": "",
13
+ "livestream-started": "Live: ",
14
+ "livestream-scheduled": "Live Scheduled: "
15
+ },
16
+ "es": {
17
+ "new": "",
18
+ "new-episode": "",
19
+ "new-podcast": "",
20
+ "new-video": "",
21
+ "new-video-channel": "",
22
+ "new-track": "",
23
+ "new-album": "",
24
+ "livestream-started": "En vivo: ",
25
+ "livestream-scheduled": "En vivo programado: "
26
+ },
27
+ "fr": {
28
+ "new": "",
29
+ "new-episode": "",
30
+ "new-podcast": "",
31
+ "new-video": "",
32
+ "new-video-channel": "",
33
+ "new-track": "",
34
+ "new-album": "",
35
+ "livestream-started": "En direct: ",
36
+ "livestream-scheduled": "En direct programmé: "
37
+ },
38
+ "el-GR": {
39
+ "new": "",
40
+ "new-episode": "",
41
+ "new-podcast": "",
42
+ "new-video": "",
43
+ "new-video-channel": "",
44
+ "new-track": "",
45
+ "new-album": "",
46
+ "livestream-started": "Ζωντανά: ",
47
+ "livestream-scheduled": "Προγραμματισμένα ζωντανά: "
48
+ }
49
+ };
@@ -1,25 +1,3 @@
1
- import { GoogleFCMService } from '@external-services/services/google/fcm';
2
- import { ILoggerLike } from 'podverse-helpers/dist/lib/backend/logger';
3
- export interface SendNotificationOptions {
4
- itemFullImageUrl?: string | null;
5
- itemGuid?: string | null;
6
- itemIdText?: string;
7
- itemTitle?: string | null;
8
- channelIdText: string;
9
- channelFullImageUrl?: string | null;
10
- channelTitle?: string | null;
11
- }
12
- type Constructor = {
13
- userAgent: string;
14
- googleAuthToken: string;
15
- firebaseProjectId: string;
16
- loggerService: ILoggerLike;
17
- };
18
- export declare class NotificationsService {
19
- GoogleFCMService: GoogleFCMService;
20
- constructor({ userAgent, googleAuthToken, firebaseProjectId, loggerService }: Constructor);
21
- sendNewItemDetectedNotifications: (account_fcm_tokens: string[], options: SendNotificationOptions) => Promise<void>;
22
- sendLiveItemLiveDetectedNotifications: (account_fcm_tokens: string[], options: SendNotificationOptions) => Promise<void>;
23
- }
24
- export {};
1
+ export * from './i18nNotifications';
2
+ export * from './notificationOrchestrator';
25
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAEvE,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAEnC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAED,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,WAAW,CAAA;CAC3B,CAAA;AAED,qBAAa,oBAAoB;IACvB,gBAAgB,EAAE,gBAAgB,CAAA;gBAG7B,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,EAAE,WAAW;IAW1F,gCAAgC,GAAU,oBAAoB,MAAM,EAAE,EAAE,SAAS,uBAAuB,KAAG,OAAO,CAAC,IAAI,CAAC,CAKvH;IAED,qCAAqC,GAAU,oBAAoB,MAAM,EAAE,EAAE,SAAS,uBAAuB,KAAG,OAAO,CAAC,IAAI,CAAC,CAK5H;CACF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/notifications/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC"}
@@ -1,38 +1,18 @@
1
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
- });
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
10
15
  };
11
16
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.NotificationsService = void 0;
13
- const fcm_1 = require("@external-services/services/google/fcm");
14
- class NotificationsService {
15
- // declare UnifiedPushService: UnifiedPushService
16
- constructor({ userAgent, googleAuthToken, firebaseProjectId, loggerService }) {
17
- this.sendNewItemDetectedNotifications = (account_fcm_tokens, options) => __awaiter(this, void 0, void 0, function* () {
18
- yield Promise.all([
19
- this.GoogleFCMService.sendFcmNewItemDetectedNotification(account_fcm_tokens, options),
20
- // this.UnifiedPushService.sendUpNewEpisodeDetectedNotification(options)
21
- ]);
22
- });
23
- this.sendLiveItemLiveDetectedNotifications = (account_fcm_tokens, options) => __awaiter(this, void 0, void 0, function* () {
24
- yield Promise.all([
25
- this.GoogleFCMService.sendFcmLiveItemLiveDetectedNotification(account_fcm_tokens, options),
26
- // this.UnifiedPushService.sendUpLiveItemLiveDetectedNotification(options)
27
- ]);
28
- });
29
- this.GoogleFCMService = new fcm_1.GoogleFCMService({
30
- userAgent,
31
- authToken: googleAuthToken,
32
- firebaseProjectId,
33
- loggerService
34
- });
35
- // this.UnifiedPushService = new UnifiedPushService()
36
- }
37
- }
38
- exports.NotificationsService = NotificationsService;
17
+ __exportStar(require("./i18nNotifications"), exports);
18
+ __exportStar(require("./notificationOrchestrator"), exports);
@@ -0,0 +1,20 @@
1
+ import { NotificationMessageType } from './i18nNotifications';
2
+ export type NotificationPlatform = 'web' | 'android' | 'ios' | 'generic';
3
+ export type NotificationService = 'firebase';
4
+ type NotificationOrchestratorParams = {
5
+ service: NotificationService;
6
+ tokens: string[];
7
+ messageText: string;
8
+ messageType: NotificationMessageType;
9
+ locale: string;
10
+ platform: NotificationPlatform;
11
+ icon?: string;
12
+ linkIdText?: string;
13
+ channelId?: string;
14
+ badge?: number;
15
+ sound?: string;
16
+ data?: Record<string, any>;
17
+ };
18
+ export declare function notificationOrchestrator(params: NotificationOrchestratorParams): Promise<any[]>;
19
+ export {};
20
+ //# sourceMappingURL=notificationOrchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notificationOrchestrator.d.ts","sourceRoot":"","sources":["../../../src/services/notifications/notificationOrchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;AACzE,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC;AA4B7C,KAAK,8BAA8B,GAAG;IACpC,OAAO,EAAE,mBAAmB,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,uBAAuB,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,oBAAoB,CAAC;IAE/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AASF,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,8BAA8B,kBA6CpF"}
@@ -0,0 +1,96 @@
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.notificationOrchestrator = notificationOrchestrator;
24
+ const firebaseNotificationOrchestrator_1 = require("../google/firebase/firebaseNotificationOrchestrator");
25
+ const i18nNotifications_1 = require("./i18nNotifications");
26
+ /**
27
+ * Gets the URL path prefix for a given notification message type
28
+ */
29
+ function getLinkPathFromMessageType(messageType) {
30
+ switch (messageType) {
31
+ case 'new-episode':
32
+ return '/episode';
33
+ case 'new-podcast':
34
+ return '/podcast';
35
+ case 'new-video':
36
+ return '/video';
37
+ case 'new-video-channel':
38
+ return '/channel';
39
+ case 'new-track':
40
+ return '/track';
41
+ case 'new-album':
42
+ return '/album';
43
+ case 'livestream-started':
44
+ case 'livestream-scheduled':
45
+ return '/livestream';
46
+ case 'new':
47
+ default:
48
+ return '';
49
+ }
50
+ }
51
+ function getFinalText(messageText, messageType, locale) {
52
+ const baseLocale = locale.includes('-') ? locale.split('-')[0] : locale;
53
+ const localeMap = i18nNotifications_1.i18nNotifications[locale] || i18nNotifications_1.i18nNotifications[baseLocale] || i18nNotifications_1.i18nNotifications.en;
54
+ const prefix = localeMap[messageType] || i18nNotifications_1.i18nNotifications.en[messageType];
55
+ return `${prefix}${messageText}`;
56
+ }
57
+ function notificationOrchestrator(params) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const { service, messageText, messageType, locale, linkIdText } = params, serviceParams = __rest(params, ["service", "messageText", "messageType", "locale", "linkIdText"]);
60
+ const finalText = getFinalText(messageText, messageType, locale);
61
+ // Construct the link from messageType and linkIdText
62
+ let link;
63
+ if (linkIdText) {
64
+ const pathPrefix = getLinkPathFromMessageType(messageType);
65
+ link = pathPrefix ? `${pathPrefix}/${linkIdText}` : undefined;
66
+ }
67
+ console.log('[notificationOrchestrator] params:', {
68
+ service,
69
+ tokens: params.tokens,
70
+ messageText,
71
+ messageType,
72
+ locale,
73
+ platform: params.platform,
74
+ icon: params.icon,
75
+ linkIdText,
76
+ channelId: params.channelId,
77
+ badge: params.badge,
78
+ sound: params.sound,
79
+ data: params.data,
80
+ finalText,
81
+ link
82
+ });
83
+ switch (service) {
84
+ case 'firebase':
85
+ return yield (0, firebaseNotificationOrchestrator_1.firebaseNotificationBatchOrchestrator)(Object.assign(Object.assign({}, serviceParams), { finalText,
86
+ link }));
87
+ // Future services can be added here:
88
+ // case 'onesignal':
89
+ // return await onesignalNotificationOrchestrator(serviceParams);
90
+ // case 'pusher':
91
+ // return await pusherNotificationOrchestrator(serviceParams);
92
+ default:
93
+ throw new Error(`Unsupported notification service: ${service}`);
94
+ }
95
+ });
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-external-services",
3
- "version": "5.1.15-alpha.0",
3
+ "version": "5.1.16-alpha.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "crypto-js": "^4.2.0",
20
20
  "csv-parser": "^3.2.0",
21
- "firebase-admin": "^13.5.0",
21
+ "firebase-admin": "^13.6.0",
22
22
  "http-errors": "2.0.0",
23
23
  "module-alias": "^2.2.3",
24
24
  "paypal-rest-sdk": "2.0.0-rc.2",
@@ -35,9 +35,9 @@
35
35
  "eslint": "^9.35.0",
36
36
  "nodemon": "^3.1.10",
37
37
  "typescript": "^5.9.2",
38
- "podverse-helpers": "5.1.15-alpha.0"
38
+ "podverse-helpers": "5.1.16-alpha.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "podverse-helpers": "5.1.15-alpha.0"
41
+ "podverse-helpers": "5.1.16-alpha.0"
42
42
  }
43
43
  }
@@ -1,21 +0,0 @@
1
- import { ILoggerLike } from 'podverse-helpers/dist/lib/backend/logger';
2
- import { SendNotificationOptions } from '@external-services/services/notifications';
3
- type GoogleFCMServiceParams = {
4
- userAgent: string;
5
- authToken: string;
6
- firebaseProjectId: string;
7
- loggerService: ILoggerLike;
8
- };
9
- export declare class GoogleFCMService {
10
- private userAgent;
11
- private authToken;
12
- private firebaseProjectId;
13
- private loggerService;
14
- constructor({ userAgent, authToken, firebaseProjectId, loggerService }: GoogleFCMServiceParams);
15
- private getFcmGoogleApiPath;
16
- sendFcmNewItemDetectedNotification: (account_fcm_tokens: string[], options: SendNotificationOptions) => Promise<void>;
17
- sendFcmLiveItemLiveDetectedNotification: (account_fcm_tokens: string[], options: SendNotificationOptions) => Promise<void>;
18
- sendFCMGoogleApiNotification: (fcmTokens: string[], title: string, body: string, channelIdText: string, notificationType: "live" | "new-item", channelTitle: string, itemTitle: string, channelImage?: string | null, itemImage?: string | null, itemIdText?: string) => Promise<void>;
19
- }
20
- export {};
21
- //# sourceMappingURL=fcm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fcm.d.ts","sourceRoot":"","sources":["../../../src/services/google/fcm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEpF,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,aAAa,CAAc;gBAEvB,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,aAAa,EAAE,EAAE,sBAAsB;IAO9F,OAAO,CAAC,mBAAmB;IAI3B,kCAAkC,GAAU,oBAAoB,MAAM,EAAE,EAAE,SAAS,uBAAuB,mBAsBxG;IAEF,uCAAuC,GAAU,oBAAoB,MAAM,EAAE,EAAE,SAAS,uBAAuB,mBAsB7G;IAEF,4BAA4B,GAC1B,WAAW,MAAM,EAAE,EACnB,OAAO,MAAM,EACb,MAAM,MAAM,EACZ,eAAe,MAAM,EACrB,kBAAkB,MAAM,GAAG,UAAU,EACrC,cAAc,MAAM,EACpB,WAAW,MAAM,EACjB,eAAe,MAAM,GAAG,IAAI,EAC5B,YAAY,MAAM,GAAG,IAAI,EACzB,aAAa,MAAM,mBAuEnB;CACH"}
@@ -1,114 +0,0 @@
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.GoogleFCMService = void 0;
13
- const podverse_helpers_1 = require("podverse-helpers");
14
- class GoogleFCMService {
15
- constructor({ userAgent, authToken, firebaseProjectId, loggerService }) {
16
- this.sendFcmNewItemDetectedNotification = (account_fcm_tokens, options) => __awaiter(this, void 0, void 0, function* () {
17
- const { channelIdText, channelFullImageUrl, itemFullImageUrl, itemIdText } = options;
18
- const channelTitle = options.channelTitle || 'Untitled';
19
- const itemTitle = options.itemTitle || 'Untitled';
20
- const title = channelTitle;
21
- const body = itemTitle;
22
- const finalPodcastImageUrl = channelFullImageUrl;
23
- const finalEpisodeImageUrl = itemFullImageUrl;
24
- return this.sendFCMGoogleApiNotification(account_fcm_tokens, title, body, channelIdText, 'new-item', channelTitle, itemTitle, finalPodcastImageUrl, finalEpisodeImageUrl, itemIdText);
25
- });
26
- this.sendFcmLiveItemLiveDetectedNotification = (account_fcm_tokens, options) => __awaiter(this, void 0, void 0, function* () {
27
- const { channelIdText, channelFullImageUrl, itemFullImageUrl, itemIdText } = options;
28
- const channelTitle = options.channelTitle || 'Untitled';
29
- const itemTitle = options.itemTitle || 'Livestream starting';
30
- const title = `LIVE: ${channelTitle}`;
31
- const body = itemTitle;
32
- const finalPodcastImageUrl = channelFullImageUrl;
33
- const finalEpisodeImageUrl = itemFullImageUrl;
34
- return this.sendFCMGoogleApiNotification(account_fcm_tokens, title, body, channelIdText, 'live', channelTitle, itemTitle, finalPodcastImageUrl, finalEpisodeImageUrl, itemIdText);
35
- });
36
- this.sendFCMGoogleApiNotification = (fcmTokens, title, body, channelIdText, notificationType, channelTitle, itemTitle, channelImage, itemImage, itemIdText) => __awaiter(this, void 0, void 0, function* () {
37
- if (!fcmTokens || fcmTokens.length === 0)
38
- return;
39
- const fcmTokenBatches = [];
40
- const size = 1000;
41
- for (let i = 0; i < fcmTokens.length; i += size) {
42
- fcmTokenBatches.push(fcmTokens.slice(i, i + size));
43
- }
44
- const fcmGoogleApiPath = this.getFcmGoogleApiPath();
45
- for (const fcmTokenBatch of fcmTokenBatches) {
46
- if ((fcmTokenBatch === null || fcmTokenBatch === void 0 ? void 0 : fcmTokenBatch.length) > 0) {
47
- const imageUrl = itemImage || channelImage;
48
- try {
49
- for (const token of fcmTokenBatch) {
50
- yield (0, podverse_helpers_1.request)(fcmGoogleApiPath, {
51
- method: 'POST',
52
- headers: {
53
- 'User-Agent': this.userAgent,
54
- Authorization: `Bearer ${this.authToken}`,
55
- 'Content-Type': 'application/json'
56
- },
57
- data: {
58
- message: {
59
- token,
60
- notification: {
61
- title,
62
- body,
63
- image: imageUrl
64
- },
65
- data: {
66
- podcastId: channelIdText,
67
- episodeId: itemIdText,
68
- podcastTitle: channelTitle,
69
- episodeTitle: itemTitle,
70
- notificationType,
71
- timeSent: new Date().toISOString()
72
- },
73
- android: {
74
- notification: {
75
- image: imageUrl
76
- }
77
- },
78
- apns: {
79
- payload: {
80
- aps: {
81
- 'mutable-content': 1
82
- }
83
- },
84
- fcm_options: {
85
- image: imageUrl
86
- }
87
- },
88
- webpush: {
89
- notification: {
90
- image: imageUrl
91
- }
92
- }
93
- }
94
- },
95
- responseType: 'json'
96
- });
97
- }
98
- }
99
- catch (error) {
100
- this.loggerService.logError('sendFCMGoogleApiNotification error', error);
101
- }
102
- }
103
- }
104
- });
105
- this.userAgent = userAgent;
106
- this.authToken = authToken;
107
- this.firebaseProjectId = firebaseProjectId;
108
- this.loggerService = loggerService;
109
- }
110
- getFcmGoogleApiPath() {
111
- return `https://fcm.googleapis.com/v1/projects/${this.firebaseProjectId}/messages:send`;
112
- }
113
- }
114
- exports.GoogleFCMService = GoogleFCMService;
@@ -1,9 +0,0 @@
1
- export interface FirebaseAccessTokenServiceParams {
2
- keyFilePath: string;
3
- }
4
- export declare class FirebaseAccessTokenService {
5
- private serviceAccount;
6
- constructor({ keyFilePath }: FirebaseAccessTokenServiceParams);
7
- generateAccessToken(): Promise<string>;
8
- }
9
- //# sourceMappingURL=firebaseAccessTokenService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"firebaseAccessTokenService.d.ts","sourceRoot":"","sources":["../../../src/services/google/firebaseAccessTokenService.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gCAAgC;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,0BAA0B;IACrC,OAAO,CAAC,cAAc,CAAM;gBAEhB,EAAE,WAAW,EAAE,EAAE,gCAAgC;IAavD,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;CAI7C"}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.FirebaseAccessTokenService = void 0;
46
- const admin = __importStar(require("firebase-admin"));
47
- const fs = __importStar(require("fs"));
48
- class FirebaseAccessTokenService {
49
- constructor({ keyFilePath }) {
50
- if (!keyFilePath) {
51
- throw new Error('keyFilePath is required');
52
- }
53
- this.serviceAccount = JSON.parse(fs.readFileSync(keyFilePath, 'utf8'));
54
- if (!admin.apps.length) {
55
- admin.initializeApp({
56
- credential: admin.credential.cert(this.serviceAccount),
57
- });
58
- }
59
- }
60
- generateAccessToken() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const token = yield admin.credential.cert(this.serviceAccount).getAccessToken();
63
- return token.access_token;
64
- });
65
- }
66
- }
67
- exports.FirebaseAccessTokenService = FirebaseAccessTokenService;