@mxweb/core 1.0.0

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -0
  3. package/dist/application.d.ts +402 -0
  4. package/dist/application.js +1 -0
  5. package/dist/application.mjs +1 -0
  6. package/dist/common.d.ts +323 -0
  7. package/dist/common.js +1 -0
  8. package/dist/common.mjs +1 -0
  9. package/dist/config.d.ts +258 -0
  10. package/dist/config.js +1 -0
  11. package/dist/config.mjs +1 -0
  12. package/dist/context.d.ts +48 -0
  13. package/dist/context.js +1 -0
  14. package/dist/context.mjs +1 -0
  15. package/dist/controller.d.ts +238 -0
  16. package/dist/controller.js +1 -0
  17. package/dist/controller.mjs +1 -0
  18. package/dist/decorator.d.ts +349 -0
  19. package/dist/decorator.js +1 -0
  20. package/dist/decorator.mjs +1 -0
  21. package/dist/error.d.ts +301 -0
  22. package/dist/error.js +1 -0
  23. package/dist/error.mjs +1 -0
  24. package/dist/execute.d.ts +469 -0
  25. package/dist/execute.js +1 -0
  26. package/dist/execute.mjs +1 -0
  27. package/dist/feature.d.ts +239 -0
  28. package/dist/feature.js +1 -0
  29. package/dist/feature.mjs +1 -0
  30. package/dist/hooks.d.ts +251 -0
  31. package/dist/hooks.js +1 -0
  32. package/dist/hooks.mjs +1 -0
  33. package/dist/index.d.ts +14 -0
  34. package/dist/index.js +1 -0
  35. package/dist/index.mjs +1 -0
  36. package/dist/logger.d.ts +360 -0
  37. package/dist/logger.js +1 -0
  38. package/dist/logger.mjs +1 -0
  39. package/dist/response.d.ts +665 -0
  40. package/dist/response.js +1 -0
  41. package/dist/response.mjs +1 -0
  42. package/dist/route.d.ts +298 -0
  43. package/dist/route.js +1 -0
  44. package/dist/route.mjs +1 -0
  45. package/dist/router.d.ts +205 -0
  46. package/dist/router.js +1 -0
  47. package/dist/router.mjs +1 -0
  48. package/dist/service.d.ts +261 -0
  49. package/dist/service.js +1 -0
  50. package/dist/service.mjs +1 -0
  51. package/package.json +168 -0
@@ -0,0 +1,665 @@
1
+ /**
2
+ * @fileoverview Standardized HTTP response builder for API endpoints.
3
+ *
4
+ * This module provides the `ServerResponse` class which creates consistent,
5
+ * structured JSON responses for all HTTP status codes. All responses follow
6
+ * a unified format:
7
+ *
8
+ * ```json
9
+ * {
10
+ * "success": boolean,
11
+ * "message": string,
12
+ * "code": string,
13
+ * "status": number,
14
+ * "data": any | null,
15
+ * "error": any | null
16
+ * }
17
+ * ```
18
+ *
19
+ * @module response
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { ServerResponse } from "@mxweb/core";
24
+ *
25
+ * const response = new ServerResponse();
26
+ *
27
+ * // Success responses
28
+ * return response.success(userData, "User fetched successfully");
29
+ * return response.created(newProduct, "Product created");
30
+ *
31
+ * // Error responses
32
+ * return response.notFound("User not found");
33
+ * return response.badRequest("Invalid email format", validationErrors);
34
+ * return response.unauthorized("Token expired");
35
+ * ```
36
+ */
37
+ import { NextResponse } from "next/server";
38
+ /**
39
+ * A utility class for building standardized HTTP responses.
40
+ *
41
+ * `ServerResponse` provides methods for all common HTTP status codes,
42
+ * ensuring consistent response structure across your API. Each method
43
+ * returns a `NextResponse` with properly formatted JSON body.
44
+ *
45
+ * @remarks
46
+ * - Success responses (2xx) have `success: true` and `error: null`
47
+ * - Error responses (4xx, 5xx) have `success: false` and `data: null`
48
+ * - All responses include a human-readable `message` and machine-readable `code`
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // In a controller method
53
+ * class ProductController extends BaseController {
54
+ * async getProduct(id: string) {
55
+ * const product = await this.productService.findById(id);
56
+ *
57
+ * if (!product) {
58
+ * return this.response.notFound(`Product ${id} not found`);
59
+ * }
60
+ *
61
+ * return this.response.success(product);
62
+ * }
63
+ *
64
+ * async createProduct(data: CreateProductDto) {
65
+ * const product = await this.productService.create(data);
66
+ * return this.response.created(product, "Product created successfully");
67
+ * }
68
+ * }
69
+ * ```
70
+ */
71
+ export declare class ServerResponse {
72
+ /**
73
+ * Creates a standardized JSON response object.
74
+ *
75
+ * @param code - Machine-readable status code (e.g., "SUCCESS", "NOT_FOUND")
76
+ * @param status - HTTP status code
77
+ * @param message - Human-readable message
78
+ * @param data - Response payload for success responses
79
+ * @param error - Error details for error responses
80
+ * @returns A structured response object
81
+ * @internal
82
+ */
83
+ private static toJSON;
84
+ /**
85
+ * Creates a response for HTTP OPTIONS preflight requests.
86
+ * Returns a 200 OK response, typically used for CORS.
87
+ *
88
+ * @returns NextResponse with 200 status
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * // Handling OPTIONS request
93
+ * if (method === "OPTIONS") {
94
+ * return ServerResponse.options();
95
+ * }
96
+ * ```
97
+ */
98
+ static options(): NextResponse<{
99
+ success: boolean;
100
+ message: string;
101
+ code: string;
102
+ status: number;
103
+ data: unknown;
104
+ error: unknown;
105
+ }>;
106
+ /**
107
+ * Returns a 200 OK response with optional data.
108
+ *
109
+ * @param data - The response payload
110
+ * @param message - Custom success message (default: "Successfully")
111
+ * @returns NextResponse with 200 status
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * return response.success(users, "Users retrieved successfully");
116
+ * return response.success({ token: "..." });
117
+ * ```
118
+ */
119
+ success(data?: unknown, message?: string): NextResponse<{
120
+ success: boolean;
121
+ message: string;
122
+ code: string;
123
+ status: number;
124
+ data: unknown;
125
+ error: unknown;
126
+ }>;
127
+ /**
128
+ * Returns a 201 Created response for newly created resources.
129
+ *
130
+ * @param data - The created resource
131
+ * @param message - Custom message (default: "Resource created successfully")
132
+ * @returns NextResponse with 201 status
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const newUser = await userService.create(userData);
137
+ * return response.created(newUser, "User registered successfully");
138
+ * ```
139
+ */
140
+ created(data?: unknown, message?: string): NextResponse<{
141
+ success: boolean;
142
+ message: string;
143
+ code: string;
144
+ status: number;
145
+ data: unknown;
146
+ error: unknown;
147
+ }>;
148
+ /**
149
+ * Returns a 202 Accepted response for async operations.
150
+ * Used when the request has been accepted but processing is not complete.
151
+ *
152
+ * @param data - Optional data (e.g., job ID for tracking)
153
+ * @param message - Custom message (default: "Request accepted successfully")
154
+ * @returns NextResponse with 202 status
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const jobId = await queue.enqueue(emailTask);
159
+ * return response.accepted({ jobId }, "Email will be sent shortly");
160
+ * ```
161
+ */
162
+ accepted(data?: unknown, message?: string): NextResponse<{
163
+ success: boolean;
164
+ message: string;
165
+ code: string;
166
+ status: number;
167
+ data: unknown;
168
+ error: unknown;
169
+ }>;
170
+ /**
171
+ * Returns a 204 No Content response.
172
+ * Typically used after DELETE operations.
173
+ *
174
+ * @param message - Custom message (default: "No content")
175
+ * @returns NextResponse with 204 status
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * await userService.delete(userId);
180
+ * return response.noContent("User deleted successfully");
181
+ * ```
182
+ */
183
+ noContent(message?: string): NextResponse<{
184
+ success: boolean;
185
+ message: string;
186
+ code: string;
187
+ status: number;
188
+ data: unknown;
189
+ error: unknown;
190
+ }>;
191
+ /**
192
+ * Returns a 301 Moved Permanently response.
193
+ * Indicates the resource has been permanently moved to a new URL.
194
+ *
195
+ * @returns NextResponse with 301 status
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * // Old endpoint permanently redirected
200
+ * return response.resourceMovedPermanently();
201
+ * ```
202
+ */
203
+ resourceMovedPermanently(): NextResponse<{
204
+ success: boolean;
205
+ message: string;
206
+ code: string;
207
+ status: number;
208
+ data: unknown;
209
+ error: unknown;
210
+ }>;
211
+ /**
212
+ * Returns a 302 Found (Temporary Redirect) response.
213
+ * Indicates the resource has been temporarily moved.
214
+ *
215
+ * @returns NextResponse with 302 status
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * // Temporary redirect during maintenance
220
+ * return response.resourceMovedTemporarily();
221
+ * ```
222
+ */
223
+ resourceMovedTemporarily(): NextResponse<{
224
+ success: boolean;
225
+ message: string;
226
+ code: string;
227
+ status: number;
228
+ data: unknown;
229
+ error: unknown;
230
+ }>;
231
+ /**
232
+ * Returns a 400 Bad Request response.
233
+ * Used when the request syntax is invalid or malformed.
234
+ *
235
+ * @param message - Error message (default: "Bad Request")
236
+ * @param error - Detailed error information (e.g., validation errors)
237
+ * @returns NextResponse with 400 status
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * if (!isValidEmail(email)) {
242
+ * return response.badRequest("Invalid email format", {
243
+ * field: "email",
244
+ * reason: "Must be a valid email address"
245
+ * });
246
+ * }
247
+ * ```
248
+ */
249
+ badRequest(message?: string, error?: unknown): NextResponse<{
250
+ success: boolean;
251
+ message: string;
252
+ code: string;
253
+ status: number;
254
+ data: unknown;
255
+ error: unknown;
256
+ }>;
257
+ /**
258
+ * Returns a 401 Unauthorized response.
259
+ * Used when authentication is required but missing or invalid.
260
+ *
261
+ * @param message - Error message (default: "Unauthorized")
262
+ * @param error - Detailed error information
263
+ * @returns NextResponse with 401 status
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * if (!authToken) {
268
+ * return response.unauthorized("Authentication token required");
269
+ * }
270
+ * if (tokenExpired) {
271
+ * return response.unauthorized("Token expired, please login again");
272
+ * }
273
+ * ```
274
+ */
275
+ unauthorized(message?: string, error?: unknown): NextResponse<{
276
+ success: boolean;
277
+ message: string;
278
+ code: string;
279
+ status: number;
280
+ data: unknown;
281
+ error: unknown;
282
+ }>;
283
+ /**
284
+ * Returns a 403 Forbidden response.
285
+ * Used when the user is authenticated but lacks permission.
286
+ *
287
+ * @param message - Error message (default: "Forbidden")
288
+ * @param error - Detailed error information
289
+ * @returns NextResponse with 403 status
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * if (!user.isAdmin) {
294
+ * return response.forbidden("Admin access required");
295
+ * }
296
+ * ```
297
+ */
298
+ forbidden(message?: string, error?: unknown): NextResponse<{
299
+ success: boolean;
300
+ message: string;
301
+ code: string;
302
+ status: number;
303
+ data: unknown;
304
+ error: unknown;
305
+ }>;
306
+ /**
307
+ * Returns a 404 Not Found response.
308
+ * Used when the requested resource does not exist.
309
+ *
310
+ * @param message - Error message (default: "Not Found")
311
+ * @param error - Detailed error information
312
+ * @returns NextResponse with 404 status
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * const user = await userService.findById(id);
317
+ * if (!user) {
318
+ * return response.notFound(`User with ID ${id} not found`);
319
+ * }
320
+ * ```
321
+ */
322
+ notFound(message?: string, error?: unknown): NextResponse<{
323
+ success: boolean;
324
+ message: string;
325
+ code: string;
326
+ status: number;
327
+ data: unknown;
328
+ error: unknown;
329
+ }>;
330
+ /**
331
+ * Returns a 405 Method Not Allowed response.
332
+ * Used when the HTTP method is not supported for the resource.
333
+ *
334
+ * @param message - Error message (default: "Method Not Allowed")
335
+ * @param error - Detailed error information
336
+ * @returns NextResponse with 405 status
337
+ *
338
+ * @example
339
+ * ```ts
340
+ * // Route only supports GET
341
+ * if (method !== "GET") {
342
+ * return response.methodNotAllowed(`${method} is not allowed`);
343
+ * }
344
+ * ```
345
+ */
346
+ methodNotAllowed(message?: string, error?: unknown): NextResponse<{
347
+ success: boolean;
348
+ message: string;
349
+ code: string;
350
+ status: number;
351
+ data: unknown;
352
+ error: unknown;
353
+ }>;
354
+ /**
355
+ * Returns a 406 Not Acceptable response.
356
+ * Used when the server cannot produce content matching Accept headers.
357
+ *
358
+ * @param message - Error message (default: "Not Acceptable")
359
+ * @param error - Detailed error information
360
+ * @returns NextResponse with 406 status
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * if (!supportedFormats.includes(acceptHeader)) {
365
+ * return response.notAcceptable("Requested format not supported");
366
+ * }
367
+ * ```
368
+ */
369
+ notAcceptable(message?: string, error?: unknown): NextResponse<{
370
+ success: boolean;
371
+ message: string;
372
+ code: string;
373
+ status: number;
374
+ data: unknown;
375
+ error: unknown;
376
+ }>;
377
+ /**
378
+ * Returns a 408 Request Timeout response.
379
+ * Used when the server timed out waiting for the request.
380
+ *
381
+ * @param message - Error message (default: "Request Timeout")
382
+ * @param error - Detailed error information
383
+ * @returns NextResponse with 408 status
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * try {
388
+ * await Promise.race([operation(), timeout(30000)]);
389
+ * } catch (e) {
390
+ * return response.requestTimeout("Operation timed out after 30 seconds");
391
+ * }
392
+ * ```
393
+ */
394
+ requestTimeout(message?: string, error?: unknown): NextResponse<{
395
+ success: boolean;
396
+ message: string;
397
+ code: string;
398
+ status: number;
399
+ data: unknown;
400
+ error: unknown;
401
+ }>;
402
+ /**
403
+ * Returns a 409 Conflict response.
404
+ * Used when the request conflicts with the current state of the resource.
405
+ *
406
+ * @param message - Error message (default: "Conflict")
407
+ * @param error - Detailed error information
408
+ * @returns NextResponse with 409 status
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const existingUser = await userService.findByEmail(email);
413
+ * if (existingUser) {
414
+ * return response.conflict("Email already registered");
415
+ * }
416
+ * ```
417
+ */
418
+ conflict(message?: string, error?: unknown): NextResponse<{
419
+ success: boolean;
420
+ message: string;
421
+ code: string;
422
+ status: number;
423
+ data: unknown;
424
+ error: unknown;
425
+ }>;
426
+ /**
427
+ * Returns a 410 Gone response.
428
+ * Used when a resource has been permanently deleted.
429
+ *
430
+ * @param message - Error message (default: "Gone")
431
+ * @param error - Detailed error information
432
+ * @returns NextResponse with 410 status
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * if (resource.deletedAt) {
437
+ * return response.gone("This resource has been permanently removed");
438
+ * }
439
+ * ```
440
+ */
441
+ gone(message?: string, error?: unknown): NextResponse<{
442
+ success: boolean;
443
+ message: string;
444
+ code: string;
445
+ status: number;
446
+ data: unknown;
447
+ error: unknown;
448
+ }>;
449
+ /**
450
+ * Returns a 413 Payload Too Large response.
451
+ * Used when the request body exceeds the server limit.
452
+ *
453
+ * @param message - Error message (default: "Payload Too Large")
454
+ * @param error - Detailed error information
455
+ * @returns NextResponse with 413 status
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * if (file.size > MAX_FILE_SIZE) {
460
+ * return response.payloadTooLarge(`File exceeds ${MAX_FILE_SIZE} bytes limit`);
461
+ * }
462
+ * ```
463
+ */
464
+ payloadTooLarge(message?: string, error?: unknown): NextResponse<{
465
+ success: boolean;
466
+ message: string;
467
+ code: string;
468
+ status: number;
469
+ data: unknown;
470
+ error: unknown;
471
+ }>;
472
+ /**
473
+ * Returns a 415 Unsupported Media Type response.
474
+ * Used when the request Content-Type is not supported.
475
+ *
476
+ * @param message - Error message (default: "Unsupported Media Type")
477
+ * @param error - Detailed error information
478
+ * @returns NextResponse with 415 status
479
+ *
480
+ * @example
481
+ * ```ts
482
+ * if (contentType !== "application/json") {
483
+ * return response.unsupportedMediaType("Only JSON content is accepted");
484
+ * }
485
+ * ```
486
+ */
487
+ unsupportedMediaType(message?: string, error?: unknown): NextResponse<{
488
+ success: boolean;
489
+ message: string;
490
+ code: string;
491
+ status: number;
492
+ data: unknown;
493
+ error: unknown;
494
+ }>;
495
+ /**
496
+ * Returns a 422 Unprocessable Entity response.
497
+ * Used when the request is syntactically correct but semantically invalid.
498
+ *
499
+ * @param message - Error message (default: "Unprocessable Entity")
500
+ * @param error - Detailed error information (e.g., validation errors)
501
+ * @returns NextResponse with 422 status
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * const errors = validateDto(data);
506
+ * if (errors.length > 0) {
507
+ * return response.unprocessableEntity("Validation failed", { errors });
508
+ * }
509
+ * ```
510
+ */
511
+ unprocessableEntity(message?: string, error?: unknown): NextResponse<{
512
+ success: boolean;
513
+ message: string;
514
+ code: string;
515
+ status: number;
516
+ data: unknown;
517
+ error: unknown;
518
+ }>;
519
+ /**
520
+ * Returns a 429 Too Many Requests response.
521
+ * Used for rate limiting.
522
+ *
523
+ * @param message - Error message (default: "Too Many Requests")
524
+ * @param error - Detailed error information (e.g., retry-after time)
525
+ * @returns NextResponse with 429 status
526
+ *
527
+ * @example
528
+ * ```ts
529
+ * if (rateLimiter.isExceeded(clientIp)) {
530
+ * return response.tooManyRequests("Rate limit exceeded", {
531
+ * retryAfter: 60,
532
+ * limit: 100,
533
+ * remaining: 0
534
+ * });
535
+ * }
536
+ * ```
537
+ */
538
+ tooManyRequests(message?: string, error?: unknown): NextResponse<{
539
+ success: boolean;
540
+ message: string;
541
+ code: string;
542
+ status: number;
543
+ data: unknown;
544
+ error: unknown;
545
+ }>;
546
+ /**
547
+ * Returns a 500 Internal Server Error response.
548
+ * Used for unexpected server-side errors.
549
+ *
550
+ * @param error - Error details (be careful not to expose sensitive info)
551
+ * @returns NextResponse with 500 status
552
+ *
553
+ * @example
554
+ * ```ts
555
+ * try {
556
+ * await riskyOperation();
557
+ * } catch (error) {
558
+ * logger.error("Unexpected error:", error);
559
+ * return response.internalServer({ message: "An unexpected error occurred" });
560
+ * }
561
+ * ```
562
+ */
563
+ internalServer(error?: unknown): NextResponse<{
564
+ success: boolean;
565
+ message: string;
566
+ code: string;
567
+ status: number;
568
+ data: unknown;
569
+ error: unknown;
570
+ }>;
571
+ /**
572
+ * Returns a 501 Not Implemented response.
573
+ * Used when a feature is not yet implemented.
574
+ *
575
+ * @param message - Error message (default: "Not Implemented")
576
+ * @param error - Detailed error information
577
+ * @returns NextResponse with 501 status
578
+ *
579
+ * @example
580
+ * ```ts
581
+ * return response.notImplemented("This feature is coming soon");
582
+ * ```
583
+ */
584
+ notImplemented(message?: string, error?: unknown): NextResponse<{
585
+ success: boolean;
586
+ message: string;
587
+ code: string;
588
+ status: number;
589
+ data: unknown;
590
+ error: unknown;
591
+ }>;
592
+ /**
593
+ * Returns a 502 Bad Gateway response.
594
+ * Used when an upstream server returned an invalid response.
595
+ *
596
+ * @param message - Error message (default: "Bad Gateway")
597
+ * @param error - Detailed error information
598
+ * @returns NextResponse with 502 status
599
+ *
600
+ * @example
601
+ * ```ts
602
+ * try {
603
+ * await thirdPartyApi.call();
604
+ * } catch (e) {
605
+ * return response.badGateway("External service returned invalid response");
606
+ * }
607
+ * ```
608
+ */
609
+ badGateway(message?: string, error?: unknown): NextResponse<{
610
+ success: boolean;
611
+ message: string;
612
+ code: string;
613
+ status: number;
614
+ data: unknown;
615
+ error: unknown;
616
+ }>;
617
+ /**
618
+ * Returns a 503 Service Unavailable response.
619
+ * Used during maintenance or overload conditions.
620
+ *
621
+ * @param message - Error message (default: "Service Unavailable")
622
+ * @param error - Detailed error information
623
+ * @returns NextResponse with 503 status
624
+ *
625
+ * @example
626
+ * ```ts
627
+ * if (isMaintenanceMode) {
628
+ * return response.serviceUnavailable("Service under maintenance");
629
+ * }
630
+ * ```
631
+ */
632
+ serviceUnavailable(message?: string, error?: unknown): NextResponse<{
633
+ success: boolean;
634
+ message: string;
635
+ code: string;
636
+ status: number;
637
+ data: unknown;
638
+ error: unknown;
639
+ }>;
640
+ /**
641
+ * Returns a 504 Gateway Timeout response.
642
+ * Used when an upstream server did not respond in time.
643
+ *
644
+ * @param message - Error message (default: "Gateway Timeout")
645
+ * @param error - Detailed error information
646
+ * @returns NextResponse with 504 status
647
+ *
648
+ * @example
649
+ * ```ts
650
+ * try {
651
+ * await fetchWithTimeout(upstreamUrl, 5000);
652
+ * } catch (e) {
653
+ * return response.gatewayTimeout("Upstream server did not respond");
654
+ * }
655
+ * ```
656
+ */
657
+ gatewayTimeout(message?: string, error?: unknown): NextResponse<{
658
+ success: boolean;
659
+ message: string;
660
+ code: string;
661
+ status: number;
662
+ data: unknown;
663
+ error: unknown;
664
+ }>;
665
+ }
@@ -0,0 +1 @@
1
+ "use strict";var e=require("next/server");class t{static toJSON(e,t=200,s="Successfully",o=null,r=null){return{success:t>=200&&t<400,message:s,code:e,status:t,data:o,error:r}}static options(){return(new t).success()}success(s=null,o){return e.NextResponse.json(t.toJSON("SUCCESS",200,o,s,null),{status:200})}created(s=null,o){return e.NextResponse.json(t.toJSON("CREATED",201,o??"Resource created successfully",s,null),{status:201})}accepted(s=null,o){return e.NextResponse.json(t.toJSON("ACCEPTED",202,o??"Request accepted successfully",s,null),{status:202})}noContent(s){return e.NextResponse.json(t.toJSON("NO_CONTENT",204,s??"No content",null,null),{status:204})}resourceMovedPermanently(){return e.NextResponse.json(t.toJSON("MOVED_PERMANENTLY",301,"Resource moved permanently",null,null),{status:301})}resourceMovedTemporarily(){return e.NextResponse.json(t.toJSON("REDIRECTED",302,"Resource moved temporarily",null,null),{status:302})}badRequest(s="Bad Request",o){return e.NextResponse.json(t.toJSON("BAD_REQUEST",400,s,null,o??{message:"The server could not understand the request due to invalid syntax",name:"BadRequestError",code:"BAD_REQUEST"}),{status:400})}unauthorized(s="Unauthorized",o){return e.NextResponse.json(t.toJSON("UNAUTHORIZED",401,s,null,o??{message:"Authentication is required and has failed or has not yet been provided",name:"UnauthorizedError",code:"AUTHENTICATION_REQUIRED"}),{status:401})}forbidden(s="Forbidden",o){return e.NextResponse.json(t.toJSON("FORBIDDEN",403,s,null,o??{message:"You do not have permission to access this resource",name:"ForbiddenError",code:"ACCESS_FORBIDDEN"}),{status:403})}notFound(s="Not Found",o){return e.NextResponse.json(t.toJSON("NOT_FOUND",404,s,null,o??{message:"The requested resource was not found",name:"NotFoundError",code:"URL_NOT_FOUND"}),{status:404})}methodNotAllowed(s="Method Not Allowed",o){return e.NextResponse.json(t.toJSON("METHOD_NOT_ALLOWED",405,s,null,o??{message:"The HTTP method is not allowed for this resource",name:"MethodNotAllowedError",code:"METHOD_NOT_ALLOWED"}),{status:405})}notAcceptable(s="Not Acceptable",o){return e.NextResponse.json(t.toJSON("NOT_ACCEPTABLE",406,s,null,o??{message:"The server cannot produce a response matching the acceptable values",name:"NotAcceptableError",code:"NOT_ACCEPTABLE"}),{status:406})}requestTimeout(s="Request Timeout",o){return e.NextResponse.json(t.toJSON("REQUEST_TIMEOUT",408,s,null,o??{message:"The server timed out waiting for the request",name:"RequestTimeoutError",code:"REQUEST_TIMEOUT"}),{status:408})}conflict(s="Conflict",o){return e.NextResponse.json(t.toJSON("CONFLICT",409,s,null,o??{message:"The request could not be completed due to a conflict with the current state of the resource",name:"ConflictError",code:"RESOURCE_CONFLICT"}),{status:409})}gone(s="Gone",o){return e.NextResponse.json(t.toJSON("GONE",410,s,null,o??{message:"The requested resource is no longer available and has been permanently removed",name:"GoneError",code:"RESOURCE_GONE"}),{status:410})}payloadTooLarge(s="Payload Too Large",o){return e.NextResponse.json(t.toJSON("PAYLOAD_TOO_LARGE",413,s,null,o??{message:"The request payload is larger than the server is willing to process",name:"PayloadTooLargeError",code:"PAYLOAD_TOO_LARGE"}),{status:413})}unsupportedMediaType(s="Unsupported Media Type",o){return e.NextResponse.json(t.toJSON("UNSUPPORTED_MEDIA_TYPE",415,s,null,o??{message:"The media format of the requested data is not supported by the server",name:"UnsupportedMediaTypeError",code:"UNSUPPORTED_MEDIA_TYPE"}),{status:415})}unprocessableEntity(s="Unprocessable Entity",o){return e.NextResponse.json(t.toJSON("UNPROCESSABLE_ENTITY",422,s,null,o??{message:"The request was well-formed but was unable to be followed due to semantic errors",name:"UnprocessableEntityError",code:"UNPROCESSABLE_ENTITY"}),{status:422})}tooManyRequests(s="Too Many Requests",o){return e.NextResponse.json(t.toJSON("TOO_MANY_REQUESTS",429,s,null,o??{message:"You have sent too many requests in a given amount of time",name:"TooManyRequestsError",code:"TOO_MANY_REQUESTS"}),{status:429})}internalServer(s){return e.NextResponse.json(t.toJSON("INTERNAL_SERVER_ERROR",500,"Internal Server Error",null,s??{message:"An unexpected error occurred on the server",name:"InternalServerError",code:"INTERNAL_SERVER_ERROR"}),{status:500})}notImplemented(s="Not Implemented",o){return e.NextResponse.json(t.toJSON("NOT_IMPLEMENTED",501,s,null,o??{message:"The requested functionality is not implemented",name:"NotImplementedError",code:"NOT_IMPLEMENTED"}),{status:501})}badGateway(s="Bad Gateway",o){return e.NextResponse.json(t.toJSON("BAD_GATEWAY",502,s,null,o??{message:"Received an invalid response from the upstream server",name:"BadGatewayError",code:"BAD_GATEWAY"}),{status:502})}serviceUnavailable(s="Service Unavailable",o){return e.NextResponse.json(t.toJSON("SERVICE_UNAVAILABLE",503,s,null,o??{message:"The server is currently unable to handle the request",name:"ServiceUnavailableError",code:"SERVICE_UNAVAILABLE"}),{status:503})}gatewayTimeout(s="Gateway Timeout",o){return e.NextResponse.json(t.toJSON("GATEWAY_TIMEOUT",504,s,null,o??{message:"The server did not receive a timely response from the upstream server",name:"GatewayTimeoutError",code:"GATEWAY_TIMEOUT"}),{status:504})}}exports.ServerResponse=t;
@@ -0,0 +1 @@
1
+ import{NextResponse as e}from"next/server";class t{static toJSON(e,t=200,r="Successfully",o=null,s=null){return{success:t>=200&&t<400,message:r,code:e,status:t,data:o,error:s}}static options(){return(new t).success()}success(r=null,o){return e.json(t.toJSON("SUCCESS",200,o,r,null),{status:200})}created(r=null,o){return e.json(t.toJSON("CREATED",201,o??"Resource created successfully",r,null),{status:201})}accepted(r=null,o){return e.json(t.toJSON("ACCEPTED",202,o??"Request accepted successfully",r,null),{status:202})}noContent(r){return e.json(t.toJSON("NO_CONTENT",204,r??"No content",null,null),{status:204})}resourceMovedPermanently(){return e.json(t.toJSON("MOVED_PERMANENTLY",301,"Resource moved permanently",null,null),{status:301})}resourceMovedTemporarily(){return e.json(t.toJSON("REDIRECTED",302,"Resource moved temporarily",null,null),{status:302})}badRequest(r="Bad Request",o){return e.json(t.toJSON("BAD_REQUEST",400,r,null,o??{message:"The server could not understand the request due to invalid syntax",name:"BadRequestError",code:"BAD_REQUEST"}),{status:400})}unauthorized(r="Unauthorized",o){return e.json(t.toJSON("UNAUTHORIZED",401,r,null,o??{message:"Authentication is required and has failed or has not yet been provided",name:"UnauthorizedError",code:"AUTHENTICATION_REQUIRED"}),{status:401})}forbidden(r="Forbidden",o){return e.json(t.toJSON("FORBIDDEN",403,r,null,o??{message:"You do not have permission to access this resource",name:"ForbiddenError",code:"ACCESS_FORBIDDEN"}),{status:403})}notFound(r="Not Found",o){return e.json(t.toJSON("NOT_FOUND",404,r,null,o??{message:"The requested resource was not found",name:"NotFoundError",code:"URL_NOT_FOUND"}),{status:404})}methodNotAllowed(r="Method Not Allowed",o){return e.json(t.toJSON("METHOD_NOT_ALLOWED",405,r,null,o??{message:"The HTTP method is not allowed for this resource",name:"MethodNotAllowedError",code:"METHOD_NOT_ALLOWED"}),{status:405})}notAcceptable(r="Not Acceptable",o){return e.json(t.toJSON("NOT_ACCEPTABLE",406,r,null,o??{message:"The server cannot produce a response matching the acceptable values",name:"NotAcceptableError",code:"NOT_ACCEPTABLE"}),{status:406})}requestTimeout(r="Request Timeout",o){return e.json(t.toJSON("REQUEST_TIMEOUT",408,r,null,o??{message:"The server timed out waiting for the request",name:"RequestTimeoutError",code:"REQUEST_TIMEOUT"}),{status:408})}conflict(r="Conflict",o){return e.json(t.toJSON("CONFLICT",409,r,null,o??{message:"The request could not be completed due to a conflict with the current state of the resource",name:"ConflictError",code:"RESOURCE_CONFLICT"}),{status:409})}gone(r="Gone",o){return e.json(t.toJSON("GONE",410,r,null,o??{message:"The requested resource is no longer available and has been permanently removed",name:"GoneError",code:"RESOURCE_GONE"}),{status:410})}payloadTooLarge(r="Payload Too Large",o){return e.json(t.toJSON("PAYLOAD_TOO_LARGE",413,r,null,o??{message:"The request payload is larger than the server is willing to process",name:"PayloadTooLargeError",code:"PAYLOAD_TOO_LARGE"}),{status:413})}unsupportedMediaType(r="Unsupported Media Type",o){return e.json(t.toJSON("UNSUPPORTED_MEDIA_TYPE",415,r,null,o??{message:"The media format of the requested data is not supported by the server",name:"UnsupportedMediaTypeError",code:"UNSUPPORTED_MEDIA_TYPE"}),{status:415})}unprocessableEntity(r="Unprocessable Entity",o){return e.json(t.toJSON("UNPROCESSABLE_ENTITY",422,r,null,o??{message:"The request was well-formed but was unable to be followed due to semantic errors",name:"UnprocessableEntityError",code:"UNPROCESSABLE_ENTITY"}),{status:422})}tooManyRequests(r="Too Many Requests",o){return e.json(t.toJSON("TOO_MANY_REQUESTS",429,r,null,o??{message:"You have sent too many requests in a given amount of time",name:"TooManyRequestsError",code:"TOO_MANY_REQUESTS"}),{status:429})}internalServer(r){return e.json(t.toJSON("INTERNAL_SERVER_ERROR",500,"Internal Server Error",null,r??{message:"An unexpected error occurred on the server",name:"InternalServerError",code:"INTERNAL_SERVER_ERROR"}),{status:500})}notImplemented(r="Not Implemented",o){return e.json(t.toJSON("NOT_IMPLEMENTED",501,r,null,o??{message:"The requested functionality is not implemented",name:"NotImplementedError",code:"NOT_IMPLEMENTED"}),{status:501})}badGateway(r="Bad Gateway",o){return e.json(t.toJSON("BAD_GATEWAY",502,r,null,o??{message:"Received an invalid response from the upstream server",name:"BadGatewayError",code:"BAD_GATEWAY"}),{status:502})}serviceUnavailable(r="Service Unavailable",o){return e.json(t.toJSON("SERVICE_UNAVAILABLE",503,r,null,o??{message:"The server is currently unable to handle the request",name:"ServiceUnavailableError",code:"SERVICE_UNAVAILABLE"}),{status:503})}gatewayTimeout(r="Gateway Timeout",o){return e.json(t.toJSON("GATEWAY_TIMEOUT",504,r,null,o??{message:"The server did not receive a timely response from the upstream server",name:"GatewayTimeoutError",code:"GATEWAY_TIMEOUT"}),{status:504})}}export{t as ServerResponse};