@aglyn/plugins-commerce 1.11.0 → 1.13.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/console/catalog-organization-card.component.js +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/host-quotes-card.component.js +23 -13
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.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-kiosk/kiosk-menu.d.ts +10 -3
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js +29 -8
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js.map +1 -1
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js +7 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js.map +1 -1
- package/src/lib/components/console/pos-kiosk-page.component.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk-page.component.js +54 -3
- package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js.map +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +0 -2
- package/src/lib/components/console/product-add-ons-fields.component.js +1 -6
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +7 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +129 -32
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +4 -1
- package/src/lib/components/console/quote-pay-link.component.js +23 -12
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.d.ts +3 -2
- package/src/lib/components/console/quote-proofs.component.js +73 -5
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.js +9 -6
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/console/site-member-purchases.component.js +1 -1
- package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
- package/src/lib/components/product-detail.js +1 -1
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +5 -3
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-reviews.js +17 -12
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/quote-page-body.js +14 -8
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/related-products.js +2 -1
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +1 -1
- package/src/lib/model/commerce-invoices.js +4 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-kiosk-search.d.ts +22 -0
- package/src/lib/model/commerce-kiosk-search.js +32 -0
- package/src/lib/model/commerce-kiosk-search.js.map +1 -0
- package/src/lib/model/commerce-pos-kiosk.d.ts +7 -1
- package/src/lib/model/commerce-pos-kiosk.js +1 -1
- package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
- package/src/lib/model/commerce-quote-email.d.ts +7 -6
- package/src/lib/model/commerce-quote-email.js +11 -6
- package/src/lib/model/commerce-quote-email.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +6 -1
- package/src/lib/model/commerce-quote-pay.js +18 -8
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +28 -1
- package/src/lib/model/commerce-quote-proofs.js +58 -2
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +22 -1
- package/src/lib/model/commerce-quotes.js +25 -5
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/plugin-permissions.d.ts +1 -1
- package/src/lib/model/plugin-permissions.js +10 -0
- package/src/lib/model/plugin-permissions.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +4 -0
- package/src/lib/model/product-modifiers.js +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/commerce-pdf.d.ts +1 -1
- package/src/lib/server/commerce-pdf.js +1 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/paid-media-delivery.js +1 -1
- package/src/lib/server/paid-media-delivery.js.map +1 -1
- package/src/lib/server/pos-kiosk.js +70 -15
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/quote-email.js +29 -25
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.js +6 -2
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proof-media.d.ts +63 -0
- package/src/lib/server/quote-proof-media.js +96 -0
- package/src/lib/server/quote-proof-media.js.map +1 -0
- package/src/lib/server/quote-proofs.js +17 -8
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote-uploads.d.ts +3 -1
- package/src/lib/server/quote-uploads.js +2 -1
- package/src/lib/server/quote-uploads.js.map +1 -1
- package/src/lib/server/quote.d.ts +3 -0
- package/src/lib/server/quote.js +127 -20
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/site-page-enricher.js +5 -1
- package/src/lib/server/site-page-enricher.js.map +1 -1
- package/src/lib/tenant-emails.js +16 -9
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.js +34 -5
- package/src/lib/testing/fake-firestore.js.map +1 -1
- package/src/lib/transfer/gift-cards.server.js +9 -11
- package/src/lib/transfer/gift-cards.server.js.map +1 -1
- package/src/lib/transfer/product-register-cells.d.ts +75 -0
- package/src/lib/transfer/product-register-cells.js +487 -0
- package/src/lib/transfer/product-register-cells.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +12 -0
- package/src/lib/transfer/product-transfer.js +174 -10
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +24 -9
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/commerce-document-pdf.js +12 -9
- package/src/lib/utils/commerce-document-pdf.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +2 -0
- package/src/lib/utils/quote-email-content.js +20 -10
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/site-member-purchases.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { ConsoleSiteMemberZoneProps } from '@aglyn/aglyn'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport {\n ceilingedWindow,\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport { Chip, Divider, Stack, Typography } from '@mui/material'\nimport {\n collection,\n documentId,\n limit,\n orderBy,\n query,\n where,\n} from 'firebase/firestore'\nimport { useEffect, useMemo, useState } from 'react'\nimport { splitOrderReversal } from '../../model/commerce-dispute'\nimport { computeLifetimePurchaseCents } from '../../model/site-member-purchases'\n\nconst usd = (cents: number) => `$${(cents / 100).toFixed(2)}`\n\n/**\n * How many order documents this reads for one member.\n *\n * A CEILING, not a page size: the lifetime-purchase figure above the list is\n * summed from these rows, so every one it intends to count has to be held. A\n * server page would make that headline number the total of ten orders and\n * print it as a lifetime.\n */\nconst ORDER_CEILING = 100\n/** The same, for the subscriptions this member holds. */\nconst SUBSCRIPTION_CEILING = 25\n\n/**\n * The reversal suffix on one order row, split by the door the money left\n * through (AGL-1810). `refundedCents` carries a lost chargeback as well as a\n * refund (AGL-1787 puts both there deliberately), so rendering the whole\n * figure as \"refunded\" told the merchant they chose a reversal a bank took.\n * `computeLifetimePurchaseCents` keeps netting the total; only the label\n * splits.\n */\nconst reversalSuffix = (order: any) => {\n const { refundedCents, chargedBackCents } = splitOrderReversal(order)\n return (\n (refundedCents ? ` · refunded ${usd(refundedCents)}` : '') +\n (chargedBackCents ? ` · charged back ${usd(chargedBackCents)}` : '')\n )\n}\n\n/** Display order number: v1 sequential `#1042`, else a doc-id stub. */\nconst orderNumber = (order: any) =>\n order.number != null\n ? `#${order.number}`\n : `#${String(order.$id ?? '').slice(-6).toUpperCase()}`\n\nconst orderCreatedMs = (order: any) =>\n Number(order.createdAtMs ?? (order.createdAt?.seconds ?? 0) * 1000) || 0\n\n/**\n * What a site user bought (AGL-546): the lifetime purchase total, the order\n * history (the payment records — Stripe intent id and refunds included) and\n * storefront subscriptions — the `siteMember` zone of the account's drawer.\n *\n * Orders match by email (mirrors membership-account, AGL-294) and sort\n * client-side. The QUERY orders on the document name: `orderBy('createdAt')`\n * would want a composite index and, worse, would drop every order missing the\n * field, while an equality filter plus `orderBy(documentId())` rides the\n * automatic single-field index and can drop nothing — a document's name\n * cannot be absent. That makes the window total rather than a pseudo-random\n * hundred, which is what the newest-first sort below was quietly disguising.\n * `orders` reads are admin/editor-only in rules (AGL-502), so viewers get a\n * note instead of history.\n *\n * One section per element, as a fragment: the zone is `bare`, and the drawer's\n * own column spaces what it holds.\n */\nexport function SiteMemberPurchases(props: ConsoleSiteMemberZoneProps) {\n const { hostId, member } = props\n const firestore = useFirestore()\n const memberId = String(member.$id ?? '')\n const email = String(member['email'] ?? '')\n\n const { data: orderDocs, status: ordersStatus } = useFirestoreCollection<any>(\n () =>\n email\n ? query(\n collection(firestore, 'hosts', hostId, 'orders'),\n where('customerEmail', '==', email),\n orderBy(documentId()),\n // One document past the ceiling, so \"this member has more\" is a\n // fact. `length === 100` cannot tell a member with exactly a\n // hundred orders from one with a thousand, and the difference is\n // whether the lifetime figure above is a total or a floor.\n limit(ORDER_CEILING + 1),\n )\n : null,\n [firestore, hostId, email],\n { idField: '$id' },\n )\n const { rows: readOrders, truncated: ordersTruncated } = ceilingedWindow<any>(\n orderDocs,\n ORDER_CEILING,\n )\n const orders = useMemo(\n () =>\n [...readOrders].sort((a, b) => orderCreatedMs(b) - orderCreatedMs(a)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [orderDocs],\n )\n const lifetimeCents = useMemo(\n () => computeLifetimePurchaseCents(orders),\n [orders],\n )\n /**\n * The order query failed AND nothing came back with it (AGL-1066).\n *\n * The copy this gates blames the reader's ROLE, which is the right\n * explanation for the denial this was written for — orders are\n * admin/editor-only in rules. It is the wrong explanation once a stale\n * SESSION can push a listen to `'error'` too, and flatly wrong when\n * `persistentLocalCache` is still serving the rows: telling someone their\n * role is insufficient while their orders sit right there is a support\n * ticket about permissions that was never about permissions.\n */\n const ordersUnreadable = ordersStatus === 'error' && orders.length === 0\n\n const { data: subscriptionDocs } = useFirestoreCollection<any>(\n () =>\n email\n ? query(\n collection(firestore, 'hosts', hostId, 'subscriptions'),\n where('customerEmail', '==', email),\n // The same decision as the orders above, for the same reason: a\n // subscription written without `createdAt` would be hidden by a\n // field ordering rather than mis-sorted by it.\n orderBy(documentId()),\n limit(SUBSCRIPTION_CEILING + 1),\n )\n : null,\n [firestore, hostId, email],\n { idField: '$id' },\n )\n const { rows: subscriptions, truncated: subscriptionsTruncated } =\n ceilingedWindow<any>(subscriptionDocs, SUBSCRIPTION_CEILING)\n // Product names for subscriptions, loaded only when any exist.\n const { data: productDocs } = useFirestoreCollection<any>(\n () =>\n email && (subscriptionDocs?.length ?? 0) > 0\n ? query(\n collection(firestore, 'hosts', hostId, 'products'),\n // A LOOKUP, not a list — but the same ordering decision, so the\n // hundred it reads is a reachable hundred rather than a sample,\n // and a product past it degrades a subscription's label to its\n // id rather than hiding the subscription.\n orderBy(documentId()),\n limit(100),\n )\n : null,\n [firestore, hostId, email, (subscriptionDocs?.length ?? 0) > 0],\n { idField: '$id' },\n )\n /*==========================================\n * BOTH LISTS PAGE IN MEMORY.\n *\n * Each ceiling is held whole, which is what lets the orders sort\n * newest-first and the lifetime figure sum over all of them. A server page\n * would have made both about ten rows instead of about this member.\n *=========================================*/\n const [orderPage, setOrderPage] = useState(0)\n const [orderPageSize, setOrderPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleOrders = useMemo(\n () =>\n orders.slice(\n orderPage * orderPageSize,\n orderPage * orderPageSize + orderPageSize,\n ),\n [orders, orderPage, orderPageSize],\n )\n const [subscriptionPage, setSubscriptionPage] = useState(0)\n const [subscriptionPageSize, setSubscriptionPageSize] = useState(\n TABLE_PAGE_SIZE_DEFAULT,\n )\n const visibleSubscriptions = useMemo(\n () =>\n subscriptions.slice(\n subscriptionPage * subscriptionPageSize,\n subscriptionPage * subscriptionPageSize + subscriptionPageSize,\n ),\n [subscriptions, subscriptionPage, subscriptionPageSize],\n )\n /*\n * A different member starts at page one. The drawer is reused for whoever\n * is selected, so without this the next member opens three pages into a\n * history they may not have — which renders as an empty list and reads as\n * \"this person never bought anything\".\n */\n useEffect(() => {\n setOrderPage(0)\n setSubscriptionPage(0)\n }, [memberId])\n\n const productNames = useMemo(() => {\n const map: Record<string, string> = {}\n for (const product of productDocs ?? []) {\n map[product.$id] = product.name ?? product.$id\n }\n return map\n }, [productDocs])\n\n return (\n <>\n <Divider textAlign=\"left\">{'Lifetime purchases'}</Divider>\n <Typography variant=\"h6\">\n {/*\n \"at least\", or nothing at all. This figure is summed over the order\n WINDOW, so once the probe finds an order past the ceiling it is a\n lower bound — and a lower bound printed as a lifetime is the number\n a support agent quotes back to the customer.\n */}\n {ordersUnreadable\n ? '—'\n : `${ordersTruncated ? 'at least ' : ''}${usd(lifetimeCents)}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Charged order totals minus refunds; pending and canceled ' +\n 'orders excluded.'}\n {ordersTruncated\n ? ` Summed over the ${ORDER_CEILING} orders read here; this ` +\n 'member has more.'\n : ''}\n </Typography>\n\n <Divider textAlign=\"left\">{'Orders'}</Divider>\n {ordersUnreadable ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Order history needs the editor or admin role on this site.'}\n </Typography>\n ) : orders.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No orders yet.'}\n </Typography>\n ) : (\n visibleOrders.map((order: any) => (\n <Stack key={order.$id} spacing={0}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" sx={{ flex: 1 }} noWrap>\n {`${orderNumber(order)} · ${usd(\n Number(order.totals?.totalCents ?? order.amountCents ?? 0) ||\n 0,\n )}`}\n </Typography>\n <Chip\n label={String(order.status ?? 'paid').replace('_', ' ')}\n size=\"small\"\n variant=\"outlined\"\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {orderCreatedMs(order)\n ? new Date(orderCreatedMs(order)).toLocaleDateString()\n : '—'}\n {reversalSuffix(order)}\n </Typography>\n {order.paymentIntentId ? (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ fontFamily: 'monospace' }}\n noWrap\n >\n {order.paymentIntentId}\n </Typography>\n ) : null}\n </Stack>\n ))\n )}\n {ordersUnreadable || orders.length === 0 ? null : (\n <ListPagination\n page={orderPage}\n pageSize={orderPageSize}\n rowCount={visibleOrders.length}\n // The orders held here — a slice of rows already read, so the\n // total is exact for the window. The lifetime caption above is\n // where the window's own shortfall is stated.\n count={orders.length}\n onPageChange={setOrderPage}\n onPageSizeChange={setOrderPageSize}\n />\n )}\n\n {subscriptions.length > 0 ? (\n <>\n <Divider textAlign=\"left\">{'Subscriptions'}</Divider>\n {visibleSubscriptions.map((subscription: any) => (\n <Stack\n key={subscription.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {/*\n * The amount (AGL-1732). This row named the product and the\n * renewal date and stopped, and no other console surface\n * carried the figure either — orders, analytics and the CSV\n * all read `orders`, which a subscription sale does not\n * create. Subscriptions written before that fix have no\n * `totals`, so the amount is omitted rather than shown as\n * $0.00.\n */}\n {productNames[subscription.productId] ??\n subscription.productId ??\n 'Subscription'}\n {subscription.totals?.totalCents != null\n ? ` · ${usd(Number(subscription.totals.totalCents) || 0)}${\n subscription.interval ? `/${subscription.interval}` : ''\n }`\n : ''}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {subscription.currentPeriodEndMs\n ? `Renews ${new Date(\n Number(subscription.currentPeriodEndMs),\n ).toLocaleDateString()}`\n : '—'}\n {/*\n * What this subscriber has actually paid, across every cycle\n * (AGL-1743). Omitted, not shown as 0, for subscriptions\n * whose cycles all predate `invoice.payment_succeeded`\n * being handled: those invoices are recoverable only from\n * Stripe.\n */}\n {Number(subscription.invoicesCount ?? 0) > 0\n ? ` · ${usd(Number(subscription.paidCents) || 0)} paid over ${\n Number(subscription.invoicesCount) === 1\n ? '1 invoice'\n : `${Number(subscription.invoicesCount)} invoices`\n }`\n : ''}\n </Typography>\n </Stack>\n <Chip\n label={String(subscription.status ?? 'active')}\n size=\"small\"\n variant=\"outlined\"\n color={subscription.status === 'active' ? 'success' : 'default'}\n />\n </Stack>\n ))}\n <ListPagination\n page={subscriptionPage}\n pageSize={subscriptionPageSize}\n rowCount={visibleSubscriptions.length}\n // This member's subscriptions, in full for the window.\n count={subscriptions.length}\n onPageChange={setSubscriptionPage}\n onPageSizeChange={setSubscriptionPageSize}\n />\n {subscriptionsTruncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Showing ${SUBSCRIPTION_CEILING} subscriptions; this ` +\n 'member has more.'}\n </Typography>\n ) : null}\n </>\n ) : null}\n </>\n )\n}\nSiteMemberPurchases.displayName = 'SiteMemberPurchases'\n\nexport default SiteMemberPurchases\n"],"names":["ListPagination","TABLE_PAGE_SIZE_DEFAULT","ceilingedWindow","useFirestore","useFirestoreCollection","Chip","Divider","Stack","Typography","collection","documentId","limit","orderBy","query","where","useEffect","useMemo","useState","splitOrderReversal","computeLifetimePurchaseCents","usd","cents","toFixed","ORDER_CEILING","SUBSCRIPTION_CEILING","reversalSuffix","order","refundedCents","chargedBackCents","orderNumber","number","String","$id","slice","toUpperCase","orderCreatedMs","Number","createdAtMs","createdAt","seconds","SiteMemberPurchases","props","member","hostId","firestore","memberId","email","data","orderDocs","status","ordersStatus","idField","rows","readOrders","truncated","ordersTruncated","orders","sort","a","b","lifetimeCents","ordersUnreadable","length","subscriptionDocs","subscriptions","subscriptionsTruncated","productDocs","orderPage","setOrderPage","orderPageSize","setOrderPageSize","visibleOrders","subscriptionPage","setSubscriptionPage","subscriptionPageSize","setSubscriptionPageSize","visibleSubscriptions","productNames","map","product","name","textAlign","variant","color","spacing","direction","sx","alignItems","flex","noWrap","totals","totalCents","amountCents","label","replace","size","Date","toLocaleDateString","paymentIntentId","fontFamily","page","pageSize","rowCount","count","onPageChange","onPageSizeChange","subscription","minWidth","productId","interval","currentPeriodEndMs","invoicesCount","paidCents","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD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;;;sDAEN,MAACrG;4CAAW0E,SAAQ;4CAAUC,OAAM;;gDACjCuB,aAAaI,kBAAkB,GAC5B,CAAC,OAAO,EAAE,IAAId,KACZ5D,OAAOsE,aAAaI,kBAAkB,GACtCb,kBAAkB,IAAI,GACxB;gDAQH7D,QAAOsE,8BAAAA,aAAaK,aAAa,YAA1BL,8BAA8B,KAAK,IACvC,CAAC,GAAG,EAAEtF,IAAIgB,OAAOsE,aAAaM,SAAS,KAAK,GAAG,WAAW,EACxD5E,OAAOsE,aAAaK,aAAa,MAAM,IACnC,cACA,GAAG3E,OAAOsE,aAAaK,aAAa,EAAE,SAAS,CAAC,EACpD,GACF;;;;;8CAGR,KAAC1G;oCACCwF,OAAO9D,QAAO2E,uBAAAA,aAAazD,MAAM,YAAnByD,uBAAuB;oCACrCX,MAAK;oCACLb,SAAQ;oCACRC,OAAOuB,aAAazD,MAAM,KAAK,WAAW,YAAY;;;2BAnDnDyD,aAAa1E,GAAG;;kCAuDzB,KAAChC;wBACCoG,MAAM5B;wBACN6B,UAAU3B;wBACV4B,UAAU1B,qBAAqBd,MAAM;wBACrC,uDAAuD;wBACvDyC,OAAOvC,cAAcF,MAAM;wBAC3B0C,cAAc/B;wBACdgC,kBAAkB9B;;oBAEnBV,uCACC,KAACzD;wBAAW0E,SAAQ;wBAAUC,OAAM;kCACjC,CAAC,QAAQ,EAAE3D,qBAAqB,qBAAqB,CAAC,GACrD;yBAEF;;iBAEJ;;;AAGV;AACAgB,oBAAoByE,WAAW,GAAG;AAElC,eAAezE,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/site-member-purchases.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { ConsoleSiteMemberZoneProps } from '@aglyn/aglyn'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport {\n ceilingedWindow,\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport { Chip, Divider, Stack, Typography } from '@mui/material'\nimport {\n collection,\n documentId,\n limit,\n orderBy,\n query,\n where,\n} from 'firebase/firestore'\nimport { useEffect, useMemo, useState } from 'react'\nimport { splitOrderReversal } from '../../model/commerce-dispute'\nimport { computeLifetimePurchaseCents } from '../../model/site-member-purchases'\n\nconst usd = (cents: number) => `$${(cents / 100).toFixed(2)}`\n\n/**\n * How many order documents this reads for one member.\n *\n * A CEILING, not a page size: the lifetime-purchase figure above the list is\n * summed from these rows, so every one it intends to count has to be held. A\n * server page would make that headline number the total of ten orders and\n * print it as a lifetime.\n */\nconst ORDER_CEILING = 100\n/** The same, for the subscriptions this member holds. */\nconst SUBSCRIPTION_CEILING = 25\n\n/**\n * The reversal suffix on one order row, split by the door the money left\n * through (AGL-1810). `refundedCents` carries a lost chargeback as well as a\n * refund (AGL-1787 puts both there deliberately), so rendering the whole\n * figure as \"refunded\" told the merchant they chose a reversal a bank took.\n * `computeLifetimePurchaseCents` keeps netting the total; only the label\n * splits.\n */\nconst reversalSuffix = (order: any) => {\n const { refundedCents, chargedBackCents } = splitOrderReversal(order)\n return (\n (refundedCents ? ` · refunded ${usd(refundedCents)}` : '') +\n (chargedBackCents ? ` · charged back ${usd(chargedBackCents)}` : '')\n )\n}\n\n/** Display order number: v1 sequential `#1042`, else a doc-id stub. */\nconst orderNumber = (order: any) =>\n order.number != null\n ? `#${order.number}`\n : `#${String(order.$id ?? '').slice(-6).toUpperCase()}`\n\nconst orderCreatedMs = (order: any) =>\n Number(order.createdAtMs ?? (order.createdAt?.seconds ?? 0) * 1000) || 0\n\n/**\n * What a site user bought (AGL-546): the lifetime purchase total, the order\n * history (the payment records — Stripe intent id and refunds included) and\n * storefront subscriptions — the `siteMember` zone of the account's drawer.\n *\n * Orders match by email (mirrors membership-account, AGL-294) and sort\n * client-side. The QUERY orders on the document name: `orderBy('createdAt')`\n * would want a composite index and, worse, would drop every order missing the\n * field, while an equality filter plus `orderBy(documentId())` rides the\n * automatic single-field index and can drop nothing — a document's name\n * cannot be absent. That makes the window total rather than a pseudo-random\n * hundred, which is what the newest-first sort below was quietly disguising.\n * `orders` reads are admin/editor-only in rules (AGL-502), so viewers get a\n * note instead of history.\n *\n * One section per element, as a fragment: the zone is `bare`, and the drawer's\n * own column spaces what it holds.\n */\nexport function SiteMemberPurchases(props: ConsoleSiteMemberZoneProps) {\n const { hostId, member } = props\n const firestore = useFirestore()\n const memberId = String(member.$id ?? '')\n const email = String(member['email'] ?? '')\n\n const { data: orderDocs, status: ordersStatus } = useFirestoreCollection<any>(\n () =>\n email\n ? query(\n collection(firestore, 'hosts', hostId, 'orders'),\n where('customerEmail', '==', email),\n orderBy(documentId()),\n // One document past the ceiling, so \"this member has more\" is a\n // fact. `length === 100` cannot tell a member with exactly a\n // hundred orders from one with a thousand, and the difference is\n // whether the lifetime figure above is a total or a floor.\n limit(ORDER_CEILING + 1),\n )\n : null,\n [firestore, hostId, email],\n { idField: '$id' },\n )\n const { rows: readOrders, truncated: ordersTruncated } = ceilingedWindow<any>(\n orderDocs,\n ORDER_CEILING,\n )\n const orders = useMemo(\n () =>\n [...readOrders].sort((a, b) => orderCreatedMs(b) - orderCreatedMs(a)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [orderDocs],\n )\n const lifetimeCents = useMemo(\n () => computeLifetimePurchaseCents(orders),\n [orders],\n )\n /**\n * The order query failed AND nothing came back with it (AGL-1066).\n *\n * The copy this gates blames the reader's ROLE, which is the right\n * explanation for the denial this was written for — orders are\n * admin/editor-only in rules. It is the wrong explanation once a stale\n * SESSION can push a listen to `'error'` too, and flatly wrong when\n * `persistentLocalCache` is still serving the rows: telling someone their\n * role is insufficient while their orders sit right there is a support\n * ticket about permissions that was never about permissions.\n */\n const ordersUnreadable = ordersStatus === 'error' && orders.length === 0\n\n const { data: subscriptionDocs } = useFirestoreCollection<any>(\n () =>\n email\n ? query(\n collection(firestore, 'hosts', hostId, 'subscriptions'),\n where('customerEmail', '==', email),\n // The same decision as the orders above, for the same reason: a\n // subscription written without `createdAt` would be hidden by a\n // field ordering rather than mis-sorted by it.\n orderBy(documentId()),\n limit(SUBSCRIPTION_CEILING + 1),\n )\n : null,\n [firestore, hostId, email],\n { idField: '$id' },\n )\n const { rows: subscriptions, truncated: subscriptionsTruncated } =\n ceilingedWindow<any>(subscriptionDocs, SUBSCRIPTION_CEILING)\n // Product names for subscriptions, loaded only when any exist.\n const { data: productDocs } = useFirestoreCollection<any>(\n () =>\n email && (subscriptionDocs?.length ?? 0) > 0\n ? query(\n collection(firestore, 'hosts', hostId, 'products'),\n // A LOOKUP, not a list — but the same ordering decision, so the\n // hundred it reads is a reachable hundred rather than a sample,\n // and a product past it degrades a subscription's label to its\n // id rather than hiding the subscription.\n orderBy(documentId()),\n limit(100),\n )\n : null,\n [firestore, hostId, email, (subscriptionDocs?.length ?? 0) > 0],\n { idField: '$id' },\n )\n /*==========================================\n * BOTH LISTS PAGE IN MEMORY.\n *\n * Each ceiling is held whole, which is what lets the orders sort\n * newest-first and the lifetime figure sum over all of them. A server page\n * would have made both about ten rows instead of about this member.\n *=========================================*/\n const [orderPage, setOrderPage] = useState(0)\n const [orderPageSize, setOrderPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleOrders = useMemo(\n () =>\n orders.slice(\n orderPage * orderPageSize,\n orderPage * orderPageSize + orderPageSize,\n ),\n [orders, orderPage, orderPageSize],\n )\n const [subscriptionPage, setSubscriptionPage] = useState(0)\n const [subscriptionPageSize, setSubscriptionPageSize] = useState(\n TABLE_PAGE_SIZE_DEFAULT,\n )\n const visibleSubscriptions = useMemo(\n () =>\n subscriptions.slice(\n subscriptionPage * subscriptionPageSize,\n subscriptionPage * subscriptionPageSize + subscriptionPageSize,\n ),\n [subscriptions, subscriptionPage, subscriptionPageSize],\n )\n /*\n * A different member starts at page one. The drawer is reused for whoever\n * is selected, so without this the next member opens three pages into a\n * history they may not have — which renders as an empty list and reads as\n * \"this person never bought anything\".\n */\n useEffect(() => {\n setOrderPage(0)\n setSubscriptionPage(0)\n }, [memberId])\n\n const productNames = useMemo(() => {\n const map: Record<string, string> = {}\n for (const product of productDocs ?? []) {\n map[product.$id] = product.name ?? product.$id\n }\n return map\n }, [productDocs])\n\n return (\n <>\n <Divider textAlign=\"left\">{'Lifetime purchases'}</Divider>\n <Typography variant=\"h6\">\n {/*\n \"at least\", or nothing at all. This figure is summed over the order\n WINDOW, so once the probe finds an order past the ceiling it is a\n lower bound — and a lower bound printed as a lifetime is the number\n a support agent quotes back to the customer.\n */}\n {ordersUnreadable\n ? '—'\n : `${ordersTruncated ? 'at least ' : ''}${usd(lifetimeCents)}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Charged order totals minus refunds; pending and canceled ' +\n 'orders excluded.'}\n {ordersTruncated\n ? ` Summed over the ${ORDER_CEILING} orders read here; this ` +\n 'member has more.'\n : ''}\n </Typography>\n\n <Divider textAlign=\"left\">{'Orders'}</Divider>\n {ordersUnreadable ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Order history takes the \"See orders and webhooks\" permission on this site.'}\n </Typography>\n ) : orders.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No orders yet.'}\n </Typography>\n ) : (\n visibleOrders.map((order: any) => (\n <Stack key={order.$id} spacing={0}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" sx={{ flex: 1 }} noWrap>\n {`${orderNumber(order)} · ${usd(\n Number(order.totals?.totalCents ?? order.amountCents ?? 0) ||\n 0,\n )}`}\n </Typography>\n <Chip\n label={String(order.status ?? 'paid').replace('_', ' ')}\n size=\"small\"\n variant=\"outlined\"\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {orderCreatedMs(order)\n ? new Date(orderCreatedMs(order)).toLocaleDateString()\n : '—'}\n {reversalSuffix(order)}\n </Typography>\n {order.paymentIntentId ? (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ fontFamily: 'monospace' }}\n noWrap\n >\n {order.paymentIntentId}\n </Typography>\n ) : null}\n </Stack>\n ))\n )}\n {ordersUnreadable || orders.length === 0 ? null : (\n <ListPagination\n page={orderPage}\n pageSize={orderPageSize}\n rowCount={visibleOrders.length}\n // The orders held here — a slice of rows already read, so the\n // total is exact for the window. The lifetime caption above is\n // where the window's own shortfall is stated.\n count={orders.length}\n onPageChange={setOrderPage}\n onPageSizeChange={setOrderPageSize}\n />\n )}\n\n {subscriptions.length > 0 ? (\n <>\n <Divider textAlign=\"left\">{'Subscriptions'}</Divider>\n {visibleSubscriptions.map((subscription: any) => (\n <Stack\n key={subscription.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {/*\n * The amount (AGL-1732). This row named the product and the\n * renewal date and stopped, and no other console surface\n * carried the figure either — orders, analytics and the CSV\n * all read `orders`, which a subscription sale does not\n * create. Subscriptions written before that fix have no\n * `totals`, so the amount is omitted rather than shown as\n * $0.00.\n */}\n {productNames[subscription.productId] ??\n subscription.productId ??\n 'Subscription'}\n {subscription.totals?.totalCents != null\n ? ` · ${usd(Number(subscription.totals.totalCents) || 0)}${\n subscription.interval ? `/${subscription.interval}` : ''\n }`\n : ''}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {subscription.currentPeriodEndMs\n ? `Renews ${new Date(\n Number(subscription.currentPeriodEndMs),\n ).toLocaleDateString()}`\n : '—'}\n {/*\n * What this subscriber has actually paid, across every cycle\n * (AGL-1743). Omitted, not shown as 0, for subscriptions\n * whose cycles all predate `invoice.payment_succeeded`\n * being handled: those invoices are recoverable only from\n * Stripe.\n */}\n {Number(subscription.invoicesCount ?? 0) > 0\n ? ` · ${usd(Number(subscription.paidCents) || 0)} paid over ${\n Number(subscription.invoicesCount) === 1\n ? '1 invoice'\n : `${Number(subscription.invoicesCount)} invoices`\n }`\n : ''}\n </Typography>\n </Stack>\n <Chip\n label={String(subscription.status ?? 'active')}\n size=\"small\"\n variant=\"outlined\"\n color={subscription.status === 'active' ? 'success' : 'default'}\n />\n </Stack>\n ))}\n <ListPagination\n page={subscriptionPage}\n pageSize={subscriptionPageSize}\n rowCount={visibleSubscriptions.length}\n // This member's subscriptions, in full for the window.\n count={subscriptions.length}\n onPageChange={setSubscriptionPage}\n onPageSizeChange={setSubscriptionPageSize}\n />\n {subscriptionsTruncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Showing ${SUBSCRIPTION_CEILING} subscriptions; this ` +\n 'member has more.'}\n </Typography>\n ) : null}\n </>\n ) : null}\n </>\n )\n}\nSiteMemberPurchases.displayName = 'SiteMemberPurchases'\n\nexport default SiteMemberPurchases\n"],"names":["ListPagination","TABLE_PAGE_SIZE_DEFAULT","ceilingedWindow","useFirestore","useFirestoreCollection","Chip","Divider","Stack","Typography","collection","documentId","limit","orderBy","query","where","useEffect","useMemo","useState","splitOrderReversal","computeLifetimePurchaseCents","usd","cents","toFixed","ORDER_CEILING","SUBSCRIPTION_CEILING","reversalSuffix","order","refundedCents","chargedBackCents","orderNumber","number","String","$id","slice","toUpperCase","orderCreatedMs","Number","createdAtMs","createdAt","seconds","SiteMemberPurchases","props","member","hostId","firestore","memberId","email","data","orderDocs","status","ordersStatus","idField","rows","readOrders","truncated","ordersTruncated","orders","sort","a","b","lifetimeCents","ordersUnreadable","length","subscriptionDocs","subscriptions","subscriptionsTruncated","productDocs","orderPage","setOrderPage","orderPageSize","setOrderPageSize","visibleOrders","subscriptionPage","setSubscriptionPage","subscriptionPageSize","setSubscriptionPageSize","visibleSubscriptions","productNames","map","product","name","textAlign","variant","color","spacing","direction","sx","alignItems","flex","noWrap","totals","totalCents","amountCents","label","replace","size","Date","toLocaleDateString","paymentIntentId","fontFamily","page","pageSize","rowCount","count","onPageChange","onPageSizeChange","subscription","minWidth","productId","interval","currentPeriodEndMs","invoicesCount","paidCents","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SACEC,eAAe,EACfC,YAAY,EACZC,sBAAsB,QACjB,iCAAgC;AACvC,SAASC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AAChE,SACEC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SAASC,kBAAkB,QAAQ,kCAA8B;AACjE,SAASC,4BAA4B,QAAQ,uCAAmC;AAEhF,MAAMC,MAAM,CAACC,QAAkB,CAAC,CAAC,EAAE,AAACA,CAAAA,QAAQ,GAAE,EAAGC,OAAO,CAAC,IAAI;AAE7D;;;;;;;CAOC,GACD,MAAMC,gBAAgB;AACtB,uDAAuD,GACvD,MAAMC,uBAAuB;AAE7B;;;;;;;CAOC,GACD,MAAMC,iBAAiB,CAACC;IACtB,MAAM,EAAEC,aAAa,EAAEC,gBAAgB,EAAE,GAAGV,mBAAmBQ;IAC/D,OACE,AAACC,CAAAA,gBAAgB,CAAC,YAAY,EAAEP,IAAIO,gBAAgB,GAAG,EAAC,IACvDC,CAAAA,mBAAmB,CAAC,gBAAgB,EAAER,IAAIQ,mBAAmB,GA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