@rebuy/rebuy 3.65.0 → 3.66.1

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 CHANGED
@@ -238,9 +238,11 @@ __export(src_exports, {
238
238
  PostPurchaseReviewStyles: () => PostPurchaseReviewStyles,
239
239
  PostPurchaseSessionIdSchema: () => PostPurchaseSessionIdSchema,
240
240
  PostPurchaseSettings: () => PostPurchaseSettings,
241
+ PostPurchaseShadowFlowOutcomesSchema: () => PostPurchaseShadowFlowOutcomesSchema,
241
242
  PostPurchaseShadowReportFields: () => PostPurchaseShadowReportFields,
242
243
  PostPurchaseShadowReportSchema: () => PostPurchaseShadowReportSchema,
243
244
  PostPurchaseShadowSelectionSchema: () => PostPurchaseShadowSelectionSchema,
245
+ PostPurchaseShadowSkipReasonSchema: () => PostPurchaseShadowSkipReasonSchema,
244
246
  PostPurchaseSkipReasonSchema: () => PostPurchaseSkipReasonSchema,
245
247
  PostPurchaseSkipTraceSchema: () => PostPurchaseSkipTraceSchema,
246
248
  PostPurchaseStsContext: () => PostPurchaseStsContext,
@@ -5119,6 +5121,20 @@ var PostPurchaseShadowSelectionSchema = import_zod88.z.discriminatedUnion("verdi
5119
5121
  import_zod88.z.object({ entry: DecisionEntrySchema, verdict: import_zod88.z.literal("render") }),
5120
5122
  import_zod88.z.object({ verdict: import_zod88.z.literal("skip") })
5121
5123
  ]);
5124
+ var PostPurchaseShadowSkipReasonSchema = import_zod88.z.enum([
5125
+ "destination-missing",
5126
+ "merchant-destination",
5127
+ "merchant-time",
5128
+ "no-active-flows",
5129
+ "no-eligible-flow",
5130
+ "prelude-timeout"
5131
+ ]);
5132
+ var PostPurchaseShadowFlowOutcomesSchema = import_zod88.z.array(
5133
+ import_zod88.z.object({
5134
+ flowId: import_zod88.z.number().int().positive(),
5135
+ outcome: import_zod88.z.enum(["eligible", "empty", "failed", "unsupported"])
5136
+ })
5137
+ ).max(POST_PURCHASE_SKIP_LIMIT);
5122
5138
  var PostPurchaseShadowReportFields = import_zod88.z.object({
5123
5139
  differences: import_zod88.z.array(import_zod88.z.enum(["verdict", "entry", "targeting", "incomplete-capture", "unsupported-configuration"])).refine((differences) => new Set(differences).size === differences.length, {
5124
5140
  message: "differences must not contain duplicate entries"
@@ -5126,7 +5142,14 @@ var PostPurchaseShadowReportFields = import_zod88.z.object({
5126
5142
  legacySelection: PostPurchaseShadowSelectionSchema,
5127
5143
  phase: import_zod88.z.literal("shouldRender"),
5128
5144
  sampleId: import_zod88.z.string(),
5145
+ /** Optional so rows and senders from before REB-25425 stay valid; never part of the classification. */
5146
+ serverFlowOutcomes: PostPurchaseShadowFlowOutcomesSchema.optional(),
5129
5147
  serverSelection: PostPurchaseShadowSelectionSchema.optional(),
5148
+ /**
5149
+ * Set by the sender when the Decider skipped, `incomplete` reports included (which carry no
5150
+ * `serverSelection`). Not validated against `serverSelection`, and never part of the classification.
5151
+ */
5152
+ serverSkipReason: PostPurchaseShadowSkipReasonSchema.optional(),
5130
5153
  status: import_zod88.z.enum(["match", "diverged", "incomplete"]),
5131
5154
  targetingFlowIds: import_zod88.z.array(import_zod88.z.number().int().positive()),
5132
5155
  workflowPhase: import_zod88.z.literal("decide")
package/dist/index.mjs CHANGED
@@ -4636,6 +4636,20 @@ var PostPurchaseShadowSelectionSchema = z88.discriminatedUnion("verdict", [
4636
4636
  z88.object({ entry: DecisionEntrySchema, verdict: z88.literal("render") }),
4637
4637
  z88.object({ verdict: z88.literal("skip") })
4638
4638
  ]);
4639
+ var PostPurchaseShadowSkipReasonSchema = z88.enum([
4640
+ "destination-missing",
4641
+ "merchant-destination",
4642
+ "merchant-time",
4643
+ "no-active-flows",
4644
+ "no-eligible-flow",
4645
+ "prelude-timeout"
4646
+ ]);
4647
+ var PostPurchaseShadowFlowOutcomesSchema = z88.array(
4648
+ z88.object({
4649
+ flowId: z88.number().int().positive(),
4650
+ outcome: z88.enum(["eligible", "empty", "failed", "unsupported"])
4651
+ })
4652
+ ).max(POST_PURCHASE_SKIP_LIMIT);
4639
4653
  var PostPurchaseShadowReportFields = z88.object({
4640
4654
  differences: z88.array(z88.enum(["verdict", "entry", "targeting", "incomplete-capture", "unsupported-configuration"])).refine((differences) => new Set(differences).size === differences.length, {
4641
4655
  message: "differences must not contain duplicate entries"
@@ -4643,7 +4657,14 @@ var PostPurchaseShadowReportFields = z88.object({
4643
4657
  legacySelection: PostPurchaseShadowSelectionSchema,
4644
4658
  phase: z88.literal("shouldRender"),
4645
4659
  sampleId: z88.string(),
4660
+ /** Optional so rows and senders from before REB-25425 stay valid; never part of the classification. */
4661
+ serverFlowOutcomes: PostPurchaseShadowFlowOutcomesSchema.optional(),
4646
4662
  serverSelection: PostPurchaseShadowSelectionSchema.optional(),
4663
+ /**
4664
+ * Set by the sender when the Decider skipped, `incomplete` reports included (which carry no
4665
+ * `serverSelection`). Not validated against `serverSelection`, and never part of the classification.
4666
+ */
4667
+ serverSkipReason: PostPurchaseShadowSkipReasonSchema.optional(),
4647
4668
  status: z88.enum(["match", "diverged", "incomplete"]),
4648
4669
  targetingFlowIds: z88.array(z88.number().int().positive()),
4649
4670
  workflowPhase: z88.literal("decide")
@@ -6919,9 +6940,11 @@ export {
6919
6940
  PostPurchaseReviewStyles,
6920
6941
  PostPurchaseSessionIdSchema,
6921
6942
  PostPurchaseSettings,
6943
+ PostPurchaseShadowFlowOutcomesSchema,
6922
6944
  PostPurchaseShadowReportFields,
6923
6945
  PostPurchaseShadowReportSchema,
6924
6946
  PostPurchaseShadowSelectionSchema,
6947
+ PostPurchaseShadowSkipReasonSchema,
6925
6948
  PostPurchaseSkipReasonSchema,
6926
6949
  PostPurchaseSkipTraceSchema,
6927
6950
  PostPurchaseStsContext,
@@ -15,6 +15,38 @@ export declare const PostPurchaseShadowSelectionSchema: z.ZodDiscriminatedUnion<
15
15
  verdict: z.ZodLiteral<"skip">;
16
16
  }, z.core.$strip>], "verdict">;
17
17
  export type PostPurchaseShadowSelection = z.infer<typeof PostPurchaseShadowSelectionSchema>;
18
+ /**
19
+ * Why the Decider skipped: a merchant/destination exit, no active Flow, no Flow with an eligible entry node,
20
+ * or a prelude that did not settle in budget. Diagnostic only. A hand-kept mirror of rebuy-api's
21
+ * `DecisionSkipReasonSchema`: a reason added there fails this parse, so the sender checks its reason against
22
+ * {@link PostPurchaseShadowSkipReason} at compile time and a new reason ships here first.
23
+ */
24
+ export declare const PostPurchaseShadowSkipReasonSchema: z.ZodEnum<{
25
+ "destination-missing": "destination-missing";
26
+ "merchant-destination": "merchant-destination";
27
+ "merchant-time": "merchant-time";
28
+ "no-active-flows": "no-active-flows";
29
+ "no-eligible-flow": "no-eligible-flow";
30
+ "prelude-timeout": "prelude-timeout";
31
+ }>;
32
+ export type PostPurchaseShadowSkipReason = z.infer<typeof PostPurchaseShadowSkipReasonSchema>;
33
+ /**
34
+ * Each evaluated Flow's outcome from the Decider's completed trace, in evaluation order. Capped at
35
+ * `POST_PURCHASE_SKIP_LIMIT` like the skip trace, since a shop can have more Flows than a ledger row should carry.
36
+ * The cap rejects rather than clips, so a sender slices to the limit before parsing. A shadow sample holds at most
37
+ * rebuy-api's `SHADOW_MAX_FLOWS` (10) Flows, so the list is complete there; carry a truncation marker before
38
+ * anything reports more Flows than the cap.
39
+ */
40
+ export declare const PostPurchaseShadowFlowOutcomesSchema: z.ZodArray<z.ZodObject<{
41
+ flowId: z.ZodNumber;
42
+ outcome: z.ZodEnum<{
43
+ empty: "empty";
44
+ unsupported: "unsupported";
45
+ failed: "failed";
46
+ eligible: "eligible";
47
+ }>;
48
+ }, z.core.$strip>>;
49
+ export type PostPurchaseShadowFlowOutcomes = z.infer<typeof PostPurchaseShadowFlowOutcomesSchema>;
18
50
  /**
19
51
  * The shadow report's fields WITHOUT the status/differences cross-field refinements below — the derivable
20
52
  * base. `PostPurchaseShadowReportSchema` was a plain `ZodObject` before those refinements were added, and
@@ -48,6 +80,15 @@ export declare const PostPurchaseShadowReportFields: z.ZodObject<{
48
80
  }, z.core.$strip>], "verdict">;
49
81
  phase: z.ZodLiteral<"shouldRender">;
50
82
  sampleId: z.ZodString;
83
+ serverFlowOutcomes: z.ZodOptional<z.ZodArray<z.ZodObject<{
84
+ flowId: z.ZodNumber;
85
+ outcome: z.ZodEnum<{
86
+ empty: "empty";
87
+ unsupported: "unsupported";
88
+ failed: "failed";
89
+ eligible: "eligible";
90
+ }>;
91
+ }, z.core.$strip>>>;
51
92
  serverSelection: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
52
93
  entry: z.ZodObject<{
53
94
  blockId: z.ZodNumber;
@@ -62,6 +103,14 @@ export declare const PostPurchaseShadowReportFields: z.ZodObject<{
62
103
  }, z.core.$strip>, z.ZodObject<{
63
104
  verdict: z.ZodLiteral<"skip">;
64
105
  }, z.core.$strip>], "verdict">>;
106
+ serverSkipReason: z.ZodOptional<z.ZodEnum<{
107
+ "destination-missing": "destination-missing";
108
+ "merchant-destination": "merchant-destination";
109
+ "merchant-time": "merchant-time";
110
+ "no-active-flows": "no-active-flows";
111
+ "no-eligible-flow": "no-eligible-flow";
112
+ "prelude-timeout": "prelude-timeout";
113
+ }>>;
65
114
  status: z.ZodEnum<{
66
115
  match: "match";
67
116
  diverged: "diverged";
@@ -99,6 +148,15 @@ export declare const PostPurchaseShadowReportSchema: z.ZodObject<{
99
148
  }, z.core.$strip>], "verdict">;
100
149
  phase: z.ZodLiteral<"shouldRender">;
101
150
  sampleId: z.ZodString;
151
+ serverFlowOutcomes: z.ZodOptional<z.ZodArray<z.ZodObject<{
152
+ flowId: z.ZodNumber;
153
+ outcome: z.ZodEnum<{
154
+ empty: "empty";
155
+ unsupported: "unsupported";
156
+ failed: "failed";
157
+ eligible: "eligible";
158
+ }>;
159
+ }, z.core.$strip>>>;
102
160
  serverSelection: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
103
161
  entry: z.ZodObject<{
104
162
  blockId: z.ZodNumber;
@@ -113,6 +171,14 @@ export declare const PostPurchaseShadowReportSchema: z.ZodObject<{
113
171
  }, z.core.$strip>, z.ZodObject<{
114
172
  verdict: z.ZodLiteral<"skip">;
115
173
  }, z.core.$strip>], "verdict">>;
174
+ serverSkipReason: z.ZodOptional<z.ZodEnum<{
175
+ "destination-missing": "destination-missing";
176
+ "merchant-destination": "merchant-destination";
177
+ "merchant-time": "merchant-time";
178
+ "no-active-flows": "no-active-flows";
179
+ "no-eligible-flow": "no-eligible-flow";
180
+ "prelude-timeout": "prelude-timeout";
181
+ }>>;
116
182
  status: z.ZodEnum<{
117
183
  match: "match";
118
184
  diverged: "diverged";
@@ -5335,7 +5335,14 @@ var MAX_ICON_SIZE_PX = 64;
5335
5335
  var IN_SCOPE_TIER_TYPES = new Set(progressTierTypes);
5336
5336
  var inScope = (tier) => IN_SCOPE_TIER_TYPES.has(tier.type ?? "");
5337
5337
  var thresholdOf = (tier) => tier.unlockConditionType === "item_quantity" ? Math.ceil(Number(tier.minimum)) : Math.round(Number(tier.minimum) * 100);
5338
- var tierThresholds = (tier) => presentmentThresholds(tier.presentmentCurrencies);
5338
+ var tierThresholds = (tier, shopCurrency) => {
5339
+ const shopCode = shopCurrency?.toLowerCase();
5340
+ return Object.fromEntries(
5341
+ Object.entries(presentmentThresholds(tier.presentmentCurrencies)).filter(
5342
+ ([code, cents]) => cents > 0 && code !== shopCode
5343
+ )
5344
+ );
5345
+ };
5339
5346
  var tierLabel = (tier) => {
5340
5347
  const type = tier.type;
5341
5348
  if ((tier.customTierLabel || type === "decorative") && tier.customTierLabelText) return tier.customTierLabelText;
@@ -5389,7 +5396,7 @@ var exclusionsOf = (tier) => {
5389
5396
  });
5390
5397
  return rules.length > 0 ? rules : void 0;
5391
5398
  };
5392
- var toTierMeta = (tier) => {
5399
+ var toTierMeta = (tier, shopCurrency) => {
5393
5400
  const discount = discountOf(tier);
5394
5401
  const exclusions = exclusionsOf(tier);
5395
5402
  const gift = giftOf(tier);
@@ -5410,16 +5417,16 @@ var toTierMeta = (tier) => {
5410
5417
  /** Carry the image-swap flag only on gift tiers that set it — the client shows the gift's product image in the step slot instead of the bag icon. */
5411
5418
  ...gift && tier.productTierImage && { productTierImage: true },
5412
5419
  threshold: thresholdOf(tier),
5413
- thresholds: !isItemCount && type === "shipping" ? tierThresholds(tier) : {},
5420
+ thresholds: isItemCount ? {} : tierThresholds(tier, shopCurrency),
5414
5421
  ...tier.id && { tierId: tier.id },
5415
5422
  tierType: type,
5416
5423
  ...isItemCount && { unit: "item" }
5417
5424
  };
5418
5425
  };
5419
- var renderableTiers = (bar) => (bar.tiers ?? []).filter(
5426
+ var renderableTiers = (bar, shopCurrency) => (bar.tiers ?? []).filter(
5420
5427
  (tier) => (
5421
5428
  /** onsite `isTierDataValid`: a non-numeric (null/absent) minimum is dropped — else `thresholdOf` reads it as 0, an always-reached tier that auto-adds its gift to every cart. A literal 0 is finite and kept. Divergence: onsite's strict `typeof === 'number'` also drops a string `'50'`; here `minimum` was already `z.coerce`d (`'50' → 50`), so `Number.isFinite` keeps it — see smartCart.ts. */
5422
- inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier)).success
5429
+ inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier, shopCurrency)).success
5423
5430
  )
5424
5431
  );
5425
5432
  var PRODUCT_TOKENS = ["productTitle", "remainingAmount"];
@@ -5474,7 +5481,7 @@ var toTierFeedback = (tier) => {
5474
5481
  });
5475
5482
  return sections;
5476
5483
  };
5477
- var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor) => ({
5484
+ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor, shopCurrency) => ({
5478
5485
  /**
5479
5486
  * React's `SmartCartProgressBarContent` centers the bar/message stack (`inlineAlignment="center"`); the
5480
5487
  * section inherits `layout`'s `alignment.horizontal: 'start'`, so an emitted-bare bar would left-align.
@@ -5530,7 +5537,7 @@ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progr
5530
5537
  sectionType: "progressBar",
5531
5538
  /** React's bar/message stack uses `spacing="tight"` (→ `small-100`); `layout` defaults `spacing` to `base`, a wider gap. Emit `tight` for parity (mirrors the v1 shipping converter). */
5532
5539
  spacing: "tight",
5533
- tiers: tiers.map(toTierMeta)
5540
+ tiers: tiers.map((tier) => toTierMeta(tier, shopCurrency))
5534
5541
  });
5535
5542
  var barCountries = (bar) => [
5536
5543
  ...new Set((bar.countryCodes ?? []).map((code) => code.trim().toUpperCase()).filter(Boolean))
@@ -5556,9 +5563,16 @@ var dedupeBars = (entries) => {
5556
5563
  return rendered;
5557
5564
  };
5558
5565
  var convertSmartCartProgressBarToV2 = (input) => {
5559
- const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar) }));
5566
+ const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar, input.shopCurrency) }));
5560
5567
  const sections = dedupeBars(entries).map(
5561
- ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(entry.bar, entry.tiers, countryCodes, excludeCountryCodes, input.progressColor)
5568
+ ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(
5569
+ entry.bar,
5570
+ entry.tiers,
5571
+ countryCodes,
5572
+ excludeCountryCodes,
5573
+ input.progressColor,
5574
+ input.shopCurrency
5575
+ )
5562
5576
  );
5563
5577
  return CABRootSection.parse(
5564
5578
  normalizeTextContent({
@@ -6198,7 +6212,9 @@ var fetchProgressBarContext = async (shop, ctx, prefetched) => {
6198
6212
  const entitled = config.shop.billingVersion !== "v6" || config.shop.activePackages.some((pkg) => pkg.shortName === "cart-merchandising" && pkg.isActive);
6199
6213
  return {
6200
6214
  bars: entitled ? extractSmartCartBars(config.smartCart) : [],
6201
- progressColor: await fetchThemeColor(config.shop.shopId, ctx)
6215
+ progressColor: await fetchThemeColor(config.shop.shopId, ctx),
6216
+ /** The tiers' per-currency thresholds skip the shop's own code (onsite `getStoredPresentmentMinimum`). */
6217
+ shopCurrency: config.shop.currency
6202
6218
  };
6203
6219
  };
6204
6220
  var fetchThemeColor = async (shopId, ctx) => {
@@ -6280,8 +6296,14 @@ var fetchAndConvert = async (id, input, ctx, config) => {
6280
6296
  if (isMissingUpstreamPayload(data)) throw new NotFoundError(`Widget not found: ${id}`);
6281
6297
  const normalized = convertNumericObjects(deepCamelCase(data));
6282
6298
  if (isProgressBarV1(normalized) && normalized.barSettings.barType === "smart-cart") {
6283
- const { bars, progressColor } = await fetchProgressBarContext(input.shop, ctx, config);
6284
- return convertSmartCartProgressBarToV2({ bars: bars ?? [], id, progressColor, settings: normalized });
6299
+ const { bars, progressColor, shopCurrency } = await fetchProgressBarContext(input.shop, ctx, config);
6300
+ return convertSmartCartProgressBarToV2({
6301
+ bars: bars ?? [],
6302
+ id,
6303
+ progressColor,
6304
+ settings: normalized,
6305
+ shopCurrency
6306
+ });
6285
6307
  }
6286
6308
  if (isConvertibleProgressBarV1(normalized)) {
6287
6309
  const { progressColor } = await fetchProgressBarContext(input.shop, ctx, config);
@@ -5262,7 +5262,14 @@ var MAX_ICON_SIZE_PX = 64;
5262
5262
  var IN_SCOPE_TIER_TYPES = new Set(progressTierTypes);
5263
5263
  var inScope = (tier) => IN_SCOPE_TIER_TYPES.has(tier.type ?? "");
5264
5264
  var thresholdOf = (tier) => tier.unlockConditionType === "item_quantity" ? Math.ceil(Number(tier.minimum)) : Math.round(Number(tier.minimum) * 100);
5265
- var tierThresholds = (tier) => presentmentThresholds(tier.presentmentCurrencies);
5265
+ var tierThresholds = (tier, shopCurrency) => {
5266
+ const shopCode = shopCurrency?.toLowerCase();
5267
+ return Object.fromEntries(
5268
+ Object.entries(presentmentThresholds(tier.presentmentCurrencies)).filter(
5269
+ ([code, cents]) => cents > 0 && code !== shopCode
5270
+ )
5271
+ );
5272
+ };
5266
5273
  var tierLabel = (tier) => {
5267
5274
  const type = tier.type;
5268
5275
  if ((tier.customTierLabel || type === "decorative") && tier.customTierLabelText) return tier.customTierLabelText;
@@ -5316,7 +5323,7 @@ var exclusionsOf = (tier) => {
5316
5323
  });
5317
5324
  return rules.length > 0 ? rules : void 0;
5318
5325
  };
5319
- var toTierMeta = (tier) => {
5326
+ var toTierMeta = (tier, shopCurrency) => {
5320
5327
  const discount = discountOf(tier);
5321
5328
  const exclusions = exclusionsOf(tier);
5322
5329
  const gift = giftOf(tier);
@@ -5337,16 +5344,16 @@ var toTierMeta = (tier) => {
5337
5344
  /** Carry the image-swap flag only on gift tiers that set it — the client shows the gift's product image in the step slot instead of the bag icon. */
5338
5345
  ...gift && tier.productTierImage && { productTierImage: true },
5339
5346
  threshold: thresholdOf(tier),
5340
- thresholds: !isItemCount && type === "shipping" ? tierThresholds(tier) : {},
5347
+ thresholds: isItemCount ? {} : tierThresholds(tier, shopCurrency),
5341
5348
  ...tier.id && { tierId: tier.id },
5342
5349
  tierType: type,
5343
5350
  ...isItemCount && { unit: "item" }
5344
5351
  };
5345
5352
  };
5346
- var renderableTiers = (bar) => (bar.tiers ?? []).filter(
5353
+ var renderableTiers = (bar, shopCurrency) => (bar.tiers ?? []).filter(
5347
5354
  (tier) => (
5348
5355
  /** onsite `isTierDataValid`: a non-numeric (null/absent) minimum is dropped — else `thresholdOf` reads it as 0, an always-reached tier that auto-adds its gift to every cart. A literal 0 is finite and kept. Divergence: onsite's strict `typeof === 'number'` also drops a string `'50'`; here `minimum` was already `z.coerce`d (`'50' → 50`), so `Number.isFinite` keeps it — see smartCart.ts. */
5349
- inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier)).success
5356
+ inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier, shopCurrency)).success
5350
5357
  )
5351
5358
  );
5352
5359
  var PRODUCT_TOKENS = ["productTitle", "remainingAmount"];
@@ -5401,7 +5408,7 @@ var toTierFeedback = (tier) => {
5401
5408
  });
5402
5409
  return sections;
5403
5410
  };
5404
- var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor) => ({
5411
+ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor, shopCurrency) => ({
5405
5412
  /**
5406
5413
  * React's `SmartCartProgressBarContent` centers the bar/message stack (`inlineAlignment="center"`); the
5407
5414
  * section inherits `layout`'s `alignment.horizontal: 'start'`, so an emitted-bare bar would left-align.
@@ -5457,7 +5464,7 @@ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progr
5457
5464
  sectionType: "progressBar",
5458
5465
  /** React's bar/message stack uses `spacing="tight"` (→ `small-100`); `layout` defaults `spacing` to `base`, a wider gap. Emit `tight` for parity (mirrors the v1 shipping converter). */
5459
5466
  spacing: "tight",
5460
- tiers: tiers.map(toTierMeta)
5467
+ tiers: tiers.map((tier) => toTierMeta(tier, shopCurrency))
5461
5468
  });
5462
5469
  var barCountries = (bar) => [
5463
5470
  ...new Set((bar.countryCodes ?? []).map((code) => code.trim().toUpperCase()).filter(Boolean))
@@ -5483,9 +5490,16 @@ var dedupeBars = (entries) => {
5483
5490
  return rendered;
5484
5491
  };
5485
5492
  var convertSmartCartProgressBarToV2 = (input) => {
5486
- const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar) }));
5493
+ const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar, input.shopCurrency) }));
5487
5494
  const sections = dedupeBars(entries).map(
5488
- ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(entry.bar, entry.tiers, countryCodes, excludeCountryCodes, input.progressColor)
5495
+ ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(
5496
+ entry.bar,
5497
+ entry.tiers,
5498
+ countryCodes,
5499
+ excludeCountryCodes,
5500
+ input.progressColor,
5501
+ input.shopCurrency
5502
+ )
5489
5503
  );
5490
5504
  return CABRootSection.parse(
5491
5505
  normalizeTextContent({
@@ -6125,7 +6139,9 @@ var fetchProgressBarContext = async (shop, ctx, prefetched) => {
6125
6139
  const entitled = config.shop.billingVersion !== "v6" || config.shop.activePackages.some((pkg) => pkg.shortName === "cart-merchandising" && pkg.isActive);
6126
6140
  return {
6127
6141
  bars: entitled ? extractSmartCartBars(config.smartCart) : [],
6128
- progressColor: await fetchThemeColor(config.shop.shopId, ctx)
6142
+ progressColor: await fetchThemeColor(config.shop.shopId, ctx),
6143
+ /** The tiers' per-currency thresholds skip the shop's own code (onsite `getStoredPresentmentMinimum`). */
6144
+ shopCurrency: config.shop.currency
6129
6145
  };
6130
6146
  };
6131
6147
  var fetchThemeColor = async (shopId, ctx) => {
@@ -6207,8 +6223,14 @@ var fetchAndConvert = async (id, input, ctx, config) => {
6207
6223
  if (isMissingUpstreamPayload(data)) throw new NotFoundError(`Widget not found: ${id}`);
6208
6224
  const normalized = convertNumericObjects(deepCamelCase(data));
6209
6225
  if (isProgressBarV1(normalized) && normalized.barSettings.barType === "smart-cart") {
6210
- const { bars, progressColor } = await fetchProgressBarContext(input.shop, ctx, config);
6211
- return convertSmartCartProgressBarToV2({ bars: bars ?? [], id, progressColor, settings: normalized });
6226
+ const { bars, progressColor, shopCurrency } = await fetchProgressBarContext(input.shop, ctx, config);
6227
+ return convertSmartCartProgressBarToV2({
6228
+ bars: bars ?? [],
6229
+ id,
6230
+ progressColor,
6231
+ settings: normalized,
6232
+ shopCurrency
6233
+ });
6212
6234
  }
6213
6235
  if (isConvertibleProgressBarV1(normalized)) {
6214
6236
  const { progressColor } = await fetchProgressBarContext(input.shop, ctx, config);
@@ -4866,7 +4866,14 @@ var MAX_ICON_SIZE_PX = 64;
4866
4866
  var IN_SCOPE_TIER_TYPES = new Set(progressTierTypes);
4867
4867
  var inScope = (tier) => IN_SCOPE_TIER_TYPES.has(tier.type ?? "");
4868
4868
  var thresholdOf = (tier) => tier.unlockConditionType === "item_quantity" ? Math.ceil(Number(tier.minimum)) : Math.round(Number(tier.minimum) * 100);
4869
- var tierThresholds = (tier) => presentmentThresholds(tier.presentmentCurrencies);
4869
+ var tierThresholds = (tier, shopCurrency) => {
4870
+ const shopCode = shopCurrency?.toLowerCase();
4871
+ return Object.fromEntries(
4872
+ Object.entries(presentmentThresholds(tier.presentmentCurrencies)).filter(
4873
+ ([code, cents]) => cents > 0 && code !== shopCode
4874
+ )
4875
+ );
4876
+ };
4870
4877
  var tierLabel = (tier) => {
4871
4878
  const type = tier.type;
4872
4879
  if ((tier.customTierLabel || type === "decorative") && tier.customTierLabelText) return tier.customTierLabelText;
@@ -4920,7 +4927,7 @@ var exclusionsOf = (tier) => {
4920
4927
  });
4921
4928
  return rules.length > 0 ? rules : void 0;
4922
4929
  };
4923
- var toTierMeta = (tier) => {
4930
+ var toTierMeta = (tier, shopCurrency) => {
4924
4931
  const discount = discountOf(tier);
4925
4932
  const exclusions = exclusionsOf(tier);
4926
4933
  const gift = giftOf(tier);
@@ -4941,16 +4948,16 @@ var toTierMeta = (tier) => {
4941
4948
  /** Carry the image-swap flag only on gift tiers that set it — the client shows the gift's product image in the step slot instead of the bag icon. */
4942
4949
  ...gift && tier.productTierImage && { productTierImage: true },
4943
4950
  threshold: thresholdOf(tier),
4944
- thresholds: !isItemCount && type === "shipping" ? tierThresholds(tier) : {},
4951
+ thresholds: isItemCount ? {} : tierThresholds(tier, shopCurrency),
4945
4952
  ...tier.id && { tierId: tier.id },
4946
4953
  tierType: type,
4947
4954
  ...isItemCount && { unit: "item" }
4948
4955
  };
4949
4956
  };
4950
- var renderableTiers = (bar) => (bar.tiers ?? []).filter(
4957
+ var renderableTiers = (bar, shopCurrency) => (bar.tiers ?? []).filter(
4951
4958
  (tier) => (
4952
4959
  /** onsite `isTierDataValid`: a non-numeric (null/absent) minimum is dropped — else `thresholdOf` reads it as 0, an always-reached tier that auto-adds its gift to every cart. A literal 0 is finite and kept. Divergence: onsite's strict `typeof === 'number'` also drops a string `'50'`; here `minimum` was already `z.coerce`d (`'50' → 50`), so `Number.isFinite` keeps it — see smartCart.ts. */
4953
- inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier)).success
4960
+ inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier, shopCurrency)).success
4954
4961
  )
4955
4962
  );
4956
4963
  var PRODUCT_TOKENS = ["productTitle", "remainingAmount"];
@@ -5005,7 +5012,7 @@ var toTierFeedback = (tier) => {
5005
5012
  });
5006
5013
  return sections;
5007
5014
  };
5008
- var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor) => ({
5015
+ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor, shopCurrency) => ({
5009
5016
  /**
5010
5017
  * React's `SmartCartProgressBarContent` centers the bar/message stack (`inlineAlignment="center"`); the
5011
5018
  * section inherits `layout`'s `alignment.horizontal: 'start'`, so an emitted-bare bar would left-align.
@@ -5061,7 +5068,7 @@ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progr
5061
5068
  sectionType: "progressBar",
5062
5069
  /** React's bar/message stack uses `spacing="tight"` (→ `small-100`); `layout` defaults `spacing` to `base`, a wider gap. Emit `tight` for parity (mirrors the v1 shipping converter). */
5063
5070
  spacing: "tight",
5064
- tiers: tiers.map(toTierMeta)
5071
+ tiers: tiers.map((tier) => toTierMeta(tier, shopCurrency))
5065
5072
  });
5066
5073
  var barCountries = (bar) => [
5067
5074
  ...new Set((bar.countryCodes ?? []).map((code) => code.trim().toUpperCase()).filter(Boolean))
@@ -5087,9 +5094,16 @@ var dedupeBars = (entries) => {
5087
5094
  return rendered;
5088
5095
  };
5089
5096
  var convertSmartCartProgressBarToV2 = (input) => {
5090
- const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar) }));
5097
+ const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar, input.shopCurrency) }));
5091
5098
  const sections = dedupeBars(entries).map(
5092
- ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(entry.bar, entry.tiers, countryCodes, excludeCountryCodes, input.progressColor)
5099
+ ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(
5100
+ entry.bar,
5101
+ entry.tiers,
5102
+ countryCodes,
5103
+ excludeCountryCodes,
5104
+ input.progressColor,
5105
+ input.shopCurrency
5106
+ )
5093
5107
  );
5094
5108
  return CABRootSection.parse(
5095
5109
  normalizeTextContent({
@@ -4805,7 +4805,14 @@ var MAX_ICON_SIZE_PX = 64;
4805
4805
  var IN_SCOPE_TIER_TYPES = new Set(progressTierTypes);
4806
4806
  var inScope = (tier) => IN_SCOPE_TIER_TYPES.has(tier.type ?? "");
4807
4807
  var thresholdOf = (tier) => tier.unlockConditionType === "item_quantity" ? Math.ceil(Number(tier.minimum)) : Math.round(Number(tier.minimum) * 100);
4808
- var tierThresholds = (tier) => presentmentThresholds(tier.presentmentCurrencies);
4808
+ var tierThresholds = (tier, shopCurrency) => {
4809
+ const shopCode = shopCurrency?.toLowerCase();
4810
+ return Object.fromEntries(
4811
+ Object.entries(presentmentThresholds(tier.presentmentCurrencies)).filter(
4812
+ ([code, cents]) => cents > 0 && code !== shopCode
4813
+ )
4814
+ );
4815
+ };
4809
4816
  var tierLabel = (tier) => {
4810
4817
  const type = tier.type;
4811
4818
  if ((tier.customTierLabel || type === "decorative") && tier.customTierLabelText) return tier.customTierLabelText;
@@ -4859,7 +4866,7 @@ var exclusionsOf = (tier) => {
4859
4866
  });
4860
4867
  return rules.length > 0 ? rules : void 0;
4861
4868
  };
4862
- var toTierMeta = (tier) => {
4869
+ var toTierMeta = (tier, shopCurrency) => {
4863
4870
  const discount = discountOf(tier);
4864
4871
  const exclusions = exclusionsOf(tier);
4865
4872
  const gift = giftOf(tier);
@@ -4880,16 +4887,16 @@ var toTierMeta = (tier) => {
4880
4887
  /** Carry the image-swap flag only on gift tiers that set it — the client shows the gift's product image in the step slot instead of the bag icon. */
4881
4888
  ...gift && tier.productTierImage && { productTierImage: true },
4882
4889
  threshold: thresholdOf(tier),
4883
- thresholds: !isItemCount && type === "shipping" ? tierThresholds(tier) : {},
4890
+ thresholds: isItemCount ? {} : tierThresholds(tier, shopCurrency),
4884
4891
  ...tier.id && { tierId: tier.id },
4885
4892
  tierType: type,
4886
4893
  ...isItemCount && { unit: "item" }
4887
4894
  };
4888
4895
  };
4889
- var renderableTiers = (bar) => (bar.tiers ?? []).filter(
4896
+ var renderableTiers = (bar, shopCurrency) => (bar.tiers ?? []).filter(
4890
4897
  (tier) => (
4891
4898
  /** onsite `isTierDataValid`: a non-numeric (null/absent) minimum is dropped — else `thresholdOf` reads it as 0, an always-reached tier that auto-adds its gift to every cart. A literal 0 is finite and kept. Divergence: onsite's strict `typeof === 'number'` also drops a string `'50'`; here `minimum` was already `z.coerce`d (`'50' → 50`), so `Number.isFinite` keeps it — see smartCart.ts. */
4892
- inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier)).success
4899
+ inScope(tier) && Number.isFinite(tier.minimum) && CABProgressTier.safeParse(toTierMeta(tier, shopCurrency)).success
4893
4900
  )
4894
4901
  );
4895
4902
  var PRODUCT_TOKENS = ["productTitle", "remainingAmount"];
@@ -4944,7 +4951,7 @@ var toTierFeedback = (tier) => {
4944
4951
  });
4945
4952
  return sections;
4946
4953
  };
4947
- var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor) => ({
4954
+ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progressColor, shopCurrency) => ({
4948
4955
  /**
4949
4956
  * React's `SmartCartProgressBarContent` centers the bar/message stack (`inlineAlignment="center"`); the
4950
4957
  * section inherits `layout`'s `alignment.horizontal: 'start'`, so an emitted-bare bar would left-align.
@@ -5000,7 +5007,7 @@ var toProgressBarSection = (bar, tiers, countryCodes, excludeCountryCodes, progr
5000
5007
  sectionType: "progressBar",
5001
5008
  /** React's bar/message stack uses `spacing="tight"` (→ `small-100`); `layout` defaults `spacing` to `base`, a wider gap. Emit `tight` for parity (mirrors the v1 shipping converter). */
5002
5009
  spacing: "tight",
5003
- tiers: tiers.map(toTierMeta)
5010
+ tiers: tiers.map((tier) => toTierMeta(tier, shopCurrency))
5004
5011
  });
5005
5012
  var barCountries = (bar) => [
5006
5013
  ...new Set((bar.countryCodes ?? []).map((code) => code.trim().toUpperCase()).filter(Boolean))
@@ -5026,9 +5033,16 @@ var dedupeBars = (entries) => {
5026
5033
  return rendered;
5027
5034
  };
5028
5035
  var convertSmartCartProgressBarToV2 = (input) => {
5029
- const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar) }));
5036
+ const entries = input.bars.map((bar) => ({ bar, tiers: renderableTiers(bar, input.shopCurrency) }));
5030
5037
  const sections = dedupeBars(entries).map(
5031
- ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(entry.bar, entry.tiers, countryCodes, excludeCountryCodes, input.progressColor)
5038
+ ({ countryCodes, entry, excludeCountryCodes }) => toProgressBarSection(
5039
+ entry.bar,
5040
+ entry.tiers,
5041
+ countryCodes,
5042
+ excludeCountryCodes,
5043
+ input.progressColor,
5044
+ input.shopCurrency
5045
+ )
5032
5046
  );
5033
5047
  return CABRootSection.parse(
5034
5048
  normalizeTextContent({
@@ -6,7 +6,7 @@ import { type V1ProgressBarSettings } from '../../transforms/progressBarV1/types
6
6
  * `progressBar` container per configured bar (tiers come from the shop's smart-cart config — see
7
7
  * `extractSmartCartBars`). Each container holds its tier display (composable `columns → rows → text/image`)
8
8
  * + copy as children, with milestones on `tiers` (server-precomputed per tier: cents — base +
9
- * per-presentment-currency for shipping tiers — or a raw item count for `item_quantity` tiers) so the
9
+ * per-presentment-currency on every money tier — or a raw item count for `item_quantity` tiers) so the
10
10
  * client only compares each tier against its own unit's progress, mirroring the shipping bar. DISPLAY
11
11
  * ONLY — gift add/remove is a later stage. Tiers whose meta fails the strict schema are dropped (never
12
12
  * thrown); a bar left with no renderable tier renders nothing — but a geo bar still shadows its countries
@@ -18,4 +18,6 @@ export declare const convertSmartCartProgressBarToV2: (input: {
18
18
  /** The shop theme's `buttonBackground` (bar fill), resolved by the caller; schema-defaulted when absent. */
19
19
  progressColor?: string;
20
20
  settings: V1ProgressBarSettings;
21
+ /** The shop's base-currency ISO code (`CabShopConfig.currency`): its per-currency entry is never a threshold. */
22
+ shopCurrency?: string;
21
23
  }) => CABRootSection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebuy/rebuy",
3
- "version": "3.65.0",
3
+ "version": "3.66.1",
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.",