digitaltwin-core 0.14.0 → 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 -72
  131. package/dist/storage/adapters/ovh_storage_service.d.ts.map +0 -1
  132. package/dist/storage/adapters/ovh_storage_service.js +0 -206
  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 -40
  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
@@ -1,662 +0,0 @@
1
- import type { Component, Servable } from './interfaces.js';
2
- import type { AssetsManagerConfiguration, DataResponse } from './types.js';
3
- import type { HttpMethod } from '../engine/endpoints.js';
4
- import type { StorageService } from '../storage/storage_service.js';
5
- import type { DatabaseAdapter, MetadataRow } from '../database/database_adapter.js';
6
- import type { DataRecord } from '../types/data_record.js';
7
- import type { OpenAPIDocumentable, OpenAPIComponentSpec } from '../openapi/types.js';
8
- import { UserService } from '../auth/user_service.js';
9
- /**
10
- * Extended metadata row for assets with additional fields.
11
- * This will be stored as separate columns in the database table.
12
- *
13
- * @interface AssetMetadataRow
14
- * @extends {MetadataRow}
15
- *
16
- * @example
17
- * ```typescript
18
- * const assetMeta: AssetMetadataRow = {
19
- * name: 'gltf',
20
- * type: 'model/gltf-binary',
21
- * url: '/storage/gltf/model.glb',
22
- * date: new Date(),
23
- * description: '3D building model',
24
- * source: 'https://example.com/data-source',
25
- * owner_id: 123,
26
- * filename: 'building.glb',
27
- * is_public: true
28
- * }
29
- * ```
30
- */
31
- export interface AssetMetadataRow extends MetadataRow {
32
- /** Human-readable description of the asset */
33
- description: string;
34
- /** Source URL for data provenance and licensing compliance (must be valid URL) */
35
- source: string;
36
- /** ID of the user who owns this asset (for access control) */
37
- owner_id: number | null;
38
- /** Original filename provided by the user */
39
- filename: string;
40
- /** Whether the asset is publicly accessible (true) or private (false) */
41
- is_public: boolean;
42
- }
43
- /**
44
- * Request payload for creating a new asset.
45
- *
46
- * @interface CreateAssetRequest
47
- *
48
- * @example
49
- * ```typescript
50
- * const request: CreateAssetRequest = {
51
- * description: '3D model of building',
52
- * source: 'https://city-data.example.com/buildings',
53
- * owner_id: 'user123',
54
- * filename: 'building.glb',
55
- * file: fileBuffer,
56
- * is_public: true
57
- * }
58
- * ```
59
- */
60
- export interface CreateAssetRequest {
61
- /** Human-readable description of the asset */
62
- description: string;
63
- /** Source URL for data provenance (validated as proper URL) */
64
- source: string;
65
- /** Owner user ID for access control (can be null) */
66
- owner_id: number | null;
67
- /** Original filename */
68
- filename: string;
69
- /** File content as Buffer */
70
- file: Buffer;
71
- /** Whether the asset is publicly accessible (default: true) */
72
- is_public?: boolean;
73
- }
74
- /**
75
- * Request payload for updating asset metadata.
76
- *
77
- * @interface UpdateAssetRequest
78
- *
79
- * @example
80
- * ```typescript
81
- * const updates: UpdateAssetRequest = {
82
- * description: 'Updated building model with new textures',
83
- * source: 'https://updated-source.example.com',
84
- * is_public: false
85
- * }
86
- * ```
87
- */
88
- export interface UpdateAssetRequest {
89
- /** Updated description (optional) */
90
- description?: string;
91
- /** Updated source URL (optional, validated if provided) */
92
- source?: string;
93
- /** Updated visibility (optional) */
94
- is_public?: boolean;
95
- }
96
- /**
97
- * Abstract base class for Assets Manager components with authentication and access control.
98
- *
99
- * Provides secure file upload, storage, and retrieval capabilities following the Digital Twin framework patterns.
100
- * Each concrete implementation manages a specific type of asset and creates its own database table.
101
- *
102
- * ## Authentication & Authorization
103
- *
104
- * - **Write Operations** (POST, PUT, DELETE): Require authentication via Apache APISIX headers
105
- * - **User Management**: Automatically creates/updates user records from Keycloak data
106
- * - **Access Control**: Users can only modify/delete their own assets (ownership-based)
107
- * - **Resource Linking**: Assets are automatically linked to their owners via user_id foreign key
108
- *
109
- * ## Required Headers for Authenticated Endpoints
110
- *
111
- * - `x-user-id`: Keycloak user UUID (required)
112
- * - `x-user-roles`: Comma-separated list of user roles (optional)
113
- *
114
- * These headers are automatically added by Apache APISIX after successful Keycloak authentication.
115
- *
116
- * @abstract
117
- * @class AssetsManager
118
- * @implements {Component}
119
- * @implements {Servable}
120
- *
121
- * @example
122
- * ```typescript
123
- * // Create concrete implementations for different asset types
124
- * class GLTFAssetsManager extends AssetsManager {
125
- * getConfiguration() {
126
- * return { name: 'gltf', description: 'GLTF 3D models manager', ... }
127
- * }
128
- * }
129
- *
130
- * class PointCloudAssetsManager extends AssetsManager {
131
- * getConfiguration() {
132
- * return { name: 'pointcloud', description: 'Point cloud data manager', ... }
133
- * }
134
- * }
135
- *
136
- * // Usage in engine
137
- * const gltfManager = new GLTFAssetsManager()
138
- * gltfManager.setDependencies(database, storage)
139
- *
140
- * // Each creates its own table and endpoints:
141
- * // - GLTFAssetsManager → table 'gltf', endpoints /gltf/*
142
- * // - PointCloudAssetsManager → table 'pointcloud', endpoints /pointcloud/*
143
- * ```
144
- *
145
- * @remarks
146
- * Asset metadata is stored as dedicated columns in the database table:
147
- * - id, name, url, date (standard columns)
148
- * - description, source, owner_id, filename (asset-specific columns)
149
- *
150
- * Each concrete AssetsManager creates its own table based on the configuration name.
151
- */
152
- export declare abstract class AssetsManager implements Component, Servable, OpenAPIDocumentable {
153
- protected db: DatabaseAdapter;
154
- protected storage: StorageService;
155
- protected userService: UserService;
156
- /**
157
- * Injects dependencies into the assets manager.
158
- *
159
- * Called by the framework during component initialization.
160
- *
161
- * @param {DatabaseAdapter} db - The database adapter for metadata storage
162
- * @param {StorageService} storage - The storage service for file persistence
163
- * @param {UserService} [userService] - Optional user service for authentication (created automatically if not provided)
164
- *
165
- * @example
166
- * ```typescript
167
- * // Standard usage (UserService created automatically)
168
- * const assetsManager = new MyAssetsManager()
169
- * assetsManager.setDependencies(databaseAdapter, storageService)
170
- *
171
- * // For testing (inject mock UserService)
172
- * const mockUserService = new MockUserService()
173
- * assetsManager.setDependencies(databaseAdapter, storageService, mockUserService)
174
- * ```
175
- */
176
- setDependencies(db: DatabaseAdapter, storage: StorageService, userService?: UserService): void;
177
- /**
178
- * Returns the configuration of the assets manager.
179
- *
180
- * Must be implemented by subclasses to define the asset type,
181
- * table name, and content types.
182
- *
183
- * @abstract
184
- * @returns {ComponentConfiguration} The component configuration
185
- *
186
- * @example
187
- * ```typescript
188
- * class GLTFAssetsManager extends AssetsManager {
189
- * getConfiguration(): ComponentConfiguration {
190
- * return {
191
- * name: 'gltf',
192
- * description: 'GLTF 3D models manager',
193
- * contentType: 'model/gltf-binary',
194
- * tags: ['assets', '3d', 'gltf']
195
- * }
196
- * }
197
- * }
198
- * ```
199
- */
200
- abstract getConfiguration(): AssetsManagerConfiguration;
201
- /**
202
- * Validates that a source string is a valid URL.
203
- *
204
- * Used internally to ensure data provenance URLs are properly formatted.
205
- *
206
- * @private
207
- * @param {string} source - The source URL to validate
208
- * @returns {boolean} True if the source is a valid URL, false otherwise
209
- *
210
- * @example
211
- * ```typescript
212
- * this.validateSourceURL('https://example.com/data') // returns true
213
- * this.validateSourceURL('not-a-url') // returns false
214
- * ```
215
- */
216
- private validateSourceURL;
217
- /**
218
- * Validates that a filename has the correct extension as configured.
219
- *
220
- * Used internally to ensure uploaded files match the expected extension.
221
- *
222
- * @private
223
- * @param {string} filename - The filename to validate
224
- * @returns {boolean} True if the filename has the correct extension or no extension is configured, false otherwise
225
- *
226
- * @example
227
- * ```typescript
228
- * // If config.extension = '.glb'
229
- * this.validateFileExtension('model.glb') // returns true
230
- * this.validateFileExtension('model.json') // returns false
231
- * this.validateFileExtension('model') // returns false
232
- *
233
- * // If config.extension is undefined
234
- * this.validateFileExtension('any-file.ext') // returns true
235
- * ```
236
- */
237
- private validateFileExtension;
238
- /**
239
- * Validates that a string is valid base64-encoded data.
240
- *
241
- * Used internally to ensure file data in batch uploads is properly base64-encoded
242
- * before attempting to decode it.
243
- *
244
- * @private
245
- * @param {any} data - Data to validate as base64
246
- * @returns {boolean} True if data is a valid base64 string, false otherwise
247
- *
248
- * @example
249
- * ```typescript
250
- * this.validateBase64('SGVsbG8gV29ybGQ=') // returns true
251
- * this.validateBase64('not-base64!@#') // returns false
252
- * this.validateBase64(123) // returns false (not a string)
253
- * this.validateBase64('') // returns false (empty string)
254
- * ```
255
- */
256
- private validateBase64;
257
- /**
258
- * Authenticates a request and returns the user record.
259
- *
260
- * This method consolidates the authentication flow:
261
- * 1. Validates APISIX headers are present
262
- * 2. Parses authentication headers
263
- * 3. Finds or creates user record in database
264
- *
265
- * @param req - HTTP request object
266
- * @returns AuthResult with either userRecord on success or DataResponse on failure
267
- *
268
- * @example
269
- * ```typescript
270
- * const authResult = await this.authenticateRequest(req)
271
- * if (!authResult.success) {
272
- * return authResult.response
273
- * }
274
- * const userRecord = authResult.userRecord
275
- * ```
276
- */
277
- private authenticateRequest;
278
- /**
279
- * Extracts upload data from multipart form request.
280
- *
281
- * @param req - HTTP request object with body and file
282
- * @returns UploadData object with extracted fields
283
- */
284
- private extractUploadData;
285
- /**
286
- * Validates required fields for asset upload and returns validated data.
287
- *
288
- * @param data - Upload data to validate
289
- * @returns UploadValidationResult with validated data on success or error response on failure
290
- */
291
- private validateUploadFields;
292
- /**
293
- * Reads file content from temporary upload path.
294
- *
295
- * @param filePath - Path to temporary file
296
- * @returns Buffer with file content
297
- * @throws Error if file cannot be read
298
- */
299
- private readTempFile;
300
- /**
301
- * Cleans up temporary file after processing.
302
- * Silently ignores cleanup errors.
303
- *
304
- * @param filePath - Path to temporary file
305
- */
306
- private cleanupTempFile;
307
- /**
308
- * Validates ownership of an asset.
309
- *
310
- * Admins can modify any asset. Regular users can only modify their own assets
311
- * or assets with no owner (owner_id = null).
312
- *
313
- * @param asset - Asset record to check
314
- * @param userId - User ID to validate against
315
- * @param headers - HTTP request headers (optional, for admin check)
316
- * @returns DataResponse with error if not owner/admin, undefined if valid
317
- */
318
- private validateOwnership;
319
- /**
320
- * Checks if a user can access a private asset.
321
- *
322
- * @param asset - Asset record to check
323
- * @param req - HTTP request for authentication context
324
- * @returns DataResponse with error if access denied, undefined if allowed
325
- */
326
- private checkPrivateAssetAccess;
327
- /**
328
- * Fetches an asset by ID with full access control validation.
329
- *
330
- * This method consolidates the common logic for retrieving an asset:
331
- * 1. Validates that ID is provided
332
- * 2. Fetches the asset from database
333
- * 3. Verifies the asset belongs to this component
334
- * 4. Checks access permissions for private assets
335
- *
336
- * @param req - HTTP request with params.id
337
- * @returns Object with asset on success, or DataResponse on failure
338
- */
339
- private fetchAssetWithAccessCheck;
340
- /**
341
- * Upload a new asset file with metadata.
342
- *
343
- * Stores the file using the storage service and saves metadata to the database.
344
- * Asset metadata is stored as dedicated columns in the database table.
345
- *
346
- * @param {CreateAssetRequest} request - The asset upload request
347
- * @throws {Error} If source URL is invalid
348
- *
349
- * @example
350
- * ```typescript
351
- * await assetsManager.uploadAsset({
352
- * description: '3D building model',
353
- * source: 'https://city-data.example.com/buildings',
354
- * owner_id: 'user123',
355
- * filename: 'building.glb',
356
- * file: fileBuffer,
357
- * is_public: true
358
- * })
359
- * ```
360
- */
361
- uploadAsset(request: CreateAssetRequest): Promise<void>;
362
- /**
363
- * Retrieve all assets for this component (like other components).
364
- *
365
- * Returns a JSON list of all assets with their metadata, following the
366
- * framework pattern but adapted for assets management.
367
- *
368
- * Access control:
369
- * - Unauthenticated users: Can only see public assets
370
- * - Authenticated users: Can see public assets + their own private assets
371
- * - Admin users: Can see all assets (public and private from all users)
372
- *
373
- * @returns {Promise<DataResponse>} JSON response with all assets
374
- */
375
- retrieve(req?: any): Promise<DataResponse>;
376
- /**
377
- * Gets the authenticated user's database ID from request headers.
378
- *
379
- * @param req - HTTP request object
380
- * @returns User ID or null if not authenticated
381
- */
382
- private getAuthenticatedUserId;
383
- /**
384
- * Formats assets for API response with metadata and URLs.
385
- *
386
- * @param assets - Array of asset records
387
- * @returns Formatted assets array ready for JSON serialization
388
- */
389
- private formatAssetsForResponse;
390
- /**
391
- * Get all assets for this component type.
392
- *
393
- * Retrieves all assets managed by this component, with their metadata.
394
- * Uses a very old start date to get all records.
395
- *
396
- * @returns {Promise<DataRecord[]>} Array of all asset records
397
- *
398
- * @example
399
- * ```typescript
400
- * const allAssets = await assetsManager.getAllAssets()
401
- * // Returns: [{ id, name, type, url, date, contentType }, ...]
402
- * ```
403
- */
404
- getAllAssets(): Promise<DataRecord[]>;
405
- /**
406
- * Get asset by specific ID.
407
- *
408
- * @param {string} id - The asset ID to retrieve
409
- * @returns {Promise<DataRecord | undefined>} The asset record or undefined if not found
410
- *
411
- * @example
412
- * ```typescript
413
- * const asset = await assetsManager.getAssetById('123')
414
- * if (asset) {
415
- * const fileData = await asset.data()
416
- * }
417
- * ```
418
- */
419
- getAssetById(id: string): Promise<DataRecord | undefined>;
420
- /**
421
- * Update asset metadata by ID.
422
- *
423
- * Updates the metadata (description, source, and/or visibility) of a specific asset.
424
- * Asset metadata is stored as dedicated columns in the database.
425
- *
426
- * @param {string} id - The ID of the asset to update
427
- * @param {UpdateAssetRequest} updates - The metadata updates to apply
428
- * @throws {Error} If source URL is invalid or asset not found
429
- *
430
- * @example
431
- * ```typescript
432
- * await assetsManager.updateAssetMetadata('123', {
433
- * description: 'Updated building model with new textures',
434
- * source: 'https://updated-source.example.com',
435
- * is_public: false
436
- * })
437
- * ```
438
- */
439
- updateAssetMetadata(id: string, updates: UpdateAssetRequest): Promise<void>;
440
- /**
441
- * Delete asset by ID.
442
- *
443
- * Removes a specific asset.
444
- *
445
- * @param {string} id - The ID of the asset to delete
446
- * @throws {Error} If asset not found or doesn't belong to this component
447
- *
448
- * @example
449
- * ```typescript
450
- * await assetsManager.deleteAssetById('123')
451
- * ```
452
- */
453
- deleteAssetById(id: string): Promise<void>;
454
- /**
455
- * Delete latest asset (simplified)
456
- *
457
- * Removes the most recently uploaded asset for this component type.
458
- *
459
- * @throws {Error} If no assets exist to delete
460
- *
461
- * @example
462
- * ```typescript
463
- * await assetsManager.deleteLatestAsset()
464
- * ```
465
- */
466
- deleteLatestAsset(): Promise<void>;
467
- /**
468
- * Upload multiple assets in batch for better performance
469
- *
470
- * @param {CreateAssetRequest[]} requests - Array of asset upload requests
471
- * @throws {Error} If any source URL is invalid
472
- *
473
- * @example
474
- * ```typescript
475
- * await assetsManager.uploadAssetsBatch([
476
- * { description: 'Model 1', source: 'https://example.com/1', file: buffer1, ... },
477
- * { description: 'Model 2', source: 'https://example.com/2', file: buffer2, ... }
478
- * ])
479
- * ```
480
- */
481
- uploadAssetsBatch(requests: CreateAssetRequest[]): Promise<void>;
482
- /**
483
- * Delete multiple assets by IDs in batch
484
- *
485
- * @param {string[]} ids - Array of asset IDs to delete
486
- * @throws {Error} If any asset not found or doesn't belong to this component
487
- */
488
- deleteAssetsBatch(ids: string[]): Promise<void>;
489
- /**
490
- * Get endpoints following the framework pattern
491
- */
492
- /**
493
- * Get HTTP endpoints exposed by this assets manager.
494
- *
495
- * Returns the standard CRUD endpoints following the framework pattern.
496
- *
497
- * @returns {Array} Array of endpoint descriptors with methods, paths, and handlers
498
- *
499
- * @example
500
- * ```typescript
501
- * // For a manager with assetType: 'gltf', provides:
502
- * GET /gltf - Get all assets
503
- * POST /gltf/upload - Upload new asset
504
- * GET /gltf/123 - Get specific asset
505
- * PUT /gltf/123 - Update asset metadata
506
- * GET /gltf/123/download - Download asset
507
- * DELETE /gltf/123 - Delete asset
508
- * ```
509
- */
510
- getEndpoints(): Array<{
511
- method: HttpMethod;
512
- path: string;
513
- handler: (...args: any[]) => any;
514
- responseType?: string;
515
- }>;
516
- /**
517
- * Returns the OpenAPI specification for this assets manager's endpoints.
518
- *
519
- * Generates documentation for all CRUD endpoints including batch operations.
520
- * Can be overridden by subclasses for more detailed specifications.
521
- *
522
- * @returns {OpenAPIComponentSpec} OpenAPI paths, tags, and schemas for this assets manager
523
- */
524
- getOpenAPISpec(): OpenAPIComponentSpec;
525
- /**
526
- * Handle single asset upload via HTTP POST.
527
- *
528
- * Flow:
529
- * 1. Validate request structure and authentication
530
- * 2. Extract user identity from Apache APISIX headers
531
- * 3. Validate file extension and read uploaded file
532
- * 4. Store file via storage service and metadata in database
533
- * 5. Set owner_id to authenticated user (prevents ownership spoofing)
534
- * 6. Apply is_public setting (defaults to true if not specified)
535
- *
536
- * Authentication: Required
537
- * Ownership: Automatically set to authenticated user
538
- *
539
- * @param req - HTTP request with multipart/form-data file upload
540
- * @returns HTTP response with success/error status
541
- *
542
- * @example
543
- * POST /assets
544
- * Content-Type: multipart/form-data
545
- * x-user-id: user-uuid
546
- * x-user-roles: user,premium
547
- *
548
- * Form data:
549
- * - file: <binary file>
550
- * - description: "3D model of building"
551
- * - source: "https://source.com"
552
- * - is_public: true
553
- */
554
- handleUpload(req: any): Promise<DataResponse>;
555
- /**
556
- * Handle update endpoint (PUT).
557
- *
558
- * Updates metadata for a specific asset by ID.
559
- *
560
- * @param {any} req - HTTP request object with params.id and body containing updates
561
- * @returns {Promise<DataResponse>} HTTP response
562
- *
563
- * @example
564
- * ```typescript
565
- * // PUT /gltf/123
566
- * // Body: { "description": "Updated model", "source": "https://new-source.com" }
567
- * ```
568
- */
569
- handleUpdate(req: any): Promise<DataResponse>;
570
- /**
571
- * Handle get asset endpoint (GET).
572
- *
573
- * Returns the file content of a specific asset by ID for display/use in front-end.
574
- * No download headers - just the raw file content.
575
- *
576
- * Access control:
577
- * - Public assets: Accessible to everyone
578
- * - Private assets: Accessible only to owner
579
- * - Admin users: Can access all assets (public and private)
580
- *
581
- * @param {any} req - HTTP request object with params.id
582
- * @returns {Promise<DataResponse>} HTTP response with file content
583
- *
584
- * @example
585
- * ```typescript
586
- * // GET /gltf/123
587
- * // Returns the .glb file content for display in 3D viewer
588
- * ```
589
- */
590
- handleGetAsset(req: any): Promise<DataResponse>;
591
- /**
592
- * Handle download endpoint (GET).
593
- *
594
- * Downloads the file content of a specific asset by ID with download headers.
595
- * Forces browser to download the file rather than display it.
596
- *
597
- * Access control:
598
- * - Public assets: Accessible to everyone
599
- * - Private assets: Accessible only to owner
600
- * - Admin users: Can download all assets (public and private)
601
- *
602
- * @param {any} req - HTTP request object with params.id
603
- * @returns {Promise<DataResponse>} HTTP response with file content and download headers
604
- *
605
- * @example
606
- * ```typescript
607
- * // GET /gltf/123/download
608
- * // Returns the .glb file with download headers - browser will save it
609
- * ```
610
- */
611
- handleDownload(req: any): Promise<DataResponse>;
612
- /**
613
- * Handle delete endpoint (DELETE).
614
- *
615
- * Deletes a specific asset by ID.
616
- *
617
- * @param {any} req - HTTP request object with params.id
618
- * @returns {Promise<DataResponse>} HTTP response
619
- *
620
- * @example
621
- * ```typescript
622
- * // DELETE /gltf/123
623
- * ```
624
- */
625
- handleDelete(req: any): Promise<DataResponse>;
626
- /**
627
- * Handle batch upload endpoint
628
- */
629
- handleUploadBatch(req: any): Promise<DataResponse>;
630
- /**
631
- * Validates all requests in a batch upload.
632
- *
633
- * @param requests - Array of upload requests to validate
634
- * @returns DataResponse with error if validation fails, undefined if valid
635
- */
636
- private validateBatchRequests;
637
- /**
638
- * Processes batch upload requests.
639
- *
640
- * @param requests - Array of upload requests
641
- * @param ownerId - Owner user ID
642
- * @returns Array of results for each upload
643
- */
644
- private processBatchUploads;
645
- /**
646
- * Handle batch delete endpoint
647
- */
648
- handleDeleteBatch(req: any): Promise<DataResponse>;
649
- /**
650
- * Processes batch delete requests.
651
- *
652
- * Admins can delete any asset. Regular users can only delete their own assets
653
- * or assets with no owner.
654
- *
655
- * @param ids - Array of asset IDs to delete
656
- * @param userId - User ID for ownership validation
657
- * @param headers - HTTP request headers (for admin check)
658
- * @returns Array of results for each deletion
659
- */
660
- private processBatchDeletes;
661
- }
662
- //# sourceMappingURL=assets_manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets_manager.d.ts","sourceRoot":"","sources":["../../src/components/assets_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK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