@arbidocs/sdk 0.4.32 → 0.4.33

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
@@ -3559,8 +3559,8 @@ async function extractErrorMessage(res) {
3559
3559
  const text = await res.text();
3560
3560
  if (text) {
3561
3561
  try {
3562
- const json = JSON.parse(text);
3563
- bodyDetail = detailText(json.detail) || json.message || json.error || void 0;
3562
+ const json2 = JSON.parse(text);
3563
+ bodyDetail = detailText(json2.detail) || json2.message || json2.error || void 0;
3564
3564
  } catch {
3565
3565
  if (text.length < 200) bodyDetail = text;
3566
3566
  }
@@ -4489,8 +4489,8 @@ async function getThumbnails(auth, docIds) {
4489
4489
  headers: { "Content-Type": "application/json" },
4490
4490
  body: JSON.stringify({ document_ext_ids: docIds })
4491
4491
  });
4492
- const json = await res.json();
4493
- return json.thumbnails ?? {};
4492
+ const json2 = await res.json();
4493
+ return json2.thumbnails ?? {};
4494
4494
  }
4495
4495
  async function uploadFile(auth, fileData, fileName, options) {
4496
4496
  const formData = new FormData();
@@ -5367,17 +5367,17 @@ async function encryptDmContent(arbi, plaintext, recipientEncryptionPubKeyBase64
5367
5367
  senderEncryptionSecretKey
5368
5368
  );
5369
5369
  }
5370
- async function decryptDmContent(arbi, notification, crypto) {
5370
+ async function decryptDmContent(arbi, notification, crypto2) {
5371
5371
  if (!notification.content) return null;
5372
- const isSent = notification.sender.external_id === crypto.userExtId;
5372
+ const isSent = notification.sender.external_id === crypto2.userExtId;
5373
5373
  const otherParty = isSent ? notification.recipient : notification.sender;
5374
5374
  return arbi.crypto.decryptMessage(
5375
5375
  notification.content,
5376
5376
  otherParty.encryption_public_key,
5377
- crypto.encryptionKeypair.secretKey
5377
+ crypto2.encryptionKeypair.secretKey
5378
5378
  );
5379
5379
  }
5380
- async function decryptDmBatch(arbi, notifications, crypto) {
5380
+ async function decryptDmBatch(arbi, notifications, crypto2) {
5381
5381
  const results = [];
5382
5382
  for (const n2 of notifications) {
5383
5383
  if (n2.type !== "user_message" || !n2.content) {
@@ -5385,7 +5385,7 @@ async function decryptDmBatch(arbi, notifications, crypto) {
5385
5385
  continue;
5386
5386
  }
5387
5387
  try {
5388
- const plaintext = await decryptDmContent(arbi, n2, crypto);
5388
+ const plaintext = await decryptDmContent(arbi, n2, crypto2);
5389
5389
  results.push({ ...n2, content: plaintext });
5390
5390
  } catch {
5391
5391
  results.push({ ...n2, content: "[Decryption failed]" });
@@ -5396,9 +5396,9 @@ async function decryptDmBatch(arbi, notifications, crypto) {
5396
5396
  async function listDMs(arbi) {
5397
5397
  return requireData(await arbi.fetch.GET("/v1/notifications/"), "Failed to fetch messages");
5398
5398
  }
5399
- async function listDecryptedDMs(arbi, crypto) {
5399
+ async function listDecryptedDMs(arbi, crypto2) {
5400
5400
  const raw = await listDMs(arbi);
5401
- return decryptDmBatch(arbi, raw, crypto);
5401
+ return decryptDmBatch(arbi, raw, crypto2);
5402
5402
  }
5403
5403
  async function listActivity(arbi, options) {
5404
5404
  return requireData(
@@ -5445,7 +5445,7 @@ async function resolveRecipient(arbi, ref) {
5445
5445
  }
5446
5446
  return null;
5447
5447
  }
5448
- async function sendEncryptedDM(arbi, messages, crypto) {
5448
+ async function sendEncryptedDM(arbi, messages, crypto2) {
5449
5449
  const plaintextFor = new Map(messages.map((m2) => [m2.recipient_ext_id, m2.content]));
5450
5450
  const encrypted = await Promise.all(
5451
5451
  messages.map(async (msg) => ({
@@ -5454,7 +5454,7 @@ async function sendEncryptedDM(arbi, messages, crypto) {
5454
5454
  arbi,
5455
5455
  msg.content,
5456
5456
  msg.recipient_encryption_public_key,
5457
- crypto.encryptionKeypair.secretKey
5457
+ crypto2.encryptionKeypair.secretKey
5458
5458
  )
5459
5459
  }))
5460
5460
  );
@@ -5469,7 +5469,7 @@ async function sendEncryptedDM(arbi, messages, crypto) {
5469
5469
  content: plaintextFor.get(n2.recipient.external_id) ?? n2.content
5470
5470
  }));
5471
5471
  }
5472
- async function requestWorkspaceAccess(arbi, params, crypto) {
5472
+ async function requestWorkspaceAccess(arbi, params, crypto2) {
5473
5473
  const payload = JSON.stringify({
5474
5474
  session_pubkey_b64: params.sessionPubkeyB64,
5475
5475
  note: params.note?.trim() || void 0
@@ -5478,7 +5478,7 @@ async function requestWorkspaceAccess(arbi, params, crypto) {
5478
5478
  arbi,
5479
5479
  payload,
5480
5480
  params.recipientEncryptionPublicKey,
5481
- crypto.encryptionKeypair.secretKey
5481
+ crypto2.encryptionKeypair.secretKey
5482
5482
  );
5483
5483
  return requireData(
5484
5484
  await arbi.fetch.POST("/v1/notifications/access-request", {
@@ -5879,6 +5879,7 @@ __export(workflows_exports, {
5879
5879
  createWorkflow: () => createWorkflow,
5880
5880
  deleteWorkflow: () => deleteWorkflow,
5881
5881
  getWorkflow: () => getWorkflow,
5882
+ listWorkflowRuns: () => listWorkflowRuns,
5882
5883
  listWorkflows: () => listWorkflows,
5883
5884
  runWorkflow: () => runWorkflow,
5884
5885
  updateWorkflow: () => updateWorkflow
@@ -5914,6 +5915,12 @@ async function runWorkflow(arbi, workflowId) {
5914
5915
  "Failed to run workflow"
5915
5916
  );
5916
5917
  }
5918
+ async function listWorkflowRuns(arbi, workflowId) {
5919
+ return requireData(
5920
+ await arbi.fetch.GET("/v1/workflow/{workflow_id}/runs", byId2(workflowId)),
5921
+ "Failed to list automation executions"
5922
+ );
5923
+ }
5917
5924
 
5918
5925
  // src/operations/facts.ts
5919
5926
  var facts_exports = {};
@@ -5987,8 +5994,8 @@ function tokenExpiresWithin(token, seconds) {
5987
5994
  const payload = token?.split(".")[1];
5988
5995
  if (!payload) return false;
5989
5996
  try {
5990
- const json = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
5991
- const { exp } = JSON.parse(json);
5997
+ const json2 = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
5998
+ const { exp } = JSON.parse(json2);
5992
5999
  return typeof exp === "number" && exp * 1e3 - Date.now() < seconds * 1e3;
5993
6000
  } catch {
5994
6001
  return false;
@@ -6379,9 +6386,9 @@ var Arbi = class {
6379
6386
  const lr2 = this.requireLogin();
6380
6387
  const userExtId = lr2.userExtId ?? client.session.getState().userExtId;
6381
6388
  if (!userExtId) throw new ArbiError("No user id in session \u2014 cannot request access");
6382
- const crypto = createDmCryptoContext(client, lr2.signingPrivateKey, userExtId);
6389
+ const crypto2 = createDmCryptoContext(client, lr2.signingPrivateKey, userExtId);
6383
6390
  const sessionPubkeyB64 = client.crypto.bytesToBase64(lr2.serverSessionKey);
6384
- return requestWorkspaceAccess(client, { ...params, sessionPubkeyB64 }, crypto);
6391
+ return requestWorkspaceAccess(client, { ...params, sessionPubkeyB64 }, crypto2);
6385
6392
  },
6386
6393
  copyDocuments: (targetWorkspaceId, docIds, targetWorkspaceKey) => copyDocuments(
6387
6394
  this.requireClient(),
@@ -6818,6 +6825,137 @@ var Arbi = class {
6818
6825
  }
6819
6826
  };
6820
6827
 
6828
+ // src/operations/mail.ts
6829
+ var mail_exports = {};
6830
+ __export(mail_exports, {
6831
+ NATIVE_ACCOUNT: () => NATIVE_ACCOUNT,
6832
+ attachmentFromBytes: () => attachmentFromBytes,
6833
+ claimNativeAlias: () => claimNativeAlias,
6834
+ createMailFetch: () => createMailFetch,
6835
+ downloadAttachment: () => downloadAttachment,
6836
+ getMailPolicy: () => getMailPolicy,
6837
+ getMessage: () => getMessage2,
6838
+ listFolders: () => listFolders,
6839
+ listMailAccounts: () => listMailAccounts,
6840
+ listMessages: () => listMessages,
6841
+ saveDraft: () => saveDraft,
6842
+ sendMessage: () => sendMessage,
6843
+ unlockNativeMail: () => unlockNativeMail,
6844
+ updateMessage: () => updateMessage
6845
+ });
6846
+ var NATIVE_ACCOUNT = "native";
6847
+ function createMailFetch(auth) {
6848
+ return (path, init = {}) => authenticatedFetch({
6849
+ ...auth,
6850
+ path: `/v1/mail${path}`,
6851
+ method: init.method,
6852
+ body: init.body,
6853
+ headers: {
6854
+ ...init.body ? { "Content-Type": "application/json" } : {},
6855
+ ...init.headers
6856
+ }
6857
+ });
6858
+ }
6859
+ async function json(response) {
6860
+ return (await response).json();
6861
+ }
6862
+ var accountPath = (accountId) => `/accounts/${encodeURIComponent(accountId)}`;
6863
+ function getMailPolicy(mail) {
6864
+ return json(mail("/policy"));
6865
+ }
6866
+ function listMailAccounts(mail) {
6867
+ return json(mail("/accounts"));
6868
+ }
6869
+ async function claimNativeAlias(mail, alias) {
6870
+ const { email } = await json(
6871
+ mail("/native/alias", { method: "POST", body: JSON.stringify({ alias }) })
6872
+ );
6873
+ return email;
6874
+ }
6875
+ function listFolders(mail, accountId = NATIVE_ACCOUNT) {
6876
+ return json(mail(`${accountPath(accountId)}/folders`));
6877
+ }
6878
+ function listMessages(mail, options) {
6879
+ const params = new URLSearchParams({ folder_id: options.folderId });
6880
+ if (options.query) params.set("q", options.query);
6881
+ if (options.cursor) params.set("cursor", options.cursor);
6882
+ if (options.limit) params.set("limit", String(options.limit));
6883
+ return json(mail(`${accountPath(options.accountId ?? NATIVE_ACCOUNT)}/messages?${params}`));
6884
+ }
6885
+ function getMessage2(mail, messageId, accountId = NATIVE_ACCOUNT) {
6886
+ return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`));
6887
+ }
6888
+ async function downloadAttachment(mail, messageId, attachmentId, accountId = NATIVE_ACCOUNT) {
6889
+ const path = `${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`;
6890
+ return new Uint8Array(await (await mail(path)).arrayBuffer());
6891
+ }
6892
+ async function updateMessage(mail, messageId, update, accountId = NATIVE_ACCOUNT) {
6893
+ await mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`, {
6894
+ method: "PATCH",
6895
+ body: JSON.stringify(update)
6896
+ });
6897
+ }
6898
+ function saveDraft(mail, compose, accountId = NATIVE_ACCOUNT) {
6899
+ return json(
6900
+ mail(`${accountPath(accountId)}/drafts`, { method: "POST", body: JSON.stringify(compose) })
6901
+ );
6902
+ }
6903
+ function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
6904
+ const body = { ...message, request_id: message.request_id ?? crypto.randomUUID() };
6905
+ return json(
6906
+ mail(`${accountPath(accountId)}/send`, { method: "POST", body: JSON.stringify(body) })
6907
+ );
6908
+ }
6909
+ async function unlockNativeMail(mail, keys) {
6910
+ await client.initSodium();
6911
+ const secretKey = client.deriveEncryptionKeypairFromSigning({
6912
+ publicKey: keys.signingPrivateKey.slice(32, 64),
6913
+ secretKey: keys.signingPrivateKey
6914
+ }).secretKey;
6915
+ try {
6916
+ let cursor = 0;
6917
+ while (cursor !== null) {
6918
+ const page = await json(
6919
+ mail(`/native/keys?cursor=${cursor}`)
6920
+ );
6921
+ const sealed = {};
6922
+ for (const [id, wrapped] of Object.entries(page.keys)) {
6923
+ const key = client.sealedBoxDecrypt(wrapped, secretKey);
6924
+ try {
6925
+ sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
6926
+ } finally {
6927
+ key.fill(0);
6928
+ }
6929
+ }
6930
+ if (Object.keys(sealed).length) {
6931
+ await mail("/native/session-keys", {
6932
+ method: "POST",
6933
+ body: JSON.stringify({ keys: sealed })
6934
+ });
6935
+ }
6936
+ cursor = page.next_cursor;
6937
+ }
6938
+ } finally {
6939
+ secretKey.fill(0);
6940
+ }
6941
+ }
6942
+ function attachmentFromBytes(name, contentType, bytes) {
6943
+ return {
6944
+ id: "",
6945
+ name,
6946
+ content_type: contentType,
6947
+ size: bytes.length,
6948
+ content_base64: bytesToBase64(bytes)
6949
+ };
6950
+ }
6951
+ function bytesToBase64(bytes) {
6952
+ let binary = "";
6953
+ for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
6954
+ binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
6955
+ }
6956
+ return btoa(binary);
6957
+ }
6958
+
6821
6959
  exports.Arbi = Arbi;
6822
6960
  exports.ArbiApiError = ArbiApiError;
6823
6961
  exports.ArbiError = ArbiError;
@@ -6850,6 +6988,7 @@ exports.formatWorkspaceChoices = formatWorkspaceChoices;
6850
6988
  exports.getErrorMessage = getErrorMessage;
6851
6989
  exports.getRawWorkspaceKey = getRawWorkspaceKey;
6852
6990
  exports.health = health_exports;
6991
+ exports.mail = mail_exports;
6853
6992
  exports.parseSSEEvents = parseSSEEvents;
6854
6993
  exports.parseSlashCommand = parseSlashCommand;
6855
6994
  exports.parseSlashTokenInProgress = parseSlashTokenInProgress;