@arbidocs/sdk 0.4.84 → 0.4.85
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-BOIk_RaR.d.cts} +247 -112
- package/dist/{browser-uyIwS2cN.d.ts → browser-BOIk_RaR.d.ts} +247 -112
- package/dist/browser.cjs +244 -172
- 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 +244 -172
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +244 -172
- 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 +244 -172
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.cjs
CHANGED
|
@@ -5165,17 +5165,33 @@ function extractResponseText(response) {
|
|
|
5165
5165
|
// src/operations/tags.ts
|
|
5166
5166
|
var tags_exports = {};
|
|
5167
5167
|
__export(tags_exports, {
|
|
5168
|
+
FLAT_TAG_KINDS: () => FLAT_TAG_KINDS,
|
|
5168
5169
|
TAG_FIELD_TYPES: () => TAG_FIELD_TYPES,
|
|
5170
|
+
TAG_KINDS: () => TAG_KINDS,
|
|
5169
5171
|
createTag: () => createTag,
|
|
5170
5172
|
deleteTag: () => deleteTag,
|
|
5171
|
-
|
|
5173
|
+
getTagKind: () => getTagKind,
|
|
5174
|
+
kindFieldWrites: () => kindFieldWrites,
|
|
5175
|
+
listTagKinds: () => listTagKinds,
|
|
5172
5176
|
listTags: () => listTags,
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
tagMatrixColumns: () => tagMatrixColumns,
|
|
5177
|
+
mergeKindFieldDefinitions: () => mergeKindFieldDefinitions,
|
|
5178
|
+
setTagValues: () => setTagValues,
|
|
5176
5179
|
updateTag: () => updateTag,
|
|
5177
|
-
|
|
5180
|
+
updateTagKind: () => updateTagKind
|
|
5178
5181
|
});
|
|
5182
|
+
var withFields = (schema) => ({
|
|
5183
|
+
...schema,
|
|
5184
|
+
fields: schema.fields ?? []
|
|
5185
|
+
});
|
|
5186
|
+
var TAG_KINDS = [
|
|
5187
|
+
"label",
|
|
5188
|
+
"annotation",
|
|
5189
|
+
"issue",
|
|
5190
|
+
"person",
|
|
5191
|
+
"organisation",
|
|
5192
|
+
"search"
|
|
5193
|
+
];
|
|
5194
|
+
var FLAT_TAG_KINDS = ["issue", "person", "organisation"];
|
|
5179
5195
|
var TAG_FIELD_TYPES = [
|
|
5180
5196
|
"text",
|
|
5181
5197
|
"number",
|
|
@@ -5184,8 +5200,20 @@ var TAG_FIELD_TYPES = [
|
|
|
5184
5200
|
"select",
|
|
5185
5201
|
"person"
|
|
5186
5202
|
];
|
|
5187
|
-
async function listTags(arbi) {
|
|
5188
|
-
|
|
5203
|
+
async function listTags(arbi, query = {}) {
|
|
5204
|
+
const params = {};
|
|
5205
|
+
if (query.kind) params.kind = query.kind;
|
|
5206
|
+
if (query.parentId) params.parent = query.parentId;
|
|
5207
|
+
if (query.ids?.length) params.ids = query.ids;
|
|
5208
|
+
if (query.include?.length) params.include = query.include;
|
|
5209
|
+
if (query.linksLimit !== void 0) params.links_limit = query.linksLimit;
|
|
5210
|
+
return requireData(
|
|
5211
|
+
await arbi.fetch.GET(
|
|
5212
|
+
"/v1/tag/",
|
|
5213
|
+
Object.keys(params).length ? { params: { query: params } } : {}
|
|
5214
|
+
),
|
|
5215
|
+
"Failed to fetch tags"
|
|
5216
|
+
);
|
|
5189
5217
|
}
|
|
5190
5218
|
async function createTag(arbi, options) {
|
|
5191
5219
|
return requireData(
|
|
@@ -5195,8 +5223,8 @@ async function createTag(arbi, options) {
|
|
|
5195
5223
|
tag_type: options.tagType ?? { type: "checkbox", options: [] },
|
|
5196
5224
|
instruction: options.instruction ?? null,
|
|
5197
5225
|
shared: options.shared ?? false,
|
|
5226
|
+
...options.kind ? { kind: options.kind } : {},
|
|
5198
5227
|
...options.parentId ? { parent_ext_id: options.parentId } : {},
|
|
5199
|
-
...options.fields ? { fields: options.fields } : {},
|
|
5200
5228
|
...options.fieldValues ? { field_values: options.fieldValues } : {}
|
|
5201
5229
|
}
|
|
5202
5230
|
}),
|
|
@@ -5215,48 +5243,47 @@ async function updateTag(arbi, tagId, change) {
|
|
|
5215
5243
|
return requireData(
|
|
5216
5244
|
await arbi.fetch.PATCH("/v1/tag/{tag_ext_id}", {
|
|
5217
5245
|
params: { path: { tag_ext_id: tagId } },
|
|
5218
|
-
body:
|
|
5246
|
+
body: change
|
|
5219
5247
|
}),
|
|
5220
5248
|
"Failed to update tag"
|
|
5221
5249
|
);
|
|
5222
5250
|
}
|
|
5223
|
-
async function
|
|
5224
|
-
|
|
5225
|
-
if (change.fields) body.fields = change.fields;
|
|
5226
|
-
if (change.values) body.field_values = change.values;
|
|
5227
|
-
return updateTag(arbi, tagId, body);
|
|
5251
|
+
async function setTagValues(arbi, tagId, values) {
|
|
5252
|
+
return updateTag(arbi, tagId, { field_values: values });
|
|
5228
5253
|
}
|
|
5229
|
-
async function
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
return requireData(
|
|
5233
|
-
await arbi.fetch.GET("/v1/tag/matrix", { params: { query } }),
|
|
5234
|
-
"Failed to fetch the tag matrix"
|
|
5254
|
+
async function listTagKinds(arbi) {
|
|
5255
|
+
return requireData(await arbi.fetch.GET("/v1/tag/kinds"), "Failed to fetch tag kinds").map(
|
|
5256
|
+
withFields
|
|
5235
5257
|
);
|
|
5236
5258
|
}
|
|
5237
|
-
function
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
return columns;
|
|
5259
|
+
async function getTagKind(arbi, kind) {
|
|
5260
|
+
return withFields(
|
|
5261
|
+
requireData(
|
|
5262
|
+
await arbi.fetch.GET("/v1/tag/kinds/{kind}", { params: { path: { kind } } }),
|
|
5263
|
+
"Failed to fetch the tag kind"
|
|
5264
|
+
)
|
|
5265
|
+
);
|
|
5245
5266
|
}
|
|
5246
|
-
function
|
|
5247
|
-
return (
|
|
5267
|
+
async function updateTagKind(arbi, kind, fields) {
|
|
5268
|
+
return withFields(
|
|
5269
|
+
requireData(
|
|
5270
|
+
await arbi.fetch.PUT("/v1/tag/kinds/{kind}", {
|
|
5271
|
+
params: { path: { kind } },
|
|
5272
|
+
body: { fields }
|
|
5273
|
+
}),
|
|
5274
|
+
"Failed to update the tag kind"
|
|
5275
|
+
)
|
|
5276
|
+
);
|
|
5248
5277
|
}
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
const byName = new Map(
|
|
5278
|
+
var kindFieldWrites = (fields) => fields.map((f2) => ({ id: f2.id, name: f2.name, type: f2.type, options: f2.options ?? null }));
|
|
5279
|
+
function mergeKindFieldDefinitions(current, wanted, { keepOthers = false } = {}) {
|
|
5280
|
+
const byName = new Map(current.map((f2) => [f2.name.toLowerCase(), f2]));
|
|
5252
5281
|
const out = wanted.map((w2) => {
|
|
5253
5282
|
const old = w2.id ? void 0 : byName.get(w2.name.trim().toLowerCase());
|
|
5254
5283
|
return old ? { ...w2, id: old.id } : w2;
|
|
5255
5284
|
});
|
|
5256
5285
|
if (keepOthers) {
|
|
5257
|
-
for (const f2 of
|
|
5258
|
-
if (!out.some((w2) => w2.id === f2.id))
|
|
5259
|
-
out.push({ id: f2.id, name: f2.name, type: f2.type, options: f2.options ?? null });
|
|
5286
|
+
for (const f2 of kindFieldWrites(current)) if (!out.some((w2) => w2.id === f2.id)) out.push(f2);
|
|
5260
5287
|
}
|
|
5261
5288
|
return out;
|
|
5262
5289
|
}
|
|
@@ -7055,6 +7082,137 @@ async function remindFact(arbi, factId, options = {}) {
|
|
|
7055
7082
|
);
|
|
7056
7083
|
}
|
|
7057
7084
|
|
|
7085
|
+
// src/operations/mail.ts
|
|
7086
|
+
var mail_exports = {};
|
|
7087
|
+
__export(mail_exports, {
|
|
7088
|
+
NATIVE_ACCOUNT: () => NATIVE_ACCOUNT,
|
|
7089
|
+
attachmentFromBytes: () => attachmentFromBytes,
|
|
7090
|
+
claimNativeAlias: () => claimNativeAlias,
|
|
7091
|
+
createMailFetch: () => createMailFetch,
|
|
7092
|
+
downloadAttachment: () => downloadAttachment,
|
|
7093
|
+
getMailPolicy: () => getMailPolicy,
|
|
7094
|
+
getMessage: () => getMessage2,
|
|
7095
|
+
listFolders: () => listFolders,
|
|
7096
|
+
listMailAccounts: () => listMailAccounts,
|
|
7097
|
+
listMessages: () => listMessages,
|
|
7098
|
+
saveDraft: () => saveDraft,
|
|
7099
|
+
sendMessage: () => sendMessage,
|
|
7100
|
+
unlockNativeMail: () => unlockNativeMail,
|
|
7101
|
+
updateMessage: () => updateMessage
|
|
7102
|
+
});
|
|
7103
|
+
var NATIVE_ACCOUNT = "native";
|
|
7104
|
+
function createMailFetch(auth) {
|
|
7105
|
+
return (path, init = {}) => authenticatedFetch({
|
|
7106
|
+
...auth,
|
|
7107
|
+
path: `/v1/mail${path}`,
|
|
7108
|
+
method: init.method,
|
|
7109
|
+
body: init.body,
|
|
7110
|
+
headers: {
|
|
7111
|
+
...init.body ? { "Content-Type": "application/json" } : {},
|
|
7112
|
+
...init.headers
|
|
7113
|
+
}
|
|
7114
|
+
});
|
|
7115
|
+
}
|
|
7116
|
+
async function json(response) {
|
|
7117
|
+
return (await response).json();
|
|
7118
|
+
}
|
|
7119
|
+
var accountPath = (accountId) => `/accounts/${encodeURIComponent(accountId)}`;
|
|
7120
|
+
function getMailPolicy(mail) {
|
|
7121
|
+
return json(mail("/policy"));
|
|
7122
|
+
}
|
|
7123
|
+
function listMailAccounts(mail) {
|
|
7124
|
+
return json(mail("/accounts"));
|
|
7125
|
+
}
|
|
7126
|
+
async function claimNativeAlias(mail, alias) {
|
|
7127
|
+
const { email } = await json(
|
|
7128
|
+
mail("/native/alias", { method: "POST", body: JSON.stringify({ alias }) })
|
|
7129
|
+
);
|
|
7130
|
+
return email;
|
|
7131
|
+
}
|
|
7132
|
+
function listFolders(mail, accountId = NATIVE_ACCOUNT) {
|
|
7133
|
+
return json(mail(`${accountPath(accountId)}/folders`));
|
|
7134
|
+
}
|
|
7135
|
+
function listMessages(mail, options) {
|
|
7136
|
+
const params = new URLSearchParams({ folder_id: options.folderId });
|
|
7137
|
+
if (options.query) params.set("q", options.query);
|
|
7138
|
+
if (options.cursor) params.set("cursor", options.cursor);
|
|
7139
|
+
if (options.limit) params.set("limit", String(options.limit));
|
|
7140
|
+
return json(mail(`${accountPath(options.accountId ?? NATIVE_ACCOUNT)}/messages?${params}`));
|
|
7141
|
+
}
|
|
7142
|
+
function getMessage2(mail, messageId, accountId = NATIVE_ACCOUNT) {
|
|
7143
|
+
return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`));
|
|
7144
|
+
}
|
|
7145
|
+
async function downloadAttachment(mail, messageId, attachmentId, accountId = NATIVE_ACCOUNT) {
|
|
7146
|
+
const path = `${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`;
|
|
7147
|
+
return new Uint8Array(await (await mail(path)).arrayBuffer());
|
|
7148
|
+
}
|
|
7149
|
+
async function updateMessage(mail, messageId, update, accountId = NATIVE_ACCOUNT) {
|
|
7150
|
+
await mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`, {
|
|
7151
|
+
method: "PATCH",
|
|
7152
|
+
body: JSON.stringify(update)
|
|
7153
|
+
});
|
|
7154
|
+
}
|
|
7155
|
+
function saveDraft(mail, compose, accountId = NATIVE_ACCOUNT) {
|
|
7156
|
+
return json(
|
|
7157
|
+
mail(`${accountPath(accountId)}/drafts`, { method: "POST", body: JSON.stringify(compose) })
|
|
7158
|
+
);
|
|
7159
|
+
}
|
|
7160
|
+
function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
|
|
7161
|
+
const body = { ...message, request_id: message.request_id ?? crypto.randomUUID() };
|
|
7162
|
+
return json(
|
|
7163
|
+
mail(`${accountPath(accountId)}/send`, { method: "POST", body: JSON.stringify(body) })
|
|
7164
|
+
);
|
|
7165
|
+
}
|
|
7166
|
+
async function unlockNativeMail(mail, keys) {
|
|
7167
|
+
await client.initSodium();
|
|
7168
|
+
const secretKey = client.deriveEncryptionKeypairFromSigning({
|
|
7169
|
+
publicKey: keys.signingPrivateKey.slice(32, 64),
|
|
7170
|
+
secretKey: keys.signingPrivateKey
|
|
7171
|
+
}).secretKey;
|
|
7172
|
+
try {
|
|
7173
|
+
let cursor = 0;
|
|
7174
|
+
while (cursor !== null) {
|
|
7175
|
+
const page = await json(
|
|
7176
|
+
mail(`/native/keys?cursor=${cursor}`)
|
|
7177
|
+
);
|
|
7178
|
+
const sealed = {};
|
|
7179
|
+
for (const [id, wrapped] of Object.entries(page.keys)) {
|
|
7180
|
+
const key = client.sealedBoxDecrypt(wrapped, secretKey);
|
|
7181
|
+
try {
|
|
7182
|
+
sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
|
|
7183
|
+
} finally {
|
|
7184
|
+
key.fill(0);
|
|
7185
|
+
}
|
|
7186
|
+
}
|
|
7187
|
+
if (Object.keys(sealed).length) {
|
|
7188
|
+
await mail("/native/session-keys", {
|
|
7189
|
+
method: "POST",
|
|
7190
|
+
body: JSON.stringify({ keys: sealed })
|
|
7191
|
+
});
|
|
7192
|
+
}
|
|
7193
|
+
cursor = page.next_cursor;
|
|
7194
|
+
}
|
|
7195
|
+
} finally {
|
|
7196
|
+
secretKey.fill(0);
|
|
7197
|
+
}
|
|
7198
|
+
}
|
|
7199
|
+
function attachmentFromBytes(name, contentType, bytes) {
|
|
7200
|
+
return {
|
|
7201
|
+
id: "",
|
|
7202
|
+
name,
|
|
7203
|
+
content_type: contentType,
|
|
7204
|
+
size: bytes.length,
|
|
7205
|
+
content_base64: bytesToBase642(bytes)
|
|
7206
|
+
};
|
|
7207
|
+
}
|
|
7208
|
+
function bytesToBase642(bytes) {
|
|
7209
|
+
let binary = "";
|
|
7210
|
+
for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
|
|
7211
|
+
binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
|
|
7212
|
+
}
|
|
7213
|
+
return btoa(binary);
|
|
7214
|
+
}
|
|
7215
|
+
|
|
7058
7216
|
// src/arbi.ts
|
|
7059
7217
|
function tokenExpiresWithin(token, seconds) {
|
|
7060
7218
|
const payload = token?.split(".")[1];
|
|
@@ -7705,6 +7863,39 @@ var Arbi = class {
|
|
|
7705
7863
|
return response;
|
|
7706
7864
|
})
|
|
7707
7865
|
};
|
|
7866
|
+
/**
|
|
7867
|
+
* Mail transport for `/v1/mail` (the native inbox and connected accounts), with normal session
|
|
7868
|
+
* recovery. Pass `fetch` to the `mail` operations, e.g. `mail.listFolders(arbi.mail.fetch)`.
|
|
7869
|
+
*/
|
|
7870
|
+
mail = {
|
|
7871
|
+
/** Fetch a path under `/v1/mail`; rejects a non-2xx response with an `ArbiApiError` (`status`). */
|
|
7872
|
+
fetch: (path, init = {}) => this.recovering(async () => {
|
|
7873
|
+
const { baseUrl, accessToken } = this.getAuthHeaders();
|
|
7874
|
+
const headers = new Headers(init.headers);
|
|
7875
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
7876
|
+
if (init.body && !headers.has("Content-Type"))
|
|
7877
|
+
headers.set("Content-Type", "application/json");
|
|
7878
|
+
const response = await fetch(`${baseUrl}/v1/mail${path}`, { ...init, headers });
|
|
7879
|
+
if (!response.ok) {
|
|
7880
|
+
const body = await response.json().catch(() => null);
|
|
7881
|
+
throw new ArbiApiError(
|
|
7882
|
+
typeof body?.detail === "string" ? body.detail : "The mail request could not be completed",
|
|
7883
|
+
body,
|
|
7884
|
+
response.status
|
|
7885
|
+
);
|
|
7886
|
+
}
|
|
7887
|
+
return response;
|
|
7888
|
+
}),
|
|
7889
|
+
/** Unlock the signed-in user's native inbox for this server session (see `unlockNativeMail`). */
|
|
7890
|
+
unlockNative: () => {
|
|
7891
|
+
const login = this.loginResult;
|
|
7892
|
+
if (!login) return Promise.reject(new ArbiError("Sign in to unlock your inbox"));
|
|
7893
|
+
return unlockNativeMail(this.mail.fetch, {
|
|
7894
|
+
signingPrivateKey: login.signingPrivateKey,
|
|
7895
|
+
serverSessionKey: login.serverSessionKey
|
|
7896
|
+
});
|
|
7897
|
+
}
|
|
7898
|
+
};
|
|
7708
7899
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
7709
7900
|
assistant = {
|
|
7710
7901
|
cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
|
|
@@ -7777,17 +7968,29 @@ var Arbi = class {
|
|
|
7777
7968
|
};
|
|
7778
7969
|
// ── Tags ──────────────────────────────────────────────────────────────
|
|
7779
7970
|
tags = {
|
|
7780
|
-
|
|
7971
|
+
/**
|
|
7972
|
+
* The workspace's tags, filtered (`kind`, `parentId`, `ids`) and with `include: ['links']`
|
|
7973
|
+
* each tag's documents, facts and threads: `list({ kind: 'issue', include: ['links'] })` is the
|
|
7974
|
+
* issue table's rows (its columns: `tagKinds.get('issue')`).
|
|
7975
|
+
*/
|
|
7976
|
+
list: (query) => listTags(this.requireClient(), query),
|
|
7781
7977
|
create: (options) => createTag(this.requireClient(), {
|
|
7782
7978
|
...options,
|
|
7783
7979
|
workspaceId: options.workspaceId ?? this.requireWorkspace()
|
|
7784
7980
|
}),
|
|
7785
7981
|
delete: (tagId) => deleteTag(this.requireClient(), tagId),
|
|
7786
7982
|
update: (tagId, change) => updateTag(this.requireClient(), tagId, change),
|
|
7787
|
-
/**
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7983
|
+
/** Merge-patch a tag's values for its kind's fields (`null` clears one). */
|
|
7984
|
+
setValues: (tagId, values) => setTagValues(this.requireClient(), tagId, values)
|
|
7985
|
+
};
|
|
7986
|
+
// ── Tag kinds: the workspace's fields per kind (a table's columns) ─────
|
|
7987
|
+
tagKinds = {
|
|
7988
|
+
/** Every kind's fields (the built-in ones where the workspace has not set its own). */
|
|
7989
|
+
list: () => listTagKinds(this.requireClient()),
|
|
7990
|
+
/** A kind's fields: the columns of a table of its tags. */
|
|
7991
|
+
get: (kind) => getTagKind(this.requireClient(), kind),
|
|
7992
|
+
/** Set a kind's fields in full (ids keep fields and their values; the rest are new). */
|
|
7993
|
+
update: (kind, fields) => updateTagKind(this.requireClient(), kind, fields)
|
|
7791
7994
|
};
|
|
7792
7995
|
// ── Document Tags ─────────────────────────────────────────────────────
|
|
7793
7996
|
doctags = {
|
|
@@ -8011,137 +8214,6 @@ var Arbi = class {
|
|
|
8011
8214
|
}
|
|
8012
8215
|
};
|
|
8013
8216
|
|
|
8014
|
-
// src/operations/mail.ts
|
|
8015
|
-
var mail_exports = {};
|
|
8016
|
-
__export(mail_exports, {
|
|
8017
|
-
NATIVE_ACCOUNT: () => NATIVE_ACCOUNT,
|
|
8018
|
-
attachmentFromBytes: () => attachmentFromBytes,
|
|
8019
|
-
claimNativeAlias: () => claimNativeAlias,
|
|
8020
|
-
createMailFetch: () => createMailFetch,
|
|
8021
|
-
downloadAttachment: () => downloadAttachment,
|
|
8022
|
-
getMailPolicy: () => getMailPolicy,
|
|
8023
|
-
getMessage: () => getMessage2,
|
|
8024
|
-
listFolders: () => listFolders,
|
|
8025
|
-
listMailAccounts: () => listMailAccounts,
|
|
8026
|
-
listMessages: () => listMessages,
|
|
8027
|
-
saveDraft: () => saveDraft,
|
|
8028
|
-
sendMessage: () => sendMessage,
|
|
8029
|
-
unlockNativeMail: () => unlockNativeMail,
|
|
8030
|
-
updateMessage: () => updateMessage
|
|
8031
|
-
});
|
|
8032
|
-
var NATIVE_ACCOUNT = "native";
|
|
8033
|
-
function createMailFetch(auth) {
|
|
8034
|
-
return (path, init = {}) => authenticatedFetch({
|
|
8035
|
-
...auth,
|
|
8036
|
-
path: `/v1/mail${path}`,
|
|
8037
|
-
method: init.method,
|
|
8038
|
-
body: init.body,
|
|
8039
|
-
headers: {
|
|
8040
|
-
...init.body ? { "Content-Type": "application/json" } : {},
|
|
8041
|
-
...init.headers
|
|
8042
|
-
}
|
|
8043
|
-
});
|
|
8044
|
-
}
|
|
8045
|
-
async function json(response) {
|
|
8046
|
-
return (await response).json();
|
|
8047
|
-
}
|
|
8048
|
-
var accountPath = (accountId) => `/accounts/${encodeURIComponent(accountId)}`;
|
|
8049
|
-
function getMailPolicy(mail) {
|
|
8050
|
-
return json(mail("/policy"));
|
|
8051
|
-
}
|
|
8052
|
-
function listMailAccounts(mail) {
|
|
8053
|
-
return json(mail("/accounts"));
|
|
8054
|
-
}
|
|
8055
|
-
async function claimNativeAlias(mail, alias) {
|
|
8056
|
-
const { email } = await json(
|
|
8057
|
-
mail("/native/alias", { method: "POST", body: JSON.stringify({ alias }) })
|
|
8058
|
-
);
|
|
8059
|
-
return email;
|
|
8060
|
-
}
|
|
8061
|
-
function listFolders(mail, accountId = NATIVE_ACCOUNT) {
|
|
8062
|
-
return json(mail(`${accountPath(accountId)}/folders`));
|
|
8063
|
-
}
|
|
8064
|
-
function listMessages(mail, options) {
|
|
8065
|
-
const params = new URLSearchParams({ folder_id: options.folderId });
|
|
8066
|
-
if (options.query) params.set("q", options.query);
|
|
8067
|
-
if (options.cursor) params.set("cursor", options.cursor);
|
|
8068
|
-
if (options.limit) params.set("limit", String(options.limit));
|
|
8069
|
-
return json(mail(`${accountPath(options.accountId ?? NATIVE_ACCOUNT)}/messages?${params}`));
|
|
8070
|
-
}
|
|
8071
|
-
function getMessage2(mail, messageId, accountId = NATIVE_ACCOUNT) {
|
|
8072
|
-
return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`));
|
|
8073
|
-
}
|
|
8074
|
-
async function downloadAttachment(mail, messageId, attachmentId, accountId = NATIVE_ACCOUNT) {
|
|
8075
|
-
const path = `${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`;
|
|
8076
|
-
return new Uint8Array(await (await mail(path)).arrayBuffer());
|
|
8077
|
-
}
|
|
8078
|
-
async function updateMessage(mail, messageId, update, accountId = NATIVE_ACCOUNT) {
|
|
8079
|
-
await mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`, {
|
|
8080
|
-
method: "PATCH",
|
|
8081
|
-
body: JSON.stringify(update)
|
|
8082
|
-
});
|
|
8083
|
-
}
|
|
8084
|
-
function saveDraft(mail, compose, accountId = NATIVE_ACCOUNT) {
|
|
8085
|
-
return json(
|
|
8086
|
-
mail(`${accountPath(accountId)}/drafts`, { method: "POST", body: JSON.stringify(compose) })
|
|
8087
|
-
);
|
|
8088
|
-
}
|
|
8089
|
-
function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
|
|
8090
|
-
const body = { ...message, request_id: message.request_id ?? crypto.randomUUID() };
|
|
8091
|
-
return json(
|
|
8092
|
-
mail(`${accountPath(accountId)}/send`, { method: "POST", body: JSON.stringify(body) })
|
|
8093
|
-
);
|
|
8094
|
-
}
|
|
8095
|
-
async function unlockNativeMail(mail, keys) {
|
|
8096
|
-
await client.initSodium();
|
|
8097
|
-
const secretKey = client.deriveEncryptionKeypairFromSigning({
|
|
8098
|
-
publicKey: keys.signingPrivateKey.slice(32, 64),
|
|
8099
|
-
secretKey: keys.signingPrivateKey
|
|
8100
|
-
}).secretKey;
|
|
8101
|
-
try {
|
|
8102
|
-
let cursor = 0;
|
|
8103
|
-
while (cursor !== null) {
|
|
8104
|
-
const page = await json(
|
|
8105
|
-
mail(`/native/keys?cursor=${cursor}`)
|
|
8106
|
-
);
|
|
8107
|
-
const sealed = {};
|
|
8108
|
-
for (const [id, wrapped] of Object.entries(page.keys)) {
|
|
8109
|
-
const key = client.sealedBoxDecrypt(wrapped, secretKey);
|
|
8110
|
-
try {
|
|
8111
|
-
sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
|
|
8112
|
-
} finally {
|
|
8113
|
-
key.fill(0);
|
|
8114
|
-
}
|
|
8115
|
-
}
|
|
8116
|
-
if (Object.keys(sealed).length) {
|
|
8117
|
-
await mail("/native/session-keys", {
|
|
8118
|
-
method: "POST",
|
|
8119
|
-
body: JSON.stringify({ keys: sealed })
|
|
8120
|
-
});
|
|
8121
|
-
}
|
|
8122
|
-
cursor = page.next_cursor;
|
|
8123
|
-
}
|
|
8124
|
-
} finally {
|
|
8125
|
-
secretKey.fill(0);
|
|
8126
|
-
}
|
|
8127
|
-
}
|
|
8128
|
-
function attachmentFromBytes(name, contentType, bytes) {
|
|
8129
|
-
return {
|
|
8130
|
-
id: "",
|
|
8131
|
-
name,
|
|
8132
|
-
content_type: contentType,
|
|
8133
|
-
size: bytes.length,
|
|
8134
|
-
content_base64: bytesToBase642(bytes)
|
|
8135
|
-
};
|
|
8136
|
-
}
|
|
8137
|
-
function bytesToBase642(bytes) {
|
|
8138
|
-
let binary = "";
|
|
8139
|
-
for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
|
|
8140
|
-
binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
|
|
8141
|
-
}
|
|
8142
|
-
return btoa(binary);
|
|
8143
|
-
}
|
|
8144
|
-
|
|
8145
8217
|
exports.Arbi = Arbi;
|
|
8146
8218
|
exports.ArbiApiError = ArbiApiError;
|
|
8147
8219
|
exports.ArbiError = ArbiError;
|