digitaltwin-core 0.9.1 → 0.9.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.
- package/dist/components/assets_manager.d.ts +123 -1
- package/dist/components/assets_manager.d.ts.map +1 -1
- package/dist/components/assets_manager.js +440 -684
- package/dist/components/assets_manager.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/http_responses.d.ts +155 -0
- package/dist/utils/http_responses.d.ts.map +1 -0
- package/dist/utils/http_responses.js +190 -0
- package/dist/utils/http_responses.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -2
|
@@ -159,14 +159,20 @@ export declare abstract class AssetsManager implements Component, Servable {
|
|
|
159
159
|
*
|
|
160
160
|
* @param {DatabaseAdapter} db - The database adapter for metadata storage
|
|
161
161
|
* @param {StorageService} storage - The storage service for file persistence
|
|
162
|
+
* @param {UserService} [userService] - Optional user service for authentication (created automatically if not provided)
|
|
162
163
|
*
|
|
163
164
|
* @example
|
|
164
165
|
* ```typescript
|
|
166
|
+
* // Standard usage (UserService created automatically)
|
|
165
167
|
* const assetsManager = new MyAssetsManager()
|
|
166
168
|
* assetsManager.setDependencies(databaseAdapter, storageService)
|
|
169
|
+
*
|
|
170
|
+
* // For testing (inject mock UserService)
|
|
171
|
+
* const mockUserService = new MockUserService()
|
|
172
|
+
* assetsManager.setDependencies(databaseAdapter, storageService, mockUserService)
|
|
167
173
|
* ```
|
|
168
174
|
*/
|
|
169
|
-
setDependencies(db: DatabaseAdapter, storage: StorageService): void;
|
|
175
|
+
setDependencies(db: DatabaseAdapter, storage: StorageService, userService?: UserService): void;
|
|
170
176
|
/**
|
|
171
177
|
* Returns the configuration of the assets manager.
|
|
172
178
|
*
|
|
@@ -247,6 +253,85 @@ export declare abstract class AssetsManager implements Component, Servable {
|
|
|
247
253
|
* ```
|
|
248
254
|
*/
|
|
249
255
|
private validateBase64;
|
|
256
|
+
/**
|
|
257
|
+
* Authenticates a request and returns the user record.
|
|
258
|
+
*
|
|
259
|
+
* This method consolidates the authentication flow:
|
|
260
|
+
* 1. Validates APISIX headers are present
|
|
261
|
+
* 2. Parses authentication headers
|
|
262
|
+
* 3. Finds or creates user record in database
|
|
263
|
+
*
|
|
264
|
+
* @param req - HTTP request object
|
|
265
|
+
* @returns AuthResult with either userRecord on success or DataResponse on failure
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const authResult = await this.authenticateRequest(req)
|
|
270
|
+
* if (!authResult.success) {
|
|
271
|
+
* return authResult.response
|
|
272
|
+
* }
|
|
273
|
+
* const userRecord = authResult.userRecord
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
private authenticateRequest;
|
|
277
|
+
/**
|
|
278
|
+
* Extracts upload data from multipart form request.
|
|
279
|
+
*
|
|
280
|
+
* @param req - HTTP request object with body and file
|
|
281
|
+
* @returns UploadData object with extracted fields
|
|
282
|
+
*/
|
|
283
|
+
private extractUploadData;
|
|
284
|
+
/**
|
|
285
|
+
* Validates required fields for asset upload and returns validated data.
|
|
286
|
+
*
|
|
287
|
+
* @param data - Upload data to validate
|
|
288
|
+
* @returns UploadValidationResult with validated data on success or error response on failure
|
|
289
|
+
*/
|
|
290
|
+
private validateUploadFields;
|
|
291
|
+
/**
|
|
292
|
+
* Reads file content from temporary upload path.
|
|
293
|
+
*
|
|
294
|
+
* @param filePath - Path to temporary file
|
|
295
|
+
* @returns Buffer with file content
|
|
296
|
+
* @throws Error if file cannot be read
|
|
297
|
+
*/
|
|
298
|
+
private readTempFile;
|
|
299
|
+
/**
|
|
300
|
+
* Cleans up temporary file after processing.
|
|
301
|
+
* Silently ignores cleanup errors.
|
|
302
|
+
*
|
|
303
|
+
* @param filePath - Path to temporary file
|
|
304
|
+
*/
|
|
305
|
+
private cleanupTempFile;
|
|
306
|
+
/**
|
|
307
|
+
* Validates ownership of an asset.
|
|
308
|
+
*
|
|
309
|
+
* @param asset - Asset record to check
|
|
310
|
+
* @param userId - User ID to validate against
|
|
311
|
+
* @returns DataResponse with error if not owner, undefined if valid
|
|
312
|
+
*/
|
|
313
|
+
private validateOwnership;
|
|
314
|
+
/**
|
|
315
|
+
* Checks if a user can access a private asset.
|
|
316
|
+
*
|
|
317
|
+
* @param asset - Asset record to check
|
|
318
|
+
* @param req - HTTP request for authentication context
|
|
319
|
+
* @returns DataResponse with error if access denied, undefined if allowed
|
|
320
|
+
*/
|
|
321
|
+
private checkPrivateAssetAccess;
|
|
322
|
+
/**
|
|
323
|
+
* Fetches an asset by ID with full access control validation.
|
|
324
|
+
*
|
|
325
|
+
* This method consolidates the common logic for retrieving an asset:
|
|
326
|
+
* 1. Validates that ID is provided
|
|
327
|
+
* 2. Fetches the asset from database
|
|
328
|
+
* 3. Verifies the asset belongs to this component
|
|
329
|
+
* 4. Checks access permissions for private assets
|
|
330
|
+
*
|
|
331
|
+
* @param req - HTTP request with params.id
|
|
332
|
+
* @returns Object with asset on success, or DataResponse on failure
|
|
333
|
+
*/
|
|
334
|
+
private fetchAssetWithAccessCheck;
|
|
250
335
|
/**
|
|
251
336
|
* Upload a new asset file with metadata.
|
|
252
337
|
*
|
|
@@ -283,6 +368,20 @@ export declare abstract class AssetsManager implements Component, Servable {
|
|
|
283
368
|
* @returns {Promise<DataResponse>} JSON response with all assets
|
|
284
369
|
*/
|
|
285
370
|
retrieve(req?: any): Promise<DataResponse>;
|
|
371
|
+
/**
|
|
372
|
+
* Gets the authenticated user's database ID from request headers.
|
|
373
|
+
*
|
|
374
|
+
* @param req - HTTP request object
|
|
375
|
+
* @returns User ID or null if not authenticated
|
|
376
|
+
*/
|
|
377
|
+
private getAuthenticatedUserId;
|
|
378
|
+
/**
|
|
379
|
+
* Formats assets for API response with metadata and URLs.
|
|
380
|
+
*
|
|
381
|
+
* @param assets - Array of asset records
|
|
382
|
+
* @returns Formatted assets array ready for JSON serialization
|
|
383
|
+
*/
|
|
384
|
+
private formatAssetsForResponse;
|
|
286
385
|
/**
|
|
287
386
|
* Get all assets for this component type.
|
|
288
387
|
*
|
|
@@ -514,9 +613,32 @@ export declare abstract class AssetsManager implements Component, Servable {
|
|
|
514
613
|
* Handle batch upload endpoint
|
|
515
614
|
*/
|
|
516
615
|
handleUploadBatch(req: any): Promise<DataResponse>;
|
|
616
|
+
/**
|
|
617
|
+
* Validates all requests in a batch upload.
|
|
618
|
+
*
|
|
619
|
+
* @param requests - Array of upload requests to validate
|
|
620
|
+
* @returns DataResponse with error if validation fails, undefined if valid
|
|
621
|
+
*/
|
|
622
|
+
private validateBatchRequests;
|
|
623
|
+
/**
|
|
624
|
+
* Processes batch upload requests.
|
|
625
|
+
*
|
|
626
|
+
* @param requests - Array of upload requests
|
|
627
|
+
* @param ownerId - Owner user ID
|
|
628
|
+
* @returns Array of results for each upload
|
|
629
|
+
*/
|
|
630
|
+
private processBatchUploads;
|
|
517
631
|
/**
|
|
518
632
|
* Handle batch delete endpoint
|
|
519
633
|
*/
|
|
520
634
|
handleDeleteBatch(req: any): Promise<DataResponse>;
|
|
635
|
+
/**
|
|
636
|
+
* Processes batch delete requests.
|
|
637
|
+
*
|
|
638
|
+
* @param ids - Array of asset IDs to delete
|
|
639
|
+
* @param userId - User ID for ownership validation
|
|
640
|
+
* @returns Array of results for each deletion
|
|
641
|
+
*/
|
|
642
|
+
private processBatchDeletes;
|
|
521
643
|
}
|
|
522
644
|
//# sourceMappingURL=assets_manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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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