@arbidocs/sdk 0.5.76 → 0.5.77
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/dist/{browser-C1bFelgZ.d.cts → browser-BMQMb3DJ.d.cts} +62 -4
- package/dist/{browser-CkjCLAZL.d.ts → browser-CNfgaMuJ.d.ts} +62 -4
- package/dist/browser.cjs +119 -26
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +119 -26
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +119 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +119 -26
- package/dist/index.js.map +1 -1
- package/examples/human-review/package.json +1 -1
- package/examples/react-chat/package.json +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -10550,8 +10550,10 @@ __export(mail_exports, {
|
|
|
10550
10550
|
listFolders: () => listFolders,
|
|
10551
10551
|
listMailAccounts: () => listMailAccounts,
|
|
10552
10552
|
listMessages: () => listMessages,
|
|
10553
|
+
openDraftEditor: () => openDraftEditor,
|
|
10553
10554
|
saveDraft: () => saveDraft,
|
|
10554
10555
|
sendMessage: () => sendMessage,
|
|
10556
|
+
unlockMailCredentials: () => unlockMailCredentials,
|
|
10555
10557
|
unlockNativeMail: () => unlockNativeMail,
|
|
10556
10558
|
updateMessage: () => updateMessage
|
|
10557
10559
|
});
|
|
@@ -10648,6 +10650,47 @@ async function unlockNativeMail(mail, keys) {
|
|
|
10648
10650
|
secretKey.fill(0);
|
|
10649
10651
|
}
|
|
10650
10652
|
}
|
|
10653
|
+
async function unlockMailCredentials(mail, accountId, keys) {
|
|
10654
|
+
await client.initSodium();
|
|
10655
|
+
const secretKey = client.encryptionKeypairFromSigningKey(keys.signingPrivateKey).secretKey;
|
|
10656
|
+
const { sealed_credentials } = await json(
|
|
10657
|
+
mail(`${accountPath(accountId)}/sealed-credentials`)
|
|
10658
|
+
);
|
|
10659
|
+
const bytes = client.sealedBoxDecrypt(sealed_credentials, secretKey);
|
|
10660
|
+
try {
|
|
10661
|
+
const access = await client.sealKeyForSession(bytes, keys.serverSessionKey);
|
|
10662
|
+
await mail(`${accountPath(accountId)}/session-credentials`, {
|
|
10663
|
+
method: "POST",
|
|
10664
|
+
body: JSON.stringify({ access })
|
|
10665
|
+
});
|
|
10666
|
+
} finally {
|
|
10667
|
+
bytes.fill(0);
|
|
10668
|
+
secretKey.fill(0);
|
|
10669
|
+
}
|
|
10670
|
+
}
|
|
10671
|
+
async function openDraftEditor(mail, body, keys) {
|
|
10672
|
+
const open = (extra = {}) => json(
|
|
10673
|
+
mail("/drafts/editor", { method: "POST", body: JSON.stringify({ ...body, ...extra }) })
|
|
10674
|
+
);
|
|
10675
|
+
try {
|
|
10676
|
+
return await open();
|
|
10677
|
+
} catch (error) {
|
|
10678
|
+
const { status, apiError } = error;
|
|
10679
|
+
const locked = apiError?.detail;
|
|
10680
|
+
if (status !== 423 || !locked?.sealed_key || !locked.room_id) throw error;
|
|
10681
|
+
const { signingPrivateKey, serverSessionKey } = await keys();
|
|
10682
|
+
await client.initSodium();
|
|
10683
|
+
const secretKey = client.encryptionKeypairFromSigningKey(signingPrivateKey).secretKey;
|
|
10684
|
+
const key = client.sealedBoxDecrypt(locked.sealed_key, secretKey);
|
|
10685
|
+
try {
|
|
10686
|
+
const sealed = await client.sealKeyForSession(key, serverSessionKey);
|
|
10687
|
+
return await open({ room_id: locked.room_id, key: sealed });
|
|
10688
|
+
} finally {
|
|
10689
|
+
key.fill(0);
|
|
10690
|
+
secretKey.fill(0);
|
|
10691
|
+
}
|
|
10692
|
+
}
|
|
10693
|
+
}
|
|
10651
10694
|
function attachmentFromBytes(name, contentType, bytes) {
|
|
10652
10695
|
return {
|
|
10653
10696
|
id: "",
|
|
@@ -12916,34 +12959,84 @@ var Arbi = class {
|
|
|
12916
12959
|
* recovery. Pass `fetch` to the `mail` operations, e.g. `mail.listFolders(arbi.mail.fetch)`.
|
|
12917
12960
|
*/
|
|
12918
12961
|
mail = {
|
|
12919
|
-
/**
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
typeof body?.detail === "string" ? body.detail : "The mail request could not be completed",
|
|
12931
|
-
body,
|
|
12932
|
-
response.status
|
|
12933
|
-
);
|
|
12934
|
-
}
|
|
12935
|
-
return response;
|
|
12962
|
+
/**
|
|
12963
|
+
* Fetch a path under `/v1/mail`; rejects a non-2xx response with an `ArbiApiError` (`status`).
|
|
12964
|
+
* A read of the native inbox unlocks it first (`unlockNative`), so mail that arrived since is
|
|
12965
|
+
* readable too; `nativeUnlocked` skips that when the caller already unlocked it for this pass.
|
|
12966
|
+
* With no token yet (a new tab) the session is restored first; a 401 re-logs in and is sent
|
|
12967
|
+
* again once.
|
|
12968
|
+
*/
|
|
12969
|
+
fetch: (path5, init = {}, { nativeUnlocked = false } = {}) => this.recovering(async () => {
|
|
12970
|
+
const nativeRead = path5.startsWith("/accounts/native/") && (init.method ?? "GET").toUpperCase() !== "POST";
|
|
12971
|
+
if (nativeRead && !nativeUnlocked) await this.mail.unlockNative();
|
|
12972
|
+
return this.mailRequest(path5, init);
|
|
12936
12973
|
}),
|
|
12937
|
-
/**
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12974
|
+
/**
|
|
12975
|
+
* Unlock the signed-in user's native inbox for this server session (see `unlockNativeMail`).
|
|
12976
|
+
* Concurrent calls share one unlock.
|
|
12977
|
+
*/
|
|
12978
|
+
unlockNative: () => this.nativeUnlock ??= this.nativeMailKeys().then((keys) => unlockNativeMail(this.mail.fetch, keys)).finally(() => {
|
|
12979
|
+
this.nativeUnlock = null;
|
|
12980
|
+
}),
|
|
12981
|
+
/**
|
|
12982
|
+
* Hand this session what the server needs to read `account`: the native inbox's keys, a
|
|
12983
|
+
* Microsoft or Gmail account's connector tokens, an IMAP account's sealed credentials.
|
|
12984
|
+
*/
|
|
12985
|
+
unlockAccount: async (account) => {
|
|
12986
|
+
if (account.provider === "native") return this.mail.unlockNative();
|
|
12987
|
+
if (account.provider === "microsoft" || account.provider === "gmail") {
|
|
12988
|
+
await this.connectors.bridgeTokens({ vendor: account.provider });
|
|
12989
|
+
return;
|
|
12990
|
+
}
|
|
12991
|
+
await unlockMailCredentials(this.mail.fetch, account.id, await this.nativeMailKeys());
|
|
12992
|
+
},
|
|
12993
|
+
/**
|
|
12994
|
+
* Open a native draft's body in the Word editor, unlocking its room for this session with the
|
|
12995
|
+
* user's key when the server asks (see `openDraftEditor`).
|
|
12996
|
+
*/
|
|
12997
|
+
openDraftEditor: (body) => openDraftEditor(this.mail.fetch, body, () => this.nativeMailKeys())
|
|
12946
12998
|
};
|
|
12999
|
+
/** The native inbox unlock in flight (`mail.unlockNative`). */
|
|
13000
|
+
nativeUnlock = null;
|
|
13001
|
+
/** One request under `/v1/mail` on the session's token (see `mail.fetch`). */
|
|
13002
|
+
async mailRequest(path5, init) {
|
|
13003
|
+
const client = this.requireClient();
|
|
13004
|
+
let token = client.session.getState().accessToken;
|
|
13005
|
+
if (!token) token = await client.auth.relogin();
|
|
13006
|
+
if (!token) throw new ArbiError("Sign in again to restore your session");
|
|
13007
|
+
const send = client.http?.fetch ?? globalThis.fetch;
|
|
13008
|
+
const request = (bearer) => {
|
|
13009
|
+
const headers = new Headers(init.headers);
|
|
13010
|
+
headers.set("Authorization", `Bearer ${bearer}`);
|
|
13011
|
+
if (init.body && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
13012
|
+
return send(`${this.options.url}/v1/mail${path5}`, { ...init, headers });
|
|
13013
|
+
};
|
|
13014
|
+
let response = await request(token);
|
|
13015
|
+
if (response.status === 401) {
|
|
13016
|
+
const refreshed = await client.auth.relogin();
|
|
13017
|
+
if (refreshed) response = await request(refreshed);
|
|
13018
|
+
}
|
|
13019
|
+
if (!response.ok) {
|
|
13020
|
+
const body = await response.json().catch(() => null);
|
|
13021
|
+
throw new ArbiApiError(
|
|
13022
|
+
typeof body?.detail === "string" ? body.detail : "The mail request could not be completed",
|
|
13023
|
+
body,
|
|
13024
|
+
response.status
|
|
13025
|
+
);
|
|
13026
|
+
}
|
|
13027
|
+
return response;
|
|
13028
|
+
}
|
|
13029
|
+
/**
|
|
13030
|
+
* The keys that unlock the user's mail for this server session: the session's key (current after
|
|
13031
|
+
* a re-login) and the identity key (the login's, or the one kept on this device).
|
|
13032
|
+
*/
|
|
13033
|
+
async nativeMailKeys() {
|
|
13034
|
+
const client = this.requireClient();
|
|
13035
|
+
const serverSessionKey = client.session.getState().serverSessionKey ?? this.loginResult?.serverSessionKey ?? null;
|
|
13036
|
+
const signingPrivateKey = this.loginResult?.signingPrivateKey ?? (await client.storage.getSession().catch(() => null))?.signingPrivateKey;
|
|
13037
|
+
if (!serverSessionKey || !signingPrivateKey) throw new ArbiError("Sign in to unlock your inbox");
|
|
13038
|
+
return { signingPrivateKey, serverSessionKey };
|
|
13039
|
+
}
|
|
12947
13040
|
// ── Secure mail ─────────────────────────────────────────────────────
|
|
12948
13041
|
/**
|
|
12949
13042
|
* Mail to anyone, sealed in this browser under a key that travels only in the link's fragment
|