@aglyn/plugins-commerce 1.15.1 → 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.
Files changed (212) hide show
  1. package/README.md +1 -1
  2. package/package.json +13 -13
  3. package/src/lib/components/cart.js +2 -1
  4. package/src/lib/components/cart.js.map +1 -1
  5. package/src/lib/components/console/payments-settings-card.component.js +6 -1
  6. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  7. package/src/lib/components/console/pos/pos-api.d.ts +5 -0
  8. package/src/lib/components/console/pos/pos-api.js.map +1 -1
  9. package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
  10. package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
  11. package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
  12. package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
  13. package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
  14. package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
  15. package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
  16. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  17. package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
  18. package/src/lib/components/console/product-builder-fields.component.js +195 -0
  19. package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
  20. package/src/lib/components/console/product-editor-dialog.component.js +35 -2
  21. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  22. package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
  23. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  24. package/src/lib/components/console/quote-messages.component.d.ts +21 -0
  25. package/src/lib/components/console/quote-messages.component.js +185 -0
  26. package/src/lib/components/console/quote-messages.component.js.map +1 -0
  27. package/src/lib/components/console/quote-pay-link.component.js +1 -1
  28. package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
  29. package/src/lib/components/console/quote-proofs.component.js +30 -3
  30. package/src/lib/components/console/quote-proofs.component.js.map +1 -1
  31. package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
  32. package/src/lib/components/console/quote-settings-card.component.js +154 -24
  33. package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
  34. package/src/lib/components/product-builder-context.d.ts +22 -0
  35. package/src/lib/components/product-builder-context.js +21 -0
  36. package/src/lib/components/product-builder-context.js.map +1 -0
  37. package/src/lib/components/product-builder-mockup.d.ts +42 -0
  38. package/src/lib/components/product-builder-mockup.js +120 -0
  39. package/src/lib/components/product-builder-mockup.js.map +1 -0
  40. package/src/lib/components/product-builder-sample.d.ts +63 -0
  41. package/src/lib/components/product-builder-sample.js +96 -0
  42. package/src/lib/components/product-builder-sample.js.map +1 -0
  43. package/src/lib/components/product-choice-cards.d.ts +51 -0
  44. package/src/lib/components/product-choice-cards.js +311 -0
  45. package/src/lib/components/product-choice-cards.js.map +1 -0
  46. package/src/lib/components/product-detail-panels.d.ts +42 -0
  47. package/src/lib/components/product-detail-panels.js +185 -0
  48. package/src/lib/components/product-detail-panels.js.map +1 -0
  49. package/src/lib/components/product-detail.d.ts +20 -12
  50. package/src/lib/components/product-detail.js +136 -221
  51. package/src/lib/components/product-detail.js.map +1 -1
  52. package/src/lib/components/product-grid.d.ts +7 -0
  53. package/src/lib/components/product-grid.js +11 -8
  54. package/src/lib/components/product-grid.js.map +1 -1
  55. package/src/lib/components/product-options-field-body.d.ts +9 -8
  56. package/src/lib/components/product-options-field-body.js +152 -3
  57. package/src/lib/components/product-options-field-body.js.map +1 -1
  58. package/src/lib/components/product-options-field.js +1 -1
  59. package/src/lib/components/product-options-field.js.map +1 -1
  60. package/src/lib/components/product-photo-fit.d.ts +49 -0
  61. package/src/lib/components/product-photo-fit.js +58 -0
  62. package/src/lib/components/product-photo-fit.js.map +1 -0
  63. package/src/lib/components/product-restock-notify.d.ts +12 -0
  64. package/src/lib/components/product-restock-notify.js +86 -0
  65. package/src/lib/components/product-restock-notify.js.map +1 -0
  66. package/src/lib/components/quote-messages-panel.d.ts +21 -0
  67. package/src/lib/components/quote-messages-panel.js +191 -0
  68. package/src/lib/components/quote-messages-panel.js.map +1 -0
  69. package/src/lib/components/quote-page-body.js +15 -1
  70. package/src/lib/components/quote-page-body.js.map +1 -1
  71. package/src/lib/components/quote-proof-panel.d.ts +6 -3
  72. package/src/lib/components/quote-proof-panel.js +139 -14
  73. package/src/lib/components/quote-proof-panel.js.map +1 -1
  74. package/src/lib/components/related-products.d.ts +7 -0
  75. package/src/lib/components/related-products.js +8 -6
  76. package/src/lib/components/related-products.js.map +1 -1
  77. package/src/lib/constants/quote-page.d.ts +8 -0
  78. package/src/lib/constants/quote-page.js +11 -0
  79. package/src/lib/constants/quote-page.js.map +1 -1
  80. package/src/lib/model/commerce-cart.d.ts +6 -1
  81. package/src/lib/model/commerce-cart.js +5 -1
  82. package/src/lib/model/commerce-cart.js.map +1 -1
  83. package/src/lib/model/commerce-invoices.js +5 -1
  84. package/src/lib/model/commerce-invoices.js.map +1 -1
  85. package/src/lib/model/commerce-pos-ops.d.ts +3 -0
  86. package/src/lib/model/commerce-pos-ops.js +3 -0
  87. package/src/lib/model/commerce-pos-ops.js.map +1 -1
  88. package/src/lib/model/commerce-pos.d.ts +8 -0
  89. package/src/lib/model/commerce-pos.js.map +1 -1
  90. package/src/lib/model/commerce-quote-messages.d.ts +106 -0
  91. package/src/lib/model/commerce-quote-messages.js +146 -0
  92. package/src/lib/model/commerce-quote-messages.js.map +1 -0
  93. package/src/lib/model/commerce-quote-pay.d.ts +31 -2
  94. package/src/lib/model/commerce-quote-pay.js +31 -7
  95. package/src/lib/model/commerce-quote-pay.js.map +1 -1
  96. package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
  97. package/src/lib/model/commerce-quote-proofs.js +73 -18
  98. package/src/lib/model/commerce-quote-proofs.js.map +1 -1
  99. package/src/lib/model/commerce-quote-request.d.ts +14 -4
  100. package/src/lib/model/commerce-quote-request.js +25 -2
  101. package/src/lib/model/commerce-quote-request.js.map +1 -1
  102. package/src/lib/model/commerce-quotes.d.ts +56 -3
  103. package/src/lib/model/commerce-quotes.js +47 -2
  104. package/src/lib/model/commerce-quotes.js.map +1 -1
  105. package/src/lib/model/commerce.d.ts +12 -1
  106. package/src/lib/model/commerce.js.map +1 -1
  107. package/src/lib/model/index.d.ts +1 -0
  108. package/src/lib/model/index.js +1 -0
  109. package/src/lib/model/index.js.map +1 -1
  110. package/src/lib/model/pos-cellular.d.ts +5 -0
  111. package/src/lib/model/pos-cellular.js.map +1 -1
  112. package/src/lib/model/product-card-rules.d.ts +41 -0
  113. package/src/lib/model/product-card-rules.js +90 -0
  114. package/src/lib/model/product-card-rules.js.map +1 -0
  115. package/src/lib/model/product-modifiers.d.ts +11 -0
  116. package/src/lib/model/product-modifiers.js +10 -0
  117. package/src/lib/model/product-modifiers.js.map +1 -1
  118. package/src/lib/model/product-write.d.ts +3 -0
  119. package/src/lib/server/billing-webhook.js +6 -2
  120. package/src/lib/server/billing-webhook.js.map +1 -1
  121. package/src/lib/server/cancel-order.js +15 -0
  122. package/src/lib/server/cancel-order.js.map +1 -1
  123. package/src/lib/server/channel-order-updates.js +15 -1
  124. package/src/lib/server/channel-order-updates.js.map +1 -1
  125. package/src/lib/server/channel-orders.js +20 -0
  126. package/src/lib/server/channel-orders.js.map +1 -1
  127. package/src/lib/server/checkout.js +1 -1
  128. package/src/lib/server/checkout.js.map +1 -1
  129. package/src/lib/server/local-fulfillment.js +1 -1
  130. package/src/lib/server/local-fulfillment.js.map +1 -1
  131. package/src/lib/server/pos-cellular-billing.d.ts +1 -1
  132. package/src/lib/server/pos-cellular-billing.js +2 -1
  133. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  134. package/src/lib/server/pos-cellular.d.ts +3 -1
  135. package/src/lib/server/pos-cellular.js +15 -8
  136. package/src/lib/server/pos-cellular.js.map +1 -1
  137. package/src/lib/server/pos-offline-sync.d.ts +3 -3
  138. package/src/lib/server/pos-offline-sync.js +17 -4
  139. package/src/lib/server/pos-offline-sync.js.map +1 -1
  140. package/src/lib/server/pos-order.js +17 -6
  141. package/src/lib/server/pos-order.js.map +1 -1
  142. package/src/lib/server/pos-payment.js +27 -11
  143. package/src/lib/server/pos-payment.js.map +1 -1
  144. package/src/lib/server/pos-reader-splash.js +10 -5
  145. package/src/lib/server/pos-reader-splash.js.map +1 -1
  146. package/src/lib/server/pos-readers.js +34 -10
  147. package/src/lib/server/pos-readers.js.map +1 -1
  148. package/src/lib/server/pos-return.js +19 -3
  149. package/src/lib/server/pos-return.js.map +1 -1
  150. package/src/lib/server/pos-stripe.d.ts +14 -0
  151. package/src/lib/server/pos-stripe.js +6 -2
  152. package/src/lib/server/pos-stripe.js.map +1 -1
  153. package/src/lib/server/pos-terminal-connection-token.js +23 -9
  154. package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
  155. package/src/lib/server/pos-terminal.d.ts +80 -14
  156. package/src/lib/server/pos-terminal.js +393 -123
  157. package/src/lib/server/pos-terminal.js.map +1 -1
  158. package/src/lib/server/product-drafts.d.ts +1 -1
  159. package/src/lib/server/product-drafts.js +4 -3
  160. package/src/lib/server/product-drafts.js.map +1 -1
  161. package/src/lib/server/product-writer.js +5 -4
  162. package/src/lib/server/product-writer.js.map +1 -1
  163. package/src/lib/server/product.d.ts +11 -0
  164. package/src/lib/server/product.js +18 -3
  165. package/src/lib/server/product.js.map +1 -1
  166. package/src/lib/server/products-write.js +4 -3
  167. package/src/lib/server/products-write.js.map +1 -1
  168. package/src/lib/server/quote-email.d.ts +26 -0
  169. package/src/lib/server/quote-email.js +73 -7
  170. package/src/lib/server/quote-email.js.map +1 -1
  171. package/src/lib/server/quote-messages.d.ts +72 -0
  172. package/src/lib/server/quote-messages.js +356 -0
  173. package/src/lib/server/quote-messages.js.map +1 -0
  174. package/src/lib/server/quote-pay.d.ts +42 -0
  175. package/src/lib/server/quote-pay.js +81 -4
  176. package/src/lib/server/quote-pay.js.map +1 -1
  177. package/src/lib/server/quote-proofs.d.ts +1 -1
  178. package/src/lib/server/quote-proofs.js +63 -19
  179. package/src/lib/server/quote-proofs.js.map +1 -1
  180. package/src/lib/server/quote.d.ts +12 -0
  181. package/src/lib/server/quote.js +44 -14
  182. package/src/lib/server/quote.js.map +1 -1
  183. package/src/lib/server/refund.js +3 -1
  184. package/src/lib/server/refund.js.map +1 -1
  185. package/src/lib/server/reserve-stock.js +9 -0
  186. package/src/lib/server/reserve-stock.js.map +1 -1
  187. package/src/lib/server/returns.js +15 -1
  188. package/src/lib/server/returns.js.map +1 -1
  189. package/src/lib/server/reviews.js +15 -0
  190. package/src/lib/server/reviews.js.map +1 -1
  191. package/src/lib/server/sold-out-drop.d.ts +58 -0
  192. package/src/lib/server/sold-out-drop.js +81 -0
  193. package/src/lib/server/sold-out-drop.js.map +1 -0
  194. package/src/lib/server/stock-levels.js +9 -0
  195. package/src/lib/server/stock-levels.js.map +1 -1
  196. package/src/lib/server/stripe-refund.d.ts +7 -0
  197. package/src/lib/server/stripe-refund.js +26 -7
  198. package/src/lib/server/stripe-refund.js.map +1 -1
  199. package/src/lib/server.js +2 -0
  200. package/src/lib/server.js.map +1 -1
  201. package/src/lib/tenant-emails.js +85 -2
  202. package/src/lib/tenant-emails.js.map +1 -1
  203. package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
  204. package/src/lib/testing/fake-seller-payment-account.js +40 -0
  205. package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
  206. package/src/lib/transfer/product-transfer.js +6 -5
  207. package/src/lib/transfer/product-transfer.js.map +1 -1
  208. package/src/lib/transfer/products.server.js +4 -3
  209. package/src/lib/transfer/products.server.js.map +1 -1
  210. package/src/lib/utils/quote-email-content.d.ts +6 -0
  211. package/src/lib/utils/quote-email-content.js +6 -3
  212. package/src/lib/utils/quote-email-content.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-pos.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 POS TENDER LEDGER (AGL-3607).\n *\n * A register sale used to be settled by exactly one tender and recorded none:\n * whether a POS order was paid in cash, by the QR link or to a room was\n * inferred afterwards from which other fields happened to be set. A sale now\n * carries `payments[]`, one entry per tender, and takes payments until the\n * balance due is zero. Only then is it `paid`.\n *\n * Every figure here is integer cents. `amountCents` is what a payment put\n * toward the SALE; a tip rides beside it in `tipCents` and never counts toward\n * the balance, the platform's take or the store's revenue. Tips belong to the\n * merchant and their staff.\n *\n * Pure and framework-free, so the register, the customer display and the\n * server read one answer.\n *=========================================*/\n\n/** How one payment toward a register sale was taken. */\nexport type OrderPaymentMethod =\n | 'cash'\n /** A Stripe Terminal smart reader (tap, insert or swipe). */\n | 'card_present'\n /** A card typed into the console by staff (card not present). */\n | 'card_keyed'\n /** The Stripe payment page the customer opens from a QR code. */\n | 'card_link'\n | 'gift_card'\n /** Charged to a checked-in reservation's folio. */\n | 'folio'\n /**\n * Store credit another plugin keeps — rewards, referral credit — taken\n * through core's checkout-credits seam (AGL-3640). Which plugin and which\n * account ride on the payment as `creditProviderId` and `creditReference`.\n */\n | 'credit'\n\nexport type OrderPaymentStatus =\n /** Started and not finished: reserves its amount against the balance. */\n | 'pending'\n | 'succeeded'\n /** Declined or errored; may be retried, reserves nothing. */\n | 'failed'\n | 'canceled'\n /** Taken and then handed back when the open sale was voided. */\n | 'reversed'\n\nexport const ORDER_PAYMENT_METHODS: readonly OrderPaymentMethod[] = [\n 'cash',\n 'card_present',\n 'card_keyed',\n 'card_link',\n 'gift_card',\n 'folio',\n 'credit',\n]\n\n/** One payment toward a register sale, on `HostOrder.payments`. */\nexport interface OrderPayment {\n /** Stable id, derived from the register's attempt key so a retry finds it. */\n id: string\n method: OrderPaymentMethod\n /** Cents put toward the sale. Never includes the tip. */\n amountCents: number\n /** Gratuity on top of `amountCents`, the merchant's and not revenue. */\n tipCents?: number\n status: OrderPaymentStatus\n /** When the payment was started. */\n atMs: number\n /** When it reached `succeeded`. */\n settledAtMs?: number\n /** Stripe PaymentIntent for `card_present` / `card_keyed` / a paid link. */\n paymentIntentId?: string\n /** Stripe Checkout Session for `card_link`. */\n checkoutSessionId?: string\n /** The payment page a `card_link` payment shows as a QR. */\n checkoutUrl?: string\n /** The Terminal reader a `card_present` payment runs on. */\n readerId?: string\n /** The gift card's code (its document id) for `gift_card`. */\n giftCardId?: string\n /** For `credit`: the provider that paid it (`{pluginId}.{key}`, AGL-3640). */\n creditProviderId?: string\n /** For `credit`: the provider's own handle on the account it came from. */\n creditReference?: string\n /** For `credit`: what the provider calls it, for the register and receipt. */\n creditLabel?: string\n cardBrand?: string\n last4?: string\n /** Cash handed over for a `cash` payment, and the change given back. */\n cashTenderedCents?: number\n changeCents?: number\n /** The stay a `folio` payment was charged to. */\n reservationId?: string\n /** The folio entry's `atMs`, so a void can remove exactly that entry. */\n folioAtMs?: number\n /**\n * The platform's take attributed to this payment (excludes the tip). For a\n * card payment it is netted from the payout with Stripe's processing cost\n * added, and recorded in `feeCents`; otherwise it accrues to the invoice.\n */\n takeFeeCents?: number\n /** The `application_fee_amount` a card payment carried, or 0. */\n feeCents?: number\n /** Why a `failed` payment failed, in words the cashier can read out. */\n failureMessage?: string\n /** Whether Stripe moved real money; absent for tenders Stripe never saw. */\n livemode?: boolean\n /** The console user who took the payment. */\n cashierId?: string\n}\n\n/** The tenders whose money moves through Stripe. */\nexport const POS_CARD_METHODS: ReadonlySet<OrderPaymentMethod> = new Set([\n 'card_present',\n 'card_keyed',\n 'card_link',\n])\n\nexport function isCardPaymentMethod(method: OrderPaymentMethod): boolean {\n return POS_CARD_METHODS.has(method)\n}\n\n/*==========================================\n * WHICH TENDERS CARRY THE PLATFORM FEE (AGL-4036).\n *\n * The take used to follow the sale whatever paid it (AGL-2111): a cash sale\n * owed the same percentage as a card sale and had it added to the monthly\n * invoice. In-person rivals charge nothing on cash, and an event register that\n * bills its operator for the cash in their own apron is not one they will\n * choose, so three tenders now carry none:\n *\n * - cash: no payment service touches it, and the merchant keeps all of it;\n * - gift card: the fee was taken when the card was SOLD, so charging it again\n * when the card is spent would charge the same money twice;\n * - store credit (`credit`): rewards or referral value the merchant gave\n * away, so no money changes hands and an invoiced fee on it would only\n * penalize running a rewards program.\n *\n * Everything else still carries it. Card payments net it from their payout,\n * as always. A room charge (`folio`) is new revenue booked to a stay, so its\n * share goes on the invoice.\n *\n * One predicate, so the register, the completion, the offline sync and the\n * docs cannot disagree about which tender is which.\n *=========================================*/\n\n/** The tenders that carry no platform fee (AGL-4036). */\nexport const POS_FEE_FREE_METHODS: ReadonlySet<OrderPaymentMethod> = new Set([\n 'cash',\n 'gift_card',\n 'credit',\n])\n\n/** Whether a payment by `method` carries its share of the platform's take. */\nexport function paymentCarriesPlatformFee(method: OrderPaymentMethod): boolean {\n return !POS_FEE_FREE_METHODS.has(method)\n}\n\n/**\n * The take a sale owes when ONE tender pays all of it: the whole take, or\n * nothing for a fee-free tender.\n */\nexport function posTenderTakeCents(\n method: OrderPaymentMethod,\n takeFeeCents: number,\n): number {\n return paymentCarriesPlatformFee(method) ? wholeCents(takeFeeCents) : 0\n}\n\n/** Whole non-negative cents from an untrusted value. */\nfunction wholeCents(value: unknown): number {\n const number = Math.round(Number(value))\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/**\n * The order's payments, read through one door.\n *\n * Orders written before the ledger existed carry no `payments`, so one is\n * INFERRED from the fields the single-tender register wrote: a folio sale has\n * `reservationId`, a QR sale has `checkoutSessionId`, and anything else on the\n * POS channel was cash. A pending legacy sale is the QR link still waiting.\n * Online orders paid through Stripe Checkout read as one `card_link` payment.\n * Nothing is written back: this is a reader, never a migration.\n */\nexport function orderPayments(order: {\n payments?: OrderPayment[] | null\n channel?: string\n status?: string\n totals?: { totalCents?: number; tipCents?: number } | null\n amountCents?: number\n reservationId?: string\n checkoutSessionId?: string\n paymentIntentId?: string\n createdAtMs?: number\n}): OrderPayment[] {\n if (Array.isArray(order?.payments)) {\n return order.payments.filter(\n (payment): payment is OrderPayment =>\n Boolean(payment) && typeof payment === 'object' && Boolean(payment.id),\n )\n }\n const totalCents = wholeCents(order?.totals?.totalCents ?? order?.amountCents)\n if (!(totalCents > 0)) return []\n const settled = order?.status !== 'pending' && order?.status !== 'cancelled'\n const atMs = Number(order?.createdAtMs) || 0\n const method: OrderPaymentMethod = order?.reservationId\n ? 'folio'\n : order?.checkoutSessionId || order?.paymentIntentId || order?.channel !== 'pos'\n ? 'card_link'\n : 'cash'\n return [\n {\n id: 'legacy',\n method,\n amountCents: totalCents,\n status: settled ? 'succeeded' : order?.status === 'cancelled' ? 'canceled' : 'pending',\n atMs,\n ...(order?.paymentIntentId ? { paymentIntentId: order.paymentIntentId } : {}),\n ...(order?.checkoutSessionId ? { checkoutSessionId: order.checkoutSessionId } : {}),\n ...(order?.reservationId ? { reservationId: order.reservationId } : {}),\n },\n ]\n}\n\n/** Cents put toward the sale by payments that succeeded. */\nexport function posSettledCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded')\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n}\n\n/**\n * Cents spoken for: succeeded payments plus the ones still in flight. A\n * reader waiting for a tap has claimed its share of the balance, so a second\n * tender cannot be started for the same money.\n */\nexport function posReservedCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded' || payment.status === 'pending')\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n}\n\n/** What the customer still owes, by settled payments. */\nexport function posBalanceDueCents(\n totalCents: number,\n payments: readonly OrderPayment[],\n): number {\n return Math.max(0, wholeCents(totalCents) - posSettledCents(payments))\n}\n\n/** What a NEW payment may still take: the balance less what is in flight. */\nexport function posTenderableCents(\n totalCents: number,\n payments: readonly OrderPayment[],\n): number {\n return Math.max(0, wholeCents(totalCents) - posReservedCents(payments))\n}\n\n/** Tips taken across the sale's settled payments. */\nexport function posTipCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded')\n .reduce((sum, payment) => sum + wholeCents(payment.tipCents), 0)\n}\n\n/**\n * The share of the sale's take a payment of `amountCents` carries.\n *\n * Proportional to the part of the SALE it pays, never to the tip. Card\n * payments carry their share in `application_fee_amount`; whatever the card\n * shares leave is accrued to the invoice at completion\n * ({@link posInvoiceTakeCents}), so the take is exact however the sale was\n * split and however each share rounded.\n */\nexport function posTakeShareCents(input: {\n takeFeeCents: number\n totalCents: number\n amountCents: number\n}): number {\n const take = wholeCents(input.takeFeeCents)\n const total = wholeCents(input.totalCents)\n const amount = Math.min(wholeCents(input.amountCents), total)\n if (!(take > 0) || !(total > 0) || !(amount > 0)) return 0\n return Math.min(take, Math.round((take * amount) / total))\n}\n\n/**\n * {@link posTakeShareCents} for a payment by `method`: its share of the take,\n * or 0 for a tender that carries no platform fee (AGL-4036).\n */\nexport function posPaymentTakeShareCents(input: {\n method: OrderPaymentMethod\n takeFeeCents: number\n totalCents: number\n amountCents: number\n}): number {\n if (!paymentCarriesPlatformFee(input.method)) return 0\n return posTakeShareCents(input)\n}\n\n/**\n * The part of the sale's take its tenders owe (AGL-4036): the whole take when\n * every settled payment carries the fee, and otherwise the share for the part\n * of the sale the fee-carrying payments paid. Cash and gift-card parts owe\n * nothing, so a sale paid all in cash owes 0.\n *\n * Worked from the payments' METHODS, not from the `takeFeeCents` each one\n * recorded, so a sale that was opened before this rule and finished after it\n * is charged by the rule it finished under.\n */\nexport function posOwedTakeCents(input: {\n takeFeeCents: number\n totalCents: number\n payments: readonly OrderPayment[]\n}): number {\n const take = wholeCents(input.takeFeeCents)\n const settled = input.payments.filter((payment) => payment.status === 'succeeded')\n if (settled.every((payment) => paymentCarriesPlatformFee(payment.method))) return take\n const carryingCents = settled\n .filter((payment) => paymentCarriesPlatformFee(payment.method))\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n return posTakeShareCents({\n takeFeeCents: take,\n totalCents: input.totalCents,\n amountCents: carryingCents,\n })\n}\n\n/**\n * What of the sale's take was NOT netted from a card payout, and therefore\n * goes on the merchant's invoice: the take the tenders owe\n * ({@link posOwedTakeCents}) less every succeeded card payment's share. Never\n * negative, and 0 for a sale paid only by card, cash, gift card and store credit.\n */\nexport function posInvoiceTakeCents(input: {\n takeFeeCents: number\n totalCents: number\n payments: readonly OrderPayment[]\n}): number {\n const netted = input.payments\n .filter(\n (payment) =>\n payment.status === 'succeeded' && isCardPaymentMethod(payment.method),\n )\n .reduce((sum, payment) => sum + wholeCents(payment.takeFeeCents), 0)\n return Math.max(0, posOwedTakeCents(input) - netted)\n}\n\n/**\n * How the sale's fee reaches the platform, from the payments that carried it.\n * A cash, gift-card or store-credit part carries none (AGL-4036), so a card + cash sale is\n * `payout`, not `split`.\n */\nexport function posFeeCollection(\n payments: readonly OrderPayment[],\n): 'payout' | 'invoice' | 'split' {\n const settled = payments.filter(\n (payment) =>\n payment.status === 'succeeded' && paymentCarriesPlatformFee(payment.method),\n )\n const card = settled.some((payment) => isCardPaymentMethod(payment.method))\n const other = settled.some((payment) => !isCardPaymentMethod(payment.method))\n if (card && other) return 'split'\n return card ? 'payout' : 'invoice'\n}\n\n/** A one-line description of a payment for the register, receipt and timeline. */\nexport function describeOrderPayment(payment: OrderPayment): string {\n const dollars = (cents: number) => `$${(cents / 100).toFixed(2)}`\n const label =\n (payment.method === 'credit' && payment.creditLabel) || ORDER_PAYMENT_METHOD_LABELS[payment.method] || 'Payment'\n const card =\n payment.cardBrand || payment.last4\n ? ` (${[payment.cardBrand, payment.last4 ? `•••• ${payment.last4}` : '']\n .filter(Boolean)\n .join(' ')})`\n : ''\n const tip = wholeCents(payment.tipCents)\n ? ` + ${dollars(wholeCents(payment.tipCents))} tip`\n : ''\n return `${label}${card} ${dollars(wholeCents(payment.amountCents))}${tip}`\n}\n\nexport const ORDER_PAYMENT_METHOD_LABELS: Record<OrderPaymentMethod, string> = {\n cash: 'Cash',\n card_present: 'Card reader',\n card_keyed: 'Typed card',\n card_link: 'Card (QR)',\n gift_card: 'Gift card',\n folio: 'Charged to room',\n credit: 'Store credit',\n}\n\n/*==========================================\n * TIPS (AGL-3607).\n *=========================================*/\n\n/** The presets a merchant starts with. */\nexport const POS_TIP_PERCENTAGES_DEFAULT: readonly number[] = [15, 18, 20, 25]\n\n/**\n * The merchant's tip presets from the plugin setting, a comma list such as\n * `15, 18, 20, 25`. Whole percentages from 1 to 100, at most four, in the order\n * given; anything unreadable falls back to the defaults rather than showing\n * the customer an empty choice.\n */\nexport function posTipPercentages(raw: unknown): number[] {\n const parsed = String(raw ?? '')\n .split(/[,\\s]+/)\n .map((part) => Math.round(Number(part)))\n .filter((value) => Number.isFinite(value) && value >= 1 && value <= 100)\n const unique = [...new Set(parsed)].slice(0, 4)\n return unique.length ? unique : [...POS_TIP_PERCENTAGES_DEFAULT]\n}\n\n/** A percentage tip on `baseCents`, rounded to the cent. */\nexport function posTipFromPercent(baseCents: number, percent: number): number {\n const base = wholeCents(baseCents)\n const pct = Number(percent)\n if (!(base > 0) || !Number.isFinite(pct) || pct <= 0) return 0\n return Math.round((base * pct) / 100)\n}\n\n/** The largest tip the register accepts on one payment: the payment itself. */\nexport function posTipProblem(tipCents: number, amountCents: number): string | null {\n if (!Number.isInteger(tipCents) || tipCents < 0) return 'Enter a tip of $0 or more.'\n if (tipCents > wholeCents(amountCents)) {\n return 'A tip can be at most the amount being paid. Check the amount and try again.'\n }\n return null\n}\n\n/*==========================================\n * THE CUSTOMER DISPLAY (AGL-3608).\n *\n * A paired screen facing the customer reads one document per register,\n * `hosts/{hostId}/registers/{registerId}/display/state`, through the\n * `commerce/pos-display` route and its display token. The register writes\n * the prompt; the customer's answer comes back in `response`.\n *=========================================*/\n\nexport type PosDisplayMode =\n | 'idle'\n /** The live basket, mirrored as the cashier builds it. */\n | 'cart'\n /** The customer picks a tip. */\n | 'tip'\n /** The customer picks how they want their receipt. */\n | 'receipt'\n /** A card payment is waiting on the reader. */\n | 'processing'\n | 'thanks'\n /**\n * Another plugin's screen (AGL-4042), asked for through core's customer\n * display seam (`plugin-customer-display`): the display opens that\n * plugin's public page, which sends it back here when the customer is done.\n */\n | 'screen'\n\nexport type PosReceiptChannel = 'email' | 'sms' | 'print' | 'none'\n\nexport interface PosDisplayLine {\n name: string\n variantLabel?: string\n quantity: number\n amountCents: number\n}\n\nexport interface PosDisplayCart {\n lines: PosDisplayLine[]\n itemsCents: number\n discountCents: number\n taxCents: number\n totalCents: number\n /** Taken so far, and what is still due, once payments start. */\n paidCents?: number\n dueCents?: number\n tipCents?: number\n}\n\n/** The customer's answer to the current prompt. */\nexport interface PosDisplayResponse {\n /** The prompt this answers; a stale answer is refused. */\n promptId: string\n tipCents?: number\n tipPercent?: number\n /** `none` when the customer chose no tip. */\n tipChoice?: 'percent' | 'custom' | 'none'\n receiptChannel?: PosReceiptChannel\n email?: string\n phone?: string\n marketingOptIn?: boolean\n atMs: number\n}\n\nexport interface PosDisplayState {\n mode: PosDisplayMode\n updatedAtMs: number\n /**\n * The ISO currency every amount on the screen is in (`usd`). Stamped by\n * the server from the store's own currency, never taken from the register.\n */\n currency?: string\n /** Changes every time the register asks something new. */\n promptId?: string\n cart?: PosDisplayCart\n tip?: {\n /** What a percentage is taken of: the amount being paid now. */\n baseCents: number\n percentages: number[]\n allowCustom: boolean\n }\n receipt?: {\n channels: PosReceiptChannel[]\n /** Whether to offer the store's marketing opt-in under the email field. */\n offerMarketing: boolean\n }\n processing?: { message: string }\n /** The plugin page a `screen` state opens, as core's seam shapes it. */\n screen?: PosDisplayScreen\n /**\n * The staff member (uid) who put {@link screen} on the display (AGL-4042),\n * stamped by the server from the session that pushed it, never taken from\n * the register's body. Core's display verifier names them to the screen's\n * plugin, whose record of what the customer did there names who showed it.\n * Never sent to the display.\n */\n screenShownBy?: string\n response?: PosDisplayResponse\n}\n\n/**\n * A plugin's screen on the display (AGL-4042): the shape of core's\n * `CustomerDisplayScreen`, restated so this module imports nothing. The\n * server checks it with core's own sanitizer before it is stored.\n */\nexport interface PosDisplayScreen {\n pluginId: string\n path: string\n params: Record<string, string>\n}\n\n/** Most lines a display state carries; a longer basket shows its newest. */\nexport const POS_DISPLAY_MAX_LINES = 60\n\n/** A pairing code lives this long before the register must show a new one. */\nexport const POS_DISPLAY_PAIRING_TTL_MS = 10 * 60 * 1000\n\n/** A thank-you screen returns to idle on the display after this long. */\nexport const POS_DISPLAY_THANKS_MS = 8_000\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\n/** An email address as the display may store it, or '' when it is not one. */\nexport function posDisplayEmail(value: unknown): string {\n const email = String(value ?? '').trim().toLowerCase().slice(0, 254)\n return EMAIL_PATTERN.test(email) ? email : ''\n}\n\n/** A phone number as digits with an optional leading +, or '' when too short. */\nexport function posDisplayPhone(value: unknown): string {\n const raw = String(value ?? '').trim()\n const digits = raw.replace(/[^0-9]/g, '')\n if (digits.length < 7 || digits.length > 15) return ''\n return `${raw.startsWith('+') ? '+' : ''}${digits}`\n}\n\n/**\n * The display state as the REGISTER may send it: clamped, typed and stripped\n * of anything the customer screen has no business holding. The register is\n * staff and trusted for intent, not for shape.\n */\nexport function sanitizePosDisplayState(\n raw: unknown,\n nowMs: number,\n options: {\n /**\n * Checks a `screen` state's plugin page (core's\n * `sanitizeCustomerDisplayScreen`). Without it, or when it refuses, a\n * `screen` state is idle: nothing opens on the display unchecked.\n */\n screen?: (raw: unknown) => PosDisplayScreen | null\n } = {},\n): PosDisplayState {\n const input = (raw && typeof raw === 'object' ? raw : {}) as Record<string, any>\n const modes: PosDisplayMode[] = ['idle', 'cart', 'tip', 'receipt', 'processing', 'thanks', 'screen']\n const asked = modes.includes(input['mode']) ? (input['mode'] as PosDisplayMode) : 'idle'\n const promptId = String(input['promptId'] ?? '').slice(0, 64)\n // A screen opens once per prompt, so one without a prompt, or one the\n // checker refuses, opens nothing.\n const screen = asked === 'screen' && promptId && options.screen ? options.screen(input['screen']) : null\n const mode: PosDisplayMode = asked === 'screen' && !screen ? 'idle' : asked\n const state: PosDisplayState = { mode, updatedAtMs: nowMs }\n if (promptId) state.promptId = promptId\n if (mode === 'screen' && screen) state.screen = screen\n const cart = input['cart']\n if (cart && typeof cart === 'object' && mode !== 'idle') {\n const lines = (Array.isArray(cart.lines) ? cart.lines : [])\n .slice(-POS_DISPLAY_MAX_LINES)\n .map((line: any) => ({\n name: String(line?.name ?? '').slice(0, 120),\n ...(line?.variantLabel\n ? { variantLabel: String(line.variantLabel).slice(0, 80) }\n : {}),\n quantity: Math.max(1, Math.min(999, Math.round(Number(line?.quantity) || 1))),\n amountCents: wholeCents(line?.amountCents),\n }))\n state.cart = {\n lines,\n itemsCents: wholeCents(cart.itemsCents),\n discountCents: wholeCents(cart.discountCents),\n taxCents: wholeCents(cart.taxCents),\n totalCents: wholeCents(cart.totalCents),\n ...(cart.paidCents != null ? { paidCents: wholeCents(cart.paidCents) } : {}),\n ...(cart.dueCents != null ? { dueCents: wholeCents(cart.dueCents) } : {}),\n ...(cart.tipCents != null ? { tipCents: wholeCents(cart.tipCents) } : {}),\n }\n }\n if (mode === 'tip') {\n const tip = input['tip'] ?? {}\n state.tip = {\n baseCents: wholeCents(tip.baseCents),\n percentages: posTipPercentages(\n Array.isArray(tip.percentages) ? tip.percentages.join(',') : tip.percentages,\n ),\n allowCustom: tip.allowCustom !== false,\n }\n }\n if (mode === 'receipt') {\n const receipt = input['receipt'] ?? {}\n const allowed: PosReceiptChannel[] = ['email', 'sms', 'print', 'none']\n const channels = (Array.isArray(receipt.channels) ? receipt.channels : [])\n .filter((channel: unknown): channel is PosReceiptChannel =>\n allowed.includes(channel as PosReceiptChannel),\n )\n state.receipt = {\n channels: channels.length ? [...new Set<PosReceiptChannel>(channels)] : ['print', 'none'],\n offerMarketing: receipt.offerMarketing === true,\n }\n }\n if (mode === 'processing') {\n state.processing = {\n message:\n String(input['processing']?.message ?? '').slice(0, 160) ||\n 'Tap, insert or swipe your card on the reader.',\n }\n }\n return state\n}\n\n/**\n * The customer's answer as the DISPLAY may send it, checked against the\n * prompt it claims to answer. Returns null when it answers nothing the\n * register asked: a stale screen, a replay, or a mode that takes no answer.\n */\nexport function sanitizePosDisplayResponse(\n state: PosDisplayState | null | undefined,\n raw: unknown,\n nowMs: number,\n): PosDisplayResponse | null {\n if (!state || !state.promptId) return null\n const input = (raw && typeof raw === 'object' ? raw : {}) as Record<string, any>\n if (String(input['promptId'] ?? '') !== state.promptId) return null\n const response: PosDisplayResponse = { promptId: state.promptId, atMs: nowMs }\n if (state.mode === 'tip' && state.tip) {\n const choice = input['tipChoice']\n if (choice === 'none') {\n response.tipChoice = 'none'\n response.tipCents = 0\n } else if (choice === 'percent') {\n const percent = Math.round(Number(input['tipPercent']))\n if (!state.tip.percentages.includes(percent)) return null\n response.tipChoice = 'percent'\n response.tipPercent = percent\n response.tipCents = posTipFromPercent(state.tip.baseCents, percent)\n } else if (choice === 'custom' && state.tip.allowCustom) {\n const tipCents = Math.round(Number(input['tipCents']))\n if (posTipProblem(tipCents, state.tip.baseCents)) return null\n response.tipChoice = 'custom'\n response.tipCents = tipCents\n } else {\n return null\n }\n return response\n }\n if (state.mode === 'receipt' && state.receipt) {\n const channel = input['receiptChannel'] as PosReceiptChannel\n if (!state.receipt.channels.includes(channel)) return null\n response.receiptChannel = channel\n if (channel === 'email') {\n const email = posDisplayEmail(input['email'])\n if (!email) return null\n response.email = email\n if (state.receipt.offerMarketing && input['marketingOptIn'] === true) {\n response.marketingOptIn = true\n }\n }\n if (channel === 'sms') {\n const phone = posDisplayPhone(input['phone'])\n if (!phone) return null\n response.phone = phone\n }\n return response\n }\n return null\n}\n\n/**\n * The state as the DISPLAY reads it. The customer's own typed address is\n * never echoed back to the screen: once answered, the prompt is done and the\n * screen shows what comes next, so nothing a later customer could read off\n * an unattended tablet is ever sent to it.\n */\nexport function posDisplayPublicState(\n state: PosDisplayState | null | undefined,\n nowMs: number,\n): Omit<PosDisplayState, 'response' | 'screenShownBy'> & { answered: boolean } {\n if (!state) return { mode: 'idle', updatedAtMs: nowMs, answered: false }\n // Who showed a plugin's screen is the server's to know, not the display's.\n const { response, screenShownBy: _shownBy, ...rest } = state\n if (rest.mode === 'thanks' && nowMs - rest.updatedAtMs > POS_DISPLAY_THANKS_MS) {\n return { mode: 'idle', updatedAtMs: rest.updatedAtMs, answered: false }\n }\n return {\n ...rest,\n answered: Boolean(response && response.promptId === rest.promptId),\n }\n}\n"],"names":["ORDER_PAYMENT_METHODS","POS_CARD_METHODS","Set","isCardPaymentMethod","method","has","POS_FEE_FREE_METHODS","paymentCarriesPlatformFee","posTenderTakeCents","takeFeeCents","wholeCents","value","number","Math","round","Number","isFinite","orderPayments","order","Array","isArray","payments","filter","payment","Boolean","id","totalCents","totals","amountCents","settled","status","atMs","createdAtMs","reservationId","checkoutSessionId","paymentIntentId","channel","posSettledCents","reduce","sum","posReservedCents","posBalanceDueCents","max","posTenderableCents","posTipCents","tipCents","posTakeShareCents","input","take","total","amount","min","posPaymentTakeShareCents","posOwedTakeCents","every","carryingCents","posInvoiceTakeCents","netted","posFeeCollection","card","some","other","describeOrderPayment","dollars","cents","toFixed","label","creditLabel","ORDER_PAYMENT_METHOD_LABELS","cardBrand","last4","join","tip","cash","card_present","card_keyed","card_link","gift_card","folio","credit","POS_TIP_PERCENTAGES_DEFAULT","posTipPercentages","raw","parsed","String","split","map","part","unique","slice","length","posTipFromPercent","baseCents","percent","base","pct","posTipProblem","isInteger","POS_DISPLAY_MAX_LINES","POS_DISPLAY_PAIRING_TTL_MS","POS_DISPLAY_THANKS_MS","EMAIL_PATTERN","posDisplayEmail","email","trim","toLowerCase","test","posDisplayPhone","digits","replace","startsWith","sanitizePosDisplayState","nowMs","options","modes","asked","includes","promptId","screen","mode","state","updatedAtMs","cart","lines","line","name","variantLabel","quantity","itemsCents","discountCents","taxCents","paidCents","dueCents","percentages","allowCustom","receipt","allowed","channels","offerMarketing","processing","message","sanitizePosDisplayResponse","response","choice","tipChoice","tipPercent","receiptChannel","marketingOptIn","phone","posDisplayPublicState","answered","screenShownBy","_shownBy","rest"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;2CAgB2C,GAE3C,sDAAsD;;AA6BtD,OAAO,MAAMA,wBAAuD;IAClE;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAyDD,kDAAkD,GAClD,OAAO,MAAMC,mBAAoD,IAAIC,IAAI;IACvE;IACA;IACA;CACD,EAAC;AAEF,OAAO,SAASC,oBAAoBC,MAA0B;IAC5D,OAAOH,iBAAiBI,GAAG,CAACD;AAC9B;AAEA;;;;;;;;;;;;;;;;;;;;;;2CAsB2C,GAE3C,uDAAuD,GACvD,OAAO,MAAME,uBAAwD,IAAIJ,IAAI;IAC3E;IACA;IACA;CACD,EAAC;AAEF,4EAA4E,GAC5E,OAAO,SAASK,0BAA0BH,MAA0B;IAClE,OAAO,CAACE,qBAAqBD,GAAG,CAACD;AACnC;AAEA;;;CAGC,GACD,OAAO,SAASI,mBACdJ,MAA0B,EAC1BK,YAAoB;IAEpB,OAAOF,0BAA0BH,UAAUM,WAAWD,gBAAgB;AACxE;AAEA,sDAAsD,GACtD,SAASC,WAAWC,KAAc;IAChC,MAAMC,SAASC,KAAKC,KAAK,CAACC,OAAOJ;IACjC,OAAOI,OAAOC,QAAQ,CAACJ,WAAWA,SAAS,IAAIA,SAAS;AAC1D;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASK,cAAcC,KAU7B;;QAO+BA;IAN9B,IAAIC,MAAMC,OAAO,CAACF,yBAAAA,MAAOG,QAAQ,GAAG;QAClC,OAAOH,MAAMG,QAAQ,CAAC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b,IAAI,CAACQ,OAAO,OAAO;QAAED,MAAM;QAAQE,aAAaT;QAAOsC,UAAU;IAAM;IACvE,2EAA2E;IAC3E,MAAM,EAAER,QAAQ,EAAES,eAAeC,QAAQ,EAAW,GAAGhC,OAATiC,wCAASjC;;;;IACvD,IAAIiC,KAAKlC,IAAI,KAAK,YAAYP,QAAQyC,KAAKhC,WAAW,GAAGrB,uBAAuB;QAC9E,OAAO;YAAEmB,MAAM;YAAQE,aAAagC,KAAKhC,WAAW;YAAE6B,UAAU;QAAM;IACxE;IACA,OAAO,aACFG;QACHH,UAAU9H,QAAQsH,YAAYA,SAASzB,QAAQ,KAAKoC,KAAKpC,QAAQ;;AAErE"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-pos.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 POS TENDER LEDGER (AGL-3607).\n *\n * A register sale used to be settled by exactly one tender and recorded none:\n * whether a POS order was paid in cash, by the QR link or to a room was\n * inferred afterwards from which other fields happened to be set. A sale now\n * carries `payments[]`, one entry per tender, and takes payments until the\n * balance due is zero. Only then is it `paid`.\n *\n * Every figure here is integer cents. `amountCents` is what a payment put\n * toward the SALE; a tip rides beside it in `tipCents` and never counts toward\n * the balance, the platform's take or the store's revenue. Tips belong to the\n * merchant and their staff.\n *\n * Pure and framework-free, so the register, the customer display and the\n * server read one answer.\n *=========================================*/\n\n/** How one payment toward a register sale was taken. */\nexport type OrderPaymentMethod =\n | 'cash'\n /** A Stripe Terminal smart reader (tap, insert or swipe). */\n | 'card_present'\n /** A card typed into the console by staff (card not present). */\n | 'card_keyed'\n /** The Stripe payment page the customer opens from a QR code. */\n | 'card_link'\n | 'gift_card'\n /** Charged to a checked-in reservation's folio. */\n | 'folio'\n /**\n * Store credit another plugin keeps — rewards, referral credit — taken\n * through core's checkout-credits seam (AGL-3640). Which plugin and which\n * account ride on the payment as `creditProviderId` and `creditReference`.\n */\n | 'credit'\n\nexport type OrderPaymentStatus =\n /** Started and not finished: reserves its amount against the balance. */\n | 'pending'\n | 'succeeded'\n /** Declined or errored; may be retried, reserves nothing. */\n | 'failed'\n | 'canceled'\n /** Taken and then handed back when the open sale was voided. */\n | 'reversed'\n\nexport const ORDER_PAYMENT_METHODS: readonly OrderPaymentMethod[] = [\n 'cash',\n 'card_present',\n 'card_keyed',\n 'card_link',\n 'gift_card',\n 'folio',\n 'credit',\n]\n\n/** One payment toward a register sale, on `HostOrder.payments`. */\nexport interface OrderPayment {\n /** Stable id, derived from the register's attempt key so a retry finds it. */\n id: string\n method: OrderPaymentMethod\n /** Cents put toward the sale. Never includes the tip. */\n amountCents: number\n /** Gratuity on top of `amountCents`, the merchant's and not revenue. */\n tipCents?: number\n status: OrderPaymentStatus\n /** When the payment was started. */\n atMs: number\n /** When it reached `succeeded`. */\n settledAtMs?: number\n /** Stripe PaymentIntent for `card_present` / `card_keyed` / a paid link. */\n paymentIntentId?: string\n /** Stripe Checkout Session for `card_link`. */\n checkoutSessionId?: string\n /** The payment page a `card_link` payment shows as a QR. */\n checkoutUrl?: string\n /** The Terminal reader a `card_present` payment runs on. */\n readerId?: string\n /** The gift card's code (its document id) for `gift_card`. */\n giftCardId?: string\n /** For `credit`: the provider that paid it (`{pluginId}.{key}`, AGL-3640). */\n creditProviderId?: string\n /** For `credit`: the provider's own handle on the account it came from. */\n creditReference?: string\n /** For `credit`: what the provider calls it, for the register and receipt. */\n creditLabel?: string\n cardBrand?: string\n last4?: string\n /** Cash handed over for a `cash` payment, and the change given back. */\n cashTenderedCents?: number\n changeCents?: number\n /** The stay a `folio` payment was charged to. */\n reservationId?: string\n /** The folio entry's `atMs`, so a void can remove exactly that entry. */\n folioAtMs?: number\n /**\n * The platform's take attributed to this payment (excludes the tip). For a\n * card payment it is netted from the payout with Stripe's processing cost\n * added, and recorded in `feeCents`; otherwise it accrues to the invoice.\n */\n takeFeeCents?: number\n /** The `application_fee_amount` a card payment carried, or 0. */\n feeCents?: number\n /** Why a `failed` payment failed, in words the cashier can read out. */\n failureMessage?: string\n /** Whether Stripe moved real money; absent for tenders Stripe never saw. */\n livemode?: boolean\n /**\n * `direct` when the card was charged ON the store's own Stripe account\n * (ToS v24 section 10.2(a)), with that account in `stripeAccountId`: its\n * capture, cancel and refund are made there. Absent for a destination\n * charge on the platform, every register payment before the switch.\n */\n chargeModel?: 'direct'\n stripeAccountId?: string\n /** The console user who took the payment. */\n cashierId?: string\n}\n\n/** The tenders whose money moves through Stripe. */\nexport const POS_CARD_METHODS: ReadonlySet<OrderPaymentMethod> = new Set([\n 'card_present',\n 'card_keyed',\n 'card_link',\n])\n\nexport function isCardPaymentMethod(method: OrderPaymentMethod): boolean {\n return POS_CARD_METHODS.has(method)\n}\n\n/*==========================================\n * WHICH TENDERS CARRY THE PLATFORM FEE (AGL-4036).\n *\n * The take used to follow the sale whatever paid it (AGL-2111): a cash sale\n * owed the same percentage as a card sale and had it added to the monthly\n * invoice. In-person rivals charge nothing on cash, and an event register that\n * bills its operator for the cash in their own apron is not one they will\n * choose, so three tenders now carry none:\n *\n * - cash: no payment service touches it, and the merchant keeps all of it;\n * - gift card: the fee was taken when the card was SOLD, so charging it again\n * when the card is spent would charge the same money twice;\n * - store credit (`credit`): rewards or referral value the merchant gave\n * away, so no money changes hands and an invoiced fee on it would only\n * penalize running a rewards program.\n *\n * Everything else still carries it. Card payments net it from their payout,\n * as always. A room charge (`folio`) is new revenue booked to a stay, so its\n * share goes on the invoice.\n *\n * One predicate, so the register, the completion, the offline sync and the\n * docs cannot disagree about which tender is which.\n *=========================================*/\n\n/** The tenders that carry no platform fee (AGL-4036). */\nexport const POS_FEE_FREE_METHODS: ReadonlySet<OrderPaymentMethod> = new Set([\n 'cash',\n 'gift_card',\n 'credit',\n])\n\n/** Whether a payment by `method` carries its share of the platform's take. */\nexport function paymentCarriesPlatformFee(method: OrderPaymentMethod): boolean {\n return !POS_FEE_FREE_METHODS.has(method)\n}\n\n/**\n * The take a sale owes when ONE tender pays all of it: the whole take, or\n * nothing for a fee-free tender.\n */\nexport function posTenderTakeCents(\n method: OrderPaymentMethod,\n takeFeeCents: number,\n): number {\n return paymentCarriesPlatformFee(method) ? wholeCents(takeFeeCents) : 0\n}\n\n/** Whole non-negative cents from an untrusted value. */\nfunction wholeCents(value: unknown): number {\n const number = Math.round(Number(value))\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/**\n * The order's payments, read through one door.\n *\n * Orders written before the ledger existed carry no `payments`, so one is\n * INFERRED from the fields the single-tender register wrote: a folio sale has\n * `reservationId`, a QR sale has `checkoutSessionId`, and anything else on the\n * POS channel was cash. A pending legacy sale is the QR link still waiting.\n * Online orders paid through Stripe Checkout read as one `card_link` payment.\n * Nothing is written back: this is a reader, never a migration.\n */\nexport function orderPayments(order: {\n payments?: OrderPayment[] | null\n channel?: string\n status?: string\n totals?: { totalCents?: number; tipCents?: number } | null\n amountCents?: number\n reservationId?: string\n checkoutSessionId?: string\n paymentIntentId?: string\n createdAtMs?: number\n}): OrderPayment[] {\n if (Array.isArray(order?.payments)) {\n return order.payments.filter(\n (payment): payment is OrderPayment =>\n Boolean(payment) && typeof payment === 'object' && Boolean(payment.id),\n )\n }\n const totalCents = wholeCents(order?.totals?.totalCents ?? order?.amountCents)\n if (!(totalCents > 0)) return []\n const settled = order?.status !== 'pending' && order?.status !== 'cancelled'\n const atMs = Number(order?.createdAtMs) || 0\n const method: OrderPaymentMethod = order?.reservationId\n ? 'folio'\n : order?.checkoutSessionId || order?.paymentIntentId || order?.channel !== 'pos'\n ? 'card_link'\n : 'cash'\n return [\n {\n id: 'legacy',\n method,\n amountCents: totalCents,\n status: settled ? 'succeeded' : order?.status === 'cancelled' ? 'canceled' : 'pending',\n atMs,\n ...(order?.paymentIntentId ? { paymentIntentId: order.paymentIntentId } : {}),\n ...(order?.checkoutSessionId ? { checkoutSessionId: order.checkoutSessionId } : {}),\n ...(order?.reservationId ? { reservationId: order.reservationId } : {}),\n },\n ]\n}\n\n/** Cents put toward the sale by payments that succeeded. */\nexport function posSettledCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded')\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n}\n\n/**\n * Cents spoken for: succeeded payments plus the ones still in flight. A\n * reader waiting for a tap has claimed its share of the balance, so a second\n * tender cannot be started for the same money.\n */\nexport function posReservedCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded' || payment.status === 'pending')\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n}\n\n/** What the customer still owes, by settled payments. */\nexport function posBalanceDueCents(\n totalCents: number,\n payments: readonly OrderPayment[],\n): number {\n return Math.max(0, wholeCents(totalCents) - posSettledCents(payments))\n}\n\n/** What a NEW payment may still take: the balance less what is in flight. */\nexport function posTenderableCents(\n totalCents: number,\n payments: readonly OrderPayment[],\n): number {\n return Math.max(0, wholeCents(totalCents) - posReservedCents(payments))\n}\n\n/** Tips taken across the sale's settled payments. */\nexport function posTipCents(payments: readonly OrderPayment[]): number {\n return payments\n .filter((payment) => payment.status === 'succeeded')\n .reduce((sum, payment) => sum + wholeCents(payment.tipCents), 0)\n}\n\n/**\n * The share of the sale's take a payment of `amountCents` carries.\n *\n * Proportional to the part of the SALE it pays, never to the tip. Card\n * payments carry their share in `application_fee_amount`; whatever the card\n * shares leave is accrued to the invoice at completion\n * ({@link posInvoiceTakeCents}), so the take is exact however the sale was\n * split and however each share rounded.\n */\nexport function posTakeShareCents(input: {\n takeFeeCents: number\n totalCents: number\n amountCents: number\n}): number {\n const take = wholeCents(input.takeFeeCents)\n const total = wholeCents(input.totalCents)\n const amount = Math.min(wholeCents(input.amountCents), total)\n if (!(take > 0) || !(total > 0) || !(amount > 0)) return 0\n return Math.min(take, Math.round((take * amount) / total))\n}\n\n/**\n * {@link posTakeShareCents} for a payment by `method`: its share of the take,\n * or 0 for a tender that carries no platform fee (AGL-4036).\n */\nexport function posPaymentTakeShareCents(input: {\n method: OrderPaymentMethod\n takeFeeCents: number\n totalCents: number\n amountCents: number\n}): number {\n if (!paymentCarriesPlatformFee(input.method)) return 0\n return posTakeShareCents(input)\n}\n\n/**\n * The part of the sale's take its tenders owe (AGL-4036): the whole take when\n * every settled payment carries the fee, and otherwise the share for the part\n * of the sale the fee-carrying payments paid. Cash and gift-card parts owe\n * nothing, so a sale paid all in cash owes 0.\n *\n * Worked from the payments' METHODS, not from the `takeFeeCents` each one\n * recorded, so a sale that was opened before this rule and finished after it\n * is charged by the rule it finished under.\n */\nexport function posOwedTakeCents(input: {\n takeFeeCents: number\n totalCents: number\n payments: readonly OrderPayment[]\n}): number {\n const take = wholeCents(input.takeFeeCents)\n const settled = input.payments.filter((payment) => payment.status === 'succeeded')\n if (settled.every((payment) => paymentCarriesPlatformFee(payment.method))) return take\n const carryingCents = settled\n .filter((payment) => paymentCarriesPlatformFee(payment.method))\n .reduce((sum, payment) => sum + wholeCents(payment.amountCents), 0)\n return posTakeShareCents({\n takeFeeCents: take,\n totalCents: input.totalCents,\n amountCents: carryingCents,\n })\n}\n\n/**\n * What of the sale's take was NOT netted from a card payout, and therefore\n * goes on the merchant's invoice: the take the tenders owe\n * ({@link posOwedTakeCents}) less every succeeded card payment's share. Never\n * negative, and 0 for a sale paid only by card, cash, gift card and store credit.\n */\nexport function posInvoiceTakeCents(input: {\n takeFeeCents: number\n totalCents: number\n payments: readonly OrderPayment[]\n}): number {\n const netted = input.payments\n .filter(\n (payment) =>\n payment.status === 'succeeded' && isCardPaymentMethod(payment.method),\n )\n .reduce((sum, payment) => sum + wholeCents(payment.takeFeeCents), 0)\n return Math.max(0, posOwedTakeCents(input) - netted)\n}\n\n/**\n * How the sale's fee reaches the platform, from the payments that carried it.\n * A cash, gift-card or store-credit part carries none (AGL-4036), so a card + cash sale is\n * `payout`, not `split`.\n */\nexport function posFeeCollection(\n payments: readonly OrderPayment[],\n): 'payout' | 'invoice' | 'split' {\n const settled = payments.filter(\n (payment) =>\n payment.status === 'succeeded' && paymentCarriesPlatformFee(payment.method),\n )\n const card = settled.some((payment) => isCardPaymentMethod(payment.method))\n const other = settled.some((payment) => !isCardPaymentMethod(payment.method))\n if (card && other) return 'split'\n return card ? 'payout' : 'invoice'\n}\n\n/** A one-line description of a payment for the register, receipt and timeline. */\nexport function describeOrderPayment(payment: OrderPayment): string {\n const dollars = (cents: number) => `$${(cents / 100).toFixed(2)}`\n const label =\n (payment.method === 'credit' && payment.creditLabel) || ORDER_PAYMENT_METHOD_LABELS[payment.method] || 'Payment'\n const card =\n payment.cardBrand || payment.last4\n ? ` (${[payment.cardBrand, payment.last4 ? `•••• ${payment.last4}` : '']\n .filter(Boolean)\n .join(' ')})`\n : ''\n const tip = wholeCents(payment.tipCents)\n ? ` + ${dollars(wholeCents(payment.tipCents))} tip`\n : ''\n return `${label}${card} ${dollars(wholeCents(payment.amountCents))}${tip}`\n}\n\nexport const ORDER_PAYMENT_METHOD_LABELS: Record<OrderPaymentMethod, string> = {\n cash: 'Cash',\n card_present: 'Card reader',\n card_keyed: 'Typed card',\n card_link: 'Card (QR)',\n gift_card: 'Gift card',\n folio: 'Charged to room',\n credit: 'Store credit',\n}\n\n/*==========================================\n * TIPS (AGL-3607).\n *=========================================*/\n\n/** The presets a merchant starts with. */\nexport const POS_TIP_PERCENTAGES_DEFAULT: readonly number[] = [15, 18, 20, 25]\n\n/**\n * The merchant's tip presets from the plugin setting, a comma list such as\n * `15, 18, 20, 25`. Whole percentages from 1 to 100, at most four, in the order\n * given; anything unreadable falls back to the defaults rather than showing\n * the customer an empty choice.\n */\nexport function posTipPercentages(raw: unknown): number[] {\n const parsed = String(raw ?? '')\n .split(/[,\\s]+/)\n .map((part) => Math.round(Number(part)))\n .filter((value) => Number.isFinite(value) && value >= 1 && value <= 100)\n const unique = [...new Set(parsed)].slice(0, 4)\n return unique.length ? unique : [...POS_TIP_PERCENTAGES_DEFAULT]\n}\n\n/** A percentage tip on `baseCents`, rounded to the cent. */\nexport function posTipFromPercent(baseCents: number, percent: number): number {\n const base = wholeCents(baseCents)\n const pct = Number(percent)\n if (!(base > 0) || !Number.isFinite(pct) || pct <= 0) return 0\n return Math.round((base * pct) / 100)\n}\n\n/** The largest tip the register accepts on one payment: the payment itself. */\nexport function posTipProblem(tipCents: number, amountCents: number): string | null {\n if (!Number.isInteger(tipCents) || tipCents < 0) return 'Enter a tip of $0 or more.'\n if (tipCents > wholeCents(amountCents)) {\n return 'A tip can be at most the amount being paid. Check the amount and try again.'\n }\n return null\n}\n\n/*==========================================\n * THE CUSTOMER DISPLAY (AGL-3608).\n *\n * A paired screen facing the customer reads one document per register,\n * `hosts/{hostId}/registers/{registerId}/display/state`, through the\n * `commerce/pos-display` route and its display token. The register writes\n * the prompt; the customer's answer comes back in `response`.\n *=========================================*/\n\nexport type PosDisplayMode =\n | 'idle'\n /** The live basket, mirrored as the cashier builds it. */\n | 'cart'\n /** The customer picks a tip. */\n | 'tip'\n /** The customer picks how they want their receipt. */\n | 'receipt'\n /** A card payment is waiting on the reader. */\n | 'processing'\n | 'thanks'\n /**\n * Another plugin's screen (AGL-4042), asked for through core's customer\n * display seam (`plugin-customer-display`): the display opens that\n * plugin's public page, which sends it back here when the customer is done.\n */\n | 'screen'\n\nexport type PosReceiptChannel = 'email' | 'sms' | 'print' | 'none'\n\nexport interface PosDisplayLine {\n name: string\n variantLabel?: string\n quantity: number\n amountCents: number\n}\n\nexport interface PosDisplayCart {\n lines: PosDisplayLine[]\n itemsCents: number\n discountCents: number\n taxCents: number\n totalCents: number\n /** Taken so far, and what is still due, once payments start. */\n paidCents?: number\n dueCents?: number\n tipCents?: number\n}\n\n/** The customer's answer to the current prompt. */\nexport interface PosDisplayResponse {\n /** The prompt this answers; a stale answer is refused. */\n promptId: string\n tipCents?: number\n tipPercent?: number\n /** `none` when the customer chose no tip. */\n tipChoice?: 'percent' | 'custom' | 'none'\n receiptChannel?: PosReceiptChannel\n email?: string\n phone?: string\n marketingOptIn?: boolean\n atMs: number\n}\n\nexport interface PosDisplayState {\n mode: PosDisplayMode\n updatedAtMs: number\n /**\n * The ISO currency every amount on the screen is in (`usd`). Stamped by\n * the server from the store's own currency, never taken from the register.\n */\n currency?: string\n /** Changes every time the register asks something new. */\n promptId?: string\n cart?: PosDisplayCart\n tip?: {\n /** What a percentage is taken of: the amount being paid now. */\n baseCents: number\n percentages: number[]\n allowCustom: boolean\n }\n receipt?: {\n channels: PosReceiptChannel[]\n /** Whether to offer the store's marketing opt-in under the email field. */\n offerMarketing: boolean\n }\n processing?: { message: string }\n /** The plugin page a `screen` state opens, as core's seam shapes it. */\n screen?: PosDisplayScreen\n /**\n * The staff member (uid) who put {@link screen} on the display (AGL-4042),\n * stamped by the server from the session that pushed it, never taken from\n * the register's body. Core's display verifier names them to the screen's\n * plugin, whose record of what the customer did there names who showed it.\n * Never sent to the display.\n */\n screenShownBy?: string\n response?: PosDisplayResponse\n}\n\n/**\n * A plugin's screen on the display (AGL-4042): the shape of core's\n * `CustomerDisplayScreen`, restated so this module imports nothing. The\n * server checks it with core's own sanitizer before it is stored.\n */\nexport interface PosDisplayScreen {\n pluginId: string\n path: string\n params: Record<string, string>\n}\n\n/** Most lines a display state carries; a longer basket shows its newest. */\nexport const POS_DISPLAY_MAX_LINES = 60\n\n/** A pairing code lives this long before the register must show a new one. */\nexport const POS_DISPLAY_PAIRING_TTL_MS = 10 * 60 * 1000\n\n/** A thank-you screen returns to idle on the display after this long. */\nexport const POS_DISPLAY_THANKS_MS = 8_000\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\n/** An email address as the display may store it, or '' when it is not one. */\nexport function posDisplayEmail(value: unknown): string {\n const email = String(value ?? '').trim().toLowerCase().slice(0, 254)\n return EMAIL_PATTERN.test(email) ? email : ''\n}\n\n/** A phone number as digits with an optional leading +, or '' when too short. */\nexport function posDisplayPhone(value: unknown): string {\n const raw = String(value ?? '').trim()\n const digits = raw.replace(/[^0-9]/g, '')\n if (digits.length < 7 || digits.length > 15) return ''\n return `${raw.startsWith('+') ? '+' : ''}${digits}`\n}\n\n/**\n * The display state as the REGISTER may send it: clamped, typed and stripped\n * of anything the customer screen has no business holding. The register is\n * staff and trusted for intent, not for shape.\n */\nexport function sanitizePosDisplayState(\n raw: unknown,\n nowMs: number,\n options: {\n /**\n * Checks a `screen` state's plugin page (core's\n * `sanitizeCustomerDisplayScreen`). Without it, or when it refuses, a\n * `screen` state is idle: nothing opens on the display unchecked.\n */\n screen?: (raw: unknown) => PosDisplayScreen | null\n } = {},\n): PosDisplayState {\n const input = (raw && typeof raw === 'object' ? raw : {}) as Record<string, any>\n const modes: PosDisplayMode[] = ['idle', 'cart', 'tip', 'receipt', 'processing', 'thanks', 'screen']\n const asked = modes.includes(input['mode']) ? (input['mode'] as PosDisplayMode) : 'idle'\n const promptId = String(input['promptId'] ?? '').slice(0, 64)\n // A screen opens once per prompt, so one without a prompt, or one the\n // checker refuses, opens nothing.\n const screen = asked === 'screen' && promptId && options.screen ? options.screen(input['screen']) : null\n const mode: PosDisplayMode = asked === 'screen' && !screen ? 'idle' : asked\n const state: PosDisplayState = { mode, updatedAtMs: nowMs }\n if (promptId) state.promptId = promptId\n if (mode === 'screen' && screen) state.screen = screen\n const cart = input['cart']\n if (cart && typeof cart === 'object' && mode !== 'idle') {\n const lines = (Array.isArray(cart.lines) ? cart.lines : [])\n .slice(-POS_DISPLAY_MAX_LINES)\n .map((line: any) => ({\n name: String(line?.name ?? '').slice(0, 120),\n ...(line?.variantLabel\n ? { variantLabel: String(line.variantLabel).slice(0, 80) }\n : {}),\n quantity: Math.max(1, Math.min(999, Math.round(Number(line?.quantity) || 1))),\n amountCents: wholeCents(line?.amountCents),\n }))\n state.cart = {\n lines,\n itemsCents: wholeCents(cart.itemsCents),\n discountCents: wholeCents(cart.discountCents),\n taxCents: wholeCents(cart.taxCents),\n totalCents: wholeCents(cart.totalCents),\n ...(cart.paidCents != null ? { paidCents: wholeCents(cart.paidCents) } : {}),\n ...(cart.dueCents != null ? { dueCents: wholeCents(cart.dueCents) } : {}),\n ...(cart.tipCents != null ? { tipCents: wholeCents(cart.tipCents) } : {}),\n }\n }\n if (mode === 'tip') {\n const tip = input['tip'] ?? {}\n state.tip = {\n baseCents: wholeCents(tip.baseCents),\n percentages: posTipPercentages(\n Array.isArray(tip.percentages) ? tip.percentages.join(',') : tip.percentages,\n ),\n allowCustom: tip.allowCustom !== false,\n }\n }\n if (mode === 'receipt') {\n const receipt = input['receipt'] ?? {}\n const allowed: PosReceiptChannel[] = ['email', 'sms', 'print', 'none']\n const channels = (Array.isArray(receipt.channels) ? receipt.channels : [])\n .filter((channel: unknown): channel is PosReceiptChannel =>\n allowed.includes(channel as PosReceiptChannel),\n )\n state.receipt = {\n channels: channels.length ? [...new Set<PosReceiptChannel>(channels)] : ['print', 'none'],\n offerMarketing: receipt.offerMarketing === true,\n }\n }\n if (mode === 'processing') {\n state.processing = {\n message:\n String(input['processing']?.message ?? '').slice(0, 160) ||\n 'Tap, insert or swipe your card on the reader.',\n }\n }\n return state\n}\n\n/**\n * The customer's answer as the DISPLAY may send it, checked against the\n * prompt it claims to answer. Returns null when it answers nothing the\n * register asked: a stale screen, a replay, or a mode that takes no answer.\n */\nexport function sanitizePosDisplayResponse(\n state: PosDisplayState | null | undefined,\n raw: unknown,\n nowMs: number,\n): PosDisplayResponse | null {\n if (!state || !state.promptId) return null\n const input = (raw && typeof raw === 'object' ? raw : {}) as Record<string, any>\n if (String(input['promptId'] ?? '') !== state.promptId) return null\n const response: PosDisplayResponse = { promptId: state.promptId, atMs: nowMs }\n if (state.mode === 'tip' && state.tip) {\n const choice = input['tipChoice']\n if (choice === 'none') {\n response.tipChoice = 'none'\n response.tipCents = 0\n } else if (choice === 'percent') {\n const percent = Math.round(Number(input['tipPercent']))\n if (!state.tip.percentages.includes(percent)) return null\n response.tipChoice = 'percent'\n response.tipPercent = percent\n response.tipCents = posTipFromPercent(state.tip.baseCents, percent)\n } else if (choice === 'custom' && state.tip.allowCustom) {\n const tipCents = Math.round(Number(input['tipCents']))\n if (posTipProblem(tipCents, state.tip.baseCents)) return null\n response.tipChoice = 'custom'\n response.tipCents = tipCents\n } else {\n return null\n }\n return response\n }\n if (state.mode === 'receipt' && state.receipt) {\n const channel = input['receiptChannel'] as PosReceiptChannel\n if (!state.receipt.channels.includes(channel)) return null\n response.receiptChannel = channel\n if (channel === 'email') {\n const email = posDisplayEmail(input['email'])\n if (!email) return null\n response.email = email\n if (state.receipt.offerMarketing && input['marketingOptIn'] === true) {\n response.marketingOptIn = true\n }\n }\n if (channel === 'sms') {\n const phone = posDisplayPhone(input['phone'])\n if (!phone) return null\n response.phone = phone\n }\n return response\n }\n return null\n}\n\n/**\n * The state as the DISPLAY reads it. The customer's own typed address is\n * never echoed back to the screen: once answered, the prompt is done and the\n * screen shows what comes next, so nothing a later customer could read off\n * an unattended tablet is ever sent to it.\n */\nexport function posDisplayPublicState(\n state: PosDisplayState | null | undefined,\n nowMs: number,\n): Omit<PosDisplayState, 'response' | 'screenShownBy'> & { answered: boolean } {\n if (!state) return { mode: 'idle', updatedAtMs: nowMs, answered: false }\n // Who showed a plugin's screen is the server's to know, not the display's.\n const { response, screenShownBy: _shownBy, ...rest } = state\n if (rest.mode === 'thanks' && nowMs - rest.updatedAtMs > POS_DISPLAY_THANKS_MS) {\n return { mode: 'idle', updatedAtMs: rest.updatedAtMs, answered: false }\n }\n return {\n ...rest,\n answered: Boolean(response && response.promptId === rest.promptId),\n }\n}\n"],"names":["ORDER_PAYMENT_METHODS","POS_CARD_METHODS","Set","isCardPaymentMethod","method","has","POS_FEE_FREE_METHODS","paymentCarriesPlatformFee","posTenderTakeCents","takeFeeCents","wholeCents","value","number","Math","round","Number","isFinite","orderPayments","order","Array","isArray","payments","filter","payment","Boolean","id","totalCents","totals","amountCents","settled","status","atMs","createdAtMs","reservationId","checkoutSessionId","paymentIntentId","channel","posSettledCents","reduce","sum","posReservedCents","posBalanceDueCents","max","posTenderableCents","posTipCents","tipCents","posTakeShareCents","input","take","total","amount","min","posPaymentTakeShareCents","posOwedTakeCents","every","carryingCents","posInvoiceTakeCents","netted","posFeeCollection","card","some","other","describeOrderPayment","dollars","cents","toFixed","label","creditLabel","ORDER_PAYMENT_METHOD_LABELS","cardBrand","last4","join","tip","cash","card_present","card_keyed","card_link","gift_card","folio","credit","POS_TIP_PERCENTAGES_DEFAULT","posTipPercentages","raw","parsed","String","split","map","part","unique","slice","length","posTipFromPercent","baseCents","percent","base","pct","posTipProblem","isInteger","POS_DISPLAY_MAX_LINES","POS_DISPLAY_PAIRING_TTL_MS","POS_DISPLAY_THANKS_MS","EMAIL_PATTERN","posDisplayEmail","email","trim","toLowerCase","test","posDisplayPhone","digits","replace","startsWith","sanitizePosDisplayState","nowMs","options","modes","asked","includes","promptId","screen","mode","state","updatedAtMs","cart","lines","line","name","variantLabel","quantity","itemsCents","discountCents","taxCents","paidCents","dueCents","percentages","allowCustom","receipt","allowed","channels","offerMarketing","processing","message","sanitizePosDisplayResponse","response","choice","tipChoice","tipPercent","receiptChannel","marketingOptIn","phone","posDisplayPublicState","answered","screenShownBy","_shownBy","rest"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;2CAgB2C,GAE3C,sDAAsD;;AA6BtD,OAAO,MAAMA,wBAAuD;IAClE;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAiED,kDAAkD,GAClD,OAAO,MAAMC,mBAAoD,IAAIC,IAAI;IACvE;IACA;IACA;CACD,EAAC;AAEF,OAAO,SAASC,oBAAoBC,MAA0B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* you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type HostOrder } from './commerce-orders';
18
+ import { type QuoteEmailThread } from './commerce-quotes';
19
+ /** The catalog email a reply from the quote goes out as. */
20
+ export declare const QUOTE_MESSAGE_EMAIL_KEY = "quote-message";
21
+ /** The longest message either side may send. */
22
+ export declare const QUOTE_MESSAGE_MAX = 5000;
23
+ /** The most messages a page or the console lists, newest kept. */
24
+ export declare const QUOTE_MESSAGES_SHOWN = 50;
25
+ /** One message in a quote's conversation, as stored. */
26
+ export interface QuoteMessage {
27
+ direction: 'out' | 'in';
28
+ body: string;
29
+ atMs: number;
30
+ /** The revision the quote was on when it was said. */
31
+ revision: number;
32
+ /** With `out`: who on the team sent it, an email else a uid. */
33
+ by?: string;
34
+ /** With `out`: the address it went to. */
35
+ to?: string;
36
+ /** With `out`: the `Message-ID` it was sent with, and the provider's own id. */
37
+ messageId?: string;
38
+ providerId?: string | null;
39
+ /** With `in`: the name on the quote when the customer wrote. */
40
+ name?: string;
41
+ /** With `in`: the address and browser it came from, kept as the record. */
42
+ ip?: string | null;
43
+ userAgent?: string | null;
44
+ }
45
+ /** A message as typed, trimmed, or what to fix. */
46
+ export declare function parseQuoteMessageBody(raw: unknown): {
47
+ ok: true;
48
+ body: string;
49
+ } | {
50
+ ok: false;
51
+ error: string;
52
+ };
53
+ /** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */
54
+ export declare function quoteReplyRecipient(order: Pick<HostOrder, 'quote'> | null | undefined): string;
55
+ export type QuoteReplyRefusal = 'not-a-quote' | 'no-address' | 'bad-address';
56
+ /** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */
57
+ export declare function quoteReplyRefusal(order: Pick<HostOrder, 'channel' | 'quote'> | null | undefined): QuoteReplyRefusal | null;
58
+ export declare function quoteReplyRefusalMessage(reason: QuoteReplyRefusal): string;
59
+ /**
60
+ * The quote after a reply went out: the conversation moved on to it, so the
61
+ * next email answers it, and the timeline says who wrote to whom. Nothing the
62
+ * customer sees changes, so the quote's edit stamp stays.
63
+ */
64
+ export declare function quoteAfterReply(order: HostOrder, sent: {
65
+ to: string;
66
+ by: string;
67
+ atMs: number;
68
+ }, thread: QuoteEmailThread): HostOrder;
69
+ /** A message as the customer's page shows it: who said it and what, never an address, browser or team member. */
70
+ export interface QuotePageMessage {
71
+ id: string;
72
+ from: 'business' | 'customer';
73
+ body: string;
74
+ atMs: number;
75
+ }
76
+ /** The stored messages, oldest first, as the page may show them. */
77
+ export declare function quotePageMessages(entries: ReadonlyArray<{
78
+ id: string;
79
+ data: Partial<QuoteMessage> | undefined;
80
+ }>): QuotePageMessage[];
81
+ /** A message as the console lists it. */
82
+ export interface QuoteConsoleMessage {
83
+ id: string;
84
+ direction: 'out' | 'in';
85
+ body: string;
86
+ atMs: number;
87
+ /** `to jordan@example.com by sam@shop.test`, or `Jordan Lee wrote on the quote page`. */
88
+ label: string;
89
+ }
90
+ /** The stored messages, oldest first, as the team reads them. */
91
+ export declare function quoteConsoleMessages(entries: ReadonlyArray<{
92
+ id: string;
93
+ data: Partial<QuoteMessage> | undefined;
94
+ }>): QuoteConsoleMessage[];
95
+ /** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */
96
+ export declare function quoteMessageEmailTokens(input: {
97
+ order: HostOrder;
98
+ quoteId: string;
99
+ businessName: string;
100
+ subject: string;
101
+ body: string;
102
+ url: string;
103
+ }): {
104
+ tokens: Record<string, string>;
105
+ text: string;
106
+ };
@@ -0,0 +1,146 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { appendOrderEvent } from "./commerce-orders.js";
18
+ import { quoteSendPrefill } from "./commerce-quote-email.js";
19
+ import { formatQuoteNumber, isQuote, quoteIsProofOnly } from "./commerce-quotes.js";
20
+ /*==========================================
21
+ * A QUOTE'S CONVERSATION (AGL-4207): what the business and its customer say
22
+ * to each other about one quote, kept under it at
23
+ * `hosts/{hostId}/orders/{quoteId}/messages/{id}`, so it stays through every
24
+ * revision and after the quote is paid.
25
+ *
26
+ * - `out`: a reply the business sent from the quote. It went by email, in
27
+ * the quote's own conversation in the customer's mailbox
28
+ * (`quote.emailThread`), under the `quote-message` catalog email.
29
+ * - `in`: what the customer wrote on the quote page. The business is told
30
+ * in Aglyn and by email.
31
+ *
32
+ * Nothing receives mail: a customer who answers an email reaches the
33
+ * business's own mailbox (its Reply-To), as an Inbox reply's answer does.
34
+ *=========================================*/ /** The catalog email a reply from the quote goes out as. */ export const QUOTE_MESSAGE_EMAIL_KEY = 'quote-message';
35
+ /** The longest message either side may send. */ export const QUOTE_MESSAGE_MAX = 5000;
36
+ /** The most messages a page or the console lists, newest kept. */ export const QUOTE_MESSAGES_SHOWN = 50;
37
+ /** A message as typed, trimmed, or what to fix. */ export function parseQuoteMessageBody(raw) {
38
+ const body = typeof raw === 'string' ? raw.replace(/\r\n/g, '\n').trim() : '';
39
+ if (!body) return {
40
+ ok: false,
41
+ error: 'Write a message first.'
42
+ };
43
+ if (body.length > QUOTE_MESSAGE_MAX) return {
44
+ ok: false,
45
+ error: `A message holds up to ${QUOTE_MESSAGE_MAX.toLocaleString('en-US')} characters.`
46
+ };
47
+ return {
48
+ ok: true,
49
+ body
50
+ };
51
+ }
52
+ /** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */ export function quoteReplyRecipient(order) {
53
+ return quoteSendPrefill(order);
54
+ }
55
+ /** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */ export function quoteReplyRefusal(order) {
56
+ if (!order || !isQuote(order) || !order.quote) return 'not-a-quote';
57
+ const to = quoteReplyRecipient(order);
58
+ if (!to) return 'no-address';
59
+ if (to.length > 320 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(to)) return 'bad-address';
60
+ return null;
61
+ }
62
+ export function quoteReplyRefusalMessage(reason) {
63
+ switch(reason){
64
+ case 'not-a-quote':
65
+ return 'Unknown quote';
66
+ case 'no-address':
67
+ return 'This quote has no customer email, so there is nobody to reply to. Add their email to the quote first.';
68
+ case 'bad-address':
69
+ return 'The customer email on this quote isn’t a valid address. Fix it on the quote first.';
70
+ }
71
+ }
72
+ /**
73
+ * The quote after a reply went out: the conversation moved on to it, so the
74
+ * next email answers it, and the timeline says who wrote to whom. Nothing the
75
+ * customer sees changes, so the quote's edit stamp stays.
76
+ */ export function quoteAfterReply(order, sent, thread) {
77
+ return _extends({}, order, {
78
+ timeline: appendOrderEvent(order, 'quote-message-sent', `Reply emailed to ${sent.to} by ${sent.by}`, sent.atMs),
79
+ quote: _extends({}, order.quote, {
80
+ emailThread: thread
81
+ })
82
+ });
83
+ }
84
+ /** The stored messages, oldest first, as the page may show them. */ export function quotePageMessages(entries) {
85
+ return entries.filter((entry)=>{
86
+ var _entry_data;
87
+ return typeof ((_entry_data = entry.data) == null ? void 0 : _entry_data.body) === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in');
88
+ }).map((entry)=>{
89
+ var _entry_data, _entry_data1, _entry_data2;
90
+ return {
91
+ id: entry.id,
92
+ from: ((_entry_data = entry.data) == null ? void 0 : _entry_data.direction) === 'out' ? 'business' : 'customer',
93
+ body: String((_entry_data1 = entry.data) == null ? void 0 : _entry_data1.body),
94
+ atMs: Number((_entry_data2 = entry.data) == null ? void 0 : _entry_data2.atMs) || 0
95
+ };
96
+ }).sort((a, b)=>a.atMs - b.atMs);
97
+ }
98
+ /** The stored messages, oldest first, as the team reads them. */ export function quoteConsoleMessages(entries) {
99
+ return entries.filter((entry)=>{
100
+ var _entry_data;
101
+ return typeof ((_entry_data = entry.data) == null ? void 0 : _entry_data.body) === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in');
102
+ }).map((entry)=>{
103
+ const data = entry.data;
104
+ const label = data.direction === 'out' ? `Sent to ${data.to || 'the customer'}${data.by ? ` by ${data.by}` : ''}` : `${data.name || 'The customer'} wrote on the quote page`;
105
+ return {
106
+ id: entry.id,
107
+ direction: data.direction,
108
+ body: data.body,
109
+ atMs: Number(data.atMs) || 0,
110
+ label
111
+ };
112
+ }).sort((a, b)=>a.atMs - b.atMs);
113
+ }
114
+ /** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */ export function quoteMessageEmailTokens(input) {
115
+ var _input_order_quote, _quote_revision;
116
+ const quote = (_input_order_quote = input.order.quote) != null ? _input_order_quote : {};
117
+ const proofOnly = quoteIsProofOnly(input.order);
118
+ const label = proofOnly ? 'Proof' : 'Quote';
119
+ const noun = proofOnly ? 'proof' : 'quote';
120
+ const number = formatQuoteNumber(input.order, input.quoteId).replace(/^Quote\s+/, '');
121
+ const business = input.businessName.trim() || 'the business';
122
+ const heading = `A message about your ${noun}`;
123
+ const tokens = {
124
+ 'message.subject': input.subject,
125
+ 'quote.label': label,
126
+ 'quote.number': number,
127
+ 'quote.revision': String(Math.max(1, Number((_quote_revision = quote.revision) != null ? _quote_revision : 1) || 1)),
128
+ 'message.heading': heading,
129
+ 'message.body': input.body,
130
+ 'message.buttonLabel': `View your ${noun}`,
131
+ 'quote.url': input.url
132
+ };
133
+ const text = [
134
+ heading,
135
+ input.body,
136
+ `${label}: ${number}`,
137
+ `View your ${noun}: ${input.url}`,
138
+ `Reply to this email to reach ${business}, or answer on your ${noun} page.`
139
+ ].join('\n\n');
140
+ return {
141
+ tokens,
142
+ text
143
+ };
144
+ }
145
+
146
+ //# sourceMappingURL=commerce-quote-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-quote-messages.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 { appendOrderEvent, type HostOrder } from './commerce-orders'\nimport { quoteSendPrefill } from './commerce-quote-email'\nimport { formatQuoteNumber, isQuote, quoteIsProofOnly, type OrderQuote, type QuoteEmailThread } from './commerce-quotes'\n\n/*==========================================\n * A QUOTE'S CONVERSATION (AGL-4207): what the business and its customer say\n * to each other about one quote, kept under it at\n * `hosts/{hostId}/orders/{quoteId}/messages/{id}`, so it stays through every\n * revision and after the quote is paid.\n *\n * - `out`: a reply the business sent from the quote. It went by email, in\n * the quote's own conversation in the customer's mailbox\n * (`quote.emailThread`), under the `quote-message` catalog email.\n * - `in`: what the customer wrote on the quote page. The business is told\n * in Aglyn and by email.\n *\n * Nothing receives mail: a customer who answers an email reaches the\n * business's own mailbox (its Reply-To), as an Inbox reply's answer does.\n *=========================================*/\n\n/** The catalog email a reply from the quote goes out as. */\nexport const QUOTE_MESSAGE_EMAIL_KEY = 'quote-message'\n\n/** The longest message either side may send. */\nexport const QUOTE_MESSAGE_MAX = 5_000\n\n/** The most messages a page or the console lists, newest kept. */\nexport const QUOTE_MESSAGES_SHOWN = 50\n\n/** One message in a quote's conversation, as stored. */\nexport interface QuoteMessage {\n direction: 'out' | 'in'\n body: string\n atMs: number\n /** The revision the quote was on when it was said. */\n revision: number\n /** With `out`: who on the team sent it, an email else a uid. */\n by?: string\n /** With `out`: the address it went to. */\n to?: string\n /** With `out`: the `Message-ID` it was sent with, and the provider's own id. */\n messageId?: string\n providerId?: string | null\n /** With `in`: the name on the quote when the customer wrote. */\n name?: string\n /** With `in`: the address and browser it came from, kept as the record. */\n ip?: string | null\n userAgent?: string | null\n}\n\n/** A message as typed, trimmed, or what to fix. */\nexport function parseQuoteMessageBody(raw: unknown): { ok: true; body: string } | { ok: false; error: string } {\n const body = typeof raw === 'string' ? raw.replace(/\\r\\n/g, '\\n').trim() : ''\n if (!body) return { ok: false, error: 'Write a message first.' }\n if (body.length > QUOTE_MESSAGE_MAX) return { ok: false, error: `A message holds up to ${QUOTE_MESSAGE_MAX.toLocaleString('en-US')} characters.` }\n return { ok: true, body }\n}\n\n/** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */\nexport function quoteReplyRecipient(order: Pick<HostOrder, 'quote'> | null | undefined): string {\n return quoteSendPrefill(order)\n}\n\nexport type QuoteReplyRefusal = 'not-a-quote' | 'no-address' | 'bad-address'\n\n/** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */\nexport function quoteReplyRefusal(order: Pick<HostOrder, 'channel' | 'quote'> | null | undefined): QuoteReplyRefusal | null {\n if (!order || !isQuote(order) || !order.quote) return 'not-a-quote'\n const to = quoteReplyRecipient(order)\n if (!to) return 'no-address'\n if (to.length > 320 || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(to)) return 'bad-address'\n return null\n}\n\nexport function quoteReplyRefusalMessage(reason: QuoteReplyRefusal): string {\n switch (reason) {\n case 'not-a-quote':\n return 'Unknown quote'\n case 'no-address':\n return 'This quote has no customer email, so there is nobody to reply to. Add their email to the quote first.'\n case 'bad-address':\n return 'The customer email on this quote isn’t a valid address. Fix it on the quote first.'\n }\n}\n\n/**\n * The quote after a reply went out: the conversation moved on to it, so the\n * next email answers it, and the timeline says who wrote to whom. Nothing the\n * customer sees changes, so the quote's edit stamp stays.\n */\nexport function quoteAfterReply(\n order: HostOrder,\n sent: { to: string; by: string; atMs: number },\n thread: QuoteEmailThread,\n): HostOrder {\n return {\n ...order,\n timeline: appendOrderEvent(order, 'quote-message-sent', `Reply emailed to ${sent.to} by ${sent.by}`, sent.atMs),\n quote: { ...(order.quote as OrderQuote), emailThread: thread },\n }\n}\n\n/** A message as the customer's page shows it: who said it and what, never an address, browser or team member. */\nexport interface QuotePageMessage {\n id: string\n from: 'business' | 'customer'\n body: string\n atMs: number\n}\n\n/** The stored messages, oldest first, as the page may show them. */\nexport function quotePageMessages(entries: ReadonlyArray<{ id: string; data: Partial<QuoteMessage> | undefined }>): QuotePageMessage[] {\n return entries\n .filter((entry) => typeof entry.data?.body === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in'))\n .map((entry) => ({\n id: entry.id,\n from: entry.data?.direction === 'out' ? ('business' as const) : ('customer' as const),\n body: String(entry.data?.body),\n atMs: Number(entry.data?.atMs) || 0,\n }))\n .sort((a, b) => a.atMs - b.atMs)\n}\n\n/** A message as the console lists it. */\nexport interface QuoteConsoleMessage {\n id: string\n direction: 'out' | 'in'\n body: string\n atMs: number\n /** `to jordan@example.com by sam@shop.test`, or `Jordan Lee wrote on the quote page`. */\n label: string\n}\n\n/** The stored messages, oldest first, as the team reads them. */\nexport function quoteConsoleMessages(entries: ReadonlyArray<{ id: string; data: Partial<QuoteMessage> | undefined }>): QuoteConsoleMessage[] {\n return entries\n .filter((entry) => typeof entry.data?.body === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in'))\n .map((entry) => {\n const data = entry.data as QuoteMessage\n const label =\n data.direction === 'out'\n ? `Sent to ${data.to || 'the customer'}${data.by ? ` by ${data.by}` : ''}`\n : `${data.name || 'The customer'} wrote on the quote page`\n return { id: entry.id, direction: data.direction, body: data.body, atMs: Number(data.atMs) || 0, label }\n })\n .sort((a, b) => a.atMs - b.atMs)\n}\n\n/** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */\nexport function quoteMessageEmailTokens(input: {\n order: HostOrder\n quoteId: string\n businessName: string\n subject: string\n body: string\n url: string\n}): { tokens: Record<string, string>; text: string } {\n const quote = (input.order.quote ?? {}) as OrderQuote\n const proofOnly = quoteIsProofOnly(input.order)\n const label = proofOnly ? 'Proof' : 'Quote'\n const noun = proofOnly ? 'proof' : 'quote'\n const number = formatQuoteNumber(input.order, input.quoteId).replace(/^Quote\\s+/, '')\n const business = input.businessName.trim() || 'the business'\n const heading = `A message about your ${noun}`\n const tokens: Record<string, string> = {\n 'message.subject': input.subject,\n 'quote.label': label,\n 'quote.number': number,\n 'quote.revision': String(Math.max(1, Number(quote.revision ?? 1) || 1)),\n 'message.heading': heading,\n 'message.body': input.body,\n 'message.buttonLabel': `View your ${noun}`,\n 'quote.url': input.url,\n }\n const text = [\n heading,\n input.body,\n `${label}: ${number}`,\n `View your ${noun}: ${input.url}`,\n `Reply to this email to reach ${business}, or answer on your ${noun} page.`,\n ].join('\\n\\n')\n return { tokens, text }\n}\n"],"names":["appendOrderEvent","quoteSendPrefill","formatQuoteNumber","isQuote","quoteIsProofOnly","QUOTE_MESSAGE_EMAIL_KEY","QUOTE_MESSAGE_MAX","QUOTE_MESSAGES_SHOWN","parseQuoteMessageBody","raw","body","replace","trim","ok","error","length","toLocaleString","quoteReplyRecipient","order","quoteReplyRefusal","quote","to","test","quoteReplyRefusalMessage","reason","quoteAfterReply","sent","thread","timeline","by","atMs","emailThread","quotePageMessages","entries","filter","entry","data","direction","map","id","from","String","Number","sort","a","b","quoteConsoleMessages","label","name","quoteMessageEmailTokens","input","proofOnly","noun","number","quoteId","business","businessName","heading","tokens","subject","Math","max","revision","url","text","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAwB,uBAAmB;AACpE,SAASC,gBAAgB,QAAQ,4BAAwB;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EAAE,EAAEF,MAAMa,GAAG,EAAE;QACjC,CAAC,6BAA6B,EAAER,SAAS,oBAAoB,EAAEH,KAAK,MAAM,CAAC;KAC5E,CAACa,IAAI,CAAC;IACP,OAAO;QAAEP;QAAQM;IAAK;AACxB"}
@@ -17,6 +17,8 @@
17
17
  import type { ProductType } from './commerce';
18
18
  import { type HostOrder, type OrderAddress, type OrderLineItem, type OrderStatus } from './commerce-orders';
19
19
  import { type OrderQuote, type QuoteDiscount, type QuoteTaxBasis, type QuoteUnmatchedPayment } from './commerce-quotes';
20
+ import { type QuoteProofAccess } from './commerce-quote-proofs';
21
+ import type { QuotePageMessage } from './commerce-quote-messages';
20
22
  import type { TaxSettings } from './commerce-tax';
21
23
  import { type StorefrontTaxMode } from './commerce-tax-decision';
22
24
  import { type OrderListFields } from './order-list-fields';
@@ -129,11 +131,13 @@ export interface QuotePageProof {
129
131
  export interface QuotePageResponse {
130
132
  action: 'approve' | 'changes';
131
133
  atMs: number;
132
- /** With an approval: the name it was given under. */
134
+ /** The name it was given under: an approval's, or a rejection's (AGL-4206). */
133
135
  name: string | null;
134
136
  comment: string | null;
135
137
  /** How many files came with it. */
136
138
  files: number;
139
+ /** With an approval: what they ticked before approving (AGL-4206). */
140
+ confirmed: string[];
137
141
  }
138
142
  /**
139
143
  * What the quote page shows. Allow-listed, never spread: the order document
@@ -219,8 +223,27 @@ export interface QuotePageView {
219
223
  proofs: QuotePageProof[];
220
224
  /** The customer's latest answer to it, if any. */
221
225
  response: QuotePageResponse | null;
222
- /** Approve and Request changes belong on the page. */
226
+ /** Approve and Reject with changes belong on the page. */
223
227
  respondable: boolean;
228
+ /**
229
+ * What the customer ticks before Approve works (AGL-4206), word for word;
230
+ * Approve sends them back. Empty when the page takes no answer.
231
+ */
232
+ approvalStatements: string[];
233
+ /**
234
+ * Whether this browser may see the proof (AGL-4206): `open`, or a sign-in
235
+ * the quote waits on. While it waits the view carries no proofs, no answer
236
+ * and nothing to respond with, and `proofAccessMessage` says what to do.
237
+ */
238
+ proofAccess: QuoteProofAccess;
239
+ proofAccessMessage: string | null;
240
+ /**
241
+ * The quote's conversation with the business, oldest first (AGL-4207):
242
+ * what each side wrote, never an address or who on the team sent it. The
243
+ * customer writes back on the page. Empty for an invoice, and while the
244
+ * proof waits on a sign-in.
245
+ */
246
+ messages: QuotePageMessage[];
224
247
  }
225
248
  /** What a signed link for an older version of the quote opens: nothing of the quote. */
226
249
  export interface QuotePageReplacedView {
@@ -253,6 +276,12 @@ export declare function buildQuotePageView(input: {
253
276
  store?: PayLinkStore | null;
254
277
  /** Whether the business can take a card payment now; absent, it is not judged here. */
255
278
  paymentsReady?: boolean;
279
+ /** What the customer ticks before approving: the store's {@link quoteApprovalStatements}. */
280
+ approvalStatements?: readonly string[];
281
+ /** Whether this browser may see the proof ({@link quoteProofAccess}); absent reads as `open`. */
282
+ proofAccess?: QuoteProofAccess;
283
+ /** The quote's conversation ({@link quotePageMessages}); absent, none is shown. */
284
+ messages?: QuotePageMessage[];
256
285
  }): QuotePageView;
257
286
  /** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */
258
287
  export declare function quotePageLines(lines: readonly OrderLineItem[]): QuotePageLine[];