@haex-space/vault-sdk 4.5.0 → 4.7.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 (49) hide show
  1. package/README.md +40 -0
  2. package/dist/cli/index.mjs.map +1 -1
  3. package/dist/{client-Dw2uH1EM.d.ts → client-DS-j-fHu.d.mts} +179 -2
  4. package/dist/{client-D4VYF0bP.d.mts → client-DkVe1o-u.d.ts} +179 -2
  5. package/dist/{config-D_HXjsEV.d.mts → config-P_6DqTHl.d.mts} +2 -1
  6. package/dist/{config-D_HXjsEV.d.ts → config-P_6DqTHl.d.ts} +2 -1
  7. package/dist/index.d.mts +42 -8
  8. package/dist/index.d.ts +42 -8
  9. package/dist/index.js +143 -5
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +140 -5
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/node.d.mts +4 -3
  14. package/dist/node.d.ts +4 -3
  15. package/dist/node.mjs +1 -1
  16. package/dist/node.mjs.map +1 -1
  17. package/dist/nuxt.d.mts +2 -1
  18. package/dist/nuxt.d.ts +2 -1
  19. package/dist/nuxt.js +1 -1
  20. package/dist/nuxt.js.map +1 -1
  21. package/dist/react.d.mts +3 -2
  22. package/dist/react.d.ts +3 -2
  23. package/dist/react.js +139 -5
  24. package/dist/react.js.map +1 -1
  25. package/dist/react.mjs +138 -4
  26. package/dist/react.mjs.map +1 -1
  27. package/dist/runtime/nuxt.plugin.client.d.mts +4 -3
  28. package/dist/runtime/nuxt.plugin.client.d.ts +4 -3
  29. package/dist/runtime/nuxt.plugin.client.js +128 -1
  30. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  31. package/dist/runtime/nuxt.plugin.client.mjs +128 -1
  32. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  33. package/dist/svelte.d.mts +3 -2
  34. package/dist/svelte.d.ts +3 -2
  35. package/dist/svelte.js +139 -5
  36. package/dist/svelte.js.map +1 -1
  37. package/dist/svelte.mjs +138 -4
  38. package/dist/svelte.mjs.map +1 -1
  39. package/dist/{types-CYuW3glJ.d.mts → types-snPkjDCj.d.mts} +10 -1
  40. package/dist/{types-CYuW3glJ.d.ts → types-snPkjDCj.d.ts} +10 -1
  41. package/dist/vite.d.mts +2 -1
  42. package/dist/vite.d.ts +2 -1
  43. package/dist/vue.d.mts +3 -2
  44. package/dist/vue.d.ts +3 -2
  45. package/dist/vue.js +139 -5
  46. package/dist/vue.js.map +1 -1
  47. package/dist/vue.mjs +138 -4
  48. package/dist/vue.mjs.map +1 -1
  49. package/package.json +3 -3
@@ -23,6 +23,10 @@ var NOTIFICATION_EVENTS = {
23
23
  /** A click on one of this extension's notifications (body or action button). */
24
24
  CLICK: "haextension:notification:click"
25
25
  };
26
+ var MODEL_JOB_EVENTS = {
27
+ /** A job of this frame ended: completed, failed or cancelled. */
28
+ COMPLETED: "haextension:model-job:completed"
29
+ };
26
30
  var EXTERNAL_EVENTS = {
27
31
  /** External request from authorized client */
28
32
  REQUEST: "haextension:external:request",
@@ -326,6 +330,16 @@ var CONTACT_COMMANDS = {
326
330
  photo: "extension_contacts_photo"
327
331
  };
328
332
 
333
+ // src/commands/models.ts
334
+ var MODEL_COMMANDS = {
335
+ /** The models the user allowed to this extension, without addresses or keys */
336
+ list: "extension_model_list",
337
+ /** Starts a job; the result follows as an event */
338
+ start: "extension_model_job_start",
339
+ /** Cancels a running job of this frame */
340
+ cancel: "extension_model_job_cancel"
341
+ };
342
+
329
343
  // src/commands/mail.ts
330
344
  var MAIL_COMMANDS = {
331
345
  /** LIST mailboxes + optional STATUS counts */
@@ -336,6 +350,12 @@ var MAIL_COMMANDS = {
336
350
  fetchMessage: "extension_mail_fetch_message",
337
351
  /** Fetch a single attachment's bytes (base64) by part index */
338
352
  fetchAttachment: "extension_mail_fetch_attachment",
353
+ /** Search a mailbox on the server by criteria; answers UIDs, newest first */
354
+ search: "extension_mail_search",
355
+ /** CREATE a mailbox (reports whether it was already there) */
356
+ createMailbox: "extension_mail_create_mailbox",
357
+ /** Delete messages for good: `\Deleted` plus UID EXPUNGE of exactly those UIDs */
358
+ deleteMessages: "extension_mail_delete_messages",
339
359
  /** Set or unset IMAP flags on a UID set */
340
360
  setFlags: "extension_mail_set_flags",
341
361
  /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
@@ -1535,6 +1555,68 @@ var ContactsAPI = class {
1535
1555
  }
1536
1556
  };
1537
1557
 
1558
+ // src/api/models.ts
1559
+ var ModelsAPI = class {
1560
+ constructor(client) {
1561
+ this.client = client;
1562
+ }
1563
+ /** The models the user allowed to this extension; empty without any. */
1564
+ async listAsync() {
1565
+ const answer = await this.client.request(
1566
+ MODEL_COMMANDS.list,
1567
+ {}
1568
+ );
1569
+ return answer.models;
1570
+ }
1571
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
1572
+ async startAsync(job) {
1573
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
1574
+ job
1575
+ });
1576
+ return { jobId: answer.jobId };
1577
+ }
1578
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
1579
+ async cancelAsync(jobId) {
1580
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
1581
+ jobId
1582
+ });
1583
+ return answer.cancelled;
1584
+ }
1585
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
1586
+ onCompleted(handler) {
1587
+ const wrapped = (event) => {
1588
+ const data = event.data;
1589
+ if (data) handler(data);
1590
+ };
1591
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1592
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1593
+ }
1594
+ /**
1595
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
1596
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1597
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1598
+ * until then.
1599
+ */
1600
+ async runAsync(job) {
1601
+ const ended = /* @__PURE__ */ new Map();
1602
+ let waiting = null;
1603
+ const unsubscribe = this.onCompleted((completion) => {
1604
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1605
+ else ended.set(completion.jobId, completion);
1606
+ });
1607
+ try {
1608
+ const { jobId } = await this.startAsync(job);
1609
+ return await new Promise((resolve) => {
1610
+ const early = ended.get(jobId);
1611
+ if (early) resolve(early);
1612
+ else waiting = { jobId, resolve };
1613
+ });
1614
+ } finally {
1615
+ unsubscribe();
1616
+ }
1617
+ }
1618
+ };
1619
+
1538
1620
  // src/api/mail.ts
1539
1621
  var MailAPI = class {
1540
1622
  constructor(client) {
@@ -1584,6 +1666,45 @@ var MailAPI = class {
1584
1666
  partIndex
1585
1667
  });
1586
1668
  }
1669
+ /**
1670
+ * Search a whole mailbox on the server. Answers the UIDs of the newest `limit` hits (1 to 1000;
1671
+ * all that fit one answer when omitted), newest first, and the number of all hits. Fetch their
1672
+ * envelopes with `fetchEnvelopesAsync` and a `uidList` range.
1673
+ */
1674
+ async searchMessagesAsync(imap, mailbox, criteria, limit) {
1675
+ return this.client.request(MAIL_COMMANDS.search, {
1676
+ imap,
1677
+ mailbox,
1678
+ criteria,
1679
+ limit
1680
+ });
1681
+ }
1682
+ /**
1683
+ * Create a mailbox. Resolves to `false`, not an error, when it already existed. The name may
1684
+ * contain the server's hierarchy delimiter; `*` and `%` are not allowed.
1685
+ */
1686
+ async createMailboxAsync(imap, mailbox) {
1687
+ const { created } = await this.client.request(
1688
+ MAIL_COMMANDS.createMailbox,
1689
+ { imap, mailbox }
1690
+ );
1691
+ return created;
1692
+ }
1693
+ /**
1694
+ * Delete messages for good: flags exactly these UIDs `\Deleted` and expunges exactly them, so
1695
+ * other messages marked `\Deleted` stay. Refused with an error on a server without UIDPLUS,
1696
+ * before anything is marked. If the expunge fails after marking, the messages stay in the
1697
+ * mailbox flagged `\Deleted` and the call rejects; do not show them as deleted. At most 1000 UIDs
1698
+ * per call. For a message that can still be recovered, use `moveMessagesAsync` into the trash
1699
+ * instead.
1700
+ */
1701
+ async deleteMessagesAsync(imap, mailbox, uids) {
1702
+ return this.client.request(MAIL_COMMANDS.deleteMessages, {
1703
+ imap,
1704
+ mailbox,
1705
+ uids
1706
+ });
1707
+ }
1587
1708
  /**
1588
1709
  * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
1589
1710
  * mark messages as read; `add=false` removes the flag(s).
@@ -2568,6 +2689,7 @@ var AI_COMMANDS = {
2568
2689
  // src/client/permissionRetry.ts
2569
2690
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2570
2691
  var MAX_PERMISSION_RETRIES = 3;
2692
+ var MAX_PERMISSION_PROMPTS = 8;
2571
2693
  function permissionKey(resourceType, action, target) {
2572
2694
  return `${resourceType}:${action}:${target}`;
2573
2695
  }
@@ -2603,14 +2725,18 @@ function toDeniedError(error) {
2603
2725
  return { ...error, code: 1002 /* DENIED */ };
2604
2726
  }
2605
2727
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2728
+ const asked = /* @__PURE__ */ new Map();
2606
2729
  for (let attempt = 0; ; attempt++) {
2607
2730
  try {
2608
2731
  return await send();
2609
2732
  } catch (error) {
2610
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
2733
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2611
2734
  throw error;
2612
2735
  }
2613
2736
  const key = permissionKey(error.resourceType, error.action, error.target);
2737
+ const times = asked.get(key) ?? 0;
2738
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
2739
+ asked.set(key, times + 1);
2614
2740
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2615
2741
  const outcome = await registry.wait(key, timeoutMs);
2616
2742
  if (outcome === "granted") {
@@ -2679,6 +2805,7 @@ var HaexVaultSdk = class {
2679
2805
  this.shell = new ShellAPI(this);
2680
2806
  this.passwords = new PasswordsAPI(this);
2681
2807
  this.contacts = new ContactsAPI(this);
2808
+ this.models = new ModelsAPI(this);
2682
2809
  this.mail = new MailAPI(this);
2683
2810
  this.notifications = new NotificationsAPI(this);
2684
2811
  this.tab = new TabAPI(this);