@lyxa.ai/core 1.4.10 → 1.4.12
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/dist/libraries/firebase/fcmService.d.ts +2 -0
- package/dist/libraries/firebase/fcmService.js +55 -11
- package/dist/libraries/firebase/fcmService.js.map +1 -1
- package/dist/libraries/mongo/models/vendor-access-control.model.d.ts +6 -5
- package/dist/libraries/mongo/models/vendor-access-control.model.js +5 -0
- package/dist/libraries/mongo/models/vendor-access-control.model.js.map +1 -1
- package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +12 -12
- package/package.json +1 -1
|
@@ -26,7 +26,9 @@ export declare class FCMService {
|
|
|
26
26
|
private chunkArray;
|
|
27
27
|
private compareVersions;
|
|
28
28
|
private isNotifiableEntityType;
|
|
29
|
+
private isConsoleEntityType;
|
|
29
30
|
private shouldUseNewStructure;
|
|
31
|
+
private buildConsoleMessage;
|
|
30
32
|
private buildMessage;
|
|
31
33
|
private buildOldMessage;
|
|
32
34
|
sendNotification(payload: FCMNotificationPayload, targets: NotificationTokenTarget[]): Promise<{
|
|
@@ -63,6 +63,9 @@ let FCMService = class FCMService {
|
|
|
63
63
|
type === enum_1.NotificationAccountType.RIDER ||
|
|
64
64
|
type === enum_1.NotificationAccountType.SHOP);
|
|
65
65
|
}
|
|
66
|
+
isConsoleEntityType(type) {
|
|
67
|
+
return type === enum_1.NotificationAccountType.SHOP_CONSOLE;
|
|
68
|
+
}
|
|
66
69
|
shouldUseNewStructure(entityType, platform, version) {
|
|
67
70
|
if (!this.isNotifiableEntityType(entityType))
|
|
68
71
|
return false;
|
|
@@ -73,6 +76,19 @@ let FCMService = class FCMService {
|
|
|
73
76
|
return false;
|
|
74
77
|
return this.compareVersions(version, minVersion) >= 0;
|
|
75
78
|
}
|
|
79
|
+
buildConsoleMessage(payload, batchTokens) {
|
|
80
|
+
const isInvisible = payload.invisible === true;
|
|
81
|
+
const channelId = payload.sound ? 'order_alert' : 'default';
|
|
82
|
+
const message = {
|
|
83
|
+
data: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },
|
|
84
|
+
notification: {
|
|
85
|
+
title: payload.title,
|
|
86
|
+
body: payload.body,
|
|
87
|
+
},
|
|
88
|
+
tokens: batchTokens,
|
|
89
|
+
};
|
|
90
|
+
return message;
|
|
91
|
+
}
|
|
76
92
|
buildMessage(payload, batchTokens) {
|
|
77
93
|
const isInvisible = payload.invisible === true;
|
|
78
94
|
const channelId = payload.sound ? 'order_alert' : 'default';
|
|
@@ -143,31 +159,42 @@ let FCMService = class FCMService {
|
|
|
143
159
|
const logger = (0, __1.getLibraries)().getLoggerKit();
|
|
144
160
|
const oldTokens = [];
|
|
145
161
|
const newTokens = [];
|
|
162
|
+
const consoleTokens = [];
|
|
146
163
|
for (const t of targets) {
|
|
164
|
+
if (this.isConsoleEntityType(t.entityType)) {
|
|
165
|
+
consoleTokens.push(t.token);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
147
168
|
const useNew = this.shouldUseNewStructure(t.entityType, t.platform, t.appVersion);
|
|
148
169
|
if (useNew)
|
|
149
170
|
newTokens.push(t.token);
|
|
150
171
|
else
|
|
151
172
|
oldTokens.push(t.token);
|
|
152
173
|
}
|
|
153
|
-
const sendGroup = async (
|
|
154
|
-
const tokenChunks = this.chunkArray(groupTokens, FCMService_1.MAX_BATCH);
|
|
174
|
+
const sendGroup = async (data) => {
|
|
175
|
+
const tokenChunks = this.chunkArray(data.groupTokens, FCMService_1.MAX_BATCH);
|
|
155
176
|
const success = [];
|
|
156
177
|
const failed = [];
|
|
157
178
|
const results = await Promise.all(tokenChunks.map(async (chunk) => {
|
|
158
|
-
const message =
|
|
159
|
-
? this.
|
|
160
|
-
:
|
|
179
|
+
const message = data.consoleNotification
|
|
180
|
+
? this.buildConsoleMessage(data.groupPayload, chunk)
|
|
181
|
+
: data.oldNotificationStructure
|
|
182
|
+
? this.buildOldMessage(data.groupPayload, chunk)
|
|
183
|
+
: this.buildMessage(data.groupPayload, chunk);
|
|
161
184
|
const response = await this.messaging.sendEachForMulticast(message);
|
|
162
185
|
const logEntry = {
|
|
163
186
|
timestamp: new Date().toISOString(),
|
|
164
|
-
groupTokens,
|
|
165
|
-
groupPayload,
|
|
166
|
-
oldNotificationStructure,
|
|
187
|
+
groupTokens: data.groupTokens,
|
|
188
|
+
groupPayload: data.groupPayload,
|
|
189
|
+
oldNotificationStructure: data.oldNotificationStructure,
|
|
190
|
+
consoleNotification: data.consoleNotification,
|
|
167
191
|
message,
|
|
168
192
|
response,
|
|
169
193
|
};
|
|
170
|
-
logger.debug('Called Firebase function sendEachForMulticast', {
|
|
194
|
+
logger.debug('Called Firebase function sendEachForMulticast', {
|
|
195
|
+
tag: enum_1.LogTag.NOTIFICATION_ATTEMPTED,
|
|
196
|
+
data: logEntry,
|
|
197
|
+
});
|
|
171
198
|
const batchSuccess = [];
|
|
172
199
|
const batchFailed = [];
|
|
173
200
|
response.responses.forEach((resp, idx) => {
|
|
@@ -194,12 +221,29 @@ let FCMService = class FCMService {
|
|
|
194
221
|
let successTokens = [];
|
|
195
222
|
let failedTokens = [];
|
|
196
223
|
if (oldTokens.length) {
|
|
197
|
-
const r = await sendGroup(
|
|
224
|
+
const r = await sendGroup({
|
|
225
|
+
groupTokens: oldTokens,
|
|
226
|
+
groupPayload: payload,
|
|
227
|
+
oldNotificationStructure: true,
|
|
228
|
+
});
|
|
198
229
|
successTokens.push(...r.success);
|
|
199
230
|
failedTokens.push(...r.failed);
|
|
200
231
|
}
|
|
201
232
|
if (newTokens.length) {
|
|
202
|
-
const r = await sendGroup(
|
|
233
|
+
const r = await sendGroup({
|
|
234
|
+
groupTokens: newTokens,
|
|
235
|
+
groupPayload: payload,
|
|
236
|
+
oldNotificationStructure: false,
|
|
237
|
+
});
|
|
238
|
+
successTokens.push(...r.success);
|
|
239
|
+
failedTokens.push(...r.failed);
|
|
240
|
+
}
|
|
241
|
+
if (consoleTokens.length) {
|
|
242
|
+
const r = await sendGroup({
|
|
243
|
+
groupTokens: consoleTokens,
|
|
244
|
+
groupPayload: payload,
|
|
245
|
+
consoleNotification: true,
|
|
246
|
+
});
|
|
203
247
|
successTokens.push(...r.success);
|
|
204
248
|
failedTokens.push(...r.failed);
|
|
205
249
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fcmService.js","sourceRoot":"/","sources":["libraries/firebase/fcmService.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mDAA2C;AAC3C,6BAAqC;AACrC,mCAAiC;AAEjC,+CAAoF;AAwBpF,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;CACD,CAAC;AAEW,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AACvC,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AACvC,QAAA,mBAAmB,GAAG,oBAAoB,CAAC;AAGjD,IAAM,UAA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,EAAE,CAAC;QACjC,IAAI,YAAY,GAAa,EAAE,CAAC;QAGhC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAEpD,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAGD,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAErD,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;IACxC,CAAC;;AAnPW,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAoPtB","sourcesContent":["import { messaging } from 'firebase-admin';\nimport { getLibraries } from '../..';\nimport { Service } from 'typedi';\nimport { App } from 'firebase-admin/app';\nimport { AppPlatform, LogTag, NotificationAccountType } from '../../utilities/enum';\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\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\nexport const FCMServiceForUser = 'fcm.service.user';\nexport const FCMServiceForRider = 'fcm.service.rider';\nexport const FCMServiceForShop = 'fcm.service.shop';\nexport const FCMServiceForCpanel = 'fcm.service.cpanel';\n\n@Service()\nexport class FCMService {\n\tprivate messaging!: messaging.Messaging;\n\tprivate static readonly MAX_BATCH = 500;\n\n\tconstructor(app?: App) {\n\t\tconst firebaseApp = app ?? getLibraries().getFirebaseService().superApp;\n\t\tthis.messaging = messaging(firebaseApp);\n\t}\n\n\t/**\n\t * Split array into chunks of fixed size\n\t */\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 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 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);\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\t/**\n\t * Build multicast message safely\n\t */\n\tprivate buildMessage(payload: FCMNotificationPayload, batchTokens: string[]): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t\tandroid: {\n\t\t\t\tpriority: 'high',\n\t\t\t\tnotification: {\n\t\t\t\t\tchannelId: 'silent',\n\t\t\t\t},\n\t\t\t},\n\t\t\tapns: {\n\t\t\t\tpayload: {\n\t\t\t\t\taps: {\n\t\t\t\t\t\tsound: payload.sound || 'default',\n\t\t\t\t\t\tcontentAvailable: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\theaders: {\n\t\t\t\t\t'apns-push-type': 'background',\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Build multicast message safely for old apps\n\t */\n\tprivate buildOldMessage(\n\t\tpayload: FCMNotificationPayload,\n\t\tbatchTokens: string[]\n\t): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: payload.data || {},\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t\tandroid: { priority: 'high' },\n\t\t\tapns: {\n\t\t\t\tpayload: {\n\t\t\t\t\taps: {\n\t\t\t\t\t\tsound: payload.sound || 'default',\n\t\t\t\t\t\tcontentAvailable: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tif (!isInvisible) {\n\t\t\tmessage.notification = {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t};\n\n\t\t\tmessage.android = {\n\t\t\t\tpriority: 'high',\n\t\t\t\tnotification: {\n\t\t\t\t\tchannelId: payload.sound ? 'android_Push_Notification_Channel_1' : 'default',\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Sends a push notification (visible or invisible) to multiple device tokens\n\t * @param payload - Notification title, body, and optional data\n\t * @param tokens - FCM device tokens\n\t * @returns Object containing success and invalid tokens\n\t */\n\tasync sendNotification(\n\t\tpayload: FCMNotificationPayload,\n\t\ttargets: NotificationTokenTarget[]\n\t): Promise<{ successTokens: string[]; failedTokens: string[] }> {\n\t\tif (!targets.length) {\n\t\t\treturn { successTokens: [], failedTokens: [] };\n\t\t}\n\n\t\tconst logger = getLibraries().getLoggerKit();\n\n\t\tconst oldTokens: string[] = [];\n\t\tconst newTokens: string[] = [];\n\n\t\tfor (const t of targets) {\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\tconst sendGroup = async (\n\t\t\tgroupTokens: string[],\n\t\t\tgroupPayload: FCMNotificationPayload,\n\t\t\toldNotificationStructure: boolean = false\n\t\t) => {\n\t\t\tconst tokenChunks = this.chunkArray(groupTokens, FCMService.MAX_BATCH);\n\n\t\t\tconst success: string[] = [];\n\t\t\tconst failed: string[] = [];\n\n\t\t\tconst results = await Promise.all(\n\t\t\t\ttokenChunks.map(async chunk => {\n\t\t\t\t\tconst message = oldNotificationStructure\n\t\t\t\t\t\t? this.buildOldMessage(groupPayload, chunk)\n\t\t\t\t\t\t: this.buildMessage(groupPayload, chunk);\n\n\t\t\t\t\tconst response = await this.messaging.sendEachForMulticast(message);\n\n\t\t\t\t\tconst logEntry = {\n\t\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\t\tgroupTokens,\n\t\t\t\t\t\tgroupPayload,\n\t\t\t\t\t\toldNotificationStructure,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t};\n\n\t\t\t\t\tlogger.debug('Called Firebase function sendEachForMulticast', { tag: LogTag.NOTIFICATION_ATTEMPTED, data: logEntry });\n\n\t\t\t\t\tconst batchSuccess: string[] = [];\n\t\t\t\t\tconst batchFailed: string[] = [];\n\n\t\t\t\t\tresponse.responses.forEach((resp, idx) => {\n\t\t\t\t\t\tif (resp.success) {\n\t\t\t\t\t\t\tbatchSuccess.push(chunk[idx]);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst errorCode = resp.error?.code;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\terrorCode === 'messaging/invalid-argument' ||\n\t\t\t\t\t\t\t\terrorCode === 'messaging/registration-token-not-registered'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tbatchFailed.push(chunk[idx]);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.warn(`FCM Error for token ${chunk[idx]}:`, resp.error?.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treturn { batchSuccess, batchFailed };\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tfor (const r of results) {\n\t\t\t\tsuccess.push(...r.batchSuccess);\n\t\t\t\tfailed.push(...r.batchFailed);\n\t\t\t}\n\n\t\t\treturn { success, failed };\n\t\t};\n\n\t\tlet successTokens: string[] = [];\n\t\tlet failedTokens: string[] = [];\n\n\t\t// send old payload\n\t\tif (oldTokens.length) {\n\t\t\tconst r = await sendGroup(oldTokens, payload, true);\n\n\t\t\tsuccessTokens.push(...r.success);\n\t\t\tfailedTokens.push(...r.failed);\n\t\t}\n\n\t\t// send new payload\n\t\tif (newTokens.length) {\n\t\t\tconst r = await sendGroup(newTokens, payload, false);\n\n\t\t\tsuccessTokens.push(...r.success);\n\t\t\tfailedTokens.push(...r.failed);\n\t\t}\n\n\t\treturn { successTokens, failedTokens };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fcmService.js","sourceRoot":"/","sources":["libraries/firebase/fcmService.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mDAA2C;AAC3C,6BAAqC;AACrC,mCAAiC;AAEjC,+CAAoF;AAwBpF,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;CACD,CAAC;AAEW,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AACvC,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AACvC,QAAA,mBAAmB,GAAG,oBAAoB,CAAC;AAGjD,IAAM,UAAU,GAAhB,MAAM,UAAU;;IACd,SAAS,CAAuB;IAChC,MAAM,CAAU,SAAS,GAAG,GAAG,CAAC;IAExC,YAAY,GAAS;QACpB,MAAM,WAAW,GAAG,GAAG,IAAI,IAAA,gBAAY,GAAE,CAAC,kBAAkB,EAAE,CA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AC,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAGD,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC;gBACzB,WAAW,EAAE,SAAS;gBACtB,YAAY,EAAE,OAAO;gBACrB,wBAAwB,EAAE,KAAK;aAC/B,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAGD,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC;gBACzB,WAAW,EAAE,aAAa;gBAC1B,YAAY,EAAE,OAAO;gBACrB,mBAAmB,EAAE,IAAI;aACzB,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;IACxC,CAAC;;AA9SW,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA+StB","sourcesContent":["import { messaging } from 'firebase-admin';\nimport { getLibraries } from '../..';\nimport { Service } from 'typedi';\nimport { App } from 'firebase-admin/app';\nimport { AppPlatform, LogTag, NotificationAccountType } from '../../utilities/enum';\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\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\nexport const FCMServiceForUser = 'fcm.service.user';\nexport const FCMServiceForRider = 'fcm.service.rider';\nexport const FCMServiceForShop = 'fcm.service.shop';\nexport const FCMServiceForCpanel = 'fcm.service.cpanel';\n\n@Service()\nexport class FCMService {\n\tprivate messaging!: messaging.Messaging;\n\tprivate static readonly MAX_BATCH = 500;\n\n\tconstructor(app?: App) {\n\t\tconst firebaseApp = app ?? getLibraries().getFirebaseService().superApp;\n\t\tthis.messaging = messaging(firebaseApp);\n\t}\n\n\t/**\n\t * Split array into chunks of fixed size\n\t */\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 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 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);\n\t}\n\n\tprivate isConsoleEntityType(type: NotificationAccountType): type is NotifiableEntityType {\n\t\treturn type === NotificationAccountType.SHOP_CONSOLE;\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\t/**\n\t * Build multicast message safely\n\t */\n\tprivate buildConsoleMessage(\n\t\tpayload: FCMNotificationPayload,\n\t\tbatchTokens: string[]\n\t): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t};\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Build multicast message safely\n\t */\n\tprivate buildMessage(payload: FCMNotificationPayload, batchTokens: string[]): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t\tandroid: {\n\t\t\t\tpriority: 'high',\n\t\t\t\tnotification: {\n\t\t\t\t\tchannelId: 'silent',\n\t\t\t\t},\n\t\t\t},\n\t\t\tapns: {\n\t\t\t\tpayload: {\n\t\t\t\t\taps: {\n\t\t\t\t\t\tsound: payload.sound || 'default',\n\t\t\t\t\t\tcontentAvailable: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\theaders: {\n\t\t\t\t\t'apns-push-type': 'background',\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Build multicast message safely for old apps\n\t */\n\tprivate buildOldMessage(\n\t\tpayload: FCMNotificationPayload,\n\t\tbatchTokens: string[]\n\t): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: payload.data || {},\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t\tandroid: { priority: 'high' },\n\t\t\tapns: {\n\t\t\t\tpayload: {\n\t\t\t\t\taps: {\n\t\t\t\t\t\tsound: payload.sound || 'default',\n\t\t\t\t\t\tcontentAvailable: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tif (!isInvisible) {\n\t\t\tmessage.notification = {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t};\n\n\t\t\tmessage.android = {\n\t\t\t\tpriority: 'high',\n\t\t\t\tnotification: {\n\t\t\t\t\tchannelId: payload.sound ? 'android_Push_Notification_Channel_1' : 'default',\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Sends a push notification (visible or invisible) to multiple device tokens\n\t * @param payload - Notification title, body, and optional data\n\t * @param tokens - FCM device tokens\n\t * @returns Object containing success and invalid tokens\n\t */\n\tasync sendNotification(\n\t\tpayload: FCMNotificationPayload,\n\t\ttargets: NotificationTokenTarget[]\n\t): Promise<{ successTokens: string[]; failedTokens: string[] }> {\n\t\tif (!targets.length) {\n\t\t\treturn { successTokens: [], failedTokens: [] };\n\t\t}\n\n\t\tconst logger = getLibraries().getLoggerKit();\n\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\tconst sendGroup = async (data: {\n\t\t\tgroupTokens: string[];\n\t\t\tgroupPayload: FCMNotificationPayload;\n\t\t\toldNotificationStructure?: boolean;\n\t\t\tconsoleNotification?: boolean;\n\t\t}) => {\n\t\t\tconst tokenChunks = this.chunkArray(data.groupTokens, FCMService.MAX_BATCH);\n\n\t\t\tconst success: string[] = [];\n\t\t\tconst failed: string[] = [];\n\n\t\t\tconst results = await Promise.all(\n\t\t\t\ttokenChunks.map(async chunk => {\n\t\t\t\t\tconst message = data.consoleNotification\n\t\t\t\t\t\t? this.buildConsoleMessage(data.groupPayload, chunk)\n\t\t\t\t\t\t: data.oldNotificationStructure\n\t\t\t\t\t\t\t? this.buildOldMessage(data.groupPayload, chunk)\n\t\t\t\t\t\t\t: this.buildMessage(data.groupPayload, chunk);\n\n\t\t\t\t\tconst response = await this.messaging.sendEachForMulticast(message);\n\n\t\t\t\t\tconst logEntry = {\n\t\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\t\tgroupTokens: data.groupTokens,\n\t\t\t\t\t\tgroupPayload: data.groupPayload,\n\t\t\t\t\t\toldNotificationStructure: data.oldNotificationStructure,\n\t\t\t\t\t\tconsoleNotification: data.consoleNotification,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t};\n\n\t\t\t\t\tlogger.debug('Called Firebase function sendEachForMulticast', {\n\t\t\t\t\t\ttag: LogTag.NOTIFICATION_ATTEMPTED,\n\t\t\t\t\t\tdata: logEntry,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst batchSuccess: string[] = [];\n\t\t\t\t\tconst batchFailed: string[] = [];\n\n\t\t\t\t\tresponse.responses.forEach((resp, idx) => {\n\t\t\t\t\t\tif (resp.success) {\n\t\t\t\t\t\t\tbatchSuccess.push(chunk[idx]);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst errorCode = resp.error?.code;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\terrorCode === 'messaging/invalid-argument' ||\n\t\t\t\t\t\t\t\terrorCode === 'messaging/registration-token-not-registered'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tbatchFailed.push(chunk[idx]);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.warn(`FCM Error for token ${chunk[idx]}:`, resp.error?.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treturn { batchSuccess, batchFailed };\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tfor (const r of results) {\n\t\t\t\tsuccess.push(...r.batchSuccess);\n\t\t\t\tfailed.push(...r.batchFailed);\n\t\t\t}\n\n\t\t\treturn { success, failed };\n\t\t};\n\n\t\tlet successTokens: string[] = [];\n\t\tlet failedTokens: string[] = [];\n\n\t\t// send old payload\n\t\tif (oldTokens.length) {\n\t\t\tconst r = await sendGroup({\n\t\t\t\tgroupTokens: oldTokens,\n\t\t\t\tgroupPayload: payload,\n\t\t\t\toldNotificationStructure: true,\n\t\t\t});\n\n\t\t\tsuccessTokens.push(...r.success);\n\t\t\tfailedTokens.push(...r.failed);\n\t\t}\n\n\t\t// send new payload\n\t\tif (newTokens.length) {\n\t\t\tconst r = await sendGroup({\n\t\t\t\tgroupTokens: newTokens,\n\t\t\t\tgroupPayload: payload,\n\t\t\t\toldNotificationStructure: false,\n\t\t\t});\n\n\t\t\tsuccessTokens.push(...r.success);\n\t\t\tfailedTokens.push(...r.failed);\n\t\t}\n\n\t\t// send console tokens\n\t\tif (consoleTokens.length) {\n\t\t\tconst r = await sendGroup({\n\t\t\t\tgroupTokens: consoleTokens,\n\t\t\t\tgroupPayload: payload,\n\t\t\t\tconsoleNotification: true,\n\t\t\t});\n\n\t\t\tsuccessTokens.push(...r.success);\n\t\t\tfailedTokens.push(...r.failed);\n\t\t}\n\n\t\treturn { successTokens, failedTokens };\n\t}\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Ref } from
|
|
2
|
-
import { TimeStamps } from
|
|
3
|
-
import { Vendor } from
|
|
4
|
-
import { VendorRole } from
|
|
5
|
-
import { VendorParent } from
|
|
1
|
+
import { Ref } from '@typegoose/typegoose';
|
|
2
|
+
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
3
|
+
import { Vendor } from './vendor.model';
|
|
4
|
+
import { VendorRole } from '../../../utilities/enum';
|
|
5
|
+
import { VendorParent } from './vendor-parent.model';
|
|
6
6
|
export declare class VendorAccessControl extends TimeStamps {
|
|
7
7
|
name: string;
|
|
8
8
|
email: string;
|
|
@@ -10,4 +10,5 @@ export declare class VendorAccessControl extends TimeStamps {
|
|
|
10
10
|
parent?: Ref<VendorParent>;
|
|
11
11
|
vendors?: Ref<Vendor>[];
|
|
12
12
|
role: VendorRole;
|
|
13
|
+
status?: string;
|
|
13
14
|
}
|
|
@@ -23,6 +23,7 @@ let VendorAccessControl = class VendorAccessControl extends defaultClasses_1.Tim
|
|
|
23
23
|
parent;
|
|
24
24
|
vendors;
|
|
25
25
|
role;
|
|
26
|
+
status;
|
|
26
27
|
};
|
|
27
28
|
exports.VendorAccessControl = VendorAccessControl;
|
|
28
29
|
__decorate([
|
|
@@ -49,6 +50,10 @@ __decorate([
|
|
|
49
50
|
(0, typegoose_1.prop)({ required: true, type: String, enum: enum_1.VendorRole }),
|
|
50
51
|
__metadata("design:type", String)
|
|
51
52
|
], VendorAccessControl.prototype, "role", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.Status, default: enum_1.Status.ACTIVE }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], VendorAccessControl.prototype, "status", void 0);
|
|
52
57
|
exports.VendorAccessControl = VendorAccessControl = __decorate([
|
|
53
58
|
(0, typegoose_1.pre)('save', async function (next) {
|
|
54
59
|
if (this.isModified('password')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vendor-access-control.model.js","sourceRoot":"/","sources":["libraries/mongo/models/vendor-access-control.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,iDAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"vendor-access-control.model.js","sourceRoot":"/","sources":["libraries/mongo/models/vendor-access-control.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,iDAAwC;AACxC,kDAA6D;AAC7D,0DAA2D;AAE3D,+DAAqD;AAkB9C,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,2BAAU;IAE3C,IAAI,CAAU;IAGd,KAAK,CAAU;IAGf,QAAQ,CAAU;IAGlB,MAAM,CAAqB;IAG3B,OAAO,CAAiB;IAGxB,IAAI,CAAc;IAGlB,MAAM,CAAU;CACvB,CAAA;AArBY,kDAAmB;AAExB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;;iDACjC;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kDACjB;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;;qDAC5B;AAGlB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E,IAAI,EAAE,EAAE,CAAC;IACnF,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,sBAAsB,EAAE,EAAE,CAAC;GAC3D,mBAAmB,CAqB/B","sourcesContent":["import { index, modelOptions, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { Vendor } from './vendor.model';\nimport { Status, VendorRole } from '../../../utilities/enum';\nimport { hashPassword } from '../../../utilities/password';\nimport { Query } from 'mongoose';\nimport { VendorParent } from './vendor-parent.model';\n\n@pre<VendorAccessControl>('save', async function (next) {\n\tif (this.isModified('password')) {\n\t\tthis.password = await hashPassword(this.password);\n\t}\n\tnext();\n})\n@pre<Query<any, VendorAccessControl>>('findOneAndUpdate', async function (next) {\n\tconst update = this.getUpdate() as Record<string, any>;\n\tif (update?.password) {\n\t\tupdate.password = await hashPassword(update.password);\n\t\tthis.setUpdate(update);\n\t}\n\tnext();\n})\n@index({ email: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })\n@modelOptions({ schemaOptions: { collection: 'vendorAccessControls' } })\nexport class VendorAccessControl extends TimeStamps {\n\t@prop({ required: true, type: String, maxlength: 50 })\n\tpublic name!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic email!: string;\n\n\t@prop({ required: true, type: String, minlength: 8 })\n\tpublic password!: string;\n\n\t@prop({ required: true, ref: () => VendorParent })\n\tpublic parent?: Ref<VendorParent>;\n\n\t@prop({ ref: () => Vendor, default: [] })\n\tpublic vendors?: Ref<Vendor>[];\n\n\t@prop({ required: true, type: String, enum: VendorRole })\n\tpublic role!: VendorRole;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: string;\n}\n"]}
|
|
@@ -5,10 +5,10 @@ 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;
|
|
8
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
10
|
tokenType: TokenType | undefined;
|
|
10
11
|
entity: import("../context").EntityContext | undefined;
|
|
11
|
-
req: import("http").IncomingMessage;
|
|
12
12
|
requestId: string | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
|
@@ -4,10 +4,10 @@ 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;
|
|
7
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
9
|
tokenType: import("../../auth").TokenType | undefined;
|
|
9
10
|
entity: import("../context").EntityContext | undefined;
|
|
10
|
-
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
13
13
|
tokenRenewed: boolean | undefined;
|
|
@@ -3,10 +3,10 @@ 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;
|
|
6
7
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
7
8
|
tokenType: import("../../auth").TokenType | undefined;
|
|
8
9
|
entity: import("../context").EntityContext | undefined;
|
|
9
|
-
req: import("http").IncomingMessage;
|
|
10
10
|
requestId: string | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
12
12
|
tokenRenewed: boolean | undefined;
|
|
@@ -5,10 +5,10 @@ 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;
|
|
8
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
10
|
tokenType: TokenType | undefined;
|
|
10
11
|
entity: import("../context").EntityContext | undefined;
|
|
11
|
-
req: import("http").IncomingMessage;
|
|
12
12
|
requestId: string | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -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
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
30
29
|
populate?: any;
|
|
30
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
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
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
40
39
|
populate?: any;
|
|
40
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
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
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
740
739
|
populate?: any;
|
|
740
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
741
741
|
}, {
|
|
742
742
|
_id: string | import("mongoose").Types.ObjectId;
|
|
743
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
744
743
|
populate?: any;
|
|
744
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
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
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
758
757
|
populate?: any;
|
|
758
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
759
759
|
}, {
|
|
760
760
|
_id: string | import("mongoose").Types.ObjectId;
|
|
761
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
762
761
|
populate?: any;
|
|
762
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
763
763
|
withAttributeHiddenItems?: boolean | undefined;
|
|
764
764
|
withAddonsHiddenItems?: boolean | undefined;
|
|
765
765
|
}>;
|
|
@@ -772,14 +772,14 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
|
|
|
772
772
|
userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
|
|
773
773
|
}, "strip", z.ZodTypeAny, {
|
|
774
774
|
_id: import("mongoose").Types.ObjectId;
|
|
775
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
776
775
|
populate?: any;
|
|
776
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
777
777
|
groupByCategories?: boolean | undefined;
|
|
778
778
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
779
779
|
}, {
|
|
780
780
|
_id: string | import("mongoose").Types.ObjectId;
|
|
781
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
782
781
|
populate?: any;
|
|
782
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
783
783
|
groupByCategories?: boolean | undefined;
|
|
784
784
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
785
785
|
}>;
|
|
@@ -788,11 +788,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
|
|
|
788
788
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
789
789
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
790
790
|
}, "strip", z.ZodTypeAny, {
|
|
791
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
792
791
|
populate?: any;
|
|
793
|
-
}, {
|
|
794
792
|
select?: Record<string, 0 | 1> | undefined;
|
|
793
|
+
}, {
|
|
795
794
|
populate?: any;
|
|
795
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
796
796
|
}>>;
|
|
797
797
|
export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
|
|
798
798
|
export declare const GetOneQuerySchema: z.ZodObject<{
|
|
@@ -800,12 +800,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
|
|
|
800
800
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
801
801
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
802
802
|
}, "strip", z.ZodTypeAny, {
|
|
803
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
804
803
|
populate?: any;
|
|
804
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
805
805
|
query?: Record<string, any> | undefined;
|
|
806
806
|
}, {
|
|
807
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
808
807
|
populate?: any;
|
|
808
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
809
809
|
query?: Record<string, any> | undefined;
|
|
810
810
|
}>;
|
|
811
811
|
export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
|