@lyxa.ai/core 1.4.332-alpha.2 → 1.4.332

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/dist/libraries/notification/firebase-message.builder.d.ts +5 -1
  2. package/dist/libraries/notification/firebase-message.builder.js +32 -1
  3. package/dist/libraries/notification/firebase-message.builder.js.map +1 -1
  4. package/dist/libraries/notification/lyxa-fcm.service.d.ts +1 -0
  5. package/dist/libraries/notification/lyxa-fcm.service.js +16 -0
  6. package/dist/libraries/notification/lyxa-fcm.service.js.map +1 -1
  7. package/dist/libraries/redis/index.d.ts +0 -5
  8. package/dist/libraries/redis/index.js +0 -16
  9. package/dist/libraries/redis/index.js.map +1 -1
  10. package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +28 -28
  11. package/dist/libraries/socket/events/order-actions.socket.event.d.ts +44 -44
  12. package/dist/libraries/socket/events/rider-location-update.socket.event.d.ts +4 -4
  13. package/dist/libraries/socket/events/ticket-actions.socket.event.d.ts +17 -17
  14. package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +20 -20
  15. package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
  16. package/dist/libraries/trpc/middlewares/auth.js +0 -2
  17. package/dist/libraries/trpc/middlewares/auth.js.map +1 -1
  18. package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
  19. package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
  20. package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
  21. package/dist/types/README.md +1 -1
  22. package/dist/types/package.json +1 -1
  23. package/dist/types/utilities/validation/common-validation.d.ts +59 -59
  24. package/dist/utilities/validation/common-validation.d.ts +63 -63
  25. package/package.json +1 -1
@@ -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
- name: string;
20
19
  _id: import("mongoose").Types.ObjectId;
21
- }, {
22
20
  name: string;
21
+ }, {
23
22
  _id: string | import("mongoose").Types.ObjectId;
23
+ name: string;
24
24
  }>;
25
25
  orderStatus: z.ZodNativeEnum<typeof RegularOrderStatus>;
26
26
  orderAction: z.ZodNativeEnum<typeof OrderAction>;
@@ -40,19 +40,19 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
40
40
  secondaryRiderTips: z.ZodNumber;
41
41
  }, "strip", z.ZodTypeAny, {
42
42
  deliveryFee: number;
43
- riderTips: number;
44
- total: number;
45
43
  secondaryDeliveryFee: number;
44
+ riderTips: number;
46
45
  secondaryRiderTips: number;
46
+ total: number;
47
47
  secondaryTotal: number;
48
48
  paidAmount: number;
49
49
  secondaryPaidAmount: number;
50
50
  }, {
51
51
  deliveryFee: number;
52
- riderTips: number;
53
- total: number;
54
52
  secondaryDeliveryFee: number;
53
+ riderTips: number;
55
54
  secondaryRiderTips: number;
55
+ total: number;
56
56
  secondaryTotal: number;
57
57
  paidAmount: number;
58
58
  secondaryPaidAmount: number;
@@ -61,10 +61,10 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
61
61
  paymentMethod: PaymentMethod;
62
62
  pricing: {
63
63
  deliveryFee: number;
64
- riderTips: number;
65
- total: number;
66
64
  secondaryDeliveryFee: number;
65
+ riderTips: number;
67
66
  secondaryRiderTips: number;
67
+ total: number;
68
68
  secondaryTotal: number;
69
69
  paidAmount: number;
70
70
  secondaryPaidAmount: number;
@@ -74,10 +74,10 @@ export declare const OrderActionsOutputSchema: z.ZodObject<{
74
74
  paymentMethod: PaymentMethod;
75
75
  pricing: {
76
76
  deliveryFee: number;
77
- riderTips: number;
78
- total: number;
79
77
  secondaryDeliveryFee: number;
78
+ riderTips: number;
80
79
  secondaryRiderTips: number;
80
+ total: number;
81
81
  secondaryTotal: number;
82
82
  paidAmount: number;
83
83
  secondaryPaidAmount: number;
@@ -88,59 +88,59 @@ 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
- createdAt: Date;
92
91
  _id: import("mongoose").Types.ObjectId;
92
+ orderId: string;
93
93
  shopId: import("mongoose").Types.ObjectId;
94
+ createdAt: Date;
94
95
  user: {
95
- name: string;
96
96
  _id: import("mongoose").Types.ObjectId;
97
+ name: string;
97
98
  };
98
- paymentMethod: PaymentMethod;
99
- orderId: string;
100
99
  triggerAt: Date;
101
100
  adjustedFinance: {
102
101
  paymentMethod: PaymentMethod;
103
102
  pricing: {
104
103
  deliveryFee: number;
105
- riderTips: number;
106
- total: number;
107
104
  secondaryDeliveryFee: number;
105
+ riderTips: number;
108
106
  secondaryRiderTips: number;
107
+ total: number;
109
108
  secondaryTotal: number;
110
109
  paidAmount: number;
111
110
  secondaryPaidAmount: number;
112
111
  };
113
112
  shopProfit: number;
114
113
  };
114
+ paymentMethod: PaymentMethod;
115
115
  orderActionType: OrderAction;
116
116
  orderStatus: RegularOrderStatus;
117
117
  orderAction: OrderAction;
118
118
  preparationTimeMinutes: number;
119
119
  }, {
120
- createdAt: Date;
121
120
  _id: string | import("mongoose").Types.ObjectId;
121
+ orderId: string;
122
122
  shopId: string | import("mongoose").Types.ObjectId;
123
+ createdAt: Date;
123
124
  user: {
124
- name: string;
125
125
  _id: string | import("mongoose").Types.ObjectId;
126
+ name: string;
126
127
  };
127
- paymentMethod: PaymentMethod;
128
- orderId: string;
129
128
  triggerAt: Date;
130
129
  adjustedFinance: {
131
130
  paymentMethod: PaymentMethod;
132
131
  pricing: {
133
132
  deliveryFee: number;
134
- riderTips: number;
135
- total: number;
136
133
  secondaryDeliveryFee: number;
134
+ riderTips: number;
137
135
  secondaryRiderTips: number;
136
+ total: number;
138
137
  secondaryTotal: number;
139
138
  paidAmount: number;
140
139
  secondaryPaidAmount: number;
141
140
  };
142
141
  shopProfit: number;
143
142
  };
143
+ paymentMethod: PaymentMethod;
144
144
  orderActionType: OrderAction;
145
145
  orderStatus: RegularOrderStatus;
146
146
  orderAction: OrderAction;
@@ -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
- name: string;
164
163
  _id: import("mongoose").Types.ObjectId;
165
- }, {
166
164
  name: string;
165
+ }, {
167
166
  _id: string | import("mongoose").Types.ObjectId;
167
+ name: string;
168
168
  }>;
169
169
  orderStatus: z.ZodNativeEnum<typeof RegularOrderStatus>;
170
170
  orderAction: z.ZodNativeEnum<typeof OrderAction>;
@@ -184,19 +184,19 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
184
184
  secondaryRiderTips: z.ZodNumber;
185
185
  }, "strip", z.ZodTypeAny, {
186
186
  deliveryFee: number;
187
- riderTips: number;
188
- total: number;
189
187
  secondaryDeliveryFee: number;
188
+ riderTips: number;
190
189
  secondaryRiderTips: number;
190
+ total: number;
191
191
  secondaryTotal: number;
192
192
  paidAmount: number;
193
193
  secondaryPaidAmount: number;
194
194
  }, {
195
195
  deliveryFee: number;
196
- riderTips: number;
197
- total: number;
198
196
  secondaryDeliveryFee: number;
197
+ riderTips: number;
199
198
  secondaryRiderTips: number;
199
+ total: number;
200
200
  secondaryTotal: number;
201
201
  paidAmount: number;
202
202
  secondaryPaidAmount: number;
@@ -205,10 +205,10 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
205
205
  paymentMethod: PaymentMethod;
206
206
  pricing: {
207
207
  deliveryFee: number;
208
- riderTips: number;
209
- total: number;
210
208
  secondaryDeliveryFee: number;
209
+ riderTips: number;
211
210
  secondaryRiderTips: number;
211
+ total: number;
212
212
  secondaryTotal: number;
213
213
  paidAmount: number;
214
214
  secondaryPaidAmount: number;
@@ -218,10 +218,10 @@ export declare class OrderActionsSocketEvent extends BaseSocketEvent<typeof Orde
218
218
  paymentMethod: PaymentMethod;
219
219
  pricing: {
220
220
  deliveryFee: number;
221
- riderTips: number;
222
- total: number;
223
221
  secondaryDeliveryFee: number;
222
+ riderTips: number;
224
223
  secondaryRiderTips: number;
224
+ total: number;
225
225
  secondaryTotal: number;
226
226
  paidAmount: number;
227
227
  secondaryPaidAmount: number;
@@ -232,59 +232,59 @@ 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
- createdAt: Date;
236
235
  _id: import("mongoose").Types.ObjectId;
236
+ orderId: string;
237
237
  shopId: import("mongoose").Types.ObjectId;
238
+ createdAt: Date;
238
239
  user: {
239
- name: string;
240
240
  _id: import("mongoose").Types.ObjectId;
241
+ name: string;
241
242
  };
242
- paymentMethod: PaymentMethod;
243
- orderId: string;
244
243
  triggerAt: Date;
245
244
  adjustedFinance: {
246
245
  paymentMethod: PaymentMethod;
247
246
  pricing: {
248
247
  deliveryFee: number;
249
- riderTips: number;
250
- total: number;
251
248
  secondaryDeliveryFee: number;
249
+ riderTips: number;
252
250
  secondaryRiderTips: number;
251
+ total: number;
253
252
  secondaryTotal: number;
254
253
  paidAmount: number;
255
254
  secondaryPaidAmount: number;
256
255
  };
257
256
  shopProfit: number;
258
257
  };
258
+ paymentMethod: PaymentMethod;
259
259
  orderActionType: OrderAction;
260
260
  orderStatus: RegularOrderStatus;
261
261
  orderAction: OrderAction;
262
262
  preparationTimeMinutes: number;
263
263
  }, {
264
- createdAt: Date;
265
264
  _id: string | import("mongoose").Types.ObjectId;
265
+ orderId: string;
266
266
  shopId: string | import("mongoose").Types.ObjectId;
267
+ createdAt: Date;
267
268
  user: {
268
- name: string;
269
269
  _id: string | import("mongoose").Types.ObjectId;
270
+ name: string;
270
271
  };
271
- paymentMethod: PaymentMethod;
272
- orderId: string;
273
272
  triggerAt: Date;
274
273
  adjustedFinance: {
275
274
  paymentMethod: PaymentMethod;
276
275
  pricing: {
277
276
  deliveryFee: number;
278
- riderTips: number;
279
- total: number;
280
277
  secondaryDeliveryFee: number;
278
+ riderTips: number;
281
279
  secondaryRiderTips: number;
280
+ total: number;
282
281
  secondaryTotal: number;
283
282
  paidAmount: number;
284
283
  secondaryPaidAmount: number;
285
284
  };
286
285
  shopProfit: number;
287
286
  };
287
+ paymentMethod: PaymentMethod;
288
288
  orderActionType: OrderAction;
289
289
  orderStatus: RegularOrderStatus;
290
290
  orderAction: OrderAction;
@@ -19,17 +19,17 @@ 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
+ _id: import("mongoose").Types.ObjectId;
22
23
  latitude: number;
23
24
  longitude: number;
24
25
  updatedAt: Date;
25
- _id: import("mongoose").Types.ObjectId;
26
26
  riderId: import("mongoose").Types.ObjectId;
27
27
  bearing?: number | undefined;
28
28
  }, {
29
+ _id: string | import("mongoose").Types.ObjectId;
29
30
  latitude: number;
30
31
  longitude: number;
31
32
  updatedAt: string | Date;
32
- _id: string | import("mongoose").Types.ObjectId;
33
33
  riderId: string | import("mongoose").Types.ObjectId;
34
34
  bearing?: number | undefined;
35
35
  }>;
@@ -55,17 +55,17 @@ 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
+ _id: import("mongoose").Types.ObjectId;
58
59
  latitude: number;
59
60
  longitude: number;
60
61
  updatedAt: Date;
61
- _id: import("mongoose").Types.ObjectId;
62
62
  riderId: import("mongoose").Types.ObjectId;
63
63
  bearing?: number | undefined;
64
64
  }, {
65
+ _id: string | import("mongoose").Types.ObjectId;
65
66
  latitude: number;
66
67
  longitude: number;
67
68
  updatedAt: string | Date;
68
- _id: string | import("mongoose").Types.ObjectId;
69
69
  riderId: string | import("mongoose").Types.ObjectId;
70
70
  bearing?: number | undefined;
71
71
  }>;
@@ -8,19 +8,19 @@ 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.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>>;
11
+ content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
12
+ title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
13
13
  silent: z.ZodOptional<z.ZodBoolean>;
14
14
  }, "strip", z.ZodTypeAny, {
15
- type: TicketType;
16
15
  status: TicketStatus;
16
+ type: TicketType;
17
17
  _id: import("mongoose").Types.ObjectId;
18
18
  title?: string | undefined;
19
19
  content?: string | undefined;
20
20
  silent?: boolean | undefined;
21
21
  }, {
22
- type: TicketType;
23
22
  status: TicketStatus;
23
+ type: TicketType;
24
24
  _id: import("mongoose").Types.ObjectId;
25
25
  title?: string | undefined;
26
26
  content?: string | undefined;
@@ -30,17 +30,17 @@ 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.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>>;
33
+ content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
34
+ title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
35
35
  }, "strip", z.ZodTypeAny, {
36
- type: TicketType;
37
36
  status: TicketStatus;
37
+ type: TicketType;
38
38
  ticketId: import("mongoose").Types.ObjectId;
39
39
  title?: string | undefined;
40
40
  content?: string | undefined;
41
41
  }, {
42
- type: TicketType;
43
42
  status: TicketStatus;
43
+ type: TicketType;
44
44
  ticketId: import("mongoose").Types.ObjectId;
45
45
  title?: string | undefined;
46
46
  content?: string | undefined;
@@ -55,19 +55,19 @@ 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.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>>;
58
+ content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
59
+ title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
60
60
  silent: z.ZodOptional<z.ZodBoolean>;
61
61
  }, "strip", z.ZodTypeAny, {
62
- type: TicketType;
63
62
  status: TicketStatus;
63
+ type: TicketType;
64
64
  _id: import("mongoose").Types.ObjectId;
65
65
  title?: string | undefined;
66
66
  content?: string | undefined;
67
67
  silent?: boolean | undefined;
68
68
  }, {
69
- type: TicketType;
70
69
  status: TicketStatus;
70
+ type: TicketType;
71
71
  _id: import("mongoose").Types.ObjectId;
72
72
  title?: string | undefined;
73
73
  content?: string | undefined;
@@ -77,17 +77,17 @@ 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.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>>;
80
+ content: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
81
+ title: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>> | z.ZodOptional<z.ZodString>;
82
82
  }, "strip", z.ZodTypeAny, {
83
- type: TicketType;
84
83
  status: TicketStatus;
84
+ type: TicketType;
85
85
  ticketId: import("mongoose").Types.ObjectId;
86
86
  title?: string | undefined;
87
87
  content?: string | undefined;
88
88
  }, {
89
- type: TicketType;
90
89
  status: TicketStatus;
90
+ type: TicketType;
91
91
  ticketId: import("mongoose").Types.ObjectId;
92
92
  title?: string | undefined;
93
93
  content?: string | undefined;
@@ -96,8 +96,8 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
96
96
  get notificationSettings(): NotificationSettings | undefined;
97
97
  constructor(payload: TicketActionsSocketOutputDTO);
98
98
  getPushNotificationPayload(): {
99
- type: TicketType;
100
99
  status: TicketStatus;
100
+ type: TicketType;
101
101
  ticketId: import("mongoose").Types.ObjectId;
102
102
  title?: string | undefined;
103
103
  content?: string | undefined;
@@ -14,13 +14,13 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
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
16
  type: UserRef;
17
- name: string;
18
17
  _id: import("mongoose").Types.ObjectId;
18
+ name: string;
19
19
  profilePhoto: string | null;
20
20
  }, {
21
21
  type: UserRef;
22
- name: string;
23
22
  _id: string | import("mongoose").Types.ObjectId;
23
+ name: string;
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>;
@@ -39,41 +39,41 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
39
39
  }>;
40
40
  unreadCount: z.ZodNumber;
41
41
  }, "strip", z.ZodTypeAny, {
42
- type: TicketType;
43
42
  status: TicketStatus;
43
+ type: TicketType;
44
+ _id: import("mongoose").Types.ObjectId;
44
45
  createdAt: Date;
45
46
  updatedAt: Date;
46
- _id: import("mongoose").Types.ObjectId;
47
47
  lastMessage: {
48
48
  createdAt: Date;
49
49
  content: string;
50
50
  };
51
- unreadCount: number;
52
51
  client: {
53
52
  type: UserRef;
54
- name: string;
55
53
  _id: import("mongoose").Types.ObjectId;
54
+ name: string;
56
55
  profilePhoto: string | null;
57
56
  };
57
+ unreadCount: number;
58
58
  chatroomId: import("mongoose").Types.ObjectId;
59
59
  orderId?: import("mongoose").Types.ObjectId | undefined;
60
60
  }, {
61
- type: TicketType;
62
61
  status: TicketStatus;
62
+ type: TicketType;
63
+ _id: string | import("mongoose").Types.ObjectId;
63
64
  createdAt: string | Date;
64
65
  updatedAt: string | Date;
65
- _id: string | import("mongoose").Types.ObjectId;
66
66
  lastMessage: {
67
67
  createdAt: string | Date;
68
68
  content: string;
69
69
  };
70
- unreadCount: number;
71
70
  client: {
72
71
  type: UserRef;
73
- name: string;
74
72
  _id: string | import("mongoose").Types.ObjectId;
73
+ name: string;
75
74
  profilePhoto: string | null;
76
75
  };
76
+ unreadCount: number;
77
77
  chatroomId: string | import("mongoose").Types.ObjectId;
78
78
  orderId?: string | import("mongoose").Types.ObjectId | undefined;
79
79
  }>;
@@ -92,13 +92,13 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
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
94
  type: UserRef;
95
- name: string;
96
95
  _id: import("mongoose").Types.ObjectId;
96
+ name: string;
97
97
  profilePhoto: string | null;
98
98
  }, {
99
99
  type: UserRef;
100
- name: string;
101
100
  _id: string | import("mongoose").Types.ObjectId;
101
+ name: string;
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>;
@@ -117,41 +117,41 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
117
117
  }>;
118
118
  unreadCount: z.ZodNumber;
119
119
  }, "strip", z.ZodTypeAny, {
120
- type: TicketType;
121
120
  status: TicketStatus;
121
+ type: TicketType;
122
+ _id: import("mongoose").Types.ObjectId;
122
123
  createdAt: Date;
123
124
  updatedAt: Date;
124
- _id: import("mongoose").Types.ObjectId;
125
125
  lastMessage: {
126
126
  createdAt: Date;
127
127
  content: string;
128
128
  };
129
- unreadCount: number;
130
129
  client: {
131
130
  type: UserRef;
132
- name: string;
133
131
  _id: import("mongoose").Types.ObjectId;
132
+ name: string;
134
133
  profilePhoto: string | null;
135
134
  };
135
+ unreadCount: number;
136
136
  chatroomId: import("mongoose").Types.ObjectId;
137
137
  orderId?: import("mongoose").Types.ObjectId | undefined;
138
138
  }, {
139
- type: TicketType;
140
139
  status: TicketStatus;
140
+ type: TicketType;
141
+ _id: string | import("mongoose").Types.ObjectId;
141
142
  createdAt: string | Date;
142
143
  updatedAt: string | Date;
143
- _id: string | import("mongoose").Types.ObjectId;
144
144
  lastMessage: {
145
145
  createdAt: string | Date;
146
146
  content: string;
147
147
  };
148
- unreadCount: number;
149
148
  client: {
150
149
  type: UserRef;
151
- name: string;
152
150
  _id: string | import("mongoose").Types.ObjectId;
151
+ name: string;
153
152
  profilePhoto: string | null;
154
153
  };
154
+ unreadCount: number;
155
155
  chatroomId: string | import("mongoose").Types.ObjectId;
156
156
  orderId?: string | import("mongoose").Types.ObjectId | undefined;
157
157
  }>;
@@ -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;
10
9
  req: import("http").IncomingMessage;
11
10
  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,7 +7,6 @@ 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("../../..");
11
10
  function createAuthenticatedProcedure(options) {
12
11
  const { entityTypes, allowRefreshToken = true, autoRefresh = true } = options;
13
12
  return index_1.publicProcedure.use(async ({ ctx, next }) => {
@@ -75,7 +74,6 @@ function createAuthenticatedProcedure(options) {
75
74
  else {
76
75
  (0, error_common_1.unauthorizedError)('You have been logged out, Please login in again');
77
76
  }
78
- (0, __1.getLibraries)().getRedisService().setLastOnline(auth_1.AuthEntityType.DELIVERY_BOY, rider._id.toString());
79
77
  }
80
78
  if (entity) {
81
79
  ctx.entity = entity;
@@ -1 +1 @@
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,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,E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,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\tgetLibraries().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"]}
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;QAEtB,IAAI,kBAAkB,EAAE,CAAC;YACxB,YAAY;gBACX,OAAO,kBAAkB,KAAK,QAAQ;oBACrC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,EA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AC,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"]}
@@ -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;
9
8
  req: import("http").IncomingMessage;
10
9
  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;
8
7
  req: import("http").IncomingMessage;
9
8
  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;
10
9
  req: import("http").IncomingMessage;
11
10
  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;