@arbidocs/sdk 0.4.84 → 0.4.86
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-uyIwS2cN.d.cts → browser-V51dp6kY.d.cts} +251 -117
- package/dist/{browser-uyIwS2cN.d.ts → browser-V51dp6kY.d.ts} +251 -117
- package/dist/browser.cjs +249 -180
- 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 +250 -181
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +249 -180
- 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 +250 -181
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5714,17 +5714,33 @@ function extractResponseText(response) {
|
|
|
5714
5714
|
// src/operations/tags.ts
|
|
5715
5715
|
var tags_exports = {};
|
|
5716
5716
|
__export(tags_exports, {
|
|
5717
|
+
FLAT_TAG_KINDS: () => FLAT_TAG_KINDS,
|
|
5717
5718
|
TAG_FIELD_TYPES: () => TAG_FIELD_TYPES,
|
|
5719
|
+
TAG_KINDS: () => TAG_KINDS,
|
|
5718
5720
|
createTag: () => createTag,
|
|
5719
5721
|
deleteTag: () => deleteTag,
|
|
5720
|
-
|
|
5722
|
+
getTagKind: () => getTagKind,
|
|
5723
|
+
kindFieldWrites: () => kindFieldWrites,
|
|
5724
|
+
listTagKinds: () => listTagKinds,
|
|
5721
5725
|
listTags: () => listTags,
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
tagMatrixColumns: () => tagMatrixColumns,
|
|
5726
|
+
mergeKindFieldDefinitions: () => mergeKindFieldDefinitions,
|
|
5727
|
+
setTagValues: () => setTagValues,
|
|
5725
5728
|
updateTag: () => updateTag,
|
|
5726
|
-
|
|
5729
|
+
updateTagKind: () => updateTagKind
|
|
5727
5730
|
});
|
|
5731
|
+
var withFields = (schema) => ({
|
|
5732
|
+
...schema,
|
|
5733
|
+
fields: schema.fields ?? []
|
|
5734
|
+
});
|
|
5735
|
+
var TAG_KINDS = [
|
|
5736
|
+
"label",
|
|
5737
|
+
"annotation",
|
|
5738
|
+
"issue",
|
|
5739
|
+
"person",
|
|
5740
|
+
"organisation",
|
|
5741
|
+
"search"
|
|
5742
|
+
];
|
|
5743
|
+
var FLAT_TAG_KINDS = ["issue", "person", "organisation"];
|
|
5728
5744
|
var TAG_FIELD_TYPES = [
|
|
5729
5745
|
"text",
|
|
5730
5746
|
"number",
|
|
@@ -5733,8 +5749,20 @@ var TAG_FIELD_TYPES = [
|
|
|
5733
5749
|
"select",
|
|
5734
5750
|
"person"
|
|
5735
5751
|
];
|
|
5736
|
-
async function listTags(arbi) {
|
|
5737
|
-
|
|
5752
|
+
async function listTags(arbi, query = {}) {
|
|
5753
|
+
const params = {};
|
|
5754
|
+
if (query.kind) params.kind = query.kind;
|
|
5755
|
+
if (query.parentId) params.parent = query.parentId;
|
|
5756
|
+
if (query.ids?.length) params.ids = query.ids;
|
|
5757
|
+
if (query.include?.length) params.include = query.include;
|
|
5758
|
+
if (query.linksLimit !== void 0) params.links_limit = query.linksLimit;
|
|
5759
|
+
return requireData(
|
|
5760
|
+
await arbi.fetch.GET(
|
|
5761
|
+
"/v1/tag/",
|
|
5762
|
+
Object.keys(params).length ? { params: { query: params } } : {}
|
|
5763
|
+
),
|
|
5764
|
+
"Failed to fetch tags"
|
|
5765
|
+
);
|
|
5738
5766
|
}
|
|
5739
5767
|
async function createTag(arbi, options) {
|
|
5740
5768
|
return requireData(
|
|
@@ -5744,8 +5772,8 @@ async function createTag(arbi, options) {
|
|
|
5744
5772
|
tag_type: options.tagType ?? { type: "checkbox", options: [] },
|
|
5745
5773
|
instruction: options.instruction ?? null,
|
|
5746
5774
|
shared: options.shared ?? false,
|
|
5775
|
+
...options.kind ? { kind: options.kind } : {},
|
|
5747
5776
|
...options.parentId ? { parent_ext_id: options.parentId } : {},
|
|
5748
|
-
...options.fields ? { fields: options.fields } : {},
|
|
5749
5777
|
...options.fieldValues ? { field_values: options.fieldValues } : {}
|
|
5750
5778
|
}
|
|
5751
5779
|
}),
|
|
@@ -5764,48 +5792,47 @@ async function updateTag(arbi, tagId, change) {
|
|
|
5764
5792
|
return requireData(
|
|
5765
5793
|
await arbi.fetch.PATCH("/v1/tag/{tag_ext_id}", {
|
|
5766
5794
|
params: { path: { tag_ext_id: tagId } },
|
|
5767
|
-
body:
|
|
5795
|
+
body: change
|
|
5768
5796
|
}),
|
|
5769
5797
|
"Failed to update tag"
|
|
5770
5798
|
);
|
|
5771
5799
|
}
|
|
5772
|
-
async function
|
|
5773
|
-
|
|
5774
|
-
if (change.fields) body.fields = change.fields;
|
|
5775
|
-
if (change.values) body.field_values = change.values;
|
|
5776
|
-
return updateTag(arbi, tagId, body);
|
|
5800
|
+
async function setTagValues(arbi, tagId, values) {
|
|
5801
|
+
return updateTag(arbi, tagId, { field_values: values });
|
|
5777
5802
|
}
|
|
5778
|
-
async function
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
return requireData(
|
|
5782
|
-
await arbi.fetch.GET("/v1/tag/matrix", { params: { query } }),
|
|
5783
|
-
"Failed to fetch the tag matrix"
|
|
5803
|
+
async function listTagKinds(arbi) {
|
|
5804
|
+
return requireData(await arbi.fetch.GET("/v1/tag/kinds"), "Failed to fetch tag kinds").map(
|
|
5805
|
+
withFields
|
|
5784
5806
|
);
|
|
5785
5807
|
}
|
|
5786
|
-
function
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
return columns;
|
|
5808
|
+
async function getTagKind(arbi, kind) {
|
|
5809
|
+
return withFields(
|
|
5810
|
+
requireData(
|
|
5811
|
+
await arbi.fetch.GET("/v1/tag/kinds/{kind}", { params: { path: { kind } } }),
|
|
5812
|
+
"Failed to fetch the tag kind"
|
|
5813
|
+
)
|
|
5814
|
+
);
|
|
5794
5815
|
}
|
|
5795
|
-
function
|
|
5796
|
-
return (
|
|
5816
|
+
async function updateTagKind(arbi, kind, fields) {
|
|
5817
|
+
return withFields(
|
|
5818
|
+
requireData(
|
|
5819
|
+
await arbi.fetch.PUT("/v1/tag/kinds/{kind}", {
|
|
5820
|
+
params: { path: { kind } },
|
|
5821
|
+
body: { fields }
|
|
5822
|
+
}),
|
|
5823
|
+
"Failed to update the tag kind"
|
|
5824
|
+
)
|
|
5825
|
+
);
|
|
5797
5826
|
}
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
const byName = new Map(
|
|
5827
|
+
var kindFieldWrites = (fields) => fields.map((f2) => ({ id: f2.id, name: f2.name, type: f2.type, options: f2.options ?? null }));
|
|
5828
|
+
function mergeKindFieldDefinitions(current, wanted, { keepOthers = false } = {}) {
|
|
5829
|
+
const byName = new Map(current.map((f2) => [f2.name.toLowerCase(), f2]));
|
|
5801
5830
|
const out = wanted.map((w2) => {
|
|
5802
5831
|
const old = w2.id ? void 0 : byName.get(w2.name.trim().toLowerCase());
|
|
5803
5832
|
return old ? { ...w2, id: old.id } : w2;
|
|
5804
5833
|
});
|
|
5805
5834
|
if (keepOthers) {
|
|
5806
|
-
for (const f2 of
|
|
5807
|
-
if (!out.some((w2) => w2.id === f2.id))
|
|
5808
|
-
out.push({ id: f2.id, name: f2.name, type: f2.type, options: f2.options ?? null });
|
|
5835
|
+
for (const f2 of kindFieldWrites(current)) if (!out.some((w2) => w2.id === f2.id)) out.push(f2);
|
|
5809
5836
|
}
|
|
5810
5837
|
return out;
|
|
5811
5838
|
}
|
|
@@ -7619,6 +7646,137 @@ async function remindFact(arbi, factId, options = {}) {
|
|
|
7619
7646
|
);
|
|
7620
7647
|
}
|
|
7621
7648
|
|
|
7649
|
+
// src/operations/mail.ts
|
|
7650
|
+
var mail_exports = {};
|
|
7651
|
+
__export(mail_exports, {
|
|
7652
|
+
NATIVE_ACCOUNT: () => NATIVE_ACCOUNT,
|
|
7653
|
+
attachmentFromBytes: () => attachmentFromBytes,
|
|
7654
|
+
claimNativeAlias: () => claimNativeAlias,
|
|
7655
|
+
createMailFetch: () => createMailFetch,
|
|
7656
|
+
downloadAttachment: () => downloadAttachment,
|
|
7657
|
+
getMailPolicy: () => getMailPolicy,
|
|
7658
|
+
getMessage: () => getMessage2,
|
|
7659
|
+
listFolders: () => listFolders,
|
|
7660
|
+
listMailAccounts: () => listMailAccounts,
|
|
7661
|
+
listMessages: () => listMessages,
|
|
7662
|
+
saveDraft: () => saveDraft,
|
|
7663
|
+
sendMessage: () => sendMessage,
|
|
7664
|
+
unlockNativeMail: () => unlockNativeMail,
|
|
7665
|
+
updateMessage: () => updateMessage
|
|
7666
|
+
});
|
|
7667
|
+
var NATIVE_ACCOUNT = "native";
|
|
7668
|
+
function createMailFetch(auth) {
|
|
7669
|
+
return (path4, init = {}) => authenticatedFetch({
|
|
7670
|
+
...auth,
|
|
7671
|
+
path: `/v1/mail${path4}`,
|
|
7672
|
+
method: init.method,
|
|
7673
|
+
body: init.body,
|
|
7674
|
+
headers: {
|
|
7675
|
+
...init.body ? { "Content-Type": "application/json" } : {},
|
|
7676
|
+
...init.headers
|
|
7677
|
+
}
|
|
7678
|
+
});
|
|
7679
|
+
}
|
|
7680
|
+
async function json(response) {
|
|
7681
|
+
return (await response).json();
|
|
7682
|
+
}
|
|
7683
|
+
var accountPath = (accountId) => `/accounts/${encodeURIComponent(accountId)}`;
|
|
7684
|
+
function getMailPolicy(mail) {
|
|
7685
|
+
return json(mail("/policy"));
|
|
7686
|
+
}
|
|
7687
|
+
function listMailAccounts(mail) {
|
|
7688
|
+
return json(mail("/accounts"));
|
|
7689
|
+
}
|
|
7690
|
+
async function claimNativeAlias(mail, alias) {
|
|
7691
|
+
const { email } = await json(
|
|
7692
|
+
mail("/native/alias", { method: "POST", body: JSON.stringify({ alias }) })
|
|
7693
|
+
);
|
|
7694
|
+
return email;
|
|
7695
|
+
}
|
|
7696
|
+
function listFolders(mail, accountId = NATIVE_ACCOUNT) {
|
|
7697
|
+
return json(mail(`${accountPath(accountId)}/folders`));
|
|
7698
|
+
}
|
|
7699
|
+
function listMessages(mail, options) {
|
|
7700
|
+
const params = new URLSearchParams({ folder_id: options.folderId });
|
|
7701
|
+
if (options.query) params.set("q", options.query);
|
|
7702
|
+
if (options.cursor) params.set("cursor", options.cursor);
|
|
7703
|
+
if (options.limit) params.set("limit", String(options.limit));
|
|
7704
|
+
return json(mail(`${accountPath(options.accountId ?? NATIVE_ACCOUNT)}/messages?${params}`));
|
|
7705
|
+
}
|
|
7706
|
+
function getMessage2(mail, messageId, accountId = NATIVE_ACCOUNT) {
|
|
7707
|
+
return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`));
|
|
7708
|
+
}
|
|
7709
|
+
async function downloadAttachment(mail, messageId, attachmentId, accountId = NATIVE_ACCOUNT) {
|
|
7710
|
+
const path4 = `${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`;
|
|
7711
|
+
return new Uint8Array(await (await mail(path4)).arrayBuffer());
|
|
7712
|
+
}
|
|
7713
|
+
async function updateMessage(mail, messageId, update, accountId = NATIVE_ACCOUNT) {
|
|
7714
|
+
await mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`, {
|
|
7715
|
+
method: "PATCH",
|
|
7716
|
+
body: JSON.stringify(update)
|
|
7717
|
+
});
|
|
7718
|
+
}
|
|
7719
|
+
function saveDraft(mail, compose, accountId = NATIVE_ACCOUNT) {
|
|
7720
|
+
return json(
|
|
7721
|
+
mail(`${accountPath(accountId)}/drafts`, { method: "POST", body: JSON.stringify(compose) })
|
|
7722
|
+
);
|
|
7723
|
+
}
|
|
7724
|
+
function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
|
|
7725
|
+
const body = { ...message, request_id: message.request_id ?? crypto.randomUUID() };
|
|
7726
|
+
return json(
|
|
7727
|
+
mail(`${accountPath(accountId)}/send`, { method: "POST", body: JSON.stringify(body) })
|
|
7728
|
+
);
|
|
7729
|
+
}
|
|
7730
|
+
async function unlockNativeMail(mail, keys) {
|
|
7731
|
+
await client.initSodium();
|
|
7732
|
+
const secretKey = client.deriveEncryptionKeypairFromSigning({
|
|
7733
|
+
publicKey: keys.signingPrivateKey.slice(32, 64),
|
|
7734
|
+
secretKey: keys.signingPrivateKey
|
|
7735
|
+
}).secretKey;
|
|
7736
|
+
try {
|
|
7737
|
+
let cursor = 0;
|
|
7738
|
+
while (cursor !== null) {
|
|
7739
|
+
const page = await json(
|
|
7740
|
+
mail(`/native/keys?cursor=${cursor}`)
|
|
7741
|
+
);
|
|
7742
|
+
const sealed = {};
|
|
7743
|
+
for (const [id, wrapped] of Object.entries(page.keys)) {
|
|
7744
|
+
const key = client.sealedBoxDecrypt(wrapped, secretKey);
|
|
7745
|
+
try {
|
|
7746
|
+
sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
|
|
7747
|
+
} finally {
|
|
7748
|
+
key.fill(0);
|
|
7749
|
+
}
|
|
7750
|
+
}
|
|
7751
|
+
if (Object.keys(sealed).length) {
|
|
7752
|
+
await mail("/native/session-keys", {
|
|
7753
|
+
method: "POST",
|
|
7754
|
+
body: JSON.stringify({ keys: sealed })
|
|
7755
|
+
});
|
|
7756
|
+
}
|
|
7757
|
+
cursor = page.next_cursor;
|
|
7758
|
+
}
|
|
7759
|
+
} finally {
|
|
7760
|
+
secretKey.fill(0);
|
|
7761
|
+
}
|
|
7762
|
+
}
|
|
7763
|
+
function attachmentFromBytes(name, contentType, bytes) {
|
|
7764
|
+
return {
|
|
7765
|
+
id: "",
|
|
7766
|
+
name,
|
|
7767
|
+
content_type: contentType,
|
|
7768
|
+
size: bytes.length,
|
|
7769
|
+
content_base64: bytesToBase642(bytes)
|
|
7770
|
+
};
|
|
7771
|
+
}
|
|
7772
|
+
function bytesToBase642(bytes) {
|
|
7773
|
+
let binary = "";
|
|
7774
|
+
for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
|
|
7775
|
+
binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
|
|
7776
|
+
}
|
|
7777
|
+
return btoa(binary);
|
|
7778
|
+
}
|
|
7779
|
+
|
|
7622
7780
|
// src/arbi.ts
|
|
7623
7781
|
function tokenExpiresWithin(token, seconds) {
|
|
7624
7782
|
const payload = token?.split(".")[1];
|
|
@@ -7981,25 +8139,22 @@ var Arbi = class {
|
|
|
7981
8139
|
return result;
|
|
7982
8140
|
},
|
|
7983
8141
|
/**
|
|
7984
|
-
* Change (or, after recovery, set) the master password
|
|
7985
|
-
*
|
|
7986
|
-
*
|
|
8142
|
+
* Change (or, after recovery, set) the master password. Omit `currentPassword` in recovery
|
|
8143
|
+
* mode. One request: the account identity is re-wrapped under the new password and nothing is
|
|
8144
|
+
* re-encrypted, so the session, the workspace keys and the recovery key all stay as they are.
|
|
7987
8145
|
*/
|
|
7988
8146
|
changePassword: async (params) => {
|
|
7989
8147
|
const client$1 = this.requireClient();
|
|
7990
8148
|
const lr2 = this.requireLogin();
|
|
7991
8149
|
const email = client$1.session.getState().userEmail ?? this.userProfile?.email;
|
|
7992
8150
|
if (!email) throw new ArbiError("The account email is unknown; sign in again.");
|
|
7993
|
-
|
|
7994
|
-
{ ...params, email,
|
|
8151
|
+
await client.changePassword(
|
|
8152
|
+
{ ...params, email, identitySecretKey: lr2.signingPrivateKey },
|
|
7995
8153
|
{
|
|
7996
8154
|
fetchClient: client$1.fetch,
|
|
7997
8155
|
deploymentDomain: this.getDeploymentDomain()
|
|
7998
8156
|
}
|
|
7999
8157
|
);
|
|
8000
|
-
this.loginResult = { ...lr2, signingPrivateKey: result.newSigningPrivateKey };
|
|
8001
|
-
this.wrappedKeys.clear();
|
|
8002
|
-
return result;
|
|
8003
8158
|
},
|
|
8004
8159
|
/** Close the account (soft delete) and sign out. Refused while a subscription is active. */
|
|
8005
8160
|
requestDeletion: async () => {
|
|
@@ -8269,6 +8424,39 @@ var Arbi = class {
|
|
|
8269
8424
|
return response;
|
|
8270
8425
|
})
|
|
8271
8426
|
};
|
|
8427
|
+
/**
|
|
8428
|
+
* Mail transport for `/v1/mail` (the native inbox and connected accounts), with normal session
|
|
8429
|
+
* recovery. Pass `fetch` to the `mail` operations, e.g. `mail.listFolders(arbi.mail.fetch)`.
|
|
8430
|
+
*/
|
|
8431
|
+
mail = {
|
|
8432
|
+
/** Fetch a path under `/v1/mail`; rejects a non-2xx response with an `ArbiApiError` (`status`). */
|
|
8433
|
+
fetch: (path4, init = {}) => this.recovering(async () => {
|
|
8434
|
+
const { baseUrl, accessToken } = this.getAuthHeaders();
|
|
8435
|
+
const headers = new Headers(init.headers);
|
|
8436
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
8437
|
+
if (init.body && !headers.has("Content-Type"))
|
|
8438
|
+
headers.set("Content-Type", "application/json");
|
|
8439
|
+
const response = await fetch(`${baseUrl}/v1/mail${path4}`, { ...init, headers });
|
|
8440
|
+
if (!response.ok) {
|
|
8441
|
+
const body = await response.json().catch(() => null);
|
|
8442
|
+
throw new ArbiApiError(
|
|
8443
|
+
typeof body?.detail === "string" ? body.detail : "The mail request could not be completed",
|
|
8444
|
+
body,
|
|
8445
|
+
response.status
|
|
8446
|
+
);
|
|
8447
|
+
}
|
|
8448
|
+
return response;
|
|
8449
|
+
}),
|
|
8450
|
+
/** Unlock the signed-in user's native inbox for this server session (see `unlockNativeMail`). */
|
|
8451
|
+
unlockNative: () => {
|
|
8452
|
+
const login = this.loginResult;
|
|
8453
|
+
if (!login) return Promise.reject(new ArbiError("Sign in to unlock your inbox"));
|
|
8454
|
+
return unlockNativeMail(this.mail.fetch, {
|
|
8455
|
+
signingPrivateKey: login.signingPrivateKey,
|
|
8456
|
+
serverSessionKey: login.serverSessionKey
|
|
8457
|
+
});
|
|
8458
|
+
}
|
|
8459
|
+
};
|
|
8272
8460
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
8273
8461
|
assistant = {
|
|
8274
8462
|
cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
|
|
@@ -8341,17 +8529,29 @@ var Arbi = class {
|
|
|
8341
8529
|
};
|
|
8342
8530
|
// ── Tags ──────────────────────────────────────────────────────────────
|
|
8343
8531
|
tags = {
|
|
8344
|
-
|
|
8532
|
+
/**
|
|
8533
|
+
* The workspace's tags, filtered (`kind`, `parentId`, `ids`) and with `include: ['links']`
|
|
8534
|
+
* each tag's documents, facts and threads: `list({ kind: 'issue', include: ['links'] })` is the
|
|
8535
|
+
* issue table's rows (its columns: `tagKinds.get('issue')`).
|
|
8536
|
+
*/
|
|
8537
|
+
list: (query) => listTags(this.requireClient(), query),
|
|
8345
8538
|
create: (options) => createTag(this.requireClient(), {
|
|
8346
8539
|
...options,
|
|
8347
8540
|
workspaceId: options.workspaceId ?? this.requireWorkspace()
|
|
8348
8541
|
}),
|
|
8349
8542
|
delete: (tagId) => deleteTag(this.requireClient(), tagId),
|
|
8350
8543
|
update: (tagId, change) => updateTag(this.requireClient(), tagId, change),
|
|
8351
|
-
/**
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8544
|
+
/** Merge-patch a tag's values for its kind's fields (`null` clears one). */
|
|
8545
|
+
setValues: (tagId, values) => setTagValues(this.requireClient(), tagId, values)
|
|
8546
|
+
};
|
|
8547
|
+
// ── Tag kinds: the workspace's fields per kind (a table's columns) ─────
|
|
8548
|
+
tagKinds = {
|
|
8549
|
+
/** Every kind's fields (the built-in ones where the workspace has not set its own). */
|
|
8550
|
+
list: () => listTagKinds(this.requireClient()),
|
|
8551
|
+
/** A kind's fields: the columns of a table of its tags. */
|
|
8552
|
+
get: (kind) => getTagKind(this.requireClient(), kind),
|
|
8553
|
+
/** Set a kind's fields in full (ids keep fields and their values; the rest are new). */
|
|
8554
|
+
update: (kind, fields) => updateTagKind(this.requireClient(), kind, fields)
|
|
8355
8555
|
};
|
|
8356
8556
|
// ── Document Tags ─────────────────────────────────────────────────────
|
|
8357
8557
|
doctags = {
|
|
@@ -9320,137 +9520,6 @@ async function uploadArchive(auth, archivePath, options) {
|
|
|
9320
9520
|
}
|
|
9321
9521
|
}
|
|
9322
9522
|
|
|
9323
|
-
// src/operations/mail.ts
|
|
9324
|
-
var mail_exports = {};
|
|
9325
|
-
__export(mail_exports, {
|
|
9326
|
-
NATIVE_ACCOUNT: () => NATIVE_ACCOUNT,
|
|
9327
|
-
attachmentFromBytes: () => attachmentFromBytes,
|
|
9328
|
-
claimNativeAlias: () => claimNativeAlias,
|
|
9329
|
-
createMailFetch: () => createMailFetch,
|
|
9330
|
-
downloadAttachment: () => downloadAttachment,
|
|
9331
|
-
getMailPolicy: () => getMailPolicy,
|
|
9332
|
-
getMessage: () => getMessage2,
|
|
9333
|
-
listFolders: () => listFolders,
|
|
9334
|
-
listMailAccounts: () => listMailAccounts,
|
|
9335
|
-
listMessages: () => listMessages,
|
|
9336
|
-
saveDraft: () => saveDraft,
|
|
9337
|
-
sendMessage: () => sendMessage,
|
|
9338
|
-
unlockNativeMail: () => unlockNativeMail,
|
|
9339
|
-
updateMessage: () => updateMessage
|
|
9340
|
-
});
|
|
9341
|
-
var NATIVE_ACCOUNT = "native";
|
|
9342
|
-
function createMailFetch(auth) {
|
|
9343
|
-
return (path4, init = {}) => authenticatedFetch({
|
|
9344
|
-
...auth,
|
|
9345
|
-
path: `/v1/mail${path4}`,
|
|
9346
|
-
method: init.method,
|
|
9347
|
-
body: init.body,
|
|
9348
|
-
headers: {
|
|
9349
|
-
...init.body ? { "Content-Type": "application/json" } : {},
|
|
9350
|
-
...init.headers
|
|
9351
|
-
}
|
|
9352
|
-
});
|
|
9353
|
-
}
|
|
9354
|
-
async function json(response) {
|
|
9355
|
-
return (await response).json();
|
|
9356
|
-
}
|
|
9357
|
-
var accountPath = (accountId) => `/accounts/${encodeURIComponent(accountId)}`;
|
|
9358
|
-
function getMailPolicy(mail) {
|
|
9359
|
-
return json(mail("/policy"));
|
|
9360
|
-
}
|
|
9361
|
-
function listMailAccounts(mail) {
|
|
9362
|
-
return json(mail("/accounts"));
|
|
9363
|
-
}
|
|
9364
|
-
async function claimNativeAlias(mail, alias) {
|
|
9365
|
-
const { email } = await json(
|
|
9366
|
-
mail("/native/alias", { method: "POST", body: JSON.stringify({ alias }) })
|
|
9367
|
-
);
|
|
9368
|
-
return email;
|
|
9369
|
-
}
|
|
9370
|
-
function listFolders(mail, accountId = NATIVE_ACCOUNT) {
|
|
9371
|
-
return json(mail(`${accountPath(accountId)}/folders`));
|
|
9372
|
-
}
|
|
9373
|
-
function listMessages(mail, options) {
|
|
9374
|
-
const params = new URLSearchParams({ folder_id: options.folderId });
|
|
9375
|
-
if (options.query) params.set("q", options.query);
|
|
9376
|
-
if (options.cursor) params.set("cursor", options.cursor);
|
|
9377
|
-
if (options.limit) params.set("limit", String(options.limit));
|
|
9378
|
-
return json(mail(`${accountPath(options.accountId ?? NATIVE_ACCOUNT)}/messages?${params}`));
|
|
9379
|
-
}
|
|
9380
|
-
function getMessage2(mail, messageId, accountId = NATIVE_ACCOUNT) {
|
|
9381
|
-
return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`));
|
|
9382
|
-
}
|
|
9383
|
-
async function downloadAttachment(mail, messageId, attachmentId, accountId = NATIVE_ACCOUNT) {
|
|
9384
|
-
const path4 = `${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`;
|
|
9385
|
-
return new Uint8Array(await (await mail(path4)).arrayBuffer());
|
|
9386
|
-
}
|
|
9387
|
-
async function updateMessage(mail, messageId, update, accountId = NATIVE_ACCOUNT) {
|
|
9388
|
-
await mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`, {
|
|
9389
|
-
method: "PATCH",
|
|
9390
|
-
body: JSON.stringify(update)
|
|
9391
|
-
});
|
|
9392
|
-
}
|
|
9393
|
-
function saveDraft(mail, compose, accountId = NATIVE_ACCOUNT) {
|
|
9394
|
-
return json(
|
|
9395
|
-
mail(`${accountPath(accountId)}/drafts`, { method: "POST", body: JSON.stringify(compose) })
|
|
9396
|
-
);
|
|
9397
|
-
}
|
|
9398
|
-
function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
|
|
9399
|
-
const body = { ...message, request_id: message.request_id ?? crypto.randomUUID() };
|
|
9400
|
-
return json(
|
|
9401
|
-
mail(`${accountPath(accountId)}/send`, { method: "POST", body: JSON.stringify(body) })
|
|
9402
|
-
);
|
|
9403
|
-
}
|
|
9404
|
-
async function unlockNativeMail(mail, keys) {
|
|
9405
|
-
await client.initSodium();
|
|
9406
|
-
const secretKey = client.deriveEncryptionKeypairFromSigning({
|
|
9407
|
-
publicKey: keys.signingPrivateKey.slice(32, 64),
|
|
9408
|
-
secretKey: keys.signingPrivateKey
|
|
9409
|
-
}).secretKey;
|
|
9410
|
-
try {
|
|
9411
|
-
let cursor = 0;
|
|
9412
|
-
while (cursor !== null) {
|
|
9413
|
-
const page = await json(
|
|
9414
|
-
mail(`/native/keys?cursor=${cursor}`)
|
|
9415
|
-
);
|
|
9416
|
-
const sealed = {};
|
|
9417
|
-
for (const [id, wrapped] of Object.entries(page.keys)) {
|
|
9418
|
-
const key = client.sealedBoxDecrypt(wrapped, secretKey);
|
|
9419
|
-
try {
|
|
9420
|
-
sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
|
|
9421
|
-
} finally {
|
|
9422
|
-
key.fill(0);
|
|
9423
|
-
}
|
|
9424
|
-
}
|
|
9425
|
-
if (Object.keys(sealed).length) {
|
|
9426
|
-
await mail("/native/session-keys", {
|
|
9427
|
-
method: "POST",
|
|
9428
|
-
body: JSON.stringify({ keys: sealed })
|
|
9429
|
-
});
|
|
9430
|
-
}
|
|
9431
|
-
cursor = page.next_cursor;
|
|
9432
|
-
}
|
|
9433
|
-
} finally {
|
|
9434
|
-
secretKey.fill(0);
|
|
9435
|
-
}
|
|
9436
|
-
}
|
|
9437
|
-
function attachmentFromBytes(name, contentType, bytes) {
|
|
9438
|
-
return {
|
|
9439
|
-
id: "",
|
|
9440
|
-
name,
|
|
9441
|
-
content_type: contentType,
|
|
9442
|
-
size: bytes.length,
|
|
9443
|
-
content_base64: bytesToBase642(bytes)
|
|
9444
|
-
};
|
|
9445
|
-
}
|
|
9446
|
-
function bytesToBase642(bytes) {
|
|
9447
|
-
let binary = "";
|
|
9448
|
-
for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
|
|
9449
|
-
binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
|
|
9450
|
-
}
|
|
9451
|
-
return btoa(binary);
|
|
9452
|
-
}
|
|
9453
|
-
|
|
9454
9523
|
// src/operations/mail-node.ts
|
|
9455
9524
|
var mail_node_exports = {};
|
|
9456
9525
|
__export(mail_node_exports, {
|