@rebuy/rebuy 3.30.1 → 3.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.
package/README.md CHANGED
@@ -17,7 +17,7 @@ Node `^22.14.0 || ^24.10.0 || ^26.0.0` for development; the published artifacts
17
17
  | Subpath | Contents |
18
18
  | --- | --- |
19
19
  | `@rebuy/rebuy` | Root barrel: schemas, client helpers, utilities |
20
- | `@rebuy/rebuy/cab` | zod-free CAB renderer helpers shared by every renderer (`contentText`, `tiptapPlainText`, `tiptapRuns`, `asLayout`, `idFromGid`, `toCents`, `decoratedOrderId`) |
20
+ | `@rebuy/rebuy/cab` | zod-free CAB renderer helpers shared by every renderer (`contentText`, `tiptapPlainText`, `tiptapRuns`, `asLayout`, `idFromGid`, `toCents`, `decoratedOrderId`, `reviewStars`) |
21
21
  | `@rebuy/rebuy/client` | `RebuyClient` API client |
22
22
  | `@rebuy/rebuy/gwp` | Gift-with-purchase validation helpers |
23
23
  | `@rebuy/rebuy/pricing` | Variant pricing/discount forecast (`priceVariant`, `currencyDecimals`) |
@@ -26,6 +26,7 @@ __export(cab_exports, {
26
26
  idFromGid: () => idFromGid,
27
27
  interpolateAndSanitize: () => interpolateAndSanitize,
28
28
  isTiptapDoc: () => isTiptapDoc,
29
+ reviewStars: () => reviewStars,
29
30
  selectLanguage: () => selectLanguage,
30
31
  tiptapPlainText: () => tiptapPlainText,
31
32
  tiptapRuns: () => tiptapRuns,
@@ -94,6 +95,34 @@ var decoratedOrderId = (orderId) => orderId?.match(/\/Order(?:Identity)?\/(\d+)$
94
95
  // src/cab/gid.ts
95
96
  var idFromGid = (gid) => gid.slice(gid.lastIndexOf("/") + 1);
96
97
 
98
+ // src/cab/reviewStars.ts
99
+ var STAR_WIDTH = 120;
100
+ var STAR_PATH = "M43 41C62 0 58 0 77 41c45 6 45 1 11 33 8 46 12 41-28 21-40 20-36 25-28-21C-2 42-2 47 43 41Z";
101
+ var escapeXml = (value) => value.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
102
+ var reviewStars = ({ color, height, outline, rating, total = 5 }) => {
103
+ const filled = `${(rating / total * 100).toFixed()}%`;
104
+ const empty = `${(100 - rating / total * 100).toFixed()}%`;
105
+ const label = `${rating} out of ${total} stars`;
106
+ const stars = Array.from({ length: total }, (_, index) => `<use href='#star' x='${index * STAR_WIDTH}' />`).join(
107
+ ""
108
+ );
109
+ const stroke = outline ? `<g fill='none' stroke='${escapeXml(outline.color)}' stroke-width='${outline.width * STAR_WIDTH / height}'>${stars}</g>` : "";
110
+ return {
111
+ label,
112
+ svg: [
113
+ `<svg aria-label='${label}' height='${height}' viewBox='0 0 ${total * STAR_WIDTH} 120'`,
114
+ ` width='${height * total}' xmlns='http://www.w3.org/2000/svg'>`,
115
+ `<defs><mask id='partial'>`,
116
+ `<rect fill='#fff' height='100%' width='${filled}' x='0' y='0' />`,
117
+ `<rect fill='#333' height='100%' width='${empty}' x='${filled}' y='0' />`,
118
+ `</mask><path d='${STAR_PATH}' id='star' /></defs>`,
119
+ `<g fill='${escapeXml(color)}' mask='url(#partial)'>${stars}</g>`,
120
+ stroke,
121
+ "</svg>"
122
+ ].join("")
123
+ };
124
+ };
125
+
97
126
  // src/transforms/htmlToTiptap/isValidHref.ts
98
127
  var RELATIVE_BASE = "https://x.invalid";
99
128
  var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
@@ -3,6 +3,7 @@ export * from '../cab/contentText';
3
3
  export * from '../cab/decoratedOrderId';
4
4
  export * from '../cab/gid';
5
5
  export * from '../cab/interpolateAndSanitize';
6
+ export * from '../cab/reviewStars';
6
7
  export * from '../cab/selectLanguage';
7
8
  export * from '../cab/tiptapPlain';
8
9
  export * from '../cab/tiptapRuns';
@@ -59,6 +59,34 @@ var decoratedOrderId = (orderId) => orderId?.match(/\/Order(?:Identity)?\/(\d+)$
59
59
  // src/cab/gid.ts
60
60
  var idFromGid = (gid) => gid.slice(gid.lastIndexOf("/") + 1);
61
61
 
62
+ // src/cab/reviewStars.ts
63
+ var STAR_WIDTH = 120;
64
+ var STAR_PATH = "M43 41C62 0 58 0 77 41c45 6 45 1 11 33 8 46 12 41-28 21-40 20-36 25-28-21C-2 42-2 47 43 41Z";
65
+ var escapeXml = (value) => value.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
66
+ var reviewStars = ({ color, height, outline, rating, total = 5 }) => {
67
+ const filled = `${(rating / total * 100).toFixed()}%`;
68
+ const empty = `${(100 - rating / total * 100).toFixed()}%`;
69
+ const label = `${rating} out of ${total} stars`;
70
+ const stars = Array.from({ length: total }, (_, index) => `<use href='#star' x='${index * STAR_WIDTH}' />`).join(
71
+ ""
72
+ );
73
+ const stroke = outline ? `<g fill='none' stroke='${escapeXml(outline.color)}' stroke-width='${outline.width * STAR_WIDTH / height}'>${stars}</g>` : "";
74
+ return {
75
+ label,
76
+ svg: [
77
+ `<svg aria-label='${label}' height='${height}' viewBox='0 0 ${total * STAR_WIDTH} 120'`,
78
+ ` width='${height * total}' xmlns='http://www.w3.org/2000/svg'>`,
79
+ `<defs><mask id='partial'>`,
80
+ `<rect fill='#fff' height='100%' width='${filled}' x='0' y='0' />`,
81
+ `<rect fill='#333' height='100%' width='${empty}' x='${filled}' y='0' />`,
82
+ `</mask><path d='${STAR_PATH}' id='star' /></defs>`,
83
+ `<g fill='${escapeXml(color)}' mask='url(#partial)'>${stars}</g>`,
84
+ stroke,
85
+ "</svg>"
86
+ ].join("")
87
+ };
88
+ };
89
+
62
90
  // src/transforms/htmlToTiptap/isValidHref.ts
63
91
  var RELATIVE_BASE = "https://x.invalid";
64
92
  var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
@@ -147,6 +175,7 @@ export {
147
175
  idFromGid,
148
176
  interpolateAndSanitize,
149
177
  isTiptapDoc,
178
+ reviewStars,
150
179
  selectLanguage,
151
180
  tiptapPlainText,
152
181
  tiptapRuns,
@@ -0,0 +1,24 @@
1
+ export type ReviewStarsOptions = {
2
+ /** Fill colour of the rated portion; merchant-supplied, so it is XML-escaped. */
3
+ color: string;
4
+ /** Pixel height of one star; the row is `height * total` wide. */
5
+ height: number;
6
+ /** Stroke drawn over every star, `width` in px (scaled into viewBox units); omit for no outline. */
7
+ outline?: {
8
+ color: string;
9
+ width: number;
10
+ };
11
+ rating: number;
12
+ total?: number;
13
+ };
14
+ /**
15
+ * A partially-filled review-star row as an SVG string plus its accessible label — the same stars in every
16
+ * renderer. A mask clips the fill to `rating / total`; each renderer wraps the string in its own element
17
+ * (a data-URL image on checkout) and keeps its own rating and count provider. The string must stay an isolated
18
+ * document (a data URL / `<img>`), never inlined into the page: its `#partial` and `#star` ids are fixed, so two
19
+ * inlined rows would share the first row's mask.
20
+ */
21
+ export declare const reviewStars: ({ color, height, outline, rating, total }: ReviewStarsOptions) => {
22
+ label: string;
23
+ svg: string;
24
+ };
@@ -4882,7 +4882,7 @@ var fetchDataSourceResults = async (input, ctx) => {
4882
4882
  var import_zod37 = require("zod");
4883
4883
  var SUPPLY_KEY = { production: "AQF5RKLR", staging: "Z56LQ7PS" };
4884
4884
  var OFFER_LIMIT = 4;
4885
- var SUPPORTED_COUNTRIES = /* @__PURE__ */ new Set(["US", "CA"]);
4885
+ var SUPPORTED_COUNTRIES = /* @__PURE__ */ new Set(["US", "CA", "GB"]);
4886
4886
  var MAX_TRANSACTION_ITEMS = 50;
4887
4887
  var TEST_CUSTOMER_EMAIL = "test@rebuyengine.com";
4888
4888
  var transactionItems = (input) => (input.transactionItems?.map(({ id, priceCents, quantity, title, type }) => ({
@@ -4831,7 +4831,7 @@ var fetchDataSourceResults = async (input, ctx) => {
4831
4831
  import { z as z37 } from "zod";
4832
4832
  var SUPPLY_KEY = { production: "AQF5RKLR", staging: "Z56LQ7PS" };
4833
4833
  var OFFER_LIMIT = 4;
4834
- var SUPPORTED_COUNTRIES = /* @__PURE__ */ new Set(["US", "CA"]);
4834
+ var SUPPORTED_COUNTRIES = /* @__PURE__ */ new Set(["US", "CA", "GB"]);
4835
4835
  var MAX_TRANSACTION_ITEMS = 50;
4836
4836
  var TEST_CUSTOMER_EMAIL = "test@rebuyengine.com";
4837
4837
  var transactionItems = (input) => (input.transactionItems?.map(({ id, priceCents, quantity, title, type }) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebuy/rebuy",
3
- "version": "3.30.1",
3
+ "version": "3.32.0",
4
4
  "description": "Shared zod schemas, legacy-to-CAB widget transforms, and server orchestrators for Rebuy's Shopify consumers (rebuy-api, admin-nextjs, rebuy-shopify-extensions)",
5
5
  "license": "MIT",
6
6
  "author": "Rebuy, Inc.",