@haex-space/vault-sdk 2.5.40 → 2.5.43

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/index.mjs CHANGED
@@ -485,7 +485,19 @@ var HAEXTENSION_METHODS = {
485
485
  filesystem: {
486
486
  saveFile: "haextension:filesystem:save-file",
487
487
  openFile: "haextension:filesystem:open-file",
488
- showImage: "haextension:filesystem:show-image"
488
+ showImage: "haextension:filesystem:show-image",
489
+ // Generic FS operations (Phase 2)
490
+ readFile: "haextension:filesystem:read-file",
491
+ writeFile: "haextension:filesystem:write-file",
492
+ readDir: "haextension:filesystem:read-dir",
493
+ mkdir: "haextension:filesystem:mkdir",
494
+ remove: "haextension:filesystem:remove",
495
+ exists: "haextension:filesystem:exists",
496
+ stat: "haextension:filesystem:stat",
497
+ selectFolder: "haextension:filesystem:select-folder",
498
+ selectFile: "haextension:filesystem:select-file",
499
+ rename: "haextension:filesystem:rename",
500
+ copy: "haextension:filesystem:copy"
489
501
  },
490
502
  filesync: {
491
503
  // Spaces
@@ -537,6 +549,19 @@ var HAEXTENSION_METHODS = {
537
549
  clear: "haextension:storage:clear",
538
550
  keys: "haextension:storage:keys"
539
551
  },
552
+ // Remote Storage API (S3, WebDAV, FTP, etc.)
553
+ remoteStorage: {
554
+ // Backend Management
555
+ listBackends: "haextension:remote-storage:list-backends",
556
+ addBackend: "haextension:remote-storage:add-backend",
557
+ removeBackend: "haextension:remote-storage:remove-backend",
558
+ testBackend: "haextension:remote-storage:test-backend",
559
+ // Storage Operations
560
+ upload: "haextension:remote-storage:upload",
561
+ download: "haextension:remote-storage:download",
562
+ delete: "haextension:remote-storage:delete",
563
+ list: "haextension:remote-storage:list"
564
+ },
540
565
  web: {
541
566
  fetch: "haextension:web:fetch"
542
567
  },
@@ -1062,6 +1087,136 @@ var FilesystemAPI = class {
1062
1087
  );
1063
1088
  return result;
1064
1089
  }
1090
+ // ==========================================================================
1091
+ // Generic Filesystem Operations (Phase 2)
1092
+ // ==========================================================================
1093
+ /**
1094
+ * Read file contents
1095
+ * @param path Absolute path to the file
1096
+ * @returns File contents as Uint8Array
1097
+ */
1098
+ async readFile(path) {
1099
+ const base64 = await this.client.request(
1100
+ HAEXTENSION_METHODS.filesystem.readFile,
1101
+ { path }
1102
+ );
1103
+ const binary = atob(base64);
1104
+ const bytes = new Uint8Array(binary.length);
1105
+ for (let i = 0; i < binary.length; i++) {
1106
+ bytes[i] = binary.charCodeAt(i);
1107
+ }
1108
+ return bytes;
1109
+ }
1110
+ /**
1111
+ * Write file contents
1112
+ * @param path Absolute path to the file
1113
+ * @param data File contents as Uint8Array
1114
+ */
1115
+ async writeFile(path, data) {
1116
+ const base64 = btoa(String.fromCharCode(...data));
1117
+ await this.client.request(
1118
+ HAEXTENSION_METHODS.filesystem.writeFile,
1119
+ { path, data: base64 }
1120
+ );
1121
+ }
1122
+ /**
1123
+ * Read directory contents
1124
+ * @param path Absolute path to the directory
1125
+ * @returns Array of directory entries
1126
+ */
1127
+ async readDir(path) {
1128
+ return this.client.request(
1129
+ HAEXTENSION_METHODS.filesystem.readDir,
1130
+ { path }
1131
+ );
1132
+ }
1133
+ /**
1134
+ * Create a directory (and parent directories if needed)
1135
+ * @param path Absolute path to create
1136
+ */
1137
+ async mkdir(path) {
1138
+ await this.client.request(
1139
+ HAEXTENSION_METHODS.filesystem.mkdir,
1140
+ { path }
1141
+ );
1142
+ }
1143
+ /**
1144
+ * Remove a file or directory
1145
+ * @param path Absolute path to remove
1146
+ * @param recursive If true, remove directories recursively
1147
+ */
1148
+ async remove(path, recursive = false) {
1149
+ await this.client.request(
1150
+ HAEXTENSION_METHODS.filesystem.remove,
1151
+ { path, recursive }
1152
+ );
1153
+ }
1154
+ /**
1155
+ * Check if a path exists
1156
+ * @param path Absolute path to check
1157
+ * @returns True if the path exists
1158
+ */
1159
+ async exists(path) {
1160
+ return this.client.request(
1161
+ HAEXTENSION_METHODS.filesystem.exists,
1162
+ { path }
1163
+ );
1164
+ }
1165
+ /**
1166
+ * Get file/directory metadata
1167
+ * @param path Absolute path
1168
+ * @returns File metadata
1169
+ */
1170
+ async stat(path) {
1171
+ return this.client.request(
1172
+ HAEXTENSION_METHODS.filesystem.stat,
1173
+ { path }
1174
+ );
1175
+ }
1176
+ /**
1177
+ * Open a folder selection dialog
1178
+ * @param options Dialog options
1179
+ * @returns Selected folder path, or null if cancelled
1180
+ */
1181
+ async selectFolder(options = {}) {
1182
+ return this.client.request(
1183
+ HAEXTENSION_METHODS.filesystem.selectFolder,
1184
+ options
1185
+ );
1186
+ }
1187
+ /**
1188
+ * Open a file selection dialog
1189
+ * @param options Dialog options
1190
+ * @returns Selected file paths, or null if cancelled
1191
+ */
1192
+ async selectFile(options = {}) {
1193
+ return this.client.request(
1194
+ HAEXTENSION_METHODS.filesystem.selectFile,
1195
+ options
1196
+ );
1197
+ }
1198
+ /**
1199
+ * Rename/move a file or directory
1200
+ * @param from Source path
1201
+ * @param to Destination path
1202
+ */
1203
+ async rename(from, to) {
1204
+ await this.client.request(
1205
+ HAEXTENSION_METHODS.filesystem.rename,
1206
+ { from, to }
1207
+ );
1208
+ }
1209
+ /**
1210
+ * Copy a file
1211
+ * @param from Source path
1212
+ * @param to Destination path
1213
+ */
1214
+ async copy(from, to) {
1215
+ await this.client.request(
1216
+ HAEXTENSION_METHODS.filesystem.copy,
1217
+ { from, to }
1218
+ );
1219
+ }
1065
1220
  };
1066
1221
 
1067
1222
  // src/api/web.ts
@@ -1231,6 +1386,111 @@ var PermissionsAPI = class {
1231
1386
  }
1232
1387
  };
1233
1388
 
1389
+ // src/api/remoteStorage.ts
1390
+ var RemoteStorageAPI = class {
1391
+ constructor(client) {
1392
+ this.client = client;
1393
+ this.backends = new BackendManagement(client);
1394
+ }
1395
+ /**
1396
+ * Upload data to a storage backend
1397
+ * @param backendId - Backend ID to upload to
1398
+ * @param key - Object key (path in the bucket)
1399
+ * @param data - Data to upload
1400
+ */
1401
+ async upload(backendId, key, data) {
1402
+ const base64 = btoa(String.fromCharCode(...data));
1403
+ await this.client.request(HAEXTENSION_METHODS.remoteStorage.upload, {
1404
+ backendId,
1405
+ key,
1406
+ data: base64
1407
+ });
1408
+ }
1409
+ /**
1410
+ * Download data from a storage backend
1411
+ * @param backendId - Backend ID to download from
1412
+ * @param key - Object key (path in the bucket)
1413
+ * @returns Downloaded data as Uint8Array
1414
+ */
1415
+ async download(backendId, key) {
1416
+ const base64 = await this.client.request(
1417
+ HAEXTENSION_METHODS.remoteStorage.download,
1418
+ { backendId, key }
1419
+ );
1420
+ const binary = atob(base64);
1421
+ const bytes = new Uint8Array(binary.length);
1422
+ for (let i = 0; i < binary.length; i++) {
1423
+ bytes[i] = binary.charCodeAt(i);
1424
+ }
1425
+ return bytes;
1426
+ }
1427
+ /**
1428
+ * Delete an object from a storage backend
1429
+ * @param backendId - Backend ID
1430
+ * @param key - Object key to delete
1431
+ */
1432
+ async delete(backendId, key) {
1433
+ await this.client.request(HAEXTENSION_METHODS.remoteStorage.delete, {
1434
+ backendId,
1435
+ key
1436
+ });
1437
+ }
1438
+ /**
1439
+ * List objects in a storage backend
1440
+ * @param backendId - Backend ID
1441
+ * @param prefix - Optional prefix to filter objects
1442
+ * @returns List of objects
1443
+ */
1444
+ async list(backendId, prefix) {
1445
+ return this.client.request(
1446
+ HAEXTENSION_METHODS.remoteStorage.list,
1447
+ { backendId, prefix }
1448
+ );
1449
+ }
1450
+ };
1451
+ var BackendManagement = class {
1452
+ constructor(client) {
1453
+ this.client = client;
1454
+ }
1455
+ /**
1456
+ * List all available storage backends
1457
+ */
1458
+ async list() {
1459
+ return this.client.request(
1460
+ HAEXTENSION_METHODS.remoteStorage.listBackends
1461
+ );
1462
+ }
1463
+ /**
1464
+ * Add a new storage backend
1465
+ * @param request - Backend configuration
1466
+ * @returns Created backend info
1467
+ */
1468
+ async add(request) {
1469
+ return this.client.request(
1470
+ HAEXTENSION_METHODS.remoteStorage.addBackend,
1471
+ request
1472
+ );
1473
+ }
1474
+ /**
1475
+ * Remove a storage backend
1476
+ * @param backendId - Backend ID to remove
1477
+ */
1478
+ async remove(backendId) {
1479
+ await this.client.request(HAEXTENSION_METHODS.remoteStorage.removeBackend, {
1480
+ backendId
1481
+ });
1482
+ }
1483
+ /**
1484
+ * Test connection to a storage backend
1485
+ * @param backendId - Backend ID to test
1486
+ */
1487
+ async test(backendId) {
1488
+ await this.client.request(HAEXTENSION_METHODS.remoteStorage.testBackend, {
1489
+ backendId
1490
+ });
1491
+ }
1492
+ };
1493
+
1234
1494
  // src/client/tableName.ts
1235
1495
  function validatePublicKey(publicKey) {
1236
1496
  if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
@@ -1451,7 +1711,20 @@ var TAURI_COMMANDS = {
1451
1711
  filesystem: {
1452
1712
  saveFile: "webview_extension_fs_save_file",
1453
1713
  openFile: "webview_extension_fs_open_file",
1454
- showImage: "webview_extension_fs_show_image"
1714
+ showImage: "webview_extension_fs_show_image",
1715
+ // Generic filesystem operations (no webview_ prefix because they're global)
1716
+ // Permission checks happen in the message handler layer
1717
+ readFile: "filesystem_read_file",
1718
+ writeFile: "filesystem_write_file",
1719
+ readDir: "filesystem_read_dir",
1720
+ mkdir: "filesystem_mkdir",
1721
+ remove: "filesystem_remove",
1722
+ exists: "filesystem_exists",
1723
+ stat: "filesystem_stat",
1724
+ selectFolder: "filesystem_select_folder",
1725
+ selectFile: "filesystem_select_file",
1726
+ rename: "filesystem_rename",
1727
+ copy: "filesystem_copy"
1455
1728
  },
1456
1729
  external: {
1457
1730
  // Response handling (called by extensions running in WebView)
@@ -1480,6 +1753,20 @@ var TAURI_COMMANDS = {
1480
1753
  getInfo: "webview_extension_get_info",
1481
1754
  getContext: "webview_extension_context_get"
1482
1755
  },
1756
+ storage: {
1757
+ // Backend Management (generic, shared by all extensions)
1758
+ // These commands don't use webview_ prefix because storage backends are global,
1759
+ // not extension-specific. All extensions share the same storage backends.
1760
+ listBackends: "storage_list_backends",
1761
+ addBackend: "storage_add_backend",
1762
+ removeBackend: "storage_remove_backend",
1763
+ testBackend: "storage_test_backend",
1764
+ // Storage Operations
1765
+ upload: "storage_upload",
1766
+ download: "storage_download",
1767
+ delete: "storage_delete",
1768
+ list: "storage_list"
1769
+ },
1483
1770
  filesync: {
1484
1771
  // Spaces (webview_* commands extract extension info from WebviewWindow)
1485
1772
  listSpaces: "webview_filesync_list_spaces",
@@ -2100,6 +2387,7 @@ var HaexVaultSdk = class {
2100
2387
  this.filesystem = new FilesystemAPI(this);
2101
2388
  this.web = new WebAPI(this);
2102
2389
  this.permissions = new PermissionsAPI(this);
2390
+ this.remoteStorage = new RemoteStorageAPI(this);
2103
2391
  installConsoleForwarding(this.config.debug);
2104
2392
  this.readyPromise = new Promise((resolve) => {
2105
2393
  this.resolveReady = resolve;
@@ -2724,6 +3012,6 @@ function createHaexVaultSdk(config = {}) {
2724
3012
  return new HaexVaultSdk(config);
2725
3013
  }
2726
3014
 
2727
- export { CONFLICT_STRATEGY, DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FILE_SYNC_STATE, FileSyncAPI, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HAEXTENSION_METHODS, HaexVaultSdk, HaexVaultSdkError, PermissionStatus, PermissionsAPI, QUEUE_OPERATION, QUEUE_STATUS, STORAGE_BACKEND_TYPE, SYNC_DIRECTION, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, generateVaultKey, getTableName, hexToBytes, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, wrapKey };
3015
+ export { CONFLICT_STRATEGY, DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FILE_SYNC_STATE, FileSyncAPI, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HAEXTENSION_METHODS, HaexVaultSdk, HaexVaultSdkError, PermissionStatus, PermissionsAPI, QUEUE_OPERATION, QUEUE_STATUS, RemoteStorageAPI, STORAGE_BACKEND_TYPE, SYNC_DIRECTION, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, generateVaultKey, getTableName, hexToBytes, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, wrapKey };
2728
3016
  //# sourceMappingURL=index.mjs.map
2729
3017
  //# sourceMappingURL=index.mjs.map