@lyxa.ai/core 1.4.333-alpha-2.0 → 1.4.334-alpha-11
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/embedded/live-activity-token-info.model.d.ts +4 -0
- package/dist/libraries/mongo/models/embedded/live-activity-token-info.model.js +27 -0
- package/dist/libraries/mongo/models/embedded/live-activity-token-info.model.js.map +1 -0
- package/dist/libraries/mongo/models/order.model.d.ts +2 -1
- package/dist/libraries/mongo/models/order.model.js +5 -4
- package/dist/libraries/mongo/models/order.model.js.map +1 -1
- package/dist/libraries/notification/firebase-message.builder.js +1 -1
- package/dist/libraries/notification/firebase-message.builder.js.map +1 -1
- package/dist/libraries/notification/index.d.ts +1 -0
- package/dist/libraries/notification/index.js.map +1 -1
- package/dist/libraries/notification/lyxa-fcm-sender.js +7 -0
- package/dist/libraries/notification/lyxa-fcm-sender.js.map +1 -1
- package/dist/libraries/notification/lyxa-fcm.service.js +8 -4
- 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 +20 -20
- package/dist/libraries/socket/events/order-actions.socket.event.d.ts +20 -20
- package/dist/libraries/socket/events/rider-location-update.socket.event.d.ts +8 -8
- package/dist/libraries/socket/events/ticket-actions.socket.event.d.ts +12 -12
- package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +24 -24
- 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
|
@@ -20,21 +20,21 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
20
20
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
21
21
|
type: z.ZodNativeEnum<typeof UserRef>;
|
|
22
22
|
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
type: UserRef;
|
|
24
23
|
name: string;
|
|
25
24
|
id: import("mongoose").Types.ObjectId;
|
|
26
|
-
}, {
|
|
27
25
|
type: UserRef;
|
|
26
|
+
}, {
|
|
28
27
|
name: string;
|
|
29
28
|
id: import("mongoose").Types.ObjectId;
|
|
29
|
+
type: UserRef;
|
|
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
39
|
mediaType: MediaType;
|
|
40
40
|
mediaUrl: string;
|
|
@@ -63,12 +63,12 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
63
63
|
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>>;
|
|
64
64
|
createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
|
|
65
65
|
}, "strip", z.ZodTypeAny, {
|
|
66
|
-
_id: import("mongoose").Types.ObjectId;
|
|
67
66
|
createdAt: Date;
|
|
67
|
+
_id: import("mongoose").Types.ObjectId;
|
|
68
68
|
sender: {
|
|
69
|
-
type: UserRef;
|
|
70
69
|
name: string;
|
|
71
70
|
id: import("mongoose").Types.ObjectId;
|
|
71
|
+
type: UserRef;
|
|
72
72
|
};
|
|
73
73
|
senderType: UserRef;
|
|
74
74
|
media: {
|
|
@@ -89,12 +89,12 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
89
89
|
content?: string | undefined;
|
|
90
90
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
91
91
|
}, {
|
|
92
|
-
_id: import("mongoose").Types.ObjectId;
|
|
93
92
|
createdAt: Date;
|
|
93
|
+
_id: import("mongoose").Types.ObjectId;
|
|
94
94
|
sender: {
|
|
95
|
-
type: UserRef;
|
|
96
95
|
name: string;
|
|
97
96
|
id: import("mongoose").Types.ObjectId;
|
|
97
|
+
type: UserRef;
|
|
98
98
|
};
|
|
99
99
|
senderType: UserRef;
|
|
100
100
|
media: {
|
|
@@ -116,7 +116,7 @@ export declare const ChatroomMessageSendOutputSchema: z.ZodObject<{
|
|
|
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>>;
|
|
@@ -156,21 +156,21 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
156
156
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
157
157
|
type: z.ZodNativeEnum<typeof UserRef>;
|
|
158
158
|
}, "strip", z.ZodTypeAny, {
|
|
159
|
-
type: UserRef;
|
|
160
159
|
name: string;
|
|
161
160
|
id: import("mongoose").Types.ObjectId;
|
|
162
|
-
}, {
|
|
163
161
|
type: UserRef;
|
|
162
|
+
}, {
|
|
164
163
|
name: string;
|
|
165
164
|
id: import("mongoose").Types.ObjectId;
|
|
165
|
+
type: UserRef;
|
|
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
175
|
mediaType: MediaType;
|
|
176
176
|
mediaUrl: string;
|
|
@@ -199,12 +199,12 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
199
199
|
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>>;
|
|
200
200
|
createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
|
|
201
201
|
}, "strip", z.ZodTypeAny, {
|
|
202
|
-
_id: import("mongoose").Types.ObjectId;
|
|
203
202
|
createdAt: Date;
|
|
203
|
+
_id: import("mongoose").Types.ObjectId;
|
|
204
204
|
sender: {
|
|
205
|
-
type: UserRef;
|
|
206
205
|
name: string;
|
|
207
206
|
id: import("mongoose").Types.ObjectId;
|
|
207
|
+
type: UserRef;
|
|
208
208
|
};
|
|
209
209
|
senderType: UserRef;
|
|
210
210
|
media: {
|
|
@@ -225,12 +225,12 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
225
225
|
content?: string | undefined;
|
|
226
226
|
chatroomId?: import("mongoose").Types.ObjectId | undefined;
|
|
227
227
|
}, {
|
|
228
|
-
_id: import("mongoose").Types.ObjectId;
|
|
229
228
|
createdAt: Date;
|
|
229
|
+
_id: import("mongoose").Types.ObjectId;
|
|
230
230
|
sender: {
|
|
231
|
-
type: UserRef;
|
|
232
231
|
name: string;
|
|
233
232
|
id: import("mongoose").Types.ObjectId;
|
|
233
|
+
type: UserRef;
|
|
234
234
|
};
|
|
235
235
|
senderType: UserRef;
|
|
236
236
|
media: {
|
|
@@ -252,7 +252,7 @@ export declare class ChatroomMessageSendSocketEvent extends BaseSocketEvent<type
|
|
|
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>>;
|
|
@@ -16,11 +16,11 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
|
|
|
16
16
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
17
17
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
18
18
|
}, "strip", z.ZodTypeAny, {
|
|
19
|
-
_id: import("mongoose").Types.ObjectId;
|
|
20
19
|
name: string;
|
|
20
|
+
_id: import("mongoose").Types.ObjectId;
|
|
21
21
|
}, {
|
|
22
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
23
22
|
name: string;
|
|
23
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
24
24
|
}>;
|
|
25
25
|
orderStatus: z.ZodNativeEnum<typeof RegularOrderStatus>;
|
|
26
26
|
orderAction: z.ZodNativeEnum<typeof OrderAction>;
|
|
@@ -88,15 +88,15 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
|
|
|
88
88
|
triggerAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
|
|
89
89
|
orderActionType: z.ZodNativeEnum<typeof OrderAction>;
|
|
90
90
|
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
_id: import("mongoose").Types.ObjectId;
|
|
92
|
-
orderId: string;
|
|
93
|
-
shopId: import("mongoose").Types.ObjectId;
|
|
94
91
|
createdAt: Date;
|
|
92
|
+
_id: import("mongoose").Types.ObjectId;
|
|
95
93
|
user: {
|
|
96
|
-
_id: import("mongoose").Types.ObjectId;
|
|
97
94
|
name: string;
|
|
95
|
+
_id: import("mongoose").Types.ObjectId;
|
|
98
96
|
};
|
|
97
|
+
orderId: string;
|
|
99
98
|
triggerAt: Date;
|
|
99
|
+
shopId: import("mongoose").Types.ObjectId;
|
|
100
100
|
adjustedFinance: {
|
|
101
101
|
paymentMethod: PaymentMethod;
|
|
102
102
|
pricing: {
|
|
@@ -117,15 +117,15 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
|
|
|
117
117
|
orderAction: OrderAction;
|
|
118
118
|
preparationTimeMinutes: number;
|
|
119
119
|
}, {
|
|
120
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
121
|
-
orderId: string;
|
|
122
|
-
shopId: string | import("mongoose").Types.ObjectId;
|
|
123
120
|
createdAt: Date;
|
|
121
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
124
122
|
user: {
|
|
125
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
126
123
|
name: string;
|
|
124
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
127
125
|
};
|
|
126
|
+
orderId: string;
|
|
128
127
|
triggerAt: Date;
|
|
128
|
+
shopId: string | import("mongoose").Types.ObjectId;
|
|
129
129
|
adjustedFinance: {
|
|
130
130
|
paymentMethod: PaymentMethod;
|
|
131
131
|
pricing: {
|
|
@@ -160,11 +160,11 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
|
|
|
160
160
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
161
161
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
162
162
|
}, "strip", z.ZodTypeAny, {
|
|
163
|
-
_id: import("mongoose").Types.ObjectId;
|
|
164
163
|
name: string;
|
|
164
|
+
_id: import("mongoose").Types.ObjectId;
|
|
165
165
|
}, {
|
|
166
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
167
166
|
name: string;
|
|
167
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
168
168
|
}>;
|
|
169
169
|
orderStatus: z.ZodNativeEnum<typeof RegularOrderStatus>;
|
|
170
170
|
orderAction: z.ZodNativeEnum<typeof OrderAction>;
|
|
@@ -232,15 +232,15 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
|
|
|
232
232
|
triggerAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
|
|
233
233
|
orderActionType: z.ZodNativeEnum<typeof OrderAction>;
|
|
234
234
|
}, "strip", z.ZodTypeAny, {
|
|
235
|
-
_id: import("mongoose").Types.ObjectId;
|
|
236
|
-
orderId: string;
|
|
237
|
-
shopId: import("mongoose").Types.ObjectId;
|
|
238
235
|
createdAt: Date;
|
|
236
|
+
_id: import("mongoose").Types.ObjectId;
|
|
239
237
|
user: {
|
|
240
|
-
_id: import("mongoose").Types.ObjectId;
|
|
241
238
|
name: string;
|
|
239
|
+
_id: import("mongoose").Types.ObjectId;
|
|
242
240
|
};
|
|
241
|
+
orderId: string;
|
|
243
242
|
triggerAt: Date;
|
|
243
|
+
shopId: import("mongoose").Types.ObjectId;
|
|
244
244
|
adjustedFinance: {
|
|
245
245
|
paymentMethod: PaymentMethod;
|
|
246
246
|
pricing: {
|
|
@@ -261,15 +261,15 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
|
|
|
261
261
|
orderAction: OrderAction;
|
|
262
262
|
preparationTimeMinutes: number;
|
|
263
263
|
}, {
|
|
264
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
265
|
-
orderId: string;
|
|
266
|
-
shopId: string | import("mongoose").Types.ObjectId;
|
|
267
264
|
createdAt: Date;
|
|
265
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
268
266
|
user: {
|
|
269
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
270
267
|
name: string;
|
|
268
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
271
269
|
};
|
|
270
|
+
orderId: string;
|
|
272
271
|
triggerAt: Date;
|
|
272
|
+
shopId: string | import("mongoose").Types.ObjectId;
|
|
273
273
|
adjustedFinance: {
|
|
274
274
|
paymentMethod: PaymentMethod;
|
|
275
275
|
pricing: {
|
|
@@ -19,18 +19,18 @@ export declare const RiderLocationUpdateSocketOutputSchema: z.ZodObject<{
|
|
|
19
19
|
bearing: z.ZodOptional<z.ZodNumber>;
|
|
20
20
|
updatedAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
updatedAt: Date;
|
|
22
23
|
_id: import("mongoose").Types.ObjectId;
|
|
24
|
+
riderId: import("mongoose").Types.ObjectId;
|
|
23
25
|
latitude: number;
|
|
24
26
|
longitude: number;
|
|
25
|
-
updatedAt: Date;
|
|
26
|
-
riderId: import("mongoose").Types.ObjectId;
|
|
27
27
|
bearing?: number | undefined;
|
|
28
28
|
}, {
|
|
29
|
+
updatedAt: string | Date;
|
|
29
30
|
_id: string | import("mongoose").Types.ObjectId;
|
|
31
|
+
riderId: string | import("mongoose").Types.ObjectId;
|
|
30
32
|
latitude: number;
|
|
31
33
|
longitude: number;
|
|
32
|
-
updatedAt: string | Date;
|
|
33
|
-
riderId: string | import("mongoose").Types.ObjectId;
|
|
34
34
|
bearing?: number | undefined;
|
|
35
35
|
}>;
|
|
36
36
|
export type RiderLocationUpdateSocketInputDTO = DTO<typeof RiderLocationUpdateSocketInputSchema>;
|
|
@@ -55,18 +55,18 @@ export declare class RiderLocationUpdateSocketEvent extends BaseSocketEvent<type
|
|
|
55
55
|
bearing: z.ZodOptional<z.ZodNumber>;
|
|
56
56
|
updatedAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
57
57
|
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
updatedAt: Date;
|
|
58
59
|
_id: import("mongoose").Types.ObjectId;
|
|
60
|
+
riderId: import("mongoose").Types.ObjectId;
|
|
59
61
|
latitude: number;
|
|
60
62
|
longitude: number;
|
|
61
|
-
updatedAt: Date;
|
|
62
|
-
riderId: import("mongoose").Types.ObjectId;
|
|
63
63
|
bearing?: number | undefined;
|
|
64
64
|
}, {
|
|
65
|
+
updatedAt: string | Date;
|
|
65
66
|
_id: string | import("mongoose").Types.ObjectId;
|
|
67
|
+
riderId: string | import("mongoose").Types.ObjectId;
|
|
66
68
|
latitude: number;
|
|
67
69
|
longitude: number;
|
|
68
|
-
updatedAt: string | Date;
|
|
69
|
-
riderId: string | import("mongoose").Types.ObjectId;
|
|
70
70
|
bearing?: number | undefined;
|
|
71
71
|
}>;
|
|
72
72
|
};
|
|
@@ -8,20 +8,20 @@ export declare const TicketActionsSocketOutputSchema: z.ZodObject<{
|
|
|
8
8
|
_id: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
|
|
9
9
|
status: z.ZodNativeEnum<typeof TicketStatus>;
|
|
10
10
|
type: z.ZodNativeEnum<typeof TicketType>;
|
|
11
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
12
|
-
title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
11
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
12
|
+
title: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
13
13
|
silent: z.ZodOptional<z.ZodBoolean>;
|
|
14
14
|
}, "strip", z.ZodTypeAny, {
|
|
15
15
|
status: TicketStatus;
|
|
16
|
-
type: TicketType;
|
|
17
16
|
_id: import("mongoose").Types.ObjectId;
|
|
17
|
+
type: TicketType;
|
|
18
18
|
title?: string | undefined;
|
|
19
19
|
content?: string | undefined;
|
|
20
20
|
silent?: boolean | undefined;
|
|
21
21
|
}, {
|
|
22
22
|
status: TicketStatus;
|
|
23
|
-
type: TicketType;
|
|
24
23
|
_id: import("mongoose").Types.ObjectId;
|
|
24
|
+
type: TicketType;
|
|
25
25
|
title?: string | undefined;
|
|
26
26
|
content?: string | undefined;
|
|
27
27
|
silent?: boolean | undefined;
|
|
@@ -30,8 +30,8 @@ export declare const TicketActionsPushOutputSchema: z.ZodObject<{
|
|
|
30
30
|
ticketId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
|
|
31
31
|
status: z.ZodNativeEnum<typeof TicketStatus>;
|
|
32
32
|
type: z.ZodNativeEnum<typeof TicketType>;
|
|
33
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
34
|
-
title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
33
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
34
|
+
title: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
35
35
|
}, "strip", z.ZodTypeAny, {
|
|
36
36
|
status: TicketStatus;
|
|
37
37
|
type: TicketType;
|
|
@@ -55,20 +55,20 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
|
|
|
55
55
|
_id: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
|
|
56
56
|
status: z.ZodNativeEnum<typeof TicketStatus>;
|
|
57
57
|
type: z.ZodNativeEnum<typeof TicketType>;
|
|
58
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
59
|
-
title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
58
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
59
|
+
title: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
60
60
|
silent: z.ZodOptional<z.ZodBoolean>;
|
|
61
61
|
}, "strip", z.ZodTypeAny, {
|
|
62
62
|
status: TicketStatus;
|
|
63
|
-
type: TicketType;
|
|
64
63
|
_id: import("mongoose").Types.ObjectId;
|
|
64
|
+
type: TicketType;
|
|
65
65
|
title?: string | undefined;
|
|
66
66
|
content?: string | undefined;
|
|
67
67
|
silent?: boolean | undefined;
|
|
68
68
|
}, {
|
|
69
69
|
status: TicketStatus;
|
|
70
|
-
type: TicketType;
|
|
71
70
|
_id: import("mongoose").Types.ObjectId;
|
|
71
|
+
type: TicketType;
|
|
72
72
|
title?: string | undefined;
|
|
73
73
|
content?: string | undefined;
|
|
74
74
|
silent?: boolean | undefined;
|
|
@@ -77,8 +77,8 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
|
|
|
77
77
|
ticketId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
|
|
78
78
|
status: z.ZodNativeEnum<typeof TicketStatus>;
|
|
79
79
|
type: z.ZodNativeEnum<typeof TicketType>;
|
|
80
|
-
content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
81
|
-
title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
80
|
+
content: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
81
|
+
title: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
82
82
|
}, "strip", z.ZodTypeAny, {
|
|
83
83
|
status: TicketStatus;
|
|
84
84
|
type: TicketType;
|
|
@@ -13,14 +13,14 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
13
13
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
14
14
|
profilePhoto: z.ZodNullable<z.ZodString> | z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
15
15
|
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
type: UserRef;
|
|
17
|
-
_id: import("mongoose").Types.ObjectId;
|
|
18
16
|
name: string;
|
|
17
|
+
_id: import("mongoose").Types.ObjectId;
|
|
18
|
+
type: UserRef;
|
|
19
19
|
profilePhoto: string | null;
|
|
20
20
|
}, {
|
|
21
|
-
type: UserRef;
|
|
22
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
23
21
|
name: string;
|
|
22
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
23
|
+
type: UserRef;
|
|
24
24
|
profilePhoto: string | null;
|
|
25
25
|
}>;
|
|
26
26
|
createdAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
@@ -40,18 +40,18 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
40
40
|
unreadCount: z.ZodNumber;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
42
|
status: TicketStatus;
|
|
43
|
-
type: TicketType;
|
|
44
|
-
_id: import("mongoose").Types.ObjectId;
|
|
45
43
|
createdAt: Date;
|
|
46
44
|
updatedAt: Date;
|
|
45
|
+
_id: import("mongoose").Types.ObjectId;
|
|
46
|
+
type: TicketType;
|
|
47
47
|
lastMessage: {
|
|
48
48
|
createdAt: Date;
|
|
49
49
|
content: string;
|
|
50
50
|
};
|
|
51
51
|
client: {
|
|
52
|
-
type: UserRef;
|
|
53
|
-
_id: import("mongoose").Types.ObjectId;
|
|
54
52
|
name: string;
|
|
53
|
+
_id: import("mongoose").Types.ObjectId;
|
|
54
|
+
type: UserRef;
|
|
55
55
|
profilePhoto: string | null;
|
|
56
56
|
};
|
|
57
57
|
unreadCount: number;
|
|
@@ -59,18 +59,18 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
59
59
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
60
60
|
}, {
|
|
61
61
|
status: TicketStatus;
|
|
62
|
-
type: TicketType;
|
|
63
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
64
62
|
createdAt: string | Date;
|
|
65
63
|
updatedAt: string | Date;
|
|
64
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
65
|
+
type: TicketType;
|
|
66
66
|
lastMessage: {
|
|
67
67
|
createdAt: string | Date;
|
|
68
68
|
content: string;
|
|
69
69
|
};
|
|
70
70
|
client: {
|
|
71
|
-
type: UserRef;
|
|
72
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
73
71
|
name: string;
|
|
72
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
73
|
+
type: UserRef;
|
|
74
74
|
profilePhoto: string | null;
|
|
75
75
|
};
|
|
76
76
|
unreadCount: number;
|
|
@@ -91,14 +91,14 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
91
91
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
92
92
|
profilePhoto: z.ZodNullable<z.ZodString> | z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
93
93
|
}, "strip", z.ZodTypeAny, {
|
|
94
|
-
type: UserRef;
|
|
95
|
-
_id: import("mongoose").Types.ObjectId;
|
|
96
94
|
name: string;
|
|
95
|
+
_id: import("mongoose").Types.ObjectId;
|
|
96
|
+
type: UserRef;
|
|
97
97
|
profilePhoto: string | null;
|
|
98
98
|
}, {
|
|
99
|
-
type: UserRef;
|
|
100
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
101
99
|
name: string;
|
|
100
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
101
|
+
type: UserRef;
|
|
102
102
|
profilePhoto: string | null;
|
|
103
103
|
}>;
|
|
104
104
|
createdAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
@@ -118,18 +118,18 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
118
118
|
unreadCount: z.ZodNumber;
|
|
119
119
|
}, "strip", z.ZodTypeAny, {
|
|
120
120
|
status: TicketStatus;
|
|
121
|
-
type: TicketType;
|
|
122
|
-
_id: import("mongoose").Types.ObjectId;
|
|
123
121
|
createdAt: Date;
|
|
124
122
|
updatedAt: Date;
|
|
123
|
+
_id: import("mongoose").Types.ObjectId;
|
|
124
|
+
type: TicketType;
|
|
125
125
|
lastMessage: {
|
|
126
126
|
createdAt: Date;
|
|
127
127
|
content: string;
|
|
128
128
|
};
|
|
129
129
|
client: {
|
|
130
|
-
type: UserRef;
|
|
131
|
-
_id: import("mongoose").Types.ObjectId;
|
|
132
130
|
name: string;
|
|
131
|
+
_id: import("mongoose").Types.ObjectId;
|
|
132
|
+
type: UserRef;
|
|
133
133
|
profilePhoto: string | null;
|
|
134
134
|
};
|
|
135
135
|
unreadCount: number;
|
|
@@ -137,18 +137,18 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
137
137
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
138
138
|
}, {
|
|
139
139
|
status: TicketStatus;
|
|
140
|
-
type: TicketType;
|
|
141
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
142
140
|
createdAt: string | Date;
|
|
143
141
|
updatedAt: string | Date;
|
|
142
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
143
|
+
type: TicketType;
|
|
144
144
|
lastMessage: {
|
|
145
145
|
createdAt: string | Date;
|
|
146
146
|
content: string;
|
|
147
147
|
};
|
|
148
148
|
client: {
|
|
149
|
-
type: UserRef;
|
|
150
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
151
149
|
name: string;
|
|
150
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
151
|
+
type: UserRef;
|
|
152
152
|
profilePhoto: string | null;
|
|
153
153
|
};
|
|
154
154
|
unreadCount: number;
|
|
@@ -6,9 +6,9 @@ interface AuthOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
8
|
requestId: string | undefined;
|
|
9
|
+
entity: import("../context").EntityContext | undefined;
|
|
9
10
|
req: import("http").IncomingMessage;
|
|
10
11
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
11
|
-
entity: import("../context").EntityContext | undefined;
|
|
12
12
|
tokenType: TokenType | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
|
@@ -7,6 +7,7 @@ const auth_1 = require("../../auth");
|
|
|
7
7
|
const models_1 = require("../../mongo/models");
|
|
8
8
|
const enum_1 = require("../../../utilities/enum");
|
|
9
9
|
const error_common_1 = require("../../../utilities/error-common");
|
|
10
|
+
const __1 = require("../../..");
|
|
10
11
|
function createAuthenticatedProcedure(options) {
|
|
11
12
|
const { entityTypes, allowRefreshToken = true, autoRefresh = true } = options;
|
|
12
13
|
return index_1.publicProcedure.use(async ({ ctx, next }) => {
|
|
@@ -74,6 +75,7 @@ function createAuthenticatedProcedure(options) {
|
|
|
74
75
|
else {
|
|
75
76
|
(0, error_common_1.unauthorizedError)('You have been logged out, Please login in again');
|
|
76
77
|
}
|
|
78
|
+
await (0, __1.getLibraries)().getRedisService().setLastOnline(auth_1.AuthEntityType.DELIVERY_BOY, rider._id.toString());
|
|
77
79
|
}
|
|
78
80
|
if (entity) {
|
|
79
81
|
ctx.entity = entity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/auth.ts"],"names":[],"mappings":";;AAwBA,oEA4HC;AApJD,yCAAyC;AACzC,oCAA2C;AAC3C,qCAA+F;AAC/F,+CAO4B;AAC5B,kDAAiD;AACjD,kEAAoE;AAYpE,SAAgB,4BAA4B,CAAC,OAAoB;IAChE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE9E,OAAO,uBAAe,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;QAClD,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACpD,MAAM,kBAAkB,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAE9D,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,MAAM,IAAI,kBAAS,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,YAAY,GAAG,EAAE,CAAC;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C,YAAY,CAAC,CAAC;QAE7D,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,YAAY,GACjB,aAAa,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,uBAAuB,CAAC;YAEtG,IAAA,gCAAiB,EAAC,YAAY,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAO,CAAC,IAAI,CAAC;YAAE,IAAA,gCAAiB,EAAC,0BAA0B,CAAC,CAAC;QAErG,GAAG,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;QAClC,GAAG,CAAC,SAAS,GAAG,gBAAS,CAAC,OAAO,CAAC;QAClC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE5B,GAAG,CAAC,YAAY,GAAG,aAAa,CAAC,WAAW,KAAK,SAAS,CAAC;QAE3D,IAAI,WAAW,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;YAC5C,IAAI,aAAa,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;gBACzC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,EAAE,aAAa,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAC9E,CAAC;YAED,IAAI,aAAa,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;gBAC1C,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;YAChF,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { TRPCError } from '@trpc/server';\nimport { publicProcedure } from '../index';\nimport { AuthEntityType, handleTokenRenewal, TokenType, verifyAccessToken, } from '../../auth';\nimport {\n\tAdminModel,\n\tgetCoreUserModel,\n\tParentModel,\n\tRiderModel,\n\tShopAccessControlModel,\n\tShopModel,\n} from '../../mongo/models';\nimport { Status } from '../../../utilities/enum';\nimport { unauthorizedError } from '../../../utilities/error-common';\n\ninterface AuthOptions {\n\tentityTypes: AuthEntityType[];\n\tallowRefreshToken?: boolean;\n\tautoRefresh?: boolean;\n}\n\n/**\n * A factory that creates an authenticated procedure, optionally allowing\n * refresh tokens and auto-refreshing expired access tokens.\n */\nexport function createAuthenticatedProcedure(options: AuthOptions) {\n\tconst { entityTypes, allowRefreshToken = true, autoRefresh = true } = options;\n\n\treturn publicProcedure.use(async ({ ctx, next }) => {\n\t\tconst authHeader = ctx.req.headers['authorization'];\n\t\tconst refreshTokenHeader = ctx.req.headers['x-refresh-token'];\n\n\t\tif (!authHeader) {\n\t\t\tthrow new TRPCError({ code: 'UNAUTHORIZED', message: 'No authorization header' });\n\t\t}\n\n\t\tconst accessToken = authHeader.replace(/^Bearer\\s+/, '');\n\t\tlet refreshToken = '';\n\n\t\tif (refreshTokenHeader) {\n\t\t\trefreshToken =\n\t\t\t\ttypeof refreshTokenHeader === 'string'\n\t\t\t\t\t? refreshTokenHeader.replace(/^Bearer\\s+/, '')\n\t\t\t\t\t: refreshTokenHeader[0].replace(/^Bearer\\s+/, '');\n\t\t}\n\n\t\tif (!accessToken) unauthorizedError('Missing access token');\n\n\t\tlet entity = await verifyAccessToken(entityTypes, accessToken);\n\n\t\tif (entity?.type == AuthEntityType.USER) {\n\t\t\tconst user = await getCoreUserModel().findOne({ _id: entity.parameters.coreUserId });\n\n\t\t\tif (!user) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not found' });\n\t\t\tif (user.status !== Status.ACTIVE) unauthorizedError('User is not active');\n\t\t}\n\n\t\tif (entity?.type == AuthEntityType.CRM) {\n\t\t\tconst admin = await AdminModel.findOne({ _id: entity.parameters.adminId });\n\n\t\t\tif (!admin) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Admin not found' });\n\t\t\tif (admin.status !== Status.ACTIVE) unauthorizedError('Admin is not active');\n\t\t}\n\n\t\t// Seller\n\t\tif (entity?.type == AuthEntityType.SELLER) {\n\t\t\tconst shopAccessControlModel = await ShopAccessControlModel.findOne({ _id: entity.id });\n\t\t\tif (!shopAccessControlModel) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\n\t\t\t// For Parent\n\t\t\tif (['parent', 'parent_manager', 'parent_order_manager'].includes(shopAccessControlModel.role)) {\n\t\t\t\tconst parent = await ParentModel.findOne({ _id: shopAccessControlModel.parent });\n\n\t\t\t\tif (!parent) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\t\t\t\tif (parent.status !== Status.ACTIVE) unauthorizedError('Seller is not active');\n\t\t\t}\n\n\t\t\t// For Shop\n\t\t\tconst shops = shopAccessControlModel.shops ?? [];\n\n\t\t\tif (\n\t\t\t\tshops.length > 0 &&\n\t\t\t\t['shop', 'shop_manager', 'shop_order_manager'].includes(shopAccessControlModel.role)\n\t\t\t) {\n\t\t\t\tconst shopId = shops[0];\n\t\t\t\tconst shop = await ShopModel.findOne({ _id: shopId });\n\n\t\t\t\tif (!shop) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\t\t\t\tif (shop.status !== Status.ACTIVE) unauthorizedError('Seller is not active');\n\t\t\t}\n\t\t}\n\n\t\t// For rider\n\t\tif (entity?.type == AuthEntityType.DELIVERY_BOY) {\n\t\t\tconst rider = await RiderModel.findOne({ _id: entity.id });\n\n\t\t\t// Check the rider exists or not\n\t\t\tif (!rider) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Admin not found' });\n\n\t\t\t// Check the rider isLogin true or false\n\t\t\tif (rider.isLogin) {\n\t\t\t\tif (rider.lastLoginDeviceId !== entity.parameters.deviceId) {\n\t\t\t\t\tunauthorizedError('You already logged in another device');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tunauthorizedError('You have been logged out, Please login in again');\n\t\t\t}\n\t\t}\n\n\t\tif (entity) {\n\t\t\tctx.entity = entity;\n\t\t\tctx.tokenType = TokenType.ACCESS;\n\t\t\tctx.usedRefreshToken = false;\n\t\t\tctx.tokenRenewed = false;\n\n\t\t\treturn next({ ctx });\n\t\t}\n\n\t\tif (!allowRefreshToken || !refreshToken) unauthorizedError('Invalid access token');\n\n\t\tconst renewalResult = await handleTokenRenewal(refreshToken);\n\n\t\tif (!renewalResult.success) {\n\t\t\tconst errorMessage =\n\t\t\t\trenewalResult.tokenStatus === 'revoked' ? 'Refresh token has been revoked' : 'Invalid refresh token';\n\n\t\t\tunauthorizedError(errorMessage);\n\t\t}\n\n\t\tif (!entityTypes.includes(renewalResult.entity!.type)) unauthorizedError('Unauthorized entity type');\n\n\t\tctx.entity = renewalResult.entity;\n\t\tctx.tokenType = TokenType.REFRESH;\n\t\tctx.usedRefreshToken = true;\n\n\t\tctx.tokenRenewed = renewalResult.tokenStatus === 'expired';\n\n\t\tif (autoRefresh && renewalResult.newTokens) {\n\t\t\tif (renewalResult.newTokens.accessToken) {\n\t\t\t\tctx.res.setHeader('X-New-Access-Token', renewalResult.newTokens.accessToken);\n\t\t\t}\n\n\t\t\tif (renewalResult.newTokens.refreshToken) {\n\t\t\t\tctx.res.setHeader('X-New-Refresh-Token', renewalResult.newTokens.refreshToken);\n\t\t\t}\n\t\t}\n\n\t\treturn next({ ctx });\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/auth.ts"],"names":[],"mappings":";;AAyBA,oEA8HC;AAvJD,yCAAyC;AACzC,oCAA2C;AAC3C,qCAA8F;AAC9F,+CAO4B;AAC5B,kDAAiD;AACjD,kEAAoE;AACpE,gCAAwC;AAYxC,SAAgB,4BAA4B,CAAC,OAAoB;IAChE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE9E,OAAO,uBAAe,CAAC,GAAG,CAAC,KAAK,EA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AAC,SAAS,EAAE,CAAC;YAC5C,IAAI,aAAa,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;gBACzC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,EAAE,aAAa,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAC9E,CAAC;YAED,IAAI,aAAa,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;gBAC1C,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;YAChF,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { TRPCError } from '@trpc/server';\nimport { publicProcedure } from '../index';\nimport { AuthEntityType, handleTokenRenewal, TokenType, verifyAccessToken } from '../../auth';\nimport {\n\tAdminModel,\n\tgetCoreUserModel,\n\tParentModel,\n\tRiderModel,\n\tShopAccessControlModel,\n\tShopModel,\n} from '../../mongo/models';\nimport { Status } from '../../../utilities/enum';\nimport { unauthorizedError } from '../../../utilities/error-common';\nimport { getLibraries } from '../../..';\n\ninterface AuthOptions {\n\tentityTypes: AuthEntityType[];\n\tallowRefreshToken?: boolean;\n\tautoRefresh?: boolean;\n}\n\n/**\n * A factory that creates an authenticated procedure, optionally allowing\n * refresh tokens and auto-refreshing expired access tokens.\n */\nexport function createAuthenticatedProcedure(options: AuthOptions) {\n\tconst { entityTypes, allowRefreshToken = true, autoRefresh = true } = options;\n\n\treturn publicProcedure.use(async ({ ctx, next }) => {\n\t\tconst authHeader = ctx.req.headers['authorization'];\n\t\tconst refreshTokenHeader = ctx.req.headers['x-refresh-token'];\n\n\t\tif (!authHeader) {\n\t\t\tthrow new TRPCError({ code: 'UNAUTHORIZED', message: 'No authorization header' });\n\t\t}\n\n\t\tconst accessToken = authHeader.replace(/^Bearer\\s+/, '');\n\t\tlet refreshToken = '';\n\n\t\tif (refreshTokenHeader) {\n\t\t\trefreshToken =\n\t\t\t\ttypeof refreshTokenHeader === 'string'\n\t\t\t\t\t? refreshTokenHeader.replace(/^Bearer\\s+/, '')\n\t\t\t\t\t: refreshTokenHeader[0].replace(/^Bearer\\s+/, '');\n\t\t}\n\n\t\tif (!accessToken) unauthorizedError('Missing access token');\n\n\t\tlet entity = await verifyAccessToken(entityTypes, accessToken);\n\n\t\tif (entity?.type == AuthEntityType.USER) {\n\t\t\tconst user = await getCoreUserModel().findOne({ _id: entity.parameters.coreUserId });\n\n\t\t\tif (!user) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not found' });\n\t\t\tif (user.status !== Status.ACTIVE) unauthorizedError('User is not active');\n\t\t}\n\n\t\tif (entity?.type == AuthEntityType.CRM) {\n\t\t\tconst admin = await AdminModel.findOne({ _id: entity.parameters.adminId });\n\n\t\t\tif (!admin) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Admin not found' });\n\t\t\tif (admin.status !== Status.ACTIVE) unauthorizedError('Admin is not active');\n\t\t}\n\n\t\t// Seller\n\t\tif (entity?.type == AuthEntityType.SELLER) {\n\t\t\tconst shopAccessControlModel = await ShopAccessControlModel.findOne({ _id: entity.id });\n\t\t\tif (!shopAccessControlModel) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\n\t\t\t// For Parent\n\t\t\tif (['parent', 'parent_manager', 'parent_order_manager'].includes(shopAccessControlModel.role)) {\n\t\t\t\tconst parent = await ParentModel.findOne({ _id: shopAccessControlModel.parent });\n\n\t\t\t\tif (!parent) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\t\t\t\tif (parent.status !== Status.ACTIVE) unauthorizedError('Seller is not active');\n\t\t\t}\n\n\t\t\t// For Shop\n\t\t\tconst shops = shopAccessControlModel.shops ?? [];\n\n\t\t\tif (\n\t\t\t\tshops.length > 0 &&\n\t\t\t\t['shop', 'shop_manager', 'shop_order_manager'].includes(shopAccessControlModel.role)\n\t\t\t) {\n\t\t\t\tconst shopId = shops[0];\n\t\t\t\tconst shop = await ShopModel.findOne({ _id: shopId });\n\n\t\t\t\tif (!shop) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Seller not found' });\n\t\t\t\tif (shop.status !== Status.ACTIVE) unauthorizedError('Seller is not active');\n\t\t\t}\n\t\t}\n\n\t\t// For rider\n\t\tif (entity?.type == AuthEntityType.DELIVERY_BOY) {\n\t\t\tconst rider = await RiderModel.findOne({ _id: entity.id });\n\n\t\t\t// Check the rider exists or not\n\t\t\tif (!rider) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Admin not found' });\n\n\t\t\t// Check the rider isLogin true or false\n\t\t\tif (rider.isLogin) {\n\t\t\t\tif (rider.lastLoginDeviceId !== entity.parameters.deviceId) {\n\t\t\t\t\tunauthorizedError('You already logged in another device');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tunauthorizedError('You have been logged out, Please login in again');\n\t\t\t}\n\n\t\t\tawait getLibraries().getRedisService().setLastOnline(AuthEntityType.DELIVERY_BOY, rider._id.toString());\n\t\t}\n\n\t\tif (entity) {\n\t\t\tctx.entity = entity;\n\t\t\tctx.tokenType = TokenType.ACCESS;\n\t\t\tctx.usedRefreshToken = false;\n\t\t\tctx.tokenRenewed = false;\n\n\t\t\treturn next({ ctx });\n\t\t}\n\n\t\tif (!allowRefreshToken || !refreshToken) unauthorizedError('Invalid access token');\n\n\t\tconst renewalResult = await handleTokenRenewal(refreshToken);\n\n\t\tif (!renewalResult.success) {\n\t\t\tconst errorMessage =\n\t\t\t\trenewalResult.tokenStatus === 'revoked' ? 'Refresh token has been revoked' : 'Invalid refresh token';\n\n\t\t\tunauthorizedError(errorMessage);\n\t\t}\n\n\t\tif (!entityTypes.includes(renewalResult.entity!.type)) unauthorizedError('Unauthorized entity type');\n\n\t\tctx.entity = renewalResult.entity;\n\t\tctx.tokenType = TokenType.REFRESH;\n\t\tctx.usedRefreshToken = true;\n\n\t\tctx.tokenRenewed = renewalResult.tokenStatus === 'expired';\n\n\t\tif (autoRefresh && renewalResult.newTokens) {\n\t\t\tif (renewalResult.newTokens.accessToken) {\n\t\t\t\tctx.res.setHeader('X-New-Access-Token', renewalResult.newTokens.accessToken);\n\t\t\t}\n\n\t\t\tif (renewalResult.newTokens.refreshToken) {\n\t\t\t\tctx.res.setHeader('X-New-Refresh-Token', renewalResult.newTokens.refreshToken);\n\t\t\t}\n\t\t}\n\n\t\treturn next({ ctx });\n\t});\n}\n"]}
|
|
@@ -5,9 +5,9 @@ interface RoleProtectedOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
7
|
requestId: string | undefined;
|
|
8
|
+
entity: import("../context").EntityContext | undefined;
|
|
8
9
|
req: import("http").IncomingMessage;
|
|
9
10
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
|
-
entity: import("../context").EntityContext | undefined;
|
|
11
11
|
tokenType: import("../../auth").TokenType | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
13
13
|
tokenRenewed: boolean | undefined;
|
|
@@ -4,9 +4,9 @@ interface PhoneVerifiedOptions {
|
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
6
|
requestId: string | undefined;
|
|
7
|
+
entity: import("../context").EntityContext | undefined;
|
|
7
8
|
req: import("http").IncomingMessage;
|
|
8
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
|
-
entity: import("../context").EntityContext | undefined;
|
|
10
10
|
tokenType: import("../../auth").TokenType | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
12
12
|
tokenRenewed: boolean | undefined;
|
|
@@ -6,9 +6,9 @@ interface AuthOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
8
|
requestId: string | undefined;
|
|
9
|
+
entity: import("../context").EntityContext | undefined;
|
|
9
10
|
req: import("http").IncomingMessage;
|
|
10
11
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
11
|
-
entity: import("../context").EntityContext | undefined;
|
|
12
12
|
tokenType: TokenType | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lyxa.ai/types",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.334-alpha-11",
|
|
4
4
|
"description": "Lyxa type definitions and validation schemas for both frontend and backend",
|
|
5
5
|
"author": "elie <42282499+Internalizable@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|