@medyll/idae-api 0.180.0 → 0.187.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.
@@ -0,0 +1 @@
1
+ Suppression des adapters custom: multiAdapters.ts, registerAdapters.ts
@@ -1,18 +1,18 @@
1
- // packages\idae-api\src\lib\idae-api.d.ts
2
-
3
- import mongoose from "mongoose";
4
- import { IdaeDb, IdaeDbAdapter } from "@medyll/idae-db";
5
-
6
- declare global {
7
- namespace Express {
8
- interface Request {
9
- dbConnection?: mongoose.Connection;
10
- collectionName?: string;
11
- dbName?: string;
12
- idaeDb?: IdaeDb;
13
- connectedCollection: IdaeDbAdapter;
14
- }
15
- }
16
- }
17
-
18
- export {};
1
+ // packages\idae-api\src\lib\idae-api.d.ts
2
+
3
+ import mongoose from "mongoose";
4
+ import { IdaeDb, IdaeDbAdapter } from "@medyll/idae-db";
5
+
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ dbConnection?: mongoose.Connection;
10
+ collectionName?: string;
11
+ dbName?: string;
12
+ idaeDb?: IdaeDb;
13
+ connectedCollection: IdaeDbAdapter;
14
+ }
15
+ }
16
+ }
17
+
18
+ export {};
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export * from './client/IdaeApiClientConfig.js';
5
5
  export * from './client/IdaeApiClientCollection.js';
6
6
  export * from './client/IdaeApiClient.js';
7
7
  export * from './@types/types.js';
8
+ export * from './__tests__/helpers/testUtils.js';
9
+ export * from './__tests__/fixtures/mockData.js';
8
10
  export * from './server/services/AuthService.js';
9
11
  export * from './server/middleware/validationMiddleware.js';
10
12
  export * from './server/middleware/validationLayer.js';
@@ -20,5 +22,3 @@ export * from './server/engine/types.js';
20
22
  export * from './server/engine/routeManager.js';
21
23
  export * from './server/engine/requestDatabaseManager.js';
22
24
  export * from './server/engine/mongooseConnectionManager.js';
23
- export * from './__tests__/helpers/testUtils.js';
24
- export * from './__tests__/fixtures/mockData.js';
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ export * from './client/IdaeApiClientConfig.js';
6
6
  export * from './client/IdaeApiClientCollection.js';
7
7
  export * from './client/IdaeApiClient.js';
8
8
  export * from './@types/types.js';
9
+ export * from './__tests__/helpers/testUtils.js';
10
+ export * from './__tests__/fixtures/mockData.js';
9
11
  export * from './server/services/AuthService.js';
10
12
  export * from './server/middleware/validationMiddleware.js';
11
13
  export * from './server/middleware/validationLayer.js';
@@ -21,5 +23,3 @@ export * from './server/engine/types.js';
21
23
  export * from './server/engine/routeManager.js';
22
24
  export * from './server/engine/requestDatabaseManager.js';
23
25
  export * from './server/engine/mongooseConnectionManager.js';
24
- export * from './__tests__/helpers/testUtils.js';
25
- export * from './__tests__/fixtures/mockData.js';
@@ -1,12 +1,12 @@
1
- <!-- Minimal Redoc HTML, loads /openapi.json -->
2
- <!DOCTYPE html>
3
- <html lang="en">
4
- <head>
5
- <meta charset="UTF-8">
6
- <title>Redoc</title>
7
- <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
8
- </head>
9
- <body>
10
- <redoc spec-url="/openapi.json"></redoc>
11
- </body>
12
- </html>
1
+ <!-- Minimal Redoc HTML, loads /openapi.json -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>Redoc</title>
7
+ <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
8
+ </head>
9
+ <body>
10
+ <redoc spec-url="/openapi.json"></redoc>
11
+ </body>
12
+ </html>
@@ -1,23 +1,23 @@
1
- <!-- Minimal Swagger UI HTML, loads /openapi.json -->
2
- <!DOCTYPE html>
3
- <html lang="en">
4
- <head>
5
- <meta charset="UTF-8">
6
- <title>Swagger UI</title>
7
- <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
8
- </head>
9
- <body>
10
- <div id="swagger-ui"></div>
11
- <script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
12
- <script>
13
- window.onload = function() {
14
- window.ui = SwaggerUIBundle({
15
- url: '/openapi.json',
16
- dom_id: '#swagger-ui',
17
- presets: [SwaggerUIBundle.presets.apis],
18
- layout: "BaseLayout"
19
- });
20
- };
21
- </script>
22
- </body>
23
- </html>
1
+ <!-- Minimal Swagger UI HTML, loads /openapi.json -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>Swagger UI</title>
7
+ <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
8
+ </head>
9
+ <body>
10
+ <div id="swagger-ui"></div>
11
+ <script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
12
+ <script>
13
+ window.onload = function() {
14
+ window.ui = SwaggerUIBundle({
15
+ url: '/openapi.json',
16
+ dom_id: '#swagger-ui',
17
+ presets: [SwaggerUIBundle.presets.apis],
18
+ layout: "BaseLayout"
19
+ });
20
+ };
21
+ </script>
22
+ </body>
23
+ </html>
@@ -1,46 +1,46 @@
1
- # Middleware Documentation
2
-
3
- This document describes all middleware available in the `@medyll/idae-api` package, their purpose, usage, and integration order.
4
-
5
- ## Overview
6
-
7
- Middleware in this project is located in `src/lib/server/middleware/`. Each middleware serves a specific purpose (validation, authentication, multi-tenancy, docs, health, etc.) and is applied in a specific order in the Express app lifecycle.
8
-
9
- ## List of Middleware
10
-
11
- - **authMiddleware**: Handles JWT authentication and attaches user context to requests.
12
- - **authorizationMiddleware**: Enforces RBAC/ABAC policies per route.
13
- - **databaseMiddleware**: Injects `req.idaeDb` and manages per-request DB/collection context.
14
- - **tenantContextMiddleware**: Extracts tenant context from JWT/user and enforces multi-tenancy.
15
- - **validationMiddleware**: Validates request bodies/queries using Zod schemas.
16
- - **validationLayer**: (Advanced) Layered validation, supports Zod and future OpenAPI/ajv.
17
- - **docsMiddleware**: Serves Swagger UI and Redoc API docs.
18
- - **openApiMiddleware**: Serves OpenAPI JSON spec.
19
- - **healthMiddleware**: Provides health and readiness endpoints.
20
- - **mcpMiddleware**: Placeholder for MCP-specific logic (future extension).
21
-
22
- ## Middleware Application Order
23
-
24
- The recommended order (see `IdaeApi.ts`):
25
- 1. Express body/URL parsers
26
- 2. `authMiddleware` (if enabled)
27
- 3. `tenantContextMiddleware` (if multi-tenancy enabled)
28
- 4. `databaseMiddleware`
29
- 5. `validationMiddleware`/`validationLayer`
30
- 6. Custom routes
31
- 7. `docsMiddleware`, `openApiMiddleware`, `healthMiddleware`
32
- 8. Error handler
33
-
34
- ## Usage Example
35
-
36
- ```
37
- import { authMiddleware, tenantContextMiddleware, databaseMiddleware } from './middleware';
38
- app.use(authMiddleware(...));
39
- app.use(tenantContextMiddleware(...));
40
- app.use(databaseMiddleware);
41
- ```
42
-
43
- ## Notes
44
- - Always apply `authMiddleware` before `databaseMiddleware` if using per-user DB context.
45
- - `tenantContextMiddleware` is required for strict multi-tenancy.
46
- - See each middleware file for detailed JSDoc and options.
1
+ # Middleware Documentation
2
+
3
+ This document describes all middleware available in the `@medyll/idae-api` package, their purpose, usage, and integration order.
4
+
5
+ ## Overview
6
+
7
+ Middleware in this project is located in `src/lib/server/middleware/`. Each middleware serves a specific purpose (validation, authentication, multi-tenancy, docs, health, etc.) and is applied in a specific order in the Express app lifecycle.
8
+
9
+ ## List of Middleware
10
+
11
+ - **authMiddleware**: Handles JWT authentication and attaches user context to requests.
12
+ - **authorizationMiddleware**: Enforces RBAC/ABAC policies per route.
13
+ - **databaseMiddleware**: Injects `req.idaeDb` and manages per-request DB/collection context.
14
+ - **tenantContextMiddleware**: Extracts tenant context from JWT/user and enforces multi-tenancy.
15
+ - **validationMiddleware**: Validates request bodies/queries using Zod schemas.
16
+ - **validationLayer**: (Advanced) Layered validation, supports Zod and future OpenAPI/ajv.
17
+ - **docsMiddleware**: Serves Swagger UI and Redoc API docs.
18
+ - **openApiMiddleware**: Serves OpenAPI JSON spec.
19
+ - **healthMiddleware**: Provides health and readiness endpoints.
20
+ - **mcpMiddleware**: Placeholder for MCP-specific logic (future extension).
21
+
22
+ ## Middleware Application Order
23
+
24
+ The recommended order (see `IdaeApi.ts`):
25
+ 1. Express body/URL parsers
26
+ 2. `authMiddleware` (if enabled)
27
+ 3. `tenantContextMiddleware` (if multi-tenancy enabled)
28
+ 4. `databaseMiddleware`
29
+ 5. `validationMiddleware`/`validationLayer`
30
+ 6. Custom routes
31
+ 7. `docsMiddleware`, `openApiMiddleware`, `healthMiddleware`
32
+ 8. Error handler
33
+
34
+ ## Usage Example
35
+
36
+ ```
37
+ import { authMiddleware, tenantContextMiddleware, databaseMiddleware } from './middleware';
38
+ app.use(authMiddleware(...));
39
+ app.use(tenantContextMiddleware(...));
40
+ app.use(databaseMiddleware);
41
+ ```
42
+
43
+ ## Notes
44
+ - Always apply `authMiddleware` before `databaseMiddleware` if using per-user DB context.
45
+ - `tenantContextMiddleware` is required for strict multi-tenancy.
46
+ - See each middleware file for detailed JSDoc and options.
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "@medyll/idae-api",
3
+ "bin": {
4
+ "idae-api": "./cli.js"
5
+ },
3
6
  "scope": "@medyll",
4
- "version": "0.180.0",
7
+ "author": "Lebrun Meddy",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/medyll/idae.git"
11
+ },
12
+ "version": "0.187.2",
5
13
  "main": "./dist/index.js",
6
14
  "module": "./dist/index.js",
7
15
  "description": "A flexible and extensible API framework for Node.js, designed to work with multiple database types and configurations. It features a modular architecture, dynamic database connection management, and a flexible routing system. The framework supports TypeScript for improved robustness and maintainability.",
@@ -23,57 +31,63 @@
23
31
  ]
24
32
  },
25
33
  "dependencies": {
26
- "compression": "^1.7.4",
27
- "cors": "^2.8.5",
28
- "express": "^5.1.0",
29
- "express-rate-limit": "^7.1.5",
30
- "helmet": "^7.2.0",
31
- "jsonwebtoken": "^9.0.2",
32
- "mongoose": "^8.15.1",
34
+ "compression": "^1.8.1",
35
+ "cors": "^2.8.6",
36
+ "express": "^5.2.1",
37
+ "express-rate-limit": "^8.2.1",
38
+ "helmet": "^8.1.0",
39
+ "jsonwebtoken": "^9.0.3",
40
+ "mongoose": "^9.1.5",
33
41
  "mongoose-sequence": "^6.0.1",
34
- "qs": "^6.14.0",
42
+ "pg": "^8.17.2",
43
+ "qs": "^6.14.1",
35
44
  "sequelize": "^6.37.7"
36
45
  },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "directory": "."
49
+ },
37
50
  "devDependencies": {
38
- "@sveltejs/adapter-auto": "^6.0.1",
39
- "@sveltejs/kit": "^2.21.2",
40
- "@sveltejs/package": "^2.3.11",
41
- "@sveltejs/vite-plugin-svelte": "^5.1.0",
42
- "@types/compression": "^1.7.5",
43
- "@types/cors": "^2.8.17",
51
+ "@semantic-release/github": "^12.0.2",
52
+ "@sveltejs/adapter-auto": "^7.0.0",
53
+ "@sveltejs/kit": "^2.50.1",
54
+ "@sveltejs/package": "^2.5.7",
55
+ "@sveltejs/vite-plugin-svelte": "^6.2.4",
56
+ "@types/compression": "^1.8.1",
57
+ "@types/cors": "^2.8.19",
44
58
  "@types/eslint": "^9.6.1",
45
- "@types/express-rate-limit": "^5.1.3",
59
+ "@types/express-rate-limit": "^6.0.2",
46
60
  "@types/helmet": "^4.0.0",
47
- "@types/jest": "^29.5.14",
48
- "@types/jsonwebtoken": "^9.0.9",
61
+ "@types/jest": "^30.0.0",
62
+ "@types/jsonwebtoken": "^9.0.10",
49
63
  "@types/mongoose": "^5.11.97",
50
64
  "@types/mongoose-sequence": "^3.0.11",
51
65
  "@types/sinon": "^21.0.0",
52
66
  "@types/supertest": "^6.0.3",
53
- "eslint": "^9.28.0",
54
- "eslint-config-prettier": "^10.1.5",
55
- "eslint-plugin-svelte": "^3.9.1",
56
- "globals": "^16.2.0",
57
- "jest": "^29.7.0",
58
- "mongodb-memory-server": "^10.1.4",
59
- "mysql2": "^3.14.1",
67
+ "eslint": "^9.39.2",
68
+ "eslint-config-prettier": "^10.1.8",
69
+ "eslint-plugin-svelte": "^3.14.0",
70
+ "globals": "^17.2.0",
71
+ "jest": "^30.2.0",
72
+ "mongodb-memory-server": "^11.0.1",
73
+ "mysql2": "^3.16.2",
60
74
  "node-mocks-http": "^1.17.2",
61
- "prettier": "^3.5.3",
62
- "prettier-plugin-svelte": "^3.4.0",
75
+ "prettier": "^3.8.1",
76
+ "prettier-plugin-svelte": "^3.4.1",
63
77
  "sinon": "^21.0.1",
64
- "supertest": "^7.1.1",
65
- "svelte": "^5.33.14",
66
- "svelte-check": "^4.2.1",
78
+ "supertest": "^7.2.2",
79
+ "svelte": "^5.48.5",
80
+ "svelte-check": "^4.3.5",
67
81
  "tslib": "^2.8.1",
68
- "tsx": "^4.19.4",
82
+ "tsx": "^4.21.0",
69
83
  "typedoc": "^0.28.16",
70
- "typescript": "^5.8.3",
71
- "typescript-eslint": "^8.33.1",
72
- "vite": "^6.3.5",
73
- "vitest": "^3.2.1",
74
- "zod": "^3.22.4",
75
- "@medyll/idae-db": "0.148.0",
76
- "@medyll/idae-prettier-config": "1.2.1"
84
+ "typescript": "^5.9.3",
85
+ "typescript-eslint": "^8.54.0",
86
+ "vite": "^7.3.1",
87
+ "vitest": "^4.0.18",
88
+ "zod": "^4.3.6",
89
+ "@medyll/idae-db": "0.155.2",
90
+ "@medyll/idae-eslint-config": "0.1.5"
77
91
  },
78
92
  "svelte": "./dist/index.js",
79
93
  "types": "./dist/index.d.ts",
@@ -89,7 +103,7 @@
89
103
  "test": "vitest",
90
104
  "lint": "prettier --check . && eslint .",
91
105
  "format": "prettier --write .",
92
- "package:pre": "node scripts/package-pre.js",
106
+ "prepackage": "node scripts/package-pre.js",
93
107
  "doc": "typedoc --entryPointStrategy expand src/lib/server/middleware src/lib/server/engine src/lib/client"
94
108
  }
95
109
  }
@@ -1,153 +0,0 @@
1
- /**
2
- * Test Utilities & Helpers
3
- * Common patterns and utilities for consistent testing
4
- */
5
- /**
6
- * Generate a mock JWT token for testing
7
- */
8
- export declare function generateMockToken(payload?: any, secret?: string, expiresIn?: string): never;
9
- /**
10
- * Create a mock Express Request object
11
- */
12
- export declare function createMockRequest(overrides?: any): any;
13
- /**
14
- * Create a mock Express Response object
15
- */
16
- export declare function createMockResponse(): {
17
- status: (code: number) => {
18
- json: (data: any) => {};
19
- send: (data: any) => {};
20
- };
21
- json: (data: any) => {};
22
- send: (data: any) => {};
23
- setHeader: (key: string, value: string) => {};
24
- getHeader: (key: string) => string | undefined;
25
- getStatusCode: () => number;
26
- getResponseData: () => any;
27
- statusCode: number;
28
- responseData: any;
29
- headers: Map<string, string>;
30
- };
31
- /**
32
- * Create a mock NextFunction
33
- */
34
- export declare function createMockNextFunction(): import("vitest/index.cjs").Mock<(err?: any) => void>;
35
- /**
36
- * Create a complete mock middleware context
37
- */
38
- export declare function createMockMiddlewareContext(overrides?: any): {
39
- req: any;
40
- res: {
41
- status: (code: number) => {
42
- json: (data: any) => {};
43
- send: (data: any) => {};
44
- };
45
- json: (data: any) => {};
46
- send: (data: any) => {};
47
- setHeader: (key: string, value: string) => {};
48
- getHeader: (key: string) => string | undefined;
49
- getStatusCode: () => number;
50
- getResponseData: () => any;
51
- statusCode: number;
52
- responseData: any;
53
- headers: Map<string, string>;
54
- };
55
- next: import("vitest/index.cjs").Mock<(err?: any) => void>;
56
- };
57
- /**
58
- * Wait for async operations to complete
59
- */
60
- export declare function waitFor(condition: () => boolean, timeout?: number): Promise<void>;
61
- /**
62
- * Create a mock IdaeDb collection adapter
63
- */
64
- export declare function createMockCollection(defaultData?: any[]): {
65
- find: import("vitest/index.cjs").Mock<(filter?: any) => Promise<any[]>>;
66
- findById: import("vitest/index.cjs").Mock<(id: string) => Promise<any>>;
67
- findAll: import("vitest/index.cjs").Mock<() => Promise<any[]>>;
68
- create: import("vitest/index.cjs").Mock<(data: any) => Promise<any>>;
69
- update: import("vitest/index.cjs").Mock<(id: string, data: any) => Promise<any>>;
70
- deleteById: import("vitest/index.cjs").Mock<(id: string) => Promise<void>>;
71
- deleteWhere: import("vitest/index.cjs").Mock<(filter: any) => Promise<number>>;
72
- };
73
- /**
74
- * Create a mock IdaeDb database adapter
75
- */
76
- export declare function createMockIdaeDb(collections?: Record<string, any>): {
77
- init: import("vitest/index.cjs").Mock<(uri: string, options: any) => Promise<{
78
- db: import("vitest/index.cjs").Mock<(dbName: string) => Promise<{
79
- collection: import("vitest/index.cjs").Mock<(collectionName: string) => any>;
80
- }>>;
81
- }>>;
82
- collection: import("vitest/index.cjs").Mock<(collectionName: string) => any>;
83
- };
84
- /**
85
- * Create a mock HTTP fetch response
86
- */
87
- export declare function createMockFetchResponse(data?: any, options?: any): Promise<{
88
- ok: boolean;
89
- status: any;
90
- headers: Map<unknown, unknown>;
91
- json: () => Promise<any>;
92
- text: () => Promise<string>;
93
- blob: () => Promise<Blob>;
94
- clone: () => Promise</*elided*/ any>;
95
- }>;
96
- /**
97
- * Assert that a middleware was called with specific arguments
98
- */
99
- export declare function assertMiddlewareCalled(middleware: any, argIndex: number, expected: any): void;
100
- /**
101
- * Mock an external module
102
- */
103
- export declare function mockModule(moduleName: string, implementation: any): void;
104
- /**
105
- * Restore all mocks
106
- */
107
- export declare function resetAllMocks(): void;
108
- /**
109
- * Create a test database URI
110
- */
111
- export declare function createTestDatabaseUri(dbType?: string, dbName?: string): string;
112
- /**
113
- * Extract bearer token from Authorization header
114
- */
115
- export declare function extractBearerToken(authHeader?: string): string | null;
116
- /**
117
- * Validate token format
118
- */
119
- export declare function isValidTokenFormat(token: string): boolean;
120
- /**
121
- * Create assertion helpers for common patterns
122
- */
123
- export declare const testAssertions: {
124
- /**
125
- * Assert middleware sets status code
126
- */
127
- statusCode: (res: any, expectedCode: number) => void;
128
- /**
129
- * Assert middleware sets Authorization header
130
- */
131
- hasAuthHeader: (req: any) => void;
132
- /**
133
- * Assert response has error
134
- */
135
- hasError: (res: any) => void;
136
- /**
137
- * Assert response has success data
138
- */
139
- hasData: (res: any) => void;
140
- };
141
- /**
142
- * Performance testing helper
143
- */
144
- export declare function measurePerformance(fn: () => Promise<any>, iterations?: number): Promise<{
145
- average: number;
146
- min: number;
147
- max: number;
148
- times: number[];
149
- }>;
150
- /**
151
- * Test data sanitizer - remove sensitive info before assertions
152
- */
153
- export declare function sanitizeForAssertion(data: any, keysToRemove?: string[]): any;