/** * Benchling Secrets Management * * This module provides types, validation, and utilities for managing * Benchling API credentials in AWS Secrets Manager. * * ## Supported Formats * * ### ARN Format * Provide the ARN of an existing AWS Secrets Manager secret: * ``` * arn:aws:secretsmanager:us-east-1:123456789012:secret:benchling-webhook/credentials * ``` * * ### JSON Format * Provide credentials as a JSON object: * ```json * { * "client_id": "your-client-id", * "client_secret": "your-client-secret", * "tenant": "your-tenant", * "app_definition_id": "optional-app-id", * "api_url": "https://optional-api-url.com" * } * ``` * * ## Usage * * ```typescript * import { parseAndValidateSecrets } from './secrets'; * * // Parse and validate ARN * const arnConfig = parseAndValidateSecrets( * 'arn:aws:secretsmanager:us-east-1:123456789012:secret:name' * ); * console.log(arnConfig.format); // "arn" * console.log(arnConfig.arn); // the validated ARN * * // Parse and validate JSON * const jsonConfig = parseAndValidateSecrets( * '{"client_id":"abc","client_secret":"secret","tenant":"company"}' * ); * console.log(jsonConfig.format); // "json" * console.log(jsonConfig.data); // the validated secret data * * // Handle validation errors * try { * parseAndValidateSecrets('invalid'); * } catch (error) { * if (error instanceof SecretsValidationError) { * console.error(error.formatForCLI()); * } * } * ``` * * @module secrets */ /** * Generate standardized secret name for AWS Secrets Manager * * Format: quiltdata/benchling-webhook/{profile}/{tenant} * * @param profile - Profile name (e.g., "default", "staging", "prod") * @param tenant - Benchling tenant name (e.g., "quilt-dtt") * @returns Standardized secret name * * @example * generateSecretName("default", "quilt-dtt") // "quiltdata/benchling-webhook/default/quilt-dtt" * generateSecretName("staging", "acme-corp") // "quiltdata/benchling-webhook/staging/acme-corp" */ export declare function generateSecretName(profile: string, tenant: string): string; /** * Benchling secret structure stored in AWS Secrets Manager */ export interface BenchlingSecretData { /** Benchling OAuth client ID */ client_id: string; /** Benchling OAuth client secret */ client_secret: string; /** Benchling tenant name (e.g., "company" for company.benchling.com) */ tenant: string; /** Benchling app definition ID (optional for backward compatibility) */ app_definition_id?: string; /** Custom Benchling API URL (optional, defaults to https://{tenant}.benchling.com) */ api_url?: string; } /** * Accepted formats for BENCHLING_SECRETS parameter * Can be either a Secret ARN or JSON string */ export type BenchlingSecretsInput = string; /** * Parsed and validated secret configuration */ export interface BenchlingSecretsConfig { /** The input format detected */ format: "arn" | "json"; /** If format is "arn", the validated ARN */ arn?: string; /** If format is "json", the validated secret data */ data?: BenchlingSecretData; /** Original input value (for error messages) */ original: string; } /** * Validation result with errors and warnings */ export interface ValidationResult { valid: boolean; errors: ValidationError[]; warnings: string[]; } /** * Validation error details */ export interface ValidationError { field: string; message: string; suggestion?: string; } /** * Detect whether input is an ARN or JSON string * * @param input - The BENCHLING_SECRETS input value * @returns "arn" if input looks like an ARN, "json" otherwise * * @example * detectSecretsFormat("arn:aws:secretsmanager:...") // returns "arn" * detectSecretsFormat('{"client_id":"..."}') // returns "json" */ export declare function detectSecretsFormat(input: string): "arn" | "json"; /** * Validate AWS Secrets Manager ARN format * * @param arn - The ARN string to validate * @returns Validation result with errors and warnings * * @example * validateSecretArn("arn:aws:secretsmanager:us-east-1:123456789012:secret:name") * // returns { valid: true, errors: [], warnings: [] } */ export declare function validateSecretArn(arn: string): ValidationResult; /** * Validate secret data structure and field values * * @param data - The secret data object to validate * @returns Validation result with errors and warnings * * @example * validateSecretData({ client_id: "abc", client_secret: "secret", tenant: "company" }) * // returns { valid: true, errors: [], warnings: [] } */ export declare function validateSecretData(data: unknown): ValidationResult; /** * Custom error class for secrets validation failures */ export declare class SecretsValidationError extends Error { readonly errors: ValidationError[]; readonly warnings: string[]; constructor(message: string, errors: ValidationError[], warnings: string[]); /** * Format errors for CLI display */ formatForCLI(): string; } /** * Parse and validate BENCHLING_SECRETS input * * This is the main entry point for secret validation. It detects the format * (ARN or JSON), performs appropriate validation, and returns a structured * configuration object. * * @param input - The BENCHLING_SECRETS input string * @returns Parsed and validated configuration * @throws SecretsValidationError if validation fails * * @example * // Parse ARN * const config = parseAndValidateSecrets("arn:aws:secretsmanager:...") * console.log(config.format) // "arn" * * @example * // Parse JSON * const config = parseAndValidateSecrets('{"client_id":"...","client_secret":"...","tenant":"..."}') * console.log(config.format) // "json" */ export declare function parseAndValidateSecrets(input: string): BenchlingSecretsConfig; //# sourceMappingURL=secrets.d.ts.map