| 9 | const UNSAFE_SESSION_FILENAME = 'auth-session.json'; |
| 10 | |
| 11 | export class PlaintextFileSessionStore implements CredentialsStore { |
| 12 | private readonly filePath: string; |
| 13 | |
| 14 | constructor(private readonly cacheDir: string, private readonly logger: Logger) { |
| 15 | this.filePath = path.join(this.cacheDir, UNSAFE_SESSION_FILENAME); |
| 16 | } |
| 17 | |
| 18 | async load(): Promise<Credentials | null> { |
| 19 | const file = Bun.file(this.filePath); |
| 20 | if (!(await file.exists())) { |
| 21 | this.logger.debug(`Session file does not exist: ${this.filePath}`); |
| 22 | return null; |
| 23 | } |
| 24 | this.logger.debug(`Loading session from file: ${this.filePath}`); |
| 25 | return parseStoredSnapshot(await file.text()); |
| 26 | } |
| 27 | |
| 28 | async save(snapshot: Credentials): Promise<void> { |
| 29 | this.logger.debug(`Saving session to file: ${this.filePath}`); |
| 30 | await Bun.write(this.filePath, JSON.stringify(snapshot), { mode: 0o600 }); |
| 31 | } |
| 32 | |
| 33 | async remove(): Promise<void> { |
| 34 | this.logger.debug(`Removing session file: ${this.filePath}`); |
| 35 | try { |
| 36 | await unlink(this.filePath); |
| 37 | } catch (err: unknown) { |
| 38 | const code = err && typeof err === 'object' && 'code' in err ? (err as NodeJS.ErrnoException).code : undefined; |
| 39 | if (code !== 'ENOENT') { |
| 40 | throw err; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
nothing calls this directly
no outgoing calls
no test coverage detected