@haex-space/vault-sdk 4.5.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.
- package/README.md +40 -0
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-Dw2uH1EM.d.ts → client-CcNhK76M.d.mts} +131 -2
- package/dist/{client-D4VYF0bP.d.mts → client-DIvNHfx-.d.ts} +131 -2
- package/dist/{config-D_HXjsEV.d.mts → config-P_6DqTHl.d.mts} +2 -1
- package/dist/{config-D_HXjsEV.d.ts → config-P_6DqTHl.d.ts} +2 -1
- package/dist/index.d.mts +32 -7
- package/dist/index.d.ts +32 -7
- package/dist/index.js +98 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -5
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +4 -3
- package/dist/node.d.ts +4 -3
- package/dist/node.mjs +1 -1
- package/dist/node.mjs.map +1 -1
- package/dist/nuxt.d.mts +2 -1
- package/dist/nuxt.d.ts +2 -1
- package/dist/nuxt.js +1 -1
- package/dist/nuxt.js.map +1 -1
- package/dist/react.d.mts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/react.js +94 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +93 -4
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.d.mts +4 -3
- package/dist/runtime/nuxt.plugin.client.d.ts +4 -3
- package/dist/runtime/nuxt.plugin.client.js +83 -1
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +83 -1
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +3 -2
- package/dist/svelte.d.ts +3 -2
- package/dist/svelte.js +94 -5
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +93 -4
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-CYuW3glJ.d.mts → types-snPkjDCj.d.mts} +10 -1
- package/dist/{types-CYuW3glJ.d.ts → types-snPkjDCj.d.ts} +10 -1
- package/dist/vite.d.mts +2 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vue.d.mts +3 -2
- package/dist/vue.d.ts +3 -2
- package/dist/vue.js +94 -5
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +93 -4
- package/dist/vue.mjs.map +1 -1
- 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 {
|
|
4
|
-
import {
|
|
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 {
|
|
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 {
|
|
4
|
-
import {
|
|
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 {
|
|
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",
|
|
@@ -328,6 +332,16 @@ var CONTACT_COMMANDS = {
|
|
|
328
332
|
photo: "extension_contacts_photo"
|
|
329
333
|
};
|
|
330
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
|
+
|
|
331
345
|
// src/commands/mail.ts
|
|
332
346
|
var MAIL_COMMANDS = {
|
|
333
347
|
/** LIST mailboxes + optional STATUS counts */
|
|
@@ -1537,6 +1551,68 @@ var ContactsAPI = class {
|
|
|
1537
1551
|
}
|
|
1538
1552
|
};
|
|
1539
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
|
+
|
|
1540
1616
|
// src/api/mail.ts
|
|
1541
1617
|
var MailAPI = class {
|
|
1542
1618
|
constructor(client) {
|
|
@@ -2570,6 +2646,7 @@ var AI_COMMANDS = {
|
|
|
2570
2646
|
// src/client/permissionRetry.ts
|
|
2571
2647
|
var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2572
2648
|
var MAX_PERMISSION_RETRIES = 3;
|
|
2649
|
+
var MAX_PERMISSION_PROMPTS = 8;
|
|
2573
2650
|
function permissionKey(resourceType, action, target) {
|
|
2574
2651
|
return `${resourceType}:${action}:${target}`;
|
|
2575
2652
|
}
|
|
@@ -2605,14 +2682,18 @@ function toDeniedError(error) {
|
|
|
2605
2682
|
return { ...error, code: 1002 /* DENIED */ };
|
|
2606
2683
|
}
|
|
2607
2684
|
async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
|
|
2685
|
+
const asked = /* @__PURE__ */ new Map();
|
|
2608
2686
|
for (let attempt = 0; ; attempt++) {
|
|
2609
2687
|
try {
|
|
2610
2688
|
return await send();
|
|
2611
2689
|
} catch (error) {
|
|
2612
|
-
if (!isPermissionPromptError(error) || attempt >=
|
|
2690
|
+
if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
|
|
2613
2691
|
throw error;
|
|
2614
2692
|
}
|
|
2615
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);
|
|
2616
2697
|
log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
|
|
2617
2698
|
const outcome = await registry.wait(key, timeoutMs);
|
|
2618
2699
|
if (outcome === "granted") {
|
|
@@ -2681,6 +2762,7 @@ var HaexVaultSdk = class {
|
|
|
2681
2762
|
this.shell = new ShellAPI(this);
|
|
2682
2763
|
this.passwords = new PasswordsAPI(this);
|
|
2683
2764
|
this.contacts = new ContactsAPI(this);
|
|
2765
|
+
this.models = new ModelsAPI(this);
|
|
2684
2766
|
this.mail = new MailAPI(this);
|
|
2685
2767
|
this.notifications = new NotificationsAPI(this);
|
|
2686
2768
|
this.tab = new TabAPI(this);
|