@coherent.js/api 1.0.0-beta.2

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/LICENSE +21 -0
  2. package/README.md +91 -0
  3. package/dist/api/errors.d.ts +92 -0
  4. package/dist/api/errors.d.ts.map +1 -0
  5. package/dist/api/errors.js +161 -0
  6. package/dist/api/errors.js.map +1 -0
  7. package/dist/api/index.d.ts +61 -0
  8. package/dist/api/index.d.ts.map +1 -0
  9. package/dist/api/index.js +41 -0
  10. package/dist/api/index.js.map +1 -0
  11. package/dist/api/middleware.d.ts +57 -0
  12. package/dist/api/middleware.d.ts.map +1 -0
  13. package/dist/api/middleware.js +244 -0
  14. package/dist/api/middleware.js.map +1 -0
  15. package/dist/api/openapi.d.ts +54 -0
  16. package/dist/api/openapi.d.ts.map +1 -0
  17. package/dist/api/openapi.js +144 -0
  18. package/dist/api/openapi.js.map +1 -0
  19. package/dist/api/router.d.ts +368 -0
  20. package/dist/api/router.d.ts.map +1 -0
  21. package/dist/api/router.js +1508 -0
  22. package/dist/api/router.js.map +1 -0
  23. package/dist/api/security.d.ts +64 -0
  24. package/dist/api/security.d.ts.map +1 -0
  25. package/dist/api/security.js +239 -0
  26. package/dist/api/security.js.map +1 -0
  27. package/dist/api/serialization.d.ts +86 -0
  28. package/dist/api/serialization.d.ts.map +1 -0
  29. package/dist/api/serialization.js +151 -0
  30. package/dist/api/serialization.js.map +1 -0
  31. package/dist/api/validation.d.ts +34 -0
  32. package/dist/api/validation.d.ts.map +1 -0
  33. package/dist/api/validation.js +172 -0
  34. package/dist/api/validation.js.map +1 -0
  35. package/dist/index.cjs +1776 -0
  36. package/dist/index.cjs.map +7 -0
  37. package/dist/index.js +1722 -0
  38. package/dist/index.js.map +7 -0
  39. package/package.json +46 -0
  40. package/types/index.d.ts +720 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Thomas Drouvin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @coherent.js/api
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@coherent.js/api.svg)](https://www.npmjs.com/package/@coherent.js/api)
4
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](../../LICENSE)
5
+ [![Node >= 20](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](https://nodejs.org)
6
+
7
+ API framework utilities for Coherent.js (routing, validation, serialization, security).
8
+
9
+ - ESM-only, Node 20+
10
+ - Build APIs with an object-first approach
11
+ - Batteries-included: validation, error handling, auth helpers, and serialization
12
+
13
+ For a high-level overview and repository-wide instructions, see the root README: ../../README.md
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pnpm add @coherent.js/api
19
+ ```
20
+
21
+ Requirements:
22
+ - Node.js >= 20
23
+ - ESM module system
24
+
25
+ ## Quick start
26
+
27
+ JavaScript (ESM):
28
+ ```js
29
+ import { createRouter, withValidation, ApiError } from '@coherent.js/api';
30
+
31
+ const router = createRouter({
32
+ 'GET /health': () => ({ status: 'ok' }),
33
+ 'POST /echo': withValidation({ body: { message: 'string' } }, ({ body }) => ({ message: body.message }))
34
+ });
35
+
36
+ // router.handle(req) -> { statusCode, headers, body }
37
+ ```
38
+
39
+ TypeScript:
40
+ ```ts
41
+ import { createRouter, withValidation, ApiError } from '@coherent.js/api';
42
+
43
+ type EchoBody = { message: string };
44
+
45
+ const router = createRouter({
46
+ 'GET /health': () => ({ status: 'ok' }),
47
+ 'POST /echo': withValidation<{ body: EchoBody }>({ body: { message: 'string' } }, ({ body }) => ({ message: body.message }))
48
+ });
49
+ ```
50
+
51
+ ## Exports overview (selected)
52
+
53
+ - Routing
54
+ - `createRouter`
55
+ - Errors & handlers
56
+ - `ApiError`, `ValidationError`, `AuthenticationError`, `AuthorizationError`, `NotFoundError`, `ConflictError`
57
+ - `withErrorHandling`, `createErrorHandler`
58
+ - Validation
59
+ - `validateAgainstSchema`, `validateField`, `withValidation`, `withQueryValidation`, `withParamsValidation`
60
+ - Serialization
61
+ - `serializeDate`, `deserializeDate`, `serializeMap`, `deserializeMap`, `serializeSet`, `deserializeSet`, `withSerialization`, `serializeForJSON`
62
+ - Security
63
+ - `withAuth`, `withRole`, `hashPassword`, `verifyPassword`, `generateToken`, `withInputValidation`
64
+
65
+ Tip: Combine `withValidation`, `withAuth`, and `withErrorHandling` to build robust endpoints.
66
+
67
+ ## Development
68
+
69
+ Run tests for this package:
70
+ ```bash
71
+ pnpm --filter @coherent.js/api run test
72
+ ```
73
+
74
+ Watch mode:
75
+ ```bash
76
+ pnpm --filter @coherent.js/api run test:watch
77
+ ```
78
+
79
+ Type check:
80
+ ```bash
81
+ pnpm --filter @coherent.js/api run typecheck
82
+ ```
83
+
84
+ Build:
85
+ ```bash
86
+ pnpm --filter @coherent.js/api run build
87
+ ```
88
+
89
+ ## License
90
+
91
+ MIT © Coherent.js Team
@@ -0,0 +1,92 @@
1
+ /**
2
+ * API Error Handling for Coherent.js
3
+ * @fileoverview Standardized error classes and handling utilities
4
+ */
5
+ /**
6
+ * Base API Error class
7
+ * @extends Error
8
+ */
9
+ export class ApiError extends Error {
10
+ /**
11
+ * Create an API error
12
+ * @param {string} message - Error message
13
+ * @param {number} statusCode - HTTP status code
14
+ * @param {Object} details - Additional error details
15
+ */
16
+ constructor(message: string, statusCode?: number, details?: Object);
17
+ statusCode: number;
18
+ details: Object;
19
+ /**
20
+ * Convert error to JSON-serializable object
21
+ * @returns {Object} Error object
22
+ */
23
+ toJSON(): Object;
24
+ }
25
+ /**
26
+ * Validation Error class
27
+ * @extends ApiError
28
+ */
29
+ export class ValidationError extends ApiError {
30
+ /**
31
+ * Create a validation error
32
+ * @param {Object} errors - Validation errors
33
+ * @param {string} message - Error message
34
+ */
35
+ constructor(errors: Object, message?: string);
36
+ }
37
+ /**
38
+ * Authentication Error class
39
+ * @extends ApiError
40
+ */
41
+ export class AuthenticationError extends ApiError {
42
+ /**
43
+ * Create an authentication error
44
+ * @param {string} message - Error message
45
+ */
46
+ constructor(message?: string);
47
+ }
48
+ /**
49
+ * Authorization Error class
50
+ * @extends ApiError
51
+ */
52
+ export class AuthorizationError extends ApiError {
53
+ /**
54
+ * Create an authorization error
55
+ * @param {string} message - Error message
56
+ */
57
+ constructor(message?: string);
58
+ }
59
+ /**
60
+ * Not Found Error class
61
+ * @extends ApiError
62
+ */
63
+ export class NotFoundError extends ApiError {
64
+ /**
65
+ * Create a not found error
66
+ * @param {string} message - Error message
67
+ */
68
+ constructor(message?: string);
69
+ }
70
+ /**
71
+ * Conflict Error class
72
+ * @extends ApiError
73
+ */
74
+ export class ConflictError extends ApiError {
75
+ /**
76
+ * Create a conflict error
77
+ * @param {string} message - Error message
78
+ */
79
+ constructor(message?: string);
80
+ }
81
+ /**
82
+ * Create error handling middleware
83
+ * @param {Function} handler - Error handler function
84
+ * @returns {Function} Middleware function
85
+ */
86
+ export function withErrorHandling(handler: Function): Function;
87
+ /**
88
+ * Global error handler middleware
89
+ * @returns {Function} Express error handler middleware
90
+ */
91
+ export function createErrorHandler(): Function;
92
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/api/errors.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH;IACE;;;;;OAKG;IACH,qBAJW,MAAM,eACN,MAAM,YACN,MAAM,EAYhB;IAPC,mBAA4B;IAC5B,gBAAsB;IAQxB;;;OAGG;IACH,UAFa,MAAM,CASlB;CACF;AAED;;;GAGG;AACH;IACE;;;;OAIG;IACH,oBAHW,MAAM,YACN,MAAM,EAKhB;CACF;AAED;;;GAGG;AACH;IACE;;;OAGG;IACH,sBAFW,MAAM,EAKhB;CACF;AAED;;;GAGG;AACH;IACE;;;OAGG;IACH,sBAFW,MAAM,EAKhB;CACF;AAED;;;GAGG;AACH;IACE;;;OAGG;IACH,sBAFW,MAAM,EAKhB;CACF;AAED;;;GAGG;AACH;IACE;;;OAGG;IACH,sBAFW,MAAM,EAKhB;CACF;AAED;;;;GAIG;AACH,+DAcC;AAED;;;GAGG;AACH,+CA6BC"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * API Error Handling for Coherent.js
3
+ * @fileoverview Standardized error classes and handling utilities
4
+ */
5
+ /**
6
+ * Base API Error class
7
+ * @extends Error
8
+ */
9
+ class ApiError extends Error {
10
+ /**
11
+ * Create an API error
12
+ * @param {string} message - Error message
13
+ * @param {number} statusCode - HTTP status code
14
+ * @param {Object} details - Additional error details
15
+ */
16
+ constructor(message, statusCode = 500, details = {}) {
17
+ super(message);
18
+ this.name = 'ApiError';
19
+ this.statusCode = statusCode;
20
+ this.details = details;
21
+ // Ensure proper stack trace
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, ApiError);
24
+ }
25
+ }
26
+ /**
27
+ * Convert error to JSON-serializable object
28
+ * @returns {Object} Error object
29
+ */
30
+ toJSON() {
31
+ return {
32
+ error: this.name,
33
+ message: this.message,
34
+ statusCode: this.statusCode,
35
+ details: this.details
36
+ };
37
+ }
38
+ }
39
+ /**
40
+ * Validation Error class
41
+ * @extends ApiError
42
+ */
43
+ class ValidationError extends ApiError {
44
+ /**
45
+ * Create a validation error
46
+ * @param {Object} errors - Validation errors
47
+ * @param {string} message - Error message
48
+ */
49
+ constructor(errors, message = 'Validation failed') {
50
+ super(message, 400, { errors });
51
+ this.name = 'ValidationError';
52
+ }
53
+ }
54
+ /**
55
+ * Authentication Error class
56
+ * @extends ApiError
57
+ */
58
+ class AuthenticationError extends ApiError {
59
+ /**
60
+ * Create an authentication error
61
+ * @param {string} message - Error message
62
+ */
63
+ constructor(message = 'Authentication required') {
64
+ super(message, 401);
65
+ this.name = 'AuthenticationError';
66
+ }
67
+ }
68
+ /**
69
+ * Authorization Error class
70
+ * @extends ApiError
71
+ */
72
+ class AuthorizationError extends ApiError {
73
+ /**
74
+ * Create an authorization error
75
+ * @param {string} message - Error message
76
+ */
77
+ constructor(message = 'Access denied') {
78
+ super(message, 403);
79
+ this.name = 'AuthorizationError';
80
+ }
81
+ }
82
+ /**
83
+ * Not Found Error class
84
+ * @extends ApiError
85
+ */
86
+ class NotFoundError extends ApiError {
87
+ /**
88
+ * Create a not found error
89
+ * @param {string} message - Error message
90
+ */
91
+ constructor(message = 'Resource not found') {
92
+ super(message, 404);
93
+ this.name = 'NotFoundError';
94
+ }
95
+ }
96
+ /**
97
+ * Conflict Error class
98
+ * @extends ApiError
99
+ */
100
+ class ConflictError extends ApiError {
101
+ /**
102
+ * Create a conflict error
103
+ * @param {string} message - Error message
104
+ */
105
+ constructor(message = 'Resource conflict') {
106
+ super(message, 409);
107
+ this.name = 'ConflictError';
108
+ }
109
+ }
110
+ /**
111
+ * Create error handling middleware
112
+ * @param {Function} handler - Error handler function
113
+ * @returns {Function} Middleware function
114
+ */
115
+ function withErrorHandling(handler) {
116
+ return async (req, res, next) => {
117
+ try {
118
+ return await handler(req, res, next);
119
+ }
120
+ catch (error) {
121
+ // If it's already an API error, use it as-is
122
+ if (error instanceof ApiError) {
123
+ throw error;
124
+ }
125
+ // Otherwise, wrap it as a generic server error
126
+ throw new ApiError(error.message || 'Internal server error', 500);
127
+ }
128
+ };
129
+ }
130
+ /**
131
+ * Global error handler middleware
132
+ * @returns {Function} Express error handler middleware
133
+ */
134
+ function createErrorHandler() {
135
+ return (error, req, res, next) => {
136
+ // Log error for debugging
137
+ console.error('API Error:', error);
138
+ // If headers are already sent, delegate to default error handler
139
+ if (res.headersSent) {
140
+ return next(error);
141
+ }
142
+ // Format error response
143
+ const response = {
144
+ error: error.name || 'Error',
145
+ message: error.message || 'An error occurred',
146
+ statusCode: error.statusCode || 500
147
+ };
148
+ // Add details if available
149
+ if (error.details) {
150
+ response.details = error.details;
151
+ }
152
+ // Add stack trace in development
153
+ if (process.env.NODE_ENV === 'development') {
154
+ response.stack = error.stack;
155
+ }
156
+ res.status(response.statusCode).json(response);
157
+ };
158
+ }
159
+ // Export all error classes and utilities
160
+ export { ApiError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, withErrorHandling, createErrorHandler };
161
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/api/errors.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,QAAS,SAAQ,KAAK;IAC1B;;;;;OAKG;IACH,YAAY,OAAO,EAAE,UAAU,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,4BAA4B;QAC5B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KA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,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;YAC3C,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC/B,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,yCAAyC;AACzC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EACnB,CAAC"}
@@ -0,0 +1,61 @@
1
+ declare namespace _default {
2
+ export { createObjectRouter };
3
+ export { ApiError };
4
+ export { ValidationError };
5
+ export { AuthenticationError };
6
+ export { AuthorizationError };
7
+ export { NotFoundError };
8
+ export { ConflictError };
9
+ export { withErrorHandling };
10
+ export { createErrorHandler };
11
+ export { validateAgainstSchema };
12
+ export { validateField };
13
+ export { withValidation };
14
+ export { withQueryValidation };
15
+ export { withParamsValidation };
16
+ export { serializeDate };
17
+ export { deserializeDate };
18
+ export { serializeMap };
19
+ export { deserializeMap };
20
+ export { serializeSet };
21
+ export { deserializeSet };
22
+ export { withSerialization };
23
+ export { serializeForJSON };
24
+ export { withAuth };
25
+ export { withRole };
26
+ export { hashPassword };
27
+ export { verifyPassword };
28
+ export { generateToken };
29
+ export { withInputValidation };
30
+ }
31
+ export default _default;
32
+ import { createObjectRouter } from './router.js';
33
+ import { ApiError } from './errors.js';
34
+ import { ValidationError } from './errors.js';
35
+ import { AuthenticationError } from './errors.js';
36
+ import { AuthorizationError } from './errors.js';
37
+ import { NotFoundError } from './errors.js';
38
+ import { ConflictError } from './errors.js';
39
+ import { withErrorHandling } from './errors.js';
40
+ import { createErrorHandler } from './errors.js';
41
+ import { validateAgainstSchema } from './validation.js';
42
+ import { validateField } from './validation.js';
43
+ import { withValidation } from './validation.js';
44
+ import { withQueryValidation } from './validation.js';
45
+ import { withParamsValidation } from './validation.js';
46
+ import { serializeDate } from './serialization.js';
47
+ import { deserializeDate } from './serialization.js';
48
+ import { serializeMap } from './serialization.js';
49
+ import { deserializeMap } from './serialization.js';
50
+ import { serializeSet } from './serialization.js';
51
+ import { deserializeSet } from './serialization.js';
52
+ import { withSerialization } from './serialization.js';
53
+ import { serializeForJSON } from './serialization.js';
54
+ import { withAuth } from './security.js';
55
+ import { withRole } from './security.js';
56
+ import { hashPassword } from './security.js';
57
+ import { verifyPassword } from './security.js';
58
+ import { generateToken } from './security.js';
59
+ import { withInputValidation } from './security.js';
60
+ export { createObjectRouter, ApiError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, withErrorHandling, createErrorHandler, validateAgainstSchema, validateField, withValidation, withQueryValidation, withParamsValidation, serializeDate, deserializeDate, serializeMap, deserializeMap, serializeSet, deserializeSet, withSerialization, serializeForJSON, withAuth, withRole, hashPassword, verifyPassword, generateToken, withInputValidation };
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAKmC,aAAa;yBACwG,aAAa;gCAAb,aAAa;oCAAb,aAAa;mCAAb,aAAa;8BAAb,aAAa;8BAAb,aAAa;kCAAb,aAAa;mCAAb,aAAa;sCACrD,iBAAiB;8BAAjB,iBAAiB;+BAAjB,iBAAiB;oCAAjB,iBAAiB;qCAAjB,iBAAiB;8BACe,oBAAoB;gCAApB,oBAAoB;6BAApB,oBAAoB;+BAApB,oBAAoB;6BAApB,oBAAoB;+BAApB,oBAAoB;kCAApB,oBAAoB;iCAApB,oBAAoB;yBAC/D,eAAe;yBAAf,eAAe;6BAAf,eAAe;+BAAf,eAAe;8BAAf,eAAe;oCAAf,eAAe"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Coherent.js API Module
3
+ * @fileoverview Core utilities for building APIs with Coherent.js
4
+ */
5
+ import { createObjectRouter } from './router.js';
6
+ import { ApiError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, withErrorHandling, createErrorHandler } from './errors.js';
7
+ import { validateAgainstSchema, validateField, withValidation, withQueryValidation, withParamsValidation } from './validation.js';
8
+ import { serializeDate, deserializeDate, serializeMap, deserializeMap, serializeSet, deserializeSet, withSerialization, serializeForJSON } from './serialization.js';
9
+ import { withAuth, withRole, hashPassword, verifyPassword, generateToken, withInputValidation } from './security.js';
10
+ export { createObjectRouter, ApiError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, withErrorHandling, createErrorHandler, validateAgainstSchema, validateField, withValidation, withQueryValidation, withParamsValidation, serializeDate, deserializeDate, serializeMap, deserializeMap, serializeSet, deserializeSet, withSerialization, serializeForJSON, withAuth, withRole, hashPassword, verifyPassword, generateToken, withInputValidation };
11
+ export default {
12
+ createObjectRouter,
13
+ ApiError,
14
+ ValidationError,
15
+ AuthenticationError,
16
+ AuthorizationError,
17
+ NotFoundError,
18
+ ConflictError,
19
+ withErrorHandling,
20
+ createErrorHandler,
21
+ validateAgainstSchema,
22
+ validateField,
23
+ withValidation,
24
+ withQueryValidation,
25
+ withParamsValidation,
26
+ serializeDate,
27
+ deserializeDate,
28
+ serializeMap,
29
+ deserializeMap,
30
+ serializeSet,
31
+ deserializeSet,
32
+ withSerialization,
33
+ serializeForJSON,
34
+ withAuth,
35
+ withRole,
36
+ hashPassword,
37
+ verifyPassword,
38
+ generateToken,
39
+ withInputValidation
40
+ };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/index.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtK,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAClI,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACrK,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,aAAa,EACb,mBAAmB,EACpB,CAAC;AAEF,eAAe;IACb,kBAAkB;IAClB,QAAQ;IACR,eAAe;IACf,mBAAmB;IACnB,kBAAkB;IAClB,aAAa;IACb,aAAa;IACb,iBAAiB;IACjB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;IACb,cAAc;IACd,mBAAmB;IACnB,oBAAoB;IACpB,aAAa;IACb,eAAe;IACf,YAAY;IACZ,cAAc;IACd,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,cAAc;IACd,aAAa;IACb,mBAAmB;CACpB,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Middleware system for Coherent.js API framework
3
+ * @fileoverview Common middleware utilities for API routes
4
+ */
5
+ /**
6
+ * Creates a custom API middleware with error handling
7
+ * @param {Function} handler - Middleware handler function
8
+ * @returns {Function} Middleware function that catches errors
9
+ */
10
+ export function createApiMiddleware(handler: Function): Function;
11
+ /**
12
+ * Authentication middleware
13
+ * @param {Function} verifyToken - Function to verify authentication token
14
+ * @returns {Function} Middleware function
15
+ */
16
+ export function withAuth(verifyToken: Function): Function;
17
+ /**
18
+ * Authorization middleware
19
+ * @param {Function} checkPermission - Function to check user permissions
20
+ * @returns {Function} Middleware function
21
+ */
22
+ export function withPermission(checkPermission: Function): Function;
23
+ /**
24
+ * Logging middleware
25
+ * @param {Object} options - Logging options
26
+ * @returns {Function} Middleware function
27
+ */
28
+ export function withLogging(options?: Object): Function;
29
+ /**
30
+ * CORS middleware
31
+ * @param {Object} options - CORS options
32
+ * @returns {Function} Middleware function
33
+ */
34
+ export function withCors(options?: Object): Function;
35
+ /**
36
+ * Rate limiting middleware
37
+ * @param {Object} options - Rate limiting options
38
+ * @returns {Function} Middleware function
39
+ */
40
+ export function withRateLimit(options?: Object): Function;
41
+ /**
42
+ * Input sanitization middleware
43
+ * @param {Object} options - Sanitization options
44
+ * @returns {Function} Middleware function
45
+ */
46
+ export function withSanitization(options?: Object): Function;
47
+ declare namespace _default {
48
+ export { createApiMiddleware };
49
+ export { withAuth };
50
+ export { withPermission };
51
+ export { withLogging };
52
+ export { withCors };
53
+ export { withRateLimit };
54
+ export { withSanitization };
55
+ }
56
+ export default _default;
57
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../src/api/middleware.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,iEASC;AAED;;;;GAIG;AACH,0DAwBC;AAED;;;;GAIG;AACH,oEA2BC;AAED;;;;GAIG;AACH,sCAHW,MAAM,YAsBhB;AAED;;;;GAIG;AACH,mCAHW,MAAM,YAiChB;AAED;;;;GAIG;AACH,wCAHW,MAAM,YAgEhB;AAED;;;;GAIG;AACH,2CAHW,MAAM,YAyBhB"}