@lyxa.ai/core 1.4.162 → 1.4.164

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 (36) hide show
  1. package/dist/index.js +11 -13
  2. package/dist/index.js.map +1 -1
  3. package/dist/libraries/index.d.ts +4 -6
  4. package/dist/libraries/index.js +6 -14
  5. package/dist/libraries/index.js.map +1 -1
  6. package/dist/libraries/mongo/models/embedded/delivery-charge-setting.model.d.ts +0 -3
  7. package/dist/libraries/mongo/models/embedded/delivery-charge-setting.model.js +0 -6
  8. package/dist/libraries/mongo/models/embedded/delivery-charge-setting.model.js.map +1 -1
  9. package/dist/libraries/mongo/models/zone.model.d.ts +2 -0
  10. package/dist/libraries/mongo/models/zone.model.js +6 -0
  11. package/dist/libraries/mongo/models/zone.model.js.map +1 -1
  12. package/dist/libraries/notification/firebase-fcm.service.d.ts +7 -0
  13. package/dist/libraries/notification/firebase-fcm.service.js +40 -0
  14. package/dist/libraries/notification/firebase-fcm.service.js.map +1 -0
  15. package/dist/libraries/notification/firebase-message.builder.d.ts +22 -0
  16. package/dist/libraries/notification/firebase-message.builder.js +107 -0
  17. package/dist/libraries/notification/firebase-message.builder.js.map +1 -0
  18. package/dist/libraries/notification/index.d.ts +1 -1
  19. package/dist/libraries/notification/index.js.map +1 -1
  20. package/dist/libraries/notification/lyxa-fcm-sender.d.ts +13 -0
  21. package/dist/libraries/notification/lyxa-fcm-sender.js +104 -0
  22. package/dist/libraries/notification/lyxa-fcm-sender.js.map +1 -0
  23. package/dist/libraries/notification/lyxa-fcm.service.d.ts +42 -0
  24. package/dist/libraries/notification/lyxa-fcm.service.js +174 -0
  25. package/dist/libraries/notification/lyxa-fcm.service.js.map +1 -0
  26. package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
  27. package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
  28. package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
  29. package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
  30. package/dist/types/README.md +1 -1
  31. package/dist/types/package.json +1 -1
  32. package/dist/types/utilities/validation/common-validation.d.ts +12 -12
  33. package/package.json +1 -1
  34. package/dist/libraries/firebase/fcmService.d.ts +0 -38
  35. package/dist/libraries/firebase/fcmService.js +0 -267
  36. package/dist/libraries/firebase/fcmService.js.map +0 -1
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var LyxaFcmSender_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.LyxaFcmSender = void 0;
14
+ const typedi_1 = require("typedi");
15
+ const firebase_fcm_service_1 = require("./firebase-fcm.service");
16
+ const firebase_message_builder_1 = require("./firebase-message.builder");
17
+ const __1 = require("../..");
18
+ let LyxaFcmSender = class LyxaFcmSender {
19
+ static { LyxaFcmSender_1 = this; }
20
+ fcmService;
21
+ builder;
22
+ static MAX_BATCH = 500;
23
+ constructor(fcmService, builder) {
24
+ this.fcmService = fcmService;
25
+ this.builder = builder;
26
+ }
27
+ async sendMessages(project, type, tokens, payload) {
28
+ if (!tokens.length)
29
+ return [];
30
+ const messages = this.buildMultiCastMessages(type, tokens, payload);
31
+ return await this.sendToAllTokens(project, type, payload, messages);
32
+ }
33
+ buildMultiCastMessages(type, tokens, payload) {
34
+ const tokenChunks = this.chunkArray(tokens, LyxaFcmSender_1.MAX_BATCH);
35
+ return tokenChunks.map(chunk => this.builder.buildMessage(type, payload, chunk));
36
+ }
37
+ chunkArray(arr, size) {
38
+ const chunks = [];
39
+ for (let i = 0; i < arr.length; i += size) {
40
+ chunks.push(arr.slice(i, i + size));
41
+ }
42
+ return chunks;
43
+ }
44
+ async sendToAllTokens(project, type, payload, messages) {
45
+ const logger = (0, __1.getLibraries)().getLoggerKit();
46
+ const failedTokens = [];
47
+ await Promise.all(messages.map(async (message) => {
48
+ let logData;
49
+ try {
50
+ const result = await this.fcmService.sendMessage(project, message);
51
+ result.responses.forEach((r, i) => {
52
+ if (!r.success)
53
+ failedTokens.push(message.tokens[i]);
54
+ });
55
+ logData = {
56
+ timestamp: new Date().toISOString(),
57
+ project,
58
+ type,
59
+ consoleNotification: type === firebase_message_builder_1.MultiMessageType.CONSOLE,
60
+ groupTokens: message.tokens,
61
+ groupPayload: payload,
62
+ message,
63
+ response: {
64
+ successCount: result.successCount,
65
+ failureCount: result.failureCount,
66
+ responses: result.responses.map((r, i) => ({
67
+ token: message.tokens[i],
68
+ success: r.success,
69
+ ...(r.error && { errorCode: r.error.code, errorMessage: r.error.message }),
70
+ })),
71
+ },
72
+ };
73
+ logger.info('Called Firebase function sendEachForMulticast', {
74
+ tag: 'notification.attempted.new',
75
+ data: logData,
76
+ });
77
+ }
78
+ catch (err) {
79
+ failedTokens.push(...message.tokens);
80
+ logData = {
81
+ timestamp: new Date().toISOString(),
82
+ project,
83
+ type,
84
+ consoleNotification: type === firebase_message_builder_1.MultiMessageType.CONSOLE,
85
+ groupTokens: message.tokens,
86
+ groupPayload: payload,
87
+ message,
88
+ };
89
+ logger.error('Called Firebase function sendEachForMulticast', err, {
90
+ tag: 'notification.attempted.new',
91
+ data: logData,
92
+ });
93
+ }
94
+ }));
95
+ return failedTokens;
96
+ }
97
+ };
98
+ exports.LyxaFcmSender = LyxaFcmSender;
99
+ exports.LyxaFcmSender = LyxaFcmSender = LyxaFcmSender_1 = __decorate([
100
+ (0, typedi_1.Service)(),
101
+ __metadata("design:paramtypes", [firebase_fcm_service_1.FirebaseFcmService,
102
+ firebase_message_builder_1.FirebaseMessageBuilderFactory])
103
+ ], LyxaFcmSender);
104
+ //# sourceMappingURL=lyxa-fcm-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lyxa-fcm-sender.js","sourceRoot":"/","sources":["libraries/notification/lyxa-fcm-sender.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mCAAiC;AACjC,iEAA4D;AAC5D,yEAA6F;AAG7F,6BAAqC;AAG9B,IAAM,aAAa,GAAnB,MAAM,aAAa;;IAIP;IACA;IAJX,MAAM,CAAU,SAAS,GAAG,GAAG,CAAC;IAEvC,YACkB,UAA8B,EAC9B,OAAsC;QADtC,eAAU,GAAV,UAAU,CAAoB;QAC9B,YAAO,GAAP,OAAO,CAA+B;IACrD,CAAC;IAEG,KAAK,CAAC,YAAY,CACxB,OAAmB,EACnB,IAAsB,EACtB,MAAgB,EAChB,OAA+B;QAE/B,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACpE,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;IAEO,sBAAsB,CAC7B,IAAsB,EACtB,MAAgB,EAChB,OAA+B;QAE/B,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,eAAa,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAClF,CAAC;I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ent":["import { Service } from 'typedi';\nimport { FirebaseFcmService } from './firebase-fcm.service';\nimport { FirebaseMessageBuilderFactory, MultiMessageType } from './firebase-message.builder';\nimport { messaging } from 'firebase-admin';\nimport { FCMNotificationPayload, FcmProject } from './lyxa-fcm.service';\nimport { getLibraries } from '../..';\n\n@Service()\nexport class LyxaFcmSender {\n\tpublic static readonly MAX_BATCH = 500;\n\n\tconstructor(\n\t\tprivate readonly fcmService: FirebaseFcmService,\n\t\tprivate readonly builder: FirebaseMessageBuilderFactory\n\t) {}\n\n\tpublic async sendMessages(\n\t\tproject: FcmProject,\n\t\ttype: MultiMessageType,\n\t\ttokens: string[],\n\t\tpayload: FCMNotificationPayload\n\t): Promise<string[]> {\n\t\tif (!tokens.length) return [];\n\t\tconst messages = this.buildMultiCastMessages(type, tokens, payload);\n\t\treturn await this.sendToAllTokens(project, type, payload, messages);\n\t}\n\n\tprivate buildMultiCastMessages(\n\t\ttype: MultiMessageType,\n\t\ttokens: string[],\n\t\tpayload: FCMNotificationPayload\n\t): messaging.MulticastMessage[] {\n\t\tconst tokenChunks = this.chunkArray(tokens, LyxaFcmSender.MAX_BATCH);\n\t\treturn tokenChunks.map(chunk => this.builder.buildMessage(type, payload, chunk));\n\t}\n\n\tprivate chunkArray<T>(arr: T[], size: number): T[][] {\n\t\tconst chunks: T[][] = [];\n\t\tfor (let i = 0; i < arr.length; i += size) {\n\t\t\tchunks.push(arr.slice(i, i + size));\n\t\t}\n\t\treturn chunks;\n\t}\n\n\tprivate async sendToAllTokens(\n\t\tproject: FcmProject,\n\t\ttype: MultiMessageType,\n\t\tpayload: FCMNotificationPayload,\n\t\tmessages: messaging.MulticastMessage[]\n\t): Promise<string[]> {\n\t\tconst logger = getLibraries().getLoggerKit();\n\t\tconst failedTokens: string[] = [];\n\n\t\tawait Promise.all(\n\t\t\tmessages.map(async message => {\n\t\t\t\tlet logData: Record<string, unknown>;\n\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await this.fcmService.sendMessage(project, message);\n\t\t\t\t\tresult.responses.forEach((r, i) => {\n\t\t\t\t\t\tif (!r.success) failedTokens.push(message.tokens[i]);\n\t\t\t\t\t});\n\n\t\t\t\t\tlogData = {\n\t\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\t\tproject,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tconsoleNotification: type === MultiMessageType.CONSOLE,\n\t\t\t\t\t\tgroupTokens: message.tokens,\n\t\t\t\t\t\tgroupPayload: payload,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tsuccessCount: result.successCount,\n\t\t\t\t\t\t\tfailureCount: result.failureCount,\n\t\t\t\t\t\t\tresponses: result.responses.map((r, i) => ({\n\t\t\t\t\t\t\t\ttoken: message.tokens[i],\n\t\t\t\t\t\t\t\tsuccess: r.success,\n\t\t\t\t\t\t\t\t...(r.error && { errorCode: r.error.code, errorMessage: r.error.message }),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tlogger.info('Called Firebase function sendEachForMulticast', {\n\t\t\t\t\t\ttag: 'notification.attempted.new',\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t});\n\t\t\t\t} catch (err) {\n\t\t\t\t\tfailedTokens.push(...message.tokens);\n\n\t\t\t\t\tlogData = {\n\t\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\t\tproject,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tconsoleNotification: type === MultiMessageType.CONSOLE,\n\t\t\t\t\t\tgroupTokens: message.tokens,\n\t\t\t\t\t\tgroupPayload: payload,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t};\n\t\t\t\t\tlogger.error('Called Firebase function sendEachForMulticast', err, {\n\t\t\t\t\t\ttag: 'notification.attempted.new',\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\n\t\treturn failedTokens;\n\t}\n}\n"]}
@@ -0,0 +1,42 @@
1
+ import { AppPlatform, NotificationAccountType } from '../../utilities/enum';
2
+ import { LyxaFcmSender } from './lyxa-fcm-sender';
3
+ export declare enum FcmProject {
4
+ USER = "fcm.service.user",
5
+ RIDER = "fcm.service.rider",
6
+ SHOP = "fcm.service.shop",
7
+ CPANEL = "fcm.service.cpanel"
8
+ }
9
+ export interface FCMNotificationPayload {
10
+ title?: string;
11
+ body?: string;
12
+ data?: Record<string, string>;
13
+ sound?: string;
14
+ invisible?: boolean;
15
+ }
16
+ export interface NotificationTokenTarget {
17
+ token: string;
18
+ entityType: NotificationAccountType;
19
+ deviceId?: string;
20
+ entityId?: string;
21
+ platform?: AppPlatform;
22
+ appVersion?: string;
23
+ }
24
+ export type LyxaTokens = {
25
+ oldTokens: string[];
26
+ newTokens: string[];
27
+ consoleTokens: string[];
28
+ };
29
+ export declare class LyxaFcmService {
30
+ private readonly lyxaFcmSender;
31
+ constructor(lyxaFcmSender: LyxaFcmSender);
32
+ private deduplicateTargets;
33
+ private separateTokens;
34
+ static getProjectForAccountType(accountType: NotificationAccountType): FcmProject;
35
+ sendToTokens(project: FcmProject, payload: FCMNotificationPayload, targets: NotificationTokenTarget[]): Promise<{
36
+ failedTokens: string[];
37
+ }>;
38
+ private isNotifiableEntityType;
39
+ private isConsoleEntityType;
40
+ private compareVersions;
41
+ private shouldUseNewStructure;
42
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LyxaFcmService = exports.FcmProject = void 0;
13
+ const typedi_1 = require("typedi");
14
+ const firebase_message_builder_1 = require("./firebase-message.builder");
15
+ const enum_1 = require("../../utilities/enum");
16
+ const lyxa_fcm_sender_1 = require("./lyxa-fcm-sender");
17
+ const __1 = require("../..");
18
+ var FcmProject;
19
+ (function (FcmProject) {
20
+ FcmProject["USER"] = "fcm.service.user";
21
+ FcmProject["RIDER"] = "fcm.service.rider";
22
+ FcmProject["SHOP"] = "fcm.service.shop";
23
+ FcmProject["CPANEL"] = "fcm.service.cpanel";
24
+ })(FcmProject || (exports.FcmProject = FcmProject = {}));
25
+ const NotificationVersionRules = {
26
+ [enum_1.NotificationAccountType.RIDER]: {
27
+ [enum_1.AppPlatform.IOS]: '2.0.3',
28
+ [enum_1.AppPlatform.ANDROID]: '2.0.4',
29
+ },
30
+ [enum_1.NotificationAccountType.USER]: {
31
+ [enum_1.AppPlatform.IOS]: '2.0.3',
32
+ [enum_1.AppPlatform.ANDROID]: '2.0.3',
33
+ },
34
+ [enum_1.NotificationAccountType.SHOP]: {
35
+ [enum_1.AppPlatform.IOS]: '2.0.3',
36
+ [enum_1.AppPlatform.ANDROID]: '2.0.3',
37
+ },
38
+ [enum_1.NotificationAccountType.PROFESSIONAL]: {
39
+ [enum_1.AppPlatform.IOS]: '2.0.3',
40
+ [enum_1.AppPlatform.ANDROID]: '2.0.3',
41
+ },
42
+ };
43
+ let LyxaFcmService = class LyxaFcmService {
44
+ lyxaFcmSender;
45
+ constructor(lyxaFcmSender) {
46
+ this.lyxaFcmSender = lyxaFcmSender;
47
+ }
48
+ deduplicateTargets(targets) {
49
+ const sorted = targets.slice().sort((a, b) => {
50
+ if (a.token !== b.token)
51
+ return a.token < b.token ? -1 : 1;
52
+ if (!a.appVersion && !b.appVersion)
53
+ return 0;
54
+ if (!a.appVersion)
55
+ return 1;
56
+ if (!b.appVersion)
57
+ return -1;
58
+ return this.compareVersions(b.appVersion, a.appVersion);
59
+ });
60
+ return sorted.filter((t, i) => i === 0 || t.token !== sorted[i - 1].token);
61
+ }
62
+ separateTokens(targets) {
63
+ const oldTokens = [];
64
+ const newTokens = [];
65
+ const consoleTokens = [];
66
+ for (const t of targets) {
67
+ if (this.isConsoleEntityType(t.entityType)) {
68
+ consoleTokens.push(t.token);
69
+ continue;
70
+ }
71
+ const useNew = this.shouldUseNewStructure(t.entityType, t.platform, t.appVersion);
72
+ if (useNew)
73
+ newTokens.push(t.token);
74
+ else
75
+ oldTokens.push(t.token);
76
+ }
77
+ if (true) {
78
+ (0, __1.getLibraries)()
79
+ .getLoggerKit()
80
+ .debug('FCM token separation', {
81
+ tag: 'notification.token.separated',
82
+ data: {
83
+ totalTargets: targets.length,
84
+ buckets: {
85
+ old: oldTokens.length,
86
+ new: newTokens.length,
87
+ console: consoleTokens.length,
88
+ },
89
+ targets: targets.map(t => ({
90
+ entityId: t.entityId,
91
+ entityType: t.entityType,
92
+ platform: t.platform,
93
+ appVersion: t.appVersion,
94
+ bucket: this.isConsoleEntityType(t.entityType)
95
+ ? 'console'
96
+ : this.shouldUseNewStructure(t.entityType, t.platform, t.appVersion)
97
+ ? 'new'
98
+ : 'old',
99
+ })),
100
+ },
101
+ });
102
+ }
103
+ return {
104
+ oldTokens,
105
+ newTokens,
106
+ consoleTokens,
107
+ };
108
+ }
109
+ static getProjectForAccountType(accountType) {
110
+ switch (accountType) {
111
+ case enum_1.NotificationAccountType.USER:
112
+ return FcmProject.USER;
113
+ case enum_1.NotificationAccountType.SHOP:
114
+ case enum_1.NotificationAccountType.PROFESSIONAL:
115
+ return FcmProject.SHOP;
116
+ case enum_1.NotificationAccountType.RIDER:
117
+ return FcmProject.RIDER;
118
+ default:
119
+ return FcmProject.USER;
120
+ }
121
+ }
122
+ async sendToTokens(project, payload, targets) {
123
+ if (!targets.length)
124
+ return { failedTokens: [] };
125
+ console.log('targets', targets);
126
+ const cleanedTargets = this.deduplicateTargets(targets);
127
+ console.log('cleanedTargets', cleanedTargets);
128
+ const tokens = this.separateTokens(cleanedTargets);
129
+ const results = await Promise.all([
130
+ this.lyxaFcmSender.sendMessages(project, firebase_message_builder_1.MultiMessageType.OLD, tokens.oldTokens, payload),
131
+ this.lyxaFcmSender.sendMessages(project, firebase_message_builder_1.MultiMessageType.DEFAULT, tokens.newTokens, payload),
132
+ this.lyxaFcmSender.sendMessages(FcmProject.CPANEL, firebase_message_builder_1.MultiMessageType.CONSOLE, tokens.consoleTokens, payload),
133
+ ]);
134
+ return { failedTokens: results.flat() };
135
+ }
136
+ isNotifiableEntityType(type) {
137
+ return (type === enum_1.NotificationAccountType.USER ||
138
+ type === enum_1.NotificationAccountType.RIDER ||
139
+ type === enum_1.NotificationAccountType.SHOP ||
140
+ type === enum_1.NotificationAccountType.PROFESSIONAL);
141
+ }
142
+ isConsoleEntityType(type) {
143
+ return (type === enum_1.NotificationAccountType.SHOP_CONSOLE ||
144
+ type === enum_1.NotificationAccountType.PARENT ||
145
+ type === enum_1.NotificationAccountType.VENDOR ||
146
+ type === enum_1.NotificationAccountType.VENDOR_PARENT);
147
+ }
148
+ compareVersions(v1, v2) {
149
+ const a = v1.split('.').map(Number);
150
+ const b = v2.split('.').map(Number);
151
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
152
+ const diff = (a[i] || 0) - (b[i] || 0);
153
+ if (diff !== 0)
154
+ return diff;
155
+ }
156
+ return 0;
157
+ }
158
+ shouldUseNewStructure(entityType, platform, version) {
159
+ if (!this.isNotifiableEntityType(entityType))
160
+ return false;
161
+ if (!platform || !version)
162
+ return false;
163
+ const minVersion = NotificationVersionRules?.[entityType]?.[platform];
164
+ if (!minVersion)
165
+ return false;
166
+ return this.compareVersions(version, minVersion) >= 0;
167
+ }
168
+ };
169
+ exports.LyxaFcmService = LyxaFcmService;
170
+ exports.LyxaFcmService = LyxaFcmService = __decorate([
171
+ (0, typedi_1.Service)(),
172
+ __metadata("design:paramtypes", [lyxa_fcm_sender_1.LyxaFcmSender])
173
+ ], LyxaFcmService);
174
+ //# sourceMappingURL=lyxa-fcm.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lyxa-fcm.service.js","sourceRoot":"/","sources":["libraries/notification/lyxa-fcm.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AACjC,yEAA8D;AAC9D,+CAA4E;AAC5E,uDAAkD;AAClD,6BAAqC;AAErC,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,uCAAyB,CAAA;IACzB,yCAA2B,CAAA;IAC3B,uCAAyB,CAAA;IACzB,2CAA6B,CAAA;AAC9B,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAyBD,MAAM,wBAAwB,GAAuE;IACpG,CAAC,8BAAuB,CAAC,KAAK,CAAC,EAAE;QAChC,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,OAAO;QAC1B,CAAC,kBAAW,CAAC,OAAO,CAAC,EAAE,OAAO;KAC9B;IAED,CAAC,8BAAuB,CAAC,IAAI,CAAC,EAAE;QAC/B,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,OAAO;QAC1B,CAAC,kBAAW,CAAC,OAAO,CAAC,EAAE,OAAO;KAC9B;IAED,CAAC,8BAAuB,CAAC,IAAI,CAAC,EAAE;QAC/B,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,OAAO;QAC1B,CAAC,kBAAW,CAAC,OAAO,CAAC,EAAE,OAAO;KAC9B;IAED,CAAC,8BAAuB,CAAC,YAAY,CAAC,EAAE;QACvC,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,OAAO;QAC1B,CAAC,kBAAW,CAAC,OAAO,CAAC,EAAE,OAAO;KAC9B;CACD,CAAC;AASK,IAAM,cAAc,GAApB,MAAM,cAAc;IACG;IAA7B,YAA6B,aAA4B;QAA5B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E,OAAO,KAAK,CAAC;QAE3D,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QAExC,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;QAEtE,IAAI,CAAC,UAAU;YAAE,OAAO,KAAK,CAAC;QAE9B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;CACD,CAAA;AArJY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,gBAAO,GAAE;qCAEmC,+BAAa;GAD7C,cAAc,CAqJ1B","sourcesContent":["import { Service } from 'typedi';\nimport { MultiMessageType } from './firebase-message.builder';\nimport { AppPlatform, NotificationAccountType } from '../../utilities/enum';\nimport { LyxaFcmSender } from './lyxa-fcm-sender';\nimport { getLibraries } from '../..';\n\nexport enum FcmProject {\n\tUSER = 'fcm.service.user',\n\tRIDER = 'fcm.service.rider',\n\tSHOP = 'fcm.service.shop',\n\tCPANEL = 'fcm.service.cpanel',\n}\n\nexport interface FCMNotificationPayload {\n\ttitle?: string;\n\tbody?: string;\n\tdata?: Record<string, string>;\n\tsound?: string;\n\tinvisible?: boolean;\n}\n\nexport interface NotificationTokenTarget {\n\ttoken: string;\n\tentityType: NotificationAccountType;\n\tdeviceId?: string;\n\tentityId?: string;\n\tplatform?: AppPlatform;\n\tappVersion?: string;\n}\n\ntype NotifiableEntityType =\n\t| NotificationAccountType.USER\n\t| NotificationAccountType.SHOP\n\t| NotificationAccountType.RIDER\n\t| NotificationAccountType.PROFESSIONAL;\n\nconst NotificationVersionRules: Record<NotifiableEntityType, Partial<Record<AppPlatform, string>>> = {\n\t[NotificationAccountType.RIDER]: {\n\t\t[AppPlatform.IOS]: '2.0.3',\n\t\t[AppPlatform.ANDROID]: '2.0.4',\n\t},\n\n\t[NotificationAccountType.USER]: {\n\t\t[AppPlatform.IOS]: '2.0.3',\n\t\t[AppPlatform.ANDROID]: '2.0.3',\n\t},\n\n\t[NotificationAccountType.SHOP]: {\n\t\t[AppPlatform.IOS]: '2.0.3',\n\t\t[AppPlatform.ANDROID]: '2.0.3',\n\t},\n\n\t[NotificationAccountType.PROFESSIONAL]: {\n\t\t[AppPlatform.IOS]: '2.0.3',\n\t\t[AppPlatform.ANDROID]: '2.0.3',\n\t},\n};\n\nexport type LyxaTokens = {\n\toldTokens: string[];\n\tnewTokens: string[];\n\tconsoleTokens: string[];\n};\n\n@Service()\nexport class LyxaFcmService {\n\tconstructor(private readonly lyxaFcmSender: LyxaFcmSender) {}\n\n\tprivate deduplicateTargets(targets: NotificationTokenTarget[]): NotificationTokenTarget[] {\n\t\tconst sorted = targets.slice().sort((a, b) => {\n\t\t\tif (a.token !== b.token) return a.token < b.token ? -1 : 1;\n\t\t\tif (!a.appVersion && !b.appVersion) return 0;\n\t\t\tif (!a.appVersion) return 1;\n\t\t\tif (!b.appVersion) return -1;\n\t\t\treturn this.compareVersions(b.appVersion, a.appVersion);\n\t\t});\n\t\treturn sorted.filter((t, i) => i === 0 || t.token !== sorted[i - 1].token);\n\t}\n\n\tprivate separateTokens(targets: NotificationTokenTarget[]): LyxaTokens {\n\t\tconst oldTokens: string[] = [];\n\t\tconst newTokens: string[] = [];\n\t\tconst consoleTokens: string[] = [];\n\n\t\tfor (const t of targets) {\n\t\t\tif (this.isConsoleEntityType(t.entityType)) {\n\t\t\t\tconsoleTokens.push(t.token);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst useNew = this.shouldUseNewStructure(t.entityType, t.platform, t.appVersion);\n\n\t\t\tif (useNew) newTokens.push(t.token);\n\t\t\telse oldTokens.push(t.token);\n\t\t}\n\n\t\tif (true) {\n\t\t\tgetLibraries()\n\t\t\t\t.getLoggerKit()\n\t\t\t\t.debug('FCM token separation', {\n\t\t\t\t\ttag: 'notification.token.separated',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttotalTargets: targets.length,\n\t\t\t\t\t\tbuckets: {\n\t\t\t\t\t\t\told: oldTokens.length,\n\t\t\t\t\t\t\tnew: newTokens.length,\n\t\t\t\t\t\t\tconsole: consoleTokens.length,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttargets: targets.map(t => ({\n\t\t\t\t\t\t\tentityId: t.entityId,\n\t\t\t\t\t\t\tentityType: t.entityType,\n\t\t\t\t\t\t\tplatform: t.platform,\n\t\t\t\t\t\t\tappVersion: t.appVersion,\n\t\t\t\t\t\t\tbucket: this.isConsoleEntityType(t.entityType)\n\t\t\t\t\t\t\t\t? 'console'\n\t\t\t\t\t\t\t\t: this.shouldUseNewStructure(t.entityType, t.platform, t.appVersion)\n\t\t\t\t\t\t\t\t\t? 'new'\n\t\t\t\t\t\t\t\t\t: 'old',\n\t\t\t\t\t\t})),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\toldTokens,\n\t\t\tnewTokens,\n\t\t\tconsoleTokens,\n\t\t};\n\t}\n\n\tpublic static getProjectForAccountType(accountType: NotificationAccountType): FcmProject {\n\t\tswitch (accountType) {\n\t\t\tcase NotificationAccountType.USER:\n\t\t\t\treturn FcmProject.USER;\n\t\t\tcase NotificationAccountType.SHOP:\n\t\t\tcase NotificationAccountType.PROFESSIONAL:\n\t\t\t\treturn FcmProject.SHOP;\n\t\t\tcase NotificationAccountType.RIDER:\n\t\t\t\treturn FcmProject.RIDER;\n\t\t\tdefault:\n\t\t\t\treturn FcmProject.USER;\n\t\t}\n\t}\n\n\tpublic async sendToTokens(\n\t\tproject: FcmProject,\n\t\tpayload: FCMNotificationPayload,\n\t\ttargets: NotificationTokenTarget[]\n\t): Promise<{ failedTokens: string[] }> {\n\t\tif (!targets.length) return { failedTokens: [] };\n\t\tconsole.log('targets', targets);\n\t\tconst cleanedTargets = this.deduplicateTargets(targets);\n\t\tconsole.log('cleanedTargets', cleanedTargets);\n\t\tconst tokens = this.separateTokens(cleanedTargets);\n\n\t\tconst results = await Promise.all([\n\t\t\tthis.lyxaFcmSender.sendMessages(project, MultiMessageType.OLD, tokens.oldTokens, payload),\n\t\t\tthis.lyxaFcmSender.sendMessages(project, MultiMessageType.DEFAULT, tokens.newTokens, payload),\n\t\t\tthis.lyxaFcmSender.sendMessages(\n\t\t\t\tFcmProject.CPANEL,\n\t\t\t\tMultiMessageType.CONSOLE,\n\t\t\t\ttokens.consoleTokens,\n\t\t\t\tpayload\n\t\t\t),\n\t\t]);\n\n\t\treturn { failedTokens: results.flat() };\n\t}\n\n\tprivate isNotifiableEntityType(type: NotificationAccountType): type is NotifiableEntityType {\n\t\treturn (\n\t\t\ttype === NotificationAccountType.USER ||\n\t\t\ttype === NotificationAccountType.RIDER ||\n\t\t\ttype === NotificationAccountType.SHOP ||\n\t\t\ttype === NotificationAccountType.PROFESSIONAL\n\t\t);\n\t}\n\n\tprivate isConsoleEntityType(type: NotificationAccountType): type is NotifiableEntityType {\n\t\treturn (\n\t\t\ttype === NotificationAccountType.SHOP_CONSOLE ||\n\t\t\ttype === NotificationAccountType.PARENT ||\n\t\t\ttype === NotificationAccountType.VENDOR ||\n\t\t\ttype === NotificationAccountType.VENDOR_PARENT\n\t\t);\n\t}\n\n\tprivate compareVersions(v1: string, v2: string): number {\n\t\tconst a = v1.split('.').map(Number);\n\t\tconst b = v2.split('.').map(Number);\n\n\t\tfor (let i = 0; i < Math.max(a.length, b.length); i++) {\n\t\t\tconst diff = (a[i] || 0) - (b[i] || 0);\n\t\t\tif (diff !== 0) return diff;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tprivate shouldUseNewStructure(\n\t\tentityType: NotificationAccountType,\n\t\tplatform?: AppPlatform,\n\t\tversion?: string\n\t): boolean {\n\t\tif (!this.isNotifiableEntityType(entityType)) return false;\n\n\t\tif (!platform || !version) return false;\n\n\t\tconst minVersion = NotificationVersionRules?.[entityType]?.[platform];\n\n\t\tif (!minVersion) return false;\n\n\t\treturn this.compareVersions(version, minVersion) >= 0;\n\t}\n}\n"]}
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
- req: import("http").IncomingMessage;
9
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
10
9
  tokenType: TokenType | undefined;
10
+ req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
4
4
  allowedRoles: string[];
5
5
  }
6
6
  export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
7
- req: import("http").IncomingMessage;
8
7
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
8
  tokenType: import("../../auth").TokenType | undefined;
9
+ req: import("http").IncomingMessage;
10
10
  requestId: string | undefined;
11
11
  entity: import("../context").EntityContext | undefined;
12
12
  usedRefreshToken: boolean | undefined;
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
3
3
  entityTypes: AuthEntityType[];
4
4
  }
5
5
  export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
6
- req: import("http").IncomingMessage;
7
6
  res: import("http").ServerResponse<import("http").IncomingMessage>;
8
7
  tokenType: import("../../auth").TokenType | undefined;
8
+ req: import("http").IncomingMessage;
9
9
  requestId: string | undefined;
10
10
  entity: import("../context").EntityContext | undefined;
11
11
  usedRefreshToken: boolean | undefined;
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
- req: import("http").IncomingMessage;
9
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
10
9
  tokenType: TokenType | undefined;
10
+ req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.4.162
25
+ Version: 1.4.164
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.4.162",
3
+ "version": "1.4.164",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- populate?: any;
30
29
  select?: Record<string, 0 | 1> | undefined;
30
+ populate?: any;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- populate?: any;
40
39
  select?: Record<string, 0 | 1> | undefined;
40
+ populate?: any;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -736,12 +736,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
736
736
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
737
737
  }, "strip", z.ZodTypeAny, {
738
738
  _id: import("mongoose").Types.ObjectId;
739
- populate?: any;
740
739
  select?: Record<string, 0 | 1> | undefined;
740
+ populate?: any;
741
741
  }, {
742
742
  _id: string | import("mongoose").Types.ObjectId;
743
- populate?: any;
744
743
  select?: Record<string, 0 | 1> | undefined;
744
+ populate?: any;
745
745
  }>;
746
746
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
747
747
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -754,12 +754,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
754
754
  _id: import("mongoose").Types.ObjectId;
755
755
  withAttributeHiddenItems: boolean;
756
756
  withAddonsHiddenItems: boolean;
757
- populate?: any;
758
757
  select?: Record<string, 0 | 1> | undefined;
758
+ populate?: any;
759
759
  }, {
760
760
  _id: string | import("mongoose").Types.ObjectId;
761
- populate?: any;
762
761
  select?: Record<string, 0 | 1> | undefined;
762
+ populate?: any;
763
763
  withAttributeHiddenItems?: boolean | undefined;
764
764
  withAddonsHiddenItems?: boolean | undefined;
765
765
  }>;
@@ -773,15 +773,15 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
773
773
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
774
774
  }, "strip", z.ZodTypeAny, {
775
775
  _id: import("mongoose").Types.ObjectId;
776
- populate?: any;
777
776
  select?: Record<string, 0 | 1> | undefined;
777
+ populate?: any;
778
778
  groupByCategories?: boolean | undefined;
779
779
  getParentCategory?: boolean | undefined;
780
780
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
781
781
  }, {
782
782
  _id: string | import("mongoose").Types.ObjectId;
783
- populate?: any;
784
783
  select?: Record<string, 0 | 1> | undefined;
784
+ populate?: any;
785
785
  groupByCategories?: boolean | undefined;
786
786
  getParentCategory?: boolean | undefined;
787
787
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
@@ -791,11 +791,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
791
791
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
792
792
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
793
793
  }, "strip", z.ZodTypeAny, {
794
- populate?: any;
795
794
  select?: Record<string, 0 | 1> | undefined;
796
- }, {
797
795
  populate?: any;
796
+ }, {
798
797
  select?: Record<string, 0 | 1> | undefined;
798
+ populate?: any;
799
799
  }>>;
800
800
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
801
801
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -803,12 +803,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
803
803
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
804
804
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
805
805
  }, "strip", z.ZodTypeAny, {
806
- populate?: any;
807
806
  select?: Record<string, 0 | 1> | undefined;
807
+ populate?: any;
808
808
  query?: Record<string, any> | undefined;
809
809
  }, {
810
- populate?: any;
811
810
  select?: Record<string, 0 | 1> | undefined;
811
+ populate?: any;
812
812
  query?: Record<string, any> | undefined;
813
813
  }>;
814
814
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.4.162",
3
+ "version": "1.4.164",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -1,38 +0,0 @@
1
- import { App } from 'firebase-admin/app';
2
- import { AppPlatform, NotificationAccountType } from '../../utilities/enum';
3
- export interface FCMNotificationPayload {
4
- title?: string;
5
- body?: string;
6
- data?: Record<string, string>;
7
- sound?: string;
8
- invisible?: boolean;
9
- }
10
- export interface NotificationTokenTarget {
11
- token: string;
12
- entityType: NotificationAccountType;
13
- deviceId?: string;
14
- entityId?: string;
15
- platform?: AppPlatform;
16
- appVersion?: string;
17
- }
18
- export declare const FCMServiceForUser = "fcm.service.user";
19
- export declare const FCMServiceForRider = "fcm.service.rider";
20
- export declare const FCMServiceForShop = "fcm.service.shop";
21
- export declare const FCMServiceForCpanel = "fcm.service.cpanel";
22
- export declare class FCMService {
23
- private messaging;
24
- private static readonly MAX_BATCH;
25
- constructor(app?: App);
26
- private chunkArray;
27
- private compareVersions;
28
- private isNotifiableEntityType;
29
- private isConsoleEntityType;
30
- private shouldUseNewStructure;
31
- private buildConsoleMessage;
32
- private buildMessage;
33
- private buildOldMessage;
34
- sendNotification(payload: FCMNotificationPayload, targets: NotificationTokenTarget[]): Promise<{
35
- successTokens: string[];
36
- failedTokens: string[];
37
- }>;
38
- }