@lyxa.ai/core 1.4.332 → 1.4.333
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/event/events/mongo-stream-changes-batch-process-shops-event.d.ts +2 -2
- package/dist/libraries/event/events/punch-marketing/sync-user-shop-punch-marketing-history-event.d.ts +2 -2
- package/dist/libraries/event/events/sync-order-again-sections-for-shop-event.d.ts +2 -2
- package/dist/libraries/mongo/models/payment-intent.model.d.ts +2 -1
- package/dist/libraries/mongo/models/payment-intent.model.js +5 -0
- package/dist/libraries/mongo/models/payment-intent.model.js.map +1 -1
- package/dist/libraries/notification/firebase-message.builder.d.ts +1 -5
- package/dist/libraries/notification/firebase-message.builder.js +1 -32
- package/dist/libraries/notification/firebase-message.builder.js.map +1 -1
- package/dist/libraries/notification/lyxa-fcm.service.d.ts +0 -1
- package/dist/libraries/notification/lyxa-fcm.service.js +0 -16
- package/dist/libraries/notification/lyxa-fcm.service.js.map +1 -1
- package/dist/libraries/redis/index.d.ts +5 -0
- package/dist/libraries/redis/index.js +16 -0
- package/dist/libraries/redis/index.js.map +1 -1
- package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +25 -25
- package/dist/libraries/socket/events/order-actions.socket.event.d.ts +24 -24
- package/dist/libraries/socket/events/rider-location-update.socket.event.d.ts +4 -4
- package/dist/libraries/socket/events/ticket-actions.socket.event.d.ts +12 -12
- package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +4 -4
- package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/auth.js +2 -0
- package/dist/libraries/trpc/middlewares/auth.js.map +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 +66 -66
- package/dist/types/utilities/validation/validation-for-frontend.d.ts +2 -2
- package/dist/utilities/pagination.d.ts +3 -3
- package/dist/utilities/validation/common-validation.d.ts +70 -70
- package/dist/utilities/validation/validation-for-frontend.d.ts +2 -2
- package/package.json +1 -1
|
@@ -24,13 +24,13 @@ declare const MongoStreamsBatchProcessShopsSchema: z.ZodObject<{
|
|
|
24
24
|
}, "strict", z.ZodTypeAny, {
|
|
25
25
|
operation: ChangeStreamOperationTypes;
|
|
26
26
|
updateCollection: UpdateCollectionAtlasSearchEnum;
|
|
27
|
-
updatedFields?: any;
|
|
28
27
|
fullDocument?: any;
|
|
28
|
+
updatedFields?: any;
|
|
29
29
|
}, {
|
|
30
30
|
operation: ChangeStreamOperationTypes;
|
|
31
31
|
updateCollection: UpdateCollectionAtlasSearchEnum;
|
|
32
|
-
updatedFields?: any;
|
|
33
32
|
fullDocument?: any;
|
|
33
|
+
updatedFields?: any;
|
|
34
34
|
}>;
|
|
35
35
|
export type MongoStreamsBatchProcessShopsDTO = DTO<typeof MongoStreamsBatchProcessShopsSchema>;
|
|
36
36
|
export declare class MongoStreamsBatchProcessShopsEvent extends BaseEvent<Record<string, unknown>> {
|
|
@@ -6,12 +6,12 @@ declare const SyncUserShopPunchMarketingHistoryInCacheValidationSchema: import("
|
|
|
6
6
|
shopId: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
7
7
|
operation: import("zod").ZodNativeEnum<typeof ChangeStreamOperationTypes>;
|
|
8
8
|
}, "strict", import("zod").ZodTypeAny, {
|
|
9
|
-
userId: import("mongoose").Types.ObjectId;
|
|
10
9
|
shopId: import("mongoose").Types.ObjectId;
|
|
10
|
+
userId: import("mongoose").Types.ObjectId;
|
|
11
11
|
operation: ChangeStreamOperationTypes;
|
|
12
12
|
}, {
|
|
13
|
-
userId: string | import("mongoose").Types.ObjectId;
|
|
14
13
|
shopId: string | import("mongoose").Types.ObjectId;
|
|
14
|
+
userId: string | import("mongoose").Types.ObjectId;
|
|
15
15
|
operation: ChangeStreamOperationTypes;
|
|
16
16
|
}>;
|
|
17
17
|
export type SyncUserShopPunchMarketingHistoryInCacheValidationDTO = DTO<typeof SyncUserShopPunchMarketingHistoryInCacheValidationSchema>;
|
|
@@ -4,11 +4,11 @@ declare const SyncSingleShopValidationSchema: import("zod").ZodObject<{
|
|
|
4
4
|
userId: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
5
5
|
shopId: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
6
6
|
}, "strict", import("zod").ZodTypeAny, {
|
|
7
|
-
userId: import("mongoose").Types.ObjectId;
|
|
8
7
|
shopId: import("mongoose").Types.ObjectId;
|
|
8
|
+
userId: import("mongoose").Types.ObjectId;
|
|
9
9
|
}, {
|
|
10
|
-
userId: string | import("mongoose").Types.ObjectId;
|
|
11
10
|
shopId: string | import("mongoose").Types.ObjectId;
|
|
11
|
+
userId: string | import("mongoose").Types.ObjectId;
|
|
12
12
|
}>;
|
|
13
13
|
export type SyncSingleShopOrderAgainCacheDTO = DTO<typeof SyncSingleShopValidationSchema>;
|
|
14
14
|
export declare class SyncSingleShopOrderAgainInCacheEvent extends BaseEvent<Record<string, unknown>> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ref } from '@typegoose/typegoose';
|
|
2
2
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
3
3
|
import { CoreUser } from './core-user.model';
|
|
4
|
-
import { PaymentIntentStatus } from '../../../utilities/enum';
|
|
4
|
+
import { PaymentIntentStatus, PaymentProvider } from '../../../utilities/enum';
|
|
5
5
|
import { User } from './user.model';
|
|
6
6
|
export declare class PaymentIntent extends TimeStamps {
|
|
7
7
|
coreUser: Ref<CoreUser>;
|
|
@@ -14,4 +14,5 @@ export declare class PaymentIntent extends TimeStamps {
|
|
|
14
14
|
authorization?: string;
|
|
15
15
|
paymentContext?: any;
|
|
16
16
|
status?: PaymentIntentStatus;
|
|
17
|
+
provider?: PaymentProvider;
|
|
17
18
|
}
|
|
@@ -26,6 +26,7 @@ let PaymentIntent = class PaymentIntent extends defaultClasses_1.TimeStamps {
|
|
|
26
26
|
authorization;
|
|
27
27
|
paymentContext;
|
|
28
28
|
status;
|
|
29
|
+
provider;
|
|
29
30
|
};
|
|
30
31
|
exports.PaymentIntent = PaymentIntent;
|
|
31
32
|
__decorate([
|
|
@@ -68,6 +69,10 @@ __decorate([
|
|
|
68
69
|
(0, typegoose_1.prop)({ type: String, enum: enum_1.PaymentIntentStatus, default: enum_1.PaymentIntentStatus.PENDING }),
|
|
69
70
|
__metadata("design:type", String)
|
|
70
71
|
], PaymentIntent.prototype, "status", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.PaymentProvider }),
|
|
74
|
+
__metadata("design:type", String)
|
|
75
|
+
], PaymentIntent.prototype, "provider", void 0);
|
|
71
76
|
exports.PaymentIntent = PaymentIntent = __decorate([
|
|
72
77
|
(0, typegoose_1.modelOptions)({
|
|
73
78
|
schemaOptions: { collection: 'paymentIntents' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment-intent.model.js","sourceRoot":"/","sources":["libraries/mongo/models/payment-intent.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAmF;AACnF,4EAAqE;AACrE,uDAA6C;AAC7C,
|
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AAI,EAAC,EAAE,IAAI,EAAE,oBAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;;qDAChB;AAGrB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,0BAAmB,EAAE,OAAO,EAAE,0BAAmB,CAAC,OAAO,EAAE,CAAC;;6CACpD;AAG7B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAe,EAAE,CAAC;;+CACZ;wBAhCtB,aAAa;IANzB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE;QAC/C,OAAO,EAAE;YACR,UAAU,EAAE,oBAAQ,CAAC,KAAK;SAC1B;KACD,CAAC;GACW,aAAa,CAiCzB","sourcesContent":["import { modelOptions, mongoose, prop, Ref, Severity } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { CoreUser } from './core-user.model';\nimport { PaymentIntentStatus, PaymentProvider } from '../../../utilities/enum';\nimport { User } from './user.model';\n\n@modelOptions({\n\tschemaOptions: { collection: 'paymentIntents' },\n\toptions: {\n\t\tallowMixed: Severity.ALLOW,\n\t},\n})\nexport class PaymentIntent extends TimeStamps {\n\t@prop({ required: true, ref: () => CoreUser })\n\tpublic coreUser!: Ref<CoreUser>;\n\n\t@prop({ required: true, ref: () => User })\n\tpublic user!: Ref<User>;\n\n\t@prop({ required: true, type: String })\n\tpublic orderId!: string;\n\n\t@prop({ type: String })\n\tpublic token?: string; // only for areeba\n\n\t@prop({ type: String })\n\tpublic externalId?: string; // only for whish\n\n\t@prop({ required: true, type: Number })\n\tpublic amount!: number;\n\n\t@prop({ type: Number })\n\tpublic secondaryAmount?: number;\n\n\t@prop({ type: String })\n\tpublic authorization?: string;\n\n\t@prop({ type: mongoose.Schema.Types.Mixed })\n\tpublic paymentContext?: any;\n\n\t@prop({ type: String, enum: PaymentIntentStatus, default: PaymentIntentStatus.PENDING })\n\tpublic status?: PaymentIntentStatus;\n\n\t@prop({ type: String, enum: PaymentProvider })\n\tpublic provider?: PaymentProvider;\n}\n"]}
|
|
@@ -3,8 +3,7 @@ import { FCMNotificationPayload } from './lyxa-fcm.service';
|
|
|
3
3
|
export declare enum MultiMessageType {
|
|
4
4
|
OLD = "old",
|
|
5
5
|
CONSOLE = "console",
|
|
6
|
-
DEFAULT = "default"
|
|
7
|
-
LIVE_ACTIVITY = "live_activity"
|
|
6
|
+
DEFAULT = "default"
|
|
8
7
|
}
|
|
9
8
|
export interface IFirebaseMessageBuilder {
|
|
10
9
|
buildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage;
|
|
@@ -21,6 +20,3 @@ export declare class OldMessageBuilder implements IFirebaseMessageBuilder {
|
|
|
21
20
|
export declare class ConsoleMessageBuilder implements IFirebaseMessageBuilder {
|
|
22
21
|
buildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage;
|
|
23
22
|
}
|
|
24
|
-
export declare class LiveActivityMessageBuilder implements IFirebaseMessageBuilder {
|
|
25
|
-
buildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage;
|
|
26
|
-
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
3
|
+
exports.ConsoleMessageBuilder = exports.OldMessageBuilder = exports.DefaultMessageBuilder = exports.FirebaseMessageBuilderFactory = exports.MultiMessageType = void 0;
|
|
8
4
|
var MultiMessageType;
|
|
9
5
|
(function (MultiMessageType) {
|
|
10
6
|
MultiMessageType["OLD"] = "old";
|
|
11
7
|
MultiMessageType["CONSOLE"] = "console";
|
|
12
8
|
MultiMessageType["DEFAULT"] = "default";
|
|
13
|
-
MultiMessageType["LIVE_ACTIVITY"] = "live_activity";
|
|
14
9
|
})(MultiMessageType || (exports.MultiMessageType = MultiMessageType = {}));
|
|
15
10
|
class FirebaseMessageBuilderFactory {
|
|
16
11
|
buildMessage(type, payload, tokens) {
|
|
@@ -109,30 +104,4 @@ class ConsoleMessageBuilder {
|
|
|
109
104
|
}
|
|
110
105
|
}
|
|
111
106
|
exports.ConsoleMessageBuilder = ConsoleMessageBuilder;
|
|
112
|
-
class LiveActivityMessageBuilder {
|
|
113
|
-
buildMessage(payload, tokens) {
|
|
114
|
-
return {
|
|
115
|
-
notification: {
|
|
116
|
-
title: payload.title,
|
|
117
|
-
body: payload.body,
|
|
118
|
-
},
|
|
119
|
-
tokens: tokens,
|
|
120
|
-
apns: {
|
|
121
|
-
payload: {
|
|
122
|
-
aps: {
|
|
123
|
-
timestamp: (0, dayjs_1.default)().unix(),
|
|
124
|
-
event: payload.data.event,
|
|
125
|
-
'content-state': { status: payload.data.status, etaMinutes: payload.data.deliveredInMinutes },
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
headers: {
|
|
129
|
-
'apns-push-type': 'liveactivity',
|
|
130
|
-
'apns-priority': '10',
|
|
131
|
-
'apns-topic': 'com.lyxa.app.push-type.liveactivity',
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.LiveActivityMessageBuilder = LiveActivityMessageBuilder;
|
|
138
107
|
//# sourceMappingURL=firebase-message.builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase-message.builder.js","sourceRoot":"/","sources":["libraries/notification/firebase-message.builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"firebase-message.builder.js","sourceRoot":"/","sources":["libraries/notification/firebase-message.builder.ts"],"names":[],"mappings":";;;AAGA,IAAY,gBA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QAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5D,OAAO;YACN,IAAI,EAAE;gBACL,GAAG,OAAO,CAAC,IAAI;gBACf,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;gBAC7C,iBAAiB,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;gBACtC,gBAAgB,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;aACpC;YACD,MAAM,EAAE,MAAM;SACd,CAAC;IACH,CAAC;CACD;AAdD,sDAcC","sourcesContent":["import { messaging } from 'firebase-admin';\nimport { FCMNotificationPayload } from './lyxa-fcm.service';\n\nexport enum MultiMessageType {\n\tOLD = 'old',\n\tCONSOLE = 'console',\n\tDEFAULT = 'default',\n}\n\nexport interface IFirebaseMessageBuilder {\n\tbuildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage;\n}\n\nexport class FirebaseMessageBuilderFactory {\n\tpublic buildMessage(\n\t\ttype: MultiMessageType,\n\t\tpayload: FCMNotificationPayload,\n\t\ttokens: string[]\n\t): messaging.MulticastMessage {\n\t\tswitch (type) {\n\t\t\tcase MultiMessageType.CONSOLE:\n\t\t\t\treturn new ConsoleMessageBuilder().buildMessage(payload, tokens);\n\t\t\tcase MultiMessageType.OLD:\n\t\t\t\treturn new OldMessageBuilder().buildMessage(payload, tokens);\n\t\t\t// case MultiMessageType.DEFAULT:\n\t\t\t// \treturn new DefaultMessageBuilder().buildMessage(payload, tokens);\n\t\t\tdefault:\n\t\t\t\treturn new DefaultMessageBuilder().buildMessage(payload, tokens);\n\t\t}\n\t}\n}\n\nexport class DefaultMessageBuilder implements IFirebaseMessageBuilder {\n\tbuildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\n\t\treturn {\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: tokens,\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\t}\n}\n\nexport class OldMessageBuilder implements IFirebaseMessageBuilder {\n\tbuildMessage(payload: FCMNotificationPayload, tokens: string[]): 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: tokens,\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\nexport class ConsoleMessageBuilder implements IFirebaseMessageBuilder {\n\tbuildMessage(payload: FCMNotificationPayload, tokens: string[]): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\t\treturn {\n\t\t\tdata: {\n\t\t\t\t...payload.data,\n\t\t\t\tchannelId: isInvisible ? 'silent' : channelId,\n\t\t\t\tnotificationTitle: payload.title ?? '',\n\t\t\t\tnotificationBody: payload.body ?? '',\n\t\t\t},\n\t\t\ttokens: tokens,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -33,7 +33,6 @@ export declare class LyxaFcmService {
|
|
|
33
33
|
private separateTokens;
|
|
34
34
|
static getProjectForAccountType(accountType: NotificationAccountType): FcmProject;
|
|
35
35
|
sendToTokens(project: FcmProject, payload: FCMNotificationPayload, targets: NotificationTokenTarget[]): Promise<FcmSendResult>;
|
|
36
|
-
sendToTokensToSpecificMultiMessageType(project: FcmProject, payload: FCMNotificationPayload, targets: NotificationTokenTarget[]): Promise<FcmSendResult>;
|
|
37
36
|
private isNotifiableEntityType;
|
|
38
37
|
private isConsoleEntityType;
|
|
39
38
|
private compareVersions;
|
|
@@ -136,22 +136,6 @@ let LyxaFcmService = class LyxaFcmService {
|
|
|
136
136
|
tokensToDelete: results.flatMap(r => r.tokensToDelete),
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
async sendToTokensToSpecificMultiMessageType(project, payload, targets) {
|
|
140
|
-
if (!targets.length)
|
|
141
|
-
return { failedTokens: [], tokensToDelete: [] };
|
|
142
|
-
console.log('targets', targets);
|
|
143
|
-
const cleanedTargets = this.deduplicateTargets(targets);
|
|
144
|
-
console.log('cleanedTargets', cleanedTargets);
|
|
145
|
-
const tokens = this.separateTokens(cleanedTargets);
|
|
146
|
-
console.log({ tokens });
|
|
147
|
-
const results = await Promise.all([
|
|
148
|
-
this.lyxaFcmSender.sendMessages(project, firebase_message_builder_1.MultiMessageType.LIVE_ACTIVITY, tokens.newTokens, payload),
|
|
149
|
-
]);
|
|
150
|
-
return {
|
|
151
|
-
failedTokens: results.flatMap(r => r.failedTokens),
|
|
152
|
-
tokensToDelete: results.flatMap(r => r.tokensToDelete),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
139
|
isNotifiableEntityType(type) {
|
|
156
140
|
return (type === enum_1.NotificationAccountType.USER ||
|
|
157
141
|
type === enum_1.NotificationAccountType.RIDER ||
|
|
@@ -1 +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,uDAAiE;AACjE,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,O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AAC;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;AA7KY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,gBAAO,GAAE;qCAEmC,+BAAa;GAD7C,cAAc,CA6K1B","sourcesContent":["import { Service } from 'typedi';\nimport { MultiMessageType } from './firebase-message.builder';\nimport { AppPlatform, NotificationAccountType } from '../../utilities/enum';\nimport { FcmSendResult, 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<FcmSendResult> {\n\t\tif (!targets.length) return { failedTokens: [], tokensToDelete: [] };\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),\t\t\t\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 {\n\t\t\tfailedTokens: results.flatMap(r => r.failedTokens),\n\t\t\ttokensToDelete: results.flatMap(r => r.tokensToDelete),\n\t\t};\n\t}\t\n\n\tpublic async sendToTokensToSpecificMultiMessageType(\n\t\tproject: FcmProject,\n\t\tpayload: FCMNotificationPayload,\n\t\ttargets: NotificationTokenTarget[]\n\t): Promise<FcmSendResult> {\n\t\tif (!targets.length) return { failedTokens: [], tokensToDelete: [] };\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\t\tconsole.log({ tokens })\n\t\tconst results = await Promise.all([\n\t\t\tthis.lyxaFcmSender.sendMessages(project, MultiMessageType.LIVE_ACTIVITY, tokens.newTokens, payload),\n\t\t]);\n\n\t\treturn {\n\t\t\tfailedTokens: results.flatMap(r => r.failedTokens),\n\t\t\ttokensToDelete: results.flatMap(r => r.tokensToDelete),\n\t\t};\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"]}
|
|
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,uDAAiE;AACjE,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,CA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CAAC,MAAM,CAAC,CAAC;QAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACvD,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YACvC,IAAI,IAAI,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,CAAC;IACV,CAAC;IAEO,qBAAqB,CAC5B,UAAmC,EACnC,QAAsB,EACtB,OAAgB;QAEhB,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC;YAAE,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;AAxJY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,gBAAO,GAAE;qCAEmC,+BAAa;GAD7C,cAAc,CAwJ1B","sourcesContent":["import { Service } from 'typedi';\nimport { MultiMessageType } from './firebase-message.builder';\nimport { AppPlatform, NotificationAccountType } from '../../utilities/enum';\nimport { FcmSendResult, 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<FcmSendResult> {\n\t\tif (!targets.length) return { failedTokens: [], tokensToDelete: [] };\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 {\n\t\t\tfailedTokens: results.flatMap(r => r.failedTokens),\n\t\t\ttokensToDelete: results.flatMap(r => r.tokensToDelete),\n\t\t};\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"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
+
import { AuthEntityType } from '../auth';
|
|
2
3
|
interface LockOptions {
|
|
3
4
|
maxRetries?: number;
|
|
4
5
|
retryDelayMs?: number;
|
|
@@ -21,5 +22,9 @@ export declare class RedisService {
|
|
|
21
22
|
acquireLock(key: string, ttl?: number): Promise<string | null>;
|
|
22
23
|
releaseLock(key: string, lockValue: string): Promise<boolean>;
|
|
23
24
|
executeWithLock<T>(key: string, ttl: number, callback: () => Promise<T>, errorMessage?: string, options?: LockOptions): Promise<T>;
|
|
25
|
+
private buildLastOnlineKey;
|
|
26
|
+
setLastOnline(entityType: AuthEntityType, entityId: string, timestamp?: number): Promise<void>;
|
|
27
|
+
clearLastOnline(entityType: AuthEntityType, entityId: string): Promise<void>;
|
|
28
|
+
getOnlineEntities(entityType: AuthEntityType, cutoffTime: Date): Promise<string[]>;
|
|
24
29
|
}
|
|
25
30
|
export {};
|
|
@@ -128,6 +128,22 @@ let RedisService = class RedisService {
|
|
|
128
128
|
cause: { retryable: true },
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
+
buildLastOnlineKey(entityType) {
|
|
132
|
+
return `lastOnline:${entityType}`;
|
|
133
|
+
}
|
|
134
|
+
async setLastOnline(entityType, entityId, timestamp = Date.now()) {
|
|
135
|
+
const key = this.buildLastOnlineKey(entityType);
|
|
136
|
+
await this._redisClient.zadd(key, timestamp, entityId);
|
|
137
|
+
}
|
|
138
|
+
async clearLastOnline(entityType, entityId) {
|
|
139
|
+
const key = this.buildLastOnlineKey(entityType);
|
|
140
|
+
await this._redisClient.zrem(key, entityId);
|
|
141
|
+
}
|
|
142
|
+
async getOnlineEntities(entityType, cutoffTime) {
|
|
143
|
+
const key = this.buildLastOnlineKey(entityType);
|
|
144
|
+
const cutoffMs = cutoffTime.getTime();
|
|
145
|
+
return await this._redisClient.zrangebyscore(key, cutoffMs, '+inf');
|
|
146
|
+
}
|
|
131
147
|
};
|
|
132
148
|
exports.RedisService = RedisService;
|
|
133
149
|
exports.RedisService = RedisService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA4B;AAC5B,mCAAiC;AACjC,mCAAoC;AACpC,kCAAoC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA4B;AAC5B,mCAAiC;AACjC,mCAAoC;AACpC,kCAAoC;AAS7B,IAAM,YAAY,GAAlB,MAAM,YAAY;IAChB,YAAY,CAAS;IAE7B,YAAY,QAAgB;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;YACvC,oBAAoB,EAAE,IAAI;SAC1B,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,WAAW;Q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redis from 'ioredis';\nimport { Service } from 'typedi';\nimport { randomUUID } from 'crypto';\nimport { TRPCError } from '../trpc';\nimport { AuthEntityType } from '../auth';\n\ninterface LockOptions {\n\tmaxRetries?: number;\n\tretryDelayMs?: number;\n}\n\n@Service()\nexport class RedisService {\n\tprivate _redisClient!: Redis;\n\n\tconstructor(redisURL: string) {\n\t\tthis._redisClient = new Redis(redisURL, {\n\t\t\tmaxRetriesPerRequest: null,\n\t\t});\n\t}\n\n\tget redisClient(): Redis {\n\t\treturn this._redisClient;\n\t}\n\n\tpublic async getCachedObject<T>(key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.get(key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async cacheObject<T>(key: string, object: T, expiry?: number): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\n\t\tif (expiry) {\n\t\t\tawait this._redisClient.setex(key, expiry, stringifiedObject);\n\t\t} else {\n\t\t\tawait this._redisClient.set(key, stringifiedObject);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObject(key: string): Promise<boolean> {\n\t\tawait this._redisClient.del(key);\n\t\treturn true;\n\t}\n\n\tpublic async getCachedObjectByGroup<T>(group: string, key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.hget(group, key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\t\tawait this._redisClient.hset(group, key, stringifiedObject);\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean> {\n\t\tawait this._redisClient.hdel(group, key);\n\t\treturn true;\n\t}\n\n\tpublic sanitizeKey(key: string) {\n\t\treturn key\n\t\t\t.replace(/[^\\w\\s]/gi, '')\n\t\t\t.replace(/\\s+/g, '-')\n\t\t\t.toLowerCase();\n\t}\n\n\tpublic async addToSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.sadd(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async removeFromSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.srem(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async isMemberOfSet(group: string, member: string): Promise<boolean> {\n\t\treturn (await this._redisClient.sismember(group, member)) === 1;\n\t}\n\n\tpublic async getSetMembers(group: string): Promise<string[]> {\n\t\treturn await this._redisClient.smembers(group);\n\t}\n\n\tpublic async acquireLock(\n\t\tkey: string,\n\t\tttl: number = 10000 // default 10s\n\t): Promise<string | null> {\n\t\tconst lockKey = `lock:${key}`;\n\t\tconst lockValue = randomUUID(); // unique value per process\n\n\t\tconst result = await this._redisClient.set(lockKey, lockValue, 'PX', ttl, 'NX');\n\n\t\t// If result === 'OK' → lock acquired\n\t\tif (result === 'OK') {\n\t\t\treturn lockValue;\n\t\t}\n\n\t\treturn null; // lock not acquired\n\t}\n\n\tpublic async releaseLock(key: string, lockValue: string): Promise<boolean> {\n\t\tconst lockKey = `lock:${key}`;\n\n\t\tconst luaScript = `\n\t\tif redis.call(\"get\", KEYS[1]) == ARGV[1] then\n\t\t\treturn redis.call(\"del\", KEYS[1])\n\t\telse\n\t\t\treturn 0\n\t\tend\n\t`;\n\n\t\tconst result = await this._redisClient.eval(luaScript, 1, lockKey, lockValue);\n\n\t\treturn result === 1;\n\t}\n\n\tpublic async executeWithLock<T>(\n\t\tkey: string,\n\t\tttl: number,\n\t\tcallback: () => Promise<T>,\n\t\terrorMessage?: string,\n\t\toptions?: LockOptions\n\t): Promise<T> {\n\t\tconst maxRetries = options?.maxRetries ?? 10;\n\t\tconst retryDelayMs = options?.retryDelayMs ?? 500;\n\n\t\tlet attempt = 0;\n\n\t\twhile (attempt <= maxRetries) {\n\t\t\tconst lockValue = await this.acquireLock(key, ttl);\n\n\t\t\tif (lockValue) {\n\t\t\t\ttry {\n\t\t\t\t\treturn await callback();\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.releaseLock(key, lockValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait new Promise(r => setTimeout(r, retryDelayMs + Math.random() * 100));\n\n\t\t\tattempt++;\n\t\t}\n\n\t\tthrow new TRPCError({\n\t\t\tcode: 'CONFLICT',\n\t\t\tmessage: errorMessage || 'Resource is locked',\n\t\t\tcause: { retryable: true },\n\t\t});\n\t}\n\n\tprivate buildLastOnlineKey(entityType: AuthEntityType) {\n\t\treturn `lastOnline:${entityType}`;\n\t}\n\n\tpublic async setLastOnline(entityType: AuthEntityType, entityId: string, timestamp: number = Date.now()) {\n\t\tconst key = this.buildLastOnlineKey(entityType);\n\t\tawait this._redisClient.zadd(key, timestamp, entityId);\n\t}\n\n\tpublic async clearLastOnline(entityType: AuthEntityType, entityId: string) {\n\t\tconst key = this.buildLastOnlineKey(entityType);\n\t\tawait this._redisClient.zrem(key, entityId);\n\t}\n\n\tpublic async getOnlineEntities(entityType: AuthEntityType, cutoffTime: Date) {\n\t\tconst key = this.buildLastOnlineKey(entityType);\n\t\tconst cutoffMs = cutoffTime.getTime();\n\n\t\treturn await this._redisClient.zrangebyscore(key, cutoffMs, '+inf');\n\t}\n}\n"]}
|
|
@@ -28,22 +28,22 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
28
28
|
name: string;
|
|
29
29
|
id: import("mongoose").Types.ObjectId;
|
|
30
30
|
}>;
|
|
31
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
31
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
32
32
|
media: z.ZodArray<z.ZodObject<{
|
|
33
33
|
mimeType: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
34
34
|
mediaType: z.ZodNativeEnum<typeof MediaType>;
|
|
35
35
|
mediaUrl: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
36
|
-
thumbnailUrl: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
37
|
-
name: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
36
|
+
thumbnailUrl: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
37
|
+
name: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
39
|
-
mediaType: MediaType;
|
|
40
39
|
mediaUrl: string;
|
|
40
|
+
mediaType: MediaType;
|
|
41
41
|
mimeType: string;
|
|
42
42
|
name?: string | undefined;
|
|
43
43
|
thumbnailUrl?: string | undefined;
|
|
44
44
|
}, {
|
|
45
|
-
mediaType: MediaType;
|
|
46
45
|
mediaUrl: string;
|
|
46
|
+
mediaType: MediaType;
|
|
47
47
|
mimeType: string;
|
|
48
48
|
name?: string | undefined;
|
|
49
49
|
thumbnailUrl?: string | undefined;
|
|
@@ -72,19 +72,19 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
72
72
|
};
|
|
73
73
|
senderType: UserRef;
|
|
74
74
|
media: {
|
|
75
|
-
mediaType: MediaType;
|
|
76
75
|
mediaUrl: string;
|
|
76
|
+
mediaType: MediaType;
|
|
77
77
|
mimeType: string;
|
|
78
78
|
name?: string | undefined;
|
|
79
79
|
thumbnailUrl?: string | undefined;
|
|
80
80
|
}[];
|
|
81
81
|
chatroomType: ChatroomType;
|
|
82
82
|
senderId: import("mongoose").Types.ObjectId;
|
|
83
|
-
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
84
83
|
location?: {
|
|
85
84
|
latitude?: number | undefined;
|
|
86
85
|
longitude?: number | undefined;
|
|
87
86
|
} | undefined;
|
|
87
|
+
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
88
88
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
89
89
|
content?: string | undefined;
|
|
90
90
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
@@ -98,25 +98,25 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
98
98
|
};
|
|
99
99
|
senderType: UserRef;
|
|
100
100
|
media: {
|
|
101
|
-
mediaType: MediaType;
|
|
102
101
|
mediaUrl: string;
|
|
102
|
+
mediaType: MediaType;
|
|
103
103
|
mimeType: string;
|
|
104
104
|
name?: string | undefined;
|
|
105
105
|
thumbnailUrl?: string | undefined;
|
|
106
106
|
}[];
|
|
107
107
|
chatroomType: ChatroomType;
|
|
108
108
|
senderId: import("mongoose").Types.ObjectId;
|
|
109
|
-
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
110
109
|
location?: {
|
|
111
110
|
latitude?: number | undefined;
|
|
112
111
|
longitude?: number | undefined;
|
|
113
112
|
} | undefined;
|
|
113
|
+
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
114
114
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
115
115
|
content?: string | undefined;
|
|
116
116
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
117
117
|
}>;
|
|
118
118
|
export declare const ChatroomMessageSendPushOutputSchema: z.ZodObject<{
|
|
119
|
-
lastMessage: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
119
|
+
lastMessage: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
120
120
|
chatroomId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
121
121
|
ticketId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
122
122
|
orderId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
@@ -124,14 +124,14 @@ export declare const ChatroomMessageSendPushOutputSchema: z.ZodObject<{
|
|
|
124
124
|
}, "strip", z.ZodTypeAny, {
|
|
125
125
|
type: ChatroomType;
|
|
126
126
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
127
|
-
lastMessage?: string | undefined;
|
|
128
127
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
128
|
+
lastMessage?: string | undefined;
|
|
129
129
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
130
130
|
}, {
|
|
131
131
|
type: ChatroomType;
|
|
132
132
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
133
|
-
lastMessage?: string | undefined;
|
|
134
133
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
134
|
+
lastMessage?: string | undefined;
|
|
135
135
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
136
136
|
}>;
|
|
137
137
|
export type ChatlistMessageSendPushOutputDTO = DTO<typeof ChatroomMessageSendPushOutputSchema>;
|
|
@@ -164,22 +164,22 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
164
164
|
name: string;
|
|
165
165
|
id: import("mongoose").Types.ObjectId;
|
|
166
166
|
}>;
|
|
167
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
167
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
168
168
|
media: z.ZodArray<z.ZodObject<{
|
|
169
169
|
mimeType: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
170
170
|
mediaType: z.ZodNativeEnum<typeof MediaType>;
|
|
171
171
|
mediaUrl: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
172
|
-
thumbnailUrl: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
173
|
-
name: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
172
|
+
thumbnailUrl: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
173
|
+
name: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
174
174
|
}, "strip", z.ZodTypeAny, {
|
|
175
|
-
mediaType: MediaType;
|
|
176
175
|
mediaUrl: string;
|
|
176
|
+
mediaType: MediaType;
|
|
177
177
|
mimeType: string;
|
|
178
178
|
name?: string | undefined;
|
|
179
179
|
thumbnailUrl?: string | undefined;
|
|
180
180
|
}, {
|
|
181
|
-
mediaType: MediaType;
|
|
182
181
|
mediaUrl: string;
|
|
182
|
+
mediaType: MediaType;
|
|
183
183
|
mimeType: string;
|
|
184
184
|
name?: string | undefined;
|
|
185
185
|
thumbnailUrl?: string | undefined;
|
|
@@ -208,19 +208,19 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
208
208
|
};
|
|
209
209
|
senderType: UserRef;
|
|
210
210
|
media: {
|
|
211
|
-
mediaType: MediaType;
|
|
212
211
|
mediaUrl: string;
|
|
212
|
+
mediaType: MediaType;
|
|
213
213
|
mimeType: string;
|
|
214
214
|
name?: string | undefined;
|
|
215
215
|
thumbnailUrl?: string | undefined;
|
|
216
216
|
}[];
|
|
217
217
|
chatroomType: ChatroomType;
|
|
218
218
|
senderId: import("mongoose").Types.ObjectId;
|
|
219
|
-
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
220
219
|
location?: {
|
|
221
220
|
latitude?: number | undefined;
|
|
222
221
|
longitude?: number | undefined;
|
|
223
222
|
} | undefined;
|
|
223
|
+
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
224
224
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
225
225
|
content?: string | undefined;
|
|
226
226
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
@@ -234,25 +234,25 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
234
234
|
};
|
|
235
235
|
senderType: UserRef;
|
|
236
236
|
media: {
|
|
237
|
-
mediaType: MediaType;
|
|
238
237
|
mediaUrl: string;
|
|
238
|
+
mediaType: MediaType;
|
|
239
239
|
mimeType: string;
|
|
240
240
|
name?: string | undefined;
|
|
241
241
|
thumbnailUrl?: string | undefined;
|
|
242
242
|
}[];
|
|
243
243
|
chatroomType: ChatroomType;
|
|
244
244
|
senderId: import("mongoose").Types.ObjectId;
|
|
245
|
-
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
246
245
|
location?: {
|
|
247
246
|
latitude?: number | undefined;
|
|
248
247
|
longitude?: number | undefined;
|
|
249
248
|
} | undefined;
|
|
249
|
+
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
250
250
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
251
251
|
content?: string | undefined;
|
|
252
252
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
253
253
|
}>;
|
|
254
254
|
pushNotificationOutput: z.ZodObject<{
|
|
255
|
-
lastMessage: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
255
|
+
lastMessage: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
256
256
|
chatroomId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
257
257
|
ticketId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
258
258
|
orderId: z.ZodOptional<z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>>;
|
|
@@ -260,14 +260,14 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
260
260
|
}, "strip", z.ZodTypeAny, {
|
|
261
261
|
type: ChatroomType;
|
|
262
262
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
263
|
-
lastMessage?: string | undefined;
|
|
264
263
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
264
|
+
lastMessage?: string | undefined;
|
|
265
265
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
266
266
|
}, {
|
|
267
267
|
type: ChatroomType;
|
|
268
268
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
269
|
-
lastMessage?: string | undefined;
|
|
270
269
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
270
|
+
lastMessage?: string | undefined;
|
|
271
271
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
272
272
|
}>;
|
|
273
273
|
};
|
|
@@ -278,8 +278,8 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
278
278
|
getPushNotificationPayload(): {
|
|
279
279
|
type: ChatroomType;
|
|
280
280
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
281
|
-
lastMessage?: string | undefined;
|
|
282
281
|
ticketId?: import("mongoose").Types.ObjectId | undefined;
|
|
282
|
+
lastMessage?: string | undefined;
|
|
283
283
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
284
284
|
} | undefined;
|
|
285
285
|
protected getIdentifier(): string;
|