@aglyn/plugins-commerce 1.14.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 (214) 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 +38 -9
  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 +282 -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 +32 -8
  49. package/src/lib/components/product-detail.js.map +1 -1
  50. package/src/lib/components/quote-page-body.js +7 -3
  51. package/src/lib/components/quote-page-body.js.map +1 -1
  52. package/src/lib/components/related-products.js +6 -3
  53. package/src/lib/components/related-products.js.map +1 -1
  54. package/src/lib/components/storefront-payment-element.d.ts +7 -1
  55. package/src/lib/components/storefront-payment-element.js +11 -7
  56. package/src/lib/components/storefront-payment-element.js.map +1 -1
  57. package/src/lib/constants/operator-alerts.d.ts +1 -1
  58. package/src/lib/constants/operator-alerts.js +4 -4
  59. package/src/lib/constants/operator-alerts.js.map +1 -1
  60. package/src/lib/model/commerce-orders.d.ts +6 -2
  61. package/src/lib/model/commerce-orders.js.map +1 -1
  62. package/src/lib/model/commerce-payment-methods.d.ts +27 -16
  63. package/src/lib/model/commerce-payment-methods.js +11 -83
  64. package/src/lib/model/commerce-payment-methods.js.map +1 -1
  65. package/src/lib/model/commerce.d.ts +6 -0
  66. package/src/lib/model/commerce.js.map +1 -1
  67. package/src/lib/model/index.d.ts +1 -0
  68. package/src/lib/model/index.js +1 -0
  69. package/src/lib/model/index.js.map +1 -1
  70. package/src/lib/model/paid-media.d.ts +8 -0
  71. package/src/lib/model/paid-media.js +13 -0
  72. package/src/lib/model/paid-media.js.map +1 -1
  73. package/src/lib/model/pos-hardware-in-person.d.ts +23 -2
  74. package/src/lib/model/pos-hardware-in-person.js +52 -20
  75. package/src/lib/model/pos-hardware-in-person.js.map +1 -1
  76. package/src/lib/model/pos-hardware-tax-summary.d.ts +5 -1
  77. package/src/lib/model/pos-hardware-tax-summary.js +2 -1
  78. package/src/lib/model/pos-hardware-tax-summary.js.map +1 -1
  79. package/src/lib/model/pos-hardware-terms.d.ts +37 -2
  80. package/src/lib/model/pos-hardware-terms.js +68 -3
  81. package/src/lib/model/pos-hardware-terms.js.map +1 -1
  82. package/src/lib/model/pos-hardware.d.ts +101 -15
  83. package/src/lib/model/pos-hardware.js +128 -18
  84. package/src/lib/model/pos-hardware.js.map +1 -1
  85. package/src/lib/model/pos-reader-splash.js +2 -2
  86. package/src/lib/model/pos-reader-splash.js.map +1 -1
  87. package/src/lib/model/product-write.d.ts +3 -0
  88. package/src/lib/model/subscription-view.d.ts +90 -0
  89. package/src/lib/model/subscription-view.js +176 -0
  90. package/src/lib/model/subscription-view.js.map +1 -0
  91. package/src/lib/server/billing-webhook.d.ts +27 -6
  92. package/src/lib/server/billing-webhook.js +271 -81
  93. package/src/lib/server/billing-webhook.js.map +1 -1
  94. package/src/lib/server/cancel-order.js +4 -3
  95. package/src/lib/server/cancel-order.js.map +1 -1
  96. package/src/lib/server/cart-checkout.js +105 -23
  97. package/src/lib/server/cart-checkout.js.map +1 -1
  98. package/src/lib/server/cart.js +15 -3
  99. package/src/lib/server/cart.js.map +1 -1
  100. package/src/lib/server/catalog.js +58 -22
  101. package/src/lib/server/catalog.js.map +1 -1
  102. package/src/lib/server/checkout-session-expiry.d.ts +1 -1
  103. package/src/lib/server/checkout-session-expiry.js +19 -5
  104. package/src/lib/server/checkout-session-expiry.js.map +1 -1
  105. package/src/lib/server/checkout-status.js +4 -3
  106. package/src/lib/server/checkout-status.js.map +1 -1
  107. package/src/lib/server/checkout.js +98 -26
  108. package/src/lib/server/checkout.js.map +1 -1
  109. package/src/lib/server/connect.js +42 -11
  110. package/src/lib/server/connect.js.map +1 -1
  111. package/src/lib/server/draft-order.js +36 -7
  112. package/src/lib/server/draft-order.js.map +1 -1
  113. package/src/lib/server/manual-tax-rate.d.ts +11 -3
  114. package/src/lib/server/manual-tax-rate.js +10 -6
  115. package/src/lib/server/manual-tax-rate.js.map +1 -1
  116. package/src/lib/server/membership-account.d.ts +22 -0
  117. package/src/lib/server/membership-account.js +52 -8
  118. package/src/lib/server/membership-account.js.map +1 -1
  119. package/src/lib/server/native-checkout.d.ts +10 -3
  120. package/src/lib/server/native-checkout.js +8 -3
  121. package/src/lib/server/native-checkout.js.map +1 -1
  122. package/src/lib/server/payment-method-domains.d.ts +50 -9
  123. package/src/lib/server/payment-method-domains.js +150 -51
  124. package/src/lib/server/payment-method-domains.js.map +1 -1
  125. package/src/lib/server/payment-methods.js +3 -2
  126. package/src/lib/server/payment-methods.js.map +1 -1
  127. package/src/lib/server/pos-auth.d.ts +3 -3
  128. package/src/lib/server/pos-auth.js +3 -3
  129. package/src/lib/server/pos-auth.js.map +1 -1
  130. package/src/lib/server/pos-cellular-billing.js +1 -1
  131. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  132. package/src/lib/server/pos-cellular-notify.js +1 -1
  133. package/src/lib/server/pos-cellular-notify.js.map +1 -1
  134. package/src/lib/server/pos-cellular.js +1 -1
  135. package/src/lib/server/pos-cellular.js.map +1 -1
  136. package/src/lib/server/pos-hardware-admin.js +86 -13
  137. package/src/lib/server/pos-hardware-admin.js.map +1 -1
  138. package/src/lib/server/pos-hardware-attach.js +5 -5
  139. package/src/lib/server/pos-hardware-attach.js.map +1 -1
  140. package/src/lib/server/pos-hardware-cancel.js +65 -0
  141. package/src/lib/server/pos-hardware-cancel.js.map +1 -1
  142. package/src/lib/server/pos-hardware-closure-notices.js +2 -5
  143. package/src/lib/server/pos-hardware-closure-notices.js.map +1 -1
  144. package/src/lib/server/pos-hardware-closure.js +5 -8
  145. package/src/lib/server/pos-hardware-closure.js.map +1 -1
  146. package/src/lib/server/pos-hardware-in-person.d.ts +2 -1
  147. package/src/lib/server/pos-hardware-in-person.js +72 -17
  148. package/src/lib/server/pos-hardware-in-person.js.map +1 -1
  149. package/src/lib/server/pos-hardware-notify.d.ts +2 -0
  150. package/src/lib/server/pos-hardware-notify.js +30 -5
  151. package/src/lib/server/pos-hardware-notify.js.map +1 -1
  152. package/src/lib/server/pos-hardware-readers.d.ts +25 -0
  153. package/src/lib/server/pos-hardware-readers.js +206 -85
  154. package/src/lib/server/pos-hardware-readers.js.map +1 -1
  155. package/src/lib/server/pos-hardware-returns.d.ts +8 -3
  156. package/src/lib/server/pos-hardware-returns.js +39 -7
  157. package/src/lib/server/pos-hardware-returns.js.map +1 -1
  158. package/src/lib/server/pos-hardware-sale-fields.d.ts +76 -0
  159. package/src/lib/server/pos-hardware-sale-fields.js +114 -1
  160. package/src/lib/server/pos-hardware-sale-fields.js.map +1 -1
  161. package/src/lib/server/pos-hardware-sale.d.ts +2 -0
  162. package/src/lib/server/pos-hardware-sale.js +1 -0
  163. package/src/lib/server/pos-hardware-sale.js.map +1 -1
  164. package/src/lib/server/pos-hardware-tax-return-source.js +7 -4
  165. package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -1
  166. package/src/lib/server/pos-hardware-webhook.js +16 -3
  167. package/src/lib/server/pos-hardware-webhook.js.map +1 -1
  168. package/src/lib/server/pos-hardware.d.ts +14 -3
  169. package/src/lib/server/pos-hardware.js +83 -18
  170. package/src/lib/server/pos-hardware.js.map +1 -1
  171. package/src/lib/server/pos-ops-routes.js +2 -10
  172. package/src/lib/server/pos-ops-routes.js.map +1 -1
  173. package/src/lib/server/pos-order.js +5 -1
  174. package/src/lib/server/pos-order.js.map +1 -1
  175. package/src/lib/server/pos-stripe.d.ts +7 -7
  176. package/src/lib/server/pos-stripe.js +15 -13
  177. package/src/lib/server/pos-stripe.js.map +1 -1
  178. package/src/lib/server/pos-terminal.js +11 -3
  179. package/src/lib/server/pos-terminal.js.map +1 -1
  180. package/src/lib/server/quote-pay.d.ts +23 -1
  181. package/src/lib/server/quote-pay.js +111 -27
  182. package/src/lib/server/quote-pay.js.map +1 -1
  183. package/src/lib/server/quote.d.ts +2 -1
  184. package/src/lib/server/quote.js +12 -11
  185. package/src/lib/server/quote.js.map +1 -1
  186. package/src/lib/server/refund.js +13 -6
  187. package/src/lib/server/refund.js.map +1 -1
  188. package/src/lib/server/related.js +10 -3
  189. package/src/lib/server/related.js.map +1 -1
  190. package/src/lib/server/reserve.js +19 -6
  191. package/src/lib/server/reserve.js.map +1 -1
  192. package/src/lib/server/revenue-source.d.ts +6 -0
  193. package/src/lib/server/revenue-source.js +25 -9
  194. package/src/lib/server/revenue-source.js.map +1 -1
  195. package/src/lib/server/seller-stripe-account.d.ts +45 -0
  196. package/src/lib/server/seller-stripe-account.js +99 -0
  197. package/src/lib/server/seller-stripe-account.js.map +1 -0
  198. package/src/lib/server/storefront-tax-record.js +6 -1
  199. package/src/lib/server/storefront-tax-record.js.map +1 -1
  200. package/src/lib/server/storefront-tax.d.ts +33 -2
  201. package/src/lib/server/storefront-tax.js +39 -3
  202. package/src/lib/server/storefront-tax.js.map +1 -1
  203. package/src/lib/server/stream.d.ts +2 -0
  204. package/src/lib/server/stream.js +22 -2
  205. package/src/lib/server/stream.js.map +1 -1
  206. package/src/lib/server/stripe-refund.d.ts +15 -0
  207. package/src/lib/server/stripe-refund.js +54 -26
  208. package/src/lib/server/stripe-refund.js.map +1 -1
  209. package/src/lib/server/subscription-portal.js +8 -3
  210. package/src/lib/server/subscription-portal.js.map +1 -1
  211. package/src/lib/server/tax-return-source.js +5 -1
  212. package/src/lib/server/tax-return-source.js.map +1 -1
  213. package/src/lib/server.js +2 -2
  214. package/src/lib/server.js.map +1 -1
@@ -0,0 +1,176 @@
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 a storefront subscription (`hosts/{hostId}/subscriptions`) reads to a
18
+ * person (AGL-4191): its status in words, the one date that matters next, and
19
+ * what it is worth a month. One copy for the console's Subscriptions list and
20
+ * the buyer's account page, so the merchant and the subscriber never read two
21
+ * different answers about the same subscription.
22
+ */ /** Stripe's subscription statuses, in the merchant's words. */ export const SUBSCRIPTION_STATUS_LABELS = {
23
+ active: 'Active',
24
+ trialing: 'Trial',
25
+ past_due: 'Past due',
26
+ unpaid: 'Unpaid',
27
+ incomplete: 'Incomplete',
28
+ incomplete_expired: 'Expired',
29
+ canceled: 'Canceled',
30
+ paused: 'Paused'
31
+ };
32
+ export const SUBSCRIPTION_STATUS_COLOR = {
33
+ active: 'success',
34
+ trialing: 'info',
35
+ past_due: 'warning',
36
+ unpaid: 'error',
37
+ incomplete: 'warning'
38
+ };
39
+ /** The statuses the console's filter offers, in the order a merchant scans them. */ // AGL-1715-EXEMPT: the options of the subscriptions list's status filter, a
40
+ // display vocabulary rather than a "live" test; nothing is granted or refused
41
+ // by membership in it.
42
+ export const SUBSCRIPTION_FILTER_STATUSES = [
43
+ 'active',
44
+ 'trialing',
45
+ 'past_due',
46
+ 'unpaid',
47
+ 'incomplete',
48
+ 'canceled'
49
+ ];
50
+ /**
51
+ * The statuses that bring money in every cycle: what monthly recurring revenue
52
+ * counts. A trial has not paid yet, and `unpaid` has stopped paying; `past_due`
53
+ * stays in because Stripe is still collecting and the subscriber has not left,
54
+ * the same reason it stays live for access (`commerce-subscription-status.ts`).
55
+ */ export const SUBSCRIPTION_PAYING_STATUSES = [
56
+ 'active',
57
+ 'past_due'
58
+ ];
59
+ export function subscriptionStatusLabel(status) {
60
+ var _SUBSCRIPTION_STATUS_LABELS_key;
61
+ const key = String(status != null ? status : '');
62
+ return (_SUBSCRIPTION_STATUS_LABELS_key = SUBSCRIPTION_STATUS_LABELS[key]) != null ? _SUBSCRIPTION_STATUS_LABELS_key : key ? key.replace(/_/g, ' ') : 'Unknown';
63
+ }
64
+ export function subscriptionStatusColor(status) {
65
+ var _SUBSCRIPTION_STATUS_COLOR_String;
66
+ return (_SUBSCRIPTION_STATUS_COLOR_String = SUBSCRIPTION_STATUS_COLOR[String(status != null ? status : '')]) != null ? _SUBSCRIPTION_STATUS_COLOR_String : 'default';
67
+ }
68
+ /** `month` or `year` from a stored value, or null for anything else. */ export function subscriptionInterval(value) {
69
+ return value === 'month' || value === 'year' ? value : null;
70
+ }
71
+ /**
72
+ * A recurring charge as a monthly figure: a yearly price counts a twelfth.
73
+ * Tax is the government's, not the merchant's revenue, so it is left out.
74
+ * Rounded to whole cents.
75
+ */ export function monthlyRecurringCents(totalCents, taxCents, interval) {
76
+ const net = Math.max(0, (Number(totalCents) || 0) - (Number(taxCents) || 0));
77
+ const cadence = subscriptionInterval(interval);
78
+ if (cadence === 'year') return Math.round(net / 12);
79
+ if (cadence === 'month') return Math.round(net);
80
+ return 0;
81
+ }
82
+ function positiveMs(value) {
83
+ const ms = Number(value);
84
+ return Number.isFinite(ms) && ms > 0 ? ms : undefined;
85
+ }
86
+ /**
87
+ * The one date that matters next for a subscription, or null when there is
88
+ * nothing honest to say.
89
+ *
90
+ * `cancelAtPeriodEnd` wins over a renewal: a subscriber who cancelled in the
91
+ * billing portal keeps access to the end of the period they paid for and is
92
+ * not charged again, so "Renews" would be a promise of a charge that will not
93
+ * happen. A failed payment names no date, because Stripe moves the period end
94
+ * forward while the unpaid invoice is retried, so that date is neither a
95
+ * renewal nor an end.
96
+ */ export function subscriptionDateLine(subscription) {
97
+ var _subscription_status, _positiveMs;
98
+ const status = String((_subscription_status = subscription.status) != null ? _subscription_status : '');
99
+ const periodEnd = (_positiveMs = positiveMs(subscription.currentPeriodEndMs)) != null ? _positiveMs : positiveMs(subscription.paidThroughMs);
100
+ const ending = subscription.cancelAtPeriodEnd === true;
101
+ switch(status){
102
+ case 'active':
103
+ if (!periodEnd) return null;
104
+ return {
105
+ kind: ending ? 'ends' : 'renews',
106
+ atMs: periodEnd
107
+ };
108
+ case 'trialing':
109
+ if (!periodEnd) return null;
110
+ return {
111
+ kind: ending ? 'ends' : 'trialEnds',
112
+ atMs: periodEnd
113
+ };
114
+ case 'past_due':
115
+ case 'unpaid':
116
+ return {
117
+ kind: 'paymentFailed'
118
+ };
119
+ case 'incomplete':
120
+ return {
121
+ kind: 'awaitingPayment'
122
+ };
123
+ case 'canceled':
124
+ case 'incomplete_expired':
125
+ return periodEnd ? {
126
+ kind: 'ended',
127
+ atMs: periodEnd
128
+ } : null;
129
+ default:
130
+ return null;
131
+ }
132
+ }
133
+ /** A short date in the reader's own locale: "Dec 4, 2026". */ export function formatSubscriptionDate(ms) {
134
+ return new Date(ms).toLocaleDateString(undefined, {
135
+ month: 'short',
136
+ day: 'numeric',
137
+ year: 'numeric'
138
+ });
139
+ }
140
+ /** The date line in words: "Renews Dec 4, 2026", "Payment failed". */ export function subscriptionDateText(line, formatDate = formatSubscriptionDate) {
141
+ if (!line) return '';
142
+ const on = line.atMs ? formatDate(line.atMs) : '';
143
+ switch(line.kind){
144
+ case 'renews':
145
+ return `Renews ${on}`;
146
+ case 'trialEnds':
147
+ return `Trial ends ${on}`;
148
+ case 'ends':
149
+ return `Ends ${on}`;
150
+ case 'ended':
151
+ return `Ended ${on}`;
152
+ case 'paymentFailed':
153
+ return 'Payment failed';
154
+ case 'awaitingPayment':
155
+ return 'Waiting for the first payment';
156
+ }
157
+ }
158
+ /** "/month" or "/year", or "" for a stored value that is neither. */ export function subscriptionIntervalSuffix(interval) {
159
+ const cadence = subscriptionInterval(interval);
160
+ return cadence ? `/${cadence}` : '';
161
+ }
162
+ /**
163
+ * What a subscription's plan is called: the line the subscriber bought, with
164
+ * its quantity when more than one, or the product id for a subscription sold
165
+ * before lines were stored (AGL-1732).
166
+ */ export function subscriptionPlanName(subscription) {
167
+ var _subscription_lineItems;
168
+ const line = (_subscription_lineItems = subscription.lineItems) == null ? void 0 : _subscription_lineItems[0];
169
+ if (line == null ? void 0 : line.name) {
170
+ var _line_quantity;
171
+ return ((_line_quantity = line.quantity) != null ? _line_quantity : 1) > 1 ? `${line.quantity}× ${line.name}` : line.name;
172
+ }
173
+ return subscription.productId || 'Subscription';
174
+ }
175
+
176
+ //# sourceMappingURL=subscription-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/subscription-view.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * How a storefront subscription (`hosts/{hostId}/subscriptions`) reads to a\n * person (AGL-4191): its status in words, the one date that matters next, and\n * what it is worth a month. One copy for the console's Subscriptions list and\n * the buyer's account page, so the merchant and the subscriber never read two\n * different answers about the same subscription.\n */\n\nexport type SubscriptionBillingInterval = 'month' | 'year'\n\n/** Stripe's subscription statuses, in the merchant's words. */\nexport const SUBSCRIPTION_STATUS_LABELS: Readonly<Record<string, string>> = {\n active: 'Active',\n trialing: 'Trial',\n past_due: 'Past due',\n unpaid: 'Unpaid',\n incomplete: 'Incomplete',\n incomplete_expired: 'Expired',\n canceled: 'Canceled',\n paused: 'Paused',\n}\n\nexport const SUBSCRIPTION_STATUS_COLOR: Readonly<\n Record<string, 'success' | 'info' | 'warning' | 'error' | 'default'>\n> = {\n active: 'success',\n trialing: 'info',\n past_due: 'warning',\n unpaid: 'error',\n incomplete: 'warning',\n}\n\n/** The statuses the console's filter offers, in the order a merchant scans them. */\n// AGL-1715-EXEMPT: the options of the subscriptions list's status filter, a\n// display vocabulary rather than a \"live\" test; nothing is granted or refused\n// by membership in it.\nexport const SUBSCRIPTION_FILTER_STATUSES = [\n 'active',\n 'trialing',\n 'past_due',\n 'unpaid',\n 'incomplete',\n 'canceled',\n] as const\n\n/**\n * The statuses that bring money in every cycle: what monthly recurring revenue\n * counts. A trial has not paid yet, and `unpaid` has stopped paying; `past_due`\n * stays in because Stripe is still collecting and the subscriber has not left,\n * the same reason it stays live for access (`commerce-subscription-status.ts`).\n */\nexport const SUBSCRIPTION_PAYING_STATUSES = ['active', 'past_due'] as const\n\nexport function subscriptionStatusLabel(status: unknown): string {\n const key = String(status ?? '')\n return SUBSCRIPTION_STATUS_LABELS[key] ?? (key ? key.replace(/_/g, ' ') : 'Unknown')\n}\n\nexport function subscriptionStatusColor(\n status: unknown,\n): 'success' | 'info' | 'warning' | 'error' | 'default' {\n return SUBSCRIPTION_STATUS_COLOR[String(status ?? '')] ?? 'default'\n}\n\n/** `month` or `year` from a stored value, or null for anything else. */\nexport function subscriptionInterval(value: unknown): SubscriptionBillingInterval | null {\n return value === 'month' || value === 'year' ? value : null\n}\n\n/**\n * A recurring charge as a monthly figure: a yearly price counts a twelfth.\n * Tax is the government's, not the merchant's revenue, so it is left out.\n * Rounded to whole cents.\n */\nexport function monthlyRecurringCents(\n totalCents: unknown,\n taxCents: unknown,\n interval: unknown,\n): number {\n const net = Math.max(0, (Number(totalCents) || 0) - (Number(taxCents) || 0))\n const cadence = subscriptionInterval(interval)\n if (cadence === 'year') return Math.round(net / 12)\n if (cadence === 'month') return Math.round(net)\n return 0\n}\n\n/** The fields of a stored subscription the date line reads. */\nexport interface SubscriptionDateFields {\n status?: unknown\n cancelAtPeriodEnd?: unknown\n currentPeriodEndMs?: unknown\n /** Set by each paid invoice; the fallback when Stripe sent no period end. */\n paidThroughMs?: unknown\n}\n\nexport type SubscriptionDateKind =\n | 'renews'\n | 'trialEnds'\n | 'ends'\n | 'ended'\n | 'paymentFailed'\n | 'awaitingPayment'\n\nexport interface SubscriptionDateLine {\n kind: SubscriptionDateKind\n /** Absent where the line names no date (\"Payment failed\"). */\n atMs?: number\n}\n\nfunction positiveMs(value: unknown): number | undefined {\n const ms = Number(value)\n return Number.isFinite(ms) && ms > 0 ? ms : undefined\n}\n\n/**\n * The one date that matters next for a subscription, or null when there is\n * nothing honest to say.\n *\n * `cancelAtPeriodEnd` wins over a renewal: a subscriber who cancelled in the\n * billing portal keeps access to the end of the period they paid for and is\n * not charged again, so \"Renews\" would be a promise of a charge that will not\n * happen. A failed payment names no date, because Stripe moves the period end\n * forward while the unpaid invoice is retried, so that date is neither a\n * renewal nor an end.\n */\nexport function subscriptionDateLine(\n subscription: SubscriptionDateFields,\n): SubscriptionDateLine | null {\n const status = String(subscription.status ?? '')\n const periodEnd =\n positiveMs(subscription.currentPeriodEndMs) ?? positiveMs(subscription.paidThroughMs)\n const ending = subscription.cancelAtPeriodEnd === true\n switch (status) {\n case 'active':\n if (!periodEnd) return null\n return { kind: ending ? 'ends' : 'renews', atMs: periodEnd }\n case 'trialing':\n if (!periodEnd) return null\n return { kind: ending ? 'ends' : 'trialEnds', atMs: periodEnd }\n case 'past_due':\n case 'unpaid':\n return { kind: 'paymentFailed' }\n case 'incomplete':\n return { kind: 'awaitingPayment' }\n case 'canceled':\n case 'incomplete_expired':\n return periodEnd ? { kind: 'ended', atMs: periodEnd } : null\n default:\n return null\n }\n}\n\n/** A short date in the reader's own locale: \"Dec 4, 2026\". */\nexport function formatSubscriptionDate(ms: number): string {\n return new Date(ms).toLocaleDateString(undefined, {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n })\n}\n\n/** The date line in words: \"Renews Dec 4, 2026\", \"Payment failed\". */\nexport function subscriptionDateText(\n line: SubscriptionDateLine | null,\n formatDate: (ms: number) => string = formatSubscriptionDate,\n): string {\n if (!line) return ''\n const on = line.atMs ? formatDate(line.atMs) : ''\n switch (line.kind) {\n case 'renews':\n return `Renews ${on}`\n case 'trialEnds':\n return `Trial ends ${on}`\n case 'ends':\n return `Ends ${on}`\n case 'ended':\n return `Ended ${on}`\n case 'paymentFailed':\n return 'Payment failed'\n case 'awaitingPayment':\n return 'Waiting for the first payment'\n }\n}\n\n/** \"/month\" or \"/year\", or \"\" for a stored value that is neither. */\nexport function subscriptionIntervalSuffix(interval: unknown): string {\n const cadence = subscriptionInterval(interval)\n return cadence ? `/${cadence}` : ''\n}\n\n/**\n * What a subscription's plan is called: the line the subscriber bought, with\n * its quantity when more than one, or the product id for a subscription sold\n * before lines were stored (AGL-1732).\n */\nexport function subscriptionPlanName(subscription: {\n lineItems?: Array<{ name?: string; quantity?: number }>\n productId?: string\n}): string {\n const line = subscription.lineItems?.[0]\n if (line?.name) {\n return (line.quantity ?? 1) > 1 ? `${line.quantity}× ${line.name}` : line.name\n }\n return subscription.productId || 'Subscription'\n}\n"],"names":["SUBSCRIPTION_STATUS_LABELS","active","trialing","past_due","unpaid","incomplete","incomplete_expired","canceled","paused","SUBSCRIPTION_STATUS_COLOR","SUBSCRIPTION_FILTER_STATUSES","SUBSCRIPTION_PAYING_STATUSES","subscriptionStatusLabel","status","key","String","replace","subscriptionStatusColor","subscriptionInterval","value","monthlyRecurringCents","totalCents","taxCents","interval","net","Math","max","Number","cadence","round","positiveMs","ms","isFinite","undefined","subscriptionDateLine","subscription","periodEnd","currentPeriodEndMs","paidThroughMs","ending","cancelAtPeriodEnd","kind","atMs","formatSubscriptionDate","Date","toLocaleDateString","month","day","year","subscriptionDateText","line","formatDate","on","subscriptionIntervalSuffix","subscriptionPlanName","lineItems","name","quantity","productId"],"mappings":"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"}
@@ -16,11 +16,32 @@
16
16
  */
17
17
  import type { BillingWebhookHandler } from '@aglyn/aglyn/server';
18
18
  /**
19
- * Commerce sections of the platform Stripe webhook (AGL-418): relocated
20
- * verbatim from the console route — subscriptions sync, reservations,
21
- * cart orders, draft orders, Commerce Starter orders, plus the license-key
22
- * assignment helper (AGL-308). Registered via registerCommerceConsoleApi;
23
- * every section is idempotent by doc key and self-selects on
24
- * `object.metadata.type`, exactly as the inline route sections did.
19
+ * A Stripe subscription's current period end, in seconds (AGL-4191). Older API
20
+ * versions carry it on the subscription; newer ones moved it to each item.
21
+ * Exported for the spec.
25
22
  */
23
+ export declare function subscriptionPeriodEnd(object: any): number | null;
24
+ /**
25
+ * The connected account a Connect-delivered event belongs to, or null for an
26
+ * event on the platform's own account. Direct-charge sales are created ON the
27
+ * seller's account, so their events arrive through the Connect destination
28
+ * with the seller named at the top level.
29
+ */
30
+ export declare function connectEventAccount(event: unknown): string | null;
31
+ /**
32
+ * Whether this handler should act on the event at all, as far as WHOSE
33
+ * account it came from can say. A platform event always passes. A
34
+ * Connect-delivered one passes only when its object says it was sold by
35
+ * direct charge, or when it is a charge-level event the order lookup will
36
+ * judge ({@link connectEventOrderIsDirect}). Exported for the spec.
37
+ */
38
+ export declare function connectEventIsForDirectSale(type: unknown, object: unknown, event: unknown): boolean;
39
+ /**
40
+ * The fields a direct sale's records carry so every later reader can tell it
41
+ * apart without asking Stripe: `refund.ts` refunds on the seller's account,
42
+ * the revenue report counts the application fee as Aglyn's whole take, and
43
+ * the dispute branch leaves the transfer reversal out. Empty for a
44
+ * destination sale, so those documents are written exactly as before.
45
+ */
46
+ export declare function directChargeRecordFields(direct: boolean, account: string | null): Record<string, string>;
26
47
  export declare const commerceBillingWebhookHandler: BillingWebhookHandler;