@arbidocs/sdk 0.5.4 → 0.5.5

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/index.cjs CHANGED
@@ -5645,6 +5645,7 @@ __export(workspaces_exports, {
5645
5645
  createWorkspace: () => createWorkspace,
5646
5646
  deleteWorkspaces: () => deleteWorkspaces,
5647
5647
  exportWorkspaceData: () => exportWorkspaceData,
5648
+ getWorkspaceAccessStatus: () => getWorkspaceAccessStatus,
5648
5649
  getWorkspaceActivity: () => getWorkspaceActivity,
5649
5650
  getWorkspaceTransfer: () => getWorkspaceTransfer,
5650
5651
  grantTemporaryWorkspaceAccess: () => grantTemporaryWorkspaceAccess,
@@ -5845,6 +5846,14 @@ async function exportWorkspaceData(arbi, scope) {
5845
5846
  "Failed to export the workspace"
5846
5847
  );
5847
5848
  }
5849
+ async function getWorkspaceAccessStatus(arbi, workspaceId) {
5850
+ return requireData(
5851
+ await arbi.fetch.GET("/v1/workspace/{workspace_ext_id}/access-status", {
5852
+ params: { path: { workspace_ext_id: workspaceId } }
5853
+ }),
5854
+ "Could not read workspace access"
5855
+ );
5856
+ }
5848
5857
 
5849
5858
  // src/operations/conversations.ts
5850
5859
  var conversations_exports = {};
@@ -6531,6 +6540,7 @@ var contacts_exports = {};
6531
6540
  __export(contacts_exports, {
6532
6541
  createContact: () => createContact,
6533
6542
  deleteContact: () => deleteContact,
6543
+ ensureContactsUnlocked: () => ensureContactsUnlocked,
6534
6544
  groupContactsByStatus: () => groupContactsByStatus,
6535
6545
  importContacts: () => importContacts,
6536
6546
  inviteContacts: () => inviteContacts,
@@ -6539,6 +6549,42 @@ __export(contacts_exports, {
6539
6549
  searchContacts: () => searchContacts,
6540
6550
  updateContact: () => updateContact
6541
6551
  });
6552
+ var contactUnlocks = /* @__PURE__ */ new WeakMap();
6553
+ async function ensureContactsUnlocked(client, keys) {
6554
+ if (!keys) return;
6555
+ let pending = contactUnlocks.get(keys.serverSessionKey);
6556
+ if (!pending) {
6557
+ pending = unlockContacts(client, keys).catch((error) => {
6558
+ contactUnlocks.delete(keys.serverSessionKey);
6559
+ throw error;
6560
+ });
6561
+ contactUnlocks.set(keys.serverSessionKey, pending);
6562
+ }
6563
+ await pending;
6564
+ }
6565
+ async function unlockContacts(client$1, keys) {
6566
+ await client.initSodium();
6567
+ const keypair = client.encryptionKeypairFromSigningKey(keys.signingPrivateKey);
6568
+ try {
6569
+ const page = requireData(await client$1.fetch.GET("/v1/contacts/keys"), "Reading contact keys");
6570
+ const sealed = {};
6571
+ for (const [id, wrapped] of Object.entries(page.keys)) {
6572
+ const key = client.sealedBoxDecrypt(wrapped, keypair.secretKey);
6573
+ try {
6574
+ sealed[id] = await client.sealKeyForSession(key, keys.serverSessionKey);
6575
+ } finally {
6576
+ key.fill(0);
6577
+ }
6578
+ }
6579
+ if (Object.keys(sealed).length)
6580
+ requireOk(
6581
+ await client$1.fetch.POST("/v1/contacts/session-keys", { body: { keys: sealed } }),
6582
+ "Unlocking contacts"
6583
+ );
6584
+ } finally {
6585
+ keypair.secretKey.fill(0);
6586
+ }
6587
+ }
6542
6588
  function requireContact(result, message) {
6543
6589
  const error = result.error;
6544
6590
  if (result.response?.status === 409 && error && typeof error === "object" && "contact_id" in error)
@@ -11051,6 +11097,7 @@ var Arbi = class {
11051
11097
  }
11052
11098
  // ── Workspaces ────────────────────────────────────────────────────────
11053
11099
  workspaces = {
11100
+ accessStatus: (workspaceId) => getWorkspaceAccessStatus(this.requireClient(), workspaceId),
11054
11101
  /**
11055
11102
  * Make a workspace usable for requests that name it, WITHOUT changing the current workspace
11056
11103
  * (on the server or in the host). `removeUsers` and `documents.list` open the workspace they
@@ -11558,22 +11605,27 @@ var Arbi = class {
11558
11605
  generate: (tagIds, docIds, options) => generateDocTags(this.requireClient(), tagIds, docIds, options)
11559
11606
  };
11560
11607
  // ── Contacts ──────────────────────────────────────────────────────────
11561
- // A card is sealed under its address book's key, which the calendar key bridge carries: without
11608
+ // A card is sealed under its address book's key, which the contacts key bridge carries: without
11562
11609
  // it the server returns `card: null` and refuses card writes.
11563
11610
  contacts = {
11564
- list: () => this.withCalendarKeys((c2) => listContacts(c2)),
11611
+ list: () => this.withContactKeys((c2) => listContacts(c2)),
11565
11612
  invite: (emails) => inviteContacts(this.requireClient(), emails),
11566
- create: (body) => this.withCalendarKeys((c2) => createContact(c2, body)),
11567
- update: (contactId, card) => this.withCalendarKeys((c2) => updateContact(c2, contactId, card)),
11613
+ create: (body) => this.withContactKeys((c2) => createContact(c2, body)),
11614
+ update: (contactId, card) => this.withContactKeys((c2) => updateContact(c2, contactId, card)),
11568
11615
  /** Link a card-only contact to `email` (invites it, or links the account at once). */
11569
- link: (contactId, email, card) => this.withCalendarKeys((c2) => linkContact(c2, contactId, email, card)),
11570
- delete: (contactId) => this.withCalendarKeys((c2) => deleteContact(c2, contactId)),
11616
+ link: (contactId, email, card) => this.withContactKeys((c2) => linkContact(c2, contactId, email, card)),
11617
+ delete: (contactId) => this.withContactKeys((c2) => deleteContact(c2, contactId)),
11571
11618
  /** Import one .vcf file (Pro). */
11572
- import: (file) => this.withCalendarKeys((c2) => importContacts(c2, file)),
11573
- search: (q2) => this.withCalendarKeys((c2) => searchContacts(c2, q2)),
11619
+ import: (file) => this.withContactKeys((c2) => importContacts(c2, file)),
11620
+ search: (q2) => this.withContactKeys((c2) => searchContacts(c2, q2)),
11574
11621
  groupByStatus: groupContactsByStatus
11575
11622
  };
11576
11623
  // ── Calendar ──────────────────────────────────────────────────────────
11624
+ async withContactKeys(op) {
11625
+ const client = this.requireClient();
11626
+ await ensureContactsUnlocked(client, this.calendarKeys());
11627
+ return op(client);
11628
+ }
11577
11629
  /** The keys the calendar unlock needs; `null` before login (calendars then read as locked). */
11578
11630
  calendarKeys() {
11579
11631
  const login = this.loginResult;