@exyconn/common 2.3.2 → 2.3.4

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 (40) hide show
  1. package/README.md +117 -12
  2. package/dist/client/http/index.d.mts +280 -49
  3. package/dist/client/http/index.d.ts +280 -49
  4. package/dist/client/http/index.js +564 -90
  5. package/dist/client/http/index.js.map +1 -1
  6. package/dist/client/http/index.mjs +520 -80
  7. package/dist/client/http/index.mjs.map +1 -1
  8. package/dist/client/index.d.mts +3 -3
  9. package/dist/client/index.d.ts +3 -3
  10. package/dist/client/index.js +573 -316
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/client/index.mjs +529 -287
  13. package/dist/client/index.mjs.map +1 -1
  14. package/dist/client/utils/index.d.mts +3 -279
  15. package/dist/client/utils/index.d.ts +3 -279
  16. package/dist/{index-D9a9oxQy.d.ts → index-CdbQ8YPt.d.ts} +51 -39
  17. package/dist/{index-D3yCCjBZ.d.mts → index-Ckhm_HaX.d.mts} +21 -2
  18. package/dist/{index-01hoqibP.d.ts → index-br6POSyA.d.ts} +21 -2
  19. package/dist/{index-DuxL84IW.d.mts → index-guYdqefq.d.mts} +51 -39
  20. package/dist/index.d.mts +3 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +1214 -326
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +1226 -338
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/packageCheck-B_qfsD6R.d.ts +280 -0
  27. package/dist/packageCheck-C2_FT_Rl.d.mts +280 -0
  28. package/dist/server/index.d.mts +1 -1
  29. package/dist/server/index.d.ts +1 -1
  30. package/dist/server/index.js +631 -0
  31. package/dist/server/index.js.map +1 -1
  32. package/dist/server/index.mjs +625 -2
  33. package/dist/server/index.mjs.map +1 -1
  34. package/dist/server/middleware/index.d.mts +283 -2
  35. package/dist/server/middleware/index.d.ts +283 -2
  36. package/dist/server/middleware/index.js +761 -0
  37. package/dist/server/middleware/index.js.map +1 -1
  38. package/dist/server/middleware/index.mjs +751 -1
  39. package/dist/server/middleware/index.mjs.map +1 -1
  40. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
- import { Request, Response, NextFunction } from 'express';
1
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
2
+ import { Model, Document } from 'mongoose';
2
3
 
3
4
  /**
4
5
  * Extended Request with auth information
@@ -53,4 +54,284 @@ declare const extractOrganization: (req: AuthRequest, _res: Response, next: Next
53
54
  */
54
55
  declare const requireOrganization: (req: AuthRequest, res: Response, next: NextFunction) => void;
55
56
 
56
- export { type AuthRequest, type JWTPayload, authenticateApiKey, authenticateJWT, extractOrganization, optionalAuthenticateJWT, requireOrganization };
57
+ /**
58
+ * Query Parser Middleware
59
+ *
60
+ * Parses query parameters into a standardized format for pagination and filtering.
61
+ */
62
+
63
+ /**
64
+ * Parse query parameters from request
65
+ * Supports:
66
+ * - page, limit for pagination
67
+ * - sort or sortBy/sortOrder for sorting
68
+ * - search for text search
69
+ * - filter object or direct query params for filtering
70
+ */
71
+ declare const queryParser: (req: Request, _: Response, next: NextFunction) => void;
72
+
73
+ /**
74
+ * Query Pagination Middleware
75
+ *
76
+ * Provides standardized pagination for Mongoose models.
77
+ * Works with queryParser middleware for parsed query parameters.
78
+ */
79
+
80
+ type ZodObject$2<T = Record<string, unknown>> = {
81
+ parse: (data: unknown) => T;
82
+ safeParse: (data: unknown) => {
83
+ success: boolean;
84
+ data?: T;
85
+ error?: Error;
86
+ };
87
+ };
88
+ interface PaginationOptions {
89
+ searchFields?: string[];
90
+ validatorSchema?: ZodObject$2<unknown>;
91
+ regexFilterFields?: string[];
92
+ }
93
+ /**
94
+ * Creates a pagination middleware for a Mongoose model
95
+ *
96
+ * @param model - The Mongoose model to paginate
97
+ * @param options - Pagination options
98
+ * @param withOrgId - Whether to filter by organization ID from header
99
+ */
100
+ declare const queryPagination: <T>(model: Model<T>, options?: PaginationOptions, withOrgId?: boolean) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
101
+
102
+ /**
103
+ * CRUD Middleware Factory
104
+ *
105
+ * High-configuration middleware for standardized CRUD operations.
106
+ * Provides consistent API patterns across all services.
107
+ *
108
+ * Features:
109
+ * - getAll with pagination, search, filters, sorting
110
+ * - getById with validation
111
+ * - create with validation and auto-response
112
+ * - update with validation and auto-response
113
+ * - delete (single and bulk)
114
+ * - Organization-scoped queries
115
+ */
116
+
117
+ interface ZodIssue {
118
+ path: (string | number)[];
119
+ message: string;
120
+ }
121
+ interface ZodError extends Error {
122
+ errors: ZodIssue[];
123
+ }
124
+ interface ZodSchema<T = unknown> {
125
+ parse: (data: unknown) => T;
126
+ safeParse: (data: unknown) => {
127
+ success: boolean;
128
+ data?: T;
129
+ error?: ZodError;
130
+ };
131
+ }
132
+ type ZodObject$1<T = Record<string, unknown>> = ZodSchema<T>;
133
+ /**
134
+ * Extended request with organization ID
135
+ */
136
+ interface OrgRequest extends Request {
137
+ organizationId?: string;
138
+ }
139
+ /**
140
+ * Extended response with paginated result
141
+ */
142
+ interface PaginatedResponse extends Response {
143
+ paginatedResult?: {
144
+ data: unknown[];
145
+ meta: {
146
+ page: number;
147
+ limit: number;
148
+ total: number;
149
+ totalPages: number;
150
+ };
151
+ columns?: unknown[];
152
+ };
153
+ }
154
+ /**
155
+ * CRUD controller configuration
156
+ */
157
+ interface CrudConfig<T> {
158
+ /** Mongoose model */
159
+ model: Model<T>;
160
+ /** Resource name for logging and messages */
161
+ resourceName: string;
162
+ /** Zod schema for create validation */
163
+ createSchema?: ZodObject$1<unknown>;
164
+ /** Zod schema for update validation */
165
+ updateSchema?: ZodObject$1<unknown>;
166
+ /** Fields to search on (for getAll) */
167
+ searchFields?: string[];
168
+ /** Fields that use regex matching for filters */
169
+ regexFilterFields?: string[];
170
+ /** Whether to scope by organizationId (default: true) */
171
+ withOrganization?: boolean;
172
+ /** Field to use as the organization reference (default: 'organizationId') */
173
+ orgField?: string;
174
+ /** Custom transform for create input */
175
+ transformCreate?: (input: unknown, req: OrgRequest) => unknown;
176
+ /** Custom transform for update input */
177
+ transformUpdate?: (input: unknown, req: OrgRequest) => unknown;
178
+ /** Custom post-create hook */
179
+ afterCreate?: (doc: Document, req: OrgRequest) => Promise<void> | void;
180
+ /** Custom post-update hook */
181
+ afterUpdate?: (doc: Document, req: OrgRequest) => Promise<void> | void;
182
+ /** Custom post-delete hook */
183
+ afterDelete?: (id: string, req: OrgRequest) => Promise<void> | void;
184
+ /** Fields to exclude from response */
185
+ excludeFields?: string[];
186
+ /** Fields to populate in queries */
187
+ populateFields?: string[];
188
+ /** Custom query builder for getAll */
189
+ buildQuery?: (req: OrgRequest, baseQuery: Record<string, unknown>) => Record<string, unknown>;
190
+ }
191
+ /**
192
+ * Creates standardized CRUD controller handlers
193
+ */
194
+ declare function createCrudControllers<T extends Document>(config: CrudConfig<T>): {
195
+ getAll: RequestHandler;
196
+ getById: RequestHandler;
197
+ create: RequestHandler;
198
+ update: RequestHandler;
199
+ deleteOne: RequestHandler;
200
+ bulkDelete: RequestHandler;
201
+ };
202
+ /**
203
+ * Creates a standardized pagination middleware for a model
204
+ */
205
+ declare function createPaginationMiddleware<T>(model: Model<T>, config?: Partial<CrudConfig<T>>): RequestHandler;
206
+
207
+ /**
208
+ * Bulk Delete Middleware
209
+ *
210
+ * Common delete middleware for all services.
211
+ * Supports:
212
+ * - ['*'] → delete all records
213
+ * - ['id1', 'id2', ...] → delete multiple records
214
+ * - Single ID deletion as subset of multiple
215
+ */
216
+
217
+ /**
218
+ * Extended request interface with parsed delete IDs
219
+ */
220
+ interface BulkDeleteRequest extends Request {
221
+ deleteIds?: string[];
222
+ deleteAll?: boolean;
223
+ }
224
+ /**
225
+ * Validates and parses bulk delete request body
226
+ *
227
+ * Expected request body formats:
228
+ * - { "ids": ["*"] } or ["*"] → delete all
229
+ * - { "ids": ["id1", "id2"] } or ["id1", "id2"] → delete specific records
230
+ */
231
+ declare const parseBulkDelete: (req: Request, res: Response, next: NextFunction) => void | Response;
232
+ /**
233
+ * Helper function to build delete filter for MongoDB
234
+ */
235
+ declare const buildDeleteFilter: (req: BulkDeleteRequest, organizationId: string) => Record<string, unknown>;
236
+ /**
237
+ * Generic bulk delete handler factory
238
+ *
239
+ * Creates a controller function that handles bulk delete operations
240
+ * for any Mongoose model.
241
+ */
242
+ declare const createBulkDeleteHandler: (Model: {
243
+ deleteMany: (filter: Record<string, unknown>) => Promise<{
244
+ deletedCount?: number;
245
+ }>;
246
+ }, modelName: string) => (req: Request, res: Response) => Promise<Response>;
247
+
248
+ /**
249
+ * Pagination Types
250
+ * Standard types for pagination middleware
251
+ */
252
+
253
+ /**
254
+ * Sort order for queries
255
+ */
256
+ type SortOrder = 'asc' | 'desc';
257
+ /**
258
+ * Sort configuration
259
+ */
260
+ interface SortConfig {
261
+ field: string;
262
+ order: SortOrder;
263
+ }
264
+ /**
265
+ * Parsed query parameters from request
266
+ */
267
+ interface ParsedQuery {
268
+ page: number;
269
+ limit: number;
270
+ sort?: SortConfig;
271
+ search?: string;
272
+ filter: Record<string, string>;
273
+ }
274
+ /**
275
+ * Extended Express Request with parsed query
276
+ */
277
+ interface PaginatedRequest extends Request {
278
+ parsedQuery: ParsedQuery;
279
+ }
280
+ /**
281
+ * Pagination metadata for response
282
+ */
283
+ interface PaginationMeta {
284
+ page: number;
285
+ limit: number;
286
+ total: number;
287
+ totalPages: number;
288
+ }
289
+ /**
290
+ * Paginated result for response
291
+ */
292
+ interface PaginatedResult<T = unknown> {
293
+ data: T[];
294
+ meta: PaginationMeta;
295
+ columns?: unknown[];
296
+ }
297
+ declare global {
298
+ namespace Express {
299
+ interface Request {
300
+ parsedQuery: ParsedQuery;
301
+ }
302
+ interface Response {
303
+ paginatedResult?: PaginatedResult;
304
+ }
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Schema Meta Extraction Utility
310
+ * Extracts column metadata from Mongoose models and Zod schemas
311
+ */
312
+
313
+ interface ZodTypeAny {
314
+ _def?: {
315
+ typeName?: string;
316
+ innerType?: ZodTypeAny;
317
+ values?: unknown[];
318
+ };
319
+ }
320
+ type ZodObject<T = unknown> = {
321
+ shape?: Record<string, ZodTypeAny>;
322
+ parse: (data: unknown) => T;
323
+ };
324
+ /**
325
+ * Column metadata interface
326
+ */
327
+ interface ColumnMeta {
328
+ name: string;
329
+ datatype: string;
330
+ required: boolean;
331
+ }
332
+ /**
333
+ * Extract column metadata from Mongoose model and optional Zod schema
334
+ */
335
+ declare const extractSchemaMeta: <T>(model: Model<T>, zodSchema?: ZodObject<unknown>) => ColumnMeta[];
336
+
337
+ export { type AuthRequest, type BulkDeleteRequest, type ColumnMeta, type CrudConfig, type JWTPayload, type OrgRequest, type PaginatedRequest, type PaginatedResponse, type PaginatedResult, type PaginationMeta, type ParsedQuery, type SortConfig, type SortOrder, authenticateApiKey, authenticateJWT, buildDeleteFilter, createBulkDeleteHandler, createCrudControllers, createPaginationMiddleware, extractOrganization, extractSchemaMeta, optionalAuthenticateJWT, parseBulkDelete, queryPagination, queryParser, requireOrganization };
@@ -1,4 +1,5 @@
1
- import { Request, Response, NextFunction } from 'express';
1
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
2
+ import { Model, Document } from 'mongoose';
2
3
 
3
4
  /**
4
5
  * Extended Request with auth information
@@ -53,4 +54,284 @@ declare const extractOrganization: (req: AuthRequest, _res: Response, next: Next
53
54
  */
54
55
  declare const requireOrganization: (req: AuthRequest, res: Response, next: NextFunction) => void;
55
56
 
56
- export { type AuthRequest, type JWTPayload, authenticateApiKey, authenticateJWT, extractOrganization, optionalAuthenticateJWT, requireOrganization };
57
+ /**
58
+ * Query Parser Middleware
59
+ *
60
+ * Parses query parameters into a standardized format for pagination and filtering.
61
+ */
62
+
63
+ /**
64
+ * Parse query parameters from request
65
+ * Supports:
66
+ * - page, limit for pagination
67
+ * - sort or sortBy/sortOrder for sorting
68
+ * - search for text search
69
+ * - filter object or direct query params for filtering
70
+ */
71
+ declare const queryParser: (req: Request, _: Response, next: NextFunction) => void;
72
+
73
+ /**
74
+ * Query Pagination Middleware
75
+ *
76
+ * Provides standardized pagination for Mongoose models.
77
+ * Works with queryParser middleware for parsed query parameters.
78
+ */
79
+
80
+ type ZodObject$2<T = Record<string, unknown>> = {
81
+ parse: (data: unknown) => T;
82
+ safeParse: (data: unknown) => {
83
+ success: boolean;
84
+ data?: T;
85
+ error?: Error;
86
+ };
87
+ };
88
+ interface PaginationOptions {
89
+ searchFields?: string[];
90
+ validatorSchema?: ZodObject$2<unknown>;
91
+ regexFilterFields?: string[];
92
+ }
93
+ /**
94
+ * Creates a pagination middleware for a Mongoose model
95
+ *
96
+ * @param model - The Mongoose model to paginate
97
+ * @param options - Pagination options
98
+ * @param withOrgId - Whether to filter by organization ID from header
99
+ */
100
+ declare const queryPagination: <T>(model: Model<T>, options?: PaginationOptions, withOrgId?: boolean) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
101
+
102
+ /**
103
+ * CRUD Middleware Factory
104
+ *
105
+ * High-configuration middleware for standardized CRUD operations.
106
+ * Provides consistent API patterns across all services.
107
+ *
108
+ * Features:
109
+ * - getAll with pagination, search, filters, sorting
110
+ * - getById with validation
111
+ * - create with validation and auto-response
112
+ * - update with validation and auto-response
113
+ * - delete (single and bulk)
114
+ * - Organization-scoped queries
115
+ */
116
+
117
+ interface ZodIssue {
118
+ path: (string | number)[];
119
+ message: string;
120
+ }
121
+ interface ZodError extends Error {
122
+ errors: ZodIssue[];
123
+ }
124
+ interface ZodSchema<T = unknown> {
125
+ parse: (data: unknown) => T;
126
+ safeParse: (data: unknown) => {
127
+ success: boolean;
128
+ data?: T;
129
+ error?: ZodError;
130
+ };
131
+ }
132
+ type ZodObject$1<T = Record<string, unknown>> = ZodSchema<T>;
133
+ /**
134
+ * Extended request with organization ID
135
+ */
136
+ interface OrgRequest extends Request {
137
+ organizationId?: string;
138
+ }
139
+ /**
140
+ * Extended response with paginated result
141
+ */
142
+ interface PaginatedResponse extends Response {
143
+ paginatedResult?: {
144
+ data: unknown[];
145
+ meta: {
146
+ page: number;
147
+ limit: number;
148
+ total: number;
149
+ totalPages: number;
150
+ };
151
+ columns?: unknown[];
152
+ };
153
+ }
154
+ /**
155
+ * CRUD controller configuration
156
+ */
157
+ interface CrudConfig<T> {
158
+ /** Mongoose model */
159
+ model: Model<T>;
160
+ /** Resource name for logging and messages */
161
+ resourceName: string;
162
+ /** Zod schema for create validation */
163
+ createSchema?: ZodObject$1<unknown>;
164
+ /** Zod schema for update validation */
165
+ updateSchema?: ZodObject$1<unknown>;
166
+ /** Fields to search on (for getAll) */
167
+ searchFields?: string[];
168
+ /** Fields that use regex matching for filters */
169
+ regexFilterFields?: string[];
170
+ /** Whether to scope by organizationId (default: true) */
171
+ withOrganization?: boolean;
172
+ /** Field to use as the organization reference (default: 'organizationId') */
173
+ orgField?: string;
174
+ /** Custom transform for create input */
175
+ transformCreate?: (input: unknown, req: OrgRequest) => unknown;
176
+ /** Custom transform for update input */
177
+ transformUpdate?: (input: unknown, req: OrgRequest) => unknown;
178
+ /** Custom post-create hook */
179
+ afterCreate?: (doc: Document, req: OrgRequest) => Promise<void> | void;
180
+ /** Custom post-update hook */
181
+ afterUpdate?: (doc: Document, req: OrgRequest) => Promise<void> | void;
182
+ /** Custom post-delete hook */
183
+ afterDelete?: (id: string, req: OrgRequest) => Promise<void> | void;
184
+ /** Fields to exclude from response */
185
+ excludeFields?: string[];
186
+ /** Fields to populate in queries */
187
+ populateFields?: string[];
188
+ /** Custom query builder for getAll */
189
+ buildQuery?: (req: OrgRequest, baseQuery: Record<string, unknown>) => Record<string, unknown>;
190
+ }
191
+ /**
192
+ * Creates standardized CRUD controller handlers
193
+ */
194
+ declare function createCrudControllers<T extends Document>(config: CrudConfig<T>): {
195
+ getAll: RequestHandler;
196
+ getById: RequestHandler;
197
+ create: RequestHandler;
198
+ update: RequestHandler;
199
+ deleteOne: RequestHandler;
200
+ bulkDelete: RequestHandler;
201
+ };
202
+ /**
203
+ * Creates a standardized pagination middleware for a model
204
+ */
205
+ declare function createPaginationMiddleware<T>(model: Model<T>, config?: Partial<CrudConfig<T>>): RequestHandler;
206
+
207
+ /**
208
+ * Bulk Delete Middleware
209
+ *
210
+ * Common delete middleware for all services.
211
+ * Supports:
212
+ * - ['*'] → delete all records
213
+ * - ['id1', 'id2', ...] → delete multiple records
214
+ * - Single ID deletion as subset of multiple
215
+ */
216
+
217
+ /**
218
+ * Extended request interface with parsed delete IDs
219
+ */
220
+ interface BulkDeleteRequest extends Request {
221
+ deleteIds?: string[];
222
+ deleteAll?: boolean;
223
+ }
224
+ /**
225
+ * Validates and parses bulk delete request body
226
+ *
227
+ * Expected request body formats:
228
+ * - { "ids": ["*"] } or ["*"] → delete all
229
+ * - { "ids": ["id1", "id2"] } or ["id1", "id2"] → delete specific records
230
+ */
231
+ declare const parseBulkDelete: (req: Request, res: Response, next: NextFunction) => void | Response;
232
+ /**
233
+ * Helper function to build delete filter for MongoDB
234
+ */
235
+ declare const buildDeleteFilter: (req: BulkDeleteRequest, organizationId: string) => Record<string, unknown>;
236
+ /**
237
+ * Generic bulk delete handler factory
238
+ *
239
+ * Creates a controller function that handles bulk delete operations
240
+ * for any Mongoose model.
241
+ */
242
+ declare const createBulkDeleteHandler: (Model: {
243
+ deleteMany: (filter: Record<string, unknown>) => Promise<{
244
+ deletedCount?: number;
245
+ }>;
246
+ }, modelName: string) => (req: Request, res: Response) => Promise<Response>;
247
+
248
+ /**
249
+ * Pagination Types
250
+ * Standard types for pagination middleware
251
+ */
252
+
253
+ /**
254
+ * Sort order for queries
255
+ */
256
+ type SortOrder = 'asc' | 'desc';
257
+ /**
258
+ * Sort configuration
259
+ */
260
+ interface SortConfig {
261
+ field: string;
262
+ order: SortOrder;
263
+ }
264
+ /**
265
+ * Parsed query parameters from request
266
+ */
267
+ interface ParsedQuery {
268
+ page: number;
269
+ limit: number;
270
+ sort?: SortConfig;
271
+ search?: string;
272
+ filter: Record<string, string>;
273
+ }
274
+ /**
275
+ * Extended Express Request with parsed query
276
+ */
277
+ interface PaginatedRequest extends Request {
278
+ parsedQuery: ParsedQuery;
279
+ }
280
+ /**
281
+ * Pagination metadata for response
282
+ */
283
+ interface PaginationMeta {
284
+ page: number;
285
+ limit: number;
286
+ total: number;
287
+ totalPages: number;
288
+ }
289
+ /**
290
+ * Paginated result for response
291
+ */
292
+ interface PaginatedResult<T = unknown> {
293
+ data: T[];
294
+ meta: PaginationMeta;
295
+ columns?: unknown[];
296
+ }
297
+ declare global {
298
+ namespace Express {
299
+ interface Request {
300
+ parsedQuery: ParsedQuery;
301
+ }
302
+ interface Response {
303
+ paginatedResult?: PaginatedResult;
304
+ }
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Schema Meta Extraction Utility
310
+ * Extracts column metadata from Mongoose models and Zod schemas
311
+ */
312
+
313
+ interface ZodTypeAny {
314
+ _def?: {
315
+ typeName?: string;
316
+ innerType?: ZodTypeAny;
317
+ values?: unknown[];
318
+ };
319
+ }
320
+ type ZodObject<T = unknown> = {
321
+ shape?: Record<string, ZodTypeAny>;
322
+ parse: (data: unknown) => T;
323
+ };
324
+ /**
325
+ * Column metadata interface
326
+ */
327
+ interface ColumnMeta {
328
+ name: string;
329
+ datatype: string;
330
+ required: boolean;
331
+ }
332
+ /**
333
+ * Extract column metadata from Mongoose model and optional Zod schema
334
+ */
335
+ declare const extractSchemaMeta: <T>(model: Model<T>, zodSchema?: ZodObject<unknown>) => ColumnMeta[];
336
+
337
+ export { type AuthRequest, type BulkDeleteRequest, type ColumnMeta, type CrudConfig, type JWTPayload, type OrgRequest, type PaginatedRequest, type PaginatedResponse, type PaginatedResult, type PaginationMeta, type ParsedQuery, type SortConfig, type SortOrder, authenticateApiKey, authenticateJWT, buildDeleteFilter, createBulkDeleteHandler, createCrudControllers, createPaginationMiddleware, extractOrganization, extractSchemaMeta, optionalAuthenticateJWT, parseBulkDelete, queryPagination, queryParser, requireOrganization };