@aglyn/plugins-commerce 1.15.2 → 1.16.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 +1 -1
- package/package.json +13 -13
- package/src/lib/components/cart.js +2 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +6 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +5 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
- package/src/lib/components/console/product-builder-fields.component.js +195 -0
- package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +35 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-messages.component.d.ts +21 -0
- package/src/lib/components/console/quote-messages.component.js +185 -0
- package/src/lib/components/console/quote-messages.component.js.map +1 -0
- package/src/lib/components/console/quote-pay-link.component.js +1 -1
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.js +30 -3
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
- package/src/lib/components/console/quote-settings-card.component.js +154 -24
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
- package/src/lib/components/product-builder-context.d.ts +22 -0
- package/src/lib/components/product-builder-context.js +21 -0
- package/src/lib/components/product-builder-context.js.map +1 -0
- package/src/lib/components/product-builder-mockup.d.ts +42 -0
- package/src/lib/components/product-builder-mockup.js +120 -0
- package/src/lib/components/product-builder-mockup.js.map +1 -0
- package/src/lib/components/product-builder-sample.d.ts +63 -0
- package/src/lib/components/product-builder-sample.js +96 -0
- package/src/lib/components/product-builder-sample.js.map +1 -0
- package/src/lib/components/product-choice-cards.d.ts +51 -0
- package/src/lib/components/product-choice-cards.js +311 -0
- package/src/lib/components/product-choice-cards.js.map +1 -0
- package/src/lib/components/product-detail-panels.d.ts +42 -0
- package/src/lib/components/product-detail-panels.js +185 -0
- package/src/lib/components/product-detail-panels.js.map +1 -0
- package/src/lib/components/product-detail.d.ts +20 -12
- package/src/lib/components/product-detail.js +136 -221
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +7 -0
- package/src/lib/components/product-grid.js +11 -8
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-options-field-body.d.ts +9 -8
- package/src/lib/components/product-options-field-body.js +152 -3
- package/src/lib/components/product-options-field-body.js.map +1 -1
- package/src/lib/components/product-options-field.js +1 -1
- package/src/lib/components/product-options-field.js.map +1 -1
- package/src/lib/components/product-photo-fit.d.ts +49 -0
- package/src/lib/components/product-photo-fit.js +58 -0
- package/src/lib/components/product-photo-fit.js.map +1 -0
- package/src/lib/components/product-restock-notify.d.ts +12 -0
- package/src/lib/components/product-restock-notify.js +86 -0
- package/src/lib/components/product-restock-notify.js.map +1 -0
- package/src/lib/components/quote-messages-panel.d.ts +21 -0
- package/src/lib/components/quote-messages-panel.js +191 -0
- package/src/lib/components/quote-messages-panel.js.map +1 -0
- package/src/lib/components/quote-page-body.js +15 -1
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/quote-proof-panel.d.ts +6 -3
- package/src/lib/components/quote-proof-panel.js +139 -14
- package/src/lib/components/quote-proof-panel.js.map +1 -1
- package/src/lib/components/related-products.d.ts +7 -0
- package/src/lib/components/related-products.js +8 -6
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/constants/quote-page.d.ts +8 -0
- package/src/lib/constants/quote-page.js +11 -0
- package/src/lib/constants/quote-page.js.map +1 -1
- package/src/lib/model/commerce-cart.d.ts +6 -1
- package/src/lib/model/commerce-cart.js +5 -1
- package/src/lib/model/commerce-cart.js.map +1 -1
- package/src/lib/model/commerce-invoices.js +5 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-pos-ops.d.ts +3 -0
- package/src/lib/model/commerce-pos-ops.js +3 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -1
- package/src/lib/model/commerce-pos.d.ts +8 -0
- package/src/lib/model/commerce-pos.js.map +1 -1
- package/src/lib/model/commerce-quote-messages.d.ts +106 -0
- package/src/lib/model/commerce-quote-messages.js +146 -0
- package/src/lib/model/commerce-quote-messages.js.map +1 -0
- package/src/lib/model/commerce-quote-pay.d.ts +31 -2
- package/src/lib/model/commerce-quote-pay.js +31 -7
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
- package/src/lib/model/commerce-quote-proofs.js +73 -18
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quote-request.d.ts +14 -4
- package/src/lib/model/commerce-quote-request.js +25 -2
- package/src/lib/model/commerce-quote-request.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +56 -3
- package/src/lib/model/commerce-quotes.js +47 -2
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/commerce.d.ts +12 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/pos-cellular.d.ts +5 -0
- package/src/lib/model/pos-cellular.js.map +1 -1
- package/src/lib/model/product-card-rules.d.ts +41 -0
- package/src/lib/model/product-card-rules.js +90 -0
- package/src/lib/model/product-card-rules.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +11 -0
- package/src/lib/model/product-modifiers.js +10 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/server/billing-webhook.js +6 -2
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +15 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/channel-order-updates.js +15 -1
- package/src/lib/server/channel-order-updates.js.map +1 -1
- package/src/lib/server/channel-orders.js +20 -0
- package/src/lib/server/channel-orders.js.map +1 -1
- package/src/lib/server/checkout.js +1 -1
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/local-fulfillment.js +1 -1
- package/src/lib/server/local-fulfillment.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.d.ts +1 -1
- package/src/lib/server/pos-cellular-billing.js +2 -1
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular.d.ts +3 -1
- package/src/lib/server/pos-cellular.js +15 -8
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +3 -3
- package/src/lib/server/pos-offline-sync.js +17 -4
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-order.js +17 -6
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.js +27 -11
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-reader-splash.js +10 -5
- package/src/lib/server/pos-reader-splash.js.map +1 -1
- package/src/lib/server/pos-readers.js +34 -10
- package/src/lib/server/pos-readers.js.map +1 -1
- package/src/lib/server/pos-return.js +19 -3
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +14 -0
- package/src/lib/server/pos-stripe.js +6 -2
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal-connection-token.js +23 -9
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +80 -14
- package/src/lib/server/pos-terminal.js +393 -123
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/product-drafts.d.ts +1 -1
- package/src/lib/server/product-drafts.js +4 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.js +5 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/product.d.ts +11 -0
- package/src/lib/server/product.js +18 -3
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.js +4 -3
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/quote-email.d.ts +26 -0
- package/src/lib/server/quote-email.js +73 -7
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-messages.d.ts +72 -0
- package/src/lib/server/quote-messages.js +356 -0
- package/src/lib/server/quote-messages.js.map +1 -0
- package/src/lib/server/quote-pay.d.ts +42 -0
- package/src/lib/server/quote-pay.js +81 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.d.ts +1 -1
- package/src/lib/server/quote-proofs.js +63 -19
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote.d.ts +12 -0
- package/src/lib/server/quote.js +44 -14
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/refund.js +3 -1
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve-stock.js +9 -0
- package/src/lib/server/reserve-stock.js.map +1 -1
- package/src/lib/server/returns.js +15 -1
- package/src/lib/server/returns.js.map +1 -1
- package/src/lib/server/reviews.js +15 -0
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/sold-out-drop.d.ts +58 -0
- package/src/lib/server/sold-out-drop.js +81 -0
- package/src/lib/server/sold-out-drop.js.map +1 -0
- package/src/lib/server/stock-levels.js +9 -0
- package/src/lib/server/stock-levels.js.map +1 -1
- package/src/lib/server/stripe-refund.d.ts +7 -0
- package/src/lib/server/stripe-refund.js +26 -7
- package/src/lib/server/stripe-refund.js.map +1 -1
- package/src/lib/server.js +2 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tenant-emails.js +85 -2
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
- package/src/lib/testing/fake-seller-payment-account.js +40 -0
- package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
- package/src/lib/transfer/product-transfer.js +6 -5
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +4 -3
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +6 -0
- package/src/lib/utils/quote-email-content.js +6 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/quote-proof-panel.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n checkVisitorUploadSelection,\n describeVisitorUploadTypes,\n formatVisitorUploadBytes,\n VISITOR_UPLOAD_ACCEPT,\n VISITOR_UPLOAD_HONEYPOT_FIELD,\n VISITOR_UPLOAD_MAX_BYTES,\n VISITOR_UPLOAD_MAX_FILES,\n type VisitorUploadFileView,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { sendVisitorUpload } from '@aglyn/aglyn/app-utils/visitor-upload-client'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Chip from '@mui/material/Chip'\nimport Paper from '@mui/material/Paper'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { useCallback, useRef, useState, type ChangeEvent } from 'react'\nimport type { QuotePageView } from '../model'\n\n/** The page's own fetch: the site's API, with the site's preview rules. */\ntype SiteFetch = (input: string, init?: RequestInit) => Promise<Response>\n\nexport interface QuoteProofPanelProps {\n view: QuotePageView\n hostId: string\n quoteId: string\n token: string\n siteFetch: SiteFetch\n /** The quote as the server answered after a response, or after it changed. */\n onView: (view: QuotePageView) => void\n /** Reload the quote: it changed since the page loaded. */\n onReload: () => void\n /** The link was replaced. */\n onReplaced: () => void\n}\n\nfunction dateLabel(atMs: number): string {\n return new Date(atMs).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' })\n}\n\nconst newKey = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n/**\n * The quote's proofs on the customer's page (AGL-4096): each image shown,\n * every other file a download, and while the quote is open for an answer,\n * \"Approve this proof\" (under a typed name) and \"Request changes\" (a comment\n * and any artwork). The latest answer is the one that counts, so a customer\n * who asked for changes can still approve, and the panel says what they last\n * said. A paid quote shows its proofs and nothing to press.\n */\nexport function QuoteProofPanel(props: QuoteProofPanelProps) {\n const { view, hostId, quoteId, token, siteFetch, onView, onReload, onReplaced } = props\n const [mode, setMode] = useState<'idle' | 'approve' | 'changes'>('idle')\n const [name, setName] = useState('')\n const [comment, setComment] = useState('')\n const [files, setFiles] = useState<VisitorUploadFileView[]>([])\n const [uploading, setUploading] = useState<{ done: number; total: number } | null>(null)\n const [sending, setSending] = useState(false)\n const [error, setError] = useState('')\n // Whatever a bot types into the hidden field, sent as typed.\n const [honeypot, setHoneypot] = useState('')\n const picker = useRef<HTMLInputElement>(null)\n const attempt = useRef('')\n\n const link = `hostId=${encodeURIComponent(hostId)}&q=${encodeURIComponent(quoteId)}&t=${encodeURIComponent(token)}`\n const proofHref = (id: string) => `/api/commerce/quote-proof?${link}&file=${encodeURIComponent(id)}`\n const business = view.storeName || 'the business'\n\n const post = useCallback(\n async (path: string, body: Record<string, unknown>, headers: Record<string, string> = {}) => {\n const response = await siteFetch(path, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify({ hostId, q: quoteId, t: token, ...body }),\n })\n return { response, payload: (await response.json().catch(() => ({}))) as Record<string, any> }\n },\n [siteFetch, hostId, quoteId, token],\n )\n\n const attach = useCallback(\n async (picked: File[]) => {\n setError('')\n const problem = checkVisitorUploadSelection(picked, files.length)\n if (problem) return void setError(problem)\n setUploading({ done: 0, total: picked.length })\n try {\n for (const [index, file] of picked.entries()) {\n const sent = await sendVisitorUpload({\n file,\n requestTicket: async (request) => {\n const { response, payload } = await post('/api/commerce/quote-upload', {\n action: 'ticket',\n file: request,\n [VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot,\n })\n return response.ok && payload['ticket']\n ? (payload as { ticket: string; upload: { url: string; fields: Record<string, string> } })\n : { error: String(payload['error'] ?? 'The file could not be sent. Try again.') }\n },\n finalize: async (ticket) => {\n const { response, payload } = await post('/api/commerce/quote-upload', { action: 'finalize', ticket })\n return response.ok && payload['file']\n ? { file: payload['file'] as VisitorUploadFileView }\n : { error: String(payload['error'] ?? 'The file could not be sent. Try again.') }\n },\n })\n if ('error' in sent) {\n setError(sent.error)\n break\n }\n setFiles((prev) => [...prev, sent.file])\n setUploading({ done: index + 1, total: picked.length })\n }\n } finally {\n setUploading(null)\n }\n },\n [files.length, post, honeypot],\n )\n\n const respond = useCallback(async () => {\n if (sending) return\n setError('')\n if (mode === 'approve' && name.trim().length < 2) return void setError('Type your name to approve the proof.')\n if (mode === 'changes' && !comment.trim()) return void setError('Tell us what to change.')\n setSending(true)\n // One key per answer: a retry of the same press is answered from the first.\n if (!attempt.current) attempt.current = newKey()\n try {\n const { response, payload } = await post(\n '/api/commerce/quote-respond',\n {\n v: view.version,\n action: mode === 'approve' ? 'approve' : 'changes',\n ...(mode === 'approve' ? { name: name.trim() } : { comment: comment.trim(), fileIds: files.map((file) => file.id) }),\n [VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot,\n },\n { 'Idempotency-Key': attempt.current },\n )\n attempt.current = ''\n if (response.ok && payload['view']) {\n setMode('idle')\n setName('')\n setComment('')\n setFiles([])\n onView(payload['view'] as QuotePageView)\n return\n }\n if (payload['replaced']) return onReplaced()\n if (payload['reason'] === 'updated' || payload['reason'] === 'paid') onReload()\n setError(String(payload['error'] ?? 'Your answer could not be sent. Try again.'))\n } catch {\n setError('Your answer could not be sent. Check your connection and try again.')\n } finally {\n setSending(false)\n }\n }, [sending, mode, name, comment, files, view.version, honeypot, post, onView, onReload, onReplaced])\n\n if (!view.proofs.length) return null\n const response = view.response\n\n return (\n <Paper variant=\"outlined\" sx={{ p: { xs: 2, sm: 3 } }}>\n <Stack spacing={2}>\n <Stack spacing={0.5}>\n <Typography variant=\"h6\" component=\"h2\">\n {view.proofs.length === 1 ? 'Your proof' : 'Your proofs'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {view.status === 'unpaid'\n ? `Revision ${view.revision}. Look it over, then approve it or tell ${business} what to change.`\n : `Revision ${view.revision}.`}\n </Typography>\n </Stack>\n\n <Stack spacing={1.5}>\n {view.proofs.map((proof) =>\n proof.inline ? (\n <Stack key={proof.id} spacing={0.5}>\n <Box\n component=\"img\"\n src={proofHref(proof.id)}\n alt={proof.name}\n loading=\"lazy\"\n sx={{ display: 'block', maxWidth: 1, height: 'auto', borderRadius: 1, border: 1, borderColor: 'divider' }}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {proof.name}\n </Typography>\n </Stack>\n ) : (\n <Box key={proof.id}>\n <Button variant=\"outlined\" size=\"small\" href={proofHref(proof.id)} download={proof.name}>\n {`Download ${proof.name} (${formatVisitorUploadBytes(proof.size)})`}\n </Button>\n </Box>\n ),\n )}\n </Stack>\n\n {response ? (\n response.action === 'approve' ? (\n <Alert severity=\"success\">\n {`You approved this proof on ${dateLabel(response.atMs)}${response.name ? ` as ${response.name}` : ''}.`}\n </Alert>\n ) : (\n <Alert severity=\"info\">\n {`You asked for changes on ${dateLabel(response.atMs)}. ${business.charAt(0).toUpperCase()}${business.slice(1)} will send you a new proof.`}\n </Alert>\n )\n ) : null}\n\n {view.respondable ? (\n <Stack spacing={2}>\n {/* Honeypot: people never see or fill this. */}\n <Box\n component=\"input\"\n type=\"text\"\n name={VISITOR_UPLOAD_HONEYPOT_FIELD}\n tabIndex={-1}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n value={honeypot}\n onChange={(event: ChangeEvent<HTMLInputElement>) => setHoneypot(event.target.value)}\n sx={{ position: 'absolute', left: '-100vw', width: 0, height: 0, opacity: 0 }}\n />\n {mode === 'idle' ? (\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>\n {response?.action !== 'approve' ? (\n <Button variant=\"contained\" onClick={() => setMode('approve')}>\n {'Approve this proof'}\n </Button>\n ) : null}\n <Button variant={response?.action === 'approve' ? 'outlined' : 'text'} onClick={() => setMode('changes')}>\n {'Request changes'}\n </Button>\n </Stack>\n ) : mode === 'approve' ? (\n <Stack spacing={1.5}>\n <Typography variant=\"body2\">\n {`Type your name to approve revision ${view.revision}. ${business.charAt(0).toUpperCase()}${business.slice(1)} keeps your name and the time as the record of your approval.`}\n </Typography>\n <TextField\n label=\"Your name\"\n value={name}\n autoComplete=\"name\"\n onChange={(event) => setName(event.target.value)}\n slotProps={{ htmlInput: { maxLength: 120 } }}\n />\n <Stack direction=\"row\" spacing={1}>\n <Button variant=\"contained\" disabled={sending} onClick={() => void respond()}>\n {sending ? 'Approving…' : 'Approve'}\n </Button>\n <Button disabled={sending} onClick={() => setMode('idle')}>\n {'Cancel'}\n </Button>\n </Stack>\n </Stack>\n ) : (\n <Stack spacing={1.5}>\n <TextField\n label=\"What should change?\"\n value={comment}\n multiline\n minRows={3}\n required\n onChange={(event) => setComment(event.target.value)}\n slotProps={{ htmlInput: { maxLength: 5000 } }}\n />\n <input\n ref={picker}\n type=\"file\"\n multiple\n hidden\n accept={VISITOR_UPLOAD_ACCEPT}\n data-testid=\"quote-artwork-picker\"\n onChange={(event) => {\n const picked = Array.from(event.target.files ?? [])\n event.target.value = ''\n if (picked.length) void attach(picked)\n }}\n />\n {files.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {files.map((file) => (\n <Chip\n key={file.id}\n label={`${file.name} · ${formatVisitorUploadBytes(file.size)}`}\n onDelete={sending ? undefined : () => setFiles((prev) => prev.filter((entry) => entry.id !== file.id))}\n />\n ))}\n </Stack>\n ) : null}\n <Box>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={sending || Boolean(uploading) || files.length >= VISITOR_UPLOAD_MAX_FILES}\n onClick={() => picker.current?.click()}\n >\n {uploading ? `Sending ${uploading.done + 1} of ${uploading.total}…` : 'Attach artwork'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ mt: 0.5 }}>\n {`Optional. ${describeVisitorUploadTypes()}, up to ${VISITOR_UPLOAD_MAX_FILES} files of ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`}\n </Typography>\n </Box>\n <Stack direction=\"row\" spacing={1}>\n <Button variant=\"contained\" disabled={sending || Boolean(uploading)} onClick={() => void respond()}>\n {sending ? 'Sending…' : 'Send changes'}\n </Button>\n <Button disabled={sending} onClick={() => setMode('idle')}>\n {'Cancel'}\n </Button>\n </Stack>\n </Stack>\n )}\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n </Stack>\n ) : null}\n </Stack>\n </Paper>\n )\n}\n\nexport default QuoteProofPanel\n"],"names":["checkVisitorUploadSelection","describeVisitorUploadTypes","formatVisitorUploadBytes","VISITOR_UPLOAD_ACCEPT","VISITOR_UPLOAD_HONEYPOT_FIELD","VISITOR_UPLOAD_MAX_BYTES","VISITOR_UPLOAD_MAX_FILES","sendVisitorUpload","Alert","Box","Button","Chip","Paper","Stack","TextField","Typography","useCallback","useRef","useState","dateLabel","atMs","Date","toLocaleDateString","undefined","month","day","year","newKey","globalThis","crypto","randomUUID","now","Math","random","toString","slice","QuoteProofPanel","props","view","hostId","quoteId","token","siteFetch","onView","onReload","onReplaced","mode","setMode","name","setName","comment","setComment","files","setFiles","uploading","setUploading","sending","setSending","error","setError","honeypot","setHoneypot","picker","attempt","link","encodeURIComponent","proofHref","id","business","storeName","post","path","body","headers","response","method","JSON","stringify","q","t","payload","json","catch","attach","picked","problem","length","done","total","index","file","entries","sent","requestTicket","request","action","ok","String","finalize","ticket","prev","respond","trim","current","v","version","fileIds","map","proofs","variant","sx","p","xs","sm","spacing","component","color","status","revision","proof","inline","src","alt","loading","display","maxWidth","height","borderRadius","border","borderColor","size","href","download","severity","charAt","toUpperCase","respondable","type","tabIndex","autoComplete","aria-hidden","value","onChange","event","target","position","left","width","opacity","direction","onClick","label","slotProps","htmlInput","maxLength","disabled","multiline","minRows","required","input","ref","multiple","hidden","accept","data-testid","Array","from","useFlexGap","flexWrap","onDelete","filter","entry","Boolean","click","mt"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,2BAA2B,EAC3BC,0BAA0B,EAC1BC,wBAAwB,EACxBC,qBAAqB,EACrBC,6BAA6B,EAC7BC,wBAAwB,EACxBC,wBAAwB,QAEnB,wCAAuC;AAC9C,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,OA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AAEjC,UAAUkC,KAAK,CAAC,CAAC,CAAC,GAAG;;sDAExE,KAACzE;4CAAW8F,SAAQ;4CAAUO,OAAM;4CAAiBD,WAAU;4CAAIL,IAAI;gDAAEgE,IAAI;4CAAI;sDAC9E,CAAC,UAAU,EAAE7K,6BAA6B,QAAQ,EAAEK,yBAAyB,UAAU,EAAEJ,yBAAyBG,0BAA0B,MAAM,CAAC;;;;8CAGxJ,MAACQ;oCAAMwI,WAAU;oCAAMnC,SAAS;;sDAC9B,KAACxG;4CAAOmG,SAAQ;4CAAY8C,UAAUnG,WAAWoH,QAAQtH;4CAAYgG,SAAS,IAAM,KAAKjD;sDACtF7C,UAAU,aAAa;;sDAE1B,KAAC9C;4CAAOiJ,UAAUnG;4CAAS8F,SAAS,IAAMvG,QAAQ;sDAC/C;;;;;;wBAKRW,sBAAQ,KAAClD;4BAAM6H,UAAS;sCAAS3E;6BAAiB;;qBAEnD;;;;AAIZ;AAEA,eAAetB,gBAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/quote-proof-panel.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n checkVisitorUploadSelection,\n describeVisitorUploadTypes,\n formatVisitorUploadBytes,\n VISITOR_UPLOAD_ACCEPT,\n VISITOR_UPLOAD_HONEYPOT_FIELD,\n VISITOR_UPLOAD_MAX_BYTES,\n VISITOR_UPLOAD_MAX_FILES,\n type VisitorUploadFileView,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { sendVisitorUpload } from '@aglyn/aglyn/app-utils/visitor-upload-client'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Checkbox from '@mui/material/Checkbox'\nimport Chip from '@mui/material/Chip'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport FormGroup from '@mui/material/FormGroup'\nimport Paper from '@mui/material/Paper'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { useCallback, useRef, useState, type ChangeEvent } from 'react'\nimport { quoteSignInHref } from '../constants/quote-page'\nimport type { QuotePageView } from '../model'\n\n/** The page's own fetch: the site's API, with the site's preview rules. */\ntype SiteFetch = (input: string, init?: RequestInit) => Promise<Response>\n\nexport interface QuoteProofPanelProps {\n view: QuotePageView\n hostId: string\n quoteId: string\n token: string\n siteFetch: SiteFetch\n /** The quote as the server answered after a response, or after it changed. */\n onView: (view: QuotePageView) => void\n /** Reload the quote: it changed since the page loaded. */\n onReload: () => void\n /** The link was replaced. */\n onReplaced: () => void\n}\n\nfunction dateLabel(atMs: number): string {\n return new Date(atMs).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' })\n}\n\nconst newKey = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n/** The sign-in page, back to this very page once signed in. */\nfunction signInHref(): string {\n if (typeof window === 'undefined') return quoteSignInHref('')\n return quoteSignInHref(`${window.location.pathname}${window.location.search}`)\n}\n\n/**\n * The quote's proofs on the customer's page (AGL-4096): each image shown,\n * every other file a download, and while the quote is open for an answer,\n * \"Approve this proof\" (every statement ticked and a typed name, AGL-4206)\n * and \"Reject with changes\" (what to change under a typed name, and any\n * artwork, AGL-4206). A quote that asks a\n * customer with a site account to sign in shows a sign-in button instead of\n * the proof until they do. The latest answer is the one that counts, so a customer\n * who rejected it with changes can still approve, and the panel says what they last\n * said. A paid quote shows its proofs and nothing to press.\n */\nexport function QuoteProofPanel(props: QuoteProofPanelProps) {\n const { view, hostId, quoteId, token, siteFetch, onView, onReload, onReplaced } = props\n const [mode, setMode] = useState<'idle' | 'approve' | 'changes'>('idle')\n const [name, setName] = useState('')\n // The statements ticked, by their words: a reworded statement is a new box.\n const [ticked, setTicked] = useState<string[]>([])\n const [comment, setComment] = useState('')\n const [files, setFiles] = useState<VisitorUploadFileView[]>([])\n const [uploading, setUploading] = useState<{ done: number; total: number } | null>(null)\n const [sending, setSending] = useState(false)\n const [error, setError] = useState('')\n // Whatever a bot types into the hidden field, sent as typed.\n const [honeypot, setHoneypot] = useState('')\n const picker = useRef<HTMLInputElement>(null)\n const attempt = useRef('')\n\n const link = `hostId=${encodeURIComponent(hostId)}&q=${encodeURIComponent(quoteId)}&t=${encodeURIComponent(token)}`\n const proofHref = (id: string) => `/api/commerce/quote-proof?${link}&file=${encodeURIComponent(id)}`\n const business = view.storeName || 'the business'\n\n const post = useCallback(\n async (path: string, body: Record<string, unknown>, headers: Record<string, string> = {}) => {\n const response = await siteFetch(path, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify({ hostId, q: quoteId, t: token, ...body }),\n })\n return { response, payload: (await response.json().catch(() => ({}))) as Record<string, any> }\n },\n [siteFetch, hostId, quoteId, token],\n )\n\n const attach = useCallback(\n async (picked: File[]) => {\n setError('')\n const problem = checkVisitorUploadSelection(picked, files.length)\n if (problem) return void setError(problem)\n setUploading({ done: 0, total: picked.length })\n try {\n for (const [index, file] of picked.entries()) {\n const sent = await sendVisitorUpload({\n file,\n requestTicket: async (request) => {\n const { response, payload } = await post('/api/commerce/quote-upload', {\n action: 'ticket',\n file: request,\n [VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot,\n })\n return response.ok && payload['ticket']\n ? (payload as { ticket: string; upload: { url: string; fields: Record<string, string> } })\n : { error: String(payload['error'] ?? 'The file could not be sent. Try again.') }\n },\n finalize: async (ticket) => {\n const { response, payload } = await post('/api/commerce/quote-upload', { action: 'finalize', ticket })\n return response.ok && payload['file']\n ? { file: payload['file'] as VisitorUploadFileView }\n : { error: String(payload['error'] ?? 'The file could not be sent. Try again.') }\n },\n })\n if ('error' in sent) {\n setError(sent.error)\n break\n }\n setFiles((prev) => [...prev, sent.file])\n setUploading({ done: index + 1, total: picked.length })\n }\n } finally {\n setUploading(null)\n }\n },\n [files.length, post, honeypot],\n )\n\n const respond = useCallback(async () => {\n if (sending) return\n setError('')\n const statements = view.approvalStatements ?? []\n if (mode === 'approve' && statements.some((statement) => !ticked.includes(statement))) {\n return void setError('Tick each box to confirm you checked the proof.')\n }\n if (mode === 'approve' && name.trim().length < 2) return void setError('Type your name to approve the proof.')\n if (mode === 'changes' && !comment.trim()) return void setError('Tell us what to change.')\n if (mode === 'changes' && name.trim().length < 2) return void setError('Type your name to reject the proof.')\n setSending(true)\n // One key per answer: a retry of the same press is answered from the first.\n if (!attempt.current) attempt.current = newKey()\n try {\n const { response, payload } = await post(\n '/api/commerce/quote-respond',\n {\n v: view.version,\n action: mode === 'approve' ? 'approve' : 'changes',\n ...(mode === 'approve'\n ? { name: name.trim(), confirmed: statements.filter((statement) => ticked.includes(statement)) }\n : { comment: comment.trim(), name: name.trim(), fileIds: files.map((file) => file.id) }),\n [VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot,\n },\n { 'Idempotency-Key': attempt.current },\n )\n attempt.current = ''\n if (response.ok && payload['view']) {\n setMode('idle')\n setName('')\n setTicked([])\n setComment('')\n setFiles([])\n onView(payload['view'] as QuotePageView)\n return\n }\n if (payload['replaced']) return onReplaced()\n if (payload['reason'] === 'updated' || payload['reason'] === 'paid') onReload()\n setError(String(payload['error'] ?? 'Your answer could not be sent. Try again.'))\n } catch {\n setError('Your answer could not be sent. Check your connection and try again.')\n } finally {\n setSending(false)\n }\n }, [sending, mode, name, ticked, comment, files, view.version, view.approvalStatements, honeypot, post, onView, onReload, onReplaced])\n\n // The quote asks this customer to sign in to their account first (AGL-4206).\n if (view.proofAccess && view.proofAccess !== 'open') {\n return (\n <Paper variant=\"outlined\" sx={{ p: { xs: 2, sm: 3 } }} data-quote-proof-sign-in=\"\">\n <Stack spacing={2}>\n <Typography variant=\"h6\" component=\"h2\">\n {'Your proof'}\n </Typography>\n <Alert severity=\"info\">{view.proofAccessMessage}</Alert>\n <Box>\n <Button variant=\"contained\" href={signInHref()}>\n {'Sign in'}\n </Button>\n </Box>\n </Stack>\n </Paper>\n )\n }\n\n if (!view.proofs.length) return null\n const response = view.response\n const statements = view.approvalStatements ?? []\n const allTicked = statements.every((statement) => ticked.includes(statement))\n const toggle = (statement: string, on: boolean) =>\n setTicked((prev) => (on ? [...prev.filter((entry) => entry !== statement), statement] : prev.filter((entry) => entry !== statement)))\n\n return (\n <Paper variant=\"outlined\" sx={{ p: { xs: 2, sm: 3 } }}>\n <Stack spacing={2}>\n <Stack spacing={0.5}>\n <Typography variant=\"h6\" component=\"h2\">\n {view.proofs.length === 1 ? 'Your proof' : 'Your proofs'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {view.status === 'unpaid'\n ? `Revision ${view.revision}. Look it over, then approve it or reject it and tell ${business} what to change.`\n : `Revision ${view.revision}.`}\n </Typography>\n </Stack>\n\n <Stack spacing={1.5}>\n {view.proofs.map((proof) =>\n proof.inline ? (\n <Stack key={proof.id} spacing={0.5}>\n <Box\n component=\"img\"\n src={proofHref(proof.id)}\n alt={proof.name}\n loading=\"lazy\"\n sx={{ display: 'block', maxWidth: 1, height: 'auto', borderRadius: 1, border: 1, borderColor: 'divider' }}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {proof.name}\n </Typography>\n </Stack>\n ) : (\n <Box key={proof.id}>\n <Button variant=\"outlined\" size=\"small\" href={proofHref(proof.id)} download={proof.name}>\n {`Download ${proof.name} (${formatVisitorUploadBytes(proof.size)})`}\n </Button>\n </Box>\n ),\n )}\n </Stack>\n\n {response ? (\n response.action === 'approve' ? (\n <Alert severity=\"success\">\n {`You approved this proof on ${dateLabel(response.atMs)}${response.name ? ` as ${response.name}` : ''}.`}\n {response.confirmed?.length ? (\n <Box component=\"ul\" sx={{ m: 0, mt: 0.5, pl: 2.5 }}>\n {response.confirmed.map((statement) => (\n <Typography key={statement} component=\"li\" variant=\"body2\">\n {statement}\n </Typography>\n ))}\n </Box>\n ) : null}\n </Alert>\n ) : (\n <Alert severity=\"info\">\n {`You rejected this proof with changes on ${dateLabel(response.atMs)}${response.name ? ` as ${response.name}` : ''}. ${business.charAt(0).toUpperCase()}${business.slice(1)} will send you a new proof.`}\n </Alert>\n )\n ) : null}\n\n {view.respondable ? (\n <Stack spacing={2}>\n {/* Honeypot: people never see or fill this. */}\n <Box\n component=\"input\"\n type=\"text\"\n name={VISITOR_UPLOAD_HONEYPOT_FIELD}\n tabIndex={-1}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n value={honeypot}\n onChange={(event: ChangeEvent<HTMLInputElement>) => setHoneypot(event.target.value)}\n sx={{ position: 'absolute', left: '-100vw', width: 0, height: 0, opacity: 0 }}\n />\n {mode === 'idle' ? (\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>\n {response?.action !== 'approve' ? (\n <Button variant=\"contained\" onClick={() => setMode('approve')}>\n {'Approve this proof'}\n </Button>\n ) : null}\n <Button variant=\"outlined\" color=\"primary\" onClick={() => setMode('changes')}>\n {'Reject with changes'}\n </Button>\n </Stack>\n ) : mode === 'approve' ? (\n <Stack spacing={1.5}>\n <Typography variant=\"body2\">\n {`Before you approve revision ${view.revision}, confirm each of these.`}\n </Typography>\n <FormGroup>\n {statements.map((statement) => (\n <FormControlLabel\n key={statement}\n sx={{ alignItems: 'flex-start', mb: 0.5 }}\n control={\n <Checkbox\n checked={ticked.includes(statement)}\n disabled={sending}\n onChange={(event) => toggle(statement, event.target.checked)}\n sx={{ pt: 0.25 }}\n />\n }\n label={<Typography variant=\"body2\">{statement}</Typography>}\n />\n ))}\n </FormGroup>\n <Typography variant=\"body2\">\n {`Then type your name. ${business.charAt(0).toUpperCase()}${business.slice(1)} keeps your name, what you confirmed and the time as the record of your approval.`}\n </Typography>\n <TextField\n label=\"Your name\"\n value={name}\n autoComplete=\"name\"\n onChange={(event) => setName(event.target.value)}\n slotProps={{ htmlInput: { maxLength: 120 } }}\n />\n <Stack direction=\"row\" spacing={1}>\n <Button\n variant=\"contained\"\n disabled={sending || !allTicked || name.trim().length < 2}\n onClick={() => void respond()}\n >\n {sending ? 'Approving…' : 'Approve'}\n </Button>\n <Button\n disabled={sending}\n onClick={() => {\n setMode('idle')\n setTicked([])\n }}\n >\n {'Cancel'}\n </Button>\n </Stack>\n </Stack>\n ) : (\n <Stack spacing={1.5}>\n <Typography variant=\"body2\">\n {`Tell ${business} what to change on revision ${view.revision}. They keep your note, your name and the time with the quote, and send you a new proof.`}\n </Typography>\n <TextField\n label=\"What should change?\"\n value={comment}\n multiline\n minRows={3}\n required\n onChange={(event) => setComment(event.target.value)}\n slotProps={{ htmlInput: { maxLength: 5000 } }}\n />\n <TextField\n label=\"Your name\"\n value={name}\n required\n autoComplete=\"name\"\n onChange={(event) => setName(event.target.value)}\n slotProps={{ htmlInput: { maxLength: 120 } }}\n />\n <input\n ref={picker}\n type=\"file\"\n multiple\n hidden\n accept={VISITOR_UPLOAD_ACCEPT}\n data-testid=\"quote-artwork-picker\"\n onChange={(event) => {\n const picked = Array.from(event.target.files ?? [])\n event.target.value = ''\n if (picked.length) void attach(picked)\n }}\n />\n {files.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {files.map((file) => (\n <Chip\n key={file.id}\n label={`${file.name} · ${formatVisitorUploadBytes(file.size)}`}\n onDelete={sending ? undefined : () => setFiles((prev) => prev.filter((entry) => entry.id !== file.id))}\n />\n ))}\n </Stack>\n ) : null}\n <Box>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={sending || Boolean(uploading) || files.length >= VISITOR_UPLOAD_MAX_FILES}\n onClick={() => picker.current?.click()}\n >\n {uploading ? `Sending ${uploading.done + 1} of ${uploading.total}…` : 'Attach artwork'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ mt: 0.5 }}>\n {`Optional. ${describeVisitorUploadTypes()}, up to ${VISITOR_UPLOAD_MAX_FILES} files of ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`}\n </Typography>\n </Box>\n <Stack direction=\"row\" spacing={1}>\n <Button variant=\"contained\" disabled={sending || Boolean(uploading)} onClick={() => void respond()}>\n {sending ? 'Sending…' : 'Reject with changes'}\n </Button>\n <Button disabled={sending} onClick={() => setMode('idle')}>\n {'Cancel'}\n </Button>\n </Stack>\n </Stack>\n )}\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n </Stack>\n ) : null}\n </Stack>\n </Paper>\n )\n}\n\nexport default QuoteProofPanel\n"],"names":["checkVisitorUploadSelection","describeVisitorUploadTypes","formatVisitorUploadBytes","VISITOR_UPLOAD_ACCEPT","VISITOR_UPLOAD_HONEYPOT_FIELD","VISITOR_UPLOAD_MAX_BYTES","VISITOR_UPLOAD_MAX_FILES","sendVisitorUpload","Alert","Box","Button","Checkbox","Chip","FormControlLabel","FormGroup","Paper","Stack","TextField","Typography","useCallback","useRef","useState","quoteSignInHref","dateLabel","atMs","Date","toLocaleDateString","undefined","month","day","year","newKey","globalThis","crypto","randomUUID","now","Math","random","toString","slice","signInHref","window","location","pathname","search","QuoteProofPanel","props","view","response","hostId","quoteId","token","siteFetch","onView","onReload","onReplaced","mode","setMode","name","setName","ticked","setTicked","comment","setComment","files","setFiles","uploading","setUploading","sending","setSending","error","setError","honeypot","setHoneypot","picker","attempt","link","encodeURIComponent","proofHref","id","business","storeName","post","path","body","headers","method","JSON","stringify","q","t","payload","json","catch","attach","picked","problem","length","done","total","index","file","entries","sent","requestTicket","request","action","ok","String","finalize","ticket","prev","respond","statements","approvalStatements","some","statement","includes","trim","current","v","version","confirmed","filter","fileIds","map","proofAccess","variant","sx","p","xs","sm","data-quote-proof-sign-in","spacing","component","severity","proofAccessMessage","href","proofs","allTicked","every","toggle","on","entry","color","status","revision","proof","inline","src","alt","loading","display","maxWidth","height","borderRadius","border","borderColor","size","download","m","mt","pl","charAt","toUpperCase","respondable","type","tabIndex","autoComplete","aria-hidden","value","onChange","event","target","position","left","width","opacity","direction","onClick","alignItems","mb","control","checked","disabled","pt","label","slotProps","htmlInput","maxLength","multiline","minRows","required","input","ref","multiple","hidden","accept","data-testid","Array","from","useFlexGap","flexWrap","onDelete","Boolean","click"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,2BAA2B,EAC3BC,0BAA0B,EAC1BC,wBAAwB,EACxBC,qBAAqB,EACrBC,6BAA6B,EAC7BC,wBAAwB,EACxBC,wBAAwB,QAEnB,wCAAuC;AAC9C,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAA0B,QAAO;AACvE,SAASC,eAAe,QAAQ,6BAAyB;AAoBzD,SAASC,UAAUC,IAAY;IAC7B,OAAO,IAAIC,KAAKD,MAAME,kBAAkB,CAACC,WAAW;QAAEC,OAAO;QAASC,KAAK;QAAWC,MAAM;IAAU;AACxG;AAEA,MAAMC,SAAS;;QAAMC,+BAAAA;oBAAAA,qBAAAA,WAAWC,MAAM,sBAAjBD,gCAAAA,mBAAmBE,UAAU,qBAA7BF,mCAAAA,sCAAqC,GAAGP,KAAKU,GAAG,GAAG,CAAC,EAAEC,KAAK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AAU,EAAEhK,6BAA6B,QAAQ,EAAEK,yBAAyB,UAAU,EAAEJ,yBAAyBG,0BAA0B,MAAM,CAAC;;;;8CAGxJ,MAACW;oCAAMkK,WAAU;oCAAM7C,SAAS;;sDAC9B,KAAC3H;4CAAOqH,SAAQ;4CAAYyD,UAAUpH,WAAWwI,QAAQ1I;4CAAYiH,SAAS,IAAM,KAAKnE;sDACtF5C,UAAU,aAAa;;sDAE1B,KAAC1D;4CAAO8K,UAAUpH;4CAAS+G,SAAS,IAAM1H,QAAQ;sDAC/C;;;;;;wBAKRa,sBAAQ,KAAC9D;4BAAM+H,UAAS;sCAASjE;6BAAiB;;qBAEnD;;;;AAIZ;AAEA,eAAezB,gBAAe"}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import * as Aglyn from '@aglyn/aglyn';
|
|
18
|
+
import { type ProductPhotoFit } from './product-photo-fit';
|
|
18
19
|
export declare const ID: Aglyn.ComponentId;
|
|
19
20
|
export interface RelatedProductsProps {
|
|
20
21
|
/** Anchor product id; blank follows the /products/{slug} page. */
|
|
@@ -27,6 +28,12 @@ export interface RelatedProductsProps {
|
|
|
27
28
|
* them in a grid of up to four across — the product grid's photo look.
|
|
28
29
|
*/
|
|
29
30
|
layout?: 'strip' | 'grid';
|
|
31
|
+
/**
|
|
32
|
+
* How each card draws its photo: `cover`, the default, fills the frame and
|
|
33
|
+
* crops what does not fit; `contain` shows the whole photo inside the same
|
|
34
|
+
* frame. Blank or unknown is `cover`.
|
|
35
|
+
*/
|
|
36
|
+
photoFit?: ProductPhotoFit;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* Related products / upsell strip (AGL-325): the product's manual list,
|
|
@@ -29,6 +29,7 @@ import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
|
29
29
|
import { generatePresetId } from "../utils/generate-preset-id.js";
|
|
30
30
|
import { formatOrderMoney } from "../model/buyer-notifications.js";
|
|
31
31
|
import { ProductImagePlaceholder } from "./product-image-placeholder.js";
|
|
32
|
+
import { PRODUCT_PHOTO_FIT_ATTRIBUTE, productPhotoFit, productPhotoFitSx } from "./product-photo-fit.js";
|
|
32
33
|
// Component ids are persisted in screen documents; never rename.
|
|
33
34
|
export const ID = 'related-products';
|
|
34
35
|
/**
|
|
@@ -37,11 +38,12 @@ export const ID = 'related-products';
|
|
|
37
38
|
* category neighbors — resolved server-side, rendered as cards.
|
|
38
39
|
*/ const RelatedProducts = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
39
40
|
var _site_pageData_commerce_product, _site_pageData_commerce, _site_pageData;
|
|
40
|
-
const { productId: productIdProp, heading, maxItems, layout } = props, rest = _object_without_properties_loose(props, [
|
|
41
|
+
const { productId: productIdProp, heading, maxItems, layout, photoFit } = props, rest = _object_without_properties_loose(props, [
|
|
41
42
|
"productId",
|
|
42
43
|
"heading",
|
|
43
44
|
"maxItems",
|
|
44
|
-
"layout"
|
|
45
|
+
"layout",
|
|
46
|
+
"photoFit"
|
|
45
47
|
]);
|
|
46
48
|
// Node styles ride the renderer-merged sx; recompose (stack.ts pattern).
|
|
47
49
|
const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [
|
|
@@ -111,6 +113,7 @@ export const ID = 'related-products';
|
|
|
111
113
|
ref: ref
|
|
112
114
|
}, rest));
|
|
113
115
|
const grid = layout === 'grid';
|
|
116
|
+
const photoFitSx = productPhotoFitSx(productPhotoFit(photoFit));
|
|
114
117
|
return /*#__PURE__*/ _jsxs(Box, _extends({
|
|
115
118
|
ref: ref
|
|
116
119
|
}, rest, {
|
|
@@ -170,9 +173,7 @@ export const ID = 'related-products';
|
|
|
170
173
|
component: "img",
|
|
171
174
|
image: imageUrl,
|
|
172
175
|
alt: item.name,
|
|
173
|
-
sx: _extends({}, mediaSx,
|
|
174
|
-
objectFit: 'cover'
|
|
175
|
-
})
|
|
176
|
+
sx: _extends({}, mediaSx, photoFitSx)
|
|
176
177
|
}, Aglyn.DEFERRED_IMAGE_ATTRIBUTES)) : // Never a blank tile: a product with no photo yet says
|
|
177
178
|
// so, in the theme's colours (AGL-3676 follow-up).
|
|
178
179
|
/*#__PURE__*/ _jsx(ProductImagePlaceholder, {
|
|
@@ -260,7 +261,8 @@ export const schema = {
|
|
|
260
261
|
value: 'grid'
|
|
261
262
|
}
|
|
262
263
|
]
|
|
263
|
-
}
|
|
264
|
+
},
|
|
265
|
+
PRODUCT_PHOTO_FIT_ATTRIBUTE
|
|
264
266
|
]
|
|
265
267
|
};
|
|
266
268
|
export const presets = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/related-products.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport { mdiShapePlus } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, useEffect, useState } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\nimport { formatOrderMoney } from '../model/buyer-notifications'\nimport { ProductImagePlaceholder } from './product-image-placeholder'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'related-products'\n\nexport interface RelatedProductsProps {\n /** Anchor product id; blank follows the /products/{slug} page. */\n productId?: string\n heading?: string\n maxItems?: number\n /**\n * How the items are drawn: `strip`, the default, a scrolling row of small\n * cards; `grid`, tall photo cards (4:5) with the name and price under\n * them in a grid of up to four across — the product grid's photo look.\n */\n layout?: 'strip' | 'grid'\n}\n\ninterface CatalogItem {\n id: string\n name: string\n slug: string\n priceUsd: number\n imageUrl?: string\n /** Listed before it has a price (AGL-3676). */\n priceComingSoon?: boolean\n}\n\n/**\n * Related products / upsell strip (AGL-325): the product's manual list,\n * else \"frequently bought together\" from recent orders, else tag and\n * category neighbors — resolved server-side, rendered as cards.\n */\nconst RelatedProducts = forwardRef<HTMLDivElement, RelatedProductsProps>(\n (props, ref) => {\n const { productId: productIdProp, heading, maxItems, layout, ...rest } = props\n // Node styles ride the renderer-merged sx; recompose (stack.ts pattern).\n const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [props['sx']]\n const site = Aglyn.useSite()\n const { hostId } = site\n // The page's product, when the server seeded it (AGL-659): its id is the\n // anchor, so the rail skips a product lookup the page already made.\n const seededProductId = (\n site.pageData as { commerce?: { product?: { id?: string } } } | undefined\n )?.commerce?.product?.id\n const [items, setItems] = useState<CatalogItem[] | null>(null)\n // The catalog counts the cap over products on sale (AGL-4038).\n const cap = Number(maxItems) > 0 ? Math.floor(Number(maxItems)) : 6\n\n useEffect(() => {\n if (!hostId) return\n let active = true\n void (async () => {\n let anchor = productIdProp || seededProductId || ''\n if (!anchor) {\n const match = window.location.pathname.match(/\\/products\\/([^/?#]+)/)\n if (!match) return\n const response = await fetch(\n `/api/commerce/product?hostId=${encodeURIComponent(hostId)}` +\n `&slug=${encodeURIComponent(decodeURIComponent(match[1]))}`,\n ).catch(() => null)\n const payload = await response?.json().catch(() => ({}))\n anchor = String(payload?.product?.id ?? '')\n }\n if (!active || !anchor) return\n const relatedResponse = await fetch(\n `/api/commerce/related?hostId=${encodeURIComponent(hostId)}` +\n `&productId=${encodeURIComponent(anchor)}`,\n ).catch(() => null)\n const related = await relatedResponse?.json().catch(() => ({}))\n const ids: string[] = related?.productIds ?? []\n if (!active || ids.length === 0) return setItems([])\n const catalogResponse = await fetch(\n `/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}` +\n `&ids=${encodeURIComponent(ids.join(','))}&limit=${cap}`,\n ).catch(() => null)\n const catalog = await catalogResponse?.json().catch(() => ({}))\n if (active) setItems(catalog?.items ?? [])\n })()\n return () => {\n active = false\n }\n }, [hostId, productIdProp, seededProductId, cap])\n\n if (!hostId) {\n return (\n <Box\n ref={ref}\n {...rest}\n sx={[\n {\n p: 3,\n border: '1px dashed',\n borderColor: 'divider',\n borderRadius: 1,\n color: 'text.secondary',\n fontSize: 13,\n fontFamily: 'system-ui, sans-serif',\n },\n ...nodeSx,\n ]}\n >\n {'Related products render here'}\n </Box>\n )\n }\n if (!items || items.length === 0) return <Box ref={ref} {...rest} />\n\n const grid = layout === 'grid'\n return (\n <Box ref={ref} {...rest}>\n <Typography variant={grid ? 'h5' : 'h6'} component=\"h2\" gutterBottom sx={grid ? { mb: 2 } : undefined}>\n {heading || 'You may also like'}\n </Typography>\n <Box\n sx={\n grid\n ? {\n display: 'grid',\n gap: 2,\n gridTemplateColumns: { xs: 'repeat(2, minmax(0, 1fr))', md: 'repeat(4, minmax(0, 1fr))' },\n }\n : { display: 'flex', gap: 1.5, overflowX: 'auto', pb: 1 }\n }\n >\n {items\n .slice(0, cap)\n .map((item) => {\n // AGL-1726: resolved BEFORE the guard — see the note in\n // `product-detail.tsx`.\n const imageUrl = Aglyn.siteRelativeMediaSrc(item.imageUrl, {\n hostId,\n })\n const mediaSx = grid\n ? { aspectRatio: '4 / 5', borderRadius: 2 }\n : { height: 110 }\n return (\n <Card\n key={item.id}\n variant={grid ? 'elevation' : 'outlined'}\n elevation={0}\n sx={grid ? { bgcolor: 'transparent', overflow: 'visible', minWidth: 0 } : { minWidth: 160 }}\n >\n <CardActionArea\n href={`/products/${item.slug}`}\n sx={grid ? { borderRadius: 2 } : undefined}\n >\n {imageUrl ? (\n <CardMedia\n component=\"img\"\n image={imageUrl}\n alt={item.name}\n sx={{ ...mediaSx, objectFit: 'cover' }}\n // Deferred (AGL-2486). A related-products rail sits at\n // the BOTTOM of a product page by construction, and it\n // was fetching eagerly against the gallery hero above\n // it — the one image on that page that is the LCP.\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : (\n // Never a blank tile: a product with no photo yet says\n // so, in the theme's colours (AGL-3676 follow-up).\n <ProductImagePlaceholder name={item.name} sx={mediaSx} />\n )}\n <CardContent sx={grid ? { px: 0.5, pt: 1.5, pb: 1 } : { py: 1 }}>\n <Typography variant={grid ? 'subtitle1' : 'body2'} noWrap>\n {item.name}\n </Typography>\n <Typography variant={grid ? 'body2' : 'caption'} color=\"text.secondary\">\n {item.priceComingSoon\n ? 'Price coming soon'\n : formatOrderMoney(Math.round(item.priceUsd * 100))}\n </Typography>\n </CardContent>\n </CardActionArea>\n </Card>\n )\n })}\n </Box>\n </Box>\n )\n },\n)\nRelatedProducts.displayName = 'AglynRelatedProducts'\n\nexport const schema: Aglyn.ComponentSchema<RelatedProductsProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Related products',\n description:\n 'An upsell strip — your manual picks, or what people buy together.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiShapePlus.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'productId',\n label: 'Product id',\n description:\n 'The product to find relatives OF. Blank reads it from the URL, so ' +\n 'a product template shows each product’s own related items; naming ' +\n 'one pins the rail to that product’s relatives everywhere.',\n component: Aglyn.FieldComponentType.PRODUCT_SELECT,\n },\n {\n name: 'heading',\n label: 'Heading',\n description: 'Defaults to \"You may also like\".',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'maxItems',\n label: 'Max items',\n description: 'Cap the strip (default 6).',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n type: 'number',\n },\n {\n // Default `strip`, so a page that already places this block keeps it.\n name: 'layout',\n label: 'Layout',\n description: 'A scrolling strip of small cards, or a grid of tall photo cards.',\n component: Aglyn.FieldComponentType.SELECT,\n options: [\n { label: 'Strip', value: 'strip' },\n { label: 'Photo grid', value: 'grid' },\n ],\n },\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Related products',\n pluginId: BUNDLE_ID,\n description: 'Manual picks or frequently-bought-together',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiShapePlus.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: {},\n },\n },\n]\n\nexport default RelatedProducts\n"],"names":["Aglyn","mdiShapePlus","Box","Card","CardActionArea","CardContent","CardMedia","Typography","forwardRef","useEffect","useState","BUNDLE_ID","generatePresetId","formatOrderMoney","ProductImagePlaceholder","ID","RelatedProducts","props","ref","site","productId","productIdProp","heading","maxItems","layout","rest","nodeSx","Array","isArray","useSite","hostId","seededProductId","pageData","commerce","product","id","items","setItems","cap","Number","Math","floor","active","anchor","payload","match","window","location","pathname","response","fetch","encodeURIComponent","decodeURIComponent","catch","json","String","relatedResponse","related","ids","productIds","length","catalogResponse","join","catalog","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","grid","variant","component","gutterBottom","mb","undefined","display","gap","gridTemplateColumns","xs","md","overflowX","pb","slice","map","item","imageUrl","siteRelativeMediaSrc","mediaSx","aspectRatio","height","elevation","bgcolor","overflow","minWidth","href","slug","image","alt","name","objectFit","DEFERRED_IMAGE_ATTRIBUTES","px","pt","py","noWrap","priceComingSoon","round","priceUsd","displayName","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","label","FieldComponentType","PRODUCT_SELECT","TEXT_FIELD","type","SELECT","options","value","presets","NodeType","PRESET","data","componentId"],"mappings":";;;AAA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uEACA;YACFzC,WAAW1E,MAAM+H,kBAAkB,CAACC,cAAc;QACpD;QACA;YACE3B,MAAM;YACNyB,OAAO;YACPX,aAAa;YACbzC,WAAW1E,MAAM+H,kBAAkB,CAACE,UAAU;QAChD;QACA;YACE5B,MAAM;YACNyB,OAAO;YACPX,aAAa;YACbzC,WAAW1E,MAAM+H,kBAAkB,CAACE,UAAU;YAC9CC,MAAM;QACR;QACA;YACE,sEAAsE;YACtE7B,MAAM;YACNyB,OAAO;YACPX,aAAa;YACbzC,WAAW1E,MAAM+H,kBAAkB,CAACI,MAAM;YAC1CC,SAAS;gBACP;oBAAEN,OAAO;oBAASO,OAAO;gBAAQ;gBACjC;oBAAEP,OAAO;oBAAcO,OAAO;gBAAO;aACtC;QACH;KACD;AACH,EAAC;AAED,OAAO,MAAMC,UAAgC;IAC3C;QACErB,KAAKrG,iBAAiBG;QACtBmH,MAAMlI,MAAMuI,QAAQ,CAACC,MAAM;QAC3BzB,aAAa;QACbG,UAAUvG;QACVwG,aAAa;QACbC,UAAUpH,MAAMqH,iBAAiB,CAACC,QAAQ;QAC1CC,MAAM;YAAEC,MAAMvH,aAAauH,IAAI;YAAExD,IAAI;gBAAEK,OAAO;YAAU;QAAE;QAC1DoE,MAAM;YACJxB,KAAK;YACLyB,aAAa3H;YACbmG,UAAUvG;YACVM,OAAO,CAAC;QACV;IACF;CACD,CAAA;AAED,eAAeD,gBAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/related-products.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport { mdiShapePlus } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, useEffect, useState } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\nimport { formatOrderMoney } from '../model/buyer-notifications'\nimport { ProductImagePlaceholder } from './product-image-placeholder'\nimport {\n PRODUCT_PHOTO_FIT_ATTRIBUTE,\n productPhotoFit,\n productPhotoFitSx,\n type ProductPhotoFit,\n} from './product-photo-fit'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'related-products'\n\nexport interface RelatedProductsProps {\n /** Anchor product id; blank follows the /products/{slug} page. */\n productId?: string\n heading?: string\n maxItems?: number\n /**\n * How the items are drawn: `strip`, the default, a scrolling row of small\n * cards; `grid`, tall photo cards (4:5) with the name and price under\n * them in a grid of up to four across — the product grid's photo look.\n */\n layout?: 'strip' | 'grid'\n /**\n * How each card draws its photo: `cover`, the default, fills the frame and\n * crops what does not fit; `contain` shows the whole photo inside the same\n * frame. Blank or unknown is `cover`.\n */\n photoFit?: ProductPhotoFit\n}\n\ninterface CatalogItem {\n id: string\n name: string\n slug: string\n priceUsd: number\n imageUrl?: string\n /** Listed before it has a price (AGL-3676). */\n priceComingSoon?: boolean\n}\n\n/**\n * Related products / upsell strip (AGL-325): the product's manual list,\n * else \"frequently bought together\" from recent orders, else tag and\n * category neighbors — resolved server-side, rendered as cards.\n */\nconst RelatedProducts = forwardRef<HTMLDivElement, RelatedProductsProps>(\n (props, ref) => {\n const { productId: productIdProp, heading, maxItems, layout, photoFit, ...rest } = props\n // Node styles ride the renderer-merged sx; recompose (stack.ts pattern).\n const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [props['sx']]\n const site = Aglyn.useSite()\n const { hostId } = site\n // The page's product, when the server seeded it (AGL-659): its id is the\n // anchor, so the rail skips a product lookup the page already made.\n const seededProductId = (\n site.pageData as { commerce?: { product?: { id?: string } } } | undefined\n )?.commerce?.product?.id\n const [items, setItems] = useState<CatalogItem[] | null>(null)\n // The catalog counts the cap over products on sale (AGL-4038).\n const cap = Number(maxItems) > 0 ? Math.floor(Number(maxItems)) : 6\n\n useEffect(() => {\n if (!hostId) return\n let active = true\n void (async () => {\n let anchor = productIdProp || seededProductId || ''\n if (!anchor) {\n const match = window.location.pathname.match(/\\/products\\/([^/?#]+)/)\n if (!match) return\n const response = await fetch(\n `/api/commerce/product?hostId=${encodeURIComponent(hostId)}` +\n `&slug=${encodeURIComponent(decodeURIComponent(match[1]))}`,\n ).catch(() => null)\n const payload = await response?.json().catch(() => ({}))\n anchor = String(payload?.product?.id ?? '')\n }\n if (!active || !anchor) return\n const relatedResponse = await fetch(\n `/api/commerce/related?hostId=${encodeURIComponent(hostId)}` +\n `&productId=${encodeURIComponent(anchor)}`,\n ).catch(() => null)\n const related = await relatedResponse?.json().catch(() => ({}))\n const ids: string[] = related?.productIds ?? []\n if (!active || ids.length === 0) return setItems([])\n const catalogResponse = await fetch(\n `/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}` +\n `&ids=${encodeURIComponent(ids.join(','))}&limit=${cap}`,\n ).catch(() => null)\n const catalog = await catalogResponse?.json().catch(() => ({}))\n if (active) setItems(catalog?.items ?? [])\n })()\n return () => {\n active = false\n }\n }, [hostId, productIdProp, seededProductId, cap])\n\n if (!hostId) {\n return (\n <Box\n ref={ref}\n {...rest}\n sx={[\n {\n p: 3,\n border: '1px dashed',\n borderColor: 'divider',\n borderRadius: 1,\n color: 'text.secondary',\n fontSize: 13,\n fontFamily: 'system-ui, sans-serif',\n },\n ...nodeSx,\n ]}\n >\n {'Related products render here'}\n </Box>\n )\n }\n if (!items || items.length === 0) return <Box ref={ref} {...rest} />\n\n const grid = layout === 'grid'\n const photoFitSx = productPhotoFitSx(productPhotoFit(photoFit))\n return (\n <Box ref={ref} {...rest}>\n <Typography variant={grid ? 'h5' : 'h6'} component=\"h2\" gutterBottom sx={grid ? { mb: 2 } : undefined}>\n {heading || 'You may also like'}\n </Typography>\n <Box\n sx={\n grid\n ? {\n display: 'grid',\n gap: 2,\n gridTemplateColumns: { xs: 'repeat(2, minmax(0, 1fr))', md: 'repeat(4, minmax(0, 1fr))' },\n }\n : { display: 'flex', gap: 1.5, overflowX: 'auto', pb: 1 }\n }\n >\n {items\n .slice(0, cap)\n .map((item) => {\n // AGL-1726: resolved BEFORE the guard — see the note in\n // `product-detail.tsx`.\n const imageUrl = Aglyn.siteRelativeMediaSrc(item.imageUrl, {\n hostId,\n })\n const mediaSx = grid\n ? { aspectRatio: '4 / 5', borderRadius: 2 }\n : { height: 110 }\n return (\n <Card\n key={item.id}\n variant={grid ? 'elevation' : 'outlined'}\n elevation={0}\n sx={grid ? { bgcolor: 'transparent', overflow: 'visible', minWidth: 0 } : { minWidth: 160 }}\n >\n <CardActionArea\n href={`/products/${item.slug}`}\n sx={grid ? { borderRadius: 2 } : undefined}\n >\n {imageUrl ? (\n <CardMedia\n component=\"img\"\n image={imageUrl}\n alt={item.name}\n sx={{ ...mediaSx, ...photoFitSx }}\n // Deferred (AGL-2486). A related-products rail sits at\n // the BOTTOM of a product page by construction, and it\n // was fetching eagerly against the gallery hero above\n // it — the one image on that page that is the LCP.\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : (\n // Never a blank tile: a product with no photo yet says\n // so, in the theme's colours (AGL-3676 follow-up).\n <ProductImagePlaceholder name={item.name} sx={mediaSx} />\n )}\n <CardContent sx={grid ? { px: 0.5, pt: 1.5, pb: 1 } : { py: 1 }}>\n <Typography variant={grid ? 'subtitle1' : 'body2'} noWrap>\n {item.name}\n </Typography>\n <Typography variant={grid ? 'body2' : 'caption'} color=\"text.secondary\">\n {item.priceComingSoon\n ? 'Price coming soon'\n : formatOrderMoney(Math.round(item.priceUsd * 100))}\n </Typography>\n </CardContent>\n </CardActionArea>\n </Card>\n )\n })}\n </Box>\n </Box>\n )\n },\n)\nRelatedProducts.displayName = 'AglynRelatedProducts'\n\nexport const schema: Aglyn.ComponentSchema<RelatedProductsProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Related products',\n description:\n 'An upsell strip — your manual picks, or what people buy together.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiShapePlus.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'productId',\n label: 'Product id',\n description:\n 'The product to find relatives OF. Blank reads it from the URL, so ' +\n 'a product template shows each product’s own related items; naming ' +\n 'one pins the rail to that product’s relatives everywhere.',\n component: Aglyn.FieldComponentType.PRODUCT_SELECT,\n },\n {\n name: 'heading',\n label: 'Heading',\n description: 'Defaults to \"You may also like\".',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'maxItems',\n label: 'Max items',\n description: 'Cap the strip (default 6).',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n type: 'number',\n },\n {\n // Default `strip`, so a page that already places this block keeps it.\n name: 'layout',\n label: 'Layout',\n description: 'A scrolling strip of small cards, or a grid of tall photo cards.',\n component: Aglyn.FieldComponentType.SELECT,\n options: [\n { label: 'Strip', value: 'strip' },\n { label: 'Photo grid', value: 'grid' },\n ],\n },\n PRODUCT_PHOTO_FIT_ATTRIBUTE,\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Related products',\n pluginId: BUNDLE_ID,\n description: 'Manual picks or frequently-bought-together',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiShapePlus.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: {},\n },\n },\n]\n\nexport default RelatedProducts\n"],"names":["Aglyn","mdiShapePlus","Box","Card","CardActionArea","CardContent","CardMedia","Typography","forwardRef","useEffect","useState","BUNDLE_ID","generatePresetId","formatOrderMoney","ProductImagePlaceholder","PRODUCT_PHOTO_FIT_ATTRIBUTE","productPhotoFit","productPhotoFitSx","ID","RelatedProducts","props","ref","site","productId","productIdProp","heading","maxItems","layout","photoFit","rest","nodeSx","Array","isArray","useSite","hostId","seededProductId","pageData","commerce","product","id","items","setItems","cap","Number","Math","floor","active","anchor","payload","match","window","location","pathname","response","fetch","encodeURIComponent","decodeURIComponent","catch","json","String","relatedResponse","related","ids","productIds","length","catalogResponse","join","catalog","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","grid","photoFitSx","variant","component","gutterBottom","mb","undefined","display","gap","gridTemplateColumns","xs","md","overflowX","pb","slice","map","item","imageUrl","siteRelativeMediaSrc","mediaSx","aspectRatio","height","elevation","bgcolor","overflow","minWidth","href","slug","image","alt","name","DEFERRED_IMAGE_ATTRIBUTES","px","pt","py","noWrap","priceComingSoon","round","priceUsd","displayName","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","label","FieldComponentType","PRODUCT_SELECT","TEXT_FIELD","type","SELECT","options","value","presets","NodeType","PRESET","data","componentId"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,YAAY,QAAQ,yBAAwB;AACrD,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACvD,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,gBAAgB,Q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CC,MAAM;QACR;QACA;YACE,sEAAsE;YACtE5B,MAAM;YACNwB,OAAO;YACPX,aAAa;YACbxC,WAAW/E,MAAMmI,kBAAkB,CAACI,MAAM;YAC1CC,SAAS;gBACP;oBAAEN,OAAO;oBAASO,OAAO;gBAAQ;gBACjC;oBAAEP,OAAO;oBAAcO,OAAO;gBAAO;aACtC;QACH;QACA1H;KACD;AACH,EAAC;AAED,OAAO,MAAM2H,UAAgC;IAC3C;QACErB,KAAKzG,iBAAiBM;QACtBoH,MAAMtI,MAAM2I,QAAQ,CAACC,MAAM;QAC3BzB,aAAa;QACbG,UAAU3G;QACV4G,aAAa;QACbC,UAAUxH,MAAMyH,iBAAiB,CAACC,QAAQ;QAC1CC,MAAM;YAAEC,MAAM3H,aAAa2H,IAAI;YAAExD,IAAI;gBAAEK,OAAO;YAAU;QAAE;QAC1DoE,MAAM;YACJxB,KAAK;YACLyB,aAAa5H;YACboG,UAAU3G;YACVS,OAAO,CAAC;QACV;IACF;CACD,CAAA;AAED,eAAeD,gBAAe"}
|
|
@@ -28,3 +28,11 @@ export declare const QUOTE_PAGE_COMPONENT_ID = "quote-page";
|
|
|
28
28
|
export declare const QUOTE_PAGE_PATH = "pay-quote";
|
|
29
29
|
/** The page's address for one quote and its signed link token, relative to the site. */
|
|
30
30
|
export declare function quotePageHref(quoteId: string, token: string): string;
|
|
31
|
+
/** Where the site's built-in sign-in page is (the User Accounts plugin's own route). */
|
|
32
|
+
export declare const QUOTE_SIGN_IN_PATH = "/signin";
|
|
33
|
+
/**
|
|
34
|
+
* The sign-in page, returning to `back` (the quote page's own path and query)
|
|
35
|
+
* once the customer signs in (AGL-4206). The sign-in block honors `continue`
|
|
36
|
+
* for same-site paths only.
|
|
37
|
+
*/
|
|
38
|
+
export declare function quoteSignInHref(back: string): string;
|
|
@@ -31,5 +31,16 @@ export const QUOTE_PAGE_PATH = 'pay-quote';
|
|
|
31
31
|
});
|
|
32
32
|
return `/${QUOTE_PAGE_PATH}?${query.toString()}`;
|
|
33
33
|
}
|
|
34
|
+
/** Where the site's built-in sign-in page is (the User Accounts plugin's own route). */ export const QUOTE_SIGN_IN_PATH = '/signin';
|
|
35
|
+
/**
|
|
36
|
+
* The sign-in page, returning to `back` (the quote page's own path and query)
|
|
37
|
+
* once the customer signs in (AGL-4206). The sign-in block honors `continue`
|
|
38
|
+
* for same-site paths only.
|
|
39
|
+
*/ export function quoteSignInHref(back) {
|
|
40
|
+
const path = back.startsWith('/') && !back.startsWith('//') ? back : `/${QUOTE_PAGE_PATH}`;
|
|
41
|
+
return `${QUOTE_SIGN_IN_PATH}?${new URLSearchParams({
|
|
42
|
+
continue: path
|
|
43
|
+
}).toString()}`;
|
|
44
|
+
}
|
|
34
45
|
|
|
35
46
|
//# sourceMappingURL=quote-page.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/constants/quote-page.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The customer's quote page (AGL-4094), where a quote's pay link opens.\n *\n * The component id is persisted in screen documents; never rename it. The\n * path is where the site serves the page when it has no page of its own\n * there. It is `pay-quote` rather than `quote` because a business that sells\n * made-to-order work often has a \"Request a quote\" page at `/quote` already,\n * and a page of the site's own at an address always wins over this one: a pay\n * link there would open the request form.\n */\nexport const QUOTE_PAGE_COMPONENT_ID = 'quote-page'\n\nexport const QUOTE_PAGE_PATH = 'pay-quote'\n\n/** The page's address for one quote and its signed link token, relative to the site. */\nexport function quotePageHref(quoteId: string, token: string): string {\n const query = new URLSearchParams({ q: quoteId, t: token })\n return `/${QUOTE_PAGE_PATH}?${query.toString()}`\n}\n"],"names":["QUOTE_PAGE_COMPONENT_ID","QUOTE_PAGE_PATH","quotePageHref","quoteId","token","query","URLSearchParams","q","t","toString"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GACD,OAAO,MAAMA,0BAA0B,aAAY;AAEnD,OAAO,MAAMC,kBAAkB,YAAW;AAE1C,sFAAsF,GACtF,OAAO,SAASC,cAAcC,OAAe,EAAEC,KAAa;IAC1D,MAAMC,QAAQ,IAAIC,gBAAgB;QAAEC,GAAGJ;QAASK,GAAGJ;IAAM;IACzD,OAAO,CAAC,CAAC,EAAEH,gBAAgB,CAAC,EAAEI,MAAMI,QAAQ,IAAI;AAClD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/constants/quote-page.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The customer's quote page (AGL-4094), where a quote's pay link opens.\n *\n * The component id is persisted in screen documents; never rename it. The\n * path is where the site serves the page when it has no page of its own\n * there. It is `pay-quote` rather than `quote` because a business that sells\n * made-to-order work often has a \"Request a quote\" page at `/quote` already,\n * and a page of the site's own at an address always wins over this one: a pay\n * link there would open the request form.\n */\nexport const QUOTE_PAGE_COMPONENT_ID = 'quote-page'\n\nexport const QUOTE_PAGE_PATH = 'pay-quote'\n\n/** The page's address for one quote and its signed link token, relative to the site. */\nexport function quotePageHref(quoteId: string, token: string): string {\n const query = new URLSearchParams({ q: quoteId, t: token })\n return `/${QUOTE_PAGE_PATH}?${query.toString()}`\n}\n\n/** Where the site's built-in sign-in page is (the User Accounts plugin's own route). */\nexport const QUOTE_SIGN_IN_PATH = '/signin'\n\n/**\n * The sign-in page, returning to `back` (the quote page's own path and query)\n * once the customer signs in (AGL-4206). The sign-in block honors `continue`\n * for same-site paths only.\n */\nexport function quoteSignInHref(back: string): string {\n const path = back.startsWith('/') && !back.startsWith('//') ? back : `/${QUOTE_PAGE_PATH}`\n return `${QUOTE_SIGN_IN_PATH}?${new URLSearchParams({ continue: path }).toString()}`\n}\n"],"names":["QUOTE_PAGE_COMPONENT_ID","QUOTE_PAGE_PATH","quotePageHref","quoteId","token","query","URLSearchParams","q","t","toString","QUOTE_SIGN_IN_PATH","quoteSignInHref","back","path","startsWith","continue"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GACD,OAAO,MAAMA,0BAA0B,aAAY;AAEnD,OAAO,MAAMC,kBAAkB,YAAW;AAE1C,sFAAsF,GACtF,OAAO,SAASC,cAAcC,OAAe,EAAEC,KAAa;IAC1D,MAAMC,QAAQ,IAAIC,gBAAgB;QAAEC,GAAGJ;QAASK,GAAGJ;IAAM;IACzD,OAAO,CAAC,CAAC,EAAEH,gBAAgB,CAAC,EAAEI,MAAMI,QAAQ,IAAI;AAClD;AAEA,sFAAsF,GACtF,OAAO,MAAMC,qBAAqB,UAAS;AAE3C;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,IAAY;IAC1C,MAAMC,OAAOD,KAAKE,UAAU,CAAC,QAAQ,CAACF,KAAKE,UAAU,CAAC,QAAQF,OAAO,CAAC,CAAC,EAAEX,iBAAiB;IAC1F,OAAO,GAAGS,mBAAmB,CAAC,EAAE,IAAIJ,gBAAgB;QAAES,UAAUF;IAAK,GAAGJ,QAAQ,IAAI;AACtF"}
|
|
@@ -50,7 +50,12 @@ export interface HostCart {
|
|
|
50
50
|
createdAtMs?: number;
|
|
51
51
|
}
|
|
52
52
|
export declare const CART_MAX_LINES = 50;
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The most of one line a shopper can buy online (AGL-4205): 9,999, the same
|
|
55
|
+
* ceiling a quote line has (`QUOTE_MAX_QUANTITY`). It was 99, which stopped a
|
|
56
|
+
* print shop's 100-, 250- and 500-piece apparel orders at the product page.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CART_MAX_QUANTITY = 9999;
|
|
54
59
|
/**
|
|
55
60
|
* One cart line's identity: product, variant, use day and add-ons
|
|
56
61
|
* (AGL-4100). A line with no add-ons keeps the key it always had, so a cart
|
|
@@ -22,7 +22,11 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
22
22
|
* a stale price. Pure helpers; the cart API owns I/O.
|
|
23
23
|
*/ import { modifierSelectionKey } from "./product-modifiers.js";
|
|
24
24
|
export const CART_MAX_LINES = 50;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The most of one line a shopper can buy online (AGL-4205): 9,999, the same
|
|
27
|
+
* ceiling a quote line has (`QUOTE_MAX_QUANTITY`). It was 99, which stopped a
|
|
28
|
+
* print shop's 100-, 250- and 500-piece apparel orders at the product page.
|
|
29
|
+
*/ export const CART_MAX_QUANTITY = 9999;
|
|
26
30
|
/**
|
|
27
31
|
* One cart line's identity: product, variant, use day and add-ons
|
|
28
32
|
* (AGL-4100). A line with no add-ons keeps the key it always had, so a cart
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-cart.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Cart v1 (AGL-293): a server-backed cart doc at\n * `hosts/{hostId}/carts/{cartId}`, keyed by an httpOnly cookie. Lines\n * store only ids + quantity — display data and prices resolve from the\n * product docs at read/checkout time, so a stale cart can never charge\n * a stale price. Pure helpers; the cart API owns I/O.\n */\n\nimport { modifierSelectionKey, type ModifierSelection } from './product-modifiers'\n\nexport interface CartLine {\n productId: string\n /** Absent = the product's default variant. */\n variantId?: string\n quantity: number\n /**\n * The day the shopper chose to use a check-in item (AGL-4043),\n * `YYYY-MM-DD` on the store's calendar. Absent: the day they buy. Two\n * different days of one pass are two lines.\n */\n useDayKey?: string\n /**\n * The add-ons the shopper chose on the product's page (AGL-4100), ids\n * only, in the product's group order: priced from the product on every\n * read and at checkout, never stored with a price. Absent: none. The same\n * product with different choices is a different line.\n */\n modifiers?: ModifierSelection[]\n}\n\n/** `hosts/{hostId}/carts/{cartId}` doc. */\nexport interface HostCart {\n lines: CartLine[]\n /** Storefront customer once signed in (AGL-294 merge). */\n customerId?: string\n updatedAtMs?: number\n createdAtMs?: number\n}\n\nexport const CART_MAX_LINES = 50\nexport const CART_MAX_QUANTITY =
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-cart.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Cart v1 (AGL-293): a server-backed cart doc at\n * `hosts/{hostId}/carts/{cartId}`, keyed by an httpOnly cookie. Lines\n * store only ids + quantity — display data and prices resolve from the\n * product docs at read/checkout time, so a stale cart can never charge\n * a stale price. Pure helpers; the cart API owns I/O.\n */\n\nimport { modifierSelectionKey, type ModifierSelection } from './product-modifiers'\n\nexport interface CartLine {\n productId: string\n /** Absent = the product's default variant. */\n variantId?: string\n quantity: number\n /**\n * The day the shopper chose to use a check-in item (AGL-4043),\n * `YYYY-MM-DD` on the store's calendar. Absent: the day they buy. Two\n * different days of one pass are two lines.\n */\n useDayKey?: string\n /**\n * The add-ons the shopper chose on the product's page (AGL-4100), ids\n * only, in the product's group order: priced from the product on every\n * read and at checkout, never stored with a price. Absent: none. The same\n * product with different choices is a different line.\n */\n modifiers?: ModifierSelection[]\n}\n\n/** `hosts/{hostId}/carts/{cartId}` doc. */\nexport interface HostCart {\n lines: CartLine[]\n /** Storefront customer once signed in (AGL-294 merge). */\n customerId?: string\n updatedAtMs?: number\n createdAtMs?: number\n}\n\nexport const CART_MAX_LINES = 50\n/**\n * The most of one line a shopper can buy online (AGL-4205): 9,999, the same\n * ceiling a quote line has (`QUOTE_MAX_QUANTITY`). It was 99, which stopped a\n * print shop's 100-, 250- and 500-piece apparel orders at the product page.\n */\nexport const CART_MAX_QUANTITY = 9_999\n\n/**\n * One cart line's identity: product, variant, use day and add-ons\n * (AGL-4100). A line with no add-ons keeps the key it always had, so a cart\n * stored before add-ons were sold online reads, merges and removes as it did.\n */\nexport function cartLineKey(\n line: Pick<CartLine, 'productId' | 'variantId' | 'useDayKey' | 'modifiers'>,\n): string {\n const base = `${line.productId}:${line.variantId ?? ''}:${line.useDayKey ?? ''}`\n const choices = modifierSelectionKey(line.modifiers)\n return choices ? `${base}:${choices}` : base\n}\n\nconst lineKey = cartLineKey\n\n/**\n * A line quantity, coerced to a whole finite number (AGL-2285).\n *\n * `Math.round(line.quantity)` was the whole sanitiser, and `Math.round(NaN)` is\n * `NaN` — which then walked past the guard below, because `NaN <= 0` is\n * `false`. A cart line with `quantity: NaN` (a legal Firestore double) was\n * stored, and from there `cartCount` reported `NaN` in the mini-cart badge and\n * `cart-checkout.ts` computed `itemsCents`, the platform fee and the Stripe\n * `line_items[n][quantity]` as `NaN` too — so Stripe 400s and the shopper\n * cannot check out AT ALL until they find the poisoned line and remove it.\n *\n * Answering 0 is what makes the existing `<= 0` guard do its job: an\n * unusable quantity removes the line (or refuses to add one) rather than\n * writing a value nothing downstream can compare against. The same lesson as\n * AGL-2229 one collection over — `Math.max`/`Math.min`/`Math.round` propagate\n * `NaN`, they do not discard it.\n */\nfunction wholeQuantity(value: unknown): number {\n const quantity = Math.round(Number(value ?? 0))\n return Number.isFinite(quantity) ? quantity : 0\n}\n\n/**\n * Adds/merges a line (quantities accumulate), clamped to per-line and\n * line-count caps. Quantity ≤ 0 removes the line.\n */\nexport function upsertCartLine(\n cart: Pick<HostCart, 'lines'>,\n line: CartLine,\n mode: 'add' | 'set' = 'add',\n): CartLine[] {\n const quantity = wholeQuantity(line.quantity)\n const key = lineKey(line)\n const existing = cart.lines.find((item) => lineKey(item) === key)\n if (!existing) {\n if (quantity <= 0) return cart.lines\n if (cart.lines.length >= CART_MAX_LINES) return cart.lines\n return [\n ...cart.lines,\n { ...line, quantity: Math.min(CART_MAX_QUANTITY, quantity) },\n ]\n }\n // The STORED side is coerced too (AGL-2285): a line written before this\n // guard, or by any other writer, can still hold a non-finite quantity, and\n // adding to it would carry that forward forever.\n const nextQuantity =\n mode === 'add' ? wholeQuantity(existing.quantity) + quantity : quantity\n if (nextQuantity <= 0) {\n return cart.lines.filter((item) => lineKey(item) !== key)\n }\n return cart.lines.map((item) =>\n lineKey(item) === key\n ? { ...item, quantity: Math.min(CART_MAX_QUANTITY, nextQuantity) }\n : item,\n )\n}\n\nexport function removeCartLine(\n cart: Pick<HostCart, 'lines'>,\n line: Pick<CartLine, 'productId' | 'variantId' | 'useDayKey' | 'modifiers'>,\n): CartLine[] {\n const key = lineKey(line)\n return cart.lines.filter((item) => lineKey(item) !== key)\n}\n\n/** Total units across lines (the mini-cart badge). */\nexport function cartCount(cart: Pick<HostCart, 'lines'> | undefined): number {\n // Coerced per line (AGL-2285) so one stored `NaN` cannot make the badge read\n // `NaN` for a cart that otherwise has real items in it.\n return (cart?.lines ?? []).reduce(\n (sum, line) => sum + wholeQuantity(line?.quantity),\n 0,\n )\n}\n\n/**\n * Merges a guest cart into a customer cart on sign-in (AGL-294):\n * quantities accumulate per line, capped as usual.\n */\nexport function mergeCarts(\n customerCart: Pick<HostCart, 'lines'>,\n guestCart: Pick<HostCart, 'lines'>,\n): CartLine[] {\n let lines = [...customerCart.lines]\n for (const line of guestCart.lines) {\n lines = upsertCartLine({ lines }, line, 'add')\n }\n return lines\n}\n"],"names":["modifierSelectionKey","CART_MAX_LINES","CART_MAX_QUANTITY","cartLineKey","line","base","productId","variantId","useDayKey","choices","modifiers","lineKey","wholeQuantity","value","quantity","Math","round","Number","isFinite","upsertCartLine","cart","mode","key","existing","lines","find","item","length","min","nextQuantity","filter","map","removeCartLine","cartCount","reduce","sum","mergeCarts","customerCart","guestCart"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;CAMC,GAED,SAASA,oBAAoB,QAAgC,yBAAqB;AA+BlF,OAAO,MAAMC,iBAAiB,GAAE;AAChC;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB,KAAK;AAEtC;;;;CAIC,GACD,OAAO,SAASC,YACdC,IAA2E;QAEzCA,iBAAwBA;IAA1D,MAAMC,OAAO,GAAGD,KAAKE,SAAS,CAAC,CAAC,GAAEF,kBAAAA,KAAKG,SAAS,YAAdH,kBAAkB,GAAG,CAAC,GAAEA,kBAAAA,KAAKI,SAAS,YAAdJ,kBAAkB,IAAI;IAChF,MAAMK,UAAUT,qBAAqBI,KAAKM,SAAS;IACnD,OAAOD,UAAU,GAAGJ,KAAK,CAAC,EAAEI,SAAS,GAAGJ;AAC1C;AAEA,MAAMM,UAAUR;AAEhB;;;;;;;;;;;;;;;;CAgBC,GACD,SAASS,cAAcC,KAAc;IACnC,MAAMC,WAAWC,KAAKC,KAA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EU,MAAM,CAC/B,CAACC,KAAK/B,OAAS+B,MAAMvB,cAAcR,wBAAAA,KAAMU,QAAQ,GACjD;AAEJ;AAEA;;;CAGC,GACD,OAAO,SAASsB,WACdC,YAAqC,EACrCC,SAAkC;IAElC,IAAId,QAAQ;WAAIa,aAAab,KAAK;KAAC;IACnC,KAAK,MAAMpB,QAAQkC,UAAUd,KAAK,CAAE;QAClCA,QAAQL,eAAe;YAAEK;QAAM,GAAGpB,MAAM;IAC1C;IACA,OAAOoB;AACT"}
|
|
@@ -256,7 +256,11 @@ export function invoicePayRefusal(order, orderId, /** The store's sales tax choi
|
|
|
256
256
|
revision: 1,
|
|
257
257
|
proofs: [],
|
|
258
258
|
response: null,
|
|
259
|
-
respondable: false
|
|
259
|
+
respondable: false,
|
|
260
|
+
approvalStatements: [],
|
|
261
|
+
proofAccess: 'open',
|
|
262
|
+
proofAccessMessage: null,
|
|
263
|
+
messages: []
|
|
260
264
|
};
|
|
261
265
|
}
|
|
262
266
|
/*==========================================
|