UNPKG

@simbachain/simbats

Version:
134 lines 4.71 kB
import Configstore from 'configstore'; import { Logger } from "tslog"; export declare enum SimbaEnvVarKeys { SIMBA_AUTH_CLIENT_ID = "SIMBA_AUTH_CLIENT_ID", SIMBA_AUTH_CLIENT_SECRET = "SIMBA_AUTH_CLIENT_SECRET", SIMBA_API_BASE_URL = "SIMBA_API_BASE_URL", SIMBA_AUTH_BASE_URL = "SIMBA_AUTH_BASE_URL", SIMBA_AUTH_SCOPE = "SIMBA_AUTH_SCOPE", SIMBA_AUTH_REALM = "SIMBA_AUTH_REALM", SIMBA_AUTH_ENDPOINT = "SIMBA_AUTH_ENDPOINT", SIMBA_LOGGING_HOME = "SIMBA_LOGGING_HOME", SIMBA_HOME = "SIMBA_HOME", SIMBA_LOG_LEVEL = "SIMBA_LOG_LEVEL" } declare enum SimbaEnvFiles { DOT_SIMBACHAIN_DOT_ENV = ".simbachain.env", SIMBACHAIN_DOT_ENV = "simbachain.env", DOT_ENV = ".env" } export declare const simbaEnvFilesArray: SimbaEnvFiles[]; export declare const AUTHKEY = "SIMBAAUTH"; export declare enum LogLevel { SILLY = "silly", TRACE = "trace", DEBUG = "debug", INFO = "info", WARN = "warn", ERROR = "error", FATAL = "fatal" } export declare class SimbaConfig { static _authConfig: Configstore; static _projectConfigStore: Configstore; static simbaEnvVarFileConfigured: boolean | undefined; static simbaEnvVarFile: string | undefined; static envVars: Record<any, any>; /** * handles our auth / access token info */ static get authConfig(): Configstore; /** * handles project info, contained in simba.json * simba.json is not currently used in SimbaTS, but * there may be a use case for storing project info in the future */ static get ProjectConfigStore(): Configstore; /** * this is what we use for logging */ static get log(): Logger; /** * how we get loglevel */ static get logLevel(): LogLevel; /** * retrieves SIMBA_API_BASE_URL from env file */ static get baseURL(): string; /** * helper function for setting env vars, so we're not repeating loop code * @param dir * @param foundKeys * @returns */ private static setEnvVarsFromDirectory; /** * this method only gets called once, when a process first tries to retrieve an env var * if SimbaConfig.envVars's values is zero length, then we call this method * * The code is a bit convoluted, so here's the process: * 1. iterate through file names of (.simbachain.env, simbachain.env, .env) in our project root * 2. we then loop through each of our SimbaEnvVarKeys until we find all of them, or * we have finished going through all files (not all env vars are necessary to be set) * 3. we then run through 1-4 again, but we use SIMBA_HOME instead of project root * 4. set as SimbaConfig.envVars once finished * @returns {Promise<Record<any, any>>} */ static setEnvVars(): Record<any, any>; /** * retrieves value for env var key. looks for: * * if SimbaConfig.envVars values has zero length, we first call SimbaConfig.setEnvVars * @param SimbaEnvVarKeys * @returns */ static retrieveEnvVar(envVarKey: SimbaEnvVarKeys): string; /** * sets auth token in authconfig.json * @param authToken * @returns */ static setAuthToken(authToken: Record<any, any>): void; /** * retrieves auth token from authconfig.json * @returns {Record<any, any>} */ static getAuthTokenFromConfig(): Record<any, any>; /** * takes in an auth token and adds new fields, such as retrieved_at and expires_at * @param authToken * @returns {Record<any, any>} */ static parseExpiry(authToken: Record<any, any>): Record<any, any>; /** * parses auth token and sets it in authconfig.json * @param authToken * @returns {Record<any, any>} */ static getAndSetParsedAuthToken(authToken: Record<any, any>): Record<any, any>; /** * checks if auth token is expired. used as a check before we make http call * idea is to check for bad token before http call, if possible * @returns {boolean} */ static tokenExpired(): boolean; /** * checks if refresh token is expired. used as a check before we make http call * idea is to check for bad token before http call, if possible * * Note: likely won't use, since the SDK will use client creds, and the * access token for client creds does not have a refresh token * @returns {boolean} */ refreshTokenExpired(): boolean; /** * set a field in auth token in authconfig.json * @param fieldKey * @param fieldVal * @returns */ static setAuthTokenField(fieldKey: string, fieldVal: any): void; } export {}; //# sourceMappingURL=config.d.ts.map