@rebuy/rebuy 3.42.0 → 3.43.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/dist/index.cjs +899 -781
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +899 -781
- package/dist/pricing/index.cjs +58 -1
- package/dist/pricing/index.d.ts +2 -0
- package/dist/pricing/index.mjs +58 -1
- package/dist/pricing/postPurchaseDisplayFacts.d.ts +36 -0
- package/dist/pricing/postPurchaseDisplayPrice.d.ts +8 -0
- package/dist/pricing/postPurchaseReduction.d.ts +17 -0
- package/dist/schema/checkout-and-beyond/constants.cjs +4 -0
- package/dist/schema/checkout-and-beyond/constants.mjs +4 -0
- package/dist/schema/checkout-and-beyond/index.cjs +388 -374
- package/dist/schema/checkout-and-beyond/index.mjs +388 -374
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/postPurchaseDisplayPrice.d.ts +31 -0
- package/dist/schema/postPurchaseHealth.d.ts +5 -0
- package/dist/schema/postPurchasePlanCatalog.d.ts +2 -0
- package/dist/schema/postPurchaseProduct.d.ts +2 -0
- package/dist/schema/postPurchaseProductCollectionView.d.ts +24 -0
- package/dist/schema/postPurchaseProductView.d.ts +26 -1
- package/dist/schema/postPurchaseSubscriptionProduct.d.ts +2 -0
- package/dist/schema/widget-data.cjs +452 -441
- package/dist/schema/widget-data.mjs +452 -441
- package/dist/schema/widgets/checkout-and-beyond/common.d.ts +14 -0
- package/dist/schema/widgets/checkout-and-beyond/image.d.ts +8 -0
- package/dist/schema/widgets/checkout-and-beyond/imageThumbnails.d.ts +13 -0
- package/dist/schema/widgets/checkout-and-beyond/index.d.ts +1 -0
- package/dist/schema/widgets/checkout-and-beyond/variants.d.ts +1 -0
- package/dist/server/index.cjs +1653 -1364
- package/dist/server/index.mjs +1575 -1286
- package/dist/server/postPurchasePlanCatalog.d.ts +4 -1
- package/dist/server/preparePostPurchaseAdmissionView.d.ts +21 -0
- package/dist/server/preparePostPurchaseCollectionGroup.d.ts +25 -0
- package/dist/server/preparePostPurchaseCollectionView.d.ts +21 -0
- package/dist/server/preparePostPurchaseGroupAdmissionView.d.ts +21 -0
- package/dist/server/preparePostPurchaseGroupDefault.d.ts +21 -0
- package/dist/server/preparePostPurchaseGroupView.d.ts +21 -0
- package/dist/server/preparePostPurchaseMemberView.d.ts +63 -0
- package/dist/server/preparePostPurchaseQuantityAdmissionView.d.ts +21 -0
- package/dist/server/preparePostPurchaseQuantityView.d.ts +21 -0
- package/dist/server/preparePostPurchaseSubscription.d.ts +1 -0
- package/dist/server/selectPostPurchaseChoice.d.ts +1 -0
- package/dist/transforms/index.cjs +980 -581
- package/dist/transforms/index.mjs +980 -581
- package/dist/transforms/postPurchase/convertProductInformation.d.ts +6 -2
- package/dist/transforms/postPurchase/productCardControls.d.ts +7 -0
- package/dist/transforms/postPurchase/productCardCosts.d.ts +3 -0
- package/dist/transforms/postPurchase/productCardPricing.d.ts +3 -0
- package/dist/transforms/postPurchase/productCardRows.d.ts +63 -0
- package/dist/transforms/postPurchase/productCardSettings.d.ts +103 -0
- package/dist/transforms/postPurchase/types.d.ts +2 -2
- package/dist/transforms/productCard/earnedText.d.ts +25 -0
- package/dist/transforms/productCard/priceText.d.ts +2 -0
- package/dist/transforms/productCard/quantitySection.d.ts +28 -0
- package/dist/transforms/productCard/subscriptionToggle.d.ts +18 -0
- package/package.json +1 -1
package/dist/pricing/index.cjs
CHANGED
|
@@ -24,7 +24,11 @@ __export(pricing_exports, {
|
|
|
24
24
|
computeCompareAtPrice: () => computeCompareAtPrice,
|
|
25
25
|
computeDisplayPrice: () => computeDisplayPrice,
|
|
26
26
|
currencyDecimals: () => currencyDecimals,
|
|
27
|
-
|
|
27
|
+
postPurchaseDisplayFacts: () => postPurchaseDisplayFacts,
|
|
28
|
+
postPurchaseDisplayPricing: () => postPurchaseDisplayPricing,
|
|
29
|
+
postPurchasePlanDiscountPercentage: () => postPurchasePlanDiscountPercentage,
|
|
30
|
+
priceVariant: () => priceVariant,
|
|
31
|
+
reducePostPurchaseMinor: () => reducePostPurchaseMinor
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(pricing_exports);
|
|
30
34
|
|
|
@@ -107,6 +111,59 @@ var currencyDecimals = (currencyCode) => {
|
|
|
107
111
|
return decimals;
|
|
108
112
|
};
|
|
109
113
|
|
|
114
|
+
// src/pricing/postPurchaseReduction.ts
|
|
115
|
+
var reducePostPurchaseMinor = (priceMinor, { amount, type }, decimals) => {
|
|
116
|
+
if (type === "price") return amountToCents(amount, decimals);
|
|
117
|
+
const reduction = type === "percentage" ? Math.round(priceMinor * (amount / 100)) : type === "fixed_amount" ? amountToCents(amount, decimals) : 0;
|
|
118
|
+
return Math.max(0, priceMinor - reduction);
|
|
119
|
+
};
|
|
120
|
+
var postPurchasePlanDiscountPercentage = (price, adjustment) => {
|
|
121
|
+
const regularMinor = amountToCents(price);
|
|
122
|
+
const planMinor = adjustment ? reducePostPurchaseMinor(regularMinor, adjustment, 2) : regularMinor;
|
|
123
|
+
return regularMinor > 0 && planMinor < regularMinor ? Math.round((1 - planMinor / regularMinor) * 100) : 0;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/pricing/postPurchaseDisplayFacts.ts
|
|
127
|
+
var wholePercent = (savingMinor, struckMinor) => {
|
|
128
|
+
const percent = savingMinor / struckMinor * 100;
|
|
129
|
+
return Math.round(percent.toString().length > 5 ? Number(percent.toFixed(2)) : percent);
|
|
130
|
+
};
|
|
131
|
+
var postPurchaseDisplayPricing = ({
|
|
132
|
+
compareAtPrice,
|
|
133
|
+
currencyCode,
|
|
134
|
+
discount,
|
|
135
|
+
discountedFrom,
|
|
136
|
+
plan,
|
|
137
|
+
price
|
|
138
|
+
}) => {
|
|
139
|
+
const decimals = currencyDecimals(currencyCode);
|
|
140
|
+
const regularMinor = amountToCents(price, decimals);
|
|
141
|
+
const compareAtMinor = amountToCents(compareAtPrice, decimals);
|
|
142
|
+
const fromCompareAt = discountedFrom === "compare_at_price" || discount.type === "none" && !plan;
|
|
143
|
+
const comparisonMinor = fromCompareAt && compareAtMinor > regularMinor ? compareAtMinor : regularMinor;
|
|
144
|
+
const planMinor = plan ? reducePostPurchaseMinor(regularMinor, plan, decimals) : regularMinor;
|
|
145
|
+
const priceMinor = reducePostPurchaseMinor(planMinor, discount, decimals);
|
|
146
|
+
const savingMinor = Math.max(0, comparisonMinor - priceMinor);
|
|
147
|
+
return {
|
|
148
|
+
comparisonMinor,
|
|
149
|
+
priceMinor,
|
|
150
|
+
savingMinor,
|
|
151
|
+
savingPercent: savingMinor && wholePercent(savingMinor, comparisonMinor)
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
var postPurchaseDisplayFacts = (input) => {
|
|
155
|
+
const { comparisonMinor, priceMinor, savingMinor, savingPercent } = postPurchaseDisplayPricing(input);
|
|
156
|
+
const percentPlan = input.plan?.type === "fixed_amount" || input.plan?.type === "price";
|
|
157
|
+
return {
|
|
158
|
+
currencyCode: input.currencyCode,
|
|
159
|
+
savingFormat: !percentPlan && input.discount.type === "fixed_amount" ? "amount" : "percent",
|
|
160
|
+
savingMinor,
|
|
161
|
+
savingPercent,
|
|
162
|
+
variantCompareAtPriceMinor: savingMinor > 0 ? comparisonMinor : null,
|
|
163
|
+
variantPriceMinor: priceMinor
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
110
167
|
// src/pricing/priceVariant.ts
|
|
111
168
|
var priceVariant = ({
|
|
112
169
|
compareAtPrice,
|
package/dist/pricing/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ export * from '../pricing/amountToCents';
|
|
|
2
2
|
export * from '../pricing/computeCompareAtPrice';
|
|
3
3
|
export * from '../pricing/computeDisplayPrice';
|
|
4
4
|
export * from '../pricing/currencyDecimals';
|
|
5
|
+
export * from '../pricing/postPurchaseDisplayFacts';
|
|
6
|
+
export * from '../pricing/postPurchaseReduction';
|
|
5
7
|
export * from '../pricing/priceVariant';
|
|
6
8
|
export * from '../pricing/types';
|
package/dist/pricing/index.mjs
CHANGED
|
@@ -77,6 +77,59 @@ var currencyDecimals = (currencyCode) => {
|
|
|
77
77
|
return decimals;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
+
// src/pricing/postPurchaseReduction.ts
|
|
81
|
+
var reducePostPurchaseMinor = (priceMinor, { amount, type }, decimals) => {
|
|
82
|
+
if (type === "price") return amountToCents(amount, decimals);
|
|
83
|
+
const reduction = type === "percentage" ? Math.round(priceMinor * (amount / 100)) : type === "fixed_amount" ? amountToCents(amount, decimals) : 0;
|
|
84
|
+
return Math.max(0, priceMinor - reduction);
|
|
85
|
+
};
|
|
86
|
+
var postPurchasePlanDiscountPercentage = (price, adjustment) => {
|
|
87
|
+
const regularMinor = amountToCents(price);
|
|
88
|
+
const planMinor = adjustment ? reducePostPurchaseMinor(regularMinor, adjustment, 2) : regularMinor;
|
|
89
|
+
return regularMinor > 0 && planMinor < regularMinor ? Math.round((1 - planMinor / regularMinor) * 100) : 0;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/pricing/postPurchaseDisplayFacts.ts
|
|
93
|
+
var wholePercent = (savingMinor, struckMinor) => {
|
|
94
|
+
const percent = savingMinor / struckMinor * 100;
|
|
95
|
+
return Math.round(percent.toString().length > 5 ? Number(percent.toFixed(2)) : percent);
|
|
96
|
+
};
|
|
97
|
+
var postPurchaseDisplayPricing = ({
|
|
98
|
+
compareAtPrice,
|
|
99
|
+
currencyCode,
|
|
100
|
+
discount,
|
|
101
|
+
discountedFrom,
|
|
102
|
+
plan,
|
|
103
|
+
price
|
|
104
|
+
}) => {
|
|
105
|
+
const decimals = currencyDecimals(currencyCode);
|
|
106
|
+
const regularMinor = amountToCents(price, decimals);
|
|
107
|
+
const compareAtMinor = amountToCents(compareAtPrice, decimals);
|
|
108
|
+
const fromCompareAt = discountedFrom === "compare_at_price" || discount.type === "none" && !plan;
|
|
109
|
+
const comparisonMinor = fromCompareAt && compareAtMinor > regularMinor ? compareAtMinor : regularMinor;
|
|
110
|
+
const planMinor = plan ? reducePostPurchaseMinor(regularMinor, plan, decimals) : regularMinor;
|
|
111
|
+
const priceMinor = reducePostPurchaseMinor(planMinor, discount, decimals);
|
|
112
|
+
const savingMinor = Math.max(0, comparisonMinor - priceMinor);
|
|
113
|
+
return {
|
|
114
|
+
comparisonMinor,
|
|
115
|
+
priceMinor,
|
|
116
|
+
savingMinor,
|
|
117
|
+
savingPercent: savingMinor && wholePercent(savingMinor, comparisonMinor)
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
var postPurchaseDisplayFacts = (input) => {
|
|
121
|
+
const { comparisonMinor, priceMinor, savingMinor, savingPercent } = postPurchaseDisplayPricing(input);
|
|
122
|
+
const percentPlan = input.plan?.type === "fixed_amount" || input.plan?.type === "price";
|
|
123
|
+
return {
|
|
124
|
+
currencyCode: input.currencyCode,
|
|
125
|
+
savingFormat: !percentPlan && input.discount.type === "fixed_amount" ? "amount" : "percent",
|
|
126
|
+
savingMinor,
|
|
127
|
+
savingPercent,
|
|
128
|
+
variantCompareAtPriceMinor: savingMinor > 0 ? comparisonMinor : null,
|
|
129
|
+
variantPriceMinor: priceMinor
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
80
133
|
// src/pricing/priceVariant.ts
|
|
81
134
|
var priceVariant = ({
|
|
82
135
|
compareAtPrice,
|
|
@@ -112,5 +165,9 @@ export {
|
|
|
112
165
|
computeCompareAtPrice,
|
|
113
166
|
computeDisplayPrice,
|
|
114
167
|
currencyDecimals,
|
|
115
|
-
|
|
168
|
+
postPurchaseDisplayFacts,
|
|
169
|
+
postPurchaseDisplayPricing,
|
|
170
|
+
postPurchasePlanDiscountPercentage,
|
|
171
|
+
priceVariant,
|
|
172
|
+
reducePostPurchaseMinor
|
|
116
173
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type PostPurchaseReduction } from '../pricing/postPurchaseReduction';
|
|
2
|
+
export type PostPurchaseDisplayFactsInput = {
|
|
3
|
+
compareAtPrice: number | string | null;
|
|
4
|
+
currencyCode: string;
|
|
5
|
+
/** The Widget's discount for this choice (the subscription discount on a plan choice). */
|
|
6
|
+
discount: PostPurchaseReduction;
|
|
7
|
+
discountedFrom: 'price' | 'compare_at_price';
|
|
8
|
+
/** The selected plan's adjustment; a plan choice without one, or a one-time choice, omits it. */
|
|
9
|
+
plan?: PostPurchaseReduction;
|
|
10
|
+
price: number | string;
|
|
11
|
+
};
|
|
12
|
+
/** `PostPurchaseDisplayPrice` without the subscription unit estimate. */
|
|
13
|
+
export type PostPurchaseDisplayFacts = {
|
|
14
|
+
currencyCode: string;
|
|
15
|
+
savingFormat: 'amount' | 'percent';
|
|
16
|
+
savingMinor: number;
|
|
17
|
+
savingPercent: number;
|
|
18
|
+
variantCompareAtPriceMinor: number | null;
|
|
19
|
+
variantPriceMinor: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Legacy `calculateDiscount` for the current choice. The comparison is the compare-at price when it is strictly
|
|
23
|
+
* higher and the Widget discounts from it (L136) or nothing reduces the price at all (L137 as the inventory states
|
|
24
|
+
* it, Peter 2026-10-02 — legacy never reached that branch), else the regular price; the plan then the Widget discount
|
|
25
|
+
* compound on the regular price (L138). A strike shows only above the price. The saving text is currency for a
|
|
26
|
+
* fixed Widget discount (L140), except that a plan priced or reduced by a fixed amount always shows a percent
|
|
27
|
+
* (`useDiscountText`, L143 — here the real rounded percent, not legacy's float or its inverted fixed maths).
|
|
28
|
+
*/
|
|
29
|
+
export declare const postPurchaseDisplayPricing: ({ compareAtPrice, currencyCode, discount, discountedFrom, plan, price, }: PostPurchaseDisplayFactsInput) => {
|
|
30
|
+
comparisonMinor: number;
|
|
31
|
+
priceMinor: number;
|
|
32
|
+
savingMinor: number;
|
|
33
|
+
savingPercent: number;
|
|
34
|
+
};
|
|
35
|
+
/** The display facts rebuy-api sends as `displayPrice` (minus `subscriptionUnit`), in the currency's minor units. */
|
|
36
|
+
export declare const postPurchaseDisplayFacts: (input: PostPurchaseDisplayFactsInput) => PostPurchaseDisplayFacts;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { PostPurchaseDisplayPrice } from '../schema/postPurchaseDisplayPrice';
|
|
3
|
+
import type { PreparedPostPurchaseProduct } from '../schema/postPurchaseProduct';
|
|
4
|
+
/**
|
|
5
|
+
* The prepared view's `displayPrice` for the choice this preparation binds — one-time or a plan — derived from the
|
|
6
|
+
* same preparation the changeset is, in the buyer's presentment currency. A plan choice also carries the unit estimate.
|
|
7
|
+
*/
|
|
8
|
+
export declare const postPurchaseDisplayPrice: (prepared: z.infer<typeof PreparedPostPurchaseProduct>, currencyCode: string) => PostPurchaseDisplayPrice;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A Widget discount or a selling-plan adjustment as the prepared terms carry them (`'amount'` already normalised). */
|
|
2
|
+
export type PostPurchaseReduction = {
|
|
3
|
+
amount: number;
|
|
4
|
+
type: 'none' | 'percentage' | 'fixed_amount' | 'price';
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Legacy `discountCalculation` in the currency's minor units: a percentage rounds on the minor price (L133), a
|
|
8
|
+
* fixed amount is its minor units, a plan `price` replaces the price outright (L139), and nothing goes below 0
|
|
9
|
+
* (L135). Legacy's `subtract` floor (L134) is a no-op on the integer reduction.
|
|
10
|
+
*/
|
|
11
|
+
export declare const reducePostPurchaseMinor: (priceMinor: number, { amount, type }: PostPurchaseReduction, decimals: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* cab-checkout's per-plan `discountPercentage` (`allocationDiscount`): the plan's own whole-percent saving on the
|
|
14
|
+
* regular price, before any Widget discount, and 0 when the plan saves nothing. Scale-free, so hundredths serve
|
|
15
|
+
* every currency.
|
|
16
|
+
*/
|
|
17
|
+
export declare const postPurchasePlanDiscountPercentage: (price: number | string, adjustment?: PostPurchaseReduction) => number;
|
|
@@ -57,6 +57,7 @@ __export(common_exports, {
|
|
|
57
57
|
VariableType: () => VariableType,
|
|
58
58
|
VariantMode: () => VariantMode,
|
|
59
59
|
VariantSelector: () => VariantSelector,
|
|
60
|
+
VariantsMode: () => VariantsMode,
|
|
60
61
|
VerticalAlignment: () => VerticalAlignment,
|
|
61
62
|
WidgetType: () => WidgetType,
|
|
62
63
|
bannerColors: () => bannerColors,
|
|
@@ -98,6 +99,7 @@ __export(common_exports, {
|
|
|
98
99
|
variableTypes: () => variableTypes,
|
|
99
100
|
variantModes: () => variantModes,
|
|
100
101
|
variantSelectors: () => variantSelectors,
|
|
102
|
+
variantsModes: () => variantsModes,
|
|
101
103
|
verticalAlignments: () => verticalAlignments,
|
|
102
104
|
widgetTypes: () => widgetTypes
|
|
103
105
|
});
|
|
@@ -275,6 +277,8 @@ var variableTypes = ["boolean", "number", "text"];
|
|
|
275
277
|
var VariableType = freezeEnum(variableTypes);
|
|
276
278
|
var variantModes = ["multiple", "single"];
|
|
277
279
|
var VariantMode = freezeEnum(variantModes);
|
|
280
|
+
var variantsModes = [...variantModes, "productGroup"];
|
|
281
|
+
var VariantsMode = freezeEnum(variantsModes);
|
|
278
282
|
var variantSelectors = ["menu", "radio", "button"];
|
|
279
283
|
var VariantSelector = freezeEnum(variantSelectors);
|
|
280
284
|
var verticalAlignments = ["top", "middle", "bottom"];
|
|
@@ -172,6 +172,8 @@ var variableTypes = ["boolean", "number", "text"];
|
|
|
172
172
|
var VariableType = freezeEnum(variableTypes);
|
|
173
173
|
var variantModes = ["multiple", "single"];
|
|
174
174
|
var VariantMode = freezeEnum(variantModes);
|
|
175
|
+
var variantsModes = [...variantModes, "productGroup"];
|
|
176
|
+
var VariantsMode = freezeEnum(variantsModes);
|
|
175
177
|
var variantSelectors = ["menu", "radio", "button"];
|
|
176
178
|
var VariantSelector = freezeEnum(variantSelectors);
|
|
177
179
|
var verticalAlignments = ["top", "middle", "bottom"];
|
|
@@ -241,6 +243,7 @@ export {
|
|
|
241
243
|
VariableType,
|
|
242
244
|
VariantMode,
|
|
243
245
|
VariantSelector,
|
|
246
|
+
VariantsMode,
|
|
244
247
|
VerticalAlignment,
|
|
245
248
|
WidgetType,
|
|
246
249
|
bannerColors,
|
|
@@ -282,6 +285,7 @@ export {
|
|
|
282
285
|
variableTypes,
|
|
283
286
|
variantModes,
|
|
284
287
|
variantSelectors,
|
|
288
|
+
variantsModes,
|
|
285
289
|
verticalAlignments,
|
|
286
290
|
widgetTypes
|
|
287
291
|
};
|