@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
package/dist/index.js CHANGED
@@ -4,17 +4,22 @@ var sqliteProxy = require('drizzle-orm/sqlite-proxy');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
9
14
  };
10
15
  var __export = (target, all) => {
11
16
  for (var name in all)
12
17
  __defProp(target, name, { get: all[name], enumerable: true });
13
18
  };
14
19
 
15
- // node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.29_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
20
+ // node_modules/.pnpm/tsup@9.0.0_jiti@2.7.0_postcss@8.5.31_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
16
21
  var init_cjs_shims = __esm({
17
- "node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.29_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js"() {
22
+ "node_modules/.pnpm/tsup@9.0.0_jiti@2.7.0_postcss@8.5.31_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js"() {
18
23
  }
19
24
  });
20
25
 
@@ -758,6 +763,10 @@ var NOTIFICATION_EVENTS = {
758
763
  /** A click on one of this extension's notifications (body or action button). */
759
764
  CLICK: "haextension:notification:click"
760
765
  };
766
+ var MODEL_JOB_EVENTS = {
767
+ /** A job of this frame ended: completed, failed or cancelled. */
768
+ COMPLETED: "haextension:model-job:completed"
769
+ };
761
770
  var EXTERNAL_EVENTS = {
762
771
  /** External request from authorized client */
763
772
  REQUEST: "haextension:external:request",
@@ -1175,6 +1184,30 @@ var PASSWORD_COMMANDS = {
1175
1184
  delete: "extension_password_delete"
1176
1185
  };
1177
1186
 
1187
+ // src/commands/contacts.ts
1188
+ init_cjs_shims();
1189
+ var CONTACT_COMMANDS = {
1190
+ /** Contacts in scope, a page at a time, optionally of one group */
1191
+ list: "extension_contacts_list",
1192
+ /** One contact with all its values, by id */
1193
+ read: "extension_contacts_read",
1194
+ /** Contacts in scope whose name, organization, phone or e-mail matches */
1195
+ search: "extension_contacts_search",
1196
+ /** The JPEG of a contact's photo, by its hash */
1197
+ photo: "extension_contacts_photo"
1198
+ };
1199
+
1200
+ // src/commands/models.ts
1201
+ init_cjs_shims();
1202
+ var MODEL_COMMANDS = {
1203
+ /** The models the user allowed to this extension, without addresses or keys */
1204
+ list: "extension_model_list",
1205
+ /** Starts a job; the result follows as an event */
1206
+ start: "extension_model_job_start",
1207
+ /** Cancels a running job of this frame */
1208
+ cancel: "extension_model_job_cancel"
1209
+ };
1210
+
1178
1211
  // src/commands/mail.ts
1179
1212
  init_cjs_shims();
1180
1213
  var MAIL_COMMANDS = {
@@ -1226,6 +1259,8 @@ var TAURI_COMMANDS = {
1226
1259
  spaces: SPACE_COMMANDS,
1227
1260
  shell: SHELL_COMMANDS,
1228
1261
  passwords: PASSWORD_COMMANDS,
1262
+ contacts: CONTACT_COMMANDS,
1263
+ models: MODEL_COMMANDS,
1229
1264
  mail: MAIL_COMMANDS,
1230
1265
  notifications: NOTIFICATION_COMMANDS
1231
1266
  };
@@ -2364,6 +2399,107 @@ var PasswordsAPI = class {
2364
2399
  }
2365
2400
  };
2366
2401
 
2402
+ // src/api/contacts.ts
2403
+ init_cjs_shims();
2404
+ init_vaultKey();
2405
+ var ContactsAPI = class {
2406
+ constructor(client) {
2407
+ this.client = client;
2408
+ }
2409
+ /** One page of the contacts in scope, optionally of one group. */
2410
+ async listAsync(options = {}) {
2411
+ return this.client.request(CONTACT_COMMANDS.list, {
2412
+ ...options
2413
+ });
2414
+ }
2415
+ /** One contact with all its values. */
2416
+ async readAsync(id) {
2417
+ return this.client.request(CONTACT_COMMANDS.read, { id });
2418
+ }
2419
+ /**
2420
+ * The contacts in scope whose name, organization, phone number or e-mail
2421
+ * address contains `query`, regardless of case and accents. The host's
2422
+ * default limit is 20, its maximum 200.
2423
+ */
2424
+ async searchAsync(query, limit) {
2425
+ const answer = await this.client.request(
2426
+ CONTACT_COMMANDS.search,
2427
+ limit === void 0 ? { query } : { query, limit }
2428
+ );
2429
+ return answer.contacts;
2430
+ }
2431
+ /** The JPEG of a photo a readable contact uses, by its hash. */
2432
+ async photoAsync(hash) {
2433
+ const base64 = await this.client.request(CONTACT_COMMANDS.photo, {
2434
+ hash
2435
+ });
2436
+ return base64ToArrayBuffer(base64);
2437
+ }
2438
+ };
2439
+
2440
+ // src/api/models.ts
2441
+ init_cjs_shims();
2442
+ var ModelsAPI = class {
2443
+ constructor(client) {
2444
+ this.client = client;
2445
+ }
2446
+ /** The models the user allowed to this extension; empty without any. */
2447
+ async listAsync() {
2448
+ const answer = await this.client.request(
2449
+ MODEL_COMMANDS.list,
2450
+ {}
2451
+ );
2452
+ return answer.models;
2453
+ }
2454
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
2455
+ async startAsync(job) {
2456
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
2457
+ job
2458
+ });
2459
+ return { jobId: answer.jobId };
2460
+ }
2461
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
2462
+ async cancelAsync(jobId) {
2463
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
2464
+ jobId
2465
+ });
2466
+ return answer.cancelled;
2467
+ }
2468
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
2469
+ onCompleted(handler) {
2470
+ const wrapped = (event) => {
2471
+ const data = event.data;
2472
+ if (data) handler(data);
2473
+ };
2474
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2475
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2476
+ }
2477
+ /**
2478
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
2479
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2480
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2481
+ * until then.
2482
+ */
2483
+ async runAsync(job) {
2484
+ const ended = /* @__PURE__ */ new Map();
2485
+ let waiting = null;
2486
+ const unsubscribe = this.onCompleted((completion) => {
2487
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2488
+ else ended.set(completion.jobId, completion);
2489
+ });
2490
+ try {
2491
+ const { jobId } = await this.startAsync(job);
2492
+ return await new Promise((resolve) => {
2493
+ const early = ended.get(jobId);
2494
+ if (early) resolve(early);
2495
+ else waiting = { jobId, resolve };
2496
+ });
2497
+ } finally {
2498
+ unsubscribe();
2499
+ }
2500
+ }
2501
+ };
2502
+
2367
2503
  // src/api/mail.ts
2368
2504
  init_cjs_shims();
2369
2505
  var MailAPI = class {
@@ -3320,6 +3456,7 @@ var AI_COMMANDS = {
3320
3456
  init_cjs_shims();
3321
3457
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
3322
3458
  var MAX_PERMISSION_RETRIES = 3;
3459
+ var MAX_PERMISSION_PROMPTS = 8;
3323
3460
  function permissionKey(resourceType, action, target) {
3324
3461
  return `${resourceType}:${action}:${target}`;
3325
3462
  }
@@ -3355,14 +3492,18 @@ function toDeniedError(error) {
3355
3492
  return { ...error, code: 1002 /* DENIED */ };
3356
3493
  }
3357
3494
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
3495
+ const asked = /* @__PURE__ */ new Map();
3358
3496
  for (let attempt = 0; ; attempt++) {
3359
3497
  try {
3360
3498
  return await send();
3361
3499
  } catch (error) {
3362
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
3500
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3363
3501
  throw error;
3364
3502
  }
3365
3503
  const key = permissionKey(error.resourceType, error.action, error.target);
3504
+ const times = asked.get(key) ?? 0;
3505
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
3506
+ asked.set(key, times + 1);
3366
3507
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
3367
3508
  const outcome = await registry.wait(key, timeoutMs);
3368
3509
  if (outcome === "granted") {
@@ -3430,6 +3571,8 @@ var HaexVaultSdk = class {
3430
3571
  this.spaces = new SpacesAPI(this);
3431
3572
  this.shell = new ShellAPI(this);
3432
3573
  this.passwords = new PasswordsAPI(this);
3574
+ this.contacts = new ContactsAPI(this);
3575
+ this.models = new ModelsAPI(this);
3433
3576
  this.mail = new MailAPI(this);
3434
3577
  this.notifications = new NotificationsAPI(this);
3435
3578
  this.tab = new TabAPI(this);
@@ -4299,7 +4442,9 @@ function createHaexVaultSdk(config = {}) {
4299
4442
  return new HaexVaultSdk(config);
4300
4443
  }
4301
4444
 
4445
+ exports.CONTACT_COMMANDS = CONTACT_COMMANDS;
4302
4446
  exports.COSE_ALGORITHM = COSE_ALGORITHM;
4447
+ exports.ContactsAPI = ContactsAPI;
4303
4448
  exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
4304
4449
  exports.DatabaseAPI = DatabaseAPI;
4305
4450
  exports.DialogAPI = DialogAPI;
@@ -4320,7 +4465,10 @@ exports.LOCALSEND_EVENTS = LOCALSEND_EVENTS;
4320
4465
  exports.LocalSendAPI = LocalSendAPI;
4321
4466
  exports.MAIL_COMMANDS = MAIL_COMMANDS;
4322
4467
  exports.MAIL_EVENTS = MAIL_EVENTS;
4468
+ exports.MODEL_COMMANDS = MODEL_COMMANDS;
4469
+ exports.MODEL_JOB_EVENTS = MODEL_JOB_EVENTS;
4323
4470
  exports.MailAPI = MailAPI;
4471
+ exports.ModelsAPI = ModelsAPI;
4324
4472
  exports.NOTIFICATION_COMMANDS = NOTIFICATION_COMMANDS;
4325
4473
  exports.NOTIFICATION_EVENTS = NOTIFICATION_EVENTS;
4326
4474
  exports.NotificationsAPI = NotificationsAPI;