@usethrottle/quotes 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx","../src/errors.ts","../src/client.ts","../src/hooks.ts","../src/QuoteView.tsx","../src/QuoteRequestForm.tsx"],"sourcesContent":["export { QuotesClient, createQuotesClient, formatMoney, scaleLineCharges, computeSelectionTotal } from './client';\nexport { ThrottleQuotesError } from './errors';\nexport { useQuote, useQuoteRequestForm } from './hooks';\nexport type { UseQuoteResult, UseQuoteRequestFormResult } from './hooks';\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 QuoteRevision,\n QuotesClientOptions,\n RequestFormConfig,\n SubmitQuoteRequestInput,\n ThrottleEnvelope,\n} from './types';\n","import { ThrottleError } 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 }) {\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 });\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 /** 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/** 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 }>,\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 const { taxAmount, discountAmount } = scaleLineCharges(item, qty);\n total += item.unitPrice * qty + taxAmount - discountAmount;\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 type {\n AcceptQuoteInput,\n BuyerQuote,\n ItemSelection,\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 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 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 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","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { formatMoney } 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' };\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 canAct = quote.status === 'ready';\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 </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 {included\n ? formatMoney(\n item.unitPrice * state.quantity + item.taxAmount - item.discountAmount,\n currency,\n )\n : formatMoney(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>Total</strong>\n <strong>{formatMoney(q.total, currency)}</strong>\n </div>\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 ) : 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 &amp; continue to payment\n </button>\n </form>\n ) : (\n <button type=\"button\" onClick={() => setShowAccept(true)}>\n Accept &amp; 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","import { useState, type CSSProperties, type ReactNode } from 'react';\nimport { useQuoteRequestForm } from './hooks';\nimport type { 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 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 onSubmitted,\n loadingFallback,\n className,\n}: QuoteRequestFormProps) {\n const f = useQuoteRequestForm(formToken, options ?? {});\n const [values, setValues] = useState({\n email: '',\n name: '',\n companyName: '',\n phone: '',\n buyerReference: '',\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,\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 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.buyerReference ? (\n <label>\n Your reference #\n <input value={values.buyerReference} onChange={set('buyerReference')} />\n </label>\n ) : null}\n <label>\n What do you need?\n <textarea value={values.message} onChange={set('message')} required />\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 type=\"submit\" disabled={f.submitting || !values.email || !values.message}>\n {f.submitting ? 'Sending…' : 'Request a quote'}\n </button>\n </form>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA8B;AAcvB,IAAM,sBAAN,cAAkC,4BAAc;AAAA,EACrD,YAAY,MAKT;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;;;AC3BA,IAAM,eAAe;AAOd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UAAU,IAAI,gBAAgB,GAAG;AAAA,WACxE,IACE;AAAA,QACJ,8CAAC,WAAM;AAAA;AAAA,UAEL,6CAAC,cAAS,OAAO,OAAO,SAAS,UAAU,IAAI,SAAS,GAAG,UAAQ,MAAC;AAAA,WACtE;AAAA,QAEA,6CAAC,SAAI,OAAO,eAAe,eAAY,QACrC,wDAAC,WAAM;AAAA;AAAA,UAEL;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,6CAAC,YAAO,MAAK,UAAS,UAAU,EAAE,cAAc,CAAC,OAAO,SAAS,CAAC,OAAO,SACtE,YAAE,aAAa,kBAAa,mBAC/B;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["import_react","import_react","import_jsx_runtime"]}
@@ -0,0 +1,354 @@
1
+ import { ThrottleError } from '@usethrottle/errors';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { ReactNode } from 'react';
4
+
5
+ type BuyerQuoteStatus = 'in_progress' | 'ready' | 'being_revised' | 'accepted' | 'ordered' | 'declined' | 'expired';
6
+ type PaymentTerms = {
7
+ mode: 'pay_in_full';
8
+ } | {
9
+ mode: 'net_terms';
10
+ netN: number;
11
+ } | {
12
+ mode: 'deposit_balance';
13
+ deposit: {
14
+ type: 'percent' | 'fixed';
15
+ value: number;
16
+ };
17
+ balanceNetN: number;
18
+ };
19
+ interface QuoteItem {
20
+ id: string;
21
+ type: string;
22
+ sku: string | null;
23
+ name: string;
24
+ description: string | null;
25
+ unitPrice: number;
26
+ quantity: number;
27
+ subtotal: number;
28
+ taxAmount: number;
29
+ discountAmount: number;
30
+ total: number;
31
+ /** Buyer may deselect this line. */
32
+ optional: boolean;
33
+ optionalSelected: boolean;
34
+ /** Buyer may change the quantity. Reps lock volume-priced lines. */
35
+ qtyEditable: boolean;
36
+ imageUrl: string | null;
37
+ position: number;
38
+ }
39
+ interface QuoteRevision {
40
+ id: string;
41
+ revisionNumber: number;
42
+ issuedAt: string | null;
43
+ expiresAt: string | null;
44
+ subtotal: number;
45
+ taxTotal: number;
46
+ discountTotal: number;
47
+ shippingTotal: number;
48
+ total: number;
49
+ shippingMode: 'none' | 'flat' | 'checkout_calculated' | 'free';
50
+ shippingFlatAmount: number | null;
51
+ paymentTerms: PaymentTerms;
52
+ /** Frozen at issue time for deposit_balance terms. */
53
+ depositAmount: number | null;
54
+ buyerNote: string | null;
55
+ changeSummary: string | null;
56
+ leadTime: string | null;
57
+ items: QuoteItem[];
58
+ }
59
+ interface QuoteComment {
60
+ id: string;
61
+ authorType: 'buyer' | 'merchant' | 'system';
62
+ authorName: string | null;
63
+ body: string;
64
+ createdAt: string;
65
+ }
66
+ interface QuoteBranding {
67
+ displayName?: string | null;
68
+ logoUrl?: string | null;
69
+ brandColor?: string | null;
70
+ }
71
+ interface BuyerQuote {
72
+ quoteNumber: string;
73
+ status: BuyerQuoteStatus;
74
+ buyerReference: string | null;
75
+ currency: string;
76
+ expiresAt: string | null;
77
+ currentRevision: QuoteRevision | null;
78
+ revisionHistory: QuoteRevision[];
79
+ comments: QuoteComment[];
80
+ /** Present only once the quote has converted. */
81
+ orderId?: string | null;
82
+ branding?: QuoteBranding | null;
83
+ }
84
+ /** What the buyer chose: which optional lines they kept, at what quantities. */
85
+ interface ItemSelection {
86
+ itemId: string;
87
+ selected?: boolean;
88
+ quantity?: number;
89
+ }
90
+ interface AcceptQuoteInput {
91
+ revisionId: string;
92
+ acceptedByName: string;
93
+ acceptedByEmail: string;
94
+ buyerReference?: string | null;
95
+ itemSelections?: ItemSelection[];
96
+ }
97
+ interface AcceptQuoteResult {
98
+ quote: BuyerQuote;
99
+ /** Hosted checkout URL — redirect the buyer here immediately. */
100
+ checkoutUrl: string;
101
+ }
102
+ interface RequestFormConfig {
103
+ title: string | null;
104
+ introText: string | null;
105
+ successMessage: string | null;
106
+ redirectUrl: string | null;
107
+ fields: {
108
+ companyName?: boolean;
109
+ phone?: boolean;
110
+ buyerReference?: boolean;
111
+ requireTurnstile?: boolean;
112
+ };
113
+ branding?: QuoteBranding | null;
114
+ }
115
+ interface SubmitQuoteRequestInput {
116
+ email: string;
117
+ message: string;
118
+ name?: string | null;
119
+ companyName?: string | null;
120
+ phone?: string | null;
121
+ buyerReference?: string | null;
122
+ /** Honeypot — leave empty. The component wires this for you. */
123
+ website?: string | null;
124
+ /** Client mount time in ms; the API enforces a minimum fill duration. */
125
+ formLoadedAt?: number;
126
+ turnstileToken?: string;
127
+ }
128
+ interface ThrottleEnvelope<T> {
129
+ data?: T;
130
+ error?: {
131
+ code: string;
132
+ message: string;
133
+ details?: unknown;
134
+ };
135
+ meta?: {
136
+ requestId?: string;
137
+ };
138
+ }
139
+ interface QuotesClientOptions {
140
+ /**
141
+ * Where the public quote-link routes live. Defaults to Throttle's API.
142
+ * Point this at your own origin when proxying through `createQuoteProxyHandler`
143
+ * so the browser never talks to a third-party host.
144
+ */
145
+ baseUrl?: string;
146
+ fetch?: typeof globalThis.fetch;
147
+ timeoutMs?: number;
148
+ }
149
+
150
+ /**
151
+ * Headless client for the public quote surfaces. Everything is authorized by
152
+ * the capability token in the URL — there is no API key here, and there must
153
+ * not be: this runs in the buyer's browser.
154
+ */
155
+ declare class QuotesClient {
156
+ private readonly baseUrl;
157
+ private readonly fetchImpl;
158
+ private readonly timeoutMs;
159
+ constructor(opts?: QuotesClientOptions);
160
+ private request;
161
+ /** Fetch the quote a buyer link points at. 404s for unknown/rotated tokens. */
162
+ getQuote(token: string): Promise<BuyerQuote>;
163
+ /**
164
+ * Tell the merchant the buyer opened the quote. Fire-and-forget: the server
165
+ * throttles the resulting webhook to one per revision per 6h, and a failed
166
+ * beacon must never break the page.
167
+ */
168
+ recordView(token: string): Promise<void>;
169
+ addComment(token: string, input: {
170
+ body: string;
171
+ authorName?: string;
172
+ authorEmail?: string;
173
+ }): Promise<QuoteComment>;
174
+ requestRevision(token: string, input?: {
175
+ message?: string;
176
+ authorName?: string;
177
+ }): Promise<BuyerQuote>;
178
+ decline(token: string, input?: {
179
+ reason?: string;
180
+ authorName?: string;
181
+ }): Promise<BuyerQuote>;
182
+ /**
183
+ * Accept and get the checkout URL to send the buyer to.
184
+ *
185
+ * Re-accepting the same revision is idempotent and replays the same URL.
186
+ * Accepting a superseded revision throws `revision_superseded` carrying
187
+ * `currentRevisionId`; an expired offer throws `quote_expired`.
188
+ */
189
+ accept(token: string, input: AcceptQuoteInput): Promise<AcceptQuoteResult>;
190
+ /** URL of the PDF for the revision the buyer is looking at (server 302s to signed storage). */
191
+ pdfUrl(token: string): string;
192
+ getRequestForm(formToken: string): Promise<RequestFormConfig>;
193
+ /**
194
+ * Submit an RFQ. The response is deliberately thin (`{ submitted: true }`) —
195
+ * anonymous callers learn no internal identifiers. A submission caught by
196
+ * the honeypot returns the same shape without creating anything, so a bot
197
+ * cannot tell it was detected; treat success as "accepted", not "created".
198
+ */
199
+ submitRequest(formToken: string, input: SubmitQuoteRequestInput): Promise<{
200
+ submitted: boolean;
201
+ }>;
202
+ }
203
+ declare function createQuotesClient(opts?: QuotesClientOptions): QuotesClient;
204
+ /** Minor units → a display string, e.g. (104000, 'USD') → "$1,040.00". */
205
+ declare function formatMoney(minorUnits: number, currency: string, locale?: string): string;
206
+ /**
207
+ * Scale a line's quoted tax/discount to an edited quantity.
208
+ *
209
+ * MUST match `scaleLineCharges` in @commerce/quotes — the server recomputes
210
+ * the accepted total with this rule, and any divergence shows the buyer one
211
+ * total and charges another.
212
+ */
213
+ declare function scaleLineCharges(item: {
214
+ quantity: number;
215
+ taxAmount: number;
216
+ discountAmount: number;
217
+ }, quantity: number): {
218
+ taxAmount: number;
219
+ discountAmount: number;
220
+ };
221
+ /** Effective total for a selection, using the same math the server will apply. */
222
+ declare function computeSelectionTotal(items: Array<{
223
+ id: string;
224
+ unitPrice: number;
225
+ quantity: number;
226
+ taxAmount: number;
227
+ discountAmount: number;
228
+ optional: boolean;
229
+ }>, selections: Record<string, {
230
+ selected: boolean;
231
+ quantity: number;
232
+ }>, shippingTotal?: number): number;
233
+
234
+ /**
235
+ * Every failure from the quote-link routes surfaces as this. The `code` is the
236
+ * API's own error code, so callers can branch on the ones that matter to a
237
+ * buyer flow rather than parsing messages:
238
+ *
239
+ * revision_superseded — a newer revision was issued; `details.currentRevisionId`
240
+ * tells you what to reload
241
+ * quote_expired — the offer lapsed (HTTP 410)
242
+ * invalid_item_selection — locked-line edit, non-optional deselect, or unknown item
243
+ * accept_in_progress — a concurrent accept won; retry shortly
244
+ * not_found — unknown/rotated token, or a draft/archived quote
245
+ */
246
+ declare class ThrottleQuotesError extends ThrottleError {
247
+ constructor(args: {
248
+ code: string;
249
+ message: string;
250
+ statusCode: number;
251
+ details?: unknown;
252
+ });
253
+ /** The offer moved on — reload and show the buyer the current revision. */
254
+ get isSuperseded(): boolean;
255
+ get isExpired(): boolean;
256
+ /** Revision the server considers current, when it told us (spec §8.1). */
257
+ get currentRevisionId(): string | undefined;
258
+ }
259
+
260
+ interface UseQuoteResult {
261
+ quote: BuyerQuote | null;
262
+ loading: boolean;
263
+ error: ThrottleQuotesError | null;
264
+ /** Re-fetch — call after a `revision_superseded` to show the current offer. */
265
+ refresh: () => Promise<void>;
266
+ /** Buyer's current line choices, keyed by item id. */
267
+ selections: Record<string, {
268
+ selected: boolean;
269
+ quantity: number;
270
+ }>;
271
+ setSelected: (itemId: string, selected: boolean) => void;
272
+ setQuantity: (itemId: string, quantity: number) => void;
273
+ /** Live total for the current selections, using the server's own math. */
274
+ total: number;
275
+ accept: (input: Omit<AcceptQuoteInput, 'revisionId' | 'itemSelections'>) => Promise<{
276
+ checkoutUrl: string;
277
+ }>;
278
+ requestRevision: (message: string, authorName?: string) => Promise<void>;
279
+ decline: (reason?: string, authorName?: string) => Promise<void>;
280
+ addComment: (body: string, authorName?: string) => Promise<void>;
281
+ pdfUrl: string;
282
+ submitting: boolean;
283
+ }
284
+ /**
285
+ * Everything the buyer quote page needs.
286
+ *
287
+ * Fires the view beacon once per mount, keeps line selections in local state,
288
+ * and recomputes the total with the same rule the server applies at
289
+ * acceptance — so the number the buyer sees is the number they are charged.
290
+ */
291
+ declare function useQuote(token: string, options?: QuotesClientOptions): UseQuoteResult;
292
+ interface UseQuoteRequestFormResult {
293
+ config: RequestFormConfig | null;
294
+ loading: boolean;
295
+ error: ThrottleQuotesError | null;
296
+ submitting: boolean;
297
+ submitted: boolean;
298
+ submit: (input: SubmitQuoteRequestInput) => Promise<void>;
299
+ /** Mount time; pass through so the API's minimum-fill-time check passes. */
300
+ formLoadedAt: number;
301
+ }
302
+ /** Loads a hosted RFQ form's config and submits it, with bot fields handled. */
303
+ declare function useQuoteRequestForm(formToken: string, options?: QuotesClientOptions): UseQuoteRequestFormResult;
304
+
305
+ interface QuoteViewProps {
306
+ /** The `qtl_…` token from the buyer's link. */
307
+ token: string;
308
+ options?: QuotesClientOptions;
309
+ /**
310
+ * Where to send the buyer after acceptance. Defaults to assigning
311
+ * `window.location.href`, which is what the hosted page does.
312
+ */
313
+ onCheckout?: (checkoutUrl: string) => void;
314
+ /** Rendered instead of the built-in markup while loading. */
315
+ loadingFallback?: ReactNode;
316
+ className?: string;
317
+ }
318
+ /**
319
+ * Drop-in buyer quote page: line items with optional toggles and quantity
320
+ * editing, live totals, revision history, comment thread, and the
321
+ * accept / request-changes / decline actions.
322
+ *
323
+ * Intentionally unstyled beyond a readable default — it is meant to be
324
+ * restyled or replaced. `useQuote` carries all the behaviour if you want to
325
+ * build your own presentation.
326
+ */
327
+ declare function QuoteView({ token, options, onCheckout, loadingFallback, className }: QuoteViewProps): react_jsx_runtime.JSX.Element;
328
+
329
+ interface QuoteRequestFormProps {
330
+ /** The `qrf_…` token from the merchant's hosted form URL. */
331
+ formToken: string;
332
+ options?: QuotesClientOptions;
333
+ /**
334
+ * Turnstile token, when the form requires it. Render the widget yourself and
335
+ * pass its token through — this package deliberately pulls in no Cloudflare
336
+ * script. If `config.fields.requireTurnstile` is set and this is empty, the
337
+ * API fails the submission closed.
338
+ */
339
+ turnstileToken?: string;
340
+ onSubmitted?: () => void;
341
+ loadingFallback?: ReactNode;
342
+ className?: string;
343
+ }
344
+ /**
345
+ * Hosted RFQ intake form.
346
+ *
347
+ * Bot protection is wired in for you: the honeypot field and the mount-time
348
+ * anchor that feeds the API's minimum-fill-time check. A honeypot hit returns
349
+ * a success-shaped response and creates nothing, so `onSubmitted` fires either
350
+ * way — by design, a bot must not learn it was caught.
351
+ */
352
+ declare function QuoteRequestForm({ formToken, options, turnstileToken, onSubmitted, loadingFallback, className, }: QuoteRequestFormProps): react_jsx_runtime.JSX.Element;
353
+
354
+ export { type AcceptQuoteInput, type AcceptQuoteResult, type BuyerQuote, type BuyerQuoteStatus, type ItemSelection, type PaymentTerms, type QuoteBranding, type QuoteComment, type QuoteItem, QuoteRequestForm, type QuoteRequestFormProps, type QuoteRevision, QuoteView, type QuoteViewProps, QuotesClient, type QuotesClientOptions, type RequestFormConfig, type SubmitQuoteRequestInput, type ThrottleEnvelope, ThrottleQuotesError, type UseQuoteRequestFormResult, type UseQuoteResult, computeSelectionTotal, createQuotesClient, formatMoney, scaleLineCharges, useQuote, useQuoteRequestForm };