@haex-space/vault-sdk 4.4.0 → 4.6.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 +40 -0
  2. package/dist/cli/index.mjs.map +1 -1
  3. package/dist/{client-C44dqakd.d.ts → client-CcNhK76M.d.mts} +234 -2
  4. package/dist/{client-BCUfRZvU.d.mts → client-DIvNHfx-.d.ts} +234 -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/haex_bundle_bg.wasm +0 -0
  8. package/dist/index.d.mts +59 -7
  9. package/dist/index.d.ts +59 -7
  10. package/dist/index.js +153 -5
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +148 -5
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/node.d.mts +4 -3
  15. package/dist/node.d.ts +4 -3
  16. package/dist/node.mjs +1 -1
  17. package/dist/node.mjs.map +1 -1
  18. package/dist/nuxt.d.mts +2 -1
  19. package/dist/nuxt.d.ts +2 -1
  20. package/dist/nuxt.js +1 -1
  21. package/dist/nuxt.js.map +1 -1
  22. package/dist/nuxt.mjs.map +1 -1
  23. package/dist/react.d.mts +3 -2
  24. package/dist/react.d.ts +3 -2
  25. package/dist/react.js +146 -5
  26. package/dist/react.js.map +1 -1
  27. package/dist/react.mjs +145 -4
  28. package/dist/react.mjs.map +1 -1
  29. package/dist/runtime/nuxt.plugin.client.d.mts +4 -3
  30. package/dist/runtime/nuxt.plugin.client.d.ts +4 -3
  31. package/dist/runtime/nuxt.plugin.client.js +132 -1
  32. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  33. package/dist/runtime/nuxt.plugin.client.mjs +132 -1
  34. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  35. package/dist/svelte.d.mts +3 -2
  36. package/dist/svelte.d.ts +3 -2
  37. package/dist/svelte.js +146 -5
  38. package/dist/svelte.js.map +1 -1
  39. package/dist/svelte.mjs +145 -4
  40. package/dist/svelte.mjs.map +1 -1
  41. package/dist/{types-DoNvKiW_.d.mts → types-snPkjDCj.d.mts} +15 -1
  42. package/dist/{types-DoNvKiW_.d.ts → types-snPkjDCj.d.ts} +15 -1
  43. package/dist/vite.d.mts +2 -1
  44. package/dist/vite.d.ts +2 -1
  45. package/dist/vue.d.mts +3 -2
  46. package/dist/vue.d.ts +3 -2
  47. package/dist/vue.js +146 -5
  48. package/dist/vue.js.map +1 -1
  49. package/dist/vue.mjs +145 -4
  50. package/dist/vue.mjs.map +1 -1
  51. 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",
@@ -314,6 +318,28 @@ var PASSWORD_COMMANDS = {
314
318
  delete: "extension_password_delete"
315
319
  };
316
320
 
321
+ // src/commands/contacts.ts
322
+ var CONTACT_COMMANDS = {
323
+ /** Contacts in scope, a page at a time, optionally of one group */
324
+ list: "extension_contacts_list",
325
+ /** One contact with all its values, by id */
326
+ read: "extension_contacts_read",
327
+ /** Contacts in scope whose name, organization, phone or e-mail matches */
328
+ search: "extension_contacts_search",
329
+ /** The JPEG of a contact's photo, by its hash */
330
+ photo: "extension_contacts_photo"
331
+ };
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
+
317
343
  // src/commands/mail.ts
318
344
  var MAIL_COMMANDS = {
319
345
  /** LIST mailboxes + optional STATUS counts */
@@ -1487,6 +1513,104 @@ var PasswordsAPI = class {
1487
1513
  }
1488
1514
  };
1489
1515
 
1516
+ // src/api/contacts.ts
1517
+ var ContactsAPI = class {
1518
+ constructor(client) {
1519
+ this.client = client;
1520
+ }
1521
+ /** One page of the contacts in scope, optionally of one group. */
1522
+ async listAsync(options = {}) {
1523
+ return this.client.request(CONTACT_COMMANDS.list, {
1524
+ ...options
1525
+ });
1526
+ }
1527
+ /** One contact with all its values. */
1528
+ async readAsync(id) {
1529
+ return this.client.request(CONTACT_COMMANDS.read, { id });
1530
+ }
1531
+ /**
1532
+ * The contacts in scope whose name, organization, phone number or e-mail
1533
+ * address contains `query`, regardless of case and accents. The host's
1534
+ * default limit is 20, its maximum 200.
1535
+ */
1536
+ async searchAsync(query, limit) {
1537
+ const answer = await this.client.request(
1538
+ CONTACT_COMMANDS.search,
1539
+ limit === void 0 ? { query } : { query, limit }
1540
+ );
1541
+ return answer.contacts;
1542
+ }
1543
+ /** The JPEG of a photo a readable contact uses, by its hash. */
1544
+ async photoAsync(hash) {
1545
+ const base64 = await this.client.request(CONTACT_COMMANDS.photo, {
1546
+ hash
1547
+ });
1548
+ return base64ToArrayBuffer(base64);
1549
+ }
1550
+ };
1551
+
1552
+ // src/api/models.ts
1553
+ var ModelsAPI = class {
1554
+ constructor(client) {
1555
+ this.client = client;
1556
+ }
1557
+ /** The models the user allowed to this extension; empty without any. */
1558
+ async listAsync() {
1559
+ const answer = await this.client.request(
1560
+ MODEL_COMMANDS.list,
1561
+ {}
1562
+ );
1563
+ return answer.models;
1564
+ }
1565
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
1566
+ async startAsync(job) {
1567
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
1568
+ job
1569
+ });
1570
+ return { jobId: answer.jobId };
1571
+ }
1572
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
1573
+ async cancelAsync(jobId) {
1574
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
1575
+ jobId
1576
+ });
1577
+ return answer.cancelled;
1578
+ }
1579
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
1580
+ onCompleted(handler) {
1581
+ const wrapped = (event) => {
1582
+ const data = event.data;
1583
+ if (data) handler(data);
1584
+ };
1585
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1586
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1587
+ }
1588
+ /**
1589
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
1590
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1591
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1592
+ * until then.
1593
+ */
1594
+ async runAsync(job) {
1595
+ const ended = /* @__PURE__ */ new Map();
1596
+ let waiting = null;
1597
+ const unsubscribe = this.onCompleted((completion) => {
1598
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1599
+ else ended.set(completion.jobId, completion);
1600
+ });
1601
+ try {
1602
+ const { jobId } = await this.startAsync(job);
1603
+ return await new Promise((resolve) => {
1604
+ const early = ended.get(jobId);
1605
+ if (early) resolve(early);
1606
+ else waiting = { jobId, resolve };
1607
+ });
1608
+ } finally {
1609
+ unsubscribe();
1610
+ }
1611
+ }
1612
+ };
1613
+
1490
1614
  // src/api/mail.ts
1491
1615
  var MailAPI = class {
1492
1616
  constructor(client) {
@@ -2520,6 +2644,7 @@ var AI_COMMANDS = {
2520
2644
  // src/client/permissionRetry.ts
2521
2645
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2522
2646
  var MAX_PERMISSION_RETRIES = 3;
2647
+ var MAX_PERMISSION_PROMPTS = 8;
2523
2648
  function permissionKey(resourceType, action, target) {
2524
2649
  return `${resourceType}:${action}:${target}`;
2525
2650
  }
@@ -2555,14 +2680,18 @@ function toDeniedError(error) {
2555
2680
  return { ...error, code: 1002 /* DENIED */ };
2556
2681
  }
2557
2682
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2683
+ const asked = /* @__PURE__ */ new Map();
2558
2684
  for (let attempt = 0; ; attempt++) {
2559
2685
  try {
2560
2686
  return await send();
2561
2687
  } catch (error) {
2562
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
2688
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2563
2689
  throw error;
2564
2690
  }
2565
2691
  const key = permissionKey(error.resourceType, error.action, error.target);
2692
+ const times = asked.get(key) ?? 0;
2693
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
2694
+ asked.set(key, times + 1);
2566
2695
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2567
2696
  const outcome = await registry.wait(key, timeoutMs);
2568
2697
  if (outcome === "granted") {
@@ -2630,6 +2759,8 @@ var HaexVaultSdk = class {
2630
2759
  this.spaces = new SpacesAPI(this);
2631
2760
  this.shell = new ShellAPI(this);
2632
2761
  this.passwords = new PasswordsAPI(this);
2762
+ this.contacts = new ContactsAPI(this);
2763
+ this.models = new ModelsAPI(this);
2633
2764
  this.mail = new MailAPI(this);
2634
2765
  this.notifications = new NotificationsAPI(this);
2635
2766
  this.tab = new TabAPI(this);