dify/cli/test/fixtures/mem-store.ts
Xiyuan Chen a650ffc00a
refactor(cli): auth/workspace cleanup — record-backed token store (#37219)
Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
2026-06-12 03:10:54 +00:00

28 lines
835 B
TypeScript

import type { TokenStore } from '../../src/store/token-store.js'
// In-memory TokenStore for tests; mirrors keyring semantics (empty string = missing).
export class MemStore implements TokenStore {
readonly entries: Map<string, string>
// Seed keys use the composite "<host> <email>" form, e.g. { 'h1 a@x': 'dfoa_a' }.
constructor(seed: Record<string, string> = {}) {
this.entries = new Map(Object.entries(seed))
}
private k(host: string, email: string): string {
return `${host} ${email}`
}
read(host: string, email: string): string {
return this.entries.get(this.k(host, email)) ?? ''
}
write(host: string, email: string, bearer: string): void {
this.entries.set(this.k(host, email), bearer)
}
remove(host: string, email: string): void {
this.entries.delete(this.k(host, email))
}
}