@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.mjs CHANGED
@@ -4,15 +4,20 @@ import { drizzle } from '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
  var init_esm_shims = __esm({
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/esm_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/esm_shims.js"() {
16
21
  }
17
22
  });
18
23
 
@@ -756,6 +761,10 @@ var NOTIFICATION_EVENTS = {
756
761
  /** A click on one of this extension's notifications (body or action button). */
757
762
  CLICK: "haextension:notification:click"
758
763
  };
764
+ var MODEL_JOB_EVENTS = {
765
+ /** A job of this frame ended: completed, failed or cancelled. */
766
+ COMPLETED: "haextension:model-job:completed"
767
+ };
759
768
  var EXTERNAL_EVENTS = {
760
769
  /** External request from authorized client */
761
770
  REQUEST: "haextension:external:request",
@@ -1186,6 +1195,17 @@ var CONTACT_COMMANDS = {
1186
1195
  photo: "extension_contacts_photo"
1187
1196
  };
1188
1197
 
1198
+ // src/commands/models.ts
1199
+ init_esm_shims();
1200
+ var MODEL_COMMANDS = {
1201
+ /** The models the user allowed to this extension, without addresses or keys */
1202
+ list: "extension_model_list",
1203
+ /** Starts a job; the result follows as an event */
1204
+ start: "extension_model_job_start",
1205
+ /** Cancels a running job of this frame */
1206
+ cancel: "extension_model_job_cancel"
1207
+ };
1208
+
1189
1209
  // src/commands/mail.ts
1190
1210
  init_esm_shims();
1191
1211
  var MAIL_COMMANDS = {
@@ -1197,6 +1217,12 @@ var MAIL_COMMANDS = {
1197
1217
  fetchMessage: "extension_mail_fetch_message",
1198
1218
  /** Fetch a single attachment's bytes (base64) by part index */
1199
1219
  fetchAttachment: "extension_mail_fetch_attachment",
1220
+ /** Search a mailbox on the server by criteria; answers UIDs, newest first */
1221
+ search: "extension_mail_search",
1222
+ /** CREATE a mailbox (reports whether it was already there) */
1223
+ createMailbox: "extension_mail_create_mailbox",
1224
+ /** Delete messages for good: `\Deleted` plus UID EXPUNGE of exactly those UIDs */
1225
+ deleteMessages: "extension_mail_delete_messages",
1200
1226
  /** Set or unset IMAP flags on a UID set */
1201
1227
  setFlags: "extension_mail_set_flags",
1202
1228
  /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
@@ -1238,6 +1264,7 @@ var TAURI_COMMANDS = {
1238
1264
  shell: SHELL_COMMANDS,
1239
1265
  passwords: PASSWORD_COMMANDS,
1240
1266
  contacts: CONTACT_COMMANDS,
1267
+ models: MODEL_COMMANDS,
1241
1268
  mail: MAIL_COMMANDS,
1242
1269
  notifications: NOTIFICATION_COMMANDS
1243
1270
  };
@@ -2414,6 +2441,69 @@ var ContactsAPI = class {
2414
2441
  }
2415
2442
  };
2416
2443
 
2444
+ // src/api/models.ts
2445
+ init_esm_shims();
2446
+ var ModelsAPI = class {
2447
+ constructor(client) {
2448
+ this.client = client;
2449
+ }
2450
+ /** The models the user allowed to this extension; empty without any. */
2451
+ async listAsync() {
2452
+ const answer = await this.client.request(
2453
+ MODEL_COMMANDS.list,
2454
+ {}
2455
+ );
2456
+ return answer.models;
2457
+ }
2458
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
2459
+ async startAsync(job) {
2460
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
2461
+ job
2462
+ });
2463
+ return { jobId: answer.jobId };
2464
+ }
2465
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
2466
+ async cancelAsync(jobId) {
2467
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
2468
+ jobId
2469
+ });
2470
+ return answer.cancelled;
2471
+ }
2472
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
2473
+ onCompleted(handler) {
2474
+ const wrapped = (event) => {
2475
+ const data = event.data;
2476
+ if (data) handler(data);
2477
+ };
2478
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2479
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2480
+ }
2481
+ /**
2482
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
2483
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2484
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2485
+ * until then.
2486
+ */
2487
+ async runAsync(job) {
2488
+ const ended = /* @__PURE__ */ new Map();
2489
+ let waiting = null;
2490
+ const unsubscribe = this.onCompleted((completion) => {
2491
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2492
+ else ended.set(completion.jobId, completion);
2493
+ });
2494
+ try {
2495
+ const { jobId } = await this.startAsync(job);
2496
+ return await new Promise((resolve) => {
2497
+ const early = ended.get(jobId);
2498
+ if (early) resolve(early);
2499
+ else waiting = { jobId, resolve };
2500
+ });
2501
+ } finally {
2502
+ unsubscribe();
2503
+ }
2504
+ }
2505
+ };
2506
+
2417
2507
  // src/api/mail.ts
2418
2508
  init_esm_shims();
2419
2509
  var MailAPI = class {
@@ -2464,6 +2554,45 @@ var MailAPI = class {
2464
2554
  partIndex
2465
2555
  });
2466
2556
  }
2557
+ /**
2558
+ * Search a whole mailbox on the server. Answers the UIDs of the newest `limit` hits (1 to 1000;
2559
+ * all that fit one answer when omitted), newest first, and the number of all hits. Fetch their
2560
+ * envelopes with `fetchEnvelopesAsync` and a `uidList` range.
2561
+ */
2562
+ async searchMessagesAsync(imap, mailbox, criteria, limit) {
2563
+ return this.client.request(MAIL_COMMANDS.search, {
2564
+ imap,
2565
+ mailbox,
2566
+ criteria,
2567
+ limit
2568
+ });
2569
+ }
2570
+ /**
2571
+ * Create a mailbox. Resolves to `false`, not an error, when it already existed. The name may
2572
+ * contain the server's hierarchy delimiter; `*` and `%` are not allowed.
2573
+ */
2574
+ async createMailboxAsync(imap, mailbox) {
2575
+ const { created } = await this.client.request(
2576
+ MAIL_COMMANDS.createMailbox,
2577
+ { imap, mailbox }
2578
+ );
2579
+ return created;
2580
+ }
2581
+ /**
2582
+ * Delete messages for good: flags exactly these UIDs `\Deleted` and expunges exactly them, so
2583
+ * other messages marked `\Deleted` stay. Refused with an error on a server without UIDPLUS,
2584
+ * before anything is marked. If the expunge fails after marking, the messages stay in the
2585
+ * mailbox flagged `\Deleted` and the call rejects; do not show them as deleted. At most 1000 UIDs
2586
+ * per call. For a message that can still be recovered, use `moveMessagesAsync` into the trash
2587
+ * instead.
2588
+ */
2589
+ async deleteMessagesAsync(imap, mailbox, uids) {
2590
+ return this.client.request(MAIL_COMMANDS.deleteMessages, {
2591
+ imap,
2592
+ mailbox,
2593
+ uids
2594
+ });
2595
+ }
2467
2596
  /**
2468
2597
  * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
2469
2598
  * mark messages as read; `add=false` removes the flag(s).
@@ -3370,6 +3499,7 @@ var AI_COMMANDS = {
3370
3499
  init_esm_shims();
3371
3500
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
3372
3501
  var MAX_PERMISSION_RETRIES = 3;
3502
+ var MAX_PERMISSION_PROMPTS = 8;
3373
3503
  function permissionKey(resourceType, action, target) {
3374
3504
  return `${resourceType}:${action}:${target}`;
3375
3505
  }
@@ -3405,14 +3535,18 @@ function toDeniedError(error) {
3405
3535
  return { ...error, code: 1002 /* DENIED */ };
3406
3536
  }
3407
3537
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
3538
+ const asked = /* @__PURE__ */ new Map();
3408
3539
  for (let attempt = 0; ; attempt++) {
3409
3540
  try {
3410
3541
  return await send();
3411
3542
  } catch (error) {
3412
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
3543
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3413
3544
  throw error;
3414
3545
  }
3415
3546
  const key = permissionKey(error.resourceType, error.action, error.target);
3547
+ const times = asked.get(key) ?? 0;
3548
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
3549
+ asked.set(key, times + 1);
3416
3550
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
3417
3551
  const outcome = await registry.wait(key, timeoutMs);
3418
3552
  if (outcome === "granted") {
@@ -3481,6 +3615,7 @@ var HaexVaultSdk = class {
3481
3615
  this.shell = new ShellAPI(this);
3482
3616
  this.passwords = new PasswordsAPI(this);
3483
3617
  this.contacts = new ContactsAPI(this);
3618
+ this.models = new ModelsAPI(this);
3484
3619
  this.mail = new MailAPI(this);
3485
3620
  this.notifications = new NotificationsAPI(this);
3486
3621
  this.tab = new TabAPI(this);
@@ -4350,6 +4485,6 @@ function createHaexVaultSdk(config = {}) {
4350
4485
  return new HaexVaultSdk(config);
4351
4486
  }
4352
4487
 
4353
- export { CONTACT_COMMANDS, COSE_ALGORITHM, ContactsAPI, DEFAULT_TIMEOUT, DatabaseAPI, DialogAPI, ENCRYPTED_FOLDER_COMMANDS, EXTERNAL_EVENTS, EncryptedFoldersAPI, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, HostErrorCode, KEY_AGREEMENT_ALGO, KnownPath, LOCALSEND_EVENTS, LocalSendAPI, MAIL_COMMANDS, MAIL_EVENTS, MailAPI, NOTIFICATION_COMMANDS, NOTIFICATION_EVENTS, NotificationsAPI, PASSWORD_COMMANDS, PasswordsAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, SHELL_EVENTS, SIGNING_ALGO, SPACE_COMMANDS, ShellAPI, SpacesAPI, TABLE_SEPARATOR, TAURI_COMMANDS, TabAPI, ToolsAPI, WebAPI, arrayBufferToBase64, base58btcDecode, base58btcEncode, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptPrivateKeyAsync, decryptSpaceNameAsync, decryptString, decryptVaultKey, decryptVaultName, decryptWithPrivateKeyAsync, deriveKeyFromPassword, didKeyToPublicKeyAsync, encryptCrdtData, encryptPrivateKeyAsync, encryptSpaceNameAsync, encryptString, encryptVaultKey, encryptWithPublicKeyAsync, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, exportUserKeypairAsync, generateCredentialId, generateIdentityAsync, generatePasskeyPairAsync, generateSpaceKey, generateUserKeypairAsync, generateVaultKey, getTableName, importPrivateKeyAsync, importPrivateKeyForKeyAgreementAsync, importPublicKeyAsync, importPublicKeyForKeyAgreementAsync, importUserPrivateKeyAsync, importUserPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, publicKeyToDidKeyAsync, signClaimPresentationAsync, signRecordAsync, signSpaceChallengeAsync, signWithPasskeyAsync, unwrapKey, verifyClaimPresentationAsync, verifyRecordSignatureAsync, verifySpaceChallengeAsync, verifyWithPasskeyAsync, wrapKey };
4488
+ export { CONTACT_COMMANDS, COSE_ALGORITHM, ContactsAPI, DEFAULT_TIMEOUT, DatabaseAPI, DialogAPI, ENCRYPTED_FOLDER_COMMANDS, EXTERNAL_EVENTS, EncryptedFoldersAPI, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, HostErrorCode, KEY_AGREEMENT_ALGO, KnownPath, LOCALSEND_EVENTS, LocalSendAPI, MAIL_COMMANDS, MAIL_EVENTS, MODEL_COMMANDS, MODEL_JOB_EVENTS, MailAPI, ModelsAPI, NOTIFICATION_COMMANDS, NOTIFICATION_EVENTS, NotificationsAPI, PASSWORD_COMMANDS, PasswordsAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, SHELL_EVENTS, SIGNING_ALGO, SPACE_COMMANDS, ShellAPI, SpacesAPI, TABLE_SEPARATOR, TAURI_COMMANDS, TabAPI, ToolsAPI, WebAPI, arrayBufferToBase64, base58btcDecode, base58btcEncode, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptPrivateKeyAsync, decryptSpaceNameAsync, decryptString, decryptVaultKey, decryptVaultName, decryptWithPrivateKeyAsync, deriveKeyFromPassword, didKeyToPublicKeyAsync, encryptCrdtData, encryptPrivateKeyAsync, encryptSpaceNameAsync, encryptString, encryptVaultKey, encryptWithPublicKeyAsync, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, exportUserKeypairAsync, generateCredentialId, generateIdentityAsync, generatePasskeyPairAsync, generateSpaceKey, generateUserKeypairAsync, generateVaultKey, getTableName, importPrivateKeyAsync, importPrivateKeyForKeyAgreementAsync, importPublicKeyAsync, importPublicKeyForKeyAgreementAsync, importUserPrivateKeyAsync, importUserPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, publicKeyToDidKeyAsync, signClaimPresentationAsync, signRecordAsync, signSpaceChallengeAsync, signWithPasskeyAsync, unwrapKey, verifyClaimPresentationAsync, verifyRecordSignatureAsync, verifySpaceChallengeAsync, verifyWithPasskeyAsync, wrapKey };
4354
4489
  //# sourceMappingURL=index.mjs.map
4355
4490
  //# sourceMappingURL=index.mjs.map