@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.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
- getTagMatrix: () => getTagMatrix,
5173
+ getTagKind: () => getTagKind,
5174
+ kindFieldWrites: () => kindFieldWrites,
5175
+ listTagKinds: () => listTagKinds,
5172
5176
  listTags: () => listTags,
5173
- mergeTagFieldDefinitions: () => mergeTagFieldDefinitions,
5174
- ownTagFields: () => ownTagFields,
5175
- tagMatrixColumns: () => tagMatrixColumns,
5177
+ mergeKindFieldDefinitions: () => mergeKindFieldDefinitions,
5178
+ setTagValues: () => setTagValues,
5176
5179
  updateTag: () => updateTag,
5177
- updateTagFields: () => updateTagFields
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
- return requireData(await arbi.fetch.GET("/v1/tag/list"), "Failed to fetch tags");
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: { kind_to_children: false, ...change }
5246
+ body: change
5219
5247
  }),
5220
5248
  "Failed to update tag"
5221
5249
  );
5222
5250
  }
5223
- async function updateTagFields(arbi, tagId, change) {
5224
- const body = {};
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 getTagMatrix(arbi, selection, linksLimit) {
5230
- const query = "parentId" in selection ? { parent_ext_id: selection.parentId } : { tag_ext_id: selection.tagIds };
5231
- if (linksLimit !== void 0) query.links_limit = linksLimit;
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 tagMatrixColumns(matrix) {
5238
- const columns = [];
5239
- const add = (f2) => {
5240
- if (!columns.some((c2) => c2.id === f2.id)) columns.push(f2);
5241
- };
5242
- for (const f2 of matrix.parent?.fields ?? []) add(f2);
5243
- for (const row of matrix.rows ?? []) for (const f2 of row.tag.fields ?? []) add(f2);
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 ownTagFields(tag) {
5247
- return (tag.fields ?? []).filter((f2) => f2.tag_ext_id === tag.external_id);
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
- function mergeTagFieldDefinitions(tag, wanted, { keepOthers = false } = {}) {
5250
- const own = ownTagFields(tag);
5251
- const byName = new Map(own.map((f2) => [f2.name.toLowerCase(), f2]));
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 own)
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];
@@ -7417,25 +7575,22 @@ var Arbi = class {
7417
7575
  return result;
7418
7576
  },
7419
7577
  /**
7420
- * Change (or, after recovery, set) the master password: re-keys the workspaces and direct
7421
- * messages. Omit `currentPassword` in recovery mode. Resolves with the new signing key, whose
7422
- * recovery file the user should save.
7578
+ * Change (or, after recovery, set) the master password. Omit `currentPassword` in recovery
7579
+ * mode. One request: the account identity is re-wrapped under the new password and nothing is
7580
+ * re-encrypted, so the session, the workspace keys and the recovery key all stay as they are.
7423
7581
  */
7424
7582
  changePassword: async (params) => {
7425
7583
  const client$1 = this.requireClient();
7426
7584
  const lr2 = this.requireLogin();
7427
7585
  const email = client$1.session.getState().userEmail ?? this.userProfile?.email;
7428
7586
  if (!email) throw new ArbiError("The account email is unknown; sign in again.");
7429
- const result = await client.changePasswordWithRekey(
7430
- { ...params, email, userExtId: lr2.userExtId },
7587
+ await client.changePassword(
7588
+ { ...params, email, identitySecretKey: lr2.signingPrivateKey },
7431
7589
  {
7432
7590
  fetchClient: client$1.fetch,
7433
7591
  deploymentDomain: this.getDeploymentDomain()
7434
7592
  }
7435
7593
  );
7436
- this.loginResult = { ...lr2, signingPrivateKey: result.newSigningPrivateKey };
7437
- this.wrappedKeys.clear();
7438
- return result;
7439
7594
  },
7440
7595
  /** Close the account (soft delete) and sign out. Refused while a subscription is active. */
7441
7596
  requestDeletion: async () => {
@@ -7705,6 +7860,39 @@ var Arbi = class {
7705
7860
  return response;
7706
7861
  })
7707
7862
  };
7863
+ /**
7864
+ * Mail transport for `/v1/mail` (the native inbox and connected accounts), with normal session
7865
+ * recovery. Pass `fetch` to the `mail` operations, e.g. `mail.listFolders(arbi.mail.fetch)`.
7866
+ */
7867
+ mail = {
7868
+ /** Fetch a path under `/v1/mail`; rejects a non-2xx response with an `ArbiApiError` (`status`). */
7869
+ fetch: (path, init = {}) => this.recovering(async () => {
7870
+ const { baseUrl, accessToken } = this.getAuthHeaders();
7871
+ const headers = new Headers(init.headers);
7872
+ headers.set("Authorization", `Bearer ${accessToken}`);
7873
+ if (init.body && !headers.has("Content-Type"))
7874
+ headers.set("Content-Type", "application/json");
7875
+ const response = await fetch(`${baseUrl}/v1/mail${path}`, { ...init, headers });
7876
+ if (!response.ok) {
7877
+ const body = await response.json().catch(() => null);
7878
+ throw new ArbiApiError(
7879
+ typeof body?.detail === "string" ? body.detail : "The mail request could not be completed",
7880
+ body,
7881
+ response.status
7882
+ );
7883
+ }
7884
+ return response;
7885
+ }),
7886
+ /** Unlock the signed-in user's native inbox for this server session (see `unlockNativeMail`). */
7887
+ unlockNative: () => {
7888
+ const login = this.loginResult;
7889
+ if (!login) return Promise.reject(new ArbiError("Sign in to unlock your inbox"));
7890
+ return unlockNativeMail(this.mail.fetch, {
7891
+ signingPrivateKey: login.signingPrivateKey,
7892
+ serverSessionKey: login.serverSessionKey
7893
+ });
7894
+ }
7895
+ };
7708
7896
  // ── Assistant ─────────────────────────────────────────────────────────
7709
7897
  assistant = {
7710
7898
  cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
@@ -7777,17 +7965,29 @@ var Arbi = class {
7777
7965
  };
7778
7966
  // ── Tags ──────────────────────────────────────────────────────────────
7779
7967
  tags = {
7780
- list: () => listTags(this.requireClient()),
7968
+ /**
7969
+ * The workspace's tags, filtered (`kind`, `parentId`, `ids`) and with `include: ['links']`
7970
+ * each tag's documents, facts and threads: `list({ kind: 'issue', include: ['links'] })` is the
7971
+ * issue table's rows (its columns: `tagKinds.get('issue')`).
7972
+ */
7973
+ list: (query) => listTags(this.requireClient(), query),
7781
7974
  create: (options) => createTag(this.requireClient(), {
7782
7975
  ...options,
7783
7976
  workspaceId: options.workspaceId ?? this.requireWorkspace()
7784
7977
  }),
7785
7978
  delete: (tagId) => deleteTag(this.requireClient(), tagId),
7786
7979
  update: (tagId, change) => updateTag(this.requireClient(), tagId, change),
7787
- /** Replace a tag's own field definitions and/or merge-patch its values (`null` clears one). */
7788
- updateFields: (tagId, change) => updateTagFields(this.requireClient(), tagId, change),
7789
- /** Tags as rows (a parent's children, or the given tags) with field values, docs and facts. */
7790
- matrix: (selection, linksLimit) => getTagMatrix(this.requireClient(), selection, linksLimit)
7980
+ /** Merge-patch a tag's values for its kind's fields (`null` clears one). */
7981
+ setValues: (tagId, values) => setTagValues(this.requireClient(), tagId, values)
7982
+ };
7983
+ // ── Tag kinds: the workspace's fields per kind (a table's columns) ─────
7984
+ tagKinds = {
7985
+ /** Every kind's fields (the built-in ones where the workspace has not set its own). */
7986
+ list: () => listTagKinds(this.requireClient()),
7987
+ /** A kind's fields: the columns of a table of its tags. */
7988
+ get: (kind) => getTagKind(this.requireClient(), kind),
7989
+ /** Set a kind's fields in full (ids keep fields and their values; the rest are new). */
7990
+ update: (kind, fields) => updateTagKind(this.requireClient(), kind, fields)
7791
7991
  };
7792
7992
  // ── Document Tags ─────────────────────────────────────────────────────
7793
7993
  doctags = {
@@ -8011,137 +8211,6 @@ var Arbi = class {
8011
8211
  }
8012
8212
  };
8013
8213
 
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
8214
  exports.Arbi = Arbi;
8146
8215
  exports.ArbiApiError = ArbiApiError;
8147
8216
  exports.ArbiError = ArbiError;