@usethrottle/quotes 0.7.0 → 0.8.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/README.md +11 -1
- package/dist/index.cjs +50 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +40 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/hooks.ts","../src/quote-cart.ts","../src/QuoteView.tsx","../../core-cadence/src/cadence.ts","../../core-cadence/src/schedule.ts","../../core-cadence/src/labels.ts","../src/QuoteRequestForm.tsx"],"sourcesContent":["import { ThrottleError, type ThrottleErrorArgs } from '@usethrottle/errors';\n\n/**\n * Every failure from the quote-link routes surfaces as this. The `code` is the\n * API's own error code, so callers can branch on the ones that matter to a\n * buyer flow rather than parsing messages:\n *\n * revision_superseded — a newer revision was issued; `details.currentRevisionId`\n * tells you what to reload\n * quote_expired — the offer lapsed (HTTP 410)\n * invalid_item_selection — locked-line edit, non-optional deselect, or unknown item\n * accept_in_progress — a concurrent accept won; retry shortly\n * not_found — unknown/rotated token, or a draft/archived quote\n */\nexport class ThrottleQuotesError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n responseHeaders?: ThrottleErrorArgs['responseHeaders'];\n }) {\n super(args);\n this.name = 'ThrottleQuotesError';\n }\n\n /** The offer moved on — reload and show the buyer the current revision. */\n get isSuperseded(): boolean {\n return this.code === 'revision_superseded';\n }\n\n get isExpired(): boolean {\n return this.code === 'quote_expired';\n }\n\n /** Revision the server considers current, when it told us (spec §8.1). */\n get currentRevisionId(): string | undefined {\n const d = this.details as { currentRevisionId?: string } | undefined;\n return d?.currentRevisionId;\n }\n}\n","import { ThrottleQuotesError } from './errors';\nimport type {\n AcceptQuoteInput,\n AcceptQuoteResult,\n BuyerQuote,\n QuoteComment,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n ThrottleEnvelope,\n} from './types';\n\nconst DEFAULT_BASE = 'https://api.usethrottle.dev';\n\n/**\n * Headless client for the public quote surfaces. Everything is authorized by\n * the capability token in the URL — there is no API key here, and there must\n * not be: this runs in the buyer's browser.\n */\nexport class QuotesClient {\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: QuotesClientOptions = {}) {\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('QuotesClient: fetch is required');\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE).replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n try {\n const res = await this.fetchImpl(`${this.baseUrl}${path}`, {\n method,\n headers: body === undefined ? {} : { 'content-type': 'application/json' },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n signal: ctrl.signal,\n });\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleQuotesError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n responseHeaders: res.headers,\n });\n }\n return json.data as T;\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** Fetch the quote a buyer link points at. 404s for unknown/rotated tokens. */\n getQuote(token: string): Promise<BuyerQuote> {\n return this.request<BuyerQuote>('GET', `/api/v1/quote-links/${encodeURIComponent(token)}`);\n }\n\n /**\n * Tell the merchant the buyer opened the quote. Fire-and-forget: the server\n * throttles the resulting webhook to one per revision per 6h, and a failed\n * beacon must never break the page.\n */\n async recordView(token: string): Promise<void> {\n try {\n await this.request('POST', `/api/v1/quote-links/${encodeURIComponent(token)}/view`, {});\n } catch {\n /* telemetry only */\n }\n }\n\n addComment(token: string, input: { body: string; authorName?: string; authorEmail?: string }) {\n return this.request<QuoteComment>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/comments`,\n input,\n );\n }\n\n requestRevision(token: string, input: { message?: string; authorName?: string } = {}) {\n return this.request<BuyerQuote>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/request-revision`,\n input,\n );\n }\n\n decline(token: string, input: { reason?: string; authorName?: string } = {}) {\n return this.request<BuyerQuote>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/decline`,\n input,\n );\n }\n\n /**\n * Accept and get the checkout URL to send the buyer to.\n *\n * Re-accepting the same revision is idempotent and replays the same URL.\n * Accepting a superseded revision throws `revision_superseded` carrying\n * `currentRevisionId`; an expired offer throws `quote_expired`.\n */\n accept(token: string, input: AcceptQuoteInput): Promise<AcceptQuoteResult> {\n return this.request<AcceptQuoteResult>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/accept`,\n input,\n );\n }\n\n /**\n * Send a buyer who already accepted back to a LIVE checkout.\n *\n * Checkout sessions expire after 30 minutes, so the URL returned by\n * `accept` is usually dead by the time the buyer returns to the link. This\n * re-opens a session against the same cart when it is (no re-pricing).\n * Throws `checkout_not_resumable` if the quote was never accepted, and\n * `checkout_completed` once it has been paid.\n */\n resumeCheckout(token: string): Promise<{ checkoutUrl: string }> {\n return this.request<{ checkoutUrl: string }>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/checkout`,\n {},\n );\n }\n\n /** URL of the PDF for the revision the buyer is looking at (server 302s to signed storage). */\n pdfUrl(token: string): string {\n return `${this.baseUrl}/api/v1/quote-links/${encodeURIComponent(token)}/pdf`;\n }\n\n // ── RFQ intake ─────────────────────────────────────────────────────────────\n\n getRequestForm(formToken: string): Promise<RequestFormConfig> {\n return this.request<RequestFormConfig>(\n 'GET',\n `/api/v1/quote-request-forms/${encodeURIComponent(formToken)}/public`,\n );\n }\n\n /**\n * Submit an RFQ. The response is deliberately thin (`{ submitted: true }`) —\n * anonymous callers learn no internal identifiers. A submission caught by\n * the honeypot returns the same shape without creating anything, so a bot\n * cannot tell it was detected; treat success as \"accepted\", not \"created\".\n */\n submitRequest(formToken: string, input: SubmitQuoteRequestInput): Promise<{ submitted: boolean }> {\n return this.request<{ submitted: boolean }>('POST', '/api/v1/quote-requests', {\n formToken,\n ...input,\n });\n }\n}\n\nexport function createQuotesClient(opts: QuotesClientOptions = {}): QuotesClient {\n return new QuotesClient(opts);\n}\n\n// ── money formatting ─────────────────────────────────────────────────────────\n\n/** Minor units → a display string, e.g. (104000, 'USD') → \"$1,040.00\". */\nexport function formatMoney(minorUnits: number, currency: string, locale?: string): string {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(minorUnits / 100);\n}\n\n/**\n * Scale a line's quoted tax/discount to an edited quantity.\n *\n * MUST match `scaleLineCharges` in @commerce/quotes — the server recomputes\n * the accepted total with this rule, and any divergence shows the buyer one\n * total and charges another.\n */\nexport function scaleLineCharges(\n item: { quantity: number; taxAmount: number; discountAmount: number },\n quantity: number,\n): { taxAmount: number; discountAmount: number } {\n const base = item.quantity;\n if (!base || base <= 0 || quantity === base) {\n return { taxAmount: item.taxAmount, discountAmount: item.discountAmount };\n }\n const ratio = quantity / base;\n return {\n taxAmount: Math.round(item.taxAmount * ratio),\n discountAmount: Math.round(item.discountAmount * ratio),\n };\n}\n\n/** A subscription line with a free trial: nothing is charged for it at acceptance. */\nexport function isFreeTrialLine(item: { recurring?: { trialDays?: number | null } | null }): boolean {\n return (item.recurring?.trialDays ?? 0) > 0;\n}\n\n/**\n * What one line charges at acceptance, at `quantity`. MUST match\n * `lineDueAtAcceptance` in @commerce/quotes (shared test vectors).\n */\nexport function lineDueAtAcceptance(\n item: {\n unitPrice: number;\n quantity: number;\n taxAmount: number;\n discountAmount: number;\n recurring?: { trialDays?: number | null } | null;\n },\n quantity: number,\n): number {\n const { taxAmount, discountAmount } = scaleLineCharges(item, quantity);\n return (isFreeTrialLine(item) ? 0 : item.unitPrice * quantity) + taxAmount - discountAmount;\n}\n\n/** Effective total for a selection, using the same math the server will apply. */\nexport function computeSelectionTotal(\n items: Array<{\n id: string;\n unitPrice: number;\n quantity: number;\n taxAmount: number;\n discountAmount: number;\n optional: boolean;\n recurring?: { trialDays?: number | null } | null;\n }>,\n selections: Record<string, { selected: boolean; quantity: number }>,\n shippingTotal = 0,\n): number {\n let total = shippingTotal;\n for (const item of items) {\n const state = selections[item.id];\n if (item.optional && state && !state.selected) continue;\n const qty = state?.quantity ?? item.quantity;\n total += lineDueAtAcceptance(item, qty);\n }\n return total;\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { QuotesClient, computeSelectionTotal, createQuotesClient } from './client';\nimport { ThrottleQuotesError } from './errors';\nimport { createQuoteCart, type QuoteCart, type QuoteCartLine, type QuoteCartOptions } from './quote-cart';\nimport type {\n AcceptQuoteInput,\n BuyerQuote,\n ItemSelection,\n QuoteRequestItem,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n} from './types';\n\nexport interface UseQuoteResult {\n quote: BuyerQuote | null;\n loading: boolean;\n error: ThrottleQuotesError | null;\n /** Re-fetch — call after a `revision_superseded` to show the current offer. */\n refresh: () => Promise<void>;\n /** Buyer's current line choices, keyed by item id. */\n selections: Record<string, { selected: boolean; quantity: number }>;\n setSelected: (itemId: string, selected: boolean) => void;\n setQuantity: (itemId: string, quantity: number) => void;\n /** Live total for the current selections, using the server's own math. */\n total: number;\n accept: (\n input: Omit<AcceptQuoteInput, 'revisionId' | 'itemSelections'>,\n ) => Promise<{ checkoutUrl: string }>;\n /** Live checkout URL for a buyer returning to an already-accepted quote —\n * the one minted at acceptance has usually expired by then. */\n resumeCheckout: () => Promise<{ checkoutUrl: string }>;\n requestRevision: (message: string, authorName?: string) => Promise<void>;\n decline: (reason?: string, authorName?: string) => Promise<void>;\n addComment: (body: string, authorName?: string) => Promise<void>;\n pdfUrl: string;\n submitting: boolean;\n}\n\n/**\n * Everything the buyer quote page needs.\n *\n * Fires the view beacon once per mount, keeps line selections in local state,\n * and recomputes the total with the same rule the server applies at\n * acceptance — so the number the buyer sees is the number they are charged.\n */\nexport function useQuote(token: string, options: QuotesClientOptions = {}): UseQuoteResult {\n const client = useMemo(\n () => new QuotesClient(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.baseUrl, options.timeoutMs],\n );\n const [quote, setQuote] = useState<BuyerQuote | null>(null);\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [error, setError] = useState<ThrottleQuotesError | null>(null);\n const [selections, setSelections] = useState<Record<string, { selected: boolean; quantity: number }>>({});\n const beaconSent = useRef(false);\n\n const load = useCallback(async () => {\n setLoading(true);\n try {\n const q = await client.getQuote(token);\n setQuote(q);\n setError(null);\n // Seed selections from the revision's own defaults so a re-issue that\n // adds or locks lines resets the buyer's choices to the new offer.\n const next: Record<string, { selected: boolean; quantity: number }> = {};\n for (const item of q.currentRevision?.items ?? []) {\n next[item.id] = { selected: item.optional ? item.optionalSelected : true, quantity: item.quantity };\n }\n setSelections(next);\n } catch (e) {\n setError(e as ThrottleQuotesError);\n } finally {\n setLoading(false);\n }\n }, [client, token]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n useEffect(() => {\n if (!quote || beaconSent.current) return;\n beaconSent.current = true;\n void client.recordView(token);\n }, [client, quote, token]);\n\n const setSelected = useCallback((itemId: string, selected: boolean) => {\n setSelections((prev) => ({ ...prev, [itemId]: { ...(prev[itemId] ?? { quantity: 1 }), selected } }));\n }, []);\n\n const setQuantity = useCallback((itemId: string, quantity: number) => {\n setSelections((prev) => ({\n ...prev,\n [itemId]: { ...(prev[itemId] ?? { selected: true }), quantity: Math.max(1, Math.floor(quantity) || 1) },\n }));\n }, []);\n\n const total = useMemo(\n () =>\n computeSelectionTotal(\n quote?.currentRevision?.items ?? [],\n selections,\n quote?.currentRevision?.shippingTotal ?? 0,\n ),\n [quote, selections],\n );\n\n /** Only send selections the rep actually allows the buyer to change. */\n const buildSelections = useCallback((): ItemSelection[] => {\n const items = quote?.currentRevision?.items ?? [];\n const out: ItemSelection[] = [];\n for (const item of items) {\n const state = selections[item.id];\n if (!state) continue;\n const sel: ItemSelection = { itemId: item.id };\n let include = false;\n if (item.optional && state.selected !== item.optionalSelected) {\n sel.selected = state.selected;\n include = true;\n }\n if (item.qtyEditable && state.quantity !== item.quantity) {\n sel.quantity = state.quantity;\n include = true;\n }\n if (include) out.push(sel);\n }\n return out;\n }, [quote, selections]);\n\n const guard = useCallback(\n async <T,>(fn: () => Promise<T>): Promise<T> => {\n setSubmitting(true);\n try {\n const result = await fn();\n setError(null);\n return result;\n } catch (e) {\n const err = e as ThrottleQuotesError;\n setError(err);\n // A superseded offer means our copy is stale — pull the current one so\n // the buyer sees what they can actually accept (spec §8.1).\n if (err.isSuperseded) void load();\n throw err;\n } finally {\n setSubmitting(false);\n }\n },\n [load],\n );\n\n const accept = useCallback(\n async (input: Omit<AcceptQuoteInput, 'revisionId' | 'itemSelections'>) => {\n const revisionId = quote?.currentRevision?.id;\n if (!revisionId) throw new Error('useQuote: no current revision to accept');\n const itemSelections = buildSelections();\n const res = await guard(() =>\n client.accept(token, {\n ...input,\n revisionId,\n ...(itemSelections.length ? { itemSelections } : {}),\n }),\n );\n return { checkoutUrl: res.checkoutUrl };\n },\n [buildSelections, client, guard, quote, token],\n );\n\n const resumeCheckout = useCallback(\n async () => guard(() => client.resumeCheckout(token)),\n [client, guard, token],\n );\n\n const requestRevision = useCallback(\n async (message: string, authorName?: string) => {\n const q = await guard(() => client.requestRevision(token, { message, authorName }));\n setQuote(q);\n },\n [client, guard, token],\n );\n\n const decline = useCallback(\n async (reason?: string, authorName?: string) => {\n const q = await guard(() => client.decline(token, { reason, authorName }));\n setQuote(q);\n },\n [client, guard, token],\n );\n\n const addComment = useCallback(\n async (body: string, authorName?: string) => {\n await guard(() => client.addComment(token, { body, authorName }));\n await load();\n },\n [client, guard, load, token],\n );\n\n return {\n quote,\n loading,\n error,\n refresh: load,\n selections,\n setSelected,\n setQuantity,\n total,\n accept,\n resumeCheckout,\n requestRevision,\n decline,\n addComment,\n pdfUrl: client.pdfUrl(token),\n submitting,\n };\n}\n\nexport interface UseQuoteRequestFormResult {\n config: RequestFormConfig | null;\n loading: boolean;\n error: ThrottleQuotesError | null;\n submitting: boolean;\n submitted: boolean;\n submit: (input: SubmitQuoteRequestInput) => Promise<void>;\n /** Mount time; pass through so the API's minimum-fill-time check passes. */\n formLoadedAt: number;\n}\n\n/** Loads a hosted RFQ form's config and submits it, with bot fields handled. */\nexport function useQuoteRequestForm(\n formToken: string,\n options: QuotesClientOptions = {},\n): UseQuoteRequestFormResult {\n const client = useMemo(\n () => new QuotesClient(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.baseUrl, options.timeoutMs],\n );\n const [config, setConfig] = useState<RequestFormConfig | null>(null);\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<ThrottleQuotesError | null>(null);\n const formLoadedAt = useRef(Date.now()).current;\n\n useEffect(() => {\n let cancelled = false;\n (async () => {\n try {\n const cfg = await client.getRequestForm(formToken);\n if (!cancelled) setConfig(cfg);\n } catch (e) {\n if (!cancelled) setError(e as ThrottleQuotesError);\n } finally {\n if (!cancelled) setLoading(false);\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [client, formToken]);\n\n const submit = useCallback(\n async (input: SubmitQuoteRequestInput) => {\n setSubmitting(true);\n try {\n await client.submitRequest(formToken, { formLoadedAt, ...input });\n setSubmitted(true);\n setError(null);\n } catch (e) {\n setError(e as ThrottleQuotesError);\n throw e;\n } finally {\n setSubmitting(false);\n }\n },\n [client, formLoadedAt, formToken],\n );\n\n return { config, loading, error, submitting, submitted, submit, formLoadedAt };\n}\n\nexport { createQuotesClient };\n\nexport interface UseQuoteCartResult {\n lines: QuoteCartLine[];\n /** Total quantity across lines — for a header badge. */\n count: number;\n add: (item: QuoteRequestItem) => void;\n addMany: (items: QuoteRequestItem[]) => void;\n update: (key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>) => void;\n remove: (key: string) => void;\n clear: () => void;\n /** The underlying cart, for use outside React (an Add to Quote button in plain JS). */\n cart: QuoteCart;\n}\n\n/**\n * A quote cart the buyer fills while browsing, then submits as one request.\n *\n * The cart persists across page views, so an Add to Quote button on a product\n * page and a Request quote page elsewhere on the site see the same lines.\n * Pass the result of `toRequestItems()` (or `lines`) to\n * `useQuoteRequestForm().submit` as `items`.\n */\nexport function useQuoteCart(options: QuoteCartOptions = {}): UseQuoteCartResult {\n const cart = useMemo(\n () => createQuoteCart(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.storageKey, options.maxLines],\n );\n // Seeded empty rather than from storage: reading localStorage during render\n // makes the server and the first client render disagree, which is a\n // hydration mismatch. The effect below fills it in immediately after mount.\n const [lines, setLines] = useState<QuoteCartLine[]>([]);\n\n useEffect(() => {\n setLines(cart.read());\n return cart.subscribe(setLines);\n }, [cart]);\n\n return {\n lines,\n count: lines.reduce((sum, line) => sum + line.quantity, 0),\n add: useCallback((item: QuoteRequestItem) => void cart.add(item), [cart]),\n addMany: useCallback((items: QuoteRequestItem[]) => void cart.addMany(items), [cart]),\n update: useCallback(\n (key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>) => void cart.update(key, patch),\n [cart],\n ),\n remove: useCallback((key: string) => void cart.remove(key), [cart]),\n clear: useCallback(() => cart.clear(), [cart]),\n cart,\n };\n}\n","import type { QuoteRequestItem } from './types';\n\n/**\n * A quote cart: the buyer's running list of things to be quoted, built up\n * while they browse.\n *\n * Throttle stores no catalog, so the storefront owns product data and hands\n * lines in — the same arrangement as the shopping cart. Nothing here is sent\n * until `read()` is submitted through `QuotesClient.submitRequest`, and the\n * amounts a storefront attaches are the buyer's TARGET price, never a price\n * we will honour.\n *\n * Lines are keyed by `sku ?? referenceId ?? name`, so adding the same product\n * twice increases its quantity instead of stacking duplicate rows.\n */\n\nexport interface QuoteCartLine extends QuoteRequestItem {\n /** Stable identity for updates and removals. */\n key: string;\n quantity: number;\n}\n\nexport interface QuoteCartStorage {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\nexport interface QuoteCartOptions {\n /** Namespacing key, so two storefronts on one origin cannot collide. */\n storageKey?: string;\n /**\n * Where the cart survives page navigation. Defaults to `localStorage` in a\n * browser and to memory everywhere else (SSR, tests) — a cart that throws\n * during server rendering would take the whole page down.\n */\n storage?: QuoteCartStorage | null;\n /** Refuse to grow past this many distinct lines. The API caps at 100. */\n maxLines?: number;\n}\n\nconst DEFAULT_KEY = 'throttle:quote-cart';\nconst DEFAULT_MAX_LINES = 100;\n\nfunction memoryStorage(): QuoteCartStorage {\n const map = new Map<string, string>();\n return {\n getItem: (key) => map.get(key) ?? null,\n setItem: (key, value) => void map.set(key, value),\n removeItem: (key) => void map.delete(key),\n };\n}\n\nfunction defaultStorage(): QuoteCartStorage {\n try {\n if (typeof globalThis !== 'undefined' && (globalThis as any).localStorage) {\n return (globalThis as any).localStorage as QuoteCartStorage;\n }\n } catch {\n // Safari in private mode throws on access rather than returning null.\n }\n return memoryStorage();\n}\n\nfunction lineKey(item: QuoteRequestItem): string {\n const raw = item.sku?.trim() || item.referenceId?.trim() || item.name.trim();\n return raw.toLowerCase();\n}\n\nfunction normalizeQuantity(value: number | null | undefined): number {\n const n = Math.floor(Number(value ?? 1));\n return Number.isFinite(n) && n > 0 ? n : 1;\n}\n\nexport interface QuoteCart {\n /** Current lines, oldest first. */\n read(): QuoteCartLine[];\n /** Total quantity across lines — what a header badge should show. */\n count(): number;\n /** Add a line, merging quantities into an existing one with the same key. */\n add(item: QuoteRequestItem): QuoteCartLine[];\n /** Add several at once (a \"quote this whole cart\" button). */\n addMany(items: QuoteRequestItem[]): QuoteCartLine[];\n /** Change any field of a line. A quantity below 1 removes it. */\n update(key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>): QuoteCartLine[];\n remove(key: string): QuoteCartLine[];\n clear(): void;\n /** Subscribe to every change. Returns an unsubscribe function. */\n subscribe(listener: (lines: QuoteCartLine[]) => void): () => void;\n /** The `items` payload for `QuotesClient.submitRequest`. */\n toRequestItems(): QuoteRequestItem[];\n}\n\nexport function createQuoteCart(options: QuoteCartOptions = {}): QuoteCart {\n const storageKey = options.storageKey ?? DEFAULT_KEY;\n const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n const storage = options.storage === null ? memoryStorage() : (options.storage ?? defaultStorage());\n const listeners = new Set<(lines: QuoteCartLine[]) => void>();\n\n function load(): QuoteCartLine[] {\n try {\n const raw = storage.getItem(storageKey);\n if (!raw) return [];\n const parsed = JSON.parse(raw);\n if (!Array.isArray(parsed)) return [];\n // Storage is buyer-writable — anything shaped wrong is dropped rather\n // than trusted into a submission.\n return parsed\n .filter((line: any) => line && typeof line.name === 'string' && line.name.trim())\n .map((line: any) => ({\n ...line,\n key: typeof line.key === 'string' && line.key ? line.key : lineKey(line),\n quantity: normalizeQuantity(line.quantity),\n }))\n .slice(0, maxLines);\n } catch {\n return [];\n }\n }\n\n function save(lines: QuoteCartLine[]): QuoteCartLine[] {\n try {\n storage.setItem(storageKey, JSON.stringify(lines));\n } catch {\n // Quota or a disabled store — the cart still works for this page view.\n }\n for (const listener of listeners) listener(lines);\n return lines;\n }\n\n return {\n read: load,\n\n count() {\n return load().reduce((sum, line) => sum + line.quantity, 0);\n },\n\n add(item) {\n return this.addMany([item]);\n },\n\n addMany(items) {\n const lines = load();\n for (const item of items) {\n if (!item?.name?.trim()) continue;\n const key = lineKey(item);\n const existing = lines.find((line) => line.key === key);\n if (existing) {\n existing.quantity += normalizeQuantity(item.quantity);\n // Later detail wins — a product page knows more than a listing card.\n if (item.note) existing.note = item.note;\n if (item.targetUnitPrice != null) existing.targetUnitPrice = item.targetUnitPrice;\n continue;\n }\n if (lines.length >= maxLines) break;\n lines.push({ ...item, key, quantity: normalizeQuantity(item.quantity) });\n }\n return save(lines);\n },\n\n update(key, patch) {\n const lines = load();\n const index = lines.findIndex((line) => line.key === key);\n if (index === -1) return lines;\n if (patch.quantity != null && Math.floor(Number(patch.quantity)) < 1) {\n lines.splice(index, 1);\n return save(lines);\n }\n lines[index] = {\n ...lines[index],\n ...patch,\n key,\n quantity: normalizeQuantity(patch.quantity ?? lines[index].quantity),\n };\n return save(lines);\n },\n\n remove(key) {\n return save(load().filter((line) => line.key !== key));\n },\n\n clear() {\n try {\n storage.removeItem(storageKey);\n } catch {\n // Ignore — the notification below still resets any subscriber.\n }\n for (const listener of listeners) listener([]);\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => void listeners.delete(listener);\n },\n\n toRequestItems() {\n return load().map(({ key: _key, ...item }) => item);\n },\n };\n}\n","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { recurringTermsLabel } from '@core/cadence';\nimport { formatMoney, lineDueAtAcceptance } from './client';\nimport { useQuote } from './hooks';\nimport type { QuotesClientOptions } from './types';\n\nexport interface QuoteViewProps {\n /** The `qtl_…` token from the buyer's link. */\n token: string;\n options?: QuotesClientOptions;\n /**\n * Where to send the buyer after acceptance. Defaults to assigning\n * `window.location.href`, which is what the hosted page does.\n */\n onCheckout?: (checkoutUrl: string) => void;\n /** Rendered instead of the built-in markup while loading. */\n loadingFallback?: ReactNode;\n className?: string;\n}\n\nconst row: CSSProperties = { display: 'flex', justifyContent: 'space-between', gap: 16, padding: '8px 0' };\n\nconst muted: CSSProperties = { color: '#666', fontSize: 13 };\n\n/**\n * Drop-in buyer quote page: line items with optional toggles and quantity\n * editing, live totals, revision history, comment thread, and the\n * accept / request-changes / decline actions.\n *\n * Intentionally unstyled beyond a readable default — it is meant to be\n * restyled or replaced. `useQuote` carries all the behaviour if you want to\n * build your own presentation.\n */\nexport function QuoteView({ token, options, onCheckout, loadingFallback, className }: QuoteViewProps) {\n const q = useQuote(token, options ?? {});\n const [name, setName] = useState('');\n const [email, setEmail] = useState('');\n const [showAccept, setShowAccept] = useState(false);\n const [comment, setComment] = useState('');\n\n if (q.loading) return <>{loadingFallback ?? <p>Loading quote…</p>}</>;\n if (!q.quote) {\n return <p>This quote link is no longer available.</p>;\n }\n\n const quote = q.quote;\n const rev = quote.currentRevision;\n const currency = quote.currency;\n const ordered = quote.status === 'ordered';\n const accepted = quote.status === 'accepted';\n const canAct = quote.status === 'ready';\n // The subscription lines the buyer is keeping (an unticked optional plan drops out).\n const recurringKept = rev\n ? rev.items.filter((i) => i.recurring && (!i.optional || (q.selections[i.id]?.selected ?? true)))\n : [];\n\n const handleResume = async () => {\n const { checkoutUrl } = await q.resumeCheckout();\n if (onCheckout) onCheckout(checkoutUrl);\n else if (typeof window !== 'undefined') window.location.href = checkoutUrl;\n };\n\n const handleAccept = async () => {\n const { checkoutUrl } = await q.accept({ acceptedByName: name, acceptedByEmail: email });\n if (onCheckout) onCheckout(checkoutUrl);\n else if (typeof window !== 'undefined') window.location.href = checkoutUrl;\n };\n\n return (\n <div className={className}>\n <header>\n {quote.branding?.displayName ? <p style={muted}>{quote.branding.displayName}</p> : null}\n <h1>Quote {quote.quoteNumber}</h1>\n <p style={muted}>{statusLabel(quote.status)}</p>\n {quote.buyerReference ? <p style={muted}>Your reference: {quote.buyerReference}</p> : null}\n {rev ? (\n <p style={muted}>\n Revision {rev.revisionNumber}\n {rev.expiresAt ? ` · valid until ${new Date(rev.expiresAt).toLocaleDateString()}` : null}\n {' · '}\n <a href={q.pdfUrl}>Download PDF</a>\n </p>\n ) : null}\n </header>\n\n {q.error ? (\n <p role=\"alert\">\n {q.error.isSuperseded\n ? 'This quote was updated — showing the latest version.'\n : q.error.message}\n </p>\n ) : null}\n\n {rev ? (\n <table style={{ width: '100%', borderCollapse: 'collapse' }}>\n <thead>\n <tr>\n <th align=\"left\">Item</th>\n <th align=\"right\">Unit price</th>\n <th align=\"right\">Qty</th>\n <th align=\"right\">Total</th>\n </tr>\n </thead>\n <tbody>\n {rev.items.map((item) => {\n const state = q.selections[item.id] ?? { selected: true, quantity: item.quantity };\n const included = item.optional ? state.selected : true;\n return (\n <tr key={item.id}>\n <td>\n {item.optional ? (\n <label>\n <input\n type=\"checkbox\"\n checked={state.selected}\n disabled={!canAct}\n onChange={(e) => q.setSelected(item.id, e.target.checked)}\n />{' '}\n {item.name} <span style={muted}>optional</span>\n </label>\n ) : (\n item.name\n )}\n {item.description ? <div style={muted}>{item.description}</div> : null}\n {item.recurring ? (\n <div style={muted}>\n Subscription · {recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) => formatMoney(m, currency))}\n </div>\n ) : null}\n </td>\n <td align=\"right\">{formatMoney(item.unitPrice, currency)}</td>\n <td align=\"right\">\n {item.qtyEditable && canAct ? (\n <input\n type=\"number\"\n min={1}\n value={state.quantity}\n disabled={!included}\n aria-label={`Quantity for ${item.name}`}\n onChange={(e) => q.setQuantity(item.id, Number(e.target.value))}\n style={{ width: 64 }}\n />\n ) : (\n state.quantity\n )}\n </td>\n <td align=\"right\">\n {formatMoney(included ? lineDueAtAcceptance(item, state.quantity) : 0, currency)}\n </td>\n </tr>\n );\n })}\n </tbody>\n </table>\n ) : null}\n\n {rev ? (\n <section>\n <div style={row}>\n <strong>{recurringKept.length > 0 ? 'Due at acceptance' : 'Total'}</strong>\n <strong>{formatMoney(q.total, currency)}</strong>\n </div>\n {recurringKept.length > 0 ? (\n <div>\n <p style={muted}>Recurring after</p>\n {recurringKept.map((i) => (\n <p key={i.id} style={muted}>\n {i.name}: {recurringTermsLabel(i.recurring!, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) => formatMoney(m, currency))}\n </p>\n ))}\n </div>\n ) : null}\n <p style={muted}>{termsLabel(rev.paymentTerms, rev.depositAmount, currency)}</p>\n {rev.leadTime ? <p style={muted}>Lead time: {rev.leadTime}</p> : null}\n {rev.buyerNote ? <blockquote>{rev.buyerNote}</blockquote> : null}\n </section>\n ) : null}\n\n {ordered ? (\n <p>\n Ordered{quote.orderId ? ` — order ${quote.orderId}` : ''}. Thank you.\n </p>\n ) : accepted ? (\n // Accepted but not yet paid. The checkout session minted at acceptance\n // expires in 30 minutes, so this asks the server for a live one rather\n // than linking to a URL that is probably dead.\n <section>\n <p>You accepted this quote — payment is not finished yet.</p>\n <button type=\"button\" disabled={q.submitting} onClick={() => void handleResume()}>\n Continue to checkout\n </button>\n </section>\n ) : canAct ? (\n <section>\n {showAccept ? (\n <form\n onSubmit={(e) => {\n e.preventDefault();\n void handleAccept();\n }}\n >\n <label>\n Your name\n <input value={name} onChange={(e) => setName(e.target.value)} required />\n </label>\n <label>\n Email\n <input type=\"email\" value={email} onChange={(e) => setEmail(e.target.value)} required />\n </label>\n <button type=\"submit\" disabled={q.submitting || !name || !email}>\n Confirm & continue to payment\n </button>\n </form>\n ) : (\n <button type=\"button\" onClick={() => setShowAccept(true)}>\n Accept & checkout\n </button>\n )}\n <button\n type=\"button\"\n disabled={q.submitting}\n onClick={() => void q.requestRevision('Please revise this quote.', name || undefined)}\n >\n Request changes\n </button>\n <button type=\"button\" disabled={q.submitting} onClick={() => void q.decline(undefined, name || undefined)}>\n Decline\n </button>\n </section>\n ) : null}\n\n {quote.revisionHistory.length > 0 ? (\n <details>\n <summary>Previous versions ({quote.revisionHistory.length})</summary>\n <ul>\n {quote.revisionHistory.map((r) => (\n <li key={r.id}>\n Revision {r.revisionNumber} — {formatMoney(r.total, currency)}\n {r.changeSummary ? ` · ${r.changeSummary}` : ''}\n </li>\n ))}\n </ul>\n </details>\n ) : null}\n\n <section>\n <h2>Questions</h2>\n {quote.comments.map((c) => (\n <p key={c.id}>\n <strong>{c.authorName ?? (c.authorType === 'merchant' ? 'Seller' : 'You')}:</strong> {c.body}\n </p>\n ))}\n <form\n onSubmit={(e) => {\n e.preventDefault();\n const body = comment.trim();\n if (!body) return;\n setComment('');\n void q.addComment(body, name || undefined);\n }}\n >\n <input\n value={comment}\n onChange={(e) => setComment(e.target.value)}\n placeholder=\"Ask a question…\"\n aria-label=\"Ask a question\"\n />\n <button type=\"submit\" disabled={q.submitting || !comment.trim()}>\n Send\n </button>\n </form>\n </section>\n </div>\n );\n}\n\nfunction statusLabel(status: string): string {\n switch (status) {\n case 'in_progress':\n return 'We are preparing your quote';\n case 'ready':\n return 'Ready for your review';\n case 'being_revised':\n return 'We are revising this quote';\n case 'accepted':\n return 'Accepted — completing payment';\n case 'ordered':\n return 'Ordered';\n case 'declined':\n return 'Declined';\n case 'expired':\n return 'This quote has expired — request updated pricing';\n default:\n return status;\n }\n}\n\nfunction termsLabel(\n terms: { mode: string; netN?: number; balanceNetN?: number },\n depositAmount: number | null,\n currency: string,\n): string {\n if (terms.mode === 'net_terms') return `Payment terms: Net ${terms.netN}`;\n if (terms.mode === 'deposit_balance') {\n const dep = depositAmount != null ? formatMoney(depositAmount, currency) : 'a deposit';\n return `${dep} due today, balance Net ${terms.balanceNetN}`;\n }\n return 'Payment in full';\n}\n","/**\n * A subscription's billing cadence: \"every N units\".\n *\n * Every subscription row stores a unit and a count; the five named intervals\n * are shorthand for particular combinations. This module is the only place\n * that knows the vocabulary, the bounds, and how a period boundary is\n * computed — the engine, the renewal cron, the API, the dashboard and the\n * buyer surfaces all import it. Before it existed there were three divergent\n * copies of the period math, and the renewal cron's advanced months with\n * `setMonth`, which overflows: a subscription started on Jan 31 renewed on\n * Mar 3 and never returned to the 31st.\n */\n\nexport const INTERVAL_UNITS = ['hour', 'day', 'week', 'month'] as const;\nexport type IntervalUnit = (typeof INTERVAL_UNITS)[number];\n\nexport const NAMED_INTERVALS = ['weekly', 'biweekly', 'monthly', 'quarterly', 'yearly'] as const;\nexport type NamedInterval = (typeof NAMED_INTERVALS)[number];\n\n/** What the `interval` field holds: a named interval, or `custom` for everything else. */\nexport const INTERVAL_VALUES = [...NAMED_INTERVALS, 'custom'] as const;\nexport type IntervalValue = (typeof INTERVAL_VALUES)[number];\n\nexport interface Cadence {\n interval: IntervalValue;\n unit: IntervalUnit;\n count: number;\n}\n\n/** Anything that describes a cadence the way the API and the database do. */\nexport interface CadenceLike {\n interval: string;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface CadenceInput {\n interval?: string | null;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n}\n\nexport const NAMED_SHORTHAND: Readonly<Record<NamedInterval, { unit: IntervalUnit; count: number }>> = {\n weekly: { unit: 'week', count: 1 },\n biweekly: { unit: 'week', count: 2 },\n monthly: { unit: 'month', count: 1 },\n quarterly: { unit: 'month', count: 3 },\n // month × 12 rather than a year unit, so a Feb 29 anniversary clamps to Feb\n // 28 and comes back to Feb 29 in leap years like every other month cadence.\n yearly: { unit: 'month', count: 12 },\n};\n\n/** At most one year in every unit. The shortest cadence is 1 hour. */\nexport const MAX_INTERVAL_COUNT: Readonly<Record<IntervalUnit, number>> = {\n hour: 8760,\n day: 365,\n week: 52,\n month: 12,\n};\n\nexport const HOUR_MS = 3_600_000;\nexport const DAY_MS = 24 * HOUR_MS;\nexport const WEEK_MS = 7 * DAY_MS;\n\nconst FIXED_UNIT_MS = { hour: HOUR_MS, day: DAY_MS, week: WEEK_MS } as const;\n\nexport class CadenceError extends Error {\n readonly statusCode = 400;\n constructor(\n readonly code: 'invalid_interval' | 'interval_conflict',\n message: string,\n ) {\n super(message);\n this.name = 'CadenceError';\n }\n}\n\nexport function isNamedInterval(value: unknown): value is NamedInterval {\n return typeof value === 'string' && (NAMED_INTERVALS as readonly string[]).includes(value);\n}\n\nexport function isIntervalUnit(value: unknown): value is IntervalUnit {\n return typeof value === 'string' && (INTERVAL_UNITS as readonly string[]).includes(value);\n}\n\nfunction isIntervalValue(value: unknown): value is IntervalValue {\n return typeof value === 'string' && (INTERVAL_VALUES as readonly string[]).includes(value);\n}\n\nfunction reduceToLargestUnit(unit: IntervalUnit, count: number): { unit: IntervalUnit; count: number } {\n let u = unit;\n let c = count;\n if (u === 'hour' && c % 24 === 0) {\n u = 'day';\n c = c / 24;\n }\n if (u === 'day' && c % 7 === 0) {\n u = 'week';\n c = c / 7;\n }\n return { unit: u, count: c };\n}\n\nfunction namedFor(unit: IntervalUnit, count: number): NamedInterval | null {\n for (const name of NAMED_INTERVALS) {\n const s = NAMED_SHORTHAND[name];\n if (s.unit === unit && s.count === count) return name;\n }\n return null;\n}\n\n/**\n * Turn whatever a caller sent into the one stored form. Accepts a named\n * interval alone, a unit and count alone, or both — in which case they must\n * agree. The result is reduced to its largest exact unit and mapped to a named\n * interval whenever one matches, so there is exactly one representation per\n * cadence and \"every 2 weeks\" can never be filed apart from \"biweekly\".\n */\nexport function canonicalizeCadence(input: CadenceInput): Cadence {\n const interval = input.interval ?? undefined;\n if (interval !== undefined && !isIntervalValue(interval)) {\n throw new CadenceError('invalid_interval', `Unknown interval \"${interval}\"`);\n }\n const hasUnit = input.intervalUnit != null;\n const hasCount = input.intervalCount != null;\n if (hasUnit !== hasCount) {\n throw new CadenceError('invalid_interval', 'intervalUnit and intervalCount must be sent together');\n }\n if (!hasUnit) {\n if (isNamedInterval(interval)) return { interval, ...NAMED_SHORTHAND[interval] };\n throw new CadenceError(\n 'invalid_interval',\n interval === 'custom'\n ? 'A custom interval needs intervalUnit and intervalCount'\n : 'Send an interval, or intervalUnit and intervalCount',\n );\n }\n\n const unit = input.intervalUnit;\n const count = input.intervalCount as number;\n if (!isIntervalUnit(unit)) {\n throw new CadenceError('invalid_interval', 'intervalUnit must be one of hour, day, week, month');\n }\n if (!Number.isInteger(count) || count < 1) {\n throw new CadenceError('invalid_interval', 'intervalCount must be a whole number of at least 1');\n }\n if (count > MAX_INTERVAL_COUNT[unit]) {\n throw new CadenceError(\n 'invalid_interval',\n `A cadence can be at most one year: ${MAX_INTERVAL_COUNT[unit]} ${unit}s`,\n );\n }\n\n const reduced = reduceToLargestUnit(unit, count);\n const cadence: Cadence = { interval: namedFor(reduced.unit, reduced.count) ?? 'custom', ...reduced };\n if (interval !== undefined && interval !== 'custom' && interval !== cadence.interval) {\n throw new CadenceError(\n 'interval_conflict',\n `interval \"${interval}\" does not match every ${count} ${unit}${count === 1 ? '' : 's'}`,\n );\n }\n return cadence;\n}\n\n/**\n * Read the cadence off a stored subscription. A named interval always means\n * its shorthand, whatever the unit/count columns hold: a canonical row's\n * columns match the shorthand anyway, and code that predates the columns\n * (still serving between migration 0224 and the deploy) changes `interval`\n * without touching them, so for a named row they can be stale. Only a\n * `custom` row is read from its unit and count. The same rule applies to the\n * pending cadence — pass `{ interval: pendingInterval, intervalUnit:\n * pendingIntervalUnit, intervalCount: pendingIntervalCount }`.\n */\nexport function cadenceOf(row: CadenceLike): Cadence {\n if (isNamedInterval(row.interval)) return { interval: row.interval, ...NAMED_SHORTHAND[row.interval] };\n if (row.interval === 'custom' && row.intervalUnit != null && row.intervalCount != null && isIntervalUnit(row.intervalUnit)) {\n return { interval: 'custom', unit: row.intervalUnit, count: row.intervalCount };\n }\n throw new Error(`Unknown subscription interval: ${row.interval}`);\n}\n\n/** The exact period length for hour/day/week cadences; null for months, which vary. */\nexport function fixedPeriodMs(cadence: Cadence): number | null {\n return cadence.unit === 'month' ? null : cadence.count * FIXED_UNIT_MS[cadence.unit];\n}\n\n/** The shortest a period can be. A month counts as 28 days. */\nexport function minimumPeriodMs(cadence: Cadence): number {\n return fixedPeriodMs(cadence) ?? cadence.count * 28 * DAY_MS;\n}\n\n/** anchor + months, keeping the anchor's day-of-month (clamped to month end) and UTC time of day. */\nexport function addMonthsAnchored(anchor: Date, months: number): Date {\n const monthIndex = anchor.getUTCMonth() + months;\n const year = anchor.getUTCFullYear() + Math.floor(monthIndex / 12);\n const month = ((monthIndex % 12) + 12) % 12;\n const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();\n return new Date(\n Date.UTC(\n year,\n month,\n Math.min(anchor.getUTCDate(), lastDay),\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n ),\n );\n}\n\n/**\n * The first period boundary strictly after `after`, on the grid measured from\n * `anchor`. Never chained from a previous boundary — that is what made the\n * month-end clamp stick on the 28th. An `after` that is off the grid (a late\n * tick, a recovery) resolves to the next grid date.\n */\nexport function nextPeriodEnd(args: { anchor: Date; cadence: Cadence; after: Date }): Date {\n const { anchor, cadence, after } = args;\n const step = fixedPeriodMs(cadence);\n if (step !== null) {\n const k = Math.max(1, Math.floor((after.getTime() - anchor.getTime()) / step) + 1);\n return new Date(anchor.getTime() + k * step);\n }\n const monthsElapsed =\n (after.getUTCFullYear() - anchor.getUTCFullYear()) * 12 + (after.getUTCMonth() - anchor.getUTCMonth());\n let k = Math.max(1, Math.floor(monthsElapsed / cadence.count));\n let boundary = addMonthsAnchored(anchor, k * cadence.count);\n while (boundary.getTime() <= after.getTime()) {\n k += 1;\n boundary = addMonthsAnchored(anchor, k * cadence.count);\n }\n return boundary;\n}\n\n/**\n * The grid period that contains `at`: the latest boundary at or before it (never\n * before the anchor) and the one after. A subscription that fell more than a\n * period behind is billed once, for this period, and the periods it missed are\n * skipped rather than charged back to back (D38).\n */\nexport function periodContaining(args: { anchor: Date; cadence: Cadence; at: Date }): { start: Date; end: Date } {\n const { anchor, cadence, at } = args;\n const step = fixedPeriodMs(cadence);\n if (step !== null) {\n const k = Math.max(0, Math.floor((at.getTime() - anchor.getTime()) / step));\n const start = new Date(anchor.getTime() + k * step);\n return { start, end: new Date(start.getTime() + step) };\n }\n const monthsElapsed =\n (at.getUTCFullYear() - anchor.getUTCFullYear()) * 12 + (at.getUTCMonth() - anchor.getUTCMonth());\n let k = Math.max(0, Math.floor(monthsElapsed / cadence.count));\n let start = addMonthsAnchored(anchor, k * cadence.count);\n while (k > 0 && start.getTime() > at.getTime()) {\n k -= 1;\n start = addMonthsAnchored(anchor, k * cadence.count);\n }\n return { start, end: addMonthsAnchored(anchor, (k + 1) * cadence.count) };\n}\n\nconst RETRY_CAP_DAYS = [1, 3, 7] as const;\n\n/**\n * How long to wait before retry number `failureNumber` (1..3). Short cadences\n * retry proportionally faster; anything of a week or longer lands on the\n * original 1 / 3 / 7 days exactly.\n */\nexport function dunningRetryDelayMs(cadence: Cadence, failureNumber: number): number {\n const n = Math.min(Math.max(Math.trunc(failureNumber), 1), RETRY_CAP_DAYS.length);\n return Math.min(n * minimumPeriodMs(cadence), RETRY_CAP_DAYS[n - 1] * DAY_MS);\n}\n\n/** The 3-days-ahead renewal reminder only makes sense for cadences of a week or longer. */\nexport function sendsRenewalReminder(cadence: Cadence): boolean {\n return minimumPeriodMs(cadence) >= WEEK_MS;\n}\n\n/**\n * Multiply a period's charge by this to get its monthly equivalent. Chosen so\n * `weekly` is exactly 52/12 and `biweekly` exactly 26/12, the factors\n * analytics already report — no existing MRR number moves.\n */\nexport function monthlyEquivalentFactor(cadence: Cadence): number {\n if (cadence.unit === 'month') return 1 / cadence.count;\n return (52 / 12) * (WEEK_MS / (fixedPeriodMs(cadence) as number));\n}\n","// packages/core-cadence/src/schedule.ts\n/**\n * Installment schedules: a plan whose payments differ in amount and in the gap\n * before each one. Row 0 is charged at signup and has no gap; row i's gap is\n * how long after payment i-1 it falls due. Gaps use the custom-cadence units\n * and bounds. Due dates are anchored and cumulative (spec S26): months are\n * clamped against the anchor's day, so a Jan 31 plan pays Feb 28, Mar 31,\n * Apr 30 — never chained from a clamped date.\n */\nimport {\n addMonthsAnchored,\n canonicalizeCadence,\n cadenceOf,\n CadenceError,\n fixedPeriodMs,\n isIntervalUnit,\n nextPeriodEnd,\n type Cadence,\n type IntervalUnit,\n} from './cadence';\nimport { MAX_TOTAL_PAYMENTS, MIN_TOTAL_PAYMENTS } from './installments';\n\nexport interface ScheduleRow {\n /** Gross, per unit of the line, minor units. */\n amount: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n}\n\n/** What `subscriptions.payment_schedule` holds, one per payment. */\nexport interface PaymentScheduleRow {\n /** Gross, per unit. */\n unitAmount: number;\n /** This payment's share of the deal discount, line total (quantity included). */\n discount: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n}\n\nexport type GapRow = { intervalUnit: IntervalUnit | null; intervalCount: number | null };\n\nexport type ScheduleErrorCode = 'invalid_schedule' | 'schedule_first_payment_mismatch';\n\nexport class ScheduleError extends Error {\n readonly statusCode = 400;\n constructor(\n readonly code: ScheduleErrorCode,\n message: string,\n ) {\n super(message);\n this.name = 'ScheduleError';\n }\n}\n\nconst ROW_KEYS = new Set(['amount', 'intervalUnit', 'intervalCount']);\n\nfunction invalid(message: string): ScheduleError {\n return new ScheduleError('invalid_schedule', message);\n}\n\n/** Validate and canonicalize a schedule. Every message starts with the row it is about. */\nexport function normalizeSchedule(input: unknown): ScheduleRow[] {\n if (!Array.isArray(input) || input.length < MIN_TOTAL_PAYMENTS || input.length > MAX_TOTAL_PAYMENTS) {\n throw invalid(`schedule must be an array of ${MIN_TOTAL_PAYMENTS} to ${MAX_TOTAL_PAYMENTS} payments`);\n }\n return input.map((raw, i) => {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw invalid(`schedule[${i}] must be an object`);\n const row = raw as Record<string, unknown>;\n const unknown = Object.keys(row).filter((k) => !ROW_KEYS.has(k));\n if (unknown.length > 0) throw invalid(`schedule[${i}] has unsupported field(s): ${unknown.join(', ')}`);\n const amount = row.amount;\n if (typeof amount !== 'number' || !Number.isInteger(amount) || amount <= 0) {\n throw invalid(`schedule[${i}].amount must be a whole number of minor units above 0`);\n }\n const hasUnit = row.intervalUnit != null;\n const hasCount = row.intervalCount != null;\n if (i === 0) {\n if (hasUnit || hasCount) throw invalid('schedule[0] is paid at signup and cannot have intervalUnit or intervalCount');\n return { amount, intervalUnit: null, intervalCount: null };\n }\n if (!hasUnit || !hasCount) throw invalid(`schedule[${i}] needs intervalUnit and intervalCount`);\n if (!isIntervalUnit(row.intervalUnit)) {\n throw invalid(`schedule[${i}].intervalUnit must be one of hour, day, week, month`);\n }\n let gap: Cadence;\n try {\n gap = canonicalizeCadence({ intervalUnit: row.intervalUnit, intervalCount: row.intervalCount as number });\n } catch (err) {\n if (err instanceof CadenceError) throw invalid(`schedule[${i}].intervalCount: ${err.message}`);\n throw err;\n }\n return { amount, intervalUnit: gap.unit, intervalCount: gap.count };\n });\n}\n\nexport function assertScheduleFirstPayment(schedule: ScheduleRow[], unitPrice: number): void {\n if (schedule[0].amount !== unitPrice) {\n throw new ScheduleError(\n 'schedule_first_payment_mismatch',\n `unitPrice (${unitPrice}) must equal schedule[0].amount (${schedule[0].amount}): payment 1 is what the line charges today`,\n );\n }\n}\n\nexport function scheduleUnitTotal(schedule: Array<{ amount: number }>): number {\n return schedule.reduce((sum, row) => sum + row.amount, 0);\n}\n\n/** A row's gap as a canonical cadence (interval name included), for the subscription's cadence columns. */\nexport function scheduleGapCadence(row: GapRow): Cadence {\n return canonicalizeCadence({ intervalUnit: row.intervalUnit, intervalCount: row.intervalCount });\n}\n\n/** Due time of payment `index`: the anchor plus every gap after `anchorIndex`, months first. */\nexport function scheduleDueAt(args: { anchor: Date; anchorIndex: number; rows: GapRow[]; index: number }): Date {\n const { anchor, anchorIndex, rows, index } = args;\n if (index < anchorIndex) throw new Error(`payment ${index} is before the anchor row ${anchorIndex}`);\n let months = 0;\n let fixedMs = 0;\n for (let j = anchorIndex + 1; j <= index; j += 1) {\n const gap = scheduleGapCadence(rows[j]);\n if (gap.unit === 'month') months += gap.count;\n else fixedMs += fixedPeriodMs(gap) as number;\n }\n return new Date(addMonthsAnchored(anchor, months).getTime() + fixedMs);\n}\n\n/**\n * The end of the period payment `index` pays for: the next payment's due time,\n * or — for the last payment, which nothing follows — its own gap once more.\n */\nexport function scheduleCoveredUntil(args: { anchor: Date; anchorIndex: number; rows: GapRow[]; index: number }): Date {\n const { rows, index } = args;\n if (index + 1 < rows.length) return scheduleDueAt({ ...args, index: index + 1 });\n const extended = [...rows, rows[index]];\n return scheduleDueAt({ ...args, rows: extended, index: index + 1 });\n}\n\n/** A line's subtotal as the discount engine sees it: the whole deal for an installment line (S33). */\nexport function lineDealSubtotal(line: {\n unitPrice?: number | null;\n quantity?: number | null;\n subtotal?: number | null;\n recurring?: unknown;\n}): number {\n const quantity = Number(line.quantity ?? 1);\n const unitPrice = Number(line.unitPrice ?? 0);\n const subtotal = line.subtotal != null ? Number(line.subtotal) : unitPrice * quantity;\n const r = line.recurring as { plan?: unknown; schedule?: unknown; totalPayments?: unknown; trialDays?: unknown } | null | undefined;\n if (!r || typeof r.plan !== 'string') return subtotal;\n if (Array.isArray(r.schedule)) return scheduleUnitTotal(r.schedule as Array<{ amount: number }>) * quantity;\n if (typeof r.totalPayments === 'number' && Number(r.trialDays ?? 0) === 0) return r.totalPayments * unitPrice * quantity;\n return subtotal;\n}\n\n/** S33: the part of a deal-wide discount that today's charge carries. */\nexport function todayShareOfDealDiscount(args: { dealDiscount: number; todayWeight: number; dealWeight: number }): number {\n const { dealDiscount, todayWeight, dealWeight } = args;\n if (dealDiscount <= 0 || dealWeight <= 0 || todayWeight <= 0) return 0;\n return Math.min(dealDiscount, Math.round((dealDiscount * todayWeight) / dealWeight));\n}\n\nexport interface PaymentScheduleViewRow {\n index: number;\n amount: number;\n discount: number;\n net: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n status: 'paid' | 'due' | 'upcoming';\n dueAt: string | null;\n}\n\nexport interface PaymentScheduleView {\n rows: PaymentScheduleViewRow[];\n scheduleTotal: number;\n nextPaymentAmount: number | null;\n}\n\nexport type ScheduleSubLike = {\n status: string;\n amount: number;\n quantity?: number | null;\n totalPayments?: number | null;\n paymentsMade?: number | null;\n interval: string;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n billingAnchorAt?: Date | string | null;\n currentPeriodEnd?: Date | string | null;\n scheduleRows?: PaymentScheduleRow[] | null;\n scheduleAnchorIndex?: number | null;\n};\n\nconst toDate = (v: Date | string | null | undefined): Date | null => (v == null ? null : new Date(v));\n\n/** The response view (spec §2, S35). Null for an ongoing subscription. */\nexport function paymentScheduleView(sub: ScheduleSubLike, _now: Date = new Date()): PaymentScheduleView | null {\n if (sub.totalPayments == null) return null;\n const quantity = sub.quantity ?? 1;\n const made = Math.min(sub.paymentsMade ?? 0, sub.totalPayments);\n const billing = ['active', 'past_due', 'paused', 'unpaid'].includes(sub.status);\n const rows: PaymentScheduleRow[] =\n sub.scheduleRows && sub.scheduleRows.length > 0\n ? sub.scheduleRows\n : Array.from({ length: sub.totalPayments }, (_, i) => ({\n unitAmount: sub.amount,\n discount: 0,\n intervalUnit: i === 0 ? null : ((sub.intervalUnit ?? null) as IntervalUnit | null),\n intervalCount: i === 0 ? null : (sub.intervalCount ?? null),\n }));\n const nextDue = toDate(sub.currentPeriodEnd);\n const dueAtOf = (i: number): string | null => {\n if (i < made || !billing || !nextDue) return null;\n if (sub.scheduleRows && sub.scheduleRows.length > 0) {\n const anchor = toDate(sub.billingAnchorAt) ?? nextDue;\n return scheduleDueAt({ anchor, anchorIndex: sub.scheduleAnchorIndex ?? 0, rows, index: i }).toISOString();\n }\n // Equal plan: the stored period end, then the anchored grid.\n const cadence = cadenceOf({ interval: sub.interval, intervalUnit: sub.intervalUnit, intervalCount: sub.intervalCount });\n const anchor = toDate(sub.billingAnchorAt) ?? nextDue;\n let at = nextDue;\n for (let k = made; k < i; k += 1) at = nextPeriodEnd({ anchor, cadence, after: at });\n return at.toISOString();\n };\n const view = rows.map((row, i) => {\n const net = row.unitAmount * quantity - row.discount;\n const status: PaymentScheduleViewRow['status'] =\n i < made ? 'paid' : i === made && (sub.status === 'past_due' || sub.status === 'unpaid') ? 'due' : 'upcoming';\n return {\n index: i, amount: row.unitAmount, discount: row.discount, net,\n intervalUnit: row.intervalUnit, intervalCount: row.intervalCount, status, dueAt: dueAtOf(i),\n };\n });\n return {\n rows: view,\n scheduleTotal: view.reduce((s, r) => s + r.net, 0),\n nextPaymentAmount: billing && made < view.length ? view[made].net : null,\n };\n}\n\n/**\n * True when a subscription's synthesized payment rows are a genuinely custom schedule: any discount,\n * any amount differing from payment 1, or any gap (payments 2..N) differing from payment 2's.\n * Equal installment plans also carry synthesized rows and must render as before.\n */\nexport function isVariedSchedule(\n rows: Array<{ amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null }> | null | undefined,\n): boolean {\n if (!rows || rows.length === 0) return false;\n return rows.some(\n (r, i) =>\n r.discount !== 0 ||\n r.amount !== rows[0].amount ||\n (i > 1 && (r.intervalUnit !== rows[1].intervalUnit || r.intervalCount !== rows[1].intervalCount)),\n );\n}\n\n/**\n * A varied schedule's payments still to come — unpaid rows that carry an\n * estimated date — for the buyer-facing dated lists (spec §5: order\n * confirmation, portal, billing page). Empty for an equal plan, so those\n * surfaces render exactly as before. Each surface formats amount and date itself.\n */\nexport function upcomingSchedulePayments<\n R extends { amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null; status: string; dueAt: string | null },\n>(rows: R[] | null | undefined): Array<R & { dueAt: string }> {\n if (!rows || !isVariedSchedule(rows)) return [];\n return rows.filter((r): r is R & { dueAt: string } => r.status !== 'paid' && r.dueAt != null);\n}\n","import { isIntervalUnit, isNamedInterval, type CadenceLike, type NamedInterval } from './cadence';\nimport { isVariedSchedule, scheduleUnitTotal } from './schedule';\n\nconst NAMED_NOUN: Record<NamedInterval, string> = {\n weekly: 'week',\n biweekly: '2 weeks',\n monthly: 'month',\n quarterly: 'quarter',\n yearly: 'year',\n};\n\nconst NAMED_LABEL: Record<NamedInterval, string> = {\n weekly: 'Weekly',\n biweekly: 'Biweekly',\n monthly: 'Monthly',\n quarterly: 'Quarterly',\n yearly: 'Yearly',\n};\n\n/**\n * The period as a noun — what reads correctly after a slash: \"$49.00 / 10\n * days\". This replaces the per-file `INTERVAL_WORD` maps whose drift shipped\n * \"$49.00 / biweekly\" once already. Unknown input falls through unchanged so a\n * value this build doesn't know still renders instead of vanishing.\n */\nexport function cadenceNoun(cadence: CadenceLike): string {\n if (isNamedInterval(cadence.interval)) return NAMED_NOUN[cadence.interval];\n if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) {\n return cadence.intervalCount === 1 ? cadence.intervalUnit : `${cadence.intervalCount} ${cadence.intervalUnit}s`;\n }\n return cadence.interval;\n}\n\n/** The cadence as a standalone label, e.g. an Interval column: \"Monthly\", \"Every 10 days\". */\nexport function cadenceLabel(cadence: CadenceLike): string {\n if (isNamedInterval(cadence.interval)) return NAMED_LABEL[cadence.interval];\n if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) return `Every ${cadenceNoun(cadence)}`;\n return cadence.interval;\n}\n\n/** Sub-daily cadences show the time of the next charge, not just its date. */\nexport function isSubDaily(cadence: CadenceLike): boolean {\n return cadence.intervalUnit === 'hour';\n}\n\n/** A subscription line's terms, the fields a label needs. */\nexport interface RecurringTermsLike extends CadenceLike {\n totalPayments?: number | null;\n trialDays?: number | null;\n schedule?: Array<{ amount: number }> | null;\n}\n\n/**\n * One short label for a subscription line's terms, for carts and quotes:\n * \"$20.00 / month\", \"$20.00 / 10 days · 3 payments\", \"Free for 14 days, then\n * $20.00 / month\", \"$100.00 total · 4 payments\". The label computes the money\n * itself from the line's unit price and seats — for a schedule, the deal total\n * (every payment × seats), never the line's unit price (payment 1) — and hands\n * it to `money`, so each surface keeps its own money style.\n */\nexport function recurringTermsLabel(\n terms: RecurringTermsLike,\n price: { unitPrice: number; quantity?: number | null },\n money: (minor: number) => string,\n): string {\n const quantity = price.quantity ?? 1;\n if (terms.schedule && terms.schedule.length > 0) {\n return `${money(scheduleUnitTotal(terms.schedule) * quantity)} total · ${terms.schedule.length} payments`;\n }\n const each = money(price.unitPrice * quantity);\n const noun = cadenceNoun(terms);\n const trialDays = terms.trialDays ?? 0;\n if (trialDays > 0) return `Free for ${trialDays} day${trialDays === 1 ? '' : 's'}, then ${each} / ${noun}`;\n return `${each} / ${noun}` + (terms.totalPayments != null ? ` · ${terms.totalPayments} payments` : '');\n}\n\n/** A subscription's public schedule fields, as the API returns them. */\nexport interface ScheduleDealLike {\n paymentSchedule?: Array<{ amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null }> | null;\n scheduleTotal?: number | null;\n}\n\n/**\n * A varied schedule's deal — its total (every row's net: seats in, discounts\n * out) and its payment count — or null for an equal plan, whose synthesized\n * schedule keeps the per-period label, and for an ongoing plan. A varied\n * schedule has no per-period price: `amount` and the cadence columns hold only\n * the next row's (ruling R-FR4). Every surface gates both its price and its\n * cadence cells on this one answer.\n */\nexport function scheduleDeal(sub: ScheduleDealLike): { total: number; payments: number } | null {\n if (!sub.paymentSchedule || sub.scheduleTotal == null || !isVariedSchedule(sub.paymentSchedule)) return null;\n return { total: sub.scheduleTotal, payments: sub.paymentSchedule.length };\n}\n\n/** \"$100.00 total · 4 payments\" for a varied schedule, else null. `money` keeps each surface's money style. */\nexport function scheduleDealLabel(sub: ScheduleDealLike, money: (minor: number) => string): string | null {\n const deal = scheduleDeal(sub);\n return deal ? `${money(deal.total)} total · ${deal.payments} payments` : null;\n}\n","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { useQuoteRequestForm } from './hooks';\nimport type { QuoteRequestItem, QuotesClientOptions } from './types';\n\nexport interface QuoteRequestFormProps {\n /** The `qrf_…` token from the merchant's hosted form URL. */\n formToken: string;\n options?: QuotesClientOptions;\n /**\n * Turnstile token, when the form requires it. Render the widget yourself and\n * pass its token through — this package deliberately pulls in no Cloudflare\n * script. If `config.fields.requireTurnstile` is set and this is empty, the\n * API fails the submission closed.\n */\n turnstileToken?: string;\n /**\n * Lines to submit with the request — typically `useQuoteCart().lines` after\n * the buyer has been adding products while browsing. When present, the\n * written message is optional.\n */\n items?: QuoteRequestItem[];\n onSubmitted?: () => void;\n loadingFallback?: ReactNode;\n className?: string;\n}\n\n/** Off-screen but still focusable-free; bots fill it, humans never see it. */\nconst honeypotStyle: CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n whiteSpace: 'nowrap',\n border: 0,\n};\n\n/**\n * Hosted RFQ intake form.\n *\n * Bot protection is wired in for you: the honeypot field and the mount-time\n * anchor that feeds the API's minimum-fill-time check. A honeypot hit returns\n * a success-shaped response and creates nothing, so `onSubmitted` fires either\n * way — by design, a bot must not learn it was caught.\n */\nexport function QuoteRequestForm({\n formToken,\n options,\n turnstileToken,\n items,\n onSubmitted,\n loadingFallback,\n className,\n}: QuoteRequestFormProps) {\n const f = useQuoteRequestForm(formToken, options ?? {});\n // Lines the host collected while the buyer browsed (see `useQuoteCart`).\n // With any of these present the written message becomes optional: the ask\n // is the list.\n const lines = items ?? [];\n const [values, setValues] = useState({\n email: '',\n name: '',\n companyName: '',\n phone: '',\n buyerReference: '',\n addressLine1: '',\n addressLine2: '',\n city: '',\n stateProvince: '',\n postalCode: '',\n countryCode: '',\n message: '',\n website: '', // honeypot\n });\n\n const set = (k: keyof typeof values) => (e: { target: { value: string } }) =>\n setValues((prev) => ({ ...prev, [k]: e.target.value }));\n\n if (f.loading) return <>{loadingFallback ?? <p>Loading…</p>}</>;\n if (!f.config) return <p>This request form is not available.</p>;\n\n if (f.submitted) {\n const redirect = f.config.redirectUrl;\n // Re-check the scheme client-side even though the API rejects non-http(s)\n // on write — a stale row must not be able to script the host page.\n if (redirect && /^https?:\\/\\//i.test(redirect) && typeof window !== 'undefined') {\n window.location.href = redirect;\n }\n return <p>{f.config.successMessage ?? 'Thanks — we will be in touch shortly.'}</p>;\n }\n\n const fields = f.config.fields ?? {};\n\n return (\n <form\n className={className}\n onSubmit={(e) => {\n e.preventDefault();\n void f\n .submit({\n email: values.email,\n message: values.message || null,\n ...(lines.length > 0 ? { items: lines } : {}),\n name: values.name || null,\n companyName: fields.companyName ? values.companyName || null : null,\n phone: fields.phone ? values.phone || null : null,\n buyerReference: fields.buyerReference ? values.buyerReference || null : null,\n ...(fields.shippingAddress\n ? {\n shippingAddress: {\n addressLine1: values.addressLine1 || null,\n addressLine2: values.addressLine2 || null,\n city: values.city || null,\n stateProvince: values.stateProvince || null,\n postalCode: values.postalCode || null,\n countryCode: values.countryCode || null,\n },\n }\n : {}),\n website: values.website || null,\n ...(turnstileToken ? { turnstileToken } : {}),\n })\n .then(() => onSubmitted?.())\n .catch(() => {\n /* surfaced via f.error */\n });\n }}\n >\n {f.config.title ? <h1>{f.config.title}</h1> : null}\n {f.config.introText ? <p>{f.config.introText}</p> : null}\n {f.error ? <p role=\"alert\">{f.error.message}</p> : null}\n\n <label>\n Email\n <input type=\"email\" value={values.email} onChange={set('email')} required />\n </label>\n <label>\n Name\n <input value={values.name} onChange={set('name')} />\n </label>\n {fields.companyName ? (\n <label>\n Company\n <input value={values.companyName} onChange={set('companyName')} />\n </label>\n ) : null}\n {fields.phone ? (\n <label>\n Phone\n <input value={values.phone} onChange={set('phone')} />\n </label>\n ) : null}\n {fields.shippingAddress ? (\n <fieldset>\n <legend>Shipping address (optional)</legend>\n <label>\n Address line 1\n <input value={values.addressLine1} onChange={set('addressLine1')} />\n </label>\n <label>\n Address line 2\n <input value={values.addressLine2} onChange={set('addressLine2')} />\n </label>\n <label>\n City\n <input value={values.city} onChange={set('city')} />\n </label>\n <label>\n State / province\n <input value={values.stateProvince} onChange={set('stateProvince')} />\n </label>\n <label>\n Postal code\n <input value={values.postalCode} onChange={set('postalCode')} />\n </label>\n <label>\n Country code (e.g. US)\n <input value={values.countryCode} onChange={set('countryCode')} maxLength={2} />\n </label>\n </fieldset>\n ) : null}\n {fields.buyerReference ? (\n <label>\n Your reference #\n <input value={values.buyerReference} onChange={set('buyerReference')} />\n </label>\n ) : null}\n {lines.length > 0 ? (\n <ul aria-label=\"Items on this request\">\n {lines.map((line, index) => (\n <li key={line.sku ?? line.referenceId ?? `${line.name}-${index}`}>\n {line.quantity ?? 1} × {line.name}\n {line.sku ? ` (${line.sku})` : ''}\n {line.note ? ` — ${line.note}` : ''}\n </li>\n ))}\n </ul>\n ) : null}\n <label>\n {lines.length > 0 ? 'Anything else we should know?' : 'What do you need?'}\n <textarea\n value={values.message}\n onChange={set('message')}\n required={lines.length === 0}\n />\n </label>\n\n <div style={honeypotStyle} aria-hidden=\"true\">\n <label>\n Website\n <input\n name=\"website\"\n tabIndex={-1}\n autoComplete=\"off\"\n value={values.website}\n onChange={set('website')}\n />\n </label>\n </div>\n\n <button\n type=\"submit\"\n disabled={f.submitting || !values.email || (!values.message && lines.length === 0)}\n >\n {f.submitting ? 'Sending…' : 'Request a quote'}\n </button>\n </form>\n );\n}\n"],"mappings":";AAAA,SAAS,qBAA6C;AAc/C,IAAM,sBAAN,cAAkC,cAAc;AAAA,EACrD,YAAY,MAMT;AACD,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,eAAwB;AAC1B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,IAAI,YAAqB;AACvB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,oBAAwC;AAC1C,UAAM,IAAI,KAAK;AACf,WAAO,GAAG;AAAA,EACZ;AACF;;;AC5BA,IAAM,eAAe;AAOd,IAAM,eAAN,MAAmB;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,OAA4B,CAAC,GAAG;AAC1C,UAAM,YAAY,KAAK,SAAS,WAAW;AAC3C,QAAI,CAAC,UAAW,OAAM,IAAI,MAAM,iCAAiC;AACjE,SAAK,WAAW,KAAK,WAAW,cAAc,QAAQ,QAAQ,EAAE;AAChE,SAAK,YAAY;AACjB,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AAAA,EAEA,MAAc,QAAW,QAAgB,MAAc,MAA4B;AACjF,UAAM,OAAO,IAAI,gBAAgB;AACjC,UAAM,QAAQ,WAAW,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS;AAC3D,QAAI;AACF,YAAM,MAAM,MAAM,KAAK,UAAU,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,QACzD;AAAA,QACA,SAAS,SAAS,SAAY,CAAC,IAAI,EAAE,gBAAgB,mBAAmB;A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,IACE;AAAA,QACJ,gBAAAA,MAAC,WACE;AAAA,gBAAM,SAAS,IAAI,kCAAkC;AAAA,UACtD,gBAAAD;AAAA,YAAC;AAAA;AAAA,cACC,OAAO,OAAO;AAAA,cACd,UAAU,IAAI,SAAS;AAAA,cACvB,UAAU,MAAM,WAAW;AAAA;AAAA,UAC7B;AAAA,WACF;AAAA,QAEA,gBAAAA,KAAC,SAAI,OAAO,eAAe,eAAY,QACrC,0BAAAC,MAAC,WAAM;AAAA;AAAA,UAEL,gBAAAD;AAAA,YAAC;AAAA;AAAA,cACC,MAAK;AAAA,cACL,UAAU;AAAA,cACV,cAAa;AAAA,cACb,OAAO,OAAO;AAAA,cACd,UAAU,IAAI,SAAS;AAAA;AAAA,UACzB;AAAA,WACF,GACF;AAAA,QAEA,gBAAAA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,UAAU,EAAE,cAAc,CAAC,OAAO,SAAU,CAAC,OAAO,WAAW,MAAM,WAAW;AAAA,YAE/E,YAAE,aAAa,kBAAa;AAAA;AAAA,QAC/B;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["useState","row","useState","useState","Fragment","jsx","jsxs","useState"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/hooks.ts","../src/quote-cart.ts","../src/QuoteView.tsx","../../core-cadence/src/cadence.ts","../../core-cadence/src/schedule.ts","../../core-cadence/src/labels.ts","../src/QuoteRequestForm.tsx","../src/index.tsx"],"sourcesContent":["import { formatMoney as formatMinor } from '@usethrottle/money';\nimport { ThrottleQuotesError } from './errors';\nimport type {\n AcceptQuoteInput,\n AcceptQuoteResult,\n BuyerQuote,\n QuoteComment,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n ThrottleEnvelope,\n} from './types';\n\nconst DEFAULT_BASE = 'https://api.usethrottle.dev';\n\n/**\n * Headless client for the public quote surfaces. Everything is authorized by\n * the capability token in the URL — there is no API key here, and there must\n * not be: this runs in the buyer's browser.\n */\nexport class QuotesClient {\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: QuotesClientOptions = {}) {\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('QuotesClient: fetch is required');\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE).replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n try {\n const res = await this.fetchImpl(`${this.baseUrl}${path}`, {\n method,\n headers: body === undefined ? {} : { 'content-type': 'application/json' },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n signal: ctrl.signal,\n });\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleQuotesError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n responseHeaders: res.headers,\n });\n }\n return json.data as T;\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** Fetch the quote a buyer link points at. 404s for unknown/rotated tokens. */\n getQuote(token: string): Promise<BuyerQuote> {\n return this.request<BuyerQuote>('GET', `/api/v1/quote-links/${encodeURIComponent(token)}`);\n }\n\n /**\n * Tell the merchant the buyer opened the quote. Fire-and-forget: the server\n * throttles the resulting webhook to one per revision per 6h, and a failed\n * beacon must never break the page.\n */\n async recordView(token: string): Promise<void> {\n try {\n await this.request('POST', `/api/v1/quote-links/${encodeURIComponent(token)}/view`, {});\n } catch {\n /* telemetry only */\n }\n }\n\n addComment(token: string, input: { body: string; authorName?: string; authorEmail?: string }) {\n return this.request<QuoteComment>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/comments`,\n input,\n );\n }\n\n requestRevision(token: string, input: { message?: string; authorName?: string } = {}) {\n return this.request<BuyerQuote>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/request-revision`,\n input,\n );\n }\n\n decline(token: string, input: { reason?: string; authorName?: string } = {}) {\n return this.request<BuyerQuote>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/decline`,\n input,\n );\n }\n\n /**\n * Accept and get the checkout URL to send the buyer to.\n *\n * Re-accepting the same revision is idempotent and replays the same URL.\n * Accepting a superseded revision throws `revision_superseded` carrying\n * `currentRevisionId`; an expired offer throws `quote_expired`.\n */\n accept(token: string, input: AcceptQuoteInput): Promise<AcceptQuoteResult> {\n return this.request<AcceptQuoteResult>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/accept`,\n input,\n );\n }\n\n /**\n * Send a buyer who already accepted back to a LIVE checkout.\n *\n * Checkout sessions expire after 30 minutes, so the URL returned by\n * `accept` is usually dead by the time the buyer returns to the link. This\n * re-opens a session against the same cart when it is (no re-pricing).\n * Throws `checkout_not_resumable` if the quote was never accepted, and\n * `checkout_completed` once it has been paid.\n */\n resumeCheckout(token: string): Promise<{ checkoutUrl: string }> {\n return this.request<{ checkoutUrl: string }>(\n 'POST',\n `/api/v1/quote-links/${encodeURIComponent(token)}/checkout`,\n {},\n );\n }\n\n /** URL of the PDF for the revision the buyer is looking at (server 302s to signed storage). */\n pdfUrl(token: string): string {\n return `${this.baseUrl}/api/v1/quote-links/${encodeURIComponent(token)}/pdf`;\n }\n\n // ── RFQ intake ─────────────────────────────────────────────────────────────\n\n getRequestForm(formToken: string): Promise<RequestFormConfig> {\n return this.request<RequestFormConfig>(\n 'GET',\n `/api/v1/quote-request-forms/${encodeURIComponent(formToken)}/public`,\n );\n }\n\n /**\n * Submit an RFQ. The response is deliberately thin (`{ submitted: true }`) —\n * anonymous callers learn no internal identifiers. A submission caught by\n * the honeypot returns the same shape without creating anything, so a bot\n * cannot tell it was detected; treat success as \"accepted\", not \"created\".\n */\n submitRequest(formToken: string, input: SubmitQuoteRequestInput): Promise<{ submitted: boolean }> {\n return this.request<{ submitted: boolean }>('POST', '/api/v1/quote-requests', {\n formToken,\n ...input,\n });\n }\n}\n\nexport function createQuotesClient(opts: QuotesClientOptions = {}): QuotesClient {\n return new QuotesClient(opts);\n}\n\n// ── money formatting ─────────────────────────────────────────────────────────\n\n/**\n * Minor units → a display string, e.g. (104000, 'USD') → \"$1,040.00\".\n *\n * Digits are en-US on every surface and runtime, so `locale` no longer changes\n * them (it is kept so existing calls compile); the exponent is the currency's\n * own (JPY has none, KWD has three).\n *\n * @deprecated Use `money.formatMoney` from this package or `formatMoney` from\n * `@usethrottle/money`.\n */\nexport function formatMoney(minorUnits: number, currency: string, locale?: string): string {\n void locale;\n return formatMinor(minorUnits, currency);\n}\n\n/**\n * Scale a line's quoted tax/discount to an edited quantity.\n *\n * MUST match `scaleLineCharges` in @commerce/quotes — the server recomputes\n * the accepted total with this rule, and any divergence shows the buyer one\n * total and charges another.\n */\nexport function scaleLineCharges(\n item: { quantity: number; taxAmount: number; discountAmount: number },\n quantity: number,\n): { taxAmount: number; discountAmount: number } {\n const base = item.quantity;\n if (!base || base <= 0 || quantity === base) {\n return { taxAmount: item.taxAmount, discountAmount: item.discountAmount };\n }\n const ratio = quantity / base;\n return {\n taxAmount: Math.round(item.taxAmount * ratio),\n discountAmount: Math.round(item.discountAmount * ratio),\n };\n}\n\n/** A subscription line with a free trial: nothing is charged for it at acceptance. */\nexport function isFreeTrialLine(item: { recurring?: { trialDays?: number | null } | null }): boolean {\n return (item.recurring?.trialDays ?? 0) > 0;\n}\n\n/**\n * What one line charges at acceptance, at `quantity`. MUST match\n * `lineDueAtAcceptance` in @commerce/quotes (shared test vectors).\n */\nexport function lineDueAtAcceptance(\n item: {\n unitPrice: number;\n quantity: number;\n taxAmount: number;\n discountAmount: number;\n recurring?: { trialDays?: number | null } | null;\n },\n quantity: number,\n): number {\n const { taxAmount, discountAmount } = scaleLineCharges(item, quantity);\n return (isFreeTrialLine(item) ? 0 : item.unitPrice * quantity) + taxAmount - discountAmount;\n}\n\n/** Effective total for a selection, using the same math the server will apply. */\nexport function computeSelectionTotal(\n items: Array<{\n id: string;\n unitPrice: number;\n quantity: number;\n taxAmount: number;\n discountAmount: number;\n optional: boolean;\n recurring?: { trialDays?: number | null } | null;\n }>,\n selections: Record<string, { selected: boolean; quantity: number }>,\n shippingTotal = 0,\n): number {\n let total = shippingTotal;\n for (const item of items) {\n const state = selections[item.id];\n if (item.optional && state && !state.selected) continue;\n const qty = state?.quantity ?? item.quantity;\n total += lineDueAtAcceptance(item, qty);\n }\n return total;\n}\n","import { ThrottleError, type ThrottleErrorArgs } from '@usethrottle/errors';\n\n/**\n * Every failure from the quote-link routes surfaces as this. The `code` is the\n * API's own error code, so callers can branch on the ones that matter to a\n * buyer flow rather than parsing messages:\n *\n * revision_superseded — a newer revision was issued; `details.currentRevisionId`\n * tells you what to reload\n * quote_expired — the offer lapsed (HTTP 410)\n * invalid_item_selection — locked-line edit, non-optional deselect, or unknown item\n * accept_in_progress — a concurrent accept won; retry shortly\n * not_found — unknown/rotated token, or a draft/archived quote\n */\nexport class ThrottleQuotesError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n responseHeaders?: ThrottleErrorArgs['responseHeaders'];\n }) {\n super(args);\n this.name = 'ThrottleQuotesError';\n }\n\n /** The offer moved on — reload and show the buyer the current revision. */\n get isSuperseded(): boolean {\n return this.code === 'revision_superseded';\n }\n\n get isExpired(): boolean {\n return this.code === 'quote_expired';\n }\n\n /** Revision the server considers current, when it told us (spec §8.1). */\n get currentRevisionId(): string | undefined {\n const d = this.details as { currentRevisionId?: string } | undefined;\n return d?.currentRevisionId;\n }\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { QuotesClient, computeSelectionTotal, createQuotesClient } from './client';\nimport { ThrottleQuotesError } from './errors';\nimport { createQuoteCart, type QuoteCart, type QuoteCartLine, type QuoteCartOptions } from './quote-cart';\nimport type {\n AcceptQuoteInput,\n BuyerQuote,\n ItemSelection,\n QuoteRequestItem,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n} from './types';\n\nexport interface UseQuoteResult {\n quote: BuyerQuote | null;\n loading: boolean;\n error: ThrottleQuotesError | null;\n /** Re-fetch — call after a `revision_superseded` to show the current offer. */\n refresh: () => Promise<void>;\n /** Buyer's current line choices, keyed by item id. */\n selections: Record<string, { selected: boolean; quantity: number }>;\n setSelected: (itemId: string, selected: boolean) => void;\n setQuantity: (itemId: string, quantity: number) => void;\n /** Live total for the current selections, using the server's own math. */\n total: number;\n accept: (\n input: Omit<AcceptQuoteInput, 'revisionId' | 'itemSelections'>,\n ) => Promise<{ checkoutUrl: string }>;\n /** Live checkout URL for a buyer returning to an already-accepted quote —\n * the one minted at acceptance has usually expired by then. */\n resumeCheckout: () => Promise<{ checkoutUrl: string }>;\n requestRevision: (message: string, authorName?: string) => Promise<void>;\n decline: (reason?: string, authorName?: string) => Promise<void>;\n addComment: (body: string, authorName?: string) => Promise<void>;\n pdfUrl: string;\n submitting: boolean;\n}\n\n/**\n * Everything the buyer quote page needs.\n *\n * Fires the view beacon once per mount, keeps line selections in local state,\n * and recomputes the total with the same rule the server applies at\n * acceptance — so the number the buyer sees is the number they are charged.\n */\nexport function useQuote(token: string, options: QuotesClientOptions = {}): UseQuoteResult {\n const client = useMemo(\n () => new QuotesClient(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.baseUrl, options.timeoutMs],\n );\n const [quote, setQuote] = useState<BuyerQuote | null>(null);\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [error, setError] = useState<ThrottleQuotesError | null>(null);\n const [selections, setSelections] = useState<Record<string, { selected: boolean; quantity: number }>>({});\n const beaconSent = useRef(false);\n\n const load = useCallback(async () => {\n setLoading(true);\n try {\n const q = await client.getQuote(token);\n setQuote(q);\n setError(null);\n // Seed selections from the revision's own defaults so a re-issue that\n // adds or locks lines resets the buyer's choices to the new offer.\n const next: Record<string, { selected: boolean; quantity: number }> = {};\n for (const item of q.currentRevision?.items ?? []) {\n next[item.id] = { selected: item.optional ? item.optionalSelected : true, quantity: item.quantity };\n }\n setSelections(next);\n } catch (e) {\n setError(e as ThrottleQuotesError);\n } finally {\n setLoading(false);\n }\n }, [client, token]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n useEffect(() => {\n if (!quote || beaconSent.current) return;\n beaconSent.current = true;\n void client.recordView(token);\n }, [client, quote, token]);\n\n const setSelected = useCallback((itemId: string, selected: boolean) => {\n setSelections((prev) => ({ ...prev, [itemId]: { ...(prev[itemId] ?? { quantity: 1 }), selected } }));\n }, []);\n\n const setQuantity = useCallback((itemId: string, quantity: number) => {\n setSelections((prev) => ({\n ...prev,\n [itemId]: { ...(prev[itemId] ?? { selected: true }), quantity: Math.max(1, Math.floor(quantity) || 1) },\n }));\n }, []);\n\n const total = useMemo(\n () =>\n computeSelectionTotal(\n quote?.currentRevision?.items ?? [],\n selections,\n quote?.currentRevision?.shippingTotal ?? 0,\n ),\n [quote, selections],\n );\n\n /** Only send selections the rep actually allows the buyer to change. */\n const buildSelections = useCallback((): ItemSelection[] => {\n const items = quote?.currentRevision?.items ?? [];\n const out: ItemSelection[] = [];\n for (const item of items) {\n const state = selections[item.id];\n if (!state) continue;\n const sel: ItemSelection = { itemId: item.id };\n let include = false;\n if (item.optional && state.selected !== item.optionalSelected) {\n sel.selected = state.selected;\n include = true;\n }\n if (item.qtyEditable && state.quantity !== item.quantity) {\n sel.quantity = state.quantity;\n include = true;\n }\n if (include) out.push(sel);\n }\n return out;\n }, [quote, selections]);\n\n const guard = useCallback(\n async <T,>(fn: () => Promise<T>): Promise<T> => {\n setSubmitting(true);\n try {\n const result = await fn();\n setError(null);\n return result;\n } catch (e) {\n const err = e as ThrottleQuotesError;\n setError(err);\n // A superseded offer means our copy is stale — pull the current one so\n // the buyer sees what they can actually accept (spec §8.1).\n if (err.isSuperseded) void load();\n throw err;\n } finally {\n setSubmitting(false);\n }\n },\n [load],\n );\n\n const accept = useCallback(\n async (input: Omit<AcceptQuoteInput, 'revisionId' | 'itemSelections'>) => {\n const revisionId = quote?.currentRevision?.id;\n if (!revisionId) throw new Error('useQuote: no current revision to accept');\n const itemSelections = buildSelections();\n const res = await guard(() =>\n client.accept(token, {\n ...input,\n revisionId,\n ...(itemSelections.length ? { itemSelections } : {}),\n }),\n );\n return { checkoutUrl: res.checkoutUrl };\n },\n [buildSelections, client, guard, quote, token],\n );\n\n const resumeCheckout = useCallback(\n async () => guard(() => client.resumeCheckout(token)),\n [client, guard, token],\n );\n\n const requestRevision = useCallback(\n async (message: string, authorName?: string) => {\n const q = await guard(() => client.requestRevision(token, { message, authorName }));\n setQuote(q);\n },\n [client, guard, token],\n );\n\n const decline = useCallback(\n async (reason?: string, authorName?: string) => {\n const q = await guard(() => client.decline(token, { reason, authorName }));\n setQuote(q);\n },\n [client, guard, token],\n );\n\n const addComment = useCallback(\n async (body: string, authorName?: string) => {\n await guard(() => client.addComment(token, { body, authorName }));\n await load();\n },\n [client, guard, load, token],\n );\n\n return {\n quote,\n loading,\n error,\n refresh: load,\n selections,\n setSelected,\n setQuantity,\n total,\n accept,\n resumeCheckout,\n requestRevision,\n decline,\n addComment,\n pdfUrl: client.pdfUrl(token),\n submitting,\n };\n}\n\nexport interface UseQuoteRequestFormResult {\n config: RequestFormConfig | null;\n loading: boolean;\n error: ThrottleQuotesError | null;\n submitting: boolean;\n submitted: boolean;\n submit: (input: SubmitQuoteRequestInput) => Promise<void>;\n /** Mount time; pass through so the API's minimum-fill-time check passes. */\n formLoadedAt: number;\n}\n\n/** Loads a hosted RFQ form's config and submits it, with bot fields handled. */\nexport function useQuoteRequestForm(\n formToken: string,\n options: QuotesClientOptions = {},\n): UseQuoteRequestFormResult {\n const client = useMemo(\n () => new QuotesClient(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.baseUrl, options.timeoutMs],\n );\n const [config, setConfig] = useState<RequestFormConfig | null>(null);\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<ThrottleQuotesError | null>(null);\n const formLoadedAt = useRef(Date.now()).current;\n\n useEffect(() => {\n let cancelled = false;\n (async () => {\n try {\n const cfg = await client.getRequestForm(formToken);\n if (!cancelled) setConfig(cfg);\n } catch (e) {\n if (!cancelled) setError(e as ThrottleQuotesError);\n } finally {\n if (!cancelled) setLoading(false);\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [client, formToken]);\n\n const submit = useCallback(\n async (input: SubmitQuoteRequestInput) => {\n setSubmitting(true);\n try {\n await client.submitRequest(formToken, { formLoadedAt, ...input });\n setSubmitted(true);\n setError(null);\n } catch (e) {\n setError(e as ThrottleQuotesError);\n throw e;\n } finally {\n setSubmitting(false);\n }\n },\n [client, formLoadedAt, formToken],\n );\n\n return { config, loading, error, submitting, submitted, submit, formLoadedAt };\n}\n\nexport { createQuotesClient };\n\nexport interface UseQuoteCartResult {\n lines: QuoteCartLine[];\n /** Total quantity across lines — for a header badge. */\n count: number;\n add: (item: QuoteRequestItem) => void;\n addMany: (items: QuoteRequestItem[]) => void;\n update: (key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>) => void;\n remove: (key: string) => void;\n clear: () => void;\n /** The underlying cart, for use outside React (an Add to Quote button in plain JS). */\n cart: QuoteCart;\n}\n\n/**\n * A quote cart the buyer fills while browsing, then submits as one request.\n *\n * The cart persists across page views, so an Add to Quote button on a product\n * page and a Request quote page elsewhere on the site see the same lines.\n * Pass the result of `toRequestItems()` (or `lines`) to\n * `useQuoteRequestForm().submit` as `items`.\n */\nexport function useQuoteCart(options: QuoteCartOptions = {}): UseQuoteCartResult {\n const cart = useMemo(\n () => createQuoteCart(options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.storageKey, options.maxLines],\n );\n // Seeded empty rather than from storage: reading localStorage during render\n // makes the server and the first client render disagree, which is a\n // hydration mismatch. The effect below fills it in immediately after mount.\n const [lines, setLines] = useState<QuoteCartLine[]>([]);\n\n useEffect(() => {\n setLines(cart.read());\n return cart.subscribe(setLines);\n }, [cart]);\n\n return {\n lines,\n count: lines.reduce((sum, line) => sum + line.quantity, 0),\n add: useCallback((item: QuoteRequestItem) => void cart.add(item), [cart]),\n addMany: useCallback((items: QuoteRequestItem[]) => void cart.addMany(items), [cart]),\n update: useCallback(\n (key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>) => void cart.update(key, patch),\n [cart],\n ),\n remove: useCallback((key: string) => void cart.remove(key), [cart]),\n clear: useCallback(() => cart.clear(), [cart]),\n cart,\n };\n}\n","import type { QuoteRequestItem } from './types';\n\n/**\n * A quote cart: the buyer's running list of things to be quoted, built up\n * while they browse.\n *\n * Throttle stores no catalog, so the storefront owns product data and hands\n * lines in — the same arrangement as the shopping cart. Nothing here is sent\n * until `read()` is submitted through `QuotesClient.submitRequest`, and the\n * amounts a storefront attaches are the buyer's TARGET price, never a price\n * we will honour.\n *\n * Lines are keyed by `sku ?? referenceId ?? name`, so adding the same product\n * twice increases its quantity instead of stacking duplicate rows.\n */\n\nexport interface QuoteCartLine extends QuoteRequestItem {\n /** Stable identity for updates and removals. */\n key: string;\n quantity: number;\n}\n\nexport interface QuoteCartStorage {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\nexport interface QuoteCartOptions {\n /** Namespacing key, so two storefronts on one origin cannot collide. */\n storageKey?: string;\n /**\n * Where the cart survives page navigation. Defaults to `localStorage` in a\n * browser and to memory everywhere else (SSR, tests) — a cart that throws\n * during server rendering would take the whole page down.\n */\n storage?: QuoteCartStorage | null;\n /** Refuse to grow past this many distinct lines. The API caps at 100. */\n maxLines?: number;\n}\n\nconst DEFAULT_KEY = 'throttle:quote-cart';\nconst DEFAULT_MAX_LINES = 100;\n\nfunction memoryStorage(): QuoteCartStorage {\n const map = new Map<string, string>();\n return {\n getItem: (key) => map.get(key) ?? null,\n setItem: (key, value) => void map.set(key, value),\n removeItem: (key) => void map.delete(key),\n };\n}\n\nfunction defaultStorage(): QuoteCartStorage {\n try {\n if (typeof globalThis !== 'undefined' && (globalThis as any).localStorage) {\n return (globalThis as any).localStorage as QuoteCartStorage;\n }\n } catch {\n // Safari in private mode throws on access rather than returning null.\n }\n return memoryStorage();\n}\n\nfunction lineKey(item: QuoteRequestItem): string {\n const raw = item.sku?.trim() || item.referenceId?.trim() || item.name.trim();\n return raw.toLowerCase();\n}\n\nfunction normalizeQuantity(value: number | null | undefined): number {\n const n = Math.floor(Number(value ?? 1));\n return Number.isFinite(n) && n > 0 ? n : 1;\n}\n\nexport interface QuoteCart {\n /** Current lines, oldest first. */\n read(): QuoteCartLine[];\n /** Total quantity across lines — what a header badge should show. */\n count(): number;\n /** Add a line, merging quantities into an existing one with the same key. */\n add(item: QuoteRequestItem): QuoteCartLine[];\n /** Add several at once (a \"quote this whole cart\" button). */\n addMany(items: QuoteRequestItem[]): QuoteCartLine[];\n /** Change any field of a line. A quantity below 1 removes it. */\n update(key: string, patch: Partial<Omit<QuoteCartLine, 'key'>>): QuoteCartLine[];\n remove(key: string): QuoteCartLine[];\n clear(): void;\n /** Subscribe to every change. Returns an unsubscribe function. */\n subscribe(listener: (lines: QuoteCartLine[]) => void): () => void;\n /** The `items` payload for `QuotesClient.submitRequest`. */\n toRequestItems(): QuoteRequestItem[];\n}\n\nexport function createQuoteCart(options: QuoteCartOptions = {}): QuoteCart {\n const storageKey = options.storageKey ?? DEFAULT_KEY;\n const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n const storage = options.storage === null ? memoryStorage() : (options.storage ?? defaultStorage());\n const listeners = new Set<(lines: QuoteCartLine[]) => void>();\n\n function load(): QuoteCartLine[] {\n try {\n const raw = storage.getItem(storageKey);\n if (!raw) return [];\n const parsed = JSON.parse(raw);\n if (!Array.isArray(parsed)) return [];\n // Storage is buyer-writable — anything shaped wrong is dropped rather\n // than trusted into a submission.\n return parsed\n .filter((line: any) => line && typeof line.name === 'string' && line.name.trim())\n .map((line: any) => ({\n ...line,\n key: typeof line.key === 'string' && line.key ? line.key : lineKey(line),\n quantity: normalizeQuantity(line.quantity),\n }))\n .slice(0, maxLines);\n } catch {\n return [];\n }\n }\n\n function save(lines: QuoteCartLine[]): QuoteCartLine[] {\n try {\n storage.setItem(storageKey, JSON.stringify(lines));\n } catch {\n // Quota or a disabled store — the cart still works for this page view.\n }\n for (const listener of listeners) listener(lines);\n return lines;\n }\n\n return {\n read: load,\n\n count() {\n return load().reduce((sum, line) => sum + line.quantity, 0);\n },\n\n add(item) {\n return this.addMany([item]);\n },\n\n addMany(items) {\n const lines = load();\n for (const item of items) {\n if (!item?.name?.trim()) continue;\n const key = lineKey(item);\n const existing = lines.find((line) => line.key === key);\n if (existing) {\n existing.quantity += normalizeQuantity(item.quantity);\n // Later detail wins — a product page knows more than a listing card.\n if (item.note) existing.note = item.note;\n if (item.targetUnitPrice != null) existing.targetUnitPrice = item.targetUnitPrice;\n continue;\n }\n if (lines.length >= maxLines) break;\n lines.push({ ...item, key, quantity: normalizeQuantity(item.quantity) });\n }\n return save(lines);\n },\n\n update(key, patch) {\n const lines = load();\n const index = lines.findIndex((line) => line.key === key);\n if (index === -1) return lines;\n if (patch.quantity != null && Math.floor(Number(patch.quantity)) < 1) {\n lines.splice(index, 1);\n return save(lines);\n }\n lines[index] = {\n ...lines[index],\n ...patch,\n key,\n quantity: normalizeQuantity(patch.quantity ?? lines[index].quantity),\n };\n return save(lines);\n },\n\n remove(key) {\n return save(load().filter((line) => line.key !== key));\n },\n\n clear() {\n try {\n storage.removeItem(storageKey);\n } catch {\n // Ignore — the notification below still resets any subscriber.\n }\n for (const listener of listeners) listener([]);\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => void listeners.delete(listener);\n },\n\n toRequestItems() {\n return load().map(({ key: _key, ...item }) => item);\n },\n };\n}\n","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { recurringTermsLabel } from '@core/cadence';\nimport { formatMoney } from '@usethrottle/money';\nimport { lineDueAtAcceptance } from './client';\nimport { useQuote } from './hooks';\nimport type { QuotesClientOptions } from './types';\n\nexport interface QuoteViewProps {\n /** The `qtl_…` token from the buyer's link. */\n token: string;\n options?: QuotesClientOptions;\n /**\n * Where to send the buyer after acceptance. Defaults to assigning\n * `window.location.href`, which is what the hosted page does.\n */\n onCheckout?: (checkoutUrl: string) => void;\n /** Rendered instead of the built-in markup while loading. */\n loadingFallback?: ReactNode;\n className?: string;\n}\n\nconst row: CSSProperties = { display: 'flex', justifyContent: 'space-between', gap: 16, padding: '8px 0' };\n\nconst muted: CSSProperties = { color: '#666', fontSize: 13 };\n\n/**\n * Drop-in buyer quote page: line items with optional toggles and quantity\n * editing, live totals, revision history, comment thread, and the\n * accept / request-changes / decline actions.\n *\n * Intentionally unstyled beyond a readable default — it is meant to be\n * restyled or replaced. `useQuote` carries all the behaviour if you want to\n * build your own presentation.\n */\nexport function QuoteView({ token, options, onCheckout, loadingFallback, className }: QuoteViewProps) {\n const q = useQuote(token, options ?? {});\n const [name, setName] = useState('');\n const [email, setEmail] = useState('');\n const [showAccept, setShowAccept] = useState(false);\n const [comment, setComment] = useState('');\n\n if (q.loading) return <>{loadingFallback ?? <p>Loading quote…</p>}</>;\n if (!q.quote) {\n return <p>This quote link is no longer available.</p>;\n }\n\n const quote = q.quote;\n const rev = quote.currentRevision;\n const currency = quote.currency;\n const ordered = quote.status === 'ordered';\n const accepted = quote.status === 'accepted';\n const canAct = quote.status === 'ready';\n // The subscription lines the buyer is keeping (an unticked optional plan drops out).\n const recurringKept = rev\n ? rev.items.filter((i) => i.recurring && (!i.optional || (q.selections[i.id]?.selected ?? true)))\n : [];\n\n const handleResume = async () => {\n const { checkoutUrl } = await q.resumeCheckout();\n if (onCheckout) onCheckout(checkoutUrl);\n else if (typeof window !== 'undefined') window.location.href = checkoutUrl;\n };\n\n const handleAccept = async () => {\n const { checkoutUrl } = await q.accept({ acceptedByName: name, acceptedByEmail: email });\n if (onCheckout) onCheckout(checkoutUrl);\n else if (typeof window !== 'undefined') window.location.href = checkoutUrl;\n };\n\n return (\n <div className={className}>\n <header>\n {quote.branding?.displayName ? <p style={muted}>{quote.branding.displayName}</p> : null}\n <h1>Quote {quote.quoteNumber}</h1>\n <p style={muted}>{statusLabel(quote.status)}</p>\n {quote.buyerReference ? <p style={muted}>Your reference: {quote.buyerReference}</p> : null}\n {rev ? (\n <p style={muted}>\n Revision {rev.revisionNumber}\n {rev.expiresAt ? ` · valid until ${new Date(rev.expiresAt).toLocaleDateString()}` : null}\n {' · '}\n <a href={q.pdfUrl}>Download PDF</a>\n </p>\n ) : null}\n </header>\n\n {q.error ? (\n <p role=\"alert\">\n {q.error.isSuperseded\n ? 'This quote was updated — showing the latest version.'\n : q.error.message}\n </p>\n ) : null}\n\n {rev ? (\n <table style={{ width: '100%', borderCollapse: 'collapse' }}>\n <thead>\n <tr>\n <th align=\"left\">Item</th>\n <th align=\"right\">Unit price</th>\n <th align=\"right\">Qty</th>\n <th align=\"right\">Total</th>\n </tr>\n </thead>\n <tbody>\n {rev.items.map((item) => {\n const state = q.selections[item.id] ?? { selected: true, quantity: item.quantity };\n const included = item.optional ? state.selected : true;\n return (\n <tr key={item.id}>\n <td>\n {item.optional ? (\n <label>\n <input\n type=\"checkbox\"\n checked={state.selected}\n disabled={!canAct}\n onChange={(e) => q.setSelected(item.id, e.target.checked)}\n />{' '}\n {item.name} <span style={muted}>optional</span>\n </label>\n ) : (\n item.name\n )}\n {item.description ? <div style={muted}>{item.description}</div> : null}\n {item.recurring ? (\n <div style={muted}>\n Subscription · {recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) => formatMoney(m, currency))}\n </div>\n ) : null}\n </td>\n <td align=\"right\">{formatMoney(item.unitPrice, currency)}</td>\n <td align=\"right\">\n {item.qtyEditable && canAct ? (\n <input\n type=\"number\"\n min={1}\n value={state.quantity}\n disabled={!included}\n aria-label={`Quantity for ${item.name}`}\n onChange={(e) => q.setQuantity(item.id, Number(e.target.value))}\n style={{ width: 64 }}\n />\n ) : (\n state.quantity\n )}\n </td>\n <td align=\"right\">\n {formatMoney(included ? lineDueAtAcceptance(item, state.quantity) : 0, currency)}\n </td>\n </tr>\n );\n })}\n </tbody>\n </table>\n ) : null}\n\n {rev ? (\n <section>\n <div style={row}>\n <strong>{recurringKept.length > 0 ? 'Due at acceptance' : 'Total'}</strong>\n <strong>{formatMoney(q.total, currency)}</strong>\n </div>\n {recurringKept.length > 0 ? (\n <div>\n <p style={muted}>Recurring after</p>\n {recurringKept.map((i) => (\n <p key={i.id} style={muted}>\n {i.name}: {recurringTermsLabel(i.recurring!, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) => formatMoney(m, currency))}\n </p>\n ))}\n </div>\n ) : null}\n <p style={muted}>{termsLabel(rev.paymentTerms, rev.depositAmount, currency)}</p>\n {rev.leadTime ? <p style={muted}>Lead time: {rev.leadTime}</p> : null}\n {rev.buyerNote ? <blockquote>{rev.buyerNote}</blockquote> : null}\n </section>\n ) : null}\n\n {ordered ? (\n <p>\n Ordered{quote.orderId ? ` — order ${quote.orderId}` : ''}. Thank you.\n </p>\n ) : accepted ? (\n // Accepted but not yet paid. The checkout session minted at acceptance\n // expires in 30 minutes, so this asks the server for a live one rather\n // than linking to a URL that is probably dead.\n <section>\n <p>You accepted this quote — payment is not finished yet.</p>\n <button type=\"button\" disabled={q.submitting} onClick={() => void handleResume()}>\n Continue to checkout\n </button>\n </section>\n ) : canAct ? (\n <section>\n {showAccept ? (\n <form\n onSubmit={(e) => {\n e.preventDefault();\n void handleAccept();\n }}\n >\n <label>\n Your name\n <input value={name} onChange={(e) => setName(e.target.value)} required />\n </label>\n <label>\n Email\n <input type=\"email\" value={email} onChange={(e) => setEmail(e.target.value)} required />\n </label>\n <button type=\"submit\" disabled={q.submitting || !name || !email}>\n Confirm & continue to payment\n </button>\n </form>\n ) : (\n <button type=\"button\" onClick={() => setShowAccept(true)}>\n Accept & checkout\n </button>\n )}\n <button\n type=\"button\"\n disabled={q.submitting}\n onClick={() => void q.requestRevision('Please revise this quote.', name || undefined)}\n >\n Request changes\n </button>\n <button type=\"button\" disabled={q.submitting} onClick={() => void q.decline(undefined, name || undefined)}>\n Decline\n </button>\n </section>\n ) : null}\n\n {quote.revisionHistory.length > 0 ? (\n <details>\n <summary>Previous versions ({quote.revisionHistory.length})</summary>\n <ul>\n {quote.revisionHistory.map((r) => (\n <li key={r.id}>\n Revision {r.revisionNumber} — {formatMoney(r.total, currency)}\n {r.changeSummary ? ` · ${r.changeSummary}` : ''}\n </li>\n ))}\n </ul>\n </details>\n ) : null}\n\n <section>\n <h2>Questions</h2>\n {quote.comments.map((c) => (\n <p key={c.id}>\n <strong>{c.authorName ?? (c.authorType === 'merchant' ? 'Seller' : 'You')}:</strong> {c.body}\n </p>\n ))}\n <form\n onSubmit={(e) => {\n e.preventDefault();\n const body = comment.trim();\n if (!body) return;\n setComment('');\n void q.addComment(body, name || undefined);\n }}\n >\n <input\n value={comment}\n onChange={(e) => setComment(e.target.value)}\n placeholder=\"Ask a question…\"\n aria-label=\"Ask a question\"\n />\n <button type=\"submit\" disabled={q.submitting || !comment.trim()}>\n Send\n </button>\n </form>\n </section>\n </div>\n );\n}\n\nfunction statusLabel(status: string): string {\n switch (status) {\n case 'in_progress':\n return 'We are preparing your quote';\n case 'ready':\n return 'Ready for your review';\n case 'being_revised':\n return 'We are revising this quote';\n case 'accepted':\n return 'Accepted — completing payment';\n case 'ordered':\n return 'Ordered';\n case 'declined':\n return 'Declined';\n case 'expired':\n return 'This quote has expired — request updated pricing';\n default:\n return status;\n }\n}\n\nfunction termsLabel(\n terms: { mode: string; netN?: number; balanceNetN?: number },\n depositAmount: number | null,\n currency: string,\n): string {\n if (terms.mode === 'net_terms') return `Payment terms: Net ${terms.netN}`;\n if (terms.mode === 'deposit_balance') {\n const dep = depositAmount != null ? formatMoney(depositAmount, currency) : 'a deposit';\n return `${dep} due today, balance Net ${terms.balanceNetN}`;\n }\n return 'Payment in full';\n}\n","/**\n * A subscription's billing cadence: \"every N units\".\n *\n * Every subscription row stores a unit and a count; the five named intervals\n * are shorthand for particular combinations. This module is the only place\n * that knows the vocabulary, the bounds, and how a period boundary is\n * computed — the engine, the renewal cron, the API, the dashboard and the\n * buyer surfaces all import it. Before it existed there were three divergent\n * copies of the period math, and the renewal cron's advanced months with\n * `setMonth`, which overflows: a subscription started on Jan 31 renewed on\n * Mar 3 and never returned to the 31st.\n */\n\nexport const INTERVAL_UNITS = ['hour', 'day', 'week', 'month'] as const;\nexport type IntervalUnit = (typeof INTERVAL_UNITS)[number];\n\nexport const NAMED_INTERVALS = ['weekly', 'biweekly', 'monthly', 'quarterly', 'yearly'] as const;\nexport type NamedInterval = (typeof NAMED_INTERVALS)[number];\n\n/** What the `interval` field holds: a named interval, or `custom` for everything else. */\nexport const INTERVAL_VALUES = [...NAMED_INTERVALS, 'custom'] as const;\nexport type IntervalValue = (typeof INTERVAL_VALUES)[number];\n\nexport interface Cadence {\n interval: IntervalValue;\n unit: IntervalUnit;\n count: number;\n}\n\n/** Anything that describes a cadence the way the API and the database do. */\nexport interface CadenceLike {\n interval: string;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface CadenceInput {\n interval?: string | null;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n}\n\nexport const NAMED_SHORTHAND: Readonly<Record<NamedInterval, { unit: IntervalUnit; count: number }>> = {\n weekly: { unit: 'week', count: 1 },\n biweekly: { unit: 'week', count: 2 },\n monthly: { unit: 'month', count: 1 },\n quarterly: { unit: 'month', count: 3 },\n // month × 12 rather than a year unit, so a Feb 29 anniversary clamps to Feb\n // 28 and comes back to Feb 29 in leap years like every other month cadence.\n yearly: { unit: 'month', count: 12 },\n};\n\n/** At most one year in every unit. The shortest cadence is 1 hour. */\nexport const MAX_INTERVAL_COUNT: Readonly<Record<IntervalUnit, number>> = {\n hour: 8760,\n day: 365,\n week: 52,\n month: 12,\n};\n\nexport const HOUR_MS = 3_600_000;\nexport const DAY_MS = 24 * HOUR_MS;\nexport const WEEK_MS = 7 * DAY_MS;\n\nconst FIXED_UNIT_MS = { hour: HOUR_MS, day: DAY_MS, week: WEEK_MS } as const;\n\nexport class CadenceError extends Error {\n readonly statusCode = 400;\n constructor(\n readonly code: 'invalid_interval' | 'interval_conflict',\n message: string,\n ) {\n super(message);\n this.name = 'CadenceError';\n }\n}\n\nexport function isNamedInterval(value: unknown): value is NamedInterval {\n return typeof value === 'string' && (NAMED_INTERVALS as readonly string[]).includes(value);\n}\n\nexport function isIntervalUnit(value: unknown): value is IntervalUnit {\n return typeof value === 'string' && (INTERVAL_UNITS as readonly string[]).includes(value);\n}\n\nfunction isIntervalValue(value: unknown): value is IntervalValue {\n return typeof value === 'string' && (INTERVAL_VALUES as readonly string[]).includes(value);\n}\n\nfunction reduceToLargestUnit(unit: IntervalUnit, count: number): { unit: IntervalUnit; count: number } {\n let u = unit;\n let c = count;\n if (u === 'hour' && c % 24 === 0) {\n u = 'day';\n c = c / 24;\n }\n if (u === 'day' && c % 7 === 0) {\n u = 'week';\n c = c / 7;\n }\n return { unit: u, count: c };\n}\n\nfunction namedFor(unit: IntervalUnit, count: number): NamedInterval | null {\n for (const name of NAMED_INTERVALS) {\n const s = NAMED_SHORTHAND[name];\n if (s.unit === unit && s.count === count) return name;\n }\n return null;\n}\n\n/**\n * Turn whatever a caller sent into the one stored form. Accepts a named\n * interval alone, a unit and count alone, or both — in which case they must\n * agree. The result is reduced to its largest exact unit and mapped to a named\n * interval whenever one matches, so there is exactly one representation per\n * cadence and \"every 2 weeks\" can never be filed apart from \"biweekly\".\n */\nexport function canonicalizeCadence(input: CadenceInput): Cadence {\n const interval = input.interval ?? undefined;\n if (interval !== undefined && !isIntervalValue(interval)) {\n throw new CadenceError('invalid_interval', `Unknown interval \"${interval}\"`);\n }\n const hasUnit = input.intervalUnit != null;\n const hasCount = input.intervalCount != null;\n if (hasUnit !== hasCount) {\n throw new CadenceError('invalid_interval', 'intervalUnit and intervalCount must be sent together');\n }\n if (!hasUnit) {\n if (isNamedInterval(interval)) return { interval, ...NAMED_SHORTHAND[interval] };\n throw new CadenceError(\n 'invalid_interval',\n interval === 'custom'\n ? 'A custom interval needs intervalUnit and intervalCount'\n : 'Send an interval, or intervalUnit and intervalCount',\n );\n }\n\n const unit = input.intervalUnit;\n const count = input.intervalCount as number;\n if (!isIntervalUnit(unit)) {\n throw new CadenceError('invalid_interval', 'intervalUnit must be one of hour, day, week, month');\n }\n if (!Number.isInteger(count) || count < 1) {\n throw new CadenceError('invalid_interval', 'intervalCount must be a whole number of at least 1');\n }\n if (count > MAX_INTERVAL_COUNT[unit]) {\n throw new CadenceError(\n 'invalid_interval',\n `A cadence can be at most one year: ${MAX_INTERVAL_COUNT[unit]} ${unit}s`,\n );\n }\n\n const reduced = reduceToLargestUnit(unit, count);\n const cadence: Cadence = { interval: namedFor(reduced.unit, reduced.count) ?? 'custom', ...reduced };\n if (interval !== undefined && interval !== 'custom' && interval !== cadence.interval) {\n throw new CadenceError(\n 'interval_conflict',\n `interval \"${interval}\" does not match every ${count} ${unit}${count === 1 ? '' : 's'}`,\n );\n }\n return cadence;\n}\n\n/**\n * Read the cadence off a stored subscription. A named interval always means\n * its shorthand, whatever the unit/count columns hold: a canonical row's\n * columns match the shorthand anyway, and code that predates the columns\n * (still serving between migration 0224 and the deploy) changes `interval`\n * without touching them, so for a named row they can be stale. Only a\n * `custom` row is read from its unit and count. The same rule applies to the\n * pending cadence — pass `{ interval: pendingInterval, intervalUnit:\n * pendingIntervalUnit, intervalCount: pendingIntervalCount }`.\n */\nexport function cadenceOf(row: CadenceLike): Cadence {\n if (isNamedInterval(row.interval)) return { interval: row.interval, ...NAMED_SHORTHAND[row.interval] };\n if (row.interval === 'custom' && row.intervalUnit != null && row.intervalCount != null && isIntervalUnit(row.intervalUnit)) {\n return { interval: 'custom', unit: row.intervalUnit, count: row.intervalCount };\n }\n throw new Error(`Unknown subscription interval: ${row.interval}`);\n}\n\n/** The exact period length for hour/day/week cadences; null for months, which vary. */\nexport function fixedPeriodMs(cadence: Cadence): number | null {\n return cadence.unit === 'month' ? null : cadence.count * FIXED_UNIT_MS[cadence.unit];\n}\n\n/** The shortest a period can be. A month counts as 28 days. */\nexport function minimumPeriodMs(cadence: Cadence): number {\n return fixedPeriodMs(cadence) ?? cadence.count * 28 * DAY_MS;\n}\n\n/** anchor + months, keeping the anchor's day-of-month (clamped to month end) and UTC time of day. */\nexport function addMonthsAnchored(anchor: Date, months: number): Date {\n const monthIndex = anchor.getUTCMonth() + months;\n const year = anchor.getUTCFullYear() + Math.floor(monthIndex / 12);\n const month = ((monthIndex % 12) + 12) % 12;\n const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();\n return new Date(\n Date.UTC(\n year,\n month,\n Math.min(anchor.getUTCDate(), lastDay),\n anchor.getUTCHours(),\n anchor.getUTCMinutes(),\n anchor.getUTCSeconds(),\n anchor.getUTCMilliseconds(),\n ),\n );\n}\n\n/**\n * The first period boundary strictly after `after`, on the grid measured from\n * `anchor`. Never chained from a previous boundary — that is what made the\n * month-end clamp stick on the 28th. An `after` that is off the grid (a late\n * tick, a recovery) resolves to the next grid date.\n */\nexport function nextPeriodEnd(args: { anchor: Date; cadence: Cadence; after: Date }): Date {\n const { anchor, cadence, after } = args;\n const step = fixedPeriodMs(cadence);\n if (step !== null) {\n const k = Math.max(1, Math.floor((after.getTime() - anchor.getTime()) / step) + 1);\n return new Date(anchor.getTime() + k * step);\n }\n const monthsElapsed =\n (after.getUTCFullYear() - anchor.getUTCFullYear()) * 12 + (after.getUTCMonth() - anchor.getUTCMonth());\n let k = Math.max(1, Math.floor(monthsElapsed / cadence.count));\n let boundary = addMonthsAnchored(anchor, k * cadence.count);\n while (boundary.getTime() <= after.getTime()) {\n k += 1;\n boundary = addMonthsAnchored(anchor, k * cadence.count);\n }\n return boundary;\n}\n\n/**\n * The grid period that contains `at`: the latest boundary at or before it (never\n * before the anchor) and the one after. A subscription that fell more than a\n * period behind is billed once, for this period, and the periods it missed are\n * skipped rather than charged back to back (D38).\n */\nexport function periodContaining(args: { anchor: Date; cadence: Cadence; at: Date }): { start: Date; end: Date } {\n const { anchor, cadence, at } = args;\n const step = fixedPeriodMs(cadence);\n if (step !== null) {\n const k = Math.max(0, Math.floor((at.getTime() - anchor.getTime()) / step));\n const start = new Date(anchor.getTime() + k * step);\n return { start, end: new Date(start.getTime() + step) };\n }\n const monthsElapsed =\n (at.getUTCFullYear() - anchor.getUTCFullYear()) * 12 + (at.getUTCMonth() - anchor.getUTCMonth());\n let k = Math.max(0, Math.floor(monthsElapsed / cadence.count));\n let start = addMonthsAnchored(anchor, k * cadence.count);\n while (k > 0 && start.getTime() > at.getTime()) {\n k -= 1;\n start = addMonthsAnchored(anchor, k * cadence.count);\n }\n return { start, end: addMonthsAnchored(anchor, (k + 1) * cadence.count) };\n}\n\nconst RETRY_CAP_DAYS = [1, 3, 7] as const;\n\n/**\n * How long to wait before retry number `failureNumber` (1..3). Short cadences\n * retry proportionally faster; anything of a week or longer lands on the\n * original 1 / 3 / 7 days exactly.\n */\nexport function dunningRetryDelayMs(cadence: Cadence, failureNumber: number): number {\n const n = Math.min(Math.max(Math.trunc(failureNumber), 1), RETRY_CAP_DAYS.length);\n return Math.min(n * minimumPeriodMs(cadence), RETRY_CAP_DAYS[n - 1] * DAY_MS);\n}\n\n/** The 3-days-ahead renewal reminder only makes sense for cadences of a week or longer. */\nexport function sendsRenewalReminder(cadence: Cadence): boolean {\n return minimumPeriodMs(cadence) >= WEEK_MS;\n}\n\n/**\n * Multiply a period's charge by this to get its monthly equivalent. Chosen so\n * `weekly` is exactly 52/12 and `biweekly` exactly 26/12, the factors\n * analytics already report — no existing MRR number moves.\n */\nexport function monthlyEquivalentFactor(cadence: Cadence): number {\n if (cadence.unit === 'month') return 1 / cadence.count;\n return (52 / 12) * (WEEK_MS / (fixedPeriodMs(cadence) as number));\n}\n","// packages/core-cadence/src/schedule.ts\n/**\n * Installment schedules: a plan whose payments differ in amount and in the gap\n * before each one. Row 0 is charged at signup and has no gap; row i's gap is\n * how long after payment i-1 it falls due. Gaps use the custom-cadence units\n * and bounds. Due dates are anchored and cumulative (spec S26): months are\n * clamped against the anchor's day, so a Jan 31 plan pays Feb 28, Mar 31,\n * Apr 30 — never chained from a clamped date.\n */\nimport {\n addMonthsAnchored,\n canonicalizeCadence,\n cadenceOf,\n CadenceError,\n fixedPeriodMs,\n isIntervalUnit,\n nextPeriodEnd,\n type Cadence,\n type IntervalUnit,\n} from './cadence';\nimport { MAX_TOTAL_PAYMENTS, MIN_TOTAL_PAYMENTS } from './installments';\n\nexport interface ScheduleRow {\n /** Gross, per unit of the line, minor units. */\n amount: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n}\n\n/** What `subscriptions.payment_schedule` holds, one per payment. */\nexport interface PaymentScheduleRow {\n /** Gross, per unit. */\n unitAmount: number;\n /** This payment's share of the deal discount, line total (quantity included). */\n discount: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n}\n\nexport type GapRow = { intervalUnit: IntervalUnit | null; intervalCount: number | null };\n\nexport type ScheduleErrorCode = 'invalid_schedule' | 'schedule_first_payment_mismatch';\n\nexport class ScheduleError extends Error {\n readonly statusCode = 400;\n constructor(\n readonly code: ScheduleErrorCode,\n message: string,\n ) {\n super(message);\n this.name = 'ScheduleError';\n }\n}\n\nconst ROW_KEYS = new Set(['amount', 'intervalUnit', 'intervalCount']);\n\nfunction invalid(message: string): ScheduleError {\n return new ScheduleError('invalid_schedule', message);\n}\n\n/** Validate and canonicalize a schedule. Every message starts with the row it is about. */\nexport function normalizeSchedule(input: unknown): ScheduleRow[] {\n if (!Array.isArray(input) || input.length < MIN_TOTAL_PAYMENTS || input.length > MAX_TOTAL_PAYMENTS) {\n throw invalid(`schedule must be an array of ${MIN_TOTAL_PAYMENTS} to ${MAX_TOTAL_PAYMENTS} payments`);\n }\n return input.map((raw, i) => {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw invalid(`schedule[${i}] must be an object`);\n const row = raw as Record<string, unknown>;\n const unknown = Object.keys(row).filter((k) => !ROW_KEYS.has(k));\n if (unknown.length > 0) throw invalid(`schedule[${i}] has unsupported field(s): ${unknown.join(', ')}`);\n const amount = row.amount;\n if (typeof amount !== 'number' || !Number.isInteger(amount) || amount <= 0) {\n throw invalid(`schedule[${i}].amount must be a whole number of minor units above 0`);\n }\n const hasUnit = row.intervalUnit != null;\n const hasCount = row.intervalCount != null;\n if (i === 0) {\n if (hasUnit || hasCount) throw invalid('schedule[0] is paid at signup and cannot have intervalUnit or intervalCount');\n return { amount, intervalUnit: null, intervalCount: null };\n }\n if (!hasUnit || !hasCount) throw invalid(`schedule[${i}] needs intervalUnit and intervalCount`);\n if (!isIntervalUnit(row.intervalUnit)) {\n throw invalid(`schedule[${i}].intervalUnit must be one of hour, day, week, month`);\n }\n let gap: Cadence;\n try {\n gap = canonicalizeCadence({ intervalUnit: row.intervalUnit, intervalCount: row.intervalCount as number });\n } catch (err) {\n if (err instanceof CadenceError) throw invalid(`schedule[${i}].intervalCount: ${err.message}`);\n throw err;\n }\n return { amount, intervalUnit: gap.unit, intervalCount: gap.count };\n });\n}\n\nexport function assertScheduleFirstPayment(schedule: ScheduleRow[], unitPrice: number): void {\n if (schedule[0].amount !== unitPrice) {\n throw new ScheduleError(\n 'schedule_first_payment_mismatch',\n `unitPrice (${unitPrice}) must equal schedule[0].amount (${schedule[0].amount}): payment 1 is what the line charges today`,\n );\n }\n}\n\nexport function scheduleUnitTotal(schedule: Array<{ amount: number }>): number {\n return schedule.reduce((sum, row) => sum + row.amount, 0);\n}\n\n/** A row's gap as a canonical cadence (interval name included), for the subscription's cadence columns. */\nexport function scheduleGapCadence(row: GapRow): Cadence {\n return canonicalizeCadence({ intervalUnit: row.intervalUnit, intervalCount: row.intervalCount });\n}\n\n/** Due time of payment `index`: the anchor plus every gap after `anchorIndex`, months first. */\nexport function scheduleDueAt(args: { anchor: Date; anchorIndex: number; rows: GapRow[]; index: number }): Date {\n const { anchor, anchorIndex, rows, index } = args;\n if (index < anchorIndex) throw new Error(`payment ${index} is before the anchor row ${anchorIndex}`);\n let months = 0;\n let fixedMs = 0;\n for (let j = anchorIndex + 1; j <= index; j += 1) {\n const gap = scheduleGapCadence(rows[j]);\n if (gap.unit === 'month') months += gap.count;\n else fixedMs += fixedPeriodMs(gap) as number;\n }\n return new Date(addMonthsAnchored(anchor, months).getTime() + fixedMs);\n}\n\n/**\n * The end of the period payment `index` pays for: the next payment's due time,\n * or — for the last payment, which nothing follows — its own gap once more.\n */\nexport function scheduleCoveredUntil(args: { anchor: Date; anchorIndex: number; rows: GapRow[]; index: number }): Date {\n const { rows, index } = args;\n if (index + 1 < rows.length) return scheduleDueAt({ ...args, index: index + 1 });\n const extended = [...rows, rows[index]];\n return scheduleDueAt({ ...args, rows: extended, index: index + 1 });\n}\n\n/** A line's subtotal as the discount engine sees it: the whole deal for an installment line (S33). */\nexport function lineDealSubtotal(line: {\n unitPrice?: number | null;\n quantity?: number | null;\n subtotal?: number | null;\n recurring?: unknown;\n}): number {\n const quantity = Number(line.quantity ?? 1);\n const unitPrice = Number(line.unitPrice ?? 0);\n const subtotal = line.subtotal != null ? Number(line.subtotal) : unitPrice * quantity;\n const r = line.recurring as { plan?: unknown; schedule?: unknown; totalPayments?: unknown; trialDays?: unknown } | null | undefined;\n if (!r || typeof r.plan !== 'string') return subtotal;\n if (Array.isArray(r.schedule)) return scheduleUnitTotal(r.schedule as Array<{ amount: number }>) * quantity;\n if (typeof r.totalPayments === 'number' && Number(r.trialDays ?? 0) === 0) return r.totalPayments * unitPrice * quantity;\n return subtotal;\n}\n\n/** S33: the part of a deal-wide discount that today's charge carries. */\nexport function todayShareOfDealDiscount(args: { dealDiscount: number; todayWeight: number; dealWeight: number }): number {\n const { dealDiscount, todayWeight, dealWeight } = args;\n if (dealDiscount <= 0 || dealWeight <= 0 || todayWeight <= 0) return 0;\n return Math.min(dealDiscount, Math.round((dealDiscount * todayWeight) / dealWeight));\n}\n\nexport interface PaymentScheduleViewRow {\n index: number;\n amount: number;\n discount: number;\n net: number;\n intervalUnit: IntervalUnit | null;\n intervalCount: number | null;\n status: 'paid' | 'due' | 'upcoming';\n dueAt: string | null;\n}\n\nexport interface PaymentScheduleView {\n rows: PaymentScheduleViewRow[];\n scheduleTotal: number;\n nextPaymentAmount: number | null;\n}\n\nexport type ScheduleSubLike = {\n status: string;\n amount: number;\n quantity?: number | null;\n totalPayments?: number | null;\n paymentsMade?: number | null;\n interval: string;\n intervalUnit?: string | null;\n intervalCount?: number | null;\n billingAnchorAt?: Date | string | null;\n currentPeriodEnd?: Date | string | null;\n scheduleRows?: PaymentScheduleRow[] | null;\n scheduleAnchorIndex?: number | null;\n};\n\nconst toDate = (v: Date | string | null | undefined): Date | null => (v == null ? null : new Date(v));\n\n/** The response view (spec §2, S35). Null for an ongoing subscription. */\nexport function paymentScheduleView(sub: ScheduleSubLike, _now: Date = new Date()): PaymentScheduleView | null {\n if (sub.totalPayments == null) return null;\n const quantity = sub.quantity ?? 1;\n const made = Math.min(sub.paymentsMade ?? 0, sub.totalPayments);\n const billing = ['active', 'past_due', 'paused', 'unpaid'].includes(sub.status);\n const rows: PaymentScheduleRow[] =\n sub.scheduleRows && sub.scheduleRows.length > 0\n ? sub.scheduleRows\n : Array.from({ length: sub.totalPayments }, (_, i) => ({\n unitAmount: sub.amount,\n discount: 0,\n intervalUnit: i === 0 ? null : ((sub.intervalUnit ?? null) as IntervalUnit | null),\n intervalCount: i === 0 ? null : (sub.intervalCount ?? null),\n }));\n const nextDue = toDate(sub.currentPeriodEnd);\n const dueAtOf = (i: number): string | null => {\n if (i < made || !billing || !nextDue) return null;\n if (sub.scheduleRows && sub.scheduleRows.length > 0) {\n const anchor = toDate(sub.billingAnchorAt) ?? nextDue;\n return scheduleDueAt({ anchor, anchorIndex: sub.scheduleAnchorIndex ?? 0, rows, index: i }).toISOString();\n }\n // Equal plan: the stored period end, then the anchored grid.\n const cadence = cadenceOf({ interval: sub.interval, intervalUnit: sub.intervalUnit, intervalCount: sub.intervalCount });\n const anchor = toDate(sub.billingAnchorAt) ?? nextDue;\n let at = nextDue;\n for (let k = made; k < i; k += 1) at = nextPeriodEnd({ anchor, cadence, after: at });\n return at.toISOString();\n };\n const view = rows.map((row, i) => {\n const net = row.unitAmount * quantity - row.discount;\n const status: PaymentScheduleViewRow['status'] =\n i < made ? 'paid' : i === made && (sub.status === 'past_due' || sub.status === 'unpaid') ? 'due' : 'upcoming';\n return {\n index: i, amount: row.unitAmount, discount: row.discount, net,\n intervalUnit: row.intervalUnit, intervalCount: row.intervalCount, status, dueAt: dueAtOf(i),\n };\n });\n return {\n rows: view,\n scheduleTotal: view.reduce((s, r) => s + r.net, 0),\n nextPaymentAmount: billing && made < view.length ? view[made].net : null,\n };\n}\n\n/**\n * True when a subscription's synthesized payment rows are a genuinely custom schedule: any discount,\n * any amount differing from payment 1, or any gap (payments 2..N) differing from payment 2's.\n * Equal installment plans also carry synthesized rows and must render as before.\n */\nexport function isVariedSchedule(\n rows: Array<{ amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null }> | null | undefined,\n): boolean {\n if (!rows || rows.length === 0) return false;\n return rows.some(\n (r, i) =>\n r.discount !== 0 ||\n r.amount !== rows[0].amount ||\n (i > 1 && (r.intervalUnit !== rows[1].intervalUnit || r.intervalCount !== rows[1].intervalCount)),\n );\n}\n\n/**\n * A varied schedule's payments still to come — unpaid rows that carry an\n * estimated date — for the buyer-facing dated lists (spec §5: order\n * confirmation, portal, billing page). Empty for an equal plan, so those\n * surfaces render exactly as before. Each surface formats amount and date itself.\n */\nexport function upcomingSchedulePayments<\n R extends { amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null; status: string; dueAt: string | null },\n>(rows: R[] | null | undefined): Array<R & { dueAt: string }> {\n if (!rows || !isVariedSchedule(rows)) return [];\n return rows.filter((r): r is R & { dueAt: string } => r.status !== 'paid' && r.dueAt != null);\n}\n","import { isIntervalUnit, isNamedInterval, type CadenceLike, type NamedInterval } from './cadence';\nimport { isVariedSchedule, scheduleUnitTotal } from './schedule';\n\nconst NAMED_NOUN: Record<NamedInterval, string> = {\n weekly: 'week',\n biweekly: '2 weeks',\n monthly: 'month',\n quarterly: 'quarter',\n yearly: 'year',\n};\n\nconst NAMED_LABEL: Record<NamedInterval, string> = {\n weekly: 'Weekly',\n biweekly: 'Biweekly',\n monthly: 'Monthly',\n quarterly: 'Quarterly',\n yearly: 'Yearly',\n};\n\n/**\n * The period as a noun — what reads correctly after a slash: \"$49.00 / 10\n * days\". This replaces the per-file `INTERVAL_WORD` maps whose drift shipped\n * \"$49.00 / biweekly\" once already. Unknown input falls through unchanged so a\n * value this build doesn't know still renders instead of vanishing.\n */\nexport function cadenceNoun(cadence: CadenceLike): string {\n if (isNamedInterval(cadence.interval)) return NAMED_NOUN[cadence.interval];\n if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) {\n return cadence.intervalCount === 1 ? cadence.intervalUnit : `${cadence.intervalCount} ${cadence.intervalUnit}s`;\n }\n return cadence.interval;\n}\n\n/** The cadence as a standalone label, e.g. an Interval column: \"Monthly\", \"Every 10 days\". */\nexport function cadenceLabel(cadence: CadenceLike): string {\n if (isNamedInterval(cadence.interval)) return NAMED_LABEL[cadence.interval];\n if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) return `Every ${cadenceNoun(cadence)}`;\n return cadence.interval;\n}\n\n/** Sub-daily cadences show the time of the next charge, not just its date. */\nexport function isSubDaily(cadence: CadenceLike): boolean {\n return cadence.intervalUnit === 'hour';\n}\n\n/** A subscription line's terms, the fields a label needs. */\nexport interface RecurringTermsLike extends CadenceLike {\n totalPayments?: number | null;\n trialDays?: number | null;\n schedule?: Array<{ amount: number }> | null;\n}\n\n/**\n * One short label for a subscription line's terms, for carts and quotes:\n * \"$20.00 / month\", \"$20.00 / 10 days · 3 payments\", \"Free for 14 days, then\n * $20.00 / month\", \"$100.00 total · 4 payments\". The label computes the money\n * itself from the line's unit price and seats — for a schedule, the deal total\n * (every payment × seats), never the line's unit price (payment 1) — and hands\n * it to `money`, so each surface keeps its own money style.\n */\nexport function recurringTermsLabel(\n terms: RecurringTermsLike,\n price: { unitPrice: number; quantity?: number | null },\n money: (minor: number) => string,\n): string {\n const quantity = price.quantity ?? 1;\n if (terms.schedule && terms.schedule.length > 0) {\n return `${money(scheduleUnitTotal(terms.schedule) * quantity)} total · ${terms.schedule.length} payments`;\n }\n const each = money(price.unitPrice * quantity);\n const noun = cadenceNoun(terms);\n const trialDays = terms.trialDays ?? 0;\n if (trialDays > 0) return `Free for ${trialDays} day${trialDays === 1 ? '' : 's'}, then ${each} / ${noun}`;\n return `${each} / ${noun}` + (terms.totalPayments != null ? ` · ${terms.totalPayments} payments` : '');\n}\n\n/** A subscription's public schedule fields, as the API returns them. */\nexport interface ScheduleDealLike {\n paymentSchedule?: Array<{ amount: number; discount: number; intervalUnit: string | null; intervalCount: number | null }> | null;\n scheduleTotal?: number | null;\n}\n\n/**\n * A varied schedule's deal — its total (every row's net: seats in, discounts\n * out) and its payment count — or null for an equal plan, whose synthesized\n * schedule keeps the per-period label, and for an ongoing plan. A varied\n * schedule has no per-period price: `amount` and the cadence columns hold only\n * the next row's (ruling R-FR4). Every surface gates both its price and its\n * cadence cells on this one answer.\n */\nexport function scheduleDeal(sub: ScheduleDealLike): { total: number; payments: number } | null {\n if (!sub.paymentSchedule || sub.scheduleTotal == null || !isVariedSchedule(sub.paymentSchedule)) return null;\n return { total: sub.scheduleTotal, payments: sub.paymentSchedule.length };\n}\n\n/** \"$100.00 total · 4 payments\" for a varied schedule, else null. `money` keeps each surface's money style. */\nexport function scheduleDealLabel(sub: ScheduleDealLike, money: (minor: number) => string): string | null {\n const deal = scheduleDeal(sub);\n return deal ? `${money(deal.total)} total · ${deal.payments} payments` : null;\n}\n","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { useQuoteRequestForm } from './hooks';\nimport type { QuoteRequestItem, QuotesClientOptions } from './types';\n\nexport interface QuoteRequestFormProps {\n /** The `qrf_…` token from the merchant's hosted form URL. */\n formToken: string;\n options?: QuotesClientOptions;\n /**\n * Turnstile token, when the form requires it. Render the widget yourself and\n * pass its token through — this package deliberately pulls in no Cloudflare\n * script. If `config.fields.requireTurnstile` is set and this is empty, the\n * API fails the submission closed.\n */\n turnstileToken?: string;\n /**\n * Lines to submit with the request — typically `useQuoteCart().lines` after\n * the buyer has been adding products while browsing. When present, the\n * written message is optional.\n */\n items?: QuoteRequestItem[];\n onSubmitted?: () => void;\n loadingFallback?: ReactNode;\n className?: string;\n}\n\n/** Off-screen but still focusable-free; bots fill it, humans never see it. */\nconst honeypotStyle: CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n whiteSpace: 'nowrap',\n border: 0,\n};\n\n/**\n * Hosted RFQ intake form.\n *\n * Bot protection is wired in for you: the honeypot field and the mount-time\n * anchor that feeds the API's minimum-fill-time check. A honeypot hit returns\n * a success-shaped response and creates nothing, so `onSubmitted` fires either\n * way — by design, a bot must not learn it was caught.\n */\nexport function QuoteRequestForm({\n formToken,\n options,\n turnstileToken,\n items,\n onSubmitted,\n loadingFallback,\n className,\n}: QuoteRequestFormProps) {\n const f = useQuoteRequestForm(formToken, options ?? {});\n // Lines the host collected while the buyer browsed (see `useQuoteCart`).\n // With any of these present the written message becomes optional: the ask\n // is the list.\n const lines = items ?? [];\n const [values, setValues] = useState({\n email: '',\n name: '',\n companyName: '',\n phone: '',\n buyerReference: '',\n addressLine1: '',\n addressLine2: '',\n city: '',\n stateProvince: '',\n postalCode: '',\n countryCode: '',\n message: '',\n website: '', // honeypot\n });\n\n const set = (k: keyof typeof values) => (e: { target: { value: string } }) =>\n setValues((prev) => ({ ...prev, [k]: e.target.value }));\n\n if (f.loading) return <>{loadingFallback ?? <p>Loading…</p>}</>;\n if (!f.config) return <p>This request form is not available.</p>;\n\n if (f.submitted) {\n const redirect = f.config.redirectUrl;\n // Re-check the scheme client-side even though the API rejects non-http(s)\n // on write — a stale row must not be able to script the host page.\n if (redirect && /^https?:\\/\\//i.test(redirect) && typeof window !== 'undefined') {\n window.location.href = redirect;\n }\n return <p>{f.config.successMessage ?? 'Thanks — we will be in touch shortly.'}</p>;\n }\n\n const fields = f.config.fields ?? {};\n\n return (\n <form\n className={className}\n onSubmit={(e) => {\n e.preventDefault();\n void f\n .submit({\n email: values.email,\n message: values.message || null,\n ...(lines.length > 0 ? { items: lines } : {}),\n name: values.name || null,\n companyName: fields.companyName ? values.companyName || null : null,\n phone: fields.phone ? values.phone || null : null,\n buyerReference: fields.buyerReference ? values.buyerReference || null : null,\n ...(fields.shippingAddress\n ? {\n shippingAddress: {\n addressLine1: values.addressLine1 || null,\n addressLine2: values.addressLine2 || null,\n city: values.city || null,\n stateProvince: values.stateProvince || null,\n postalCode: values.postalCode || null,\n countryCode: values.countryCode || null,\n },\n }\n : {}),\n website: values.website || null,\n ...(turnstileToken ? { turnstileToken } : {}),\n })\n .then(() => onSubmitted?.())\n .catch(() => {\n /* surfaced via f.error */\n });\n }}\n >\n {f.config.title ? <h1>{f.config.title}</h1> : null}\n {f.config.introText ? <p>{f.config.introText}</p> : null}\n {f.error ? <p role=\"alert\">{f.error.message}</p> : null}\n\n <label>\n Email\n <input type=\"email\" value={values.email} onChange={set('email')} required />\n </label>\n <label>\n Name\n <input value={values.name} onChange={set('name')} />\n </label>\n {fields.companyName ? (\n <label>\n Company\n <input value={values.companyName} onChange={set('companyName')} />\n </label>\n ) : null}\n {fields.phone ? (\n <label>\n Phone\n <input value={values.phone} onChange={set('phone')} />\n </label>\n ) : null}\n {fields.shippingAddress ? (\n <fieldset>\n <legend>Shipping address (optional)</legend>\n <label>\n Address line 1\n <input value={values.addressLine1} onChange={set('addressLine1')} />\n </label>\n <label>\n Address line 2\n <input value={values.addressLine2} onChange={set('addressLine2')} />\n </label>\n <label>\n City\n <input value={values.city} onChange={set('city')} />\n </label>\n <label>\n State / province\n <input value={values.stateProvince} onChange={set('stateProvince')} />\n </label>\n <label>\n Postal code\n <input value={values.postalCode} onChange={set('postalCode')} />\n </label>\n <label>\n Country code (e.g. US)\n <input value={values.countryCode} onChange={set('countryCode')} maxLength={2} />\n </label>\n </fieldset>\n ) : null}\n {fields.buyerReference ? (\n <label>\n Your reference #\n <input value={values.buyerReference} onChange={set('buyerReference')} />\n </label>\n ) : null}\n {lines.length > 0 ? (\n <ul aria-label=\"Items on this request\">\n {lines.map((line, index) => (\n <li key={line.sku ?? line.referenceId ?? `${line.name}-${index}`}>\n {line.quantity ?? 1} × {line.name}\n {line.sku ? ` (${line.sku})` : ''}\n {line.note ? ` — ${line.note}` : ''}\n </li>\n ))}\n </ul>\n ) : null}\n <label>\n {lines.length > 0 ? 'Anything else we should know?' : 'What do you need?'}\n <textarea\n value={values.message}\n onChange={set('message')}\n required={lines.length === 0}\n />\n </label>\n\n <div style={honeypotStyle} aria-hidden=\"true\">\n <label>\n Website\n <input\n name=\"website\"\n tabIndex={-1}\n autoComplete=\"off\"\n value={values.website}\n onChange={set('website')}\n />\n </label>\n </div>\n\n <button\n type=\"submit\"\n disabled={f.submitting || !values.email || (!values.message && lines.length === 0)}\n >\n {f.submitting ? 'Sending…' : 'Request a quote'}\n </button>\n </form>\n );\n}\n","export {\n QuotesClient,\n createQuotesClient,\n formatMoney,\n scaleLineCharges,\n computeSelectionTotal,\n lineDueAtAcceptance,\n isFreeTrialLine,\n} from './client';\nexport { ThrottleQuotesError } from './errors';\nexport { useQuote, useQuoteCart, useQuoteRequestForm } from './hooks';\nexport type { UseQuoteResult, UseQuoteCartResult, UseQuoteRequestFormResult } from './hooks';\nexport { createQuoteCart } from './quote-cart';\nexport type { QuoteCart, QuoteCartLine, QuoteCartOptions, QuoteCartStorage } from './quote-cart';\nexport { QuoteView } from './QuoteView';\nexport type { QuoteViewProps } from './QuoteView';\nexport { QuoteRequestForm } from './QuoteRequestForm';\nexport type { QuoteRequestFormProps } from './QuoteRequestForm';\nexport type {\n AcceptQuoteInput,\n AcceptQuoteResult,\n BuyerQuote,\n BuyerQuoteStatus,\n ItemSelection,\n PaymentTerms,\n QuoteBranding,\n QuoteComment,\n QuoteItem,\n QuoteItemRecurring,\n QuoteRequestItem,\n QuoteRevision,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n ThrottleEnvelope,\n} from './types';\n// Money helpers (MC2-R34). `formatMoney` is not re-exported flat: this entry\n// already exports its own (deprecated) one above (MC2-R48); money's is\n// `money.formatMoney`.\nexport * as money from '@usethrottle/money';\nexport {\n currencySymbol,\n minorUnitsOf,\n toDecimalString,\n toMinor,\n parseMoney,\n moneyValue,\n CURRENCIES,\n isKnownCurrency,\n UnknownCurrencyError,\n} from '@usethrottle/money';\nexport type { CurrencyCode, MoneyValue } from '@usethrottle/money';\n"],"mappings":";AAAA,SAAS,eAAe,mBAAmB;;;ACA3C,SAAS,qBAA6C;AAc/C,IAAM,sBAAN,cAAkC,cAAc;AAAA,EACrD,YAAY,MAMT;AACD,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,eAAwB;AAC1B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,IAAI,YAAqB;AACvB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,oBAAwC;AAC1C,UAAM,IAAI,KAAK;AACf,WAAO,GAAG;AAAA,EACZ;AACF;;;AD3BA,IAAM,eAAe;AAOd,IAAM,eAAN,MAAmB;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,OAA4B,CAAC,GAAG;AAC1C,UAAM,YAAY,KAAK,SAAS,WAAW;AAC3C,QAAI,CAAC,UAAW,OAAM,IAAI,MAAM,iCAAiC;AACjE,SAAK,WAAW,KAAK,WAAW,cAAc,QAAQ,QA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oney","useState","Fragment","jsx","jsxs","useState"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/quotes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Buyer-facing React components, hooks and server proxy for Throttle B2B quotes — hosted quote links and RFQ request forms.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"react"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@usethrottle/errors": "^1.1.0"
|
|
34
|
+
"@usethrottle/errors": "^1.1.0",
|
|
35
|
+
"@usethrottle/money": "^1.0.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"react": ">=18"
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@testing-library/react": "^16.1.0",
|
|
41
42
|
"@types/react": "^19.1.0",
|
|
43
|
+
"@types/react-dom": "^19.1.0",
|
|
42
44
|
"@vitejs/plugin-react": "^4.3.4",
|
|
43
45
|
"jsdom": "^25.0.1",
|
|
44
46
|
"react": "^19.1.0",
|