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