@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
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.30_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.30_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",
@@ -1188,6 +1197,17 @@ var CONTACT_COMMANDS = {
1188
1197
  photo: "extension_contacts_photo"
1189
1198
  };
1190
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
+
1191
1211
  // src/commands/mail.ts
1192
1212
  init_cjs_shims();
1193
1213
  var MAIL_COMMANDS = {
@@ -1199,6 +1219,12 @@ var MAIL_COMMANDS = {
1199
1219
  fetchMessage: "extension_mail_fetch_message",
1200
1220
  /** Fetch a single attachment's bytes (base64) by part index */
1201
1221
  fetchAttachment: "extension_mail_fetch_attachment",
1222
+ /** Search a mailbox on the server by criteria; answers UIDs, newest first */
1223
+ search: "extension_mail_search",
1224
+ /** CREATE a mailbox (reports whether it was already there) */
1225
+ createMailbox: "extension_mail_create_mailbox",
1226
+ /** Delete messages for good: `\Deleted` plus UID EXPUNGE of exactly those UIDs */
1227
+ deleteMessages: "extension_mail_delete_messages",
1202
1228
  /** Set or unset IMAP flags on a UID set */
1203
1229
  setFlags: "extension_mail_set_flags",
1204
1230
  /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
@@ -1240,6 +1266,7 @@ var TAURI_COMMANDS = {
1240
1266
  shell: SHELL_COMMANDS,
1241
1267
  passwords: PASSWORD_COMMANDS,
1242
1268
  contacts: CONTACT_COMMANDS,
1269
+ models: MODEL_COMMANDS,
1243
1270
  mail: MAIL_COMMANDS,
1244
1271
  notifications: NOTIFICATION_COMMANDS
1245
1272
  };
@@ -2416,6 +2443,69 @@ var ContactsAPI = class {
2416
2443
  }
2417
2444
  };
2418
2445
 
2446
+ // src/api/models.ts
2447
+ init_cjs_shims();
2448
+ var ModelsAPI = class {
2449
+ constructor(client) {
2450
+ this.client = client;
2451
+ }
2452
+ /** The models the user allowed to this extension; empty without any. */
2453
+ async listAsync() {
2454
+ const answer = await this.client.request(
2455
+ MODEL_COMMANDS.list,
2456
+ {}
2457
+ );
2458
+ return answer.models;
2459
+ }
2460
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
2461
+ async startAsync(job) {
2462
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
2463
+ job
2464
+ });
2465
+ return { jobId: answer.jobId };
2466
+ }
2467
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
2468
+ async cancelAsync(jobId) {
2469
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
2470
+ jobId
2471
+ });
2472
+ return answer.cancelled;
2473
+ }
2474
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
2475
+ onCompleted(handler) {
2476
+ const wrapped = (event) => {
2477
+ const data = event.data;
2478
+ if (data) handler(data);
2479
+ };
2480
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2481
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2482
+ }
2483
+ /**
2484
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
2485
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2486
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2487
+ * until then.
2488
+ */
2489
+ async runAsync(job) {
2490
+ const ended = /* @__PURE__ */ new Map();
2491
+ let waiting = null;
2492
+ const unsubscribe = this.onCompleted((completion) => {
2493
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2494
+ else ended.set(completion.jobId, completion);
2495
+ });
2496
+ try {
2497
+ const { jobId } = await this.startAsync(job);
2498
+ return await new Promise((resolve) => {
2499
+ const early = ended.get(jobId);
2500
+ if (early) resolve(early);
2501
+ else waiting = { jobId, resolve };
2502
+ });
2503
+ } finally {
2504
+ unsubscribe();
2505
+ }
2506
+ }
2507
+ };
2508
+
2419
2509
  // src/api/mail.ts
2420
2510
  init_cjs_shims();
2421
2511
  var MailAPI = class {
@@ -2466,6 +2556,45 @@ var MailAPI = class {
2466
2556
  partIndex
2467
2557
  });
2468
2558
  }
2559
+ /**
2560
+ * Search a whole mailbox on the server. Answers the UIDs of the newest `limit` hits (1 to 1000;
2561
+ * all that fit one answer when omitted), newest first, and the number of all hits. Fetch their
2562
+ * envelopes with `fetchEnvelopesAsync` and a `uidList` range.
2563
+ */
2564
+ async searchMessagesAsync(imap, mailbox, criteria, limit) {
2565
+ return this.client.request(MAIL_COMMANDS.search, {
2566
+ imap,
2567
+ mailbox,
2568
+ criteria,
2569
+ limit
2570
+ });
2571
+ }
2572
+ /**
2573
+ * Create a mailbox. Resolves to `false`, not an error, when it already existed. The name may
2574
+ * contain the server's hierarchy delimiter; `*` and `%` are not allowed.
2575
+ */
2576
+ async createMailboxAsync(imap, mailbox) {
2577
+ const { created } = await this.client.request(
2578
+ MAIL_COMMANDS.createMailbox,
2579
+ { imap, mailbox }
2580
+ );
2581
+ return created;
2582
+ }
2583
+ /**
2584
+ * Delete messages for good: flags exactly these UIDs `\Deleted` and expunges exactly them, so
2585
+ * other messages marked `\Deleted` stay. Refused with an error on a server without UIDPLUS,
2586
+ * before anything is marked. If the expunge fails after marking, the messages stay in the
2587
+ * mailbox flagged `\Deleted` and the call rejects; do not show them as deleted. At most 1000 UIDs
2588
+ * per call. For a message that can still be recovered, use `moveMessagesAsync` into the trash
2589
+ * instead.
2590
+ */
2591
+ async deleteMessagesAsync(imap, mailbox, uids) {
2592
+ return this.client.request(MAIL_COMMANDS.deleteMessages, {
2593
+ imap,
2594
+ mailbox,
2595
+ uids
2596
+ });
2597
+ }
2469
2598
  /**
2470
2599
  * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
2471
2600
  * mark messages as read; `add=false` removes the flag(s).
@@ -3372,6 +3501,7 @@ var AI_COMMANDS = {
3372
3501
  init_cjs_shims();
3373
3502
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
3374
3503
  var MAX_PERMISSION_RETRIES = 3;
3504
+ var MAX_PERMISSION_PROMPTS = 8;
3375
3505
  function permissionKey(resourceType, action, target) {
3376
3506
  return `${resourceType}:${action}:${target}`;
3377
3507
  }
@@ -3407,14 +3537,18 @@ function toDeniedError(error) {
3407
3537
  return { ...error, code: 1002 /* DENIED */ };
3408
3538
  }
3409
3539
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
3540
+ const asked = /* @__PURE__ */ new Map();
3410
3541
  for (let attempt = 0; ; attempt++) {
3411
3542
  try {
3412
3543
  return await send();
3413
3544
  } catch (error) {
3414
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
3545
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3415
3546
  throw error;
3416
3547
  }
3417
3548
  const key = permissionKey(error.resourceType, error.action, error.target);
3549
+ const times = asked.get(key) ?? 0;
3550
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
3551
+ asked.set(key, times + 1);
3418
3552
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
3419
3553
  const outcome = await registry.wait(key, timeoutMs);
3420
3554
  if (outcome === "granted") {
@@ -3483,6 +3617,7 @@ var HaexVaultSdk = class {
3483
3617
  this.shell = new ShellAPI(this);
3484
3618
  this.passwords = new PasswordsAPI(this);
3485
3619
  this.contacts = new ContactsAPI(this);
3620
+ this.models = new ModelsAPI(this);
3486
3621
  this.mail = new MailAPI(this);
3487
3622
  this.notifications = new NotificationsAPI(this);
3488
3623
  this.tab = new TabAPI(this);
@@ -4375,7 +4510,10 @@ exports.LOCALSEND_EVENTS = LOCALSEND_EVENTS;
4375
4510
  exports.LocalSendAPI = LocalSendAPI;
4376
4511
  exports.MAIL_COMMANDS = MAIL_COMMANDS;
4377
4512
  exports.MAIL_EVENTS = MAIL_EVENTS;
4513
+ exports.MODEL_COMMANDS = MODEL_COMMANDS;
4514
+ exports.MODEL_JOB_EVENTS = MODEL_JOB_EVENTS;
4378
4515
  exports.MailAPI = MailAPI;
4516
+ exports.ModelsAPI = ModelsAPI;
4379
4517
  exports.NOTIFICATION_COMMANDS = NOTIFICATION_COMMANDS;
4380
4518
  exports.NOTIFICATION_EVENTS = NOTIFICATION_EVENTS;
4381
4519
  exports.NotificationsAPI = NotificationsAPI;