@haex-space/vault-sdk 2.5.42 → 2.5.45

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.
@@ -72,50 +72,19 @@ var HAEXTENSION_METHODS = {
72
72
  filesystem: {
73
73
  saveFile: "haextension:filesystem:save-file",
74
74
  openFile: "haextension:filesystem:open-file",
75
- showImage: "haextension:filesystem:show-image"
76
- },
77
- filesync: {
78
- // Spaces
79
- listSpaces: "haextension:filesync:list-spaces",
80
- createSpace: "haextension:filesync:create-space",
81
- deleteSpace: "haextension:filesync:delete-space",
82
- // Files
83
- listFiles: "haextension:filesync:list-files",
84
- getFile: "haextension:filesync:get-file",
85
- uploadFile: "haextension:filesync:upload-file",
86
- downloadFile: "haextension:filesync:download-file",
87
- deleteFile: "haextension:filesync:delete-file",
88
- // Backends
89
- listBackends: "haextension:filesync:list-backends",
90
- addBackend: "haextension:filesync:add-backend",
91
- removeBackend: "haextension:filesync:remove-backend",
92
- testBackend: "haextension:filesync:test-backend",
93
- // Sync Rules
94
- listSyncRules: "haextension:filesync:list-sync-rules",
95
- addSyncRule: "haextension:filesync:add-sync-rule",
96
- updateSyncRule: "haextension:filesync:update-sync-rule",
97
- removeSyncRule: "haextension:filesync:remove-sync-rule",
98
- // Sync Operations
99
- getSyncStatus: "haextension:filesync:get-sync-status",
100
- triggerSync: "haextension:filesync:trigger-sync",
101
- pauseSync: "haextension:filesync:pause-sync",
102
- resumeSync: "haextension:filesync:resume-sync",
103
- // Conflict Resolution
104
- resolveConflict: "haextension:filesync:resolve-conflict",
105
- // UI Helpers
106
- selectFolder: "haextension:filesync:select-folder",
107
- scanLocal: "haextension:filesync:scan-local",
108
- // Sync Queue (persistent upload/download queue)
109
- addToQueue: "haextension:filesync:add-to-queue",
110
- getQueue: "haextension:filesync:get-queue",
111
- getQueueSummary: "haextension:filesync:get-queue-summary",
112
- startQueueEntry: "haextension:filesync:start-queue-entry",
113
- completeQueueEntry: "haextension:filesync:complete-queue-entry",
114
- failQueueEntry: "haextension:filesync:fail-queue-entry",
115
- retryFailedQueue: "haextension:filesync:retry-failed-queue",
116
- removeQueueEntry: "haextension:filesync:remove-queue-entry",
117
- clearQueue: "haextension:filesync:clear-queue",
118
- recoverQueue: "haextension:filesync:recover-queue"
75
+ showImage: "haextension:filesystem:show-image",
76
+ // Generic FS operations (Phase 2)
77
+ readFile: "haextension:filesystem:read-file",
78
+ writeFile: "haextension:filesystem:write-file",
79
+ readDir: "haextension:filesystem:read-dir",
80
+ mkdir: "haextension:filesystem:mkdir",
81
+ remove: "haextension:filesystem:remove",
82
+ exists: "haextension:filesystem:exists",
83
+ stat: "haextension:filesystem:stat",
84
+ selectFolder: "haextension:filesystem:select-folder",
85
+ selectFile: "haextension:filesystem:select-file",
86
+ rename: "haextension:filesystem:rename",
87
+ copy: "haextension:filesystem:copy"
119
88
  },
120
89
  storage: {
121
90
  getItem: "haextension:storage:get-item",
@@ -261,364 +230,193 @@ var DatabaseAPI = class {
261
230
  }
262
231
  };
263
232
 
264
- // src/api/filesync.ts
265
- var FileSyncAPI = class {
233
+ // src/api/filesystem.ts
234
+ var FilesystemAPI = class {
266
235
  constructor(client) {
267
236
  this.client = client;
268
237
  }
269
- // --------------------------------------------------------------------------
270
- // Spaces
271
- // --------------------------------------------------------------------------
272
- /**
273
- * List all file spaces
274
- */
275
- async listSpacesAsync() {
276
- return this.client.request(
277
- HAEXTENSION_METHODS.filesync.listSpaces
278
- );
279
- }
280
238
  /**
281
- * Create a new file space
282
- */
283
- async createSpaceAsync(options) {
284
- return this.client.request(
285
- HAEXTENSION_METHODS.filesync.createSpace,
286
- options
287
- );
288
- }
289
- /**
290
- * Delete a file space
291
- */
292
- async deleteSpaceAsync(spaceId) {
293
- await this.client.request(HAEXTENSION_METHODS.filesync.deleteSpace, {
294
- spaceId
295
- });
296
- }
297
- // --------------------------------------------------------------------------
298
- // Files
299
- // --------------------------------------------------------------------------
300
- /**
301
- * List files in a space
239
+ * Opens a save file dialog and saves the provided data to the selected location
240
+ * @param data The file data as Uint8Array
241
+ * @param options Options for the save dialog
242
+ * @returns The path where the file was saved, or null if cancelled
302
243
  */
303
- async listFilesAsync(options) {
304
- return this.client.request(
305
- HAEXTENSION_METHODS.filesync.listFiles,
306
- options
244
+ async saveFileAsync(data, options = {}) {
245
+ const result = await this.client.request(
246
+ HAEXTENSION_METHODS.filesystem.saveFile,
247
+ {
248
+ data: Array.from(data),
249
+ // Convert Uint8Array to regular array for postMessage
250
+ defaultPath: options.defaultPath,
251
+ title: options.title,
252
+ filters: options.filters
253
+ }
307
254
  );
255
+ return result;
308
256
  }
309
257
  /**
310
- * Scan local files in a sync rule folder
311
- * Returns unencrypted local files for display in the UI
258
+ * Opens a file with the system's default viewer
259
+ * @param data The file data as Uint8Array
260
+ * @param options Options for opening the file
261
+ * @returns The result of the operation
312
262
  */
313
- async scanLocalAsync(options) {
314
- return this.client.request(
315
- HAEXTENSION_METHODS.filesync.scanLocal,
316
- options
263
+ async openFileAsync(data, options) {
264
+ const result = await this.client.request(
265
+ HAEXTENSION_METHODS.filesystem.openFile,
266
+ {
267
+ data: Array.from(data),
268
+ // Convert Uint8Array to regular array for postMessage
269
+ fileName: options.fileName,
270
+ mimeType: options.mimeType
271
+ }
317
272
  );
273
+ return result;
318
274
  }
319
275
  /**
320
- * Get file info by ID
276
+ * Shows an image using a data URL (safe, read-only viewing)
277
+ * This is safe to use without special permissions as it only displays images
278
+ * and doesn't execute any code or open files with external applications
279
+ * @param options Options containing the data URL
280
+ * @returns The result of the operation
321
281
  */
322
- async getFileAsync(fileId) {
323
- return this.client.request(
324
- HAEXTENSION_METHODS.filesync.getFile,
325
- { fileId }
282
+ async showImageAsync(options) {
283
+ const result = await this.client.request(
284
+ HAEXTENSION_METHODS.filesystem.showImage,
285
+ {
286
+ dataUrl: options.dataUrl
287
+ }
326
288
  );
289
+ return result;
327
290
  }
291
+ // ==========================================================================
292
+ // Generic Filesystem Operations (Phase 2)
293
+ // ==========================================================================
328
294
  /**
329
- * Upload a file to the sync system
295
+ * Read file contents
296
+ * @param path Absolute path to the file
297
+ * @returns File contents as Uint8Array
330
298
  */
331
- async uploadFileAsync(options) {
332
- return this.client.request(
333
- HAEXTENSION_METHODS.filesync.uploadFile,
334
- options
299
+ async readFile(path) {
300
+ const base64 = await this.client.request(
301
+ HAEXTENSION_METHODS.filesystem.readFile,
302
+ { path }
335
303
  );
304
+ const binary = atob(base64);
305
+ const bytes = new Uint8Array(binary.length);
306
+ for (let i = 0; i < binary.length; i++) {
307
+ bytes[i] = binary.charCodeAt(i);
308
+ }
309
+ return bytes;
336
310
  }
337
311
  /**
338
- * Download a file to local storage
312
+ * Write file contents
313
+ * @param path Absolute path to the file
314
+ * @param data File contents as Uint8Array
339
315
  */
340
- async downloadFileAsync(options) {
316
+ async writeFile(path, data) {
317
+ const base64 = btoa(String.fromCharCode(...data));
341
318
  await this.client.request(
342
- HAEXTENSION_METHODS.filesync.downloadFile,
343
- options
319
+ HAEXTENSION_METHODS.filesystem.writeFile,
320
+ { path, data: base64 }
344
321
  );
345
322
  }
346
323
  /**
347
- * Delete a file from the sync system
324
+ * Read directory contents
325
+ * @param path Absolute path to the directory
326
+ * @returns Array of directory entries
348
327
  */
349
- async deleteFileAsync(fileId) {
350
- await this.client.request(HAEXTENSION_METHODS.filesync.deleteFile, {
351
- fileId
352
- });
353
- }
354
- // --------------------------------------------------------------------------
355
- // Storage Backends
356
- // --------------------------------------------------------------------------
357
- /**
358
- * List configured storage backends
359
- */
360
- async listBackendsAsync() {
361
- return this.client.request(
362
- HAEXTENSION_METHODS.filesync.listBackends
363
- );
364
- }
365
- /**
366
- * Add a new storage backend
367
- */
368
- async addBackendAsync(options) {
328
+ async readDir(path) {
369
329
  return this.client.request(
370
- HAEXTENSION_METHODS.filesync.addBackend,
371
- options
330
+ HAEXTENSION_METHODS.filesystem.readDir,
331
+ { path }
372
332
  );
373
333
  }
374
334
  /**
375
- * Remove a storage backend
376
- */
377
- async removeBackendAsync(backendId) {
378
- await this.client.request(HAEXTENSION_METHODS.filesync.removeBackend, {
379
- backendId
380
- });
381
- }
382
- /**
383
- * Test backend connection
335
+ * Create a directory (and parent directories if needed)
336
+ * @param path Absolute path to create
384
337
  */
385
- async testBackendAsync(backendId) {
386
- return this.client.request(
387
- HAEXTENSION_METHODS.filesync.testBackend,
388
- { backendId }
338
+ async mkdir(path) {
339
+ await this.client.request(
340
+ HAEXTENSION_METHODS.filesystem.mkdir,
341
+ { path }
389
342
  );
390
343
  }
391
- // --------------------------------------------------------------------------
392
- // Sync Rules
393
- // --------------------------------------------------------------------------
394
344
  /**
395
- * List sync rules
345
+ * Remove a file or directory
346
+ * @param path Absolute path to remove
347
+ * @param recursive If true, remove directories recursively
396
348
  */
397
- async listSyncRulesAsync() {
398
- return this.client.request(
399
- HAEXTENSION_METHODS.filesync.listSyncRules
349
+ async remove(path, recursive = false) {
350
+ await this.client.request(
351
+ HAEXTENSION_METHODS.filesystem.remove,
352
+ { path, recursive }
400
353
  );
401
354
  }
402
355
  /**
403
- * Add a sync rule
356
+ * Check if a path exists
357
+ * @param path Absolute path to check
358
+ * @returns True if the path exists
404
359
  */
405
- async addSyncRuleAsync(options) {
360
+ async exists(path) {
406
361
  return this.client.request(
407
- HAEXTENSION_METHODS.filesync.addSyncRule,
408
- options
362
+ HAEXTENSION_METHODS.filesystem.exists,
363
+ { path }
409
364
  );
410
365
  }
411
366
  /**
412
- * Update a sync rule
367
+ * Get file/directory metadata
368
+ * @param path Absolute path
369
+ * @returns File metadata
413
370
  */
414
- async updateSyncRuleAsync(options) {
371
+ async stat(path) {
415
372
  return this.client.request(
416
- HAEXTENSION_METHODS.filesync.updateSyncRule,
417
- options
373
+ HAEXTENSION_METHODS.filesystem.stat,
374
+ { path }
418
375
  );
419
376
  }
420
- /**
421
- * Remove a sync rule
422
- */
423
- async removeSyncRuleAsync(ruleId) {
424
- await this.client.request(HAEXTENSION_METHODS.filesync.removeSyncRule, {
425
- ruleId
426
- });
427
- }
428
- // --------------------------------------------------------------------------
429
- // Sync Operations
430
- // --------------------------------------------------------------------------
431
- /**
432
- * Get current sync status
433
- */
434
- async getSyncStatusAsync() {
435
- return this.client.request(
436
- HAEXTENSION_METHODS.filesync.getSyncStatus
437
- );
438
- }
439
- /**
440
- * Trigger a manual sync
441
- */
442
- async triggerSyncAsync() {
443
- await this.client.request(HAEXTENSION_METHODS.filesync.triggerSync);
444
- }
445
- /**
446
- * Pause syncing
447
- */
448
- async pauseSyncAsync() {
449
- await this.client.request(HAEXTENSION_METHODS.filesync.pauseSync);
450
- }
451
- /**
452
- * Resume syncing
453
- */
454
- async resumeSyncAsync() {
455
- await this.client.request(HAEXTENSION_METHODS.filesync.resumeSync);
456
- }
457
- // --------------------------------------------------------------------------
458
- // Conflict Resolution
459
- // --------------------------------------------------------------------------
460
- /**
461
- * Resolve a file conflict
462
- */
463
- async resolveConflictAsync(fileId, resolution) {
464
- await this.client.request(HAEXTENSION_METHODS.filesync.resolveConflict, {
465
- fileId,
466
- resolution
467
- });
468
- }
469
- // --------------------------------------------------------------------------
470
- // Folder Selection (Native Dialog)
471
- // --------------------------------------------------------------------------
472
377
  /**
473
378
  * Open a folder selection dialog
379
+ * @param options Dialog options
380
+ * @returns Selected folder path, or null if cancelled
474
381
  */
475
- async selectFolderAsync() {
476
- return this.client.request(
477
- HAEXTENSION_METHODS.filesync.selectFolder
478
- );
479
- }
480
- // --------------------------------------------------------------------------
481
- // Sync Queue
482
- // --------------------------------------------------------------------------
483
- /**
484
- * Add files to the sync queue
485
- */
486
- async addToQueueAsync(options) {
382
+ async selectFolder(options = {}) {
487
383
  return this.client.request(
488
- HAEXTENSION_METHODS.filesync.addToQueue,
384
+ HAEXTENSION_METHODS.filesystem.selectFolder,
489
385
  options
490
386
  );
491
387
  }
492
388
  /**
493
- * Get queue entries for the current device
389
+ * Open a file selection dialog
390
+ * @param options Dialog options
391
+ * @returns Selected file paths, or null if cancelled
494
392
  */
495
- async getQueueAsync(options) {
393
+ async selectFile(options = {}) {
496
394
  return this.client.request(
497
- HAEXTENSION_METHODS.filesync.getQueue,
395
+ HAEXTENSION_METHODS.filesystem.selectFile,
498
396
  options
499
397
  );
500
398
  }
501
399
  /**
502
- * Get aggregated queue summary for the current device
503
- */
504
- async getQueueSummaryAsync() {
505
- return this.client.request(
506
- HAEXTENSION_METHODS.filesync.getQueueSummary
507
- );
508
- }
509
- /**
510
- * Mark a queue entry as started (in_progress)
511
- */
512
- async startQueueEntryAsync(entryId) {
513
- await this.client.request(HAEXTENSION_METHODS.filesync.startQueueEntry, {
514
- entryId
515
- });
516
- }
517
- /**
518
- * Mark a queue entry as completed
519
- */
520
- async completeQueueEntryAsync(entryId) {
521
- await this.client.request(HAEXTENSION_METHODS.filesync.completeQueueEntry, {
522
- entryId
523
- });
524
- }
525
- /**
526
- * Mark a queue entry as failed
527
- */
528
- async failQueueEntryAsync(entryId, errorMessage) {
529
- await this.client.request(HAEXTENSION_METHODS.filesync.failQueueEntry, {
530
- entryId,
531
- errorMessage
532
- });
533
- }
534
- /**
535
- * Retry all failed queue entries (reset to pending)
536
- */
537
- async retryFailedQueueAsync() {
538
- await this.client.request(HAEXTENSION_METHODS.filesync.retryFailedQueue);
539
- }
540
- /**
541
- * Remove a queue entry
542
- */
543
- async removeQueueEntryAsync(entryId) {
544
- await this.client.request(HAEXTENSION_METHODS.filesync.removeQueueEntry, {
545
- entryId
546
- });
547
- }
548
- /**
549
- * Clear all queue entries for a sync rule
550
- */
551
- async clearQueueAsync(ruleId) {
552
- await this.client.request(HAEXTENSION_METHODS.filesync.clearQueue, {
553
- ruleId
554
- });
555
- }
556
- /**
557
- * Reset in_progress entries to pending (for recovery after crash)
558
- */
559
- async recoverQueueAsync() {
560
- await this.client.request(HAEXTENSION_METHODS.filesync.recoverQueue);
561
- }
562
- };
563
-
564
- // src/api/filesystem.ts
565
- var FilesystemAPI = class {
566
- constructor(client) {
567
- this.client = client;
568
- this.sync = new FileSyncAPI(client);
569
- }
570
- /**
571
- * Opens a save file dialog and saves the provided data to the selected location
572
- * @param data The file data as Uint8Array
573
- * @param options Options for the save dialog
574
- * @returns The path where the file was saved, or null if cancelled
575
- */
576
- async saveFileAsync(data, options = {}) {
577
- const result = await this.client.request(
578
- HAEXTENSION_METHODS.filesystem.saveFile,
579
- {
580
- data: Array.from(data),
581
- // Convert Uint8Array to regular array for postMessage
582
- defaultPath: options.defaultPath,
583
- title: options.title,
584
- filters: options.filters
585
- }
586
- );
587
- return result;
588
- }
589
- /**
590
- * Opens a file with the system's default viewer
591
- * @param data The file data as Uint8Array
592
- * @param options Options for opening the file
593
- * @returns The result of the operation
400
+ * Rename/move a file or directory
401
+ * @param from Source path
402
+ * @param to Destination path
594
403
  */
595
- async openFileAsync(data, options) {
596
- const result = await this.client.request(
597
- HAEXTENSION_METHODS.filesystem.openFile,
598
- {
599
- data: Array.from(data),
600
- // Convert Uint8Array to regular array for postMessage
601
- fileName: options.fileName,
602
- mimeType: options.mimeType
603
- }
404
+ async rename(from, to) {
405
+ await this.client.request(
406
+ HAEXTENSION_METHODS.filesystem.rename,
407
+ { from, to }
604
408
  );
605
- return result;
606
409
  }
607
410
  /**
608
- * Shows an image using a data URL (safe, read-only viewing)
609
- * This is safe to use without special permissions as it only displays images
610
- * and doesn't execute any code or open files with external applications
611
- * @param options Options containing the data URL
612
- * @returns The result of the operation
411
+ * Copy a file
412
+ * @param from Source path
413
+ * @param to Destination path
613
414
  */
614
- async showImageAsync(options) {
615
- const result = await this.client.request(
616
- HAEXTENSION_METHODS.filesystem.showImage,
617
- {
618
- dataUrl: options.dataUrl
619
- }
415
+ async copy(from, to) {
416
+ await this.client.request(
417
+ HAEXTENSION_METHODS.filesystem.copy,
418
+ { from, to }
620
419
  );
621
- return result;
622
420
  }
623
421
  };
624
422
 
@@ -1188,8 +986,7 @@ var TAURI_COMMANDS = {
1188
986
  filesystem: {
1189
987
  saveFile: "webview_extension_fs_save_file",
1190
988
  openFile: "webview_extension_fs_open_file",
1191
- showImage: "webview_extension_fs_show_image"
1192
- },
989
+ showImage: "webview_extension_fs_show_image"},
1193
990
  external: {
1194
991
  // Response handling (called by extensions running in WebView)
1195
992
  respond: "webview_extension_external_respond"},