@vitrina/api 11.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vitrina
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # `@vitrina/api`
2
+
3
+ The TypeScript SDK for the [Vitrina](https://vitrinadev.com) public API. Every route, every error code
4
+ and every webhook event is typed from the same OpenAPI contract the backend serves, so the editor
5
+ knows the shape before you run anything.
6
+
7
+ ```bash
8
+ npm install @vitrina/api
9
+ ```
10
+
11
+ Node 18 or newer. The version matches the platform release it describes: `@vitrina/api@11.1.2`
12
+ documents API 11.1.2.
13
+
14
+ Full guide: **https://docs.vitrinadev.com/docs/sdk**
15
+
16
+ ## The client
17
+
18
+ ```ts
19
+ import { createClient } from '@vitrina/api';
20
+
21
+ const client = createClient({
22
+ baseUrl: 'https://api.vitrinadev.com/api/v1',
23
+ apiKey: process.env.VITRINA_KEY,
24
+ });
25
+
26
+ const { data, error } = await client.GET('/locations');
27
+ if (error) throw error;
28
+ console.log(data.data[0].name);
29
+ ```
30
+
31
+ `apiKey` takes an `sk_` API key or a personal token. If you manage your own tokens — a Supabase
32
+ session, say — pass `bearer` instead. The client accepts at most one of the two.
33
+
34
+ Mint a key in the app under **Configuración › Desarrolladores › API keys**, or over the API with a key
35
+ that already holds `api_keys:write`.
36
+
37
+ ## Errors you can branch on
38
+
39
+ `unwrap()` collapses the `{ data, error }` pair and throws a typed error instead:
40
+
41
+ ```ts
42
+ import { unwrap, VitrinaApiError } from '@vitrina/api';
43
+
44
+ try {
45
+ const locations = unwrap(await client.GET('/locations'));
46
+ } catch (err) {
47
+ if (err instanceof VitrinaApiError) {
48
+ err.status; // 404
49
+ err.code; // 'NOT_FOUND', typed against the catalogue
50
+ err.requestId; // the id to quote when you ask us about the call
51
+ }
52
+ }
53
+ ```
54
+
55
+ `isNotFound`, `isUnauthorized`, `isForbidden`, `isRateLimited` and `isIdempotencyConflict` cover the
56
+ common branches. Branch on `err.code`, never on `err.message`.
57
+
58
+ > `err.code` is typed `ErrorCode | (string & {})`. Autocomplete shows the codes that existed when the
59
+ > package was generated, and a server release can publish a new one before you upgrade — so a `switch`
60
+ > over it still needs a `default`.
61
+
62
+ `OutboundVerdictError` is the one worth knowing about beyond the usual: a send that the outbound
63
+ policy refuses carries the verdict that refused it.
64
+
65
+ ## Retrying without duplicating
66
+
67
+ ```ts
68
+ import { idempotencyKey, generateIdempotencyKey } from '@vitrina/api';
69
+
70
+ await client.POST('/pipelines', {
71
+ params: { header: idempotencyKey(`crear-pipeline-${userId}`) },
72
+ body: { name: 'Postventa' },
73
+ });
74
+ ```
75
+
76
+ The same key with the same body replays the original response instead of creating a second copy. The
77
+ same key with a *different* body answers `409 IDEMPOTENCY_KEY_CONFLICT`, which `isIdempotencyConflict`
78
+ recognises. Use a natural key when you have one; `generateIdempotencyKey()` when you don't.
79
+
80
+ ## Pagination — check the route first
81
+
82
+ The API paginates three ways, and the SDK's helper covers one of them on purpose:
83
+
84
+ | Shape | Operations | Helper |
85
+ |---|---|---|
86
+ | `cursor` / `limit` | 2 — `GET /appointments`, `GET /conversations/{id}/messages` | `paginate()`, `paginateAll()` |
87
+ | `offset` / `limit` | 15 — `/stock`, `/vehicles`, `/contacts/search`, … | your own loop |
88
+ | `page` / `page_size` | the rest, `/leads` among them | your own loop |
89
+
90
+ ```ts
91
+ import { paginate } from '@vitrina/api';
92
+
93
+ for await (const appointment of paginate((cursor) =>
94
+ client.GET('/appointments', { params: { query: { cursor, limit: 100 } } }),
95
+ )) {
96
+ console.log(appointment.id);
97
+ }
98
+ ```
99
+
100
+ Passing `cursor` to a route that paginates by `offset` does not quietly return the first page — it does
101
+ not compile. That is what generating this package from the contract buys you.
102
+
103
+ ## Webhooks
104
+
105
+ `constructEvent()` verifies the HMAC, checks the timestamp window, and hands back a typed envelope:
106
+
107
+ ```ts
108
+ app.post('/vitrina', express.raw({ type: 'application/json' }), (req, res) => {
109
+ const event = client.events.constructEvent({
110
+ secret: process.env.VITRINA_WEBHOOK_SECRET!,
111
+ signatureHeader: req.header('X-Webhook-Signature')!,
112
+ rawBody: req.body,
113
+ });
114
+
115
+ if (event.type === 'contact.created') console.log(event.data?.name);
116
+ res.json({ received: true });
117
+ });
118
+ ```
119
+
120
+ > **The raw body, not a reparsed one.** The signature is over the bytes that arrived, and
121
+ > `JSON.parse` followed by `JSON.stringify` produces a different string. Mount the receiver with
122
+ > `express.raw({ type: 'application/json' })` and pass that buffer straight to `rawBody`. A `req.body`
123
+ > that `express.json()` already reparsed will fail every signature.
124
+
125
+ It throws `WebhookSignatureError` rather than returning a result you can forget to check. If you want
126
+ `{ ok, reason }` without the exception, use `client.events.verifySignature()`.
127
+
128
+ When a subscription did not ask for `include_data`, or the event arrives as a notice because its owner
129
+ lacked the scope, the envelope carries `resource.url` and nothing in `data`. `event.fetch()` resolves
130
+ it with the same client's credentials, and throws `EventResourceUnavailableError` when there is no
131
+ single owning resource to fetch.
132
+
133
+ ## Exports
134
+
135
+ `createClient` · `unwrap` · `VitrinaApiError` · `OutboundVerdictError` · `WebhookSignatureError` ·
136
+ `EventResourceUnavailableError` · `paginate` · `paginateAll` · `idempotencyKey` ·
137
+ `generateIdempotencyKey` · `verifyWebhookSignature` · `constructEventEnvelope` · and the generated
138
+ `paths`, `components`, `operations` types.
139
+
140
+ ## Regenerating
141
+
142
+ The types come from the committed `openapi.public.json` at the repo root, never from a live server:
143
+
144
+ ```bash
145
+ pnpm run generate # types + the error catalogue
146
+ pnpm run build
147
+ pnpm run test
148
+ ```
149
+
150
+ ## Licence
151
+
152
+ MIT.
package/dist/index.cjs ADDED
@@ -0,0 +1,344 @@
1
+ 'use strict';
2
+
3
+ var createOpenApiClient = require('openapi-fetch');
4
+ var crypto = require('crypto');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var createOpenApiClient__default = /*#__PURE__*/_interopDefault(createOpenApiClient);
9
+
10
+ // src/client.ts
11
+
12
+ // src/generated/error-codes.ts
13
+ var ERROR_CODES = [
14
+ "VALIDATION_ERROR",
15
+ "NOT_FOUND",
16
+ "UNAUTHORIZED",
17
+ "FORBIDDEN",
18
+ "CONFLICT",
19
+ "UNIQUE_CONFLICT",
20
+ "IDEMPOTENCY_KEY_CONFLICT",
21
+ "VERTICAL_NOT_ENABLED",
22
+ "ENTITLEMENT_NOT_ACTIVE",
23
+ "UNSUPPORTED_VEHICLE_TYPE",
24
+ "NO_OFFERING_ADAPTER",
25
+ "PAYLOAD_TOO_LARGE",
26
+ "UNSUPPORTED_MEDIA_TYPE",
27
+ "UPSTREAM_ERROR",
28
+ "RATE_LIMITED",
29
+ "GONE",
30
+ "INTERNAL_ERROR",
31
+ "MESSAGING_ACCOUNT_TENANT_MISSING",
32
+ "COPILOT_APPROVALS_UNAVAILABLE",
33
+ "COPILOT_APPROVAL_REPLAY_BLOCKED",
34
+ "DEALER_SITES_NOT_CONFIGURED",
35
+ "STOREFRONT_ZONES_NOT_CONFIGURED",
36
+ "RECONTACTO_NOT_ENABLED",
37
+ "SYNC_QUEUE_UNAVAILABLE",
38
+ "ATTRIBUTION_PROFILE_UNAVAILABLE",
39
+ "ATTRIBUTION_PROFILE_MISMATCH",
40
+ "ADS_KEY_NEEDS_REMINT",
41
+ "MISSING_SIGNATURE",
42
+ "MALFORMED_SIGNATURE",
43
+ "STALE_SIGNATURE",
44
+ "INVALID_SIGNATURE",
45
+ "REPLAY_DETECTED",
46
+ "TURNSTILE_UNAVAILABLE",
47
+ "TASADOR_QUOTA_EXHAUSTED",
48
+ "TASADOR_ANON_DAILY_LIMIT",
49
+ "TASADOR_CAPACITY_REACHED",
50
+ "CLINIC_PLAN_REQUIRED",
51
+ "TENANT_BILLING_PAUSED",
52
+ "FACEBOOK_MARKETPLACE_NOT_AVAILABLE",
53
+ "WORKSPACE_MEMBER_INACTIVE",
54
+ "DEVICE_AGENT_ALREADY_PAIRED",
55
+ "DEVICE_AGENT_SELF_REQUIRES_USER",
56
+ "DEVICE_AGENT_KIND_NOT_ALLOWED",
57
+ "DEVICE_TASK_STATUS_NOT_ALLOWED",
58
+ "FACEBOOK_MARKETPLACE_NO_PHONE_AGENT",
59
+ "FACEBOOK_MARKETPLACE_THREAD_NOT_ADDRESSABLE",
60
+ "FACEBOOK_MARKETPLACE_ATTACHMENT_UNSUPPORTED",
61
+ "REPLY_PACING_LOCKED",
62
+ "SANDBOX_CHANNEL_FORBIDDEN",
63
+ "SANDBOX_BILLING_FORBIDDEN",
64
+ "SANDBOX_NOT_PROVISIONED",
65
+ "SANDBOX_RESET_UNAVAILABLE",
66
+ "CONNECTED_APP_SENSITIVE_DATA",
67
+ "handoff_mismatch",
68
+ "sync_in_flight",
69
+ "atribu_refused",
70
+ "start_again",
71
+ "reconnect",
72
+ "partner_token_invalid",
73
+ "OUTBOUND_BLOCKED",
74
+ "OUTBOUND_WARNING",
75
+ "dpa_acceptance_required",
76
+ "EMAIL_SENDER_UNRESOLVED",
77
+ "CAMPAIGN_FROM_CONNECTED_MAILBOX",
78
+ "BANK_FEED_NOT_CONFIGURED",
79
+ "ADDON_NOT_PRICED"
80
+ ];
81
+
82
+ // src/errors.ts
83
+ var VitrinaApiError = class extends Error {
84
+ constructor(status, body, options = {}) {
85
+ super(body.message || `Vitrina API error ${body.code} (HTTP ${status})`);
86
+ this.name = "VitrinaApiError";
87
+ this.status = status;
88
+ this.code = body.code;
89
+ this.details = body.details;
90
+ this.fieldErrors = body.field_errors;
91
+ this.requestId = body.requestId;
92
+ this.body = body;
93
+ this.requestUrl = options.requestUrl;
94
+ this.requestMethod = options.requestMethod;
95
+ }
96
+ /** `429 RATE_LIMITED`. */
97
+ get isRateLimited() {
98
+ return this.status === 429;
99
+ }
100
+ /** `401` — no credential, or one the server does not recognise. */
101
+ get isUnauthorized() {
102
+ return this.status === 401;
103
+ }
104
+ /** `403` — a real credential, missing the scope this call needs. */
105
+ get isForbidden() {
106
+ return this.status === 403;
107
+ }
108
+ /** `404 NOT_FOUND`. */
109
+ get isNotFound() {
110
+ return this.status === 404;
111
+ }
112
+ /** `409 IDEMPOTENCY_KEY_CONFLICT` — same `Idempotency-Key`, different body. */
113
+ get isIdempotencyConflict() {
114
+ return this.code === "IDEMPOTENCY_KEY_CONFLICT";
115
+ }
116
+ };
117
+ var OutboundVerdictError = class extends VitrinaApiError {
118
+ constructor(status, body, options = {}) {
119
+ super(status, body, options);
120
+ this.name = "OutboundVerdictError";
121
+ const detailsReasons = body.details?.reasons;
122
+ this.reasons = body.reasons ?? detailsReasons ?? [];
123
+ this.hint = body.hint ?? this.reasons[0]?.hint ?? "";
124
+ }
125
+ /** A Bloqueo — the law, the customer or the provider already said no. */
126
+ get isBlocked() {
127
+ return this.code === "OUTBOUND_BLOCKED";
128
+ }
129
+ /** An Advertencia — resend once with `acknowledge` to proceed. */
130
+ get isWarning() {
131
+ return this.code === "OUTBOUND_WARNING";
132
+ }
133
+ /** `reasons` codes, ready to pass back as `{ acknowledge: [...] }`. */
134
+ get acknowledgeCodes() {
135
+ return this.reasons.map((r) => r.code);
136
+ }
137
+ };
138
+ function asErrorBody(payload, status) {
139
+ if (payload && typeof payload === "object") {
140
+ const maybeEnvelope = payload;
141
+ const candidate = maybeEnvelope.error && typeof maybeEnvelope.error === "object" ? maybeEnvelope.error : payload;
142
+ if (typeof candidate.code === "string" && typeof candidate.message === "string") {
143
+ return candidate;
144
+ }
145
+ }
146
+ return {
147
+ code: "INTERNAL_ERROR",
148
+ message: `HTTP ${status} with an unrecognised response body`
149
+ };
150
+ }
151
+ function toApiError(status, payload, options = {}) {
152
+ const body = asErrorBody(payload, status);
153
+ if (body.code === "OUTBOUND_BLOCKED" || body.code === "OUTBOUND_WARNING") {
154
+ return new OutboundVerdictError(status, body, options);
155
+ }
156
+ return new VitrinaApiError(status, body, options);
157
+ }
158
+ function unwrap(result, options = {}) {
159
+ if (result.error !== void 0) {
160
+ throw toApiError(result.response.status, result.error, options);
161
+ }
162
+ if (result.data === void 0) {
163
+ throw new VitrinaApiError(
164
+ result.response.status,
165
+ {
166
+ code: "INTERNAL_ERROR",
167
+ message: "Response had neither data nor error"
168
+ },
169
+ options
170
+ );
171
+ }
172
+ return result.data;
173
+ }
174
+ function parseSignatureHeader(header) {
175
+ const parts = {};
176
+ for (const pair of header.split(",")) {
177
+ const at = pair.indexOf("=");
178
+ if (at === -1) continue;
179
+ parts[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();
180
+ }
181
+ const timestamp = Number(parts.t);
182
+ if (!Number.isFinite(timestamp) || !parts.v1) return null;
183
+ return { timestamp, v1: parts.v1 };
184
+ }
185
+ function verifyWebhookSignature(params) {
186
+ const parsed = parseSignatureHeader(params.signatureHeader);
187
+ if (!parsed) return { ok: false, reason: "malformed_header" };
188
+ const body = typeof params.rawBody === "string" ? params.rawBody : params.rawBody.toString("utf8");
189
+ const expected = crypto.createHmac("sha256", params.secret).update(`${parsed.timestamp}.${body}`).digest("hex");
190
+ const given = Buffer.from(parsed.v1, "utf8");
191
+ const mine = Buffer.from(expected, "utf8");
192
+ const signatureMatches = given.length === mine.length && crypto.timingSafeEqual(given, mine);
193
+ if (!signatureMatches) return { ok: false, reason: "bad_signature" };
194
+ const tolerance = params.toleranceSeconds ?? 300;
195
+ const now = params.nowUnix ?? Math.floor(Date.now() / 1e3);
196
+ if (Math.abs(now - parsed.timestamp) > tolerance) {
197
+ return { ok: false, reason: "stale" };
198
+ }
199
+ return { ok: true };
200
+ }
201
+ var WebhookSignatureError = class extends Error {
202
+ constructor(reason) {
203
+ super(`Webhook signature verification failed: ${reason}`);
204
+ this.name = "WebhookSignatureError";
205
+ this.reason = reason;
206
+ }
207
+ };
208
+ function constructEventEnvelope(params) {
209
+ const result = verifyWebhookSignature(params);
210
+ if (!result.ok) throw new WebhookSignatureError(result.reason);
211
+ const body = typeof params.rawBody === "string" ? params.rawBody : params.rawBody.toString("utf8");
212
+ return JSON.parse(body);
213
+ }
214
+
215
+ // src/events.ts
216
+ var EventResourceUnavailableError = class extends Error {
217
+ constructor(event) {
218
+ super(
219
+ event.data_omitted ? `Event ${event.id} (${event.type}) carries no resource URL \u2014 data_omitted: ${event.data_omitted}` : `Event ${event.id} (${event.type}) carries no resource URL`
220
+ );
221
+ this.name = "EventResourceUnavailableError";
222
+ this.event = event;
223
+ }
224
+ };
225
+ function createEventsNamespace(deps) {
226
+ async function fetchResource(event) {
227
+ if (!event.resource.url) throw new EventResourceUnavailableError(event);
228
+ const res = await deps.fetch(event.resource.url, { headers: deps.headers });
229
+ let json;
230
+ try {
231
+ json = await res.json();
232
+ } catch {
233
+ json = void 0;
234
+ }
235
+ if (!res.ok) {
236
+ throw toApiError(res.status, json, {
237
+ requestUrl: event.resource.url,
238
+ requestMethod: "GET"
239
+ });
240
+ }
241
+ return json?.data;
242
+ }
243
+ return {
244
+ /** Verifies an `X-Webhook-Signature` header. Never throws. */
245
+ verifySignature: (params) => verifyWebhookSignature(params),
246
+ /**
247
+ * Verifies + parses a webhook delivery and returns it with a bound
248
+ * `.fetch()`. Throws `WebhookSignatureError` on a bad/stale signature.
249
+ *
250
+ * const event = client.events.constructEvent({
251
+ * secret: subscriptionSecret,
252
+ * signatureHeader: req.headers['x-webhook-signature'],
253
+ * rawBody: req.rawBody,
254
+ * });
255
+ * if (event.type === 'contact.created') {
256
+ * const contact = await event.fetch<Contact>();
257
+ * }
258
+ */
259
+ constructEvent(params) {
260
+ const envelope = constructEventEnvelope(params);
261
+ return Object.assign(envelope, {
262
+ fetch: () => fetchResource(envelope)
263
+ });
264
+ }
265
+ };
266
+ }
267
+
268
+ // src/client.ts
269
+ function createClient(opts) {
270
+ if (opts.apiKey && opts.bearer) {
271
+ throw new RangeError(
272
+ "createClient(): pass at most one of `apiKey` / `bearer`, not both"
273
+ );
274
+ }
275
+ const credential = opts.apiKey ?? opts.bearer;
276
+ const headers = {
277
+ ...credential ? { Authorization: `Bearer ${credential}` } : {},
278
+ ...opts.headers
279
+ };
280
+ const fetchImpl = opts.fetch ?? fetch;
281
+ const base = createOpenApiClient__default.default({
282
+ baseUrl: opts.baseUrl,
283
+ headers,
284
+ fetch: fetchImpl
285
+ });
286
+ const events = createEventsNamespace({ headers, fetch: fetchImpl });
287
+ return Object.assign(base, { events });
288
+ }
289
+
290
+ // src/pagination.ts
291
+ function nextCursorOf(meta) {
292
+ const cursor = meta?.pagination?.nextCursor ?? meta?.nextCursor ?? null;
293
+ return cursor ?? void 0;
294
+ }
295
+ async function* paginate(fetchPage) {
296
+ let cursor;
297
+ for (; ; ) {
298
+ const result = await fetchPage(cursor);
299
+ if (result.error !== void 0) {
300
+ throw toApiError(result.response.status, result.error);
301
+ }
302
+ const page = result.data;
303
+ if (!page || !Array.isArray(page.data)) return;
304
+ for (const item of page.data) yield item;
305
+ const next = nextCursorOf(page.meta);
306
+ if (!next) return;
307
+ cursor = next;
308
+ }
309
+ }
310
+ async function paginateAll(fetchPage) {
311
+ const items = [];
312
+ for await (const item of paginate(fetchPage)) items.push(item);
313
+ return items;
314
+ }
315
+ var KEY_PATTERN = /^[A-Za-z0-9_-]{8,200}$/;
316
+ function idempotencyKey(key) {
317
+ if (!KEY_PATTERN.test(key)) {
318
+ throw new RangeError(
319
+ `Idempotency-Key must be 8-200 characters of [A-Za-z0-9_-], got: ${JSON.stringify(key)}`
320
+ );
321
+ }
322
+ return { "Idempotency-Key": key };
323
+ }
324
+ function generateIdempotencyKey(prefix) {
325
+ const id = crypto.randomUUID().replace(/-/g, "");
326
+ return prefix ? `${prefix}-${id}` : id;
327
+ }
328
+
329
+ exports.ERROR_CODES = ERROR_CODES;
330
+ exports.EventResourceUnavailableError = EventResourceUnavailableError;
331
+ exports.OutboundVerdictError = OutboundVerdictError;
332
+ exports.VitrinaApiError = VitrinaApiError;
333
+ exports.WebhookSignatureError = WebhookSignatureError;
334
+ exports.constructEventEnvelope = constructEventEnvelope;
335
+ exports.createClient = createClient;
336
+ exports.generateIdempotencyKey = generateIdempotencyKey;
337
+ exports.idempotencyKey = idempotencyKey;
338
+ exports.paginate = paginate;
339
+ exports.paginateAll = paginateAll;
340
+ exports.toApiError = toApiError;
341
+ exports.unwrap = unwrap;
342
+ exports.verifyWebhookSignature = verifyWebhookSignature;
343
+ //# sourceMappingURL=index.cjs.map
344
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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":";;;;;;;;;;;;AA6EO,IAAM,WAAA,GAAoC;AAAA,EAC/C,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,sBAAA;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CAAa,IAAA,CAAK,IAAI,CAAA;AACnC,IAAA,IAAI,CAAC,IAAA,EAAM;AACX,IAAA,MAAA,GAAS,IAAA;AAAA,EACX;AACF;AAKA,eAAsB,YACpB,SAAA,EACc;AACd,EAAA,MAAM,QAAa,EAAC;AAEpB,EAAA,WAAA,MAAiB,QAAQ,QAAA,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,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 | '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 | 'DEALER_SITES_NOT_CONFIGURED'\n | 'STOREFRONT_ZONES_NOT_CONFIGURED'\n | 'RECONTACTO_NOT_ENABLED'\n | 'SYNC_QUEUE_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_UNAVAILABLE'\n | 'ATTRIBUTION_PROFILE_MISMATCH'\n | 'ADS_KEY_NEEDS_REMINT'\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 | 'FACEBOOK_MARKETPLACE_NOT_AVAILABLE'\n | 'WORKSPACE_MEMBER_INACTIVE'\n | 'DEVICE_AGENT_ALREADY_PAIRED'\n | 'DEVICE_AGENT_SELF_REQUIRES_USER'\n | 'DEVICE_AGENT_KIND_NOT_ALLOWED'\n | 'DEVICE_TASK_STATUS_NOT_ALLOWED'\n | 'FACEBOOK_MARKETPLACE_NO_PHONE_AGENT'\n | 'FACEBOOK_MARKETPLACE_THREAD_NOT_ADDRESSABLE'\n | 'FACEBOOK_MARKETPLACE_ATTACHMENT_UNSUPPORTED'\n | 'REPLY_PACING_LOCKED'\n | 'SANDBOX_CHANNEL_FORBIDDEN'\n | 'SANDBOX_BILLING_FORBIDDEN'\n | 'SANDBOX_NOT_PROVISIONED'\n | 'SANDBOX_RESET_UNAVAILABLE'\n | 'CONNECTED_APP_SENSITIVE_DATA'\n | 'handoff_mismatch'\n | 'sync_in_flight'\n | 'atribu_refused'\n | 'start_again'\n | 'reconnect'\n | 'partner_token_invalid'\n | 'OUTBOUND_BLOCKED'\n | 'OUTBOUND_WARNING'\n | 'dpa_acceptance_required'\n | 'EMAIL_SENDER_UNRESOLVED'\n | 'CAMPAIGN_FROM_CONNECTED_MAILBOX'\n | 'BANK_FEED_NOT_CONFIGURED'\n | 'ADDON_NOT_PRICED';\n\nexport const ERROR_CODES: readonly ErrorCode[] = [\n 'VALIDATION_ERROR',\n 'NOT_FOUND',\n 'UNAUTHORIZED',\n 'FORBIDDEN',\n '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 'DEALER_SITES_NOT_CONFIGURED',\n 'STOREFRONT_ZONES_NOT_CONFIGURED',\n 'RECONTACTO_NOT_ENABLED',\n 'SYNC_QUEUE_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_UNAVAILABLE',\n 'ATTRIBUTION_PROFILE_MISMATCH',\n 'ADS_KEY_NEEDS_REMINT',\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 'FACEBOOK_MARKETPLACE_NOT_AVAILABLE',\n 'WORKSPACE_MEMBER_INACTIVE',\n 'DEVICE_AGENT_ALREADY_PAIRED',\n 'DEVICE_AGENT_SELF_REQUIRES_USER',\n 'DEVICE_AGENT_KIND_NOT_ALLOWED',\n 'DEVICE_TASK_STATUS_NOT_ALLOWED',\n 'FACEBOOK_MARKETPLACE_NO_PHONE_AGENT',\n 'FACEBOOK_MARKETPLACE_THREAD_NOT_ADDRESSABLE',\n 'FACEBOOK_MARKETPLACE_ATTACHMENT_UNSUPPORTED',\n 'REPLY_PACING_LOCKED',\n 'SANDBOX_CHANNEL_FORBIDDEN',\n 'SANDBOX_BILLING_FORBIDDEN',\n 'SANDBOX_NOT_PROVISIONED',\n 'SANDBOX_RESET_UNAVAILABLE',\n 'CONNECTED_APP_SENSITIVE_DATA',\n 'handoff_mismatch',\n 'sync_in_flight',\n 'atribu_refused',\n 'start_again',\n 'reconnect',\n 'partner_token_invalid',\n 'OUTBOUND_BLOCKED',\n 'OUTBOUND_WARNING',\n 'dpa_acceptance_required',\n 'EMAIL_SENDER_UNRESOLVED',\n 'CAMPAIGN_FROM_CONNECTED_MAILBOX',\n 'BANK_FEED_NOT_CONFIGURED',\n 'ADDON_NOT_PRICED',\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"]}