@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
@@ -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-BCUfRZvU.mjs';
4
- import { A as ApplicationContext } from '../types-DoNvKiW_.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-C44dqakd.js';
4
- import { A as ApplicationContext } from '../types-DoNvKiW_.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",
@@ -316,6 +320,28 @@ var PASSWORD_COMMANDS = {
316
320
  delete: "extension_password_delete"
317
321
  };
318
322
 
323
+ // src/commands/contacts.ts
324
+ var CONTACT_COMMANDS = {
325
+ /** Contacts in scope, a page at a time, optionally of one group */
326
+ list: "extension_contacts_list",
327
+ /** One contact with all its values, by id */
328
+ read: "extension_contacts_read",
329
+ /** Contacts in scope whose name, organization, phone or e-mail matches */
330
+ search: "extension_contacts_search",
331
+ /** The JPEG of a contact's photo, by its hash */
332
+ photo: "extension_contacts_photo"
333
+ };
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
+
319
345
  // src/commands/mail.ts
320
346
  var MAIL_COMMANDS = {
321
347
  /** LIST mailboxes + optional STATUS counts */
@@ -1489,6 +1515,104 @@ var PasswordsAPI = class {
1489
1515
  }
1490
1516
  };
1491
1517
 
1518
+ // src/api/contacts.ts
1519
+ var ContactsAPI = class {
1520
+ constructor(client) {
1521
+ this.client = client;
1522
+ }
1523
+ /** One page of the contacts in scope, optionally of one group. */
1524
+ async listAsync(options = {}) {
1525
+ return this.client.request(CONTACT_COMMANDS.list, {
1526
+ ...options
1527
+ });
1528
+ }
1529
+ /** One contact with all its values. */
1530
+ async readAsync(id) {
1531
+ return this.client.request(CONTACT_COMMANDS.read, { id });
1532
+ }
1533
+ /**
1534
+ * The contacts in scope whose name, organization, phone number or e-mail
1535
+ * address contains `query`, regardless of case and accents. The host's
1536
+ * default limit is 20, its maximum 200.
1537
+ */
1538
+ async searchAsync(query, limit) {
1539
+ const answer = await this.client.request(
1540
+ CONTACT_COMMANDS.search,
1541
+ limit === void 0 ? { query } : { query, limit }
1542
+ );
1543
+ return answer.contacts;
1544
+ }
1545
+ /** The JPEG of a photo a readable contact uses, by its hash. */
1546
+ async photoAsync(hash) {
1547
+ const base64 = await this.client.request(CONTACT_COMMANDS.photo, {
1548
+ hash
1549
+ });
1550
+ return base64ToArrayBuffer(base64);
1551
+ }
1552
+ };
1553
+
1554
+ // src/api/models.ts
1555
+ var ModelsAPI = class {
1556
+ constructor(client) {
1557
+ this.client = client;
1558
+ }
1559
+ /** The models the user allowed to this extension; empty without any. */
1560
+ async listAsync() {
1561
+ const answer = await this.client.request(
1562
+ MODEL_COMMANDS.list,
1563
+ {}
1564
+ );
1565
+ return answer.models;
1566
+ }
1567
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
1568
+ async startAsync(job) {
1569
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
1570
+ job
1571
+ });
1572
+ return { jobId: answer.jobId };
1573
+ }
1574
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
1575
+ async cancelAsync(jobId) {
1576
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
1577
+ jobId
1578
+ });
1579
+ return answer.cancelled;
1580
+ }
1581
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
1582
+ onCompleted(handler) {
1583
+ const wrapped = (event) => {
1584
+ const data = event.data;
1585
+ if (data) handler(data);
1586
+ };
1587
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1588
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1589
+ }
1590
+ /**
1591
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
1592
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1593
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1594
+ * until then.
1595
+ */
1596
+ async runAsync(job) {
1597
+ const ended = /* @__PURE__ */ new Map();
1598
+ let waiting = null;
1599
+ const unsubscribe = this.onCompleted((completion) => {
1600
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1601
+ else ended.set(completion.jobId, completion);
1602
+ });
1603
+ try {
1604
+ const { jobId } = await this.startAsync(job);
1605
+ return await new Promise((resolve) => {
1606
+ const early = ended.get(jobId);
1607
+ if (early) resolve(early);
1608
+ else waiting = { jobId, resolve };
1609
+ });
1610
+ } finally {
1611
+ unsubscribe();
1612
+ }
1613
+ }
1614
+ };
1615
+
1492
1616
  // src/api/mail.ts
1493
1617
  var MailAPI = class {
1494
1618
  constructor(client) {
@@ -2522,6 +2646,7 @@ var AI_COMMANDS = {
2522
2646
  // src/client/permissionRetry.ts
2523
2647
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2524
2648
  var MAX_PERMISSION_RETRIES = 3;
2649
+ var MAX_PERMISSION_PROMPTS = 8;
2525
2650
  function permissionKey(resourceType, action, target) {
2526
2651
  return `${resourceType}:${action}:${target}`;
2527
2652
  }
@@ -2557,14 +2682,18 @@ function toDeniedError(error) {
2557
2682
  return { ...error, code: 1002 /* DENIED */ };
2558
2683
  }
2559
2684
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2685
+ const asked = /* @__PURE__ */ new Map();
2560
2686
  for (let attempt = 0; ; attempt++) {
2561
2687
  try {
2562
2688
  return await send();
2563
2689
  } catch (error) {
2564
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
2690
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2565
2691
  throw error;
2566
2692
  }
2567
2693
  const key = permissionKey(error.resourceType, error.action, error.target);
2694
+ const times = asked.get(key) ?? 0;
2695
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
2696
+ asked.set(key, times + 1);
2568
2697
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2569
2698
  const outcome = await registry.wait(key, timeoutMs);
2570
2699
  if (outcome === "granted") {
@@ -2632,6 +2761,8 @@ var HaexVaultSdk = class {
2632
2761
  this.spaces = new SpacesAPI(this);
2633
2762
  this.shell = new ShellAPI(this);
2634
2763
  this.passwords = new PasswordsAPI(this);
2764
+ this.contacts = new ContactsAPI(this);
2765
+ this.models = new ModelsAPI(this);
2635
2766
  this.mail = new MailAPI(this);
2636
2767
  this.notifications = new NotificationsAPI(this);
2637
2768
  this.tab = new TabAPI(this);