MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / readStore

Function readStore

packages/cli/src/auth/store.ts:120–143  ·  view source on GitHub ↗
(path = credentialPath())

Source from the content-addressed store, hash-verified

118}
119
120export async function readStore(path = credentialPath()): Promise<ReadResult> {
121 let raw: string;
122 try {
123 raw = await fs.readFile(path, "utf8");
124 } catch (err) {
125 if ((err as NodeJS.ErrnoException).code === "ENOENT") {
126 return { credentials: {}, source: "absent" };
127 }
128 throw ErrInvalidStore(`unable to read ${path}: ${(err as Error).message}`);
129 }
130
131 const trimmed = raw.trim();
132 if (trimmed.length === 0) return { credentials: {}, source: "absent" };
133
134 if (trimmed.startsWith("{")) {
135 return { credentials: parseJsonStore(trimmed), source: "file_json" };
136 }
137
138 if (looksLikeApiKey(trimmed)) {
139 return { credentials: { api_key: trimmed }, source: "file_legacy" };
140 }
141
142 throw ErrInvalidStore("file is not JSON and does not look like a plain API key");
143}
144
145export async function writeStore(credentials: Credentials, path = credentialPath()): Promise<void> {
146 await ensureDir(dirname(path));

Callers 13

persistOAuthFunction · 0.85
resolveCredentialFunction · 0.85
oauth.test.tsFile · 0.85
saveUserInfoFunction · 0.85
loadUserInfoFunction · 0.85
clearUserInfoFunction · 0.85
clearOAuthFunction · 0.85
user.test.tsFile · 0.85
store.test.tsFile · 0.85
login.test.tsFile · 0.85
snapshotStoreFunction · 0.85
runFunction · 0.85

Calls 4

credentialPathFunction · 0.85
ErrInvalidStoreFunction · 0.85
parseJsonStoreFunction · 0.85
looksLikeApiKeyFunction · 0.85

Tested by

no test coverage detected