@aglyn/plugins-commerce 1.11.0 → 1.13.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/package.json +13 -13
- package/src/lib/components/console/catalog-organization-card.component.js +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/host-quotes-card.component.js +23 -13
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -1
- package/src/lib/components/console/pos-devices-card.component.js +2 -2
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
- package/src/lib/components/console/pos-kiosk/kiosk-menu.d.ts +10 -3
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js +29 -8
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js.map +1 -1
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js +7 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js.map +1 -1
- package/src/lib/components/console/pos-kiosk-page.component.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk-page.component.js +54 -3
- package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js.map +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +0 -2
- package/src/lib/components/console/product-add-ons-fields.component.js +1 -6
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +7 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +129 -32
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +4 -1
- package/src/lib/components/console/quote-pay-link.component.js +23 -12
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.d.ts +3 -2
- package/src/lib/components/console/quote-proofs.component.js +73 -5
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.js +9 -6
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/console/site-member-purchases.component.js +1 -1
- package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
- package/src/lib/components/product-detail.js +1 -1
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +5 -3
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-reviews.js +17 -12
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/quote-page-body.js +14 -8
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/related-products.js +2 -1
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +1 -1
- package/src/lib/model/commerce-invoices.js +4 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-kiosk-search.d.ts +22 -0
- package/src/lib/model/commerce-kiosk-search.js +32 -0
- package/src/lib/model/commerce-kiosk-search.js.map +1 -0
- package/src/lib/model/commerce-pos-kiosk.d.ts +7 -1
- package/src/lib/model/commerce-pos-kiosk.js +1 -1
- package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
- package/src/lib/model/commerce-quote-email.d.ts +7 -6
- package/src/lib/model/commerce-quote-email.js +11 -6
- package/src/lib/model/commerce-quote-email.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +6 -1
- package/src/lib/model/commerce-quote-pay.js +18 -8
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +28 -1
- package/src/lib/model/commerce-quote-proofs.js +58 -2
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +22 -1
- package/src/lib/model/commerce-quotes.js +25 -5
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/plugin-permissions.d.ts +1 -1
- package/src/lib/model/plugin-permissions.js +10 -0
- package/src/lib/model/plugin-permissions.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +4 -0
- package/src/lib/model/product-modifiers.js +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/commerce-pdf.d.ts +1 -1
- package/src/lib/server/commerce-pdf.js +1 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/paid-media-delivery.js +1 -1
- package/src/lib/server/paid-media-delivery.js.map +1 -1
- package/src/lib/server/pos-kiosk.js +70 -15
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/quote-email.js +29 -25
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.js +6 -2
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proof-media.d.ts +63 -0
- package/src/lib/server/quote-proof-media.js +96 -0
- package/src/lib/server/quote-proof-media.js.map +1 -0
- package/src/lib/server/quote-proofs.js +17 -8
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote-uploads.d.ts +3 -1
- package/src/lib/server/quote-uploads.js +2 -1
- package/src/lib/server/quote-uploads.js.map +1 -1
- package/src/lib/server/quote.d.ts +3 -0
- package/src/lib/server/quote.js +127 -20
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/site-page-enricher.js +5 -1
- package/src/lib/server/site-page-enricher.js.map +1 -1
- package/src/lib/tenant-emails.js +16 -9
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.js +34 -5
- package/src/lib/testing/fake-firestore.js.map +1 -1
- package/src/lib/transfer/gift-cards.server.js +9 -11
- package/src/lib/transfer/gift-cards.server.js.map +1 -1
- package/src/lib/transfer/product-register-cells.d.ts +75 -0
- package/src/lib/transfer/product-register-cells.js +487 -0
- package/src/lib/transfer/product-register-cells.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +12 -0
- package/src/lib/transfer/product-transfer.js +174 -10
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +24 -9
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/commerce-document-pdf.js +12 -9
- package/src/lib/utils/commerce-document-pdf.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +2 -0
- package/src/lib/utils/quote-email-content.js +20 -10
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -276,7 +276,7 @@ const UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it ove
|
|
|
276
276
|
* email's button, which opens the quote's dialog on the Orders page.
|
|
277
277
|
*/ function noticeOf(input) {
|
|
278
278
|
var _response_files, _ref, _response_name, _response_comment, _ref1;
|
|
279
|
-
var _quote_customer, _quote_customer1, _quote_customer2, _order_totals,
|
|
279
|
+
var _quote_customer, _quote_customer1, _quote_customer2, _order_totals, _quote_customer3, _quote_customer4, _quote_customer5, _quote_customer6;
|
|
280
280
|
const { hostId, quoteId, order, response } = input;
|
|
281
281
|
const quote = order.quote;
|
|
282
282
|
const number = CommerceModel.formatQuoteNumber(order, quoteId);
|
|
@@ -284,8 +284,11 @@ const UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it ove
|
|
|
284
284
|
const revision = response.revision;
|
|
285
285
|
const files = (_response_files = response.files) != null ? _response_files : [];
|
|
286
286
|
const approving = response.action === 'approve';
|
|
287
|
+
const proofOnly = CommerceModel.quoteIsProofOnly(order);
|
|
287
288
|
const money = CommerceModel.formatOrderMoney(Number((_ref = (_order_totals = order.totals) == null ? void 0 : _order_totals.totalCents) != null ? _ref : 0), input.currency);
|
|
288
|
-
|
|
289
|
+
// The tax the customer is charged (AGL-4162). The saved total stands whichever
|
|
290
|
+
// basis that is: a basis taken from the store's choice now adds no tax here.
|
|
291
|
+
const total = CommerceModel.quotePayTax(quote, input.store).basis.kind === 'at-payment' ? `${money} before tax` : money;
|
|
289
292
|
const filesSent = `${files.length} file${files.length === 1 ? '' : 's'}`;
|
|
290
293
|
const details = [
|
|
291
294
|
{
|
|
@@ -304,10 +307,13 @@ const UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it ove
|
|
|
304
307
|
label: 'Revision',
|
|
305
308
|
value: String(revision)
|
|
306
309
|
},
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
310
|
+
// A proof only quote has no price to name yet (AGL-4184).
|
|
311
|
+
...proofOnly ? [] : [
|
|
312
|
+
{
|
|
313
|
+
label: 'Total',
|
|
314
|
+
value: total
|
|
315
|
+
}
|
|
316
|
+
],
|
|
311
317
|
...approving ? [
|
|
312
318
|
{
|
|
313
319
|
label: 'Approved as',
|
|
@@ -335,7 +341,7 @@ const UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it ove
|
|
|
335
341
|
label: approving ? 'Proof approved' : 'Changes requested',
|
|
336
342
|
actionLabel: 'View quote',
|
|
337
343
|
title: approving ? `${customer} approved the proof for ${number} on {site}` : `${customer} asked for changes to ${number} on {site}`,
|
|
338
|
-
body: approving ? (quote.requireProofApproval === true ? `Revision ${revision} is approved, so they can pay the quote now. It becomes an order when they do.` : `Revision ${revision} is approved. The quote becomes an order when they pay.`) + ' The approval, with the name, time and address it was given from, is on the quote.' : files.length ? `What they want changed on revision ${revision}, and the ${filesSent} they sent, are on the quote. ` + `Read them, then start revision ${revision + 1} with new proofs and send it.` : `What they want changed on revision ${revision} is on the quote. ` + `Read it, then start revision ${revision + 1} with new proofs and send it.`,
|
|
344
|
+
body: approving ? (proofOnly ? `Revision ${revision} is approved. It has no price yet: add items to the quote when you’re ready, and send it.` : quote.requireProofApproval === true ? `Revision ${revision} is approved, so they can pay the quote now. It becomes an order when they do.` : `Revision ${revision} is approved. The quote becomes an order when they pay.`) + ' The approval, with the name, time and address it was given from, is on the quote.' : files.length ? `What they want changed on revision ${revision}, and the ${filesSent} they sent, are on the quote. ` + `Read them, then start revision ${revision + 1} with new proofs and send it.` : `What they want changed on revision ${revision} is on the quote. ` + `Read it, then start revision ${revision + 1} with new proofs and send it.`,
|
|
339
345
|
link: `/${hostId}/products/orders?quote=${encodeURIComponent(quoteId)}`
|
|
340
346
|
},
|
|
341
347
|
options: _extends({
|
|
@@ -523,7 +529,10 @@ const UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it ove
|
|
|
523
529
|
quoteId,
|
|
524
530
|
order: settled.order,
|
|
525
531
|
response: settled.response,
|
|
526
|
-
currency: String((_store_get = store.get('currency')) != null ? _store_get : 'USD')
|
|
532
|
+
currency: String((_store_get = store.get('currency')) != null ? _store_get : 'USD'),
|
|
533
|
+
store: CommerceModel.payLinkStoreOf({
|
|
534
|
+
tax: store.get('tax')
|
|
535
|
+
})
|
|
527
536
|
});
|
|
528
537
|
void deps.notify(hostId, notice.payload, notice.options);
|
|
529
538
|
return outcome;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/quote-proofs.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\nimport { claimAttempt, type PluginApiHandler, type PluginApiRequest } from '@aglyn/aglyn/server'\nimport { readClientIp } from '@aglyn/aglyn/app-utils/request-ip'\nimport { VISITOR_UPLOAD_HONEYPOT_FIELD, visitorUploadFileView, visitorUploadFolder } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { notifyHostManagers } from '@aglyn/tenant-data-admin'\nimport * as CommerceModel from '../model'\nimport {\n defaultQuotePayDeps,\n limitedQuoteLink,\n loadLinkedQuote,\n payLinkPageView,\n quoteLinkParams,\n sendQuoteLinkOutcome,\n type QuoteLinkOutcome,\n type QuotePayDeps,\n} from './quote-pay'\nimport { keepSentQuoteUploads, quoteUploadKeyRef, recordPendingQuoteUpload } from './quote-upload-keys'\nimport { quoteUploadCalls, type QuoteUploadCalls } from './quote-uploads'\n\n/*==========================================\n * THE CUSTOMER'S SIDE OF A PROOF (AGL-4096), on the business's site, behind\n * the quote's signed pay link like the page itself:\n *\n * GET /api/commerce/quote-proof?hostId=&q=&t=&file=<proofId>\n * → a proof from any revision, for a link to any version of this quote\n * (a picture inline, anything else as a download) | 404 | 429\n * POST /api/commerce/quote-upload { hostId, q, t, action: 'ticket', file: { name, contentType, size } }\n * → { ticket, upload: { url, fields }, file }\n * POST /api/commerce/quote-upload { hostId, q, t, action: 'finalize', ticket }\n * → { file: { id, name, contentType, size, uploadedAtMs } }\n * POST /api/commerce/quote-respond { hostId, q, t, v, action: 'approve', name }\n * { hostId, q, t, v, action: 'changes', comment, fileIds? }\n * + Idempotency-Key → 200 { view } | 409 { error, reason } | 410 { replaced } | 404 | 400 | 429\n *\n * Every route spends a per-address rate limit on the site BEFORE the token is\n * checked, answers a wrong token exactly as a missing quote, and (but for a\n * proof, which an earlier email still draws) answers a link to an older\n * version as replaced. The uploads are the shared visitor\n * upload (`@aglyn/tenant-data-admin/server/visitor-upload`), scoped to this\n * quote's artwork; the answer names the files by id and the server reads\n * them back from that scope, so nothing else can be attached.\n *\n * `v` is the edit of the quote the page showed, as Pay sends it: an answer to\n * proofs the customer has not seen is refused and the page is shown again.\n *\n * A file goes up before the answer does, so each one is recorded as pending\n * under its quote from its ticket on, and the answer that sends it takes it\n * off; one never sent is deleted a day later (`quote-upload-keys.ts`).\n *=========================================*/\n\n/** Proofs one address may load per site, per ten minutes: every thumbnail of a few visits. */\nexport const QUOTE_PROOF_LOADS_PER_WINDOW = 120\n/** Upload calls (tickets and finalizes) one address may make per site, per ten minutes, before the upload's own limits. */\nexport const QUOTE_UPLOAD_CALLS_PER_WINDOW = 80\n/** Answers one address may send per site, per ten minutes. */\nexport const QUOTE_RESPONSES_PER_WINDOW = 20\n\nexport interface QuoteProofDeps extends QuotePayDeps {\n uploads(): Promise<QuoteUploadCalls>\n notify(...args: Parameters<typeof notifyHostManagers>): Promise<void>\n}\n\nexport function defaultQuoteProofDeps(): QuoteProofDeps {\n return {\n ...defaultQuotePayDeps(),\n uploads: async () => quoteUploadCalls(),\n notify: (...args) => notifyHostManagers(...args),\n }\n}\n\nfunction bodyOf(req: PluginApiRequest): Record<string, unknown> {\n const raw = req.body\n if (typeof raw === 'string') {\n try {\n const parsed = JSON.parse(raw)\n return parsed && typeof parsed === 'object' ? parsed : {}\n } catch {\n return {}\n }\n }\n return raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : {}\n}\n\nfunction headerOf(req: PluginApiRequest, name: string): string {\n const headers = (req.headers ?? {}) as Record<string, unknown>\n const value = headers[name.toLowerCase()] ?? headers[name]\n return String(Array.isArray(value) ? (value[0] ?? '') : (value ?? '')).trim()\n}\n\nconst clientIp = (req: PluginApiRequest): string | null =>\n readClientIp(req.headers as never, { remoteAddress: req.socket?.remoteAddress })\n\nconst reasonRefusal = (status: number, reason: string, error: string): QuoteLinkOutcome => ({\n status,\n body: { error, reason },\n})\n\n/** What a proof route answers: a JSON outcome, or a file to stream. */\nexport type QuoteProofOutcome = QuoteLinkOutcome & { file?: { path: string; name: string; contentType: string } }\n\nconst PROOF_GONE: QuoteProofOutcome = { status: 404, body: { error: 'That proof is no longer on this quote.' } }\n\n/**\n * `GET /api/commerce/quote-proof`: one of the proofs in the quote's history\n * (AGL-4097). An email is a record the customer keeps, so the proof it draws\n * keeps showing after the business starts the next revision or replaces the\n * link: any link signed for this quote, an older version's too, is served the\n * current revision's proofs and every earlier revision's as its snapshot kept\n * them. A proof taken off its revision, another quote's file and a wrong token\n * are not found.\n */\nexport async function handleQuoteProof(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteProofOutcome> {\n if (req.method !== 'GET') return { status: 405, body: { error: 'Method not allowed' } }\n const query = (req.query ?? {}) as Record<string, unknown>\n const { hostId, quoteId, token, complete } = quoteLinkParams(query)\n const fileId = String(query['file'] ?? '').slice(0, 200)\n if (!complete || !fileId) return { status: 400, body: { error: 'This link is incomplete.' } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-proof:${hostId}`, QUOTE_PROOF_LOADS_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token, { history: true })\n if ('outcome' in linked) return linked.outcome\n const quote = linked.loaded.order.quote\n // The earlier revisions are read only when the current one lacks the proof.\n let proof = CommerceModel.quoteProofInHistory(quote, [], fileId)\n if (!proof) {\n const listed = await linked.loaded.hostRef.collection('orders').doc(quoteId).collection('revisions').get()\n const snapshots = listed.docs.map((entry) => entry.data() as Partial<CommerceModel.QuoteRevisionSnapshot>)\n proof = CommerceModel.quoteProofInHistory(quote, snapshots, fileId)\n }\n // A proof is kept under this quote's own folder; a path anywhere else is never served.\n const folder = visitorUploadFolder({ hostId, purpose: CommerceModel.QUOTE_PROOF_PURPOSE, purposeId: quoteId })\n if (!proof?.path || !proof.path.startsWith(folder)) return PROOF_GONE\n return { status: 200, body: {}, file: { path: proof.path, name: proof.name, contentType: proof.contentType } }\n}\n\n/** `POST /api/commerce/quote-upload`: a ticket for one of the customer's files, or its finalize. */\nexport async function handleQuoteUpload(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteLinkOutcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = bodyOf(req)\n const { hostId, quoteId, token, complete } = quoteLinkParams(body)\n if (!complete) return { status: 400, body: { error: 'This link is incomplete.' } }\n // A form a person fills never fills this; a bot that did learns nothing.\n const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD]\n if (typeof honeypot === 'string' && honeypot.trim()) return { status: 200, body: { received: true } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-upload:${hostId}`, QUOTE_UPLOAD_CALLS_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token)\n if ('outcome' in linked) return linked.outcome\n const { order, storeName } = linked.loaded\n // Artwork rides an answer; a quote that cannot be answered takes none.\n const refused = CommerceModel.quoteRespondRefusal(order)\n if (refused) return reasonRefusal(409, refused, CommerceModel.quoteRespondRefusalMessage(refused, storeName))\n\n const scope = { hostId, purpose: CommerceModel.QUOTE_ARTWORK_PURPOSE, purposeId: quoteId }\n const caller = { ip: clientIp(req) ?? 'no-address' }\n const uploads = await deps.uploads()\n if (body['action'] === 'ticket') {\n const minted = await uploads.mint({ scope, request: body['file'], caller })\n if ('error' in minted) {\n return {\n status: minted.status,\n body: { error: minted.error, code: minted.code },\n ...(minted.retryAfterSeconds ? { headers: { 'Retry-After': String(minted.retryAfterSeconds) } } : {}),\n }\n }\n // Pending before a byte can arrive, so a file kept and never sent is always swept.\n await recordPendingQuoteUpload(deps.firestore(), { hostId, quoteId, fileId: minted.file.id, nowMs: deps.now() })\n return { status: 200, body: { ticket: minted.ticket, upload: minted.upload, file: minted.file } }\n }\n if (body['action'] === 'finalize') {\n const kept = await uploads.finalize({ scope, ticket: body['ticket'], caller })\n if ('error' in kept) return { status: kept.status, body: { error: kept.error, code: kept.code } }\n // Its day starts again from the latest file.\n await recordPendingQuoteUpload(deps.firestore(), { hostId, quoteId, fileId: kept.file.id, nowMs: deps.now() })\n return { status: 200, body: { file: visitorUploadFileView(kept.file) } }\n }\n return { status: 400, body: { error: 'Unknown action' } }\n}\n\nconst UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it over again before you answer.'\n\n/**\n * The managers' notice of an answer (AGL-4096): who, which quote and\n * revision, what they said, and what to do next.\n *\n * It rides `content.order`, so whoever is told about orders (in the feed, by\n * email, by push) is told about the quotes that become them, and it names\n * itself as what it is rather than as that type: \"Proof approved\" or\n * \"Changes requested\" where the feed and the email's eyebrow would say \"New\n * order\", the customer and the quote as its heading, and \"View quote\" on the\n * email's button, which opens the quote's dialog on the Orders page.\n */\nfunction noticeOf(input: {\n hostId: string\n quoteId: string\n order: CommerceModel.HostOrder\n response: CommerceModel.QuoteCustomerResponse\n currency: string\n}) {\n const { hostId, quoteId, order, response } = input\n const quote = order.quote as CommerceModel.OrderQuote\n const number = CommerceModel.formatQuoteNumber(order, quoteId)\n const customer = quote.customer?.name || quote.customer?.company || quote.customer?.email || 'The customer'\n const revision = response.revision\n const files = response.files ?? []\n const approving = response.action === 'approve'\n const money = CommerceModel.formatOrderMoney(Number(order.totals?.totalCents ?? 0), input.currency)\n const total = quote.tax?.kind === 'at-payment' ? `${money} before tax` : money\n const filesSent = `${files.length} file${files.length === 1 ? '' : 's'}`\n const details = [\n { label: 'Quote', value: number },\n { label: 'Customer', value: [quote.customer?.name, quote.customer?.company, quote.customer?.email].filter(Boolean).join(', ') },\n { label: 'Revision', value: String(revision) },\n { label: 'Total', value: total },\n ...(approving\n ? [{ label: 'Approved as', value: response.name ?? '' }]\n : [\n { label: 'What to change', value: response.comment ?? '' },\n ...(files.length ? [{ label: 'Files sent', value: files.map((file) => file.name).join(', ') }] : []),\n ]),\n ]\n const email = String(quote.customer?.email ?? '').trim()\n return {\n payload: {\n type: 'content.order' as const,\n // Good news for an approval; a change request is work to read.\n level: approving ? ('success' as const) : ('info' as const),\n label: approving ? 'Proof approved' : 'Changes requested',\n actionLabel: 'View quote',\n title: approving\n ? `${customer} approved the proof for ${number} on {site}`\n : `${customer} asked for changes to ${number} on {site}`,\n body: approving\n ? (quote.requireProofApproval === true\n ? `Revision ${revision} is approved, so they can pay the quote now. It becomes an order when they do.`\n : `Revision ${revision} is approved. The quote becomes an order when they pay.`) +\n ' The approval, with the name, time and address it was given from, is on the quote.'\n : files.length\n ? `What they want changed on revision ${revision}, and the ${filesSent} they sent, are on the quote. ` +\n `Read them, then start revision ${revision + 1} with new proofs and send it.`\n : `What they want changed on revision ${revision} is on the quote. ` +\n `Read it, then start revision ${revision + 1} with new proofs and send it.`,\n link: `/${hostId}/products/orders?quote=${encodeURIComponent(quoteId)}`,\n },\n options: {\n emailDetails: details,\n ...(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email) ? { replyTo: email } : {}),\n },\n }\n}\n\n/** `POST /api/commerce/quote-respond`: the customer approves the proof or asks for changes. */\nexport async function handleQuoteRespond(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteLinkOutcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = bodyOf(req)\n const { hostId, quoteId, token, complete } = quoteLinkParams(body)\n if (!complete) return { status: 400, body: { error: 'This link is incomplete.' } }\n const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD]\n if (typeof honeypot === 'string' && honeypot.trim()) return { status: 200, body: { received: true } }\n const idempotencyKey = headerOf(req, 'idempotency-key').slice(0, 200)\n if (!idempotencyKey) return { status: 400, body: { error: 'An answer needs an Idempotency-Key header.' } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-respond:${hostId}`, QUOTE_RESPONSES_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token)\n if ('outcome' in linked) return linked.outcome\n const { hostRef, host, order, storeName, store } = linked.loaded\n\n // Everything the customer can be refused is decided before the claim, so\n // none of it spends the attempt.\n const seen = Number(body['v'])\n const version = Number(order.quote?.updatedAtMs) || 0\n if (!Number.isFinite(seen) || seen !== version) return reasonRefusal(409, 'updated', UPDATED_MESSAGE)\n const parsed = CommerceModel.parseQuoteResponseInput(body)\n if ('error' in parsed) return { status: 400, body: { error: parsed.error } }\n const refused = CommerceModel.quoteRespondRefusal(order)\n if (refused) return reasonRefusal(409, refused, CommerceModel.quoteRespondRefusalMessage(refused, storeName))\n\n // The files are read back from this quote's artwork, by id: nothing the\n // browser says about a file is believed, and no other record's file can\n // be named.\n let files: CommerceModel.QuoteResponseFile[] = []\n if (parsed.input.action === 'changes' && parsed.input.fileIds.length) {\n const uploads = await deps.uploads()\n const scope = { hostId, purpose: CommerceModel.QUOTE_ARTWORK_PURPOSE, purposeId: quoteId }\n const read = await Promise.all(parsed.input.fileIds.map((id) => uploads.read(scope, id)))\n if (read.some((file) => !file)) {\n return { status: 400, body: { error: 'One of your files did not finish sending. Send it again.' } }\n }\n files = read.map((file) => ({\n id: file!.id,\n name: file!.name,\n contentType: file!.contentType,\n size: file!.size,\n path: file!.path,\n }))\n }\n\n const claimed = await claimAttempt(deps.firestore(), {\n kind: 'commerce-quote-respond',\n scopeId: `${hostId}:${quoteId}`,\n orgId: '',\n key: idempotencyKey,\n busyMessage: 'Your answer is already being sent',\n })\n if ('replay' in claimed) {\n return { status: claimed.replay.status, body: claimed.replay.body as Record<string, unknown> }\n }\n const claim = claimed.claim\n const now = deps.now()\n try {\n const ref = hostRef.collection('orders').doc(quoteId)\n const pendingRef = quoteUploadKeyRef(deps.firestore(), hostId, quoteId)\n const settled = await deps.firestore().runTransaction(\n async (transaction): Promise<{ outcome: QuoteLinkOutcome; order?: CommerceModel.HostOrder; response?: CommerceModel.QuoteCustomerResponse }> => {\n const snapshot = await transaction.get(ref)\n // The files this answer sends leave the pending record with it.\n const pending = files.length ? await transaction.get(pendingRef) : null\n const current = snapshot.exists ? (snapshot.data() as CommerceModel.HostOrder) : null\n if (!current || !CommerceModel.isQuote(current) || !current.quote) {\n return { outcome: { status: 404, body: { error: 'We could not find that quote. Check the link you were sent.' } } }\n }\n if (CommerceModel.quoteLinkVersion(current.quote) !== CommerceModel.quoteLinkVersion(order.quote)) {\n return {\n outcome: {\n status: 410,\n body: { replaced: true, error: `This quote was updated, and ${storeName || 'the business'} sent you a newer link.` },\n },\n }\n }\n if ((Number(current.quote.updatedAtMs) || 0) !== version) {\n return { outcome: reasonRefusal(409, 'updated', UPDATED_MESSAGE) }\n }\n const answered = CommerceModel.applyQuoteResponse(\n current,\n { ...parsed.input, ...(files.length ? { files } : {}) },\n { atMs: now, ip: clientIp(req), userAgent: headerOf(req, 'user-agent') || null },\n )\n if ('reason' in answered) {\n return {\n outcome: reasonRefusal(409, answered.reason, CommerceModel.quoteRespondRefusalMessage(answered.reason, storeName)),\n }\n }\n transaction.set(ref, answered.order)\n if (pending) keepSentQuoteUploads(transaction, pending, pendingRef, files.map((file) => file.id))\n return { outcome: { status: 200, body: {} }, order: answered.order, response: answered.response }\n },\n )\n if (!settled.order || !settled.response) {\n await claim.release()\n return settled.outcome\n }\n // The page's own view, so an approval brings Pay back only where Pay would work.\n const view = await payLinkPageView(deps, {\n hostId,\n orderId: quoteId,\n loaded: { host, order: settled.order, storeName, store, kind: 'quote' },\n })\n const outcome = { status: 200, body: { view } as Record<string, unknown> }\n await claim.record(200, outcome.body)\n const notice = noticeOf({\n hostId,\n quoteId,\n order: settled.order,\n response: settled.response,\n currency: String(store.get('currency') ?? 'USD'),\n })\n void deps.notify(hostId, notice.payload, notice.options)\n return outcome\n } catch (error) {\n console.error('quote respond failed', error)\n await claim.release()\n return { status: 500, body: { error: 'Your answer could not be sent. Try again.' } }\n }\n}\n\n/** `GET /api/commerce/quote-proof`. */\nexport const quoteProofHandler: PluginApiHandler = async (req, res) => {\n const deps = defaultQuoteProofDeps()\n try {\n const outcome = await handleQuoteProof(deps, req)\n if (!outcome.file) return sendQuoteLinkOutcome(res, outcome)\n const uploads = await deps.uploads()\n return await uploads.send(res as never, outcome.file)\n } catch (error) {\n console.error('quote proof failed', error)\n return sendQuoteLinkOutcome(res, { status: 500, body: { error: 'This proof could not be loaded. Try again.' } })\n }\n}\n\n/** `POST /api/commerce/quote-upload`. */\nexport const quoteUploadHandler: PluginApiHandler = async (req, res) => {\n try {\n return sendQuoteLinkOutcome(res, await handleQuoteUpload(defaultQuoteProofDeps(), req))\n } catch (error) {\n console.error('quote upload failed', error)\n return sendQuoteLinkOutcome(res, { status: 500, body: { error: 'The file could not be sent. Try again.' } })\n }\n}\n\n/** `POST /api/commerce/quote-respond`. */\nexport const quoteRespondHandler: PluginApiHandler = async (req, res) =>\n sendQuoteLinkOutcome(res, await handleQuoteRespond(defaultQuoteProofDeps(), req))\n"],"names":["claimAttempt","readClientIp","VISITOR_UPLOAD_HONEYPOT_FIELD","visitorUploadFileView","visitorUploadFolder","notifyHostManagers","CommerceModel","defaultQuotePayDeps","limitedQuoteLink","loadLinkedQuote","payLinkPageView","quoteLinkParams","sendQuoteLinkOutcome","keepSentQuoteUploads","quoteUploadKeyRef","recordPendingQuoteUpload","quoteUploadCalls","QUOTE_PROOF_LOADS_PER_WINDOW","QUOTE_UPLOAD_CALLS_PER_WINDOW","QUOTE_RESPONSES_PER_WINDOW","defaultQuoteProofDeps","uploads","notify","args","bodyOf","req","raw","body","parsed","JSON","parse","headerOf","name","headers","value","toLowerCase","String","Array","isArray","trim","clientIp","remoteAddress","socket","reasonRefusal","status","reason","error","PROOF_GONE","handleQuoteProof","deps","query","method","hostId","quoteId","token","complete","fileId","slice","limited","linked","history","outcome","quote","loaded","order","proof","quoteProofInHistory","listed","hostRef","collection","doc","get","snapshots","docs","map","entry","data","folder","purpose","QUOTE_PROOF_PURPOSE","purposeId","path","startsWith","file","contentType","handleQuoteUpload","honeypot","received","storeName","refused","quoteRespondRefusal","quoteRespondRefusalMessage","scope","QUOTE_ARTWORK_PURPOSE","caller","ip","minted","mint","request","code","retryAfterSeconds","firestore","id","nowMs","now","ticket","upload","kept","finalize","UPDATED_MESSAGE","noticeOf","input","response","number","formatQuoteNumber","customer","company","email","revision","files","approving","action","money","formatOrderMoney","Number","totals","totalCents","currency","total","tax","kind","filesSent","length","details","label","filter","Boolean","join","comment","payload","type","level","actionLabel","title","requireProofApproval","link","encodeURIComponent","options","emailDetails","test","replyTo","handleQuoteRespond","idempotencyKey","host","store","seen","version","updatedAtMs","isFinite","parseQuoteResponseInput","fileIds","read","Promise","all","some","size","claimed","scopeId","orgId","key","busyMessage","replay","claim","ref","pendingRef","settled","runTransaction","transaction","snapshot","pending","current","exists","isQuote","quoteLinkVersion","replaced","answered","applyQuoteResponse","atMs","userAgent","set","release","view","orderId","record","notice","console","quoteProofHandler","res","send","quoteUploadHandler","quoteRespondHandler"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,YAAY,QAAsD,sBAAqB;AAChG,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,6BAA6B,EAAEC,qBAAqB,EAAEC,mBAAmB,QAAQ,wCAAuC;AACjI,SAASC,kBAAkB,QAAQ,2BAA0B;AAC7D,YAAYC,mBAAmB,oBAAU;AACzC,SACEC,mBAAmB,EACnBC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,oBAAoB,QAGf,iBAAa;AACpB,SAASC,oBAAoB,EAAEC,iBAAiB,EAAEC,wBAAwB,QAAQ,yBAAqB;AACvG,SAASC,gBAAgB,QAA+B,qBAAiB;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA6B2C,GAE3C,4FAA4F,GAC5F,OAAO,MAAMC,+BAA+B,IAAG;AAC/C,yHAAyH,GACzH,OAAO,MAAMC,gCAAgC,GAAE;AAC/C,4DAA4D,GAC5D,OAAO,MAAMC,6BAA6B,GAAE;AAO5C,OAAO,SAASC;IACd,OAAO,aACFb;QACHc,SAAS,UAAYL;QACrBM,QAAQ,CAAC,GAAGC,OAASlB,sBAAsBkB;;AAE/C;AAEA,SAASC,OAAOC,GAAqB;IACnC,MAAMC,MAAMD,IAAIE,IAAI;IACpB,IAAI,OAAOD,QAAQ,UAAU;QAC3B,IAAI;YACF,MAAME,SAASC,KAAKC,KAAK,CAACJ;YAC1B,OAAOE,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ACpC,OAAOlC,qBAAqByL,KAAK;YAAEzJ,QAAQ;YAAKjB,MAAM;gBAAEmB,OAAO;YAA6C;QAAE;IAChH;AACF,EAAC;AAED,uCAAuC,GACvC,OAAO,MAAMyJ,qBAAuC,OAAO9K,KAAK4K;IAC9D,IAAI;QACF,OAAOzL,qBAAqByL,KAAK,MAAMhH,kBAAkBjE,yBAAyBK;IACpF,EAAE,OAAOqB,OAAO;QACdqJ,QAAQrJ,KAAK,CAAC,uBAAuBA;QACrC,OAAOlC,qBAAqByL,KAAK;YAAEzJ,QAAQ;YAAKjB,MAAM;gBAAEmB,OAAO;YAAyC;QAAE;IAC5G;AACF,EAAC;AAED,wCAAwC,GACxC,OAAO,MAAM0J,sBAAwC,OAAO/K,KAAK4K,MAC/DzL,qBAAqByL,KAAK,MAAM9C,mBAAmBnI,yBAAyBK,MAAK"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/quote-proofs.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\nimport { claimAttempt, type PluginApiHandler, type PluginApiRequest } from '@aglyn/aglyn/server'\nimport { readClientIp } from '@aglyn/aglyn/app-utils/request-ip'\nimport { VISITOR_UPLOAD_HONEYPOT_FIELD, visitorUploadFileView, visitorUploadFolder } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { notifyHostManagers } from '@aglyn/tenant-data-admin'\nimport * as CommerceModel from '../model'\nimport {\n defaultQuotePayDeps,\n limitedQuoteLink,\n loadLinkedQuote,\n payLinkPageView,\n quoteLinkParams,\n sendQuoteLinkOutcome,\n type QuoteLinkOutcome,\n type QuotePayDeps,\n} from './quote-pay'\nimport { keepSentQuoteUploads, quoteUploadKeyRef, recordPendingQuoteUpload } from './quote-upload-keys'\nimport { quoteUploadCalls, type QuoteUploadCalls } from './quote-uploads'\n\n/*==========================================\n * THE CUSTOMER'S SIDE OF A PROOF (AGL-4096), on the business's site, behind\n * the quote's signed pay link like the page itself:\n *\n * GET /api/commerce/quote-proof?hostId=&q=&t=&file=<proofId>\n * → a proof from any revision, for a link to any version of this quote\n * (a picture inline, anything else as a download) | 404 | 429\n * POST /api/commerce/quote-upload { hostId, q, t, action: 'ticket', file: { name, contentType, size } }\n * → { ticket, upload: { url, fields }, file }\n * POST /api/commerce/quote-upload { hostId, q, t, action: 'finalize', ticket }\n * → { file: { id, name, contentType, size, uploadedAtMs } }\n * POST /api/commerce/quote-respond { hostId, q, t, v, action: 'approve', name }\n * { hostId, q, t, v, action: 'changes', comment, fileIds? }\n * + Idempotency-Key → 200 { view } | 409 { error, reason } | 410 { replaced } | 404 | 400 | 429\n *\n * Every route spends a per-address rate limit on the site BEFORE the token is\n * checked, answers a wrong token exactly as a missing quote, and (but for a\n * proof, which an earlier email still draws) answers a link to an older\n * version as replaced. The uploads are the shared visitor\n * upload (`@aglyn/tenant-data-admin/server/visitor-upload`), scoped to this\n * quote's artwork; the answer names the files by id and the server reads\n * them back from that scope, so nothing else can be attached.\n *\n * `v` is the edit of the quote the page showed, as Pay sends it: an answer to\n * proofs the customer has not seen is refused and the page is shown again.\n *\n * A file goes up before the answer does, so each one is recorded as pending\n * under its quote from its ticket on, and the answer that sends it takes it\n * off; one never sent is deleted a day later (`quote-upload-keys.ts`).\n *=========================================*/\n\n/** Proofs one address may load per site, per ten minutes: every thumbnail of a few visits. */\nexport const QUOTE_PROOF_LOADS_PER_WINDOW = 120\n/** Upload calls (tickets and finalizes) one address may make per site, per ten minutes, before the upload's own limits. */\nexport const QUOTE_UPLOAD_CALLS_PER_WINDOW = 80\n/** Answers one address may send per site, per ten minutes. */\nexport const QUOTE_RESPONSES_PER_WINDOW = 20\n\nexport interface QuoteProofDeps extends QuotePayDeps {\n uploads(): Promise<QuoteUploadCalls>\n notify(...args: Parameters<typeof notifyHostManagers>): Promise<void>\n}\n\nexport function defaultQuoteProofDeps(): QuoteProofDeps {\n return {\n ...defaultQuotePayDeps(),\n uploads: async () => quoteUploadCalls(),\n notify: (...args) => notifyHostManagers(...args),\n }\n}\n\nfunction bodyOf(req: PluginApiRequest): Record<string, unknown> {\n const raw = req.body\n if (typeof raw === 'string') {\n try {\n const parsed = JSON.parse(raw)\n return parsed && typeof parsed === 'object' ? parsed : {}\n } catch {\n return {}\n }\n }\n return raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : {}\n}\n\nfunction headerOf(req: PluginApiRequest, name: string): string {\n const headers = (req.headers ?? {}) as Record<string, unknown>\n const value = headers[name.toLowerCase()] ?? headers[name]\n return String(Array.isArray(value) ? (value[0] ?? '') : (value ?? '')).trim()\n}\n\nconst clientIp = (req: PluginApiRequest): string | null =>\n readClientIp(req.headers as never, { remoteAddress: req.socket?.remoteAddress })\n\nconst reasonRefusal = (status: number, reason: string, error: string): QuoteLinkOutcome => ({\n status,\n body: { error, reason },\n})\n\n/** What a proof route answers: a JSON outcome, or a file to stream. */\nexport type QuoteProofOutcome = QuoteLinkOutcome & { file?: { path: string; name: string; contentType: string } }\n\nconst PROOF_GONE: QuoteProofOutcome = { status: 404, body: { error: 'That proof is no longer on this quote.' } }\n\n/**\n * `GET /api/commerce/quote-proof`: one of the proofs in the quote's history\n * (AGL-4097). An email is a record the customer keeps, so the proof it draws\n * keeps showing after the business starts the next revision or replaces the\n * link: any link signed for this quote, an older version's too, is served the\n * current revision's proofs and every earlier revision's as its snapshot kept\n * them. A proof taken off its revision, another quote's file and a wrong token\n * are not found.\n */\nexport async function handleQuoteProof(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteProofOutcome> {\n if (req.method !== 'GET') return { status: 405, body: { error: 'Method not allowed' } }\n const query = (req.query ?? {}) as Record<string, unknown>\n const { hostId, quoteId, token, complete } = quoteLinkParams(query)\n const fileId = String(query['file'] ?? '').slice(0, 200)\n if (!complete || !fileId) return { status: 400, body: { error: 'This link is incomplete.' } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-proof:${hostId}`, QUOTE_PROOF_LOADS_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token, { history: true })\n if ('outcome' in linked) return linked.outcome\n const quote = linked.loaded.order.quote\n // The earlier revisions are read only when the current one lacks the proof.\n let proof = CommerceModel.quoteProofInHistory(quote, [], fileId)\n if (!proof) {\n const listed = await linked.loaded.hostRef.collection('orders').doc(quoteId).collection('revisions').get()\n const snapshots = listed.docs.map((entry) => entry.data() as Partial<CommerceModel.QuoteRevisionSnapshot>)\n proof = CommerceModel.quoteProofInHistory(quote, snapshots, fileId)\n }\n // A proof is kept under this quote's own folder; a path anywhere else is never served.\n const folder = visitorUploadFolder({ hostId, purpose: CommerceModel.QUOTE_PROOF_PURPOSE, purposeId: quoteId })\n if (!proof?.path || !proof.path.startsWith(folder)) return PROOF_GONE\n return { status: 200, body: {}, file: { path: proof.path, name: proof.name, contentType: proof.contentType } }\n}\n\n/** `POST /api/commerce/quote-upload`: a ticket for one of the customer's files, or its finalize. */\nexport async function handleQuoteUpload(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteLinkOutcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = bodyOf(req)\n const { hostId, quoteId, token, complete } = quoteLinkParams(body)\n if (!complete) return { status: 400, body: { error: 'This link is incomplete.' } }\n // A form a person fills never fills this; a bot that did learns nothing.\n const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD]\n if (typeof honeypot === 'string' && honeypot.trim()) return { status: 200, body: { received: true } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-upload:${hostId}`, QUOTE_UPLOAD_CALLS_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token)\n if ('outcome' in linked) return linked.outcome\n const { order, storeName } = linked.loaded\n // Artwork rides an answer; a quote that cannot be answered takes none.\n const refused = CommerceModel.quoteRespondRefusal(order)\n if (refused) return reasonRefusal(409, refused, CommerceModel.quoteRespondRefusalMessage(refused, storeName))\n\n const scope = { hostId, purpose: CommerceModel.QUOTE_ARTWORK_PURPOSE, purposeId: quoteId }\n const caller = { ip: clientIp(req) ?? 'no-address' }\n const uploads = await deps.uploads()\n if (body['action'] === 'ticket') {\n const minted = await uploads.mint({ scope, request: body['file'], caller })\n if ('error' in minted) {\n return {\n status: minted.status,\n body: { error: minted.error, code: minted.code },\n ...(minted.retryAfterSeconds ? { headers: { 'Retry-After': String(minted.retryAfterSeconds) } } : {}),\n }\n }\n // Pending before a byte can arrive, so a file kept and never sent is always swept.\n await recordPendingQuoteUpload(deps.firestore(), { hostId, quoteId, fileId: minted.file.id, nowMs: deps.now() })\n return { status: 200, body: { ticket: minted.ticket, upload: minted.upload, file: minted.file } }\n }\n if (body['action'] === 'finalize') {\n const kept = await uploads.finalize({ scope, ticket: body['ticket'], caller })\n if ('error' in kept) return { status: kept.status, body: { error: kept.error, code: kept.code } }\n // Its day starts again from the latest file.\n await recordPendingQuoteUpload(deps.firestore(), { hostId, quoteId, fileId: kept.file.id, nowMs: deps.now() })\n return { status: 200, body: { file: visitorUploadFileView(kept.file) } }\n }\n return { status: 400, body: { error: 'Unknown action' } }\n}\n\nconst UPDATED_MESSAGE = 'This quote was updated since you opened it. Look it over again before you answer.'\n\n/**\n * The managers' notice of an answer (AGL-4096): who, which quote and\n * revision, what they said, and what to do next.\n *\n * It rides `content.order`, so whoever is told about orders (in the feed, by\n * email, by push) is told about the quotes that become them, and it names\n * itself as what it is rather than as that type: \"Proof approved\" or\n * \"Changes requested\" where the feed and the email's eyebrow would say \"New\n * order\", the customer and the quote as its heading, and \"View quote\" on the\n * email's button, which opens the quote's dialog on the Orders page.\n */\nfunction noticeOf(input: {\n hostId: string\n quoteId: string\n order: CommerceModel.HostOrder\n response: CommerceModel.QuoteCustomerResponse\n currency: string\n /** The store's sales tax choice, which a quote saved before it was made takes. */\n store: CommerceModel.PayLinkStore\n}) {\n const { hostId, quoteId, order, response } = input\n const quote = order.quote as CommerceModel.OrderQuote\n const number = CommerceModel.formatQuoteNumber(order, quoteId)\n const customer = quote.customer?.name || quote.customer?.company || quote.customer?.email || 'The customer'\n const revision = response.revision\n const files = response.files ?? []\n const approving = response.action === 'approve'\n const proofOnly = CommerceModel.quoteIsProofOnly(order)\n const money = CommerceModel.formatOrderMoney(Number(order.totals?.totalCents ?? 0), input.currency)\n // The tax the customer is charged (AGL-4162). The saved total stands whichever\n // basis that is: a basis taken from the store's choice now adds no tax here.\n const total = CommerceModel.quotePayTax(quote, input.store).basis.kind === 'at-payment' ? `${money} before tax` : money\n const filesSent = `${files.length} file${files.length === 1 ? '' : 's'}`\n const details = [\n { label: 'Quote', value: number },\n { label: 'Customer', value: [quote.customer?.name, quote.customer?.company, quote.customer?.email].filter(Boolean).join(', ') },\n { label: 'Revision', value: String(revision) },\n // A proof only quote has no price to name yet (AGL-4184).\n ...(proofOnly ? [] : [{ label: 'Total', value: total }]),\n ...(approving\n ? [{ label: 'Approved as', value: response.name ?? '' }]\n : [\n { label: 'What to change', value: response.comment ?? '' },\n ...(files.length ? [{ label: 'Files sent', value: files.map((file) => file.name).join(', ') }] : []),\n ]),\n ]\n const email = String(quote.customer?.email ?? '').trim()\n return {\n payload: {\n type: 'content.order' as const,\n // Good news for an approval; a change request is work to read.\n level: approving ? ('success' as const) : ('info' as const),\n label: approving ? 'Proof approved' : 'Changes requested',\n actionLabel: 'View quote',\n title: approving\n ? `${customer} approved the proof for ${number} on {site}`\n : `${customer} asked for changes to ${number} on {site}`,\n body: approving\n ? (proofOnly\n ? `Revision ${revision} is approved. It has no price yet: add items to the quote when you’re ready, and send it.`\n : quote.requireProofApproval === true\n ? `Revision ${revision} is approved, so they can pay the quote now. It becomes an order when they do.`\n : `Revision ${revision} is approved. The quote becomes an order when they pay.`) +\n ' The approval, with the name, time and address it was given from, is on the quote.'\n : files.length\n ? `What they want changed on revision ${revision}, and the ${filesSent} they sent, are on the quote. ` +\n `Read them, then start revision ${revision + 1} with new proofs and send it.`\n : `What they want changed on revision ${revision} is on the quote. ` +\n `Read it, then start revision ${revision + 1} with new proofs and send it.`,\n link: `/${hostId}/products/orders?quote=${encodeURIComponent(quoteId)}`,\n },\n options: {\n emailDetails: details,\n ...(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email) ? { replyTo: email } : {}),\n },\n }\n}\n\n/** `POST /api/commerce/quote-respond`: the customer approves the proof or asks for changes. */\nexport async function handleQuoteRespond(deps: QuoteProofDeps, req: PluginApiRequest): Promise<QuoteLinkOutcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = bodyOf(req)\n const { hostId, quoteId, token, complete } = quoteLinkParams(body)\n if (!complete) return { status: 400, body: { error: 'This link is incomplete.' } }\n const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD]\n if (typeof honeypot === 'string' && honeypot.trim()) return { status: 200, body: { received: true } }\n const idempotencyKey = headerOf(req, 'idempotency-key').slice(0, 200)\n if (!idempotencyKey) return { status: 400, body: { error: 'An answer needs an Idempotency-Key header.' } }\n const limited = await limitedQuoteLink(deps, req, `commerce-quote-respond:${hostId}`, QUOTE_RESPONSES_PER_WINDOW)\n if (limited) return limited\n const linked = await loadLinkedQuote(deps, hostId, quoteId, token)\n if ('outcome' in linked) return linked.outcome\n const { hostRef, host, order, storeName, store } = linked.loaded\n\n // Everything the customer can be refused is decided before the claim, so\n // none of it spends the attempt.\n const seen = Number(body['v'])\n const version = Number(order.quote?.updatedAtMs) || 0\n if (!Number.isFinite(seen) || seen !== version) return reasonRefusal(409, 'updated', UPDATED_MESSAGE)\n const parsed = CommerceModel.parseQuoteResponseInput(body)\n if ('error' in parsed) return { status: 400, body: { error: parsed.error } }\n const refused = CommerceModel.quoteRespondRefusal(order)\n if (refused) return reasonRefusal(409, refused, CommerceModel.quoteRespondRefusalMessage(refused, storeName))\n\n // The files are read back from this quote's artwork, by id: nothing the\n // browser says about a file is believed, and no other record's file can\n // be named.\n let files: CommerceModel.QuoteResponseFile[] = []\n if (parsed.input.action === 'changes' && parsed.input.fileIds.length) {\n const uploads = await deps.uploads()\n const scope = { hostId, purpose: CommerceModel.QUOTE_ARTWORK_PURPOSE, purposeId: quoteId }\n const read = await Promise.all(parsed.input.fileIds.map((id) => uploads.read(scope, id)))\n if (read.some((file) => !file)) {\n return { status: 400, body: { error: 'One of your files did not finish sending. Send it again.' } }\n }\n files = read.map((file) => ({\n id: file!.id,\n name: file!.name,\n contentType: file!.contentType,\n size: file!.size,\n path: file!.path,\n }))\n }\n\n const claimed = await claimAttempt(deps.firestore(), {\n kind: 'commerce-quote-respond',\n scopeId: `${hostId}:${quoteId}`,\n orgId: '',\n key: idempotencyKey,\n busyMessage: 'Your answer is already being sent',\n })\n if ('replay' in claimed) {\n return { status: claimed.replay.status, body: claimed.replay.body as Record<string, unknown> }\n }\n const claim = claimed.claim\n const now = deps.now()\n try {\n const ref = hostRef.collection('orders').doc(quoteId)\n const pendingRef = quoteUploadKeyRef(deps.firestore(), hostId, quoteId)\n const settled = await deps.firestore().runTransaction(\n async (transaction): Promise<{ outcome: QuoteLinkOutcome; order?: CommerceModel.HostOrder; response?: CommerceModel.QuoteCustomerResponse }> => {\n const snapshot = await transaction.get(ref)\n // The files this answer sends leave the pending record with it.\n const pending = files.length ? await transaction.get(pendingRef) : null\n const current = snapshot.exists ? (snapshot.data() as CommerceModel.HostOrder) : null\n if (!current || !CommerceModel.isQuote(current) || !current.quote) {\n return { outcome: { status: 404, body: { error: 'We could not find that quote. Check the link you were sent.' } } }\n }\n if (CommerceModel.quoteLinkVersion(current.quote) !== CommerceModel.quoteLinkVersion(order.quote)) {\n return {\n outcome: {\n status: 410,\n body: { replaced: true, error: `This quote was updated, and ${storeName || 'the business'} sent you a newer link.` },\n },\n }\n }\n if ((Number(current.quote.updatedAtMs) || 0) !== version) {\n return { outcome: reasonRefusal(409, 'updated', UPDATED_MESSAGE) }\n }\n const answered = CommerceModel.applyQuoteResponse(\n current,\n { ...parsed.input, ...(files.length ? { files } : {}) },\n { atMs: now, ip: clientIp(req), userAgent: headerOf(req, 'user-agent') || null },\n )\n if ('reason' in answered) {\n return {\n outcome: reasonRefusal(409, answered.reason, CommerceModel.quoteRespondRefusalMessage(answered.reason, storeName)),\n }\n }\n transaction.set(ref, answered.order)\n if (pending) keepSentQuoteUploads(transaction, pending, pendingRef, files.map((file) => file.id))\n return { outcome: { status: 200, body: {} }, order: answered.order, response: answered.response }\n },\n )\n if (!settled.order || !settled.response) {\n await claim.release()\n return settled.outcome\n }\n // The page's own view, so an approval brings Pay back only where Pay would work.\n const view = await payLinkPageView(deps, {\n hostId,\n orderId: quoteId,\n loaded: { host, order: settled.order, storeName, store, kind: 'quote' },\n })\n const outcome = { status: 200, body: { view } as Record<string, unknown> }\n await claim.record(200, outcome.body)\n const notice = noticeOf({\n hostId,\n quoteId,\n order: settled.order,\n response: settled.response,\n currency: String(store.get('currency') ?? 'USD'),\n store: CommerceModel.payLinkStoreOf({ tax: store.get('tax') }),\n })\n void deps.notify(hostId, notice.payload, notice.options)\n return outcome\n } catch (error) {\n console.error('quote respond failed', error)\n await claim.release()\n return { status: 500, body: { error: 'Your answer could not be sent. Try again.' } }\n }\n}\n\n/** `GET /api/commerce/quote-proof`. */\nexport const quoteProofHandler: PluginApiHandler = async (req, res) => {\n const deps = defaultQuoteProofDeps()\n try {\n const outcome = await handleQuoteProof(deps, req)\n if (!outcome.file) return sendQuoteLinkOutcome(res, outcome)\n const uploads = await deps.uploads()\n return await uploads.send(res as never, outcome.file)\n } catch (error) {\n console.error('quote proof failed', error)\n return sendQuoteLinkOutcome(res, { status: 500, body: { error: 'This proof could not be loaded. Try again.' } })\n }\n}\n\n/** `POST /api/commerce/quote-upload`. */\nexport const quoteUploadHandler: PluginApiHandler = async (req, res) => {\n try {\n return sendQuoteLinkOutcome(res, await handleQuoteUpload(defaultQuoteProofDeps(), req))\n } catch (error) {\n console.error('quote upload failed', error)\n return sendQuoteLinkOutcome(res, { status: 500, body: { error: 'The file could not be sent. Try again.' } })\n }\n}\n\n/** `POST /api/commerce/quote-respond`. */\nexport const quoteRespondHandler: PluginApiHandler = async (req, res) =>\n sendQuoteLinkOutcome(res, await handleQuoteRespond(defaultQuoteProofDeps(), req))\n"],"names":["claimAttempt","readClientIp","VISITOR_UPLOAD_HONEYPOT_FIELD","visitorUploadFileView","visitorUploadFolder","notifyHostManagers","CommerceModel","defaultQuotePayDeps","limitedQuoteLink","loadLinkedQuote","payLinkPageView","quoteLinkParams","sendQuoteLinkOutcome","keepSentQuoteUploads","quoteUploadKeyRef","recordPendingQuoteUpload","quoteUploadCalls","QUOTE_PROOF_LOADS_PER_WINDOW","QUOTE_UPLOAD_CALLS_PER_WINDOW","QUOTE_RESPONSES_PER_WINDOW","defaultQuoteProofDeps","uploads","notify","args","bodyOf","req","raw","body","parsed","JSON","parse","headerOf","name","headers","value","toLowerCase","String","Array","isArray","trim","clientIp","remoteAddress","socket","reasonRefusal","status","reason","error","PROOF_GONE","handleQuoteProof","deps","query","method","hostId","quoteId","token","complete","fileId","slice","limited","linked","history","outcome","quote","loaded","order","proof","quoteProofInHistory","listed","hostRef","collection","doc","get","snapshots","docs","map","entry","data","folder","purpose","QUOTE_PROOF_PURPOSE","purposeId","path","startsWith","file","contentType","handleQuoteUpload","honeypot","received","storeName","refused","quoteRespondRefusal","quoteRespondRefusalMessage","scope","QUOTE_ARTWORK_PURPOSE","caller","ip","minted","mint","request","code","retryAfterSeconds","firestore","id","nowMs","now","ticket","upload","kept","finalize","UPDATED_MESSAGE","noticeOf","input","response","number","formatQuoteNumber","customer","company","email","revision","files","approving","action","proofOnly","quoteIsProofOnly","money","formatOrderMoney","Number","totals","totalCents","currency","total","quotePayTax","store","basis","kind","filesSent","length","details","label","filter","Boolean","join","comment","payload","type","level","actionLabel","title","requireProofApproval","link","encodeURIComponent","options","emailDetails","test","replyTo","handleQuoteRespond","idempotencyKey","host","seen","version","updatedAtMs","isFinite","parseQuoteResponseInput","fileIds","read","Promise","all","some","size","claimed","scopeId","orgId","key","busyMessage","replay","claim","ref","pendingRef","settled","runTransaction","transaction","snapshot","pending","current","exists","isQuote","quoteLinkVersion","replaced","answered","applyQuoteResponse","atMs","userAgent","set","release","view","orderId","record","notice","payLinkStoreOf","tax","console","quoteProofHandler","res","send","quoteUploadHandler","quoteRespondHandler"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,YAAY,QAAsD,sBAAqB;AAChG,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,6BAA6B,EAAEC,qBAAqB,EAAEC,mBAAmB,QAAQ,wCAAuC;AACjI,SAASC,kBAAkB,QAAQ,2BAA0B;AAC7D,YAAYC,mBAAmB,oBAAU;AACzC,SACEC,mBAAmB,EACnBC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,oBAAoB,QAGf,iBAAa;AACpB,SAASC,oBAAoB,EAAEC,iBAAiB,EAAEC,wBAAwB,QAAQ,yBAAqB;AACvG,SAASC,gBAAgB,QAA+B,qBAAiB;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA6B2C,GAE3C,4FAA4F,GAC5F,OAAO,MAAMC,+BAA+B,IAAG;AAC/C,yHAAyH,GACzH,OAAO,MAAMC,gCAAgC,GAAE;AAC/C,4DAA4D,GAC5D,OAAO,MAAMC,6BAA6B,GAAE;AAO5C,OAAO,SAASC;IACd,OAAO,aACFb;QACHc,SAAS,UAAYL;QACrBM,QAAQ,CAAC,GAAGC,OAASlB,sBAAsBkB;;AAE/C;AAEA,SAASC,OAAOC,GAAqB;IACnC,MAAMC,MAAMD,IAAIE,IAAI;IACpB,IAAI,OAAOD,QAAQ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AM2J,oBAAsC,OAAOhL,KAAKiL;IAC7D,MAAMzJ,OAAO7B;IACb,IAAI;QACF,MAAMyC,UAAU,MAAMb,iBAAiBC,MAAMxB;QAC7C,IAAI,CAACoC,QAAQsB,IAAI,EAAE,OAAOvE,qBAAqB8L,KAAK7I;QACpD,MAAMxC,UAAU,MAAM4B,KAAK5B,OAAO;QAClC,OAAO,MAAMA,QAAQsL,IAAI,CAACD,KAAc7I,QAAQsB,IAAI;IACtD,EAAE,OAAOrC,OAAO;QACd0J,QAAQ1J,KAAK,CAAC,sBAAsBA;QACpC,OAAOlC,qBAAqB8L,KAAK;YAAE9J,QAAQ;YAAKjB,MAAM;gBAAEmB,OAAO;YAA6C;QAAE;IAChH;AACF,EAAC;AAED,uCAAuC,GACvC,OAAO,MAAM8J,qBAAuC,OAAOnL,KAAKiL;IAC9D,IAAI;QACF,OAAO9L,qBAAqB8L,KAAK,MAAMrH,kBAAkBjE,yBAAyBK;IACpF,EAAE,OAAOqB,OAAO;QACd0J,QAAQ1J,KAAK,CAAC,uBAAuBA;QACrC,OAAOlC,qBAAqB8L,KAAK;YAAE9J,QAAQ;YAAKjB,MAAM;gBAAEmB,OAAO;YAAyC;QAAE;IAC5G;AACF,EAAC;AAED,wCAAwC,GACxC,OAAO,MAAM+J,sBAAwC,OAAOpL,KAAKiL,MAC/D9L,qBAAqB8L,KAAK,MAAM/C,mBAAmBvI,yBAAyBK,MAAK"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import type { VisitorUploadFile, VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload';
|
|
18
|
-
import { finalizeVisitorUpload, mintVisitorUploadTicket, type VisitorUploadResponse } from '@aglyn/tenant-data-admin/server/visitor-upload';
|
|
18
|
+
import { finalizeVisitorUpload, keepVisitorUploadCopy, mintVisitorUploadTicket, type VisitorUploadResponse } from '@aglyn/tenant-data-admin/server/visitor-upload';
|
|
19
19
|
/**
|
|
20
20
|
* The visitor-upload calls a quote's routes make (AGL-4096). The routes reach
|
|
21
21
|
* this module by a dynamic import of it, so the upload pipeline, the bucket
|
|
@@ -25,6 +25,8 @@ import { finalizeVisitorUpload, mintVisitorUploadTicket, type VisitorUploadRespo
|
|
|
25
25
|
export interface QuoteUploadCalls {
|
|
26
26
|
mint(input: Parameters<typeof mintVisitorUploadTicket>[1]): ReturnType<typeof mintVisitorUploadTicket>;
|
|
27
27
|
finalize(input: Parameters<typeof finalizeVisitorUpload>[1]): ReturnType<typeof finalizeVisitorUpload>;
|
|
28
|
+
/** A copy of a file already in Storage, through the same checks an upload meets. */
|
|
29
|
+
keepCopy(input: Parameters<typeof keepVisitorUploadCopy>[1]): ReturnType<typeof keepVisitorUploadCopy>;
|
|
28
30
|
read(scope: VisitorUploadScope, id: string): Promise<VisitorUploadFile | null>;
|
|
29
31
|
remove(path: string): Promise<void>;
|
|
30
32
|
removeAll(scope: VisitorUploadScope): Promise<void>;
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/ import { defaultVisitorUploadDeps, deleteVisitorUpload, deleteVisitorUploads, finalizeVisitorUpload, mintVisitorUploadTicket, readVisitorUpload, sendVisitorUploadFile } from "@aglyn/tenant-data-admin/server/visitor-upload";
|
|
16
|
+
*/ import { defaultVisitorUploadDeps, deleteVisitorUpload, deleteVisitorUploads, finalizeVisitorUpload, keepVisitorUploadCopy, mintVisitorUploadTicket, readVisitorUpload, sendVisitorUploadFile } from "@aglyn/tenant-data-admin/server/visitor-upload";
|
|
17
17
|
export function quoteUploadCalls() {
|
|
18
18
|
const deps = defaultVisitorUploadDeps();
|
|
19
19
|
return {
|
|
20
20
|
mint: (input)=>mintVisitorUploadTicket(deps, input),
|
|
21
21
|
finalize: (input)=>finalizeVisitorUpload(deps, input),
|
|
22
|
+
keepCopy: (input)=>keepVisitorUploadCopy(deps, input),
|
|
22
23
|
read: (scope, id)=>readVisitorUpload(deps, scope, id),
|
|
23
24
|
remove: (path)=>deleteVisitorUpload(deps, path),
|
|
24
25
|
removeAll: (scope)=>deleteVisitorUploads(deps, scope),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/quote-uploads.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\nimport type { VisitorUploadFile, VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport {\n defaultVisitorUploadDeps,\n deleteVisitorUpload,\n deleteVisitorUploads,\n finalizeVisitorUpload,\n mintVisitorUploadTicket,\n readVisitorUpload,\n sendVisitorUploadFile,\n type VisitorUploadResponse,\n} from '@aglyn/tenant-data-admin/server/visitor-upload'\n\n/**\n * The visitor-upload calls a quote's routes make (AGL-4096). The routes reach\n * this module by a dynamic import of it, so the upload pipeline, the bucket\n * and the SVG sanitizer load only when a proof or a customer's artwork is\n * actually sent or served, never with the routes' own modules.\n */\nexport interface QuoteUploadCalls {\n mint(input: Parameters<typeof mintVisitorUploadTicket>[1]): ReturnType<typeof mintVisitorUploadTicket>\n finalize(input: Parameters<typeof finalizeVisitorUpload>[1]): ReturnType<typeof finalizeVisitorUpload>\n read(scope: VisitorUploadScope, id: string): Promise<VisitorUploadFile | null>\n remove(path: string): Promise<void>\n removeAll(scope: VisitorUploadScope): Promise<void>\n send(res: VisitorUploadResponse, file: Pick<VisitorUploadFile, 'path' | 'name' | 'contentType'>): Promise<void>\n}\n\nexport function quoteUploadCalls(): QuoteUploadCalls {\n const deps = defaultVisitorUploadDeps()\n return {\n mint: (input) => mintVisitorUploadTicket(deps, input),\n finalize: (input) => finalizeVisitorUpload(deps, input),\n read: (scope, id) => readVisitorUpload(deps, scope, id),\n remove: (path) => deleteVisitorUpload(deps, path),\n removeAll: (scope) => deleteVisitorUploads(deps, scope),\n send: (res, file) => sendVisitorUploadFile(deps, res, file),\n }\n}\n"],"names":["defaultVisitorUploadDeps","deleteVisitorUpload","deleteVisitorUploads","finalizeVisitorUpload","mintVisitorUploadTicket","readVisitorUpload","sendVisitorUploadFile","quoteUploadCalls","deps","mint","input","finalize","read","scope","id","remove","path","removeAll","send","res","file"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SACEA,wBAAwB,EACxBC,mBAAmB,EACnBC,oBAAoB,EACpBC,qBAAqB,EACrBC,uBAAuB,EACvBC,iBAAiB,EACjBC,qBAAqB,QAEhB,iDAAgD;
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/quote-uploads.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\nimport type { VisitorUploadFile, VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport {\n defaultVisitorUploadDeps,\n deleteVisitorUpload,\n deleteVisitorUploads,\n finalizeVisitorUpload,\n keepVisitorUploadCopy,\n mintVisitorUploadTicket,\n readVisitorUpload,\n sendVisitorUploadFile,\n type VisitorUploadResponse,\n} from '@aglyn/tenant-data-admin/server/visitor-upload'\n\n/**\n * The visitor-upload calls a quote's routes make (AGL-4096). The routes reach\n * this module by a dynamic import of it, so the upload pipeline, the bucket\n * and the SVG sanitizer load only when a proof or a customer's artwork is\n * actually sent or served, never with the routes' own modules.\n */\nexport interface QuoteUploadCalls {\n mint(input: Parameters<typeof mintVisitorUploadTicket>[1]): ReturnType<typeof mintVisitorUploadTicket>\n finalize(input: Parameters<typeof finalizeVisitorUpload>[1]): ReturnType<typeof finalizeVisitorUpload>\n /** A copy of a file already in Storage, through the same checks an upload meets. */\n keepCopy(input: Parameters<typeof keepVisitorUploadCopy>[1]): ReturnType<typeof keepVisitorUploadCopy>\n read(scope: VisitorUploadScope, id: string): Promise<VisitorUploadFile | null>\n remove(path: string): Promise<void>\n removeAll(scope: VisitorUploadScope): Promise<void>\n send(res: VisitorUploadResponse, file: Pick<VisitorUploadFile, 'path' | 'name' | 'contentType'>): Promise<void>\n}\n\nexport function quoteUploadCalls(): QuoteUploadCalls {\n const deps = defaultVisitorUploadDeps()\n return {\n mint: (input) => mintVisitorUploadTicket(deps, input),\n finalize: (input) => finalizeVisitorUpload(deps, input),\n keepCopy: (input) => keepVisitorUploadCopy(deps, input),\n read: (scope, id) => readVisitorUpload(deps, scope, id),\n remove: (path) => deleteVisitorUpload(deps, path),\n removeAll: (scope) => deleteVisitorUploads(deps, scope),\n send: (res, file) => sendVisitorUploadFile(deps, res, file),\n }\n}\n"],"names":["defaultVisitorUploadDeps","deleteVisitorUpload","deleteVisitorUploads","finalizeVisitorUpload","keepVisitorUploadCopy","mintVisitorUploadTicket","readVisitorUpload","sendVisitorUploadFile","quoteUploadCalls","deps","mint","input","finalize","keepCopy","read","scope","id","remove","path","removeAll","send","res","file"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SACEA,wBAAwB,EACxBC,mBAAmB,EACnBC,oBAAoB,EACpBC,qBAAqB,EACrBC,qBAAqB,EACrBC,uBAAuB,EACvBC,iBAAiB,EACjBC,qBAAqB,QAEhB,iDAAgD;AAmBvD,OAAO,SAASC;IACd,MAAMC,OAAOT;IACb,OAAO;QACLU,MAAM,CAACC,QAAUN,wBAAwBI,MAAME;QAC/CC,UAAU,CAACD,QAAUR,sBAAsBM,MAAME;QACjDE,UAAU,CAACF,QAAUP,sBAAsBK,MAAME;QACjDG,MAAM,CAACC,OAAOC,KAAOV,kBAAkBG,MAAMM,OAAOC;QACpDC,QAAQ,CAACC,OAASjB,oBAAoBQ,MAAMS;QAC5CC,WAAW,CAACJ,QAAUb,qBAAqBO,MAAMM;QACjDK,MAAM,CAACC,KAAKC,OAASf,sBAAsBE,MAAMY,KAAKC;IACxD;AACF"}
|
|
@@ -22,6 +22,7 @@ import { type CheckoutSessionExpiry } from './checkout-session-expiry';
|
|
|
22
22
|
import type { quotePdfFile } from './commerce-pdf';
|
|
23
23
|
import { type CommercePdfFile } from './pdf-response';
|
|
24
24
|
import type { QuoteMailer } from './quote-email';
|
|
25
|
+
import type { QuoteProofMediaAnswer, QuoteProofMediaRequest } from './quote-proof-media';
|
|
25
26
|
import type { QuoteUploadCalls } from './quote-uploads';
|
|
26
27
|
export interface QuoteDeps {
|
|
27
28
|
verifyIdToken(token: string): Promise<{
|
|
@@ -47,6 +48,8 @@ export interface QuoteDeps {
|
|
|
47
48
|
quotePdf(input: Parameters<typeof quotePdfFile>[0]): Promise<CommercePdfFile>;
|
|
48
49
|
/** The upload pipeline, loaded only by the proof actions. */
|
|
49
50
|
uploads(): Promise<QuoteUploadCalls>;
|
|
51
|
+
/** Where a media library file chosen for a proof is, for this member on this site, or why they may not have it. */
|
|
52
|
+
proofMedia(request: QuoteProofMediaRequest): Promise<QuoteProofMediaAnswer>;
|
|
50
53
|
/** The quote email (AGL-4097): the renderer, the PDF and sharp, loaded only by the send. */
|
|
51
54
|
mailer(): Promise<QuoteMailer>;
|
|
52
55
|
/**
|
package/src/lib/server/quote.js
CHANGED
|
@@ -47,6 +47,7 @@ export function defaultQuoteDeps() {
|
|
|
47
47
|
proofLinkUrl: (host, hostId, quoteId, version, proofId)=>quoteProofLinkUrl(host, hostId, quoteId, version, proofId),
|
|
48
48
|
quotePdf: async (input)=>(await import("./commerce-pdf.js")).quotePdfFile(input),
|
|
49
49
|
uploads: async ()=>(await import("./quote-uploads.js")).quoteUploadCalls(),
|
|
50
|
+
proofMedia: async (request)=>(await import("./quote-proof-media.js")).locateQuoteProofMedia(request),
|
|
50
51
|
mailer: async ()=>(await import("./quote-email.js")).quoteMailer(),
|
|
51
52
|
requestFacts: async (request)=>{
|
|
52
53
|
var _ref;
|
|
@@ -507,9 +508,18 @@ export async function handleQuote(deps, req) {
|
|
|
507
508
|
if (!idempotencyKey) return refuse(400, 'A quote save needs an Idempotency-Key header.');
|
|
508
509
|
const owner = await deps.orgForHost(hostId);
|
|
509
510
|
if (!checkEntitlement(owner == null ? void 0 : owner.org, 'commerce')) return refuse(403, 'Selling is not enabled');
|
|
510
|
-
|
|
511
|
+
// Whether a quote with no lines has its proof is answered below, per action.
|
|
512
|
+
const parsed = CommerceModel.parseQuoteInput(body['quote'], {
|
|
513
|
+
allowNoLines: true
|
|
514
|
+
});
|
|
511
515
|
if ('error' in parsed) return refuse(400, parsed.error);
|
|
512
516
|
const input = parsed.input;
|
|
517
|
+
const libraryProofs = action === 'create' ? CommerceModel.parseQuoteLibraryProofs(body['libraryProofs']) : null;
|
|
518
|
+
if (libraryProofs && 'error' in libraryProofs) return refuse(400, libraryProofs.error);
|
|
519
|
+
const chosenProofs = libraryProofs && 'proofs' in libraryProofs ? libraryProofs.proofs : [];
|
|
520
|
+
if (action === 'create' && !input.lines.length && !chosenProofs.length) {
|
|
521
|
+
return refuse(400, CommerceModel.QUOTE_NEEDS_LINE_OR_PROOF);
|
|
522
|
+
}
|
|
513
523
|
/*
|
|
514
524
|
* A new quote from a request (AGL-4098): the request is read again, here,
|
|
515
525
|
* for the member saving, and what the quote takes from it — which request,
|
|
@@ -545,12 +555,32 @@ export async function handleQuote(deps, req) {
|
|
|
545
555
|
}
|
|
546
556
|
const claim = claimed.claim;
|
|
547
557
|
const now = deps.now();
|
|
558
|
+
// The quote whose kept proofs a failed save must take back.
|
|
559
|
+
let keptFor = '';
|
|
548
560
|
try {
|
|
549
561
|
let outcome;
|
|
550
562
|
if (action === 'create') {
|
|
551
563
|
const orderRef = hostRef.collection('orders').doc(createResourceUid());
|
|
552
564
|
const counterRef = hostRef.collection('counters').doc('orders');
|
|
553
565
|
let number = 0;
|
|
566
|
+
const keptProofs = [];
|
|
567
|
+
if (chosenProofs.length) keptFor = orderRef.id;
|
|
568
|
+
for (const media of chosenProofs){
|
|
569
|
+
var _ref1;
|
|
570
|
+
const kept = await keepLibraryProof(deps, {
|
|
571
|
+
hostId,
|
|
572
|
+
quoteId: orderRef.id,
|
|
573
|
+
orgId: String((_ref1 = owner == null ? void 0 : owner.id) != null ? _ref1 : ''),
|
|
574
|
+
uid: decoded.uid,
|
|
575
|
+
media
|
|
576
|
+
});
|
|
577
|
+
if ('outcome' in kept) {
|
|
578
|
+
await removeQuoteFiles(deps, hostId, orderRef.id);
|
|
579
|
+
await claim.release();
|
|
580
|
+
return kept.outcome;
|
|
581
|
+
}
|
|
582
|
+
keptProofs.push(kept.file);
|
|
583
|
+
}
|
|
554
584
|
await firestore.runTransaction(async (transaction)=>{
|
|
555
585
|
var _counter_get, _input_requireProofApproval;
|
|
556
586
|
const counter = await transaction.get(counterRef);
|
|
@@ -580,7 +610,7 @@ export async function handleQuote(deps, req) {
|
|
|
580
610
|
});
|
|
581
611
|
// No `createdAtMs`, list fields or customer fields at the top: an
|
|
582
612
|
// unpaid quote is not an order any list counts (`commerce-quotes.ts`).
|
|
583
|
-
|
|
613
|
+
let order = _extends({
|
|
584
614
|
number,
|
|
585
615
|
status: 'pending',
|
|
586
616
|
channel: 'quote',
|
|
@@ -597,7 +627,16 @@ export async function handleQuote(deps, req) {
|
|
|
597
627
|
}
|
|
598
628
|
],
|
|
599
629
|
quote
|
|
600
|
-
})
|
|
630
|
+
});
|
|
631
|
+
for (const file of keptProofs){
|
|
632
|
+
const added = CommerceModel.withQuoteProofAdded(order, quoteProofOf(file), {
|
|
633
|
+
atMs: now,
|
|
634
|
+
by: actor
|
|
635
|
+
});
|
|
636
|
+
if ('reason' in added) throw new Error(`a new quote refused its proof: ${added.reason}`);
|
|
637
|
+
order = added.order;
|
|
638
|
+
}
|
|
639
|
+
transaction.set(orderRef, order);
|
|
601
640
|
});
|
|
602
641
|
outcome = {
|
|
603
642
|
status: 200,
|
|
@@ -625,6 +664,9 @@ export async function handleQuote(deps, req) {
|
|
|
625
664
|
if (Number(existing.quote.updatedAtMs) !== baseUpdatedAtMs) {
|
|
626
665
|
return refuse(409, 'Someone else changed this quote. Close it and open it again to see their changes.');
|
|
627
666
|
}
|
|
667
|
+
if (!priced.lineItems.length && !CommerceModel.currentQuoteProofs(existing.quote).length) {
|
|
668
|
+
return refuse(400, CommerceModel.QUOTE_NEEDS_LINE_OR_PROOF);
|
|
669
|
+
}
|
|
628
670
|
// The tax mode is restated from this pricing, and dropped when it has
|
|
629
671
|
// none. The pay page's open session was priced from the quote before
|
|
630
672
|
// this edit, so it is closed and forgotten.
|
|
@@ -662,6 +704,7 @@ export async function handleQuote(deps, req) {
|
|
|
662
704
|
return outcome;
|
|
663
705
|
} catch (error) {
|
|
664
706
|
console.error('commerce quote save failed', error);
|
|
707
|
+
if (keptFor) await removeQuoteFiles(deps, hostId, keptFor);
|
|
665
708
|
await claim.release();
|
|
666
709
|
return refuse(500, 'The quote could not be saved');
|
|
667
710
|
}
|
|
@@ -671,11 +714,56 @@ export async function handleQuote(deps, req) {
|
|
|
671
714
|
*=========================================*/ const PROOF_ACTIONS = new Set([
|
|
672
715
|
'proof-ticket',
|
|
673
716
|
'proof-finalize',
|
|
717
|
+
'proof-from-media',
|
|
674
718
|
'proof-remove',
|
|
675
719
|
'start-revision',
|
|
676
720
|
'revisions',
|
|
677
721
|
'file'
|
|
678
722
|
]);
|
|
723
|
+
/** A kept file as a quote's proof takes it. */ const quoteProofOf = (file)=>({
|
|
724
|
+
id: file.id,
|
|
725
|
+
name: file.name,
|
|
726
|
+
contentType: file.contentType,
|
|
727
|
+
size: file.size,
|
|
728
|
+
path: file.path
|
|
729
|
+
});
|
|
730
|
+
/**
|
|
731
|
+
* A copy of a media library file in the quote's private proofs (AGL-4184), once
|
|
732
|
+
* the member is found able to read it. The caller puts it on the quote.
|
|
733
|
+
*/ async function keepLibraryProof(deps, input) {
|
|
734
|
+
const { hostId, quoteId, orgId, uid, media } = input;
|
|
735
|
+
const located = await deps.proofMedia({
|
|
736
|
+
hostId,
|
|
737
|
+
orgId,
|
|
738
|
+
uid,
|
|
739
|
+
mediaScope: media.mediaScope,
|
|
740
|
+
mediaId: media.mediaId
|
|
741
|
+
});
|
|
742
|
+
if ('error' in located) return {
|
|
743
|
+
outcome: refuse(located.status, located.error)
|
|
744
|
+
};
|
|
745
|
+
const uploads = await deps.uploads();
|
|
746
|
+
const kept = await uploads.keepCopy({
|
|
747
|
+
scope: {
|
|
748
|
+
hostId,
|
|
749
|
+
purpose: CommerceModel.QUOTE_PROOF_PURPOSE,
|
|
750
|
+
purposeId: quoteId
|
|
751
|
+
},
|
|
752
|
+
source: {
|
|
753
|
+
path: located.path,
|
|
754
|
+
name: located.name
|
|
755
|
+
},
|
|
756
|
+
caller: {
|
|
757
|
+
uid
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
if ('error' in kept) return {
|
|
761
|
+
outcome: refuse(kept.status, kept.error)
|
|
762
|
+
};
|
|
763
|
+
return {
|
|
764
|
+
file: kept.file
|
|
765
|
+
};
|
|
766
|
+
}
|
|
679
767
|
/** Deletes a quote's kept files, its proofs and the customer's artwork; never throws. */ async function removeQuoteFiles(deps, hostId, quoteId) {
|
|
680
768
|
try {
|
|
681
769
|
const uploads = await deps.uploads();
|
|
@@ -797,16 +885,41 @@ async function handleProofAction(deps, context) {
|
|
|
797
885
|
}
|
|
798
886
|
};
|
|
799
887
|
}
|
|
800
|
-
if (action === 'proof-finalize') {
|
|
888
|
+
if (action === 'proof-finalize' || action === 'proof-from-media') {
|
|
801
889
|
const uploads = await deps.uploads();
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
890
|
+
let kept;
|
|
891
|
+
if (action === 'proof-from-media') {
|
|
892
|
+
var _body_media, _ref2, _media_mediaScope, _media_mediaId;
|
|
893
|
+
const media = (_body_media = body['media']) != null ? _body_media : {};
|
|
894
|
+
const snapshot = await ref.get();
|
|
895
|
+
const refused = CommerceModel.quoteProofChangeRefusal(snapshot.exists ? snapshot.data() : null, 'add');
|
|
896
|
+
if (refused) return refuse(refused === 'not-a-quote' ? 404 : 409, CommerceModel.quoteProofRefusalMessage(refused));
|
|
897
|
+
// Storage is spent here, so the plan must sell, as a ticket's must.
|
|
898
|
+
const owner = await deps.orgForHost(hostId);
|
|
899
|
+
if (!checkEntitlement(owner == null ? void 0 : owner.org, 'commerce')) return refuse(403, 'Selling is not enabled');
|
|
900
|
+
const copied = await keepLibraryProof(deps, {
|
|
901
|
+
hostId,
|
|
902
|
+
quoteId,
|
|
903
|
+
orgId: String((_ref2 = owner == null ? void 0 : owner.id) != null ? _ref2 : ''),
|
|
904
|
+
uid,
|
|
905
|
+
media: {
|
|
906
|
+
mediaScope: String((_media_mediaScope = media.mediaScope) != null ? _media_mediaScope : ''),
|
|
907
|
+
mediaId: String((_media_mediaId = media.mediaId) != null ? _media_mediaId : '')
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
if ('outcome' in copied) return copied.outcome;
|
|
911
|
+
kept = copied;
|
|
912
|
+
} else {
|
|
913
|
+
const finalized = await uploads.finalize({
|
|
914
|
+
scope: proofScope,
|
|
915
|
+
ticket: body['ticket'],
|
|
916
|
+
caller: {
|
|
917
|
+
uid
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
if ('error' in finalized) return refuse(finalized.status, finalized.error);
|
|
921
|
+
kept = finalized;
|
|
922
|
+
}
|
|
810
923
|
const now = deps.now();
|
|
811
924
|
const answer = await firestore.runTransaction(async (transaction)=>{
|
|
812
925
|
const snapshot = await transaction.get(ref);
|
|
@@ -829,13 +942,7 @@ async function handleProofAction(deps, context) {
|
|
|
829
942
|
}
|
|
830
943
|
};
|
|
831
944
|
}
|
|
832
|
-
const added = CommerceModel.withQuoteProofAdded(order, {
|
|
833
|
-
id: kept.file.id,
|
|
834
|
-
name: kept.file.name,
|
|
835
|
-
contentType: kept.file.contentType,
|
|
836
|
-
size: kept.file.size,
|
|
837
|
-
path: kept.file.path
|
|
838
|
-
}, {
|
|
945
|
+
const added = CommerceModel.withQuoteProofAdded(order, quoteProofOf(kept.file), {
|
|
839
946
|
atMs: now,
|
|
840
947
|
by: actor
|
|
841
948
|
});
|
|
@@ -975,7 +1082,7 @@ async function handleProofAction(deps, context) {
|
|
|
975
1082
|
const to = CommerceModel.quoteSendRecipient(stored, parsed.input.to);
|
|
976
1083
|
const refused = CommerceModel.quoteSendRefusal(stored, to);
|
|
977
1084
|
if (refused) {
|
|
978
|
-
return refuse(refused === 'not-a-quote' ? 404 : refused === 'paid' ? 409 : 400, CommerceModel.quoteSendRefusalMessage(refused));
|
|
1085
|
+
return refuse(refused === 'not-a-quote' ? 404 : refused === 'paid' || refused === 'nothing-to-send' ? 409 : 400, CommerceModel.quoteSendRefusalMessage(refused));
|
|
979
1086
|
}
|
|
980
1087
|
if (!deps.payLinkUrl(host, hostId, quoteId, CommerceModel.quoteLinkVersion(stored == null ? void 0 : stored.quote))) {
|
|
981
1088
|
return refuse(409, 'This site has no web address yet, so its quotes have no pay link. Publish the site first.');
|