feat: add car inquiries with resilience, ownership privacy, and retry visibility

Introduce plate, chassis, and third-party car endpoints, a wall-clock inquiry
deadline with transport-only retries, and ownership-safe no-match errors so
another person's identity never leaks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 17:21:16 +03:30
co-authored by Cursor
parent b4be98b156
commit 61098f1bf4
40 changed files with 2595 additions and 374 deletions
+20 -36
View File
@@ -7,9 +7,12 @@ import {
InquiryProvider,
ProviderExecutionContext,
} from '../../common/interfaces/inquiry-provider.interface';
import { withRetry } from '../../common/helpers/retry.helper';
import { withTimeout } from '../../common/helpers/timeout.helper';
import { RequestLogger } from '../../common/helpers/request-logger.helper';
import {
PROVIDER_DEFAULT_MAX_ATTEMPTS,
isTransportRetryable,
runWithProviderResilience,
} from '../../common/helpers/provider-resilience.helper';
import { ProviderConfigSlice } from '../interfaces/provider-config.interface';
import {
AppErrorCode,
@@ -22,9 +25,9 @@ import {
* Abstract base for all provider adapters.
*
* Responsibilities:
* - Retry + timeout orchestration
* - Retry + timeout + inquiry deadline orchestration
* - Attempt trail recording
* - Standardized error normalization
* - Response formatting hooks
* - Structured logging
*
* Subclasses implement provider-specific HTTP/business logic only.
@@ -108,43 +111,19 @@ export abstract class BaseProvider<TRequest = unknown, TResponse = unknown>
fn: () => Promise<T>,
context: ProviderExecutionContext,
): Promise<T> {
const operation = () =>
withTimeout(fn(), this.config.timeout, `${this.name} request`);
const maxAttempts = Math.max(1, this.config.maxRetries || PROVIDER_DEFAULT_MAX_ATTEMPTS);
return withRetry(operation, {
maxAttempts: this.config.maxRetries,
delayMs: 300,
return runWithProviderResilience(fn, {
providerName: this.name,
maxAttempts,
timeoutMs: this.config.timeout,
context,
shouldRetry: (error) => this.isRetryable(error),
});
}
protected isRetryable(error: unknown): boolean {
if (!error || typeof error !== 'object') return false;
// Network-level transient errors
if ('code' in error) {
const code = (error as { code?: string }).code;
if (code === 'ETIMEDOUT' || code === 'ECONNABORTED' || code === 'ECONNRESET') {
return true;
}
}
// HTTP errors that indicate provider unavailability
if ('response' in error) {
const status = (error as { response?: { status?: number } }).response?.status;
if (typeof status === 'number') {
if (
status === 408 || // Request Timeout — provider didn't answer in time
status === 429 || // Too Many Requests — provider rate-limited us
status === 499 || // Client Closed Request — provider hung up
(status >= 500 && status < 600) // 5xx server errors
) {
return true;
}
}
}
return false;
return isTransportRetryable(error);
}
protected normalizeError(partial: Partial<NormalizedErrorDto>): NormalizedErrorDto {
@@ -184,9 +163,14 @@ export abstract class BaseProvider<TRequest = unknown, TResponse = unknown>
): Error {
const message = providerMessage?.trim() || fallbackMessage;
const upstreamCode = providerCode?.trim();
const code = this.toProviderErrorCode(upstreamCode);
const catalogMessage =
code !== 'PROVIDER_ERROR' && fallbackMessage === 'Provider request failed'
? undefined
: fallbackMessage;
const normalized = this.normalizeError({
code: upstreamCode,
message: fallbackMessage,
message: catalogMessage,
providerMessage: message,
providerCode: upstreamCode,
...extras,