@lyxa.ai/core 1.4.305-alpha.0 → 1.4.305
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/mongo/models/embedded/service-line-item.model.d.ts +6 -4
- package/dist/libraries/mongo/models/embedded/service-line-item.model.js +18 -8
- package/dist/libraries/mongo/models/embedded/service-line-item.model.js.map +1 -1
- package/dist/libraries/mongo/models/service-booking.model.d.ts +1 -0
- package/dist/libraries/mongo/models/service-booking.model.js +5 -0
- package/dist/libraries/mongo/models/service-booking.model.js.map +1 -1
- package/dist/libraries/socket/events/chatlist-message-send.socket.event.d.ts +24 -24
- package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +70 -70
- package/dist/libraries/socket/events/order-actions.socket.event.d.ts +70 -70
- 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 +13 -13
- package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +16 -16
- package/dist/libraries/trpc/middlewares/auth.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/auth.js +0 -5
- package/dist/libraries/trpc/middlewares/auth.js.map +1 -1
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +2 -2
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +12 -12
- package/dist/utilities/pagination.d.ts +3 -3
- package/dist/utilities/validation/common-validation.d.ts +72 -72
- package/package.json +1 -1
|
@@ -15,16 +15,16 @@ export declare const TicketActionsSocketOutputSchema: z.ZodObject<{
|
|
|
15
15
|
status: TicketStatus;
|
|
16
16
|
type: TicketType;
|
|
17
17
|
_id: import("mongoose").Types.ObjectId;
|
|
18
|
-
silent?: boolean | undefined;
|
|
19
|
-
title?: string | undefined;
|
|
20
18
|
content?: string | undefined;
|
|
19
|
+
title?: string | undefined;
|
|
20
|
+
silent?: boolean | undefined;
|
|
21
21
|
}, {
|
|
22
22
|
status: TicketStatus;
|
|
23
23
|
type: TicketType;
|
|
24
24
|
_id: import("mongoose").Types.ObjectId;
|
|
25
|
-
silent?: boolean | undefined;
|
|
26
|
-
title?: string | undefined;
|
|
27
25
|
content?: string | undefined;
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
silent?: boolean | undefined;
|
|
28
28
|
}>;
|
|
29
29
|
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>;
|
|
@@ -36,14 +36,14 @@ export declare const TicketActionsPushOutputSchema: z.ZodObject<{
|
|
|
36
36
|
status: TicketStatus;
|
|
37
37
|
type: TicketType;
|
|
38
38
|
ticketId: import("mongoose").Types.ObjectId;
|
|
39
|
-
title?: string | undefined;
|
|
40
39
|
content?: string | undefined;
|
|
40
|
+
title?: string | undefined;
|
|
41
41
|
}, {
|
|
42
42
|
status: TicketStatus;
|
|
43
43
|
type: TicketType;
|
|
44
44
|
ticketId: import("mongoose").Types.ObjectId;
|
|
45
|
-
title?: string | undefined;
|
|
46
45
|
content?: string | undefined;
|
|
46
|
+
title?: string | undefined;
|
|
47
47
|
}>;
|
|
48
48
|
export type TicketActionsSocketOutputDTO = DTO<typeof TicketActionsSocketOutputSchema>;
|
|
49
49
|
export type TicketActionsPushOutputDTO = DTO<typeof TicketActionsPushOutputSchema>;
|
|
@@ -62,16 +62,16 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
|
|
|
62
62
|
status: TicketStatus;
|
|
63
63
|
type: TicketType;
|
|
64
64
|
_id: import("mongoose").Types.ObjectId;
|
|
65
|
-
silent?: boolean | undefined;
|
|
66
|
-
title?: string | undefined;
|
|
67
65
|
content?: string | undefined;
|
|
66
|
+
title?: string | undefined;
|
|
67
|
+
silent?: boolean | undefined;
|
|
68
68
|
}, {
|
|
69
69
|
status: TicketStatus;
|
|
70
70
|
type: TicketType;
|
|
71
71
|
_id: import("mongoose").Types.ObjectId;
|
|
72
|
-
silent?: boolean | undefined;
|
|
73
|
-
title?: string | undefined;
|
|
74
72
|
content?: string | undefined;
|
|
73
|
+
title?: string | undefined;
|
|
74
|
+
silent?: boolean | undefined;
|
|
75
75
|
}>;
|
|
76
76
|
pushNotificationOutput: z.ZodObject<{
|
|
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>;
|
|
@@ -83,14 +83,14 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
|
|
|
83
83
|
status: TicketStatus;
|
|
84
84
|
type: TicketType;
|
|
85
85
|
ticketId: import("mongoose").Types.ObjectId;
|
|
86
|
-
title?: string | undefined;
|
|
87
86
|
content?: string | undefined;
|
|
87
|
+
title?: string | undefined;
|
|
88
88
|
}, {
|
|
89
89
|
status: TicketStatus;
|
|
90
90
|
type: TicketType;
|
|
91
91
|
ticketId: import("mongoose").Types.ObjectId;
|
|
92
|
-
title?: string | undefined;
|
|
93
92
|
content?: string | undefined;
|
|
93
|
+
title?: string | undefined;
|
|
94
94
|
}>;
|
|
95
95
|
};
|
|
96
96
|
get notificationSettings(): NotificationSettings | undefined;
|
|
@@ -99,8 +99,8 @@ export declare class TicketActionsSocketEvent extends BaseSocketEvent<typeof Tic
|
|
|
99
99
|
status: TicketStatus;
|
|
100
100
|
type: TicketType;
|
|
101
101
|
ticketId: import("mongoose").Types.ObjectId;
|
|
102
|
-
title?: string | undefined;
|
|
103
102
|
content?: string | undefined;
|
|
103
|
+
title?: string | undefined;
|
|
104
104
|
} | undefined;
|
|
105
105
|
protected getIdentifier(): string;
|
|
106
106
|
}
|
|
@@ -31,22 +31,22 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
31
31
|
content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
32
32
|
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>;
|
|
33
33
|
}, "strip", z.ZodTypeAny, {
|
|
34
|
-
createdAt: Date;
|
|
35
34
|
content: string;
|
|
35
|
+
createdAt: Date;
|
|
36
36
|
}, {
|
|
37
|
-
createdAt: string | Date;
|
|
38
37
|
content: string;
|
|
38
|
+
createdAt: string | Date;
|
|
39
39
|
}>;
|
|
40
40
|
unreadCount: z.ZodNumber;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
42
|
status: TicketStatus;
|
|
43
43
|
type: TicketType;
|
|
44
|
+
chatroomId: import("mongoose").Types.ObjectId;
|
|
44
45
|
_id: import("mongoose").Types.ObjectId;
|
|
45
46
|
createdAt: Date;
|
|
46
|
-
updatedAt: Date;
|
|
47
47
|
lastMessage: {
|
|
48
|
-
createdAt: Date;
|
|
49
48
|
content: string;
|
|
49
|
+
createdAt: Date;
|
|
50
50
|
};
|
|
51
51
|
unreadCount: number;
|
|
52
52
|
client: {
|
|
@@ -55,17 +55,17 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
55
55
|
name: string;
|
|
56
56
|
profilePhoto: string | null;
|
|
57
57
|
};
|
|
58
|
-
|
|
58
|
+
updatedAt: Date;
|
|
59
59
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
60
60
|
}, {
|
|
61
61
|
status: TicketStatus;
|
|
62
62
|
type: TicketType;
|
|
63
|
+
chatroomId: string | import("mongoose").Types.ObjectId;
|
|
63
64
|
_id: string | import("mongoose").Types.ObjectId;
|
|
64
65
|
createdAt: string | Date;
|
|
65
|
-
updatedAt: string | Date;
|
|
66
66
|
lastMessage: {
|
|
67
|
-
createdAt: string | Date;
|
|
68
67
|
content: string;
|
|
68
|
+
createdAt: string | Date;
|
|
69
69
|
};
|
|
70
70
|
unreadCount: number;
|
|
71
71
|
client: {
|
|
@@ -74,7 +74,7 @@ export declare const TicketAssignSocketOutputSchema: z.ZodObject<{
|
|
|
74
74
|
name: string;
|
|
75
75
|
profilePhoto: string | null;
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
updatedAt: string | Date;
|
|
78
78
|
orderId?: string | import("mongoose").Types.ObjectId | undefined;
|
|
79
79
|
}>;
|
|
80
80
|
export type TicketAssignSocketOutputDTO = DTO<typeof TicketAssignSocketOutputSchema>;
|
|
@@ -109,22 +109,22 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
109
109
|
content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
110
110
|
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>;
|
|
111
111
|
}, "strip", z.ZodTypeAny, {
|
|
112
|
-
createdAt: Date;
|
|
113
112
|
content: string;
|
|
113
|
+
createdAt: Date;
|
|
114
114
|
}, {
|
|
115
|
-
createdAt: string | Date;
|
|
116
115
|
content: string;
|
|
116
|
+
createdAt: string | Date;
|
|
117
117
|
}>;
|
|
118
118
|
unreadCount: z.ZodNumber;
|
|
119
119
|
}, "strip", z.ZodTypeAny, {
|
|
120
120
|
status: TicketStatus;
|
|
121
121
|
type: TicketType;
|
|
122
|
+
chatroomId: import("mongoose").Types.ObjectId;
|
|
122
123
|
_id: import("mongoose").Types.ObjectId;
|
|
123
124
|
createdAt: Date;
|
|
124
|
-
updatedAt: Date;
|
|
125
125
|
lastMessage: {
|
|
126
|
-
createdAt: Date;
|
|
127
126
|
content: string;
|
|
127
|
+
createdAt: Date;
|
|
128
128
|
};
|
|
129
129
|
unreadCount: number;
|
|
130
130
|
client: {
|
|
@@ -133,17 +133,17 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
133
133
|
name: string;
|
|
134
134
|
profilePhoto: string | null;
|
|
135
135
|
};
|
|
136
|
-
|
|
136
|
+
updatedAt: Date;
|
|
137
137
|
orderId?: import("mongoose").Types.ObjectId | undefined;
|
|
138
138
|
}, {
|
|
139
139
|
status: TicketStatus;
|
|
140
140
|
type: TicketType;
|
|
141
|
+
chatroomId: string | import("mongoose").Types.ObjectId;
|
|
141
142
|
_id: string | import("mongoose").Types.ObjectId;
|
|
142
143
|
createdAt: string | Date;
|
|
143
|
-
updatedAt: string | Date;
|
|
144
144
|
lastMessage: {
|
|
145
|
-
createdAt: string | Date;
|
|
146
145
|
content: string;
|
|
146
|
+
createdAt: string | Date;
|
|
147
147
|
};
|
|
148
148
|
unreadCount: number;
|
|
149
149
|
client: {
|
|
@@ -152,7 +152,7 @@ export declare class TicketAssignEvent extends BaseSocketEvent<typeof TicketAssi
|
|
|
152
152
|
name: string;
|
|
153
153
|
profilePhoto: string | null;
|
|
154
154
|
};
|
|
155
|
-
|
|
155
|
+
updatedAt: string | Date;
|
|
156
156
|
orderId?: string | import("mongoose").Types.ObjectId | undefined;
|
|
157
157
|
}>;
|
|
158
158
|
};
|
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
requestId: string | undefined;
|
|
9
|
-
entity: import("../context").EntityContext | undefined;
|
|
10
8
|
req: import("http").IncomingMessage;
|
|
11
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
|
+
entity: import("../context").EntityContext | undefined;
|
|
11
|
+
requestId: string | 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,10 +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
|
-
const redis = (0, __1.getLibraries)().getRedisService();
|
|
79
|
-
const key = `connectedRiders:${rider._id.toString()}`;
|
|
80
|
-
const expiryInSeconds = 5 * 60;
|
|
81
|
-
await redis.cacheObject(key, { updatedAt: new Date() }, expiryInSeconds);
|
|
82
77
|
}
|
|
83
78
|
if (entity) {
|
|
84
79
|
ctx.entity = entity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/auth.ts"],"names":[],"mappings":";;AAyBA,oEAkIC;AA3JD,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,EAAE;QAClD,MAAM,UAAU,GAAG,GAAG,CAAC,GAA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G,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';\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\t// set rider as connected\n\t\t\tconst redis = getLibraries().getRedisService();\n\t\t\tconst key = `connectedRiders:${rider._id.toString()}`;\n\t\t\tconst expiryInSeconds = 5 * 60;\n\t\t\tawait redis.cacheObject(key, { updatedAt: new Date() }, expiryInSeconds);\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;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edure } 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"]}
|
|
@@ -4,10 +4,10 @@ interface RoleProtectedOptions {
|
|
|
4
4
|
allowedRoles: string[];
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
|
-
requestId: string | undefined;
|
|
8
|
-
entity: import("../context").EntityContext | undefined;
|
|
9
7
|
req: import("http").IncomingMessage;
|
|
10
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
|
+
entity: import("../context").EntityContext | undefined;
|
|
10
|
+
requestId: string | undefined;
|
|
11
11
|
tokenType: import("../../auth").TokenType | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
13
13
|
tokenRenewed: boolean | undefined;
|
|
@@ -3,10 +3,10 @@ interface PhoneVerifiedOptions {
|
|
|
3
3
|
entityTypes: AuthEntityType[];
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
|
-
requestId: string | undefined;
|
|
7
|
-
entity: import("../context").EntityContext | undefined;
|
|
8
6
|
req: import("http").IncomingMessage;
|
|
9
7
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
|
+
entity: import("../context").EntityContext | undefined;
|
|
9
|
+
requestId: string | undefined;
|
|
10
10
|
tokenType: import("../../auth").TokenType | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
12
12
|
tokenRenewed: boolean | undefined;
|
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
requestId: string | undefined;
|
|
9
|
-
entity: import("../context").EntityContext | undefined;
|
|
10
8
|
req: import("http").IncomingMessage;
|
|
11
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
|
+
entity: import("../context").EntityContext | undefined;
|
|
11
|
+
requestId: string | 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.305
|
|
3
|
+
"version": "1.4.305",
|
|
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",
|
|
@@ -22,24 +22,24 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
22
22
|
size: number;
|
|
23
23
|
page: number;
|
|
24
24
|
sort?: Record<string, 1 | -1> | undefined;
|
|
25
|
+
query?: Record<string, any> | undefined;
|
|
26
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
27
|
+
populate?: any;
|
|
25
28
|
search?: {
|
|
26
29
|
searchKey: string;
|
|
27
30
|
searchFields?: string[] | undefined;
|
|
28
31
|
} | undefined;
|
|
29
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
30
|
-
populate?: any;
|
|
31
|
-
query?: Record<string, any> | undefined;
|
|
32
32
|
}, {
|
|
33
|
+
size?: number | undefined;
|
|
34
|
+
page?: number | undefined;
|
|
33
35
|
sort?: Record<string, 1 | -1> | undefined;
|
|
36
|
+
query?: Record<string, any> | undefined;
|
|
37
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
38
|
+
populate?: any;
|
|
34
39
|
search?: {
|
|
35
40
|
searchKey: string;
|
|
36
41
|
searchFields?: string[] | undefined;
|
|
37
42
|
} | undefined;
|
|
38
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
39
|
-
populate?: any;
|
|
40
|
-
size?: number | undefined;
|
|
41
|
-
page?: number | undefined;
|
|
42
|
-
query?: Record<string, any> | undefined;
|
|
43
43
|
}>>;
|
|
44
44
|
export type FilterDTO = z.infer<typeof FilterSchema>;
|
|
45
45
|
export declare const StringSchema: z.ZodString;
|
|
@@ -181,7 +181,6 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
181
181
|
} & {
|
|
182
182
|
_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>]>;
|
|
183
183
|
}, "strip", z.ZodTypeAny, {
|
|
184
|
-
_id: import("mongoose").Types.ObjectId;
|
|
185
184
|
address: string;
|
|
186
185
|
country: string;
|
|
187
186
|
location: {
|
|
@@ -193,6 +192,7 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
193
192
|
addressLabel: string;
|
|
194
193
|
apartment: string;
|
|
195
194
|
buildingName: string;
|
|
195
|
+
_id: import("mongoose").Types.ObjectId;
|
|
196
196
|
description?: string | undefined;
|
|
197
197
|
city?: string | undefined;
|
|
198
198
|
state?: string | undefined;
|
|
@@ -200,7 +200,6 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
200
200
|
deliveryOption?: string | undefined;
|
|
201
201
|
instructions?: string | undefined;
|
|
202
202
|
}, {
|
|
203
|
-
_id: string | import("mongoose").Types.ObjectId;
|
|
204
203
|
address: string;
|
|
205
204
|
country: string;
|
|
206
205
|
location: {
|
|
@@ -212,6 +211,7 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
212
211
|
addressLabel: string;
|
|
213
212
|
apartment: string;
|
|
214
213
|
buildingName: string;
|
|
214
|
+
_id: string | import("mongoose").Types.ObjectId;
|
|
215
215
|
description?: string | undefined;
|
|
216
216
|
city?: string | undefined;
|
|
217
217
|
state?: string | undefined;
|
|
@@ -803,13 +803,13 @@ export declare const GetOneQuerySchema: z.ZodObject<{
|
|
|
803
803
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
804
804
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
805
805
|
}, "strip", z.ZodTypeAny, {
|
|
806
|
+
query?: Record<string, any> | undefined;
|
|
806
807
|
select?: Record<string, 0 | 1> | undefined;
|
|
807
808
|
populate?: any;
|
|
808
|
-
query?: Record<string, any> | undefined;
|
|
809
809
|
}, {
|
|
810
|
+
query?: Record<string, any> | undefined;
|
|
810
811
|
select?: Record<string, 0 | 1> | undefined;
|
|
811
812
|
populate?: any;
|
|
812
|
-
query?: Record<string, any> | undefined;
|
|
813
813
|
}>;
|
|
814
814
|
export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
|
|
815
815
|
declare const ShareableLinkSchema: z.ZodObject<{
|
|
@@ -22,7 +22,6 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
22
22
|
}, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>, z.ZodUndefined]>, "strip">>;
|
|
23
23
|
items: z.ZodArray<ItemType, "many">;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
|
-
items: ItemType["_output"][];
|
|
26
25
|
metadata: {
|
|
27
26
|
size: number;
|
|
28
27
|
page: number;
|
|
@@ -31,8 +30,8 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
31
30
|
} & {
|
|
32
31
|
[k: string]: string | number | boolean | null | undefined;
|
|
33
32
|
};
|
|
33
|
+
items: ItemType["_output"][];
|
|
34
34
|
}, {
|
|
35
|
-
items: ItemType["_input"][];
|
|
36
35
|
metadata: {
|
|
37
36
|
size: number;
|
|
38
37
|
page: number;
|
|
@@ -41,6 +40,7 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
41
40
|
} & {
|
|
42
41
|
[k: string]: string | number | boolean | null | undefined;
|
|
43
42
|
};
|
|
43
|
+
items: ItemType["_input"][];
|
|
44
44
|
}>;
|
|
45
45
|
export interface RawPaginatedResult<T extends AnyParamConstructor<any>> {
|
|
46
46
|
metadata: {
|
|
@@ -62,7 +62,6 @@ export interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {
|
|
|
62
62
|
}
|
|
63
63
|
export declare function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(model: ReturnModelType<T>): (options: PaginatorOptions<T>) => Promise<RawPaginatedResult<T>>;
|
|
64
64
|
export declare function createPaginatorObject<T extends AnyParamConstructor<any>>(model: ReturnModelType<T>, itemSchema: z.ZodTypeAny, transformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>): (options: PaginatorOptions<T>) => Promise<{
|
|
65
|
-
items: any[];
|
|
66
65
|
metadata: {
|
|
67
66
|
size: number;
|
|
68
67
|
page: number;
|
|
@@ -71,6 +70,7 @@ export declare function createPaginatorObject<T extends AnyParamConstructor<any>
|
|
|
71
70
|
} & {
|
|
72
71
|
[k: string]: string | number | boolean | null | undefined;
|
|
73
72
|
};
|
|
73
|
+
items: any[];
|
|
74
74
|
}>;
|
|
75
75
|
export declare function paginateAggregation(model: any, pipeline: any[], page?: number, size?: number, sort?: any, populateOptions?: any): Promise<{
|
|
76
76
|
metadata: {
|