@capillarytech/creatives-library 9.0.31 → 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.31",
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;
@@ -1082,12 +1089,24 @@ const CommonTestAndPreview = (props) => {
1082
1089
  ? singleRcsCardPayload.suggestions
1083
1090
  : [];
1084
1091
  const suggestionsFormattedForTestMeta = suggestionsFromCard.map((suggestionItem, index) => mapRcsSuggestionForTestMeta(
1085
- { ...suggestionItem, text: resolveTagsInText(suggestionItem?.text, customValuesObj) },
1092
+ {
1093
+ ...suggestionItem,
1094
+ text: resolveTagsInText(
1095
+ suggestionItem?.text != null ? String(suggestionItem.text) : '',
1096
+ customValuesObj,
1097
+ ),
1098
+ },
1086
1099
  index,
1087
1100
  ));
1088
1101
  return {
1089
- title: resolveTagsInText(singleRcsCardPayload?.title ?? '', customValuesObj),
1090
- description: resolveTagsInText(singleRcsCardPayload?.description ?? '', customValuesObj),
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
+ ),
1091
1110
  mediaType: singleRcsCardPayload?.mediaType ?? MEDIA_TYPE_TEXT,
1092
1111
  ...(normalizedCardMediaForTestApi && { media: normalizedCardMediaForTestApi }),
1093
1112
  ...(suggestionsFormattedForTestMeta.length > 0 && {