@xedo/sdk 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/index.cjs +39 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +839 -75
- package/dist/index.d.ts +839 -75
- package/dist/index.js +39 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,13 @@ xedo.lastRateLimit; // { limit, remaining, reset } from the last call
|
|
|
53
53
|
| `xedo.collections` | `list`, `listAll`, `retrieve`, `retrieveBySlug` |
|
|
54
54
|
| `xedo.orders` | `list`, `listAll`, `retrieve`, `invoice` (PDF) |
|
|
55
55
|
| `xedo.carts` | `list`, `listAll`, `retrieve`, `preview`, `create`, `pay`, `createAndPay` |
|
|
56
|
+
| `xedo.deliveryAreas` | `list` → `DeliveryArea[]` |
|
|
57
|
+
| `xedo.marketplace` | `retrieve` → `MarketplaceProfile` |
|
|
58
|
+
|
|
59
|
+
Every entity is fully typed (`Product`, `Order`, `Cart`, `Collection`, …). Note
|
|
60
|
+
that `list()`/`listAll()` return lightweight summary rows (`OrderListItem`,
|
|
61
|
+
`CartListItem`) while `retrieve()` returns the full detail object (`Order`,
|
|
62
|
+
`Cart`).
|
|
56
63
|
|
|
57
64
|
### Pagination
|
|
58
65
|
|
|
@@ -67,6 +74,13 @@ for await (const order of xedo.orders.listAll()) {
|
|
|
67
74
|
}
|
|
68
75
|
```
|
|
69
76
|
|
|
77
|
+
### Delivery areas & marketplace
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const profile = await xedo.marketplace.retrieve(); // payment config, business category…
|
|
81
|
+
const areas = await xedo.deliveryAreas.list(); // use area.id as delivery.deliveryAreaId
|
|
82
|
+
```
|
|
83
|
+
|
|
70
84
|
### Checkout
|
|
71
85
|
|
|
72
86
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -150,8 +150,8 @@ async function* paginate(fetchPage, params) {
|
|
|
150
150
|
// src/resources/carts.ts
|
|
151
151
|
var Carts = class extends Resource {
|
|
152
152
|
/**
|
|
153
|
-
* `GET /v1/carts` — one page of carts. `DRAFT` carts are
|
|
154
|
-
* the API.
|
|
153
|
+
* `GET /v1/carts` — one page of carts (summary rows). `DRAFT` carts are
|
|
154
|
+
* never exposed by the API.
|
|
155
155
|
*/
|
|
156
156
|
list(params = {}) {
|
|
157
157
|
return this.transport.getPage("/v1/carts", {
|
|
@@ -159,7 +159,7 @@ var Carts = class extends Resource {
|
|
|
159
159
|
signal: params.signal
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
-
/** Async iterator over every cart across all pages. */
|
|
162
|
+
/** Async iterator over every cart (summary row) across all pages. */
|
|
163
163
|
listAll(params = {}) {
|
|
164
164
|
return paginate((p) => this.list(p), params);
|
|
165
165
|
}
|
|
@@ -203,6 +203,10 @@ var Carts = class extends Resource {
|
|
|
203
203
|
* the payment provider could not be reached (`PAYMENT_INIT_FAILED`), retry
|
|
204
204
|
* `pay()` once with the same `returnUrl`. Stays transparent — it logs the
|
|
205
205
|
* code and never swallows a definitive failure.
|
|
206
|
+
*
|
|
207
|
+
* Returns a {@link CheckoutResult} on the happy path, or a
|
|
208
|
+
* {@link CheckoutRetryResult} when the retry succeeded — both carry
|
|
209
|
+
* `checkoutUrl` and `payment`.
|
|
206
210
|
*/
|
|
207
211
|
async createAndPay(input, opts = {}) {
|
|
208
212
|
try {
|
|
@@ -250,16 +254,42 @@ var Collections = class extends Resource {
|
|
|
250
254
|
}
|
|
251
255
|
};
|
|
252
256
|
|
|
257
|
+
// src/resources/delivery-areas.ts
|
|
258
|
+
var DeliveryAreas = class extends Resource {
|
|
259
|
+
/**
|
|
260
|
+
* `GET /v1/delivery-areas` — every delivery area configured by the merchant.
|
|
261
|
+
* Use a returned `id` as `delivery.deliveryAreaId` when creating a cart.
|
|
262
|
+
*/
|
|
263
|
+
list(opts = {}) {
|
|
264
|
+
return this.transport.getData("GET", "/v1/delivery-areas", {
|
|
265
|
+
signal: opts.signal
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// src/resources/marketplace.ts
|
|
271
|
+
var Marketplace = class extends Resource {
|
|
272
|
+
/**
|
|
273
|
+
* `GET /v1/marketplace` — the merchant's marketplace profile: enabled
|
|
274
|
+
* payment methods, split-payment configuration, business category, …
|
|
275
|
+
*/
|
|
276
|
+
retrieve(opts = {}) {
|
|
277
|
+
return this.transport.getData("GET", "/v1/marketplace", {
|
|
278
|
+
signal: opts.signal
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
253
283
|
// src/resources/orders.ts
|
|
254
284
|
var Orders = class extends Resource {
|
|
255
|
-
/** `GET /v1/orders` — one page of paid orders. */
|
|
285
|
+
/** `GET /v1/orders` — one page of paid orders (summary rows). */
|
|
256
286
|
list(params = {}) {
|
|
257
287
|
return this.transport.getPage("/v1/orders", {
|
|
258
288
|
query: toListQuery(params),
|
|
259
289
|
signal: params.signal
|
|
260
290
|
});
|
|
261
291
|
}
|
|
262
|
-
/** Async iterator over every order across all pages. */
|
|
292
|
+
/** Async iterator over every order (summary row) across all pages. */
|
|
263
293
|
listAll(params = {}) {
|
|
264
294
|
return paginate((p) => this.list(p), params);
|
|
265
295
|
}
|
|
@@ -499,6 +529,8 @@ var Xedo = class {
|
|
|
499
529
|
collections;
|
|
500
530
|
orders;
|
|
501
531
|
carts;
|
|
532
|
+
deliveryAreas;
|
|
533
|
+
marketplace;
|
|
502
534
|
apiKey;
|
|
503
535
|
transport;
|
|
504
536
|
constructor(options) {
|
|
@@ -538,6 +570,8 @@ var Xedo = class {
|
|
|
538
570
|
this.collections = new Collections(this.transport);
|
|
539
571
|
this.orders = new Orders(this.transport);
|
|
540
572
|
this.carts = new Carts(this.transport);
|
|
573
|
+
this.deliveryAreas = new DeliveryAreas(this.transport);
|
|
574
|
+
this.marketplace = new Marketplace(this.transport);
|
|
541
575
|
}
|
|
542
576
|
/**
|
|
543
577
|
* The environment inferred from the key prefix. The rest of the key is
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/resources/base.ts","../src/resources/carts.ts","../src/resources/collections.ts","../src/resources/orders.ts","../src/resources/products.ts","../src/transport.ts","../src/client.ts"],"sourcesContent":["export { Xedo, type XedoOptions } from './client';\nexport type { FetchLike } from './transport';\n\nexport {\n XedoError,\n XedoAuthError,\n XedoValidationError,\n XedoNotFoundError,\n XedoStockError,\n XedoConflictError,\n XedoRateLimitError,\n XedoPaymentInitError,\n XedoConnectionError,\n type XedoErrorParams,\n} from './errors';\n\nexport type {\n JsonObject,\n SortOrder,\n PingResult,\n Product,\n Collection,\n Order,\n Cart,\n CheckoutPreview,\n CheckoutResult,\n ListParams,\n ProductListParams,\n CollectionListParams,\n OrderListParams,\n CartListParams,\n RetrieveOptions,\n RequestOptions,\n PaginatedResult,\n RateLimitInfo,\n CheckoutItem,\n CheckoutDelivery,\n CheckoutCustomer,\n PaymentMethod,\n CheckoutPreviewInput,\n CheckoutCreateInput,\n CheckoutRetryPayInput,\n} from './types/public';\n","/**\n * Typed error hierarchy. Every `success: false` response (and every transport\n * failure) is thrown as a {@link XedoError} or one of its subclasses. Route on\n * `error.code` (stable, machine-readable), never on `error.message` (French,\n * subject to change).\n */\n\nexport interface XedoErrorParams {\n message: string;\n /** Machine-readable code, e.g. \"PRODUCT_NOT_FOUND\". */\n code: string;\n /** HTTP status (0 for transport/connection errors). */\n status: number;\n /** Per-field validation details. */\n errors?: Record<string, string[]>;\n /** Extra context (e.g. `cartPublicId` on PAYMENT_INIT_FAILED). */\n data?: unknown;\n /** Request id, when the API returns one. */\n requestId?: string;\n /** `Retry-After` value in seconds, when present. */\n retryAfter?: number;\n}\n\nexport class XedoError extends Error {\n readonly code: string;\n readonly status: number;\n readonly errors?: Record<string, string[]>;\n readonly data?: unknown;\n readonly requestId?: string;\n\n constructor(params: XedoErrorParams) {\n super(params.message);\n // Keep the concrete subclass name on instances created via `new.target`.\n this.name = new.target.name;\n this.code = params.code;\n this.status = params.status;\n this.errors = params.errors;\n this.data = params.data;\n this.requestId = params.requestId;\n // Restore the prototype chain for `instanceof` under transpiled targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** 401 — `MISSING_DEVELOPER_API_KEY`, `INVALID_DEVELOPER_API_KEY`. */\nexport class XedoAuthError extends XedoError {}\n\n/** 400 — bad request / invalid payment configuration. */\nexport class XedoValidationError extends XedoError {}\n\n/** 404 — product, combination, delivery area, cart or generic not found. */\nexport class XedoNotFoundError extends XedoError {}\n\n/** 422 — `INSUFFICIENT_STOCK` (per-product detail in `errors`). */\nexport class XedoStockError extends XedoError {}\n\n/** 409 — `CART_NOT_RETRYABLE`. */\nexport class XedoConflictError extends XedoError {}\n\n/** 429 — `RATE_LIMITED`. Exposes `retryAfter` (seconds). */\nexport class XedoRateLimitError extends XedoError {\n readonly retryAfter?: number;\n constructor(params: XedoErrorParams) {\n super(params);\n this.retryAfter = params.retryAfter;\n }\n}\n\n/**\n * 502 — `PAYMENT_INIT_FAILED`. The cart was kept; relaunch the payment via\n * `xedo.carts.pay(cartPublicId, …)`. Exposes `cartPublicId`.\n */\nexport class XedoPaymentInitError extends XedoError {\n readonly cartPublicId?: string;\n constructor(params: XedoErrorParams) {\n super(params);\n const data = params.data as { cartPublicId?: string } | undefined;\n this.cartPublicId = data?.cartPublicId;\n }\n}\n\n/** Transport-level failure (timeout, network, malformed response). */\nexport class XedoConnectionError extends XedoError {}\n\nconst CODE_MAP: Record<string, new (p: XedoErrorParams) => XedoError> = {\n MISSING_DEVELOPER_API_KEY: XedoAuthError,\n INVALID_DEVELOPER_API_KEY: XedoAuthError,\n BAD_REQUEST: XedoValidationError,\n INVALID_PAYMENT_METHOD: XedoValidationError,\n SPLIT_PAYMENT_NOT_ENABLED: XedoValidationError,\n COMBINATION_PRODUCT_MISMATCH: XedoValidationError,\n PRODUCT_NOT_FOUND: XedoNotFoundError,\n COMBINATION_NOT_FOUND: XedoNotFoundError,\n DELIVERY_AREA_NOT_FOUND: XedoNotFoundError,\n CART_NOT_FOUND: XedoNotFoundError,\n NOT_FOUND: XedoNotFoundError,\n INSUFFICIENT_STOCK: XedoStockError,\n CART_NOT_RETRYABLE: XedoConflictError,\n RATE_LIMITED: XedoRateLimitError,\n PAYMENT_INIT_FAILED: XedoPaymentInitError,\n};\n\nfunction fallbackByStatus(status: number): new (p: XedoErrorParams) => XedoError {\n switch (status) {\n case 400:\n return XedoValidationError;\n case 401:\n return XedoAuthError;\n case 404:\n return XedoNotFoundError;\n case 409:\n return XedoConflictError;\n case 422:\n return XedoStockError;\n case 429:\n return XedoRateLimitError;\n case 502:\n return XedoPaymentInitError;\n default:\n return XedoError;\n }\n}\n\n/** Build the most specific {@link XedoError} subclass for a failed response. */\nexport function createXedoError(params: XedoErrorParams): XedoError {\n const Ctor = CODE_MAP[params.code] ?? fallbackByStatus(params.status);\n return new Ctor(params);\n}\n","import type { Transport } from '../transport';\nimport type { ListParams, PaginatedResult } from '../types/public';\n\nexport abstract class Resource {\n constructor(protected readonly transport: Transport) {}\n}\n\n/** Map the SDK's camelCase list params to the API's wire query keys. */\nexport function toListQuery(params: ListParams): Record<string, unknown> {\n return {\n page: params.page,\n per_page: params.perPage,\n _sort: (params as { sort?: string }).sort,\n _order: params.order,\n search: params.search,\n };\n}\n\n/**\n * Walk every page of a list endpoint, yielding items one by one. Defaults to a\n * large page size to minimise round-trips; the transport's 429 retry provides\n * the throughput guard.\n */\nexport async function* paginate<T, P extends ListParams>(\n fetchPage: (params: P) => Promise<PaginatedResult<T>>,\n params: P,\n): AsyncGenerator<T> {\n let page = params.page ?? 1;\n const perPage = params.perPage ?? 100;\n for (;;) {\n const result = await fetchPage({ ...params, page, perPage });\n for (const item of result.data) yield item;\n if (result.data.length === 0 || result.end >= result.total) break;\n page += 1;\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport { XedoPaymentInitError } from '../errors';\nimport type {\n Cart,\n CartListParams,\n CheckoutCreateInput,\n CheckoutPreview,\n CheckoutPreviewInput,\n CheckoutResult,\n CheckoutRetryPayInput,\n PaginatedResult,\n RequestOptions,\n} from '../types/public';\n\nexport class Carts extends Resource {\n /**\n * `GET /v1/carts` — one page of carts. `DRAFT` carts are never exposed by\n * the API.\n */\n list(params: CartListParams = {}): Promise<PaginatedResult<Cart>> {\n return this.transport.getPage<Cart>('/v1/carts', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every cart across all pages. */\n listAll(params: CartListParams = {}): AsyncGenerator<Cart> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/carts/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Cart> {\n return this.transport.getData<Cart>('GET', `/v1/carts/${encodeURIComponent(publicId)}`, {\n signal: opts.signal,\n });\n }\n\n /** `POST /v1/carts/preview` — compute totals without persisting anything. */\n preview(input: CheckoutPreviewInput, opts: RequestOptions = {}): Promise<CheckoutPreview> {\n return this.transport.getData<CheckoutPreview>('POST', '/v1/carts/preview', {\n body: input,\n signal: opts.signal,\n });\n }\n\n /**\n * `POST /v1/carts` — create the cart (`PENDING_PAYMENT`) and return\n * `data.checkoutUrl`. On a `502 PAYMENT_INIT_FAILED` the cart is kept; retry\n * the payment with {@link Carts.pay} (or use {@link Carts.createAndPay}).\n */\n create(input: CheckoutCreateInput, opts: RequestOptions = {}): Promise<CheckoutResult> {\n return this.transport.getData<CheckoutResult>('POST', '/v1/carts', {\n body: input,\n signal: opts.signal,\n });\n }\n\n /**\n * `POST /v1/carts/{publicId}/pay` — relaunch payment initialization after a\n * `502 PAYMENT_INIT_FAILED`.\n */\n pay(publicId: string, input: CheckoutRetryPayInput, opts: RequestOptions = {}): Promise<CheckoutResult> {\n return this.transport.getData<CheckoutResult>(\n 'POST',\n `/v1/carts/${encodeURIComponent(publicId)}/pay`,\n { body: input, signal: opts.signal },\n );\n }\n\n /**\n * Convenience wrapper around the 502 checkout flow: create the cart, and if\n * the payment provider could not be reached (`PAYMENT_INIT_FAILED`), retry\n * `pay()` once with the same `returnUrl`. Stays transparent — it logs the\n * code and never swallows a definitive failure.\n */\n async createAndPay(input: CheckoutCreateInput, opts: RequestOptions = {}): Promise<CheckoutResult> {\n try {\n return await this.create(input, opts);\n } catch (err) {\n if (err instanceof XedoPaymentInitError && err.cartPublicId) {\n console.warn(\n `[xedo] PAYMENT_INIT_FAILED for cart ${err.cartPublicId}; retrying once via pay().`,\n );\n return this.pay(err.cartPublicId, { returnUrl: input.returnUrl }, opts);\n }\n throw err;\n }\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { Collection, CollectionListParams, PaginatedResult, RequestOptions } from '../types/public';\n\nexport class Collections extends Resource {\n /** `GET /v1/collections` — one page of collections. */\n list(params: CollectionListParams = {}): Promise<PaginatedResult<Collection>> {\n return this.transport.getPage<Collection>('/v1/collections', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every collection across all pages. */\n listAll(params: CollectionListParams = {}): AsyncGenerator<Collection> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/collections/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Collection> {\n return this.transport.getData<Collection>(\n 'GET',\n `/v1/collections/${encodeURIComponent(publicId)}`,\n { signal: opts.signal },\n );\n }\n\n /** `GET /v1/collections/by-slug/{slug}`. */\n retrieveBySlug(slug: string, opts: RequestOptions = {}): Promise<Collection> {\n return this.transport.getData<Collection>(\n 'GET',\n `/v1/collections/by-slug/${encodeURIComponent(slug)}`,\n { signal: opts.signal },\n );\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { Order, OrderListParams, PaginatedResult, RequestOptions } from '../types/public';\n\nexport class Orders extends Resource {\n /** `GET /v1/orders` — one page of paid orders. */\n list(params: OrderListParams = {}): Promise<PaginatedResult<Order>> {\n return this.transport.getPage<Order>('/v1/orders', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every order across all pages. */\n listAll(params: OrderListParams = {}): AsyncGenerator<Order> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/orders/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Order> {\n return this.transport.getData<Order>('GET', `/v1/orders/${encodeURIComponent(publicId)}`, {\n signal: opts.signal,\n });\n }\n\n /**\n * `GET /v1/orders/{publicId}/invoice` — the invoice PDF as a binary\n * `ArrayBuffer` (not JSON). Throws {@link XedoNotFoundError} if the invoice\n * has not been generated yet.\n */\n invoice(publicId: string, opts: RequestOptions = {}): Promise<ArrayBuffer> {\n return this.transport.getBinary('GET', `/v1/orders/${encodeURIComponent(publicId)}/invoice`, {\n accept: 'application/pdf',\n signal: opts.signal,\n });\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { PaginatedResult, Product, ProductListParams, RetrieveOptions } from '../types/public';\n\nexport class Products extends Resource {\n /** `GET /v1/products` — one page of products. */\n list(params: ProductListParams = {}): Promise<PaginatedResult<Product>> {\n return this.transport.getPage<Product>('/v1/products', {\n query: {\n ...toListQuery(params),\n collection: params.collection,\n includeVariations: params.includeVariations,\n includeDisabled: params.includeDisabled,\n },\n signal: params.signal,\n });\n }\n\n /** Async iterator over every product across all pages. */\n listAll(params: ProductListParams = {}): AsyncGenerator<Product> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/products/{publicId}`. */\n retrieve(publicId: string, opts: RetrieveOptions = {}): Promise<Product> {\n return this.transport.getData<Product>('GET', `/v1/products/${encodeURIComponent(publicId)}`, {\n query: { includeDisabled: opts.includeDisabled },\n signal: opts.signal,\n });\n }\n\n /** `GET /v1/products/by-slug/{slug}`. */\n retrieveBySlug(slug: string, opts: RetrieveOptions = {}): Promise<Product> {\n return this.transport.getData<Product>('GET', `/v1/products/by-slug/${encodeURIComponent(slug)}`, {\n query: { includeDisabled: opts.includeDisabled },\n signal: opts.signal,\n });\n }\n}\n","import { createXedoError, XedoConnectionError, type XedoErrorParams } from './errors';\nimport type { PaginatedResult, RateLimitInfo } from './types/public';\n\nexport type FetchLike = (\n input: string | URL,\n init?: RequestInit,\n) => Promise<Response>;\n\nexport interface TransportOptions {\n apiKey: string;\n baseUrl: string;\n maxRetries: number;\n timeoutMs: number;\n fetchImpl: FetchLike;\n}\n\nexport interface RequestConfig {\n query?: Record<string, unknown>;\n body?: unknown;\n signal?: AbortSignal;\n /** Accept header; defaults to `application/json`. */\n accept?: string;\n}\n\ntype HttpMethod = 'GET' | 'POST';\n\ninterface Envelope {\n success: boolean;\n code?: string;\n message?: string;\n errors?: Record<string, string[]>;\n data?: unknown;\n total?: number;\n start?: number;\n end?: number;\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason ?? new Error('Aborted'));\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason ?? new Error('Aborted'));\n };\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nfunction parseHeaderInt(value: string | null): number | null {\n if (value == null) return null;\n const n = Number(value);\n return Number.isFinite(n) ? n : null;\n}\n\n/**\n * Owns the HTTP concern: auth header, query/body serialization, per-request\n * timeout + abort, automatic 429 retries, envelope parsing and error mapping.\n * Resources sit on top and never touch `fetch` directly.\n */\nexport class Transport {\n lastRateLimit: RateLimitInfo | null = null;\n\n constructor(private readonly opts: TransportOptions) {}\n\n // --- Public helpers used by resources --------------------------------------\n\n /** Run a request and return the unwrapped `data` payload, typed as `T`. */\n async getData<T>(method: HttpMethod, path: string, config: RequestConfig = {}): Promise<T> {\n const env = await this.requestJson(method, path, config);\n return env.data as T;\n }\n\n /** Run a GET list request and return `{ data, total, start, end }`. */\n async getPage<T>(path: string, config: RequestConfig = {}): Promise<PaginatedResult<T>> {\n const env = await this.requestJson('GET', path, config);\n return {\n data: (env.data as T[]) ?? [],\n total: env.total ?? 0,\n start: env.start ?? 0,\n end: env.end ?? 0,\n };\n }\n\n /** Run a request that returns a binary body (e.g. the invoice PDF). */\n async getBinary(method: HttpMethod, path: string, config: RequestConfig = {}): Promise<ArrayBuffer> {\n const res = await this.execute(method, path, config);\n if (!res.ok) {\n throw this.toError(res, await this.tryParseJson(res));\n }\n return res.arrayBuffer();\n }\n\n // --- Internals -------------------------------------------------------------\n\n private async requestJson(method: HttpMethod, path: string, config: RequestConfig): Promise<Envelope> {\n const res = await this.execute(method, path, config);\n const body = await this.tryParseJson(res);\n if (!res.ok || body?.success === false) {\n throw this.toError(res, body);\n }\n if (!body) {\n throw new XedoConnectionError({\n code: 'INVALID_RESPONSE',\n status: res.status,\n message: 'Expected a JSON response body but received none.',\n });\n }\n return body;\n }\n\n private async tryParseJson(res: Response): Promise<Envelope | undefined> {\n const text = await res.text();\n if (!text) return undefined;\n try {\n return JSON.parse(text) as Envelope;\n } catch {\n return undefined;\n }\n }\n\n private toError(res: Response, body: Envelope | undefined): Error {\n const retryAfter = parseHeaderInt(res.headers.get('retry-after'));\n const params: XedoErrorParams = {\n code: body?.code ?? `HTTP_${res.status}`,\n message: body?.message ?? res.statusText ?? 'Request failed',\n status: res.status,\n errors: body?.errors,\n data: body?.data,\n requestId: res.headers.get('x-request-id') ?? undefined,\n retryAfter: retryAfter ?? undefined,\n };\n return createXedoError(params);\n }\n\n /** Fetch with retry on 429; returns the final {@link Response}. */\n private async execute(method: HttpMethod, path: string, config: RequestConfig): Promise<Response> {\n const url = this.buildUrl(path, config.query);\n let attempt = 0;\n for (;;) {\n const res = await this.fetchOnce(method, url, config);\n this.captureRateLimit(res);\n if (res.status === 429 && attempt < this.opts.maxRetries) {\n await sleep(this.retryDelayMs(res, attempt), config.signal);\n attempt += 1;\n continue;\n }\n return res;\n }\n }\n\n private async fetchOnce(method: HttpMethod, url: URL, config: RequestConfig): Promise<Response> {\n const controller = new AbortController();\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, this.opts.timeoutMs);\n\n const userSignal = config.signal;\n const onUserAbort = () => controller.abort();\n if (userSignal) {\n if (userSignal.aborted) controller.abort();\n else userSignal.addEventListener('abort', onUserAbort, { once: true });\n }\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.opts.apiKey}`,\n Accept: config.accept ?? 'application/json',\n };\n let body: string | undefined;\n if (config.body !== undefined) {\n headers['Content-Type'] = 'application/json';\n body = JSON.stringify(config.body);\n }\n\n try {\n return await this.opts.fetchImpl(url, { method, headers, body, signal: controller.signal });\n } catch (err) {\n if (timedOut) {\n throw new XedoConnectionError({\n code: 'TIMEOUT',\n status: 0,\n message: `Request to ${url.pathname} timed out after ${this.opts.timeoutMs}ms.`,\n });\n }\n // Genuine user-initiated cancellation: surface it untouched.\n if (userSignal?.aborted) throw err;\n throw new XedoConnectionError({\n code: 'CONNECTION_ERROR',\n status: 0,\n message: err instanceof Error ? err.message : 'Network request failed.',\n });\n } finally {\n clearTimeout(timer);\n userSignal?.removeEventListener('abort', onUserAbort);\n }\n }\n\n private buildUrl(path: string, query: Record<string, unknown> | undefined): URL {\n const url = new URL(this.opts.baseUrl.replace(/\\/+$/, '') + path);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url;\n }\n\n private captureRateLimit(res: Response): void {\n const limit = parseHeaderInt(res.headers.get('x-ratelimit-limit'));\n const remaining = parseHeaderInt(res.headers.get('x-ratelimit-remaining'));\n const reset = parseHeaderInt(res.headers.get('x-ratelimit-reset'));\n if (limit === null && remaining === null && reset === null) return;\n this.lastRateLimit = { limit, remaining, reset };\n }\n\n private retryDelayMs(res: Response, attempt: number): number {\n const retryAfter = parseHeaderInt(res.headers.get('retry-after'));\n if (retryAfter !== null) return retryAfter * 1000;\n // Exponential backoff with jitter: 500ms, 1s, 2s, … capped at 8s.\n const base = Math.min(8000, 500 * 2 ** attempt);\n return base + Math.random() * base * 0.25;\n }\n}\n","import { XedoConnectionError, XedoError } from './errors';\nimport { Carts } from './resources/carts';\nimport { Collections } from './resources/collections';\nimport { Orders } from './resources/orders';\nimport { Products } from './resources/products';\nimport { Transport, type FetchLike } from './transport';\nimport type { PingResult, RateLimitInfo, RequestOptions } from './types/public';\n\nconst DEFAULT_BASE_URL = 'https://systems.xedoapp.com/marketplace';\nconst DEFAULT_MAX_RETRIES = 4;\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nexport interface XedoOptions {\n /** Developer API key: `xdk_live_…` or `xdk_test_…`. */\n apiKey: string;\n /** Override the API base URL. Defaults to the production marketplace URL. */\n baseUrl?: string;\n /** Max automatic retries on `429`. Defaults to 4. */\n maxRetries?: number;\n /** Per-request timeout in milliseconds. Defaults to 30000. */\n timeoutMs?: number;\n /** Inject a custom fetch (tests, edge runtimes). Defaults to global fetch. */\n fetch?: FetchLike;\n /**\n * Escape hatch to run in a browser. Strongly discouraged: your\n * `xdk_live_…` key would be exposed in the client bundle.\n */\n dangerouslyAllowBrowser?: boolean;\n}\n\n/**\n * The Xedo Developer API client. Server-side only — see\n * `dangerouslyAllowBrowser`.\n *\n * ```ts\n * const xedo = new Xedo({ apiKey: process.env.XEDO_API_KEY! });\n * const { data } = await xedo.products.list({ perPage: 20 });\n * ```\n */\nexport class Xedo {\n readonly products: Products;\n readonly collections: Collections;\n readonly orders: Orders;\n readonly carts: Carts;\n\n private readonly apiKey: string;\n private readonly transport: Transport;\n\n constructor(options: XedoOptions) {\n if (!options?.apiKey) {\n throw new XedoError({\n code: 'MISSING_DEVELOPER_API_KEY',\n status: 0,\n message: 'A Xedo `apiKey` is required.',\n });\n }\n\n const maybeWindow = (globalThis as { window?: { document?: unknown } }).window;\n const isBrowser = typeof maybeWindow !== 'undefined' && typeof maybeWindow.document !== 'undefined';\n if (isBrowser && !options.dangerouslyAllowBrowser) {\n throw new XedoError({\n code: 'BROWSER_ENV_DETECTED',\n status: 0,\n message:\n 'The Xedo SDK is server-side only: running it in a browser would expose your ' +\n 'xdk_live_… key in the client bundle. Call it from a server (Next.js Server ' +\n 'Component / Route Handler, Express, a worker, …). See the README on authentication.',\n });\n }\n\n const fetchImpl: FetchLike =\n options.fetch ?? ((input, init) => globalThis.fetch(input, init));\n if (typeof globalThis.fetch !== 'function' && !options.fetch) {\n throw new XedoConnectionError({\n code: 'NO_FETCH',\n status: 0,\n message: 'Global fetch is unavailable (Node >= 18 required) — pass `options.fetch`.',\n });\n }\n\n this.apiKey = options.apiKey;\n this.transport = new Transport({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,\n maxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES,\n timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetchImpl,\n });\n\n this.products = new Products(this.transport);\n this.collections = new Collections(this.transport);\n this.orders = new Orders(this.transport);\n this.carts = new Carts(this.transport);\n }\n\n /**\n * The environment inferred from the key prefix. The rest of the key is\n * treated as opaque.\n */\n get environment(): 'test' | 'live' | 'unknown' {\n if (this.apiKey.startsWith('xdk_live_')) return 'live';\n if (this.apiKey.startsWith('xdk_test_')) return 'test';\n return 'unknown';\n }\n\n /** Rate-limit headers from the most recent response, for monitoring. */\n get lastRateLimit(): RateLimitInfo | null {\n return this.transport.lastRateLimit;\n }\n\n /** `GET /v1/ping` — validate the API key end to end. */\n ping(opts: RequestOptions = {}): Promise<PingResult> {\n return this.transport.getData<PingResult>('GET', '/v1/ping', { signal: opts.signal });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuBO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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src/resources/collections.ts","../src/resources/delivery-areas.ts","../src/resources/marketplace.ts","../src/resources/orders.ts","../src/resources/products.ts","../src/transport.ts","../src/client.ts"],"sourcesContent":["export { Xedo, type XedoOptions } from './client';\nexport type { FetchLike } from './transport';\n\nexport {\n XedoError,\n XedoAuthError,\n XedoValidationError,\n XedoNotFoundError,\n XedoStockError,\n XedoConflictError,\n XedoRateLimitError,\n XedoPaymentInitError,\n XedoConnectionError,\n type XedoErrorParams,\n} from './errors';\n\nexport type {\n JsonObject,\n SortOrder,\n // Enums\n OrderStatus,\n CartStatus,\n FulfillmentStatus,\n DeliveryType,\n PaymentStatus,\n OrderPaymentMethod,\n PriceAdjustmentType,\n MediaType,\n // Entities\n PingResult,\n Product,\n ProductCollection,\n ProductGalleryMedia,\n ProductVariation,\n ProductVariationOption,\n ProductCombination,\n Collection,\n Order,\n OrderListItem,\n OrderCustomer,\n OrderPayment,\n OrderItem,\n OrderTotals,\n OrderDelivery,\n Cart,\n CartListItem,\n CartCustomer,\n CartItem,\n CartTotals,\n CartDelivery,\n CheckoutPreview,\n CheckoutTotals,\n CheckoutPayment,\n CheckoutResult,\n CheckoutRetryResult,\n DeliveryArea,\n BusinessCategory,\n MarketplaceProfile,\n // List / request params\n ListParams,\n ProductListParams,\n CollectionListParams,\n OrderListParams,\n CartListParams,\n RetrieveOptions,\n RequestOptions,\n PaginatedResult,\n RateLimitInfo,\n // Checkout inputs\n CheckoutItem,\n CheckoutDelivery,\n CheckoutCustomer,\n PaymentMethod,\n CheckoutPreviewInput,\n CheckoutCreateInput,\n CheckoutRetryPayInput,\n} from './types/public';\n","/**\n * Typed error hierarchy. Every `success: false` response (and every transport\n * failure) is thrown as a {@link XedoError} or one of its subclasses. Route on\n * `error.code` (stable, machine-readable), never on `error.message` (French,\n * subject to change).\n */\n\nexport interface XedoErrorParams {\n message: string;\n /** Machine-readable code, e.g. \"PRODUCT_NOT_FOUND\". */\n code: string;\n /** HTTP status (0 for transport/connection errors). */\n status: number;\n /** Per-field validation details. */\n errors?: Record<string, string[]>;\n /** Extra context (e.g. `cartPublicId` on PAYMENT_INIT_FAILED). */\n data?: unknown;\n /** Request id, when the API returns one. */\n requestId?: string;\n /** `Retry-After` value in seconds, when present. */\n retryAfter?: number;\n}\n\nexport class XedoError extends Error {\n readonly code: string;\n readonly status: number;\n readonly errors?: Record<string, string[]>;\n readonly data?: unknown;\n readonly requestId?: string;\n\n constructor(params: XedoErrorParams) {\n super(params.message);\n // Keep the concrete subclass name on instances created via `new.target`.\n this.name = new.target.name;\n this.code = params.code;\n this.status = params.status;\n this.errors = params.errors;\n this.data = params.data;\n this.requestId = params.requestId;\n // Restore the prototype chain for `instanceof` under transpiled targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** 401 — `MISSING_DEVELOPER_API_KEY`, `INVALID_DEVELOPER_API_KEY`. */\nexport class XedoAuthError extends XedoError {}\n\n/** 400 — bad request / invalid payment configuration. */\nexport class XedoValidationError extends XedoError {}\n\n/** 404 — product, combination, delivery area, cart or generic not found. */\nexport class XedoNotFoundError extends XedoError {}\n\n/** 422 — `INSUFFICIENT_STOCK` (per-product detail in `errors`). */\nexport class XedoStockError extends XedoError {}\n\n/** 409 — `CART_NOT_RETRYABLE`. */\nexport class XedoConflictError extends XedoError {}\n\n/** 429 — `RATE_LIMITED`. Exposes `retryAfter` (seconds). */\nexport class XedoRateLimitError extends XedoError {\n readonly retryAfter?: number;\n constructor(params: XedoErrorParams) {\n super(params);\n this.retryAfter = params.retryAfter;\n }\n}\n\n/**\n * 502 — `PAYMENT_INIT_FAILED`. The cart was kept; relaunch the payment via\n * `xedo.carts.pay(cartPublicId, …)`. Exposes `cartPublicId`.\n */\nexport class XedoPaymentInitError extends XedoError {\n readonly cartPublicId?: string;\n constructor(params: XedoErrorParams) {\n super(params);\n const data = params.data as { cartPublicId?: string } | undefined;\n this.cartPublicId = data?.cartPublicId;\n }\n}\n\n/** Transport-level failure (timeout, network, malformed response). */\nexport class XedoConnectionError extends XedoError {}\n\nconst CODE_MAP: Record<string, new (p: XedoErrorParams) => XedoError> = {\n MISSING_DEVELOPER_API_KEY: XedoAuthError,\n INVALID_DEVELOPER_API_KEY: XedoAuthError,\n BAD_REQUEST: XedoValidationError,\n INVALID_PAYMENT_METHOD: XedoValidationError,\n SPLIT_PAYMENT_NOT_ENABLED: XedoValidationError,\n COMBINATION_PRODUCT_MISMATCH: XedoValidationError,\n PRODUCT_NOT_FOUND: XedoNotFoundError,\n COMBINATION_NOT_FOUND: XedoNotFoundError,\n DELIVERY_AREA_NOT_FOUND: XedoNotFoundError,\n CART_NOT_FOUND: XedoNotFoundError,\n NOT_FOUND: XedoNotFoundError,\n INSUFFICIENT_STOCK: XedoStockError,\n CART_NOT_RETRYABLE: XedoConflictError,\n RATE_LIMITED: XedoRateLimitError,\n PAYMENT_INIT_FAILED: XedoPaymentInitError,\n};\n\nfunction fallbackByStatus(status: number): new (p: XedoErrorParams) => XedoError {\n switch (status) {\n case 400:\n return XedoValidationError;\n case 401:\n return XedoAuthError;\n case 404:\n return XedoNotFoundError;\n case 409:\n return XedoConflictError;\n case 422:\n return XedoStockError;\n case 429:\n return XedoRateLimitError;\n case 502:\n return XedoPaymentInitError;\n default:\n return XedoError;\n }\n}\n\n/** Build the most specific {@link XedoError} subclass for a failed response. */\nexport function createXedoError(params: XedoErrorParams): XedoError {\n const Ctor = CODE_MAP[params.code] ?? fallbackByStatus(params.status);\n return new Ctor(params);\n}\n","import type { Transport } from '../transport';\nimport type { ListParams, PaginatedResult } from '../types/public';\n\nexport abstract class Resource {\n constructor(protected readonly transport: Transport) {}\n}\n\n/** Map the SDK's camelCase list params to the API's wire query keys. */\nexport function toListQuery(params: ListParams): Record<string, unknown> {\n return {\n page: params.page,\n per_page: params.perPage,\n _sort: (params as { sort?: string }).sort,\n _order: params.order,\n search: params.search,\n };\n}\n\n/**\n * Walk every page of a list endpoint, yielding items one by one. Defaults to a\n * large page size to minimise round-trips; the transport's 429 retry provides\n * the throughput guard.\n */\nexport async function* paginate<T, P extends ListParams>(\n fetchPage: (params: P) => Promise<PaginatedResult<T>>,\n params: P,\n): AsyncGenerator<T> {\n let page = params.page ?? 1;\n const perPage = params.perPage ?? 100;\n for (;;) {\n const result = await fetchPage({ ...params, page, perPage });\n for (const item of result.data) yield item;\n if (result.data.length === 0 || result.end >= result.total) break;\n page += 1;\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport { XedoPaymentInitError } from '../errors';\nimport type {\n Cart,\n CartListItem,\n CartListParams,\n CheckoutCreateInput,\n CheckoutPreview,\n CheckoutPreviewInput,\n CheckoutResult,\n CheckoutRetryPayInput,\n CheckoutRetryResult,\n PaginatedResult,\n RequestOptions,\n} from '../types/public';\n\nexport class Carts extends Resource {\n /**\n * `GET /v1/carts` — one page of carts (summary rows). `DRAFT` carts are\n * never exposed by the API.\n */\n list(params: CartListParams = {}): Promise<PaginatedResult<CartListItem>> {\n return this.transport.getPage<CartListItem>('/v1/carts', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every cart (summary row) across all pages. */\n listAll(params: CartListParams = {}): AsyncGenerator<CartListItem> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/carts/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Cart> {\n return this.transport.getData<Cart>('GET', `/v1/carts/${encodeURIComponent(publicId)}`, {\n signal: opts.signal,\n });\n }\n\n /** `POST /v1/carts/preview` — compute totals without persisting anything. */\n preview(input: CheckoutPreviewInput, opts: RequestOptions = {}): Promise<CheckoutPreview> {\n return this.transport.getData<CheckoutPreview>('POST', '/v1/carts/preview', {\n body: input,\n signal: opts.signal,\n });\n }\n\n /**\n * `POST /v1/carts` — create the cart (`PENDING_PAYMENT`) and return\n * `data.checkoutUrl`. On a `502 PAYMENT_INIT_FAILED` the cart is kept; retry\n * the payment with {@link Carts.pay} (or use {@link Carts.createAndPay}).\n */\n create(input: CheckoutCreateInput, opts: RequestOptions = {}): Promise<CheckoutResult> {\n return this.transport.getData<CheckoutResult>('POST', '/v1/carts', {\n body: input,\n signal: opts.signal,\n });\n }\n\n /**\n * `POST /v1/carts/{publicId}/pay` — relaunch payment initialization after a\n * `502 PAYMENT_INIT_FAILED`.\n */\n pay(publicId: string, input: CheckoutRetryPayInput, opts: RequestOptions = {}): Promise<CheckoutRetryResult> {\n return this.transport.getData<CheckoutRetryResult>(\n 'POST',\n `/v1/carts/${encodeURIComponent(publicId)}/pay`,\n { body: input, signal: opts.signal },\n );\n }\n\n /**\n * Convenience wrapper around the 502 checkout flow: create the cart, and if\n * the payment provider could not be reached (`PAYMENT_INIT_FAILED`), retry\n * `pay()` once with the same `returnUrl`. Stays transparent — it logs the\n * code and never swallows a definitive failure.\n *\n * Returns a {@link CheckoutResult} on the happy path, or a\n * {@link CheckoutRetryResult} when the retry succeeded — both carry\n * `checkoutUrl` and `payment`.\n */\n async createAndPay(\n input: CheckoutCreateInput,\n opts: RequestOptions = {},\n ): Promise<CheckoutResult | CheckoutRetryResult> {\n try {\n return await this.create(input, opts);\n } catch (err) {\n if (err instanceof XedoPaymentInitError && err.cartPublicId) {\n console.warn(\n `[xedo] PAYMENT_INIT_FAILED for cart ${err.cartPublicId}; retrying once via pay().`,\n );\n return this.pay(err.cartPublicId, { returnUrl: input.returnUrl }, opts);\n }\n throw err;\n }\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { Collection, CollectionListParams, PaginatedResult, RequestOptions } from '../types/public';\n\nexport class Collections extends Resource {\n /** `GET /v1/collections` — one page of collections. */\n list(params: CollectionListParams = {}): Promise<PaginatedResult<Collection>> {\n return this.transport.getPage<Collection>('/v1/collections', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every collection across all pages. */\n listAll(params: CollectionListParams = {}): AsyncGenerator<Collection> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/collections/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Collection> {\n return this.transport.getData<Collection>(\n 'GET',\n `/v1/collections/${encodeURIComponent(publicId)}`,\n { signal: opts.signal },\n );\n }\n\n /** `GET /v1/collections/by-slug/{slug}`. */\n retrieveBySlug(slug: string, opts: RequestOptions = {}): Promise<Collection> {\n return this.transport.getData<Collection>(\n 'GET',\n `/v1/collections/by-slug/${encodeURIComponent(slug)}`,\n { signal: opts.signal },\n );\n }\n}\n","import { Resource } from './base';\nimport type { DeliveryArea, RequestOptions } from '../types/public';\n\nexport class DeliveryAreas extends Resource {\n /**\n * `GET /v1/delivery-areas` — every delivery area configured by the merchant.\n * Use a returned `id` as `delivery.deliveryAreaId` when creating a cart.\n */\n list(opts: RequestOptions = {}): Promise<DeliveryArea[]> {\n return this.transport.getData<DeliveryArea[]>('GET', '/v1/delivery-areas', {\n signal: opts.signal,\n });\n }\n}\n","import { Resource } from './base';\nimport type { MarketplaceProfile, RequestOptions } from '../types/public';\n\nexport class Marketplace extends Resource {\n /**\n * `GET /v1/marketplace` — the merchant's marketplace profile: enabled\n * payment methods, split-payment configuration, business category, …\n */\n retrieve(opts: RequestOptions = {}): Promise<MarketplaceProfile> {\n return this.transport.getData<MarketplaceProfile>('GET', '/v1/marketplace', {\n signal: opts.signal,\n });\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { Order, OrderListItem, OrderListParams, PaginatedResult, RequestOptions } from '../types/public';\n\nexport class Orders extends Resource {\n /** `GET /v1/orders` — one page of paid orders (summary rows). */\n list(params: OrderListParams = {}): Promise<PaginatedResult<OrderListItem>> {\n return this.transport.getPage<OrderListItem>('/v1/orders', {\n query: toListQuery(params),\n signal: params.signal,\n });\n }\n\n /** Async iterator over every order (summary row) across all pages. */\n listAll(params: OrderListParams = {}): AsyncGenerator<OrderListItem> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/orders/{publicId}`. */\n retrieve(publicId: string, opts: RequestOptions = {}): Promise<Order> {\n return this.transport.getData<Order>('GET', `/v1/orders/${encodeURIComponent(publicId)}`, {\n signal: opts.signal,\n });\n }\n\n /**\n * `GET /v1/orders/{publicId}/invoice` — the invoice PDF as a binary\n * `ArrayBuffer` (not JSON). Throws {@link XedoNotFoundError} if the invoice\n * has not been generated yet.\n */\n invoice(publicId: string, opts: RequestOptions = {}): Promise<ArrayBuffer> {\n return this.transport.getBinary('GET', `/v1/orders/${encodeURIComponent(publicId)}/invoice`, {\n accept: 'application/pdf',\n signal: opts.signal,\n });\n }\n}\n","import { paginate, Resource, toListQuery } from './base';\nimport type { PaginatedResult, Product, ProductListParams, RetrieveOptions } from '../types/public';\n\nexport class Products extends Resource {\n /** `GET /v1/products` — one page of products. */\n list(params: ProductListParams = {}): Promise<PaginatedResult<Product>> {\n return this.transport.getPage<Product>('/v1/products', {\n query: {\n ...toListQuery(params),\n collection: params.collection,\n includeVariations: params.includeVariations,\n includeDisabled: params.includeDisabled,\n },\n signal: params.signal,\n });\n }\n\n /** Async iterator over every product across all pages. */\n listAll(params: ProductListParams = {}): AsyncGenerator<Product> {\n return paginate((p) => this.list(p), params);\n }\n\n /** `GET /v1/products/{publicId}`. */\n retrieve(publicId: string, opts: RetrieveOptions = {}): Promise<Product> {\n return this.transport.getData<Product>('GET', `/v1/products/${encodeURIComponent(publicId)}`, {\n query: { includeDisabled: opts.includeDisabled },\n signal: opts.signal,\n });\n }\n\n /** `GET /v1/products/by-slug/{slug}`. */\n retrieveBySlug(slug: string, opts: RetrieveOptions = {}): Promise<Product> {\n return this.transport.getData<Product>('GET', `/v1/products/by-slug/${encodeURIComponent(slug)}`, {\n query: { includeDisabled: opts.includeDisabled },\n signal: opts.signal,\n });\n }\n}\n","import { createXedoError, XedoConnectionError, type XedoErrorParams } from './errors';\nimport type { PaginatedResult, RateLimitInfo } from './types/public';\n\nexport type FetchLike = (\n input: string | URL,\n init?: RequestInit,\n) => Promise<Response>;\n\nexport interface TransportOptions {\n apiKey: string;\n baseUrl: string;\n maxRetries: number;\n timeoutMs: number;\n fetchImpl: FetchLike;\n}\n\nexport interface RequestConfig {\n query?: Record<string, unknown>;\n body?: unknown;\n signal?: AbortSignal;\n /** Accept header; defaults to `application/json`. */\n accept?: string;\n}\n\ntype HttpMethod = 'GET' | 'POST';\n\ninterface Envelope {\n success: boolean;\n code?: string;\n message?: string;\n errors?: Record<string, string[]>;\n data?: unknown;\n total?: number;\n start?: number;\n end?: number;\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason ?? new Error('Aborted'));\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason ?? new Error('Aborted'));\n };\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nfunction parseHeaderInt(value: string | null): number | null {\n if (value == null) return null;\n const n = Number(value);\n return Number.isFinite(n) ? n : null;\n}\n\n/**\n * Owns the HTTP concern: auth header, query/body serialization, per-request\n * timeout + abort, automatic 429 retries, envelope parsing and error mapping.\n * Resources sit on top and never touch `fetch` directly.\n */\nexport class Transport {\n lastRateLimit: RateLimitInfo | null = null;\n\n constructor(private readonly opts: TransportOptions) {}\n\n // --- Public helpers used by resources --------------------------------------\n\n /** Run a request and return the unwrapped `data` payload, typed as `T`. */\n async getData<T>(method: HttpMethod, path: string, config: RequestConfig = {}): Promise<T> {\n const env = await this.requestJson(method, path, config);\n return env.data as T;\n }\n\n /** Run a GET list request and return `{ data, total, start, end }`. */\n async getPage<T>(path: string, config: RequestConfig = {}): Promise<PaginatedResult<T>> {\n const env = await this.requestJson('GET', path, config);\n return {\n data: (env.data as T[]) ?? [],\n total: env.total ?? 0,\n start: env.start ?? 0,\n end: env.end ?? 0,\n };\n }\n\n /** Run a request that returns a binary body (e.g. the invoice PDF). */\n async getBinary(method: HttpMethod, path: string, config: RequestConfig = {}): Promise<ArrayBuffer> {\n const res = await this.execute(method, path, config);\n if (!res.ok) {\n throw this.toError(res, await this.tryParseJson(res));\n }\n return res.arrayBuffer();\n }\n\n // --- Internals -------------------------------------------------------------\n\n private async requestJson(method: HttpMethod, path: string, config: RequestConfig): Promise<Envelope> {\n const res = await this.execute(method, path, config);\n const body = await this.tryParseJson(res);\n if (!res.ok || body?.success === false) {\n throw this.toError(res, body);\n }\n if (!body) {\n throw new XedoConnectionError({\n code: 'INVALID_RESPONSE',\n status: res.status,\n message: 'Expected a JSON response body but received none.',\n });\n }\n return body;\n }\n\n private async tryParseJson(res: Response): Promise<Envelope | undefined> {\n const text = await res.text();\n if (!text) return undefined;\n try {\n return JSON.parse(text) as Envelope;\n } catch {\n return undefined;\n }\n }\n\n private toError(res: Response, body: Envelope | undefined): Error {\n const retryAfter = parseHeaderInt(res.headers.get('retry-after'));\n const params: XedoErrorParams = {\n code: body?.code ?? `HTTP_${res.status}`,\n message: body?.message ?? res.statusText ?? 'Request failed',\n status: res.status,\n errors: body?.errors,\n data: body?.data,\n requestId: res.headers.get('x-request-id') ?? undefined,\n retryAfter: retryAfter ?? undefined,\n };\n return createXedoError(params);\n }\n\n /** Fetch with retry on 429; returns the final {@link Response}. */\n private async execute(method: HttpMethod, path: string, config: RequestConfig): Promise<Response> {\n const url = this.buildUrl(path, config.query);\n let attempt = 0;\n for (;;) {\n const res = await this.fetchOnce(method, url, config);\n this.captureRateLimit(res);\n if (res.status === 429 && attempt < this.opts.maxRetries) {\n await sleep(this.retryDelayMs(res, attempt), config.signal);\n attempt += 1;\n continue;\n }\n return res;\n }\n }\n\n private async fetchOnce(method: HttpMethod, url: URL, config: RequestConfig): Promise<Response> {\n const controller = new AbortController();\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, this.opts.timeoutMs);\n\n const userSignal = config.signal;\n const onUserAbort = () => controller.abort();\n if (userSignal) {\n if (userSignal.aborted) controller.abort();\n else userSignal.addEventListener('abort', onUserAbort, { once: true });\n }\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.opts.apiKey}`,\n Accept: config.accept ?? 'application/json',\n };\n let body: string | undefined;\n if (config.body !== undefined) {\n headers['Content-Type'] = 'application/json';\n body = JSON.stringify(config.body);\n }\n\n try {\n return await this.opts.fetchImpl(url, { method, headers, body, signal: controller.signal });\n } catch (err) {\n if (timedOut) {\n throw new XedoConnectionError({\n code: 'TIMEOUT',\n status: 0,\n message: `Request to ${url.pathname} timed out after ${this.opts.timeoutMs}ms.`,\n });\n }\n // Genuine user-initiated cancellation: surface it untouched.\n if (userSignal?.aborted) throw err;\n throw new XedoConnectionError({\n code: 'CONNECTION_ERROR',\n status: 0,\n message: err instanceof Error ? err.message : 'Network request failed.',\n });\n } finally {\n clearTimeout(timer);\n userSignal?.removeEventListener('abort', onUserAbort);\n }\n }\n\n private buildUrl(path: string, query: Record<string, unknown> | undefined): URL {\n const url = new URL(this.opts.baseUrl.replace(/\\/+$/, '') + path);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url;\n }\n\n private captureRateLimit(res: Response): void {\n const limit = parseHeaderInt(res.headers.get('x-ratelimit-limit'));\n const remaining = parseHeaderInt(res.headers.get('x-ratelimit-remaining'));\n const reset = parseHeaderInt(res.headers.get('x-ratelimit-reset'));\n if (limit === null && remaining === null && reset === null) return;\n this.lastRateLimit = { limit, remaining, reset };\n }\n\n private retryDelayMs(res: Response, attempt: number): number {\n const retryAfter = parseHeaderInt(res.headers.get('retry-after'));\n if (retryAfter !== null) return retryAfter * 1000;\n // Exponential backoff with jitter: 500ms, 1s, 2s, … capped at 8s.\n const base = Math.min(8000, 500 * 2 ** attempt);\n return base + Math.random() * base * 0.25;\n }\n}\n","import { XedoConnectionError, XedoError } from './errors';\nimport { Carts } from './resources/carts';\nimport { Collections } from './resources/collections';\nimport { DeliveryAreas } from './resources/delivery-areas';\nimport { Marketplace } from './resources/marketplace';\nimport { Orders } from './resources/orders';\nimport { Products } from './resources/products';\nimport { Transport, type FetchLike } from './transport';\nimport type { PingResult, RateLimitInfo, RequestOptions } from './types/public';\n\nconst DEFAULT_BASE_URL = 'https://systems.xedoapp.com/marketplace';\nconst DEFAULT_MAX_RETRIES = 4;\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nexport interface XedoOptions {\n /** Developer API key: `xdk_live_…` or `xdk_test_…`. */\n apiKey: string;\n /** Override the API base URL. Defaults to the production marketplace URL. */\n baseUrl?: string;\n /** Max automatic retries on `429`. Defaults to 4. */\n maxRetries?: number;\n /** Per-request timeout in milliseconds. Defaults to 30000. */\n timeoutMs?: number;\n /** Inject a custom fetch (tests, edge runtimes). Defaults to global fetch. */\n fetch?: FetchLike;\n /**\n * Escape hatch to run in a browser. Strongly discouraged: your\n * `xdk_live_…` key would be exposed in the client bundle.\n */\n dangerouslyAllowBrowser?: boolean;\n}\n\n/**\n * The Xedo Developer API client. Server-side only — see\n * `dangerouslyAllowBrowser`.\n *\n * ```ts\n * const xedo = new Xedo({ apiKey: process.env.XEDO_API_KEY! });\n * const { data } = await xedo.products.list({ perPage: 20 });\n * ```\n */\nexport class Xedo {\n readonly products: Products;\n readonly collections: Collections;\n readonly orders: Orders;\n readonly carts: Carts;\n readonly deliveryAreas: DeliveryAreas;\n readonly marketplace: Marketplace;\n\n private readonly apiKey: string;\n private readonly transport: Transport;\n\n constructor(options: XedoOptions) {\n if (!options?.apiKey) {\n throw new XedoError({\n code: 'MISSING_DEVELOPER_API_KEY',\n status: 0,\n message: 'A Xedo `apiKey` is required.',\n });\n }\n\n const maybeWindow = (globalThis as { window?: { document?: unknown } }).window;\n const isBrowser = typeof maybeWindow !== 'undefined' && typeof maybeWindow.document !== 'undefined';\n if (isBrowser && !options.dangerouslyAllowBrowser) {\n throw new XedoError({\n code: 'BROWSER_ENV_DETECTED',\n status: 0,\n message:\n 'The Xedo SDK is server-side only: running it in a browser would expose your ' +\n 'xdk_live_… key in the client bundle. Call it from a server (Next.js Server ' +\n 'Component / Route Handler, Express, a worker, …). See the README on authentication.',\n });\n }\n\n const fetchImpl: FetchLike =\n options.fetch ?? ((input, init) => globalThis.fetch(input, init));\n if (typeof globalThis.fetch !== 'function' && !options.fetch) {\n throw new XedoConnectionError({\n code: 'NO_FETCH',\n status: 0,\n message: 'Global fetch is unavailable (Node >= 18 required) — pass `options.fetch`.',\n });\n }\n\n this.apiKey = options.apiKey;\n this.transport = new Transport({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,\n maxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES,\n timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetchImpl,\n });\n\n this.products = new Products(this.transport);\n this.collections = new Collections(this.transport);\n this.orders = new Orders(this.transport);\n this.carts = new Carts(this.transport);\n this.deliveryAreas = new DeliveryAreas(this.transport);\n this.marketplace = new Marketplace(this.transport);\n }\n\n /**\n * The environment inferred from the key prefix. The rest of the key is\n * treated as opaque.\n */\n get environment(): 'test' | 'live' | 'unknown' {\n if (this.apiKey.startsWith('xdk_live_')) return 'live';\n if (this.apiKey.startsWith('xdk_test_')) return 'test';\n return 'unknown';\n }\n\n /** Rate-limit headers from the most recent response, for monitoring. */\n get lastRateLimit(): RateLimitInfo | null {\n return this.transport.lastRateLimit;\n }\n\n /** `GET /v1/ping` — validate the API key end to end. */\n ping(opts: RequestOptions = {}): Promise<PingResult> {\n return this.transport.getData<PingResult>('GET', '/v1/ping', { signal: opts.signal });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuBO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAyB;AACnC,UAAM,OAAO,OAAO;AAEpB,SAAK,OAAO,WAAW;AACvB,SAAK,OAAO,OAAO;AACnB,SAAK,SAAS,OA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