@cortexkit/common-auth 0.11.4 → 0.11.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.
@@ -7,7 +7,7 @@ export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, Cla
7
7
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
8
8
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, type HostSlotContent, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
9
9
  export { acceptAccount, type DeclinedAccount, declineAccount, isDeclined, } from './interlock.js';
10
- export { type AccountMapper, acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, mutateVaultRoster, type ProjectionOptions, projectVaultRoster, type QuotaReceipt, readVaultRoster, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, type VaultPrimary, type VaultPrimaryBinding, type VaultPrimaryUnavailableReason, type VaultRosterFile, type VaultRosterLockContext, type VaultRosterRow, vaultRoutingRows, } from './roster.js';
10
+ export { type AccountMapper, acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, type MutateVaultRosterOptions, mutateVaultRoster, type ProjectionOptions, projectVaultRoster, type QuotaReceipt, readVaultRoster, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, type VaultPrimary, type VaultPrimaryBinding, type VaultPrimaryUnavailableReason, type VaultRosterFile, type VaultRosterLockContext, type VaultRosterRow, vaultRoutingRows, } from './roster.js';
11
11
  /**
12
12
  * Connect the client that lists and fetches this consumer's vault credentials
13
13
  * on the request path. `connectionFile` is required: this library
@@ -90,6 +90,16 @@ export declare function readVaultRoster(path: string): Promise<VaultRosterFile |
90
90
  export interface VaultRosterLockContext {
91
91
  assertOwned: () => Promise<void>;
92
92
  }
93
+ export interface MutateVaultRosterOptions {
94
+ /**
95
+ * Runs when the new roster is fully staged on disk, immediately before the
96
+ * rename that publishes it, so a caller can confirm a lease of its own at
97
+ * the moment of publication rather than when `change` returned. If it
98
+ * throws, nothing is published and the staged file is removed. The
99
+ * roster's own write lock is reasserted right after it.
100
+ */
101
+ beforePublish?: () => Promise<void>;
102
+ }
93
103
  /**
94
104
  * Read, change and write the roster under its write lock. `change` returns
95
105
  * undefined to leave the file as it is. Call `assertOwned()` immediately
@@ -101,7 +111,7 @@ export declare function mutateVaultRoster<T>(path: string, change: (current: Vau
101
111
  }> | {
102
112
  next?: VaultRosterFile;
103
113
  result: T;
104
- }): Promise<T>;
114
+ }, options?: MutateVaultRosterOptions): Promise<T>;
105
115
  /** Mark a vault account declined; it stays listed but never routes. */
106
116
  export declare function declineVaultRoute(path: string, routeId: string): Promise<undefined>;
107
117
  /** Lift the user's decline for a vault account and every alias of it. */
@@ -316,7 +316,7 @@ const DISCOVERY_LEASE = { name: 'claustrum-roster', ttlMs: 30_000 };
316
316
  * undefined to leave the file as it is. Call `assertOwned()` immediately
317
317
  * before any rename performed inside `change`; if it throws, do not rename.
318
318
  */
319
- export async function mutateVaultRoster(path, change) {
319
+ export async function mutateVaultRoster(path, change, options = {}) {
320
320
  return withLock(path, WRITE_LOCK, async (lock) => {
321
321
  const current = await readVaultRoster(path);
322
322
  const { next, result } = await change(current, {
@@ -324,7 +324,14 @@ export async function mutateVaultRoster(path, change) {
324
324
  });
325
325
  if (next) {
326
326
  await lock.assertOwned();
327
- await writeJsonAtomic(path, next);
327
+ // Staging the file takes several awaited steps; check both the caller's
328
+ // lease and this lock again at the last moment before the rename.
329
+ await writeJsonAtomic(path, next, {
330
+ beforeRename: async () => {
331
+ await options.beforePublish?.();
332
+ await lock.assertOwned();
333
+ },
334
+ });
328
335
  }
329
336
  return result;
330
337
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/common-auth",
3
- "version": "0.11.4",
3
+ "version": "0.11.5",
4
4
  "description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
5
5
  "license": "MIT",
6
6
  "repository": {