import { t as StandardSchemaV1 } from "../../standard-DIedMFAS.js"; //#region src/core/commerce/fourthwall.d.ts interface FwMoney { /** Amount in the currency's major unit (for example, 25 = $25.00) unless a live * store proves otherwise; mapped to products.price (whole dollars). */ value: number; currency: string; } interface FwImage { url: string; width?: number; height?: number; } interface FwVariantAttributes { color?: { name?: string; swatch?: string; }; size?: { name?: string; }; } interface FwStock { type?: "LIMITED" | "UNLIMITED"; inStock?: number; } interface FwVariant { id: string; name: string; sku?: string; unitPrice: FwMoney; compareAtPrice?: FwMoney | null; attributes?: FwVariantAttributes; stock?: FwStock; images?: FwImage[]; } /** * One panel of a product's "additional information"—the accordion under a * product on Fourthwall's storefront (More details, Size and fit, Guarantee and * returns). `ProductAdditionalInformationV1` in Fourthwall's OpenAPI spec. * Every member is optional: it is a shape we are told about, not one we control. */ interface FwAdditionalInformation { /** for example, `"MORE_DETAILS"`. */ type?: string; title?: string; bodyHtml?: string; } interface FwProduct { id: string; name: string; slug: string; description?: string; images: FwImage[]; variants: FwVariant[]; state?: "AVAILABLE" | "SOLD_OUT"; access?: string; /** The accordion panels—see {@link fourthwallCopy} for the one worth mirroring. */ additionalInformation?: FwAdditionalInformation[]; } interface FwCollection { id: string; name: string; slug: string; } /** All storefront collections (Prints, Totes, Buttons, Stickers, …). */ declare function listCollections(token: string): Promise; /** * Every product in a collection, following Fourthwall's paging to the end. * * This used to send no `page`/`size` and read whatever one page the server * chose to return—then hand it back as if it were the collection. The * failure is silent by construction: products past the first page do not * error, they simply never appear, and a consumer mirroring the catalog gets a * smaller shop with nothing to indicate it. It also gets worse the more the * store sells, so it looks like a store that works right up until it matters. * A real shop was two uploads from losing products this way. * * `size` is always sent because the omitted default is undocumented, and * `page` is 0-indexed per Fourthwall's docs. * * THROWS at {@link MAX_PAGES} rather than returning what it has. A truncated * catalog is worse than a failed call for the thing this feeds: a caller * reconciling its mirror against "everything Fourthwall has" will delete or * unpublish whatever it did not see. */ declare function getCollectionProducts(token: string, collectionSlug: string): Promise; interface FwCartItem { variantId: string; quantity: number; } /** * Create a Fourthwall cart from variant+quantity items. Returns the cart id, * which the checkout redirect carries: `${checkout}/checkout/?cartCurrency=…&cartId=…`. * POST /v1/carts { items: [{ variantId, quantity }] } → { id }. */ declare function createCart(token: string, items: FwCartItem[]): Promise<{ id: string; }>; /** A single product by slug (authoritative pricing for import). */ declare function getProduct(token: string, slug: string): Promise; /** Walk every collection and return its products together with the collection * they came from (Fourthwall does not put collection membership on the product, * so category has to come from the collection). In Fourthwall's order, which * puts the catch-all "All Products" LAST—pass the result through * {@link catchAllFirst} before any last-write-wins category assignment. */ declare function listCatalog(token: string): Promise<{ collection: FwCollection; products: FwProduct[]; }[]>; /** The host Fourthwall serves product images from (signed imgproxy URLs). */ declare const FW_IMAGE_HOST = "imgproxy.fourthwall.dev"; /** * Fourthwall's catch-all collection ("All Products"), which every product is * also in. It is a shelf holding the whole store, not a category. */ declare function isCatchAllCollection(collection: { slug: string; name: string; }): boolean; /** * {@link listCatalog}'s entries with the catch-all collection moved FIRST, the * rest in their original order. * * A product is in every collection it was filed under, so a sync that sets a * product's category per collection keeps whichever it wrote LAST. Fourthwall * returns the catch-all last—so every product also in "Prints" ends up * categorised "All Products". Catch-all first means a real collection always * has the final word, while a product filed nowhere else still gets one. */ declare function catchAllFirst(catalog: readonly T[]): T[]; interface FourthwallCopyOptions { /** The panel to read. Default `"MORE_DETAILS"`. */ panel?: string; /** * Called when the panel still carried compliance text after stripping and * was dropped. Fourthwall's markup changed, or the strip under-matched; log * it—the sync is declining copy it was given. */ onComplianceDropped?: (product: FwProduct) => void; } /** * The product copy worth mirroring: the More details panel with Fourthwall's * hidden compliance block removed, falling back to `description`. * * `description` alone is often empty—the copy a seller types lives in the * More details panel. And mirroring that panel verbatim would publish * Fourthwall's fulfilment address (and feed it to any meta description derived * from the copy) as if it were the seller's. The strip is a plain non-greedy * match, and if compliance text survives it the panel is dropped whole—so an * under-strip costs the copy, never a leak. * * HTML out; sanitize before rendering, as with any stored rich text. */ declare function fourthwallCopy(product: FwProduct, options?: FourthwallCopyOptions): string | null; /** Lowest variant price, in whole dollars, for the catalog "from" price. */ declare function lowestPrice(product: FwProduct): number; /** * Verify a Fourthwall webhook signature. Fourthwall sends the base64-encoded * HMAC-SHA256 of the raw request body in the `X-Fourthwall-Hmac-SHA256` header, * keyed by the webhook's signing secret. `payload` must be the raw body text. */ declare function verifyFourthwallSignature(payload: string, header: string | null, secret: string): Promise; /** A Fourthwall `order.*` webhook event, thinned to what the mapper reads. */ interface FourthwallOrderEvent { id?: string; type?: string; testMode?: boolean; data?: Record; } /** * Validate a Fourthwall webhook body into a {@link FourthwallOrderEvent}. Run it * via {@link import("./index.js").parseWebhookEvent} AFTER * {@link verifyFourthwallSignature}—the HMAC proves the sender, this proves * the envelope, then {@link mapFourthwallOrder} normalizes the (alias-heavy, * intentionally untyped) `data`. Only the envelope is schema-locked here: the * order body's field aliases (offers/items/lineItems, id/orderId, money as * object-or-number) stay tolerant in the mapper, since a strict inner schema * would reject—and so drop—a live order on any shape drift. */ declare const fourthwallOrderEventSchema: StandardSchemaV1 | undefined; }>; /** One line item on a normalized Fourthwall order. */ interface FourthwallOrderItem { slug: string | null; name: string; qty: number; /** Unit price in cents, or null when the payload omits it. */ unitPrice: number | null; } /** A coarse order lifecycle state derived from Fourthwall's status string. */ type FourthwallOrderStatus = "paid" | "fulfilled" | "canceled"; /** A Fourthwall order mapped to a normalized, storage-ready shape. The site * upserts this into its own `orders` table (idempotent on `fourthwallOrderId`). */ interface FourthwallOrder { fourthwallOrderId: string; orderNumber: string | null; email: string | null; /** Order total in cents. */ amount: number | null; currency: string | null; items: FourthwallOrderItem[]; shippingAddress: unknown; orderStatus: FourthwallOrderStatus; } /** Fourthwall money is `{ value, currency }` in major units (or a bare number); * normalize to integer cents. */ declare function fourthwallMoneyToCents(m: unknown): number | null; /** Map a Fourthwall status string to a coarse lifecycle state. */ declare function mapFourthwallOrderStatus(status: string | null): FourthwallOrderStatus; /** * Parse a Fourthwall `order.*` webhook event into a normalized {@link * FourthwallOrder}, or `null` when it carries no order id (nothing to record). * Defensive: Fourthwall payload shapes vary, so it reads several field aliases * (`id`/`orderId`, `friendlyId`/`number`, `total`/`amounts.total`/`amount`, * top-level or nested `customer.email`). The site upserts the result into its * own `orders` table, adding any site-schema columns (for example, `raw`, `fulfillment`). */ declare function mapFourthwallOrder(event: FourthwallOrderEvent): FourthwallOrder | null; //#endregion export { FW_IMAGE_HOST, FourthwallCopyOptions, FourthwallOrder, FourthwallOrderEvent, FourthwallOrderItem, FourthwallOrderStatus, FwAdditionalInformation, FwCartItem, FwCollection, FwImage, FwMoney, FwProduct, FwStock, FwVariant, FwVariantAttributes, catchAllFirst, createCart, fourthwallCopy, fourthwallMoneyToCents, fourthwallOrderEventSchema, getCollectionProducts, getProduct, isCatchAllCollection, listCatalog, listCollections, lowestPrice, mapFourthwallOrder, mapFourthwallOrderStatus, verifyFourthwallSignature };