@vitrina/api 14.41.0 → 14.42.0

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 CHANGED
@@ -24,6 +24,8 @@ var ERROR_CODES = [
24
24
  "VERTICAL_NOT_ENABLED",
25
25
  "ENTITLEMENT_NOT_ACTIVE",
26
26
  "UNSUPPORTED_VEHICLE_TYPE",
27
+ "VEHICLE_VALUE_OUT_OF_RANGE",
28
+ "PRICE_CHANGE_CONFIRMATION_REQUIRED",
27
29
  "NO_OFFERING_ADAPTER",
28
30
  "PAYLOAD_TOO_LARGE",
29
31
  "UNSUPPORTED_MEDIA_TYPE",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generated/error-codes.ts","../src/errors.ts","../src/webhooks.ts","../src/events.ts","../src/client.ts","../src/pagination.ts","../src/idempotency.ts"],"names":["createHmac","timingSafeEqual","createOpenApiClient","randomUUID"],"mappings":";;;;;;;;;;;;AAsEO,IAAM,WAAA,GAAoC;AAAA,EAC/C,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,0BAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,sBAAA;AAAA,EACA,wBAAA;AAAA,EACA,0BAAA;AAAA,EACA,qBAAA;AAAA,EACA,mBAAA;AAAA,EACA,wBAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA,gBAAA;AAAA,EACA,kCAAA;AAAA,EACA,+BAAA;AAAA,EACA,iCAAA;AAAA,EACA,kBAAA;AAAA,EACA,yBAAA;AAAA,EACA,6BAAA;AAAA,EACA,iCAAA;AAAA,EACA,wBAAA;AAAA,EACA,wBAAA;AAAA,EACA,yBAAA;AAAA,EACA,yBAAA;AAAA,EACA,iCAAA;AAAA,EACA,2BAAA;AAAA,EACA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AAA,EAAI;AAClC;AASO,SAAS,uBAAuB,MAAA,EAAyB;AAC9D,EAAA,MAAM,EAAA,GAAKC,iBAAA,EAAW,CAAE,OAAA,CAAQ,MAAM,EAAE,CAAA;AACxC,EAAA,OAAO,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAA;AACtC","file":"index.cjs","sourcesContent":["// AUTO-GENERATED by scripts/generate-error-codes.ts from the repo-root src/errors/index.ts's `ErrorCode` union — do not edit by hand.\n\n/**\n * Every code the API error envelope can carry as `error.code`, at the\n * commit this SDK was generated from. Kept OPEN (see `OpenErrorCode` in\n * `../errors.ts`) because a server can ship a new code before this SDK\n * is regenerated — narrow on the ones you handle, never assume this\n * list is exhaustive at runtime.\n */\nexport type ErrorCode =\n | 'VALIDATION_ERROR'\n | 'NOT_FOUND'\n | 'UNAUTHORIZED'\n | 'FORBIDDEN'\n | 'CONFLICT'\n | 'ACCOUNT_DELETION_BLOCKED'\n | 'CONFIRMATION_REQUIRED'\n | 'VERSION_CONFLICT'\n | 'UNIQUE_CONFLICT'\n | 'IDEMPOTENCY_KEY_CONFLICT'\n | 'VERTICAL_NOT_ENABLED'\n | 'ENTITLEMENT_NOT_ACTIVE'\n | 'UNSUPPORTED_VEHICLE_TYPE'\n | 'NO_OFFERING_ADAPTER'\n | 'PAYLOAD_TOO_LARGE'\n | 'UNSUPPORTED_MEDIA_TYPE'\n | 'UPSTREAM_ERROR'\n | 'RATE_LIMITED'\n | 'GONE'\n | 'INTERNAL_ERROR'\n | 'MESSAGING_ACCOUNT_TENANT_MISSING'\n | 'COPILOT_APPROVALS_UNAVAILABLE'\n | 'COPILOT_APPROVAL_REPLAY_BLOCKED'\n | 'COPILOT_DISABLED'\n | 'COPILOT_BUDGET_EXCEEDED'\n | 'DEALER_SITES_NOT_CONFIGURED'\n | 'STOREFRONT_ZONES_NOT_CONFIGURED'\n | 'RECONTACTO_NOT_ENABLED'\n | 'SYNC_QUEUE_UNAVAILABLE'\n | 'SHARE_IMAGE_UNAVAILABLE'\n | 'AUDIO_RENDITION_PENDING'\n | 'ATTRIBUTION_PROFILE_UNAVAILABLE'\n | 'DOCUMENT_LOGO_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_MISMATCH'\n | 'ADS_KEY_NEEDS_REMINT'\n | 'ADS_ACTION_READ_UNAVAILABLE'\n | 'ADS_ACTION_REPLAY_BLOCKED'\n | 'ADS_ACTION_NOT_AVAILABLE'\n | 'ADS_ACTION_NOT_REVERSIBLE'\n | 'ADS_ACTION_CONSENT_REQUIRED'\n | 'GTM_NOT_CONFIGURED'\n | 'GTM_NOT_CONNECTED'\n | 'GTM_CONSENT_REQUIRED'\n | 'GTM_PERMISSION_DENIED'\n | 'GTM_CONTAINER_REQUIRED'\n | 'GTM_PENDING_CHANGES'\n | 'GTM_WORKSPACE_CONFLICT'\n | 'GTM_WORKSPACE_LIMIT'\n | 'MISSING_SIGNATURE'\n | 'MALFORMED_SIGNATURE'\n | 'STALE_SIGNATURE'\n | 'INVALID_SIGNATURE'\n | 'REPLAY_DETECTED'\n | 'TURNSTILE_UNAVAILABLE'\n | 'TASADOR_QUOTA_EXHAUSTED'\n | 'TASADOR_ANON_DAILY_LIMIT'\n | 'TASADOR_CAPACITY_REACHED'\n | 'CLINIC_PLAN_REQUIRED'\n | 'TENANT_BILLING_PAUSED';\n\nexport const ERROR_CODES: readonly ErrorCode[] = [\n 'VALIDATION_ERROR',\n 'NOT_FOUND',\n 'UNAUTHORIZED',\n 'FORBIDDEN',\n 'CONFLICT',\n 'ACCOUNT_DELETION_BLOCKED',\n 'CONFIRMATION_REQUIRED',\n 'VERSION_CONFLICT',\n 'UNIQUE_CONFLICT',\n 'IDEMPOTENCY_KEY_CONFLICT',\n 'VERTICAL_NOT_ENABLED',\n 'ENTITLEMENT_NOT_ACTIVE',\n 'UNSUPPORTED_VEHICLE_TYPE',\n 'NO_OFFERING_ADAPTER',\n 'PAYLOAD_TOO_LARGE',\n 'UNSUPPORTED_MEDIA_TYPE',\n 'UPSTREAM_ERROR',\n 'RATE_LIMITED',\n 'GONE',\n 'INTERNAL_ERROR',\n 'MESSAGING_ACCOUNT_TENANT_MISSING',\n 'COPILOT_APPROVALS_UNAVAILABLE',\n 'COPILOT_APPROVAL_REPLAY_BLOCKED',\n 'COPILOT_DISABLED',\n 'COPILOT_BUDGET_EXCEEDED',\n 'DEALER_SITES_NOT_CONFIGURED',\n 'STOREFRONT_ZONES_NOT_CONFIGURED',\n 'RECONTACTO_NOT_ENABLED',\n 'SYNC_QUEUE_UNAVAILABLE',\n 'SHARE_IMAGE_UNAVAILABLE',\n 'AUDIO_RENDITION_PENDING',\n 'ATTRIBUTION_PROFILE_UNAVAILABLE',\n 'DOCUMENT_LOGO_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_MISMATCH',\n 'ADS_KEY_NEEDS_REMINT',\n 'ADS_ACTION_READ_UNAVAILABLE',\n 'ADS_ACTION_REPLAY_BLOCKED',\n 'ADS_ACTION_NOT_AVAILABLE',\n 'ADS_ACTION_NOT_REVERSIBLE',\n 'ADS_ACTION_CONSENT_REQUIRED',\n 'GTM_NOT_CONFIGURED',\n 'GTM_NOT_CONNECTED',\n 'GTM_CONSENT_REQUIRED',\n 'GTM_PERMISSION_DENIED',\n 'GTM_CONTAINER_REQUIRED',\n 'GTM_PENDING_CHANGES',\n 'GTM_WORKSPACE_CONFLICT',\n 'GTM_WORKSPACE_LIMIT',\n 'MISSING_SIGNATURE',\n 'MALFORMED_SIGNATURE',\n 'STALE_SIGNATURE',\n 'INVALID_SIGNATURE',\n 'REPLAY_DETECTED',\n 'TURNSTILE_UNAVAILABLE',\n 'TASADOR_QUOTA_EXHAUSTED',\n 'TASADOR_ANON_DAILY_LIMIT',\n 'TASADOR_CAPACITY_REACHED',\n 'CLINIC_PLAN_REQUIRED',\n 'TENANT_BILLING_PAUSED',\n] as const;\n","/**\n * Typed errors over the API's one error envelope: `{ error: { code, message,\n * details?, field_errors?, requestId?, ...extensions } }` (`src/errors/\n * index.ts` + `src/middlewares/error-handler.ts` in vitrina-app). `code` is\n * generated from the committed error catalogue (see `generated/error-codes.ts`\n * and `../scripts/generate-error-codes.ts`) but kept OPEN at the type level —\n * `ErrorCode | (string & Record<string, never>)` — because a server release\n * can ship a new code before this SDK is regenerated; never treat the union\n * as exhaustive at runtime (no `switch` without a `default`).\n */\nimport { ERROR_CODES, type ErrorCode } from './generated/error-codes';\n\nexport { ERROR_CODES };\nexport type { ErrorCode };\n\n/** `error.code`, widened so an unrecognised future code still type-checks.\n * The `Record<string, never>` intersection (not a bare `{}`) is what keeps\n * known `ErrorCode` literals showing up in autocomplete while still\n * accepting any string. */\nexport type OpenErrorCode = ErrorCode | (string & Record<string, never>);\n\n/** One entry of `error.details.reasons` on an outbound-policy verdict (C4). */\nexport interface OutboundVerdictReason {\n code: string;\n kind: 'bloqueo' | 'advertencia';\n hint: string;\n detail?: string;\n}\n\n/** The wire shape of `error` inside the envelope. */\nexport interface ApiErrorBody {\n code: OpenErrorCode;\n message: string;\n details?: unknown;\n field_errors?: Record<string, string>;\n requestId?: string;\n /** Send-verdict envelopes (C4) put `reasons`/`hint` at this level too. */\n reasons?: OutboundVerdictReason[];\n hint?: string;\n [key: string]: unknown;\n}\n\nexport interface ApiErrorOptions {\n requestUrl?: string;\n requestMethod?: string;\n}\n\n/** Base class for every error this SDK throws for a non-2xx API response. */\nexport class VitrinaApiError extends Error {\n /** The catalogue code — branch on this, never on `message`. */\n readonly code: OpenErrorCode;\n\n /** HTTP status of the response that produced this error. */\n readonly status: number;\n\n readonly details?: unknown;\n\n readonly fieldErrors?: Record<string, string>;\n\n /** Correlates this failure with the server's own logs. */\n readonly requestId?: string;\n\n /** The full parsed `error` object, for anything not surfaced above. */\n readonly body: ApiErrorBody;\n\n readonly requestUrl?: string;\n\n readonly requestMethod?: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(body.message || `Vitrina API error ${body.code} (HTTP ${status})`);\n this.name = 'VitrinaApiError';\n this.status = status;\n this.code = body.code;\n this.details = body.details;\n this.fieldErrors = body.field_errors;\n this.requestId = body.requestId;\n this.body = body;\n this.requestUrl = options.requestUrl;\n this.requestMethod = options.requestMethod;\n }\n\n /** `429 RATE_LIMITED`. */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** `401` — no credential, or one the server does not recognise. */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** `403` — a real credential, missing the scope this call needs. */\n get isForbidden(): boolean {\n return this.status === 403;\n }\n\n /** `404 NOT_FOUND`. */\n get isNotFound(): boolean {\n return this.status === 404;\n }\n\n /** `409 IDEMPOTENCY_KEY_CONFLICT` — same `Idempotency-Key`, different body. */\n get isIdempotencyConflict(): boolean {\n return this.code === 'IDEMPOTENCY_KEY_CONFLICT';\n }\n}\n\n/**\n * `422 OUTBOUND_BLOCKED` (a Bloqueo, never overridable) or `409\n * OUTBOUND_WARNING` (an Advertencia — resend the same call with\n * `acknowledge: reasons.map(r => r.code)` in the body to proceed). Cross-\n * ticket contract C4 — `src/services/api-send-verdicts.ts` in vitrina-app.\n */\nexport class OutboundVerdictError extends VitrinaApiError {\n /** Every reason the send was stopped for, with its kind and hint. */\n readonly reasons: OutboundVerdictReason[];\n\n /** The first reason's hint, surfaced at the top level like the wire body. */\n readonly hint: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(status, body, options);\n this.name = 'OutboundVerdictError';\n const detailsReasons = (\n body.details as { reasons?: OutboundVerdictReason[] } | undefined\n )?.reasons;\n this.reasons = body.reasons ?? detailsReasons ?? [];\n this.hint = body.hint ?? this.reasons[0]?.hint ?? '';\n }\n\n /** A Bloqueo — the law, the customer or the provider already said no. */\n get isBlocked(): boolean {\n return this.code === 'OUTBOUND_BLOCKED';\n }\n\n /** An Advertencia — resend once with `acknowledge` to proceed. */\n get isWarning(): boolean {\n return this.code === 'OUTBOUND_WARNING';\n }\n\n /** `reasons` codes, ready to pass back as `{ acknowledge: [...] }`. */\n get acknowledgeCodes(): string[] {\n return this.reasons.map((r) => r.code);\n }\n}\n\nfunction asErrorBody(payload: unknown, status: number): ApiErrorBody {\n if (payload && typeof payload === 'object') {\n const maybeEnvelope = payload as { error?: unknown };\n const candidate =\n maybeEnvelope.error && typeof maybeEnvelope.error === 'object'\n ? (maybeEnvelope.error as Record<string, unknown>)\n : (payload as Record<string, unknown>);\n if (\n typeof candidate.code === 'string' &&\n typeof candidate.message === 'string'\n ) {\n return candidate as unknown as ApiErrorBody;\n }\n }\n return {\n code: 'INTERNAL_ERROR',\n message: `HTTP ${status} with an unrecognised response body`,\n };\n}\n\n/** Turns a non-2xx response's status + parsed JSON body into a typed error. */\nexport function toApiError(\n status: number,\n payload: unknown,\n options: ApiErrorOptions = {},\n): VitrinaApiError {\n const body = asErrorBody(payload, status);\n if (body.code === 'OUTBOUND_BLOCKED' || body.code === 'OUTBOUND_WARNING') {\n return new OutboundVerdictError(status, body, options);\n }\n return new VitrinaApiError(status, body, options);\n}\n\n/** The subset of an `openapi-fetch` call's resolved value `unwrap` needs. */\nexport interface UnwrappableResult<T> {\n data?: T;\n error?: unknown;\n response: Response;\n}\n\n/**\n * `const location = unwrap(await api.GET('/locations/{id}', ...))` — throws\n * a typed `VitrinaApiError` (or `OutboundVerdictError`) instead of making\n * every call site check `error` by hand. `openapi-fetch` itself never\n * throws; reach for the raw `{ data, error }` result directly when you want\n * that instead.\n */\nexport function unwrap<T>(\n result: UnwrappableResult<T>,\n options: ApiErrorOptions = {},\n): T {\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error, options);\n }\n if (result.data === undefined) {\n throw new VitrinaApiError(\n result.response.status,\n {\n code: 'INTERNAL_ERROR',\n message: 'Response had neither data nor error',\n },\n options,\n );\n }\n return result.data;\n}\n","/**\n * Webhook Evento envelope + Stripe-style signature verification, matching\n * the dispatch service's own `signPayload`/`buildHeaders`\n * (`src/services/webhook-dispatch.service.ts` in vitrina-app; cross-ticket\n * contract C3). The signature is an HMAC-SHA256 over `${timestamp}.${body}`\n * with the subscription's `whsec_...` secret, carried as\n * `X-Webhook-Signature: t=<unix_seconds>,v1=<hex>`.\n *\n * `tests/api-sdk-webhook-signature.test.ts` (vitrina-app repo root) verifies\n * this against the REAL `signPayload` the dispatch service calls in\n * production — not a hand-written fixture.\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** `resource` on the envelope — what changed, and where to read it. */\nexport interface WebhookEventResource {\n type: string;\n id: string | null;\n /** Absolute `GET` URL for this resource, or `null` when none is available\n * (e.g. the event has no single owning record). Feeds `event.fetch()`. */\n url: string | null;\n}\n\n/** Who did it — see `Author` in vitrina-app's `src/types/author.ts` (C3). */\nexport interface WebhookEventAuthor {\n kind: 'member' | 'api_key' | 'ai_agent' | 'system' | 'contact';\n id: string | null;\n name: string | null;\n via?: { kind: 'connected_app' | 'personal_token'; name: string };\n}\n\n/** Why `data` is absent — every reason a subscription's owner can be denied\n * the resource body. `missing_scope:<scope>` is a family, not one literal. */\nexport type DataOmittedReason =\n | 'not_requested'\n | 'sensitive'\n | 'owner_unavailable'\n | 'restricted_visibility'\n | `missing_scope:${string}`;\n\n/** One Evento, exactly as it arrives on the wire. Exactly one of `data` /\n * `data_omitted` is ever present. */\nexport interface WebhookEventEnvelope<TData = Record<string, unknown>> {\n id: string;\n type: string;\n version: number;\n /** `false` for an event from a sandbox (test-mode) workspace, `true`\n * otherwise; mirrored on the delivery's `Vitrina-Livemode` header.\n * Optional here only so an envelope captured before vitrina-app#2693\n * still satisfies this type — every envelope on the wire carries it. */\n livemode?: boolean;\n created_at: string;\n tenant_id: string;\n resource: WebhookEventResource;\n changes?: Record<string, { from: unknown; to: unknown }>;\n author: WebhookEventAuthor;\n data?: TData;\n data_omitted?: DataOmittedReason;\n}\n\nexport interface VerifySignatureOptions {\n /** How far `X-Webhook-Timestamp` may drift from now before a signature\n * that otherwise matches is rejected as stale (replay protection).\n * Default 300 (5 minutes), matching the docs' own verifier. */\n toleranceSeconds?: number;\n /** Override \"now\", in Unix seconds — for tests. */\n nowUnix?: number;\n}\n\nexport type VerifyResult =\n | { ok: true }\n | { ok: false; reason: 'malformed_header' | 'bad_signature' | 'stale' };\n\nfunction parseSignatureHeader(\n header: string,\n): { timestamp: number; v1: string } | null {\n const parts: Record<string, string> = {};\n for (const pair of header.split(',')) {\n const at = pair.indexOf('=');\n if (at === -1) continue;\n parts[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();\n }\n const timestamp = Number(parts.t);\n if (!Number.isFinite(timestamp) || !parts.v1) return null;\n return { timestamp, v1: parts.v1 };\n}\n\n/**\n * Verifies an `X-Webhook-Signature` header against the raw delivery body.\n * Never throws — returns `{ ok: false, reason }` so a caller can log why a\n * delivery was rejected. `rawBody` must be the exact bytes the delivery\n * sent, before any JSON re-serialization (re-stringifying a parsed body\n * produces different bytes and the signature will never match).\n */\nexport function verifyWebhookSignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): VerifyResult {\n const parsed = parseSignatureHeader(params.signatureHeader);\n if (!parsed) return { ok: false, reason: 'malformed_header' };\n\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n const expected = createHmac('sha256', params.secret)\n .update(`${parsed.timestamp}.${body}`)\n .digest('hex');\n\n const given = Buffer.from(parsed.v1, 'utf8');\n const mine = Buffer.from(expected, 'utf8');\n const signatureMatches =\n given.length === mine.length && timingSafeEqual(given, mine);\n if (!signatureMatches) return { ok: false, reason: 'bad_signature' };\n\n const tolerance = params.toleranceSeconds ?? 300;\n const now = params.nowUnix ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - parsed.timestamp) > tolerance) {\n return { ok: false, reason: 'stale' };\n }\n return { ok: true };\n}\n\nexport class WebhookSignatureError extends Error {\n readonly reason: Exclude<VerifyResult, { ok: true }>['reason'];\n\n constructor(reason: Exclude<VerifyResult, { ok: true }>['reason']) {\n super(`Webhook signature verification failed: ${reason}`);\n this.name = 'WebhookSignatureError';\n this.reason = reason;\n }\n}\n\n/**\n * Verifies + parses an Evento delivery in one call (Stripe's\n * `constructEvent` naming, same idea): throws `WebhookSignatureError`\n * instead of returning a result a caller might forget to check before\n * trusting `rawBody`.\n */\nexport function constructEventEnvelope<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): WebhookEventEnvelope<TData> {\n const result = verifyWebhookSignature(params);\n if (!result.ok) throw new WebhookSignatureError(result.reason);\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n return JSON.parse(body) as WebhookEventEnvelope<TData>;\n}\n","/**\n * `event.fetch()` — read an Evento's resource in one call, using the same\n * credentials the client was created with. `resource.url` is the absolute\n * `GET` URL the server already computed (`apiPublicUrl()` in\n * `webhook-dispatch.service.ts`), so this is a plain authenticated fetch of\n * that URL — no per-resource-type routing table to keep in sync.\n */\nimport { toApiError } from './errors';\nimport {\n constructEventEnvelope,\n verifyWebhookSignature,\n type VerifySignatureOptions,\n type WebhookEventEnvelope,\n} from './webhooks';\n\nexport class EventResourceUnavailableError extends Error {\n readonly event: WebhookEventEnvelope;\n\n constructor(event: WebhookEventEnvelope) {\n super(\n event.data_omitted\n ? `Event ${event.id} (${event.type}) carries no resource URL — data_omitted: ${event.data_omitted}`\n : `Event ${event.id} (${event.type}) carries no resource URL`,\n );\n this.name = 'EventResourceUnavailableError';\n this.event = event;\n }\n}\n\n/** A parsed Evento, plus a `fetch()` bound to the client it came from. */\nexport type VitrinaEvent<TData = Record<string, unknown>> =\n WebhookEventEnvelope<TData> & {\n /**\n * `GET`s `resource.url` with this client's credentials and returns its\n * `data`. Throws `EventResourceUnavailableError` when the envelope has no\n * URL (an event with no single owning resource, or one whose `data` you\n * already have inline). Pass a type argument to get the resource typed:\n * `await event.fetch<Contact>()`.\n */\n fetch<TResource = TData>(): Promise<TResource>;\n };\n\nexport interface EventFetcherDeps {\n headers: HeadersInit;\n fetch: typeof fetch;\n}\n\n/** Builds the `events` namespace `createClient()` attaches to every client:\n * signature verification bound to nothing (pure functions), and\n * `constructEvent` bound to this client's own auth so the returned event's\n * `.fetch()` needs no arguments. */\nexport function createEventsNamespace(deps: EventFetcherDeps) {\n // `WebhookEventEnvelope<any>`: this helper only ever reads `resource` /\n // `data_omitted` / `id` / `type`, never `.data`, so it is deliberately\n // NOT generic over TData — a `WebhookEventEnvelope<TData>` for any TData\n // must be assignable here.\n async function fetchResource<TResource>(\n event: WebhookEventEnvelope<any>,\n ): Promise<TResource> {\n if (!event.resource.url) throw new EventResourceUnavailableError(event);\n const res = await deps.fetch(event.resource.url, { headers: deps.headers });\n let json: unknown;\n try {\n json = await res.json();\n } catch {\n json = undefined;\n }\n if (!res.ok) {\n throw toApiError(res.status, json, {\n requestUrl: event.resource.url,\n requestMethod: 'GET',\n });\n }\n return (json as { data: TResource })?.data;\n }\n\n return {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature: (\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ) => verifyWebhookSignature(params),\n\n /**\n * Verifies + parses a webhook delivery and returns it with a bound\n * `.fetch()`. Throws `WebhookSignatureError` on a bad/stale signature.\n *\n * const event = client.events.constructEvent({\n * secret: subscriptionSecret,\n * signatureHeader: req.headers['x-webhook-signature'],\n * rawBody: req.rawBody,\n * });\n * if (event.type === 'contact.created') {\n * const contact = await event.fetch<Contact>();\n * }\n */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData> {\n const envelope = constructEventEnvelope<TData>(params);\n return Object.assign(envelope, {\n fetch: <TResource = TData>() => fetchResource<TResource>(envelope),\n });\n },\n };\n}\n","/**\n * `createClient()` — a typed `openapi-fetch` client over the API pública\n * (`paths` generated from the committed `openapi.public.json`), plus the\n * `events` namespace (webhook signature verification + `event.fetch()`).\n *\n * Auth: pass an `sk_*` API key (workspace credential or personal token —\n * both are Bearer) or a raw bearer token you manage yourself. Exactly one of\n * `apiKey` / `bearer`.\n */\nimport createOpenApiClient, { type Client } from 'openapi-fetch';\n\nimport { createEventsNamespace, type VitrinaEvent } from './events';\nimport type { paths } from './generated/api-types';\nimport type { VerifySignatureOptions, VerifyResult } from './webhooks';\n\nexport interface CreateClientOptions {\n /** Absolute base URL, e.g. `https://api.vitrinadev.com/api/v1`. No trailing slash. */\n baseUrl: string;\n /** An `sk_*` API key (workspace key or personal token). Mutually exclusive with `bearer`. */\n apiKey?: string;\n /** A raw bearer token, for a caller that manages tokens itself (e.g. a Supabase session JWT). */\n bearer?: string;\n /** Extra headers merged onto every request (e.g. a custom `User-Agent`). */\n headers?: Record<string, string>;\n /** Override `fetch` — Node <18, undici, msw, a test double. Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n}\n\nexport interface VitrinaEventsNamespace {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VerifyResult;\n /** Verifies + parses a webhook delivery; the returned event carries a\n * `.fetch()` bound to this client. Throws `WebhookSignatureError`. */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData>;\n}\n\n/** The typed REST client (`GET`/`POST`/.../`use`/`eject`, from `openapi-fetch`)\n * plus the `events` namespace. */\nexport type VitrinaClient = Client<paths> & { events: VitrinaEventsNamespace };\n\nexport function createClient(opts: CreateClientOptions): VitrinaClient {\n if (opts.apiKey && opts.bearer) {\n throw new RangeError(\n 'createClient(): pass at most one of `apiKey` / `bearer`, not both',\n );\n }\n const credential = opts.apiKey ?? opts.bearer;\n const headers: Record<string, string> = {\n ...(credential ? { Authorization: `Bearer ${credential}` } : {}),\n ...opts.headers,\n };\n const fetchImpl = opts.fetch ?? fetch;\n\n const base = createOpenApiClient<paths>({\n baseUrl: opts.baseUrl,\n headers,\n fetch: fetchImpl,\n });\n\n const events = createEventsNamespace({ headers, fetch: fetchImpl });\n\n return Object.assign(base, { events });\n}\n","/**\n * Cursor pagination — walks a list endpoint page by page, yielding one item\n * at a time (`for await`). Vitrina's list envelopes carry the cursor as\n * `meta.pagination.nextCursor` (the shape every v1 list route in production\n * answers with — `ok(res, rows, { pagination: { nextCursor, limit } })`,\n * `src/routes/api/v1/*.ts`) with a `meta.nextCursor` fallback for the flat\n * `PaginationMeta` OpenAPI shape (`src/api/openapi-responses.ts`) some\n * generated docs describe; this helper reads either. The opaque cursor\n * itself is a base64url-encoded `{ ts, id }` pair (`src/api/pagination.ts`)\n * — never decode it, just pass it back as the next page's `cursor` query\n * param.\n */\nimport { toApiError } from './errors';\n\nexport interface PaginationMeta {\n pagination?: {\n nextCursor?: string | null;\n prevCursor?: string | null;\n limit?: number;\n };\n nextCursor?: string | null;\n prevCursor?: string | null;\n total?: number;\n limit?: number;\n [key: string]: unknown;\n}\n\nexport interface ListEnvelope<T> {\n data?: T[];\n meta?: PaginationMeta;\n}\n\n/** The subset of an `openapi-fetch` GET call's resolved value `paginate` needs. */\nexport interface FetchPageResult<T> {\n data?: ListEnvelope<T>;\n error?: unknown;\n response: Response;\n}\n\nfunction nextCursorOf(meta: PaginationMeta | undefined): string | undefined {\n const cursor = meta?.pagination?.nextCursor ?? meta?.nextCursor ?? null;\n return cursor ?? undefined;\n}\n\n/**\n * Walks every page of a cursor-paginated list, yielding one item at a time.\n *\n * for await (const appointment of paginate((cursor) =>\n * api.GET('/appointments', { params: { query: { cursor, limit: 100 } } }),\n * )) {\n * console.log(appointment.id);\n * }\n *\n * CURSOR IS THE MINORITY SHAPE, so check the route before reaching for this.\n * Measured against the published contract: exactly two operations take a\n * `cursor` — `GET /appointments` and `GET /conversations/{id}/messages`.\n * Fifteen take `offset`/`limit` (`/stock`, `/vehicles`, `/contacts/search`,\n * `/webhooks/{id}/deliveries` and the rest), and others take `page`/`page_size`\n * (`/leads` among them). Passing `cursor` to one of those is a type error, not\n * a silent first page — which is the point of generating this package from the\n * contract.\n *\n * `fetchPage` is any typed `api.GET(...)` call, called once per page with\n * the previous page's cursor (`undefined` for the first page). Throws a\n * typed `VitrinaApiError` if a page comes back as an error, same as\n * `unwrap()`.\n */\nexport async function* paginate<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): AsyncGenerator<T, void, unknown> {\n let cursor: string | undefined;\n for (;;) {\n // eslint-disable-next-line no-await-in-loop -- pages are inherently sequential (each cursor depends on the last)\n const result = await fetchPage(cursor);\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error);\n }\n const page = result.data;\n if (!page || !Array.isArray(page.data)) return;\n for (const item of page.data) yield item;\n const next = nextCursorOf(page.meta);\n if (!next) return;\n cursor = next;\n }\n}\n\n/** Same as `paginate`, but collects every page into one array. Only reach\n * for this on a list you know is bounded — an unbounded one belongs on the\n * `for await` form above. */\nexport async function paginateAll<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): Promise<T[]> {\n const items: T[] = [];\n // eslint-disable-next-line no-restricted-syntax -- collecting an async generator IS the sequential-await case for-await exists for\n for await (const item of paginate(fetchPage)) items.push(item);\n return items;\n}\n","/**\n * `Idempotency-Key` — replay-safe retries on the 39 published write\n * operations that accept it (ADR 0106 §2.3/#2400). Resending the SAME key\n * with the SAME body returns the original response (`X-Idempotent-Replay:\n * 1`) instead of creating a second copy; the same key with a DIFFERENT body\n * answers `409 IDEMPOTENCY_KEY_CONFLICT` (`VitrinaApiError#isIdempotencyConflict`).\n *\n * The generated types already carry `Idempotency-Key` as a typed header\n * parameter per operation — `idempotencyKey()` just builds a well-formed\n * value to put there:\n *\n * await api.POST('/pipelines', {\n * params: { header: idempotencyKey(`provision-${userId}-2026-04-24`) },\n * body: { ... },\n * });\n */\nimport { randomUUID } from 'node:crypto';\n\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{8,200}$/;\n\nexport interface IdempotencyKeyHeader {\n 'Idempotency-Key': string;\n}\n\n/**\n * Validates `key` against the server's own constraint (`minLength: 8,\n * maxLength: 200, pattern: ^[A-Za-z0-9_-]+$` on every operation that accepts\n * it) and returns it as a header object to spread into `params.header`.\n * Throws `RangeError` on a malformed key — better to fail before the\n * request leaves than to get back a generic `VALIDATION_ERROR`.\n */\nexport function idempotencyKey(key: string): IdempotencyKeyHeader {\n if (!KEY_PATTERN.test(key)) {\n throw new RangeError(\n `Idempotency-Key must be 8-200 characters of [A-Za-z0-9_-], got: ${JSON.stringify(key)}`,\n );\n }\n return { 'Idempotency-Key': key };\n}\n\n/**\n * A fresh, valid `Idempotency-Key`. Mint ONE per logical operation and reuse\n * it across THAT operation's retries — generating a new key per attempt\n * defeats the point (each attempt would look like a different write). `\n * prefix` is optional and purely for your own log-grepping; it plays no\n * role on the server.\n */\nexport function generateIdempotencyKey(prefix?: string): string {\n const id = randomUUID().replace(/-/g, '');\n return prefix ? `${prefix}-${id}` : id;\n}\n"]}
1
+ {"version":3,"sources":["../src/generated/error-codes.ts","../src/errors.ts","../src/webhooks.ts","../src/events.ts","../src/client.ts","../src/pagination.ts","../src/idempotency.ts"],"names":["createHmac","timingSafeEqual","createOpenApiClient","randomUUID"],"mappings":";;;;;;;;;;;;AAwEO,IAAM,WAAA,GAAoC;AAAA,EAC/C,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,0BAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,sBAAA;AAAA,EACA,wBAAA;AAAA,EACA,0BAAA;AAAA,EACA,4BAAA;AAAA,EACA,oCAAA;AAAA,EACA,qBAAA;AAAA,EACA,m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M,KAAK,IAAI,CAAA;AAC7D,EAAA,OAAO,KAAA;AACT;AC9EA,IAAM,WAAA,GAAc,wBAAA;AAab,SAAS,eAAe,GAAA,EAAmC;AAChE,EAAA,IAAI,CAAC,WAAA,CAAY,IAAA,CAAK,GAAG,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAI,UAAA;AAAA,MACR,CAAA,gEAAA,EAAmE,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA;AAAA,KACxF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,mBAAmB,GAAA,EAAI;AAClC;AASO,SAAS,uBAAuB,MAAA,EAAyB;AAC9D,EAAA,MAAM,EAAA,GAAKC,iBAAA,EAAW,CAAE,OAAA,CAAQ,MAAM,EAAE,CAAA;AACxC,EAAA,OAAO,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAA;AACtC","file":"index.cjs","sourcesContent":["// AUTO-GENERATED by scripts/generate-error-codes.ts from the repo-root src/errors/index.ts's `ErrorCode` union — do not edit by hand.\n\n/**\n * Every code the API error envelope can carry as `error.code`, at the\n * commit this SDK was generated from. Kept OPEN (see `OpenErrorCode` in\n * `../errors.ts`) because a server can ship a new code before this SDK\n * is regenerated — narrow on the ones you handle, never assume this\n * list is exhaustive at runtime.\n */\nexport type ErrorCode =\n | 'VALIDATION_ERROR'\n | 'NOT_FOUND'\n | 'UNAUTHORIZED'\n | 'FORBIDDEN'\n | 'CONFLICT'\n | 'ACCOUNT_DELETION_BLOCKED'\n | 'CONFIRMATION_REQUIRED'\n | 'VERSION_CONFLICT'\n | 'UNIQUE_CONFLICT'\n | 'IDEMPOTENCY_KEY_CONFLICT'\n | 'VERTICAL_NOT_ENABLED'\n | 'ENTITLEMENT_NOT_ACTIVE'\n | 'UNSUPPORTED_VEHICLE_TYPE'\n | 'VEHICLE_VALUE_OUT_OF_RANGE'\n | 'PRICE_CHANGE_CONFIRMATION_REQUIRED'\n | 'NO_OFFERING_ADAPTER'\n | 'PAYLOAD_TOO_LARGE'\n | 'UNSUPPORTED_MEDIA_TYPE'\n | 'UPSTREAM_ERROR'\n | 'RATE_LIMITED'\n | 'GONE'\n | 'INTERNAL_ERROR'\n | 'MESSAGING_ACCOUNT_TENANT_MISSING'\n | 'COPILOT_APPROVALS_UNAVAILABLE'\n | 'COPILOT_APPROVAL_REPLAY_BLOCKED'\n | 'COPILOT_DISABLED'\n | 'COPILOT_BUDGET_EXCEEDED'\n | 'DEALER_SITES_NOT_CONFIGURED'\n | 'STOREFRONT_ZONES_NOT_CONFIGURED'\n | 'RECONTACTO_NOT_ENABLED'\n | 'SYNC_QUEUE_UNAVAILABLE'\n | 'SHARE_IMAGE_UNAVAILABLE'\n | 'AUDIO_RENDITION_PENDING'\n | 'ATTRIBUTION_PROFILE_UNAVAILABLE'\n | 'DOCUMENT_LOGO_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_MISMATCH'\n | 'ADS_KEY_NEEDS_REMINT'\n | 'ADS_ACTION_READ_UNAVAILABLE'\n | 'ADS_ACTION_REPLAY_BLOCKED'\n | 'ADS_ACTION_NOT_AVAILABLE'\n | 'ADS_ACTION_NOT_REVERSIBLE'\n | 'ADS_ACTION_CONSENT_REQUIRED'\n | 'GTM_NOT_CONFIGURED'\n | 'GTM_NOT_CONNECTED'\n | 'GTM_CONSENT_REQUIRED'\n | 'GTM_PERMISSION_DENIED'\n | 'GTM_CONTAINER_REQUIRED'\n | 'GTM_PENDING_CHANGES'\n | 'GTM_WORKSPACE_CONFLICT'\n | 'GTM_WORKSPACE_LIMIT'\n | 'MISSING_SIGNATURE'\n | 'MALFORMED_SIGNATURE'\n | 'STALE_SIGNATURE'\n | 'INVALID_SIGNATURE'\n | 'REPLAY_DETECTED'\n | 'TURNSTILE_UNAVAILABLE'\n | 'TASADOR_QUOTA_EXHAUSTED'\n | 'TASADOR_ANON_DAILY_LIMIT'\n | 'TASADOR_CAPACITY_REACHED'\n | 'CLINIC_PLAN_REQUIRED'\n | 'TENANT_BILLING_PAUSED';\n\nexport const ERROR_CODES: readonly ErrorCode[] = [\n 'VALIDATION_ERROR',\n 'NOT_FOUND',\n 'UNAUTHORIZED',\n 'FORBIDDEN',\n 'CONFLICT',\n 'ACCOUNT_DELETION_BLOCKED',\n 'CONFIRMATION_REQUIRED',\n 'VERSION_CONFLICT',\n 'UNIQUE_CONFLICT',\n 'IDEMPOTENCY_KEY_CONFLICT',\n 'VERTICAL_NOT_ENABLED',\n 'ENTITLEMENT_NOT_ACTIVE',\n 'UNSUPPORTED_VEHICLE_TYPE',\n 'VEHICLE_VALUE_OUT_OF_RANGE',\n 'PRICE_CHANGE_CONFIRMATION_REQUIRED',\n 'NO_OFFERING_ADAPTER',\n 'PAYLOAD_TOO_LARGE',\n 'UNSUPPORTED_MEDIA_TYPE',\n 'UPSTREAM_ERROR',\n 'RATE_LIMITED',\n 'GONE',\n 'INTERNAL_ERROR',\n 'MESSAGING_ACCOUNT_TENANT_MISSING',\n 'COPILOT_APPROVALS_UNAVAILABLE',\n 'COPILOT_APPROVAL_REPLAY_BLOCKED',\n 'COPILOT_DISABLED',\n 'COPILOT_BUDGET_EXCEEDED',\n 'DEALER_SITES_NOT_CONFIGURED',\n 'STOREFRONT_ZONES_NOT_CONFIGURED',\n 'RECONTACTO_NOT_ENABLED',\n 'SYNC_QUEUE_UNAVAILABLE',\n 'SHARE_IMAGE_UNAVAILABLE',\n 'AUDIO_RENDITION_PENDING',\n 'ATTRIBUTION_PROFILE_UNAVAILABLE',\n 'DOCUMENT_LOGO_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_MISMATCH',\n 'ADS_KEY_NEEDS_REMINT',\n 'ADS_ACTION_READ_UNAVAILABLE',\n 'ADS_ACTION_REPLAY_BLOCKED',\n 'ADS_ACTION_NOT_AVAILABLE',\n 'ADS_ACTION_NOT_REVERSIBLE',\n 'ADS_ACTION_CONSENT_REQUIRED',\n 'GTM_NOT_CONFIGURED',\n 'GTM_NOT_CONNECTED',\n 'GTM_CONSENT_REQUIRED',\n 'GTM_PERMISSION_DENIED',\n 'GTM_CONTAINER_REQUIRED',\n 'GTM_PENDING_CHANGES',\n 'GTM_WORKSPACE_CONFLICT',\n 'GTM_WORKSPACE_LIMIT',\n 'MISSING_SIGNATURE',\n 'MALFORMED_SIGNATURE',\n 'STALE_SIGNATURE',\n 'INVALID_SIGNATURE',\n 'REPLAY_DETECTED',\n 'TURNSTILE_UNAVAILABLE',\n 'TASADOR_QUOTA_EXHAUSTED',\n 'TASADOR_ANON_DAILY_LIMIT',\n 'TASADOR_CAPACITY_REACHED',\n 'CLINIC_PLAN_REQUIRED',\n 'TENANT_BILLING_PAUSED',\n] as const;\n","/**\n * Typed errors over the API's one error envelope: `{ error: { code, message,\n * details?, field_errors?, requestId?, ...extensions } }` (`src/errors/\n * index.ts` + `src/middlewares/error-handler.ts` in vitrina-app). `code` is\n * generated from the committed error catalogue (see `generated/error-codes.ts`\n * and `../scripts/generate-error-codes.ts`) but kept OPEN at the type level —\n * `ErrorCode | (string & Record<string, never>)` — because a server release\n * can ship a new code before this SDK is regenerated; never treat the union\n * as exhaustive at runtime (no `switch` without a `default`).\n */\nimport { ERROR_CODES, type ErrorCode } from './generated/error-codes';\n\nexport { ERROR_CODES };\nexport type { ErrorCode };\n\n/** `error.code`, widened so an unrecognised future code still type-checks.\n * The `Record<string, never>` intersection (not a bare `{}`) is what keeps\n * known `ErrorCode` literals showing up in autocomplete while still\n * accepting any string. */\nexport type OpenErrorCode = ErrorCode | (string & Record<string, never>);\n\n/** One entry of `error.details.reasons` on an outbound-policy verdict (C4). */\nexport interface OutboundVerdictReason {\n code: string;\n kind: 'bloqueo' | 'advertencia';\n hint: string;\n detail?: string;\n}\n\n/** The wire shape of `error` inside the envelope. */\nexport interface ApiErrorBody {\n code: OpenErrorCode;\n message: string;\n details?: unknown;\n field_errors?: Record<string, string>;\n requestId?: string;\n /** Send-verdict envelopes (C4) put `reasons`/`hint` at this level too. */\n reasons?: OutboundVerdictReason[];\n hint?: string;\n [key: string]: unknown;\n}\n\nexport interface ApiErrorOptions {\n requestUrl?: string;\n requestMethod?: string;\n}\n\n/** Base class for every error this SDK throws for a non-2xx API response. */\nexport class VitrinaApiError extends Error {\n /** The catalogue code — branch on this, never on `message`. */\n readonly code: OpenErrorCode;\n\n /** HTTP status of the response that produced this error. */\n readonly status: number;\n\n readonly details?: unknown;\n\n readonly fieldErrors?: Record<string, string>;\n\n /** Correlates this failure with the server's own logs. */\n readonly requestId?: string;\n\n /** The full parsed `error` object, for anything not surfaced above. */\n readonly body: ApiErrorBody;\n\n readonly requestUrl?: string;\n\n readonly requestMethod?: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(body.message || `Vitrina API error ${body.code} (HTTP ${status})`);\n this.name = 'VitrinaApiError';\n this.status = status;\n this.code = body.code;\n this.details = body.details;\n this.fieldErrors = body.field_errors;\n this.requestId = body.requestId;\n this.body = body;\n this.requestUrl = options.requestUrl;\n this.requestMethod = options.requestMethod;\n }\n\n /** `429 RATE_LIMITED`. */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** `401` — no credential, or one the server does not recognise. */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** `403` — a real credential, missing the scope this call needs. */\n get isForbidden(): boolean {\n return this.status === 403;\n }\n\n /** `404 NOT_FOUND`. */\n get isNotFound(): boolean {\n return this.status === 404;\n }\n\n /** `409 IDEMPOTENCY_KEY_CONFLICT` — same `Idempotency-Key`, different body. */\n get isIdempotencyConflict(): boolean {\n return this.code === 'IDEMPOTENCY_KEY_CONFLICT';\n }\n}\n\n/**\n * `422 OUTBOUND_BLOCKED` (a Bloqueo, never overridable) or `409\n * OUTBOUND_WARNING` (an Advertencia — resend the same call with\n * `acknowledge: reasons.map(r => r.code)` in the body to proceed). Cross-\n * ticket contract C4 — `src/services/api-send-verdicts.ts` in vitrina-app.\n */\nexport class OutboundVerdictError extends VitrinaApiError {\n /** Every reason the send was stopped for, with its kind and hint. */\n readonly reasons: OutboundVerdictReason[];\n\n /** The first reason's hint, surfaced at the top level like the wire body. */\n readonly hint: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(status, body, options);\n this.name = 'OutboundVerdictError';\n const detailsReasons = (\n body.details as { reasons?: OutboundVerdictReason[] } | undefined\n )?.reasons;\n this.reasons = body.reasons ?? detailsReasons ?? [];\n this.hint = body.hint ?? this.reasons[0]?.hint ?? '';\n }\n\n /** A Bloqueo — the law, the customer or the provider already said no. */\n get isBlocked(): boolean {\n return this.code === 'OUTBOUND_BLOCKED';\n }\n\n /** An Advertencia — resend once with `acknowledge` to proceed. */\n get isWarning(): boolean {\n return this.code === 'OUTBOUND_WARNING';\n }\n\n /** `reasons` codes, ready to pass back as `{ acknowledge: [...] }`. */\n get acknowledgeCodes(): string[] {\n return this.reasons.map((r) => r.code);\n }\n}\n\nfunction asErrorBody(payload: unknown, status: number): ApiErrorBody {\n if (payload && typeof payload === 'object') {\n const maybeEnvelope = payload as { error?: unknown };\n const candidate =\n maybeEnvelope.error && typeof maybeEnvelope.error === 'object'\n ? (maybeEnvelope.error as Record<string, unknown>)\n : (payload as Record<string, unknown>);\n if (\n typeof candidate.code === 'string' &&\n typeof candidate.message === 'string'\n ) {\n return candidate as unknown as ApiErrorBody;\n }\n }\n return {\n code: 'INTERNAL_ERROR',\n message: `HTTP ${status} with an unrecognised response body`,\n };\n}\n\n/** Turns a non-2xx response's status + parsed JSON body into a typed error. */\nexport function toApiError(\n status: number,\n payload: unknown,\n options: ApiErrorOptions = {},\n): VitrinaApiError {\n const body = asErrorBody(payload, status);\n if (body.code === 'OUTBOUND_BLOCKED' || body.code === 'OUTBOUND_WARNING') {\n return new OutboundVerdictError(status, body, options);\n }\n return new VitrinaApiError(status, body, options);\n}\n\n/** The subset of an `openapi-fetch` call's resolved value `unwrap` needs. */\nexport interface UnwrappableResult<T> {\n data?: T;\n error?: unknown;\n response: Response;\n}\n\n/**\n * `const location = unwrap(await api.GET('/locations/{id}', ...))` — throws\n * a typed `VitrinaApiError` (or `OutboundVerdictError`) instead of making\n * every call site check `error` by hand. `openapi-fetch` itself never\n * throws; reach for the raw `{ data, error }` result directly when you want\n * that instead.\n */\nexport function unwrap<T>(\n result: UnwrappableResult<T>,\n options: ApiErrorOptions = {},\n): T {\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error, options);\n }\n if (result.data === undefined) {\n throw new VitrinaApiError(\n result.response.status,\n {\n code: 'INTERNAL_ERROR',\n message: 'Response had neither data nor error',\n },\n options,\n );\n }\n return result.data;\n}\n","/**\n * Webhook Evento envelope + Stripe-style signature verification, matching\n * the dispatch service's own `signPayload`/`buildHeaders`\n * (`src/services/webhook-dispatch.service.ts` in vitrina-app; cross-ticket\n * contract C3). The signature is an HMAC-SHA256 over `${timestamp}.${body}`\n * with the subscription's `whsec_...` secret, carried as\n * `X-Webhook-Signature: t=<unix_seconds>,v1=<hex>`.\n *\n * `tests/api-sdk-webhook-signature.test.ts` (vitrina-app repo root) verifies\n * this against the REAL `signPayload` the dispatch service calls in\n * production — not a hand-written fixture.\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** `resource` on the envelope — what changed, and where to read it. */\nexport interface WebhookEventResource {\n type: string;\n id: string | null;\n /** Absolute `GET` URL for this resource, or `null` when none is available\n * (e.g. the event has no single owning record). Feeds `event.fetch()`. */\n url: string | null;\n}\n\n/** Who did it — see `Author` in vitrina-app's `src/types/author.ts` (C3). */\nexport interface WebhookEventAuthor {\n kind: 'member' | 'api_key' | 'ai_agent' | 'system' | 'contact';\n id: string | null;\n name: string | null;\n via?: { kind: 'connected_app' | 'personal_token'; name: string };\n}\n\n/** Why `data` is absent — every reason a subscription's owner can be denied\n * the resource body. `missing_scope:<scope>` is a family, not one literal. */\nexport type DataOmittedReason =\n | 'not_requested'\n | 'sensitive'\n | 'owner_unavailable'\n | 'restricted_visibility'\n | `missing_scope:${string}`;\n\n/** One Evento, exactly as it arrives on the wire. Exactly one of `data` /\n * `data_omitted` is ever present. */\nexport interface WebhookEventEnvelope<TData = Record<string, unknown>> {\n id: string;\n type: string;\n version: number;\n /** `false` for an event from a sandbox (test-mode) workspace, `true`\n * otherwise; mirrored on the delivery's `Vitrina-Livemode` header.\n * Optional here only so an envelope captured before vitrina-app#2693\n * still satisfies this type — every envelope on the wire carries it. */\n livemode?: boolean;\n created_at: string;\n tenant_id: string;\n resource: WebhookEventResource;\n changes?: Record<string, { from: unknown; to: unknown }>;\n author: WebhookEventAuthor;\n data?: TData;\n data_omitted?: DataOmittedReason;\n}\n\nexport interface VerifySignatureOptions {\n /** How far `X-Webhook-Timestamp` may drift from now before a signature\n * that otherwise matches is rejected as stale (replay protection).\n * Default 300 (5 minutes), matching the docs' own verifier. */\n toleranceSeconds?: number;\n /** Override \"now\", in Unix seconds — for tests. */\n nowUnix?: number;\n}\n\nexport type VerifyResult =\n | { ok: true }\n | { ok: false; reason: 'malformed_header' | 'bad_signature' | 'stale' };\n\nfunction parseSignatureHeader(\n header: string,\n): { timestamp: number; v1: string } | null {\n const parts: Record<string, string> = {};\n for (const pair of header.split(',')) {\n const at = pair.indexOf('=');\n if (at === -1) continue;\n parts[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();\n }\n const timestamp = Number(parts.t);\n if (!Number.isFinite(timestamp) || !parts.v1) return null;\n return { timestamp, v1: parts.v1 };\n}\n\n/**\n * Verifies an `X-Webhook-Signature` header against the raw delivery body.\n * Never throws — returns `{ ok: false, reason }` so a caller can log why a\n * delivery was rejected. `rawBody` must be the exact bytes the delivery\n * sent, before any JSON re-serialization (re-stringifying a parsed body\n * produces different bytes and the signature will never match).\n */\nexport function verifyWebhookSignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): VerifyResult {\n const parsed = parseSignatureHeader(params.signatureHeader);\n if (!parsed) return { ok: false, reason: 'malformed_header' };\n\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n const expected = createHmac('sha256', params.secret)\n .update(`${parsed.timestamp}.${body}`)\n .digest('hex');\n\n const given = Buffer.from(parsed.v1, 'utf8');\n const mine = Buffer.from(expected, 'utf8');\n const signatureMatches =\n given.length === mine.length && timingSafeEqual(given, mine);\n if (!signatureMatches) return { ok: false, reason: 'bad_signature' };\n\n const tolerance = params.toleranceSeconds ?? 300;\n const now = params.nowUnix ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - parsed.timestamp) > tolerance) {\n return { ok: false, reason: 'stale' };\n }\n return { ok: true };\n}\n\nexport class WebhookSignatureError extends Error {\n readonly reason: Exclude<VerifyResult, { ok: true }>['reason'];\n\n constructor(reason: Exclude<VerifyResult, { ok: true }>['reason']) {\n super(`Webhook signature verification failed: ${reason}`);\n this.name = 'WebhookSignatureError';\n this.reason = reason;\n }\n}\n\n/**\n * Verifies + parses an Evento delivery in one call (Stripe's\n * `constructEvent` naming, same idea): throws `WebhookSignatureError`\n * instead of returning a result a caller might forget to check before\n * trusting `rawBody`.\n */\nexport function constructEventEnvelope<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): WebhookEventEnvelope<TData> {\n const result = verifyWebhookSignature(params);\n if (!result.ok) throw new WebhookSignatureError(result.reason);\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n return JSON.parse(body) as WebhookEventEnvelope<TData>;\n}\n","/**\n * `event.fetch()` — read an Evento's resource in one call, using the same\n * credentials the client was created with. `resource.url` is the absolute\n * `GET` URL the server already computed (`apiPublicUrl()` in\n * `webhook-dispatch.service.ts`), so this is a plain authenticated fetch of\n * that URL — no per-resource-type routing table to keep in sync.\n */\nimport { toApiError } from './errors';\nimport {\n constructEventEnvelope,\n verifyWebhookSignature,\n type VerifySignatureOptions,\n type WebhookEventEnvelope,\n} from './webhooks';\n\nexport class EventResourceUnavailableError extends Error {\n readonly event: WebhookEventEnvelope;\n\n constructor(event: WebhookEventEnvelope) {\n super(\n event.data_omitted\n ? `Event ${event.id} (${event.type}) carries no resource URL — data_omitted: ${event.data_omitted}`\n : `Event ${event.id} (${event.type}) carries no resource URL`,\n );\n this.name = 'EventResourceUnavailableError';\n this.event = event;\n }\n}\n\n/** A parsed Evento, plus a `fetch()` bound to the client it came from. */\nexport type VitrinaEvent<TData = Record<string, unknown>> =\n WebhookEventEnvelope<TData> & {\n /**\n * `GET`s `resource.url` with this client's credentials and returns its\n * `data`. Throws `EventResourceUnavailableError` when the envelope has no\n * URL (an event with no single owning resource, or one whose `data` you\n * already have inline). Pass a type argument to get the resource typed:\n * `await event.fetch<Contact>()`.\n */\n fetch<TResource = TData>(): Promise<TResource>;\n };\n\nexport interface EventFetcherDeps {\n headers: HeadersInit;\n fetch: typeof fetch;\n}\n\n/** Builds the `events` namespace `createClient()` attaches to every client:\n * signature verification bound to nothing (pure functions), and\n * `constructEvent` bound to this client's own auth so the returned event's\n * `.fetch()` needs no arguments. */\nexport function createEventsNamespace(deps: EventFetcherDeps) {\n // `WebhookEventEnvelope<any>`: this helper only ever reads `resource` /\n // `data_omitted` / `id` / `type`, never `.data`, so it is deliberately\n // NOT generic over TData — a `WebhookEventEnvelope<TData>` for any TData\n // must be assignable here.\n async function fetchResource<TResource>(\n event: WebhookEventEnvelope<any>,\n ): Promise<TResource> {\n if (!event.resource.url) throw new EventResourceUnavailableError(event);\n const res = await deps.fetch(event.resource.url, { headers: deps.headers });\n let json: unknown;\n try {\n json = await res.json();\n } catch {\n json = undefined;\n }\n if (!res.ok) {\n throw toApiError(res.status, json, {\n requestUrl: event.resource.url,\n requestMethod: 'GET',\n });\n }\n return (json as { data: TResource })?.data;\n }\n\n return {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature: (\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ) => verifyWebhookSignature(params),\n\n /**\n * Verifies + parses a webhook delivery and returns it with a bound\n * `.fetch()`. Throws `WebhookSignatureError` on a bad/stale signature.\n *\n * const event = client.events.constructEvent({\n * secret: subscriptionSecret,\n * signatureHeader: req.headers['x-webhook-signature'],\n * rawBody: req.rawBody,\n * });\n * if (event.type === 'contact.created') {\n * const contact = await event.fetch<Contact>();\n * }\n */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData> {\n const envelope = constructEventEnvelope<TData>(params);\n return Object.assign(envelope, {\n fetch: <TResource = TData>() => fetchResource<TResource>(envelope),\n });\n },\n };\n}\n","/**\n * `createClient()` — a typed `openapi-fetch` client over the API pública\n * (`paths` generated from the committed `openapi.public.json`), plus the\n * `events` namespace (webhook signature verification + `event.fetch()`).\n *\n * Auth: pass an `sk_*` API key (workspace credential or personal token —\n * both are Bearer) or a raw bearer token you manage yourself. Exactly one of\n * `apiKey` / `bearer`.\n */\nimport createOpenApiClient, { type Client } from 'openapi-fetch';\n\nimport { createEventsNamespace, type VitrinaEvent } from './events';\nimport type { paths } from './generated/api-types';\nimport type { VerifySignatureOptions, VerifyResult } from './webhooks';\n\nexport interface CreateClientOptions {\n /** Absolute base URL, e.g. `https://api.vitrinadev.com/api/v1`. No trailing slash. */\n baseUrl: string;\n /** An `sk_*` API key (workspace key or personal token). Mutually exclusive with `bearer`. */\n apiKey?: string;\n /** A raw bearer token, for a caller that manages tokens itself (e.g. a Supabase session JWT). */\n bearer?: string;\n /** Extra headers merged onto every request (e.g. a custom `User-Agent`). */\n headers?: Record<string, string>;\n /** Override `fetch` — Node <18, undici, msw, a test double. Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n}\n\nexport interface VitrinaEventsNamespace {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VerifyResult;\n /** Verifies + parses a webhook delivery; the returned event carries a\n * `.fetch()` bound to this client. Throws `WebhookSignatureError`. */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData>;\n}\n\n/** The typed REST client (`GET`/`POST`/.../`use`/`eject`, from `openapi-fetch`)\n * plus the `events` namespace. */\nexport type VitrinaClient = Client<paths> & { events: VitrinaEventsNamespace };\n\nexport function createClient(opts: CreateClientOptions): VitrinaClient {\n if (opts.apiKey && opts.bearer) {\n throw new RangeError(\n 'createClient(): pass at most one of `apiKey` / `bearer`, not both',\n );\n }\n const credential = opts.apiKey ?? opts.bearer;\n const headers: Record<string, string> = {\n ...(credential ? { Authorization: `Bearer ${credential}` } : {}),\n ...opts.headers,\n };\n const fetchImpl = opts.fetch ?? fetch;\n\n const base = createOpenApiClient<paths>({\n baseUrl: opts.baseUrl,\n headers,\n fetch: fetchImpl,\n });\n\n const events = createEventsNamespace({ headers, fetch: fetchImpl });\n\n return Object.assign(base, { events });\n}\n","/**\n * Cursor pagination — walks a list endpoint page by page, yielding one item\n * at a time (`for await`). Vitrina's list envelopes carry the cursor as\n * `meta.pagination.nextCursor` (the shape every v1 list route in production\n * answers with — `ok(res, rows, { pagination: { nextCursor, limit } })`,\n * `src/routes/api/v1/*.ts`) with a `meta.nextCursor` fallback for the flat\n * `PaginationMeta` OpenAPI shape (`src/api/openapi-responses.ts`) some\n * generated docs describe; this helper reads either. The opaque cursor\n * itself is a base64url-encoded `{ ts, id }` pair (`src/api/pagination.ts`)\n * — never decode it, just pass it back as the next page's `cursor` query\n * param.\n */\nimport { toApiError } from './errors';\n\nexport interface PaginationMeta {\n pagination?: {\n nextCursor?: string | null;\n prevCursor?: string | null;\n limit?: number;\n };\n nextCursor?: string | null;\n prevCursor?: string | null;\n total?: number;\n limit?: number;\n [key: string]: unknown;\n}\n\nexport interface ListEnvelope<T> {\n data?: T[];\n meta?: PaginationMeta;\n}\n\n/** The subset of an `openapi-fetch` GET call's resolved value `paginate` needs. */\nexport interface FetchPageResult<T> {\n data?: ListEnvelope<T>;\n error?: unknown;\n response: Response;\n}\n\nfunction nextCursorOf(meta: PaginationMeta | undefined): string | undefined {\n const cursor = meta?.pagination?.nextCursor ?? meta?.nextCursor ?? null;\n return cursor ?? undefined;\n}\n\n/**\n * Walks every page of a cursor-paginated list, yielding one item at a time.\n *\n * for await (const appointment of paginate((cursor) =>\n * api.GET('/appointments', { params: { query: { cursor, limit: 100 } } }),\n * )) {\n * console.log(appointment.id);\n * }\n *\n * CURSOR IS THE MINORITY SHAPE, so check the route before reaching for this.\n * Measured against the published contract: exactly two operations take a\n * `cursor` — `GET /appointments` and `GET /conversations/{id}/messages`.\n * Fifteen take `offset`/`limit` (`/stock`, `/vehicles`, `/contacts/search`,\n * `/webhooks/{id}/deliveries` and the rest), and others take `page`/`page_size`\n * (`/leads` among them). Passing `cursor` to one of those is a type error, not\n * a silent first page — which is the point of generating this package from the\n * contract.\n *\n * `fetchPage` is any typed `api.GET(...)` call, called once per page with\n * the previous page's cursor (`undefined` for the first page). Throws a\n * typed `VitrinaApiError` if a page comes back as an error, same as\n * `unwrap()`.\n */\nexport async function* paginate<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): AsyncGenerator<T, void, unknown> {\n let cursor: string | undefined;\n for (;;) {\n // eslint-disable-next-line no-await-in-loop -- pages are inherently sequential (each cursor depends on the last)\n const result = await fetchPage(cursor);\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error);\n }\n const page = result.data;\n if (!page || !Array.isArray(page.data)) return;\n for (const item of page.data) yield item;\n const next = nextCursorOf(page.meta);\n if (!next) return;\n cursor = next;\n }\n}\n\n/** Same as `paginate`, but collects every page into one array. Only reach\n * for this on a list you know is bounded — an unbounded one belongs on the\n * `for await` form above. */\nexport async function paginateAll<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): Promise<T[]> {\n const items: T[] = [];\n // eslint-disable-next-line no-restricted-syntax -- collecting an async generator IS the sequential-await case for-await exists for\n for await (const item of paginate(fetchPage)) items.push(item);\n return items;\n}\n","/**\n * `Idempotency-Key` — replay-safe retries on the 39 published write\n * operations that accept it (ADR 0106 §2.3/#2400). Resending the SAME key\n * with the SAME body returns the original response (`X-Idempotent-Replay:\n * 1`) instead of creating a second copy; the same key with a DIFFERENT body\n * answers `409 IDEMPOTENCY_KEY_CONFLICT` (`VitrinaApiError#isIdempotencyConflict`).\n *\n * The generated types already carry `Idempotency-Key` as a typed header\n * parameter per operation — `idempotencyKey()` just builds a well-formed\n * value to put there:\n *\n * await api.POST('/pipelines', {\n * params: { header: idempotencyKey(`provision-${userId}-2026-04-24`) },\n * body: { ... },\n * });\n */\nimport { randomUUID } from 'node:crypto';\n\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{8,200}$/;\n\nexport interface IdempotencyKeyHeader {\n 'Idempotency-Key': string;\n}\n\n/**\n * Validates `key` against the server's own constraint (`minLength: 8,\n * maxLength: 200, pattern: ^[A-Za-z0-9_-]+$` on every operation that accepts\n * it) and returns it as a header object to spread into `params.header`.\n * Throws `RangeError` on a malformed key — better to fail before the\n * request leaves than to get back a generic `VALIDATION_ERROR`.\n */\nexport function idempotencyKey(key: string): IdempotencyKeyHeader {\n if (!KEY_PATTERN.test(key)) {\n throw new RangeError(\n `Idempotency-Key must be 8-200 characters of [A-Za-z0-9_-], got: ${JSON.stringify(key)}`,\n );\n }\n return { 'Idempotency-Key': key };\n}\n\n/**\n * A fresh, valid `Idempotency-Key`. Mint ONE per logical operation and reuse\n * it across THAT operation's retries — generating a new key per attempt\n * defeats the point (each attempt would look like a different write). `\n * prefix` is optional and purely for your own log-grepping; it plays no\n * role on the server.\n */\nexport function generateIdempotencyKey(prefix?: string): string {\n const id = randomUUID().replace(/-/g, '');\n return prefix ? `${prefix}-${id}` : id;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -17420,6 +17420,8 @@ interface paths {
17420
17420
  *
17421
17421
  * **Publish in the same call (`publish_to`).** Optional. Name the marketplaces this vehicle should go to — portal slugs such as `chileautos` / `mercadolibre`, or integration ids from GET /marketplaces — and it is published right after it is saved, through the same path as POST /vehicles/{id}/publish. Omitted or `[]` saves only; there is no default. Every entry is validated first: a portal with no connected account, a slug matching several accounts, or an id from another workspace answers **422 and nothing is saved**. Once saved, the vehicle stays saved: a portal that fails to publish is an `error` entry in `publications`, never a failed request (still 201). The response then carries `publications`, one `PublishOutcome` per account (`published`, `pending` for queued transports such as `chileautos_panel` and Facebook Marketplace, `already_published`, or `error` with the reason). `publications` is absent when `publish_to` was not sent.
17422
17422
  *
17423
+ * **Sanity range.** A price fans out to every connected portal, so a typo is stopped here. `price_amount` must be between 100.000 and 2.000.000.000 CLP (a UF price is bounded at the day's UF; other currencies are not bounded) and `odometer_value` between 0 and 2.000.000; `null` clears either and is always accepted. Outside the range: **422 `VEHICLE_VALUE_OUT_OF_RANGE`**, with a Spanish `message`, `field_errors.<field>` and `details.violations[]` (`field`, `reason` = `price_out_of_range` | `km_out_of_range`, `value`, `min`, `max`, `currency`). A price change beyond 10x up or down from the current price answers **422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`** (`details.reason` = `large_price_change`, `current_price`, `requested_price`, `currency`, `factor`, `confirm_flag`) unless the body carries `confirm_large_price_change: true`; ask the user, then resend the same body with it. Nothing is written on either 422.
17424
+ *
17423
17425
  * **Normalization and `catalog_match`.** On create and update, `make` and `model` that equal an entry of GET /vehicles/catalog/brands and /catalog/models up to case, accents, spaces and hyphens are stored in the catalog's spelling ("toyota" → "Toyota", "mercedes benz" → "Mercedes-Benz", "rav 4" → "RAV4"); `fuel_type`, `gear_type` and `body_style` are stored as vocabulary codes ("Bencina" → `gasolina`, "Automática" → `automatica`, "Station Wagon" → `wagon`; codes: fuel `gasolina|diesel|hibrido|electrico|gnc|glp|otro`, gear `mecanica|automatica|otro`, body `sedan|hatchback|suv|camioneta|coupe|wagon|furgon|convertible|minivan|otro`). Nothing is invented: a value with no match is stored exactly as sent. The response (and GET /vehicles/{id}) carries `catalog_match`: `make` / `model` are `matched` | `unmatched` | `missing` (`not_applicable` for a non-`auto` vehicle_type); `version` adds `approximate` (word overlap with a catalog version, same displacement) and `catalog_version` names the catalog version it matched or most resembles; `fuel_type` / `gear_type` / `body_style` are `matched` | `unmatched` | `missing`; `warnings[]` lists `{ field, code, message }` for everything not matched, with a Spanish `message` ready to show (codes: `make_missing`, `make_not_in_catalog`, `model_missing`, `model_not_in_catalog`, `version_approximate`, `version_not_in_catalog`, `fuel_type_not_recognized`, `gear_type_not_recognized`, `body_style_not_recognized`). A make or model that is not matched still saves, but Chileautos publishes it without a technical sheet (ficha). `catalog_match` is null only when the catalog could not be loaded. Example of an unmatched push: {"make":"matched","model":"unmatched","version":"unmatched","catalog_version":null,"fuel_type":"unmatched","gear_type":"matched","body_style":"missing","warnings":[{"field":"model","code":"model_not_in_catalog","message":"Modelo 'Rav-4 xx' no está en el catálogo de Toyota (GET /vehicles/catalog/models); Chileautos lo publicará sin ficha."},{"field":"fuel_type","code":"fuel_type_not_recognized","message":"Combustible 'Hidrógeno' no se reconoce; valores aceptados: gasolina, diesel, hibrido, electrico, gnc, glp, otro."}]}
17424
17426
  */
17425
17427
  post: {
@@ -17738,6 +17740,15 @@ interface paths {
17738
17740
  "application/json": components["schemas"]["Error"];
17739
17741
  };
17740
17742
  };
17743
+ /** @description `VEHICLE_VALUE_OUT_OF_RANGE` (price or km outside the sanity range) or `PRICE_CHANGE_CONFIRMATION_REQUIRED` (a price change beyond 10x sent without `confirm_large_price_change: true`). Nothing is written. */
17744
+ 422: {
17745
+ headers: {
17746
+ [name: string]: unknown;
17747
+ };
17748
+ content: {
17749
+ "application/json": components["schemas"]["Error"];
17750
+ };
17751
+ };
17741
17752
  /** @description Rate limited */
17742
17753
  429: {
17743
17754
  headers: {
@@ -18076,6 +18087,8 @@ interface paths {
18076
18087
  *
18077
18088
  * **`publish_to` only ADDS portals.** Same contract as on POST /vehicles (validated before the edit is written; 422 writes nothing; a portal failure is an `error` entry in `publications`, never a failed request). A portal where the vehicle is already live or has a queued publish is a no-op (`already_published`) — never a second ad, so an ERP may safely retry. A portal LEFT OUT of `publish_to` is NOT unpublished: removal is DELETE /vehicles/{id}/publications/{pubId}. A body with only `publish_to` publishes without editing the vehicle.
18078
18089
  *
18090
+ * **Sanity range.** A price fans out to every connected portal, so a typo is stopped here. `price_amount` must be between 100.000 and 2.000.000.000 CLP (a UF price is bounded at the day's UF; other currencies are not bounded) and `odometer_value` between 0 and 2.000.000; `null` clears either and is always accepted. Outside the range: **422 `VEHICLE_VALUE_OUT_OF_RANGE`**, with a Spanish `message`, `field_errors.<field>` and `details.violations[]` (`field`, `reason` = `price_out_of_range` | `km_out_of_range`, `value`, `min`, `max`, `currency`). A price change beyond 10x up or down from the current price answers **422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`** (`details.reason` = `large_price_change`, `current_price`, `requested_price`, `currency`, `factor`, `confirm_flag`) unless the body carries `confirm_large_price_change: true`; ask the user, then resend the same body with it. Nothing is written on either 422.
18091
+ *
18079
18092
  * **Normalization and `catalog_match`.** On create and update, `make` and `model` that equal an entry of GET /vehicles/catalog/brands and /catalog/models up to case, accents, spaces and hyphens are stored in the catalog's spelling ("toyota" → "Toyota", "mercedes benz" → "Mercedes-Benz", "rav 4" → "RAV4"); `fuel_type`, `gear_type` and `body_style` are stored as vocabulary codes ("Bencina" → `gasolina`, "Automática" → `automatica`, "Station Wagon" → `wagon`; codes: fuel `gasolina|diesel|hibrido|electrico|gnc|glp|otro`, gear `mecanica|automatica|otro`, body `sedan|hatchback|suv|camioneta|coupe|wagon|furgon|convertible|minivan|otro`). Nothing is invented: a value with no match is stored exactly as sent. The response (and GET /vehicles/{id}) carries `catalog_match`: `make` / `model` are `matched` | `unmatched` | `missing` (`not_applicable` for a non-`auto` vehicle_type); `version` adds `approximate` (word overlap with a catalog version, same displacement) and `catalog_version` names the catalog version it matched or most resembles; `fuel_type` / `gear_type` / `body_style` are `matched` | `unmatched` | `missing`; `warnings[]` lists `{ field, code, message }` for everything not matched, with a Spanish `message` ready to show (codes: `make_missing`, `make_not_in_catalog`, `model_missing`, `model_not_in_catalog`, `version_approximate`, `version_not_in_catalog`, `fuel_type_not_recognized`, `gear_type_not_recognized`, `body_style_not_recognized`). A make or model that is not matched still saves, but Chileautos publishes it without a technical sheet (ficha). `catalog_match` is null only when the catalog could not be loaded. Example of an unmatched push: {"make":"matched","model":"unmatched","version":"unmatched","catalog_version":null,"fuel_type":"unmatched","gear_type":"matched","body_style":"missing","warnings":[{"field":"model","code":"model_not_in_catalog","message":"Modelo 'Rav-4 xx' no está en el catálogo de Toyota (GET /vehicles/catalog/models); Chileautos lo publicará sin ficha."},{"field":"fuel_type","code":"fuel_type_not_recognized","message":"Combustible 'Hidrógeno' no se reconoce; valores aceptados: gasolina, diesel, hibrido, electrico, gnc, glp, otro."}]}
18080
18093
  */
18081
18094
  put: {
@@ -18155,6 +18168,8 @@ interface paths {
18155
18168
  * ]
18156
18169
  */
18157
18170
  publish_to?: string[];
18171
+ /** @description Confirms a price change beyond 10x up or down from the current price. Without it such an edit answers 422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`; resend the same body with `true` once the user confirmed. Not stored. */
18172
+ confirm_large_price_change?: boolean;
18158
18173
  };
18159
18174
  };
18160
18175
  };
@@ -18312,6 +18327,15 @@ interface paths {
18312
18327
  "application/json": components["schemas"]["Error"];
18313
18328
  };
18314
18329
  };
18330
+ /** @description `VEHICLE_VALUE_OUT_OF_RANGE` (price or km outside the sanity range) or `PRICE_CHANGE_CONFIRMATION_REQUIRED` (a price change beyond 10x sent without `confirm_large_price_change: true`). Nothing is written. */
18331
+ 422: {
18332
+ headers: {
18333
+ [name: string]: unknown;
18334
+ };
18335
+ content: {
18336
+ "application/json": components["schemas"]["Error"];
18337
+ };
18338
+ };
18315
18339
  /** @description Rate limited */
18316
18340
  429: {
18317
18341
  headers: {
@@ -18804,7 +18828,7 @@ interface paths {
18804
18828
  };
18805
18829
  /**
18806
18830
  * A vehicle's change history (Historial)
18807
- * @description Reverse-chronological audit trail for this vehicle — created, field edits (with a before→after diff), publish/unpublish/cierre, and Override local protect/release — with teammate actors resolved to display names. It also carries the deal's milestones, read from each document's own audit rows: nota de compra emitted/voided (`purchase_note_issued`, `purchase_note_voided`), nota de venta emitted/approved/voided (`sale_note_issued`, `sale_note_approved`, `sale_note_voided`), contrato de compraventa first printed (`compraventa_printed`), mandato de consignación first printed (`mandato_issued`), a signed copy filed (`signed_copy_filed`, with `metadata.signed_document_type`) and the liquidación paid to the consignor (`liquidacion_paid`). `metadata.folio` names the document when it has one. Each document type appears only for a caller holding its read scope (`purchase_notes:read`, `sale_notes:read`, `consignments:read`; signed copies also need `vehicle_registry:read`). A download of the Resumen del negocio is `deal_settlement_downloaded`. The car's papers (ADR 0114 §7 — permiso de circulación, revisión técnica, SOAP, padrón, CAV, any named paper) appear as `paper_added` (a file filed; `metadata.replaced_attachment_id` when it replaced one), `paper_updated` (renamed or its «Vence» day set, `metadata.changed`) and `paper_removed`, each with `metadata.kind`, `metadata.label` and `metadata.expires_on` — only for a caller holding `vehicle_registry:read`. The UI merges it with /activity (leads) into one "Leads y cambios" timeline.
18831
+ * @description Reverse-chronological audit trail for this vehicle — created, field edits (with a before→after diff), publish/unpublish/cierre, and Override local protect/release — with teammate actors resolved to display names. It also carries the deal's milestones, read from each document's own audit rows: nota de compra emitted/voided (`purchase_note_issued`, `purchase_note_voided`), nota de venta emitted/approved/voided (`sale_note_issued`, `sale_note_approved`, `sale_note_voided`), contrato de compraventa first printed (`compraventa_printed`), mandato de consignación first printed (`mandato_issued`), a signed copy filed (`signed_copy_filed`, with `metadata.signed_document_type`) and the liquidación paid to the consignor (`liquidacion_paid`). `metadata.folio` names the document when it has one. Each document type appears only for a caller holding its read scope (`purchase_notes:read`, `sale_notes:read`, `consignments:read`; signed copies also need `vehicle_registry:read`). A download of the Resumen del negocio is `deal_settlement_downloaded`. The car's papers (ADR 0114 §7 — permiso de circulación, revisión técnica, SOAP, padrón, CAV, any named paper) appear as `paper_added` (a file filed; `metadata.replaced_attachment_id` when it replaced one), `paper_updated` (renamed or its «Vence» day set, `metadata.changed`) and `paper_removed`, each with `metadata.kind`, `metadata.label` and `metadata.expires_on` — only for a caller holding `vehicle_registry:read`. A value changed directly on a connected system (price, km; Veekls also year and version) and taken into Vitrina is `portal_edit` (system actor, `changes`, `metadata.provider`, `metadata.portal`, `metadata.summary`); a portal value that was not taken in is `portal_edit_ignored` (`metadata.summary`; `metadata.ignored`: field, portal_value, kept_value, reason = `pending_vitrina_edit` when it lost to a Vitrina edit still waiting to be pushed, `out_of_range` when it fell outside the price/km sanity range). The UI merges it with /activity (leads) into one "Leads y cambios" timeline.
18808
18832
  */
18809
18833
  get: {
18810
18834
  parameters: {
@@ -122842,7 +122866,7 @@ interface paths {
122842
122866
  };
122843
122867
  /**
122844
122868
  * List a conversation's Continuaciones por WhatsApp
122845
- * @description The Continuaciones started from this conversation, newest first (one per phone number). Read `state` to draw the inbox button: `pending`, `deferred` (waiting for an approved template, until `send_deadline_at`), `sent`, `failed` or `skipped` (`reason` says why). Empty when none was started. A conversation the caller cannot see is a `404`.
122869
+ * @description The Continuaciones started from this conversation, newest first (one per phone number). Read `state` to draw the inbox button: `pending`, `deferred` (waiting for an approved template, until `send_deadline_at`), `sent`, `failed` or `skipped` (`reason` says why). Empty when none was started. `meta.whatsapp_line` is `true` when the workspace has an enabled WhatsApp line a Continuación could use (the same lookup the send runs), so a caller without `messaging_accounts:read` can still decide whether to offer the button. A conversation the caller cannot see is a `404`.
122846
122870
  */
122847
122871
  get: {
122848
122872
  parameters: {
@@ -122880,7 +122904,8 @@ interface paths {
122880
122904
  * }
122881
122905
  * ],
122882
122906
  * "meta": {
122883
- * "total": 1
122907
+ * "total": 1,
122908
+ * "whatsapp_line": true
122884
122909
  * }
122885
122910
  * }
122886
122911
  */
@@ -194299,7 +194324,7 @@ declare function createClient(opts: CreateClientOptions): VitrinaClient;
194299
194324
  * is regenerated — narrow on the ones you handle, never assume this
194300
194325
  * list is exhaustive at runtime.
194301
194326
  */
194302
- type ErrorCode = 'VALIDATION_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'CONFLICT' | 'ACCOUNT_DELETION_BLOCKED' | 'CONFIRMATION_REQUIRED' | 'VERSION_CONFLICT' | 'UNIQUE_CONFLICT' | 'IDEMPOTENCY_KEY_CONFLICT' | 'VERTICAL_NOT_ENABLED' | 'ENTITLEMENT_NOT_ACTIVE' | 'UNSUPPORTED_VEHICLE_TYPE' | 'NO_OFFERING_ADAPTER' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'GONE' | 'INTERNAL_ERROR' | 'MESSAGING_ACCOUNT_TENANT_MISSING' | 'COPILOT_APPROVALS_UNAVAILABLE' | 'COPILOT_APPROVAL_REPLAY_BLOCKED' | 'COPILOT_DISABLED' | 'COPILOT_BUDGET_EXCEEDED' | 'DEALER_SITES_NOT_CONFIGURED' | 'STOREFRONT_ZONES_NOT_CONFIGURED' | 'RECONTACTO_NOT_ENABLED' | 'SYNC_QUEUE_UNAVAILABLE' | 'SHARE_IMAGE_UNAVAILABLE' | 'AUDIO_RENDITION_PENDING' | 'ATTRIBUTION_PROFILE_UNAVAILABLE' | 'DOCUMENT_LOGO_UNAVAILABLE' | 'ATTRIBUTION_PROFILE_MISMATCH' | 'ADS_KEY_NEEDS_REMINT' | 'ADS_ACTION_READ_UNAVAILABLE' | 'ADS_ACTION_REPLAY_BLOCKED' | 'ADS_ACTION_NOT_AVAILABLE' | 'ADS_ACTION_NOT_REVERSIBLE' | 'ADS_ACTION_CONSENT_REQUIRED' | 'GTM_NOT_CONFIGURED' | 'GTM_NOT_CONNECTED' | 'GTM_CONSENT_REQUIRED' | 'GTM_PERMISSION_DENIED' | 'GTM_CONTAINER_REQUIRED' | 'GTM_PENDING_CHANGES' | 'GTM_WORKSPACE_CONFLICT' | 'GTM_WORKSPACE_LIMIT' | 'MISSING_SIGNATURE' | 'MALFORMED_SIGNATURE' | 'STALE_SIGNATURE' | 'INVALID_SIGNATURE' | 'REPLAY_DETECTED' | 'TURNSTILE_UNAVAILABLE' | 'TASADOR_QUOTA_EXHAUSTED' | 'TASADOR_ANON_DAILY_LIMIT' | 'TASADOR_CAPACITY_REACHED' | 'CLINIC_PLAN_REQUIRED' | 'TENANT_BILLING_PAUSED';
194327
+ type ErrorCode = 'VALIDATION_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'CONFLICT' | 'ACCOUNT_DELETION_BLOCKED' | 'CONFIRMATION_REQUIRED' | 'VERSION_CONFLICT' | 'UNIQUE_CONFLICT' | 'IDEMPOTENCY_KEY_CONFLICT' | 'VERTICAL_NOT_ENABLED' | 'ENTITLEMENT_NOT_ACTIVE' | 'UNSUPPORTED_VEHICLE_TYPE' | 'VEHICLE_VALUE_OUT_OF_RANGE' | 'PRICE_CHANGE_CONFIRMATION_REQUIRED' | 'NO_OFFERING_ADAPTER' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'GONE' | 'INTERNAL_ERROR' | 'MESSAGING_ACCOUNT_TENANT_MISSING' | 'COPILOT_APPROVALS_UNAVAILABLE' | 'COPILOT_APPROVAL_REPLAY_BLOCKED' | 'COPILOT_DISABLED' | 'COPILOT_BUDGET_EXCEEDED' | 'DEALER_SITES_NOT_CONFIGURED' | 'STOREFRONT_ZONES_NOT_CONFIGURED' | 'RECONTACTO_NOT_ENABLED' | 'SYNC_QUEUE_UNAVAILABLE' | 'SHARE_IMAGE_UNAVAILABLE' | 'AUDIO_RENDITION_PENDING' | 'ATTRIBUTION_PROFILE_UNAVAILABLE' | 'DOCUMENT_LOGO_UNAVAILABLE' | 'ATTRIBUTION_PROFILE_MISMATCH' | 'ADS_KEY_NEEDS_REMINT' | 'ADS_ACTION_READ_UNAVAILABLE' | 'ADS_ACTION_REPLAY_BLOCKED' | 'ADS_ACTION_NOT_AVAILABLE' | 'ADS_ACTION_NOT_REVERSIBLE' | 'ADS_ACTION_CONSENT_REQUIRED' | 'GTM_NOT_CONFIGURED' | 'GTM_NOT_CONNECTED' | 'GTM_CONSENT_REQUIRED' | 'GTM_PERMISSION_DENIED' | 'GTM_CONTAINER_REQUIRED' | 'GTM_PENDING_CHANGES' | 'GTM_WORKSPACE_CONFLICT' | 'GTM_WORKSPACE_LIMIT' | 'MISSING_SIGNATURE' | 'MALFORMED_SIGNATURE' | 'STALE_SIGNATURE' | 'INVALID_SIGNATURE' | 'REPLAY_DETECTED' | 'TURNSTILE_UNAVAILABLE' | 'TASADOR_QUOTA_EXHAUSTED' | 'TASADOR_ANON_DAILY_LIMIT' | 'TASADOR_CAPACITY_REACHED' | 'CLINIC_PLAN_REQUIRED' | 'TENANT_BILLING_PAUSED';
194303
194328
  declare const ERROR_CODES: readonly ErrorCode[];
194304
194329
 
194305
194330
  /**
package/dist/index.d.ts CHANGED
@@ -17420,6 +17420,8 @@ interface paths {
17420
17420
  *
17421
17421
  * **Publish in the same call (`publish_to`).** Optional. Name the marketplaces this vehicle should go to — portal slugs such as `chileautos` / `mercadolibre`, or integration ids from GET /marketplaces — and it is published right after it is saved, through the same path as POST /vehicles/{id}/publish. Omitted or `[]` saves only; there is no default. Every entry is validated first: a portal with no connected account, a slug matching several accounts, or an id from another workspace answers **422 and nothing is saved**. Once saved, the vehicle stays saved: a portal that fails to publish is an `error` entry in `publications`, never a failed request (still 201). The response then carries `publications`, one `PublishOutcome` per account (`published`, `pending` for queued transports such as `chileautos_panel` and Facebook Marketplace, `already_published`, or `error` with the reason). `publications` is absent when `publish_to` was not sent.
17422
17422
  *
17423
+ * **Sanity range.** A price fans out to every connected portal, so a typo is stopped here. `price_amount` must be between 100.000 and 2.000.000.000 CLP (a UF price is bounded at the day's UF; other currencies are not bounded) and `odometer_value` between 0 and 2.000.000; `null` clears either and is always accepted. Outside the range: **422 `VEHICLE_VALUE_OUT_OF_RANGE`**, with a Spanish `message`, `field_errors.<field>` and `details.violations[]` (`field`, `reason` = `price_out_of_range` | `km_out_of_range`, `value`, `min`, `max`, `currency`). A price change beyond 10x up or down from the current price answers **422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`** (`details.reason` = `large_price_change`, `current_price`, `requested_price`, `currency`, `factor`, `confirm_flag`) unless the body carries `confirm_large_price_change: true`; ask the user, then resend the same body with it. Nothing is written on either 422.
17424
+ *
17423
17425
  * **Normalization and `catalog_match`.** On create and update, `make` and `model` that equal an entry of GET /vehicles/catalog/brands and /catalog/models up to case, accents, spaces and hyphens are stored in the catalog's spelling ("toyota" → "Toyota", "mercedes benz" → "Mercedes-Benz", "rav 4" → "RAV4"); `fuel_type`, `gear_type` and `body_style` are stored as vocabulary codes ("Bencina" → `gasolina`, "Automática" → `automatica`, "Station Wagon" → `wagon`; codes: fuel `gasolina|diesel|hibrido|electrico|gnc|glp|otro`, gear `mecanica|automatica|otro`, body `sedan|hatchback|suv|camioneta|coupe|wagon|furgon|convertible|minivan|otro`). Nothing is invented: a value with no match is stored exactly as sent. The response (and GET /vehicles/{id}) carries `catalog_match`: `make` / `model` are `matched` | `unmatched` | `missing` (`not_applicable` for a non-`auto` vehicle_type); `version` adds `approximate` (word overlap with a catalog version, same displacement) and `catalog_version` names the catalog version it matched or most resembles; `fuel_type` / `gear_type` / `body_style` are `matched` | `unmatched` | `missing`; `warnings[]` lists `{ field, code, message }` for everything not matched, with a Spanish `message` ready to show (codes: `make_missing`, `make_not_in_catalog`, `model_missing`, `model_not_in_catalog`, `version_approximate`, `version_not_in_catalog`, `fuel_type_not_recognized`, `gear_type_not_recognized`, `body_style_not_recognized`). A make or model that is not matched still saves, but Chileautos publishes it without a technical sheet (ficha). `catalog_match` is null only when the catalog could not be loaded. Example of an unmatched push: {"make":"matched","model":"unmatched","version":"unmatched","catalog_version":null,"fuel_type":"unmatched","gear_type":"matched","body_style":"missing","warnings":[{"field":"model","code":"model_not_in_catalog","message":"Modelo 'Rav-4 xx' no está en el catálogo de Toyota (GET /vehicles/catalog/models); Chileautos lo publicará sin ficha."},{"field":"fuel_type","code":"fuel_type_not_recognized","message":"Combustible 'Hidrógeno' no se reconoce; valores aceptados: gasolina, diesel, hibrido, electrico, gnc, glp, otro."}]}
17424
17426
  */
17425
17427
  post: {
@@ -17738,6 +17740,15 @@ interface paths {
17738
17740
  "application/json": components["schemas"]["Error"];
17739
17741
  };
17740
17742
  };
17743
+ /** @description `VEHICLE_VALUE_OUT_OF_RANGE` (price or km outside the sanity range) or `PRICE_CHANGE_CONFIRMATION_REQUIRED` (a price change beyond 10x sent without `confirm_large_price_change: true`). Nothing is written. */
17744
+ 422: {
17745
+ headers: {
17746
+ [name: string]: unknown;
17747
+ };
17748
+ content: {
17749
+ "application/json": components["schemas"]["Error"];
17750
+ };
17751
+ };
17741
17752
  /** @description Rate limited */
17742
17753
  429: {
17743
17754
  headers: {
@@ -18076,6 +18087,8 @@ interface paths {
18076
18087
  *
18077
18088
  * **`publish_to` only ADDS portals.** Same contract as on POST /vehicles (validated before the edit is written; 422 writes nothing; a portal failure is an `error` entry in `publications`, never a failed request). A portal where the vehicle is already live or has a queued publish is a no-op (`already_published`) — never a second ad, so an ERP may safely retry. A portal LEFT OUT of `publish_to` is NOT unpublished: removal is DELETE /vehicles/{id}/publications/{pubId}. A body with only `publish_to` publishes without editing the vehicle.
18078
18089
  *
18090
+ * **Sanity range.** A price fans out to every connected portal, so a typo is stopped here. `price_amount` must be between 100.000 and 2.000.000.000 CLP (a UF price is bounded at the day's UF; other currencies are not bounded) and `odometer_value` between 0 and 2.000.000; `null` clears either and is always accepted. Outside the range: **422 `VEHICLE_VALUE_OUT_OF_RANGE`**, with a Spanish `message`, `field_errors.<field>` and `details.violations[]` (`field`, `reason` = `price_out_of_range` | `km_out_of_range`, `value`, `min`, `max`, `currency`). A price change beyond 10x up or down from the current price answers **422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`** (`details.reason` = `large_price_change`, `current_price`, `requested_price`, `currency`, `factor`, `confirm_flag`) unless the body carries `confirm_large_price_change: true`; ask the user, then resend the same body with it. Nothing is written on either 422.
18091
+ *
18079
18092
  * **Normalization and `catalog_match`.** On create and update, `make` and `model` that equal an entry of GET /vehicles/catalog/brands and /catalog/models up to case, accents, spaces and hyphens are stored in the catalog's spelling ("toyota" → "Toyota", "mercedes benz" → "Mercedes-Benz", "rav 4" → "RAV4"); `fuel_type`, `gear_type` and `body_style` are stored as vocabulary codes ("Bencina" → `gasolina`, "Automática" → `automatica`, "Station Wagon" → `wagon`; codes: fuel `gasolina|diesel|hibrido|electrico|gnc|glp|otro`, gear `mecanica|automatica|otro`, body `sedan|hatchback|suv|camioneta|coupe|wagon|furgon|convertible|minivan|otro`). Nothing is invented: a value with no match is stored exactly as sent. The response (and GET /vehicles/{id}) carries `catalog_match`: `make` / `model` are `matched` | `unmatched` | `missing` (`not_applicable` for a non-`auto` vehicle_type); `version` adds `approximate` (word overlap with a catalog version, same displacement) and `catalog_version` names the catalog version it matched or most resembles; `fuel_type` / `gear_type` / `body_style` are `matched` | `unmatched` | `missing`; `warnings[]` lists `{ field, code, message }` for everything not matched, with a Spanish `message` ready to show (codes: `make_missing`, `make_not_in_catalog`, `model_missing`, `model_not_in_catalog`, `version_approximate`, `version_not_in_catalog`, `fuel_type_not_recognized`, `gear_type_not_recognized`, `body_style_not_recognized`). A make or model that is not matched still saves, but Chileautos publishes it without a technical sheet (ficha). `catalog_match` is null only when the catalog could not be loaded. Example of an unmatched push: {"make":"matched","model":"unmatched","version":"unmatched","catalog_version":null,"fuel_type":"unmatched","gear_type":"matched","body_style":"missing","warnings":[{"field":"model","code":"model_not_in_catalog","message":"Modelo 'Rav-4 xx' no está en el catálogo de Toyota (GET /vehicles/catalog/models); Chileautos lo publicará sin ficha."},{"field":"fuel_type","code":"fuel_type_not_recognized","message":"Combustible 'Hidrógeno' no se reconoce; valores aceptados: gasolina, diesel, hibrido, electrico, gnc, glp, otro."}]}
18080
18093
  */
18081
18094
  put: {
@@ -18155,6 +18168,8 @@ interface paths {
18155
18168
  * ]
18156
18169
  */
18157
18170
  publish_to?: string[];
18171
+ /** @description Confirms a price change beyond 10x up or down from the current price. Without it such an edit answers 422 `PRICE_CHANGE_CONFIRMATION_REQUIRED`; resend the same body with `true` once the user confirmed. Not stored. */
18172
+ confirm_large_price_change?: boolean;
18158
18173
  };
18159
18174
  };
18160
18175
  };
@@ -18312,6 +18327,15 @@ interface paths {
18312
18327
  "application/json": components["schemas"]["Error"];
18313
18328
  };
18314
18329
  };
18330
+ /** @description `VEHICLE_VALUE_OUT_OF_RANGE` (price or km outside the sanity range) or `PRICE_CHANGE_CONFIRMATION_REQUIRED` (a price change beyond 10x sent without `confirm_large_price_change: true`). Nothing is written. */
18331
+ 422: {
18332
+ headers: {
18333
+ [name: string]: unknown;
18334
+ };
18335
+ content: {
18336
+ "application/json": components["schemas"]["Error"];
18337
+ };
18338
+ };
18315
18339
  /** @description Rate limited */
18316
18340
  429: {
18317
18341
  headers: {
@@ -18804,7 +18828,7 @@ interface paths {
18804
18828
  };
18805
18829
  /**
18806
18830
  * A vehicle's change history (Historial)
18807
- * @description Reverse-chronological audit trail for this vehicle — created, field edits (with a before→after diff), publish/unpublish/cierre, and Override local protect/release — with teammate actors resolved to display names. It also carries the deal's milestones, read from each document's own audit rows: nota de compra emitted/voided (`purchase_note_issued`, `purchase_note_voided`), nota de venta emitted/approved/voided (`sale_note_issued`, `sale_note_approved`, `sale_note_voided`), contrato de compraventa first printed (`compraventa_printed`), mandato de consignación first printed (`mandato_issued`), a signed copy filed (`signed_copy_filed`, with `metadata.signed_document_type`) and the liquidación paid to the consignor (`liquidacion_paid`). `metadata.folio` names the document when it has one. Each document type appears only for a caller holding its read scope (`purchase_notes:read`, `sale_notes:read`, `consignments:read`; signed copies also need `vehicle_registry:read`). A download of the Resumen del negocio is `deal_settlement_downloaded`. The car's papers (ADR 0114 §7 — permiso de circulación, revisión técnica, SOAP, padrón, CAV, any named paper) appear as `paper_added` (a file filed; `metadata.replaced_attachment_id` when it replaced one), `paper_updated` (renamed or its «Vence» day set, `metadata.changed`) and `paper_removed`, each with `metadata.kind`, `metadata.label` and `metadata.expires_on` — only for a caller holding `vehicle_registry:read`. The UI merges it with /activity (leads) into one "Leads y cambios" timeline.
18831
+ * @description Reverse-chronological audit trail for this vehicle — created, field edits (with a before→after diff), publish/unpublish/cierre, and Override local protect/release — with teammate actors resolved to display names. It also carries the deal's milestones, read from each document's own audit rows: nota de compra emitted/voided (`purchase_note_issued`, `purchase_note_voided`), nota de venta emitted/approved/voided (`sale_note_issued`, `sale_note_approved`, `sale_note_voided`), contrato de compraventa first printed (`compraventa_printed`), mandato de consignación first printed (`mandato_issued`), a signed copy filed (`signed_copy_filed`, with `metadata.signed_document_type`) and the liquidación paid to the consignor (`liquidacion_paid`). `metadata.folio` names the document when it has one. Each document type appears only for a caller holding its read scope (`purchase_notes:read`, `sale_notes:read`, `consignments:read`; signed copies also need `vehicle_registry:read`). A download of the Resumen del negocio is `deal_settlement_downloaded`. The car's papers (ADR 0114 §7 — permiso de circulación, revisión técnica, SOAP, padrón, CAV, any named paper) appear as `paper_added` (a file filed; `metadata.replaced_attachment_id` when it replaced one), `paper_updated` (renamed or its «Vence» day set, `metadata.changed`) and `paper_removed`, each with `metadata.kind`, `metadata.label` and `metadata.expires_on` — only for a caller holding `vehicle_registry:read`. A value changed directly on a connected system (price, km; Veekls also year and version) and taken into Vitrina is `portal_edit` (system actor, `changes`, `metadata.provider`, `metadata.portal`, `metadata.summary`); a portal value that was not taken in is `portal_edit_ignored` (`metadata.summary`; `metadata.ignored`: field, portal_value, kept_value, reason = `pending_vitrina_edit` when it lost to a Vitrina edit still waiting to be pushed, `out_of_range` when it fell outside the price/km sanity range). The UI merges it with /activity (leads) into one "Leads y cambios" timeline.
18808
18832
  */
18809
18833
  get: {
18810
18834
  parameters: {
@@ -122842,7 +122866,7 @@ interface paths {
122842
122866
  };
122843
122867
  /**
122844
122868
  * List a conversation's Continuaciones por WhatsApp
122845
- * @description The Continuaciones started from this conversation, newest first (one per phone number). Read `state` to draw the inbox button: `pending`, `deferred` (waiting for an approved template, until `send_deadline_at`), `sent`, `failed` or `skipped` (`reason` says why). Empty when none was started. A conversation the caller cannot see is a `404`.
122869
+ * @description The Continuaciones started from this conversation, newest first (one per phone number). Read `state` to draw the inbox button: `pending`, `deferred` (waiting for an approved template, until `send_deadline_at`), `sent`, `failed` or `skipped` (`reason` says why). Empty when none was started. `meta.whatsapp_line` is `true` when the workspace has an enabled WhatsApp line a Continuación could use (the same lookup the send runs), so a caller without `messaging_accounts:read` can still decide whether to offer the button. A conversation the caller cannot see is a `404`.
122846
122870
  */
122847
122871
  get: {
122848
122872
  parameters: {
@@ -122880,7 +122904,8 @@ interface paths {
122880
122904
  * }
122881
122905
  * ],
122882
122906
  * "meta": {
122883
- * "total": 1
122907
+ * "total": 1,
122908
+ * "whatsapp_line": true
122884
122909
  * }
122885
122910
  * }
122886
122911
  */
@@ -194299,7 +194324,7 @@ declare function createClient(opts: CreateClientOptions): VitrinaClient;
194299
194324
  * is regenerated — narrow on the ones you handle, never assume this
194300
194325
  * list is exhaustive at runtime.
194301
194326
  */
194302
- type ErrorCode = 'VALIDATION_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'CONFLICT' | 'ACCOUNT_DELETION_BLOCKED' | 'CONFIRMATION_REQUIRED' | 'VERSION_CONFLICT' | 'UNIQUE_CONFLICT' | 'IDEMPOTENCY_KEY_CONFLICT' | 'VERTICAL_NOT_ENABLED' | 'ENTITLEMENT_NOT_ACTIVE' | 'UNSUPPORTED_VEHICLE_TYPE' | 'NO_OFFERING_ADAPTER' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'GONE' | 'INTERNAL_ERROR' | 'MESSAGING_ACCOUNT_TENANT_MISSING' | 'COPILOT_APPROVALS_UNAVAILABLE' | 'COPILOT_APPROVAL_REPLAY_BLOCKED' | 'COPILOT_DISABLED' | 'COPILOT_BUDGET_EXCEEDED' | 'DEALER_SITES_NOT_CONFIGURED' | 'STOREFRONT_ZONES_NOT_CONFIGURED' | 'RECONTACTO_NOT_ENABLED' | 'SYNC_QUEUE_UNAVAILABLE' | 'SHARE_IMAGE_UNAVAILABLE' | 'AUDIO_RENDITION_PENDING' | 'ATTRIBUTION_PROFILE_UNAVAILABLE' | 'DOCUMENT_LOGO_UNAVAILABLE' | 'ATTRIBUTION_PROFILE_MISMATCH' | 'ADS_KEY_NEEDS_REMINT' | 'ADS_ACTION_READ_UNAVAILABLE' | 'ADS_ACTION_REPLAY_BLOCKED' | 'ADS_ACTION_NOT_AVAILABLE' | 'ADS_ACTION_NOT_REVERSIBLE' | 'ADS_ACTION_CONSENT_REQUIRED' | 'GTM_NOT_CONFIGURED' | 'GTM_NOT_CONNECTED' | 'GTM_CONSENT_REQUIRED' | 'GTM_PERMISSION_DENIED' | 'GTM_CONTAINER_REQUIRED' | 'GTM_PENDING_CHANGES' | 'GTM_WORKSPACE_CONFLICT' | 'GTM_WORKSPACE_LIMIT' | 'MISSING_SIGNATURE' | 'MALFORMED_SIGNATURE' | 'STALE_SIGNATURE' | 'INVALID_SIGNATURE' | 'REPLAY_DETECTED' | 'TURNSTILE_UNAVAILABLE' | 'TASADOR_QUOTA_EXHAUSTED' | 'TASADOR_ANON_DAILY_LIMIT' | 'TASADOR_CAPACITY_REACHED' | 'CLINIC_PLAN_REQUIRED' | 'TENANT_BILLING_PAUSED';
194327
+ type ErrorCode = 'VALIDATION_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'CONFLICT' | 'ACCOUNT_DELETION_BLOCKED' | 'CONFIRMATION_REQUIRED' | 'VERSION_CONFLICT' | 'UNIQUE_CONFLICT' | 'IDEMPOTENCY_KEY_CONFLICT' | 'VERTICAL_NOT_ENABLED' | 'ENTITLEMENT_NOT_ACTIVE' | 'UNSUPPORTED_VEHICLE_TYPE' | 'VEHICLE_VALUE_OUT_OF_RANGE' | 'PRICE_CHANGE_CONFIRMATION_REQUIRED' | 'NO_OFFERING_ADAPTER' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'GONE' | 'INTERNAL_ERROR' | 'MESSAGING_ACCOUNT_TENANT_MISSING' | 'COPILOT_APPROVALS_UNAVAILABLE' | 'COPILOT_APPROVAL_REPLAY_BLOCKED' | 'COPILOT_DISABLED' | 'COPILOT_BUDGET_EXCEEDED' | 'DEALER_SITES_NOT_CONFIGURED' | 'STOREFRONT_ZONES_NOT_CONFIGURED' | 'RECONTACTO_NOT_ENABLED' | 'SYNC_QUEUE_UNAVAILABLE' | 'SHARE_IMAGE_UNAVAILABLE' | 'AUDIO_RENDITION_PENDING' | 'ATTRIBUTION_PROFILE_UNAVAILABLE' | 'DOCUMENT_LOGO_UNAVAILABLE' | 'ATTRIBUTION_PROFILE_MISMATCH' | 'ADS_KEY_NEEDS_REMINT' | 'ADS_ACTION_READ_UNAVAILABLE' | 'ADS_ACTION_REPLAY_BLOCKED' | 'ADS_ACTION_NOT_AVAILABLE' | 'ADS_ACTION_NOT_REVERSIBLE' | 'ADS_ACTION_CONSENT_REQUIRED' | 'GTM_NOT_CONFIGURED' | 'GTM_NOT_CONNECTED' | 'GTM_CONSENT_REQUIRED' | 'GTM_PERMISSION_DENIED' | 'GTM_CONTAINER_REQUIRED' | 'GTM_PENDING_CHANGES' | 'GTM_WORKSPACE_CONFLICT' | 'GTM_WORKSPACE_LIMIT' | 'MISSING_SIGNATURE' | 'MALFORMED_SIGNATURE' | 'STALE_SIGNATURE' | 'INVALID_SIGNATURE' | 'REPLAY_DETECTED' | 'TURNSTILE_UNAVAILABLE' | 'TASADOR_QUOTA_EXHAUSTED' | 'TASADOR_ANON_DAILY_LIMIT' | 'TASADOR_CAPACITY_REACHED' | 'CLINIC_PLAN_REQUIRED' | 'TENANT_BILLING_PAUSED';
194303
194328
  declare const ERROR_CODES: readonly ErrorCode[];
194304
194329
 
194305
194330
  /**
package/dist/index.js CHANGED
@@ -18,6 +18,8 @@ var ERROR_CODES = [
18
18
  "VERTICAL_NOT_ENABLED",
19
19
  "ENTITLEMENT_NOT_ACTIVE",
20
20
  "UNSUPPORTED_VEHICLE_TYPE",
21
+ "VEHICLE_VALUE_OUT_OF_RANGE",
22
+ "PRICE_CHANGE_CONFIRMATION_REQUIRED",
21
23
  "NO_OFFERING_ADAPTER",
22
24
  "PAYLOAD_TOO_LARGE",
23
25
  "UNSUPPORTED_MEDIA_TYPE",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generated/error-codes.ts","../src/errors.ts","../src/webhooks.ts","../src/events.ts","../src/client.ts","../src/pagination.ts","../src/idempotency.ts"],"names":[],"mappings":";;;;;;AAsEO,IAAM,WAAA,GAAoC;AAAA,EAC/C,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,0BAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,sBAAA;AAAA,EACA,wBAAA;AAAA,EACA,0BAAA;AAAA,EACA,qBAAA;AAAA,EACA,mBAAA;AAAA,EACA,wBAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA,gBAAA;AAAA,EACA,kCAAA;AAAA,EACA,+BAAA;AAAA,EACA,iCAAA;AAAA,EACA,kBAAA;AAAA,EACA,yBAAA;AAAA,EACA,6BAAA;AAAA,EACA,iCAAA;AAAA,EACA,wBAAA;AAAA,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K,SAAA,CAAU,GAAG,CAAC,CAAA;AAAA,KACxF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,mBAAmB,GAAA,EAAI;AAClC;AASO,SAAS,uBAAuB,MAAA,EAAyB;AAC9D,EAAA,MAAM,EAAA,GAAK,UAAA,EAAW,CAAE,OAAA,CAAQ,MAAM,EAAE,CAAA;AACxC,EAAA,OAAO,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAA;AACtC","file":"index.js","sourcesContent":["// AUTO-GENERATED by scripts/generate-error-codes.ts from the repo-root src/errors/index.ts's `ErrorCode` union — do not edit by hand.\n\n/**\n * Every code the API error envelope can carry as `error.code`, at the\n * commit this SDK was generated from. Kept OPEN (see `OpenErrorCode` in\n * `../errors.ts`) because a server can ship a new code before this SDK\n * is regenerated — narrow on the ones you handle, never assume this\n * list is exhaustive at runtime.\n */\nexport type ErrorCode =\n | 'VALIDATION_ERROR'\n | 'NOT_FOUND'\n | 'UNAUTHORIZED'\n | 'FORBIDDEN'\n | 'CONFLICT'\n | 'ACCOUNT_DELETION_BLOCKED'\n | 'CONFIRMATION_REQUIRED'\n | 'VERSION_CONFLICT'\n | 'UNIQUE_CONFLICT'\n | 'IDEMPOTENCY_KEY_CONFLICT'\n | 'VERTICAL_NOT_ENABLED'\n | 'ENTITLEMENT_NOT_ACTIVE'\n | 'UNSUPPORTED_VEHICLE_TYPE'\n | 'NO_OFFERING_ADAPTER'\n | 'PAYLOAD_TOO_LARGE'\n | 'UNSUPPORTED_MEDIA_TYPE'\n | 'UPSTREAM_ERROR'\n | 'RATE_LIMITED'\n | 'GONE'\n | 'INTERNAL_ERROR'\n | 'MESSAGING_ACCOUNT_TENANT_MISSING'\n | 'COPILOT_APPROVALS_UNAVAILABLE'\n | 'COPILOT_APPROVAL_REPLAY_BLOCKED'\n | 'COPILOT_DISABLED'\n | 'COPILOT_BUDGET_EXCEEDED'\n | 'DEALER_SITES_NOT_CONFIGURED'\n | 'STOREFRONT_ZONES_NOT_CONFIGURED'\n | 'RECONTACTO_NOT_ENABLED'\n | 'SYNC_QUEUE_UNAVAILABLE'\n | 'SHARE_IMAGE_UNAVAILABLE'\n | 'AUDIO_RENDITION_PENDING'\n | 'ATTRIBUTION_PROFILE_UNAVAILABLE'\n | 'DOCUMENT_LOGO_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_MISMATCH'\n | 'ADS_KEY_NEEDS_REMINT'\n | 'ADS_ACTION_READ_UNAVAILABLE'\n | 'ADS_ACTION_REPLAY_BLOCKED'\n | 'ADS_ACTION_NOT_AVAILABLE'\n | 'ADS_ACTION_NOT_REVERSIBLE'\n | 'ADS_ACTION_CONSENT_REQUIRED'\n | 'GTM_NOT_CONFIGURED'\n | 'GTM_NOT_CONNECTED'\n | 'GTM_CONSENT_REQUIRED'\n | 'GTM_PERMISSION_DENIED'\n | 'GTM_CONTAINER_REQUIRED'\n | 'GTM_PENDING_CHANGES'\n | 'GTM_WORKSPACE_CONFLICT'\n | 'GTM_WORKSPACE_LIMIT'\n | 'MISSING_SIGNATURE'\n | 'MALFORMED_SIGNATURE'\n | 'STALE_SIGNATURE'\n | 'INVALID_SIGNATURE'\n | 'REPLAY_DETECTED'\n | 'TURNSTILE_UNAVAILABLE'\n | 'TASADOR_QUOTA_EXHAUSTED'\n | 'TASADOR_ANON_DAILY_LIMIT'\n | 'TASADOR_CAPACITY_REACHED'\n | 'CLINIC_PLAN_REQUIRED'\n | 'TENANT_BILLING_PAUSED';\n\nexport const ERROR_CODES: readonly ErrorCode[] = [\n 'VALIDATION_ERROR',\n 'NOT_FOUND',\n 'UNAUTHORIZED',\n 'FORBIDDEN',\n 'CONFLICT',\n 'ACCOUNT_DELETION_BLOCKED',\n 'CONFIRMATION_REQUIRED',\n 'VERSION_CONFLICT',\n 'UNIQUE_CONFLICT',\n 'IDEMPOTENCY_KEY_CONFLICT',\n 'VERTICAL_NOT_ENABLED',\n 'ENTITLEMENT_NOT_ACTIVE',\n 'UNSUPPORTED_VEHICLE_TYPE',\n 'NO_OFFERING_ADAPTER',\n 'PAYLOAD_TOO_LARGE',\n 'UNSUPPORTED_MEDIA_TYPE',\n 'UPSTREAM_ERROR',\n 'RATE_LIMITED',\n 'GONE',\n 'INTERNAL_ERROR',\n 'MESSAGING_ACCOUNT_TENANT_MISSING',\n 'COPILOT_APPROVALS_UNAVAILABLE',\n 'COPILOT_APPROVAL_REPLAY_BLOCKED',\n 'COPILOT_DISABLED',\n 'COPILOT_BUDGET_EXCEEDED',\n 'DEALER_SITES_NOT_CONFIGURED',\n 'STOREFRONT_ZONES_NOT_CONFIGURED',\n 'RECONTACTO_NOT_ENABLED',\n 'SYNC_QUEUE_UNAVAILABLE',\n 'SHARE_IMAGE_UNAVAILABLE',\n 'AUDIO_RENDITION_PENDING',\n 'ATTRIBUTION_PROFILE_UNAVAILABLE',\n 'DOCUMENT_LOGO_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_MISMATCH',\n 'ADS_KEY_NEEDS_REMINT',\n 'ADS_ACTION_READ_UNAVAILABLE',\n 'ADS_ACTION_REPLAY_BLOCKED',\n 'ADS_ACTION_NOT_AVAILABLE',\n 'ADS_ACTION_NOT_REVERSIBLE',\n 'ADS_ACTION_CONSENT_REQUIRED',\n 'GTM_NOT_CONFIGURED',\n 'GTM_NOT_CONNECTED',\n 'GTM_CONSENT_REQUIRED',\n 'GTM_PERMISSION_DENIED',\n 'GTM_CONTAINER_REQUIRED',\n 'GTM_PENDING_CHANGES',\n 'GTM_WORKSPACE_CONFLICT',\n 'GTM_WORKSPACE_LIMIT',\n 'MISSING_SIGNATURE',\n 'MALFORMED_SIGNATURE',\n 'STALE_SIGNATURE',\n 'INVALID_SIGNATURE',\n 'REPLAY_DETECTED',\n 'TURNSTILE_UNAVAILABLE',\n 'TASADOR_QUOTA_EXHAUSTED',\n 'TASADOR_ANON_DAILY_LIMIT',\n 'TASADOR_CAPACITY_REACHED',\n 'CLINIC_PLAN_REQUIRED',\n 'TENANT_BILLING_PAUSED',\n] as const;\n","/**\n * Typed errors over the API's one error envelope: `{ error: { code, message,\n * details?, field_errors?, requestId?, ...extensions } }` (`src/errors/\n * index.ts` + `src/middlewares/error-handler.ts` in vitrina-app). `code` is\n * generated from the committed error catalogue (see `generated/error-codes.ts`\n * and `../scripts/generate-error-codes.ts`) but kept OPEN at the type level —\n * `ErrorCode | (string & Record<string, never>)` — because a server release\n * can ship a new code before this SDK is regenerated; never treat the union\n * as exhaustive at runtime (no `switch` without a `default`).\n */\nimport { ERROR_CODES, type ErrorCode } from './generated/error-codes';\n\nexport { ERROR_CODES };\nexport type { ErrorCode };\n\n/** `error.code`, widened so an unrecognised future code still type-checks.\n * The `Record<string, never>` intersection (not a bare `{}`) is what keeps\n * known `ErrorCode` literals showing up in autocomplete while still\n * accepting any string. */\nexport type OpenErrorCode = ErrorCode | (string & Record<string, never>);\n\n/** One entry of `error.details.reasons` on an outbound-policy verdict (C4). */\nexport interface OutboundVerdictReason {\n code: string;\n kind: 'bloqueo' | 'advertencia';\n hint: string;\n detail?: string;\n}\n\n/** The wire shape of `error` inside the envelope. */\nexport interface ApiErrorBody {\n code: OpenErrorCode;\n message: string;\n details?: unknown;\n field_errors?: Record<string, string>;\n requestId?: string;\n /** Send-verdict envelopes (C4) put `reasons`/`hint` at this level too. */\n reasons?: OutboundVerdictReason[];\n hint?: string;\n [key: string]: unknown;\n}\n\nexport interface ApiErrorOptions {\n requestUrl?: string;\n requestMethod?: string;\n}\n\n/** Base class for every error this SDK throws for a non-2xx API response. */\nexport class VitrinaApiError extends Error {\n /** The catalogue code — branch on this, never on `message`. */\n readonly code: OpenErrorCode;\n\n /** HTTP status of the response that produced this error. */\n readonly status: number;\n\n readonly details?: unknown;\n\n readonly fieldErrors?: Record<string, string>;\n\n /** Correlates this failure with the server's own logs. */\n readonly requestId?: string;\n\n /** The full parsed `error` object, for anything not surfaced above. */\n readonly body: ApiErrorBody;\n\n readonly requestUrl?: string;\n\n readonly requestMethod?: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(body.message || `Vitrina API error ${body.code} (HTTP ${status})`);\n this.name = 'VitrinaApiError';\n this.status = status;\n this.code = body.code;\n this.details = body.details;\n this.fieldErrors = body.field_errors;\n this.requestId = body.requestId;\n this.body = body;\n this.requestUrl = options.requestUrl;\n this.requestMethod = options.requestMethod;\n }\n\n /** `429 RATE_LIMITED`. */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** `401` — no credential, or one the server does not recognise. */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** `403` — a real credential, missing the scope this call needs. */\n get isForbidden(): boolean {\n return this.status === 403;\n }\n\n /** `404 NOT_FOUND`. */\n get isNotFound(): boolean {\n return this.status === 404;\n }\n\n /** `409 IDEMPOTENCY_KEY_CONFLICT` — same `Idempotency-Key`, different body. */\n get isIdempotencyConflict(): boolean {\n return this.code === 'IDEMPOTENCY_KEY_CONFLICT';\n }\n}\n\n/**\n * `422 OUTBOUND_BLOCKED` (a Bloqueo, never overridable) or `409\n * OUTBOUND_WARNING` (an Advertencia — resend the same call with\n * `acknowledge: reasons.map(r => r.code)` in the body to proceed). Cross-\n * ticket contract C4 — `src/services/api-send-verdicts.ts` in vitrina-app.\n */\nexport class OutboundVerdictError extends VitrinaApiError {\n /** Every reason the send was stopped for, with its kind and hint. */\n readonly reasons: OutboundVerdictReason[];\n\n /** The first reason's hint, surfaced at the top level like the wire body. */\n readonly hint: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(status, body, options);\n this.name = 'OutboundVerdictError';\n const detailsReasons = (\n body.details as { reasons?: OutboundVerdictReason[] } | undefined\n )?.reasons;\n this.reasons = body.reasons ?? detailsReasons ?? [];\n this.hint = body.hint ?? this.reasons[0]?.hint ?? '';\n }\n\n /** A Bloqueo — the law, the customer or the provider already said no. */\n get isBlocked(): boolean {\n return this.code === 'OUTBOUND_BLOCKED';\n }\n\n /** An Advertencia — resend once with `acknowledge` to proceed. */\n get isWarning(): boolean {\n return this.code === 'OUTBOUND_WARNING';\n }\n\n /** `reasons` codes, ready to pass back as `{ acknowledge: [...] }`. */\n get acknowledgeCodes(): string[] {\n return this.reasons.map((r) => r.code);\n }\n}\n\nfunction asErrorBody(payload: unknown, status: number): ApiErrorBody {\n if (payload && typeof payload === 'object') {\n const maybeEnvelope = payload as { error?: unknown };\n const candidate =\n maybeEnvelope.error && typeof maybeEnvelope.error === 'object'\n ? (maybeEnvelope.error as Record<string, unknown>)\n : (payload as Record<string, unknown>);\n if (\n typeof candidate.code === 'string' &&\n typeof candidate.message === 'string'\n ) {\n return candidate as unknown as ApiErrorBody;\n }\n }\n return {\n code: 'INTERNAL_ERROR',\n message: `HTTP ${status} with an unrecognised response body`,\n };\n}\n\n/** Turns a non-2xx response's status + parsed JSON body into a typed error. */\nexport function toApiError(\n status: number,\n payload: unknown,\n options: ApiErrorOptions = {},\n): VitrinaApiError {\n const body = asErrorBody(payload, status);\n if (body.code === 'OUTBOUND_BLOCKED' || body.code === 'OUTBOUND_WARNING') {\n return new OutboundVerdictError(status, body, options);\n }\n return new VitrinaApiError(status, body, options);\n}\n\n/** The subset of an `openapi-fetch` call's resolved value `unwrap` needs. */\nexport interface UnwrappableResult<T> {\n data?: T;\n error?: unknown;\n response: Response;\n}\n\n/**\n * `const location = unwrap(await api.GET('/locations/{id}', ...))` — throws\n * a typed `VitrinaApiError` (or `OutboundVerdictError`) instead of making\n * every call site check `error` by hand. `openapi-fetch` itself never\n * throws; reach for the raw `{ data, error }` result directly when you want\n * that instead.\n */\nexport function unwrap<T>(\n result: UnwrappableResult<T>,\n options: ApiErrorOptions = {},\n): T {\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error, options);\n }\n if (result.data === undefined) {\n throw new VitrinaApiError(\n result.response.status,\n {\n code: 'INTERNAL_ERROR',\n message: 'Response had neither data nor error',\n },\n options,\n );\n }\n return result.data;\n}\n","/**\n * Webhook Evento envelope + Stripe-style signature verification, matching\n * the dispatch service's own `signPayload`/`buildHeaders`\n * (`src/services/webhook-dispatch.service.ts` in vitrina-app; cross-ticket\n * contract C3). The signature is an HMAC-SHA256 over `${timestamp}.${body}`\n * with the subscription's `whsec_...` secret, carried as\n * `X-Webhook-Signature: t=<unix_seconds>,v1=<hex>`.\n *\n * `tests/api-sdk-webhook-signature.test.ts` (vitrina-app repo root) verifies\n * this against the REAL `signPayload` the dispatch service calls in\n * production — not a hand-written fixture.\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** `resource` on the envelope — what changed, and where to read it. */\nexport interface WebhookEventResource {\n type: string;\n id: string | null;\n /** Absolute `GET` URL for this resource, or `null` when none is available\n * (e.g. the event has no single owning record). Feeds `event.fetch()`. */\n url: string | null;\n}\n\n/** Who did it — see `Author` in vitrina-app's `src/types/author.ts` (C3). */\nexport interface WebhookEventAuthor {\n kind: 'member' | 'api_key' | 'ai_agent' | 'system' | 'contact';\n id: string | null;\n name: string | null;\n via?: { kind: 'connected_app' | 'personal_token'; name: string };\n}\n\n/** Why `data` is absent — every reason a subscription's owner can be denied\n * the resource body. `missing_scope:<scope>` is a family, not one literal. */\nexport type DataOmittedReason =\n | 'not_requested'\n | 'sensitive'\n | 'owner_unavailable'\n | 'restricted_visibility'\n | `missing_scope:${string}`;\n\n/** One Evento, exactly as it arrives on the wire. Exactly one of `data` /\n * `data_omitted` is ever present. */\nexport interface WebhookEventEnvelope<TData = Record<string, unknown>> {\n id: string;\n type: string;\n version: number;\n /** `false` for an event from a sandbox (test-mode) workspace, `true`\n * otherwise; mirrored on the delivery's `Vitrina-Livemode` header.\n * Optional here only so an envelope captured before vitrina-app#2693\n * still satisfies this type — every envelope on the wire carries it. */\n livemode?: boolean;\n created_at: string;\n tenant_id: string;\n resource: WebhookEventResource;\n changes?: Record<string, { from: unknown; to: unknown }>;\n author: WebhookEventAuthor;\n data?: TData;\n data_omitted?: DataOmittedReason;\n}\n\nexport interface VerifySignatureOptions {\n /** How far `X-Webhook-Timestamp` may drift from now before a signature\n * that otherwise matches is rejected as stale (replay protection).\n * Default 300 (5 minutes), matching the docs' own verifier. */\n toleranceSeconds?: number;\n /** Override \"now\", in Unix seconds — for tests. */\n nowUnix?: number;\n}\n\nexport type VerifyResult =\n | { ok: true }\n | { ok: false; reason: 'malformed_header' | 'bad_signature' | 'stale' };\n\nfunction parseSignatureHeader(\n header: string,\n): { timestamp: number; v1: string } | null {\n const parts: Record<string, string> = {};\n for (const pair of header.split(',')) {\n const at = pair.indexOf('=');\n if (at === -1) continue;\n parts[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();\n }\n const timestamp = Number(parts.t);\n if (!Number.isFinite(timestamp) || !parts.v1) return null;\n return { timestamp, v1: parts.v1 };\n}\n\n/**\n * Verifies an `X-Webhook-Signature` header against the raw delivery body.\n * Never throws — returns `{ ok: false, reason }` so a caller can log why a\n * delivery was rejected. `rawBody` must be the exact bytes the delivery\n * sent, before any JSON re-serialization (re-stringifying a parsed body\n * produces different bytes and the signature will never match).\n */\nexport function verifyWebhookSignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): VerifyResult {\n const parsed = parseSignatureHeader(params.signatureHeader);\n if (!parsed) return { ok: false, reason: 'malformed_header' };\n\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n const expected = createHmac('sha256', params.secret)\n .update(`${parsed.timestamp}.${body}`)\n .digest('hex');\n\n const given = Buffer.from(parsed.v1, 'utf8');\n const mine = Buffer.from(expected, 'utf8');\n const signatureMatches =\n given.length === mine.length && timingSafeEqual(given, mine);\n if (!signatureMatches) return { ok: false, reason: 'bad_signature' };\n\n const tolerance = params.toleranceSeconds ?? 300;\n const now = params.nowUnix ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - parsed.timestamp) > tolerance) {\n return { ok: false, reason: 'stale' };\n }\n return { ok: true };\n}\n\nexport class WebhookSignatureError extends Error {\n readonly reason: Exclude<VerifyResult, { ok: true }>['reason'];\n\n constructor(reason: Exclude<VerifyResult, { ok: true }>['reason']) {\n super(`Webhook signature verification failed: ${reason}`);\n this.name = 'WebhookSignatureError';\n this.reason = reason;\n }\n}\n\n/**\n * Verifies + parses an Evento delivery in one call (Stripe's\n * `constructEvent` naming, same idea): throws `WebhookSignatureError`\n * instead of returning a result a caller might forget to check before\n * trusting `rawBody`.\n */\nexport function constructEventEnvelope<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): WebhookEventEnvelope<TData> {\n const result = verifyWebhookSignature(params);\n if (!result.ok) throw new WebhookSignatureError(result.reason);\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n return JSON.parse(body) as WebhookEventEnvelope<TData>;\n}\n","/**\n * `event.fetch()` — read an Evento's resource in one call, using the same\n * credentials the client was created with. `resource.url` is the absolute\n * `GET` URL the server already computed (`apiPublicUrl()` in\n * `webhook-dispatch.service.ts`), so this is a plain authenticated fetch of\n * that URL — no per-resource-type routing table to keep in sync.\n */\nimport { toApiError } from './errors';\nimport {\n constructEventEnvelope,\n verifyWebhookSignature,\n type VerifySignatureOptions,\n type WebhookEventEnvelope,\n} from './webhooks';\n\nexport class EventResourceUnavailableError extends Error {\n readonly event: WebhookEventEnvelope;\n\n constructor(event: WebhookEventEnvelope) {\n super(\n event.data_omitted\n ? `Event ${event.id} (${event.type}) carries no resource URL — data_omitted: ${event.data_omitted}`\n : `Event ${event.id} (${event.type}) carries no resource URL`,\n );\n this.name = 'EventResourceUnavailableError';\n this.event = event;\n }\n}\n\n/** A parsed Evento, plus a `fetch()` bound to the client it came from. */\nexport type VitrinaEvent<TData = Record<string, unknown>> =\n WebhookEventEnvelope<TData> & {\n /**\n * `GET`s `resource.url` with this client's credentials and returns its\n * `data`. Throws `EventResourceUnavailableError` when the envelope has no\n * URL (an event with no single owning resource, or one whose `data` you\n * already have inline). Pass a type argument to get the resource typed:\n * `await event.fetch<Contact>()`.\n */\n fetch<TResource = TData>(): Promise<TResource>;\n };\n\nexport interface EventFetcherDeps {\n headers: HeadersInit;\n fetch: typeof fetch;\n}\n\n/** Builds the `events` namespace `createClient()` attaches to every client:\n * signature verification bound to nothing (pure functions), and\n * `constructEvent` bound to this client's own auth so the returned event's\n * `.fetch()` needs no arguments. */\nexport function createEventsNamespace(deps: EventFetcherDeps) {\n // `WebhookEventEnvelope<any>`: this helper only ever reads `resource` /\n // `data_omitted` / `id` / `type`, never `.data`, so it is deliberately\n // NOT generic over TData — a `WebhookEventEnvelope<TData>` for any TData\n // must be assignable here.\n async function fetchResource<TResource>(\n event: WebhookEventEnvelope<any>,\n ): Promise<TResource> {\n if (!event.resource.url) throw new EventResourceUnavailableError(event);\n const res = await deps.fetch(event.resource.url, { headers: deps.headers });\n let json: unknown;\n try {\n json = await res.json();\n } catch {\n json = undefined;\n }\n if (!res.ok) {\n throw toApiError(res.status, json, {\n requestUrl: event.resource.url,\n requestMethod: 'GET',\n });\n }\n return (json as { data: TResource })?.data;\n }\n\n return {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature: (\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ) => verifyWebhookSignature(params),\n\n /**\n * Verifies + parses a webhook delivery and returns it with a bound\n * `.fetch()`. Throws `WebhookSignatureError` on a bad/stale signature.\n *\n * const event = client.events.constructEvent({\n * secret: subscriptionSecret,\n * signatureHeader: req.headers['x-webhook-signature'],\n * rawBody: req.rawBody,\n * });\n * if (event.type === 'contact.created') {\n * const contact = await event.fetch<Contact>();\n * }\n */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData> {\n const envelope = constructEventEnvelope<TData>(params);\n return Object.assign(envelope, {\n fetch: <TResource = TData>() => fetchResource<TResource>(envelope),\n });\n },\n };\n}\n","/**\n * `createClient()` — a typed `openapi-fetch` client over the API pública\n * (`paths` generated from the committed `openapi.public.json`), plus the\n * `events` namespace (webhook signature verification + `event.fetch()`).\n *\n * Auth: pass an `sk_*` API key (workspace credential or personal token —\n * both are Bearer) or a raw bearer token you manage yourself. Exactly one of\n * `apiKey` / `bearer`.\n */\nimport createOpenApiClient, { type Client } from 'openapi-fetch';\n\nimport { createEventsNamespace, type VitrinaEvent } from './events';\nimport type { paths } from './generated/api-types';\nimport type { VerifySignatureOptions, VerifyResult } from './webhooks';\n\nexport interface CreateClientOptions {\n /** Absolute base URL, e.g. `https://api.vitrinadev.com/api/v1`. No trailing slash. */\n baseUrl: string;\n /** An `sk_*` API key (workspace key or personal token). Mutually exclusive with `bearer`. */\n apiKey?: string;\n /** A raw bearer token, for a caller that manages tokens itself (e.g. a Supabase session JWT). */\n bearer?: string;\n /** Extra headers merged onto every request (e.g. a custom `User-Agent`). */\n headers?: Record<string, string>;\n /** Override `fetch` — Node <18, undici, msw, a test double. Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n}\n\nexport interface VitrinaEventsNamespace {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VerifyResult;\n /** Verifies + parses a webhook delivery; the returned event carries a\n * `.fetch()` bound to this client. Throws `WebhookSignatureError`. */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData>;\n}\n\n/** The typed REST client (`GET`/`POST`/.../`use`/`eject`, from `openapi-fetch`)\n * plus the `events` namespace. */\nexport type VitrinaClient = Client<paths> & { events: VitrinaEventsNamespace };\n\nexport function createClient(opts: CreateClientOptions): VitrinaClient {\n if (opts.apiKey && opts.bearer) {\n throw new RangeError(\n 'createClient(): pass at most one of `apiKey` / `bearer`, not both',\n );\n }\n const credential = opts.apiKey ?? opts.bearer;\n const headers: Record<string, string> = {\n ...(credential ? { Authorization: `Bearer ${credential}` } : {}),\n ...opts.headers,\n };\n const fetchImpl = opts.fetch ?? fetch;\n\n const base = createOpenApiClient<paths>({\n baseUrl: opts.baseUrl,\n headers,\n fetch: fetchImpl,\n });\n\n const events = createEventsNamespace({ headers, fetch: fetchImpl });\n\n return Object.assign(base, { events });\n}\n","/**\n * Cursor pagination — walks a list endpoint page by page, yielding one item\n * at a time (`for await`). Vitrina's list envelopes carry the cursor as\n * `meta.pagination.nextCursor` (the shape every v1 list route in production\n * answers with — `ok(res, rows, { pagination: { nextCursor, limit } })`,\n * `src/routes/api/v1/*.ts`) with a `meta.nextCursor` fallback for the flat\n * `PaginationMeta` OpenAPI shape (`src/api/openapi-responses.ts`) some\n * generated docs describe; this helper reads either. The opaque cursor\n * itself is a base64url-encoded `{ ts, id }` pair (`src/api/pagination.ts`)\n * — never decode it, just pass it back as the next page's `cursor` query\n * param.\n */\nimport { toApiError } from './errors';\n\nexport interface PaginationMeta {\n pagination?: {\n nextCursor?: string | null;\n prevCursor?: string | null;\n limit?: number;\n };\n nextCursor?: string | null;\n prevCursor?: string | null;\n total?: number;\n limit?: number;\n [key: string]: unknown;\n}\n\nexport interface ListEnvelope<T> {\n data?: T[];\n meta?: PaginationMeta;\n}\n\n/** The subset of an `openapi-fetch` GET call's resolved value `paginate` needs. */\nexport interface FetchPageResult<T> {\n data?: ListEnvelope<T>;\n error?: unknown;\n response: Response;\n}\n\nfunction nextCursorOf(meta: PaginationMeta | undefined): string | undefined {\n const cursor = meta?.pagination?.nextCursor ?? meta?.nextCursor ?? null;\n return cursor ?? undefined;\n}\n\n/**\n * Walks every page of a cursor-paginated list, yielding one item at a time.\n *\n * for await (const appointment of paginate((cursor) =>\n * api.GET('/appointments', { params: { query: { cursor, limit: 100 } } }),\n * )) {\n * console.log(appointment.id);\n * }\n *\n * CURSOR IS THE MINORITY SHAPE, so check the route before reaching for this.\n * Measured against the published contract: exactly two operations take a\n * `cursor` — `GET /appointments` and `GET /conversations/{id}/messages`.\n * Fifteen take `offset`/`limit` (`/stock`, `/vehicles`, `/contacts/search`,\n * `/webhooks/{id}/deliveries` and the rest), and others take `page`/`page_size`\n * (`/leads` among them). Passing `cursor` to one of those is a type error, not\n * a silent first page — which is the point of generating this package from the\n * contract.\n *\n * `fetchPage` is any typed `api.GET(...)` call, called once per page with\n * the previous page's cursor (`undefined` for the first page). Throws a\n * typed `VitrinaApiError` if a page comes back as an error, same as\n * `unwrap()`.\n */\nexport async function* paginate<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): AsyncGenerator<T, void, unknown> {\n let cursor: string | undefined;\n for (;;) {\n // eslint-disable-next-line no-await-in-loop -- pages are inherently sequential (each cursor depends on the last)\n const result = await fetchPage(cursor);\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error);\n }\n const page = result.data;\n if (!page || !Array.isArray(page.data)) return;\n for (const item of page.data) yield item;\n const next = nextCursorOf(page.meta);\n if (!next) return;\n cursor = next;\n }\n}\n\n/** Same as `paginate`, but collects every page into one array. Only reach\n * for this on a list you know is bounded — an unbounded one belongs on the\n * `for await` form above. */\nexport async function paginateAll<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): Promise<T[]> {\n const items: T[] = [];\n // eslint-disable-next-line no-restricted-syntax -- collecting an async generator IS the sequential-await case for-await exists for\n for await (const item of paginate(fetchPage)) items.push(item);\n return items;\n}\n","/**\n * `Idempotency-Key` — replay-safe retries on the 39 published write\n * operations that accept it (ADR 0106 §2.3/#2400). Resending the SAME key\n * with the SAME body returns the original response (`X-Idempotent-Replay:\n * 1`) instead of creating a second copy; the same key with a DIFFERENT body\n * answers `409 IDEMPOTENCY_KEY_CONFLICT` (`VitrinaApiError#isIdempotencyConflict`).\n *\n * The generated types already carry `Idempotency-Key` as a typed header\n * parameter per operation — `idempotencyKey()` just builds a well-formed\n * value to put there:\n *\n * await api.POST('/pipelines', {\n * params: { header: idempotencyKey(`provision-${userId}-2026-04-24`) },\n * body: { ... },\n * });\n */\nimport { randomUUID } from 'node:crypto';\n\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{8,200}$/;\n\nexport interface IdempotencyKeyHeader {\n 'Idempotency-Key': string;\n}\n\n/**\n * Validates `key` against the server's own constraint (`minLength: 8,\n * maxLength: 200, pattern: ^[A-Za-z0-9_-]+$` on every operation that accepts\n * it) and returns it as a header object to spread into `params.header`.\n * Throws `RangeError` on a malformed key — better to fail before the\n * request leaves than to get back a generic `VALIDATION_ERROR`.\n */\nexport function idempotencyKey(key: string): IdempotencyKeyHeader {\n if (!KEY_PATTERN.test(key)) {\n throw new RangeError(\n `Idempotency-Key must be 8-200 characters of [A-Za-z0-9_-], got: ${JSON.stringify(key)}`,\n );\n }\n return { 'Idempotency-Key': key };\n}\n\n/**\n * A fresh, valid `Idempotency-Key`. Mint ONE per logical operation and reuse\n * it across THAT operation's retries — generating a new key per attempt\n * defeats the point (each attempt would look like a different write). `\n * prefix` is optional and purely for your own log-grepping; it plays no\n * role on the server.\n */\nexport function generateIdempotencyKey(prefix?: string): string {\n const id = randomUUID().replace(/-/g, '');\n return prefix ? `${prefix}-${id}` : id;\n}\n"]}
1
+ {"version":3,"sources":["../src/generated/error-codes.ts","../src/errors.ts","../src/webhooks.ts","../src/events.ts","../src/client.ts","../src/pagination.ts","../src/idempotency.ts"],"names":[],"mappings":";;;;;;AAwEO,IAAM,WAAA,GAAoC;AAAA,EAC/C,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,0BAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,sBAAA;AAAA,EACA,wBAAA;AAAA,EACA,0BAAA;AAAA,EACA,4BAAA;AAAA,E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,CAAS,SAAS,CAAA,EAAG,KAAA,CAAM,KAAK,IAAI,CAAA;AAC7D,EAAA,OAAO,KAAA;AACT;AC9EA,IAAM,WAAA,GAAc,wBAAA;AAab,SAAS,eAAe,GAAA,EAAmC;AAChE,EAAA,IAAI,CAAC,WAAA,CAAY,IAAA,CAAK,GAAG,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAI,UAAA;AAAA,MACR,CAAA,gEAAA,EAAmE,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA;AAAA,KACxF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,mBAAmB,GAAA,EAAI;AAClC;AASO,SAAS,uBAAuB,MAAA,EAAyB;AAC9D,EAAA,MAAM,EAAA,GAAK,UAAA,EAAW,CAAE,OAAA,CAAQ,MAAM,EAAE,CAAA;AACxC,EAAA,OAAO,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAA;AACtC","file":"index.js","sourcesContent":["// AUTO-GENERATED by scripts/generate-error-codes.ts from the repo-root src/errors/index.ts's `ErrorCode` union — do not edit by hand.\n\n/**\n * Every code the API error envelope can carry as `error.code`, at the\n * commit this SDK was generated from. Kept OPEN (see `OpenErrorCode` in\n * `../errors.ts`) because a server can ship a new code before this SDK\n * is regenerated — narrow on the ones you handle, never assume this\n * list is exhaustive at runtime.\n */\nexport type ErrorCode =\n | 'VALIDATION_ERROR'\n | 'NOT_FOUND'\n | 'UNAUTHORIZED'\n | 'FORBIDDEN'\n | 'CONFLICT'\n | 'ACCOUNT_DELETION_BLOCKED'\n | 'CONFIRMATION_REQUIRED'\n | 'VERSION_CONFLICT'\n | 'UNIQUE_CONFLICT'\n | 'IDEMPOTENCY_KEY_CONFLICT'\n | 'VERTICAL_NOT_ENABLED'\n | 'ENTITLEMENT_NOT_ACTIVE'\n | 'UNSUPPORTED_VEHICLE_TYPE'\n | 'VEHICLE_VALUE_OUT_OF_RANGE'\n | 'PRICE_CHANGE_CONFIRMATION_REQUIRED'\n | 'NO_OFFERING_ADAPTER'\n | 'PAYLOAD_TOO_LARGE'\n | 'UNSUPPORTED_MEDIA_TYPE'\n | 'UPSTREAM_ERROR'\n | 'RATE_LIMITED'\n | 'GONE'\n | 'INTERNAL_ERROR'\n | 'MESSAGING_ACCOUNT_TENANT_MISSING'\n | 'COPILOT_APPROVALS_UNAVAILABLE'\n | 'COPILOT_APPROVAL_REPLAY_BLOCKED'\n | 'COPILOT_DISABLED'\n | 'COPILOT_BUDGET_EXCEEDED'\n | 'DEALER_SITES_NOT_CONFIGURED'\n | 'STOREFRONT_ZONES_NOT_CONFIGURED'\n | 'RECONTACTO_NOT_ENABLED'\n | 'SYNC_QUEUE_UNAVAILABLE'\n | 'SHARE_IMAGE_UNAVAILABLE'\n | 'AUDIO_RENDITION_PENDING'\n | 'ATTRIBUTION_PROFILE_UNAVAILABLE'\n | 'DOCUMENT_LOGO_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_MISMATCH'\n | 'ADS_KEY_NEEDS_REMINT'\n | 'ADS_ACTION_READ_UNAVAILABLE'\n | 'ADS_ACTION_REPLAY_BLOCKED'\n | 'ADS_ACTION_NOT_AVAILABLE'\n | 'ADS_ACTION_NOT_REVERSIBLE'\n | 'ADS_ACTION_CONSENT_REQUIRED'\n | 'GTM_NOT_CONFIGURED'\n | 'GTM_NOT_CONNECTED'\n | 'GTM_CONSENT_REQUIRED'\n | 'GTM_PERMISSION_DENIED'\n | 'GTM_CONTAINER_REQUIRED'\n | 'GTM_PENDING_CHANGES'\n | 'GTM_WORKSPACE_CONFLICT'\n | 'GTM_WORKSPACE_LIMIT'\n | 'MISSING_SIGNATURE'\n | 'MALFORMED_SIGNATURE'\n | 'STALE_SIGNATURE'\n | 'INVALID_SIGNATURE'\n | 'REPLAY_DETECTED'\n | 'TURNSTILE_UNAVAILABLE'\n | 'TASADOR_QUOTA_EXHAUSTED'\n | 'TASADOR_ANON_DAILY_LIMIT'\n | 'TASADOR_CAPACITY_REACHED'\n | 'CLINIC_PLAN_REQUIRED'\n | 'TENANT_BILLING_PAUSED';\n\nexport const ERROR_CODES: readonly ErrorCode[] = [\n 'VALIDATION_ERROR',\n 'NOT_FOUND',\n 'UNAUTHORIZED',\n 'FORBIDDEN',\n 'CONFLICT',\n 'ACCOUNT_DELETION_BLOCKED',\n 'CONFIRMATION_REQUIRED',\n 'VERSION_CONFLICT',\n 'UNIQUE_CONFLICT',\n 'IDEMPOTENCY_KEY_CONFLICT',\n 'VERTICAL_NOT_ENABLED',\n 'ENTITLEMENT_NOT_ACTIVE',\n 'UNSUPPORTED_VEHICLE_TYPE',\n 'VEHICLE_VALUE_OUT_OF_RANGE',\n 'PRICE_CHANGE_CONFIRMATION_REQUIRED',\n 'NO_OFFERING_ADAPTER',\n 'PAYLOAD_TOO_LARGE',\n 'UNSUPPORTED_MEDIA_TYPE',\n 'UPSTREAM_ERROR',\n 'RATE_LIMITED',\n 'GONE',\n 'INTERNAL_ERROR',\n 'MESSAGING_ACCOUNT_TENANT_MISSING',\n 'COPILOT_APPROVALS_UNAVAILABLE',\n 'COPILOT_APPROVAL_REPLAY_BLOCKED',\n 'COPILOT_DISABLED',\n 'COPILOT_BUDGET_EXCEEDED',\n 'DEALER_SITES_NOT_CONFIGURED',\n 'STOREFRONT_ZONES_NOT_CONFIGURED',\n 'RECONTACTO_NOT_ENABLED',\n 'SYNC_QUEUE_UNAVAILABLE',\n 'SHARE_IMAGE_UNAVAILABLE',\n 'AUDIO_RENDITION_PENDING',\n 'ATTRIBUTION_PROFILE_UNAVAILABLE',\n 'DOCUMENT_LOGO_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_MISMATCH',\n 'ADS_KEY_NEEDS_REMINT',\n 'ADS_ACTION_READ_UNAVAILABLE',\n 'ADS_ACTION_REPLAY_BLOCKED',\n 'ADS_ACTION_NOT_AVAILABLE',\n 'ADS_ACTION_NOT_REVERSIBLE',\n 'ADS_ACTION_CONSENT_REQUIRED',\n 'GTM_NOT_CONFIGURED',\n 'GTM_NOT_CONNECTED',\n 'GTM_CONSENT_REQUIRED',\n 'GTM_PERMISSION_DENIED',\n 'GTM_CONTAINER_REQUIRED',\n 'GTM_PENDING_CHANGES',\n 'GTM_WORKSPACE_CONFLICT',\n 'GTM_WORKSPACE_LIMIT',\n 'MISSING_SIGNATURE',\n 'MALFORMED_SIGNATURE',\n 'STALE_SIGNATURE',\n 'INVALID_SIGNATURE',\n 'REPLAY_DETECTED',\n 'TURNSTILE_UNAVAILABLE',\n 'TASADOR_QUOTA_EXHAUSTED',\n 'TASADOR_ANON_DAILY_LIMIT',\n 'TASADOR_CAPACITY_REACHED',\n 'CLINIC_PLAN_REQUIRED',\n 'TENANT_BILLING_PAUSED',\n] as const;\n","/**\n * Typed errors over the API's one error envelope: `{ error: { code, message,\n * details?, field_errors?, requestId?, ...extensions } }` (`src/errors/\n * index.ts` + `src/middlewares/error-handler.ts` in vitrina-app). `code` is\n * generated from the committed error catalogue (see `generated/error-codes.ts`\n * and `../scripts/generate-error-codes.ts`) but kept OPEN at the type level —\n * `ErrorCode | (string & Record<string, never>)` — because a server release\n * can ship a new code before this SDK is regenerated; never treat the union\n * as exhaustive at runtime (no `switch` without a `default`).\n */\nimport { ERROR_CODES, type ErrorCode } from './generated/error-codes';\n\nexport { ERROR_CODES };\nexport type { ErrorCode };\n\n/** `error.code`, widened so an unrecognised future code still type-checks.\n * The `Record<string, never>` intersection (not a bare `{}`) is what keeps\n * known `ErrorCode` literals showing up in autocomplete while still\n * accepting any string. */\nexport type OpenErrorCode = ErrorCode | (string & Record<string, never>);\n\n/** One entry of `error.details.reasons` on an outbound-policy verdict (C4). */\nexport interface OutboundVerdictReason {\n code: string;\n kind: 'bloqueo' | 'advertencia';\n hint: string;\n detail?: string;\n}\n\n/** The wire shape of `error` inside the envelope. */\nexport interface ApiErrorBody {\n code: OpenErrorCode;\n message: string;\n details?: unknown;\n field_errors?: Record<string, string>;\n requestId?: string;\n /** Send-verdict envelopes (C4) put `reasons`/`hint` at this level too. */\n reasons?: OutboundVerdictReason[];\n hint?: string;\n [key: string]: unknown;\n}\n\nexport interface ApiErrorOptions {\n requestUrl?: string;\n requestMethod?: string;\n}\n\n/** Base class for every error this SDK throws for a non-2xx API response. */\nexport class VitrinaApiError extends Error {\n /** The catalogue code — branch on this, never on `message`. */\n readonly code: OpenErrorCode;\n\n /** HTTP status of the response that produced this error. */\n readonly status: number;\n\n readonly details?: unknown;\n\n readonly fieldErrors?: Record<string, string>;\n\n /** Correlates this failure with the server's own logs. */\n readonly requestId?: string;\n\n /** The full parsed `error` object, for anything not surfaced above. */\n readonly body: ApiErrorBody;\n\n readonly requestUrl?: string;\n\n readonly requestMethod?: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(body.message || `Vitrina API error ${body.code} (HTTP ${status})`);\n this.name = 'VitrinaApiError';\n this.status = status;\n this.code = body.code;\n this.details = body.details;\n this.fieldErrors = body.field_errors;\n this.requestId = body.requestId;\n this.body = body;\n this.requestUrl = options.requestUrl;\n this.requestMethod = options.requestMethod;\n }\n\n /** `429 RATE_LIMITED`. */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** `401` — no credential, or one the server does not recognise. */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** `403` — a real credential, missing the scope this call needs. */\n get isForbidden(): boolean {\n return this.status === 403;\n }\n\n /** `404 NOT_FOUND`. */\n get isNotFound(): boolean {\n return this.status === 404;\n }\n\n /** `409 IDEMPOTENCY_KEY_CONFLICT` — same `Idempotency-Key`, different body. */\n get isIdempotencyConflict(): boolean {\n return this.code === 'IDEMPOTENCY_KEY_CONFLICT';\n }\n}\n\n/**\n * `422 OUTBOUND_BLOCKED` (a Bloqueo, never overridable) or `409\n * OUTBOUND_WARNING` (an Advertencia — resend the same call with\n * `acknowledge: reasons.map(r => r.code)` in the body to proceed). Cross-\n * ticket contract C4 — `src/services/api-send-verdicts.ts` in vitrina-app.\n */\nexport class OutboundVerdictError extends VitrinaApiError {\n /** Every reason the send was stopped for, with its kind and hint. */\n readonly reasons: OutboundVerdictReason[];\n\n /** The first reason's hint, surfaced at the top level like the wire body. */\n readonly hint: string;\n\n constructor(\n status: number,\n body: ApiErrorBody,\n options: ApiErrorOptions = {},\n ) {\n super(status, body, options);\n this.name = 'OutboundVerdictError';\n const detailsReasons = (\n body.details as { reasons?: OutboundVerdictReason[] } | undefined\n )?.reasons;\n this.reasons = body.reasons ?? detailsReasons ?? [];\n this.hint = body.hint ?? this.reasons[0]?.hint ?? '';\n }\n\n /** A Bloqueo — the law, the customer or the provider already said no. */\n get isBlocked(): boolean {\n return this.code === 'OUTBOUND_BLOCKED';\n }\n\n /** An Advertencia — resend once with `acknowledge` to proceed. */\n get isWarning(): boolean {\n return this.code === 'OUTBOUND_WARNING';\n }\n\n /** `reasons` codes, ready to pass back as `{ acknowledge: [...] }`. */\n get acknowledgeCodes(): string[] {\n return this.reasons.map((r) => r.code);\n }\n}\n\nfunction asErrorBody(payload: unknown, status: number): ApiErrorBody {\n if (payload && typeof payload === 'object') {\n const maybeEnvelope = payload as { error?: unknown };\n const candidate =\n maybeEnvelope.error && typeof maybeEnvelope.error === 'object'\n ? (maybeEnvelope.error as Record<string, unknown>)\n : (payload as Record<string, unknown>);\n if (\n typeof candidate.code === 'string' &&\n typeof candidate.message === 'string'\n ) {\n return candidate as unknown as ApiErrorBody;\n }\n }\n return {\n code: 'INTERNAL_ERROR',\n message: `HTTP ${status} with an unrecognised response body`,\n };\n}\n\n/** Turns a non-2xx response's status + parsed JSON body into a typed error. */\nexport function toApiError(\n status: number,\n payload: unknown,\n options: ApiErrorOptions = {},\n): VitrinaApiError {\n const body = asErrorBody(payload, status);\n if (body.code === 'OUTBOUND_BLOCKED' || body.code === 'OUTBOUND_WARNING') {\n return new OutboundVerdictError(status, body, options);\n }\n return new VitrinaApiError(status, body, options);\n}\n\n/** The subset of an `openapi-fetch` call's resolved value `unwrap` needs. */\nexport interface UnwrappableResult<T> {\n data?: T;\n error?: unknown;\n response: Response;\n}\n\n/**\n * `const location = unwrap(await api.GET('/locations/{id}', ...))` — throws\n * a typed `VitrinaApiError` (or `OutboundVerdictError`) instead of making\n * every call site check `error` by hand. `openapi-fetch` itself never\n * throws; reach for the raw `{ data, error }` result directly when you want\n * that instead.\n */\nexport function unwrap<T>(\n result: UnwrappableResult<T>,\n options: ApiErrorOptions = {},\n): T {\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error, options);\n }\n if (result.data === undefined) {\n throw new VitrinaApiError(\n result.response.status,\n {\n code: 'INTERNAL_ERROR',\n message: 'Response had neither data nor error',\n },\n options,\n );\n }\n return result.data;\n}\n","/**\n * Webhook Evento envelope + Stripe-style signature verification, matching\n * the dispatch service's own `signPayload`/`buildHeaders`\n * (`src/services/webhook-dispatch.service.ts` in vitrina-app; cross-ticket\n * contract C3). The signature is an HMAC-SHA256 over `${timestamp}.${body}`\n * with the subscription's `whsec_...` secret, carried as\n * `X-Webhook-Signature: t=<unix_seconds>,v1=<hex>`.\n *\n * `tests/api-sdk-webhook-signature.test.ts` (vitrina-app repo root) verifies\n * this against the REAL `signPayload` the dispatch service calls in\n * production — not a hand-written fixture.\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** `resource` on the envelope — what changed, and where to read it. */\nexport interface WebhookEventResource {\n type: string;\n id: string | null;\n /** Absolute `GET` URL for this resource, or `null` when none is available\n * (e.g. the event has no single owning record). Feeds `event.fetch()`. */\n url: string | null;\n}\n\n/** Who did it — see `Author` in vitrina-app's `src/types/author.ts` (C3). */\nexport interface WebhookEventAuthor {\n kind: 'member' | 'api_key' | 'ai_agent' | 'system' | 'contact';\n id: string | null;\n name: string | null;\n via?: { kind: 'connected_app' | 'personal_token'; name: string };\n}\n\n/** Why `data` is absent — every reason a subscription's owner can be denied\n * the resource body. `missing_scope:<scope>` is a family, not one literal. */\nexport type DataOmittedReason =\n | 'not_requested'\n | 'sensitive'\n | 'owner_unavailable'\n | 'restricted_visibility'\n | `missing_scope:${string}`;\n\n/** One Evento, exactly as it arrives on the wire. Exactly one of `data` /\n * `data_omitted` is ever present. */\nexport interface WebhookEventEnvelope<TData = Record<string, unknown>> {\n id: string;\n type: string;\n version: number;\n /** `false` for an event from a sandbox (test-mode) workspace, `true`\n * otherwise; mirrored on the delivery's `Vitrina-Livemode` header.\n * Optional here only so an envelope captured before vitrina-app#2693\n * still satisfies this type — every envelope on the wire carries it. */\n livemode?: boolean;\n created_at: string;\n tenant_id: string;\n resource: WebhookEventResource;\n changes?: Record<string, { from: unknown; to: unknown }>;\n author: WebhookEventAuthor;\n data?: TData;\n data_omitted?: DataOmittedReason;\n}\n\nexport interface VerifySignatureOptions {\n /** How far `X-Webhook-Timestamp` may drift from now before a signature\n * that otherwise matches is rejected as stale (replay protection).\n * Default 300 (5 minutes), matching the docs' own verifier. */\n toleranceSeconds?: number;\n /** Override \"now\", in Unix seconds — for tests. */\n nowUnix?: number;\n}\n\nexport type VerifyResult =\n | { ok: true }\n | { ok: false; reason: 'malformed_header' | 'bad_signature' | 'stale' };\n\nfunction parseSignatureHeader(\n header: string,\n): { timestamp: number; v1: string } | null {\n const parts: Record<string, string> = {};\n for (const pair of header.split(',')) {\n const at = pair.indexOf('=');\n if (at === -1) continue;\n parts[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();\n }\n const timestamp = Number(parts.t);\n if (!Number.isFinite(timestamp) || !parts.v1) return null;\n return { timestamp, v1: parts.v1 };\n}\n\n/**\n * Verifies an `X-Webhook-Signature` header against the raw delivery body.\n * Never throws — returns `{ ok: false, reason }` so a caller can log why a\n * delivery was rejected. `rawBody` must be the exact bytes the delivery\n * sent, before any JSON re-serialization (re-stringifying a parsed body\n * produces different bytes and the signature will never match).\n */\nexport function verifyWebhookSignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): VerifyResult {\n const parsed = parseSignatureHeader(params.signatureHeader);\n if (!parsed) return { ok: false, reason: 'malformed_header' };\n\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n const expected = createHmac('sha256', params.secret)\n .update(`${parsed.timestamp}.${body}`)\n .digest('hex');\n\n const given = Buffer.from(parsed.v1, 'utf8');\n const mine = Buffer.from(expected, 'utf8');\n const signatureMatches =\n given.length === mine.length && timingSafeEqual(given, mine);\n if (!signatureMatches) return { ok: false, reason: 'bad_signature' };\n\n const tolerance = params.toleranceSeconds ?? 300;\n const now = params.nowUnix ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - parsed.timestamp) > tolerance) {\n return { ok: false, reason: 'stale' };\n }\n return { ok: true };\n}\n\nexport class WebhookSignatureError extends Error {\n readonly reason: Exclude<VerifyResult, { ok: true }>['reason'];\n\n constructor(reason: Exclude<VerifyResult, { ok: true }>['reason']) {\n super(`Webhook signature verification failed: ${reason}`);\n this.name = 'WebhookSignatureError';\n this.reason = reason;\n }\n}\n\n/**\n * Verifies + parses an Evento delivery in one call (Stripe's\n * `constructEvent` naming, same idea): throws `WebhookSignatureError`\n * instead of returning a result a caller might forget to check before\n * trusting `rawBody`.\n */\nexport function constructEventEnvelope<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n): WebhookEventEnvelope<TData> {\n const result = verifyWebhookSignature(params);\n if (!result.ok) throw new WebhookSignatureError(result.reason);\n const body =\n typeof params.rawBody === 'string'\n ? params.rawBody\n : params.rawBody.toString('utf8');\n return JSON.parse(body) as WebhookEventEnvelope<TData>;\n}\n","/**\n * `event.fetch()` — read an Evento's resource in one call, using the same\n * credentials the client was created with. `resource.url` is the absolute\n * `GET` URL the server already computed (`apiPublicUrl()` in\n * `webhook-dispatch.service.ts`), so this is a plain authenticated fetch of\n * that URL — no per-resource-type routing table to keep in sync.\n */\nimport { toApiError } from './errors';\nimport {\n constructEventEnvelope,\n verifyWebhookSignature,\n type VerifySignatureOptions,\n type WebhookEventEnvelope,\n} from './webhooks';\n\nexport class EventResourceUnavailableError extends Error {\n readonly event: WebhookEventEnvelope;\n\n constructor(event: WebhookEventEnvelope) {\n super(\n event.data_omitted\n ? `Event ${event.id} (${event.type}) carries no resource URL — data_omitted: ${event.data_omitted}`\n : `Event ${event.id} (${event.type}) carries no resource URL`,\n );\n this.name = 'EventResourceUnavailableError';\n this.event = event;\n }\n}\n\n/** A parsed Evento, plus a `fetch()` bound to the client it came from. */\nexport type VitrinaEvent<TData = Record<string, unknown>> =\n WebhookEventEnvelope<TData> & {\n /**\n * `GET`s `resource.url` with this client's credentials and returns its\n * `data`. Throws `EventResourceUnavailableError` when the envelope has no\n * URL (an event with no single owning resource, or one whose `data` you\n * already have inline). Pass a type argument to get the resource typed:\n * `await event.fetch<Contact>()`.\n */\n fetch<TResource = TData>(): Promise<TResource>;\n };\n\nexport interface EventFetcherDeps {\n headers: HeadersInit;\n fetch: typeof fetch;\n}\n\n/** Builds the `events` namespace `createClient()` attaches to every client:\n * signature verification bound to nothing (pure functions), and\n * `constructEvent` bound to this client's own auth so the returned event's\n * `.fetch()` needs no arguments. */\nexport function createEventsNamespace(deps: EventFetcherDeps) {\n // `WebhookEventEnvelope<any>`: this helper only ever reads `resource` /\n // `data_omitted` / `id` / `type`, never `.data`, so it is deliberately\n // NOT generic over TData — a `WebhookEventEnvelope<TData>` for any TData\n // must be assignable here.\n async function fetchResource<TResource>(\n event: WebhookEventEnvelope<any>,\n ): Promise<TResource> {\n if (!event.resource.url) throw new EventResourceUnavailableError(event);\n const res = await deps.fetch(event.resource.url, { headers: deps.headers });\n let json: unknown;\n try {\n json = await res.json();\n } catch {\n json = undefined;\n }\n if (!res.ok) {\n throw toApiError(res.status, json, {\n requestUrl: event.resource.url,\n requestMethod: 'GET',\n });\n }\n return (json as { data: TResource })?.data;\n }\n\n return {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature: (\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ) => verifyWebhookSignature(params),\n\n /**\n * Verifies + parses a webhook delivery and returns it with a bound\n * `.fetch()`. Throws `WebhookSignatureError` on a bad/stale signature.\n *\n * const event = client.events.constructEvent({\n * secret: subscriptionSecret,\n * signatureHeader: req.headers['x-webhook-signature'],\n * rawBody: req.rawBody,\n * });\n * if (event.type === 'contact.created') {\n * const contact = await event.fetch<Contact>();\n * }\n */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData> {\n const envelope = constructEventEnvelope<TData>(params);\n return Object.assign(envelope, {\n fetch: <TResource = TData>() => fetchResource<TResource>(envelope),\n });\n },\n };\n}\n","/**\n * `createClient()` — a typed `openapi-fetch` client over the API pública\n * (`paths` generated from the committed `openapi.public.json`), plus the\n * `events` namespace (webhook signature verification + `event.fetch()`).\n *\n * Auth: pass an `sk_*` API key (workspace credential or personal token —\n * both are Bearer) or a raw bearer token you manage yourself. Exactly one of\n * `apiKey` / `bearer`.\n */\nimport createOpenApiClient, { type Client } from 'openapi-fetch';\n\nimport { createEventsNamespace, type VitrinaEvent } from './events';\nimport type { paths } from './generated/api-types';\nimport type { VerifySignatureOptions, VerifyResult } from './webhooks';\n\nexport interface CreateClientOptions {\n /** Absolute base URL, e.g. `https://api.vitrinadev.com/api/v1`. No trailing slash. */\n baseUrl: string;\n /** An `sk_*` API key (workspace key or personal token). Mutually exclusive with `bearer`. */\n apiKey?: string;\n /** A raw bearer token, for a caller that manages tokens itself (e.g. a Supabase session JWT). */\n bearer?: string;\n /** Extra headers merged onto every request (e.g. a custom `User-Agent`). */\n headers?: Record<string, string>;\n /** Override `fetch` — Node <18, undici, msw, a test double. Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n}\n\nexport interface VitrinaEventsNamespace {\n /** Verifies an `X-Webhook-Signature` header. Never throws. */\n verifySignature(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VerifyResult;\n /** Verifies + parses a webhook delivery; the returned event carries a\n * `.fetch()` bound to this client. Throws `WebhookSignatureError`. */\n constructEvent<TData = Record<string, unknown>>(\n params: {\n secret: string;\n signatureHeader: string;\n rawBody: string | Buffer;\n } & VerifySignatureOptions,\n ): VitrinaEvent<TData>;\n}\n\n/** The typed REST client (`GET`/`POST`/.../`use`/`eject`, from `openapi-fetch`)\n * plus the `events` namespace. */\nexport type VitrinaClient = Client<paths> & { events: VitrinaEventsNamespace };\n\nexport function createClient(opts: CreateClientOptions): VitrinaClient {\n if (opts.apiKey && opts.bearer) {\n throw new RangeError(\n 'createClient(): pass at most one of `apiKey` / `bearer`, not both',\n );\n }\n const credential = opts.apiKey ?? opts.bearer;\n const headers: Record<string, string> = {\n ...(credential ? { Authorization: `Bearer ${credential}` } : {}),\n ...opts.headers,\n };\n const fetchImpl = opts.fetch ?? fetch;\n\n const base = createOpenApiClient<paths>({\n baseUrl: opts.baseUrl,\n headers,\n fetch: fetchImpl,\n });\n\n const events = createEventsNamespace({ headers, fetch: fetchImpl });\n\n return Object.assign(base, { events });\n}\n","/**\n * Cursor pagination — walks a list endpoint page by page, yielding one item\n * at a time (`for await`). Vitrina's list envelopes carry the cursor as\n * `meta.pagination.nextCursor` (the shape every v1 list route in production\n * answers with — `ok(res, rows, { pagination: { nextCursor, limit } })`,\n * `src/routes/api/v1/*.ts`) with a `meta.nextCursor` fallback for the flat\n * `PaginationMeta` OpenAPI shape (`src/api/openapi-responses.ts`) some\n * generated docs describe; this helper reads either. The opaque cursor\n * itself is a base64url-encoded `{ ts, id }` pair (`src/api/pagination.ts`)\n * — never decode it, just pass it back as the next page's `cursor` query\n * param.\n */\nimport { toApiError } from './errors';\n\nexport interface PaginationMeta {\n pagination?: {\n nextCursor?: string | null;\n prevCursor?: string | null;\n limit?: number;\n };\n nextCursor?: string | null;\n prevCursor?: string | null;\n total?: number;\n limit?: number;\n [key: string]: unknown;\n}\n\nexport interface ListEnvelope<T> {\n data?: T[];\n meta?: PaginationMeta;\n}\n\n/** The subset of an `openapi-fetch` GET call's resolved value `paginate` needs. */\nexport interface FetchPageResult<T> {\n data?: ListEnvelope<T>;\n error?: unknown;\n response: Response;\n}\n\nfunction nextCursorOf(meta: PaginationMeta | undefined): string | undefined {\n const cursor = meta?.pagination?.nextCursor ?? meta?.nextCursor ?? null;\n return cursor ?? undefined;\n}\n\n/**\n * Walks every page of a cursor-paginated list, yielding one item at a time.\n *\n * for await (const appointment of paginate((cursor) =>\n * api.GET('/appointments', { params: { query: { cursor, limit: 100 } } }),\n * )) {\n * console.log(appointment.id);\n * }\n *\n * CURSOR IS THE MINORITY SHAPE, so check the route before reaching for this.\n * Measured against the published contract: exactly two operations take a\n * `cursor` — `GET /appointments` and `GET /conversations/{id}/messages`.\n * Fifteen take `offset`/`limit` (`/stock`, `/vehicles`, `/contacts/search`,\n * `/webhooks/{id}/deliveries` and the rest), and others take `page`/`page_size`\n * (`/leads` among them). Passing `cursor` to one of those is a type error, not\n * a silent first page — which is the point of generating this package from the\n * contract.\n *\n * `fetchPage` is any typed `api.GET(...)` call, called once per page with\n * the previous page's cursor (`undefined` for the first page). Throws a\n * typed `VitrinaApiError` if a page comes back as an error, same as\n * `unwrap()`.\n */\nexport async function* paginate<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): AsyncGenerator<T, void, unknown> {\n let cursor: string | undefined;\n for (;;) {\n // eslint-disable-next-line no-await-in-loop -- pages are inherently sequential (each cursor depends on the last)\n const result = await fetchPage(cursor);\n if (result.error !== undefined) {\n throw toApiError(result.response.status, result.error);\n }\n const page = result.data;\n if (!page || !Array.isArray(page.data)) return;\n for (const item of page.data) yield item;\n const next = nextCursorOf(page.meta);\n if (!next) return;\n cursor = next;\n }\n}\n\n/** Same as `paginate`, but collects every page into one array. Only reach\n * for this on a list you know is bounded — an unbounded one belongs on the\n * `for await` form above. */\nexport async function paginateAll<T>(\n fetchPage: (cursor: string | undefined) => Promise<FetchPageResult<T>>,\n): Promise<T[]> {\n const items: T[] = [];\n // eslint-disable-next-line no-restricted-syntax -- collecting an async generator IS the sequential-await case for-await exists for\n for await (const item of paginate(fetchPage)) items.push(item);\n return items;\n}\n","/**\n * `Idempotency-Key` — replay-safe retries on the 39 published write\n * operations that accept it (ADR 0106 §2.3/#2400). Resending the SAME key\n * with the SAME body returns the original response (`X-Idempotent-Replay:\n * 1`) instead of creating a second copy; the same key with a DIFFERENT body\n * answers `409 IDEMPOTENCY_KEY_CONFLICT` (`VitrinaApiError#isIdempotencyConflict`).\n *\n * The generated types already carry `Idempotency-Key` as a typed header\n * parameter per operation — `idempotencyKey()` just builds a well-formed\n * value to put there:\n *\n * await api.POST('/pipelines', {\n * params: { header: idempotencyKey(`provision-${userId}-2026-04-24`) },\n * body: { ... },\n * });\n */\nimport { randomUUID } from 'node:crypto';\n\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{8,200}$/;\n\nexport interface IdempotencyKeyHeader {\n 'Idempotency-Key': string;\n}\n\n/**\n * Validates `key` against the server's own constraint (`minLength: 8,\n * maxLength: 200, pattern: ^[A-Za-z0-9_-]+$` on every operation that accepts\n * it) and returns it as a header object to spread into `params.header`.\n * Throws `RangeError` on a malformed key — better to fail before the\n * request leaves than to get back a generic `VALIDATION_ERROR`.\n */\nexport function idempotencyKey(key: string): IdempotencyKeyHeader {\n if (!KEY_PATTERN.test(key)) {\n throw new RangeError(\n `Idempotency-Key must be 8-200 characters of [A-Za-z0-9_-], got: ${JSON.stringify(key)}`,\n );\n }\n return { 'Idempotency-Key': key };\n}\n\n/**\n * A fresh, valid `Idempotency-Key`. Mint ONE per logical operation and reuse\n * it across THAT operation's retries — generating a new key per attempt\n * defeats the point (each attempt would look like a different write). `\n * prefix` is optional and purely for your own log-grepping; it plays no\n * role on the server.\n */\nexport function generateIdempotencyKey(prefix?: string): string {\n const id = randomUUID().replace(/-/g, '');\n return prefix ? `${prefix}-${id}` : id;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrina/api",
3
- "version": "14.41.0",
3
+ "version": "14.42.0",
4
4
  "description": "Typed TypeScript SDK for the Vitrina API pública — generated from the committed openapi.public.json (ADR 0106).",
5
5
  "type": "module",
6
6
  "license": "MIT",