@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.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.29_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",
@@ -1173,6 +1182,30 @@ var PASSWORD_COMMANDS = {
1173
1182
  delete: "extension_password_delete"
1174
1183
  };
1175
1184
 
1185
+ // src/commands/contacts.ts
1186
+ init_esm_shims();
1187
+ var CONTACT_COMMANDS = {
1188
+ /** Contacts in scope, a page at a time, optionally of one group */
1189
+ list: "extension_contacts_list",
1190
+ /** One contact with all its values, by id */
1191
+ read: "extension_contacts_read",
1192
+ /** Contacts in scope whose name, organization, phone or e-mail matches */
1193
+ search: "extension_contacts_search",
1194
+ /** The JPEG of a contact's photo, by its hash */
1195
+ photo: "extension_contacts_photo"
1196
+ };
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
+
1176
1209
  // src/commands/mail.ts
1177
1210
  init_esm_shims();
1178
1211
  var MAIL_COMMANDS = {
@@ -1224,6 +1257,8 @@ var TAURI_COMMANDS = {
1224
1257
  spaces: SPACE_COMMANDS,
1225
1258
  shell: SHELL_COMMANDS,
1226
1259
  passwords: PASSWORD_COMMANDS,
1260
+ contacts: CONTACT_COMMANDS,
1261
+ models: MODEL_COMMANDS,
1227
1262
  mail: MAIL_COMMANDS,
1228
1263
  notifications: NOTIFICATION_COMMANDS
1229
1264
  };
@@ -2362,6 +2397,107 @@ var PasswordsAPI = class {
2362
2397
  }
2363
2398
  };
2364
2399
 
2400
+ // src/api/contacts.ts
2401
+ init_esm_shims();
2402
+ init_vaultKey();
2403
+ var ContactsAPI = class {
2404
+ constructor(client) {
2405
+ this.client = client;
2406
+ }
2407
+ /** One page of the contacts in scope, optionally of one group. */
2408
+ async listAsync(options = {}) {
2409
+ return this.client.request(CONTACT_COMMANDS.list, {
2410
+ ...options
2411
+ });
2412
+ }
2413
+ /** One contact with all its values. */
2414
+ async readAsync(id) {
2415
+ return this.client.request(CONTACT_COMMANDS.read, { id });
2416
+ }
2417
+ /**
2418
+ * The contacts in scope whose name, organization, phone number or e-mail
2419
+ * address contains `query`, regardless of case and accents. The host's
2420
+ * default limit is 20, its maximum 200.
2421
+ */
2422
+ async searchAsync(query, limit) {
2423
+ const answer = await this.client.request(
2424
+ CONTACT_COMMANDS.search,
2425
+ limit === void 0 ? { query } : { query, limit }
2426
+ );
2427
+ return answer.contacts;
2428
+ }
2429
+ /** The JPEG of a photo a readable contact uses, by its hash. */
2430
+ async photoAsync(hash) {
2431
+ const base64 = await this.client.request(CONTACT_COMMANDS.photo, {
2432
+ hash
2433
+ });
2434
+ return base64ToArrayBuffer(base64);
2435
+ }
2436
+ };
2437
+
2438
+ // src/api/models.ts
2439
+ init_esm_shims();
2440
+ var ModelsAPI = class {
2441
+ constructor(client) {
2442
+ this.client = client;
2443
+ }
2444
+ /** The models the user allowed to this extension; empty without any. */
2445
+ async listAsync() {
2446
+ const answer = await this.client.request(
2447
+ MODEL_COMMANDS.list,
2448
+ {}
2449
+ );
2450
+ return answer.models;
2451
+ }
2452
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
2453
+ async startAsync(job) {
2454
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
2455
+ job
2456
+ });
2457
+ return { jobId: answer.jobId };
2458
+ }
2459
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
2460
+ async cancelAsync(jobId) {
2461
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
2462
+ jobId
2463
+ });
2464
+ return answer.cancelled;
2465
+ }
2466
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
2467
+ onCompleted(handler) {
2468
+ const wrapped = (event) => {
2469
+ const data = event.data;
2470
+ if (data) handler(data);
2471
+ };
2472
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2473
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2474
+ }
2475
+ /**
2476
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
2477
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2478
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2479
+ * until then.
2480
+ */
2481
+ async runAsync(job) {
2482
+ const ended = /* @__PURE__ */ new Map();
2483
+ let waiting = null;
2484
+ const unsubscribe = this.onCompleted((completion) => {
2485
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2486
+ else ended.set(completion.jobId, completion);
2487
+ });
2488
+ try {
2489
+ const { jobId } = await this.startAsync(job);
2490
+ return await new Promise((resolve) => {
2491
+ const early = ended.get(jobId);
2492
+ if (early) resolve(early);
2493
+ else waiting = { jobId, resolve };
2494
+ });
2495
+ } finally {
2496
+ unsubscribe();
2497
+ }
2498
+ }
2499
+ };
2500
+
2365
2501
  // src/api/mail.ts
2366
2502
  init_esm_shims();
2367
2503
  var MailAPI = class {
@@ -3318,6 +3454,7 @@ var AI_COMMANDS = {
3318
3454
  init_esm_shims();
3319
3455
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
3320
3456
  var MAX_PERMISSION_RETRIES = 3;
3457
+ var MAX_PERMISSION_PROMPTS = 8;
3321
3458
  function permissionKey(resourceType, action, target) {
3322
3459
  return `${resourceType}:${action}:${target}`;
3323
3460
  }
@@ -3353,14 +3490,18 @@ function toDeniedError(error) {
3353
3490
  return { ...error, code: 1002 /* DENIED */ };
3354
3491
  }
3355
3492
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
3493
+ const asked = /* @__PURE__ */ new Map();
3356
3494
  for (let attempt = 0; ; attempt++) {
3357
3495
  try {
3358
3496
  return await send();
3359
3497
  } catch (error) {
3360
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
3498
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3361
3499
  throw error;
3362
3500
  }
3363
3501
  const key = permissionKey(error.resourceType, error.action, error.target);
3502
+ const times = asked.get(key) ?? 0;
3503
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
3504
+ asked.set(key, times + 1);
3364
3505
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
3365
3506
  const outcome = await registry.wait(key, timeoutMs);
3366
3507
  if (outcome === "granted") {
@@ -3428,6 +3569,8 @@ var HaexVaultSdk = class {
3428
3569
  this.spaces = new SpacesAPI(this);
3429
3570
  this.shell = new ShellAPI(this);
3430
3571
  this.passwords = new PasswordsAPI(this);
3572
+ this.contacts = new ContactsAPI(this);
3573
+ this.models = new ModelsAPI(this);
3431
3574
  this.mail = new MailAPI(this);
3432
3575
  this.notifications = new NotificationsAPI(this);
3433
3576
  this.tab = new TabAPI(this);
@@ -4297,6 +4440,6 @@ function createHaexVaultSdk(config = {}) {
4297
4440
  return new HaexVaultSdk(config);
4298
4441
  }
4299
4442
 
4300
- export { COSE_ALGORITHM, 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 };
4443
+ 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 };
4301
4444
  //# sourceMappingURL=index.mjs.map
4302
4445
  //# sourceMappingURL=index.mjs.map