UNPKG

dotencr

Version:

Encrypt and decrypt individual lines inside a .env file. Supports multiple encryption keys. Keys and dotenv files can be read text file or read from the environment.

88 lines (87 loc) 3.03 kB
import { DotenvVariable } from "./dotenv_variable"; export interface DotenvParserOptions { /** * Separator used to tokenize the left side of the key value pair. */ separatorLeft?: string; /** * Min number of tokens after parsing. Used to valid the format. */ minTokensLeft?: number; /** * Max number of tokens after parsing. Used to valid the format. */ maxTokensLeft?: number; /** * Separator used to tokenize the right side of the key value pair. */ separatorRight?: string; /** * Min number of tokens after parsing. Used to valid the format. */ minTokensRight?: number; /** * Max number of tokens after parsing. Used to valid the format. */ maxTokensRight?: number; /** * Current only supports a prefix to find dotenv variables. * @example UNENCRYPTED__ * @example CIPHERED__ * @example DOTENV_ENC_KEY__ */ cryptoKeyNamePrefix?: string; } export interface TokenizeResult { isValid: boolean; tokens: string[]; } /** * Base class for the parsing of the dotenv variables */ export declare abstract class DotenvParserBase { /** * All environment variables regardless of any errors */ readonly variablesAll: DotenvVariable[]; /** * Environment variables erroneously using a reserved word for the crypto key name */ readonly variablesUsingReservedWord: DotenvVariable[]; /** * List of invalid variables. Includes values using reserved words. */ readonly variableInvalid: DotenvVariable[]; /** * Environment variables without any errors */ readonly variables: DotenvVariable[]; readonly separatorLeft: string; readonly minTokensLeft: number; readonly maxTokensLeft: number; readonly separatorRight: string; readonly minTokensRight: number; readonly maxTokensRight: number; readonly cryptoKeyNamePrefix: string; constructor(options: DotenvParserOptions); protected tokenizeLeftSide(leftSide: string): TokenizeResult | undefined; protected tokenizeRightSide(rightSide: string): TokenizeResult; protected abstract tokenize(leftSide: string, rightSide: string): DotenvVariable | undefined; parseObject(env: object): void; } export declare class DotenvParserCryptoKey extends DotenvParserBase { constructor(); protected tokenize(leftSide: string, rightSide: string): DotenvVariable | undefined; } export declare class DotenvParserPlainTextVariable extends DotenvParserBase { constructor(); tokenize(leftSide: string, rightSide: string): DotenvVariable | undefined; } export declare class DotenvParserCipheredVariable extends DotenvParserBase { constructor(); tokenize(leftSide: string, rightSide: string): DotenvVariable | undefined; } export declare class DotenvParserTestConstructor extends DotenvParserBase { constructor(options: DotenvParserOptions); tokenize(_leftSide: string, _rightSide: string): DotenvVariable | undefined; }