1919import { isHeaderSafe , readStore } from "./store.js" ;
2020import { ErrInvalidStore , ErrLoginExpired , ErrNotConfigured , isAuthError } from "./errors.js" ;
2121
22- type CredentialSource = "env" | "env_alias" | "env_oauth" | "file_json" | "file_legacy" ;
22+ type EnvSource = "env" | "env_alias" | "env_oauth" ;
23+ type CredentialSource = EnvSource | "file_json" | "file_legacy" ;
24+
25+ export const ENV_CREDENTIAL_VAR : Record < EnvSource , string > = {
26+ env : "HEYGEN_API_KEY" ,
27+ env_alias : "HYPERFRAMES_API_KEY" ,
28+ env_oauth : "HEYGEN_ACCESS_TOKEN" ,
29+ } ;
30+
31+ export const envCredentialVar = ( source : CredentialSource ) : string | undefined =>
32+ source in ENV_CREDENTIAL_VAR ? ENV_CREDENTIAL_VAR [ source as EnvSource ] : undefined ;
2333
2434interface ApiKeyCredential {
2535 type : "api_key" ;
@@ -40,12 +50,6 @@ interface OAuthCredential {
4050
4151export type ResolvedCredential = ApiKeyCredential | OAuthCredential ;
4252
43- export const ENV_CREDENTIAL_VAR : Partial < Record < CredentialSource , string > > = {
44- env : "HEYGEN_API_KEY" ,
45- env_alias : "HYPERFRAMES_API_KEY" ,
46- env_oauth : "HEYGEN_ACCESS_TOKEN" ,
47- } ;
48-
4953const EXPIRY_SKEW_MS = 60 * 1000 ;
5054
5155export interface ResolveOptions {
@@ -55,17 +59,17 @@ export interface ResolveOptions {
5559export async function resolveCredential ( opts : ResolveOptions = { } ) : Promise < ResolvedCredential > {
5660 const now = ( opts . now ?? ( ( ) => new Date ( ) ) ) ( ) ;
5761
58- const heygenEnv = headerSafeEnv ( "HEYGEN_API_KEY" ) ;
62+ const heygenEnv = headerSafeEnv ( ENV_CREDENTIAL_VAR . env ) ;
5963 if ( heygenEnv ) {
6064 return { type : "api_key" , key : heygenEnv , source : "env" } ;
6165 }
6266
63- const hfEnv = headerSafeEnv ( "HYPERFRAMES_API_KEY" ) ;
67+ const hfEnv = headerSafeEnv ( ENV_CREDENTIAL_VAR . env_alias ) ;
6468 if ( hfEnv ) {
6569 return { type : "api_key" , key : hfEnv , source : "env_alias" } ;
6670 }
6771
68- const accessToken = headerSafeEnv ( "HEYGEN_ACCESS_TOKEN" ) ;
72+ const accessToken = headerSafeEnv ( ENV_CREDENTIAL_VAR . env_oauth ) ;
6973 if ( accessToken ) {
7074 return { type : "oauth" , access_token : accessToken , source : "env_oauth" , refreshable : false } ;
7175 }
0 commit comments