import { CookieBlobStore } from "../store.js"; import { DeviceRegistry, AgentRegistry } from "../tokens.js"; import { AdminStore } from "../admin/auth.js"; import type { ICookieStore, IDeviceStore, IAgentStore, IAdminStore, DataStores, } from "./types.js"; import type { EncryptedCookieBlob, DeviceInfo, AgentToken } from "../../protocol/spec.js"; import type { AdminSettings } from "../admin/auth.js"; class MemoryCookieStore implements ICookieStore { private inner = new CookieBlobStore(); async upsert(blob: Omit): Promise { return this.inner.upsert(blob); } async delete(deviceId: string, domain: string, cookieName: string, path: string): Promise { return this.inner.delete(deviceId, domain, cookieName, path); } async deleteById(id: string): Promise { return this.inner.deleteById(id); } async getByDevice(deviceId: string, domain?: string): Promise { return this.inner.getByDevice(deviceId, domain); } async getByDevices(deviceIds: string[], domain?: string): Promise { return this.inner.getByDevices(deviceIds, domain); } async getAll(): Promise { return this.inner.getAll(); } async getById(id: string): Promise { return this.inner.getById(id); } async getUpdatedSince(deviceIds: string[], since: string): Promise { return this.inner.getUpdatedSince(deviceIds, since); } } class MemoryDeviceStore implements IDeviceStore { private inner = new DeviceRegistry(); async register(deviceId: string, name: string, platform: string, encPub: string): Promise { return this.inner.register(deviceId, name, platform, encPub); } async getByToken(token: string): Promise { return this.inner.getByToken(token); } async getById(deviceId: string): Promise { return this.inner.getById(deviceId); } async addPairing(deviceIdA: string, deviceIdB: string): Promise { this.inner.addPairing(deviceIdA, deviceIdB); } async getPairedDevices(deviceId: string): Promise { return this.inner.getPairedDevices(deviceId); } async getPairingGroup(deviceId: string): Promise { return this.inner.getPairingGroup(deviceId); } async listAll(): Promise { return this.inner.listAll(); } async revoke(deviceId: string): Promise { return this.inner.revoke(deviceId); } } class MemoryAgentStore implements IAgentStore { private inner = new AgentRegistry(); async create(name: string, encPub: string, allowedDomains: string[]): Promise { return this.inner.create(name, encPub, allowedDomains); } async getByToken(token: string): Promise { return this.inner.getByToken(token); } async grantAccess(agentId: string, deviceId: string): Promise { this.inner.grantAccess(agentId, deviceId); } async getAccessibleDevices(agentId: string): Promise { return this.inner.getAccessibleDevices(agentId); } async revokeAccess(agentId: string, deviceId: string): Promise { this.inner.revokeAccess(agentId, deviceId); } } class MemoryAdminStore implements IAdminStore { private inner = new AdminStore(); get isSetUp(): boolean { return this.inner.isSetUp; } async setup(username: string, password: string): Promise { return this.inner.setup(username, password); } async login(username: string, password: string): Promise { return this.inner.login(username, password); } verifyToken(token: string): { sub: string; role: string } { return this.inner.verifyToken(token); } getUser(): { username: string; createdAt: string } | null { return this.inner.getUser(); } getSettings(): AdminSettings { return this.inner.getSettings(); } updateSettings(patch: Partial): AdminSettings { return this.inner.updateSettings(patch); } } export function createMemoryStores(): DataStores { return { cookieStore: new MemoryCookieStore(), deviceStore: new MemoryDeviceStore(), agentStore: new MemoryAgentStore(), adminStore: new MemoryAdminStore(), async close() { /* no-op */ }, }; }