digitaltwin-core 0.13.3 → 0.14.1

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 (169) hide show
  1. package/package.json +101 -106
  2. package/dist/auth/apisix_parser.d.ts +0 -146
  3. package/dist/auth/apisix_parser.d.ts.map +0 -1
  4. package/dist/auth/apisix_parser.js +0 -185
  5. package/dist/auth/apisix_parser.js.map +0 -1
  6. package/dist/auth/auth_config.d.ts +0 -126
  7. package/dist/auth/auth_config.d.ts.map +0 -1
  8. package/dist/auth/auth_config.js +0 -169
  9. package/dist/auth/auth_config.js.map +0 -1
  10. package/dist/auth/index.d.ts +0 -5
  11. package/dist/auth/index.d.ts.map +0 -1
  12. package/dist/auth/index.js +0 -4
  13. package/dist/auth/index.js.map +0 -1
  14. package/dist/auth/types.d.ts +0 -100
  15. package/dist/auth/types.d.ts.map +0 -1
  16. package/dist/auth/types.js +0 -2
  17. package/dist/auth/types.js.map +0 -1
  18. package/dist/auth/user_service.d.ts +0 -86
  19. package/dist/auth/user_service.d.ts.map +0 -1
  20. package/dist/auth/user_service.js +0 -237
  21. package/dist/auth/user_service.js.map +0 -1
  22. package/dist/components/assets_manager.d.ts +0 -662
  23. package/dist/components/assets_manager.d.ts.map +0 -1
  24. package/dist/components/assets_manager.js +0 -1529
  25. package/dist/components/assets_manager.js.map +0 -1
  26. package/dist/components/async_upload.d.ts +0 -20
  27. package/dist/components/async_upload.d.ts.map +0 -1
  28. package/dist/components/async_upload.js +0 -10
  29. package/dist/components/async_upload.js.map +0 -1
  30. package/dist/components/collector.d.ts +0 -203
  31. package/dist/components/collector.d.ts.map +0 -1
  32. package/dist/components/collector.js +0 -202
  33. package/dist/components/collector.js.map +0 -1
  34. package/dist/components/custom_table_manager.d.ts +0 -503
  35. package/dist/components/custom_table_manager.d.ts.map +0 -1
  36. package/dist/components/custom_table_manager.js +0 -1052
  37. package/dist/components/custom_table_manager.js.map +0 -1
  38. package/dist/components/global_assets_handler.d.ts +0 -63
  39. package/dist/components/global_assets_handler.d.ts.map +0 -1
  40. package/dist/components/global_assets_handler.js +0 -127
  41. package/dist/components/global_assets_handler.js.map +0 -1
  42. package/dist/components/handler.d.ts +0 -104
  43. package/dist/components/handler.d.ts.map +0 -1
  44. package/dist/components/handler.js +0 -110
  45. package/dist/components/handler.js.map +0 -1
  46. package/dist/components/harvester.d.ts +0 -182
  47. package/dist/components/harvester.d.ts.map +0 -1
  48. package/dist/components/harvester.js +0 -393
  49. package/dist/components/harvester.js.map +0 -1
  50. package/dist/components/index.d.ts +0 -11
  51. package/dist/components/index.d.ts.map +0 -1
  52. package/dist/components/index.js +0 -9
  53. package/dist/components/index.js.map +0 -1
  54. package/dist/components/interfaces.d.ts +0 -126
  55. package/dist/components/interfaces.d.ts.map +0 -1
  56. package/dist/components/interfaces.js +0 -8
  57. package/dist/components/interfaces.js.map +0 -1
  58. package/dist/components/map_manager.d.ts +0 -61
  59. package/dist/components/map_manager.d.ts.map +0 -1
  60. package/dist/components/map_manager.js +0 -242
  61. package/dist/components/map_manager.js.map +0 -1
  62. package/dist/components/tileset_manager.d.ts +0 -125
  63. package/dist/components/tileset_manager.d.ts.map +0 -1
  64. package/dist/components/tileset_manager.js +0 -618
  65. package/dist/components/tileset_manager.js.map +0 -1
  66. package/dist/components/types.d.ts +0 -226
  67. package/dist/components/types.d.ts.map +0 -1
  68. package/dist/components/types.js +0 -8
  69. package/dist/components/types.js.map +0 -1
  70. package/dist/database/adapters/knex_database_adapter.d.ts +0 -92
  71. package/dist/database/adapters/knex_database_adapter.d.ts.map +0 -1
  72. package/dist/database/adapters/knex_database_adapter.js +0 -647
  73. package/dist/database/adapters/knex_database_adapter.js.map +0 -1
  74. package/dist/database/database_adapter.d.ts +0 -251
  75. package/dist/database/database_adapter.d.ts.map +0 -1
  76. package/dist/database/database_adapter.js +0 -46
  77. package/dist/database/database_adapter.js.map +0 -1
  78. package/dist/engine/digital_twin_engine.d.ts +0 -253
  79. package/dist/engine/digital_twin_engine.d.ts.map +0 -1
  80. package/dist/engine/digital_twin_engine.js +0 -790
  81. package/dist/engine/digital_twin_engine.js.map +0 -1
  82. package/dist/engine/endpoints.d.ts +0 -47
  83. package/dist/engine/endpoints.d.ts.map +0 -1
  84. package/dist/engine/endpoints.js +0 -56
  85. package/dist/engine/endpoints.js.map +0 -1
  86. package/dist/engine/events.d.ts +0 -93
  87. package/dist/engine/events.d.ts.map +0 -1
  88. package/dist/engine/events.js +0 -71
  89. package/dist/engine/events.js.map +0 -1
  90. package/dist/engine/initializer.d.ts +0 -62
  91. package/dist/engine/initializer.d.ts.map +0 -1
  92. package/dist/engine/initializer.js +0 -108
  93. package/dist/engine/initializer.js.map +0 -1
  94. package/dist/engine/queue_manager.d.ts +0 -87
  95. package/dist/engine/queue_manager.d.ts.map +0 -1
  96. package/dist/engine/queue_manager.js +0 -196
  97. package/dist/engine/queue_manager.js.map +0 -1
  98. package/dist/engine/scheduler.d.ts +0 -30
  99. package/dist/engine/scheduler.d.ts.map +0 -1
  100. package/dist/engine/scheduler.js +0 -370
  101. package/dist/engine/scheduler.js.map +0 -1
  102. package/dist/engine/upload_processor.d.ts +0 -36
  103. package/dist/engine/upload_processor.d.ts.map +0 -1
  104. package/dist/engine/upload_processor.js +0 -101
  105. package/dist/engine/upload_processor.js.map +0 -1
  106. package/dist/env/env.d.ts +0 -134
  107. package/dist/env/env.d.ts.map +0 -1
  108. package/dist/env/env.js +0 -177
  109. package/dist/env/env.js.map +0 -1
  110. package/dist/index.d.ts +0 -49
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/index.js +0 -57
  113. package/dist/index.js.map +0 -1
  114. package/dist/openapi/generator.d.ts +0 -93
  115. package/dist/openapi/generator.d.ts.map +0 -1
  116. package/dist/openapi/generator.js +0 -293
  117. package/dist/openapi/generator.js.map +0 -1
  118. package/dist/openapi/index.d.ts +0 -9
  119. package/dist/openapi/index.d.ts.map +0 -1
  120. package/dist/openapi/index.js +0 -9
  121. package/dist/openapi/index.js.map +0 -1
  122. package/dist/openapi/types.d.ts +0 -182
  123. package/dist/openapi/types.d.ts.map +0 -1
  124. package/dist/openapi/types.js +0 -16
  125. package/dist/openapi/types.js.map +0 -1
  126. package/dist/storage/adapters/local_storage_service.d.ts +0 -51
  127. package/dist/storage/adapters/local_storage_service.d.ts.map +0 -1
  128. package/dist/storage/adapters/local_storage_service.js +0 -110
  129. package/dist/storage/adapters/local_storage_service.js.map +0 -1
  130. package/dist/storage/adapters/ovh_storage_service.d.ts +0 -61
  131. package/dist/storage/adapters/ovh_storage_service.d.ts.map +0 -1
  132. package/dist/storage/adapters/ovh_storage_service.js +0 -172
  133. package/dist/storage/adapters/ovh_storage_service.js.map +0 -1
  134. package/dist/storage/storage_factory.d.ts +0 -14
  135. package/dist/storage/storage_factory.d.ts.map +0 -1
  136. package/dist/storage/storage_factory.js +0 -36
  137. package/dist/storage/storage_factory.js.map +0 -1
  138. package/dist/storage/storage_service.d.ts +0 -163
  139. package/dist/storage/storage_service.d.ts.map +0 -1
  140. package/dist/storage/storage_service.js +0 -54
  141. package/dist/storage/storage_service.js.map +0 -1
  142. package/dist/types/data_record.d.ts +0 -123
  143. package/dist/types/data_record.d.ts.map +0 -1
  144. package/dist/types/data_record.js +0 -8
  145. package/dist/types/data_record.js.map +0 -1
  146. package/dist/utils/http_responses.d.ts +0 -155
  147. package/dist/utils/http_responses.d.ts.map +0 -1
  148. package/dist/utils/http_responses.js +0 -190
  149. package/dist/utils/http_responses.js.map +0 -1
  150. package/dist/utils/index.d.ts +0 -8
  151. package/dist/utils/index.d.ts.map +0 -1
  152. package/dist/utils/index.js +0 -6
  153. package/dist/utils/index.js.map +0 -1
  154. package/dist/utils/logger.d.ts +0 -74
  155. package/dist/utils/logger.d.ts.map +0 -1
  156. package/dist/utils/logger.js +0 -92
  157. package/dist/utils/logger.js.map +0 -1
  158. package/dist/utils/map_to_data_record.d.ts +0 -10
  159. package/dist/utils/map_to_data_record.d.ts.map +0 -1
  160. package/dist/utils/map_to_data_record.js +0 -36
  161. package/dist/utils/map_to_data_record.js.map +0 -1
  162. package/dist/utils/servable_endpoint.d.ts +0 -63
  163. package/dist/utils/servable_endpoint.d.ts.map +0 -1
  164. package/dist/utils/servable_endpoint.js +0 -67
  165. package/dist/utils/servable_endpoint.js.map +0 -1
  166. package/dist/utils/zip_utils.d.ts +0 -66
  167. package/dist/utils/zip_utils.d.ts.map +0 -1
  168. package/dist/utils/zip_utils.js +0 -169
  169. package/dist/utils/zip_utils.js.map +0 -1
package/package.json CHANGED
@@ -1,106 +1,101 @@
1
- {
2
- "name": "digitaltwin-core",
3
- "version": "0.13.3",
4
- "description": "Minimalist framework to collect and handle data in a Digital Twin project",
5
- "license": "MIT",
6
- "author": "Axel Hoffmann",
7
- "type": "module",
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- }
15
- },
16
- "files": [
17
- "dist/",
18
- "README.md",
19
- "LICENSE"
20
- ],
21
- "scripts": {
22
- "build": "tsc",
23
- "dev": "tsc --watch",
24
- "clean": "rimraf dist",
25
- "test": "node -r ./bin/set-test-env.cjs --import ts-node-maintained/register/esm --enable-source-maps bin/test.ts",
26
- "lint": "eslint src/**/*.ts",
27
- "lint:fix": "eslint src/**/*.ts --fix",
28
- "format": "prettier --write \"src/**/*.ts\"",
29
- "format:check": "prettier --check \"src/**/*.ts\"",
30
- "check": "npm run lint && npm run format:check && npm run build",
31
- "prepublishOnly": "npm run clean && npm run check && npm run build",
32
- "prepack": "npm run build"
33
- },
34
- "keywords": [
35
- "digital twin",
36
- "data",
37
- "framework",
38
- "typescript",
39
- "iot",
40
- "real-time"
41
- ],
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/CePseudoBE/digital-twin-core"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/CePseudoBE/digital-twin-core/issues"
48
- },
49
- "homepage": "https://github.com/CePseudoBE/digital-twin-core#readme",
50
- "engines": {
51
- "node": ">=18.0.0"
52
- },
53
- "devDependencies": {
54
- "@eslint/js": "^9.0.0",
55
- "@japa/assert": "^4.1.0",
56
- "@japa/runner": "^4.3.0",
57
- "@testcontainers/redis": "^11.3.1",
58
- "@types/cors": "^2.8.19",
59
- "@types/ioredis-mock": "^8.2.6",
60
- "@types/jszip": "^3.4.0",
61
- "@types/lodash": "^4.17.20",
62
- "@types/node": "^24.0.15",
63
- "eslint": "^9.0.0",
64
- "globals": "^15.0.0",
65
- "prettier": "^3.0.0",
66
- "rimraf": "^6.0.1",
67
- "testcontainers": "^11.3.1",
68
- "ts-node-maintained": "^10.9.5",
69
- "typescript": "^5.8.0",
70
- "typescript-eslint": "^8.0.0"
71
- },
72
- "peerDependencies": {
73
- "better-sqlite3": "^12.2.0",
74
- "knex": "^3.0.0",
75
- "mysql2": "*",
76
- "pg": "*",
77
- "sqlite3": "^5.1.7"
78
- },
79
- "peerDependenciesMeta": {
80
- "pg": {
81
- "optional": true
82
- },
83
- "mysql2": {
84
- "optional": true
85
- },
86
- "sqlite3": {
87
- "optional": true
88
- },
89
- "better-sqlite3": {
90
- "optional": true
91
- }
92
- },
93
- "dependencies": {
94
- "@aws-sdk/client-s3": "^3.850.0",
95
- "@types/multer": "^2.0.0",
96
- "@types/uuid": "^10.0.0",
97
- "bullmq": "^5.56.5",
98
- "cors": "^2.8.5",
99
- "ioredis": "^5.6.1",
100
- "jszip": "^3.10.1",
101
- "lodash": "^4.17.21",
102
- "multer": "^2.0.2",
103
- "ultimate-express": "^2.0.9",
104
- "uuid": "^11.1.0"
105
- }
106
- }
1
+ {
2
+ "name": "digitaltwin-core",
3
+ "version": "0.14.1",
4
+ "description": "Minimalist framework to collect and handle data in a Digital Twin project",
5
+ "license": "MIT",
6
+ "author": "Axel Hoffmann",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "keywords": [
22
+ "digital twin",
23
+ "data",
24
+ "framework",
25
+ "typescript",
26
+ "iot",
27
+ "real-time"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/CePseudoBE/digital-twin-core"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/CePseudoBE/digital-twin-core/issues"
35
+ },
36
+ "homepage": "https://github.com/CePseudoBE/digital-twin-core#readme",
37
+ "engines": {
38
+ "node": ">=20.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint/js": "^9.0.0",
42
+ "@japa/assert": "^4.1.0",
43
+ "@japa/runner": "^4.3.0",
44
+ "@testcontainers/redis": "^11.3.1",
45
+ "@types/cors": "^2.8.19",
46
+ "@types/ioredis-mock": "^8.2.6",
47
+ "@types/jszip": "^3.4.0",
48
+ "@types/lodash": "^4.17.20",
49
+ "@types/multer": "^2.0.0",
50
+ "@types/uuid": "^10.0.0",
51
+ "eslint": "^9.0.0",
52
+ "globals": "^15.0.0",
53
+ "prettier": "^3.0.0",
54
+ "testcontainers": "^11.3.1",
55
+ "ts-node-maintained": "^10.9.5",
56
+ "typescript-eslint": "^8.0.0"
57
+ },
58
+ "peerDependencies": {
59
+ "better-sqlite3": "^12.2.0",
60
+ "knex": "^3.0.0",
61
+ "mysql2": "*",
62
+ "pg": "*",
63
+ "sqlite3": "^5.1.7"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "pg": {
67
+ "optional": true
68
+ },
69
+ "mysql2": {
70
+ "optional": true
71
+ },
72
+ "sqlite3": {
73
+ "optional": true
74
+ },
75
+ "better-sqlite3": {
76
+ "optional": true
77
+ }
78
+ },
79
+ "dependencies": {
80
+ "@aws-sdk/client-s3": "^3.850.0",
81
+ "bullmq": "^5.56.5",
82
+ "cors": "^2.8.5",
83
+ "ioredis": "^5.6.1",
84
+ "jszip": "^3.10.1",
85
+ "lodash": "^4.17.21",
86
+ "multer": "^2.0.2",
87
+ "ultimate-express": "^2.0.9",
88
+ "uuid": "^11.1.0"
89
+ },
90
+ "scripts": {
91
+ "build": "tsc",
92
+ "dev": "tsc --watch",
93
+ "clean": "rimraf dist",
94
+ "test": "node -r ./bin/set-test-env.cjs --import ts-node-maintained/register/esm --enable-source-maps bin/test.ts",
95
+ "lint": "eslint src/**/*.ts",
96
+ "lint:fix": "eslint src/**/*.ts --fix",
97
+ "format": "prettier --write \"src/**/*.ts\"",
98
+ "format:check": "prettier --check \"src/**/*.ts\"",
99
+ "check": "npm run lint && npm run format:check && npm run build"
100
+ }
101
+ }
@@ -1,146 +0,0 @@
1
- import type { AuthenticatedUser } from './types.js';
2
- /**
3
- * Parses authentication information from Apache APISIX headers set after Keycloak authentication.
4
- *
5
- * This class handles the parsing of authentication headers forwarded by Apache APISIX
6
- * after successful Keycloak authentication. APISIX acts as a gateway that:
7
- * 1. Validates JWT tokens with Keycloak
8
- * 2. Extracts user information from the token
9
- * 3. Forwards user data as HTTP headers to downstream services
10
- *
11
- * Authentication can be disabled via environment variables for development/testing:
12
- * - Set DIGITALTWIN_DISABLE_AUTH=true to bypass authentication checks
13
- * - Set DIGITALTWIN_ANONYMOUS_USER_ID=custom-id to use a custom anonymous user ID
14
- *
15
- * @example
16
- * ```typescript
17
- * // In an AssetsManager handler
18
- * if (!ApisixAuthParser.hasValidAuth(req.headers)) {
19
- * return { status: 401, content: 'Authentication required' }
20
- * }
21
- *
22
- * const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
23
- * const userRecord = await this.userService.findOrCreateUser(authUser!)
24
- * ```
25
- */
26
- export declare class ApisixAuthParser {
27
- /**
28
- * Extracts user information from APISIX headers.
29
- *
30
- * Parses the authentication headers forwarded by APISIX:
31
- * - `x-user-id`: Keycloak user UUID (required)
32
- * - `x-user-roles`: Comma-separated list of user roles (optional)
33
- *
34
- * When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
35
- * returns a default anonymous user instead of requiring headers.
36
- *
37
- * @param headers - HTTP request headers from APISIX
38
- * @returns Parsed user authentication data, or null if x-user-id is missing and auth is enabled
39
- *
40
- * @example
41
- * ```typescript
42
- * const headers = {
43
- * 'x-user-id': '6e06a527-a89d-4390-95cd-10ae63cfc939',
44
- * 'x-user-roles': 'default-roles-master,offline_access'
45
- * }
46
- *
47
- * const authUser = ApisixAuthParser.parseAuthHeaders(headers)
48
- * // Returns: { id: '6e06a527...', roles: ['default-roles-master', 'offline_access'] }
49
- *
50
- * // With DIGITALTWIN_DISABLE_AUTH=true
51
- * const authUser = ApisixAuthParser.parseAuthHeaders({})
52
- * // Returns: { id: 'anonymous', roles: ['anonymous'] }
53
- * ```
54
- */
55
- static parseAuthHeaders(headers: Record<string, string>): AuthenticatedUser | null;
56
- /**
57
- * Checks if a request has valid authentication headers.
58
- *
59
- * Performs a quick validation to determine if the request contains
60
- * the minimum required authentication information (x-user-id header).
61
- * Use this for early authentication checks before parsing.
62
- *
63
- * When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
64
- * this always returns true to allow all requests through.
65
- *
66
- * @param headers - HTTP request headers
67
- * @returns true if x-user-id header is present or auth is disabled, false otherwise
68
- *
69
- * @example
70
- * ```typescript
71
- * // Early authentication check in handler
72
- * if (!ApisixAuthParser.hasValidAuth(req.headers)) {
73
- * return { status: 401, content: 'Authentication required' }
74
- * }
75
- *
76
- * // Now safe to proceed with parsing
77
- * const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
78
- * ```
79
- */
80
- static hasValidAuth(headers: Record<string, string>): boolean;
81
- /**
82
- * Extracts just the user ID from headers.
83
- *
84
- * Convenience method for cases where you only need the user ID
85
- * without parsing the full authentication context.
86
- *
87
- * When authentication is disabled, returns the configured anonymous user ID.
88
- *
89
- * @param headers - HTTP request headers
90
- * @returns Keycloak user ID, anonymous user ID if auth disabled, or null if not present
91
- *
92
- * @example
93
- * ```typescript
94
- * const userId = ApisixAuthParser.getUserId(req.headers)
95
- * if (userId) {
96
- * console.log(`Request from user: ${userId}`)
97
- * }
98
- * ```
99
- */
100
- static getUserId(headers: Record<string, string>): string | null;
101
- /**
102
- * Extracts just the user roles from headers.
103
- *
104
- * Convenience method for cases where you only need the user roles
105
- * without parsing the full authentication context.
106
- *
107
- * When authentication is disabled, returns the anonymous user roles.
108
- *
109
- * @param headers - HTTP request headers
110
- * @returns Array of role names, anonymous roles if auth disabled, empty array if no roles header present
111
- *
112
- * @example
113
- * ```typescript
114
- * const roles = ApisixAuthParser.getUserRoles(req.headers)
115
- * if (roles.includes('admin')) {
116
- * console.log('User has admin privileges')
117
- * }
118
- * ```
119
- */
120
- static getUserRoles(headers: Record<string, string>): string[];
121
- /**
122
- * Checks if a user has the admin role.
123
- *
124
- * Determines if the authenticated user has administrative privileges by checking
125
- * if their roles include the configured admin role name (default: "admin").
126
- *
127
- * The admin role name can be configured via DIGITALTWIN_ADMIN_ROLE_NAME environment variable.
128
- *
129
- * @param headers - HTTP request headers
130
- * @returns true if user has admin role, false otherwise
131
- *
132
- * @example
133
- * ```typescript
134
- * if (ApisixAuthParser.isAdmin(req.headers)) {
135
- * // User has full administrative access
136
- * // Can view all assets including private assets owned by others
137
- * console.log('Admin user detected')
138
- * }
139
- *
140
- * // With custom admin role name (DIGITALTWIN_ADMIN_ROLE_NAME=administrator)
141
- * const isAdmin = ApisixAuthParser.isAdmin(req.headers)
142
- * ```
143
- */
144
- static isAdmin(headers: Record<string, string>): boolean;
145
- }
146
- //# sourceMappingURL=apisix_parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apisix_parser.d.ts","sourceRoot":"","sources":["../../src/auth/apisix_parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGnD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,iBAAiB,GAAG,IAAI;IAqBlF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO;IAS7D;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI;IAShE;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE;IAU9D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO;CAK3D"}
@@ -1,185 +0,0 @@
1
- import { AuthConfig } from './auth_config.js';
2
- /**
3
- * Parses authentication information from Apache APISIX headers set after Keycloak authentication.
4
- *
5
- * This class handles the parsing of authentication headers forwarded by Apache APISIX
6
- * after successful Keycloak authentication. APISIX acts as a gateway that:
7
- * 1. Validates JWT tokens with Keycloak
8
- * 2. Extracts user information from the token
9
- * 3. Forwards user data as HTTP headers to downstream services
10
- *
11
- * Authentication can be disabled via environment variables for development/testing:
12
- * - Set DIGITALTWIN_DISABLE_AUTH=true to bypass authentication checks
13
- * - Set DIGITALTWIN_ANONYMOUS_USER_ID=custom-id to use a custom anonymous user ID
14
- *
15
- * @example
16
- * ```typescript
17
- * // In an AssetsManager handler
18
- * if (!ApisixAuthParser.hasValidAuth(req.headers)) {
19
- * return { status: 401, content: 'Authentication required' }
20
- * }
21
- *
22
- * const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
23
- * const userRecord = await this.userService.findOrCreateUser(authUser!)
24
- * ```
25
- */
26
- export class ApisixAuthParser {
27
- /**
28
- * Extracts user information from APISIX headers.
29
- *
30
- * Parses the authentication headers forwarded by APISIX:
31
- * - `x-user-id`: Keycloak user UUID (required)
32
- * - `x-user-roles`: Comma-separated list of user roles (optional)
33
- *
34
- * When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
35
- * returns a default anonymous user instead of requiring headers.
36
- *
37
- * @param headers - HTTP request headers from APISIX
38
- * @returns Parsed user authentication data, or null if x-user-id is missing and auth is enabled
39
- *
40
- * @example
41
- * ```typescript
42
- * const headers = {
43
- * 'x-user-id': '6e06a527-a89d-4390-95cd-10ae63cfc939',
44
- * 'x-user-roles': 'default-roles-master,offline_access'
45
- * }
46
- *
47
- * const authUser = ApisixAuthParser.parseAuthHeaders(headers)
48
- * // Returns: { id: '6e06a527...', roles: ['default-roles-master', 'offline_access'] }
49
- *
50
- * // With DIGITALTWIN_DISABLE_AUTH=true
51
- * const authUser = ApisixAuthParser.parseAuthHeaders({})
52
- * // Returns: { id: 'anonymous', roles: ['anonymous'] }
53
- * ```
54
- */
55
- static parseAuthHeaders(headers) {
56
- // If authentication is disabled, return anonymous user
57
- if (AuthConfig.isAuthDisabled()) {
58
- return AuthConfig.getAnonymousUser();
59
- }
60
- const userId = headers['x-user-id'];
61
- if (!userId) {
62
- return null;
63
- }
64
- // Parse roles from comma-separated string
65
- const rolesString = headers['x-user-roles'] || '';
66
- const roles = rolesString ? rolesString.split(',').map(role => role.trim()) : [];
67
- return {
68
- id: userId,
69
- roles: roles
70
- };
71
- }
72
- /**
73
- * Checks if a request has valid authentication headers.
74
- *
75
- * Performs a quick validation to determine if the request contains
76
- * the minimum required authentication information (x-user-id header).
77
- * Use this for early authentication checks before parsing.
78
- *
79
- * When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
80
- * this always returns true to allow all requests through.
81
- *
82
- * @param headers - HTTP request headers
83
- * @returns true if x-user-id header is present or auth is disabled, false otherwise
84
- *
85
- * @example
86
- * ```typescript
87
- * // Early authentication check in handler
88
- * if (!ApisixAuthParser.hasValidAuth(req.headers)) {
89
- * return { status: 401, content: 'Authentication required' }
90
- * }
91
- *
92
- * // Now safe to proceed with parsing
93
- * const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
94
- * ```
95
- */
96
- static hasValidAuth(headers) {
97
- // If authentication is disabled, all requests are valid
98
- if (AuthConfig.isAuthDisabled()) {
99
- return true;
100
- }
101
- return !!headers['x-user-id'];
102
- }
103
- /**
104
- * Extracts just the user ID from headers.
105
- *
106
- * Convenience method for cases where you only need the user ID
107
- * without parsing the full authentication context.
108
- *
109
- * When authentication is disabled, returns the configured anonymous user ID.
110
- *
111
- * @param headers - HTTP request headers
112
- * @returns Keycloak user ID, anonymous user ID if auth disabled, or null if not present
113
- *
114
- * @example
115
- * ```typescript
116
- * const userId = ApisixAuthParser.getUserId(req.headers)
117
- * if (userId) {
118
- * console.log(`Request from user: ${userId}`)
119
- * }
120
- * ```
121
- */
122
- static getUserId(headers) {
123
- // If authentication is disabled, return anonymous user ID
124
- if (AuthConfig.isAuthDisabled()) {
125
- return AuthConfig.getAnonymousUserId();
126
- }
127
- return headers['x-user-id'] || null;
128
- }
129
- /**
130
- * Extracts just the user roles from headers.
131
- *
132
- * Convenience method for cases where you only need the user roles
133
- * without parsing the full authentication context.
134
- *
135
- * When authentication is disabled, returns the anonymous user roles.
136
- *
137
- * @param headers - HTTP request headers
138
- * @returns Array of role names, anonymous roles if auth disabled, empty array if no roles header present
139
- *
140
- * @example
141
- * ```typescript
142
- * const roles = ApisixAuthParser.getUserRoles(req.headers)
143
- * if (roles.includes('admin')) {
144
- * console.log('User has admin privileges')
145
- * }
146
- * ```
147
- */
148
- static getUserRoles(headers) {
149
- // If authentication is disabled, return anonymous user roles
150
- if (AuthConfig.isAuthDisabled()) {
151
- return AuthConfig.getAnonymousUser().roles;
152
- }
153
- const rolesString = headers['x-user-roles'] || '';
154
- return rolesString ? rolesString.split(',').map(role => role.trim()) : [];
155
- }
156
- /**
157
- * Checks if a user has the admin role.
158
- *
159
- * Determines if the authenticated user has administrative privileges by checking
160
- * if their roles include the configured admin role name (default: "admin").
161
- *
162
- * The admin role name can be configured via DIGITALTWIN_ADMIN_ROLE_NAME environment variable.
163
- *
164
- * @param headers - HTTP request headers
165
- * @returns true if user has admin role, false otherwise
166
- *
167
- * @example
168
- * ```typescript
169
- * if (ApisixAuthParser.isAdmin(req.headers)) {
170
- * // User has full administrative access
171
- * // Can view all assets including private assets owned by others
172
- * console.log('Admin user detected')
173
- * }
174
- *
175
- * // With custom admin role name (DIGITALTWIN_ADMIN_ROLE_NAME=administrator)
176
- * const isAdmin = ApisixAuthParser.isAdmin(req.headers)
177
- * ```
178
- */
179
- static isAdmin(headers) {
180
- const roles = this.getUserRoles(headers);
181
- const adminRoleName = AuthConfig.getAdminRoleName();
182
- return roles.includes(adminRoleName);
183
- }
184
- }
185
- //# sourceMappingURL=apisix_parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apisix_parser.js","sourceRoot":"","sources":["../../src/auth/apisix_parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAA+B;QACnD,uDAAuD;QACvD,IAAI,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAC,gBAAgB,EAAE,CAAA;QACxC,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,IAAI,CAAA;QACf,CAAC;QAED,0CAA0C;QAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;QACjD,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAEhF,OAAO;YACH,EAAE,EAAE,MAAM;YACV,KAAK,EAAE,KAAK;SACf,CAAA;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,YAAY,CAAC,OAA+B;QAC/C,wDAAwD;QACxD,IAAI,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACf,CAAC;QAED,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACjC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,SAAS,CAAC,OAA+B;QAC5C,0DAA0D;QAC1D,IAAI,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAC,kBAAkB,EAAE,CAAA;QAC1C,CAAC;QAED,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,IAAI,CAAA;IACvC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,YAAY,CAAC,OAA+B;QAC/C,6DAA6D;QAC7D,IAAI,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAA;QAC9C,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;QACjD,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,OAAO,CAAC,OAA+B;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QACxC,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAA;QACnD,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IACxC,CAAC;CACJ"}
@@ -1,126 +0,0 @@
1
- /**
2
- * Authentication configuration for Digital Twin framework.
3
- *
4
- * Controls whether authentication is required for components that support it.
5
- * When authentication is disabled, all requests are treated as authenticated
6
- * with a default anonymous user.
7
- *
8
- * Environment variables:
9
- * - DIGITALTWIN_DISABLE_AUTH: Set to "true" or "1" to disable authentication (default: false)
10
- * - DIGITALTWIN_ANONYMOUS_USER_ID: User ID to use when auth is disabled (default: "anonymous")
11
- * - DIGITALTWIN_ADMIN_ROLE_NAME: Name of the admin role in Keycloak (default: "admin")
12
- *
13
- * @example
14
- * ```bash
15
- * # Disable authentication for development
16
- * export DIGITALTWIN_DISABLE_AUTH=true
17
- * export DIGITALTWIN_ANONYMOUS_USER_ID=dev-user-123
18
- *
19
- * # Configure admin role name
20
- * export DIGITALTWIN_ADMIN_ROLE_NAME=administrator
21
- *
22
- * # Enable authentication (default)
23
- * export DIGITALTWIN_DISABLE_AUTH=false
24
- * ```
25
- *
26
- * @example
27
- * ```typescript
28
- * import { AuthConfig } from './auth_config.js'
29
- *
30
- * if (AuthConfig.isAuthDisabled()) {
31
- * console.log('Authentication is disabled')
32
- * const anonymousUser = AuthConfig.getAnonymousUser()
33
- * console.log(`Using anonymous user: ${anonymousUser.id}`)
34
- * }
35
- *
36
- * const adminRole = AuthConfig.getAdminRoleName()
37
- * console.log(`Admin role is: ${adminRole}`)
38
- * ```
39
- */
40
- export declare class AuthConfig {
41
- private static _config;
42
- /**
43
- * Loads and validates authentication configuration from environment variables.
44
- * This is called automatically the first time any method is used.
45
- */
46
- private static loadConfig;
47
- /**
48
- * Gets the loaded configuration, ensuring it's initialized.
49
- * @private
50
- */
51
- private static getConfig;
52
- /**
53
- * Checks if authentication is disabled via environment variables.
54
- *
55
- * @returns true if DIGITALTWIN_DISABLE_AUTH is set to "true" or "1", false otherwise
56
- *
57
- * @example
58
- * ```typescript
59
- * if (AuthConfig.isAuthDisabled()) {
60
- * console.log('Running in no-auth mode')
61
- * }
62
- * ```
63
- */
64
- static isAuthDisabled(): boolean;
65
- /**
66
- * Checks if authentication is enabled (opposite of isAuthDisabled).
67
- *
68
- * @returns true if authentication should be enforced, false otherwise
69
- */
70
- static isAuthEnabled(): boolean;
71
- /**
72
- * Gets the anonymous user ID to use when authentication is disabled.
73
- *
74
- * @returns The user ID configured for anonymous access
75
- *
76
- * @example
77
- * ```typescript
78
- * const userId = AuthConfig.getAnonymousUserId()
79
- * console.log(`Anonymous user ID: ${userId}`) // "anonymous" by default
80
- * ```
81
- */
82
- static getAnonymousUserId(): string;
83
- /**
84
- * Gets a fake authenticated user object for anonymous access.
85
- *
86
- * @returns An AuthenticatedUser object representing the anonymous user
87
- *
88
- * @example
89
- * ```typescript
90
- * import type { AuthenticatedUser } from './types.js'
91
- *
92
- * const anonymousUser: AuthenticatedUser = AuthConfig.getAnonymousUser()
93
- * console.log(anonymousUser) // { id: "anonymous", roles: ["anonymous"] }
94
- * ```
95
- */
96
- static getAnonymousUser(): {
97
- id: string;
98
- roles: string[];
99
- };
100
- /**
101
- * Gets the name of the admin role configured for the system.
102
- *
103
- * This role name is used to determine if a user has full administrative
104
- * access to all resources, including private assets owned by other users.
105
- *
106
- * @returns The admin role name (default: "admin")
107
- *
108
- * @example
109
- * ```typescript
110
- * const adminRole = AuthConfig.getAdminRoleName()
111
- * console.log(`Admin role: ${adminRole}`) // "admin" by default
112
- *
113
- * // Check if user has admin role
114
- * const userRoles = ['user', 'admin', 'moderator']
115
- * const isAdmin = userRoles.includes(adminRole)
116
- * ```
117
- */
118
- static getAdminRoleName(): string;
119
- /**
120
- * Resets the cached configuration (useful for testing).
121
- *
122
- * @private
123
- */
124
- static _resetConfig(): void;
125
- }
126
- //# sourceMappingURL=auth_config.d.ts.map