@aglyn/plugins-commerce 1.13.0 → 1.15.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 (152) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/account-subscriptions.d.ts +51 -0
  3. package/src/lib/components/account-subscriptions.js +168 -0
  4. package/src/lib/components/account-subscriptions.js.map +1 -0
  5. package/src/lib/components/account.js +12 -48
  6. package/src/lib/components/account.js.map +1 -1
  7. package/src/lib/components/cart.js +30 -6
  8. package/src/lib/components/cart.js.map +1 -1
  9. package/src/lib/components/commerce-console-page.js +6 -0
  10. package/src/lib/components/commerce-console-page.js.map +1 -1
  11. package/src/lib/components/commerce-console-sections.d.ts +1 -1
  12. package/src/lib/components/commerce-console-sections.js +5 -0
  13. package/src/lib/components/commerce-console-sections.js.map +1 -1
  14. package/src/lib/components/console/paid-media.d.ts +1 -0
  15. package/src/lib/components/console/paid-media.js +15 -4
  16. package/src/lib/components/console/paid-media.js.map +1 -1
  17. package/src/lib/components/console/payments-settings-card.component.js +1 -1
  18. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  19. package/src/lib/components/console/pos/pos-hardware-api.d.ts +10 -1
  20. package/src/lib/components/console/pos/pos-hardware-api.js.map +1 -1
  21. package/src/lib/components/console/pos/pos-hardware-buyer.component.js +2 -2
  22. package/src/lib/components/console/pos/pos-hardware-buyer.component.js.map +1 -1
  23. package/src/lib/components/console/pos/pos-hardware-sale-api.d.ts +2 -0
  24. package/src/lib/components/console/pos/pos-hardware-sale-api.js.map +1 -1
  25. package/src/lib/components/console/pos-cellular-control.component.d.ts +1 -1
  26. package/src/lib/components/console/pos-cellular-control.component.js +5 -5
  27. package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
  28. package/src/lib/components/console/pos-devices-card.component.js +2 -2
  29. package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
  30. package/src/lib/components/console/pos-hardware-card.component.d.ts +5 -0
  31. package/src/lib/components/console/pos-hardware-card.component.js +77 -8
  32. package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
  33. package/src/lib/components/console/pos-hardware-orders-staff-page.component.js +137 -19
  34. package/src/lib/components/console/pos-hardware-orders-staff-page.component.js.map +1 -1
  35. package/src/lib/components/console/pos-page.component.js +19 -2
  36. package/src/lib/components/console/pos-page.component.js.map +1 -1
  37. package/src/lib/components/console/product-editor-dialog.component.js +21 -2
  38. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  39. package/src/lib/components/console/subscription-detail-dialog.component.d.ts +58 -0
  40. package/src/lib/components/console/subscription-detail-dialog.component.js +201 -0
  41. package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -0
  42. package/src/lib/components/console/subscriptions-card.component.d.ts +60 -0
  43. package/src/lib/components/console/subscriptions-card.component.js +280 -0
  44. package/src/lib/components/console/subscriptions-card.component.js.map +1 -0
  45. package/src/lib/components/hardware-terms-consent.d.ts +22 -0
  46. package/src/lib/components/hardware-terms-consent.js +85 -0
  47. package/src/lib/components/hardware-terms-consent.js.map +1 -0
  48. package/src/lib/components/product-detail.js +25 -5
  49. package/src/lib/components/product-detail.js.map +1 -1
  50. package/src/lib/constants/operator-alerts.d.ts +1 -1
  51. package/src/lib/constants/operator-alerts.js +4 -4
  52. package/src/lib/constants/operator-alerts.js.map +1 -1
  53. package/src/lib/model/commerce-orders.d.ts +6 -2
  54. package/src/lib/model/commerce-orders.js.map +1 -1
  55. package/src/lib/model/commerce-payment-methods.d.ts +24 -0
  56. package/src/lib/model/commerce-payment-methods.js +35 -0
  57. package/src/lib/model/commerce-payment-methods.js.map +1 -1
  58. package/src/lib/model/commerce.d.ts +6 -0
  59. package/src/lib/model/commerce.js.map +1 -1
  60. package/src/lib/model/index.d.ts +1 -0
  61. package/src/lib/model/index.js +1 -0
  62. package/src/lib/model/index.js.map +1 -1
  63. package/src/lib/model/paid-media.d.ts +8 -0
  64. package/src/lib/model/paid-media.js +13 -0
  65. package/src/lib/model/paid-media.js.map +1 -1
  66. package/src/lib/model/pos-hardware-in-person.d.ts +23 -2
  67. package/src/lib/model/pos-hardware-in-person.js +52 -20
  68. package/src/lib/model/pos-hardware-in-person.js.map +1 -1
  69. package/src/lib/model/pos-hardware-tax-summary.d.ts +5 -1
  70. package/src/lib/model/pos-hardware-tax-summary.js +2 -1
  71. package/src/lib/model/pos-hardware-tax-summary.js.map +1 -1
  72. package/src/lib/model/pos-hardware-terms.d.ts +37 -2
  73. package/src/lib/model/pos-hardware-terms.js +68 -3
  74. package/src/lib/model/pos-hardware-terms.js.map +1 -1
  75. package/src/lib/model/pos-hardware.d.ts +101 -15
  76. package/src/lib/model/pos-hardware.js +128 -18
  77. package/src/lib/model/pos-hardware.js.map +1 -1
  78. package/src/lib/model/pos-reader-splash.js +2 -2
  79. package/src/lib/model/pos-reader-splash.js.map +1 -1
  80. package/src/lib/model/product-write.d.ts +3 -0
  81. package/src/lib/model/subscription-view.d.ts +90 -0
  82. package/src/lib/model/subscription-view.js +176 -0
  83. package/src/lib/model/subscription-view.js.map +1 -0
  84. package/src/lib/server/billing-webhook.d.ts +4 -6
  85. package/src/lib/server/billing-webhook.js +109 -51
  86. package/src/lib/server/billing-webhook.js.map +1 -1
  87. package/src/lib/server/cart-checkout.js +45 -10
  88. package/src/lib/server/cart-checkout.js.map +1 -1
  89. package/src/lib/server/cart.js +15 -3
  90. package/src/lib/server/cart.js.map +1 -1
  91. package/src/lib/server/checkout.js +58 -16
  92. package/src/lib/server/checkout.js.map +1 -1
  93. package/src/lib/server/draft-order.js +7 -3
  94. package/src/lib/server/draft-order.js.map +1 -1
  95. package/src/lib/server/membership-account.d.ts +22 -0
  96. package/src/lib/server/membership-account.js +52 -8
  97. package/src/lib/server/membership-account.js.map +1 -1
  98. package/src/lib/server/pos-auth.d.ts +3 -3
  99. package/src/lib/server/pos-auth.js +3 -3
  100. package/src/lib/server/pos-auth.js.map +1 -1
  101. package/src/lib/server/pos-cellular-billing.js +1 -1
  102. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  103. package/src/lib/server/pos-cellular-notify.js +1 -1
  104. package/src/lib/server/pos-cellular-notify.js.map +1 -1
  105. package/src/lib/server/pos-cellular.js +1 -1
  106. package/src/lib/server/pos-cellular.js.map +1 -1
  107. package/src/lib/server/pos-hardware-admin.js +86 -13
  108. package/src/lib/server/pos-hardware-admin.js.map +1 -1
  109. package/src/lib/server/pos-hardware-attach.js +5 -5
  110. package/src/lib/server/pos-hardware-attach.js.map +1 -1
  111. package/src/lib/server/pos-hardware-cancel.js +65 -0
  112. package/src/lib/server/pos-hardware-cancel.js.map +1 -1
  113. package/src/lib/server/pos-hardware-closure-notices.js +2 -5
  114. package/src/lib/server/pos-hardware-closure-notices.js.map +1 -1
  115. package/src/lib/server/pos-hardware-closure.js +5 -8
  116. package/src/lib/server/pos-hardware-closure.js.map +1 -1
  117. package/src/lib/server/pos-hardware-in-person.d.ts +2 -1
  118. package/src/lib/server/pos-hardware-in-person.js +72 -17
  119. package/src/lib/server/pos-hardware-in-person.js.map +1 -1
  120. package/src/lib/server/pos-hardware-notify.d.ts +2 -0
  121. package/src/lib/server/pos-hardware-notify.js +30 -5
  122. package/src/lib/server/pos-hardware-notify.js.map +1 -1
  123. package/src/lib/server/pos-hardware-readers.d.ts +25 -0
  124. package/src/lib/server/pos-hardware-readers.js +206 -85
  125. package/src/lib/server/pos-hardware-readers.js.map +1 -1
  126. package/src/lib/server/pos-hardware-returns.d.ts +8 -3
  127. package/src/lib/server/pos-hardware-returns.js +39 -7
  128. package/src/lib/server/pos-hardware-returns.js.map +1 -1
  129. package/src/lib/server/pos-hardware-sale-fields.d.ts +76 -0
  130. package/src/lib/server/pos-hardware-sale-fields.js +114 -1
  131. package/src/lib/server/pos-hardware-sale-fields.js.map +1 -1
  132. package/src/lib/server/pos-hardware-sale.d.ts +2 -0
  133. package/src/lib/server/pos-hardware-sale.js +1 -0
  134. package/src/lib/server/pos-hardware-sale.js.map +1 -1
  135. package/src/lib/server/pos-hardware-tax-return-source.js +7 -4
  136. package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -1
  137. package/src/lib/server/pos-hardware-webhook.js +16 -3
  138. package/src/lib/server/pos-hardware-webhook.js.map +1 -1
  139. package/src/lib/server/pos-hardware.d.ts +14 -3
  140. package/src/lib/server/pos-hardware.js +83 -18
  141. package/src/lib/server/pos-hardware.js.map +1 -1
  142. package/src/lib/server/pos-ops-routes.js +2 -10
  143. package/src/lib/server/pos-ops-routes.js.map +1 -1
  144. package/src/lib/server/quote-pay.js +8 -4
  145. package/src/lib/server/quote-pay.js.map +1 -1
  146. package/src/lib/server/stream.d.ts +2 -0
  147. package/src/lib/server/stream.js +22 -2
  148. package/src/lib/server/stream.js.map +1 -1
  149. package/src/lib/server/tax-return-source.js +5 -1
  150. package/src/lib/server/tax-return-source.js.map +1 -1
  151. package/src/lib/server.js +2 -2
  152. package/src/lib/server.js.map +1 -1
@@ -0,0 +1,58 @@
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
+ /** How many of a subscription's invoices the dialog lists: two years of monthly cycles. */
18
+ export declare const SUBSCRIPTION_INVOICE_WINDOW = 24;
19
+ /** A stored subscription, as far as this list reads one. */
20
+ export interface SubscriptionRow {
21
+ $id: string;
22
+ productId?: string;
23
+ customerEmail?: string | null;
24
+ customerName?: string | null;
25
+ status?: string;
26
+ interval?: string;
27
+ cancelAtPeriodEnd?: boolean;
28
+ currentPeriodEndMs?: number | null;
29
+ paidThroughMs?: number;
30
+ createdAtMs?: number;
31
+ paidCents?: number;
32
+ invoicesCount?: number;
33
+ livemode?: boolean;
34
+ lineItems?: Array<{
35
+ name?: string;
36
+ quantity?: number;
37
+ }>;
38
+ totals?: {
39
+ totalCents?: number;
40
+ taxCents?: number;
41
+ };
42
+ }
43
+ export interface SubscriptionDetailDialogProps {
44
+ hostId: string;
45
+ subscription: SubscriptionRow;
46
+ currency: string;
47
+ onClose: () => void;
48
+ }
49
+ /**
50
+ * One subscription and its invoices (AGL-4191). Every paid cycle is recorded
51
+ * under `subscriptions/{id}/invoices` by the billing webhook, and this is the
52
+ * first place a merchant can read them without opening Stripe.
53
+ */
54
+ export declare function SubscriptionDetailDialog(props: SubscriptionDetailDialogProps): import("react").JSX.Element;
55
+ export declare namespace SubscriptionDetailDialog {
56
+ var displayName: string;
57
+ }
58
+ export default SubscriptionDetailDialog;
@@ -0,0 +1,201 @@
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
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import * as CommerceModel from "../../model/index.js";
19
+ import { Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Link, Stack, Typography } from "@mui/material";
20
+ import { collection, limit, orderBy, query } from "firebase/firestore";
21
+ import { useFirestore, useFirestoreCollection } from "@aglyn/tenant-feature-instance";
22
+ /** How many of a subscription's invoices the dialog lists: two years of monthly cycles. */ export const SUBSCRIPTION_INVOICE_WINDOW = 24;
23
+ function Fact(props) {
24
+ return /*#__PURE__*/ _jsxs(Box, {
25
+ sx: {
26
+ display: 'flex',
27
+ gap: 2
28
+ },
29
+ children: [
30
+ /*#__PURE__*/ _jsx(Typography, {
31
+ variant: "body2",
32
+ color: "text.secondary",
33
+ sx: {
34
+ minWidth: 140
35
+ },
36
+ children: props.label
37
+ }),
38
+ /*#__PURE__*/ _jsx(Typography, {
39
+ variant: "body2",
40
+ children: props.value
41
+ })
42
+ ]
43
+ });
44
+ }
45
+ /**
46
+ * One subscription and its invoices (AGL-4191). Every paid cycle is recorded
47
+ * under `subscriptions/{id}/invoices` by the billing webhook, and this is the
48
+ * first place a merchant can read them without opening Stripe.
49
+ */ export function SubscriptionDetailDialog(props) {
50
+ var _subscription_invoicesCount, _subscription_invoicesCount1;
51
+ var _subscription_totals;
52
+ const { hostId, subscription, currency, onClose } = props;
53
+ const firestore = useFirestore();
54
+ const { data: invoiceDocs, status } = useFirestoreCollection(()=>query(collection(firestore, 'hosts', hostId, 'subscriptions', subscription.$id, 'invoices'), orderBy('paidAtMs', 'desc'), limit(SUBSCRIPTION_INVOICE_WINDOW)), [
55
+ firestore,
56
+ hostId,
57
+ subscription.$id
58
+ ], {
59
+ idField: '$id'
60
+ });
61
+ const invoices = invoiceDocs != null ? invoiceDocs : [];
62
+ const money = (cents, code = currency)=>CommerceModel.formatOrderMoney(cents, code);
63
+ const date = CommerceModel.formatSubscriptionDate;
64
+ const dateText = CommerceModel.subscriptionDateText(CommerceModel.subscriptionDateLine(subscription));
65
+ const price = ((_subscription_totals = subscription.totals) == null ? void 0 : _subscription_totals.totalCents) != null ? `${money(Number(subscription.totals.totalCents) || 0)}${CommerceModel.subscriptionIntervalSuffix(subscription.interval)}` : '';
66
+ return /*#__PURE__*/ _jsxs(Dialog, {
67
+ open: true,
68
+ onClose: onClose,
69
+ maxWidth: "sm",
70
+ fullWidth: true,
71
+ children: [
72
+ /*#__PURE__*/ _jsx(DialogTitle, {
73
+ children: /*#__PURE__*/ _jsxs(Stack, {
74
+ direction: "row",
75
+ spacing: 1,
76
+ sx: {
77
+ alignItems: 'center'
78
+ },
79
+ children: [
80
+ /*#__PURE__*/ _jsx(Box, {
81
+ sx: {
82
+ flex: 1,
83
+ minWidth: 0
84
+ },
85
+ children: CommerceModel.subscriptionPlanName(subscription)
86
+ }),
87
+ /*#__PURE__*/ _jsx(Chip, {
88
+ label: CommerceModel.subscriptionStatusLabel(subscription.status),
89
+ size: "small",
90
+ color: CommerceModel.subscriptionStatusColor(subscription.status),
91
+ variant: "outlined"
92
+ })
93
+ ]
94
+ })
95
+ }),
96
+ /*#__PURE__*/ _jsxs(DialogContent, {
97
+ sx: {
98
+ display: 'flex',
99
+ flexDirection: 'column',
100
+ gap: 1
101
+ },
102
+ children: [
103
+ /*#__PURE__*/ _jsx(Fact, {
104
+ label: "Customer",
105
+ value: [
106
+ subscription.customerName,
107
+ subscription.customerEmail
108
+ ].filter(Boolean).join(' · ') || 'Unknown customer'
109
+ }),
110
+ price ? /*#__PURE__*/ _jsx(Fact, {
111
+ label: "Price",
112
+ value: price
113
+ }) : null,
114
+ subscription.createdAtMs ? /*#__PURE__*/ _jsx(Fact, {
115
+ label: "Started",
116
+ value: date(subscription.createdAtMs)
117
+ }) : null,
118
+ dateText ? /*#__PURE__*/ _jsx(Fact, {
119
+ label: "Next",
120
+ value: dateText
121
+ }) : null,
122
+ /*#__PURE__*/ _jsx(Fact, {
123
+ label: "Paid so far",
124
+ value: `${money(Number(subscription.paidCents) || 0)} over ${Number((_subscription_invoicesCount = subscription.invoicesCount) != null ? _subscription_invoicesCount : 0)} ${Number((_subscription_invoicesCount1 = subscription.invoicesCount) != null ? _subscription_invoicesCount1 : 0) === 1 ? 'invoice' : 'invoices'}`
125
+ }),
126
+ subscription.livemode === false ? /*#__PURE__*/ _jsx(Typography, {
127
+ variant: "caption",
128
+ color: "text.secondary",
129
+ children: 'A test-mode subscription: no real money moved, and it is not counted in your recurring revenue.'
130
+ }) : null,
131
+ /*#__PURE__*/ _jsx(Divider, {
132
+ textAlign: "left",
133
+ sx: {
134
+ mt: 1
135
+ },
136
+ children: 'Invoices'
137
+ }),
138
+ invoices.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
139
+ variant: "body2",
140
+ color: "text.secondary",
141
+ children: status === 'loading' ? 'Loading invoices…' : 'No invoices recorded yet.'
142
+ }) : invoices.map((invoice)=>/*#__PURE__*/ _jsxs(Box, {
143
+ sx: {
144
+ display: 'flex',
145
+ gap: 1,
146
+ alignItems: 'center'
147
+ },
148
+ children: [
149
+ /*#__PURE__*/ _jsxs(Box, {
150
+ sx: {
151
+ flex: 1,
152
+ minWidth: 0
153
+ },
154
+ children: [
155
+ /*#__PURE__*/ _jsxs(Typography, {
156
+ variant: "body2",
157
+ children: [
158
+ invoice.paidAtMs ? date(invoice.paidAtMs) : 'Date unknown',
159
+ invoice.number ? ` · ${invoice.number}` : ''
160
+ ]
161
+ }),
162
+ invoice.periodStartMs && invoice.periodEndMs ? /*#__PURE__*/ _jsx(Typography, {
163
+ variant: "caption",
164
+ color: "text.secondary",
165
+ children: `For ${date(invoice.periodStartMs)} to ${date(invoice.periodEndMs)}`
166
+ }) : null
167
+ ]
168
+ }),
169
+ /*#__PURE__*/ _jsx(Typography, {
170
+ variant: "body2",
171
+ children: money(Number(invoice.paidCents) || 0, invoice.currency || currency)
172
+ }),
173
+ invoice.hostedInvoiceUrl ? /*#__PURE__*/ _jsx(Link, {
174
+ href: invoice.hostedInvoiceUrl,
175
+ target: "_blank",
176
+ rel: "noopener noreferrer",
177
+ variant: "body2",
178
+ children: 'View'
179
+ }) : null
180
+ ]
181
+ }, invoice.$id)),
182
+ invoices.length >= SUBSCRIPTION_INVOICE_WINDOW ? /*#__PURE__*/ _jsx(Typography, {
183
+ variant: "caption",
184
+ color: "text.secondary",
185
+ children: `The ${SUBSCRIPTION_INVOICE_WINDOW} most recent invoices.`
186
+ }) : null
187
+ ]
188
+ }),
189
+ /*#__PURE__*/ _jsx(DialogActions, {
190
+ children: /*#__PURE__*/ _jsx(Button, {
191
+ onClick: onClose,
192
+ children: 'Close'
193
+ })
194
+ })
195
+ ]
196
+ });
197
+ }
198
+ SubscriptionDetailDialog.displayName = 'SubscriptionDetailDialog';
199
+ export default SubscriptionDetailDialog;
200
+
201
+ //# sourceMappingURL=subscription-detail-dialog.component.js.map
@@ -0,0 +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,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,EAAEC,sBAAsB,QAAQ,iCAAgC;AAErF,yFAAyF,GACzF,OAAO,MAAM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026 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 Firestore } from 'firebase/firestore';
18
+ export interface SubscriptionsCardProps {
19
+ hostId: string;
20
+ }
21
+ /** The query key that opens one subscription on arrival: the renewal notification's link. */
22
+ export declare const SUBSCRIPTIONS_SUBSCRIPTION_PARAM = "subscription";
23
+ export interface SubscriptionsSummary {
24
+ monthlyRecurringCents: number;
25
+ payingCount: number;
26
+ trialCount: number;
27
+ pastDueCount: number;
28
+ }
29
+ /**
30
+ * The figures above the list, from aggregation queries: what a store with
31
+ * thousands of subscribers pays for is a handful of index reads, never one
32
+ * read per subscriber.
33
+ *
34
+ * Monthly recurring revenue is summed per billing interval, because a sum
35
+ * cannot divide a yearly price by twelve on the way. Only LIVE-mode
36
+ * subscriptions count: a test checkout is a rehearsal, and the order
37
+ * analytics leave it out for the same reason (`order-analytics.ts`). A
38
+ * subscription with no stored `interval` is left out of the figure rather
39
+ * than guessed at; every sale since AGL-1732 stores one.
40
+ */
41
+ export declare function loadSubscriptionsSummary(firestore: Firestore, hostId: string): Promise<SubscriptionsSummary>;
42
+ /**
43
+ * Subscriptions (AGL-4191): every subscription on the site, newest first, and
44
+ * what they add up to.
45
+ *
46
+ * Until this, a merchant could see subscriptions only one person at a time, in
47
+ * a site member's Purchases: a digital or service subscription writes no order
48
+ * per cycle, so Orders never showed them either.
49
+ *
50
+ * THE STATUS FILTER IS THE QUERY, as on Returns: `status == X` ordered by
51
+ * `createdAtMs` descending, served by the `subscriptions(status ASC,
52
+ * createdAtMs DESC)` composite; "All" is the single-field order alone. Opening
53
+ * a row shows the subscription's invoices; `?subscription={id}` opens one on
54
+ * arrival, which is where the renewal notification links.
55
+ */
56
+ export declare function SubscriptionsCard(props: SubscriptionsCardProps): import("react").JSX.Element;
57
+ export declare namespace SubscriptionsCard {
58
+ var displayName: string;
59
+ }
60
+ export default SubscriptionsCard;
@@ -0,0 +1,280 @@
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
+ */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ import * as CommerceModel from "../../model/index.js";
20
+ import { CardDisplay } from "@aglyn/shared-ui-jsx";
21
+ import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
22
+ import { pluginDocsHelp } from "@aglyn/aglyn";
23
+ import { Chip, List, ListItemButton, ListItemText, MenuItem, Stack, TextField, Typography } from "@mui/material";
24
+ import { collection, doc, getAggregateFromServer, limit, orderBy, query, sum, count, where } from "firebase/firestore";
25
+ import { useSearchParams } from "next/navigation";
26
+ import { useEffect, useRef, useState } from "react";
27
+ import { useFirestore, useFirestoreDoc, usePagedCollection } from "@aglyn/tenant-feature-instance";
28
+ import CommerceStatTile from "./commerce-stat-tile.component.js";
29
+ import SubscriptionDetailDialog from "./subscription-detail-dialog.component.js";
30
+ /** The query key that opens one subscription on arrival: the renewal notification's link. */ export const SUBSCRIPTIONS_SUBSCRIPTION_PARAM = 'subscription';
31
+ /**
32
+ * The figures above the list, from aggregation queries: what a store with
33
+ * thousands of subscribers pays for is a handful of index reads, never one
34
+ * read per subscriber.
35
+ *
36
+ * Monthly recurring revenue is summed per billing interval, because a sum
37
+ * cannot divide a yearly price by twelve on the way. Only LIVE-mode
38
+ * subscriptions count: a test checkout is a rehearsal, and the order
39
+ * analytics leave it out for the same reason (`order-analytics.ts`). A
40
+ * subscription with no stored `interval` is left out of the figure rather
41
+ * than guessed at; every sale since AGL-1732 stores one.
42
+ */ export async function loadSubscriptionsSummary(firestore, hostId) {
43
+ const subscriptions = collection(firestore, 'hosts', hostId, 'subscriptions');
44
+ const paying = (interval)=>getAggregateFromServer(query(subscriptions, where('status', 'in', [
45
+ ...CommerceModel.SUBSCRIPTION_PAYING_STATUSES
46
+ ]), where('interval', '==', interval), where('livemode', '==', true)), {
47
+ subscriptions: count(),
48
+ totalCents: sum('totals.totalCents'),
49
+ taxCents: sum('totals.taxCents')
50
+ });
51
+ const counted = (status)=>getAggregateFromServer(query(subscriptions, where('status', '==', status), where('livemode', '==', true)), {
52
+ subscriptions: count()
53
+ });
54
+ // AGL-1715-EXEMPT: four separate count queries, one per figure on the card;
55
+ // the status words are each query's own filter, not a membership set.
56
+ const [monthly, yearly, trials, pastDue] = await Promise.all([
57
+ paying('month'),
58
+ paying('year'),
59
+ counted('trialing'),
60
+ counted('past_due')
61
+ ]);
62
+ const figure = (value)=>Number(value) || 0;
63
+ return {
64
+ monthlyRecurringCents: CommerceModel.monthlyRecurringCents(monthly.data().totalCents, monthly.data().taxCents, 'month') + CommerceModel.monthlyRecurringCents(yearly.data().totalCents, yearly.data().taxCents, 'year'),
65
+ payingCount: figure(monthly.data().subscriptions) + figure(yearly.data().subscriptions),
66
+ trialCount: figure(trials.data().subscriptions),
67
+ pastDueCount: figure(pastDue.data().subscriptions)
68
+ };
69
+ }
70
+ /**
71
+ * Subscriptions (AGL-4191): every subscription on the site, newest first, and
72
+ * what they add up to.
73
+ *
74
+ * Until this, a merchant could see subscriptions only one person at a time, in
75
+ * a site member's Purchases: a digital or service subscription writes no order
76
+ * per cycle, so Orders never showed them either.
77
+ *
78
+ * THE STATUS FILTER IS THE QUERY, as on Returns: `status == X` ordered by
79
+ * `createdAtMs` descending, served by the `subscriptions(status ASC,
80
+ * createdAtMs DESC)` composite; "All" is the single-field order alone. Opening
81
+ * a row shows the subscription's invoices; `?subscription={id}` opens one on
82
+ * arrival, which is where the renewal notification links.
83
+ */ export function SubscriptionsCard(props) {
84
+ var _ref, _ref1, _rows_find;
85
+ const { hostId } = props;
86
+ const firestore = useFirestore();
87
+ const [filter, setFilter] = useState('all');
88
+ const [selectedId, setSelectedId] = useState(null);
89
+ const [summary, setSummary] = useState(null);
90
+ const [summaryFailed, setSummaryFailed] = useState(false);
91
+ const { data: store } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId, 'settings', 'store'), [
92
+ firestore,
93
+ hostId
94
+ ]);
95
+ const currency = String((_ref = store == null ? void 0 : store.currency) != null ? _ref : 'USD').toUpperCase();
96
+ const money = (cents)=>CommerceModel.formatOrderMoney(cents, currency);
97
+ useEffect(()=>{
98
+ let live = true;
99
+ setSummaryFailed(false);
100
+ loadSubscriptionsSummary(firestore, hostId).then((next)=>{
101
+ if (live) setSummary(next);
102
+ }).catch((error)=>{
103
+ console.error('Subscriptions summary unavailable', error);
104
+ if (live) setSummaryFailed(true);
105
+ });
106
+ return ()=>{
107
+ live = false;
108
+ };
109
+ }, [
110
+ firestore,
111
+ hostId
112
+ ]);
113
+ const { rows, hasMore, page, setPage, pageSize, setPageSize, status } = usePagedCollection((pageLimit)=>query(collection(firestore, 'hosts', hostId, 'subscriptions'), ...filter === 'all' ? [] : [
114
+ where('status', '==', filter)
115
+ ], orderBy('createdAtMs', 'desc'), limit(pageLimit)), [
116
+ firestore,
117
+ hostId,
118
+ filter
119
+ ], {
120
+ idField: '$id'
121
+ });
122
+ const searchParams = useSearchParams();
123
+ const seededId = (_ref1 = searchParams == null ? void 0 : searchParams.get(SUBSCRIPTIONS_SUBSCRIPTION_PARAM)) != null ? _ref1 : null;
124
+ // Once per id, so closing the dialog does not reopen it on the next render.
125
+ const seeded = useRef(null);
126
+ useEffect(()=>{
127
+ if (!seededId || seeded.current === seededId) return;
128
+ seeded.current = seededId;
129
+ setSelectedId(seededId);
130
+ }, [
131
+ seededId
132
+ ]);
133
+ // A linked subscription need not be on this page, so it is read by id.
134
+ const onPage = selectedId ? (_rows_find = rows.find((row)=>row.$id === selectedId)) != null ? _rows_find : null : null;
135
+ const { data: linked } = useFirestoreDoc(()=>selectedId && !onPage ? doc(firestore, 'hosts', hostId, 'subscriptions', selectedId) : null, [
136
+ firestore,
137
+ hostId,
138
+ selectedId,
139
+ Boolean(onPage)
140
+ ]);
141
+ const selected = onPage != null ? onPage : selectedId && linked ? _extends({}, linked, {
142
+ $id: selectedId
143
+ }) : null;
144
+ return /*#__PURE__*/ _jsxs(CardDisplay, {
145
+ header: 'Subscriptions',
146
+ help: pluginDocsHelp('catalog', {
147
+ anchor: '#subscriptions-list'
148
+ }),
149
+ HeaderProps: {
150
+ action: /*#__PURE__*/ _jsxs(TextField, {
151
+ label: "Status",
152
+ value: filter,
153
+ onChange: (event)=>setFilter(event.target.value),
154
+ size: "small",
155
+ select: true,
156
+ sx: {
157
+ minWidth: 160
158
+ },
159
+ children: [
160
+ /*#__PURE__*/ _jsx(MenuItem, {
161
+ value: "all",
162
+ children: 'All'
163
+ }),
164
+ CommerceModel.SUBSCRIPTION_FILTER_STATUSES.map((value)=>/*#__PURE__*/ _jsx(MenuItem, {
165
+ value: value,
166
+ children: CommerceModel.subscriptionStatusLabel(value)
167
+ }, value))
168
+ ]
169
+ })
170
+ },
171
+ contentGutterX: true,
172
+ contentGutterY: true,
173
+ children: [
174
+ /*#__PURE__*/ _jsxs(Stack, {
175
+ spacing: 2,
176
+ children: [
177
+ /*#__PURE__*/ _jsxs(Stack, {
178
+ direction: "row",
179
+ useFlexGap: true,
180
+ sx: {
181
+ flexWrap: 'wrap',
182
+ columnGap: 4,
183
+ rowGap: 1.5
184
+ },
185
+ children: [
186
+ /*#__PURE__*/ _jsx(CommerceStatTile, {
187
+ label: "Monthly recurring revenue",
188
+ value: summary ? money(summary.monthlyRecurringCents) : summaryFailed ? '—' : '…'
189
+ }),
190
+ /*#__PURE__*/ _jsx(CommerceStatTile, {
191
+ label: "Paying subscribers",
192
+ value: summary ? String(summary.payingCount) : summaryFailed ? '—' : '…'
193
+ }),
194
+ /*#__PURE__*/ _jsx(CommerceStatTile, {
195
+ label: "In a free trial",
196
+ value: summary ? String(summary.trialCount) : summaryFailed ? '—' : '…'
197
+ }),
198
+ /*#__PURE__*/ _jsx(CommerceStatTile, {
199
+ label: "Past due",
200
+ value: summary ? String(summary.pastDueCount) : summaryFailed ? '—' : '…'
201
+ })
202
+ ]
203
+ }),
204
+ /*#__PURE__*/ _jsx(Typography, {
205
+ variant: "caption",
206
+ color: "text.secondary",
207
+ children: summaryFailed ? 'These figures could not be loaded. The list below is unaffected.' : '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.'
208
+ }),
209
+ rows.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
210
+ variant: "body2",
211
+ color: "text.secondary",
212
+ children: status === 'error' ? 'Subscriptions take the "See orders and webhooks" permission on this site.' : status === 'loading' ? 'Loading subscriptions…' : filter === 'all' ? 'No subscriptions yet. When someone subscribes to a monthly or yearly product, they appear here.' : `No ${CommerceModel.subscriptionStatusLabel(filter).toLowerCase()} subscriptions.`
213
+ }) : /*#__PURE__*/ _jsx(List, {
214
+ disablePadding: true,
215
+ children: rows.map((row)=>{
216
+ var _row_invoicesCount;
217
+ var _row_totals;
218
+ const dateText = CommerceModel.subscriptionDateText(CommerceModel.subscriptionDateLine(row));
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` : '';
221
+ return /*#__PURE__*/ _jsxs(ListItemButton, {
222
+ onClick: ()=>setSelectedId(row.$id),
223
+ divider: true,
224
+ children: [
225
+ /*#__PURE__*/ _jsx(ListItemText, {
226
+ primary: `${row.customerName || row.customerEmail || 'Unknown customer'} · ${CommerceModel.subscriptionPlanName(row)}`,
227
+ secondary: [
228
+ price,
229
+ dateText,
230
+ paid
231
+ ].filter(Boolean).join(' · ')
232
+ }),
233
+ /*#__PURE__*/ _jsxs(Stack, {
234
+ direction: "row",
235
+ spacing: 1,
236
+ sx: {
237
+ alignItems: 'center',
238
+ flexShrink: 0
239
+ },
240
+ children: [
241
+ row.livemode === false ? /*#__PURE__*/ _jsx(Chip, {
242
+ label: "Test",
243
+ size: "small",
244
+ variant: "outlined"
245
+ }) : null,
246
+ /*#__PURE__*/ _jsx(Chip, {
247
+ label: CommerceModel.subscriptionStatusLabel(row.status),
248
+ size: "small",
249
+ color: CommerceModel.subscriptionStatusColor(row.status),
250
+ variant: "outlined"
251
+ })
252
+ ]
253
+ })
254
+ ]
255
+ }, row.$id);
256
+ })
257
+ }),
258
+ /*#__PURE__*/ _jsx(ListPagination, {
259
+ page: page,
260
+ pageSize: pageSize,
261
+ rowCount: rows.length,
262
+ hasMore: hasMore,
263
+ onPageChange: setPage,
264
+ onPageSizeChange: setPageSize
265
+ })
266
+ ]
267
+ }),
268
+ selected ? /*#__PURE__*/ _jsx(SubscriptionDetailDialog, {
269
+ hostId: hostId,
270
+ subscription: selected,
271
+ currency: currency,
272
+ onClose: ()=>setSelectedId(null)
273
+ }) : null
274
+ ]
275
+ });
276
+ }
277
+ SubscriptionsCard.displayName = 'SubscriptionsCard';
278
+ export default SubscriptionsCard;
279
+
280
+ //# sourceMappingURL=subscriptions-card.component.js.map