@rebuy/rebuy 3.31.0 → 3.33.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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/cab/index.cjs +29 -0
  3. package/dist/cab/index.d.ts +1 -0
  4. package/dist/cab/index.mjs +29 -0
  5. package/dist/cab/reviewStars.d.ts +24 -0
  6. package/dist/index.cjs +1138 -923
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.mjs +1138 -923
  9. package/dist/pricing/postPurchaseSubscriptionDisplay.d.ts +5 -0
  10. package/dist/schema/index.d.ts +8 -0
  11. package/dist/schema/postPurchaseChoice.d.ts +25 -0
  12. package/dist/schema/postPurchaseDiscount.d.ts +22 -0
  13. package/dist/schema/postPurchasePlanAdjustment.d.ts +11 -0
  14. package/dist/schema/postPurchasePlanCatalog.d.ts +42 -0
  15. package/dist/schema/postPurchaseProduct.d.ts +260 -0
  16. package/dist/schema/postPurchaseProductSettings.d.ts +1 -1
  17. package/dist/schema/postPurchaseProductSource.d.ts +2 -2
  18. package/dist/schema/postPurchaseSubscription.d.ts +21 -0
  19. package/dist/schema/postPurchaseSubscriptionDisplay.d.ts +10 -0
  20. package/dist/schema/postPurchaseSubscriptionProduct.d.ts +224 -0
  21. package/dist/schema/postPurchaseSubscriptionSettings.d.ts +22 -0
  22. package/dist/schema/widgets/checkout-and-beyond/banner.d.ts +1 -1
  23. package/dist/schema/widgets/checkout-and-beyond/carousel.d.ts +1 -1
  24. package/dist/schema/widgets/checkout-and-beyond/cartLine.d.ts +1 -1
  25. package/dist/schema/widgets/checkout-and-beyond/common.d.ts +1 -1
  26. package/dist/schema/widgets/checkout-and-beyond/dataSource.d.ts +2 -2
  27. package/dist/schema/widgets/checkout-and-beyond/discount.d.ts +1 -1
  28. package/dist/schema/widgets/checkout-and-beyond/icons.d.ts +1 -1
  29. package/dist/schema/widgets/checkout-and-beyond/image.d.ts +2 -2
  30. package/dist/schema/widgets/checkout-and-beyond/offers.d.ts +1 -1
  31. package/dist/schema/widgets/checkout-and-beyond/progressBar.d.ts +1 -1
  32. package/dist/schema/widgets/post-purchase-offer/postPurchaseOffer.d.ts +2 -2
  33. package/dist/schema/widgets/post-purchase-offer/postPurchaseSettings.d.ts +2 -2
  34. package/dist/schema/widgets/post-purchase-offer/postPurchaseWidget.d.ts +2 -2
  35. package/dist/server/__fixtures__/postPurchaseLegacyPlans.d.ts +35 -0
  36. package/dist/server/__fixtures__/postPurchaseSubscription.d.ts +75 -0
  37. package/dist/server/index.cjs +802 -118
  38. package/dist/server/index.d.ts +3 -1
  39. package/dist/server/index.mjs +802 -118
  40. package/dist/server/normalizePostPurchaseCollection.d.ts +16 -16
  41. package/dist/server/normalizePostPurchaseProduct.d.ts +9 -9
  42. package/dist/server/postPurchaseLegacyPlans.d.ts +3 -0
  43. package/dist/server/postPurchaseModernPlans.d.ts +7 -0
  44. package/dist/server/postPurchasePlanAdjustment.d.ts +3 -0
  45. package/dist/server/postPurchasePlanCatalog.d.ts +5 -0
  46. package/dist/server/postPurchaseSubscriptionEligibility.d.ts +5 -0
  47. package/dist/server/prepareNormalizedSubscription.d.ts +11 -0
  48. package/dist/server/preparePostPurchaseSubscription.d.ts +102 -0
  49. package/dist/server/projectPostPurchaseProduct.d.ts +7 -7
  50. package/dist/server/requestSchemas.d.ts +1 -1
  51. package/dist/server/selectPostPurchaseChoice.d.ts +43 -0
  52. package/package.json +1 -1
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
+ };