@rebuy/rebuy 2.32.0-rc.1 → 2.32.0-rc.2

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.js CHANGED
@@ -3489,6 +3489,18 @@ var convertTextToTiptapParagraph = ({
3489
3489
  });
3490
3490
  };
3491
3491
 
3492
+ // src/transforms/normalizeTokens.ts
3493
+ var DEFAULT_KNOWN_TOKENS = ["firstName", "lastName", "email"];
3494
+ var escapeForRegex = (literal) => literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3495
+ var normalizeTokens = (text, knownTokens = DEFAULT_KNOWN_TOKENS) => {
3496
+ if (typeof text !== "string") return text;
3497
+ return knownTokens.reduce((acc, token) => {
3498
+ const snakeTolerant = escapeForRegex(token).replace(/([A-Z])/g, "_?$1");
3499
+ const pattern = new RegExp(`\\{{1,2}\\s*${snakeTolerant}\\s*\\}{1,2}`, "gi");
3500
+ return acc.replace(pattern, `{{${token}}}`);
3501
+ }, text);
3502
+ };
3503
+
3492
3504
  // src/transforms/contentBlockV1/convertContentBlockTextToV2.ts
3493
3505
  var convertContentBlockTextToV2 = (language) => {
3494
3506
  const description = language?.description;
@@ -3501,20 +3513,20 @@ var convertContentBlockTextToV2 = (language) => {
3501
3513
  color: "base",
3502
3514
  fontSize: "extraLarge",
3503
3515
  marks: [{ type: "bold" }],
3504
- text: superTitle,
3516
+ text: normalizeTokens(superTitle),
3505
3517
  textAlign: "center"
3506
3518
  }) : null,
3507
3519
  title ? convertTextToTiptapParagraph({
3508
3520
  color: "base",
3509
3521
  fontSize: "medium",
3510
3522
  marks: [{ type: "bold" }],
3511
- text: title,
3523
+ text: normalizeTokens(title),
3512
3524
  textAlign: "center"
3513
3525
  }) : null,
3514
3526
  description ? convertTextToTiptapParagraph({
3515
3527
  color: "base",
3516
3528
  fontSize: "base",
3517
- text: description,
3529
+ text: normalizeTokens(description),
3518
3530
  textAlign: "center"
3519
3531
  }) : null
3520
3532
  ].filter((p) => p !== null),
@@ -3523,8 +3535,8 @@ var convertContentBlockTextToV2 = (language) => {
3523
3535
  };
3524
3536
 
3525
3537
  // src/transforms/localizedContent.ts
3526
- var localizedContent = (defaults, override) => {
3527
- const trimmed = stripContentBlockHtml(override ?? "").trim();
3538
+ var localizedContent = (defaults, override, knownTokens = []) => {
3539
+ const trimmed = normalizeTokens(stripContentBlockHtml(override ?? "").trim(), knownTokens);
3528
3540
  return trimmed ? { ...defaults, en: trimmed } : defaults;
3529
3541
  };
3530
3542
 
@@ -3971,6 +3983,9 @@ var buildOfferTemplate = ({ location: location2, name } = {}) => CABRootSection.
3971
3983
  });
3972
3984
 
3973
3985
  // src/transforms/offerV1/offerCard.ts
3986
+ var ADD_LABEL_TOKENS = ["quantity", "price", "total"];
3987
+ var SWITCH_LABEL_TOKENS = ["subscriptionDiscount", "frequency", "interval"];
3988
+ var QUANTITY_ERROR_TOKENS = ["max", "min", "step"];
3974
3989
  var VARIANT_SELECTOR = { button: "button", radio: "radio", select: "menu" };
3975
3990
  var buildStyledText = (token, style, color = "base") => {
3976
3991
  const marks = [
@@ -4056,9 +4071,9 @@ var QUANTITY_INPUT_TYPE = {
4056
4071
  };
4057
4072
  var buildQuantityErrors = (quantity) => {
4058
4073
  const en = {
4059
- ...quantity.maxError && { max: quantity.maxError },
4060
- ...quantity.minError && { min: quantity.minError },
4061
- ...quantity.negativeError && { neg: quantity.negativeError }
4074
+ ...quantity.maxError && { max: normalizeTokens(quantity.maxError, QUANTITY_ERROR_TOKENS) },
4075
+ ...quantity.minError && { min: normalizeTokens(quantity.minError, QUANTITY_ERROR_TOKENS) },
4076
+ ...quantity.negativeError && { neg: normalizeTokens(quantity.negativeError, QUANTITY_ERROR_TOKENS) }
4062
4077
  };
4063
4078
  return Object.keys(en).length ? { errorMessages: { en } } : {};
4064
4079
  };
@@ -4083,7 +4098,7 @@ var buildSubscriptionButton = (settings) => {
4083
4098
  const language = settings.language;
4084
4099
  const slot = (buttonField, override) => ({
4085
4100
  buttonField,
4086
- content: localizedContent(SWITCH_LABELS[buttonField], override),
4101
+ content: localizedContent(SWITCH_LABELS[buttonField], override, SWITCH_LABEL_TOKENS),
4087
4102
  sectionType: "text"
4088
4103
  });
4089
4104
  return [
@@ -4107,7 +4122,7 @@ var buildAddButton = (settings) => {
4107
4122
  const kind = settings.button?.kind;
4108
4123
  const slot = (buttonField, override) => ({
4109
4124
  buttonField,
4110
- content: localizedContent(OFFER_LABELS[buttonField], override),
4125
+ content: localizedContent(OFFER_LABELS[buttonField], override, ADD_LABEL_TOKENS),
4111
4126
  sectionType: "text"
4112
4127
  });
4113
4128
  return {