@aglyn/plugins-commerce 1.15.0 → 1.15.1

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 (87) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/cart.js +8 -3
  3. package/src/lib/components/cart.js.map +1 -1
  4. package/src/lib/components/console/payments-settings-card.component.js +1 -1
  5. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  6. package/src/lib/components/console/subscription-detail-dialog.component.js +2 -2
  7. package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -1
  8. package/src/lib/components/console/subscriptions-card.component.js +4 -2
  9. package/src/lib/components/console/subscriptions-card.component.js.map +1 -1
  10. package/src/lib/components/product-detail.js +7 -3
  11. package/src/lib/components/product-detail.js.map +1 -1
  12. package/src/lib/components/quote-page-body.js +7 -3
  13. package/src/lib/components/quote-page-body.js.map +1 -1
  14. package/src/lib/components/related-products.js +6 -3
  15. package/src/lib/components/related-products.js.map +1 -1
  16. package/src/lib/components/storefront-payment-element.d.ts +7 -1
  17. package/src/lib/components/storefront-payment-element.js +11 -7
  18. package/src/lib/components/storefront-payment-element.js.map +1 -1
  19. package/src/lib/model/commerce-payment-methods.d.ts +26 -39
  20. package/src/lib/model/commerce-payment-methods.js +11 -118
  21. package/src/lib/model/commerce-payment-methods.js.map +1 -1
  22. package/src/lib/server/billing-webhook.d.ts +23 -0
  23. package/src/lib/server/billing-webhook.js +162 -30
  24. package/src/lib/server/billing-webhook.js.map +1 -1
  25. package/src/lib/server/cancel-order.js +4 -3
  26. package/src/lib/server/cancel-order.js.map +1 -1
  27. package/src/lib/server/cart-checkout.js +61 -14
  28. package/src/lib/server/cart-checkout.js.map +1 -1
  29. package/src/lib/server/catalog.js +58 -22
  30. package/src/lib/server/catalog.js.map +1 -1
  31. package/src/lib/server/checkout-session-expiry.d.ts +1 -1
  32. package/src/lib/server/checkout-session-expiry.js +19 -5
  33. package/src/lib/server/checkout-session-expiry.js.map +1 -1
  34. package/src/lib/server/checkout-status.js +4 -3
  35. package/src/lib/server/checkout-status.js.map +1 -1
  36. package/src/lib/server/checkout.js +42 -12
  37. package/src/lib/server/checkout.js.map +1 -1
  38. package/src/lib/server/connect.js +42 -11
  39. package/src/lib/server/connect.js.map +1 -1
  40. package/src/lib/server/draft-order.js +37 -12
  41. package/src/lib/server/draft-order.js.map +1 -1
  42. package/src/lib/server/manual-tax-rate.d.ts +11 -3
  43. package/src/lib/server/manual-tax-rate.js +10 -6
  44. package/src/lib/server/manual-tax-rate.js.map +1 -1
  45. package/src/lib/server/native-checkout.d.ts +10 -3
  46. package/src/lib/server/native-checkout.js +8 -3
  47. package/src/lib/server/native-checkout.js.map +1 -1
  48. package/src/lib/server/payment-method-domains.d.ts +50 -9
  49. package/src/lib/server/payment-method-domains.js +150 -51
  50. package/src/lib/server/payment-method-domains.js.map +1 -1
  51. package/src/lib/server/payment-methods.js +3 -2
  52. package/src/lib/server/payment-methods.js.map +1 -1
  53. package/src/lib/server/pos-order.js +5 -1
  54. package/src/lib/server/pos-order.js.map +1 -1
  55. package/src/lib/server/pos-stripe.d.ts +7 -7
  56. package/src/lib/server/pos-stripe.js +15 -13
  57. package/src/lib/server/pos-stripe.js.map +1 -1
  58. package/src/lib/server/pos-terminal.js +11 -3
  59. package/src/lib/server/pos-terminal.js.map +1 -1
  60. package/src/lib/server/quote-pay.d.ts +23 -1
  61. package/src/lib/server/quote-pay.js +112 -32
  62. package/src/lib/server/quote-pay.js.map +1 -1
  63. package/src/lib/server/quote.d.ts +2 -1
  64. package/src/lib/server/quote.js +12 -11
  65. package/src/lib/server/quote.js.map +1 -1
  66. package/src/lib/server/refund.js +13 -6
  67. package/src/lib/server/refund.js.map +1 -1
  68. package/src/lib/server/related.js +10 -3
  69. package/src/lib/server/related.js.map +1 -1
  70. package/src/lib/server/reserve.js +19 -6
  71. package/src/lib/server/reserve.js.map +1 -1
  72. package/src/lib/server/revenue-source.d.ts +6 -0
  73. package/src/lib/server/revenue-source.js +25 -9
  74. package/src/lib/server/revenue-source.js.map +1 -1
  75. package/src/lib/server/seller-stripe-account.d.ts +45 -0
  76. package/src/lib/server/seller-stripe-account.js +99 -0
  77. package/src/lib/server/seller-stripe-account.js.map +1 -0
  78. package/src/lib/server/storefront-tax-record.js +6 -1
  79. package/src/lib/server/storefront-tax-record.js.map +1 -1
  80. package/src/lib/server/storefront-tax.d.ts +33 -2
  81. package/src/lib/server/storefront-tax.js +39 -3
  82. package/src/lib/server/storefront-tax.js.map +1 -1
  83. package/src/lib/server/stripe-refund.d.ts +15 -0
  84. package/src/lib/server/stripe-refund.js +54 -26
  85. package/src/lib/server/stripe-refund.js.map +1 -1
  86. package/src/lib/server/subscription-portal.js +8 -3
  87. package/src/lib/server/subscription-portal.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/subscription-detail-dialog.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport {\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Divider,\n Link,\n Stack,\n Typography,\n} from '@mui/material'\nimport { collection, limit, orderBy, query } from 'firebase/firestore'\nimport { useFirestore, useFirestoreCollection } from '@aglyn/tenant-feature-instance'\n\n/** How many of a subscription's invoices the dialog lists: two years of monthly cycles. */\nexport const SUBSCRIPTION_INVOICE_WINDOW = 24\n\n/** A stored subscription, as far as this list reads one. */\nexport interface SubscriptionRow {\n $id: string\n productId?: string\n customerEmail?: string | null\n customerName?: string | null\n status?: string\n interval?: string\n cancelAtPeriodEnd?: boolean\n currentPeriodEndMs?: number | null\n paidThroughMs?: number\n createdAtMs?: number\n paidCents?: number\n invoicesCount?: number\n livemode?: boolean\n lineItems?: Array<{ name?: string; quantity?: number }>\n totals?: { totalCents?: number; taxCents?: number }\n}\n\nexport interface SubscriptionDetailDialogProps {\n hostId: string\n subscription: SubscriptionRow\n currency: string\n onClose: () => void\n}\n\ninterface InvoiceRow {\n $id: string\n number?: string\n paidCents?: number\n currency?: string\n paidAtMs?: number\n periodStartMs?: number\n periodEndMs?: number\n billingReason?: string\n hostedInvoiceUrl?: string\n}\n\nfunction Fact(props: { label: string; value: string }) {\n return (\n <Box sx={{ display: 'flex', gap: 2 }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ minWidth: 140 }}>\n {props.label}\n </Typography>\n <Typography variant=\"body2\">{props.value}</Typography>\n </Box>\n )\n}\n\n/**\n * One subscription and its invoices (AGL-4191). Every paid cycle is recorded\n * under `subscriptions/{id}/invoices` by the billing webhook, and this is the\n * first place a merchant can read them without opening Stripe.\n */\nexport function SubscriptionDetailDialog(props: SubscriptionDetailDialogProps) {\n const { hostId, subscription, currency, onClose } = props\n const firestore = useFirestore()\n const { data: invoiceDocs, status } = useFirestoreCollection<InvoiceRow>(\n () =>\n query(\n collection(firestore, 'hosts', hostId, 'subscriptions', subscription.$id, 'invoices'),\n orderBy('paidAtMs', 'desc'),\n limit(SUBSCRIPTION_INVOICE_WINDOW),\n ),\n [firestore, hostId, subscription.$id],\n { idField: '$id' },\n )\n const invoices = invoiceDocs ?? []\n const money = (cents: number, code = currency) => CommerceModel.formatOrderMoney(cents, code)\n const date = CommerceModel.formatSubscriptionDate\n const dateText = CommerceModel.subscriptionDateText(\n CommerceModel.subscriptionDateLine(subscription),\n )\n const price =\n subscription.totals?.totalCents != null\n ? `${money(Number(subscription.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(subscription.interval)}`\n : ''\n\n return (\n <Dialog open onClose={onClose} maxWidth=\"sm\" fullWidth>\n <DialogTitle>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>{CommerceModel.subscriptionPlanName(subscription)}</Box>\n <Chip\n label={CommerceModel.subscriptionStatusLabel(subscription.status)}\n size=\"small\"\n color={CommerceModel.subscriptionStatusColor(subscription.status)}\n variant=\"outlined\"\n />\n </Stack>\n </DialogTitle>\n <DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <Fact\n label=\"Customer\"\n value={\n [subscription.customerName, subscription.customerEmail].filter(Boolean).join(' · ') ||\n 'Unknown customer'\n }\n />\n {price ? <Fact label=\"Price\" value={price} /> : null}\n {subscription.createdAtMs ? (\n <Fact label=\"Started\" value={date(subscription.createdAtMs)} />\n ) : null}\n {dateText ? <Fact label=\"Next\" value={dateText} /> : null}\n <Fact\n label=\"Paid so far\"\n value={`${money(Number(subscription.paidCents) || 0)} over ${Number(subscription.invoicesCount ?? 0)} ${\n Number(subscription.invoicesCount ?? 0) === 1 ? 'invoice' : 'invoices'\n }`}\n />\n {subscription.livemode === false ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A test-mode subscription: no real money moved, and it is not counted in your recurring revenue.'}\n </Typography>\n ) : null}\n <Divider textAlign=\"left\" sx={{ mt: 1 }}>\n {'Invoices'}\n </Divider>\n {invoices.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {status === 'loading' ? 'Loading invoices…' : 'No invoices recorded yet.'}\n </Typography>\n ) : (\n invoices.map((invoice) => (\n <Box key={invoice.$id} sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\">\n {invoice.paidAtMs ? date(invoice.paidAtMs) : 'Date unknown'}\n {invoice.number ? ` · ${invoice.number}` : ''}\n </Typography>\n {invoice.periodStartMs && invoice.periodEndMs ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`For ${date(invoice.periodStartMs)} to ${date(invoice.periodEndMs)}`}\n </Typography>\n ) : null}\n </Box>\n <Typography variant=\"body2\">\n {money(Number(invoice.paidCents) || 0, invoice.currency || currency)}\n </Typography>\n {invoice.hostedInvoiceUrl ? (\n <Link href={invoice.hostedInvoiceUrl} target=\"_blank\" rel=\"noopener noreferrer\" variant=\"body2\">\n {'View'}\n </Link>\n ) : null}\n </Box>\n ))\n )}\n {invoices.length >= SUBSCRIPTION_INVOICE_WINDOW ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`The ${SUBSCRIPTION_INVOICE_WINDOW} most recent invoices.`}\n </Typography>\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Close'}</Button>\n </DialogActions>\n </Dialog>\n )\n}\nSubscriptionDetailDialog.displayName = 'SubscriptionDetailDialog'\n\nexport default SubscriptionDetailDialog\n"],"names":["CommerceModel","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Divider","Link","Stack","Typography","collection","limit","orderBy","query","useFirestore","useFirestoreCollection","SUBSCRIPTION_INVOICE_WINDOW","Fact","props","sx","display","gap","variant","color","minWidth","label","value","SubscriptionDetailDialog","subscription","hostId","currency","onClose","firestore","data","invoiceDocs","status","$id","idField","invoices","money","cents","code","formatOrderMoney","date","formatSubscriptionDate","dateText","subscriptionDateText","subscriptionDateLine","price","totals","totalCents","Number","subscriptionIntervalSuffix","interval","open","maxWidth","fullWidth","direction","spacing","alignItems","flex","subscriptionPlanName","subscriptionStatusLabel","size","subscriptionStatusColor","flexDirection","customerName","customerEmail","filter","Boolean","join","createdAtMs","paidCents","invoicesCount","livemode","textAlign","mt","length","map","invoice","paidAtMs","number","periodStartMs","periodEndMs","hostedInvoiceUrl","href","target","rel","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SACEC,GAAG,EAC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AAI7D,4CAClB,KAACP;wBAAWa,SAAQ;wBAAUC,OAAM;kCACjC,CAAC,IAAI,EAAEP,4BAA4B,sBAAsB,CAAC;yBAE3D;;;0BAEN,KAACb;0BACC,cAAA,KAACH;oBAAOwF,SAASzD;8BAAU;;;;;AAInC;AACAJ,yBAAyB8D,WAAW,GAAG;AAEvC,eAAe9D,yBAAwB"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/subscription-detail-dialog.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport {\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Divider,\n Link,\n Stack,\n Typography,\n} from '@mui/material'\nimport { collection, limit, orderBy, query } from 'firebase/firestore'\nimport { useFirestore, useFirestoreCollection } from '@aglyn/tenant-feature-instance'\n\n/** How many of a subscription's invoices the dialog lists: two years of monthly cycles. */\nexport const SUBSCRIPTION_INVOICE_WINDOW = 24\n\n/** A stored subscription, as far as this list reads one. */\nexport interface SubscriptionRow {\n $id: string\n productId?: string\n customerEmail?: string | null\n customerName?: string | null\n status?: string\n interval?: string\n cancelAtPeriodEnd?: boolean\n currentPeriodEndMs?: number | null\n paidThroughMs?: number\n createdAtMs?: number\n paidCents?: number\n invoicesCount?: number\n livemode?: boolean\n lineItems?: Array<{ name?: string; quantity?: number }>\n totals?: { totalCents?: number; taxCents?: number }\n}\n\nexport interface SubscriptionDetailDialogProps {\n hostId: string\n subscription: SubscriptionRow\n currency: string\n onClose: () => void\n}\n\ninterface InvoiceRow {\n $id: string\n number?: string\n paidCents?: number\n currency?: string\n paidAtMs?: number\n periodStartMs?: number\n periodEndMs?: number\n billingReason?: string\n hostedInvoiceUrl?: string\n}\n\nfunction Fact(props: { label: string; value: string }) {\n return (\n <Box sx={{ display: 'flex', gap: 2 }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ minWidth: 140 }}>\n {props.label}\n </Typography>\n <Typography variant=\"body2\">{props.value}</Typography>\n </Box>\n )\n}\n\n/**\n * One subscription and its invoices (AGL-4191). Every paid cycle is recorded\n * under `subscriptions/{id}/invoices` by the billing webhook, and this is the\n * first place a merchant can read them without opening Stripe.\n */\nexport function SubscriptionDetailDialog(props: SubscriptionDetailDialogProps) {\n const { hostId, subscription, currency, onClose } = props\n const firestore = useFirestore()\n const { data: invoiceDocs, status } = useFirestoreCollection<InvoiceRow>(\n () =>\n query(\n collection(firestore, 'hosts', hostId, 'subscriptions', subscription.$id, 'invoices'),\n orderBy('paidAtMs', 'desc'),\n limit(SUBSCRIPTION_INVOICE_WINDOW),\n ),\n [firestore, hostId, subscription.$id],\n { idField: '$id' },\n )\n const invoices = invoiceDocs ?? []\n const money = (cents: number, code = currency) => CommerceModel.formatOrderMoney(cents, code)\n const date = CommerceModel.formatSubscriptionDate\n const dateText = CommerceModel.subscriptionDateText(\n CommerceModel.subscriptionDateLine(subscription),\n )\n const price =\n subscription.totals?.totalCents != null\n ? `${money(Number(subscription.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(subscription.interval)}`\n : ''\n\n return (\n <Dialog open onClose={onClose} maxWidth=\"sm\" fullWidth>\n <DialogTitle>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>{CommerceModel.subscriptionPlanName(subscription)}</Box>\n <Chip\n label={CommerceModel.subscriptionStatusLabel(subscription.status)}\n size=\"small\"\n color={CommerceModel.subscriptionStatusColor(subscription.status)}\n variant=\"outlined\"\n />\n </Stack>\n </DialogTitle>\n <DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <Fact\n label=\"Customer\"\n value={\n [subscription.customerName, subscription.customerEmail].filter(Boolean).join(' · ') ||\n 'Unknown customer'\n }\n />\n {price ? <Fact label=\"Price\" value={price} /> : null}\n {subscription.createdAtMs ? (\n <Fact label=\"Started\" value={date(subscription.createdAtMs)} />\n ) : null}\n {dateText ? <Fact label=\"Next\" value={dateText} /> : null}\n <Fact\n label=\"Paid so far\"\n value={\n Number(subscription.paidCents ?? 0) > 0\n ? `${money(Number(subscription.paidCents) || 0)} over ${Number(subscription.invoicesCount ?? 0)} ${\n Number(subscription.invoicesCount ?? 0) === 1 ? 'invoice' : 'invoices'\n }`\n : 'Nothing yet'\n }\n />\n {subscription.livemode === false ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A test-mode subscription: no real money moved, and it is not counted in your recurring revenue.'}\n </Typography>\n ) : null}\n <Divider textAlign=\"left\" sx={{ mt: 1 }}>\n {'Invoices'}\n </Divider>\n {invoices.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {status === 'loading' ? 'Loading invoices…' : 'No invoices recorded yet.'}\n </Typography>\n ) : (\n invoices.map((invoice) => (\n <Box key={invoice.$id} sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\">\n {invoice.paidAtMs ? date(invoice.paidAtMs) : 'Date unknown'}\n {invoice.number ? ` · ${invoice.number}` : ''}\n </Typography>\n {invoice.periodStartMs && invoice.periodEndMs ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`For ${date(invoice.periodStartMs)} to ${date(invoice.periodEndMs)}`}\n </Typography>\n ) : null}\n </Box>\n <Typography variant=\"body2\">\n {money(Number(invoice.paidCents) || 0, invoice.currency || currency)}\n </Typography>\n {invoice.hostedInvoiceUrl ? (\n <Link href={invoice.hostedInvoiceUrl} target=\"_blank\" rel=\"noopener noreferrer\" variant=\"body2\">\n {'View'}\n </Link>\n ) : null}\n </Box>\n ))\n )}\n {invoices.length >= SUBSCRIPTION_INVOICE_WINDOW ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`The ${SUBSCRIPTION_INVOICE_WINDOW} most recent invoices.`}\n </Typography>\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Close'}</Button>\n </DialogActions>\n </Dialog>\n )\n}\nSubscriptionDetailDialog.displayName = 'SubscriptionDetailDialog'\n\nexport default SubscriptionDetailDialog\n"],"names":["CommerceModel","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Divider","Link","Stack","Typography","collection","limit","orderBy","query","useFirestore","useFirestoreCollection","SUBSCRIPTION_INVOICE_WINDOW","Fact","props","sx","display","gap","variant","color","minWidth","label","value","SubscriptionDetailDialog","subscription","hostId","currency","onClose","firestore","data","invoiceDocs","status","$id","idField","invoices","money","cents","code","formatOrderMoney","date","formatSubscriptionDate","dateText","subscriptionDateText","subscriptionDateLine","price","totals","totalCents","Number","subscriptionIntervalSuffix","interval","open","maxWidth","fullWidth","direction","spacing","alignItems","flex","subscriptionPlanName","subscriptionStatusLabel","size","subscriptionStatusColor","flexDirection","customerName","customerEmail","filter","Boolean","join","createdAtMs","paidCents","invoicesCount","livemode","textAlign","mt","length","map","invoice","paidAtMs","number","periodStartMs","periodEndMs","hostedInvoiceUrl","href","target","rel","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SACEC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,OAAO,EACPC,IAAI,EACJC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAEC,KAAK,QAAQ,qBAAoB;AACtE,SAASC,YAAY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;oBAAOwF,SAASzD;8BAAU;;;;;AAInC;AACAJ,yBAAyB8D,WAAW,GAAG;AAEvC,eAAe9D,yBAAwB"}
@@ -213,11 +213,13 @@ import SubscriptionDetailDialog from "./subscription-detail-dialog.component.js"
213
213
  }) : /*#__PURE__*/ _jsx(List, {
214
214
  disablePadding: true,
215
215
  children: rows.map((row)=>{
216
- var _row_invoicesCount;
216
+ var _row_paidCents;
217
217
  var _row_totals;
218
218
  const dateText = CommerceModel.subscriptionDateText(CommerceModel.subscriptionDateLine(row));
219
219
  const price = ((_row_totals = row.totals) == null ? void 0 : _row_totals.totalCents) != null ? `${money(Number(row.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(row.interval)}` : '';
220
- const paid = Number((_row_invoicesCount = row.invoicesCount) != null ? _row_invoicesCount : 0) > 0 ? `${money(Number(row.paidCents) || 0)} paid so far` : '';
220
+ // A trial's opening invoice is $0: nothing has been paid yet,
221
+ // so the row says nothing rather than "$0.00 paid so far".
222
+ const paid = Number((_row_paidCents = row.paidCents) != null ? _row_paidCents : 0) > 0 ? `${money(Number(row.paidCents) || 0)} paid so far` : '';
221
223
  return /*#__PURE__*/ _jsxs(ListItemButton, {
222
224
  onClick: ()=>setSelectedId(row.$id),
223
225
  divider: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/subscriptions-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n Chip,\n List,\n ListItemButton,\n ListItemText,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n doc,\n getAggregateFromServer,\n limit,\n orderBy,\n query,\n sum,\n count,\n where,\n type Firestore,\n} from 'firebase/firestore'\nimport { useSearchParams } from 'next/navigation'\nimport { useEffect, useRef, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreDoc,\n usePagedCollection,\n} from '@aglyn/tenant-feature-instance'\nimport CommerceStatTile from './commerce-stat-tile.component'\nimport SubscriptionDetailDialog, { type SubscriptionRow } from './subscription-detail-dialog.component'\n\nexport interface SubscriptionsCardProps {\n hostId: string\n}\n\n/** The query key that opens one subscription on arrival: the renewal notification's link. */\nexport const SUBSCRIPTIONS_SUBSCRIPTION_PARAM = 'subscription'\n\ntype SubscriptionFilter = (typeof CommerceModel.SUBSCRIPTION_FILTER_STATUSES)[number] | 'all'\n\nexport interface SubscriptionsSummary {\n monthlyRecurringCents: number\n payingCount: number\n trialCount: number\n pastDueCount: number\n}\n\n/**\n * The figures above the list, from aggregation queries: what a store with\n * thousands of subscribers pays for is a handful of index reads, never one\n * read per subscriber.\n *\n * Monthly recurring revenue is summed per billing interval, because a sum\n * cannot divide a yearly price by twelve on the way. Only LIVE-mode\n * subscriptions count: a test checkout is a rehearsal, and the order\n * analytics leave it out for the same reason (`order-analytics.ts`). A\n * subscription with no stored `interval` is left out of the figure rather\n * than guessed at; every sale since AGL-1732 stores one.\n */\nexport async function loadSubscriptionsSummary(\n firestore: Firestore,\n hostId: string,\n): Promise<SubscriptionsSummary> {\n const subscriptions = collection(firestore, 'hosts', hostId, 'subscriptions')\n const paying = (interval: CommerceModel.SubscriptionBillingInterval) =>\n getAggregateFromServer(\n query(\n subscriptions,\n where('status', 'in', [...CommerceModel.SUBSCRIPTION_PAYING_STATUSES]),\n where('interval', '==', interval),\n where('livemode', '==', true),\n ),\n {\n subscriptions: count(),\n totalCents: sum('totals.totalCents'),\n taxCents: sum('totals.taxCents'),\n },\n )\n const counted = (status: string) =>\n getAggregateFromServer(\n query(subscriptions, where('status', '==', status), where('livemode', '==', true)),\n { subscriptions: count() },\n )\n // AGL-1715-EXEMPT: four separate count queries, one per figure on the card;\n // the status words are each query's own filter, not a membership set.\n const [monthly, yearly, trials, pastDue] = await Promise.all([\n paying('month'),\n paying('year'),\n counted('trialing'),\n counted('past_due'),\n ])\n const figure = (value: unknown) => Number(value) || 0\n return {\n monthlyRecurringCents:\n CommerceModel.monthlyRecurringCents(\n monthly.data().totalCents,\n monthly.data().taxCents,\n 'month',\n ) +\n CommerceModel.monthlyRecurringCents(\n yearly.data().totalCents,\n yearly.data().taxCents,\n 'year',\n ),\n payingCount: figure(monthly.data().subscriptions) + figure(yearly.data().subscriptions),\n trialCount: figure(trials.data().subscriptions),\n pastDueCount: figure(pastDue.data().subscriptions),\n }\n}\n\n/**\n * Subscriptions (AGL-4191): every subscription on the site, newest first, and\n * what they add up to.\n *\n * Until this, a merchant could see subscriptions only one person at a time, in\n * a site member's Purchases: a digital or service subscription writes no order\n * per cycle, so Orders never showed them either.\n *\n * THE STATUS FILTER IS THE QUERY, as on Returns: `status == X` ordered by\n * `createdAtMs` descending, served by the `subscriptions(status ASC,\n * createdAtMs DESC)` composite; \"All\" is the single-field order alone. Opening\n * a row shows the subscription's invoices; `?subscription={id}` opens one on\n * arrival, which is where the renewal notification links.\n */\nexport function SubscriptionsCard(props: SubscriptionsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const [filter, setFilter] = useState<SubscriptionFilter>('all')\n const [selectedId, setSelectedId] = useState<string | null>(null)\n const [summary, setSummary] = useState<SubscriptionsSummary | null>(null)\n const [summaryFailed, setSummaryFailed] = useState(false)\n\n const { data: store } = useFirestoreDoc<Record<string, unknown>>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n const currency = String(store?.currency ?? 'USD').toUpperCase()\n const money = (cents: number) => CommerceModel.formatOrderMoney(cents, currency)\n\n useEffect(() => {\n let live = true\n setSummaryFailed(false)\n loadSubscriptionsSummary(firestore, hostId)\n .then((next) => {\n if (live) setSummary(next)\n })\n .catch((error) => {\n console.error('Subscriptions summary unavailable', error)\n if (live) setSummaryFailed(true)\n })\n return () => {\n live = false\n }\n }, [firestore, hostId])\n\n const {\n rows,\n hasMore,\n page,\n setPage,\n pageSize,\n setPageSize,\n status,\n } = usePagedCollection<SubscriptionRow>(\n (pageLimit) =>\n query(\n collection(firestore, 'hosts', hostId, 'subscriptions'),\n ...(filter === 'all' ? [] : [where('status', '==', filter)]),\n orderBy('createdAtMs', 'desc'),\n limit(pageLimit),\n ),\n [firestore, hostId, filter],\n { idField: '$id' },\n )\n\n const searchParams = useSearchParams()\n const seededId = searchParams?.get(SUBSCRIPTIONS_SUBSCRIPTION_PARAM) ?? null\n // Once per id, so closing the dialog does not reopen it on the next render.\n const seeded = useRef<string | null>(null)\n useEffect(() => {\n if (!seededId || seeded.current === seededId) return\n seeded.current = seededId\n setSelectedId(seededId)\n }, [seededId])\n\n // A linked subscription need not be on this page, so it is read by id.\n const onPage = selectedId ? (rows.find((row) => row.$id === selectedId) ?? null) : null\n const { data: linked } = useFirestoreDoc<Omit<SubscriptionRow, '$id'>>(\n () =>\n selectedId && !onPage\n ? doc(firestore, 'hosts', hostId, 'subscriptions', selectedId)\n : null,\n [firestore, hostId, selectedId, Boolean(onPage)],\n )\n const selected: SubscriptionRow | null =\n onPage ?? (selectedId && linked ? { ...linked, $id: selectedId } : null)\n\n return (\n <CardDisplay\n header={'Subscriptions'}\n help={pluginDocsHelp('catalog', { anchor: '#subscriptions-list' })}\n HeaderProps={{\n action: (\n <TextField\n label=\"Status\"\n value={filter}\n onChange={(event) => setFilter(event.target.value as SubscriptionFilter)}\n size=\"small\"\n select\n sx={{ minWidth: 160 }}\n >\n <MenuItem value=\"all\">{'All'}</MenuItem>\n {CommerceModel.SUBSCRIPTION_FILTER_STATUSES.map((value) => (\n <MenuItem key={value} value={value}>\n {CommerceModel.subscriptionStatusLabel(value)}\n </MenuItem>\n ))}\n </TextField>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <Stack direction=\"row\" useFlexGap sx={{ flexWrap: 'wrap', columnGap: 4, rowGap: 1.5 }}>\n <CommerceStatTile\n label=\"Monthly recurring revenue\"\n value={summary ? money(summary.monthlyRecurringCents) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"Paying subscribers\"\n value={summary ? String(summary.payingCount) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"In a free trial\"\n value={summary ? String(summary.trialCount) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"Past due\"\n value={summary ? String(summary.pastDueCount) : summaryFailed ? '—' : '…'}\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {summaryFailed\n ? 'These figures could not be loaded. The list below is unaffected.'\n : 'Monthly recurring revenue counts active and past-due subscriptions paid in live mode, with a yearly plan counted as a twelfth and tax left out.'}\n </Typography>\n {rows.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {status === 'error'\n ? // The rules gate subscriptions on the order book's permission.\n 'Subscriptions take the \"See orders and webhooks\" permission on this site.'\n : status === 'loading'\n ? 'Loading subscriptions…'\n : filter === 'all'\n ? 'No subscriptions yet. When someone subscribes to a monthly or yearly product, they appear here.'\n : `No ${CommerceModel.subscriptionStatusLabel(filter).toLowerCase()} subscriptions.`}\n </Typography>\n ) : (\n <List disablePadding>\n {rows.map((row) => {\n const dateText = CommerceModel.subscriptionDateText(\n CommerceModel.subscriptionDateLine(row),\n )\n const price =\n row.totals?.totalCents != null\n ? `${money(Number(row.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(row.interval)}`\n : ''\n const paid =\n Number(row.invoicesCount ?? 0) > 0\n ? `${money(Number(row.paidCents) || 0)} paid so far`\n : ''\n return (\n <ListItemButton key={row.$id} onClick={() => setSelectedId(row.$id)} divider>\n <ListItemText\n primary={`${row.customerName || row.customerEmail || 'Unknown customer'} · ${CommerceModel.subscriptionPlanName(row)}`}\n secondary={[price, dateText, paid].filter(Boolean).join(' · ')}\n />\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexShrink: 0 }}>\n {row.livemode === false ? (\n <Chip label=\"Test\" size=\"small\" variant=\"outlined\" />\n ) : null}\n <Chip\n label={CommerceModel.subscriptionStatusLabel(row.status)}\n size=\"small\"\n color={CommerceModel.subscriptionStatusColor(row.status)}\n variant=\"outlined\"\n />\n </Stack>\n </ListItemButton>\n )\n })}\n </List>\n )}\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={rows.length}\n hasMore={hasMore}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n </Stack>\n {selected ? (\n <SubscriptionDetailDialog\n hostId={hostId}\n subscription={selected}\n currency={currency}\n onClose={() => setSelectedId(null)}\n />\n ) : null}\n </CardDisplay>\n )\n}\nSubscriptionsCard.displayName = 'SubscriptionsCard'\n\nexport default SubscriptionsCard\n"],"names":["CommerceModel","CardDisplay","ListPagination","pluginDocsHelp","Chip","List","ListItemButton","ListItemText","MenuItem","Stack","TextField","Typography","collection","doc","getAggregateFromServer","limit","orderBy","query","sum","count","where","useSearchParams","useEffect","useRef","useState","useFirestore","useFirestoreDoc","usePagedCollection","CommerceStatTile","SubscriptionDetailDialog","SUBSCRIPTIONS_SUBSCRIPTION_PARAM","loadSubscriptionsSummary","firestore","hostId","subscriptions","paying","interval","SUBSCRIPTION_PAYING_STATUSES","totalCents","taxCents","counted","status","monthly","yearly","trials","pastDue","Promise","all","figure","value","Number","monthlyRecurringCents","data","payingCount","trialCount","pastDueCount","SubscriptionsCard","props","rows","filter","setFilter","selectedId","setSelectedId","summary","setSummary","summaryFailed","setSummaryFailed","store","currency","String","toUpperCase","money","cents","formatOrderMoney","live","then","next","catch","error","console","hasMore","page","setPage","pageSize","setPageSize","pageLimit","idField","searchParams","seededId","get","seeded","current","onPage","find","row","$id","linked","Boolean","selected","header","help","anchor","HeaderProps","action","label","onChange","event","target","size","select","sx","minWidth","SUBSCRIPTION_FILTER_STATUSES","map","subscriptionStatusLabel","contentGutterX","contentGutterY","spacing","direction","useFlexGap","flexWrap","columnGap","rowGap","variant","color","length","toLowerCase","disablePadding","dateText","subscriptionDateText","subscriptionDateLine","price","totals","subscriptionIntervalSuffix","paid","invoicesCount","paidCents","onClick","divider","primary","customerName","customerEmail","subscriptionPlanName","secondary","join","alignItems","flexShrink","livemode","subscriptionStatusColor","rowCount","onPageChange","onPageSizeChange","subscription","onClose","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,cAAc,QAAQ,eAAc;AAC7C,SACEC,IAAI,EACJC,IAAI,EACJC,cAAc,EACdC,YAAY,EACZC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,GAAG,EACHC,sBAAsB,EACtBC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,KAAK,QAEA,qBAAoB;AAC3B,SAASC,eAAe,QAAQ,kBAAiB;AACjD,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnD,SACEC,YAAY,EACZC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC,OAAOC,sBAAsB,oCAAgC;AAC7D,OAAOC,8BAAwD,4CAAwC;AAMvG,2FAA2F,GAC3F,OAAO,MAAMC,mCAAmC,eAAc;AAW9D;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,yBACpBC,SAAoB,EACpBC,MAAc;IAEd,MAAMC,gBAAg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ChD,MAAM;wCACtHiD,WAAW;4CAACZ;4CAAOH;4CAAUM;yCAAK,CAAC3E,MAAM,CAACsC,SAAS+C,IAAI,CAAC;;kDAE1D,MAACvI;wCAAM6G,WAAU;wCAAMD,SAAS;wCAAGP,IAAI;4CAAEmC,YAAY;4CAAUC,YAAY;wCAAE;;4CAC1EpD,IAAIqD,QAAQ,KAAK,sBAChB,KAAC/I;gDAAKoG,OAAM;gDAAOI,MAAK;gDAAQe,SAAQ;iDACtC;0DACJ,KAACvH;gDACCoG,OAAOxG,cAAckH,uBAAuB,CAACpB,IAAIrD,MAAM;gDACvDmE,MAAK;gDACLgB,OAAO5H,cAAcoJ,uBAAuB,CAACtD,IAAIrD,MAAM;gDACvDkF,SAAQ;;;;;+BAbO7B,IAAIC,GAAG;wBAkBhC;;kCAGJ,KAAC7F;wBACC+E,MAAMA;wBACNE,UAAUA;wBACVkE,UAAU3F,KAAKmE,MAAM;wBACrB7C,SAASA;wBACTsE,cAAcpE;wBACdqE,kBAAkBnE;;;;YAGrBc,yBACC,KAACrE;gBACCI,QAAQA;gBACRuH,cAActD;gBACd9B,UAAUA;gBACVqF,SAAS,IAAM3F,cAAc;iBAE7B;;;AAGV;AACAN,kBAAkBkG,WAAW,GAAG;AAEhC,eAAelG,kBAAiB"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/subscriptions-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n Chip,\n List,\n ListItemButton,\n ListItemText,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n doc,\n getAggregateFromServer,\n limit,\n orderBy,\n query,\n sum,\n count,\n where,\n type Firestore,\n} from 'firebase/firestore'\nimport { useSearchParams } from 'next/navigation'\nimport { useEffect, useRef, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreDoc,\n usePagedCollection,\n} from '@aglyn/tenant-feature-instance'\nimport CommerceStatTile from './commerce-stat-tile.component'\nimport SubscriptionDetailDialog, { type SubscriptionRow } from './subscription-detail-dialog.component'\n\nexport interface SubscriptionsCardProps {\n hostId: string\n}\n\n/** The query key that opens one subscription on arrival: the renewal notification's link. */\nexport const SUBSCRIPTIONS_SUBSCRIPTION_PARAM = 'subscription'\n\ntype SubscriptionFilter = (typeof CommerceModel.SUBSCRIPTION_FILTER_STATUSES)[number] | 'all'\n\nexport interface SubscriptionsSummary {\n monthlyRecurringCents: number\n payingCount: number\n trialCount: number\n pastDueCount: number\n}\n\n/**\n * The figures above the list, from aggregation queries: what a store with\n * thousands of subscribers pays for is a handful of index reads, never one\n * read per subscriber.\n *\n * Monthly recurring revenue is summed per billing interval, because a sum\n * cannot divide a yearly price by twelve on the way. Only LIVE-mode\n * subscriptions count: a test checkout is a rehearsal, and the order\n * analytics leave it out for the same reason (`order-analytics.ts`). A\n * subscription with no stored `interval` is left out of the figure rather\n * than guessed at; every sale since AGL-1732 stores one.\n */\nexport async function loadSubscriptionsSummary(\n firestore: Firestore,\n hostId: string,\n): Promise<SubscriptionsSummary> {\n const subscriptions = collection(firestore, 'hosts', hostId, 'subscriptions')\n const paying = (interval: CommerceModel.SubscriptionBillingInterval) =>\n getAggregateFromServer(\n query(\n subscriptions,\n where('status', 'in', [...CommerceModel.SUBSCRIPTION_PAYING_STATUSES]),\n where('interval', '==', interval),\n where('livemode', '==', true),\n ),\n {\n subscriptions: count(),\n totalCents: sum('totals.totalCents'),\n taxCents: sum('totals.taxCents'),\n },\n )\n const counted = (status: string) =>\n getAggregateFromServer(\n query(subscriptions, where('status', '==', status), where('livemode', '==', true)),\n { subscriptions: count() },\n )\n // AGL-1715-EXEMPT: four separate count queries, one per figure on the card;\n // the status words are each query's own filter, not a membership set.\n const [monthly, yearly, trials, pastDue] = await Promise.all([\n paying('month'),\n paying('year'),\n counted('trialing'),\n counted('past_due'),\n ])\n const figure = (value: unknown) => Number(value) || 0\n return {\n monthlyRecurringCents:\n CommerceModel.monthlyRecurringCents(\n monthly.data().totalCents,\n monthly.data().taxCents,\n 'month',\n ) +\n CommerceModel.monthlyRecurringCents(\n yearly.data().totalCents,\n yearly.data().taxCents,\n 'year',\n ),\n payingCount: figure(monthly.data().subscriptions) + figure(yearly.data().subscriptions),\n trialCount: figure(trials.data().subscriptions),\n pastDueCount: figure(pastDue.data().subscriptions),\n }\n}\n\n/**\n * Subscriptions (AGL-4191): every subscription on the site, newest first, and\n * what they add up to.\n *\n * Until this, a merchant could see subscriptions only one person at a time, in\n * a site member's Purchases: a digital or service subscription writes no order\n * per cycle, so Orders never showed them either.\n *\n * THE STATUS FILTER IS THE QUERY, as on Returns: `status == X` ordered by\n * `createdAtMs` descending, served by the `subscriptions(status ASC,\n * createdAtMs DESC)` composite; \"All\" is the single-field order alone. Opening\n * a row shows the subscription's invoices; `?subscription={id}` opens one on\n * arrival, which is where the renewal notification links.\n */\nexport function SubscriptionsCard(props: SubscriptionsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const [filter, setFilter] = useState<SubscriptionFilter>('all')\n const [selectedId, setSelectedId] = useState<string | null>(null)\n const [summary, setSummary] = useState<SubscriptionsSummary | null>(null)\n const [summaryFailed, setSummaryFailed] = useState(false)\n\n const { data: store } = useFirestoreDoc<Record<string, unknown>>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n const currency = String(store?.currency ?? 'USD').toUpperCase()\n const money = (cents: number) => CommerceModel.formatOrderMoney(cents, currency)\n\n useEffect(() => {\n let live = true\n setSummaryFailed(false)\n loadSubscriptionsSummary(firestore, hostId)\n .then((next) => {\n if (live) setSummary(next)\n })\n .catch((error) => {\n console.error('Subscriptions summary unavailable', error)\n if (live) setSummaryFailed(true)\n })\n return () => {\n live = false\n }\n }, [firestore, hostId])\n\n const {\n rows,\n hasMore,\n page,\n setPage,\n pageSize,\n setPageSize,\n status,\n } = usePagedCollection<SubscriptionRow>(\n (pageLimit) =>\n query(\n collection(firestore, 'hosts', hostId, 'subscriptions'),\n ...(filter === 'all' ? [] : [where('status', '==', filter)]),\n orderBy('createdAtMs', 'desc'),\n limit(pageLimit),\n ),\n [firestore, hostId, filter],\n { idField: '$id' },\n )\n\n const searchParams = useSearchParams()\n const seededId = searchParams?.get(SUBSCRIPTIONS_SUBSCRIPTION_PARAM) ?? null\n // Once per id, so closing the dialog does not reopen it on the next render.\n const seeded = useRef<string | null>(null)\n useEffect(() => {\n if (!seededId || seeded.current === seededId) return\n seeded.current = seededId\n setSelectedId(seededId)\n }, [seededId])\n\n // A linked subscription need not be on this page, so it is read by id.\n const onPage = selectedId ? (rows.find((row) => row.$id === selectedId) ?? null) : null\n const { data: linked } = useFirestoreDoc<Omit<SubscriptionRow, '$id'>>(\n () =>\n selectedId && !onPage\n ? doc(firestore, 'hosts', hostId, 'subscriptions', selectedId)\n : null,\n [firestore, hostId, selectedId, Boolean(onPage)],\n )\n const selected: SubscriptionRow | null =\n onPage ?? (selectedId && linked ? { ...linked, $id: selectedId } : null)\n\n return (\n <CardDisplay\n header={'Subscriptions'}\n help={pluginDocsHelp('catalog', { anchor: '#subscriptions-list' })}\n HeaderProps={{\n action: (\n <TextField\n label=\"Status\"\n value={filter}\n onChange={(event) => setFilter(event.target.value as SubscriptionFilter)}\n size=\"small\"\n select\n sx={{ minWidth: 160 }}\n >\n <MenuItem value=\"all\">{'All'}</MenuItem>\n {CommerceModel.SUBSCRIPTION_FILTER_STATUSES.map((value) => (\n <MenuItem key={value} value={value}>\n {CommerceModel.subscriptionStatusLabel(value)}\n </MenuItem>\n ))}\n </TextField>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <Stack direction=\"row\" useFlexGap sx={{ flexWrap: 'wrap', columnGap: 4, rowGap: 1.5 }}>\n <CommerceStatTile\n label=\"Monthly recurring revenue\"\n value={summary ? money(summary.monthlyRecurringCents) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"Paying subscribers\"\n value={summary ? String(summary.payingCount) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"In a free trial\"\n value={summary ? String(summary.trialCount) : summaryFailed ? '—' : '…'}\n />\n <CommerceStatTile\n label=\"Past due\"\n value={summary ? String(summary.pastDueCount) : summaryFailed ? '—' : '…'}\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {summaryFailed\n ? 'These figures could not be loaded. The list below is unaffected.'\n : 'Monthly recurring revenue counts active and past-due subscriptions paid in live mode, with a yearly plan counted as a twelfth and tax left out.'}\n </Typography>\n {rows.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {status === 'error'\n ? // The rules gate subscriptions on the order book's permission.\n 'Subscriptions take the \"See orders and webhooks\" permission on this site.'\n : status === 'loading'\n ? 'Loading subscriptions…'\n : filter === 'all'\n ? 'No subscriptions yet. When someone subscribes to a monthly or yearly product, they appear here.'\n : `No ${CommerceModel.subscriptionStatusLabel(filter).toLowerCase()} subscriptions.`}\n </Typography>\n ) : (\n <List disablePadding>\n {rows.map((row) => {\n const dateText = CommerceModel.subscriptionDateText(\n CommerceModel.subscriptionDateLine(row),\n )\n const price =\n row.totals?.totalCents != null\n ? `${money(Number(row.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(row.interval)}`\n : ''\n // A trial's opening invoice is $0: nothing has been paid yet,\n // so the row says nothing rather than \"$0.00 paid so far\".\n const paid =\n Number(row.paidCents ?? 0) > 0\n ? `${money(Number(row.paidCents) || 0)} paid so far`\n : ''\n return (\n <ListItemButton key={row.$id} onClick={() => setSelectedId(row.$id)} divider>\n <ListItemText\n primary={`${row.customerName || row.customerEmail || 'Unknown customer'} · ${CommerceModel.subscriptionPlanName(row)}`}\n secondary={[price, dateText, paid].filter(Boolean).join(' · ')}\n />\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexShrink: 0 }}>\n {row.livemode === false ? (\n <Chip label=\"Test\" size=\"small\" variant=\"outlined\" />\n ) : null}\n <Chip\n label={CommerceModel.subscriptionStatusLabel(row.status)}\n size=\"small\"\n color={CommerceModel.subscriptionStatusColor(row.status)}\n variant=\"outlined\"\n />\n </Stack>\n </ListItemButton>\n )\n })}\n </List>\n )}\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={rows.length}\n hasMore={hasMore}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n </Stack>\n {selected ? (\n <SubscriptionDetailDialog\n hostId={hostId}\n subscription={selected}\n currency={currency}\n onClose={() => setSelectedId(null)}\n />\n ) : null}\n </CardDisplay>\n )\n}\nSubscriptionsCard.displayName = 'SubscriptionsCard'\n\nexport default SubscriptionsCard\n"],"names":["CommerceModel","CardDisplay","ListPagination","pluginDocsHelp","Chip","List","ListItemButton","ListItemText","MenuItem","Stack","TextField","Typography","collection","doc","getAggregateFromServer","limit","orderBy","query","sum","count","where","useSearchParams","useEffect","useRef","useState","useFirestore","useFirestoreDoc","usePagedCollection","CommerceStatTile","SubscriptionDetailDialog","SUBSCRIPTIONS_SUBSCRIPTION_PARAM","loadSubscriptionsSummary","firestore","hostId","subscriptions","paying","interval","SUBSCRIPTION_PAYING_STATUSES","totalCents","taxCents","counted","status","monthly","yearly","trials","pastDue","Promise","all","figure","value","Number","monthlyRecurringCents","data","payingCount","trialCount","pastDueCount","SubscriptionsCard","props","rows","filter","setFilter","selectedId","setSelectedId","summary","setSummary","summaryFailed","setSummaryFailed","store","currency","String","toUpperCase","money","cents","formatOrderMoney","live","then","next","catch","error","console","hasMore","page","setPage","pageSize","setPageSize","pageLimit","idField","searchParams","seededId","get","seeded","current","onPage","find","row","$id","linked","Boolean","selected","header","help","anchor","HeaderProps","action","label","onChange","event","target","size","select","sx","minWidth","SUBSCRIPTION_FILTER_STATUSES","map","subscriptionStatusLabel","contentGutterX","contentGutterY","spacing","direction","useFlexGap","flexWrap","columnGap","rowGap","variant","color","length","toLowerCase","disablePadding","dateText","subscriptionDateText","subscriptionDateLine","price","totals","subscriptionIntervalSuffix","paid","paidCents","onClick","divider","primary","customerName","customerEmail","subscriptionPlanName","secondary","join","alignItems","flexShrink","livemode","subscriptionStatusColor","rowCount","onPageChange","onPageSizeChange","subscription","onClose","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,cAAc,QAAQ,eAAc;AAC7C,SACEC,IAAI,EACJC,IAAI,EACJC,cAAc,EACdC,YAAY,EACZC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,GAAG,EACHC,sBAAsB,EACtBC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,KAAK,QAEA,qBAAoB;AAC3B,SAASC,eAAe,QAAQ,kBAAiB;AACjD,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnD,SACEC,YAAY,EACZC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC,OAAOC,sBAAsB,oCAAgC;AAC7D,OAAOC,8BAAwD,4CAAwC;AAMvG,2FAA2F,GAC3F,OAAO,MAAMC,mCAAmC,eAAc;AAW9D;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC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C,YAAY,IAAI7C,IAAI8C,aAAa,IAAI,mBAAmB,GAAG,EAAE5I,cAAc6I,oBAAoB,CAAC/C,MAAM;wCACtHgD,WAAW;4CAACX;4CAAOH;4CAAUM;yCAAK,CAAC3E,MAAM,CAACsC,SAAS8C,IAAI,CAAC;;kDAE1D,MAACtI;wCAAM6G,WAAU;wCAAMD,SAAS;wCAAGP,IAAI;4CAAEkC,YAAY;4CAAUC,YAAY;wCAAE;;4CAC1EnD,IAAIoD,QAAQ,KAAK,sBAChB,KAAC9I;gDAAKoG,OAAM;gDAAOI,MAAK;gDAAQe,SAAQ;iDACtC;0DACJ,KAACvH;gDACCoG,OAAOxG,cAAckH,uBAAuB,CAACpB,IAAIrD,MAAM;gDACvDmE,MAAK;gDACLgB,OAAO5H,cAAcmJ,uBAAuB,CAACrD,IAAIrD,MAAM;gDACvDkF,SAAQ;;;;;+BAbO7B,IAAIC,GAAG;wBAkBhC;;kCAGJ,KAAC7F;wBACC+E,MAAMA;wBACNE,UAAUA;wBACViE,UAAU1F,KAAKmE,MAAM;wBACrB7C,SAASA;wBACTqE,cAAcnE;wBACdoE,kBAAkBlE;;;;YAGrBc,yBACC,KAACrE;gBACCI,QAAQA;gBACRsH,cAAcrD;gBACd9B,UAAUA;gBACVoF,SAAS,IAAM1F,cAAc;iBAE7B;;;AAGV;AACAN,kBAAkBiG,WAAW,GAAG;AAEhC,eAAejG,kBAAiB"}
@@ -533,11 +533,14 @@ function slugFromLocation() {
533
533
  buyItem(resolved, variant, quantity, addOnGroups.length ? unitCents : undefined)
534
534
  ]
535
535
  }));
536
- setNativeCheckout({
536
+ setNativeCheckout(_extends({
537
537
  clientSecret: String(payload.clientSecret),
538
- publishableKey: String(payload.publishableKey),
538
+ publishableKey: String(payload.publishableKey)
539
+ }, payload.stripeAccount ? {
540
+ stripeAccount: String(payload.stripeAccount)
541
+ } : {}, {
539
542
  wallets: CommerceModel.readStorefrontCheckoutWallets(payload.wallets)
540
- });
543
+ }));
541
544
  setStatus('idle');
542
545
  return;
543
546
  }
@@ -1033,6 +1036,7 @@ function slugFromLocation() {
1033
1036
  children: /*#__PURE__*/ _jsx(StorefrontPaymentElement, {
1034
1037
  clientSecret: nativeCheckout.clientSecret,
1035
1038
  publishableKey: nativeCheckout.publishableKey,
1039
+ stripeAccount: nativeCheckout.stripeAccount,
1036
1040
  wallets: nativeCheckout.wallets,
1037
1041
  payLabel: buyLabel || (subscribing ? 'Subscribe' : 'Pay now'),
1038
1042
  // An expired or unloadable session is replaced, never