@aglyn/plugins-commerce 1.33.1 → 1.34.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/cart.js +3 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js +82 -69
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/discounts-card.component.js +46 -25
- package/src/lib/components/console/discounts-card.component.js.map +1 -1
- package/src/lib/components/console/gift-cards-card.component.js +81 -55
- package/src/lib/components/console/gift-cards-card.component.js.map +1 -1
- package/src/lib/components/console/host-coupons-card.component.js +36 -25
- package/src/lib/components/console/host-coupons-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +53 -32
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/member-posts-card.component.js +35 -32
- package/src/lib/components/console/member-posts-card.component.js.map +1 -1
- package/src/lib/components/console/new-store-tax-question.component.d.ts +17 -0
- package/src/lib/components/console/new-store-tax-question.component.js +197 -0
- package/src/lib/components/console/new-store-tax-question.component.js.map +1 -0
- package/src/lib/components/console/payments-settings-card.component.js +132 -5
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +6 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tax-notice.component.d.ts +21 -0
- package/src/lib/components/console/pos/pos-tax-notice.component.js +59 -0
- package/src/lib/components/console/pos/pos-tax-notice.component.js.map +1 -0
- package/src/lib/components/console/pos-page.component.js +65 -17
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/registers-card.component.js +21 -13
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/reviews-moderation-card.component.js +108 -68
- package/src/lib/components/console/reviews-moderation-card.component.js.map +1 -1
- package/src/lib/components/console/site-member-purchases.component.js +5 -3
- package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.d.ts +2 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/subscriptions-card.component.js +13 -5
- package/src/lib/components/console/subscriptions-card.component.js.map +1 -1
- package/src/lib/components/console/suppliers-card.component.js +47 -40
- package/src/lib/components/console/suppliers-card.component.js.map +1 -1
- package/src/lib/components/product-choice-cards.js +2 -1
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/components/product-detail.js +9 -4
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +3 -1
- package/src/lib/components/product-grid.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/components/store-image-sizing.d.ts +46 -0
- package/src/lib/components/store-image-sizing.js +53 -0
- package/src/lib/components/store-image-sizing.js.map +1 -0
- package/src/lib/components/wishlist.js +2 -1
- package/src/lib/components/wishlist.js.map +1 -1
- package/src/lib/declarations.console-server.js +10 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/model/commerce-tax-step.d.ts +123 -0
- package/src/lib/model/commerce-tax-step.js +185 -0
- package/src/lib/model/commerce-tax-step.js.map +1 -0
- 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/payments-setup-status.d.ts +40 -0
- package/src/lib/model/payments-setup-status.js +63 -0
- package/src/lib/model/payments-setup-status.js.map +1 -1
- package/src/lib/model/subscription-view.d.ts +19 -0
- package/src/lib/model/subscription-view.js +16 -0
- package/src/lib/model/subscription-view.js.map +1 -1
- package/src/lib/model/tap-to-pay-launch.d.ts +103 -0
- package/src/lib/model/tap-to-pay-launch.js +148 -0
- package/src/lib/model/tap-to-pay-launch.js.map +1 -0
- package/src/lib/plugin.js +12 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/billing-webhook.js +140 -116
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/checkout.js +15 -4
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/connect-return.d.ts +83 -0
- package/src/lib/server/connect-return.js +105 -0
- package/src/lib/server/connect-return.js.map +1 -0
- package/src/lib/server/connect.d.ts +18 -0
- package/src/lib/server/connect.js +60 -6
- package/src/lib/server/connect.js.map +1 -1
- package/src/lib/server/new-store-tax.d.ts +10 -0
- package/src/lib/server/new-store-tax.js +43 -0
- package/src/lib/server/new-store-tax.js.map +1 -0
- package/src/lib/server/pos-payment.js +3 -2
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-tax-step.d.ts +43 -0
- package/src/lib/server/pos-tax-step.js +55 -0
- package/src/lib/server/pos-tax-step.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +10 -1
- package/src/lib/server/pos-terminal-connection-token.js +18 -7
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +9 -0
- package/src/lib/server/pos-terminal.js +17 -1
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/tap-to-pay-launch-admin.d.ts +18 -0
- package/src/lib/server/tap-to-pay-launch-admin.js +204 -0
- package/src/lib/server/tap-to-pay-launch-admin.js.map +1 -0
- package/src/lib/server/tap-to-pay-launch.d.ts +114 -0
- package/src/lib/server/tap-to-pay-launch.js +408 -0
- package/src/lib/server/tap-to-pay-launch.js.map +1 -0
- package/src/lib/server.js +15 -0
- package/src/lib/server.js.map +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
*/ import * as Aglyn from "@aglyn/aglyn";
|
|
17
|
+
/**
|
|
18
|
+
* The `srcSet` and `sizes` a storefront product photo carries, so the browser
|
|
19
|
+
* fetches the resized WebP copy that fits the box instead of the original
|
|
20
|
+
* upload.
|
|
21
|
+
*
|
|
22
|
+
* Every commerce image used to name only the bare CDN url, which the CDN
|
|
23
|
+
* answers with the original: a shop that imported its catalog got 0.6–1.4 MB
|
|
24
|
+
* PNGs in a 360px grid card, about 11 MB for one collection page, where the
|
|
25
|
+
* 640px WebP copy of the same photo is ~55 KB. The Image element has carried
|
|
26
|
+
* a `srcSet` since AGL-175; the store surfaces never did.
|
|
27
|
+
*
|
|
28
|
+
* `sizes` is the width the photo renders at, per breakpoint, written by each
|
|
29
|
+
* caller from its own grid. Every caller also gives the `<img>` a CSS width
|
|
30
|
+
* (CardMedia's own `width: 100%`, or a fixed thumbnail edge), which is what
|
|
31
|
+
* `mediaCdnSrcSet` asks for: with `w` descriptors and no CSS width the image
|
|
32
|
+
* would be laid out at `sizes`.
|
|
33
|
+
*
|
|
34
|
+
* A url that is not ours (a hotlinked photo) has no variants, so it gets
|
|
35
|
+
* neither attribute and renders exactly as before.
|
|
36
|
+
*/ export function storeImageSizing(src, sizes) {
|
|
37
|
+
const srcSet = Aglyn.mediaCdnSrcSet(src);
|
|
38
|
+
return srcSet ? {
|
|
39
|
+
srcSet,
|
|
40
|
+
sizes
|
|
41
|
+
} : {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `sizes` for a card in a grid of `columns` columns at `md` and up and
|
|
45
|
+
* `narrowColumns` below it. Overstates by the page gutter, which only ever
|
|
46
|
+
* picks the next step up, never a blurry one.
|
|
47
|
+
*/ export function gridImageSizes(columns, narrowColumns) {
|
|
48
|
+
const wide = Math.max(1, Math.round(columns));
|
|
49
|
+
const narrow = Math.max(1, Math.round(narrowColumns));
|
|
50
|
+
return `(min-width: 900px) ${Math.ceil(100 / wide)}vw, ${Math.ceil(100 / narrow)}vw`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=store-image-sizing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/store-image-sizing.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as Aglyn from '@aglyn/aglyn'\n\n/**\n * The `srcSet` and `sizes` a storefront product photo carries, so the browser\n * fetches the resized WebP copy that fits the box instead of the original\n * upload.\n *\n * Every commerce image used to name only the bare CDN url, which the CDN\n * answers with the original: a shop that imported its catalog got 0.6–1.4 MB\n * PNGs in a 360px grid card, about 11 MB for one collection page, where the\n * 640px WebP copy of the same photo is ~55 KB. The Image element has carried\n * a `srcSet` since AGL-175; the store surfaces never did.\n *\n * `sizes` is the width the photo renders at, per breakpoint, written by each\n * caller from its own grid. Every caller also gives the `<img>` a CSS width\n * (CardMedia's own `width: 100%`, or a fixed thumbnail edge), which is what\n * `mediaCdnSrcSet` asks for: with `w` descriptors and no CSS width the image\n * would be laid out at `sizes`.\n *\n * A url that is not ours (a hotlinked photo) has no variants, so it gets\n * neither attribute and renders exactly as before.\n */\nexport function storeImageSizing(\n src: string | undefined | null,\n sizes: string,\n): { srcSet?: string; sizes?: string } {\n const srcSet = Aglyn.mediaCdnSrcSet(src)\n return srcSet ? { srcSet, sizes } : {}\n}\n\n/**\n * `sizes` for a card in a grid of `columns` columns at `md` and up and\n * `narrowColumns` below it. Overstates by the page gutter, which only ever\n * picks the next step up, never a blurry one.\n */\nexport function gridImageSizes(columns: number, narrowColumns: number): string {\n const wide = Math.max(1, Math.round(columns))\n const narrow = Math.max(1, Math.round(narrowColumns))\n return `(min-width: 900px) ${Math.ceil(100 / wide)}vw, ${Math.ceil(100 / narrow)}vw`\n}\n"],"names":["Aglyn","storeImageSizing","src","sizes","srcSet","mediaCdnSrcSet","gridImageSizes","columns","narrowColumns","wide","Math","max","round","narrow","ceil"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AAErC;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,iBACdC,GAA8B,EAC9BC,KAAa;IAEb,MAAMC,SAASJ,MAAMK,cAAc,CAACH;IACpC,OAAOE,SAAS;QAAEA;QAAQD;IAAM,IAAI,CAAC;AACvC;AAEA;;;;CAIC,GACD,OAAO,SAASG,eAAeC,OAAe,EAAEC,aAAqB;IACnE,MAAMC,OAAOC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACL;IACpC,MAAMM,SAASH,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACJ;IACtC,OAAO,CAAC,mBAAmB,EAAEE,KAAKI,IAAI,CAAC,MAAML,MAAM,IAAI,EAAEC,KAAKI,IAAI,CAAC,MAAMD,QAAQ,EAAE,CAAC;AACtF"}
|
|
@@ -29,6 +29,7 @@ import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
|
29
29
|
import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
30
30
|
import { generatePresetId } from "../utils/generate-preset-id.js";
|
|
31
31
|
import { useShopperCurrency } from "./shopper-currency.js";
|
|
32
|
+
import { gridImageSizes, storeImageSizing } from "./store-image-sizing.js";
|
|
32
33
|
// Component ids are persisted in screen documents; never rename.
|
|
33
34
|
export const ID = 'wishlist';
|
|
34
35
|
export const WISHLIST_UPDATED_EVENT = 'aglyn:wishlist-updated';
|
|
@@ -208,7 +209,7 @@ function writeLocalWishlist(hostId, productIds) {
|
|
|
208
209
|
height: 120,
|
|
209
210
|
objectFit: 'cover'
|
|
210
211
|
}
|
|
211
|
-
}, Aglyn.DEFERRED_IMAGE_ATTRIBUTES)) : /*#__PURE__*/ _jsx(Box, {
|
|
212
|
+
}, storeImageSizing(imageUrl, gridImageSizes(4, 2)), Aglyn.DEFERRED_IMAGE_ATTRIBUTES)) : /*#__PURE__*/ _jsx(Box, {
|
|
212
213
|
sx: {
|
|
213
214
|
height: 120,
|
|
214
215
|
bgcolor: 'action.hover'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/wishlist.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 { mdiHeartOutline } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, useCallback, useEffect, useState } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\nimport { useShopperCurrency } from './shopper-currency'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'wishlist'\n\nexport const WISHLIST_UPDATED_EVENT = 'aglyn:wishlist-updated'\n\nfunction storageKey(hostId: string): string {\n return `aglyn_wishlist_${hostId}`\n}\n\n/** Guest wishlist ids from localStorage. */\nexport function readLocalWishlist(hostId: string): string[] {\n try {\n const raw = window.localStorage.getItem(storageKey(hostId))\n return raw ? (JSON.parse(raw) as string[]).slice(0, 200) : []\n } catch {\n return []\n }\n}\n\nfunction writeLocalWishlist(hostId: string, productIds: string[]): void {\n try {\n window.localStorage.setItem(\n storageKey(hostId),\n JSON.stringify(productIds.slice(0, 200)),\n )\n } catch {\n // Private-mode storage failures degrade to session-only behavior.\n }\n}\n\n/**\n * Toggles a product on the wishlist (AGL-297): members persist on their\n * doc (guest list merges in on first signed-in call); guests persist in\n * localStorage. Returns whether the product is on the list afterward.\n *\n * Takes its own `fetch` (AGL-1139). This is a plain module function, not a\n * component, so it cannot read the site context that says whether it is\n * running in Preview — and both callers are components that can. Defaulting\n * to the global keeps every other caller unchanged; passing `useSiteFetch()`\n * is what stops a preview click from writing to a real member's wishlist.\n */\nexport async function toggleWishlist(\n hostId: string,\n productId: string,\n siteFetch: typeof fetch = fetch,\n): Promise<boolean> {\n const local = readLocalWishlist(hostId)\n const has = local.includes(productId)\n const next = has\n ? local.filter((id) => id !== productId)\n : [...local, productId]\n writeLocalWishlist(hostId, next)\n // Best-effort member sync — 401 just means guest.\n void siteFetch('/api/membership/wishlist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n action: has ? 'remove' : 'add',\n productId,\n }),\n }).catch(() => undefined)\n window.dispatchEvent(new Event(WISHLIST_UPDATED_EVENT))\n return !has\n}\n\nexport interface WishlistProps {\n heading?: string\n emptyText?: string\n}\n\ninterface CatalogItem {\n id: string\n name: string\n slug: string\n priceUsd: number\n /** The cheapest variant's own prices per currency (AGL-4248). */\n fixedPrices?: Record<string, number>\n imageUrl?: string\n soldOut: boolean\n /** Listed before it has a price (AGL-3676). */\n priceComingSoon?: boolean\n}\n\n/**\n * Wishlist block (AGL-297): renders the saved products (member doc when\n * signed in — merging any guest list — else localStorage) as cards\n * linking to their PDPs, with remove buttons.\n */\nconst Wishlist = forwardRef<HTMLDivElement, WishlistProps>((props, ref) => {\n const { heading, emptyText, ...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 // In the shopper's currency (AGL-4248), like every other price on the store.\n const shopper = useShopperCurrency()\n const [items, setItems] = useState<CatalogItem[] | null>(null)\n\n const refresh = useCallback(async () => {\n if (!hostId) return\n let productIds = readLocalWishlist(hostId)\n try {\n // Merge the guest list into the member doc; response is canonical.\n const response = await siteFetch('/api/membership/wishlist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, action: 'merge', productIds }),\n })\n if (response.ok) {\n const payload = await response.json()\n productIds = payload?.productIds ?? productIds\n writeLocalWishlist(hostId, productIds)\n }\n } catch {\n // Guest path.\n }\n if (productIds.length === 0) return setItems([])\n try {\n const response = await fetch(\n `/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}` +\n `&ids=${encodeURIComponent(productIds.join(','))}&limit=100`,\n )\n const payload = await response.json()\n setItems(payload?.items ?? [])\n } catch {\n setItems([])\n }\n }, [hostId, siteFetch])\n\n useEffect(() => {\n void refresh()\n const handler = () => void refresh()\n window.addEventListener(WISHLIST_UPDATED_EVENT, handler)\n return () => window.removeEventListener(WISHLIST_UPDATED_EVENT, handler)\n }, [refresh])\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 {'Wishlist — saved products render here'}\n </Box>\n )\n }\n\n return (\n <Box ref={ref} {...rest}>\n {heading ? (\n <Typography variant=\"h5\" gutterBottom>\n {heading}\n </Typography>\n ) : null}\n {items && items.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {emptyText || 'Nothing saved yet — tap the heart on any product.'}\n </Typography>\n ) : (\n <Box\n sx={{\n display: 'grid',\n gap: 2,\n gridTemplateColumns: {\n xs: 'repeat(2, 1fr)',\n md: 'repeat(4, 1fr)',\n },\n }}\n >\n {(items ?? []).map((item) => {\n // AGL-1726: resolved BEFORE the guard — see the note in\n // `product-detail.tsx`.\n const imageUrl = Aglyn.siteRelativeMediaSrc(item.imageUrl, {\n hostId,\n })\n return (\n <Card key={item.id} variant=\"outlined\">\n <CardActionArea href={`/products/${item.slug}`}>\n {imageUrl ? (\n <CardMedia\n component=\"img\"\n image={imageUrl}\n alt={item.name}\n sx={{ height: 120, objectFit: 'cover' }}\n // Deferred (AGL-2486), same reasoning as the product\n // grid: one image per saved item, none of them the lead.\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : (\n <Box sx={{ height: 120, bgcolor: 'action.hover' }} />\n )}\n <CardContent sx={{ pb: 1 }}>\n <Typography variant=\"body2\" noWrap>\n {item.name}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {item.soldOut\n ? 'Sold out'\n : item.priceComingSoon\n ? 'Price coming soon'\n : shopper.formatVariant({ priceUsd: item.priceUsd, fixedPrices: item.fixedPrices })}\n </Typography>\n </CardContent>\n </CardActionArea>\n <Button\n size=\"small\"\n color=\"error\"\n fullWidth\n onClick={() => void toggleWishlist(hostId, item.id, siteFetch)}\n >\n {'Remove'}\n </Button>\n </Card>\n )\n })}\n </Box>\n )}\n </Box>\n )\n})\nWishlist.displayName = 'AglynWishlist'\n\nexport const schema: Aglyn.ComponentSchema<WishlistProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Wishlist',\n description: 'Products a visitor saved, linking back to their pages.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiHeartOutline.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'heading',\n label: 'Heading',\n description: 'Shown above the saved products.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'emptyText',\n label: 'Empty text',\n description: 'Copy when nothing is saved.',\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: 'Wishlist',\n pluginId: BUNDLE_ID,\n description: 'Saved products with links back to their pages',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiHeartOutline.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: { heading: 'Your wishlist' },\n },\n },\n]\n\nexport default Wishlist\n"],"names":["Aglyn","mdiHeartOutline","Box","Button","Card","CardActionArea","CardContent","CardMedia","Typography","forwardRef","useCallback","useEffect","useState","BUNDLE_ID","generatePresetId","useShopperCurrency","ID","WISHLIST_UPDATED_EVENT","storageKey","hostId","readLocalWishlist","raw","window","localStorage","getItem","JSON","parse","slice","writeLocalWishlist","productIds","setItem","stringify","toggleWishlist","productId","siteFetch","fetch","local","has","includes","next","filter","id","method","headers","body","action","catch","undefined","dispatchEvent","Event","Wishlist","props","ref","heading","emptyText","rest","nodeSx","Array","isArray","useSite","useSiteFetch","shopper","items","setItems","refresh","response","ok","payload","json","length","encodeURIComponent","join","handler","addEventListener","removeEventListener","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","variant","gutterBottom","display","gap","gridTemplateColumns","xs","md","map","item","imageUrl","siteRelativeMediaSrc","href","slug","component","image","alt","name","height","objectFit","DEFERRED_IMAGE_ATTRIBUTES","bgcolor","pb","noWrap","soldOut","priceComingSoon","formatVariant","priceUsd","fixedPrices","size","fullWidth","onClick","displayName","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","label","FieldComponentType","TEXT_FIELD","presets","type","NodeType","PRESET","data","componentId"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,eAAe,QAAQ,yBAAwB;AACxD,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACpE,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,gBAAgB,QAAQ,iCAA6B;AAC9D,SAASC,kBAAkB,QAAQ,wBAAoB;AAEvD,iEAAiE;AACjE,OAAO,MAAMC,KAAwB,WAAU;AAE/C,OAAO,MAAMC,yBAAyB,yBAAwB;AAE9D,SAASC,WAAWC,MAAc;IAChC,OAAO,CAAC,eAAe,EAAEA,QAAQ;AACnC;AAEA,0CAA0C,GAC1C,OAAO,SAASC,kBAAkBD,MAAc;IAC9C,IAAI;QACF,MAAME,MAAMC,OAAOC,YAAY,CAACC,OAAO,CAACN,WAAWC;QACnD,OAAOE,MAAM,AAACI,KAAKC,KAAK,CAACL,KAAkBM,KAAK,CAAC,GAAG,OAAO,EAAE;IAC/D,EAAE,eAAM;QACN,OAAO,EAAE;IACX;AACF;AAEA,SAASC,mBAAmBT,MAAc,EAAEU,UAAoB;IAC9D,IAAI;QACFP,OAAOC,YAAY,CAACO,OAAO,CAC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AKlD,EAAE;gBAsCpB;;;;AAKV;AACAS,SAASgE,WAAW,GAAG;AAEvB,OAAO,MAAMC,SAA+C;IAC1DC,KAAKpG;IACLqG,UAAUxG;IACVqG,aAAa;IACbI,aAAa;IACbC,UAAUvH,MAAMwH,iBAAiB,CAACC,QAAQ;IAC1CC,MAAM;QAAEC,MAAM1H,gBAAgB0H,IAAI;QAAEhD,IAAI;YAAEK,OAAO;QAAU;IAAE;IAC7D4C,OAAO;QAAEC,aAAa7H,MAAM8H,YAAY,CAACC,OAAO;IAAC;IACjDC,YAAY;QACV;YACE7B,MAAM;YACN8B,OAAO;YACPX,aAAa;YACbtB,WAAWhG,MAAMkI,kBAAkB,CAACC,UAAU;QAChD;QACA;YACEhC,MAAM;YACN8B,OAAO;YACPX,aAAa;YACbtB,WAAWhG,MAAMkI,kBAAkB,CAACC,UAAU;QAChD;KACD;AACH,EAAC;AAED,OAAO,MAAMC,UAAgC;IAC3C;QACEhB,KAAKtG,iBAAiBE;QACtBqH,MAAMrI,MAAMsI,QAAQ,CAACC,MAAM;QAC3BrB,aAAa;QACbG,UAAUxG;QACVyG,aAAa;QACbC,UAAUvH,MAAMwH,iBAAiB,CAACC,QAAQ;QAC1CC,MAAM;YAAEC,MAAM1H,gBAAgB0H,IAAI;YAAEhD,IAAI;gBAAEK,OAAO;YAAU;QAAE;QAC7DwD,MAAM;YACJpB,KAAK;YACLqB,aAAazH;YACbqG,UAAUxG;YACVsC,OAAO;gBAAEE,SAAS;YAAgB;QACpC;IACF;CACD,CAAA;AAED,eAAeH,SAAQ"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/wishlist.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 { mdiHeartOutline } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Typography from '@mui/material/Typography'\nimport { forwardRef, useCallback, useEffect, useState } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\nimport { useShopperCurrency } from './shopper-currency'\nimport { gridImageSizes, storeImageSizing } from './store-image-sizing'\n\n// Component ids are persisted in screen documents; never rename.\nexport const ID: Aglyn.ComponentId = 'wishlist'\n\nexport const WISHLIST_UPDATED_EVENT = 'aglyn:wishlist-updated'\n\nfunction storageKey(hostId: string): string {\n return `aglyn_wishlist_${hostId}`\n}\n\n/** Guest wishlist ids from localStorage. */\nexport function readLocalWishlist(hostId: string): string[] {\n try {\n const raw = window.localStorage.getItem(storageKey(hostId))\n return raw ? (JSON.parse(raw) as string[]).slice(0, 200) : []\n } catch {\n return []\n }\n}\n\nfunction writeLocalWishlist(hostId: string, productIds: string[]): void {\n try {\n window.localStorage.setItem(\n storageKey(hostId),\n JSON.stringify(productIds.slice(0, 200)),\n )\n } catch {\n // Private-mode storage failures degrade to session-only behavior.\n }\n}\n\n/**\n * Toggles a product on the wishlist (AGL-297): members persist on their\n * doc (guest list merges in on first signed-in call); guests persist in\n * localStorage. Returns whether the product is on the list afterward.\n *\n * Takes its own `fetch` (AGL-1139). This is a plain module function, not a\n * component, so it cannot read the site context that says whether it is\n * running in Preview — and both callers are components that can. Defaulting\n * to the global keeps every other caller unchanged; passing `useSiteFetch()`\n * is what stops a preview click from writing to a real member's wishlist.\n */\nexport async function toggleWishlist(\n hostId: string,\n productId: string,\n siteFetch: typeof fetch = fetch,\n): Promise<boolean> {\n const local = readLocalWishlist(hostId)\n const has = local.includes(productId)\n const next = has\n ? local.filter((id) => id !== productId)\n : [...local, productId]\n writeLocalWishlist(hostId, next)\n // Best-effort member sync — 401 just means guest.\n void siteFetch('/api/membership/wishlist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n action: has ? 'remove' : 'add',\n productId,\n }),\n }).catch(() => undefined)\n window.dispatchEvent(new Event(WISHLIST_UPDATED_EVENT))\n return !has\n}\n\nexport interface WishlistProps {\n heading?: string\n emptyText?: string\n}\n\ninterface CatalogItem {\n id: string\n name: string\n slug: string\n priceUsd: number\n /** The cheapest variant's own prices per currency (AGL-4248). */\n fixedPrices?: Record<string, number>\n imageUrl?: string\n soldOut: boolean\n /** Listed before it has a price (AGL-3676). */\n priceComingSoon?: boolean\n}\n\n/**\n * Wishlist block (AGL-297): renders the saved products (member doc when\n * signed in — merging any guest list — else localStorage) as cards\n * linking to their PDPs, with remove buttons.\n */\nconst Wishlist = forwardRef<HTMLDivElement, WishlistProps>((props, ref) => {\n const { heading, emptyText, ...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 // In the shopper's currency (AGL-4248), like every other price on the store.\n const shopper = useShopperCurrency()\n const [items, setItems] = useState<CatalogItem[] | null>(null)\n\n const refresh = useCallback(async () => {\n if (!hostId) return\n let productIds = readLocalWishlist(hostId)\n try {\n // Merge the guest list into the member doc; response is canonical.\n const response = await siteFetch('/api/membership/wishlist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, action: 'merge', productIds }),\n })\n if (response.ok) {\n const payload = await response.json()\n productIds = payload?.productIds ?? productIds\n writeLocalWishlist(hostId, productIds)\n }\n } catch {\n // Guest path.\n }\n if (productIds.length === 0) return setItems([])\n try {\n const response = await fetch(\n `/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}` +\n `&ids=${encodeURIComponent(productIds.join(','))}&limit=100`,\n )\n const payload = await response.json()\n setItems(payload?.items ?? [])\n } catch {\n setItems([])\n }\n }, [hostId, siteFetch])\n\n useEffect(() => {\n void refresh()\n const handler = () => void refresh()\n window.addEventListener(WISHLIST_UPDATED_EVENT, handler)\n return () => window.removeEventListener(WISHLIST_UPDATED_EVENT, handler)\n }, [refresh])\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 {'Wishlist — saved products render here'}\n </Box>\n )\n }\n\n return (\n <Box ref={ref} {...rest}>\n {heading ? (\n <Typography variant=\"h5\" gutterBottom>\n {heading}\n </Typography>\n ) : null}\n {items && items.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {emptyText || 'Nothing saved yet — tap the heart on any product.'}\n </Typography>\n ) : (\n <Box\n sx={{\n display: 'grid',\n gap: 2,\n gridTemplateColumns: {\n xs: 'repeat(2, 1fr)',\n md: 'repeat(4, 1fr)',\n },\n }}\n >\n {(items ?? []).map((item) => {\n // AGL-1726: resolved BEFORE the guard — see the note in\n // `product-detail.tsx`.\n const imageUrl = Aglyn.siteRelativeMediaSrc(item.imageUrl, {\n hostId,\n })\n return (\n <Card key={item.id} variant=\"outlined\">\n <CardActionArea href={`/products/${item.slug}`}>\n {imageUrl ? (\n <CardMedia\n component=\"img\"\n image={imageUrl}\n alt={item.name}\n sx={{ height: 120, objectFit: 'cover' }}\n {...storeImageSizing(imageUrl, gridImageSizes(4, 2))}\n // Deferred (AGL-2486), same reasoning as the product\n // grid: one image per saved item, none of them the lead.\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : (\n <Box sx={{ height: 120, bgcolor: 'action.hover' }} />\n )}\n <CardContent sx={{ pb: 1 }}>\n <Typography variant=\"body2\" noWrap>\n {item.name}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {item.soldOut\n ? 'Sold out'\n : item.priceComingSoon\n ? 'Price coming soon'\n : shopper.formatVariant({ priceUsd: item.priceUsd, fixedPrices: item.fixedPrices })}\n </Typography>\n </CardContent>\n </CardActionArea>\n <Button\n size=\"small\"\n color=\"error\"\n fullWidth\n onClick={() => void toggleWishlist(hostId, item.id, siteFetch)}\n >\n {'Remove'}\n </Button>\n </Card>\n )\n })}\n </Box>\n )}\n </Box>\n )\n})\nWishlist.displayName = 'AglynWishlist'\n\nexport const schema: Aglyn.ComponentSchema<WishlistProps> = {\n $id: ID,\n pluginId: BUNDLE_ID,\n displayName: 'Wishlist',\n description: 'Products a visitor saved, linking back to their pages.',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiHeartOutline.path, sx: { color: '#2e7d32' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'heading',\n label: 'Heading',\n description: 'Shown above the saved products.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'emptyText',\n label: 'Empty text',\n description: 'Copy when nothing is saved.',\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: 'Wishlist',\n pluginId: BUNDLE_ID,\n description: 'Saved products with links back to their pages',\n category: Aglyn.ComponentCategory.COMMERCE,\n icon: { path: mdiHeartOutline.path, sx: { color: '#2e7d32' } },\n data: {\n $id: null,\n componentId: ID,\n pluginId: BUNDLE_ID,\n props: { heading: 'Your wishlist' },\n },\n },\n]\n\nexport default Wishlist\n"],"names":["Aglyn","mdiHeartOutline","Box","Button","Card","CardActionArea","CardContent","CardMedia","Typography","forwardRef","useCallback","useEffect","useState","BUNDLE_ID","generatePresetId","useShopperCurrency","gridImageSizes","storeImageSizing","ID","WISHLIST_UPDATED_EVENT","storageKey","hostId","readLocalWishlist","raw","window","localStorage","getItem","JSON","parse","slice","writeLocalWishlist","productIds","setItem","stringify","toggleWishlist","productId","siteFetch","fetch","local","has","includes","next","filter","id","method","headers","body","action","catch","undefined","dispatchEvent","Event","Wishlist","props","ref","heading","emptyText","rest","nodeSx","Array","isArray","useSite","useSiteFetch","shopper","items","setItems","refresh","response","ok","payload","json","length","encodeURIComponent","join","handler","addEventListener","removeEventListener","sx","p","border","borderColor","borderRadius","color","fontSize","fontFamily","variant","gutterBottom","display","gap","gridTemplateColumns","xs","md","map","item","imageUrl","siteRelativeMediaSrc","href","slug","component","image","alt","name","height","objectFit","DEFERRED_IMAGE_ATTRIBUTES","bgcolor","pb","noWrap","soldOut","priceComingSoon","formatVariant","priceUsd","fixedPrices","size","fullWidth","onClick","displayName","schema","$id","pluginId","description","category","ComponentCategory","COMMERCE","icon","path","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","label","FieldComponentType","TEXT_FIELD","presets","type","NodeType","PRESET","data","componentId"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,eAAe,QAAQ,yBAAwB;AACxD,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACpE,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,gBAAgB,QAAQ,iCAA6B;AAC9D,SAASC,kBAAkB,QAAQ,wBAAoB;A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AM;QAC3BrB,aAAa;QACbG,UAAU1G;QACV2G,aAAa;QACbC,UAAUzH,MAAM0H,iBAAiB,CAACC,QAAQ;QAC1CC,MAAM;YAAEC,MAAM5H,gBAAgB4H,IAAI;YAAEhD,IAAI;gBAAEK,OAAO;YAAU;QAAE;QAC7DwD,MAAM;YACJpB,KAAK;YACLqB,aAAazH;YACbqG,UAAU1G;YACVwC,OAAO;gBAAEE,SAAS;YAAgB;QACpC;IACF;CACD,CAAA;AAED,eAAeH,SAAQ"}
|
|
@@ -25,6 +25,7 @@ import { registerCustomerDisplayVerifier } from "@aglyn/aglyn/plugin-manager/plu
|
|
|
25
25
|
import { registerPluginEventHandler } from "@aglyn/aglyn/plugin-manager/plugin-events";
|
|
26
26
|
import { registerPluginSearchSources } from "@aglyn/aglyn/plugin-manager/plugin-search-sources";
|
|
27
27
|
import { registerPluginConsoleCron } from "@aglyn/aglyn/plugin-manager/plugin-console-crons";
|
|
28
|
+
import { registerPluginSiteCreateAnswers } from "@aglyn/aglyn/plugin-manager/plugin-site-create-answers";
|
|
28
29
|
import { COMMERCE_SERVER_SEARCH_SOURCES } from "./model/commerce-server-search-sources.js";
|
|
29
30
|
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
30
31
|
import { ORDER_HISTORY_CONTRACT } from "./model/order-history.js";
|
|
@@ -51,6 +52,15 @@ import { registerCommerceTransferResources } from "./transfer/register-transfer-
|
|
|
51
52
|
* descriptions when the document is first built. Registering again replaces
|
|
52
53
|
* this plugin's own entries.
|
|
53
54
|
*/ export function registerCommerceConsoleServerDeclarations() {
|
|
55
|
+
// "Do you charge sales tax?" from Create site (AGL-4061): saved on the new
|
|
56
|
+
// store as the Taxes editor saves it. Loaded with the first answer.
|
|
57
|
+
registerPluginSiteCreateAnswers({
|
|
58
|
+
apply: async (answer, site)=>{
|
|
59
|
+
await (await import("./server/new-store-tax.js")).applyNewStoreTaxAnswer(answer, site);
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
pluginId: BUNDLE_ID
|
|
63
|
+
});
|
|
54
64
|
// Files a customer attached to an answer on a quote and never sent
|
|
55
65
|
// (AGL-4096): deleted a day after their latest upload, on the same tick as
|
|
56
66
|
// the forms plugin's sweep of forms never sent.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/declarations.console-server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The registry's own module, not the data layer's barrel: boot needs the\n// registry, not the whole server surface.\nimport { registerApiV1SiteResource } from '@aglyn/tenant-data-admin/server/api-v1-resources'\nimport { registerPluginOrgEraser } from '@aglyn/aglyn/plugin-manager/plugin-org-erasure'\nimport { registerPluginPersonEraser } from '@aglyn/aglyn/plugin-manager/plugin-person-erasure'\nimport { registerPluginUserEraser } from '@aglyn/aglyn/plugin-manager/plugin-user-erasure'\nimport { registerPluginService } from '@aglyn/aglyn/plugin-manager/plugin-services'\nimport { registerClosureNoticeSource } from '@aglyn/aglyn/plugin-manager/plugin-closure-notices'\nimport { registerCustomerDisplayVerifier } from '@aglyn/aglyn/plugin-manager/plugin-customer-display-verifier'\nimport { registerPluginEventHandler } from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport { registerPluginSearchSources } from '@aglyn/aglyn/plugin-manager/plugin-search-sources'\nimport { registerPluginConsoleCron } from '@aglyn/aglyn/plugin-manager/plugin-console-crons'\nimport { COMMERCE_SERVER_SEARCH_SOURCES } from './model/commerce-server-search-sources'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { ORDER_HISTORY_CONTRACT } from './model/order-history'\nimport { parsePosHardwareInPersonConfig } from './model/pos-hardware'\nimport { registerCommerceTransferResources } from './transfer/register-transfer-resources'\n\n/**\n * The commerce plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. The tenant runtime registers none of it.\n *\n * It serves a site's products and orders on the customer REST API,\n * `/v1/sites/{siteId}/products/…` and `/v1/sites/{siteId}/orders/…`: the\n * console's router owns the pipeline in front — the key, the plan's API\n * access, the quota, the rate limit, the error envelope — and the site's\n * ownership, and hands every request under each resource here.\n *\n * No plan feature is named on the registrations, though both need\n * `commerce`: the handlers ask the key's scope FIRST and the plan second\n * (AGL-900, AGL-1928), so a key without the scope is told about the scope\n * whatever plan its organization is on, and the router would ask in the\n * opposite order.\n *\n * Light at boot: the handlers are imported with their first request and the\n * descriptions when the document is first built. Registering again replaces\n * this plugin's own entries.\n */\nexport function registerCommerceConsoleServerDeclarations(): void {\n // Files a customer attached to an answer on a quote and never sent\n // (AGL-4096): deleted a day after their latest upload, on the same tick as\n // the forms plugin's sweep of forms never sent.\n registerPluginConsoleCron(\n {\n id: 'commerce-quote-upload-sweep',\n label: 'Unsent quote files',\n drives:\n 'Deletes the files a customer attached to an answer on a quote and never sent, a day after the last one went up. If it stops, those files stay in the site’s private storage.',\n run: async (context) => {\n const { defaultQuoteUploadSweepDeps, sweepQuoteUploads } = await import('./server/quote-upload-sweep')\n return sweepQuoteUploads(defaultQuoteUploadSweepDeps(), context)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of a person erasure (AGL-2623, AGL-3080): every order the\n // person placed keeps its amounts, with the buyer taken off it. Required,\n // and loaded with the first erasure.\n registerPluginPersonEraser(\n async (request) => (await import('./server/person-eraser')).commercePersonEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of an ACCOUNT erasure (AGL-4038): every POS hardware\n // order the person placed that has not shipped is canceled and refunded in\n // full, then every one keeps its amounts and its tax region, with the\n // buyer taken off it. Loaded with the first erasure.\n registerPluginUserEraser(\n async (request) => (await import('./server/pos-hardware-user-eraser')).posHardwareUserEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of a WORKSPACE erasure (AGL-4038): every hardware order\n // the workspace bought that has not shipped is canceled and refunded in\n // full before the erasure deletes it, and the buyer and staff are told.\n // Never fails the erasure. Loaded with the first erasure.\n registerPluginOrgEraser(\n async (request) => (await import('./server/pos-hardware-closure')).posHardwareOrgEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // A workspace erasure turns 4G off at Stripe for every one of its stores\n // that had it (AGL-4038), so the platform stops paying for readers nobody\n // will be charged for. Never fails the erasure. Loaded with the first one.\n registerPluginOrgEraser(\n async (request) => (await import('./server/pos-cellular-billing')).posCellularOrgEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // …and says so BEFORE the closure (AGL-4038): the delete-workspace and\n // close-account screens list the unshipped hardware orders a closure will\n // cancel and refund. Loaded with the first screen that asks.\n registerClosureNoticeSource(\n {\n notices: async (subject) =>\n (await import('./server/pos-hardware-closure-notices')).posHardwareClosureNoticeSource.notices(subject),\n },\n { pluginId: BUNDLE_ID },\n )\n // A card reader bought in person before its buyer had a workspace\n // (AGL-4038) joins the workspace they create, by their account or their\n // verified address. Loaded with the first workspace created while the\n // in-person sale is on.\n registerPluginEventHandler(\n 'org.created',\n async (payload) => {\n const config = parsePosHardwareInPersonConfig(process.env)\n if (!config) return\n const { claimPosHardwareForNewWorkspace } = await import('./server/pos-hardware-attach')\n await claimPosHardwareForNewWorkspace({\n config,\n orgId: payload.orgId,\n ownerUid: payload.owner.uid,\n ownerEmail: payload.owner.email,\n emailVerified: payload.owner.emailVerified,\n })\n },\n { pluginId: BUNDLE_ID },\n )\n // Who a paired customer display is (AGL-4042), for another plugin's\n // server acting for the screen the register put on it: the display's own\n // token is the credential. Loaded with the first screen that asks.\n registerCustomerDisplayVerifier(\n { verify: async (credential) => (await import('./server/pos-display')).verifyPosCustomerDisplay(credential) },\n { pluginId: BUNDLE_ID },\n )\n // A site's earlier orders, for a plugin that reads history behind the\n // order events (AGL-3614); the reader is loaded with the first page asked.\n registerPluginService(\n ORDER_HISTORY_CONTRACT,\n { listOrders: async (request) => (await import('./server/order-history')).listOrderHistory(request) },\n { pluginId: BUNDLE_ID },\n )\n registerApiV1SiteResource(\n 'products',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/orders-and-products')).handleProducts(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).PRODUCTS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n registerApiV1SiteResource(\n 'orders',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/orders-and-products')).handleOrders(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).ORDERS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n // Products, categories, orders, discounts, coupons and gift cards on the\n // import wizard and the export dialog (AGL-3531): the transfer routes are\n // the console's alone, so they register here.\n registerCommerceTransferResources()\n // What the native apps' one box finds in a store (AGL-3943): products and\n // orders, each under its own plan flag and, for orders, the site role that\n // reads them.\n registerPluginSearchSources(COMMERCE_SERVER_SEARCH_SOURCES, { pluginId: BUNDLE_ID })\n}\n"],"names":["registerApiV1SiteResource","registerPluginOrgEraser","registerPluginPersonEraser","registerPluginUserEraser","registerPluginService","registerClosureNoticeSource","registerCustomerDisplayVerifier","registerPluginEventHandler","registerPluginSearchSources","registerPluginConsoleCron","COMMERCE_SERVER_SEARCH_SOURCES","BUNDLE_ID","ORDER_HISTORY_CONTRACT","parsePosHardwareInPersonConfig","registerCommerceTransferResources","registerCommerceConsoleServerDeclarations","id","label","drives","run","context","defaultQuoteUploadSweepDeps","sweepQuoteUploads","pluginId","request","commercePersonEraser","posHardwareUserEraser","posHardwareOrgEraser","posCellularOrgEraser","notices","subject","posHardwareClosureNoticeSource","payload","config","process","env","claimPosHardwareForNewWorkspace","orgId","ownerUid","owner","uid","ownerEmail","email","emailVerified","verify","credential","verifyPosCustomerDisplay","listOrders","listOrderHistory","handle","args","handleProducts","describe","PRODUCTS_API_V1_DESCRIPTION","handleOrders","ORDERS_API_V1_DESCRIPTION"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,yEAAyE;AACzE,0CAA0C;AAC1C,SAASA,yBAAyB,QAAQ,mDAAkD;AAC5F,SAASC,uBAAuB,QAAQ,iDAAgD;AACxF,SAASC,0BAA0B,QAAQ,oDAAmD;AAC9F,SAASC,wBAAwB,QAAQ,kDAAiD;AAC1F,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,2BAA2B,QAAQ,qDAAoD;AAChG,SAASC,+BAA+B,QAAQ,+DAA8D;AAC9G,SAASC,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,2BAA2B,QAAQ,oDAAmD;AAC/F,SAASC,yBAAyB,QAAQ,mDAAkD;AAC5F,SAASC,8BAA8B,QAAQ,4CAAwC;AACvF,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,sBAAsB,QAAQ,2BAAuB;AAC9D,SAASC,8BAA8B,QAAQ,0BAAsB;AACrE,SAASC,iCAAiC,QAAQ,4CAAwC;AAE1F;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASC;IACd,mEAAmE;IACnE,2EAA2E;IAC3E,gDAAgD;IAChDN,0BACE;QACEO,IAAI;QACJC,OAAO;QACPC,QACE;QACFC,KAAK,OAAOC;YACV,MAAM,EAAEC,2BAA2B,EAAEC,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC;YACxE,OAAOA,kBAAkBD,+BAA+BD;QAC1D;IACF,GACA;QAAEG,UAAUZ;IAAU;IAExB,6EAA6E;IAC7E,0EAA0E;IAC1E,qCAAqC;IACrCT,2BACE,OAAOsB,UAAY,AAAC,CAAA,MAAM,MAAM,CAAC,4BAAwB,EAAGC,oBAAoB,CAACD,UACjF;QAAED,UAAUZ;IAAU;IAExB,wEAAwE;IACxE,2EAA2E;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AwB,CAACD;IAAY,GAC5G;QAAEtB,UAAUZ;IAAU;IAExB,sEAAsE;IACtE,2EAA2E;IAC3EP,sBACEQ,wBACA;QAAEmC,YAAY,OAAOvB,UAAY,AAAC,CAAA,MAAM,MAAM,CAAC,4BAAwB,EAAGwB,gBAAgB,CAACxB;IAAS,GACpG;QAAED,UAAUZ;IAAU;IAExBX,0BACE,YACA;QACEiD,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGC,cAAc,IAAID;QAC1EE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGC,2BAA2B;IACzE,GACA;QAAE9B,UAAUZ;IAAU;IAExBX,0BACE,UACA;QACEiD,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGI,YAAY,IAAIJ;QACxEE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGG,yBAAyB;IACvE,GACA;QAAEhC,UAAUZ;IAAU;IAExB,yEAAyE;IACzE,0EAA0E;IAC1E,8CAA8C;IAC9CG;IACA,0EAA0E;IAC1E,2EAA2E;IAC3E,cAAc;IACdN,4BAA4BE,gCAAgC;QAAEa,UAAUZ;IAAU;AACpF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/declarations.console-server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The registry's own module, not the data layer's barrel: boot needs the\n// registry, not the whole server surface.\nimport { registerApiV1SiteResource } from '@aglyn/tenant-data-admin/server/api-v1-resources'\nimport { registerPluginOrgEraser } from '@aglyn/aglyn/plugin-manager/plugin-org-erasure'\nimport { registerPluginPersonEraser } from '@aglyn/aglyn/plugin-manager/plugin-person-erasure'\nimport { registerPluginUserEraser } from '@aglyn/aglyn/plugin-manager/plugin-user-erasure'\nimport { registerPluginService } from '@aglyn/aglyn/plugin-manager/plugin-services'\nimport { registerClosureNoticeSource } from '@aglyn/aglyn/plugin-manager/plugin-closure-notices'\nimport { registerCustomerDisplayVerifier } from '@aglyn/aglyn/plugin-manager/plugin-customer-display-verifier'\nimport { registerPluginEventHandler } from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport { registerPluginSearchSources } from '@aglyn/aglyn/plugin-manager/plugin-search-sources'\nimport { registerPluginConsoleCron } from '@aglyn/aglyn/plugin-manager/plugin-console-crons'\nimport { registerPluginSiteCreateAnswers } from '@aglyn/aglyn/plugin-manager/plugin-site-create-answers'\nimport { COMMERCE_SERVER_SEARCH_SOURCES } from './model/commerce-server-search-sources'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { ORDER_HISTORY_CONTRACT } from './model/order-history'\nimport { parsePosHardwareInPersonConfig } from './model/pos-hardware'\nimport { registerCommerceTransferResources } from './transfer/register-transfer-resources'\n\n/**\n * The commerce plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. The tenant runtime registers none of it.\n *\n * It serves a site's products and orders on the customer REST API,\n * `/v1/sites/{siteId}/products/…` and `/v1/sites/{siteId}/orders/…`: the\n * console's router owns the pipeline in front — the key, the plan's API\n * access, the quota, the rate limit, the error envelope — and the site's\n * ownership, and hands every request under each resource here.\n *\n * No plan feature is named on the registrations, though both need\n * `commerce`: the handlers ask the key's scope FIRST and the plan second\n * (AGL-900, AGL-1928), so a key without the scope is told about the scope\n * whatever plan its organization is on, and the router would ask in the\n * opposite order.\n *\n * Light at boot: the handlers are imported with their first request and the\n * descriptions when the document is first built. Registering again replaces\n * this plugin's own entries.\n */\nexport function registerCommerceConsoleServerDeclarations(): void {\n // \"Do you charge sales tax?\" from Create site (AGL-4061): saved on the new\n // store as the Taxes editor saves it. Loaded with the first answer.\n registerPluginSiteCreateAnswers(\n {\n apply: async (answer, site) => {\n await (await import('./server/new-store-tax')).applyNewStoreTaxAnswer(answer, site)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // Files a customer attached to an answer on a quote and never sent\n // (AGL-4096): deleted a day after their latest upload, on the same tick as\n // the forms plugin's sweep of forms never sent.\n registerPluginConsoleCron(\n {\n id: 'commerce-quote-upload-sweep',\n label: 'Unsent quote files',\n drives:\n 'Deletes the files a customer attached to an answer on a quote and never sent, a day after the last one went up. If it stops, those files stay in the site’s private storage.',\n run: async (context) => {\n const { defaultQuoteUploadSweepDeps, sweepQuoteUploads } = await import('./server/quote-upload-sweep')\n return sweepQuoteUploads(defaultQuoteUploadSweepDeps(), context)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of a person erasure (AGL-2623, AGL-3080): every order the\n // person placed keeps its amounts, with the buyer taken off it. Required,\n // and loaded with the first erasure.\n registerPluginPersonEraser(\n async (request) => (await import('./server/person-eraser')).commercePersonEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of an ACCOUNT erasure (AGL-4038): every POS hardware\n // order the person placed that has not shipped is canceled and refunded in\n // full, then every one keeps its amounts and its tax region, with the\n // buyer taken off it. Loaded with the first erasure.\n registerPluginUserEraser(\n async (request) => (await import('./server/pos-hardware-user-eraser')).posHardwareUserEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // Commerce's share of a WORKSPACE erasure (AGL-4038): every hardware order\n // the workspace bought that has not shipped is canceled and refunded in\n // full before the erasure deletes it, and the buyer and staff are told.\n // Never fails the erasure. Loaded with the first erasure.\n registerPluginOrgEraser(\n async (request) => (await import('./server/pos-hardware-closure')).posHardwareOrgEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // A workspace erasure turns 4G off at Stripe for every one of its stores\n // that had it (AGL-4038), so the platform stops paying for readers nobody\n // will be charged for. Never fails the erasure. Loaded with the first one.\n registerPluginOrgEraser(\n async (request) => (await import('./server/pos-cellular-billing')).posCellularOrgEraser(request),\n { pluginId: BUNDLE_ID },\n )\n // …and says so BEFORE the closure (AGL-4038): the delete-workspace and\n // close-account screens list the unshipped hardware orders a closure will\n // cancel and refund. Loaded with the first screen that asks.\n registerClosureNoticeSource(\n {\n notices: async (subject) =>\n (await import('./server/pos-hardware-closure-notices')).posHardwareClosureNoticeSource.notices(subject),\n },\n { pluginId: BUNDLE_ID },\n )\n // A card reader bought in person before its buyer had a workspace\n // (AGL-4038) joins the workspace they create, by their account or their\n // verified address. Loaded with the first workspace created while the\n // in-person sale is on.\n registerPluginEventHandler(\n 'org.created',\n async (payload) => {\n const config = parsePosHardwareInPersonConfig(process.env)\n if (!config) return\n const { claimPosHardwareForNewWorkspace } = await import('./server/pos-hardware-attach')\n await claimPosHardwareForNewWorkspace({\n config,\n orgId: payload.orgId,\n ownerUid: payload.owner.uid,\n ownerEmail: payload.owner.email,\n emailVerified: payload.owner.emailVerified,\n })\n },\n { pluginId: BUNDLE_ID },\n )\n // Who a paired customer display is (AGL-4042), for another plugin's\n // server acting for the screen the register put on it: the display's own\n // token is the credential. Loaded with the first screen that asks.\n registerCustomerDisplayVerifier(\n { verify: async (credential) => (await import('./server/pos-display')).verifyPosCustomerDisplay(credential) },\n { pluginId: BUNDLE_ID },\n )\n // A site's earlier orders, for a plugin that reads history behind the\n // order events (AGL-3614); the reader is loaded with the first page asked.\n registerPluginService(\n ORDER_HISTORY_CONTRACT,\n { listOrders: async (request) => (await import('./server/order-history')).listOrderHistory(request) },\n { pluginId: BUNDLE_ID },\n )\n registerApiV1SiteResource(\n 'products',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/orders-and-products')).handleProducts(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).PRODUCTS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n registerApiV1SiteResource(\n 'orders',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/orders-and-products')).handleOrders(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).ORDERS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n // Products, categories, orders, discounts, coupons and gift cards on the\n // import wizard and the export dialog (AGL-3531): the transfer routes are\n // the console's alone, so they register here.\n registerCommerceTransferResources()\n // What the native apps' one box finds in a store (AGL-3943): products and\n // orders, each under its own plan flag and, for orders, the site role that\n // reads them.\n registerPluginSearchSources(COMMERCE_SERVER_SEARCH_SOURCES, { pluginId: BUNDLE_ID })\n}\n"],"names":["registerApiV1SiteResource","registerPluginOrgEraser","registerPluginPersonEraser","registerPluginUserEraser","registerPluginService","registerClosureNoticeSource","registerCustomerDisplayVerifier","registerPluginEventHandler","registerPluginSearchSources","registerPluginConsoleCron","registerPluginSiteCreateAnswers","COMMERCE_SERVER_SEARCH_SOURCES","BUNDLE_ID","ORDER_HISTORY_CONTRACT","parsePosHardwareInPersonConfig","registerCommerceTransferResources","registerCommerceConsoleServerDeclarations","apply","answer","site","applyNewStoreTaxAnswer","pluginId","id","label","drives","run","context","defaultQuoteUploadSweepDeps","sweepQuoteUploads","request","commercePersonEraser","posHardwareUserEraser","posHardwareOrgEraser","posCellularOrgEraser","notices","subject","posHardwareClosureNoticeSource","payload","config","process","env","claimPosHardwareForNewWorkspace","orgId","ownerUid","owner","uid","ownerEmail","email","emailVerified","verify","credential","verifyPosCustomerDisplay","listOrders","listOrderHistory","handle","args","handleProducts","describe","PRODUCTS_API_V1_DESCRIPTION","handleOrders","ORDERS_API_V1_DESCRIPTION"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,yEAAyE;AACzE,0CAA0C;AAC1C,SAASA,yBAAyB,QAAQ,mDAAkD;AAC5F,SAASC,uBAAuB,QAAQ,iDAAgD;AACxF,SAASC,0BAA0B,QAAQ,oDAAmD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BACES,wBACA;QAAEuC,YAAY,OAAOvB,UAAY,AAAC,CAAA,MAAM,MAAM,CAAC,4BAAwB,EAAGwB,gBAAgB,CAACxB;IAAS,GACpG;QAAER,UAAUT;IAAU;IAExBZ,0BACE,YACA;QACEsD,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGC,cAAc,IAAID;QAC1EE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGC,2BAA2B;IACzE,GACA;QAAErC,UAAUT;IAAU;IAExBZ,0BACE,UACA;QACEsD,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGI,YAAY,IAAIJ;QACxEE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGG,yBAAyB;IACvE,GACA;QAAEvC,UAAUT;IAAU;IAExB,yEAAyE;IACzE,0EAA0E;IAC1E,8CAA8C;IAC9CG;IACA,0EAA0E;IAC1E,2EAA2E;IAC3E,cAAc;IACdP,4BAA4BG,gCAAgC;QAAEU,UAAUT;IAAU;AACpF"}
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
import { type TaxSettings } from './commerce-tax';
|
|
18
|
+
/**
|
|
19
|
+
* Whether anyone has answered how the store handles sales tax, from
|
|
20
|
+
* `hosts/{hostId}/settings/store.tax`. A product's own exemption is not the
|
|
21
|
+
* store's answer, so it is not asked here.
|
|
22
|
+
*/
|
|
23
|
+
export declare function storeTaxDecided(settings: TaxSettings | undefined | null): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Why the register refuses every sale although the store has decided, or
|
|
26
|
+
* null when it can take one: the in-person refusal `pos-order.ts` makes
|
|
27
|
+
* (AGL-2145), Stripe Tax at the register or Manual with no store address, in
|
|
28
|
+
* that refusal's own words. Null for an undecided store, which
|
|
29
|
+
* {@link storeTaxDecided} answers.
|
|
30
|
+
*/
|
|
31
|
+
export declare function registerTaxRefusal(settings: TaxSettings | undefined | null): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Who may decide it: the permission that governs writing the store's tax
|
|
34
|
+
* settings. `hosts/{hostId}/settings/store` is written by the console's Taxes
|
|
35
|
+
* card and the app's Taxes screen under the site catch-all rule,
|
|
36
|
+
* `canWriteHostContent` ("Edit the site", `site.edit`).
|
|
37
|
+
*/
|
|
38
|
+
export declare const STORE_TAX_DECIDE_PERMISSION = "site.edit";
|
|
39
|
+
/** Whether a member's permissions, as resolved for the site, let them decide. */
|
|
40
|
+
export declare function mayDecideStoreTax(permissions: Readonly<Record<string, boolean | undefined>> | null | undefined): boolean;
|
|
41
|
+
/** The action that opens Taxes. */
|
|
42
|
+
export declare const DECIDE_SALES_TAX_LABEL = "Decide sales tax";
|
|
43
|
+
/** What someone who may not decide is told, wherever they meet it. */
|
|
44
|
+
export declare const ASK_OWNER_SALES_TAX_TEXT = "Ask the store owner to set up sales tax.";
|
|
45
|
+
/** The register's sentence while undecided: the refusal's own words, said before any tap. */
|
|
46
|
+
export declare const REGISTER_TAX_UNDECIDED_TEXT = "This store has not set up sales tax yet, so the register can\u2019t take a sale.";
|
|
47
|
+
/** What the register says, and whether it offers {@link DECIDE_SALES_TAX_LABEL}. */
|
|
48
|
+
export interface RegisterTaxNotice {
|
|
49
|
+
text: string;
|
|
50
|
+
/** The person may decide: the notice carries "Decide sales tax". */
|
|
51
|
+
decides: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The register's notice above Charge, or null once the store has decided.
|
|
55
|
+
* `taxDecided` absent (an older console that does not say) draws nothing:
|
|
56
|
+
* the server's refusal still stands behind every sale.
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerTaxNotice(input: {
|
|
59
|
+
taxDecided: boolean | null | undefined;
|
|
60
|
+
canDecide: boolean;
|
|
61
|
+
/** Decided, but the register refuses it: {@link registerTaxRefusal}'s sentence. */
|
|
62
|
+
refusal?: string | null;
|
|
63
|
+
}): RegisterTaxNotice | null;
|
|
64
|
+
/**
|
|
65
|
+
* The Card readers screen's "Sales tax" row: Ready once decided; Needed
|
|
66
|
+
* before, with what to do. It is information only: card readiness and
|
|
67
|
+
* Tap to Pay never read it.
|
|
68
|
+
*/
|
|
69
|
+
export interface SalesTaxRowState {
|
|
70
|
+
chip: 'Ready' | 'Needed';
|
|
71
|
+
detail: string | null;
|
|
72
|
+
/** Offers "Decide sales tax". */
|
|
73
|
+
decides: boolean;
|
|
74
|
+
}
|
|
75
|
+
export declare const SALES_TAX_ROW_TITLE = "Sales tax";
|
|
76
|
+
export declare function salesTaxRowState(input: {
|
|
77
|
+
taxDecided: boolean;
|
|
78
|
+
canDecide: boolean;
|
|
79
|
+
refusal?: string | null;
|
|
80
|
+
}): SalesTaxRowState;
|
|
81
|
+
/** "Do you charge sales tax?": the three answers, the Taxes editor's three modes. */
|
|
82
|
+
export type NewStoreTaxChoice = 'none' | 'manual' | 'stripe';
|
|
83
|
+
/** What the question collected. Unanswered is "decide later": nothing is written. */
|
|
84
|
+
export interface NewStoreTaxAnswer {
|
|
85
|
+
choice: NewStoreTaxChoice;
|
|
86
|
+
/** A fixed rate: the percentage, as typed. */
|
|
87
|
+
pct?: number | string | null;
|
|
88
|
+
/** A fixed rate: where the store sells from, ISO-3166 alpha-2. */
|
|
89
|
+
country?: string | null;
|
|
90
|
+
/** A fixed rate: the state or region, optional. */
|
|
91
|
+
state?: string | null;
|
|
92
|
+
}
|
|
93
|
+
export declare const NEW_STORE_TAX_COPY: {
|
|
94
|
+
readonly question: "Do you charge sales tax?";
|
|
95
|
+
readonly lede: "Your store can’t take a sale until this is decided. You can change it any time in Products → Taxes.";
|
|
96
|
+
readonly none: "No";
|
|
97
|
+
readonly noneHelp: "This store adds no sales tax to any order.";
|
|
98
|
+
readonly manual: "A fixed rate";
|
|
99
|
+
readonly manualHelp: "One rate, charged on sales in your country or state.";
|
|
100
|
+
readonly stripe: "Stripe Tax";
|
|
101
|
+
/**
|
|
102
|
+
* The register refuses Stripe Tax in person (`STOREFRONT_TAX_POS_STRIPE_MESSAGE`),
|
|
103
|
+
* so the option says so, in that refusal's words.
|
|
104
|
+
*/
|
|
105
|
+
readonly stripeHelp: string;
|
|
106
|
+
readonly rate: "Rate %";
|
|
107
|
+
readonly country: "Country";
|
|
108
|
+
readonly state: "State";
|
|
109
|
+
readonly later: "Not sure yet? Leave it, and decide in Products → Taxes before your first sale.";
|
|
110
|
+
};
|
|
111
|
+
/** What is wrong with an answer, in the words the form shows; null when it can be saved. */
|
|
112
|
+
export declare function newStoreTaxProblem(answer: NewStoreTaxAnswer | null | undefined): string | null;
|
|
113
|
+
/**
|
|
114
|
+
* The tax settings an answer saves, as the Taxes editor writes them, or null
|
|
115
|
+
* for no write ("decide later", or an answer that is not one). Reads an
|
|
116
|
+
* untrusted body, so anything it does not recognise is no answer.
|
|
117
|
+
*
|
|
118
|
+
* A fixed rate is the editor's Manual mode: the store's origin, and one rate
|
|
119
|
+
* for that same place (country, and state when given), so the register,
|
|
120
|
+
* which taxes by the store's origin, applies it, and so do online orders to
|
|
121
|
+
* that place.
|
|
122
|
+
*/
|
|
123
|
+
export declare function newStoreTaxSettings(raw: unknown): TaxSettings | null;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { isUsableFlatTaxPct } from "./commerce-tax.js";
|
|
18
|
+
import { storefrontTaxDecision, storefrontTaxMisconfiguration } from "./commerce-tax-decision.js";
|
|
19
|
+
/*==========================================
|
|
20
|
+
* DECIDING SALES TAX BEFORE THE FIRST SALE (AGL-4061)
|
|
21
|
+
*
|
|
22
|
+
* A store that never chose how it handles sales tax has every sale refused
|
|
23
|
+
* (`storefrontTaxDecision` → `undecided`). The refusal stays as the backstop;
|
|
24
|
+
* these rules put the question in front of the store earlier: the Card
|
|
25
|
+
* readers screen's "Sales tax" row, a notice above Charge at the register,
|
|
26
|
+
* the web register, and one question when a site is created.
|
|
27
|
+
*=========================================*/ /**
|
|
28
|
+
* Whether anyone has answered how the store handles sales tax, from
|
|
29
|
+
* `hosts/{hostId}/settings/store.tax`. A product's own exemption is not the
|
|
30
|
+
* store's answer, so it is not asked here.
|
|
31
|
+
*/ export function storeTaxDecided(settings) {
|
|
32
|
+
return storefrontTaxDecision({
|
|
33
|
+
settings
|
|
34
|
+
}).kind !== 'undecided';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Why the register refuses every sale although the store has decided, or
|
|
38
|
+
* null when it can take one: the in-person refusal `pos-order.ts` makes
|
|
39
|
+
* (AGL-2145), Stripe Tax at the register or Manual with no store address, in
|
|
40
|
+
* that refusal's own words. Null for an undecided store, which
|
|
41
|
+
* {@link storeTaxDecided} answers.
|
|
42
|
+
*/ export function registerTaxRefusal(settings) {
|
|
43
|
+
if (!storeTaxDecided(settings)) return null;
|
|
44
|
+
return storefrontTaxMisconfiguration(settings, {
|
|
45
|
+
inPerson: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Who may decide it: the permission that governs writing the store's tax
|
|
50
|
+
* settings. `hosts/{hostId}/settings/store` is written by the console's Taxes
|
|
51
|
+
* card and the app's Taxes screen under the site catch-all rule,
|
|
52
|
+
* `canWriteHostContent` ("Edit the site", `site.edit`).
|
|
53
|
+
*/ export const STORE_TAX_DECIDE_PERMISSION = 'site.edit';
|
|
54
|
+
/** Whether a member's permissions, as resolved for the site, let them decide. */ export function mayDecideStoreTax(permissions) {
|
|
55
|
+
return (permissions == null ? void 0 : permissions[STORE_TAX_DECIDE_PERMISSION]) === true;
|
|
56
|
+
}
|
|
57
|
+
/** The action that opens Taxes. */ export const DECIDE_SALES_TAX_LABEL = 'Decide sales tax';
|
|
58
|
+
/** What someone who may not decide is told, wherever they meet it. */ export const ASK_OWNER_SALES_TAX_TEXT = 'Ask the store owner to set up sales tax.';
|
|
59
|
+
/** The register's sentence while undecided: the refusal's own words, said before any tap. */ export const REGISTER_TAX_UNDECIDED_TEXT = 'This store has not set up sales tax yet, so the register can’t take a sale.';
|
|
60
|
+
/**
|
|
61
|
+
* The register's notice above Charge, or null once the store has decided.
|
|
62
|
+
* `taxDecided` absent (an older console that does not say) draws nothing:
|
|
63
|
+
* the server's refusal still stands behind every sale.
|
|
64
|
+
*/ export function registerTaxNotice(input) {
|
|
65
|
+
if (input.taxDecided === true && input.refusal) return {
|
|
66
|
+
text: input.refusal,
|
|
67
|
+
decides: input.canDecide
|
|
68
|
+
};
|
|
69
|
+
if (input.taxDecided !== false) return null;
|
|
70
|
+
return input.canDecide ? {
|
|
71
|
+
text: `${REGISTER_TAX_UNDECIDED_TEXT} Decide how it handles sales tax first.`,
|
|
72
|
+
decides: true
|
|
73
|
+
} : {
|
|
74
|
+
text: `${REGISTER_TAX_UNDECIDED_TEXT} ${ASK_OWNER_SALES_TAX_TEXT}`,
|
|
75
|
+
decides: false
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export const SALES_TAX_ROW_TITLE = 'Sales tax';
|
|
79
|
+
export function salesTaxRowState(input) {
|
|
80
|
+
if (input.taxDecided && input.refusal) {
|
|
81
|
+
return {
|
|
82
|
+
chip: 'Needed',
|
|
83
|
+
detail: input.refusal,
|
|
84
|
+
decides: input.canDecide
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (input.taxDecided) return {
|
|
88
|
+
chip: 'Ready',
|
|
89
|
+
detail: null,
|
|
90
|
+
decides: false
|
|
91
|
+
};
|
|
92
|
+
return input.canDecide ? {
|
|
93
|
+
chip: 'Needed',
|
|
94
|
+
detail: 'Decide how this store handles sales tax before its first sale.',
|
|
95
|
+
decides: true
|
|
96
|
+
} : {
|
|
97
|
+
chip: 'Needed',
|
|
98
|
+
detail: ASK_OWNER_SALES_TAX_TEXT,
|
|
99
|
+
decides: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export const NEW_STORE_TAX_COPY = {
|
|
103
|
+
question: 'Do you charge sales tax?',
|
|
104
|
+
lede: 'Your store can’t take a sale until this is decided. You can change it any time in Products → Taxes.',
|
|
105
|
+
none: 'No',
|
|
106
|
+
noneHelp: 'This store adds no sales tax to any order.',
|
|
107
|
+
manual: 'A fixed rate',
|
|
108
|
+
manualHelp: 'One rate, charged on sales in your country or state.',
|
|
109
|
+
stripe: 'Stripe Tax',
|
|
110
|
+
/**
|
|
111
|
+
* The register refuses Stripe Tax in person (`STOREFRONT_TAX_POS_STRIPE_MESSAGE`),
|
|
112
|
+
* so the option says so, in that refusal's words.
|
|
113
|
+
*/ stripeHelp: 'Stripe Tax works out the tax for each buyer’s location at checkout. ' + 'The register can’t calculate it for an in-person sale.',
|
|
114
|
+
rate: 'Rate %',
|
|
115
|
+
country: 'Country',
|
|
116
|
+
state: 'State',
|
|
117
|
+
later: 'Not sure yet? Leave it, and decide in Products → Taxes before your first sale.'
|
|
118
|
+
};
|
|
119
|
+
const COUNTRY = /^[A-Z]{2}$/;
|
|
120
|
+
const STATE = /^[A-Z0-9]{1,3}$/;
|
|
121
|
+
const upper = (value)=>String(value != null ? value : '').trim().toUpperCase();
|
|
122
|
+
/** What is wrong with an answer, in the words the form shows; null when it can be saved. */ export function newStoreTaxProblem(answer) {
|
|
123
|
+
var _answer_pct;
|
|
124
|
+
if (!answer || answer.choice !== 'manual') return null;
|
|
125
|
+
const pctText = String((_answer_pct = answer.pct) != null ? _answer_pct : '').trim();
|
|
126
|
+
if (!pctText || !isUsableFlatTaxPct(Number(pctText))) {
|
|
127
|
+
return 'Enter a rate above 0 and up to 100, like 8.25.';
|
|
128
|
+
}
|
|
129
|
+
if (!COUNTRY.test(upper(answer.country))) {
|
|
130
|
+
return 'Enter the two-letter country code, like US.';
|
|
131
|
+
}
|
|
132
|
+
const state = upper(answer.state);
|
|
133
|
+
if (state && !STATE.test(state)) return 'Enter the state code, like TX, or leave it blank.';
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The tax settings an answer saves, as the Taxes editor writes them, or null
|
|
138
|
+
* for no write ("decide later", or an answer that is not one). Reads an
|
|
139
|
+
* untrusted body, so anything it does not recognise is no answer.
|
|
140
|
+
*
|
|
141
|
+
* A fixed rate is the editor's Manual mode: the store's origin, and one rate
|
|
142
|
+
* for that same place (country, and state when given), so the register,
|
|
143
|
+
* which taxes by the store's origin, applies it, and so do online orders to
|
|
144
|
+
* that place.
|
|
145
|
+
*/ export function newStoreTaxSettings(raw) {
|
|
146
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
147
|
+
const answer = raw;
|
|
148
|
+
const choice = answer['choice'];
|
|
149
|
+
if (choice === 'none') return {
|
|
150
|
+
mode: 'none'
|
|
151
|
+
};
|
|
152
|
+
if (choice === 'stripe') return {
|
|
153
|
+
mode: 'stripe'
|
|
154
|
+
};
|
|
155
|
+
if (choice !== 'manual') return null;
|
|
156
|
+
const typed = {
|
|
157
|
+
choice,
|
|
158
|
+
pct: answer['pct'],
|
|
159
|
+
country: answer['country'],
|
|
160
|
+
state: answer['state']
|
|
161
|
+
};
|
|
162
|
+
if (newStoreTaxProblem(typed)) return null;
|
|
163
|
+
const country = upper(typed.country);
|
|
164
|
+
const state = upper(typed.state);
|
|
165
|
+
const pct = Number(String(typed.pct).trim());
|
|
166
|
+
return {
|
|
167
|
+
mode: 'manual',
|
|
168
|
+
origin: _extends({
|
|
169
|
+
country
|
|
170
|
+
}, state ? {
|
|
171
|
+
state
|
|
172
|
+
} : {}),
|
|
173
|
+
rates: [
|
|
174
|
+
_extends({
|
|
175
|
+
country
|
|
176
|
+
}, state ? {
|
|
177
|
+
state
|
|
178
|
+
} : {}, {
|
|
179
|
+
pct
|
|
180
|
+
})
|
|
181
|
+
]
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=commerce-tax-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-tax-step.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isUsableFlatTaxPct, type TaxSettings } from './commerce-tax'\nimport {\n storefrontTaxDecision,\n storefrontTaxMisconfiguration,\n} from './commerce-tax-decision'\n\n/*==========================================\n * DECIDING SALES TAX BEFORE THE FIRST SALE (AGL-4061)\n *\n * A store that never chose how it handles sales tax has every sale refused\n * (`storefrontTaxDecision` → `undecided`). The refusal stays as the backstop;\n * these rules put the question in front of the store earlier: the Card\n * readers screen's \"Sales tax\" row, a notice above Charge at the register,\n * the web register, and one question when a site is created.\n *=========================================*/\n\n/**\n * Whether anyone has answered how the store handles sales tax, from\n * `hosts/{hostId}/settings/store.tax`. A product's own exemption is not the\n * store's answer, so it is not asked here.\n */\nexport function storeTaxDecided(settings: TaxSettings | undefined | null): boolean {\n return storefrontTaxDecision({ settings }).kind !== 'undecided'\n}\n\n/**\n * Why the register refuses every sale although the store has decided, or\n * null when it can take one: the in-person refusal `pos-order.ts` makes\n * (AGL-2145), Stripe Tax at the register or Manual with no store address, in\n * that refusal's own words. Null for an undecided store, which\n * {@link storeTaxDecided} answers.\n */\nexport function registerTaxRefusal(settings: TaxSettings | undefined | null): string | null {\n if (!storeTaxDecided(settings)) return null\n return storefrontTaxMisconfiguration(settings, { inPerson: true })\n}\n\n/**\n * Who may decide it: the permission that governs writing the store's tax\n * settings. `hosts/{hostId}/settings/store` is written by the console's Taxes\n * card and the app's Taxes screen under the site catch-all rule,\n * `canWriteHostContent` (\"Edit the site\", `site.edit`).\n */\nexport const STORE_TAX_DECIDE_PERMISSION = 'site.edit'\n\n/** Whether a member's permissions, as resolved for the site, let them decide. */\nexport function mayDecideStoreTax(\n permissions: Readonly<Record<string, boolean | undefined>> | null | undefined,\n): boolean {\n return permissions?.[STORE_TAX_DECIDE_PERMISSION] === true\n}\n\n/** The action that opens Taxes. */\nexport const DECIDE_SALES_TAX_LABEL = 'Decide sales tax'\n\n/** What someone who may not decide is told, wherever they meet it. */\nexport const ASK_OWNER_SALES_TAX_TEXT = 'Ask the store owner to set up sales tax.'\n\n/** The register's sentence while undecided: the refusal's own words, said before any tap. */\nexport const REGISTER_TAX_UNDECIDED_TEXT =\n 'This store has not set up sales tax yet, so the register can’t take a sale.'\n\n/** What the register says, and whether it offers {@link DECIDE_SALES_TAX_LABEL}. */\nexport interface RegisterTaxNotice {\n text: string\n /** The person may decide: the notice carries \"Decide sales tax\". */\n decides: boolean\n}\n\n/**\n * The register's notice above Charge, or null once the store has decided.\n * `taxDecided` absent (an older console that does not say) draws nothing:\n * the server's refusal still stands behind every sale.\n */\nexport function registerTaxNotice(input: {\n taxDecided: boolean | null | undefined\n canDecide: boolean\n /** Decided, but the register refuses it: {@link registerTaxRefusal}'s sentence. */\n refusal?: string | null\n}): RegisterTaxNotice | null {\n if (input.taxDecided === true && input.refusal) return { text: input.refusal, decides: input.canDecide }\n if (input.taxDecided !== false) return null\n return input.canDecide\n ? { text: `${REGISTER_TAX_UNDECIDED_TEXT} Decide how it handles sales tax first.`, decides: true }\n : { text: `${REGISTER_TAX_UNDECIDED_TEXT} ${ASK_OWNER_SALES_TAX_TEXT}`, decides: false }\n}\n\n/**\n * The Card readers screen's \"Sales tax\" row: Ready once decided; Needed\n * before, with what to do. It is information only: card readiness and\n * Tap to Pay never read it.\n */\nexport interface SalesTaxRowState {\n chip: 'Ready' | 'Needed'\n detail: string | null\n /** Offers \"Decide sales tax\". */\n decides: boolean\n}\n\nexport const SALES_TAX_ROW_TITLE = 'Sales tax'\n\nexport function salesTaxRowState(input: {\n taxDecided: boolean\n canDecide: boolean\n refusal?: string | null\n}): SalesTaxRowState {\n if (input.taxDecided && input.refusal) {\n return { chip: 'Needed', detail: input.refusal, decides: input.canDecide }\n }\n if (input.taxDecided) return { chip: 'Ready', detail: null, decides: false }\n return input.canDecide\n ? { chip: 'Needed', detail: 'Decide how this store handles sales tax before its first sale.', decides: true }\n : { chip: 'Needed', detail: ASK_OWNER_SALES_TAX_TEXT, decides: false }\n}\n\n/*==========================================\n * THE NEW-STORE QUESTION\n *=========================================*/\n\n/** \"Do you charge sales tax?\": the three answers, the Taxes editor's three modes. */\nexport type NewStoreTaxChoice = 'none' | 'manual' | 'stripe'\n\n/** What the question collected. Unanswered is \"decide later\": nothing is written. */\nexport interface NewStoreTaxAnswer {\n choice: NewStoreTaxChoice\n /** A fixed rate: the percentage, as typed. */\n pct?: number | string | null\n /** A fixed rate: where the store sells from, ISO-3166 alpha-2. */\n country?: string | null\n /** A fixed rate: the state or region, optional. */\n state?: string | null\n}\n\nexport const NEW_STORE_TAX_COPY = {\n question: 'Do you charge sales tax?',\n lede: 'Your store can’t take a sale until this is decided. You can change it any time in Products → Taxes.',\n none: 'No',\n noneHelp: 'This store adds no sales tax to any order.',\n manual: 'A fixed rate',\n manualHelp: 'One rate, charged on sales in your country or state.',\n stripe: 'Stripe Tax',\n /**\n * The register refuses Stripe Tax in person (`STOREFRONT_TAX_POS_STRIPE_MESSAGE`),\n * so the option says so, in that refusal's words.\n */\n stripeHelp:\n 'Stripe Tax works out the tax for each buyer’s location at checkout. ' +\n 'The register can’t calculate it for an in-person sale.',\n rate: 'Rate %',\n country: 'Country',\n state: 'State',\n later: 'Not sure yet? Leave it, and decide in Products → Taxes before your first sale.',\n} as const\n\nconst COUNTRY = /^[A-Z]{2}$/\nconst STATE = /^[A-Z0-9]{1,3}$/\n\nconst upper = (value: unknown) =>\n String(value ?? '')\n .trim()\n .toUpperCase()\n\n/** What is wrong with an answer, in the words the form shows; null when it can be saved. */\nexport function newStoreTaxProblem(answer: NewStoreTaxAnswer | null | undefined): string | null {\n if (!answer || answer.choice !== 'manual') return null\n const pctText = String(answer.pct ?? '').trim()\n if (!pctText || !isUsableFlatTaxPct(Number(pctText))) {\n return 'Enter a rate above 0 and up to 100, like 8.25.'\n }\n if (!COUNTRY.test(upper(answer.country))) {\n return 'Enter the two-letter country code, like US.'\n }\n const state = upper(answer.state)\n if (state && !STATE.test(state)) return 'Enter the state code, like TX, or leave it blank.'\n return null\n}\n\n/**\n * The tax settings an answer saves, as the Taxes editor writes them, or null\n * for no write (\"decide later\", or an answer that is not one). Reads an\n * untrusted body, so anything it does not recognise is no answer.\n *\n * A fixed rate is the editor's Manual mode: the store's origin, and one rate\n * for that same place (country, and state when given), so the register,\n * which taxes by the store's origin, applies it, and so do online orders to\n * that place.\n */\nexport function newStoreTaxSettings(raw: unknown): TaxSettings | null {\n if (!raw || typeof raw !== 'object') return null\n const answer = raw as Record<string, unknown>\n const choice = answer['choice']\n if (choice === 'none') return { mode: 'none' }\n if (choice === 'stripe') return { mode: 'stripe' }\n if (choice !== 'manual') return null\n const typed: NewStoreTaxAnswer = {\n choice,\n pct: answer['pct'] as number | string | null,\n country: answer['country'] as string | null,\n state: answer['state'] as string | null,\n }\n if (newStoreTaxProblem(typed)) return null\n const country = upper(typed.country)\n const state = upper(typed.state)\n const pct = Number(String(typed.pct).trim())\n return {\n mode: 'manual',\n origin: { country, ...(state ? { state } : {}) },\n rates: [{ country, ...(state ? { state } : {}), pct }],\n }\n}\n"],"names":["isUsableFlatTaxPct","storefrontTaxDecision","storefrontTaxMisconfiguration","storeTaxDecided","settings","kind","registerTaxRefusal","inPerson","STORE_TAX_DECIDE_PERMISSION","mayDecideStoreTax","permissions","DECIDE_SALES_TAX_LABEL","ASK_OWNER_SALES_TAX_TEXT","REGISTER_TAX_UNDECIDED_TEXT","registerTaxNotice","input","taxDecided","refusal","text","decides","canDecide","SALES_TAX_ROW_TITLE","salesTaxRowState","chip","detail","NEW_STORE_TAX_COPY","question","lede","none","noneHelp","manual","manualHelp","stripe","stripeHelp","rate","country","state","later","COUNTRY","STATE","upper","value","String","trim","toUpperCase","newStoreTaxProblem","answer","choice","pctText","pct","Number","test","newStoreTaxSettings","raw","mode","typed","origin","rates"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,kBAAkB,QAA0B,oBAAgB;AACrE,SACEC,qBAAqB,EACrBC,6BAA6B,QACxB,6BAAyB;AAEhC;;;;;;;;2CAQ2C,GAE3C;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,QAAwC;IACtE,O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H,MAAM,CAAC,MAAM;QAClBX,SAASW,MAAM,CAAC,UAAU;QAC1BV,OAAOU,MAAM,CAAC,QAAQ;IACxB;IACA,IAAID,mBAAmBU,QAAQ,OAAO;IACtC,MAAMpB,UAAUK,MAAMe,MAAMpB,OAAO;IACnC,MAAMC,QAAQI,MAAMe,MAAMnB,KAAK;IAC/B,MAAMa,MAAMC,OAAOR,OAAOa,MAAMN,GAAG,EAAEN,IAAI;IACzC,OAAO;QACLW,MAAM;QACNE,QAAQ;YAAErB;WAAaC,QAAQ;YAAEA;QAAM,IAAI,CAAC;QAC5CqB,OAAO;YAAC;gBAAEtB;eAAaC,QAAQ;gBAAEA;YAAM,IAAI,CAAC;gBAAIa;;SAAM;IACxD;AACF"}
|
package/src/lib/model/index.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export * from './commerce-subscription-status';
|
|
|
53
53
|
export * from './subscription-view';
|
|
54
54
|
export * from './commerce-tax';
|
|
55
55
|
export * from './commerce-tax-decision';
|
|
56
|
+
export * from './commerce-tax-step';
|
|
56
57
|
export * from './order-figures';
|
|
57
58
|
export * from './order-list-fields';
|
|
58
59
|
export * from './purchase-analytics';
|
package/src/lib/model/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export * from "./commerce-subscription-status.js";
|
|
|
51
51
|
export * from "./subscription-view.js";
|
|
52
52
|
export * from "./commerce-tax.js";
|
|
53
53
|
export * from "./commerce-tax-decision.js";
|
|
54
|
+
export * from "./commerce-tax-step.js";
|
|
54
55
|
export * from "./order-figures.js";
|
|
55
56
|
export * from "./order-list-fields.js";
|
|
56
57
|
export * from "./purchase-analytics.js";
|