@haex-space/vault-sdk 3.2.6 → 3.2.8

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.
@@ -1,4 +1,4 @@
1
- import { b as HaexHubEvent, c as EXTERNAL_EVENTS, D as DatabaseQueryResult, M as Migration, d as MigrationResult, W as WebRequestOptions, e as WebResponse, f as EventCallback, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, g as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult } from './types-CDMBvvjl.mjs';
1
+ import { b as HaexHubEvent, c as EXTERNAL_EVENTS, D as DatabaseQueryResult, M as Migration, d as MigrationResult, W as WebRequestOptions, e as WebResponse, f as EventCallback, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, g as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult } from './types-Cji-mUN0.js';
2
2
  import { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
3
3
 
4
4
  /**
@@ -1468,6 +1468,7 @@ declare class HaexVaultSdk {
1468
1468
  private readonly eventListeners;
1469
1469
  private readonly externalRequestHandlers;
1470
1470
  private readonly reactiveSubscribers;
1471
+ private readonly permissionWaiters;
1471
1472
  private messageHandler;
1472
1473
  /**
1473
1474
  * MessagePort obtained from the main window during iframe-mode handshake.
@@ -1,4 +1,4 @@
1
- import { b as HaexHubEvent, c as EXTERNAL_EVENTS, D as DatabaseQueryResult, M as Migration, d as MigrationResult, W as WebRequestOptions, e as WebResponse, f as EventCallback, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, g as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult } from './types-CDMBvvjl.js';
1
+ import { b as HaexHubEvent, c as EXTERNAL_EVENTS, D as DatabaseQueryResult, M as Migration, d as MigrationResult, W as WebRequestOptions, e as WebResponse, f as EventCallback, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, g as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult } from './types-Cji-mUN0.mjs';
2
2
  import { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
3
3
 
4
4
  /**
@@ -1468,6 +1468,7 @@ declare class HaexVaultSdk {
1468
1468
  private readonly eventListeners;
1469
1469
  private readonly externalRequestHandlers;
1470
1470
  private readonly reactiveSubscribers;
1471
+ private readonly permissionWaiters;
1471
1472
  private messageHandler;
1472
1473
  /**
1473
1474
  * MessagePort obtained from the main window during iframe-mode handshake.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk } from './client-Bbm83Oy6.mjs';
2
- export { A as AuthorizedClient, B as BlockedClient, C as ConnectionSecurity, D as DatabaseAPI, a as DecryptedSpace, b as Device, c as DeviceInfo, d as DeviceType, e as DirEntry, E as ExternalAuthDecision, f as ExternalConnection, g as ExternalConnectionErrorCode, h as ExternalConnectionState, i as ExternalRequest, j as ExternalRequestEvent, k as ExternalRequestHandler, l as ExternalRequestPayload, m as ExternalResponse, F as FileStat, n as FilesystemAPI, I as ImapConfig, K as KnownPath, o as KnownPaths, L as LOCALSEND_EVENTS, p as LocalSendAPI, q as LocalSendEvent, r as LocalSendFileInfo, s as LocalSendSettings, M as MailAPI, t as MailAccount, u as MailAddress, v as MailAttachment, w as MailFetchRange, x as MailMessage, y as MailboxInfo, z as MessageEnvelope, O as OutgoingAttachment, G as OutgoingMessage, P as PasswordInput, J as PasswordItemFull, N as PasswordItemSummary, Q as PasswordKeyValue, R as PasswordKeyValueInput, T as PasswordsAPI, U as PendingAuthorization, V as PendingTransfer, W as PermissionsAPI, X as RemoteAddBackendRequest, Y as RemoteS3Config, Z as RemoteS3PublicConfig, _ as RemoteStorageAPI, $ as RemoteStorageBackendInfo, a0 as RemoteStorageObjectInfo, a1 as RemoteUpdateBackendRequest, a2 as RequestedExtension, a3 as SelectFileOptions, a4 as SelectFolderOptions, a5 as ServerInfo, a6 as ServerStatus, a7 as SessionAuthorization, a8 as SharedSpace, a9 as ShellAPI, aa as ShellCreateOptions, ab as ShellCreateResponse, ac as ShellExitEvent, ad as ShellOutputEvent, ae as SmtpConfig, af as SpaceAccessTokenInfo, ag as SpaceAssignment, ah as SpaceInvite, ai as SpaceKeyGrantInfo, aj as SpaceMemberInfo, ak as SpacesAPI, al as SyncBackendInfo, am as TransferDirection, an as TransferProgress, ao as TransferState, ap as WebAPI, aq as canExternalClientSendRequests, ar as isExternalClientConnected } from './client-Bbm83Oy6.mjs';
3
- import { E as ExtensionManifest, h as SignedClaimPresentation, H as HaexHubConfig } from './types-CDMBvvjl.mjs';
4
- export { A as ApplicationContext, C as ClaimRequirement, i as ContextChangedEvent, j as DEFAULT_TIMEOUT, k as DatabaseColumnInfo, l as DatabaseExecuteParams, m as DatabasePermission, g as DatabasePermissionRequest, n as DatabaseQueryParams, D as DatabaseQueryResult, o as DatabaseTableInfo, c as EXTERNAL_EVENTS, p as ErrorCode, f as EventCallback, a as ExtensionInfo, q as ExtensionRuntimeMode, r as ExternalEvent, F as FileChangeEvent, s as FileChangePayload, t as FileChangeType, u as FilteredSyncTablesResult, v as HAEXTENSION_EVENTS, b as HaexHubEvent, w as HaexHubRequest, x as HaexHubResponse, y as HaexVaultSdkError, z as HaextensionEvent, I as IdentityClaim, B as ManifestI18nEntry, G as PermissionDeniedError, J as PermissionErrorBase, K as PermissionErrorCode, L as PermissionPromptError, P as PermissionResponse, N as PermissionStatus, O as SHELL_EVENTS, Q as SearchQuery, R as SearchRequestEvent, S as SearchResult, T as ShellEvent, U as SyncTablesUpdatedEvent, V as TABLE_SEPARATOR, W as WebRequestOptions, e as WebResponse, X as getTableName, Y as isPermissionDeniedError, Z as isPermissionError, _ as isPermissionPromptError } from './types-CDMBvvjl.mjs';
1
+ import { H as HaexVaultSdk } from './client-DaS2fAf-.mjs';
2
+ export { A as AuthorizedClient, B as BlockedClient, C as ConnectionSecurity, D as DatabaseAPI, a as DecryptedSpace, b as Device, c as DeviceInfo, d as DeviceType, e as DirEntry, E as ExternalAuthDecision, f as ExternalConnection, g as ExternalConnectionErrorCode, h as ExternalConnectionState, i as ExternalRequest, j as ExternalRequestEvent, k as ExternalRequestHandler, l as ExternalRequestPayload, m as ExternalResponse, F as FileStat, n as FilesystemAPI, I as ImapConfig, K as KnownPath, o as KnownPaths, L as LOCALSEND_EVENTS, p as LocalSendAPI, q as LocalSendEvent, r as LocalSendFileInfo, s as LocalSendSettings, M as MailAPI, t as MailAccount, u as MailAddress, v as MailAttachment, w as MailFetchRange, x as MailMessage, y as MailboxInfo, z as MessageEnvelope, O as OutgoingAttachment, G as OutgoingMessage, P as PasswordInput, J as PasswordItemFull, N as PasswordItemSummary, Q as PasswordKeyValue, R as PasswordKeyValueInput, T as PasswordsAPI, U as PendingAuthorization, V as PendingTransfer, W as PermissionsAPI, X as RemoteAddBackendRequest, Y as RemoteS3Config, Z as RemoteS3PublicConfig, _ as RemoteStorageAPI, $ as RemoteStorageBackendInfo, a0 as RemoteStorageObjectInfo, a1 as RemoteUpdateBackendRequest, a2 as RequestedExtension, a3 as SelectFileOptions, a4 as SelectFolderOptions, a5 as ServerInfo, a6 as ServerStatus, a7 as SessionAuthorization, a8 as SharedSpace, a9 as ShellAPI, aa as ShellCreateOptions, ab as ShellCreateResponse, ac as ShellExitEvent, ad as ShellOutputEvent, ae as SmtpConfig, af as SpaceAccessTokenInfo, ag as SpaceAssignment, ah as SpaceInvite, ai as SpaceKeyGrantInfo, aj as SpaceMemberInfo, ak as SpacesAPI, al as SyncBackendInfo, am as TransferDirection, an as TransferProgress, ao as TransferState, ap as WebAPI, aq as canExternalClientSendRequests, ar as isExternalClientConnected } from './client-DaS2fAf-.mjs';
3
+ import { E as ExtensionManifest, h as SignedClaimPresentation, H as HaexHubConfig } from './types-Cji-mUN0.mjs';
4
+ export { A as ApplicationContext, C as ClaimRequirement, i as ContextChangedEvent, j as DEFAULT_TIMEOUT, k as DatabaseColumnInfo, l as DatabaseExecuteParams, m as DatabasePermission, g as DatabasePermissionRequest, n as DatabaseQueryParams, D as DatabaseQueryResult, o as DatabaseTableInfo, c as EXTERNAL_EVENTS, p as ErrorCode, f as EventCallback, a as ExtensionInfo, q as ExtensionRuntimeMode, r as ExternalEvent, F as FileChangeEvent, s as FileChangePayload, t as FileChangeType, u as FilteredSyncTablesResult, v as HAEXTENSION_EVENTS, b as HaexHubEvent, w as HaexHubRequest, x as HaexHubResponse, y as HaexVaultSdkError, z as HaextensionEvent, I as IdentityClaim, B as ManifestI18nEntry, G as PermissionDeniedError, J as PermissionErrorBase, K as PermissionErrorCode, L as PermissionPromptError, P as PermissionResponse, N as PermissionStatus, O as SHELL_EVENTS, Q as SearchQuery, R as SearchRequestEvent, S as SearchResult, T as ShellEvent, U as SyncTablesUpdatedEvent, V as TABLE_SEPARATOR, W as WebRequestOptions, e as WebResponse, X as getTableName, Y as isPermissionDeniedError, Z as isPermissionError, _ as isPermissionPromptError } from './types-Cji-mUN0.mjs';
5
5
  export { H as HaextensionConfig } from './config-D_HXjsEV.mjs';
6
6
  import 'drizzle-orm/sqlite-proxy';
7
7
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk } from './client-exZiz0Ph.js';
2
- export { A as AuthorizedClient, B as BlockedClient, C as ConnectionSecurity, D as DatabaseAPI, a as DecryptedSpace, b as Device, c as DeviceInfo, d as DeviceType, e as DirEntry, E as ExternalAuthDecision, f as ExternalConnection, g as ExternalConnectionErrorCode, h as ExternalConnectionState, i as ExternalRequest, j as ExternalRequestEvent, k as ExternalRequestHandler, l as ExternalRequestPayload, m as ExternalResponse, F as FileStat, n as FilesystemAPI, I as ImapConfig, K as KnownPath, o as KnownPaths, L as LOCALSEND_EVENTS, p as LocalSendAPI, q as LocalSendEvent, r as LocalSendFileInfo, s as LocalSendSettings, M as MailAPI, t as MailAccount, u as MailAddress, v as MailAttachment, w as MailFetchRange, x as MailMessage, y as MailboxInfo, z as MessageEnvelope, O as OutgoingAttachment, G as OutgoingMessage, P as PasswordInput, J as PasswordItemFull, N as PasswordItemSummary, Q as PasswordKeyValue, R as PasswordKeyValueInput, T as PasswordsAPI, U as PendingAuthorization, V as PendingTransfer, W as PermissionsAPI, X as RemoteAddBackendRequest, Y as RemoteS3Config, Z as RemoteS3PublicConfig, _ as RemoteStorageAPI, $ as RemoteStorageBackendInfo, a0 as RemoteStorageObjectInfo, a1 as RemoteUpdateBackendRequest, a2 as RequestedExtension, a3 as SelectFileOptions, a4 as SelectFolderOptions, a5 as ServerInfo, a6 as ServerStatus, a7 as SessionAuthorization, a8 as SharedSpace, a9 as ShellAPI, aa as ShellCreateOptions, ab as ShellCreateResponse, ac as ShellExitEvent, ad as ShellOutputEvent, ae as SmtpConfig, af as SpaceAccessTokenInfo, ag as SpaceAssignment, ah as SpaceInvite, ai as SpaceKeyGrantInfo, aj as SpaceMemberInfo, ak as SpacesAPI, al as SyncBackendInfo, am as TransferDirection, an as TransferProgress, ao as TransferState, ap as WebAPI, aq as canExternalClientSendRequests, ar as isExternalClientConnected } from './client-exZiz0Ph.js';
3
- import { E as ExtensionManifest, h as SignedClaimPresentation, H as HaexHubConfig } from './types-CDMBvvjl.js';
4
- export { A as ApplicationContext, C as ClaimRequirement, i as ContextChangedEvent, j as DEFAULT_TIMEOUT, k as DatabaseColumnInfo, l as DatabaseExecuteParams, m as DatabasePermission, g as DatabasePermissionRequest, n as DatabaseQueryParams, D as DatabaseQueryResult, o as DatabaseTableInfo, c as EXTERNAL_EVENTS, p as ErrorCode, f as EventCallback, a as ExtensionInfo, q as ExtensionRuntimeMode, r as ExternalEvent, F as FileChangeEvent, s as FileChangePayload, t as FileChangeType, u as FilteredSyncTablesResult, v as HAEXTENSION_EVENTS, b as HaexHubEvent, w as HaexHubRequest, x as HaexHubResponse, y as HaexVaultSdkError, z as HaextensionEvent, I as IdentityClaim, B as ManifestI18nEntry, G as PermissionDeniedError, J as PermissionErrorBase, K as PermissionErrorCode, L as PermissionPromptError, P as PermissionResponse, N as PermissionStatus, O as SHELL_EVENTS, Q as SearchQuery, R as SearchRequestEvent, S as SearchResult, T as ShellEvent, U as SyncTablesUpdatedEvent, V as TABLE_SEPARATOR, W as WebRequestOptions, e as WebResponse, X as getTableName, Y as isPermissionDeniedError, Z as isPermissionError, _ as isPermissionPromptError } from './types-CDMBvvjl.js';
1
+ import { H as HaexVaultSdk } from './client-BBD-YsPv.js';
2
+ export { A as AuthorizedClient, B as BlockedClient, C as ConnectionSecurity, D as DatabaseAPI, a as DecryptedSpace, b as Device, c as DeviceInfo, d as DeviceType, e as DirEntry, E as ExternalAuthDecision, f as ExternalConnection, g as ExternalConnectionErrorCode, h as ExternalConnectionState, i as ExternalRequest, j as ExternalRequestEvent, k as ExternalRequestHandler, l as ExternalRequestPayload, m as ExternalResponse, F as FileStat, n as FilesystemAPI, I as ImapConfig, K as KnownPath, o as KnownPaths, L as LOCALSEND_EVENTS, p as LocalSendAPI, q as LocalSendEvent, r as LocalSendFileInfo, s as LocalSendSettings, M as MailAPI, t as MailAccount, u as MailAddress, v as MailAttachment, w as MailFetchRange, x as MailMessage, y as MailboxInfo, z as MessageEnvelope, O as OutgoingAttachment, G as OutgoingMessage, P as PasswordInput, J as PasswordItemFull, N as PasswordItemSummary, Q as PasswordKeyValue, R as PasswordKeyValueInput, T as PasswordsAPI, U as PendingAuthorization, V as PendingTransfer, W as PermissionsAPI, X as RemoteAddBackendRequest, Y as RemoteS3Config, Z as RemoteS3PublicConfig, _ as RemoteStorageAPI, $ as RemoteStorageBackendInfo, a0 as RemoteStorageObjectInfo, a1 as RemoteUpdateBackendRequest, a2 as RequestedExtension, a3 as SelectFileOptions, a4 as SelectFolderOptions, a5 as ServerInfo, a6 as ServerStatus, a7 as SessionAuthorization, a8 as SharedSpace, a9 as ShellAPI, aa as ShellCreateOptions, ab as ShellCreateResponse, ac as ShellExitEvent, ad as ShellOutputEvent, ae as SmtpConfig, af as SpaceAccessTokenInfo, ag as SpaceAssignment, ah as SpaceInvite, ai as SpaceKeyGrantInfo, aj as SpaceMemberInfo, ak as SpacesAPI, al as SyncBackendInfo, am as TransferDirection, an as TransferProgress, ao as TransferState, ap as WebAPI, aq as canExternalClientSendRequests, ar as isExternalClientConnected } from './client-BBD-YsPv.js';
3
+ import { E as ExtensionManifest, h as SignedClaimPresentation, H as HaexHubConfig } from './types-Cji-mUN0.js';
4
+ export { A as ApplicationContext, C as ClaimRequirement, i as ContextChangedEvent, j as DEFAULT_TIMEOUT, k as DatabaseColumnInfo, l as DatabaseExecuteParams, m as DatabasePermission, g as DatabasePermissionRequest, n as DatabaseQueryParams, D as DatabaseQueryResult, o as DatabaseTableInfo, c as EXTERNAL_EVENTS, p as ErrorCode, f as EventCallback, a as ExtensionInfo, q as ExtensionRuntimeMode, r as ExternalEvent, F as FileChangeEvent, s as FileChangePayload, t as FileChangeType, u as FilteredSyncTablesResult, v as HAEXTENSION_EVENTS, b as HaexHubEvent, w as HaexHubRequest, x as HaexHubResponse, y as HaexVaultSdkError, z as HaextensionEvent, I as IdentityClaim, B as ManifestI18nEntry, G as PermissionDeniedError, J as PermissionErrorBase, K as PermissionErrorCode, L as PermissionPromptError, P as PermissionResponse, N as PermissionStatus, O as SHELL_EVENTS, Q as SearchQuery, R as SearchRequestEvent, S as SearchResult, T as ShellEvent, U as SyncTablesUpdatedEvent, V as TABLE_SEPARATOR, W as WebRequestOptions, e as WebResponse, X as getTableName, Y as isPermissionDeniedError, Z as isPermissionError, _ as isPermissionPromptError } from './types-Cji-mUN0.js';
5
5
  export { H as HaextensionConfig } from './config-D_HXjsEV.js';
6
6
  import 'drizzle-orm/sqlite-proxy';
7
7
 
package/dist/index.js CHANGED
@@ -711,7 +711,11 @@ var HAEXTENSION_EVENTS = {
711
711
  /** File system change detected (from native file watcher) */
712
712
  FILE_CHANGED: "filesync:file-changed",
713
713
  /** Tables have been updated via sync (CRDT pull from server) */
714
- SYNC_TABLES_UPDATED: "haextension:sync:tables-updated"
714
+ SYNC_TABLES_UPDATED: "haextension:sync:tables-updated",
715
+ /** A runtime permission prompt was resolved (granted/denied) by the user.
716
+ * The SDK uses this to auto-retry the original request; extensions may also
717
+ * subscribe via `client.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, ...)`. */
718
+ PERMISSION_RESOLVED: "extension:permission-resolved"
715
719
  };
716
720
  var EXTERNAL_EVENTS = {
717
721
  /** External request from authorized client */
@@ -1484,7 +1488,10 @@ var WebAPI = class {
1484
1488
  } else if (options.body instanceof Blob) {
1485
1489
  bodyParam = await this.blobToBase64(options.body);
1486
1490
  } else {
1487
- bodyParam = options.body;
1491
+ const bytes = new TextEncoder().encode(options.body);
1492
+ bodyParam = this.arrayBufferToBase64(
1493
+ bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
1494
+ );
1488
1495
  }
1489
1496
  }
1490
1497
  const response = await this.client.request(WEB_COMMANDS.fetch, {
@@ -2297,6 +2304,21 @@ async function initNativeMode(ctx, log, onEvent, onContextChange) {
2297
2304
  await setupTauriEventListeners(ctx, log, onEvent, onContextChange);
2298
2305
  return { extensionInfo, context };
2299
2306
  }
2307
+ async function forwardEvent(listen, log, onEvent, listenOptions, eventName, shape) {
2308
+ try {
2309
+ await listen(eventName, (event) => {
2310
+ if (event.payload == null) {
2311
+ log(`Event '${eventName}' received with no payload`);
2312
+ return;
2313
+ }
2314
+ const extra = shape ? shape(event.payload) : { data: event.payload };
2315
+ onEvent({ type: eventName, timestamp: Date.now(), ...extra });
2316
+ }, listenOptions);
2317
+ log(`Listener registered: ${eventName}`);
2318
+ } catch (error) {
2319
+ log(`Failed to register listener '${eventName}':`, error);
2320
+ }
2321
+ }
2300
2322
  async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
2301
2323
  const { listen } = getTauriEvent();
2302
2324
  const webviewLabel = getCurrentWebviewLabel();
@@ -2328,207 +2350,29 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
2328
2350
  } catch (error) {
2329
2351
  log("Failed to setup context change listener:", error);
2330
2352
  }
2331
- try {
2332
- await listen(EXTERNAL_EVENTS.REQUEST, (event) => {
2333
- log("====== EXTERNAL REQUEST RECEIVED ======");
2334
- log("Event payload:", JSON.stringify(event.payload, null, 2));
2335
- if (event.payload) {
2336
- onEvent({
2337
- type: EXTERNAL_EVENTS.REQUEST,
2338
- data: event.payload,
2339
- timestamp: Date.now()
2340
- });
2341
- } else {
2342
- log("External request event has no payload!");
2343
- }
2344
- }, listenOptions);
2345
- log("External request listener registered successfully");
2346
- } catch (error) {
2347
- log("Failed to setup external request listener:", error);
2348
- }
2349
- try {
2350
- await listen(EXTERNAL_EVENTS.ACTION_REQUEST, (event) => {
2351
- log("====== AI ACTION REQUEST RECEIVED ======");
2352
- log("Payload:", JSON.stringify(event.payload));
2353
- if (event.payload) {
2354
- onEvent({
2355
- type: EXTERNAL_EVENTS.ACTION_REQUEST,
2356
- data: event.payload,
2357
- timestamp: Date.now()
2358
- });
2359
- } else {
2360
- log("AI action request event has no payload!");
2361
- }
2362
- }, listenOptions);
2363
- log("AI action request listener registered successfully");
2364
- } catch (error) {
2365
- log("Failed to setup AI action request listener:", error);
2366
- }
2367
- log("Registering file change listener for:", HAEXTENSION_EVENTS.FILE_CHANGED);
2368
- try {
2369
- await listen(HAEXTENSION_EVENTS.FILE_CHANGED, (event) => {
2370
- log("File change event received:", event.payload);
2371
- if (event.payload) {
2372
- const payload = event.payload;
2373
- onEvent({
2374
- type: HAEXTENSION_EVENTS.FILE_CHANGED,
2375
- ruleId: payload.ruleId,
2376
- changeType: payload.changeType,
2377
- path: payload.path,
2378
- timestamp: Date.now()
2379
- });
2380
- }
2381
- }, listenOptions);
2382
- log("File change listener registered successfully");
2383
- } catch (error) {
2384
- log("Failed to setup file change listener:", error);
2385
- }
2386
- log("Registering sync tables updated listener for:", HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED);
2387
- try {
2388
- await listen(HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED, (event) => {
2389
- log("Sync tables updated event received:", event.payload);
2390
- if (event.payload) {
2391
- const payload = event.payload;
2392
- onEvent({
2393
- type: HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED,
2394
- data: { tables: payload.tables },
2395
- timestamp: Date.now()
2396
- });
2397
- }
2398
- }, listenOptions);
2399
- log("Sync tables updated listener registered successfully");
2400
- } catch (error) {
2401
- log("Failed to setup sync tables updated listener:", error);
2402
- }
2403
- log("Setting up LocalSend event listeners");
2404
- try {
2405
- await setupLocalSendEventListeners(log, onEvent, listenOptions);
2406
- log("LocalSend event listeners setup complete");
2407
- } catch (error) {
2408
- log("Failed to setup LocalSend event listeners:", error);
2409
- }
2410
- log("Setting up Shell event listeners");
2411
- try {
2412
- await listen(SHELL_EVENTS.OUTPUT, (event) => {
2413
- if (event.payload) {
2414
- const payload = event.payload;
2415
- onEvent({
2416
- type: SHELL_EVENTS.OUTPUT,
2417
- timestamp: Date.now(),
2418
- sessionId: payload.sessionId,
2419
- data: payload.data
2420
- });
2421
- }
2422
- }, listenOptions);
2423
- log("Shell output listener registered");
2424
- await listen(SHELL_EVENTS.EXIT, (event) => {
2425
- if (event.payload) {
2426
- const payload = event.payload;
2427
- onEvent({
2428
- type: SHELL_EVENTS.EXIT,
2429
- timestamp: Date.now(),
2430
- sessionId: payload.sessionId,
2431
- exitCode: payload.exitCode
2432
- });
2433
- }
2434
- }, listenOptions);
2435
- log("Shell exit listener registered");
2436
- } catch (error) {
2437
- log("Failed to setup Shell event listeners:", error);
2438
- }
2439
- }
2440
- async function setupLocalSendEventListeners(log, onEvent, listenOptions) {
2441
- const { listen } = getTauriEvent();
2442
- try {
2443
- await listen(LOCALSEND_EVENTS.deviceDiscovered, (event) => {
2444
- log("LocalSend device discovered:", event.payload);
2445
- if (event.payload) {
2446
- onEvent({
2447
- type: LOCALSEND_EVENTS.deviceDiscovered,
2448
- data: event.payload,
2449
- timestamp: Date.now()
2450
- });
2451
- }
2452
- }, listenOptions);
2453
- log("LocalSend device discovered listener registered");
2454
- } catch (error) {
2455
- log("Failed to setup LocalSend device discovered listener:", error);
2456
- }
2457
- try {
2458
- await listen(LOCALSEND_EVENTS.deviceLost, (event) => {
2459
- log("LocalSend device lost:", event.payload);
2460
- if (event.payload) {
2461
- onEvent({
2462
- type: LOCALSEND_EVENTS.deviceLost,
2463
- data: event.payload,
2464
- timestamp: Date.now()
2465
- });
2466
- }
2467
- }, listenOptions);
2468
- log("LocalSend device lost listener registered");
2469
- } catch (error) {
2470
- log("Failed to setup LocalSend device lost listener:", error);
2471
- }
2472
- try {
2473
- await listen(LOCALSEND_EVENTS.transferRequest, (event) => {
2474
- log("LocalSend transfer request:", event.payload);
2475
- if (event.payload) {
2476
- onEvent({
2477
- type: LOCALSEND_EVENTS.transferRequest,
2478
- data: event.payload,
2479
- timestamp: Date.now()
2480
- });
2481
- }
2482
- }, listenOptions);
2483
- log("LocalSend transfer request listener registered");
2484
- } catch (error) {
2485
- log("Failed to setup LocalSend transfer request listener:", error);
2486
- }
2487
- try {
2488
- await listen(LOCALSEND_EVENTS.transferProgress, (event) => {
2489
- log("LocalSend transfer progress event:", event);
2490
- if (event.payload) {
2491
- onEvent({
2492
- type: LOCALSEND_EVENTS.transferProgress,
2493
- data: event.payload,
2494
- timestamp: Date.now()
2495
- });
2496
- }
2497
- }, listenOptions);
2498
- log("LocalSend transfer progress listener registered");
2499
- } catch (error) {
2500
- log("Failed to setup LocalSend transfer progress listener:", error);
2501
- }
2502
- try {
2503
- await listen(LOCALSEND_EVENTS.transferComplete, (event) => {
2504
- log("LocalSend transfer complete:", event.payload);
2505
- if (event.payload) {
2506
- onEvent({
2507
- type: LOCALSEND_EVENTS.transferComplete,
2508
- data: event.payload,
2509
- timestamp: Date.now()
2510
- });
2511
- }
2512
- }, listenOptions);
2513
- log("LocalSend transfer complete listener registered");
2514
- } catch (error) {
2515
- log("Failed to setup LocalSend transfer complete listener:", error);
2516
- }
2517
- try {
2518
- await listen(LOCALSEND_EVENTS.transferFailed, (event) => {
2519
- log("LocalSend transfer failed:", event.payload);
2520
- if (event.payload) {
2521
- onEvent({
2522
- type: LOCALSEND_EVENTS.transferFailed,
2523
- data: event.payload,
2524
- timestamp: Date.now()
2525
- });
2526
- }
2527
- }, listenOptions);
2528
- log("LocalSend transfer failed listener registered");
2529
- } catch (error) {
2530
- log("Failed to setup LocalSend transfer failed listener:", error);
2531
- }
2353
+ for (const eventName of [
2354
+ HAEXTENSION_EVENTS.PERMISSION_RESOLVED,
2355
+ EXTERNAL_EVENTS.REQUEST,
2356
+ EXTERNAL_EVENTS.ACTION_REQUEST,
2357
+ ...Object.values(LOCALSEND_EVENTS)
2358
+ ]) {
2359
+ await forwardEvent(listen, log, onEvent, listenOptions, eventName);
2360
+ }
2361
+ await forwardEvent(listen, log, onEvent, listenOptions, HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED, (payload) => ({
2362
+ data: { tables: payload.tables }
2363
+ }));
2364
+ await forwardEvent(listen, log, onEvent, listenOptions, HAEXTENSION_EVENTS.FILE_CHANGED, (payload) => {
2365
+ const { ruleId, changeType, path } = payload;
2366
+ return { ruleId, changeType, path };
2367
+ });
2368
+ await forwardEvent(listen, log, onEvent, listenOptions, SHELL_EVENTS.OUTPUT, (payload) => {
2369
+ const { sessionId, data } = payload;
2370
+ return { sessionId, data };
2371
+ });
2372
+ await forwardEvent(listen, log, onEvent, listenOptions, SHELL_EVENTS.EXIT, (payload) => {
2373
+ const { sessionId, exitCode } = payload;
2374
+ return { sessionId, exitCode };
2375
+ });
2532
2376
  }
2533
2377
  async function initIframeMode(ctx, log, messageHandler) {
2534
2378
  if (!isInIframe()) {
@@ -2872,6 +2716,68 @@ var AI_COMMANDS = {
2872
2716
  actionRespond: "ai_action_respond"
2873
2717
  };
2874
2718
 
2719
+ // src/client/permissionRetry.ts
2720
+ var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2721
+ var MAX_PERMISSION_RETRIES = 3;
2722
+ function permissionKey(resourceType, action, target) {
2723
+ return `${resourceType}:${action}:${target}`;
2724
+ }
2725
+ var PermissionWaiterRegistry = class {
2726
+ constructor() {
2727
+ this.waiters = /* @__PURE__ */ new Map();
2728
+ }
2729
+ /** Wait for a decision on `key`; resolves "timeout" if none arrives in time. */
2730
+ wait(key, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2731
+ return new Promise((resolve) => {
2732
+ const set = this.waiters.get(key) ?? /* @__PURE__ */ new Set();
2733
+ this.waiters.set(key, set);
2734
+ const settle = (outcome) => {
2735
+ if (!set.has(callback)) return;
2736
+ set.delete(callback);
2737
+ if (set.size === 0) this.waiters.delete(key);
2738
+ clearTimeout(timer);
2739
+ resolve(outcome);
2740
+ };
2741
+ const callback = (outcome) => settle(outcome);
2742
+ const timer = setTimeout(() => settle("timeout"), timeoutMs);
2743
+ set.add(callback);
2744
+ });
2745
+ }
2746
+ /** Resolve everyone waiting on `key` with the user's decision. */
2747
+ resolve(key, decision) {
2748
+ const set = this.waiters.get(key);
2749
+ if (!set) return;
2750
+ for (const callback of [...set]) callback(decision);
2751
+ }
2752
+ };
2753
+ function toDeniedError(error) {
2754
+ return { ...error, code: 1002 /* DENIED */ };
2755
+ }
2756
+ async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2757
+ for (let attempt = 0; ; attempt++) {
2758
+ try {
2759
+ return await send();
2760
+ } catch (error) {
2761
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
2762
+ throw error;
2763
+ }
2764
+ const key = permissionKey(error.resourceType, error.action, error.target);
2765
+ log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2766
+ const outcome = await registry.wait(key, timeoutMs);
2767
+ if (outcome === "granted") {
2768
+ log(`Permission ${key} granted \u2014 retrying request`);
2769
+ continue;
2770
+ }
2771
+ if (outcome === "denied") {
2772
+ log(`Permission ${key} denied`);
2773
+ throw toDeniedError(error);
2774
+ }
2775
+ log(`Permission ${key} prompt timed out`);
2776
+ throw error;
2777
+ }
2778
+ }
2779
+ }
2780
+
2875
2781
  // src/client.ts
2876
2782
  var HaexVaultSdk = class {
2877
2783
  constructor(config = {}) {
@@ -2887,6 +2793,7 @@ var HaexVaultSdk = class {
2887
2793
  this.eventListeners = /* @__PURE__ */ new Map();
2888
2794
  this.externalRequestHandlers = /* @__PURE__ */ new Map();
2889
2795
  this.reactiveSubscribers = /* @__PURE__ */ new Set();
2796
+ this.permissionWaiters = new PermissionWaiterRegistry();
2890
2797
  // Handlers
2891
2798
  this.messageHandler = null;
2892
2799
  /**
@@ -2923,6 +2830,14 @@ var HaexVaultSdk = class {
2923
2830
  this.passwords = new PasswordsAPI(this);
2924
2831
  this.mail = new MailAPI(this);
2925
2832
  installConsoleForwarding(this.config.debug);
2833
+ this.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, (event) => {
2834
+ const data = event.data;
2835
+ if (!data) return;
2836
+ this.permissionWaiters.resolve(
2837
+ permissionKey(data.resourceType, data.action, data.target),
2838
+ data.decision === "denied" ? "denied" : "granted"
2839
+ );
2840
+ });
2926
2841
  this.readyPromise = new Promise((resolve, reject) => {
2927
2842
  this.resolveReady = resolve;
2928
2843
  this.rejectReady = reject;
@@ -3071,24 +2986,27 @@ var HaexVaultSdk = class {
3071
2986
  // ==========================================================================
3072
2987
  async request(method, params) {
3073
2988
  const resolvedParams = params ?? {};
3074
- if (this.isNativeWindow && hasTauri()) {
3075
- const paramsWithCredentials = {
3076
- ...resolvedParams,
3077
- publicKey: this._extensionInfo?.publicKey,
3078
- name: this._extensionInfo?.name
3079
- };
3080
- return sendInvoke(method, paramsWithCredentials, this.config, this.log.bind(this));
3081
- }
3082
- const requestId = generateRequestId(++this.requestCounter);
3083
- return sendPostMessage(
3084
- method,
3085
- resolvedParams,
3086
- requestId,
3087
- this.config,
3088
- this._extensionInfo,
3089
- this.pendingRequests,
3090
- this.hostPort
3091
- );
2989
+ const send = () => {
2990
+ if (this.isNativeWindow && hasTauri()) {
2991
+ const paramsWithCredentials = {
2992
+ ...resolvedParams,
2993
+ publicKey: this._extensionInfo?.publicKey,
2994
+ name: this._extensionInfo?.name
2995
+ };
2996
+ return sendInvoke(method, paramsWithCredentials, this.config, this.log.bind(this));
2997
+ }
2998
+ const requestId = generateRequestId(++this.requestCounter);
2999
+ return sendPostMessage(
3000
+ method,
3001
+ resolvedParams,
3002
+ requestId,
3003
+ this.config,
3004
+ this._extensionInfo,
3005
+ this.pendingRequests,
3006
+ this.hostPort
3007
+ );
3008
+ };
3009
+ return withPermissionRetry(send, this.permissionWaiters, this.log.bind(this));
3092
3010
  }
3093
3011
  // ==========================================================================
3094
3012
  // Private: Initialization