//#region src/core/commerce/fourthwall-platform.d.ts interface FourthwallPlatformConfig { /** API username from the Fourthwall dashboard. Server-only. */ username: string; /** API password. Server-only—never ship this to a browser. */ password: string; /** * Which shop these credentials belong to, for rate-limit accounting. * * Fourthwall counts its limits **per shop**, not per API user, so adding * users does not buy you more budget. The limiter keys its buckets on this * value; it defaults to `username`, which is right for the common * one-user-per-shop case and WRONG if you have several users on one shop—there * each would get its own bucket and the pair would overrun the real * limit together. Give every client for a shop the same string. */ rateLimitKey?: string; /** * Client-side rate limiting. On by default—see {@link FourthwallRateLimits} * for what it does and, more importantly, what it cannot do. Pass `false` to * opt out when you coordinate limits yourself. */ rateLimit?: FourthwallRateLimits | false; /** * Transient-failure retry. OFF by default, matching `commerce/square`: turn it * on for unattended paths (a cron sync, a queue consumer) where a 429 or a 5xx * should cost a second rather than fail the job. Never retries a 4xx other * than 429—those are our bug, not Fourthwall's weather. * * **Not safe to enable blindly on order creation.** Unlike Square, Fourthwall * has no idempotency-key header, so a retried `POST /external-orders` that * actually succeeded server-side creates a SECOND order. See * {@link createExternalOrder}. */ retry?: FourthwallRetryConfig; /** * Abandon a request after this long, per attempt. Default 10 s. * * A timed-out request has not necessarily failed: Fourthwall may have * received and applied it. For an order create—no idempotency key—treat * a timeout like the 5xx in {@link retry}: look before you try again. */ timeoutMs?: number; } interface FourthwallRetryConfig { /** Attempts AFTER the first try. 0 disables. Defaults to 2. */ attempts?: number; /** First backoff step in ms; doubles each attempt. Defaults to 250. */ baseDelayMs?: number; /** Ceiling for one backoff step. Defaults to 4000. */ maxDelayMs?: number; } /** * The two published limits, both counted per shop. * * Defaults match Fourthwall's documented numbers; override only to go *lower* * (say, to leave headroom for a second process). Raising them does not raise * the server's limit, it just moves where you find out. */ interface FourthwallRateLimits { /** Requests per 10 seconds, all endpoints. Default 100. */ globalPer10s?: number; /** `POST /products` per minute. Default 5. */ productCreatesPerMinute?: number; } /** * Drop every cached rate-limit bucket. * * For tests, and for a long-lived process that rotates credentials—the map is * keyed by shop and would otherwise hold a bucket per key seen. Not needed in a * Worker, where the isolate's lifetime already bounds it. */ declare function resetFourthwallRateLimits(): void; /** Fourthwall money: major units (25 = $25.00), matching the Storefront API's * `FwMoney`. Kept separate from `commerce`'s minor-unit `Money` on purpose: * the two are not interchangeable and a shared name invites a 100× error. */ interface FwPlatformMoney { value: number; currency: string; } /** * A cost Fourthwall reports, in major units like {@link FwPlatformMoney}. * `currency` is the ISO 4217 code Fourthwall sent, or `null` when it sent * none. The toolkit doesn't guess a missing one: use the currency your site * sells in, `cost.currency ?? siteCurrency`. */ interface FwReportedMoney { value: number; currency: string | null; } /** One line of an external order. */ interface FwExternalOrderItem { variantId: string; quantity: number; } interface FwExternalOrderAddress { name: string; address1: string; address2?: string; city: string; /** State / province. */ state?: string; /** ISO 3166-1 alpha-2, for example, "US". */ country: string; zip: string; phone?: string; } interface FwExternalOrderInput { /** Your own order id. Fourthwall echoes it back, which is how you reconcile. */ externalId?: string; items: FwExternalOrderItem[]; shipping: FwExternalOrderAddress; email?: string; /** Anything else the Open API accepts; merged into the request body. */ [key: string]: unknown; } /** What an order will cost you, all in major units. Returned by * {@link validateExternalOrder} before you commit to anything. */ interface FwExternalOrderCosts { manufacturingCost: FwReportedMoney | null; fulfillmentFee: FwReportedMoney | null; shippingCost: FwReportedMoney | null; totalCreatorCost: FwReportedMoney | null; } interface FwExternalOrderValidation extends FwExternalOrderCosts { /** True when Fourthwall would accept this order as submitted. */ valid: boolean; /** Why not, when `valid` is false. Empty otherwise. */ problems: string[]; /** The raw response, for fields this interface doesn't name. */ raw: unknown; } /** Fourthwall's fulfillment state machine, as far as cancellation cares. */ type FwExternalOrderStatus = "PENDING" | "PROCESSING" | "PACKAGED" | "SHIPPED" | "CANCELLED" | "DELIVERED"; /** * A status that autocompletes to the known set but still accepts a string * Fourthwall adds later. * * The `(string & {})` is the trick that makes that work: a plain * `FwExternalOrderStatus | string` collapses to `string` during reduction and * you lose the completions entirely, which is the opposite of the intent. */ type FwOrderStatusLike = FwExternalOrderStatus | (string & {}); interface FwExternalOrder { id: string; externalId: string | null; status: FwOrderStatusLike; createdAt: string | null; /** The raw order, for fields this interface doesn't name. */ raw: unknown; } /** * Price an external order **without creating it**. * * Call this first, always. It is the only place the at-cost numbers—`manufacturingCost`, * `fulfillmentFee`, `shippingCost`, `totalCreatorCost`—are * available before money is committed, and an order you did not validate is * an order whose cost you learn by being billed for it. Shipping in particular * is not knowable up front: it depends on the destination and on how Fourthwall * splits the items across facilities. * * POST /external-orders/validate */ declare function validateExternalOrder(config: FourthwallPlatformConfig, order: FwExternalOrderInput): Promise; /** * Create an external order. Chargeable. * * **Fourthwall has no idempotency-key header.** A retried create that actually * succeeded server-side produces a SECOND order and a second charge, so this * call disables `config.retry` for itself rather than trusting a caller who * enabled retries globally for a sync job. If you need at-most-once across a * queue redelivery, that is yours to arrange: set `externalId`, and reconcile * with {@link listExternalOrders} before creating. * * POST /external-orders */ declare function createExternalOrder(config: FourthwallPlatformConfig, order: FwExternalOrderInput): Promise; interface FwListOrdersOptions { /** 0-based page index. */ page?: number; /** Page size. */ size?: number; status?: FwOrderStatusLike; } /** List external orders. GET /external-orders */ declare function listExternalOrders(config: FourthwallPlatformConfig, options?: FwListOrdersOptions): Promise; /** One external order, or null when it does not exist. * GET /external-orders/{id} */ declare function getExternalOrder(config: FourthwallPlatformConfig, id: string): Promise; /** * Cancel an external order. * * **Only possible early.** Once Fourthwall has moved the order to `PACKAGED` or * `SHIPPED` the goods physically exist and are moving, and the API refuses—which * surfaces here as the request throwing, not as a `false`. Check * {@link getExternalOrder} first if you want to branch rather than catch. * * POST /external-orders/{id}/cancel */ declare function cancelExternalOrder(config: FourthwallPlatformConfig, id: string): Promise; /** True for the two states Fourthwall will not cancel out of. Cheap local * check so a UI can hide the button rather than offer an action that throws. */ declare function isCancellable(order: Pick): boolean; interface FwInventoryEntry { variantId: string; /** Units available, or null when the variant is not stock-tracked. */ quantity: number | null; raw: unknown; } /** * Stock for one product's variants. **Read-only—Fourthwall has no inventory * write endpoint**, so a mirror can reflect stock but never push it. * * There is also **no inventory webhook**, which is the operationally important * half: stock drift is only detectable by polling. Pick an interval against how * bad an oversell is for you rather than against how fresh you would like the * number to be. * * GET /products/{id}/inventory */ declare function getProductInventory(config: FourthwallPlatformConfig, productId: string): Promise; /** * A physical product. Priced by **`profitMargin`, not by retail price**—you * choose what you make per unit and Fourthwall derives the price from that plus * its own cost. Setting an absolute price is not expressible, so a "price" field * copied over from another provider's model is silently ignored. */ interface FwPhysicalProductInput { kind: "physical"; name: string; description?: string; collectionId?: string; /** Your profit per unit, in major units. */ profitMargin: number; /** Anything else the Open API accepts; merged into the request body. */ [key: string]: unknown; } /** A digital product—the only kind that takes an absolute {@link price}. */ interface FwDigitalProductInput { kind: "digital"; name: string; description?: string; collectionId?: string; price: FwPlatformMoney; /** Anything else the Open API accepts; merged into the request body. */ [key: string]: unknown; } type FwProductInput = FwPhysicalProductInput | FwDigitalProductInput; interface FwPlatformProduct { id: string; name: string; slug: string | null; state: string | null; raw: unknown; } /** * Create a product. * * ## There is no update. Not "not yet"—none. * * The Platform API exposes no endpoint to change a product's name, description, * price, or variants after creation. {@link setProductAvailability} and * {@link setProductState} toggle whether an existing product is purchasable, and * {@link addProductImages} appends; nothing edits. If a detail is wrong, the * only remedy is {@link deleteProduct} and create again—which mints a NEW id, * so anything of yours keyed on the old one (a catalog mirror row, a saved cart, * an order line) has to be reconciled. * * Two consequences worth designing around: * * * Get it right the first time. Validate your own inputs before calling; * there is no correction pass. * * Do not treat product ids as stable across an edit. They are stable across * time and unstable across a "change", because a change is a re-create. * * ## Rate limit and latency * * This is the throttled endpoint: **5 per minute per shop**, and it also runs a * synchronous mockup render, so it is slow as well as rare. The client paces * itself (see {@link FourthwallRateLimits}) rather than failing—a bulk import * of 50 products takes ten minutes by design, and the alternative is 45 of them * erroring. * * POST /products */ declare function createProduct(config: FourthwallPlatformConfig, input: FwProductInput): Promise; /** * Delete a product. Permanent, and the only way to "edit" one—see * {@link createProduct}. DELETE /products/{id} */ declare function deleteProduct(config: FourthwallPlatformConfig, productId: string): Promise; /** * Whether a product can be bought at all. Distinct from * {@link setProductState}: availability is the shop-level switch, state is the * product's own lifecycle. * * POST /products/{id}/availability */ declare function setProductAvailability(config: FourthwallPlatformConfig, productId: string, available: boolean): Promise; /** Set a product's lifecycle state (for example, `"AVAILABLE"`, `"UNAVAILABLE"`). * POST /products/{id}/state */ declare function setProductState(config: FourthwallPlatformConfig, productId: string, state: string): Promise; /** * Append images to a product. **Appends**—there is no replace, and no update * (see {@link createProduct}), so an image added by mistake stays. * * POST /products/{id}/images */ declare function addProductImages(config: FourthwallPlatformConfig, productId: string, imageUrls: string[]): Promise; /** * Verify a Platform API webhook signature. * * Identical scheme to the Storefront webhooks—base64 HMAC-SHA256 of the raw * body in `X-Fourthwall-Hmac-SHA256`—but re-exported here so a server that * only imports the Platform module doesn't have to reach into the storefront * one, which is the import this module's whole split exists to discourage. * * `payload` must be the raw body text, read before any JSON parsing. */ declare function verifyFourthwallPlatformSignature(payload: string, header: string | null, secret: string): Promise; //#endregion export { FourthwallPlatformConfig, FourthwallRateLimits, FourthwallRetryConfig, FwDigitalProductInput, FwExternalOrder, FwExternalOrderAddress, FwExternalOrderCosts, FwExternalOrderInput, FwExternalOrderItem, FwExternalOrderStatus, FwExternalOrderValidation, FwInventoryEntry, FwListOrdersOptions, FwOrderStatusLike, FwPhysicalProductInput, FwPlatformMoney, FwPlatformProduct, FwProductInput, FwReportedMoney, addProductImages, cancelExternalOrder, createExternalOrder, createProduct, deleteProduct, getExternalOrder, getProductInventory, isCancellable, listExternalOrders, resetFourthwallRateLimits, setProductAvailability, setProductState, validateExternalOrder, verifyFourthwallPlatformSignature };