@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/pos-cellular.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 {\n STRIPE_PROCESSOR_FEE_FIXED_USD,\n STRIPE_PROCESSOR_FEE_PCT,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\n\n/*==========================================\n * 4G FOR STRIPE READER S710s (AGL-4038).\n *\n * Stripe sells cellular service for the Stripe Reader S710 as a monthly\n * subscription per reader, billed to the Stripe account the reader is\n * registered to — which, for every reader a store sets up here, is the\n * PLATFORM's. A reader has it when the Terminal Location it is registered\n * to has a Configuration with `cellular[enabled]`; Stripe bills a reader for\n * every calendar month it had it at any time.\n *\n * So 4G is turned on for a STORE: the platform keeps one Location and one\n * Configuration per store (`pos-terminal.ts`), and the native apps' connection\n * tokens are scoped to that one Location, so a second, cellular Location for\n * some of a store's readers would be one those apps could never reach, and\n * moving a reader there takes a fresh pairing code. Every S710 at a store\n * with 4G on has it, and each one is charged.\n *\n * The store's workspace pays what the platform pays, passed through: per\n * S710 per calendar month, Stripe's cellular price, plus what collecting it\n * costs the platform (the card processing on the charge), with no markup.\n * Both are configuration, never literals here:\n *\n * POS_CELLULAR_MONTHLY_COST_CENTS Stripe's price per reader per\n * month, in cents. Unset: 4G is not\n * offered anywhere (hidden, not\n * disabled).\n * POS_CELLULAR_BILLING_COST_BPS the processing percentage on the\n * charge, in basis points (default:\n * the platform's card rate)\n * POS_CELLULAR_BILLING_COST_FIXED_CENTS the processing fixed fee per\n * charge (default: the platform's)\n * STRIPE_PRODUCT_POS_CELLULAR the product the invoice line is\n * billed against (its tax code);\n * `setup-stripe.mjs` makes it\n * POS_CELLULAR_GRACE_DAYS how long a month's charge may stay\n * unpaid before 4G is turned off for\n * the workspace's stores (default 14)\n *\n * Billed in ARREARS, once per workspace per calendar month, on a one-off\n * invoice through core's usage-invoice charge — the same path a domain or\n * an AI overage takes — for the readers that had 4G at any time that month,\n * which is what Stripe bills the platform for. Turning 4G off stops the\n * charge from the next calendar month.\n *\n * A charge that does not collect stays open on the workspace's Billing page\n * and staff are alerted; the people who manage its billing are warned the\n * same day, once, of the day 4G turns off unless it is paid. Still unpaid\n * after the grace period, 4G is turned off at Stripe for every store of the\n * workspace, and they are told again; paying does not turn it back on, and\n * it cannot be turned on again until the charge is paid. A workspace deleted\n * mid-month is charged for that final month as it is erased.\n *=========================================*/\n\nexport const POS_CELLULAR_ENV = {\n monthlyCostCents: 'POS_CELLULAR_MONTHLY_COST_CENTS',\n billingCostBps: 'POS_CELLULAR_BILLING_COST_BPS',\n billingCostFixedCents: 'POS_CELLULAR_BILLING_COST_FIXED_CENTS',\n productId: 'STRIPE_PRODUCT_POS_CELLULAR',\n graceDays: 'POS_CELLULAR_GRACE_DAYS',\n} as const\n\n/** How long a month's charge may stay unpaid before 4G is turned off, unless configured. */\nexport const POS_CELLULAR_DEFAULT_GRACE_DAYS = 14\n\n/** A day, in milliseconds. */\nexport const POS_CELLULAR_DAY_MS = 24 * 60 * 60 * 1000\n\n/** The platform's card processing rate, in basis points: the default billing cost. */\nexport const POS_CELLULAR_DEFAULT_BILLING_COST_BPS = Math.round(STRIPE_PROCESSOR_FEE_PCT * 10_000)\n\n/** The platform's card processing fixed fee, in cents: the default billing cost. */\nexport const POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS = Math.round(STRIPE_PROCESSOR_FEE_FIXED_USD * 100)\n\n/** The Stripe device types that take cellular service: the S710, and its simulator. */\nexport const POS_CELLULAR_DEVICE_TYPES: readonly string[] = ['stripe_s710', 'simulated_stripe_s710']\n\n/** The top-level, server-only record of each reader's 4G months. */\nexport const POS_CELLULAR_READERS_COLLECTION = 'posCellularReaders'\n\n/** The top-level, server-only record of each workspace's monthly 4G charge. */\nexport const POS_CELLULAR_CHARGES_COLLECTION = 'posCellularCharges'\n\n/** The metadata `kind` the charge's invoice carries. */\nexport const POS_CELLULAR_CHARGE_KIND = 'pos-cellular'\n\n/** How many 4G periods a reader's record keeps: two years of on and off. */\nexport const POS_CELLULAR_MAX_PERIODS = 24\n\nexport interface PosCellularConfig {\n monthlyCostCents: number\n billingCostBps: number\n billingCostFixedCents: number\n productId: string\n /** Days a charge may stay unpaid before 4G is turned off for the workspace. */\n graceDays: number\n}\n\nfunction wholeNumber(text: string | undefined, fallback: number, max: number): number | null {\n const trimmed = String(text ?? '').trim()\n if (!trimmed) return fallback\n if (!/^\\d+$/.test(trimmed)) return null\n const value = Number(trimmed)\n return Number.isSafeInteger(value) && value <= max ? value : null\n}\n\n/**\n * The deployment's 4G pricing, or null when 4G is not offered: no monthly\n * cost, no product, or a value that is not a whole number in range. A bad\n * value hides the feature rather than billing a guess.\n */\nexport function parsePosCellularConfig(\n env: Record<string, string | undefined> = process.env,\n): PosCellularConfig | null {\n const costText = String(env[POS_CELLULAR_ENV.monthlyCostCents] ?? '').trim()\n if (!/^\\d+$/.test(costText)) return null\n const monthlyCostCents = Number(costText)\n if (!Number.isSafeInteger(monthlyCostCents) || monthlyCostCents <= 0 || monthlyCostCents > 100_000) return null\n const productId = String(env[POS_CELLULAR_ENV.productId] ?? '').trim()\n if (!/^prod_[A-Za-z0-9]+$/.test(productId)) return null\n const billingCostBps = wholeNumber(env[POS_CELLULAR_ENV.billingCostBps], POS_CELLULAR_DEFAULT_BILLING_COST_BPS, 5_000)\n const billingCostFixedCents = wholeNumber(\n env[POS_CELLULAR_ENV.billingCostFixedCents],\n POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS,\n 1_000,\n )\n const graceDays = wholeNumber(env[POS_CELLULAR_ENV.graceDays], POS_CELLULAR_DEFAULT_GRACE_DAYS, 90)\n if (billingCostBps === null || billingCostFixedCents === null || graceDays === null || graceDays < 1) return null\n return { monthlyCostCents, billingCostBps, billingCostFixedCents, productId, graceDays }\n}\n\n/**\n * One workspace's 4G charge for a month, in whole cents: Stripe's price for\n * each reader, grossed up so that what the charge's own processing takes\n * leaves the platform exactly that:\n *\n * ceil((readers × cost + fixed) / (1 − rate))\n *\n * Rounded up, the one direction that never bills below cost.\n * Zero readers is no charge.\n */\nexport function posCellularChargeCents(readers: number, config: PosCellularConfig): number {\n if (!Number.isSafeInteger(readers) || readers <= 0) return 0\n const passThrough = readers * config.monthlyCostCents + config.billingCostFixedCents\n return Math.ceil((passThrough * 10_000) / (10_000 - config.billingCostBps))\n}\n\n/**\n * What one reader costs a month, as the console shows it: a store's charge\n * for a single reader. More readers on one charge share its fixed fee, so\n * this is never less than any reader's share of a larger charge.\n */\nexport function posCellularReaderMonthlyCents(config: PosCellularConfig): number {\n return posCellularChargeCents(1, config)\n}\n\n/** Whether a reader of this Stripe device type can have 4G. */\nexport function isPosCellularDeviceType(deviceType: unknown): boolean {\n return typeof deviceType === 'string' && POS_CELLULAR_DEVICE_TYPES.includes(deviceType)\n}\n\n/** `2026-10` for a time in October 2026, in UTC. */\nexport function posCellularMonthKey(ms: number): string {\n const date = new Date(ms)\n return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, '0')}`\n}\n\n/** The calendar month before the one `ms` falls in. */\nexport function posCellularPreviousMonthKey(ms: number): string {\n const date = new Date(ms)\n return posCellularMonthKey(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, 1))\n}\n\n/** A month's first instant, and the next month's, in UTC; null for a key that is not one. */\nexport function posCellularMonthBounds(month: string): { startMs: number; endMs: number } | null {\n const match = /^(\\d{4})-(\\d{2})$/.exec(month)\n if (!match) return null\n const year = Number(match[1])\n const index = Number(match[2]) - 1\n if (index < 0 || index > 11) return null\n return { startMs: Date.UTC(year, index, 1), endMs: Date.UTC(year, index + 1, 1) }\n}\n\n/** `October 2026`, for the invoice line. */\nexport function posCellularMonthLabel(month: string): string {\n const bounds = posCellularMonthBounds(month)\n if (!bounds) return month\n return new Date(bounds.startMs).toLocaleString('en-US', { month: 'long', year: 'numeric', timeZone: 'UTC' })\n}\n\n/** One stretch of time a reader had 4G: from when it was turned on, to when it was turned off (open while it is on). */\nexport interface PosCellularPeriod {\n fromMs: number\n toMs: number | null\n}\n\n/**\n * `posCellularReaders/{hostId}_{readerId}`: one S710's 4G months, written\n * only by the server. No person is named on it: a workspace, a store, a\n * Stripe reader and its serial, and when it had 4G.\n */\nexport interface PosCellularReaderRecord {\n orgId: string\n hostId: string\n readerId: string\n serialNumber: string | null\n /** The store's Terminal Configuration that carries `cellular[enabled]`. */\n stripeConfigurationId: string | null\n enabled: boolean\n periods: PosCellularPeriod[]\n /** The last time a period was closed, which the month's charge queries by. */\n disabledAtMs: number | null\n updatedAtMs: number\n}\n\n/** The record's document id. */\nexport function posCellularReaderId(hostId: string, readerId: string): string {\n return `${hostId}_${readerId}`\n}\n\n/** The record with a period open from `now`, unless one already is. */\nexport function openPosCellularPeriod(\n base: Omit<PosCellularReaderRecord, 'enabled' | 'periods' | 'disabledAtMs' | 'updatedAtMs'>,\n existing: PosCellularReaderRecord | null,\n now: number,\n): PosCellularReaderRecord {\n const periods = existing?.periods ?? []\n const open = periods.some((period) => period.toMs === null)\n return {\n ...base,\n enabled: true,\n periods: open ? periods : [...periods, { fromMs: now, toMs: null }].slice(-POS_CELLULAR_MAX_PERIODS),\n disabledAtMs: existing?.disabledAtMs ?? null,\n updatedAtMs: now,\n }\n}\n\n/** The record with its open period closed at `now`; unchanged when none is open. */\nexport function closePosCellularPeriod(existing: PosCellularReaderRecord, now: number): PosCellularReaderRecord {\n if (!existing.periods.some((period) => period.toMs === null) && !existing.enabled) return existing\n return {\n ...existing,\n enabled: false,\n periods: existing.periods.map((period) => (period.toMs === null ? { ...period, toMs: now } : period)),\n disabledAtMs: now,\n updatedAtMs: now,\n }\n}\n\n/** Whether a reader had 4G at any time in the month. */\nexport function posCellularBilledInMonth(\n record: Pick<PosCellularReaderRecord, 'periods'>,\n bounds: { startMs: number; endMs: number },\n): boolean {\n return (record.periods ?? []).some(\n (period) => period.fromMs < bounds.endMs && (period.toMs === null || period.toMs > bounds.startMs),\n )\n}\n\n/** Each workspace's readers that had 4G in the month, by workspace. */\nexport function posCellularReadersByWorkspace(\n records: ReadonlyArray<PosCellularReaderRecord>,\n month: string,\n): Map<string, { readers: number; hostIds: string[] }> {\n const bounds = posCellularMonthBounds(month)\n const byOrg = new Map<string, { readers: number; hostIds: string[] }>()\n if (!bounds) return byOrg\n for (const record of records) {\n if (!record.orgId || !posCellularBilledInMonth(record, bounds)) continue\n const entry = byOrg.get(record.orgId) ?? { readers: 0, hostIds: [] }\n entry.readers += 1\n if (!entry.hostIds.includes(record.hostId)) entry.hostIds.push(record.hostId)\n byOrg.set(record.orgId, entry)\n }\n return byOrg\n}\n\n/**\n * The outcome of a workspace's month: charged and paid; charged and left\n * open on their Billing page because the card failed; still unpaid after the\n * grace period, so 4G was turned off for the workspace (`suspended`); its\n * invoice voided by staff (`voided`); not charged because there is no one to\n * bill (no workspace, no customer) or nothing to bill (under Stripe's\n * minimum); or `charging`, claimed by a run in progress.\n */\nexport type PosCellularChargeState =\n | 'charging'\n | 'paid'\n | 'open'\n | 'suspended'\n | 'voided'\n | 'failed'\n | 'no-workspace'\n | 'no-customer'\n | 'below-minimum'\n\n/** States a later run never charges again. */\nexport const POS_CELLULAR_SETTLED_STATES: readonly PosCellularChargeState[] = [\n 'paid',\n 'open',\n 'suspended',\n 'voided',\n 'no-workspace',\n 'no-customer',\n 'below-minimum',\n]\n\n/** `posCellularCharges/{orgId}_{month}`: one workspace's 4G charge for one month. */\nexport interface PosCellularCharge {\n orgId: string\n month: string\n readers: number\n amountCents: number\n state: PosCellularChargeState\n invoiceId: string | null\n paidCents: number\n attempts: number\n createdAtMs: number\n updatedAtMs: number\n /** When the charge was left open, which the grace period counts from. */\n openedAtMs?: number | null\n /** When 4G was turned off for the workspace because it stayed unpaid. */\n suspendedAtMs?: number | null\n /** The stores 4G was turned off for, whose notice clears once it is paid. */\n suspendedHostIds?: string[]\n /**\n * When the people who manage the workspace's billing were warned, as the\n * charge was left open, of the day 4G turns off unless it is paid.\n */\n warnedAtMs?: number | null\n /** When the people who manage the workspace's billing were told 4G was turned off. */\n noticeSentAtMs?: number | null\n /** Charged as the workspace was erased, for the month it was deleted in (or the one before). */\n final?: boolean\n}\n\n/**\n * When a charge left open runs out of grace: the grace period after it was\n * left open (or, for a charge from before that was recorded, after it last\n * changed).\n */\nexport function posCellularGraceEndsAtMs(\n charge: Pick<PosCellularCharge, 'openedAtMs' | 'updatedAtMs'>,\n graceDays: number,\n): number {\n return Number(charge.openedAtMs ?? charge.updatedAtMs) + graceDays * POS_CELLULAR_DAY_MS\n}\n\n/** Whether an open charge is past its grace period. */\nexport function posCellularOverdue(\n charge: Pick<PosCellularCharge, 'state' | 'openedAtMs' | 'updatedAtMs'>,\n graceDays: number,\n now: number,\n): boolean {\n return charge.state === 'open' && now >= posCellularGraceEndsAtMs(charge, graceDays)\n}\n\n/**\n * Whether the people who manage a workspace's billing are still owed the\n * warning that 4G turns off unless the charge is paid: an open charge not yet\n * warned of. Never a charge made as the workspace was erased, whose 4G is\n * already off and whose members are gone.\n */\nexport function posCellularWarningDue(\n charge: Pick<PosCellularCharge, 'state' | 'warnedAtMs' | 'final'>,\n): boolean {\n return charge.state === 'open' && !charge.warnedAtMs && !charge.final\n}\n\n/**\n * A day as the workspace reads it, `November 16, 2026`, in its time zone\n * (UTC for a zone the runtime cannot format in).\n */\nexport function posCellularDayLabel(ms: number, timeZone = 'UTC'): string {\n const options = { month: 'long', day: 'numeric', year: 'numeric' } as const\n try {\n return new Date(ms).toLocaleDateString('en-US', { ...options, timeZone })\n } catch {\n return new Date(ms).toLocaleDateString('en-US', { ...options, timeZone: 'UTC' })\n }\n}\n\n/**\n * On a store's terminal settings (`cellularSuspended`) while 4G is off because\n * a month's charge was not paid: which month, its invoice, and when.\n */\nexport interface PosCellularSuspension {\n month: string\n invoiceId: string | null\n atMs: number\n}\n\n/** What the POS devices card is told about 4G for a store; null hides it. */\nexport interface PosCellularView {\n /** What one reader costs a month, in cents, before any sales tax. */\n readerMonthlyCents: number\n enabled: boolean\n /** The store's readers that take 4G. */\n readers: number\n /** Turned off because a month's charge was not paid: that month, as `October 2026`, and when. */\n suspended?: { month: string; atMs: number } | null\n /**\n * Why the viewer may not turn 4G ON (it is charged to the workspace, so it\n * also takes \"Manage billing\"), or null. Turning it off needs only the\n * card's own key.\n */\n turnOnBlocked?: string | null\n}\n\n/**\n * The 4G row of a store's POS devices card: shown only where 4G is offered\n * and the store has an S710, or already has 4G on (so it can be turned off).\n */\nexport function posCellularView(\n config: PosCellularConfig | null,\n terminal: { cellularEnabled?: unknown; cellularSuspended?: unknown } | null | undefined,\n readers: ReadonlyArray<{ deviceType?: unknown }>,\n options: { turnOnBlocked?: string | null } = {},\n): PosCellularView | null {\n if (!config) return null\n const enabled = terminal?.cellularEnabled === true\n const capable = readers.filter((reader) => isPosCellularDeviceType(reader.deviceType)).length\n if (!enabled && capable === 0) return null\n const suspension = terminal?.cellularSuspended as Partial<PosCellularSuspension> | null | undefined\n const suspended =\n !enabled && suspension && typeof suspension.month === 'string'\n ? { month: posCellularMonthLabel(suspension.month), atMs: Number(suspension.atMs ?? 0) }\n : null\n return {\n readerMonthlyCents: posCellularReaderMonthlyCents(config),\n enabled,\n readers: capable,\n suspended,\n turnOnBlocked: options.turnOnBlocked ?? null,\n }\n}\n"],"names":["STRIPE_PROCESSOR_FEE_FIXED_USD","STRIPE_PROCESSOR_FEE_PCT","POS_CELLULAR_ENV","monthlyCostCents","billingCostBps","billingCostFixedCents","productId","graceDays","POS_CELLULAR_DEFAULT_GRACE_DAYS","POS_CELLULAR_DAY_MS","POS_CELLULAR_DEFAULT_BILLING_COST_BPS","Math","round","POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS","POS_CELLULAR_DEVICE_TYPES","POS_CELLULAR_READERS_COLLECTION","POS_CELLULAR_CHARGES_COLLECTION","POS_CELLULAR_CHARGE_KIND","POS_CELLULAR_MAX_PERIODS","wholeNumber","text","fallback","max","trimmed","String","trim","test","value","Number","isSafeInteger","parsePosCellularConfig","env","process","costText","posCellularChargeCents","readers","config","passThrough","ceil","posCellularReaderMonthlyCents","isPosCellularDeviceType","deviceType","includes","posCellularMonthKey","ms","date","Date","getUTCFullYear","getUTCMonth","padStart","posCellularPreviousMonthKey","UTC","posCellularMonthBounds","month","match","exec","year","index","startMs","endMs","posCellularMonthLabel","bounds","toLocaleString","timeZone","posCellularReaderId","hostId","readerId","openPosCellularPeriod","base","existing","now","periods","open","some","period","toMs","enabled","fromMs","slice","disabledAtMs","updatedAtMs","closePosCellularPeriod","map","posCellularBilledInMonth","record","posCellularReadersByWorkspace","records","byOrg","Map","orgId","entry","get","hostIds","push","set","POS_CELLULAR_SETTLED_STATES","posCellularGraceEndsAtMs","charge","openedAtMs","posCellularOverdue","state","posCellularWarningDue","warnedAtMs","final","posCellularDayLabel","options","day","toLocaleDateString","posCellularView","terminal","suspension","cellularEnabled","capable","filter","reader","length","cellularSuspended","suspended","atMs","readerMonthlyCents","turnOnBlocked"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,8BAA8B,EAC9BC,wBAAwB,QACnB,2CAA0C;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAmD2C,GAE3C,OAAO,MAAMC,mBAAmB;IAC9BC,kBAAkB;IAClBC,gBAAgB;IAChBC,uBAAuB;IACvBC,WAAW;IACXC,WAAW;AACb,EAAU;AAEV,0FAA0F,GAC1F,OAAO,MAAMC,kCAAkC,GAAE;AAEjD,4BAA4B,GAC5B,OAAO,MAAMC,sBAAsB,KAAK,KAAK,KAAK,KAAI;AAEtD,oFAAoF,GACpF,OAAO,MAAMC,wCAAwCC,KAAKC,KAAK,CAACX,2BAA2B,OAAO;AAElG,kFAAkF,GAClF,OAAO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KAAK,KAAK,WAClD;QAAEA,OAAOO,sBAAsBkD,WAAWzD,KAAK;QAAGiE,MAAM1F,QAAOkF,mBAAAA,WAAWQ,IAAI,YAAfR,mBAAmB;IAAG,IACrF;IACN,OAAO;QACLS,oBAAoBhF,8BAA8BH;QAClDwC;QACAzC,SAAS6E;QACTK;QACAG,aAAa,GAAEf,yBAAAA,QAAQe,aAAa,YAArBf,yBAAyB;IAC1C;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/pos-cellular.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 {\n STRIPE_PROCESSOR_FEE_FIXED_USD,\n STRIPE_PROCESSOR_FEE_PCT,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\n\n/*==========================================\n * 4G FOR STRIPE READER S710s (AGL-4038).\n *\n * Stripe sells cellular service for the Stripe Reader S710 as a monthly\n * subscription per reader, billed to the Stripe account the reader is\n * registered to — which, for every reader a store sets up here, is the\n * PLATFORM's. A reader has it when the Terminal Location it is registered\n * to has a Configuration with `cellular[enabled]`; Stripe bills a reader for\n * every calendar month it had it at any time.\n *\n * So 4G is turned on for a STORE: the platform keeps one Location and one\n * Configuration per store (`pos-terminal.ts`), and the native apps' connection\n * tokens are scoped to that one Location, so a second, cellular Location for\n * some of a store's readers would be one those apps could never reach, and\n * moving a reader there takes a fresh pairing code. Every S710 at a store\n * with 4G on has it, and each one is charged.\n *\n * The store's workspace pays what the platform pays, passed through: per\n * S710 per calendar month, Stripe's cellular price, plus what collecting it\n * costs the platform (the card processing on the charge), with no markup.\n * Both are configuration, never literals here:\n *\n * POS_CELLULAR_MONTHLY_COST_CENTS Stripe's price per reader per\n * month, in cents. Unset: 4G is not\n * offered anywhere (hidden, not\n * disabled).\n * POS_CELLULAR_BILLING_COST_BPS the processing percentage on the\n * charge, in basis points (default:\n * the platform's card rate)\n * POS_CELLULAR_BILLING_COST_FIXED_CENTS the processing fixed fee per\n * charge (default: the platform's)\n * STRIPE_PRODUCT_POS_CELLULAR the product the invoice line is\n * billed against (its tax code);\n * `setup-stripe.mjs` makes it\n * POS_CELLULAR_GRACE_DAYS how long a month's charge may stay\n * unpaid before 4G is turned off for\n * the workspace's stores (default 14)\n *\n * Billed in ARREARS, once per workspace per calendar month, on a one-off\n * invoice through core's usage-invoice charge — the same path a domain or\n * an AI overage takes — for the readers that had 4G at any time that month,\n * which is what Stripe bills the platform for. Turning 4G off stops the\n * charge from the next calendar month.\n *\n * A charge that does not collect stays open on the workspace's Billing page\n * and staff are alerted; the people who manage its billing are warned the\n * same day, once, of the day 4G turns off unless it is paid. Still unpaid\n * after the grace period, 4G is turned off at Stripe for every store of the\n * workspace, and they are told again; paying does not turn it back on, and\n * it cannot be turned on again until the charge is paid. A workspace deleted\n * mid-month is charged for that final month as it is erased.\n *=========================================*/\n\nexport const POS_CELLULAR_ENV = {\n monthlyCostCents: 'POS_CELLULAR_MONTHLY_COST_CENTS',\n billingCostBps: 'POS_CELLULAR_BILLING_COST_BPS',\n billingCostFixedCents: 'POS_CELLULAR_BILLING_COST_FIXED_CENTS',\n productId: 'STRIPE_PRODUCT_POS_CELLULAR',\n graceDays: 'POS_CELLULAR_GRACE_DAYS',\n} as const\n\n/** How long a month's charge may stay unpaid before 4G is turned off, unless configured. */\nexport const POS_CELLULAR_DEFAULT_GRACE_DAYS = 14\n\n/** A day, in milliseconds. */\nexport const POS_CELLULAR_DAY_MS = 24 * 60 * 60 * 1000\n\n/** The platform's card processing rate, in basis points: the default billing cost. */\nexport const POS_CELLULAR_DEFAULT_BILLING_COST_BPS = Math.round(STRIPE_PROCESSOR_FEE_PCT * 10_000)\n\n/** The platform's card processing fixed fee, in cents: the default billing cost. */\nexport const POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS = Math.round(STRIPE_PROCESSOR_FEE_FIXED_USD * 100)\n\n/** The Stripe device types that take cellular service: the S710, and its simulator. */\nexport const POS_CELLULAR_DEVICE_TYPES: readonly string[] = ['stripe_s710', 'simulated_stripe_s710']\n\n/** The top-level, server-only record of each reader's 4G months. */\nexport const POS_CELLULAR_READERS_COLLECTION = 'posCellularReaders'\n\n/** The top-level, server-only record of each workspace's monthly 4G charge. */\nexport const POS_CELLULAR_CHARGES_COLLECTION = 'posCellularCharges'\n\n/** The metadata `kind` the charge's invoice carries. */\nexport const POS_CELLULAR_CHARGE_KIND = 'pos-cellular'\n\n/** How many 4G periods a reader's record keeps: two years of on and off. */\nexport const POS_CELLULAR_MAX_PERIODS = 24\n\nexport interface PosCellularConfig {\n monthlyCostCents: number\n billingCostBps: number\n billingCostFixedCents: number\n productId: string\n /** Days a charge may stay unpaid before 4G is turned off for the workspace. */\n graceDays: number\n}\n\nfunction wholeNumber(text: string | undefined, fallback: number, max: number): number | null {\n const trimmed = String(text ?? '').trim()\n if (!trimmed) return fallback\n if (!/^\\d+$/.test(trimmed)) return null\n const value = Number(trimmed)\n return Number.isSafeInteger(value) && value <= max ? value : null\n}\n\n/**\n * The deployment's 4G pricing, or null when 4G is not offered: no monthly\n * cost, no product, or a value that is not a whole number in range. A bad\n * value hides the feature rather than billing a guess.\n */\nexport function parsePosCellularConfig(\n env: Record<string, string | undefined> = process.env,\n): PosCellularConfig | null {\n const costText = String(env[POS_CELLULAR_ENV.monthlyCostCents] ?? '').trim()\n if (!/^\\d+$/.test(costText)) return null\n const monthlyCostCents = Number(costText)\n if (!Number.isSafeInteger(monthlyCostCents) || monthlyCostCents <= 0 || monthlyCostCents > 100_000) return null\n const productId = String(env[POS_CELLULAR_ENV.productId] ?? '').trim()\n if (!/^prod_[A-Za-z0-9]+$/.test(productId)) return null\n const billingCostBps = wholeNumber(env[POS_CELLULAR_ENV.billingCostBps], POS_CELLULAR_DEFAULT_BILLING_COST_BPS, 5_000)\n const billingCostFixedCents = wholeNumber(\n env[POS_CELLULAR_ENV.billingCostFixedCents],\n POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS,\n 1_000,\n )\n const graceDays = wholeNumber(env[POS_CELLULAR_ENV.graceDays], POS_CELLULAR_DEFAULT_GRACE_DAYS, 90)\n if (billingCostBps === null || billingCostFixedCents === null || graceDays === null || graceDays < 1) return null\n return { monthlyCostCents, billingCostBps, billingCostFixedCents, productId, graceDays }\n}\n\n/**\n * One workspace's 4G charge for a month, in whole cents: Stripe's price for\n * each reader, grossed up so that what the charge's own processing takes\n * leaves the platform exactly that:\n *\n * ceil((readers × cost + fixed) / (1 − rate))\n *\n * Rounded up, the one direction that never bills below cost.\n * Zero readers is no charge.\n */\nexport function posCellularChargeCents(readers: number, config: PosCellularConfig): number {\n if (!Number.isSafeInteger(readers) || readers <= 0) return 0\n const passThrough = readers * config.monthlyCostCents + config.billingCostFixedCents\n return Math.ceil((passThrough * 10_000) / (10_000 - config.billingCostBps))\n}\n\n/**\n * What one reader costs a month, as the console shows it: a store's charge\n * for a single reader. More readers on one charge share its fixed fee, so\n * this is never less than any reader's share of a larger charge.\n */\nexport function posCellularReaderMonthlyCents(config: PosCellularConfig): number {\n return posCellularChargeCents(1, config)\n}\n\n/** Whether a reader of this Stripe device type can have 4G. */\nexport function isPosCellularDeviceType(deviceType: unknown): boolean {\n return typeof deviceType === 'string' && POS_CELLULAR_DEVICE_TYPES.includes(deviceType)\n}\n\n/** `2026-10` for a time in October 2026, in UTC. */\nexport function posCellularMonthKey(ms: number): string {\n const date = new Date(ms)\n return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, '0')}`\n}\n\n/** The calendar month before the one `ms` falls in. */\nexport function posCellularPreviousMonthKey(ms: number): string {\n const date = new Date(ms)\n return posCellularMonthKey(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, 1))\n}\n\n/** A month's first instant, and the next month's, in UTC; null for a key that is not one. */\nexport function posCellularMonthBounds(month: string): { startMs: number; endMs: number } | null {\n const match = /^(\\d{4})-(\\d{2})$/.exec(month)\n if (!match) return null\n const year = Number(match[1])\n const index = Number(match[2]) - 1\n if (index < 0 || index > 11) return null\n return { startMs: Date.UTC(year, index, 1), endMs: Date.UTC(year, index + 1, 1) }\n}\n\n/** `October 2026`, for the invoice line. */\nexport function posCellularMonthLabel(month: string): string {\n const bounds = posCellularMonthBounds(month)\n if (!bounds) return month\n return new Date(bounds.startMs).toLocaleString('en-US', { month: 'long', year: 'numeric', timeZone: 'UTC' })\n}\n\n/** One stretch of time a reader had 4G: from when it was turned on, to when it was turned off (open while it is on). */\nexport interface PosCellularPeriod {\n fromMs: number\n toMs: number | null\n}\n\n/**\n * `posCellularReaders/{hostId}_{readerId}`: one S710's 4G months, written\n * only by the server. No person is named on it: a workspace, a store, a\n * Stripe reader and its serial, and when it had 4G.\n */\nexport interface PosCellularReaderRecord {\n orgId: string\n hostId: string\n readerId: string\n serialNumber: string | null\n /** The store's Terminal Configuration that carries `cellular[enabled]`. */\n stripeConfigurationId: string | null\n /**\n * The store's own Stripe account that Configuration is on, for a\n * direct-charge store; absent when it is on the platform.\n */\n stripeConfigurationAccount?: string\n enabled: boolean\n periods: PosCellularPeriod[]\n /** The last time a period was closed, which the month's charge queries by. */\n disabledAtMs: number | null\n updatedAtMs: number\n}\n\n/** The record's document id. */\nexport function posCellularReaderId(hostId: string, readerId: string): string {\n return `${hostId}_${readerId}`\n}\n\n/** The record with a period open from `now`, unless one already is. */\nexport function openPosCellularPeriod(\n base: Omit<PosCellularReaderRecord, 'enabled' | 'periods' | 'disabledAtMs' | 'updatedAtMs'>,\n existing: PosCellularReaderRecord | null,\n now: number,\n): PosCellularReaderRecord {\n const periods = existing?.periods ?? []\n const open = periods.some((period) => period.toMs === null)\n return {\n ...base,\n enabled: true,\n periods: open ? periods : [...periods, { fromMs: now, toMs: null }].slice(-POS_CELLULAR_MAX_PERIODS),\n disabledAtMs: existing?.disabledAtMs ?? null,\n updatedAtMs: now,\n }\n}\n\n/** The record with its open period closed at `now`; unchanged when none is open. */\nexport function closePosCellularPeriod(existing: PosCellularReaderRecord, now: number): PosCellularReaderRecord {\n if (!existing.periods.some((period) => period.toMs === null) && !existing.enabled) return existing\n return {\n ...existing,\n enabled: false,\n periods: existing.periods.map((period) => (period.toMs === null ? { ...period, toMs: now } : period)),\n disabledAtMs: now,\n updatedAtMs: now,\n }\n}\n\n/** Whether a reader had 4G at any time in the month. */\nexport function posCellularBilledInMonth(\n record: Pick<PosCellularReaderRecord, 'periods'>,\n bounds: { startMs: number; endMs: number },\n): boolean {\n return (record.periods ?? []).some(\n (period) => period.fromMs < bounds.endMs && (period.toMs === null || period.toMs > bounds.startMs),\n )\n}\n\n/** Each workspace's readers that had 4G in the month, by workspace. */\nexport function posCellularReadersByWorkspace(\n records: ReadonlyArray<PosCellularReaderRecord>,\n month: string,\n): Map<string, { readers: number; hostIds: string[] }> {\n const bounds = posCellularMonthBounds(month)\n const byOrg = new Map<string, { readers: number; hostIds: string[] }>()\n if (!bounds) return byOrg\n for (const record of records) {\n if (!record.orgId || !posCellularBilledInMonth(record, bounds)) continue\n const entry = byOrg.get(record.orgId) ?? { readers: 0, hostIds: [] }\n entry.readers += 1\n if (!entry.hostIds.includes(record.hostId)) entry.hostIds.push(record.hostId)\n byOrg.set(record.orgId, entry)\n }\n return byOrg\n}\n\n/**\n * The outcome of a workspace's month: charged and paid; charged and left\n * open on their Billing page because the card failed; still unpaid after the\n * grace period, so 4G was turned off for the workspace (`suspended`); its\n * invoice voided by staff (`voided`); not charged because there is no one to\n * bill (no workspace, no customer) or nothing to bill (under Stripe's\n * minimum); or `charging`, claimed by a run in progress.\n */\nexport type PosCellularChargeState =\n | 'charging'\n | 'paid'\n | 'open'\n | 'suspended'\n | 'voided'\n | 'failed'\n | 'no-workspace'\n | 'no-customer'\n | 'below-minimum'\n\n/** States a later run never charges again. */\nexport const POS_CELLULAR_SETTLED_STATES: readonly PosCellularChargeState[] = [\n 'paid',\n 'open',\n 'suspended',\n 'voided',\n 'no-workspace',\n 'no-customer',\n 'below-minimum',\n]\n\n/** `posCellularCharges/{orgId}_{month}`: one workspace's 4G charge for one month. */\nexport interface PosCellularCharge {\n orgId: string\n month: string\n readers: number\n amountCents: number\n state: PosCellularChargeState\n invoiceId: string | null\n paidCents: number\n attempts: number\n createdAtMs: number\n updatedAtMs: number\n /** When the charge was left open, which the grace period counts from. */\n openedAtMs?: number | null\n /** When 4G was turned off for the workspace because it stayed unpaid. */\n suspendedAtMs?: number | null\n /** The stores 4G was turned off for, whose notice clears once it is paid. */\n suspendedHostIds?: string[]\n /**\n * When the people who manage the workspace's billing were warned, as the\n * charge was left open, of the day 4G turns off unless it is paid.\n */\n warnedAtMs?: number | null\n /** When the people who manage the workspace's billing were told 4G was turned off. */\n noticeSentAtMs?: number | null\n /** Charged as the workspace was erased, for the month it was deleted in (or the one before). */\n final?: boolean\n}\n\n/**\n * When a charge left open runs out of grace: the grace period after it was\n * left open (or, for a charge from before that was recorded, after it last\n * changed).\n */\nexport function posCellularGraceEndsAtMs(\n charge: Pick<PosCellularCharge, 'openedAtMs' | 'updatedAtMs'>,\n graceDays: number,\n): number {\n return Number(charge.openedAtMs ?? charge.updatedAtMs) + graceDays * POS_CELLULAR_DAY_MS\n}\n\n/** Whether an open charge is past its grace period. */\nexport function posCellularOverdue(\n charge: Pick<PosCellularCharge, 'state' | 'openedAtMs' | 'updatedAtMs'>,\n graceDays: number,\n now: number,\n): boolean {\n return charge.state === 'open' && now >= posCellularGraceEndsAtMs(charge, graceDays)\n}\n\n/**\n * Whether the people who manage a workspace's billing are still owed the\n * warning that 4G turns off unless the charge is paid: an open charge not yet\n * warned of. Never a charge made as the workspace was erased, whose 4G is\n * already off and whose members are gone.\n */\nexport function posCellularWarningDue(\n charge: Pick<PosCellularCharge, 'state' | 'warnedAtMs' | 'final'>,\n): boolean {\n return charge.state === 'open' && !charge.warnedAtMs && !charge.final\n}\n\n/**\n * A day as the workspace reads it, `November 16, 2026`, in its time zone\n * (UTC for a zone the runtime cannot format in).\n */\nexport function posCellularDayLabel(ms: number, timeZone = 'UTC'): string {\n const options = { month: 'long', day: 'numeric', year: 'numeric' } as const\n try {\n return new Date(ms).toLocaleDateString('en-US', { ...options, timeZone })\n } catch {\n return new Date(ms).toLocaleDateString('en-US', { ...options, timeZone: 'UTC' })\n }\n}\n\n/**\n * On a store's terminal settings (`cellularSuspended`) while 4G is off because\n * a month's charge was not paid: which month, its invoice, and when.\n */\nexport interface PosCellularSuspension {\n month: string\n invoiceId: string | null\n atMs: number\n}\n\n/** What the POS devices card is told about 4G for a store; null hides it. */\nexport interface PosCellularView {\n /** What one reader costs a month, in cents, before any sales tax. */\n readerMonthlyCents: number\n enabled: boolean\n /** The store's readers that take 4G. */\n readers: number\n /** Turned off because a month's charge was not paid: that month, as `October 2026`, and when. */\n suspended?: { month: string; atMs: number } | null\n /**\n * Why the viewer may not turn 4G ON (it is charged to the workspace, so it\n * also takes \"Manage billing\"), or null. Turning it off needs only the\n * card's own key.\n */\n turnOnBlocked?: string | null\n}\n\n/**\n * The 4G row of a store's POS devices card: shown only where 4G is offered\n * and the store has an S710, or already has 4G on (so it can be turned off).\n */\nexport function posCellularView(\n config: PosCellularConfig | null,\n terminal: { cellularEnabled?: unknown; cellularSuspended?: unknown } | null | undefined,\n readers: ReadonlyArray<{ deviceType?: unknown }>,\n options: { turnOnBlocked?: string | null } = {},\n): PosCellularView | null {\n if (!config) return null\n const enabled = terminal?.cellularEnabled === true\n const capable = readers.filter((reader) => isPosCellularDeviceType(reader.deviceType)).length\n if (!enabled && capable === 0) return null\n const suspension = terminal?.cellularSuspended as Partial<PosCellularSuspension> | null | undefined\n const suspended =\n !enabled && suspension && typeof suspension.month === 'string'\n ? { month: posCellularMonthLabel(suspension.month), atMs: Number(suspension.atMs ?? 0) }\n : null\n return {\n readerMonthlyCents: posCellularReaderMonthlyCents(config),\n enabled,\n readers: capable,\n suspended,\n turnOnBlocked: options.turnOnBlocked ?? null,\n }\n}\n"],"names":["STRIPE_PROCESSOR_FEE_FIXED_USD","STRIPE_PROCESSOR_FEE_PCT","POS_CELLULAR_ENV","monthlyCostCents","billingCostBps","billingCostFixedCents","productId","graceDays","POS_CELLULAR_DEFAULT_GRACE_DAYS","POS_CELLULAR_DAY_MS","POS_CELLULAR_DEFAULT_BILLING_COST_BPS","Math","round","POS_CELLULAR_DEFAULT_BILLING_COST_FIXED_CENTS","POS_CELLULAR_DEVICE_TYPES","POS_CELLULAR_READERS_COLLECTION","POS_CELLULAR_CHARGES_COLLECTION","POS_CELLULAR_CHARGE_KIND","POS_CELLULAR_MAX_PERIODS","wholeNumber","text","fallback","max","trimmed","String","trim","test","value","Number","isSafeInteger","parsePosCellularConfig","env","process","costText","posCellularChargeCents","readers","config","passThrough","ceil","posCellularReaderMonthlyCents","isPosCellularDeviceType","deviceType","includes","posCellularMonthKey","ms","date","Date","getUTCFullYear","getUTCMonth","padStart","posCellularPreviousMonthKey","UTC","posCellularMonthBounds","month","match","exec","year","index","startMs","endMs","posCellularMonthLabel","bounds","toLocaleString","timeZone","posCellularReaderId","hostId","readerId","openPosCellularPeriod","base","existing","now","periods","open","some","period","toMs","enabled","fromMs","slice","disabledAtMs","updatedAtMs","closePosCellularPeriod","map","posCellularBilledInMonth","record","posCellularReadersByWorkspace","records","byOrg","Map","orgId","entry","get","hostIds","push","set","POS_CELLULAR_SETTLED_STATES","posCellularGraceEndsAtMs","charge","openedAtMs","posCellularOverdue","state","posCellularWarningDue","warnedAtMs","final","posCellularDayLabel","options","day","toLocaleDateString","posCellularView","terminal","suspension","cellularEnabled","capable","filter","reader","length","cellularSuspended","suspended","atMs","readerMonthlyCents","turnOnBlocked"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACE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GC,GACD,OAAO,SAAS6C,gBACdxE,MAAgC,EAChCyE,QAAuF,EACvF1E,OAAgD,EAChDsE,UAA6C,CAAC,CAAC;QASsBK,kBAOpDL;IAdjB,IAAI,CAACrE,QAAQ,OAAO;IACpB,MAAMwC,UAAUiC,CAAAA,4BAAAA,SAAUE,eAAe,MAAK;IAC9C,MAAMC,UAAU7E,QAAQ8E,MAAM,CAAC,CAACC,SAAW1E,wBAAwB0E,OAAOzE,UAAU,GAAG0E,MAAM;IAC7F,IAAI,CAACvC,WAAWoC,YAAY,GAAG,OAAO;IACtC,MAAMF,aAAaD,4BAAAA,SAAUO,iBAAiB;IAC9C,MAAMC,YACJ,CAACzC,WAAWkC,cAAc,OAAOA,WAAWzD,KAAK,KAAK,WAClD;QAAEA,OAAOO,sBAAsBkD,WAAWzD,KAAK;QAAGiE,MAAM1F,QAAOkF,mBAAAA,WAAWQ,IAAI,YAAfR,mBAAmB;IAAG,IACrF;IACN,OAAO;QACLS,oBAAoBhF,8BAA8BH;QAClDwC;QACAzC,SAAS6E;QACTK;QACAG,aAAa,GAAEf,yBAAAA,QAAQe,aAAa,YAArBf,yBAAyB;IAC1C;AACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * 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 HostProduct } from './commerce';
18
+ /** The longest note a choice or variant card carries (AGL-4205). */
19
+ export declare const PRODUCT_CHOICE_NOTE_MAX = 160;
20
+ /** The most items a combo lists, and the longest each may be (AGL-4205). */
21
+ export declare const PRODUCT_COMBO_MAX_ITEMS = 12;
22
+ export declare const PRODUCT_COMBO_ITEM_MAX = 80;
23
+ /** The longest picture address a card keeps. */
24
+ export declare const PRODUCT_CHOICE_IMAGE_URL_MAX = 2000;
25
+ /**
26
+ * Why a card's picture and note cannot be saved, or null when they can
27
+ * (AGL-4205). Shared by a choice and a variant. `what` names it in the
28
+ * message.
29
+ */
30
+ export declare function choiceCardProblem(card: {
31
+ imageUrl?: unknown;
32
+ note?: unknown;
33
+ }, what: string): string | null;
34
+ /** Why a combo's contents cannot be saved, or null when they can (AGL-4205). */
35
+ export declare function comboIncludesProblem(includes: unknown, what: string): string | null;
36
+ /** Why a product's add-on choices' cards cannot be saved, or null when they can. */
37
+ export declare function modifierCardsProblem(groups: unknown): string | null;
38
+ /** Why the product builder's fields on a product cannot be saved, or null when they can. */
39
+ export declare function productBuilderProblem(product: Pick<HostProduct, 'modifierGroups' | 'variants' | 'mockupRequests'>): string | null;
40
+ /** {@link validateProduct} and the product builder's fields: the check every product write makes. */
41
+ export declare function validateProductForSave(product: HostProduct): string | null;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * 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
+ */ import { validateProduct } from "./commerce.js";
17
+ /*
18
+ * THE PRODUCT BUILDER'S SAVE RULES (AGL-4205): a choice's or a variant's
19
+ * picture and note, what a combo includes, and the free-mockup switch. Held at
20
+ * SAVE by {@link validateProductForSave}, which every product write calls
21
+ * (the console editor, the server writers, an import), apart from
22
+ * `validateProduct` and `modifierGroupsProblem`, which the storefront also
23
+ * runs. These fields are display only, so a page never needs them checked to
24
+ * price a sale; keeping them out of the model barrel keeps them out of what
25
+ * every page downloads (check:plugin-budgets). Import this file directly.
26
+ */ /** The longest note a choice or variant card carries (AGL-4205). */ export const PRODUCT_CHOICE_NOTE_MAX = 160;
27
+ /** The most items a combo lists, and the longest each may be (AGL-4205). */ export const PRODUCT_COMBO_MAX_ITEMS = 12;
28
+ export const PRODUCT_COMBO_ITEM_MAX = 80;
29
+ /** The longest picture address a card keeps. */ export const PRODUCT_CHOICE_IMAGE_URL_MAX = 2000;
30
+ /**
31
+ * Why a card's picture and note cannot be saved, or null when they can
32
+ * (AGL-4205). Shared by a choice and a variant. `what` names it in the
33
+ * message.
34
+ */ export function choiceCardProblem(card, what) {
35
+ if (card.imageUrl != null) {
36
+ if (typeof card.imageUrl !== 'string' || card.imageUrl.length > PRODUCT_CHOICE_IMAGE_URL_MAX) {
37
+ return `Choose the picture for “${what}” again`;
38
+ }
39
+ }
40
+ if (card.note != null) {
41
+ if (typeof card.note !== 'string') return `The note on “${what}” must be text`;
42
+ if (card.note.length > PRODUCT_CHOICE_NOTE_MAX) {
43
+ return `Keep the note on “${what}” to ${PRODUCT_CHOICE_NOTE_MAX} characters`;
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ /** Why a combo's contents cannot be saved, or null when they can (AGL-4205). */ export function comboIncludesProblem(includes, what) {
49
+ if (includes == null) return null;
50
+ if (!Array.isArray(includes)) return `What “${what}” includes must be a list`;
51
+ if (includes.length > PRODUCT_COMBO_MAX_ITEMS) {
52
+ return `“${what}” lists more than ${PRODUCT_COMBO_MAX_ITEMS} items`;
53
+ }
54
+ for (const item of includes){
55
+ if (typeof item !== 'string' || !item.trim()) return `Name every item “${what}” includes`;
56
+ if (item.length > PRODUCT_COMBO_ITEM_MAX) {
57
+ return `Keep each item “${what}” includes to ${PRODUCT_COMBO_ITEM_MAX} characters`;
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ /** Why a product's add-on choices' cards cannot be saved, or null when they can. */ export function modifierCardsProblem(groups) {
63
+ if (!Array.isArray(groups)) return null;
64
+ for (const group of groups){
65
+ for (const option of Array.isArray(group == null ? void 0 : group.options) ? group.options : []){
66
+ var _choiceCardProblem;
67
+ const problem = (_choiceCardProblem = choiceCardProblem(option, option.name)) != null ? _choiceCardProblem : comboIncludesProblem(option.includes, option.name);
68
+ if (problem) return problem;
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ /** Why the product builder's fields on a product cannot be saved, or null when they can. */ export function productBuilderProblem(product) {
74
+ var _product_variants;
75
+ if (product.mockupRequests != null && typeof product.mockupRequests !== 'boolean') {
76
+ return 'Offering a free mockup is on or off';
77
+ }
78
+ for (const variant of (_product_variants = product.variants) != null ? _product_variants : []){
79
+ var _variant_options;
80
+ const problem = choiceCardProblem(variant, Object.values((_variant_options = variant.options) != null ? _variant_options : {}).filter(Boolean).join(' / ') || 'Default');
81
+ if (problem) return problem;
82
+ }
83
+ return modifierCardsProblem(product.modifierGroups);
84
+ }
85
+ /** {@link validateProduct} and the product builder's fields: the check every product write makes. */ export function validateProductForSave(product) {
86
+ var _validateProduct;
87
+ return (_validateProduct = validateProduct(product)) != null ? _validateProduct : productBuilderProblem(product);
88
+ }
89
+
90
+ //# sourceMappingURL=product-card-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-card-rules.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 { validateProduct, type HostProduct } from './commerce'\nimport type { ProductModifierGroup } from './product-modifiers'\n\n/*\n * THE PRODUCT BUILDER'S SAVE RULES (AGL-4205): a choice's or a variant's\n * picture and note, what a combo includes, and the free-mockup switch. Held at\n * SAVE by {@link validateProductForSave}, which every product write calls\n * (the console editor, the server writers, an import), apart from\n * `validateProduct` and `modifierGroupsProblem`, which the storefront also\n * runs. These fields are display only, so a page never needs them checked to\n * price a sale; keeping them out of the model barrel keeps them out of what\n * every page downloads (check:plugin-budgets). Import this file directly.\n */\n\n/** The longest note a choice or variant card carries (AGL-4205). */\nexport const PRODUCT_CHOICE_NOTE_MAX = 160\n/** The most items a combo lists, and the longest each may be (AGL-4205). */\nexport const PRODUCT_COMBO_MAX_ITEMS = 12\nexport const PRODUCT_COMBO_ITEM_MAX = 80\n/** The longest picture address a card keeps. */\nexport const PRODUCT_CHOICE_IMAGE_URL_MAX = 2000\n\n/**\n * Why a card's picture and note cannot be saved, or null when they can\n * (AGL-4205). Shared by a choice and a variant. `what` names it in the\n * message.\n */\nexport function choiceCardProblem(\n card: { imageUrl?: unknown; note?: unknown },\n what: string,\n): string | null {\n if (card.imageUrl != null) {\n if (typeof card.imageUrl !== 'string' || card.imageUrl.length > PRODUCT_CHOICE_IMAGE_URL_MAX) {\n return `Choose the picture for “${what}” again`\n }\n }\n if (card.note != null) {\n if (typeof card.note !== 'string') return `The note on “${what}” must be text`\n if (card.note.length > PRODUCT_CHOICE_NOTE_MAX) {\n return `Keep the note on “${what}” to ${PRODUCT_CHOICE_NOTE_MAX} characters`\n }\n }\n return null\n}\n\n/** Why a combo's contents cannot be saved, or null when they can (AGL-4205). */\nexport function comboIncludesProblem(includes: unknown, what: string): string | null {\n if (includes == null) return null\n if (!Array.isArray(includes)) return `What “${what}” includes must be a list`\n if (includes.length > PRODUCT_COMBO_MAX_ITEMS) {\n return `“${what}” lists more than ${PRODUCT_COMBO_MAX_ITEMS} items`\n }\n for (const item of includes) {\n if (typeof item !== 'string' || !item.trim()) return `Name every item “${what}” includes`\n if (item.length > PRODUCT_COMBO_ITEM_MAX) {\n return `Keep each item “${what}” includes to ${PRODUCT_COMBO_ITEM_MAX} characters`\n }\n }\n return null\n}\n\n/** Why a product's add-on choices' cards cannot be saved, or null when they can. */\nexport function modifierCardsProblem(groups: unknown): string | null {\n if (!Array.isArray(groups)) return null\n for (const group of groups as ProductModifierGroup[]) {\n for (const option of Array.isArray(group?.options) ? group.options : []) {\n const problem =\n choiceCardProblem(option, option.name) ?? comboIncludesProblem(option.includes, option.name)\n if (problem) return problem\n }\n }\n return null\n}\n\n/** Why the product builder's fields on a product cannot be saved, or null when they can. */\nexport function productBuilderProblem(\n product: Pick<HostProduct, 'modifierGroups' | 'variants' | 'mockupRequests'>,\n): string | null {\n if (product.mockupRequests != null && typeof product.mockupRequests !== 'boolean') {\n return 'Offering a free mockup is on or off'\n }\n for (const variant of product.variants ?? []) {\n const problem = choiceCardProblem(\n variant,\n Object.values(variant.options ?? {}).filter(Boolean).join(' / ') || 'Default',\n )\n if (problem) return problem\n }\n return modifierCardsProblem(product.modifierGroups)\n}\n\n/** {@link validateProduct} and the product builder's fields: the check every product write makes. */\nexport function validateProductForSave(product: HostProduct): string | null {\n return validateProduct(product) ?? productBuilderProblem(product)\n}\n"],"names":["validateProduct","PRODUCT_CHOICE_NOTE_MAX","PRODUCT_COMBO_MAX_ITEMS","PRODUCT_COMBO_ITEM_MAX","PRODUCT_CHOICE_IMAGE_URL_MAX","choiceCardProblem","card","what","imageUrl","length","note","comboIncludesProblem","includes","Array","isArray","item","trim","modifierCardsProblem","groups","group","option","options","problem","name","productBuilderProblem","product","mockupRequests","variant","variants","Object","values","filter","Boolean","join","modifierGroups","validateProductForSave"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,QAA0B,gBAAY;AAG9D;;;;;;;;;CASC,GAED,kEAAkE,GAClE,OAAO,MAAMC,0BAA0B,IAAG;AAC1C,0EAA0E,GAC1E,OAAO,MAAMC,0BAA0B,GAAE;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SAASc,qBAAqBC,MAAe;IAClD,IAAI,CAACL,MAAMC,OAAO,CAACI,SAAS,OAAO;IACnC,KAAK,MAAMC,SAASD,OAAkC;QACpD,KAAK,MAAME,UAAUP,MAAMC,OAAO,CAACK,yBAAAA,MAAOE,OAAO,IAAIF,MAAME,OAAO,GAAG,EAAE,CAAE;gBAErEhB;YADF,MAAMiB,WACJjB,qBAAAA,kBAAkBe,QAAQA,OAAOG,IAAI,aAArClB,qBAA0CM,qBAAqBS,OAAOR,QAAQ,EAAEQ,OAAOG,IAAI;YAC7F,IAAID,SAAS,OAAOA;QACtB;IACF;IACA,OAAO;AACT;AAEA,0FAA0F,GAC1F,OAAO,SAASE,sBACdC,OAA4E;QAKtDA;IAHtB,IAAIA,QAAQC,cAAc,IAAI,QAAQ,OAAOD,QAAQC,cAAc,KAAK,WAAW;QACjF,OAAO;IACT;IACA,KAAK,MAAMC,YAAWF,oBAAAA,QAAQG,QAAQ,YAAhBH,oBAAoB,EAAE,CAAE;YAG5BE;QAFhB,MAAML,UAAUjB,kBACdsB,SACAE,OAAOC,MAAM,EAACH,mBAAAA,QAAQN,OAAO,YAAfM,mBAAmB,CAAC,GAAGI,MAAM,CAACC,SAASC,IAAI,CAAC,UAAU;QAEtE,IAAIX,SAAS,OAAOA;IACtB;IACA,OAAOL,qBAAqBQ,QAAQS,cAAc;AACpD;AAEA,mGAAmG,GACnG,OAAO,SAASC,uBAAuBV,OAAoB;QAClDzB;IAAP,QAAOA,mBAAAA,gBAAgByB,oBAAhBzB,mBAA4BwB,sBAAsBC;AAC3D"}
@@ -25,6 +25,15 @@ export interface ProductModifierOption {
25
25
  * `priceCents`. Read through {@link modifierOptionPriceCents}.
26
26
  */
27
27
  priceCentsByVariant?: Record<string, number>;
28
+ /** A picture of the choice, from the media library, for its card (AGL-4205). */
29
+ imageUrl?: string;
30
+ /** A short line under the choice on its card (AGL-4205): "Blocks wind on one side". */
31
+ note?: string;
32
+ /**
33
+ * What a combo holds (AGL-4205), one item per entry: "Full wall ×2". A
34
+ * choice with any is shown as a combo whose contents fold out.
35
+ */
36
+ includes?: string[];
28
37
  }
29
38
  /**
30
39
  * A set of choices offered together ("Milk", "Add-ons"). `min` of 1 or more
@@ -61,6 +70,8 @@ export declare const POS_MAX_MODIFIER_GROUPS = 10;
61
70
  export declare const POS_MAX_MODIFIER_OPTIONS = 20;
62
71
  /** $1,000 on one modifier: anything larger is a product, not an add-on. */
63
72
  export declare const POS_MAX_MODIFIER_PRICE_CENTS = 100000;
73
+ /** Whether a choice is a combo: it lists what it includes (AGL-4205). */
74
+ export declare function modifierOptionIsCombo(option: Pick<ProductModifierOption, 'includes'>): boolean;
64
75
  /** Why a product's modifier groups cannot be saved, or null when they can. */
65
76
  export declare function modifierGroupsProblem(groups: unknown): string | null;
66
77
  /** How a variant is named in a choice's price list, in the editor and in an import file. */
@@ -33,9 +33,19 @@
33
33
  * prices from the product. A choice may cost more on one variant than
34
34
  * another (`priceCentsByVariant`), which is how one page sells a canopy whose
35
35
  * walls cost more at a larger size without a variant for every combination.
36
+ *
37
+ * THE PRODUCT BUILDER (AGL-4205). A choice may carry a picture and a short
38
+ * note, which a product page set to show its choices as picture cards draws
39
+ * on the choice's card. A choice that lists what it `includes` is a combo:
40
+ * one price for a bundle ("Weekend kit: 4 walls, 4 weights, a bag"), and the
41
+ * card folds its contents out. Display only: a combo is priced and sold as
42
+ * the one choice it is.
36
43
  *=========================================*/ /** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */ export const POS_MAX_MODIFIER_GROUPS = 10;
37
44
  export const POS_MAX_MODIFIER_OPTIONS = 20;
38
45
  /** $1,000 on one modifier: anything larger is a product, not an add-on. */ export const POS_MAX_MODIFIER_PRICE_CENTS = 100000;
46
+ /** Whether a choice is a combo: it lists what it includes (AGL-4205). */ export function modifierOptionIsCombo(option) {
47
+ return Array.isArray(option.includes) && option.includes.length > 0 && option.includes.every((item)=>typeof item === 'string');
48
+ }
39
49
  function modifierPriceIsValid(price) {
40
50
  return typeof price === 'number' && Number.isInteger(price) && price >= 0 && price <= POS_MAX_MODIFIER_PRICE_CENTS;
41
51
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-modifiers.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 * REGISTER MODIFIERS AND QUICK KEYS (AGL-3607).\n *\n * A modifier is a choice added to an item as it is rung up — \"Oat milk\",\n * \"Extra shot +$0.75\", \"No onions\" — that is not a stocked variant. Groups\n * live on the product (`modifierGroups`); the register sends the chosen\n * option ids with each line and the SERVER prices them from the product\n * document, so a register never names what a modifier costs.\n *\n * A chosen modifier is folded into the line's `variantLabel` as well as kept\n * structured in `modifiers`: every receipt, email, order view and export\n * already prints the label, so the choice reaches all of them without each\n * learning a new field.\n *\n * ADD-ONS ON THE WEBSITE (AGL-4100). A group switched to \"Show on the\n * website\" (`online`) is offered on the product's page too, and a cart line,\n * Buy now and the order carry its picks the same way: ids from the shopper,\n * prices from the product. A choice may cost more on one variant than\n * another (`priceCentsByVariant`), which is how one page sells a canopy whose\n * walls cost more at a larger size without a variant for every combination.\n *=========================================*/\n\n/** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */\nexport interface ProductModifierOption {\n id: string\n name: string\n priceCents: number\n /**\n * What the choice adds on one variant, keyed by variant id (AGL-4100):\n * walls cost more on a larger canopy. A variant not listed pays\n * `priceCents`. Read through {@link modifierOptionPriceCents}.\n */\n priceCentsByVariant?: Record<string, number>\n}\n\n/**\n * A set of choices offered together (\"Milk\", \"Add-ons\"). `min` of 1 or more\n * makes it required; `max` caps how many can be picked (1 = pick one).\n */\nexport interface ProductModifierGroup {\n id: string\n name: string\n min: number\n max: number\n options: ProductModifierOption[]\n /**\n * Offered on the product's page on the website as well as at the register\n * (AGL-4100), \"Show on the website\". Absent reads as register only, so a\n * group made before the switch changes nothing on a live store; the\n * console makes new groups with it on.\n */\n online?: boolean\n}\n\n/** A modifier as the order line keeps it: names and price as sold. */\nexport interface OrderLineModifier {\n groupId: string\n optionId: string\n group: string\n name: string\n priceCents: number\n}\n\n/** What the register sends for a line: the option ids it picked, nothing priced. */\nexport interface ModifierSelection {\n groupId: string\n optionId: string\n}\n\nexport const POS_MAX_MODIFIER_GROUPS = 10\nexport const POS_MAX_MODIFIER_OPTIONS = 20\n/** $1,000 on one modifier: anything larger is a product, not an add-on. */\nexport const POS_MAX_MODIFIER_PRICE_CENTS = 100_000\n\nfunction modifierPriceIsValid(price: unknown): boolean {\n return (\n typeof price === 'number' &&\n Number.isInteger(price) &&\n price >= 0 &&\n price <= POS_MAX_MODIFIER_PRICE_CENTS\n )\n}\n\n/** Why a product's modifier groups cannot be saved, or null when they can. */\nexport function modifierGroupsProblem(groups: unknown): string | null {\n if (groups == null) return null\n if (!Array.isArray(groups)) return 'Modifiers must be a list'\n if (groups.length > POS_MAX_MODIFIER_GROUPS) {\n return `At most ${POS_MAX_MODIFIER_GROUPS} modifier groups per product`\n }\n const groupIds = new Set<string>()\n for (const group of groups as ProductModifierGroup[]) {\n if (!group?.id || groupIds.has(group.id)) return 'Modifier groups need unique ids'\n groupIds.add(group.id)\n if (!String(group.name ?? '').trim()) return 'Name every modifier group'\n const options = Array.isArray(group.options) ? group.options : []\n if (options.length === 0) return `Add a choice to “${group.name}”`\n if (options.length > POS_MAX_MODIFIER_OPTIONS) {\n return `“${group.name}” has more than ${POS_MAX_MODIFIER_OPTIONS} choices`\n }\n const optionIds = new Set<string>()\n for (const option of options) {\n if (!option?.id || optionIds.has(option.id)) return 'Modifier choices need unique ids'\n optionIds.add(option.id)\n if (!String(option.name ?? '').trim()) return `Name every choice in “${group.name}”`\n const price = option.priceCents\n if (!modifierPriceIsValid(price)) {\n return `“${option.name}” needs a price of $0 to $1,000`\n }\n const byVariant = option.priceCentsByVariant\n if (byVariant != null) {\n if (typeof byVariant !== 'object' || Array.isArray(byVariant)) {\n return `“${option.name}” has prices that are not a list by option`\n }\n if (Object.values(byVariant).some((cents) => !modifierPriceIsValid(cents))) {\n return `“${option.name}” needs a price of $0 to $1,000 for each option it is priced by`\n }\n }\n }\n if (group.online != null && typeof group.online !== 'boolean') {\n return `“${group.name}” is shown on the website or not`\n }\n const { min, max } = group\n if (!Number.isInteger(min) || min < 0) return `“${group.name}” needs a minimum of 0 or more`\n if (!Number.isInteger(max) || max < 1 || max > options.length) {\n return `“${group.name}” allows 1 to ${options.length} choices`\n }\n if (min > max) return `“${group.name}” requires more choices than it allows`\n }\n return null\n}\n\n/** How a variant is named in a choice's price list, in the editor and in an import file. */\nexport function variantPriceLabel(variant: { options?: Record<string, string> }): string {\n const values = Object.values(variant.options ?? {}).filter(Boolean)\n return values.length ? values.join(' / ') : 'Default'\n}\n\n/** The product's groups, or none when they are missing or malformed. */\nexport function productModifierGroups(product: {\n modifierGroups?: unknown\n}): ProductModifierGroup[] {\n const groups = product?.modifierGroups\n if (!Array.isArray(groups) || modifierGroupsProblem(groups)) return []\n return groups as ProductModifierGroup[]\n}\n\n/** Whether a group must be answered before the item can be added. */\nexport function modifierGroupRequired(group: ProductModifierGroup): boolean {\n return group.min > 0\n}\n\n/**\n * The groups the product's page on the website offers (AGL-4100): those\n * switched to \"Show on the website\". A register-only group is never sent to\n * a shopper, never asked of one and never priced on an online order.\n */\nexport function websiteModifierGroups(product: { modifierGroups?: unknown }): ProductModifierGroup[] {\n return productModifierGroups(product).filter((group) => group.online === true)\n}\n\n/** Whether the website must ask a shopper a choice before the item goes in a cart. */\nexport function websiteModifiersRequired(product: { modifierGroups?: unknown }): boolean {\n return websiteModifierGroups(product).some(modifierGroupRequired)\n}\n\n/**\n * What one choice adds to one unit of the picked variant (AGL-4100): its\n * price on that variant where it has one, else its own price.\n */\nexport function modifierOptionPriceCents(\n option: Pick<ProductModifierOption, 'priceCents' | 'priceCentsByVariant'>,\n variantId?: string | null,\n): number {\n const byVariant = variantId ? option.priceCentsByVariant?.[variantId] : undefined\n return typeof byVariant === 'number' && Number.isFinite(byVariant) ? byVariant : option.priceCents\n}\n\n/** A line's chosen modifiers, priced. */\nexport interface ResolvedLineModifiers {\n ok: boolean\n /** The chosen modifiers, in group order; empty when not `ok`. */\n modifiers: OrderLineModifier[]\n /** What they add to one unit, in cents. */\n extraCents: number\n /** What to fix, when not `ok`. */\n error?: string\n}\n\n/** The picks a request names, as ids only, bounded; nothing for a value that is not a list. */\nexport function modifierSelectionFrom(raw: unknown): ModifierSelection[] {\n return (Array.isArray(raw) ? raw : [])\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map((entry: any) => ({\n groupId: String(entry?.groupId ?? ''),\n optionId: String(entry?.optionId ?? ''),\n }))\n}\n\n/**\n * Prices a line's chosen modifiers from the PRODUCT, in group order, and\n * checks every group's minimum and maximum. Unknown ids, a repeated choice\n * and a group answered past its maximum are refused with what to fix.\n *\n * `variantId` is the variant the line sells (AGL-4100): a choice priced by\n * variant adds its price on that one. Without it every choice adds its own\n * `priceCents`, as it always did.\n */\nexport function resolveLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n const refuse = (error: string): ResolvedLineModifiers => ({\n ok: false,\n modifiers: [],\n extraCents: 0,\n error,\n })\n const groups = productModifierGroups(product)\n const picks = modifierSelectionFrom(raw)\n const seen = new Set<string>()\n for (const pick of picks) {\n const key = `${pick.groupId}:${pick.optionId}`\n if (seen.has(key)) return refuse(`A choice on ${product.name} was picked twice.`)\n seen.add(key)\n const group = groups.find((entry) => entry.id === pick.groupId)\n if (!group || !group.options.some((option) => option.id === pick.optionId)) {\n return refuse(`A choice on ${product.name} is no longer offered. Remove it and add it again.`)\n }\n }\n const modifiers: OrderLineModifier[] = []\n for (const group of groups) {\n const chosen = group.options.filter((option) =>\n picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id),\n )\n if (chosen.length < group.min) {\n return refuse(`Choose ${group.name.toLowerCase()} for ${product.name}.`)\n }\n if (chosen.length > group.max) {\n return refuse(`Choose at most ${group.max} for ${group.name.toLowerCase()} on ${product.name}.`)\n }\n for (const option of chosen) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n return {\n ok: true,\n modifiers,\n extraCents: modifiers.reduce((sum, modifier) => sum + modifier.priceCents, 0),\n }\n}\n\n/**\n * {@link resolveLineModifiers} for a sale made online (AGL-4100): only the\n * groups shown on the website are offered, asked or priced. A register-only\n * group, required or not, is not the shopper's to answer.\n */\nexport function resolveWebsiteLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n return resolveLineModifiers(\n { name: product.name, modifierGroups: websiteModifierGroups(product) },\n raw,\n variantId,\n )\n}\n\n/**\n * The modifiers a PAID line names, for its order record (AGL-4100): every\n * pick the product still offers, in group order, priced as it is now, with no\n * minimum or maximum asked. The money was taken when the sale was priced;\n * a choice the merchant removed since is left off the record, never a reason\n * to lose the order.\n */\nexport function soldLineModifiers(\n product: { modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): OrderLineModifier[] {\n const picks = modifierSelectionFrom(raw)\n const modifiers: OrderLineModifier[] = []\n for (const group of productModifierGroups(product)) {\n for (const option of group.options) {\n if (picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id)) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n }\n return modifiers\n}\n\n/**\n * What a shopper is told about a cart line whose add-ons no longer answer\n * the product (AGL-4100): the resolver's reason, and how to put it right.\n */\nexport function cartLineModifierProblem(error: string | undefined): string {\n const reason = String(error ?? '').trim() || 'The choices on this item have changed.'\n return /Remove it and add it again/.test(reason)\n ? reason\n : `${reason} Remove it and add it again from its page.`\n}\n\n/** The picks a priced line keeps: ids only, in the product's group order. */\nexport function modifierSelectionOf(\n modifiers: readonly Pick<OrderLineModifier, 'groupId' | 'optionId'>[],\n): ModifierSelection[] {\n return modifiers.map((modifier) => ({ groupId: modifier.groupId, optionId: modifier.optionId }))\n}\n\n/**\n * The picks as one metadata value (AGL-4100), for a payment processor that\n * holds strings only: `[[\"group\",\"option\"],…]`. Empty for no picks.\n */\nexport function encodeModifierSelection(selection: readonly ModifierSelection[] | undefined): string {\n if (!selection?.length) return ''\n return JSON.stringify(selection.map((pick) => [pick.groupId, pick.optionId]))\n}\n\n/** {@link encodeModifierSelection} read back; nothing for a value it did not write. */\nexport function decodeModifierSelection(value: unknown): ModifierSelection[] {\n if (typeof value !== 'string' || !value) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed\n .filter(\n (pair): pair is [string, string] =>\n Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string',\n )\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map(([groupId, optionId]) => ({ groupId, optionId }))\n } catch {\n return []\n }\n}\n\n/** The label a line prints: the variant, then each modifier (`Large / Oat milk, Extra shot`). */\nexport function lineLabelWithModifiers(\n variantLabel: string | undefined,\n modifiers: readonly Pick<OrderLineModifier, 'name'>[],\n): string {\n const added = modifiers.map((modifier) => modifier.name).join(', ')\n return [variantLabel, added].filter(Boolean).join(' / ')\n}\n\n/** Two lines merge only when they are the same item with the same choices. */\nexport function modifierSelectionKey(selection: readonly ModifierSelection[] | undefined): string {\n return [...(selection ?? [])]\n .map((pick) => `${pick.groupId}:${pick.optionId}`)\n .sort()\n .join('|')\n}\n"],"names":["POS_MAX_MODIFIER_GROUPS","POS_MAX_MODIFIER_OPTIONS","POS_MAX_MODIFIER_PRICE_CENTS","modifierPriceIsValid","price","Number","isInteger","modifierGroupsProblem","groups","Array","isArray","length","groupIds","Set","group","id","has","add","String","name","trim","options","optionIds","option","priceCents","byVariant","priceCentsByVariant","Object","values","some","cents","online","min","max","variantPriceLabel","variant","filter","Boolean","join","productModifierGroups","product","modifierGroups","modifierGroupRequired","websiteModifierGroups","websiteModifiersRequired","modifierOptionPriceCents","variantId","undefined","isFinite","modifierSelectionFrom","raw","slice","map","entry","groupId","optionId","resolveLineModifiers","refuse","error","ok","modifiers","extraCents","picks","seen","pick","key","find","chosen","toLowerCase","push","reduce","sum","modifier","resolveWebsiteLineModifiers","soldLineModifiers","cartLineModifierProblem","reason","test","modifierSelectionOf","encodeModifierSelection","selection","JSON","stringify","decodeModifierSelection","value","parsed","parse","pair","lineLabelWithModifiers","variantLabel","added","modifierSelectionKey","sort"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;2CAoB2C,GAE3C,mFAAmF,GA+CnF,OAAO,MAAMA,0BAA0B,GAAE;AACzC,OAAO,MAAMC,2BAA2B,GAAE;AAC1C,yEAAyE,GACzE,OAAO,MAAMC,+BAA+B,OAAO;AAEnD,SAASC,qBAAqBC,KAAc;IAC1C,OACE,OAAOA,UAAU,YACjBC,OAAOC,SAAS,CAACF,UACjBA,SAAS,KACTA,SAASF;AAEb;AAEA,4EAA4E,GAC5E,OAAO,SAASK,sBAAsBC,MAAe;IACnD,IAAIA,UAAU,MAAM,OAAO;IAC3B,IAAI,CAACC,MAAMC,OAAO,CAACF,SAAS,OAAO;IACnC,IAAIA,OAAOG,MAAM,GAAGX,yBAAyB;QAC3C,OAAO,CAAC,QAAQ,EAAEA,wBAAwB,4BAA4B,CAAC;IACzE;IACA,MAAMY,WAAW,IAAIC;IACrB,KAAK,M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AAE;KAAE,CAC1B5B,GAAG,CAAC,CAACY,OAAS,GAAGA,KAAKV,OAAO,CAAC,CAAC,EAAEU,KAAKT,QAAQ,EAAE,EAChDqC,IAAI,GACJtD,IAAI,CAAC;AACV"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-modifiers.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 * REGISTER MODIFIERS AND QUICK KEYS (AGL-3607).\n *\n * A modifier is a choice added to an item as it is rung up — \"Oat milk\",\n * \"Extra shot +$0.75\", \"No onions\" — that is not a stocked variant. Groups\n * live on the product (`modifierGroups`); the register sends the chosen\n * option ids with each line and the SERVER prices them from the product\n * document, so a register never names what a modifier costs.\n *\n * A chosen modifier is folded into the line's `variantLabel` as well as kept\n * structured in `modifiers`: every receipt, email, order view and export\n * already prints the label, so the choice reaches all of them without each\n * learning a new field.\n *\n * ADD-ONS ON THE WEBSITE (AGL-4100). A group switched to \"Show on the\n * website\" (`online`) is offered on the product's page too, and a cart line,\n * Buy now and the order carry its picks the same way: ids from the shopper,\n * prices from the product. A choice may cost more on one variant than\n * another (`priceCentsByVariant`), which is how one page sells a canopy whose\n * walls cost more at a larger size without a variant for every combination.\n *\n * THE PRODUCT BUILDER (AGL-4205). A choice may carry a picture and a short\n * note, which a product page set to show its choices as picture cards draws\n * on the choice's card. A choice that lists what it `includes` is a combo:\n * one price for a bundle (\"Weekend kit: 4 walls, 4 weights, a bag\"), and the\n * card folds its contents out. Display only: a combo is priced and sold as\n * the one choice it is.\n *=========================================*/\n\n/** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */\nexport interface ProductModifierOption {\n id: string\n name: string\n priceCents: number\n /**\n * What the choice adds on one variant, keyed by variant id (AGL-4100):\n * walls cost more on a larger canopy. A variant not listed pays\n * `priceCents`. Read through {@link modifierOptionPriceCents}.\n */\n priceCentsByVariant?: Record<string, number>\n /** A picture of the choice, from the media library, for its card (AGL-4205). */\n imageUrl?: string\n /** A short line under the choice on its card (AGL-4205): \"Blocks wind on one side\". */\n note?: string\n /**\n * What a combo holds (AGL-4205), one item per entry: \"Full wall ×2\". A\n * choice with any is shown as a combo whose contents fold out.\n */\n includes?: string[]\n}\n\n/**\n * A set of choices offered together (\"Milk\", \"Add-ons\"). `min` of 1 or more\n * makes it required; `max` caps how many can be picked (1 = pick one).\n */\nexport interface ProductModifierGroup {\n id: string\n name: string\n min: number\n max: number\n options: ProductModifierOption[]\n /**\n * Offered on the product's page on the website as well as at the register\n * (AGL-4100), \"Show on the website\". Absent reads as register only, so a\n * group made before the switch changes nothing on a live store; the\n * console makes new groups with it on.\n */\n online?: boolean\n}\n\n/** A modifier as the order line keeps it: names and price as sold. */\nexport interface OrderLineModifier {\n groupId: string\n optionId: string\n group: string\n name: string\n priceCents: number\n}\n\n/** What the register sends for a line: the option ids it picked, nothing priced. */\nexport interface ModifierSelection {\n groupId: string\n optionId: string\n}\n\nexport const POS_MAX_MODIFIER_GROUPS = 10\nexport const POS_MAX_MODIFIER_OPTIONS = 20\n/** $1,000 on one modifier: anything larger is a product, not an add-on. */\nexport const POS_MAX_MODIFIER_PRICE_CENTS = 100_000\n/** Whether a choice is a combo: it lists what it includes (AGL-4205). */\nexport function modifierOptionIsCombo(option: Pick<ProductModifierOption, 'includes'>): boolean {\n return (\n Array.isArray(option.includes) &&\n option.includes.length > 0 &&\n option.includes.every((item) => typeof item === 'string')\n )\n}\n\nfunction modifierPriceIsValid(price: unknown): boolean {\n return (\n typeof price === 'number' &&\n Number.isInteger(price) &&\n price >= 0 &&\n price <= POS_MAX_MODIFIER_PRICE_CENTS\n )\n}\n\n/** Why a product's modifier groups cannot be saved, or null when they can. */\nexport function modifierGroupsProblem(groups: unknown): string | null {\n if (groups == null) return null\n if (!Array.isArray(groups)) return 'Modifiers must be a list'\n if (groups.length > POS_MAX_MODIFIER_GROUPS) {\n return `At most ${POS_MAX_MODIFIER_GROUPS} modifier groups per product`\n }\n const groupIds = new Set<string>()\n for (const group of groups as ProductModifierGroup[]) {\n if (!group?.id || groupIds.has(group.id)) return 'Modifier groups need unique ids'\n groupIds.add(group.id)\n if (!String(group.name ?? '').trim()) return 'Name every modifier group'\n const options = Array.isArray(group.options) ? group.options : []\n if (options.length === 0) return `Add a choice to “${group.name}”`\n if (options.length > POS_MAX_MODIFIER_OPTIONS) {\n return `“${group.name}” has more than ${POS_MAX_MODIFIER_OPTIONS} choices`\n }\n const optionIds = new Set<string>()\n for (const option of options) {\n if (!option?.id || optionIds.has(option.id)) return 'Modifier choices need unique ids'\n optionIds.add(option.id)\n if (!String(option.name ?? '').trim()) return `Name every choice in “${group.name}”`\n const price = option.priceCents\n if (!modifierPriceIsValid(price)) {\n return `“${option.name}” needs a price of $0 to $1,000`\n }\n const byVariant = option.priceCentsByVariant\n if (byVariant != null) {\n if (typeof byVariant !== 'object' || Array.isArray(byVariant)) {\n return `“${option.name}” has prices that are not a list by option`\n }\n if (Object.values(byVariant).some((cents) => !modifierPriceIsValid(cents))) {\n return `“${option.name}” needs a price of $0 to $1,000 for each option it is priced by`\n }\n }\n }\n if (group.online != null && typeof group.online !== 'boolean') {\n return `“${group.name}” is shown on the website or not`\n }\n const { min, max } = group\n if (!Number.isInteger(min) || min < 0) return `“${group.name}” needs a minimum of 0 or more`\n if (!Number.isInteger(max) || max < 1 || max > options.length) {\n return `“${group.name}” allows 1 to ${options.length} choices`\n }\n if (min > max) return `“${group.name}” requires more choices than it allows`\n }\n return null\n}\n\n/** How a variant is named in a choice's price list, in the editor and in an import file. */\nexport function variantPriceLabel(variant: { options?: Record<string, string> }): string {\n const values = Object.values(variant.options ?? {}).filter(Boolean)\n return values.length ? values.join(' / ') : 'Default'\n}\n\n/** The product's groups, or none when they are missing or malformed. */\nexport function productModifierGroups(product: {\n modifierGroups?: unknown\n}): ProductModifierGroup[] {\n const groups = product?.modifierGroups\n if (!Array.isArray(groups) || modifierGroupsProblem(groups)) return []\n return groups as ProductModifierGroup[]\n}\n\n/** Whether a group must be answered before the item can be added. */\nexport function modifierGroupRequired(group: ProductModifierGroup): boolean {\n return group.min > 0\n}\n\n/**\n * The groups the product's page on the website offers (AGL-4100): those\n * switched to \"Show on the website\". A register-only group is never sent to\n * a shopper, never asked of one and never priced on an online order.\n */\nexport function websiteModifierGroups(product: { modifierGroups?: unknown }): ProductModifierGroup[] {\n return productModifierGroups(product).filter((group) => group.online === true)\n}\n\n/** Whether the website must ask a shopper a choice before the item goes in a cart. */\nexport function websiteModifiersRequired(product: { modifierGroups?: unknown }): boolean {\n return websiteModifierGroups(product).some(modifierGroupRequired)\n}\n\n/**\n * What one choice adds to one unit of the picked variant (AGL-4100): its\n * price on that variant where it has one, else its own price.\n */\nexport function modifierOptionPriceCents(\n option: Pick<ProductModifierOption, 'priceCents' | 'priceCentsByVariant'>,\n variantId?: string | null,\n): number {\n const byVariant = variantId ? option.priceCentsByVariant?.[variantId] : undefined\n return typeof byVariant === 'number' && Number.isFinite(byVariant) ? byVariant : option.priceCents\n}\n\n/** A line's chosen modifiers, priced. */\nexport interface ResolvedLineModifiers {\n ok: boolean\n /** The chosen modifiers, in group order; empty when not `ok`. */\n modifiers: OrderLineModifier[]\n /** What they add to one unit, in cents. */\n extraCents: number\n /** What to fix, when not `ok`. */\n error?: string\n}\n\n/** The picks a request names, as ids only, bounded; nothing for a value that is not a list. */\nexport function modifierSelectionFrom(raw: unknown): ModifierSelection[] {\n return (Array.isArray(raw) ? raw : [])\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map((entry: any) => ({\n groupId: String(entry?.groupId ?? ''),\n optionId: String(entry?.optionId ?? ''),\n }))\n}\n\n/**\n * Prices a line's chosen modifiers from the PRODUCT, in group order, and\n * checks every group's minimum and maximum. Unknown ids, a repeated choice\n * and a group answered past its maximum are refused with what to fix.\n *\n * `variantId` is the variant the line sells (AGL-4100): a choice priced by\n * variant adds its price on that one. Without it every choice adds its own\n * `priceCents`, as it always did.\n */\nexport function resolveLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n const refuse = (error: string): ResolvedLineModifiers => ({\n ok: false,\n modifiers: [],\n extraCents: 0,\n error,\n })\n const groups = productModifierGroups(product)\n const picks = modifierSelectionFrom(raw)\n const seen = new Set<string>()\n for (const pick of picks) {\n const key = `${pick.groupId}:${pick.optionId}`\n if (seen.has(key)) return refuse(`A choice on ${product.name} was picked twice.`)\n seen.add(key)\n const group = groups.find((entry) => entry.id === pick.groupId)\n if (!group || !group.options.some((option) => option.id === pick.optionId)) {\n return refuse(`A choice on ${product.name} is no longer offered. Remove it and add it again.`)\n }\n }\n const modifiers: OrderLineModifier[] = []\n for (const group of groups) {\n const chosen = group.options.filter((option) =>\n picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id),\n )\n if (chosen.length < group.min) {\n return refuse(`Choose ${group.name.toLowerCase()} for ${product.name}.`)\n }\n if (chosen.length > group.max) {\n return refuse(`Choose at most ${group.max} for ${group.name.toLowerCase()} on ${product.name}.`)\n }\n for (const option of chosen) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n return {\n ok: true,\n modifiers,\n extraCents: modifiers.reduce((sum, modifier) => sum + modifier.priceCents, 0),\n }\n}\n\n/**\n * {@link resolveLineModifiers} for a sale made online (AGL-4100): only the\n * groups shown on the website are offered, asked or priced. A register-only\n * group, required or not, is not the shopper's to answer.\n */\nexport function resolveWebsiteLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n return resolveLineModifiers(\n { name: product.name, modifierGroups: websiteModifierGroups(product) },\n raw,\n variantId,\n )\n}\n\n/**\n * The modifiers a PAID line names, for its order record (AGL-4100): every\n * pick the product still offers, in group order, priced as it is now, with no\n * minimum or maximum asked. The money was taken when the sale was priced;\n * a choice the merchant removed since is left off the record, never a reason\n * to lose the order.\n */\nexport function soldLineModifiers(\n product: { modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): OrderLineModifier[] {\n const picks = modifierSelectionFrom(raw)\n const modifiers: OrderLineModifier[] = []\n for (const group of productModifierGroups(product)) {\n for (const option of group.options) {\n if (picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id)) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n }\n return modifiers\n}\n\n/**\n * What a shopper is told about a cart line whose add-ons no longer answer\n * the product (AGL-4100): the resolver's reason, and how to put it right.\n */\nexport function cartLineModifierProblem(error: string | undefined): string {\n const reason = String(error ?? '').trim() || 'The choices on this item have changed.'\n return /Remove it and add it again/.test(reason)\n ? reason\n : `${reason} Remove it and add it again from its page.`\n}\n\n/** The picks a priced line keeps: ids only, in the product's group order. */\nexport function modifierSelectionOf(\n modifiers: readonly Pick<OrderLineModifier, 'groupId' | 'optionId'>[],\n): ModifierSelection[] {\n return modifiers.map((modifier) => ({ groupId: modifier.groupId, optionId: modifier.optionId }))\n}\n\n/**\n * The picks as one metadata value (AGL-4100), for a payment processor that\n * holds strings only: `[[\"group\",\"option\"],…]`. Empty for no picks.\n */\nexport function encodeModifierSelection(selection: readonly ModifierSelection[] | undefined): string {\n if (!selection?.length) return ''\n return JSON.stringify(selection.map((pick) => [pick.groupId, pick.optionId]))\n}\n\n/** {@link encodeModifierSelection} read back; nothing for a value it did not write. */\nexport function decodeModifierSelection(value: unknown): ModifierSelection[] {\n if (typeof value !== 'string' || !value) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed\n .filter(\n (pair): pair is [string, string] =>\n Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string',\n )\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map(([groupId, optionId]) => ({ groupId, optionId }))\n } catch {\n return []\n }\n}\n\n/** The label a line prints: the variant, then each modifier (`Large / Oat milk, Extra shot`). */\nexport function lineLabelWithModifiers(\n variantLabel: string | undefined,\n modifiers: readonly Pick<OrderLineModifier, 'name'>[],\n): string {\n const added = modifiers.map((modifier) => modifier.name).join(', ')\n return [variantLabel, added].filter(Boolean).join(' / ')\n}\n\n/** Two lines merge only when they are the same item with the same choices. */\nexport function modifierSelectionKey(selection: readonly ModifierSelection[] | undefined): string {\n return [...(selection ?? [])]\n .map((pick) => `${pick.groupId}:${pick.optionId}`)\n .sort()\n .join('|')\n}\n"],"names":["POS_MAX_MODIFIER_GROUPS","POS_MAX_MODIFIER_OPTIONS","POS_MAX_MODIFIER_PRICE_CENTS","modifierOptionIsCombo","option","Array","isArray","includes","length","every","item","modifierPriceIsValid","price","Number","isInteger","modifierGroupsProblem","groups","groupIds","Set","group","id","has","add","String","name","trim","options","optionIds","priceCents","byVariant","priceCentsByVariant","Object","values","some","cents","online","min","max","variantPriceLabel","variant","filter","Boolean","join","productModifierGroups","product","modifierGroups","modifierGroupRequired","websiteModifierGroups","websiteModifiersRequired","modifierOptionPriceCents","variantId","undefined","isFinite","modifierSelectionFrom","raw","slice","map","entry","groupId","optionId","resolveLineModifiers","refuse","error","ok","modifiers","extraCents","picks","seen","pick","key","find","chosen","toLowerCase","push","reduce","sum","modifier","resolveWebsiteLineModifiers","soldLineModifiers","cartLineModifierProblem","reason","test","modifierSelectionOf","encodeModifierSelection","selection","JSON","stringify","decodeModifierSelection","value","parsed","parse","pair","lineLabelWithModif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;YAAEU,KAAKT,QAAQ;SAAC;AAC7E;AAEA,qFAAqF,GACrF,OAAO,SAAS4B,wBAAwBC,KAAc;IACpD,IAAI,OAAOA,UAAU,YAAY,CAACA,OAAO,OAAO,EAAE;IAClD,IAAI;QACF,MAAMC,SAAkBJ,KAAKK,KAAK,CAACF;QACnC,IAAI,CAACnF,MAAMC,OAAO,CAACmF,SAAS,OAAO,EAAE;QACrC,OAAOA,OACJjD,MAAM,CACL,CAACmD,OACCtF,MAAMC,OAAO,CAACqF,SAAS,OAAOA,IAAI,CAAC,EAAE,KAAK,YAAY,OAAOA,IAAI,CAAC,EAAE,KAAK,UAE5EpC,KAAK,CAAC,GAAGvD,0BAA0BC,0BACnCuD,GAAG,CAAC,CAAC,CAACE,SAASC,SAAS,GAAM,CAAA;gBAAED;gBAASC;YAAS,CAAA;IACvD,EAAE,eAAM;QACN,OAAO,EAAE;IACX;AACF;AAEA,+FAA+F,GAC/F,OAAO,SAASiC,uBACdC,YAAgC,EAChC7B,SAAqD;IAErD,MAAM8B,QAAQ9B,UAAUR,GAAG,CAAC,CAACoB,WAAaA,SAASpD,IAAI,EAAEkB,IAAI,CAAC;IAC9D,OAAO;QAACmD;QAAcC;KAAM,CAACtD,MAAM,CAACC,SAASC,IAAI,CAAC;AACpD;AAEA,4EAA4E,GAC5E,OAAO,SAASqD,qBAAqBX,SAAmD;IACtF,OAAO;WAAKA,oBAAAA,YAAa,EAAE;KAAE,CAC1B5B,GAAG,CAAC,CAACY,OAAS,GAAGA,KAAKV,OAAO,CAAC,CAAC,EAAEU,KAAKT,QAAQ,EAAE,EAChDqC,IAAI,GACJtD,IAAI,CAAC;AACV"}
@@ -88,6 +88,7 @@ export declare function productSaveFields(current: EditedProduct, nowMs: number)
88
88
  giftCard?: boolean;
89
89
  lowStockThreshold?: number;
90
90
  modifierGroups?: import("./product-modifiers").ProductModifierGroup[];
91
+ mockupRequests?: boolean;
91
92
  posQuickKey?: boolean;
92
93
  sellOnline?: boolean;
93
94
  inStoreReviews?: "show" | "hide";
@@ -169,6 +170,7 @@ export declare function productEditWrite(fields: ReturnType<typeof productSaveFi
169
170
  giftCard?: boolean;
170
171
  lowStockThreshold?: number;
171
172
  modifierGroups?: import("./product-modifiers").ProductModifierGroup[];
173
+ mockupRequests?: boolean;
172
174
  posQuickKey?: boolean;
173
175
  sellOnline?: boolean;
174
176
  inStoreReviews?: "show" | "hide";
@@ -245,6 +247,7 @@ export declare function productDuplicateFields(product: HostProduct & {
245
247
  giftCard?: boolean;
246
248
  lowStockThreshold?: number;
247
249
  modifierGroups?: import("./product-modifiers").ProductModifierGroup[];
250
+ mockupRequests?: boolean;
248
251
  posQuickKey?: boolean;
249
252
  sellOnline?: boolean;
250
253
  inStoreReviews?: "show" | "hide";
@@ -1858,10 +1858,14 @@ export const commerceBillingWebhookHandler = async ({ type, object, event, reque
1858
1858
  // THE REGISTER'S CARD PAYMENTS (AGL-3607): Terminal reader actions, register
1859
1859
  // PaymentIntents and register QR pages. Each names one payment on an open
1860
1860
  // sale and is settled by re-reading Stripe in `pos-terminal.ts`; every other
1861
- // event falls through untouched.
1861
+ // event falls through untouched. A direct-charge store's register objects
1862
+ // live on its own account, so their events arrive through the Connect
1863
+ // destination naming it (and carry `metadata.chargeModel: direct`, which is
1864
+ // what let them past the gate above).
1862
1865
  const posPayment = await handlePosStripeEvent({
1863
1866
  type,
1864
- object
1867
+ object,
1868
+ account: connectEventAccount(event)
1865
1869
  });
1866
1870
  if (posPayment) return {
1867
1871
  claimed: true,