@aglyn/plugins-commerce 1.14.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.
- package/package.json +13 -13
- package/src/lib/components/account-subscriptions.d.ts +51 -0
- package/src/lib/components/account-subscriptions.js +168 -0
- package/src/lib/components/account-subscriptions.js.map +1 -0
- package/src/lib/components/account.js +12 -48
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart.js +30 -6
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/commerce-console-page.js +6 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +5 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/paid-media.d.ts +1 -0
- package/src/lib/components/console/paid-media.js +15 -4
- package/src/lib/components/console/paid-media.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +1 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-api.d.ts +10 -1
- package/src/lib/components/console/pos/pos-hardware-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js +2 -2
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-sale-api.d.ts +2 -0
- package/src/lib/components/console/pos/pos-hardware-sale-api.js.map +1 -1
- package/src/lib/components/console/pos-cellular-control.component.d.ts +1 -1
- package/src/lib/components/console/pos-cellular-control.component.js +5 -5
- package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
- package/src/lib/components/console/pos-devices-card.component.js +2 -2
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-card.component.d.ts +5 -0
- package/src/lib/components/console/pos-hardware-card.component.js +77 -8
- package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js +137 -19
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js.map +1 -1
- package/src/lib/components/console/pos-page.component.js +19 -2
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +21 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.d.ts +58 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js +201 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/subscriptions-card.component.d.ts +60 -0
- package/src/lib/components/console/subscriptions-card.component.js +280 -0
- package/src/lib/components/console/subscriptions-card.component.js.map +1 -0
- package/src/lib/components/hardware-terms-consent.d.ts +22 -0
- package/src/lib/components/hardware-terms-consent.js +85 -0
- package/src/lib/components/hardware-terms-consent.js.map +1 -0
- package/src/lib/components/product-detail.js +25 -5
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/constants/operator-alerts.d.ts +1 -1
- package/src/lib/constants/operator-alerts.js +4 -4
- package/src/lib/constants/operator-alerts.js.map +1 -1
- package/src/lib/model/commerce-orders.d.ts +6 -2
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +24 -0
- package/src/lib/model/commerce-payment-methods.js +35 -0
- package/src/lib/model/commerce-payment-methods.js.map +1 -1
- package/src/lib/model/commerce.d.ts +6 -0
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/paid-media.d.ts +8 -0
- package/src/lib/model/paid-media.js +13 -0
- package/src/lib/model/paid-media.js.map +1 -1
- package/src/lib/model/pos-hardware-in-person.d.ts +23 -2
- package/src/lib/model/pos-hardware-in-person.js +52 -20
- package/src/lib/model/pos-hardware-in-person.js.map +1 -1
- package/src/lib/model/pos-hardware-tax-summary.d.ts +5 -1
- package/src/lib/model/pos-hardware-tax-summary.js +2 -1
- package/src/lib/model/pos-hardware-tax-summary.js.map +1 -1
- package/src/lib/model/pos-hardware-terms.d.ts +37 -2
- package/src/lib/model/pos-hardware-terms.js +68 -3
- package/src/lib/model/pos-hardware-terms.js.map +1 -1
- package/src/lib/model/pos-hardware.d.ts +101 -15
- package/src/lib/model/pos-hardware.js +128 -18
- package/src/lib/model/pos-hardware.js.map +1 -1
- package/src/lib/model/pos-reader-splash.js +2 -2
- package/src/lib/model/pos-reader-splash.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/model/subscription-view.d.ts +90 -0
- package/src/lib/model/subscription-view.js +176 -0
- package/src/lib/model/subscription-view.js.map +1 -0
- package/src/lib/server/billing-webhook.d.ts +4 -6
- package/src/lib/server/billing-webhook.js +109 -51
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cart-checkout.js +45 -10
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.js +15 -3
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/checkout.js +58 -16
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +7 -3
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/membership-account.d.ts +22 -0
- package/src/lib/server/membership-account.js +52 -8
- package/src/lib/server/membership-account.js.map +1 -1
- package/src/lib/server/pos-auth.d.ts +3 -3
- package/src/lib/server/pos-auth.js +3 -3
- package/src/lib/server/pos-auth.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.js +1 -1
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular-notify.js +1 -1
- package/src/lib/server/pos-cellular-notify.js.map +1 -1
- package/src/lib/server/pos-cellular.js +1 -1
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-hardware-admin.js +86 -13
- package/src/lib/server/pos-hardware-admin.js.map +1 -1
- package/src/lib/server/pos-hardware-attach.js +5 -5
- package/src/lib/server/pos-hardware-attach.js.map +1 -1
- package/src/lib/server/pos-hardware-cancel.js +65 -0
- package/src/lib/server/pos-hardware-cancel.js.map +1 -1
- package/src/lib/server/pos-hardware-closure-notices.js +2 -5
- package/src/lib/server/pos-hardware-closure-notices.js.map +1 -1
- package/src/lib/server/pos-hardware-closure.js +5 -8
- package/src/lib/server/pos-hardware-closure.js.map +1 -1
- package/src/lib/server/pos-hardware-in-person.d.ts +2 -1
- package/src/lib/server/pos-hardware-in-person.js +72 -17
- package/src/lib/server/pos-hardware-in-person.js.map +1 -1
- package/src/lib/server/pos-hardware-notify.d.ts +2 -0
- package/src/lib/server/pos-hardware-notify.js +30 -5
- package/src/lib/server/pos-hardware-notify.js.map +1 -1
- package/src/lib/server/pos-hardware-readers.d.ts +25 -0
- package/src/lib/server/pos-hardware-readers.js +206 -85
- package/src/lib/server/pos-hardware-readers.js.map +1 -1
- package/src/lib/server/pos-hardware-returns.d.ts +8 -3
- package/src/lib/server/pos-hardware-returns.js +39 -7
- package/src/lib/server/pos-hardware-returns.js.map +1 -1
- package/src/lib/server/pos-hardware-sale-fields.d.ts +76 -0
- package/src/lib/server/pos-hardware-sale-fields.js +114 -1
- package/src/lib/server/pos-hardware-sale-fields.js.map +1 -1
- package/src/lib/server/pos-hardware-sale.d.ts +2 -0
- package/src/lib/server/pos-hardware-sale.js +1 -0
- package/src/lib/server/pos-hardware-sale.js.map +1 -1
- package/src/lib/server/pos-hardware-tax-return-source.js +7 -4
- package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -1
- package/src/lib/server/pos-hardware-webhook.js +16 -3
- package/src/lib/server/pos-hardware-webhook.js.map +1 -1
- package/src/lib/server/pos-hardware.d.ts +14 -3
- package/src/lib/server/pos-hardware.js +83 -18
- package/src/lib/server/pos-hardware.js.map +1 -1
- package/src/lib/server/pos-ops-routes.js +2 -10
- package/src/lib/server/pos-ops-routes.js.map +1 -1
- package/src/lib/server/quote-pay.js +8 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/stream.d.ts +2 -0
- package/src/lib/server/stream.js +22 -2
- package/src/lib/server/stream.js.map +1 -1
- package/src/lib/server/tax-return-source.js +5 -1
- package/src/lib/server/tax-return-source.js.map +1 -1
- package/src/lib/server.js +2 -2
- package/src/lib/server.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-commerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
31
|
-
"@aglyn/shared-ui-next": "1.
|
|
32
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
33
|
-
"@aglyn/shared-util-email": "1.
|
|
34
|
-
"@aglyn/shared-util-http": "1.
|
|
35
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
36
|
-
"@aglyn/shared-util-tools": "1.
|
|
37
|
-
"@aglyn/tenant-data-admin": "1.
|
|
38
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
39
|
-
"@aglyn/tenant-runtime": "1.
|
|
28
|
+
"@aglyn/aglyn": "1.15.0",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.15.0",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.15.0",
|
|
31
|
+
"@aglyn/shared-ui-next": "1.15.0",
|
|
32
|
+
"@aglyn/shared-ui-snackstack": "1.15.0",
|
|
33
|
+
"@aglyn/shared-util-email": "1.15.0",
|
|
34
|
+
"@aglyn/shared-util-http": "1.15.0",
|
|
35
|
+
"@aglyn/shared-util-timestamp": "1.15.0",
|
|
36
|
+
"@aglyn/shared-util-tools": "1.15.0",
|
|
37
|
+
"@aglyn/tenant-data-admin": "1.15.0",
|
|
38
|
+
"@aglyn/tenant-feature-instance": "1.15.0",
|
|
39
|
+
"@aglyn/tenant-runtime": "1.15.0",
|
|
40
40
|
"@stripe/react-stripe-js": "^6.12.0",
|
|
41
41
|
"@stripe/stripe-js": "^9.17.0",
|
|
42
42
|
"@swc/helpers": "0.5.23",
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
export interface AccountSubscription {
|
|
18
|
+
id: string;
|
|
19
|
+
productName: string;
|
|
20
|
+
status: string;
|
|
21
|
+
currentPeriodEndMs?: number | null;
|
|
22
|
+
paidThroughMs?: number;
|
|
23
|
+
cancelAtPeriodEnd?: boolean;
|
|
24
|
+
priceCents?: number;
|
|
25
|
+
interval?: string;
|
|
26
|
+
invoices?: Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
paidAtMs: number;
|
|
29
|
+
paidCents: number;
|
|
30
|
+
currency: string;
|
|
31
|
+
number?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export interface AccountSubscriptionsProps {
|
|
36
|
+
hostId: string;
|
|
37
|
+
subscriptions: AccountSubscription[];
|
|
38
|
+
siteFetch: (input: string, init?: RequestInit) => Promise<Response>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The account page's Subscriptions section (AGL-303, AGL-4191): each
|
|
42
|
+
* subscription's price, the next date that matters, Manage (Stripe's billing
|
|
43
|
+
* page) and its billing history. Its own module so the storefront's first
|
|
44
|
+
* download does not carry it; the account block loads it once a signed-in
|
|
45
|
+
* member has subscriptions to show.
|
|
46
|
+
*/
|
|
47
|
+
export declare function AccountSubscriptions(props: AccountSubscriptionsProps): import("react").JSX.Element;
|
|
48
|
+
export declare namespace AccountSubscriptions {
|
|
49
|
+
var displayName: string;
|
|
50
|
+
}
|
|
51
|
+
export default AccountSubscriptions;
|
|
@@ -0,0 +1,168 @@
|
|
|
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, Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
+
import * as CommerceModel from "../model/index.js";
|
|
19
|
+
import Box from "@mui/material/Box";
|
|
20
|
+
import Button from "@mui/material/Button";
|
|
21
|
+
import Chip from "@mui/material/Chip";
|
|
22
|
+
import Divider from "@mui/material/Divider";
|
|
23
|
+
import MuiLink from "@mui/material/Link";
|
|
24
|
+
import Typography from "@mui/material/Typography";
|
|
25
|
+
import { useState } from "react";
|
|
26
|
+
/**
|
|
27
|
+
* The account page's Subscriptions section (AGL-303, AGL-4191): each
|
|
28
|
+
* subscription's price, the next date that matters, Manage (Stripe's billing
|
|
29
|
+
* page) and its billing history. Its own module so the storefront's first
|
|
30
|
+
* download does not carry it; the account block loads it once a signed-in
|
|
31
|
+
* member has subscriptions to show.
|
|
32
|
+
*/ export function AccountSubscriptions(props) {
|
|
33
|
+
const { hostId, subscriptions, siteFetch } = props;
|
|
34
|
+
/** The subscription whose billing history is open. */ const [openHistory, setOpenHistory] = useState(null);
|
|
35
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ _jsx(Divider, {
|
|
38
|
+
textAlign: "left",
|
|
39
|
+
children: 'Subscriptions'
|
|
40
|
+
}),
|
|
41
|
+
subscriptions.map((subscription)=>{
|
|
42
|
+
var _subscription_invoices, _ref;
|
|
43
|
+
var _invoices_;
|
|
44
|
+
const invoices = (_subscription_invoices = subscription.invoices) != null ? _subscription_invoices : [];
|
|
45
|
+
const currency = (_ref = (_invoices_ = invoices[0]) == null ? void 0 : _invoices_.currency) != null ? _ref : 'USD';
|
|
46
|
+
const dateLine = CommerceModel.subscriptionDateLine(subscription);
|
|
47
|
+
// Says what to do about it: Manage opens Stripe's billing page,
|
|
48
|
+
// where the card is updated (AGL-4191).
|
|
49
|
+
const dateText = (dateLine == null ? void 0 : dateLine.kind) === 'paymentFailed' ? 'Payment failed. Update your card with Manage.' : CommerceModel.subscriptionDateText(dateLine);
|
|
50
|
+
const price = subscription.priceCents != null ? `${CommerceModel.formatOrderMoney(subscription.priceCents, currency)}${CommerceModel.subscriptionIntervalSuffix(subscription.interval)}` : '';
|
|
51
|
+
const historyOpen = openHistory === subscription.id;
|
|
52
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
53
|
+
sx: {
|
|
54
|
+
display: 'flex',
|
|
55
|
+
flexDirection: 'column',
|
|
56
|
+
gap: 0.5
|
|
57
|
+
},
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
60
|
+
sx: {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
gap: 1,
|
|
63
|
+
alignItems: 'center'
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
67
|
+
sx: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
minWidth: 0
|
|
70
|
+
},
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
73
|
+
variant: "body2",
|
|
74
|
+
noWrap: true,
|
|
75
|
+
children: subscription.productName
|
|
76
|
+
}),
|
|
77
|
+
price || dateText ? /*#__PURE__*/ _jsx(Typography, {
|
|
78
|
+
variant: "caption",
|
|
79
|
+
color: "text.secondary",
|
|
80
|
+
children: [
|
|
81
|
+
price,
|
|
82
|
+
dateText
|
|
83
|
+
].filter(Boolean).join(' · ')
|
|
84
|
+
}) : null
|
|
85
|
+
]
|
|
86
|
+
}),
|
|
87
|
+
/*#__PURE__*/ _jsx(Chip, {
|
|
88
|
+
label: CommerceModel.subscriptionStatusLabel(subscription.status),
|
|
89
|
+
size: "small",
|
|
90
|
+
variant: "outlined",
|
|
91
|
+
color: CommerceModel.subscriptionStatusColor(subscription.status)
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
94
|
+
size: "small",
|
|
95
|
+
onClick: async ()=>{
|
|
96
|
+
const response = await siteFetch('/api/commerce/subscription-portal', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-Type': 'application/json'
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
hostId
|
|
103
|
+
})
|
|
104
|
+
}).catch(()=>null);
|
|
105
|
+
const payload = await (response == null ? void 0 : response.json().catch(()=>({})));
|
|
106
|
+
if (payload == null ? void 0 : payload.url) window.location.assign(payload.url);
|
|
107
|
+
},
|
|
108
|
+
children: 'Manage'
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
}),
|
|
112
|
+
invoices.length > 0 ? /*#__PURE__*/ _jsxs(Box, {
|
|
113
|
+
children: [
|
|
114
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
115
|
+
size: "small",
|
|
116
|
+
"aria-expanded": historyOpen,
|
|
117
|
+
onClick: ()=>setOpenHistory(historyOpen ? null : subscription.id),
|
|
118
|
+
sx: {
|
|
119
|
+
px: 0
|
|
120
|
+
},
|
|
121
|
+
children: historyOpen ? 'Hide billing history' : `Billing history (${invoices.length})`
|
|
122
|
+
}),
|
|
123
|
+
historyOpen ? invoices.map((invoice)=>/*#__PURE__*/ _jsxs(Box, {
|
|
124
|
+
sx: {
|
|
125
|
+
display: 'flex',
|
|
126
|
+
gap: 1,
|
|
127
|
+
alignItems: 'center',
|
|
128
|
+
py: 0.25
|
|
129
|
+
},
|
|
130
|
+
children: [
|
|
131
|
+
/*#__PURE__*/ _jsxs(Typography, {
|
|
132
|
+
variant: "caption",
|
|
133
|
+
sx: {
|
|
134
|
+
flex: 1,
|
|
135
|
+
minWidth: 0
|
|
136
|
+
},
|
|
137
|
+
noWrap: true,
|
|
138
|
+
children: [
|
|
139
|
+
CommerceModel.formatSubscriptionDate(invoice.paidAtMs),
|
|
140
|
+
invoice.number ? ` · ${invoice.number}` : ''
|
|
141
|
+
]
|
|
142
|
+
}),
|
|
143
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
144
|
+
variant: "caption",
|
|
145
|
+
children: CommerceModel.formatOrderMoney(invoice.paidCents, invoice.currency)
|
|
146
|
+
}),
|
|
147
|
+
invoice.url ? /*#__PURE__*/ _jsx(MuiLink, {
|
|
148
|
+
href: invoice.url,
|
|
149
|
+
target: "_blank",
|
|
150
|
+
rel: "noopener noreferrer",
|
|
151
|
+
variant: "caption",
|
|
152
|
+
underline: "hover",
|
|
153
|
+
children: 'Invoice'
|
|
154
|
+
}) : null
|
|
155
|
+
]
|
|
156
|
+
}, invoice.id)) : null
|
|
157
|
+
]
|
|
158
|
+
}) : null
|
|
159
|
+
]
|
|
160
|
+
}, subscription.id);
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
AccountSubscriptions.displayName = 'AccountSubscriptions';
|
|
166
|
+
export default AccountSubscriptions;
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=account-subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/account-subscriptions.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 Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Chip from '@mui/material/Chip'\nimport Divider from '@mui/material/Divider'\nimport MuiLink from '@mui/material/Link'\nimport Typography from '@mui/material/Typography'\nimport { useState } from 'react'\n\nexport interface AccountSubscription {\n id: string\n productName: string\n status: string\n currentPeriodEndMs?: number | null\n paidThroughMs?: number\n cancelAtPeriodEnd?: boolean\n priceCents?: number\n interval?: string\n invoices?: Array<{\n id: string\n paidAtMs: number\n paidCents: number\n currency: string\n number?: string\n url?: string\n }>\n}\n\nexport interface AccountSubscriptionsProps {\n hostId: string\n subscriptions: AccountSubscription[]\n siteFetch: (input: string, init?: RequestInit) => Promise<Response>\n}\n\n/**\n * The account page's Subscriptions section (AGL-303, AGL-4191): each\n * subscription's price, the next date that matters, Manage (Stripe's billing\n * page) and its billing history. Its own module so the storefront's first\n * download does not carry it; the account block loads it once a signed-in\n * member has subscriptions to show.\n */\nexport function AccountSubscriptions(props: AccountSubscriptionsProps) {\n const { hostId, subscriptions, siteFetch } = props\n /** The subscription whose billing history is open. */\n const [openHistory, setOpenHistory] = useState<string | null>(null)\n return (\n <>\n <Divider textAlign=\"left\">{'Subscriptions'}</Divider>\n {subscriptions.map((subscription) => {\n const invoices = subscription.invoices ?? []\n const currency = invoices[0]?.currency ?? 'USD'\n const dateLine = CommerceModel.subscriptionDateLine(subscription)\n // Says what to do about it: Manage opens Stripe's billing page,\n // where the card is updated (AGL-4191).\n const dateText =\n dateLine?.kind === 'paymentFailed'\n ? 'Payment failed. Update your card with Manage.'\n : CommerceModel.subscriptionDateText(dateLine)\n const price =\n subscription.priceCents != null\n ? `${CommerceModel.formatOrderMoney(subscription.priceCents, currency)}${CommerceModel.subscriptionIntervalSuffix(subscription.interval)}`\n : ''\n const historyOpen = openHistory === subscription.id\n return (\n <Box key={subscription.id} sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>\n <Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {subscription.productName}\n </Typography>\n {price || dateText ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[price, dateText].filter(Boolean).join(' · ')}\n </Typography>\n ) : null}\n </Box>\n <Chip\n label={CommerceModel.subscriptionStatusLabel(subscription.status)}\n size=\"small\"\n variant=\"outlined\"\n color={CommerceModel.subscriptionStatusColor(subscription.status)}\n />\n <Button\n size=\"small\"\n onClick={async () => {\n const response = await siteFetch(\n '/api/commerce/subscription-portal',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId }),\n },\n ).catch(() => null)\n const payload = await response?.json().catch(() => ({}))\n if (payload?.url) window.location.assign(payload.url)\n }}\n >\n {'Manage'}\n </Button>\n </Box>\n {invoices.length > 0 ? (\n <Box>\n <Button\n size=\"small\"\n aria-expanded={historyOpen}\n onClick={() => setOpenHistory(historyOpen ? null : subscription.id)}\n sx={{ px: 0 }}\n >\n {historyOpen ? 'Hide billing history' : `Billing history (${invoices.length})`}\n </Button>\n {historyOpen\n ? invoices.map((invoice) => (\n <Box\n key={invoice.id}\n sx={{ display: 'flex', gap: 1, alignItems: 'center', py: 0.25 }}\n >\n <Typography variant=\"caption\" sx={{ flex: 1, minWidth: 0 }} noWrap>\n {CommerceModel.formatSubscriptionDate(invoice.paidAtMs)}\n {invoice.number ? ` · ${invoice.number}` : ''}\n </Typography>\n <Typography variant=\"caption\">\n {CommerceModel.formatOrderMoney(invoice.paidCents, invoice.currency)}\n </Typography>\n {invoice.url ? (\n <MuiLink\n href={invoice.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n variant=\"caption\"\n underline=\"hover\"\n >\n {'Invoice'}\n </MuiLink>\n ) : null}\n </Box>\n ))\n : null}\n </Box>\n ) : null}\n </Box>\n )\n })}\n </>\n )\n}\nAccountSubscriptions.displayName = 'AccountSubscriptions'\n\nexport default AccountSubscriptions\n"],"names":["CommerceModel","Box","Button","Chip","Divider","MuiLink","Typography","useState","AccountSubscriptions","props","hostId","subscriptions","siteFetch","openHistory","setOpenHistory","textAlign","map","subscription","invoices","currency","dateLine","subscriptionDateLine","dateText","kind","subscriptionDateText","price","priceCents","formatOrderMoney","subscriptionIntervalSuffix","interval","historyOpen","id","sx","display","flexDirection","gap","alignItems","flex","minWidth","variant","noWrap","productName","color","filter","Boolean","join","label","subscriptionStatusLabel","status","size","subscriptionStatusColor","onClick","response","method","headers","body","JSON","stringify","catch","payload","json","url","window","location","assign","length","aria-expanded","px","invoice","py","formatSubscriptionDate","paidAtMs","number","paidCents","href","target","rel","underline","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,YAAYA,mBAAmB,oBAAU;AACzC,OAAOC,SAAS,oBAAmB;A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oDAAGC,UAAU;gDAAE;gDAAGE,MAAM;;oDAC/DxC,cAAcsE,sBAAsB,CAACF,QAAQG,QAAQ;oDACrDH,QAAQI,MAAM,GAAG,CAAC,GAAG,EAAEJ,QAAQI,MAAM,EAAE,GAAG;;;0DAE7C,KAAClE;gDAAWiC,SAAQ;0DACjBvC,cAAc2B,gBAAgB,CAACyC,QAAQK,SAAS,EAAEL,QAAQjD,QAAQ;;4CAEpEiD,QAAQP,GAAG,iBACV,KAACxD;gDACCqE,MAAMN,QAAQP,GAAG;gDACjBc,QAAO;gDACPC,KAAI;gDACJrC,SAAQ;gDACRsC,WAAU;0DAET;iDAED;;uCApBCT,QAAQrC,EAAE,KAuBnB;;6BAEJ;;mBA1EId,aAAac,EAAE;YA6E7B;;;AAGJ;AACAvB,qBAAqBsE,WAAW,GAAG;AAEnC,eAAetE,qBAAoB"}
|
|
@@ -32,12 +32,13 @@ import Tab from "@mui/material/Tab";
|
|
|
32
32
|
import Tabs from "@mui/material/Tabs";
|
|
33
33
|
import TextField from "@mui/material/TextField";
|
|
34
34
|
import Typography from "@mui/material/Typography";
|
|
35
|
-
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
35
|
+
import { forwardRef, lazy, Suspense, useCallback, useEffect, useState } from "react";
|
|
36
36
|
import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
37
37
|
import { returnRequestHref } from "../constants/return-request.js";
|
|
38
38
|
import { generatePresetId } from "../utils/generate-preset-id.js";
|
|
39
39
|
// Component ids are persisted in screen documents; never rename.
|
|
40
40
|
export const ID = 'customer-account';
|
|
41
|
+
const AccountSubscriptions = /*#__PURE__*/ lazy(()=>import("./account-subscriptions.js"));
|
|
41
42
|
const usd = (cents)=>`$${(cents / 100).toFixed(2)}`;
|
|
42
43
|
/**
|
|
43
44
|
* Customer account block (AGL-294): signed-out visitors get sign-in /
|
|
@@ -408,53 +409,16 @@ const usd = (cents)=>`$${(cents / 100).toFixed(2)}`;
|
|
|
408
409
|
]
|
|
409
410
|
}, order.id);
|
|
410
411
|
}),
|
|
411
|
-
((_ref = (_account_subscriptions = account.subscriptions) == null ? void 0 : _account_subscriptions.length) != null ? _ref : 0) > 0 ?
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
alignItems: 'center'
|
|
422
|
-
},
|
|
423
|
-
children: [
|
|
424
|
-
/*#__PURE__*/ _jsx(Typography, {
|
|
425
|
-
variant: "body2",
|
|
426
|
-
sx: {
|
|
427
|
-
flex: 1
|
|
428
|
-
},
|
|
429
|
-
noWrap: true,
|
|
430
|
-
children: subscription.productName
|
|
431
|
-
}),
|
|
432
|
-
/*#__PURE__*/ _jsx(Chip, {
|
|
433
|
-
label: subscription.status,
|
|
434
|
-
size: "small",
|
|
435
|
-
variant: "outlined",
|
|
436
|
-
color: subscription.status === 'active' ? 'success' : 'default'
|
|
437
|
-
}),
|
|
438
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
439
|
-
size: "small",
|
|
440
|
-
onClick: async ()=>{
|
|
441
|
-
const response = await siteFetch('/api/commerce/subscription-portal', {
|
|
442
|
-
method: 'POST',
|
|
443
|
-
headers: {
|
|
444
|
-
'Content-Type': 'application/json'
|
|
445
|
-
},
|
|
446
|
-
body: JSON.stringify({
|
|
447
|
-
hostId
|
|
448
|
-
})
|
|
449
|
-
}).catch(()=>null);
|
|
450
|
-
const payload = await (response == null ? void 0 : response.json().catch(()=>({})));
|
|
451
|
-
if (payload == null ? void 0 : payload.url) window.location.assign(payload.url);
|
|
452
|
-
},
|
|
453
|
-
children: 'Manage'
|
|
454
|
-
})
|
|
455
|
-
]
|
|
456
|
-
}, subscription.id))
|
|
457
|
-
]
|
|
412
|
+
((_ref = (_account_subscriptions = account.subscriptions) == null ? void 0 : _account_subscriptions.length) != null ? _ref : 0) > 0 ? // Loaded on demand (AGL-4191): it only ever appears after the
|
|
413
|
+
// signed-in account has loaded in the browser, so it need not be in
|
|
414
|
+
// the storefront's first download.
|
|
415
|
+
/*#__PURE__*/ _jsx(Suspense, {
|
|
416
|
+
fallback: null,
|
|
417
|
+
children: /*#__PURE__*/ _jsx(AccountSubscriptions, {
|
|
418
|
+
hostId: hostId,
|
|
419
|
+
subscriptions: account.subscriptions,
|
|
420
|
+
siteFetch: siteFetch
|
|
421
|
+
})
|
|
458
422
|
}) : null,
|
|
459
423
|
((_ref1 = (_account_downloads = account.downloads) == null ? void 0 : _account_downloads.length) != null ? _ref1 : 0) > 0 ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
460
424
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/account.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { trackEvent } from '@aglyn/aglyn/app-utils/analytics-events'\nimport * as CommerceModel from '../model'\nimport { mdiAccountCircleOutline } from '@aglyn/shared-data-mdi'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Checkbox from '@mui/material/Checkbox'\nimport Chip from '@mui/material/Chip'\nimport Divider from '@mui/material/Divider'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport MuiLink from '@mui/material/Link'\nimport Tab from '@mui/material/Tab'\nimport Tabs from '@mui/material/Tabs'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, useCallback, useEffect, useState } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { returnRequestHref } from '../constants/return-request'\nimport { generatePresetId } from '../utils/generate-preset-id'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'customer-account'\n\nexport interface CustomerAccountProps {\n signedOutHeading?: string\n}\n\ninterface AccountData {\n member: {\n email: string\n displayName: string\n addresses: CommerceModel.OrderAddress[]\n }\n downloads?: Array<{\n orderId: string\n productId: string\n productName: string\n url: string\n licenseKeys?: string[]\n }>\n subscriptions?: Array<{\n id: string\n productName: string\n status: string\n currentPeriodEndMs?: number | null\n }>\n orders: Array<{\n id: string\n number: string\n status: string\n totalCents: number\n createdAtMs: number\n itemsSummary: string\n tracking?: { carrier?: string; trackingNumber?: string }\n }>\n}\n\nconst usd = (cents: number) => `$${(cents / 100).toFixed(2)}`\n\n/**\n * Customer account block (AGL-294): signed-out visitors get sign-in /\n * create-account forms on the AGL-109 membership APIs; signed-in\n * members see their profile, address book, and order history (status +\n * tracking) with sign-out. Session lives in the httpOnly member cookie.\n */\nconst CustomerAccount = forwardRef<HTMLDivElement, CustomerAccountProps>(\n (props, ref) => {\n const { signedOutHeading, ...rest } = props\n // Node styles ride the renderer-merged sx; recompose (stack.ts pattern).\n const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [props['sx']]\n const { hostId } = Aglyn.useSite()\n const siteFetch = Aglyn.useSiteFetch()\n const [account, setAccount] = useState<AccountData | null | 'anonymous'>(\n null,\n )\n const [tab, setTab] = useState(0)\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [displayName, setDisplayName] = useState('')\n const [marketingConsent, setMarketingConsent] = useState(false)\n const [error, setError] = useState('')\n const [busy, setBusy] = useState(false)\n const [addressDraft, setAddressDraft] = useState<CommerceModel.OrderAddress | null>(\n null,\n )\n\n const refresh = useCallback(async () => {\n if (!hostId) return\n try {\n const response = await fetch(\n `/api/membership/account?hostId=${encodeURIComponent(hostId)}`,\n )\n if (response.status === 401) return setAccount('anonymous')\n if (response.ok) return setAccount(await response.json())\n setAccount('anonymous')\n } catch {\n setAccount('anonymous')\n }\n }, [hostId])\n\n useEffect(() => {\n void refresh()\n }, [refresh])\n\n const handleAuth = useCallback(async () => {\n if (!hostId || busy) return\n setBusy(true)\n setError('')\n try {\n const endpoint =\n tab === 0 ? '/api/membership/login' : '/api/membership/register'\n const response = await siteFetch(endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n email,\n password,\n ...(tab === 1 && displayName ? { displayName } : {}),\n ...(tab === 1 && marketingConsent\n ? { marketingConsent: true }\n : {}),\n }),\n })\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n setError(String(payload?.error ?? 'Something went wrong'))\n return\n }\n if (tab === 1) {\n // Register does not set the cookie on every deployment; sign in\n // right after to be safe.\n await siteFetch('/api/membership/login', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, email, password }),\n }).catch(() => undefined)\n }\n /*\n * The host's own GA4 property, not Aglyn's (AGL-1591). Reported after\n * the response was accepted and never on a validation failure, which\n * is what makes the count mean \"an account door was completed\".\n *\n * The follow-up login above is deliberately NOT a second event: it is\n * a cookie repair for the registration that just happened, and\n * reporting it would give every new member both a `sign_up` and a\n * `login` in the same second — turning a returning-visitor metric into\n * a copy of the signup one.\n *\n * Not awaited: this branch re-renders in place rather than navigating,\n * so there is no teardown to lose the hit to.\n */\n trackEvent(tab === 1 ? 'sign_up' : 'login', { method: 'password' })\n await refresh()\n } finally {\n setBusy(false)\n }\n }, [\n hostId,\n busy,\n tab,\n email,\n password,\n displayName,\n marketingConsent,\n refresh,\n siteFetch,\n ])\n\n const handleSignOut = useCallback(async () => {\n if (!hostId) return\n await siteFetch('/api/membership/logout', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId }),\n }).catch(() => undefined)\n setAccount('anonymous')\n }, [hostId, siteFetch])\n\n const handleAddressSave = useCallback(async () => {\n if (!hostId || account === 'anonymous' || !account || !addressDraft) {\n return\n }\n const addresses = [...account.member.addresses, addressDraft].slice(-5)\n await siteFetch('/api/membership/account', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, addresses }),\n }).catch(() => undefined)\n setAddressDraft(null)\n await refresh()\n }, [hostId, account, addressDraft, refresh, siteFetch])\n\n if (!hostId) {\n return (\n <Box\n ref={ref}\n {...rest}\n sx={[\n {\n p: 3,\n border: '1px dashed',\n borderColor: 'divider',\n borderRadius: 1,\n color: 'text.secondary',\n fontSize: 13,\n fontFamily: 'system-ui, sans-serif',\n },\n ...nodeSx,\n ]}\n >\n {'Customer account — sign-in and order history render here'}\n </Box>\n )\n }\n if (account === null) return <Box ref={ref} {...rest} />\n\n if (account === 'anonymous') {\n return (\n <Box ref={ref} {...rest} sx={[{ maxWidth: 420 }, ...nodeSx]}>\n {signedOutHeading ? (\n <Typography variant=\"h5\" gutterBottom>\n {signedOutHeading}\n </Typography>\n ) : null}\n <Tabs value={tab} onChange={(_event, value) => setTab(value)}>\n <Tab label=\"Sign in\" />\n <Tab label=\"Create account\" />\n </Tabs>\n <Box\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, mt: 2 }}\n >\n {tab === 1 ? (\n <TextField\n label=\"Name\"\n value={displayName}\n onChange={(event) => setDisplayName(event.target.value)}\n size=\"small\"\n />\n ) : null}\n <TextField\n label=\"Email\"\n type=\"email\"\n value={email}\n onChange={(event) => setEmail(event.target.value)}\n size=\"small\"\n />\n <TextField\n label=\"Password\"\n type=\"password\"\n value={password}\n onChange={(event) => setPassword(event.target.value)}\n size=\"small\"\n helperText={tab === 1 ? 'At least 8 characters' : undefined}\n />\n {tab === 1 ? (\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={marketingConsent}\n onChange={(event) =>\n setMarketingConsent(event.target.checked)\n }\n />\n }\n label=\"Email me about offers and updates\"\n />\n ) : null}\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={busy || !email || !password}\n onClick={handleAuth}\n >\n {busy ? 'Working…' : tab === 0 ? 'Sign in' : 'Create account'}\n </Button>\n {tab === 0 ? (\n // Recovery flow (AGL-552): the built-in /recover route (or\n // the host's designated recovery screen) handles the rest.\n <Typography variant=\"body2\">\n <MuiLink href=\"/recover\" underline=\"hover\">\n {'Forgot password?'}\n </MuiLink>\n </Typography>\n ) : null}\n </Box>\n </Box>\n )\n }\n\n return (\n <Box ref={ref} {...rest} sx={[{ display: 'flex', flexDirection: 'column', gap: 2 }, ...nodeSx]}>\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>\n <Typography variant=\"h5\" sx={{ flex: 1 }}>\n {account.member.displayName || account.member.email}\n </Typography>\n <Button size=\"small\" onClick={handleSignOut}>\n {'Sign out'}\n </Button>\n </Box>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {account.member.email}\n </Typography>\n\n <Divider textAlign=\"left\">{'Orders'}</Divider>\n {account.orders.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No orders yet.'}\n </Typography>\n ) : (\n account.orders.map((order) => (\n <Box key={order.id} sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`${order.number} · ${order.itemsSummary || 'Order'}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {new Date(order.createdAtMs).toLocaleDateString()}\n {order.tracking?.trackingNumber\n ? ` · ${order.tracking.carrier ?? ''} ${order.tracking.trackingNumber}`\n : ''}\n </Typography>\n </Box>\n <Chip\n label={order.status.replace('_', ' ')}\n size=\"small\"\n variant=\"outlined\"\n />\n <Typography variant=\"body2\">{usd(order.totalCents)}</Typography>\n {CommerceModel.RETURNABLE_ORDER_STATUSES.includes(order.status) ? (\n // The member's session authorizes the return page, so the\n // link carries no token (AGL-3611).\n <Button size=\"small\" href={returnRequestHref(order.id)}>\n {'Request a return'}\n </Button>\n ) : null}\n </Box>\n ))\n )}\n\n {(account.subscriptions?.length ?? 0) > 0 ? (\n <>\n <Divider textAlign=\"left\">{'Subscriptions'}</Divider>\n {account.subscriptions!.map((subscription) => (\n <Box\n key={subscription.id}\n sx={{ display: 'flex', gap: 1, alignItems: 'center' }}\n >\n <Typography variant=\"body2\" sx={{ flex: 1 }} noWrap>\n {subscription.productName}\n </Typography>\n <Chip\n label={subscription.status}\n size=\"small\"\n variant=\"outlined\"\n color={\n subscription.status === 'active' ? 'success' : 'default'\n }\n />\n <Button\n size=\"small\"\n onClick={async () => {\n const response = await siteFetch(\n '/api/commerce/subscription-portal',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId }),\n },\n ).catch(() => null)\n const payload = await response?.json().catch(() => ({}))\n if (payload?.url) window.location.assign(payload.url)\n }}\n >\n {'Manage'}\n </Button>\n </Box>\n ))}\n </>\n ) : null}\n {(account.downloads?.length ?? 0) > 0 ? (\n <>\n <Divider textAlign=\"left\">{'Downloads'}</Divider>\n {account.downloads!.map((download) => (\n <Box\n key={`${download.orderId}:${download.productId}`}\n sx={{ display: 'flex', gap: 1, alignItems: 'center' }}\n >\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {download.productName}\n </Typography>\n {download.licenseKeys?.map((key) => (\n <Typography\n key={key}\n variant=\"caption\"\n sx={{ fontFamily: 'monospace', display: 'block' }}\n >\n {key}\n </Typography>\n ))}\n </Box>\n <Button size=\"small\" href={download.url}>\n {'Download'}\n </Button>\n </Box>\n ))}\n </>\n ) : null}\n\n <Divider textAlign=\"left\">{'Addresses'}</Divider>\n {account.member.addresses.map((address, index) => (\n <Typography key={index} variant=\"body2\" color=\"text.secondary\">\n {[\n address.name,\n address.line1,\n address.line2,\n `${address.city ?? ''} ${address.state ?? ''} ${address.postalCode ?? ''}`.trim(),\n address.country,\n ]\n .filter(Boolean)\n .join(', ')}\n </Typography>\n ))}\n {addressDraft ? (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n {(\n [\n ['name', 'Full name'],\n ['line1', 'Address'],\n ['line2', 'Apt / suite'],\n ['city', 'City'],\n ['state', 'State'],\n ['postalCode', 'Postal code'],\n ['country', 'Country (US)'],\n ] as const\n ).map(([field, label]) => (\n <TextField\n key={field}\n label={label}\n value={(addressDraft as any)[field] ?? ''}\n onChange={(event) =>\n setAddressDraft((prev) =>\n prev ? { ...prev, [field]: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n ))}\n <Box sx={{ display: 'flex', gap: 1 }}>\n <Button size=\"small\" onClick={() => setAddressDraft(null)}>\n {'Cancel'}\n </Button>\n <Button\n size=\"small\"\n variant=\"contained\"\n color=\"primary\"\n disabled={!addressDraft.line1 || !addressDraft.city}\n onClick={handleAddressSave}\n >\n {'Save address'}\n </Button>\n </Box>\n </Box>\n ) : (\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => setAddressDraft({})}\n >\n {'Add address'}\n </Button>\n )}\n </Box>\n )\n },\n)\nCustomerAccount.displayName = 'AglynCustomerAccount'\n\nexport const schema: Aglyn.ComponentSchema<CustomerAccountProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Customer account',\n description:\n 'Sign-in and account area — profile, addresses and order history.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiAccountCircleOutline.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'signedOutHeading',\n label: 'Signed-out heading',\n description: 'Shown above the sign-in form.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Customer account',\n pluginId: BUNDLE_ID,\n description: 'Sign-in/up, profile, addresses, and order history',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiAccountCircleOutline.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: { signedOutHeading: 'Your account' },\n },\n },\n]\n\nexport default CustomerAccount\n"],"names":["Aglyn","trackEvent","CommerceModel","mdiAccountCircleOutline","Alert","Box","Button","Checkbox","Chip","Divider","FormControlLabel","MuiLink","Tab","Tabs","TextField","Typography","forwardRef","useCallback","useEffect","useState","BUNDLE_ID","returnRequestHref","generatePresetId","ID","usd","cents","toFixed","CustomerAccount","props","ref","account","signedOutHeading","rest","nodeSx","Array","isArray","hostId","useSite","siteFetch","useSiteFetch","setAccount","tab","setTab","email","setEmail","password","setPassword","displayName","setDisplayName","marketingConsent","setMarketingConsent","error","setError","busy","setBusy","addressDraft","setAddressDraft","refresh","response","fetch","encodeURIComponent","status","ok","json","handleAuth","endpoint","method","headers","body","JSON","stringify","payload","catch","String","undefined","handleSignOut","handleAddressSave","addresses","member","slice","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","maxWidth","variant","gutterBottom","value","onChange","_event","label","display","flexDirection","gap","mt","event","target","size","type","helperText","control","checked","severity","disabled","onClick","href","underline","alignItems","flex","textAlign","orders","length","map","order","minWidth","noWrap","number","itemsSummary","Date","createdAtMs","toLocaleDateString","tracking","trackingNumber","carrier","replace","totalCents","RETURNABLE_ORDER_STATUSES","includes","id","subscriptions","subscription","productName","url","window","location","assign","downloads","download","licenseKeys","key","orderId","productId","address","index","name","line1","line2","city","state","postalCode","trim","country","filter","Boolean","join","field","prev","alignSelf","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","component","FieldComponentType","TEXT_FIELD","presets","NodeType","PRESET","data","componentId"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,UAAU,QAAQ,0C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O;gBAAEG,kBAAkB;YAAe;QAC5C;IACF;CACD,CAAA;AAED,eAAeJ,gBAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/account.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { trackEvent } from '@aglyn/aglyn/app-utils/analytics-events'\nimport * as CommerceModel from '../model'\nimport { mdiAccountCircleOutline } from '@aglyn/shared-data-mdi'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Checkbox from '@mui/material/Checkbox'\nimport Chip from '@mui/material/Chip'\nimport Divider from '@mui/material/Divider'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport MuiLink from '@mui/material/Link'\nimport Tab from '@mui/material/Tab'\nimport Tabs from '@mui/material/Tabs'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, lazy, Suspense, useCallback, useEffect, useState } from 'react'\nimport type { AccountSubscription } from './account-subscriptions'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { returnRequestHref } from '../constants/return-request'\nimport { generatePresetId } from '../utils/generate-preset-id'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'customer-account'\n\nexport interface CustomerAccountProps {\n signedOutHeading?: string\n}\n\ninterface AccountData {\n member: {\n email: string\n displayName: string\n addresses: CommerceModel.OrderAddress[]\n }\n downloads?: Array<{\n orderId: string\n productId: string\n productName: string\n url: string\n licenseKeys?: string[]\n }>\n subscriptions?: AccountSubscription[]\n orders: Array<{\n id: string\n number: string\n status: string\n totalCents: number\n createdAtMs: number\n itemsSummary: string\n tracking?: { carrier?: string; trackingNumber?: string }\n }>\n}\n\nconst AccountSubscriptions = lazy(() => import('./account-subscriptions'))\n\nconst usd = (cents: number) => `$${(cents / 100).toFixed(2)}`\n\n/**\n * Customer account block (AGL-294): signed-out visitors get sign-in /\n * create-account forms on the AGL-109 membership APIs; signed-in\n * members see their profile, address book, and order history (status +\n * tracking) with sign-out. Session lives in the httpOnly member cookie.\n */\nconst CustomerAccount = forwardRef<HTMLDivElement, CustomerAccountProps>(\n (props, ref) => {\n const { signedOutHeading, ...rest } = props\n // Node styles ride the renderer-merged sx; recompose (stack.ts pattern).\n const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [props['sx']]\n const { hostId } = Aglyn.useSite()\n const siteFetch = Aglyn.useSiteFetch()\n const [account, setAccount] = useState<AccountData | null | 'anonymous'>(\n null,\n )\n const [tab, setTab] = useState(0)\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [displayName, setDisplayName] = useState('')\n const [marketingConsent, setMarketingConsent] = useState(false)\n const [error, setError] = useState('')\n const [busy, setBusy] = useState(false)\n const [addressDraft, setAddressDraft] = useState<CommerceModel.OrderAddress | null>(\n null,\n )\n\n const refresh = useCallback(async () => {\n if (!hostId) return\n try {\n const response = await fetch(\n `/api/membership/account?hostId=${encodeURIComponent(hostId)}`,\n )\n if (response.status === 401) return setAccount('anonymous')\n if (response.ok) return setAccount(await response.json())\n setAccount('anonymous')\n } catch {\n setAccount('anonymous')\n }\n }, [hostId])\n\n useEffect(() => {\n void refresh()\n }, [refresh])\n\n const handleAuth = useCallback(async () => {\n if (!hostId || busy) return\n setBusy(true)\n setError('')\n try {\n const endpoint =\n tab === 0 ? '/api/membership/login' : '/api/membership/register'\n const response = await siteFetch(endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n email,\n password,\n ...(tab === 1 && displayName ? { displayName } : {}),\n ...(tab === 1 && marketingConsent\n ? { marketingConsent: true }\n : {}),\n }),\n })\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n setError(String(payload?.error ?? 'Something went wrong'))\n return\n }\n if (tab === 1) {\n // Register does not set the cookie on every deployment; sign in\n // right after to be safe.\n await siteFetch('/api/membership/login', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, email, password }),\n }).catch(() => undefined)\n }\n /*\n * The host's own GA4 property, not Aglyn's (AGL-1591). Reported after\n * the response was accepted and never on a validation failure, which\n * is what makes the count mean \"an account door was completed\".\n *\n * The follow-up login above is deliberately NOT a second event: it is\n * a cookie repair for the registration that just happened, and\n * reporting it would give every new member both a `sign_up` and a\n * `login` in the same second — turning a returning-visitor metric into\n * a copy of the signup one.\n *\n * Not awaited: this branch re-renders in place rather than navigating,\n * so there is no teardown to lose the hit to.\n */\n trackEvent(tab === 1 ? 'sign_up' : 'login', { method: 'password' })\n await refresh()\n } finally {\n setBusy(false)\n }\n }, [\n hostId,\n busy,\n tab,\n email,\n password,\n displayName,\n marketingConsent,\n refresh,\n siteFetch,\n ])\n\n const handleSignOut = useCallback(async () => {\n if (!hostId) return\n await siteFetch('/api/membership/logout', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId }),\n }).catch(() => undefined)\n setAccount('anonymous')\n }, [hostId, siteFetch])\n\n const handleAddressSave = useCallback(async () => {\n if (!hostId || account === 'anonymous' || !account || !addressDraft) {\n return\n }\n const addresses = [...account.member.addresses, addressDraft].slice(-5)\n await siteFetch('/api/membership/account', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, addresses }),\n }).catch(() => undefined)\n setAddressDraft(null)\n await refresh()\n }, [hostId, account, addressDraft, refresh, siteFetch])\n\n if (!hostId) {\n return (\n <Box\n ref={ref}\n {...rest}\n sx={[\n {\n p: 3,\n border: '1px dashed',\n borderColor: 'divider',\n borderRadius: 1,\n color: 'text.secondary',\n fontSize: 13,\n fontFamily: 'system-ui, sans-serif',\n },\n ...nodeSx,\n ]}\n >\n {'Customer account — sign-in and order history render here'}\n </Box>\n )\n }\n if (account === null) return <Box ref={ref} {...rest} />\n\n if (account === 'anonymous') {\n return (\n <Box ref={ref} {...rest} sx={[{ maxWidth: 420 }, ...nodeSx]}>\n {signedOutHeading ? (\n <Typography variant=\"h5\" gutterBottom>\n {signedOutHeading}\n </Typography>\n ) : null}\n <Tabs value={tab} onChange={(_event, value) => setTab(value)}>\n <Tab label=\"Sign in\" />\n <Tab label=\"Create account\" />\n </Tabs>\n <Box\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, mt: 2 }}\n >\n {tab === 1 ? (\n <TextField\n label=\"Name\"\n value={displayName}\n onChange={(event) => setDisplayName(event.target.value)}\n size=\"small\"\n />\n ) : null}\n <TextField\n label=\"Email\"\n type=\"email\"\n value={email}\n onChange={(event) => setEmail(event.target.value)}\n size=\"small\"\n />\n <TextField\n label=\"Password\"\n type=\"password\"\n value={password}\n onChange={(event) => setPassword(event.target.value)}\n size=\"small\"\n helperText={tab === 1 ? 'At least 8 characters' : undefined}\n />\n {tab === 1 ? (\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={marketingConsent}\n onChange={(event) =>\n setMarketingConsent(event.target.checked)\n }\n />\n }\n label=\"Email me about offers and updates\"\n />\n ) : null}\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={busy || !email || !password}\n onClick={handleAuth}\n >\n {busy ? 'Working…' : tab === 0 ? 'Sign in' : 'Create account'}\n </Button>\n {tab === 0 ? (\n // Recovery flow (AGL-552): the built-in /recover route (or\n // the host's designated recovery screen) handles the rest.\n <Typography variant=\"body2\">\n <MuiLink href=\"/recover\" underline=\"hover\">\n {'Forgot password?'}\n </MuiLink>\n </Typography>\n ) : null}\n </Box>\n </Box>\n )\n }\n\n return (\n <Box ref={ref} {...rest} sx={[{ display: 'flex', flexDirection: 'column', gap: 2 }, ...nodeSx]}>\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>\n <Typography variant=\"h5\" sx={{ flex: 1 }}>\n {account.member.displayName || account.member.email}\n </Typography>\n <Button size=\"small\" onClick={handleSignOut}>\n {'Sign out'}\n </Button>\n </Box>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {account.member.email}\n </Typography>\n\n <Divider textAlign=\"left\">{'Orders'}</Divider>\n {account.orders.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No orders yet.'}\n </Typography>\n ) : (\n account.orders.map((order) => (\n <Box key={order.id} sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`${order.number} · ${order.itemsSummary || 'Order'}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {new Date(order.createdAtMs).toLocaleDateString()}\n {order.tracking?.trackingNumber\n ? ` · ${order.tracking.carrier ?? ''} ${order.tracking.trackingNumber}`\n : ''}\n </Typography>\n </Box>\n <Chip\n label={order.status.replace('_', ' ')}\n size=\"small\"\n variant=\"outlined\"\n />\n <Typography variant=\"body2\">{usd(order.totalCents)}</Typography>\n {CommerceModel.RETURNABLE_ORDER_STATUSES.includes(order.status) ? (\n // The member's session authorizes the return page, so the\n // link carries no token (AGL-3611).\n <Button size=\"small\" href={returnRequestHref(order.id)}>\n {'Request a return'}\n </Button>\n ) : null}\n </Box>\n ))\n )}\n\n {(account.subscriptions?.length ?? 0) > 0 ? (\n // Loaded on demand (AGL-4191): it only ever appears after the\n // signed-in account has loaded in the browser, so it need not be in\n // the storefront's first download.\n <Suspense fallback={null}>\n <AccountSubscriptions\n hostId={hostId}\n subscriptions={account.subscriptions!}\n siteFetch={siteFetch}\n />\n </Suspense>\n ) : null}\n {(account.downloads?.length ?? 0) > 0 ? (\n <>\n <Divider textAlign=\"left\">{'Downloads'}</Divider>\n {account.downloads!.map((download) => (\n <Box\n key={`${download.orderId}:${download.productId}`}\n sx={{ display: 'flex', gap: 1, alignItems: 'center' }}\n >\n <Box sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {download.productName}\n </Typography>\n {download.licenseKeys?.map((key) => (\n <Typography\n key={key}\n variant=\"caption\"\n sx={{ fontFamily: 'monospace', display: 'block' }}\n >\n {key}\n </Typography>\n ))}\n </Box>\n <Button size=\"small\" href={download.url}>\n {'Download'}\n </Button>\n </Box>\n ))}\n </>\n ) : null}\n\n <Divider textAlign=\"left\">{'Addresses'}</Divider>\n {account.member.addresses.map((address, index) => (\n <Typography key={index} variant=\"body2\" color=\"text.secondary\">\n {[\n address.name,\n address.line1,\n address.line2,\n `${address.city ?? ''} ${address.state ?? ''} ${address.postalCode ?? ''}`.trim(),\n address.country,\n ]\n .filter(Boolean)\n .join(', ')}\n </Typography>\n ))}\n {addressDraft ? (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n {(\n [\n ['name', 'Full name'],\n ['line1', 'Address'],\n ['line2', 'Apt / suite'],\n ['city', 'City'],\n ['state', 'State'],\n ['postalCode', 'Postal code'],\n ['country', 'Country (US)'],\n ] as const\n ).map(([field, label]) => (\n <TextField\n key={field}\n label={label}\n value={(addressDraft as any)[field] ?? ''}\n onChange={(event) =>\n setAddressDraft((prev) =>\n prev ? { ...prev, [field]: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n ))}\n <Box sx={{ display: 'flex', gap: 1 }}>\n <Button size=\"small\" onClick={() => setAddressDraft(null)}>\n {'Cancel'}\n </Button>\n <Button\n size=\"small\"\n variant=\"contained\"\n color=\"primary\"\n disabled={!addressDraft.line1 || !addressDraft.city}\n onClick={handleAddressSave}\n >\n {'Save address'}\n </Button>\n </Box>\n </Box>\n ) : (\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => setAddressDraft({})}\n >\n {'Add address'}\n </Button>\n )}\n </Box>\n )\n },\n)\nCustomerAccount.displayName = 'AglynCustomerAccount'\n\nexport const schema: Aglyn.ComponentSchema<CustomerAccountProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Customer account',\n description:\n 'Sign-in and account area — profile, addresses and order history.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiAccountCircleOutline.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'signedOutHeading',\n label: 'Signed-out heading',\n description: 'Shown above the sign-in form.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Customer account',\n pluginId: BUNDLE_ID,\n description: 'Sign-in/up, profile, addresses, and order history',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiAccountCircleOutline.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: { signedOutHeading: 'Your account' },\n },\n },\n]\n\nexport default CustomerAccount\n"],"names":["Aglyn","trackEvent","CommerceModel","mdiAccountCircleOutline","Alert","Box","Button","Checkbox","Chip","Divider","FormControlLabel","MuiLink","Tab","Tabs","TextField","Typography","forwardRef","lazy","Suspense","useCallback","useEffect","useState","BUNDLE_ID","returnRequestHref","generatePresetId","ID","AccountSubscriptions","usd","cents","toFixed","CustomerAccount","props","ref","account","signedOutHeading","rest","nodeSx","Array","isArray","hostId","useSite","siteFetch","useSiteFetch","setAccount","tab","setTab","email","setEmail","password","setPassword","displayName","setDisplayName","marketingConsent","setMarketingConsent","error","setError","busy","setBusy","addressDraft","setAddressDraft","refresh","response","fetch","encodeURIComponent","status","ok","json","handleAuth","endpoint","method","headers","body","JSON","stringify","payload","catch","String","undefined","handleSignOut","handleAddressSave","addresses","member","slice","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","maxWidth","variant","gutterBottom","value","onChange","_event","label","display","flexDirection","gap","mt","event","target","size","type","helperText","control","checked","severity","disabled","onClick","href","underline","alignItems","flex","textAlign","orders","length","map","order","minWidth","noWrap","number","itemsSummary","Date","createdAtMs","toLocaleDateString","tracking","trackingNumber","carrier","replace","totalCents","RETURNABLE_ORDER_STATUSES","includes","id","subscriptions","fallback","downloads","download","productName","licenseKeys","key","url","orderId","productId","address","index","name","line1","line2","city","state","postalCode","trim","country","filter","Boolean","join","field","prev","alignSelf","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","component","FieldComponentType","TEXT_FIELD","presets","NodeType","PRESET","data","componentId"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,UAAU,QAAQ,0CAAyC;AACpE,YAAYC,mBAAmB,oBAAU;AACzC,SAASC,uBAAuB,QAAQ,yBAAwB;AAChE,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,aAAa,wBAAuB;AAC3C,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,aAAa,qBAAoB;AACxC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEpF,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,iBAAiB,QAAQ,iCAA6B;AAC/D,SAASC,gBAAgB,QAAQ,iCAA6B;AAE9D,iEAA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IACF;CACD,CAAA;AAED,eAAeJ,gBAAe"}
|
|
@@ -45,6 +45,7 @@ import { StorefrontPaymentElementFallback } from "./storefront-payment-element-f
|
|
|
45
45
|
import { CheckoutReturnNotice } from "./checkout-return-notice.js";
|
|
46
46
|
import { CartExtras, useCartExtras } from "./cart-extras.js";
|
|
47
47
|
import { CartFulfillmentChoice, useCartFulfillment } from "./cart-fulfillment.js";
|
|
48
|
+
import { HardwareTermsConsent, hardwareTermsAnswered, NO_HARDWARE_TERMS_ANSWER } from "./hardware-terms-consent.js";
|
|
48
49
|
/**
|
|
49
50
|
* The Payment Element (AGL-1944), lazily. Stripe.js and its React wrapper are
|
|
50
51
|
* a large dependency and the flag is OFF, so a static import would ship the
|
|
@@ -111,6 +112,11 @@ function CartLines(props) {
|
|
|
111
112
|
// it latches the buy control off instead of inviting another click.
|
|
112
113
|
const [status, setStatus] = useState('idle');
|
|
113
114
|
const [message, setMessage] = useState('');
|
|
115
|
+
// The terms of sale and business use, for card reader hardware (AGL-4038):
|
|
116
|
+
// asked when the cart says it holds some, or when a checkout was refused
|
|
117
|
+
// for want of them.
|
|
118
|
+
const [hardwareTerms, setHardwareTerms] = useState(NO_HARDWARE_TERMS_ANSWER);
|
|
119
|
+
const [hardwareTermsAsked, setHardwareTermsAsked] = useState(false);
|
|
114
120
|
/**
|
|
115
121
|
* The in-page checkout session (AGL-1944). Null unless the server chose
|
|
116
122
|
* native mode, which needs both the release flag and a publishable key.
|
|
@@ -253,6 +259,8 @@ function CartLines(props) {
|
|
|
253
259
|
shippingPostalCode: shipPostal.trim()
|
|
254
260
|
} : {}, extras.chosenIds.length ? {
|
|
255
261
|
extras: extras.chosenIds
|
|
262
|
+
} : {}, (cart == null ? void 0 : cart.hardwareTerms) || hardwareTermsAsked ? {
|
|
263
|
+
hardwareTerms
|
|
256
264
|
} : {}, fulfillment.request ? {
|
|
257
265
|
fulfillment: fulfillment.request
|
|
258
266
|
} : {}, advertisingConsentField(hostId)))
|
|
@@ -336,12 +344,21 @@ function CartLines(props) {
|
|
|
336
344
|
setStatus('error');
|
|
337
345
|
return;
|
|
338
346
|
}
|
|
347
|
+
// Card reader hardware needs the terms of sale ticked (AGL-4038): show
|
|
348
|
+
// the boxes with the server's sentence.
|
|
349
|
+
if (payload == null ? void 0 : payload.needsHardwareTerms) {
|
|
350
|
+
var _ref5;
|
|
351
|
+
setHardwareTermsAsked(true);
|
|
352
|
+
setMessage(String((_ref5 = payload == null ? void 0 : payload.error) != null ? _ref5 : ''));
|
|
353
|
+
setStatus('ask');
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
339
356
|
// The pickup location or delivery time went away while the cart was
|
|
340
357
|
// open (AGL-3624): ask again and let the shopper choose.
|
|
341
358
|
if (payload == null ? void 0 : payload.fulfillmentChanged) {
|
|
342
|
-
var
|
|
359
|
+
var _ref6;
|
|
343
360
|
fulfillment.reload();
|
|
344
|
-
setMessage(String((
|
|
361
|
+
setMessage(String((_ref6 = payload == null ? void 0 : payload.error) != null ? _ref6 : ''));
|
|
345
362
|
setStatus('error');
|
|
346
363
|
return;
|
|
347
364
|
}
|
|
@@ -354,13 +371,13 @@ function CartLines(props) {
|
|
|
354
371
|
// price this cart until it knows one (AGL-1721). Reveal the field and
|
|
355
372
|
// let the shopper answer; a store that never sends this never shows it.
|
|
356
373
|
if (payload == null ? void 0 : payload.needsShippingCountry) {
|
|
357
|
-
var
|
|
374
|
+
var _ref7;
|
|
358
375
|
var _payload_shippingCountries;
|
|
359
376
|
if (payload == null ? void 0 : payload.needsShippingPostalCode) setAskPostal(true);
|
|
360
377
|
setShipCountries(((_payload_shippingCountries = payload.shippingCountries) == null ? void 0 : _payload_shippingCountries.length) ? payload.shippingCountries : [
|
|
361
378
|
...CommerceModel.CHECKOUT_SHIPPING_COUNTRIES
|
|
362
379
|
]);
|
|
363
|
-
setMessage(String((
|
|
380
|
+
setMessage(String((_ref7 = payload == null ? void 0 : payload.error) != null ? _ref7 : ''));
|
|
364
381
|
// An unserved destination is a real refusal and reads as one; being
|
|
365
382
|
// asked the first time is not.
|
|
366
383
|
setStatus(shipTo ? 'error' : 'ask');
|
|
@@ -393,7 +410,9 @@ function CartLines(props) {
|
|
|
393
410
|
extras.reload,
|
|
394
411
|
extras.credits.length,
|
|
395
412
|
fulfillment.request,
|
|
396
|
-
fulfillment.reload
|
|
413
|
+
fulfillment.reload,
|
|
414
|
+
hardwareTerms,
|
|
415
|
+
hardwareTermsAsked
|
|
397
416
|
]);
|
|
398
417
|
if (!cart || cart.lines.length === 0) {
|
|
399
418
|
return /*#__PURE__*/ _jsx(Typography, {
|
|
@@ -622,6 +641,10 @@ function CartLines(props) {
|
|
|
622
641
|
}
|
|
623
642
|
}
|
|
624
643
|
}) : null,
|
|
644
|
+
cart.hardwareTerms || hardwareTermsAsked ? /*#__PURE__*/ _jsx(HardwareTermsConsent, {
|
|
645
|
+
answer: hardwareTerms,
|
|
646
|
+
onChange: setHardwareTerms
|
|
647
|
+
}) : null,
|
|
625
648
|
status === 'paused' || status === 'ask' || status === 'unconfigured' ? /*#__PURE__*/ _jsx(Alert, {
|
|
626
649
|
severity: "info",
|
|
627
650
|
children: message
|
|
@@ -638,7 +661,8 @@ function CartLines(props) {
|
|
|
638
661
|
// cannot succeed (AGL-2019).
|
|
639
662
|
status === 'unconfigured' || // Asked but unanswered: the server would only refuse again.
|
|
640
663
|
fulfillment.method === 'shipping' && shipCountries !== null && !shipTo || fulfillment.method === 'shipping' && askPostal && !shipPostal.trim() || // Pickup needs a location, delivery a zone and a time (AGL-3624).
|
|
641
|
-
!fulfillment.ready
|
|
664
|
+
!fulfillment.ready || // Card reader hardware: both boxes ticked (AGL-4038).
|
|
665
|
+
(Boolean(cart.hardwareTerms) || hardwareTermsAsked) && !hardwareTermsAnswered(hardwareTerms),
|
|
642
666
|
onClick: handleCheckout,
|
|
643
667
|
children: status === 'sending' ? // place (AGL-1944).
|
|
644
668
|
nativeCheckout ? 'Opening…' : 'Redirecting…' : checkoutLabel || 'Checkout'
|