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

Function resolveCredential

packages/cli/src/auth/resolver.ts:49–81  ·  view source on GitHub ↗
(opts: ResolveOptions = {})

Source from the content-addressed store, hash-verified

47}
48
49export async function resolveCredential(opts: ResolveOptions = {}): Promise<ResolvedCredential> {
50 const now = (opts.now ?? (() => new Date()))();
51
52 const heygenEnv = process.env["HEYGEN_API_KEY"];
53 if (heygenEnv && heygenEnv.length > 0) {
54 if (!isHeaderSafe(heygenEnv)) {
55 throw ErrInvalidStore("HEYGEN_API_KEY contains control characters");
56 }
57 return { type: "api_key", key: heygenEnv, source: "env" };
58 }
59
60 const hfEnv = process.env["HYPERFRAMES_API_KEY"];
61 if (hfEnv && hfEnv.length > 0) {
62 if (!isHeaderSafe(hfEnv)) {
63 throw ErrInvalidStore("HYPERFRAMES_API_KEY contains control characters");
64 }
65 return { type: "api_key", key: hfEnv, source: "env_alias" };
66 }
67
68 const { credentials, source } = await readStore();
69 if (source === "absent") throw ErrNotConfigured();
70
71 const fileSource: CredentialSource = source === "file_legacy" ? "file_legacy" : "file_json";
72
73 if (credentials.oauth) {
74 const oauth = pickOAuth(credentials.oauth, now, fileSource);
75 if (oauth) return oauth;
76 }
77 if (credentials.api_key) {
78 return { type: "api_key", key: credentials.api_key, source: fileSource };
79 }
80 throw ErrNotConfigured();
81}
82
83/** Like `resolveCredential` but returns `null` instead of throwing `NOT_CONFIGURED`. */
84export async function tryResolveCredential(

Callers 4

resolveCloudAuthHeadersFunction · 0.85
forceRefreshCredentialsFunction · 0.85
tryResolveCredentialFunction · 0.85
resolver.test.tsFile · 0.85

Calls 5

isHeaderSafeFunction · 0.85
ErrInvalidStoreFunction · 0.85
readStoreFunction · 0.85
ErrNotConfiguredFunction · 0.85
pickOAuthFunction · 0.85

Tested by

no test coverage detected