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