@autolink/sdk 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -267,7 +267,7 @@ var InventoryResource = class {
|
|
|
267
267
|
const result = await this.list({ ...filters, page });
|
|
268
268
|
yield result;
|
|
269
269
|
const { pagination } = result.meta;
|
|
270
|
-
if (!pagination || page >= pagination.
|
|
270
|
+
if (!pagination || page >= pagination.total_pages) break;
|
|
271
271
|
page++;
|
|
272
272
|
}
|
|
273
273
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/transport/constants.ts","../src/errors.ts","../src/transport/retry.ts","../src/transport/fetcher.ts","../src/resources/inventory.ts","../src/resources/inquiries.ts","../src/resources/profile.ts","../src/resources/articles.ts","../src/resources/integration.ts","../src/client.ts","../src/cache/index.ts"],"sourcesContent":["export { AutolinkClient } from \"./client.js\";\nexport type { AutolinkClientConfig } from \"./client.js\";\n\nexport {\n AutolinkError,\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n} from \"./errors.js\";\n\nexport type {\n GatewayEnvelope,\n GatewayMeta,\n GatewayPagination,\n AutolinkVehicle,\n VehiclePhoto,\n VehicleDealer,\n CoverImageVariants,\n InventoryListFilters,\n FilterOptions,\n AutolinkInquiryPayload,\n AutolinkInquiry,\n AutolinkProfile,\n AutolinkArticle,\n ArticleListFilters,\n IntegrationStatus,\n StockStatus,\n VehicleCondition,\n} from \"./types/index.js\";\n\n// ---------------------------------------------------------------------------\n// DX helpers\n// ---------------------------------------------------------------------------\n\nimport type { GatewayEnvelope } from \"./types/index.js\";\nimport type { AutolinkValidationError } from \"./errors.js\";\n\n/** Unwraps a GatewayEnvelope and returns the data directly */\nexport function unwrap<T>(envelope: GatewayEnvelope<T>): T {\n return envelope.data;\n}\n\n/** Returns field-level validation errors for a given field name */\nexport function getFieldErrors(\n error: AutolinkValidationError,\n field: string,\n): string[] {\n return error.fields[field] ?? [];\n}\n\nexport {\n GATEWAY_BASE_URL,\n GATEWAY_URL,\n SDK_VERSION,\n} from \"./transport/constants.js\";\n\nexport type { AutolinkCache } from \"./cache/index.js\";\nexport { MemoryCache } from \"./cache/index.js\";\n","export const GATEWAY_BASE_URL = \"https://gateway.autolink.ke\";\nexport const GATEWAY_API_VERSION = \"v1\";\nexport const GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;\n\nexport const DEFAULT_TIMEOUT_MS = 10_000;\nexport const DEFAULT_RETRY_ATTEMPTS = 3;\nexport const SDK_VERSION = \"0.1.0\";\n","export class AutolinkError extends Error {\n readonly requestId: string;\n readonly code: string;\n\n constructor(message: string, code: string, requestId: string) {\n super(message);\n this.name = \"AutolinkError\";\n this.code = code;\n this.requestId = requestId;\n }\n}\n\nexport class AutolinkAuthError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"AUTHENTICATION_ERROR\", requestId);\n this.name = \"AutolinkAuthError\";\n }\n}\n\nexport class AutolinkForbiddenError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"FORBIDDEN\", requestId);\n this.name = \"AutolinkForbiddenError\";\n }\n}\n\nexport class AutolinkNotFoundError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"NOT_FOUND\", requestId);\n this.name = \"AutolinkNotFoundError\";\n }\n}\n\nexport class AutolinkValidationError extends AutolinkError {\n readonly fields: Record<string, string[]>;\n\n constructor(\n message: string,\n requestId: string,\n fields: Record<string, string[]> = {},\n ) {\n super(message, \"VALIDATION_ERROR\", requestId);\n this.name = \"AutolinkValidationError\";\n this.fields = fields;\n }\n}\n\nexport class AutolinkRateLimitError extends AutolinkError {\n readonly retryAfter: number;\n\n constructor(message: string, requestId: string, retryAfter: number) {\n super(message, \"RATE_LIMITED\", requestId);\n this.name = \"AutolinkRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AutolinkNetworkError extends AutolinkError {\n readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message, \"NETWORK_ERROR\", \"\");\n this.name = \"AutolinkNetworkError\";\n this.cause = cause;\n }\n}\n","export interface RetryConfig {\n attempts: number;\n backoff: \"exponential\" | \"linear\";\n}\n\nconst RETRYABLE_STATUS = new Set([500, 502, 503, 504]);\n\nexport function isRetryableStatus(status: number): boolean {\n return RETRYABLE_STATUS.has(status);\n}\n\nexport function backoffMs(attempt: number): number {\n const base = 100 * Math.pow(2, attempt);\n const jitter = Math.random() * 100;\n return Math.min(base + jitter, 10_000);\n}\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import { GATEWAY_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION } from \"./constants.js\";\nimport {\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n AutolinkError,\n} from \"../errors.js\";\nimport type { RetryConfig } from \"./retry.js\";\nimport { isRetryableStatus, backoffMs, sleep } from \"./retry.js\";\n\n// Internal escape hatch for Autolink engineering only — not documented publicly.\n// Silently ignored when NODE_ENV is \"production\".\nfunction resolveGatewayUrl(): string {\n if (\n process.env[\"NODE_ENV\"] !== \"production\" &&\n process.env[\"AUTOLINK_GATEWAY_URL\"]\n ) {\n return `${process.env[\"AUTOLINK_GATEWAY_URL\"]}/sdk/v1`;\n }\n return GATEWAY_URL;\n}\n\nexport interface FetcherConfig {\n apiKey: string;\n timeout: number;\n retry: RetryConfig;\n debug: boolean;\n}\n\ninterface GatewayErrorBody {\n error: {\n code: string;\n message: string;\n fields?: Record<string, string[]>;\n request_id: string;\n };\n}\n\nfunction throwFromResponse(\n status: number,\n body: GatewayErrorBody,\n headers: Headers,\n): never {\n const { code, message, fields, request_id } = body.error;\n const rid = request_id ?? \"\";\n\n if (status === 401) throw new AutolinkAuthError(message, rid);\n if (status === 403) throw new AutolinkForbiddenError(message, rid);\n if (status === 404) throw new AutolinkNotFoundError(message, rid);\n if (status === 400 || status === 422)\n throw new AutolinkValidationError(message, rid, fields ?? {});\n if (status === 429) {\n const retryAfter = parseInt(headers.get(\"Retry-After\") ?? \"60\", 10);\n throw new AutolinkRateLimitError(message, rid, retryAfter);\n }\n throw new AutolinkError(message, code ?? \"GATEWAY_ERROR\", rid);\n}\n\nexport async function gatewayFetch<T>(\n config: FetcherConfig,\n method: string,\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n idempotencyKey?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n const base = resolveGatewayUrl();\n const url = new URL(`${base}${path}`);\n\n if (options.params) {\n for (const [k, v] of Object.entries(options.params)) {\n if (v !== undefined) url.searchParams.set(k, String(v));\n }\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.apiKey,\n \"X-Autolink-SDK-Version\": SDK_VERSION,\n };\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n const isWrite = method === \"POST\" || method === \"PUT\" || method === \"PATCH\";\n const maxAttempts =\n isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) await sleep(backoffMs(attempt - 1));\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n config.timeout ?? DEFAULT_TIMEOUT_MS,\n );\n const signal = options.signal ?? controller.signal;\n\n try {\n const res = await fetch(url.toString(), {\n method,\n headers,\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n signal,\n });\n clearTimeout(timeoutId);\n\n if (config.debug) {\n const rid = res.headers.get(\"X-Request-ID\") ?? \"\";\n console.debug(`[autolink] ${method} ${path} → ${res.status} (${rid})`);\n }\n\n if (!res.ok) {\n const errorBody = (await res.json()) as GatewayErrorBody;\n\n // Retry on 5xx but not on 4xx\n if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {\n lastError = new AutolinkError(\n errorBody.error?.message ?? \"Gateway error\",\n errorBody.error?.code ?? \"GATEWAY_ERROR\",\n errorBody.error?.request_id ?? \"\",\n );\n continue;\n }\n\n throwFromResponse(res.status, errorBody, res.headers);\n }\n\n return (await res.json()) as T;\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof AutolinkError) throw err;\n\n const networkErr = err instanceof Error ? err : new Error(String(err));\n lastError = new AutolinkNetworkError(\n `Request to Autolink gateway failed: ${networkErr.message}`,\n networkErr,\n );\n\n if (attempt < maxAttempts - 1) continue;\n }\n }\n\n throw (\n lastError ??\n new AutolinkNetworkError(\"Request failed\", new Error(\"Unknown error\"))\n );\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkVehicle,\n FilterOptions,\n InventoryListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_LIST = 300; // 5 minutes\nconst TTL_SINGLE = 600; // 10 minutes\nconst TTL_FILTER_OPTIONS = 300;\n\nexport class InventoryResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: InventoryListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle[]>> {\n const ttl = options?.ttl ?? TTL_LIST;\n const key = `autolink:inventory:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle[]>>(\n this.config,\n \"GET\",\n \"/inventory\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle>> {\n const ttl = options?.ttl ?? TTL_SINGLE;\n const key = `autolink:inventory:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle>>(\n this.config,\n \"GET\",\n `/inventory/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async filterOptions(options?: {\n ttl?: number;\n }): Promise<GatewayEnvelope<FilterOptions>> {\n const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;\n const key = \"autolink:inventory:filter-options\";\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined) return cached as GatewayEnvelope<FilterOptions>;\n }\n const result = await gatewayFetch<GatewayEnvelope<FilterOptions>>(\n this.config,\n \"GET\",\n \"/inventory/filter-options\",\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async *pages(\n filters: Omit<InventoryListFilters, \"page\"> = {},\n ): AsyncGenerator<GatewayEnvelope<AutolinkVehicle[]>> {\n let page = 1;\n while (true) {\n const result = await this.list({ ...filters, page });\n yield result;\n const { pagination } = result.meta;\n if (!pagination || page >= pagination.pages) break;\n page++;\n }\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkInquiry,\n AutolinkInquiryPayload,\n} from \"../types/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface InquiryCreateOptions {\n idempotencyKey?: string;\n}\n\nexport class InquiriesResource {\n constructor(private config: FetcherConfig) {}\n\n async create(\n payload: AutolinkInquiryPayload,\n options: InquiryCreateOptions = {},\n ): Promise<GatewayEnvelope<AutolinkInquiry>> {\n const idempotencyKey = options.idempotencyKey ?? randomUUID();\n return gatewayFetch<GatewayEnvelope<AutolinkInquiry>>(\n this.config,\n \"POST\",\n \"/inquiries\",\n { body: payload, idempotencyKey },\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, AutolinkProfile } from \"../types/index.js\";\n\nexport class ProfileResource {\n constructor(private config: FetcherConfig) {}\n\n async get(): Promise<GatewayEnvelope<AutolinkProfile>> {\n return gatewayFetch<GatewayEnvelope<AutolinkProfile>>(\n this.config,\n \"GET\",\n \"/profile\",\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkArticle,\n ArticleListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_ARTICLES = 600; // 10 minutes\n\nexport class ArticlesResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: ArticleListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle[]>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle[]>>(\n this.config,\n \"GET\",\n \"/articles\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle>>(\n this.config,\n \"GET\",\n `/articles/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, IntegrationStatus } from \"../types/index.js\";\n\nexport class IntegrationResource {\n constructor(private config: FetcherConfig) {}\n\n async check(): Promise<GatewayEnvelope<IntegrationStatus>> {\n return gatewayFetch<GatewayEnvelope<IntegrationStatus>>(\n this.config,\n \"GET\",\n \"/integration\",\n );\n }\n}\n","import {\n DEFAULT_TIMEOUT_MS,\n DEFAULT_RETRY_ATTEMPTS,\n} from \"./transport/constants.js\";\nimport type { RetryConfig } from \"./transport/retry.js\";\nimport type { FetcherConfig } from \"./transport/fetcher.js\";\nimport { InventoryResource } from \"./resources/inventory.js\";\nimport { InquiriesResource } from \"./resources/inquiries.js\";\nimport { ProfileResource } from \"./resources/profile.js\";\nimport { ArticlesResource } from \"./resources/articles.js\";\nimport { IntegrationResource } from \"./resources/integration.js\";\nimport type { AutolinkCache } from \"./cache/index.js\";\n\nexport interface AutolinkClientConfig {\n apiKey: string;\n timeout?: number;\n retry?: Partial<RetryConfig>;\n debug?: boolean;\n cache?: AutolinkCache;\n}\n\nexport class AutolinkClient {\n readonly inventory: InventoryResource;\n readonly inquiries: InquiriesResource;\n readonly profile: ProfileResource;\n readonly articles: ArticlesResource;\n readonly integration: IntegrationResource;\n\n constructor(config: AutolinkClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"AutolinkClient: apiKey is required\");\n }\n if (\n !config.apiKey.startsWith(\"gw_live_\") &&\n !config.apiKey.startsWith(\"gw_test_\")\n ) {\n throw new Error(\n 'AutolinkClient: apiKey must start with \"gw_live_\" or \"gw_test_\"',\n );\n }\n\n const fetcherConfig: FetcherConfig = {\n apiKey: config.apiKey,\n timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,\n retry: {\n attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,\n backoff: config.retry?.backoff ?? \"exponential\",\n },\n debug: config.debug ?? false,\n };\n\n this.inventory = new InventoryResource(fetcherConfig, config.cache);\n this.inquiries = new InquiriesResource(fetcherConfig);\n this.profile = new ProfileResource(fetcherConfig);\n this.articles = new ArticlesResource(fetcherConfig, config.cache);\n this.integration = new IntegrationResource(fetcherConfig);\n }\n}\n","export interface AutolinkCache {\n get(key: string): Promise<unknown> | unknown;\n set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;\n delete(key: string): Promise<void> | void;\n}\n\ninterface CacheEntry {\n value: unknown;\n expiresAt: number | null; // null = no expiry\n}\n\nconst MAX_ENTRIES = 200;\n\nexport class MemoryCache implements AutolinkCache {\n private store = new Map<string, CacheEntry>();\n\n get(key: string): unknown {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value;\n }\n\n set(key: string, value: unknown, ttlSeconds?: number): void {\n // Evict oldest entry if at capacity and key is new\n if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {\n const oldestKey = this.store.keys().next().value;\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n }\n }\n this.store.set(key, {\n value,\n expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1000 : null,\n });\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n /** Remove all expired entries. Optional maintenance call. */\n purgeExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.store) {\n if (entry.expiresAt !== null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ts","../src/transport/constants.ts","../src/errors.ts","../src/transport/retry.ts","../src/transport/fetcher.ts","../src/resources/inventory.ts","../src/resources/inquiries.ts","../src/resources/profile.ts","../src/resources/articles.ts","../src/resources/integration.ts","../src/client.ts","../src/cache/index.ts"],"sourcesContent":["export { AutolinkClient } from \"./client.js\";\nexport type { AutolinkClientConfig } from \"./client.js\";\n\nexport {\n AutolinkError,\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n} from \"./errors.js\";\n\nexport type {\n GatewayEnvelope,\n GatewayMeta,\n GatewayPagination,\n AutolinkVehicle,\n VehiclePhoto,\n VehicleDealer,\n CoverImageVariants,\n InventoryListFilters,\n FilterOptions,\n AutolinkInquiryPayload,\n AutolinkInquiry,\n AutolinkProfile,\n AutolinkArticle,\n ArticleListFilters,\n IntegrationStatus,\n StockStatus,\n VehicleCondition,\n} from \"./types/index.js\";\n\n// ---------------------------------------------------------------------------\n// DX helpers\n// ---------------------------------------------------------------------------\n\nimport type { GatewayEnvelope } from \"./types/index.js\";\nimport type { AutolinkValidationError } from \"./errors.js\";\n\n/** Unwraps a GatewayEnvelope and returns the data directly */\nexport function unwrap<T>(envelope: GatewayEnvelope<T>): T {\n return envelope.data;\n}\n\n/** Returns field-level validation errors for a given field name */\nexport function getFieldErrors(\n error: AutolinkValidationError,\n field: string,\n): string[] {\n return error.fields[field] ?? [];\n}\n\nexport {\n GATEWAY_BASE_URL,\n GATEWAY_URL,\n SDK_VERSION,\n} from \"./transport/constants.js\";\n\nexport type { AutolinkCache } from \"./cache/index.js\";\nexport { MemoryCache } from \"./cache/index.js\";\n","export const GATEWAY_BASE_URL = \"https://gateway.autolink.ke\";\nexport const GATEWAY_API_VERSION = \"v1\";\nexport const GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;\n\nexport const DEFAULT_TIMEOUT_MS = 10_000;\nexport const DEFAULT_RETRY_ATTEMPTS = 3;\nexport const SDK_VERSION = \"0.1.0\";\n","export class AutolinkError extends Error {\n readonly requestId: string;\n readonly code: string;\n\n constructor(message: string, code: string, requestId: string) {\n super(message);\n this.name = \"AutolinkError\";\n this.code = code;\n this.requestId = requestId;\n }\n}\n\nexport class AutolinkAuthError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"AUTHENTICATION_ERROR\", requestId);\n this.name = \"AutolinkAuthError\";\n }\n}\n\nexport class AutolinkForbiddenError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"FORBIDDEN\", requestId);\n this.name = \"AutolinkForbiddenError\";\n }\n}\n\nexport class AutolinkNotFoundError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"NOT_FOUND\", requestId);\n this.name = \"AutolinkNotFoundError\";\n }\n}\n\nexport class AutolinkValidationError extends AutolinkError {\n readonly fields: Record<string, string[]>;\n\n constructor(\n message: string,\n requestId: string,\n fields: Record<string, string[]> = {},\n ) {\n super(message, \"VALIDATION_ERROR\", requestId);\n this.name = \"AutolinkValidationError\";\n this.fields = fields;\n }\n}\n\nexport class AutolinkRateLimitError extends AutolinkError {\n readonly retryAfter: number;\n\n constructor(message: string, requestId: string, retryAfter: number) {\n super(message, \"RATE_LIMITED\", requestId);\n this.name = \"AutolinkRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AutolinkNetworkError extends AutolinkError {\n readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message, \"NETWORK_ERROR\", \"\");\n this.name = \"AutolinkNetworkError\";\n this.cause = cause;\n }\n}\n","export interface RetryConfig {\n attempts: number;\n backoff: \"exponential\" | \"linear\";\n}\n\nconst RETRYABLE_STATUS = new Set([500, 502, 503, 504]);\n\nexport function isRetryableStatus(status: number): boolean {\n return RETRYABLE_STATUS.has(status);\n}\n\nexport function backoffMs(attempt: number): number {\n const base = 100 * Math.pow(2, attempt);\n const jitter = Math.random() * 100;\n return Math.min(base + jitter, 10_000);\n}\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import { GATEWAY_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION } from \"./constants.js\";\nimport {\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n AutolinkError,\n} from \"../errors.js\";\nimport type { RetryConfig } from \"./retry.js\";\nimport { isRetryableStatus, backoffMs, sleep } from \"./retry.js\";\n\n// Internal escape hatch for Autolink engineering only — not documented publicly.\n// Silently ignored when NODE_ENV is \"production\".\nfunction resolveGatewayUrl(): string {\n if (\n process.env[\"NODE_ENV\"] !== \"production\" &&\n process.env[\"AUTOLINK_GATEWAY_URL\"]\n ) {\n return `${process.env[\"AUTOLINK_GATEWAY_URL\"]}/sdk/v1`;\n }\n return GATEWAY_URL;\n}\n\nexport interface FetcherConfig {\n apiKey: string;\n timeout: number;\n retry: RetryConfig;\n debug: boolean;\n}\n\ninterface GatewayErrorBody {\n error: {\n code: string;\n message: string;\n fields?: Record<string, string[]>;\n request_id: string;\n };\n}\n\nfunction throwFromResponse(\n status: number,\n body: GatewayErrorBody,\n headers: Headers,\n): never {\n const { code, message, fields, request_id } = body.error;\n const rid = request_id ?? \"\";\n\n if (status === 401) throw new AutolinkAuthError(message, rid);\n if (status === 403) throw new AutolinkForbiddenError(message, rid);\n if (status === 404) throw new AutolinkNotFoundError(message, rid);\n if (status === 400 || status === 422)\n throw new AutolinkValidationError(message, rid, fields ?? {});\n if (status === 429) {\n const retryAfter = parseInt(headers.get(\"Retry-After\") ?? \"60\", 10);\n throw new AutolinkRateLimitError(message, rid, retryAfter);\n }\n throw new AutolinkError(message, code ?? \"GATEWAY_ERROR\", rid);\n}\n\nexport async function gatewayFetch<T>(\n config: FetcherConfig,\n method: string,\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n idempotencyKey?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n const base = resolveGatewayUrl();\n const url = new URL(`${base}${path}`);\n\n if (options.params) {\n for (const [k, v] of Object.entries(options.params)) {\n if (v !== undefined) url.searchParams.set(k, String(v));\n }\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.apiKey,\n \"X-Autolink-SDK-Version\": SDK_VERSION,\n };\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n const isWrite = method === \"POST\" || method === \"PUT\" || method === \"PATCH\";\n const maxAttempts =\n isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) await sleep(backoffMs(attempt - 1));\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n config.timeout ?? DEFAULT_TIMEOUT_MS,\n );\n const signal = options.signal ?? controller.signal;\n\n try {\n const res = await fetch(url.toString(), {\n method,\n headers,\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n signal,\n });\n clearTimeout(timeoutId);\n\n if (config.debug) {\n const rid = res.headers.get(\"X-Request-ID\") ?? \"\";\n console.debug(`[autolink] ${method} ${path} → ${res.status} (${rid})`);\n }\n\n if (!res.ok) {\n const errorBody = (await res.json()) as GatewayErrorBody;\n\n // Retry on 5xx but not on 4xx\n if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {\n lastError = new AutolinkError(\n errorBody.error?.message ?? \"Gateway error\",\n errorBody.error?.code ?? \"GATEWAY_ERROR\",\n errorBody.error?.request_id ?? \"\",\n );\n continue;\n }\n\n throwFromResponse(res.status, errorBody, res.headers);\n }\n\n return (await res.json()) as T;\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof AutolinkError) throw err;\n\n const networkErr = err instanceof Error ? err : new Error(String(err));\n lastError = new AutolinkNetworkError(\n `Request to Autolink gateway failed: ${networkErr.message}`,\n networkErr,\n );\n\n if (attempt < maxAttempts - 1) continue;\n }\n }\n\n throw (\n lastError ??\n new AutolinkNetworkError(\"Request failed\", new Error(\"Unknown error\"))\n );\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkVehicle,\n FilterOptions,\n InventoryListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_LIST = 300; // 5 minutes\nconst TTL_SINGLE = 600; // 10 minutes\nconst TTL_FILTER_OPTIONS = 300;\n\nexport class InventoryResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: InventoryListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle[]>> {\n const ttl = options?.ttl ?? TTL_LIST;\n const key = `autolink:inventory:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle[]>>(\n this.config,\n \"GET\",\n \"/inventory\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle>> {\n const ttl = options?.ttl ?? TTL_SINGLE;\n const key = `autolink:inventory:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle>>(\n this.config,\n \"GET\",\n `/inventory/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async filterOptions(options?: {\n ttl?: number;\n }): Promise<GatewayEnvelope<FilterOptions>> {\n const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;\n const key = \"autolink:inventory:filter-options\";\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined) return cached as GatewayEnvelope<FilterOptions>;\n }\n const result = await gatewayFetch<GatewayEnvelope<FilterOptions>>(\n this.config,\n \"GET\",\n \"/inventory/filter-options\",\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async *pages(\n filters: Omit<InventoryListFilters, \"page\"> = {},\n ): AsyncGenerator<GatewayEnvelope<AutolinkVehicle[]>> {\n let page = 1;\n while (true) {\n const result = await this.list({ ...filters, page });\n yield result;\n const { pagination } = result.meta;\n if (!pagination || page >= pagination.total_pages) break;\n page++;\n }\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkInquiry,\n AutolinkInquiryPayload,\n} from \"../types/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface InquiryCreateOptions {\n idempotencyKey?: string;\n}\n\nexport class InquiriesResource {\n constructor(private config: FetcherConfig) {}\n\n async create(\n payload: AutolinkInquiryPayload,\n options: InquiryCreateOptions = {},\n ): Promise<GatewayEnvelope<AutolinkInquiry>> {\n const idempotencyKey = options.idempotencyKey ?? randomUUID();\n return gatewayFetch<GatewayEnvelope<AutolinkInquiry>>(\n this.config,\n \"POST\",\n \"/inquiries\",\n { body: payload, idempotencyKey },\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, AutolinkProfile } from \"../types/index.js\";\n\nexport class ProfileResource {\n constructor(private config: FetcherConfig) {}\n\n async get(): Promise<GatewayEnvelope<AutolinkProfile>> {\n return gatewayFetch<GatewayEnvelope<AutolinkProfile>>(\n this.config,\n \"GET\",\n \"/profile\",\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkArticle,\n ArticleListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_ARTICLES = 600; // 10 minutes\n\nexport class ArticlesResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: ArticleListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle[]>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle[]>>(\n this.config,\n \"GET\",\n \"/articles\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle>>(\n this.config,\n \"GET\",\n `/articles/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, IntegrationStatus } from \"../types/index.js\";\n\nexport class IntegrationResource {\n constructor(private config: FetcherConfig) {}\n\n async check(): Promise<GatewayEnvelope<IntegrationStatus>> {\n return gatewayFetch<GatewayEnvelope<IntegrationStatus>>(\n this.config,\n \"GET\",\n \"/integration\",\n );\n }\n}\n","import {\n DEFAULT_TIMEOUT_MS,\n DEFAULT_RETRY_ATTEMPTS,\n} from \"./transport/constants.js\";\nimport type { RetryConfig } from \"./transport/retry.js\";\nimport type { FetcherConfig } from \"./transport/fetcher.js\";\nimport { InventoryResource } from \"./resources/inventory.js\";\nimport { InquiriesResource } from \"./resources/inquiries.js\";\nimport { ProfileResource } from \"./resources/profile.js\";\nimport { ArticlesResource } from \"./resources/articles.js\";\nimport { IntegrationResource } from \"./resources/integration.js\";\nimport type { AutolinkCache } from \"./cache/index.js\";\n\nexport interface AutolinkClientConfig {\n apiKey: string;\n timeout?: number;\n retry?: Partial<RetryConfig>;\n debug?: boolean;\n cache?: AutolinkCache;\n}\n\nexport class AutolinkClient {\n readonly inventory: InventoryResource;\n readonly inquiries: InquiriesResource;\n readonly profile: ProfileResource;\n readonly articles: ArticlesResource;\n readonly integration: IntegrationResource;\n\n constructor(config: AutolinkClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"AutolinkClient: apiKey is required\");\n }\n if (\n !config.apiKey.startsWith(\"gw_live_\") &&\n !config.apiKey.startsWith(\"gw_test_\")\n ) {\n throw new Error(\n 'AutolinkClient: apiKey must start with \"gw_live_\" or \"gw_test_\"',\n );\n }\n\n const fetcherConfig: FetcherConfig = {\n apiKey: config.apiKey,\n timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,\n retry: {\n attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,\n backoff: config.retry?.backoff ?? \"exponential\",\n },\n debug: config.debug ?? false,\n };\n\n this.inventory = new InventoryResource(fetcherConfig, config.cache);\n this.inquiries = new InquiriesResource(fetcherConfig);\n this.profile = new ProfileResource(fetcherConfig);\n this.articles = new ArticlesResource(fetcherConfig, config.cache);\n this.integration = new IntegrationResource(fetcherConfig);\n }\n}\n","export interface AutolinkCache {\n get(key: string): Promise<unknown> | unknown;\n set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;\n delete(key: string): Promise<void> | void;\n}\n\ninterface CacheEntry {\n value: unknown;\n expiresAt: number | null; // null = no expiry\n}\n\nconst MAX_ENTRIES = 200;\n\nexport class MemoryCache implements AutolinkCache {\n private store = new Map<string, CacheEntry>();\n\n get(key: string): unknown {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value;\n }\n\n set(key: string, value: unknown, ttlSeconds?: number): void {\n // Evict oldest entry if at capacity and key is new\n if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {\n const oldestKey = this.store.keys().next().value;\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n }\n }\n this.store.set(key, {\n value,\n expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1000 : null,\n });\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n /** Remove all expired entries. Optional maintenance call. */\n purgeExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.store) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,cAAc,GAAG,gBAAgB,QAAQ,mBAAmB;AAElE,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,cAAc;;;ACNpB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,MAAc,WAAmB;AAC5D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,oBAAN,cAAgC,cAAc;AAAA,EACnD,YAA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AAI,cAAc,QAAW;AAC3B,aAAK,MAAM,OAAO,SAAS;AAAA,MAC7B;AAAA,IACF;AACA,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB;AAAA,MACA,WAAW,cAAc,OAAO,KAAK,IAAI,IAAI,aAAa,MAAO;AAAA,IACnE,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA;AAAA,EAGA,eAAqB;AACnB,UAAM,MAAM,KAAK,IAAI;AACrB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,OAAO;AACrC,UAAI,MAAM,cAAc,QAAQ,MAAM,MAAM,WAAW;AACrD,aAAK,MAAM,OAAO,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;;;AXZO,SAAS,OAAU,UAAiC;AACzD,SAAO,SAAS;AAClB;AAGO,SAAS,eACd,OACA,OACU;AACV,SAAO,MAAM,OAAO,KAAK,KAAK,CAAC;AACjC;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -14,7 +14,10 @@ interface GatewayPagination {
|
|
|
14
14
|
total: number;
|
|
15
15
|
page: number;
|
|
16
16
|
page_size: number;
|
|
17
|
-
pages
|
|
17
|
+
/** Total number of pages. The gateway field name is `total_pages`. */
|
|
18
|
+
total_pages: number;
|
|
19
|
+
has_next: boolean;
|
|
20
|
+
has_previous: boolean;
|
|
18
21
|
}
|
|
19
22
|
interface GatewayMeta {
|
|
20
23
|
request_id: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,10 @@ interface GatewayPagination {
|
|
|
14
14
|
total: number;
|
|
15
15
|
page: number;
|
|
16
16
|
page_size: number;
|
|
17
|
-
pages
|
|
17
|
+
/** Total number of pages. The gateway field name is `total_pages`. */
|
|
18
|
+
total_pages: number;
|
|
19
|
+
has_next: boolean;
|
|
20
|
+
has_previous: boolean;
|
|
18
21
|
}
|
|
19
22
|
interface GatewayMeta {
|
|
20
23
|
request_id: string;
|
package/dist/index.js
CHANGED
|
@@ -228,7 +228,7 @@ var InventoryResource = class {
|
|
|
228
228
|
const result = await this.list({ ...filters, page });
|
|
229
229
|
yield result;
|
|
230
230
|
const { pagination } = result.meta;
|
|
231
|
-
if (!pagination || page >= pagination.
|
|
231
|
+
if (!pagination || page >= pagination.total_pages) break;
|
|
232
232
|
page++;
|
|
233
233
|
}
|
|
234
234
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transport/constants.ts","../src/errors.ts","../src/transport/retry.ts","../src/transport/fetcher.ts","../src/resources/inventory.ts","../src/resources/inquiries.ts","../src/resources/profile.ts","../src/resources/articles.ts","../src/resources/integration.ts","../src/client.ts","../src/cache/index.ts","../src/index.ts"],"sourcesContent":["export const GATEWAY_BASE_URL = \"https://gateway.autolink.ke\";\nexport const GATEWAY_API_VERSION = \"v1\";\nexport const GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;\n\nexport const DEFAULT_TIMEOUT_MS = 10_000;\nexport const DEFAULT_RETRY_ATTEMPTS = 3;\nexport const SDK_VERSION = \"0.1.0\";\n","export class AutolinkError extends Error {\n readonly requestId: string;\n readonly code: string;\n\n constructor(message: string, code: string, requestId: string) {\n super(message);\n this.name = \"AutolinkError\";\n this.code = code;\n this.requestId = requestId;\n }\n}\n\nexport class AutolinkAuthError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"AUTHENTICATION_ERROR\", requestId);\n this.name = \"AutolinkAuthError\";\n }\n}\n\nexport class AutolinkForbiddenError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"FORBIDDEN\", requestId);\n this.name = \"AutolinkForbiddenError\";\n }\n}\n\nexport class AutolinkNotFoundError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"NOT_FOUND\", requestId);\n this.name = \"AutolinkNotFoundError\";\n }\n}\n\nexport class AutolinkValidationError extends AutolinkError {\n readonly fields: Record<string, string[]>;\n\n constructor(\n message: string,\n requestId: string,\n fields: Record<string, string[]> = {},\n ) {\n super(message, \"VALIDATION_ERROR\", requestId);\n this.name = \"AutolinkValidationError\";\n this.fields = fields;\n }\n}\n\nexport class AutolinkRateLimitError extends AutolinkError {\n readonly retryAfter: number;\n\n constructor(message: string, requestId: string, retryAfter: number) {\n super(message, \"RATE_LIMITED\", requestId);\n this.name = \"AutolinkRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AutolinkNetworkError extends AutolinkError {\n readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message, \"NETWORK_ERROR\", \"\");\n this.name = \"AutolinkNetworkError\";\n this.cause = cause;\n }\n}\n","export interface RetryConfig {\n attempts: number;\n backoff: \"exponential\" | \"linear\";\n}\n\nconst RETRYABLE_STATUS = new Set([500, 502, 503, 504]);\n\nexport function isRetryableStatus(status: number): boolean {\n return RETRYABLE_STATUS.has(status);\n}\n\nexport function backoffMs(attempt: number): number {\n const base = 100 * Math.pow(2, attempt);\n const jitter = Math.random() * 100;\n return Math.min(base + jitter, 10_000);\n}\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import { GATEWAY_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION } from \"./constants.js\";\nimport {\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n AutolinkError,\n} from \"../errors.js\";\nimport type { RetryConfig } from \"./retry.js\";\nimport { isRetryableStatus, backoffMs, sleep } from \"./retry.js\";\n\n// Internal escape hatch for Autolink engineering only — not documented publicly.\n// Silently ignored when NODE_ENV is \"production\".\nfunction resolveGatewayUrl(): string {\n if (\n process.env[\"NODE_ENV\"] !== \"production\" &&\n process.env[\"AUTOLINK_GATEWAY_URL\"]\n ) {\n return `${process.env[\"AUTOLINK_GATEWAY_URL\"]}/sdk/v1`;\n }\n return GATEWAY_URL;\n}\n\nexport interface FetcherConfig {\n apiKey: string;\n timeout: number;\n retry: RetryConfig;\n debug: boolean;\n}\n\ninterface GatewayErrorBody {\n error: {\n code: string;\n message: string;\n fields?: Record<string, string[]>;\n request_id: string;\n };\n}\n\nfunction throwFromResponse(\n status: number,\n body: GatewayErrorBody,\n headers: Headers,\n): never {\n const { code, message, fields, request_id } = body.error;\n const rid = request_id ?? \"\";\n\n if (status === 401) throw new AutolinkAuthError(message, rid);\n if (status === 403) throw new AutolinkForbiddenError(message, rid);\n if (status === 404) throw new AutolinkNotFoundError(message, rid);\n if (status === 400 || status === 422)\n throw new AutolinkValidationError(message, rid, fields ?? {});\n if (status === 429) {\n const retryAfter = parseInt(headers.get(\"Retry-After\") ?? \"60\", 10);\n throw new AutolinkRateLimitError(message, rid, retryAfter);\n }\n throw new AutolinkError(message, code ?? \"GATEWAY_ERROR\", rid);\n}\n\nexport async function gatewayFetch<T>(\n config: FetcherConfig,\n method: string,\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n idempotencyKey?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n const base = resolveGatewayUrl();\n const url = new URL(`${base}${path}`);\n\n if (options.params) {\n for (const [k, v] of Object.entries(options.params)) {\n if (v !== undefined) url.searchParams.set(k, String(v));\n }\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.apiKey,\n \"X-Autolink-SDK-Version\": SDK_VERSION,\n };\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n const isWrite = method === \"POST\" || method === \"PUT\" || method === \"PATCH\";\n const maxAttempts =\n isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) await sleep(backoffMs(attempt - 1));\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n config.timeout ?? DEFAULT_TIMEOUT_MS,\n );\n const signal = options.signal ?? controller.signal;\n\n try {\n const res = await fetch(url.toString(), {\n method,\n headers,\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n signal,\n });\n clearTimeout(timeoutId);\n\n if (config.debug) {\n const rid = res.headers.get(\"X-Request-ID\") ?? \"\";\n console.debug(`[autolink] ${method} ${path} → ${res.status} (${rid})`);\n }\n\n if (!res.ok) {\n const errorBody = (await res.json()) as GatewayErrorBody;\n\n // Retry on 5xx but not on 4xx\n if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {\n lastError = new AutolinkError(\n errorBody.error?.message ?? \"Gateway error\",\n errorBody.error?.code ?? \"GATEWAY_ERROR\",\n errorBody.error?.request_id ?? \"\",\n );\n continue;\n }\n\n throwFromResponse(res.status, errorBody, res.headers);\n }\n\n return (await res.json()) as T;\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof AutolinkError) throw err;\n\n const networkErr = err instanceof Error ? err : new Error(String(err));\n lastError = new AutolinkNetworkError(\n `Request to Autolink gateway failed: ${networkErr.message}`,\n networkErr,\n );\n\n if (attempt < maxAttempts - 1) continue;\n }\n }\n\n throw (\n lastError ??\n new AutolinkNetworkError(\"Request failed\", new Error(\"Unknown error\"))\n );\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkVehicle,\n FilterOptions,\n InventoryListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_LIST = 300; // 5 minutes\nconst TTL_SINGLE = 600; // 10 minutes\nconst TTL_FILTER_OPTIONS = 300;\n\nexport class InventoryResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: InventoryListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle[]>> {\n const ttl = options?.ttl ?? TTL_LIST;\n const key = `autolink:inventory:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle[]>>(\n this.config,\n \"GET\",\n \"/inventory\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle>> {\n const ttl = options?.ttl ?? TTL_SINGLE;\n const key = `autolink:inventory:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle>>(\n this.config,\n \"GET\",\n `/inventory/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async filterOptions(options?: {\n ttl?: number;\n }): Promise<GatewayEnvelope<FilterOptions>> {\n const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;\n const key = \"autolink:inventory:filter-options\";\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined) return cached as GatewayEnvelope<FilterOptions>;\n }\n const result = await gatewayFetch<GatewayEnvelope<FilterOptions>>(\n this.config,\n \"GET\",\n \"/inventory/filter-options\",\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async *pages(\n filters: Omit<InventoryListFilters, \"page\"> = {},\n ): AsyncGenerator<GatewayEnvelope<AutolinkVehicle[]>> {\n let page = 1;\n while (true) {\n const result = await this.list({ ...filters, page });\n yield result;\n const { pagination } = result.meta;\n if (!pagination || page >= pagination.pages) break;\n page++;\n }\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkInquiry,\n AutolinkInquiryPayload,\n} from \"../types/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface InquiryCreateOptions {\n idempotencyKey?: string;\n}\n\nexport class InquiriesResource {\n constructor(private config: FetcherConfig) {}\n\n async create(\n payload: AutolinkInquiryPayload,\n options: InquiryCreateOptions = {},\n ): Promise<GatewayEnvelope<AutolinkInquiry>> {\n const idempotencyKey = options.idempotencyKey ?? randomUUID();\n return gatewayFetch<GatewayEnvelope<AutolinkInquiry>>(\n this.config,\n \"POST\",\n \"/inquiries\",\n { body: payload, idempotencyKey },\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, AutolinkProfile } from \"../types/index.js\";\n\nexport class ProfileResource {\n constructor(private config: FetcherConfig) {}\n\n async get(): Promise<GatewayEnvelope<AutolinkProfile>> {\n return gatewayFetch<GatewayEnvelope<AutolinkProfile>>(\n this.config,\n \"GET\",\n \"/profile\",\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkArticle,\n ArticleListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_ARTICLES = 600; // 10 minutes\n\nexport class ArticlesResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: ArticleListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle[]>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle[]>>(\n this.config,\n \"GET\",\n \"/articles\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle>>(\n this.config,\n \"GET\",\n `/articles/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, IntegrationStatus } from \"../types/index.js\";\n\nexport class IntegrationResource {\n constructor(private config: FetcherConfig) {}\n\n async check(): Promise<GatewayEnvelope<IntegrationStatus>> {\n return gatewayFetch<GatewayEnvelope<IntegrationStatus>>(\n this.config,\n \"GET\",\n \"/integration\",\n );\n }\n}\n","import {\n DEFAULT_TIMEOUT_MS,\n DEFAULT_RETRY_ATTEMPTS,\n} from \"./transport/constants.js\";\nimport type { RetryConfig } from \"./transport/retry.js\";\nimport type { FetcherConfig } from \"./transport/fetcher.js\";\nimport { InventoryResource } from \"./resources/inventory.js\";\nimport { InquiriesResource } from \"./resources/inquiries.js\";\nimport { ProfileResource } from \"./resources/profile.js\";\nimport { ArticlesResource } from \"./resources/articles.js\";\nimport { IntegrationResource } from \"./resources/integration.js\";\nimport type { AutolinkCache } from \"./cache/index.js\";\n\nexport interface AutolinkClientConfig {\n apiKey: string;\n timeout?: number;\n retry?: Partial<RetryConfig>;\n debug?: boolean;\n cache?: AutolinkCache;\n}\n\nexport class AutolinkClient {\n readonly inventory: InventoryResource;\n readonly inquiries: InquiriesResource;\n readonly profile: ProfileResource;\n readonly articles: ArticlesResource;\n readonly integration: IntegrationResource;\n\n constructor(config: AutolinkClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"AutolinkClient: apiKey is required\");\n }\n if (\n !config.apiKey.startsWith(\"gw_live_\") &&\n !config.apiKey.startsWith(\"gw_test_\")\n ) {\n throw new Error(\n 'AutolinkClient: apiKey must start with \"gw_live_\" or \"gw_test_\"',\n );\n }\n\n const fetcherConfig: FetcherConfig = {\n apiKey: config.apiKey,\n timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,\n retry: {\n attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,\n backoff: config.retry?.backoff ?? \"exponential\",\n },\n debug: config.debug ?? false,\n };\n\n this.inventory = new InventoryResource(fetcherConfig, config.cache);\n this.inquiries = new InquiriesResource(fetcherConfig);\n this.profile = new ProfileResource(fetcherConfig);\n this.articles = new ArticlesResource(fetcherConfig, config.cache);\n this.integration = new IntegrationResource(fetcherConfig);\n }\n}\n","export interface AutolinkCache {\n get(key: string): Promise<unknown> | unknown;\n set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;\n delete(key: string): Promise<void> | void;\n}\n\ninterface CacheEntry {\n value: unknown;\n expiresAt: number | null; // null = no expiry\n}\n\nconst MAX_ENTRIES = 200;\n\nexport class MemoryCache implements AutolinkCache {\n private store = new Map<string, CacheEntry>();\n\n get(key: string): unknown {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value;\n }\n\n set(key: string, value: unknown, ttlSeconds?: number): void {\n // Evict oldest entry if at capacity and key is new\n if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {\n const oldestKey = this.store.keys().next().value;\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n }\n }\n this.store.set(key, {\n value,\n expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1000 : null,\n });\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n /** Remove all expired entries. Optional maintenance call. */\n purgeExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.store) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n}\n","export { AutolinkClient } from \"./client.js\";\nexport type { AutolinkClientConfig } from \"./client.js\";\n\nexport {\n AutolinkError,\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n} from \"./errors.js\";\n\nexport type {\n GatewayEnvelope,\n GatewayMeta,\n GatewayPagination,\n AutolinkVehicle,\n VehiclePhoto,\n VehicleDealer,\n CoverImageVariants,\n InventoryListFilters,\n FilterOptions,\n AutolinkInquiryPayload,\n AutolinkInquiry,\n AutolinkProfile,\n AutolinkArticle,\n ArticleListFilters,\n IntegrationStatus,\n StockStatus,\n VehicleCondition,\n} from \"./types/index.js\";\n\n// ---------------------------------------------------------------------------\n// DX helpers\n// ---------------------------------------------------------------------------\n\nimport type { GatewayEnvelope } from \"./types/index.js\";\nimport type { AutolinkValidationError } from \"./errors.js\";\n\n/** Unwraps a GatewayEnvelope and returns the data directly */\nexport function unwrap<T>(envelope: GatewayEnvelope<T>): T {\n return envelope.data;\n}\n\n/** Returns field-level validation errors for a given field name */\nexport function getFieldErrors(\n error: AutolinkValidationError,\n field: string,\n): string[] {\n return error.fields[field] ?? [];\n}\n\nexport {\n GATEWAY_BASE_URL,\n GATEWAY_URL,\n SDK_VERSION,\n} from \"./transport/constants.js\";\n\nexport type { AutolinkCache } from \"./cache/index.js\";\nexport { MemoryCache } from \"./cache/index.js\";\n"],"mappings":";AAAO,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,cAAc,GAAG,gBAAgB,QAAQ,mBAAmB;AAElE,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,cAAc;;;ACNpB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC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,MAAM;AAAA,EACf;AAAA,EAEA,IAAI,KAAa,OAAgB,YAA2B;AAE1D,QAAI,KAAK,MAAM,QAAQ,eAAe,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AAC1D,YAAM,YAAY,KAAK,MAAM,KAAK,EAAE,KAAK,EAAE;AAC3C,UAAI,cAAc,QAAW;AAC3B,aAAK,MAAM,OAAO,SAAS;AAAA,MAC7B;AAAA,IACF;AACA,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB;AAAA,MACA,WAAW,cAAc,OAAO,KAAK,IAAI,IAAI,aAAa,MAAO;AAAA,IACnE,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA;AAAA,EAGA,eAAqB;AACnB,UAAM,MAAM,KAAK,IAAI;AACrB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,OAAO;AACrC,UAAI,MAAM,cAAc,QAAQ,MAAM,MAAM,WAAW;AACrD,aAAK,MAAM,OAAO,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;;;ACZO,SAAS,OAAU,UAAiC;AACzD,SAAO,SAAS;AAClB;AAGO,SAAS,eACd,OACA,OACU;AACV,SAAO,MAAM,OAAO,KAAK,KAAK,CAAC;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/transport/constants.ts","../src/errors.ts","../src/transport/retry.ts","../src/transport/fetcher.ts","../src/resources/inventory.ts","../src/resources/inquiries.ts","../src/resources/profile.ts","../src/resources/articles.ts","../src/resources/integration.ts","../src/client.ts","../src/cache/index.ts","../src/index.ts"],"sourcesContent":["export const GATEWAY_BASE_URL = \"https://gateway.autolink.ke\";\nexport const GATEWAY_API_VERSION = \"v1\";\nexport const GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;\n\nexport const DEFAULT_TIMEOUT_MS = 10_000;\nexport const DEFAULT_RETRY_ATTEMPTS = 3;\nexport const SDK_VERSION = \"0.1.0\";\n","export class AutolinkError extends Error {\n readonly requestId: string;\n readonly code: string;\n\n constructor(message: string, code: string, requestId: string) {\n super(message);\n this.name = \"AutolinkError\";\n this.code = code;\n this.requestId = requestId;\n }\n}\n\nexport class AutolinkAuthError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"AUTHENTICATION_ERROR\", requestId);\n this.name = \"AutolinkAuthError\";\n }\n}\n\nexport class AutolinkForbiddenError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"FORBIDDEN\", requestId);\n this.name = \"AutolinkForbiddenError\";\n }\n}\n\nexport class AutolinkNotFoundError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"NOT_FOUND\", requestId);\n this.name = \"AutolinkNotFoundError\";\n }\n}\n\nexport class AutolinkValidationError extends AutolinkError {\n readonly fields: Record<string, string[]>;\n\n constructor(\n message: string,\n requestId: string,\n fields: Record<string, string[]> = {},\n ) {\n super(message, \"VALIDATION_ERROR\", requestId);\n this.name = \"AutolinkValidationError\";\n this.fields = fields;\n }\n}\n\nexport class AutolinkRateLimitError extends AutolinkError {\n readonly retryAfter: number;\n\n constructor(message: string, requestId: string, retryAfter: number) {\n super(message, \"RATE_LIMITED\", requestId);\n this.name = \"AutolinkRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AutolinkNetworkError extends AutolinkError {\n readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message, \"NETWORK_ERROR\", \"\");\n this.name = \"AutolinkNetworkError\";\n this.cause = cause;\n }\n}\n","export interface RetryConfig {\n attempts: number;\n backoff: \"exponential\" | \"linear\";\n}\n\nconst RETRYABLE_STATUS = new Set([500, 502, 503, 504]);\n\nexport function isRetryableStatus(status: number): boolean {\n return RETRYABLE_STATUS.has(status);\n}\n\nexport function backoffMs(attempt: number): number {\n const base = 100 * Math.pow(2, attempt);\n const jitter = Math.random() * 100;\n return Math.min(base + jitter, 10_000);\n}\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import { GATEWAY_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION } from \"./constants.js\";\nimport {\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n AutolinkError,\n} from \"../errors.js\";\nimport type { RetryConfig } from \"./retry.js\";\nimport { isRetryableStatus, backoffMs, sleep } from \"./retry.js\";\n\n// Internal escape hatch for Autolink engineering only — not documented publicly.\n// Silently ignored when NODE_ENV is \"production\".\nfunction resolveGatewayUrl(): string {\n if (\n process.env[\"NODE_ENV\"] !== \"production\" &&\n process.env[\"AUTOLINK_GATEWAY_URL\"]\n ) {\n return `${process.env[\"AUTOLINK_GATEWAY_URL\"]}/sdk/v1`;\n }\n return GATEWAY_URL;\n}\n\nexport interface FetcherConfig {\n apiKey: string;\n timeout: number;\n retry: RetryConfig;\n debug: boolean;\n}\n\ninterface GatewayErrorBody {\n error: {\n code: string;\n message: string;\n fields?: Record<string, string[]>;\n request_id: string;\n };\n}\n\nfunction throwFromResponse(\n status: number,\n body: GatewayErrorBody,\n headers: Headers,\n): never {\n const { code, message, fields, request_id } = body.error;\n const rid = request_id ?? \"\";\n\n if (status === 401) throw new AutolinkAuthError(message, rid);\n if (status === 403) throw new AutolinkForbiddenError(message, rid);\n if (status === 404) throw new AutolinkNotFoundError(message, rid);\n if (status === 400 || status === 422)\n throw new AutolinkValidationError(message, rid, fields ?? {});\n if (status === 429) {\n const retryAfter = parseInt(headers.get(\"Retry-After\") ?? \"60\", 10);\n throw new AutolinkRateLimitError(message, rid, retryAfter);\n }\n throw new AutolinkError(message, code ?? \"GATEWAY_ERROR\", rid);\n}\n\nexport async function gatewayFetch<T>(\n config: FetcherConfig,\n method: string,\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n idempotencyKey?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n const base = resolveGatewayUrl();\n const url = new URL(`${base}${path}`);\n\n if (options.params) {\n for (const [k, v] of Object.entries(options.params)) {\n if (v !== undefined) url.searchParams.set(k, String(v));\n }\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.apiKey,\n \"X-Autolink-SDK-Version\": SDK_VERSION,\n };\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n const isWrite = method === \"POST\" || method === \"PUT\" || method === \"PATCH\";\n const maxAttempts =\n isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) await sleep(backoffMs(attempt - 1));\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n config.timeout ?? DEFAULT_TIMEOUT_MS,\n );\n const signal = options.signal ?? controller.signal;\n\n try {\n const res = await fetch(url.toString(), {\n method,\n headers,\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n signal,\n });\n clearTimeout(timeoutId);\n\n if (config.debug) {\n const rid = res.headers.get(\"X-Request-ID\") ?? \"\";\n console.debug(`[autolink] ${method} ${path} → ${res.status} (${rid})`);\n }\n\n if (!res.ok) {\n const errorBody = (await res.json()) as GatewayErrorBody;\n\n // Retry on 5xx but not on 4xx\n if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {\n lastError = new AutolinkError(\n errorBody.error?.message ?? \"Gateway error\",\n errorBody.error?.code ?? \"GATEWAY_ERROR\",\n errorBody.error?.request_id ?? \"\",\n );\n continue;\n }\n\n throwFromResponse(res.status, errorBody, res.headers);\n }\n\n return (await res.json()) as T;\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof AutolinkError) throw err;\n\n const networkErr = err instanceof Error ? err : new Error(String(err));\n lastError = new AutolinkNetworkError(\n `Request to Autolink gateway failed: ${networkErr.message}`,\n networkErr,\n );\n\n if (attempt < maxAttempts - 1) continue;\n }\n }\n\n throw (\n lastError ??\n new AutolinkNetworkError(\"Request failed\", new Error(\"Unknown error\"))\n );\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkVehicle,\n FilterOptions,\n InventoryListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_LIST = 300; // 5 minutes\nconst TTL_SINGLE = 600; // 10 minutes\nconst TTL_FILTER_OPTIONS = 300;\n\nexport class InventoryResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: InventoryListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle[]>> {\n const ttl = options?.ttl ?? TTL_LIST;\n const key = `autolink:inventory:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle[]>>(\n this.config,\n \"GET\",\n \"/inventory\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle>> {\n const ttl = options?.ttl ?? TTL_SINGLE;\n const key = `autolink:inventory:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle>>(\n this.config,\n \"GET\",\n `/inventory/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async filterOptions(options?: {\n ttl?: number;\n }): Promise<GatewayEnvelope<FilterOptions>> {\n const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;\n const key = \"autolink:inventory:filter-options\";\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined) return cached as GatewayEnvelope<FilterOptions>;\n }\n const result = await gatewayFetch<GatewayEnvelope<FilterOptions>>(\n this.config,\n \"GET\",\n \"/inventory/filter-options\",\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async *pages(\n filters: Omit<InventoryListFilters, \"page\"> = {},\n ): AsyncGenerator<GatewayEnvelope<AutolinkVehicle[]>> {\n let page = 1;\n while (true) {\n const result = await this.list({ ...filters, page });\n yield result;\n const { pagination } = result.meta;\n if (!pagination || page >= pagination.total_pages) break;\n page++;\n }\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkInquiry,\n AutolinkInquiryPayload,\n} from \"../types/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface InquiryCreateOptions {\n idempotencyKey?: string;\n}\n\nexport class InquiriesResource {\n constructor(private config: FetcherConfig) {}\n\n async create(\n payload: AutolinkInquiryPayload,\n options: InquiryCreateOptions = {},\n ): Promise<GatewayEnvelope<AutolinkInquiry>> {\n const idempotencyKey = options.idempotencyKey ?? randomUUID();\n return gatewayFetch<GatewayEnvelope<AutolinkInquiry>>(\n this.config,\n \"POST\",\n \"/inquiries\",\n { body: payload, idempotencyKey },\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, AutolinkProfile } from \"../types/index.js\";\n\nexport class ProfileResource {\n constructor(private config: FetcherConfig) {}\n\n async get(): Promise<GatewayEnvelope<AutolinkProfile>> {\n return gatewayFetch<GatewayEnvelope<AutolinkProfile>>(\n this.config,\n \"GET\",\n \"/profile\",\n );\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkArticle,\n ArticleListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_ARTICLES = 600; // 10 minutes\n\nexport class ArticlesResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: ArticleListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle[]>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle[]>>(\n this.config,\n \"GET\",\n \"/articles\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle>>(\n this.config,\n \"GET\",\n `/articles/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n}\n","import type { FetcherConfig } from \"../transport/fetcher.js\";\nimport { gatewayFetch } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, IntegrationStatus } from \"../types/index.js\";\n\nexport class IntegrationResource {\n constructor(private config: FetcherConfig) {}\n\n async check(): Promise<GatewayEnvelope<IntegrationStatus>> {\n return gatewayFetch<GatewayEnvelope<IntegrationStatus>>(\n this.config,\n \"GET\",\n \"/integration\",\n );\n }\n}\n","import {\n DEFAULT_TIMEOUT_MS,\n DEFAULT_RETRY_ATTEMPTS,\n} from \"./transport/constants.js\";\nimport type { RetryConfig } from \"./transport/retry.js\";\nimport type { FetcherConfig } from \"./transport/fetcher.js\";\nimport { InventoryResource } from \"./resources/inventory.js\";\nimport { InquiriesResource } from \"./resources/inquiries.js\";\nimport { ProfileResource } from \"./resources/profile.js\";\nimport { ArticlesResource } from \"./resources/articles.js\";\nimport { IntegrationResource } from \"./resources/integration.js\";\nimport type { AutolinkCache } from \"./cache/index.js\";\n\nexport interface AutolinkClientConfig {\n apiKey: string;\n timeout?: number;\n retry?: Partial<RetryConfig>;\n debug?: boolean;\n cache?: AutolinkCache;\n}\n\nexport class AutolinkClient {\n readonly inventory: InventoryResource;\n readonly inquiries: InquiriesResource;\n readonly profile: ProfileResource;\n readonly articles: ArticlesResource;\n readonly integration: IntegrationResource;\n\n constructor(config: AutolinkClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"AutolinkClient: apiKey is required\");\n }\n if (\n !config.apiKey.startsWith(\"gw_live_\") &&\n !config.apiKey.startsWith(\"gw_test_\")\n ) {\n throw new Error(\n 'AutolinkClient: apiKey must start with \"gw_live_\" or \"gw_test_\"',\n );\n }\n\n const fetcherConfig: FetcherConfig = {\n apiKey: config.apiKey,\n timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,\n retry: {\n attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,\n backoff: config.retry?.backoff ?? \"exponential\",\n },\n debug: config.debug ?? false,\n };\n\n this.inventory = new InventoryResource(fetcherConfig, config.cache);\n this.inquiries = new InquiriesResource(fetcherConfig);\n this.profile = new ProfileResource(fetcherConfig);\n this.articles = new ArticlesResource(fetcherConfig, config.cache);\n this.integration = new IntegrationResource(fetcherConfig);\n }\n}\n","export interface AutolinkCache {\n get(key: string): Promise<unknown> | unknown;\n set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;\n delete(key: string): Promise<void> | void;\n}\n\ninterface CacheEntry {\n value: unknown;\n expiresAt: number | null; // null = no expiry\n}\n\nconst MAX_ENTRIES = 200;\n\nexport class MemoryCache implements AutolinkCache {\n private store = new Map<string, CacheEntry>();\n\n get(key: string): unknown {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value;\n }\n\n set(key: string, value: unknown, ttlSeconds?: number): void {\n // Evict oldest entry if at capacity and key is new\n if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {\n const oldestKey = this.store.keys().next().value;\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n }\n }\n this.store.set(key, {\n value,\n expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1000 : null,\n });\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n /** Remove all expired entries. Optional maintenance call. */\n purgeExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.store) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n}\n","export { AutolinkClient } from \"./client.js\";\nexport type { AutolinkClientConfig } from \"./client.js\";\n\nexport {\n AutolinkError,\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n} from \"./errors.js\";\n\nexport type {\n GatewayEnvelope,\n GatewayMeta,\n GatewayPagination,\n AutolinkVehicle,\n VehiclePhoto,\n VehicleDealer,\n CoverImageVariants,\n InventoryListFilters,\n FilterOptions,\n AutolinkInquiryPayload,\n AutolinkInquiry,\n AutolinkProfile,\n AutolinkArticle,\n ArticleListFilters,\n IntegrationStatus,\n StockStatus,\n VehicleCondition,\n} from \"./types/index.js\";\n\n// ---------------------------------------------------------------------------\n// DX helpers\n// ---------------------------------------------------------------------------\n\nimport type { GatewayEnvelope } from \"./types/index.js\";\nimport type { AutolinkValidationError } from \"./errors.js\";\n\n/** Unwraps a GatewayEnvelope and returns the data directly */\nexport function unwrap<T>(envelope: GatewayEnvelope<T>): T {\n return envelope.data;\n}\n\n/** Returns field-level validation errors for a given field name */\nexport function getFieldErrors(\n error: AutolinkValidationError,\n field: string,\n): string[] {\n return error.fields[field] ?? [];\n}\n\nexport {\n GATEWAY_BASE_URL,\n GATEWAY_URL,\n SDK_VERSION,\n} from \"./transport/constants.js\";\n\nexport type { AutolinkCache } from \"./cache/index.js\";\nexport { MemoryCache } from \"./cache/index.js\";\n"],"mappings":";AAAO,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,cAAc,GAAG,gBAAgB,QAAQ,mBAAmB;AAElE,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,cAAc;;;ACNpB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,MAAc,WAAmB;AAC5D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,oBAAN,cAAgC,cAAc;AAAA,EACnD,YAAY,SAAiB,WAAmB;AAC9C,UAAM,SAAS,wBAAwB,SAAS;AAChD,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,yBAAN,cAAqC,cAAc;AAAA,EACxD,YAAY,SAAiB,WAAmB;AAC9C,UAAM,SAAS,aAAa,SAAS;AACrC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,wBAAN,cAAoC,cAAc;AAAA,EACvD,YAAY,SAAiB,WAAmB;AAC9C,UAAM,SAAS,aAAa,SAAS;AACrC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,0BAAN,cAAsC,cAAc;AAAA,EAChD;AAAA,EAET,YACE,SACA,WACA,SAAmC,CAAC,GACpC;AACA,UAAM,SAAS,oBAAoB,SAAS;AAC5C,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;A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