/** * Represents a single environment variable parsed from a .env file */ interface EnvVariable { /** The variable name/key */ key: string; /** The variable value */ value: string; /** Optional comment from preceding line */ comment?: string; /** Line number in source file */ line: number; } /** * Represents a line in the .env file (preserves structure) */ type EnvLine = { type: "comment"; content: string; } | { type: "empty"; } | { type: "variable"; key: string; value: string; }; /** * Result of parsing an .env file */ interface ParseResult { /** Successfully parsed variables */ variables: EnvVariable[]; /** All lines preserving structure */ lines: EnvLine[]; /** Any parse errors encountered */ errors: string[]; } /** * Options for creating a 1Password Secure Note */ interface CreateItemOptions { /** Vault name */ vault: string; /** Item title */ title: string; /** Fields to store */ fields: EnvVariable[]; /** Store as password type (hidden) instead of text (visible) */ secret: boolean; } /** * Options for editing a 1Password Secure Note */ interface EditItemOptions extends CreateItemOptions { /** Item ID for reliable lookup (more robust than using title) */ itemId: string; } /** * Result of creating a 1Password item */ interface CreateItemResult { /** 1Password item ID */ id: string; /** Item title */ title: string; /** Vault name */ vault: string; /** Vault ID */ vaultId: string; /** Field IDs mapped by field label */ fieldIds: Record; } /** * Options for the convert command (env2op) */ interface ConvertOptions { /** Path to .env file */ envFile: string; /** 1Password vault name */ vault: string; /** Secure Note title */ itemName: string; /** Custom output path for template file */ output?: string; /** Preview mode - don't make changes */ dryRun: boolean; /** Store all fields as password type */ secret: boolean; /** Skip confirmation prompts */ force: boolean; /** Show op CLI output */ verbose: boolean; } /** * Options for template generation */ interface TemplateOptions { /** Vault ID */ vaultId: string; /** Item ID in 1Password */ itemId: string; /** Variables to include */ variables: EnvVariable[]; /** All lines preserving structure */ lines: EnvLine[]; /** Field IDs mapped by field label */ fieldIds: Record; } /** * Parse an .env file and extract environment variables * * @param filePath - Path to the .env file * @returns ParseResult containing variables and any errors * @throws Env2OpError if file not found */ declare function parseEnvFile(filePath: string): Promise; /** * Validate that the parsed result has variables * * @param result - ParseResult from parseEnvFile * @param filePath - Original file path for error message * @throws Env2OpError if no variables found */ declare function validateParseResult(result: ParseResult, filePath: string): void; interface VerboseOption { verbose?: boolean; } /** * Check if the 1Password CLI is installed */ declare function checkOpCli(options?: VerboseOption): Promise; /** * Check if user is signed in to 1Password CLI */ declare function checkSignedIn(options?: VerboseOption): Promise; /** * Sign in to 1Password CLI (opens system auth dialog) */ declare function signIn(options?: VerboseOption): Promise; /** * Check if an item exists in a vault, return its ID if found */ declare function itemExists2(vault: string, title: string, options?: VerboseOption): Promise; /** * Check if a vault exists */ declare function vaultExists(vault: string, options?: VerboseOption): Promise; /** * Create a new vault */ declare function createVault(name: string, options?: VerboseOption): Promise; /** * Create a Secure Note in 1Password with the given fields */ declare function createSecureNote(options: CreateItemOptions & VerboseOption): Promise; /** * Edit an existing Secure Note in 1Password - updates fields in place * This preserves the item UUID and doesn't add to trash * JSON piping completely replaces fields - no need for manual deletion */ declare function editSecureNote(options: EditItemOptions & VerboseOption): Promise; /** * Generate op:// reference template content * * Format: KEY=op://vault/item/field * * This template can be used with: * - `op2env template.tpl` to generate .env * - `op run --env-file template.tpl -- command` */ declare function generateTemplateContent(options: TemplateOptions, templateFileName: string): string; /** * Write template to file */ declare function writeTemplate(content: string, outputPath: string): void; /** * Generate usage instructions for display */ declare function generateUsageInstructions(templatePath: string): string; /** * Custom error class for env2op with error codes and suggestions */ declare class Env2OpError extends Error { code: ErrorCode; suggestion?: string | undefined; constructor(message: string, code: ErrorCode, suggestion?: string | undefined); } /** * Error codes for different failure scenarios */ declare const ErrorCodes: { readonly ENV_FILE_NOT_FOUND: "ENV_FILE_NOT_FOUND"; readonly ENV_FILE_EMPTY: "ENV_FILE_EMPTY"; readonly OP_CLI_NOT_INSTALLED: "OP_CLI_NOT_INSTALLED"; readonly OP_NOT_SIGNED_IN: "OP_NOT_SIGNED_IN"; readonly OP_SIGNIN_FAILED: "OP_SIGNIN_FAILED"; readonly VAULT_NOT_FOUND: "VAULT_NOT_FOUND"; readonly VAULT_CREATE_FAILED: "VAULT_CREATE_FAILED"; readonly ITEM_EXISTS: "ITEM_EXISTS"; readonly ITEM_CREATE_FAILED: "ITEM_CREATE_FAILED"; readonly ITEM_EDIT_FAILED: "ITEM_EDIT_FAILED"; readonly PARSE_ERROR: "PARSE_ERROR"; readonly TEMPLATE_NOT_FOUND: "TEMPLATE_NOT_FOUND"; readonly INJECT_FAILED: "INJECT_FAILED"; }; type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]; /** * Error factory functions for common scenarios */ declare const errors: { envFileNotFound: (path: string) => Env2OpError; envFileEmpty: (path: string) => Env2OpError; opCliNotInstalled: () => Env2OpError; opNotSignedIn: () => Env2OpError; opSigninFailed: () => Env2OpError; vaultNotFound: (vault: string) => Env2OpError; vaultCreateFailed: (message: string) => Env2OpError; itemExists: (title: string, vault: string) => Env2OpError; itemCreateFailed: (message: string) => Env2OpError; itemEditFailed: (message: string) => Env2OpError; parseError: (line: number, message: string) => Env2OpError; templateNotFound: (path: string) => Env2OpError; injectFailed: (message: string) => Env2OpError; }; export { writeTemplate, vaultExists, validateParseResult, signIn, parseEnvFile, itemExists2 as itemExists, generateUsageInstructions, generateTemplateContent, errors, editSecureNote, createVault, createSecureNote, checkSignedIn, checkOpCli, TemplateOptions, ParseResult, ErrorCodes, EnvVariable, EnvLine, Env2OpError, CreateItemResult, CreateItemOptions, ConvertOptions };