@vellumai/credential-executor 0.11.7-dev.202608310724.dde6a86 → 0.11.7-dev.202608311418.27c51fa
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.
|
@@ -216,6 +216,8 @@ export interface StaticCredentialPolicyInput {
|
|
|
216
216
|
*/
|
|
217
217
|
export class StaticCredentialMetadataStore {
|
|
218
218
|
private metadataPath: string;
|
|
219
|
+
/** When set, reads and writes stay in process and do not touch the file. */
|
|
220
|
+
private memory: MetadataFile | null = null;
|
|
219
221
|
|
|
220
222
|
constructor(metadataPath: string) {
|
|
221
223
|
this.metadataPath = metadataPath;
|
|
@@ -224,6 +226,17 @@ export class StaticCredentialMetadataStore {
|
|
|
224
226
|
/** Update the metadata file path (primarily for testing). */
|
|
225
227
|
setPath(path: string): void {
|
|
226
228
|
this.metadataPath = path;
|
|
229
|
+
this.memory = null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Switch to an in-memory backing filled with `records`.
|
|
234
|
+
*/
|
|
235
|
+
useMemory(records: StaticCredentialRecord[] = []): void {
|
|
236
|
+
this.memory = {
|
|
237
|
+
version: CURRENT_VERSION,
|
|
238
|
+
credentials: records.map((record) => ({ ...record })),
|
|
239
|
+
};
|
|
227
240
|
}
|
|
228
241
|
|
|
229
242
|
/** Get the current metadata file path. */
|
|
@@ -231,13 +244,28 @@ export class StaticCredentialMetadataStore {
|
|
|
231
244
|
return this.metadataPath;
|
|
232
245
|
}
|
|
233
246
|
|
|
247
|
+
private load(): LoadResult {
|
|
248
|
+
if (this.memory) {
|
|
249
|
+
return this.memory;
|
|
250
|
+
}
|
|
251
|
+
return loadFile(this.metadataPath, saveFile);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private persist(data: MetadataFile): void {
|
|
255
|
+
if (this.memory) {
|
|
256
|
+
this.memory = data;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
saveFile(data, this.metadataPath);
|
|
260
|
+
}
|
|
261
|
+
|
|
234
262
|
/**
|
|
235
263
|
* Throws if the metadata file has an unrecognized version.
|
|
236
264
|
* Call this before performing irreversible credential store operations
|
|
237
265
|
* so the operation fails cleanly before any side effects.
|
|
238
266
|
*/
|
|
239
267
|
assertWritable(): void {
|
|
240
|
-
const result =
|
|
268
|
+
const result = this.load();
|
|
241
269
|
if (isUnknownVersion(result)) {
|
|
242
270
|
throw new Error(
|
|
243
271
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -254,7 +282,7 @@ export class StaticCredentialMetadataStore {
|
|
|
254
282
|
field: string,
|
|
255
283
|
policy?: StaticCredentialPolicyInput
|
|
256
284
|
): StaticCredentialRecord {
|
|
257
|
-
const result =
|
|
285
|
+
const result = this.load();
|
|
258
286
|
if (isUnknownVersion(result)) {
|
|
259
287
|
throw new Error(
|
|
260
288
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -268,12 +296,15 @@ export class StaticCredentialMetadataStore {
|
|
|
268
296
|
);
|
|
269
297
|
|
|
270
298
|
if (existing) {
|
|
271
|
-
if (policy?.allowedTools !== undefined)
|
|
299
|
+
if (policy?.allowedTools !== undefined) {
|
|
272
300
|
existing.allowedTools = policy.allowedTools;
|
|
273
|
-
|
|
301
|
+
}
|
|
302
|
+
if (policy?.allowedDomains !== undefined) {
|
|
274
303
|
existing.allowedDomains = policy.allowedDomains;
|
|
275
|
-
|
|
304
|
+
}
|
|
305
|
+
if (policy?.usageDescription !== undefined) {
|
|
276
306
|
existing.usageDescription = policy.usageDescription;
|
|
307
|
+
}
|
|
277
308
|
if (policy?.alias !== undefined) {
|
|
278
309
|
if (policy.alias == null) {
|
|
279
310
|
delete existing.alias;
|
|
@@ -289,7 +320,7 @@ export class StaticCredentialMetadataStore {
|
|
|
289
320
|
}
|
|
290
321
|
}
|
|
291
322
|
existing.updatedAt = now;
|
|
292
|
-
|
|
323
|
+
this.persist(data);
|
|
293
324
|
return existing;
|
|
294
325
|
}
|
|
295
326
|
|
|
@@ -307,7 +338,7 @@ export class StaticCredentialMetadataStore {
|
|
|
307
338
|
};
|
|
308
339
|
|
|
309
340
|
data.credentials.push(record);
|
|
310
|
-
|
|
341
|
+
this.persist(data);
|
|
311
342
|
return record;
|
|
312
343
|
}
|
|
313
344
|
|
|
@@ -318,7 +349,7 @@ export class StaticCredentialMetadataStore {
|
|
|
318
349
|
service: string,
|
|
319
350
|
field: string
|
|
320
351
|
): StaticCredentialRecord | undefined {
|
|
321
|
-
const result =
|
|
352
|
+
const result = this.load();
|
|
322
353
|
if (isUnknownVersion(result)) return undefined;
|
|
323
354
|
return result.credentials.find(
|
|
324
355
|
(c) => c.service === service && c.field === field
|
|
@@ -329,7 +360,7 @@ export class StaticCredentialMetadataStore {
|
|
|
329
360
|
* Get metadata for a credential by its opaque ID.
|
|
330
361
|
*/
|
|
331
362
|
getById(credentialId: string): StaticCredentialRecord | undefined {
|
|
332
|
-
const result =
|
|
363
|
+
const result = this.load();
|
|
333
364
|
if (isUnknownVersion(result)) return undefined;
|
|
334
365
|
return result.credentials.find((c) => c.credentialId === credentialId);
|
|
335
366
|
}
|
|
@@ -338,7 +369,7 @@ export class StaticCredentialMetadataStore {
|
|
|
338
369
|
* List all credential metadata records.
|
|
339
370
|
*/
|
|
340
371
|
list(): StaticCredentialRecord[] {
|
|
341
|
-
const result =
|
|
372
|
+
const result = this.load();
|
|
342
373
|
if (isUnknownVersion(result)) return [];
|
|
343
374
|
return result.credentials;
|
|
344
375
|
}
|
|
@@ -347,7 +378,7 @@ export class StaticCredentialMetadataStore {
|
|
|
347
378
|
* Delete metadata for a credential.
|
|
348
379
|
*/
|
|
349
380
|
delete(service: string, field: string): boolean {
|
|
350
|
-
const result =
|
|
381
|
+
const result = this.load();
|
|
351
382
|
if (isUnknownVersion(result)) {
|
|
352
383
|
throw new Error(
|
|
353
384
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -359,7 +390,7 @@ export class StaticCredentialMetadataStore {
|
|
|
359
390
|
);
|
|
360
391
|
if (idx === -1) return false;
|
|
361
392
|
data.credentials.splice(idx, 1);
|
|
362
|
-
|
|
393
|
+
this.persist(data);
|
|
363
394
|
return true;
|
|
364
395
|
}
|
|
365
396
|
}
|