@aglyn/plugins-commerce 1.30.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +4 -0
  2. package/package.json +13 -13
  3. package/src/lib/components/cart.js +46 -20
  4. package/src/lib/components/cart.js.map +1 -1
  5. package/src/lib/components/commerce-console-page.js +6 -0
  6. package/src/lib/components/commerce-console-page.js.map +1 -1
  7. package/src/lib/components/console/currencies-card.component.d.ts +21 -0
  8. package/src/lib/components/console/currencies-card.component.js +408 -0
  9. package/src/lib/components/console/currencies-card.component.js.map +1 -0
  10. package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
  11. package/src/lib/components/console/product-add-ons-fields.component.js +74 -2
  12. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  13. package/src/lib/components/console/product-editor-dialog.component.js +47 -1
  14. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  15. package/src/lib/components/console/product-fixed-prices-fields.component.d.ts +25 -0
  16. package/src/lib/components/console/product-fixed-prices-fields.component.js +112 -0
  17. package/src/lib/components/console/product-fixed-prices-fields.component.js.map +1 -0
  18. package/src/lib/components/console/product-traffic-card.component.d.ts +24 -0
  19. package/src/lib/components/console/product-traffic-card.component.js +172 -0
  20. package/src/lib/components/console/product-traffic-card.component.js.map +1 -0
  21. package/src/lib/components/console/products-hub-card.component.js +181 -59
  22. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  23. package/src/lib/components/console/reservations-card.component.js +32 -15
  24. package/src/lib/components/console/reservations-card.component.js.map +1 -1
  25. package/src/lib/components/console/shipping-settings-card.component.js +131 -10
  26. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  27. package/src/lib/components/console/store-settings-card.component.js +1 -1
  28. package/src/lib/components/console/store-settings-card.component.js.map +1 -1
  29. package/src/lib/components/console/use-currency-setup.d.ts +20 -0
  30. package/src/lib/components/console/use-currency-setup.js +61 -0
  31. package/src/lib/components/console/use-currency-setup.js.map +1 -0
  32. package/src/lib/components/currency-selector.d.ts +36 -0
  33. package/src/lib/components/currency-selector.js +157 -0
  34. package/src/lib/components/currency-selector.js.map +1 -0
  35. package/src/lib/components/product-add-ons.d.ts +9 -1
  36. package/src/lib/components/product-add-ons.js +8 -4
  37. package/src/lib/components/product-add-ons.js.map +1 -1
  38. package/src/lib/components/product-choice-cards.d.ts +13 -1
  39. package/src/lib/components/product-choice-cards.js +5 -4
  40. package/src/lib/components/product-choice-cards.js.map +1 -1
  41. package/src/lib/components/product-detail.d.ts +8 -0
  42. package/src/lib/components/product-detail.js +38 -11
  43. package/src/lib/components/product-detail.js.map +1 -1
  44. package/src/lib/components/product-grid.d.ts +2 -0
  45. package/src/lib/components/product-grid.js +22 -9
  46. package/src/lib/components/product-grid.js.map +1 -1
  47. package/src/lib/components/related-products.js +6 -2
  48. package/src/lib/components/related-products.js.map +1 -1
  49. package/src/lib/components/shopper-currency.d.ts +108 -0
  50. package/src/lib/components/shopper-currency.js +262 -0
  51. package/src/lib/components/shopper-currency.js.map +1 -0
  52. package/src/lib/components/wishlist.js +7 -1
  53. package/src/lib/components/wishlist.js.map +1 -1
  54. package/src/lib/declarations.server.js +39 -0
  55. package/src/lib/declarations.server.js.map +1 -1
  56. package/src/lib/model/commerce-currency-setup.d.ts +79 -0
  57. package/src/lib/model/commerce-currency-setup.js +124 -0
  58. package/src/lib/model/commerce-currency-setup.js.map +1 -0
  59. package/src/lib/model/commerce-currency.d.ts +215 -0
  60. package/src/lib/model/commerce-currency.js +511 -0
  61. package/src/lib/model/commerce-currency.js.map +1 -0
  62. package/src/lib/model/commerce-orders.d.ts +17 -0
  63. package/src/lib/model/commerce-orders.js +10 -5
  64. package/src/lib/model/commerce-orders.js.map +1 -1
  65. package/src/lib/model/commerce-record-routes.js +56 -0
  66. package/src/lib/model/commerce-record-routes.js.map +1 -1
  67. package/src/lib/model/commerce-reservations.d.ts +6 -0
  68. package/src/lib/model/commerce-reservations.js.map +1 -1
  69. package/src/lib/model/commerce-shipping.d.ts +61 -17
  70. package/src/lib/model/commerce-shipping.js +346 -32
  71. package/src/lib/model/commerce-shipping.js.map +1 -1
  72. package/src/lib/model/commerce.d.ts +6 -0
  73. package/src/lib/model/commerce.js.map +1 -1
  74. package/src/lib/model/index.d.ts +2 -0
  75. package/src/lib/model/index.js +2 -0
  76. package/src/lib/model/index.js.map +1 -1
  77. package/src/lib/model/order-figures.js +9 -2
  78. package/src/lib/model/order-figures.js.map +1 -1
  79. package/src/lib/model/product-modifiers.d.ts +5 -0
  80. package/src/lib/model/product-modifiers.js.map +1 -1
  81. package/src/lib/model/product-write.d.ts +10 -1
  82. package/src/lib/model/product-write.js +13 -2
  83. package/src/lib/model/product-write.js.map +1 -1
  84. package/src/lib/server/billing-webhook.js +37 -24
  85. package/src/lib/server/billing-webhook.js.map +1 -1
  86. package/src/lib/server/carrier-shipping.js +3 -2
  87. package/src/lib/server/carrier-shipping.js.map +1 -1
  88. package/src/lib/server/cart-checkout.js +77 -15
  89. package/src/lib/server/cart-checkout.js.map +1 -1
  90. package/src/lib/server/cart.d.ts +12 -0
  91. package/src/lib/server/cart.js +52 -6
  92. package/src/lib/server/cart.js.map +1 -1
  93. package/src/lib/server/catalog.d.ts +5 -0
  94. package/src/lib/server/catalog.js +7 -0
  95. package/src/lib/server/catalog.js.map +1 -1
  96. package/src/lib/server/checkout.js +54 -16
  97. package/src/lib/server/checkout.js.map +1 -1
  98. package/src/lib/server/currency.d.ts +93 -0
  99. package/src/lib/server/currency.js +182 -0
  100. package/src/lib/server/currency.js.map +1 -0
  101. package/src/lib/server/draft-order.js +3 -3
  102. package/src/lib/server/draft-order.js.map +1 -1
  103. package/src/lib/server/order-notifications.js +4 -2
  104. package/src/lib/server/order-notifications.js.map +1 -1
  105. package/src/lib/server/product.d.ts +9 -0
  106. package/src/lib/server/product.js +12 -0
  107. package/src/lib/server/product.js.map +1 -1
  108. package/src/lib/server/products-write.js +10 -2
  109. package/src/lib/server/products-write.js.map +1 -1
  110. package/src/lib/server/refund.js +3 -3
  111. package/src/lib/server/refund.js.map +1 -1
  112. package/src/lib/server/site-chat-tools.d.ts +22 -0
  113. package/src/lib/server/site-chat-tools.js +369 -0
  114. package/src/lib/server/site-chat-tools.js.map +1 -0
  115. package/src/lib/server/site-chat-visitor.d.ts +24 -0
  116. package/src/lib/server/site-chat-visitor.js +39 -0
  117. package/src/lib/server/site-chat-visitor.js.map +1 -0
  118. package/src/lib/server/site-offers.d.ts +31 -0
  119. package/src/lib/server/site-offers.js +91 -0
  120. package/src/lib/server/site-offers.js.map +1 -0
  121. package/src/lib/server/stays-site-search.d.ts +20 -0
  122. package/src/lib/server/stays-site-search.js +78 -0
  123. package/src/lib/server/stays-site-search.js.map +1 -0
  124. package/src/lib/server.js +20 -0
  125. package/src/lib/server.js.map +1 -1
  126. package/src/lib/site-chat-tool-definitions.d.ts +26 -0
  127. package/src/lib/site-chat-tool-definitions.js +141 -0
  128. package/src/lib/site-chat-tool-definitions.js.map +1 -0
  129. package/src/lib/site.js +8 -0
  130. package/src/lib/site.js.map +1 -1
  131. package/src/lib/subprocessors.js +7 -0
  132. package/src/lib/subprocessors.js.map +1 -1
@@ -0,0 +1,25 @@
1
+ import * as CommerceModel from '../../model';
2
+ export interface ProductFixedPricesFieldsProps {
3
+ variants: readonly CommerceModel.ProductVariant[];
4
+ /** The store currency. */
5
+ base: string;
6
+ /** The other currencies the store sells in. */
7
+ currencies: readonly CommerceModel.StoreCurrency[];
8
+ rates: CommerceModel.FxRates | undefined;
9
+ /**
10
+ * A variant's fixed price in one currency, as typed: blank clears it, so
11
+ * the price converts again.
12
+ */
13
+ onPrice: (index: number, code: string, raw: string) => void;
14
+ }
15
+ /**
16
+ * Prices in other currencies (AGL-4248): for each variant, one field per
17
+ * currency the store sells in. A blank cell is converted from the
18
+ * variant's price at the day's rate, rounded the way the Currencies card
19
+ * says, and shows that figure as its placeholder; a typed one is charged as
20
+ * typed, the way Shopify Markets' fixed prices are.
21
+ *
22
+ * Fields keep what is typed until they are left (`defaultValue` + blur), so
23
+ * a keystroke redraws nothing else in the editor (AGL-3423).
24
+ */
25
+ export declare const ProductFixedPricesFields: import("react").MemoExoticComponent<(props: ProductFixedPricesFieldsProps) => import("react").JSX.Element>;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ import { Box, Stack, TextField, Typography } from "@mui/material";
20
+ import { memo, useState } from "react";
21
+ import * as CommerceModel from "../../model/index.js";
22
+ const DECIMAL = {
23
+ inputMode: 'decimal'
24
+ };
25
+ /**
26
+ * Prices in other currencies (AGL-4248): for each variant, one field per
27
+ * currency the store sells in. A blank cell is converted from the
28
+ * variant's price at the day's rate, rounded the way the Currencies card
29
+ * says, and shows that figure as its placeholder; a typed one is charged as
30
+ * typed, the way Shopify Markets' fixed prices are.
31
+ *
32
+ * Fields keep what is typed until they are left (`defaultValue` + blur), so
33
+ * a keystroke redraws nothing else in the editor (AGL-3423).
34
+ */ export const ProductFixedPricesFields = /*#__PURE__*/ memo(function ProductFixedPricesFields(props) {
35
+ const { variants, base, currencies, rates, onPrice } = props;
36
+ const [invalid, setInvalid] = useState({});
37
+ return /*#__PURE__*/ _jsxs(Box, {
38
+ children: [
39
+ /*#__PURE__*/ _jsx(Typography, {
40
+ variant: "caption",
41
+ color: "text.secondary",
42
+ component: "p",
43
+ sx: {
44
+ mb: 1
45
+ },
46
+ children: 'Optional. Leave a price blank to convert it automatically from the price above.'
47
+ }),
48
+ /*#__PURE__*/ _jsx(Stack, {
49
+ spacing: 1.5,
50
+ children: variants.map((variant, index)=>{
51
+ const label = CommerceModel.variantPriceLabel(variant);
52
+ return /*#__PURE__*/ _jsxs(Box, {
53
+ children: [
54
+ variants.length > 1 ? /*#__PURE__*/ _jsx(Typography, {
55
+ variant: "body2",
56
+ sx: {
57
+ mb: 0.5
58
+ },
59
+ children: label
60
+ }) : null,
61
+ /*#__PURE__*/ _jsx(Box, {
62
+ sx: {
63
+ display: 'grid',
64
+ gridTemplateColumns: {
65
+ xs: 'repeat(2, minmax(0, 1fr))',
66
+ sm: 'repeat(4, minmax(0, 1fr))'
67
+ },
68
+ gap: 1
69
+ },
70
+ children: currencies.map((entry)=>{
71
+ var _variant_fixedPrices;
72
+ const cellKey = `${variant.id}:${entry.code}`;
73
+ const fixed = (_variant_fixedPrices = variant.fixedPrices) == null ? void 0 : _variant_fixedPrices[entry.code];
74
+ const converted = CommerceModel.variantHasPrice(variant) ? CommerceModel.variantPriceMinor({
75
+ priceUsd: variant.priceUsd
76
+ }, base, entry, rates) : undefined;
77
+ return /*#__PURE__*/ _jsx(TextField, {
78
+ label: `Price (${entry.code})`,
79
+ defaultValue: fixed == null ? '' : String(fixed),
80
+ placeholder: CommerceModel.minorToInput(converted, entry.code),
81
+ onBlur: (event)=>{
82
+ const bad = CommerceModel.parseMajorInput(event.target.value) === null;
83
+ setInvalid((was)=>_extends({}, was, {
84
+ [cellKey]: bad
85
+ }));
86
+ if (!bad) onPrice(index, entry.code, event.target.value);
87
+ },
88
+ error: invalid[cellKey] === true,
89
+ helperText: invalid[cellKey] ? 'Not a price' : undefined,
90
+ size: "small",
91
+ slotProps: {
92
+ // A label always shows the placeholder (the converted
93
+ // price) rather than covering it.
94
+ inputLabel: {
95
+ shrink: true
96
+ },
97
+ htmlInput: _extends({}, DECIMAL, {
98
+ 'aria-label': `Price in ${entry.code} — ${label}`
99
+ })
100
+ }
101
+ }, cellKey);
102
+ })
103
+ })
104
+ ]
105
+ }, variant.id);
106
+ })
107
+ })
108
+ ]
109
+ });
110
+ });
111
+
112
+ //# sourceMappingURL=product-fixed-prices-fields.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-fixed-prices-fields.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 { Box, Stack, TextField, Typography } from '@mui/material'\nimport { memo, useState } from 'react'\nimport * as CommerceModel from '../../model'\n\nexport interface ProductFixedPricesFieldsProps {\n variants: readonly CommerceModel.ProductVariant[]\n /** The store currency. */\n base: string\n /** The other currencies the store sells in. */\n currencies: readonly CommerceModel.StoreCurrency[]\n rates: CommerceModel.FxRates | undefined\n /**\n * A variant's fixed price in one currency, as typed: blank clears it, so\n * the price converts again.\n */\n onPrice: (index: number, code: string, raw: string) => void\n}\n\nconst DECIMAL = { inputMode: 'decimal' } as const\n\n/**\n * Prices in other currencies (AGL-4248): for each variant, one field per\n * currency the store sells in. A blank cell is converted from the\n * variant's price at the day's rate, rounded the way the Currencies card\n * says, and shows that figure as its placeholder; a typed one is charged as\n * typed, the way Shopify Markets' fixed prices are.\n *\n * Fields keep what is typed until they are left (`defaultValue` + blur), so\n * a keystroke redraws nothing else in the editor (AGL-3423).\n */\nexport const ProductFixedPricesFields = memo(function ProductFixedPricesFields(\n props: ProductFixedPricesFieldsProps,\n) {\n const { variants, base, currencies, rates, onPrice } = props\n const [invalid, setInvalid] = useState<Record<string, boolean>>({})\n return (\n <Box>\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ mb: 1 }}>\n {'Optional. Leave a price blank to convert it automatically from the price above.'}\n </Typography>\n <Stack spacing={1.5}>\n {variants.map((variant, index) => {\n const label = CommerceModel.variantPriceLabel(variant)\n return (\n <Box key={variant.id}>\n {variants.length > 1 ? (\n <Typography variant=\"body2\" sx={{ mb: 0.5 }}>\n {label}\n </Typography>\n ) : null}\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: 'repeat(2, minmax(0, 1fr))', sm: 'repeat(4, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {currencies.map((entry) => {\n const cellKey = `${variant.id}:${entry.code}`\n const fixed = variant.fixedPrices?.[entry.code]\n const converted = CommerceModel.variantHasPrice(variant)\n ? CommerceModel.variantPriceMinor({ priceUsd: variant.priceUsd }, base, entry, rates)\n : undefined\n return (\n <TextField\n key={cellKey}\n label={`Price (${entry.code})`}\n defaultValue={fixed == null ? '' : String(fixed)}\n placeholder={CommerceModel.minorToInput(converted, entry.code)}\n onBlur={(event) => {\n const bad = CommerceModel.parseMajorInput(event.target.value) === null\n setInvalid((was) => ({ ...was, [cellKey]: bad }))\n if (!bad) onPrice(index, entry.code, event.target.value)\n }}\n error={invalid[cellKey] === true}\n helperText={invalid[cellKey] ? 'Not a price' : undefined}\n size=\"small\"\n slotProps={{\n // A label always shows the placeholder (the converted\n // price) rather than covering it.\n inputLabel: { shrink: true },\n htmlInput: { ...DECIMAL, 'aria-label': `Price in ${entry.code} — ${label}` },\n }}\n />\n )\n })}\n </Box>\n </Box>\n )\n })}\n </Stack>\n </Box>\n )\n})\n"],"names":["Box","Stack","TextField","Typography","memo","useState","CommerceModel","DECIMAL","inputMode","ProductFixedPricesFields","props","variants","base","currencies","rates","onPrice","invalid","setInvalid","variant","color","component","sx","mb","spacing","map","index","label","variantPriceLabel","length","display","gridTemplateColumns","xs","sm","gap","entry","cellKey","id","code","fixed","fixedPrices","converted","variantHasPrice","variantPriceMinor","priceUsd","undefined","defaultValue","String","placeholder","minorToInput","onBlur","event","bad","parseMajorInput","target","value","was","error","helperText","size","slotProps","inputLabel","shrink","htmlInput"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,GAAG,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAe;AACjE,SAASC,IAAI,EAAEC,QAAQ,QAAQ,QAAO;AACtC,YAAYC,mBAAmB,uBAAa;AAgB5C,MAAMC,UAAU;IAAEC,WAAW;AAAU;AAEvC;;;;;;;;;CASC,GACD,OAAO,MAAMC,yCAA2BL,KAAK,SAASK,yBACpDC,KAAoC;IAEpC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGL;IACvD,MAAM,CAACM,SAASC,WAAW,GAAGZ,SAAkC,CAAC;IACjE,qBACE,MAACL;;0BACC,KAACG;gBAAWe,SAAQ;gBAAUC,OAAM;gBAAiBC,WAAU;gBAAIC,IAAI;oBAAEC,IAAI;gBAAE;0BAC5E;;0BAEH,KAACrB;gBAAMsB,SAAS;0BACbZ,SAASa,GAAG,CAAC,CAACN,SAASO;oBACtB,MAAMC,QAAQpB,cAAcqB,iBAAiB,CAACT;oBAC9C,qBACE,MAAClB;;4BACEW,SAASiB,MAAM,GAAG,kBACjB,KAACzB;gCAAWe,SAAQ;gCAAQG,IAAI;oCAAEC,IAAI;gCAAI;0CACvCI;iCAED;0CACJ,KAAC1B;gCACCqB,IAAI;oCACFQ,SAAS;oCACTC,qBAAqB;wCAAEC,IAAI;wCAA6BC,IAAI;oCAA4B;oCACxFC,KAAK;gCACP;0CAECpB,WAAWW,GAAG,CAAC,CAACU;wCAEDhB;oCADd,MAAMiB,UAAU,GAAGjB,QAAQkB,EAAE,CAAC,CAAC,EAAEF,MAAMG,IAAI,EAAE;oCAC7C,MAAMC,SAAQpB,uBAAAA,QAAQqB,WAAW,qBAAnBrB,oBAAqB,CAACgB,MAAMG,IAAI,CAAC;oCAC/C,MAAMG,YAAYlC,cAAcmC,eAAe,CAACvB,WAC5CZ,cAAcoC,iBAAiB,CAAC;wCAAEC,UAAUzB,QAAQyB,QAAQ;oCAAC,GAAG/B,MAAMsB,OAAOpB,SAC7E8B;oCACJ,qBACE,KAAC1C;wCAECwB,OAAO,CAAC,OAAO,EAAEQ,MAAMG,IAAI,CAAC,CAAC,CAAC;wCAC9BQ,cAAcP,SAAS,OAAO,KAAKQ,OAAOR;wCAC1CS,aAAazC,cAAc0C,YAAY,CAACR,WAAWN,MAAMG,IAAI;wCAC7DY,QAAQ,CAACC;4CACP,MAAMC,MAAM7C,cAAc8C,eAAe,CAACF,MAAMG,MAAM,CAACC,KAAK,MAAM;4CAClErC,WAAW,CAACsC,MAAS,aAAKA;oDAAK,CAACpB,QAAQ,EAAEgB;;4CAC1C,IAAI,CAACA,KAAKpC,QAAQU,OAAOS,MAAMG,IAAI,EAAEa,MAAMG,MAAM,CAACC,KAAK;wCACzD;wCACAE,OAAOxC,OAAO,CAACmB,QAAQ,KAAK;wCAC5BsB,YAAYzC,OAAO,CAACmB,QAAQ,GAAG,gBAAgBS;wCAC/Cc,MAAK;wCACLC,WAAW;4CACT,sDAAsD;4CACtD,kCAAkC;4CAClCC,YAAY;gDAAEC,QAAQ;4CAAK;4CAC3BC,WAAW,aAAKvD;gDAAS,cAAc,CAAC,SAAS,EAAE2B,MAAMG,IAAI,CAAC,GAAG,EAAEX,OAAO;;wCAC5E;uCAjBKS;gCAoBX;;;uBAzCMjB,QAAQkB,EAAE;gBA6CxB;;;;AAIR,GAAE"}
@@ -0,0 +1,24 @@
1
+ /** The last `days` UTC day ids, oldest first — the ids the beacon writes under. */
2
+ export declare function productTrafficDayIds(now: number, days?: number): string[];
3
+ /**
4
+ * One product's page views, day by day (AGL-4253) — the product's own row of
5
+ * the site's Pages table, where a merchant edits it.
6
+ *
7
+ * Read from `hosts/{hostId}/analytics/{day}.paths['/products/{slug}']`, never
8
+ * from the product template screen's counts: every product renders through
9
+ * that ONE screen, so its counts are the whole catalog's (the AGL-2498
10
+ * lesson). Devices and referrers are counted for the site, not per page, so
11
+ * this card does not show them.
12
+ *
13
+ * Paid like the Pages table (`screenAnalytics`, Pro+); a plan without it sees
14
+ * nothing here — the Pages table is where the upgrade is offered.
15
+ */
16
+ export declare function ProductTrafficCard(props: {
17
+ hostId: string;
18
+ /** The product's STORED slug; a retyped, unsaved one names no page yet. */
19
+ slug: string | null | undefined;
20
+ }): import("react").JSX.Element;
21
+ export declare namespace ProductTrafficCard {
22
+ var displayName: string;
23
+ }
24
+ export default ProductTrafficCard;
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import { analyticsPathKey, checkEntitlement } from "@aglyn/aglyn";
19
+ import { Box, LinearProgress, Stack, Tooltip, Typography } from "@mui/material";
20
+ import { doc, getDoc } from "firebase/firestore";
21
+ import { useEffect, useState } from "react";
22
+ import { useFirestore, useOrgPlan } from "@aglyn/tenant-feature-instance";
23
+ const DAYS = 14;
24
+ const DAY_MS = 24 * 60 * 60 * 1000;
25
+ /** The last `days` UTC day ids, oldest first — the ids the beacon writes under. */ export function productTrafficDayIds(now, days = DAYS) {
26
+ const ids = [];
27
+ for(let back = days - 1; back >= 0; back -= 1){
28
+ ids.push(new Date(now - back * DAY_MS).toISOString().slice(0, 10));
29
+ }
30
+ return ids;
31
+ }
32
+ /**
33
+ * Module cache of closed days' counts for one path (the live day is re-read
34
+ * after a minute): reopening a product's editor does not re-read fourteen
35
+ * day documents.
36
+ */ const dayCache = new Map();
37
+ const LIVE_TTL_MS = 60000;
38
+ /**
39
+ * One product's page views, day by day (AGL-4253) — the product's own row of
40
+ * the site's Pages table, where a merchant edits it.
41
+ *
42
+ * Read from `hosts/{hostId}/analytics/{day}.paths['/products/{slug}']`, never
43
+ * from the product template screen's counts: every product renders through
44
+ * that ONE screen, so its counts are the whole catalog's (the AGL-2498
45
+ * lesson). Devices and referrers are counted for the site, not per page, so
46
+ * this card does not show them.
47
+ *
48
+ * Paid like the Pages table (`screenAnalytics`, Pro+); a plan without it sees
49
+ * nothing here — the Pages table is where the upgrade is offered.
50
+ */ export function ProductTrafficCard(props) {
51
+ const { hostId, slug } = props;
52
+ const firestore = useFirestore();
53
+ const { org, ready } = useOrgPlan(hostId);
54
+ const entitled = ready && checkEntitlement(org, 'screenAnalytics');
55
+ const [days, setDays] = useState(null);
56
+ const path = slug ? `/products/${slug}` : null;
57
+ useEffect(()=>{
58
+ if (!entitled || !path) return;
59
+ let active = true;
60
+ const now = Date.now();
61
+ const ids = productTrafficDayIds(now);
62
+ const live = ids[ids.length - 1];
63
+ const key = analyticsPathKey(path);
64
+ void Promise.all(ids.map(async (day)=>{
65
+ const cacheKey = `${hostId}|${key}|${day}`;
66
+ const hit = dayCache.get(cacheKey);
67
+ if (hit && (day !== live || now - hit.storedAt < LIVE_TTL_MS)) {
68
+ return {
69
+ day,
70
+ views: hit.views,
71
+ failed: false
72
+ };
73
+ }
74
+ try {
75
+ var _snapshot_get, _paths_key;
76
+ const snapshot = await getDoc(doc(firestore, 'hosts', hostId, 'analytics', day));
77
+ const paths = (_snapshot_get = snapshot.get('paths')) != null ? _snapshot_get : {};
78
+ const views = Number((_paths_key = paths[key]) != null ? _paths_key : 0);
79
+ dayCache.set(cacheKey, {
80
+ views,
81
+ storedAt: now
82
+ });
83
+ return {
84
+ day,
85
+ views,
86
+ failed: false
87
+ };
88
+ } catch (unused) {
89
+ return {
90
+ day,
91
+ views: 0,
92
+ failed: true
93
+ };
94
+ }
95
+ })).then((counts)=>{
96
+ if (active) setDays(counts);
97
+ });
98
+ return ()=>{
99
+ active = false;
100
+ };
101
+ }, [
102
+ entitled,
103
+ firestore,
104
+ hostId,
105
+ path
106
+ ]);
107
+ if (!entitled || !path) return null;
108
+ const total = (days != null ? days : []).reduce((sum, day)=>sum + day.views, 0);
109
+ const failed = (days != null ? days : []).filter((day)=>day.failed).length;
110
+ const max = Math.max(1, ...(days != null ? days : []).map((day)=>day.views));
111
+ return /*#__PURE__*/ _jsxs(Stack, {
112
+ spacing: 1,
113
+ "aria-label": 'Product page views',
114
+ children: [
115
+ /*#__PURE__*/ _jsxs(Stack, {
116
+ direction: "row",
117
+ spacing: 1,
118
+ sx: {
119
+ alignItems: 'baseline'
120
+ },
121
+ children: [
122
+ /*#__PURE__*/ _jsx(Typography, {
123
+ variant: "subtitle2",
124
+ children: 'Page views (14 days)'
125
+ }),
126
+ days !== null && /*#__PURE__*/ _jsx(Typography, {
127
+ variant: "subtitle2",
128
+ color: "text.secondary",
129
+ children: total.toLocaleString()
130
+ })
131
+ ]
132
+ }),
133
+ days === null ? /*#__PURE__*/ _jsx(LinearProgress, {}) : total === 0 && failed === 0 ? /*#__PURE__*/ _jsx(Typography, {
134
+ variant: "body2",
135
+ color: "text.secondary",
136
+ children: `No views of ${path} in the last 14 days.`
137
+ }) : /*#__PURE__*/ _jsx(Box, {
138
+ sx: {
139
+ display: 'flex',
140
+ alignItems: 'flex-end',
141
+ gap: 0.5,
142
+ height: 48
143
+ },
144
+ children: days.map((day)=>/*#__PURE__*/ _jsx(Tooltip, {
145
+ title: day.failed ? `${day.day} · could not be read` : `${day.day} · ${day.views} view${day.views === 1 ? '' : 's'}`,
146
+ children: /*#__PURE__*/ _jsx(Box, {
147
+ sx: {
148
+ flexGrow: 1,
149
+ height: `${Math.max(2, day.views / max * 48)}px`,
150
+ bgcolor: day.failed ? 'warning.light' : day.views > 0 ? 'primary.main' : 'divider',
151
+ borderRadius: 0.5
152
+ }
153
+ })
154
+ }, day.day))
155
+ }),
156
+ /*#__PURE__*/ _jsxs(Typography, {
157
+ variant: "caption",
158
+ color: "text.secondary",
159
+ children: [
160
+ failed > 0 ? `${failed} of the 14 days could not be read and are left out. ` : '',
161
+ 'Counted at ',
162
+ path,
163
+ '. Every product side by side is in Analytics → Pages.'
164
+ ]
165
+ })
166
+ ]
167
+ });
168
+ }
169
+ ProductTrafficCard.displayName = 'ProductTrafficCard';
170
+ export default ProductTrafficCard;
171
+
172
+ //# sourceMappingURL=product-traffic-card.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-traffic-card.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 { analyticsPathKey, checkEntitlement } from '@aglyn/aglyn'\nimport { Box, LinearProgress, Stack, Tooltip, Typography } from '@mui/material'\nimport { doc, getDoc } from 'firebase/firestore'\nimport { useEffect, useState } from 'react'\nimport { useFirestore, useOrgPlan } from '@aglyn/tenant-feature-instance'\n\nconst DAYS = 14\nconst DAY_MS = 24 * 60 * 60 * 1000\n\n/** The last `days` UTC day ids, oldest first — the ids the beacon writes under. */\nexport function productTrafficDayIds(now: number, days = DAYS): string[] {\n const ids: string[] = []\n for (let back = days - 1; back >= 0; back -= 1) {\n ids.push(new Date(now - back * DAY_MS).toISOString().slice(0, 10))\n }\n return ids\n}\n\ninterface DayCount {\n day: string\n views: number\n failed: boolean\n}\n\n/**\n * Module cache of closed days' counts for one path (the live day is re-read\n * after a minute): reopening a product's editor does not re-read fourteen\n * day documents.\n */\nconst dayCache = new Map<string, { views: number; storedAt: number }>()\nconst LIVE_TTL_MS = 60_000\n\n/**\n * One product's page views, day by day (AGL-4253) — the product's own row of\n * the site's Pages table, where a merchant edits it.\n *\n * Read from `hosts/{hostId}/analytics/{day}.paths['/products/{slug}']`, never\n * from the product template screen's counts: every product renders through\n * that ONE screen, so its counts are the whole catalog's (the AGL-2498\n * lesson). Devices and referrers are counted for the site, not per page, so\n * this card does not show them.\n *\n * Paid like the Pages table (`screenAnalytics`, Pro+); a plan without it sees\n * nothing here — the Pages table is where the upgrade is offered.\n */\nexport function ProductTrafficCard(props: {\n hostId: string\n /** The product's STORED slug; a retyped, unsaved one names no page yet. */\n slug: string | null | undefined\n}) {\n const { hostId, slug } = props\n const firestore = useFirestore()\n const { org, ready } = useOrgPlan(hostId)\n const entitled = ready && checkEntitlement(org as never, 'screenAnalytics')\n const [days, setDays] = useState<DayCount[] | null>(null)\n const path = slug ? `/products/${slug}` : null\n\n useEffect(() => {\n if (!entitled || !path) return\n let active = true\n const now = Date.now()\n const ids = productTrafficDayIds(now)\n const live = ids[ids.length - 1]\n const key = analyticsPathKey(path)\n void Promise.all(\n ids.map(async (day): Promise<DayCount> => {\n const cacheKey = `${hostId}|${key}|${day}`\n const hit = dayCache.get(cacheKey)\n if (hit && (day !== live || now - hit.storedAt < LIVE_TTL_MS)) {\n return { day, views: hit.views, failed: false }\n }\n try {\n const snapshot = await getDoc(doc(firestore, 'hosts', hostId, 'analytics', day))\n const paths = (snapshot.get('paths') ?? {}) as Record<string, number>\n const views = Number(paths[key] ?? 0)\n dayCache.set(cacheKey, { views, storedAt: now })\n return { day, views, failed: false }\n } catch {\n return { day, views: 0, failed: true }\n }\n }),\n ).then((counts) => {\n if (active) setDays(counts)\n })\n return () => {\n active = false\n }\n }, [entitled, firestore, hostId, path])\n\n if (!entitled || !path) return null\n\n const total = (days ?? []).reduce((sum, day) => sum + day.views, 0)\n const failed = (days ?? []).filter((day) => day.failed).length\n const max = Math.max(1, ...(days ?? []).map((day) => day.views))\n\n return (\n <Stack spacing={1} aria-label={'Product page views'}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"subtitle2\">{'Page views (14 days)'}</Typography>\n {days !== null && (\n <Typography variant=\"subtitle2\" color=\"text.secondary\">\n {total.toLocaleString()}\n </Typography>\n )}\n </Stack>\n {days === null ? (\n <LinearProgress />\n ) : total === 0 && failed === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`No views of ${path} in the last 14 days.`}\n </Typography>\n ) : (\n <Box sx={{ display: 'flex', alignItems: 'flex-end', gap: 0.5, height: 48 }}>\n {days.map((day) => (\n <Tooltip\n key={day.day}\n title={\n day.failed\n ? `${day.day} · could not be read`\n : `${day.day} · ${day.views} view${day.views === 1 ? '' : 's'}`\n }\n >\n <Box\n sx={{\n flexGrow: 1,\n height: `${Math.max(2, (day.views / max) * 48)}px`,\n bgcolor: day.failed ? 'warning.light' : day.views > 0 ? 'primary.main' : 'divider',\n borderRadius: 0.5,\n }}\n />\n </Tooltip>\n ))}\n </Box>\n )}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {failed > 0\n ? `${failed} of the 14 days could not be read and are left out. `\n : ''}\n {'Counted at '}\n {path}\n {'. Every product side by side is in Analytics → Pages.'}\n </Typography>\n </Stack>\n )\n}\nProductTrafficCard.displayName = 'ProductTrafficCard'\n\nexport default ProductTrafficCard\n"],"names":["analyticsPathKey","checkEntitlement","Box","LinearProgress","Stack","Tooltip","Typography","doc","getDoc","useEffect","useState","useFirestore","useOrgPlan","DAYS","DAY_MS","productTrafficDayIds","now","days","ids","back","push","Date","toISOString","slice","dayCache","Map","LIVE_TTL_MS","ProductTrafficCard","props","hostId","slug","firestore","org","ready","entitled","setDays","path","active","live","length","key","Promise","all","map","day","cacheKey","hit","get","storedAt","views","failed","snapshot","paths","Number","set","then","counts","total","reduce","sum","filter","max","Math","spacing","aria-label","direction","sx","alignItems","variant","color","toLocaleString","display","gap","height","title","flexGrow","bgcolor","borderRadius","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,gBAAgB,EAAEC,gBAAgB,QAAQ,eAAc;AACjE,SAASC,GAAG,EAAEC,cAAc,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,QAAQ,gBAAe;AAC/E,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,YAAY,EAAEC,UAAU,QAAQ,iCAAgC;AAEzE,MAAMC,OAAO;AACb,MAAMC,SAAS,KAAK,KAAK,KAAK;AAE9B,iFAAiF,GACjF,OAAO,SAASC,qBAAqBC,GAAW,EAAEC,OAAOJ,IAAI;IAC3D,MAAMK,MAAgB,EAAE;IACxB,IAAK,IAAIC,OAAOF,OAAO,GAAGE,QAAQ,GAAGA,QAAQ,EAAG;QAC9CD,IAAIE,IAAI,CAAC,IAAIC,KAAKL,MAAMG,OAAOL,QAAQQ,WAAW,GAAGC,KAAK,CAAC,GAAG;IAChE;IACA,OAAOL;AACT;AAQA;;;;CAIC,GACD,MAAMM,WAAW,IAAIC;AACrB,MAAMC,cAAc;AAEpB;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,mBAAmBC,KAIlC;IACC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGF;IACzB,MAAMG,YAAYpB;IAClB,MAAM,EAAEqB,GAAG,EAAEC,KAAK,EAAE,GAAGrB,WAAWiB;IAClC,MAAMK,WAAWD,SAAShC,iBAAiB+B,KAAc;IACzD,MAAM,CAACf,MAAMkB,QAAQ,GA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