UNPKG

document-extraction-service

Version:
72 lines (59 loc) 1.62 kB
class ExtractionConfig { #endpoint; #headers; #callback_url_pattern; #timeout_days; #max_retries; constructor(config) { if (!config || typeof config !== 'object') { throw new Error('Invalid configuration'); } this.#validateConfig(config); this.#endpoint = config.endpoint; this.#headers = config.headers || {}; this.#timeout_days = this.#validateTimeoutDays(config.timeout_days); this.#max_retries = this.#validateMaxRetries(config.max_retries); } #validateTimeoutDays(days) { const parsed = parseInt(days); if (isNaN(parsed) || parsed < 1) { return 2; // default value } return parsed; } #validateMaxRetries(retries) { const parsed = parseInt(retries); if (isNaN(parsed) || parsed < 0) { return 3; // default value } return parsed; } get endpoint() { return this.#endpoint; } get headers() { return { ...this.#headers }; } get callback_url_pattern() { return this.#callback_url_pattern; } get timeout_days() { return this.#timeout_days; } get max_retries() { return this.#max_retries; } #validateConfig(config) { if (!config.endpoint) { throw new Error('Endpoint is required'); } if (!config.headers?.callback_url_pattern) { throw new Error('Callback URL pattern is required'); } if (!config.headers.callback_url_pattern.includes('{{docId}}') || !config.headers.callback_url_pattern.includes('{{streamId}}')) { throw new Error('Invalid callback URL pattern format'); } } } module.exports = ExtractionConfig;