@enspirit/emb
Version:
A replacement for our Makefile-for-monorepos
61 lines (60 loc) • 2.25 kB
TypeScript
/**
* Cached token metadata stored on disk.
*/
export interface CachedToken {
/** Unix timestamp (ms) when the token was cached */
createdAt: number;
/** Unix timestamp (ms) when the token expires */
expiresAt: number;
/** Vault namespace (if any) */
namespace?: string;
/** The Vault client token */
token: string;
/** Vault address this token is for */
vaultAddress: string;
}
/**
* Options for token caching.
*/
export interface TokenCacheOptions {
/** Custom cache directory (default: ~/.emb/vault-tokens) */
cacheDir?: string;
/** Buffer time in ms before expiry to consider token invalid (default: 5 minutes) */
expiryBuffer?: number;
}
/**
* Retrieve a cached token if it exists and is still valid.
*
* @param vaultAddress - The Vault server address
* @param namespace - Optional Vault namespace
* @param options - Cache options
* @returns The cached token or null if not found/expired
*/
export declare function getCachedToken(vaultAddress: string, namespace?: string, options?: TokenCacheOptions): Promise<CachedToken | null>;
/**
* Cache a Vault token to disk (encrypted).
*
* @param vaultAddress - The Vault server address
* @param token - The Vault client token
* @param ttlSeconds - Token TTL in seconds (from Vault's lease_duration)
* @param namespace - Optional Vault namespace
* @param options - Cache options
*/
export declare function cacheToken(vaultAddress: string, token: string, ttlSeconds: number, namespace?: string, options?: TokenCacheOptions): Promise<void>;
/**
* Clear a cached token.
*
* @param vaultAddress - The Vault server address
* @param namespace - Optional Vault namespace
* @param options - Cache options
*/
export declare function clearCachedToken(vaultAddress: string, namespace?: string, options?: TokenCacheOptions): Promise<void>;
/**
* Check if a cached token exists and is valid (without returning the token).
*
* @param vaultAddress - The Vault server address
* @param namespace - Optional Vault namespace
* @param options - Cache options
* @returns True if a valid cached token exists
*/
export declare function hasCachedToken(vaultAddress: string, namespace?: string, options?: TokenCacheOptions): Promise<boolean>;