@capillarytech/creatives-library 9.0.30 → 9.0.32

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "9.0.30",
4
+ "version": "9.0.32",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -665,10 +665,17 @@ const CommonTestAndPreview = (props) => {
665
665
  let resolvedText = text;
666
666
 
667
667
  // Replace each tag with its custom value
668
- Object.keys(tagValues).forEach((tagPath) => {
668
+ Object.keys(tagValues || {}).forEach((tagPath) => {
669
669
  const tagName = tagPath.split('.').pop(); // Get the actual tag name from the path
670
- const tagRegex = new RegExp(`{{${tagName}}}`, 'g');
671
- resolvedText = resolvedText.replace(tagRegex, tagValues[tagPath] || `{{${tagName}}}`);
670
+ // Escape regex metacharacters in tagName (arbitrary JSON key) so it can't break the pattern.
671
+ const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
672
+ const tagRegex = new RegExp(`{{${escapedTagName}}}`, 'g');
673
+ const rawValue = tagValues[tagPath];
674
+ // Preserve legitimate falsy values (0, false); only an unset/blank slot keeps the placeholder.
675
+ const hasValue = rawValue !== null && rawValue !== undefined && rawValue !== '';
676
+ const replacement = hasValue ? String(rawValue) : `{{${tagName}}}`;
677
+ // Replacer function (not a string) so `$&`/`$1`-style sequences in the value are inserted literally.
678
+ resolvedText = resolvedText.replace(tagRegex, () => replacement);
672
679
  });
673
680
 
674
681
  return resolvedText;
@@ -1056,7 +1063,7 @@ const CommonTestAndPreview = (props) => {
1056
1063
  const buildRcsTestMessagePayload = (
1057
1064
  creativeFormData,
1058
1065
  _unusedEditorContentString,
1059
- _customValuesObj,
1066
+ customValuesObj,
1060
1067
  deliverySettingsOverride,
1061
1068
  basePayload,
1062
1069
  _rcsTestMetaExtras = {},
@@ -1071,7 +1078,9 @@ const CommonTestAndPreview = (props) => {
1071
1078
  } else if (rcsContentFromForm?.cardContent) {
1072
1079
  rcsCardPayloadList = [rcsContentFromForm.cardContent];
1073
1080
  }
1074
- // Raw title/description with template tags; SMS fallback uses tagged template fields (pickFirst…).
1081
+ // Title/description/suggestion text carry {{tag}} placeholders; resolve them against the
1082
+ // user's test values here, same as every other channel (see resolveTagsInText usage below
1083
+ // for SMS/EMAIL/WHATSAPP) — otherwise the test send goes out with literal tags unresolved.
1075
1084
  const cardContentForTestMetaApi = rcsCardPayloadList.map((singleRcsCardPayload) => {
1076
1085
  const normalizedCardMediaForTestApi = singleRcsCardPayload?.media
1077
1086
  ? normalizeRcsTestCardMedia(singleRcsCardPayload.media)
@@ -1079,11 +1088,25 @@ const CommonTestAndPreview = (props) => {
1079
1088
  const suggestionsFromCard = Array.isArray(singleRcsCardPayload?.suggestions)
1080
1089
  ? singleRcsCardPayload.suggestions
1081
1090
  : [];
1082
- const suggestionsFormattedForTestMeta = suggestionsFromCard.map((suggestionItem, index) =>
1083
- mapRcsSuggestionForTestMeta(suggestionItem, index));
1091
+ const suggestionsFormattedForTestMeta = suggestionsFromCard.map((suggestionItem, index) => mapRcsSuggestionForTestMeta(
1092
+ {
1093
+ ...suggestionItem,
1094
+ text: resolveTagsInText(
1095
+ suggestionItem?.text != null ? String(suggestionItem.text) : '',
1096
+ customValuesObj,
1097
+ ),
1098
+ },
1099
+ index,
1100
+ ));
1084
1101
  return {
1085
- title: singleRcsCardPayload?.title ?? '',
1086
- description: singleRcsCardPayload?.description ?? '',
1102
+ title: resolveTagsInText(
1103
+ singleRcsCardPayload?.title != null ? String(singleRcsCardPayload.title) : '',
1104
+ customValuesObj,
1105
+ ),
1106
+ description: resolveTagsInText(
1107
+ singleRcsCardPayload?.description != null ? String(singleRcsCardPayload.description) : '',
1108
+ customValuesObj,
1109
+ ),
1087
1110
  mediaType: singleRcsCardPayload?.mediaType ?? MEDIA_TYPE_TEXT,
1088
1111
  ...(normalizedCardMediaForTestApi && { media: normalizedCardMediaForTestApi }),
1089
1112
  ...(suggestionsFormattedForTestMeta.length > 0 && {