@foldrun/core 20.1.0 → 20.2.0

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.
@@ -57,9 +57,18 @@ export interface VaultStore {
57
57
  mutate(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile;
58
58
  /** The workspaces of this account whose scope is in the store. */
59
59
  workspaces(tenant: string): string[];
60
+ /** The scope's FILE was just written while the store is not serving it
61
+ * (switched off): whatever the store still holds for it is stale and must
62
+ * go, so switching back on starts from the file. */
63
+ forget?(tenant: string, workspace?: string): void;
60
64
  }
61
65
  /** Register (or, with null, remove) the platform's vault store. None: files. */
62
66
  export declare function setVaultStore(store: VaultStore | null): void;
67
+ /** Where a scope's vault file is (a platform store imports from it and keeps
68
+ * it current while files remain the fallback). */
69
+ export declare function vaultFilePath(tenant: string, workspace?: string): string;
70
+ /** A vault file's records as they are stored; {} when there is none. */
71
+ export declare function readVaultFile(file: string): SecretsFile;
63
72
  /**
64
73
  * An exclusive lock on `file` for a read-change-write, across processes and
65
74
  * pods: `<file>.lock` opened O_EXCL (NFS 4.1 and EFS honour it), taken over
@@ -208,7 +208,26 @@ function read(tenant, workspace) {
208
208
  /** Change one vault scope safely, wherever it lives (see mutateVaultFile). */
209
209
  function mutateVault(tenant, workspace, change) {
210
210
  const store = inStore(tenant, workspace);
211
- return store ? store.mutate(tenant, workspace, change) : mutateVaultFile(secretsFile(tenant, workspace), change);
211
+ if (store)
212
+ return store.mutate(tenant, workspace, change);
213
+ let wrote = false;
214
+ const after = mutateVaultFile(secretsFile(tenant, workspace), (all) => {
215
+ const next = change(all);
216
+ wrote = next !== null;
217
+ return next;
218
+ });
219
+ if (wrote)
220
+ vaultStore?.forget?.(tenant, workspace);
221
+ return after;
222
+ }
223
+ /** Where a scope's vault file is (a platform store imports from it and keeps
224
+ * it current while files remain the fallback). */
225
+ export function vaultFilePath(tenant, workspace) {
226
+ return secretsFile(tenant, workspace);
227
+ }
228
+ /** A vault file's records as they are stored; {} when there is none. */
229
+ export function readVaultFile(file) {
230
+ return readFile(file);
212
231
  }
213
232
  // ------------------------------------------------------------ safe writes
214
233
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "20.1.0",
3
+ "version": "20.2.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/secrets.ts CHANGED
@@ -272,6 +272,10 @@ export interface VaultStore {
272
272
  mutate(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile;
273
273
  /** The workspaces of this account whose scope is in the store. */
274
274
  workspaces(tenant: string): string[];
275
+ /** The scope's FILE was just written while the store is not serving it
276
+ * (switched off): whatever the store still holds for it is stale and must
277
+ * go, so switching back on starts from the file. */
278
+ forget?(tenant: string, workspace?: string): void;
275
279
  }
276
280
 
277
281
  let vaultStore: VaultStore | null = null;
@@ -289,7 +293,25 @@ function read(tenant: string, workspace?: string): SecretsFile {
289
293
  /** Change one vault scope safely, wherever it lives (see mutateVaultFile). */
290
294
  function mutateVault(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile {
291
295
  const store = inStore(tenant, workspace);
292
- return store ? store.mutate(tenant, workspace, change) : mutateVaultFile(secretsFile(tenant, workspace), change);
296
+ if (store) return store.mutate(tenant, workspace, change);
297
+ let wrote = false;
298
+ const after = mutateVaultFile(secretsFile(tenant, workspace), (all) => {
299
+ const next = change(all);
300
+ wrote = next !== null;
301
+ return next;
302
+ });
303
+ if (wrote) vaultStore?.forget?.(tenant, workspace);
304
+ return after;
305
+ }
306
+
307
+ /** Where a scope's vault file is (a platform store imports from it and keeps
308
+ * it current while files remain the fallback). */
309
+ export function vaultFilePath(tenant: string, workspace?: string): string {
310
+ return secretsFile(tenant, workspace);
311
+ }
312
+ /** A vault file's records as they are stored; {} when there is none. */
313
+ export function readVaultFile(file: string): SecretsFile {
314
+ return readFile(file);
293
315
  }
294
316
 
295
317
  // ------------------------------------------------------------ safe writes