@haex-space/vault-sdk 3.7.0 → 4.1.0

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 (51) hide show
  1. package/README.md +51 -19
  2. package/dist/cli/index.js +437 -355
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/cli/index.mjs +428 -339
  5. package/dist/cli/index.mjs.map +1 -1
  6. package/dist/{client-DH4Km77u.d.ts → client-CD5QZi7F.d.ts} +76 -12
  7. package/dist/{client-Dn4AbXbT.d.mts → client-Cx4ZyQFL.d.mts} +76 -12
  8. package/dist/haex_bundle_bg.wasm +0 -0
  9. package/dist/index.d.mts +16 -61
  10. package/dist/index.d.ts +16 -61
  11. package/dist/index.js +185 -116
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +204 -134
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/node.d.mts +53 -2
  16. package/dist/node.d.ts +53 -2
  17. package/dist/node.js +319 -2
  18. package/dist/node.js.map +1 -1
  19. package/dist/node.mjs +320 -5
  20. package/dist/node.mjs.map +1 -1
  21. package/dist/nuxt.js +7 -5
  22. package/dist/nuxt.js.map +1 -1
  23. package/dist/nuxt.mjs +3 -2
  24. package/dist/nuxt.mjs.map +1 -1
  25. package/dist/react.d.mts +2 -2
  26. package/dist/react.d.ts +2 -2
  27. package/dist/react.js +192 -18
  28. package/dist/react.js.map +1 -1
  29. package/dist/react.mjs +212 -38
  30. package/dist/react.mjs.map +1 -1
  31. package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
  32. package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
  33. package/dist/runtime/nuxt.plugin.client.js +100 -18
  34. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  35. package/dist/runtime/nuxt.plugin.client.mjs +100 -18
  36. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  37. package/dist/svelte.d.mts +2 -2
  38. package/dist/svelte.d.ts +2 -2
  39. package/dist/svelte.js +192 -18
  40. package/dist/svelte.js.map +1 -1
  41. package/dist/svelte.mjs +212 -38
  42. package/dist/svelte.mjs.map +1 -1
  43. package/dist/{types-DQZCRfC-.d.mts → types-BwFKGH70.d.mts} +11 -3
  44. package/dist/{types-DQZCRfC-.d.ts → types-BwFKGH70.d.ts} +11 -3
  45. package/dist/vue.d.mts +2 -2
  46. package/dist/vue.d.ts +2 -2
  47. package/dist/vue.js +192 -18
  48. package/dist/vue.js.map +1 -1
  49. package/dist/vue.mjs +212 -38
  50. package/dist/vue.mjs.map +1 -1
  51. package/package.json +9 -7
@@ -180,7 +180,12 @@ var EXTENSION_COMMANDS = {
180
180
  /** Get extension info (manifest, id, etc.) */
181
181
  getInfo: "extension_get_info",
182
182
  /** Get application context (theme, locale, etc.) */
183
- getContext: "extension_context_get"};
183
+ getContext: "extension_context_get",
184
+ /** Ask the host to mark (or unmark) this extension's own tab as wanting attention */
185
+ tabAttention: "extension_tab_attention",
186
+ /** Ask the user to confirm, in a dialog the host draws over this extension's tab */
187
+ dialogConfirm: "extension_dialog_confirm"
188
+ };
184
189
 
185
190
  // src/commands/remoteStorage.ts
186
191
  var REMOTE_STORAGE_COMMANDS = {
@@ -273,6 +278,8 @@ var SHELL_COMMANDS = {
273
278
  create: "extension_shell_create",
274
279
  /** Write data to a shell session's stdin */
275
280
  write: "extension_shell_write",
281
+ /** Acknowledge `shell:output` events handed on (backpressure; sent by the SDK itself) */
282
+ ack: "extension_shell_ack",
276
283
  /** Resize a shell session's terminal */
277
284
  resize: "extension_shell_resize",
278
285
  /** Close a shell session */
@@ -313,9 +320,9 @@ var MAIL_COMMANDS = {
313
320
  sendMessage: "extension_mail_send_message",
314
321
  /** Build RFC822 bytes without sending (for Drafts via APPEND) */
315
322
  buildRfc822: "extension_mail_build_rfc822",
316
- /** Start (or replace) a background poll watch for an account/mailbox */
323
+ /** Start (or replace) a background new-mail watch for an account/mailbox */
317
324
  startWatch: "extension_mail_start_watch",
318
- /** Stop a background poll watch */
325
+ /** Stop a background new-mail watch */
319
326
  stopWatch: "extension_mail_stop_watch"
320
327
  };
321
328
 
@@ -1229,9 +1236,44 @@ var SpacesAPI = class {
1229
1236
  };
1230
1237
 
1231
1238
  // src/api/shell.ts
1239
+ var NOT_SUPPORTED = 8e3;
1240
+ function isUnsupported(error) {
1241
+ if (error?.code === NOT_SUPPORTED) return true;
1242
+ return typeof error === "string" && /\bcommand (\S+ )?not found\b/i.test(error);
1243
+ }
1232
1244
  var ShellAPI = class {
1233
1245
  constructor(sdk) {
1234
1246
  this.sdk = sdk;
1247
+ /** `shell:output` events per session handed on but not yet acknowledged. */
1248
+ this.unacknowledged = /* @__PURE__ */ new Map();
1249
+ this.flushScheduled = false;
1250
+ /** The host does not know `extension_shell_ack` (it reads output without backpressure). */
1251
+ this.ackUnsupported = false;
1252
+ this.sdk.on(SHELL_EVENTS.OUTPUT, (event) => this.acknowledge(event));
1253
+ }
1254
+ /**
1255
+ * Backpressure: the host keeps reading a shell's output only while this frame has few
1256
+ * events open, so a shell that writes fast waits instead of flooding the page. The SDK
1257
+ * acknowledges every event once the listeners have had it, in one request per session and
1258
+ * task.
1259
+ */
1260
+ acknowledge(event) {
1261
+ const sessionId = event.data?.sessionId;
1262
+ if (this.ackUnsupported || typeof sessionId !== "string") return;
1263
+ this.unacknowledged.set(sessionId, (this.unacknowledged.get(sessionId) ?? 0) + 1);
1264
+ if (this.flushScheduled) return;
1265
+ this.flushScheduled = true;
1266
+ queueMicrotask(() => this.flushAcknowledgements());
1267
+ }
1268
+ flushAcknowledgements() {
1269
+ this.flushScheduled = false;
1270
+ const counts = [...this.unacknowledged];
1271
+ this.unacknowledged.clear();
1272
+ for (const [sessionId, count] of counts) {
1273
+ this.sdk.request(SHELL_COMMANDS.ack, { sessionId, count }).catch((error) => {
1274
+ if (isUnsupported(error)) this.ackUnsupported = true;
1275
+ });
1276
+ }
1235
1277
  }
1236
1278
  /**
1237
1279
  * List available shell environments on the host system.
@@ -1447,22 +1489,29 @@ var MailAPI = class {
1447
1489
  });
1448
1490
  }
1449
1491
  /**
1450
- * Start (or replace) a background poll watch for `accountId`/`mailboxName`.
1451
- * The host resolves credentials itself from `accountId` — no `ImapConfig`
1452
- * is passed in. Requires `mail` permission with action `poll` on the
1453
- * account's IMAP host (prompted on first call, same as `fetch`/`send`).
1492
+ * Start (or replace) a background watch for `accountId`/`mailboxName`.
1493
+ * Requires `mail` permission with action `poll` on the account's IMAP
1494
+ * host (`imap.host` when passed; prompted on first call, same as
1495
+ * `fetch`/`send`).
1496
+ *
1497
+ * Pass the account's `imap` config, as for every other mail call: the host
1498
+ * keeps the credentials in memory for as long as the watch runs and never
1499
+ * stores them. Hosts that wait with IMAP IDLE are told about new mail by the
1500
+ * server; `intervalSeconds` (clamped host-side to [30, 3600]) is the polling
1501
+ * interval for servers without IDLE. Listen for results via `onNewMessages`.
1454
1502
  *
1455
- * `intervalSeconds` is clamped host-side to [30, 3600]. Listen for
1456
- * results via `onNewMessages`.
1503
+ * `imap` is optional for hosts that resolve the credentials themselves from
1504
+ * `accountId`; holzi requires it.
1457
1505
  */
1458
- async startWatchingAsync(accountId, mailboxName, intervalSeconds) {
1506
+ async startWatchingAsync(accountId, mailboxName, intervalSeconds, imap) {
1459
1507
  return this.client.request(MAIL_COMMANDS.startWatch, {
1460
1508
  accountId,
1461
1509
  mailboxName,
1462
- intervalSeconds
1510
+ intervalSeconds,
1511
+ imap
1463
1512
  });
1464
1513
  }
1465
- /** Stop a background poll watch previously started with `startWatchingAsync`. */
1514
+ /** Stop a background watch previously started with `startWatchingAsync`. */
1466
1515
  async stopWatchingAsync(accountId, mailboxName) {
1467
1516
  return this.client.request(MAIL_COMMANDS.stopWatch, {
1468
1517
  accountId,
@@ -1515,6 +1564,32 @@ var NotificationsAPI = class {
1515
1564
  }
1516
1565
  };
1517
1566
 
1567
+ // src/api/tab.ts
1568
+ var TabAPI = class {
1569
+ constructor(client) {
1570
+ this.client = client;
1571
+ }
1572
+ /**
1573
+ * Mark the tab as wanting the user's attention (`true`), e.g. for unread
1574
+ * content, or clear the mark (`false`).
1575
+ */
1576
+ async requestAttention(active) {
1577
+ await this.client.request(EXTENSION_COMMANDS.tabAttention, { active });
1578
+ }
1579
+ };
1580
+
1581
+ // src/api/dialog.ts
1582
+ var DialogAPI = class {
1583
+ constructor(client) {
1584
+ this.client = client;
1585
+ }
1586
+ /** Asks the user; resolves `true` for confirm, `false` for cancel or when the dialog is closed. */
1587
+ async confirm(options) {
1588
+ const answer = await this.client.request(EXTENSION_COMMANDS.dialogConfirm, { ...options }, { timeout: null });
1589
+ return answer === true;
1590
+ }
1591
+ };
1592
+
1518
1593
  // src/messages.ts
1519
1594
  var HAEXSPACE_MESSAGE_TYPES = {
1520
1595
  /** Debug message for development/troubleshooting */
@@ -1840,6 +1915,10 @@ function waitForHostPortAsync(log) {
1840
1915
  const handler = (event) => {
1841
1916
  const type = event.data?.type;
1842
1917
  if (type !== HAEXSPACE_MESSAGE_TYPES.PORT_INIT) return;
1918
+ if (event.source !== window.parent) {
1919
+ log("PORT_INIT from a window other than the parent \u2014 ignoring");
1920
+ return;
1921
+ }
1843
1922
  const port = event.ports[0];
1844
1923
  if (!port) {
1845
1924
  log("PORT_INIT received but event.ports is empty \u2014 ignoring");
@@ -1876,7 +1955,7 @@ postMessage error: ${e}`);
1876
1955
  function generateRequestId(counter) {
1877
1956
  return `req_${counter}`;
1878
1957
  }
1879
- function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port) {
1958
+ function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port, timeoutMs = config.timeout) {
1880
1959
  if (!port) {
1881
1960
  return Promise.reject(
1882
1961
  new HaexVaultSdkError(
@@ -1891,14 +1970,14 @@ function sendPostMessage(method, params, requestId, config, extensionInfo, pendi
1891
1970
  timestamp: Date.now()
1892
1971
  };
1893
1972
  return new Promise((resolve, reject) => {
1894
- const timeout = setTimeout(() => {
1973
+ const timeout = timeoutMs === null ? void 0 : setTimeout(() => {
1895
1974
  pendingRequests.delete(requestId);
1896
1975
  reject(
1897
1976
  new HaexVaultSdkError("TIMEOUT" /* TIMEOUT */, "errors.timeout", {
1898
- timeout: config.timeout
1977
+ timeout: timeoutMs
1899
1978
  })
1900
1979
  );
1901
- }, config.timeout);
1980
+ }, timeoutMs);
1902
1981
  pendingRequests.set(requestId, { resolve, reject, timeout });
1903
1982
  if (config.debug) {
1904
1983
  console.log("[SDK Debug] ========== Sending Request ==========");
@@ -2251,6 +2330,8 @@ var HaexVaultSdk = class {
2251
2330
  this.passwords = new PasswordsAPI(this);
2252
2331
  this.mail = new MailAPI(this);
2253
2332
  this.notifications = new NotificationsAPI(this);
2333
+ this.tab = new TabAPI(this);
2334
+ this.dialog = new DialogAPI(this);
2254
2335
  installConsoleForwarding(this.config.debug);
2255
2336
  this.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, (event) => {
2256
2337
  const data = event.data;
@@ -2406,7 +2487,7 @@ var HaexVaultSdk = class {
2406
2487
  // ==========================================================================
2407
2488
  // Communication
2408
2489
  // ==========================================================================
2409
- async request(method, params) {
2490
+ async request(method, params, options) {
2410
2491
  const resolvedParams = params ?? {};
2411
2492
  const send = () => {
2412
2493
  if (this.isNativeWindow && hasTauri()) {
@@ -2425,7 +2506,8 @@ var HaexVaultSdk = class {
2425
2506
  this.config,
2426
2507
  this._extensionInfo,
2427
2508
  this.pendingRequests,
2428
- this.hostPort
2509
+ this.hostPort,
2510
+ options?.timeout
2429
2511
  );
2430
2512
  };
2431
2513
  return withPermissionRetry(send, this.permissionWaiters, this.log.bind(this));