@capillarytech/creatives-library 8.0.345-alpha.15 → 8.0.345-alpha.16

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.
Files changed (130) hide show
  1. package/constants/unified.js +0 -29
  2. package/package.json +1 -1
  3. package/services/tests/api.test.js +0 -13
  4. package/utils/commonUtils.js +1 -19
  5. package/v2Components/CapActionButton/constants.js +0 -7
  6. package/v2Components/CapActionButton/index.js +109 -167
  7. package/v2Components/CapActionButton/index.scss +6 -157
  8. package/v2Components/CapActionButton/messages.js +3 -19
  9. package/v2Components/CapActionButton/tests/index.test.js +17 -41
  10. package/v2Components/CapTagList/index.js +0 -10
  11. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -70
  12. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
  13. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -207
  14. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
  18. package/v2Components/CommonTestAndPreview/SendTestMessage.js +5 -10
  19. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +15 -160
  20. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +76 -341
  21. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
  22. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +0 -11
  23. package/v2Components/CommonTestAndPreview/constants.js +2 -38
  24. package/v2Components/CommonTestAndPreview/index.js +186 -676
  25. package/v2Components/CommonTestAndPreview/messages.js +3 -49
  26. package/v2Components/CommonTestAndPreview/sagas.js +6 -15
  27. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +284 -308
  28. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
  29. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
  30. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
  31. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +1 -8
  32. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +13 -34
  33. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +283 -281
  34. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
  35. package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -132
  36. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  37. package/v2Components/FormBuilder/index.js +10 -8
  38. package/v2Components/TemplatePreview/_templatePreview.scss +23 -33
  39. package/v2Components/TemplatePreview/index.js +28 -143
  40. package/v2Components/TemplatePreview/tests/index.test.js +0 -142
  41. package/v2Components/TestAndPreviewSlidebox/index.js +1 -13
  42. package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
  43. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
  44. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
  45. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -10
  46. package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
  47. package/v2Containers/CreativesContainer/constants.js +0 -9
  48. package/v2Containers/CreativesContainer/index.js +103 -300
  49. package/v2Containers/CreativesContainer/index.scss +1 -51
  50. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
  51. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
  52. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
  53. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
  54. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +15 -20
  55. package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
  56. package/v2Containers/Email/reducer.js +12 -3
  57. package/v2Containers/Email/sagas.js +9 -4
  58. package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +4 -0
  59. package/v2Containers/Email/tests/reducer.test.js +47 -0
  60. package/v2Containers/Email/tests/sagas.test.js +146 -6
  61. package/v2Containers/Rcs/constants.js +8 -119
  62. package/v2Containers/Rcs/index.js +811 -2383
  63. package/v2Containers/Rcs/index.scss +6 -276
  64. package/v2Containers/Rcs/messages.js +3 -38
  65. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +70073 -98018
  66. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
  67. package/v2Containers/Rcs/tests/index.test.js +121 -152
  68. package/v2Containers/Rcs/tests/mockData.js +0 -38
  69. package/v2Containers/Rcs/tests/utils.test.js +30 -646
  70. package/v2Containers/Rcs/utils.js +11 -478
  71. package/v2Containers/Sms/Create/index.js +40 -100
  72. package/v2Containers/SmsTrai/Create/index.js +4 -9
  73. package/v2Containers/SmsTrai/Edit/constants.js +0 -2
  74. package/v2Containers/SmsTrai/Edit/index.js +130 -636
  75. package/v2Containers/SmsTrai/Edit/messages.js +4 -14
  76. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2296 -4249
  77. package/v2Containers/SmsWrapper/index.js +8 -37
  78. package/v2Containers/TagList/index.js +0 -6
  79. package/v2Containers/Templates/_templates.scss +2 -163
  80. package/v2Containers/Templates/actions.js +0 -11
  81. package/v2Containers/Templates/constants.js +0 -2
  82. package/v2Containers/Templates/index.js +54 -119
  83. package/v2Containers/Templates/sagas.js +12 -57
  84. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1079 -1043
  85. package/v2Containers/Templates/tests/sagas.test.js +123 -193
  86. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
  87. package/v2Containers/TemplatesV2/index.js +23 -86
  88. package/v2Containers/Whatsapp/index.js +20 -3
  89. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +34 -578
  90. package/utils/rcsPayloadUtils.js +0 -92
  91. package/utils/templateVarUtils.js +0 -201
  92. package/utils/tests/templateVarUtils.test.js +0 -204
  93. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js.rej +0 -18
  94. package/v2Components/CommonTestAndPreview/previewApiUtils.js +0 -59
  95. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +0 -67
  96. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +0 -87
  97. package/v2Components/SmsFallback/constants.js +0 -73
  98. package/v2Components/SmsFallback/index.js +0 -955
  99. package/v2Components/SmsFallback/index.scss +0 -265
  100. package/v2Components/SmsFallback/messages.js +0 -78
  101. package/v2Components/SmsFallback/smsFallbackUtils.js +0 -118
  102. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +0 -50
  103. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +0 -147
  104. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +0 -304
  105. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +0 -197
  106. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -277
  107. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +0 -422
  108. package/v2Components/SmsFallback/useLocalTemplateList.js +0 -92
  109. package/v2Components/TemplatePreview/constants.js +0 -2
  110. package/v2Components/VarSegmentMessageEditor/constants.js +0 -2
  111. package/v2Components/VarSegmentMessageEditor/index.js +0 -125
  112. package/v2Components/VarSegmentMessageEditor/index.scss +0 -46
  113. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +0 -43
  114. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +0 -67
  115. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +0 -90
  116. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +0 -258
  117. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +0 -125
  118. package/v2Containers/Rcs/index.js.rej +0 -1336
  119. package/v2Containers/Rcs/index.scss.rej +0 -74
  120. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -225
  121. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap.rej +0 -128
  122. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -318
  123. package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
  124. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
  125. package/v2Containers/SmsTrai/Edit/index.scss +0 -121
  126. package/v2Containers/Templates/TemplatesActionBar.js +0 -101
  127. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
  128. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
  129. package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
  130. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
@@ -1,92 +0,0 @@
1
- import isEmpty from 'lodash/isEmpty';
2
- import { RCS_API_SMS_FALLBACK_KEYS } from '../constants/unified';
3
- import {
4
- COMBINED_SMS_TEMPLATE_VAR_REGEX,
5
- isAnyTemplateVarToken,
6
- splitTemplateVarString,
7
- } from './templateVarUtils';
8
-
9
- const {
10
- MESSAGE,
11
- TEMPLATE_CONFIGS,
12
- RCS_SMS_FALLBACK_VAR_MAPPED,
13
- } = RCS_API_SMS_FALLBACK_KEYS;
14
-
15
- function mergeSmsFallbackSlots(templateStr, varMapped) {
16
- const map = varMapped != null && typeof varMapped === 'object' ? varMapped : {};
17
- if (!Object.keys(map).length) return typeof templateStr === 'string' ? templateStr : '';
18
- const str = typeof templateStr === 'string' ? templateStr : '';
19
- return splitTemplateVarString(str, COMBINED_SMS_TEMPLATE_VAR_REGEX)
20
- .map((seg, i) => {
21
- if (!isAnyTemplateVarToken(seg)) return seg;
22
- const key = `${seg}_${i}`;
23
- if (Object.prototype.hasOwnProperty.call(map, key)) {
24
- const v = map[key];
25
- return v == null ? '' : String(v);
26
- }
27
- return seg;
28
- })
29
- .join('');
30
- }
31
-
32
- /**
33
- * Mutates one RCS messageContent entry: strips UI-only fields, promotes smsFallBackContent to a
34
- * sibling of rcsContent, and folds rcsSmsFallbackVarMapped into the message string for the API.
35
- */
36
- export const normalizeRcsMessageContentForApi = messageContentItem => {
37
- const {
38
- rcsContent = {},
39
- smsFallBackContent: rootSmsFallbackContent = {},
40
- } = messageContentItem;
41
- const {
42
- smsFallBackContent: legacySmsFallbackNestedUnderCard,
43
- ...rcsCardPayloadOnly
44
- } = { ...rcsContent };
45
- /* Legacy nested first, then root — so current root `smsFallBackContent` wins on key clashes. */
46
- const mergedSmsFallbackSources = {
47
- ...(legacySmsFallbackNestedUnderCard ?? {}),
48
- ...rootSmsFallbackContent,
49
- };
50
- messageContentItem.rcsContent = rcsCardPayloadOnly;
51
-
52
- delete messageContentItem.templateConfigs;
53
- delete rcsCardPayloadOnly.templateConfigs;
54
-
55
- if (Array.isArray(rcsCardPayloadOnly.cardContent)) {
56
- rcsCardPayloadOnly.cardContent.forEach(card => {
57
- if (Array.isArray(card.suggestions)) {
58
- card.suggestions.forEach(suggestion => {
59
- delete suggestion.isSaved;
60
- });
61
- }
62
- });
63
- }
64
-
65
- const varMappedMerged = mergedSmsFallbackSources[RCS_SMS_FALLBACK_VAR_MAPPED];
66
- const hasVarMapped =
67
- varMappedMerged != null
68
- && typeof varMappedMerged === 'object'
69
- && Object.keys(varMappedMerged).length > 0;
70
- const hasMessageKey = Object.prototype.hasOwnProperty.call(mergedSmsFallbackSources, MESSAGE);
71
- const rawMessage = hasMessageKey ? mergedSmsFallbackSources[MESSAGE] : undefined;
72
- const messageForApi =
73
- hasMessageKey && hasVarMapped
74
- ? mergeSmsFallbackSlots(rawMessage == null ? '' : String(rawMessage), varMappedMerged)
75
- : rawMessage;
76
-
77
- const apiSiblingSmsFallback = Object.fromEntries(
78
- [
79
- hasMessageKey && [MESSAGE, messageForApi],
80
- !isEmpty(mergedSmsFallbackSources[TEMPLATE_CONFIGS]) && [
81
- TEMPLATE_CONFIGS,
82
- mergedSmsFallbackSources[TEMPLATE_CONFIGS],
83
- ],
84
- ].filter(Boolean),
85
- );
86
-
87
- if (Object.keys(apiSiblingSmsFallback).length) {
88
- messageContentItem.smsFallBackContent = apiSiblingSmsFallback;
89
- } else {
90
- delete messageContentItem.smsFallBackContent;
91
- }
92
- };
@@ -1,201 +0,0 @@
1
- /**
2
- * Shared utilities for templates containing {{var}} and DLT `{#var#}` tokens.
3
- * Same split process used by WhatsApp/RCS: match vars with regex, then split content at each var.
4
- */
5
-
6
- import {
7
- COMBINED_SMS_TEMPLATE_VAR_REGEX,
8
- DEFAULT_MUSTACHE_VAR_REGEX,
9
- DLT_HASH_VAR_TOKEN_FULL_STRING_REGEX,
10
- DLT_HASH_TOKEN_INNER_NAME_REGEX,
11
- DLT_VAR_BODY_CAPTURE_REGEX,
12
- MUSTACHE_TOKEN_INNER_NAME_REGEX,
13
- MUSTACHE_VAR_NAME_CAPTURE_REGEX,
14
- MUSTACHE_VAR_TOKEN_FULL_STRING_REGEX,
15
- } from '../constants/unified';
16
-
17
- export { COMBINED_SMS_TEMPLATE_VAR_REGEX, DEFAULT_MUSTACHE_VAR_REGEX } from '../constants/unified';
18
-
19
- const isMustacheVarToken = (s) =>
20
- typeof s === 'string' && MUSTACHE_VAR_TOKEN_FULL_STRING_REGEX.test(s);
21
-
22
- export const isDltHashVarToken = (s) =>
23
- typeof s === 'string' && DLT_HASH_VAR_TOKEN_FULL_STRING_REGEX.test(s);
24
-
25
- export const isAnyTemplateVarToken = (s) => isMustacheVarToken(s) || isDltHashVarToken(s);
26
-
27
- /**
28
- * `RegExp.prototype.exec` only advances `lastIndex` when the `g` and/or `y` flag is set.
29
- * A non-global regex in a `while ((m = re.exec(s)) !== null)` loop never advances and can run forever.
30
- *
31
- * @param {RegExp} regex
32
- * @returns {RegExp} Same instance if already global; otherwise a new RegExp with `g` appended to flags.
33
- */
34
- function ensureGlobalRegexForExecLoop(regex) {
35
- if (!regex || !(regex instanceof RegExp) || regex.global) {
36
- return regex;
37
- }
38
- return new RegExp(regex.source, `${regex.flags}g`);
39
- }
40
-
41
- /**
42
- * Splits `content` into alternating plain-text segments and variable tokens, using the order of
43
- * matches in `matchedVariableTokens` (e.g. from `String.prototype.match` with a global regex).
44
- *
45
- * @param {string[]} matchedVariableTokens - Matched tokens in left-to-right order
46
- * @param {string} content - Full template string
47
- * @returns {string[]}
48
- */
49
- export const splitContentByOrderedVarTokens = (matchedVariableTokens, content) => {
50
- const segmentList = [];
51
- const tokenQueue = [...(matchedVariableTokens ?? [])];
52
- let remainder = content ?? '';
53
- while ((remainder?.length ?? 0) > 0) {
54
- const nextVarToken = tokenQueue?.[0];
55
- if (nextVarToken == null || nextVarToken === '') {
56
- segmentList.push(remainder);
57
- break;
58
- }
59
- const varStartIndex = remainder.indexOf(nextVarToken);
60
- if (varStartIndex !== -1) {
61
- segmentList.push(remainder.substring(0, varStartIndex));
62
- segmentList.push(nextVarToken);
63
- const afterVar = varStartIndex + (nextVarToken?.length ?? 0);
64
- remainder = remainder.substring(afterVar, remainder?.length ?? 0);
65
- tokenQueue.shift();
66
- } else {
67
- segmentList.push(remainder);
68
- break;
69
- }
70
- }
71
- return segmentList;
72
- };
73
-
74
- /**
75
- * Splits a template string into an array of text + {{var}} segments using the given regex.
76
- *
77
- * @param {string} str - Template string
78
- * @param {RegExp} [varRegex] - Regex that matches var tokens; defaults to DEFAULT_MUSTACHE_VAR_REGEX
79
- * @returns {string[]}
80
- */
81
- export const splitTemplateVarString = (str = '', varRegex = DEFAULT_MUSTACHE_VAR_REGEX) => {
82
- if (!str) return [];
83
- const matchedVariableTokens = str.match(varRegex) || [];
84
- return splitContentByOrderedVarTokens(matchedVariableTokens, str).filter(
85
- (segment) => segment === 0 || segment
86
- );
87
- };
88
-
89
- /**
90
- * Extracts unique variable names from `{{var}}` (and, when using default capture, `{#var#}`) strings.
91
- *
92
- * @param {string} templateStr
93
- * @param {RegExp} [captureRegex] - regex with a single capture group for the var name; if omitted, also scans DLT `{#…#}`.
94
- * @returns {string[]}
95
- */
96
- export const extractTemplateVariables = (templateStr = '', captureRegex) => {
97
- if (!templateStr) return [];
98
- const variables = [];
99
- const add = (name) => {
100
- const n = (name || '').trim();
101
- if (n && !variables.includes(n)) variables.push(n);
102
- };
103
- const mustacheRe = ensureGlobalRegexForExecLoop(
104
- captureRegex || MUSTACHE_VAR_NAME_CAPTURE_REGEX,
105
- );
106
- let match;
107
- while ((match = mustacheRe.exec(templateStr)) !== null) {
108
- add(match?.[1]);
109
- }
110
- if (!captureRegex) {
111
- const dltRe = new RegExp(DLT_VAR_BODY_CAPTURE_REGEX.source, DLT_VAR_BODY_CAPTURE_REGEX.flags);
112
- let dltMatch;
113
- while ((dltMatch = dltRe.exec(templateStr)) !== null) {
114
- add(dltMatch?.[1] || 'var');
115
- }
116
- }
117
- return variables;
118
- };
119
-
120
- /**
121
- * Looks up the inner name of a `{{name}}` or `{#name#}` token in a flat key→value map.
122
- * Handles both exact matches and dot-path suffixes (e.g. `tag.FORMAT_1` → name `FORMAT_1`).
123
- * Returns the resolved string value, or `undefined` if not found / blank.
124
- */
125
- function resolveUserVarForToken(segment, userVarMap) {
126
- if (!userVarMap || typeof userVarMap !== 'object') return undefined;
127
- const mMustache = segment.match(MUSTACHE_TOKEN_INNER_NAME_REGEX);
128
- const mDlt = segment.match(DLT_HASH_TOKEN_INNER_NAME_REGEX);
129
- const innerName = ((mMustache ? mMustache[1] : (mDlt ? mDlt[1] : '')) ?? '').trim();
130
- if (!innerName) return undefined;
131
- const direct = userVarMap[innerName];
132
- if (direct != null && String(direct).trim() !== '') return String(direct);
133
- const hit = Object.keys(userVarMap).find((k) => k === innerName || k.endsWith(`.${innerName}`));
134
- if (hit != null && userVarMap[hit] != null && String(userVarMap[hit]).trim() !== '') return String(userVarMap[hit]);
135
- return undefined;
136
- }
137
-
138
- /**
139
- * SMS / DLT template preview: replace `{{…}}` / `{#…#}` tokens using `varMapData` keys `${token}_${index}`.
140
- * Used by SmsTraiEdit (RCS SMS fallback) and UnifiedPreview fallback SMS bubble.
141
- * DLT `{#…#}`: empty / unset slot values show the raw token (matches DLT preview UX); mustache `{{…}}` still
142
- * resolves to empty when the slot is cleared.
143
- *
144
- * @param {string} templateStr
145
- * @param {Object} varMapData - Slot map (`${token}_${index}` → value)
146
- * @param {Object|null} [userVarMap] - Optional Test & Preview custom values; used as fallback when a slot
147
- * is absent or blank. When omitted the function behaves identically to its original two-argument form.
148
- */
149
- export const getFallbackResolvedContent = (templateStr = '', varMapData = {}, userVarMap = null) => {
150
- const fallbackVarSlotMap = varMapData ?? {};
151
- const templateSegments = splitTemplateVarString(templateStr, COMBINED_SMS_TEMPLATE_VAR_REGEX);
152
- return templateSegments
153
- .map((segment, segmentIndex) => {
154
- const isVariableToken = typeof segment === 'string' && isAnyTemplateVarToken(segment);
155
- if (!isVariableToken) return segment;
156
- const slotKey = `${segment}_${segmentIndex}`;
157
- if (Object.prototype.hasOwnProperty.call(fallbackVarSlotMap, slotKey)) {
158
- const slotValue = fallbackVarSlotMap[slotKey];
159
- if (isDltHashVarToken(segment)) {
160
- if (slotValue == null || String(slotValue).trim() === '') {
161
- if (userVarMap) { const uv = resolveUserVarForToken(segment, userVarMap); if (uv !== undefined) return uv; }
162
- return segment;
163
- }
164
- return String(slotValue);
165
- }
166
- if (slotValue != null && String(slotValue).trim() !== '') return String(slotValue);
167
- if (userVarMap) { const uv = resolveUserVarForToken(segment, userVarMap); if (uv !== undefined) return uv; }
168
- return '';
169
- }
170
- if (userVarMap) { const uv = resolveUserVarForToken(segment, userVarMap); if (uv !== undefined) return uv; }
171
- if (isDltHashVarToken(segment)) return segment;
172
- return '';
173
- })
174
- .join('');
175
- };
176
-
177
- /**
178
- * SMS fallback **card** (library list): show filled slot text; if a slot is empty, unset, or
179
- * whitespace-only, show the raw `{{…}}` / `{#…#}` token so “save without labels” still shows
180
- * `{#var#}` in the card. {@link getFallbackResolvedContent} keeps DLT placeholders in preview when
181
- * slots are empty; mustache cleared slots can still render empty.
182
- */
183
- export const getFallbackResolvedContentForCardDisplay = (templateStr = '', varMapData = {}) => {
184
- const fallbackVarSlotMap = varMapData ?? {};
185
- const templateSegments = splitTemplateVarString(templateStr, COMBINED_SMS_TEMPLATE_VAR_REGEX);
186
- return templateSegments
187
- .map((segment, segmentIndex) => {
188
- const isVariableToken = typeof segment === 'string' && isAnyTemplateVarToken(segment);
189
- if (!isVariableToken) return segment;
190
- const slotKey = `${segment}_${segmentIndex}`;
191
- if (Object.prototype.hasOwnProperty.call(fallbackVarSlotMap, slotKey)) {
192
- const slotValue = fallbackVarSlotMap[slotKey];
193
- if (slotValue == null) return segment;
194
- const str = String(slotValue);
195
- if (str.trim() === '') return segment;
196
- return str;
197
- }
198
- return segment;
199
- })
200
- .join('');
201
- };
@@ -1,204 +0,0 @@
1
- import {
2
- extractTemplateVariables,
3
- splitTemplateVarString,
4
- splitContentByOrderedVarTokens,
5
- getFallbackResolvedContent,
6
- getFallbackResolvedContentForCardDisplay,
7
- isDltHashVarToken,
8
- isAnyTemplateVarToken,
9
- } from '../templateVarUtils';
10
-
11
- describe('templateVarUtils', () => {
12
- describe('splitContentByOrderedVarTokens', () => {
13
- it('pushes remainder when next token is not found in string', () => {
14
- expect(splitContentByOrderedVarTokens(['{{b}}'], 'hello')).toEqual(['hello']);
15
- });
16
-
17
- it('handles empty token queue by pushing remainder', () => {
18
- expect(splitContentByOrderedVarTokens([], 'rest')).toEqual(['rest']);
19
- });
20
-
21
- it('handles null matchedVariableTokens as empty queue', () => {
22
- expect(splitContentByOrderedVarTokens(null, 'abc')).toEqual(['abc']);
23
- });
24
-
25
- it('stops and pushes remainder when next token in queue is empty string', () => {
26
- expect(splitContentByOrderedVarTokens(['{{a}}', ''], 'x{{a}}y')).toEqual(['x', '{{a}}', 'y']);
27
- });
28
-
29
- it('splits multiple ordered tokens across content', () => {
30
- expect(splitContentByOrderedVarTokens(['{{a}}', '{{b}}'], 'p{{a}}q{{b}}r')).toEqual([
31
- 'p',
32
- '{{a}}',
33
- 'q',
34
- '{{b}}',
35
- 'r',
36
- ]);
37
- });
38
-
39
- it('returns empty segment list when content is null and queue is empty', () => {
40
- expect(splitContentByOrderedVarTokens([], null)).toEqual([]);
41
- });
42
- });
43
-
44
- describe('splitTemplateVarString', () => {
45
- it('returns empty array for falsy string', () => {
46
- expect(splitTemplateVarString('')).toEqual([]);
47
- expect(splitTemplateVarString(null)).toEqual([]);
48
- });
49
-
50
- it('splits mustache segments', () => {
51
- const parts = splitTemplateVarString('Hi {{name}}!');
52
- expect(parts.some((p) => p.includes('name'))).toBe(true);
53
- });
54
-
55
- it('omits empty segments after filtering', () => {
56
- expect(splitTemplateVarString('a{{x}}b')).toEqual(['a', '{{x}}', 'b']);
57
- });
58
- });
59
-
60
- describe('getFallbackResolvedContent', () => {
61
- it('replaces var segments from varMapData', () => {
62
- const out = getFallbackResolvedContent('{{a}}', { '{{a}}_0': 'X' });
63
- expect(out).toBe('X');
64
- });
65
-
66
- it('keeps DLT token string when slot empty', () => {
67
- const out = getFallbackResolvedContent('{#v#}', {});
68
- expect(out).toContain('#');
69
- });
70
-
71
- it('returns empty string for mustache slot when map has no value', () => {
72
- const out = getFallbackResolvedContent('Hi {{missing}}', {});
73
- expect(out).toBe('Hi ');
74
- });
75
-
76
- it('treats null as empty; explicit empty string is kept (cleared input)', () => {
77
- expect(getFallbackResolvedContent('{{a}}', { '{{a}}_0': null })).toBe('');
78
- expect(getFallbackResolvedContent('{{a}}', { '{{a}}_0': '' })).toBe('');
79
- });
80
-
81
- it('keeps DLT token in preview when slot map has empty string (no tag yet)', () => {
82
- expect(getFallbackResolvedContent('{#v#}', { '{#v#}_0': '' })).toBe('{#v#}');
83
- });
84
-
85
- it('keeps DLT token in preview when slot map has null', () => {
86
- expect(getFallbackResolvedContent('{#v#}', { '{#v#}_0': null })).toBe('{#v#}');
87
- });
88
-
89
- it('uses slot replacement when value is non-empty string', () => {
90
- expect(getFallbackResolvedContent('A{{b}}C', { '{{b}}_1': 'ok' })).toBe('AokC');
91
- });
92
- });
93
-
94
- describe('getFallbackResolvedContentForCardDisplay', () => {
95
- it('shows raw tokens when map is empty or slots unset', () => {
96
- expect(getFallbackResolvedContentForCardDisplay('Hi {{name}}', {})).toBe('Hi {{name}}');
97
- expect(getFallbackResolvedContentForCardDisplay('{#var#}', {})).toBe('{#var#}');
98
- });
99
-
100
- it('shows raw token when slot key exists but value is empty (no labels)', () => {
101
- expect(getFallbackResolvedContentForCardDisplay('{#var#}', { '{#var#}_0': '' })).toBe('{#var#}');
102
- expect(getFallbackResolvedContentForCardDisplay('{{a}}', { '{{a}}_0': '' })).toBe('{{a}}');
103
- });
104
-
105
- it('replaces when slot has non-empty value', () => {
106
- expect(getFallbackResolvedContentForCardDisplay('Hi {{name}}', { '{{name}}_1': 'Pat' })).toBe('Hi Pat');
107
- });
108
- });
109
-
110
- describe('isDltHashVarToken / isAnyTemplateVarToken', () => {
111
- it('detects DLT hash token', () => {
112
- expect(isDltHashVarToken('{#x#}')).toBe(true);
113
- expect(isDltHashVarToken('plain')).toBe(false);
114
- });
115
-
116
- it('isAnyTemplateVarToken combines mustache and DLT', () => {
117
- expect(isAnyTemplateVarToken('{{a}}')).toBe(true);
118
- expect(isAnyTemplateVarToken('{#x#}')).toBe(true);
119
- });
120
- });
121
-
122
- describe('extractTemplateVariables', () => {
123
- it('returns empty array for empty or missing template', () => {
124
- expect(extractTemplateVariables('')).toEqual([]);
125
- expect(extractTemplateVariables()).toEqual([]);
126
- });
127
-
128
- it('includes DLT {#var#} names when no custom capture regex', () => {
129
- const vars = extractTemplateVariables('Hello {#promo#} and {{name}}');
130
- expect(vars).toEqual(expect.arrayContaining(['promo', 'name']));
131
- });
132
-
133
- it('skips DLT scan when captureRegex is provided', () => {
134
- const re = /\{\{([^}]+)\}\}/g;
135
- expect(extractTemplateVariables('{#x#} {{y}}', re)).toEqual(['y']);
136
- });
137
-
138
- it('dedupes duplicate variable names', () => {
139
- expect(extractTemplateVariables('{{a}} {{a}}')).toEqual(['a']);
140
- });
141
-
142
- it('uses default name var when DLT body capture is empty', () => {
143
- const vars = extractTemplateVariables('{##}');
144
- expect(vars).toContain('var');
145
- });
146
- });
147
-
148
- describe('extractTemplateVariables (regex global)', () => {
149
- it('extracts all vars when caller passes a non-global capture regex (avoids infinite exec loop)', () => {
150
- const nonGlobal = /\{\{([^}]+)\}\}/;
151
- expect(nonGlobal.global).toBe(false);
152
- expect(extractTemplateVariables('{{a}} and {{b}}', nonGlobal)).toEqual(['a', 'b']);
153
- });
154
-
155
- it('still works when capture regex already has the global flag', () => {
156
- const globalRe = /\{\{([^}]+)\}\}/g;
157
- expect(extractTemplateVariables('{{x}} {{y}}', globalRe)).toEqual(['x', 'y']);
158
- });
159
- });
160
-
161
- describe('getFallbackResolvedContent — userVarMap (third param)', () => {
162
- it('falls back to userVarMap for mustache slot absent from varMapData', () => {
163
- expect(getFallbackResolvedContent('Hi {{name}}', {}, { name: 'Alice' })).toBe('Hi Alice');
164
- });
165
-
166
- it('falls back to userVarMap for DLT slot absent from varMapData', () => {
167
- expect(getFallbackResolvedContent('{#city#}', {}, { city: 'Mumbai' })).toBe('Mumbai');
168
- });
169
-
170
- it('falls back to userVarMap when mustache slot is present but blank', () => {
171
- expect(getFallbackResolvedContent('{{x}}', { '{{x}}_0': '' }, { x: 'val' })).toBe('val');
172
- });
173
-
174
- it('falls back to userVarMap when DLT slot is present but blank', () => {
175
- expect(getFallbackResolvedContent('{#x#}', { '{#x#}_0': '' }, { x: 'val' })).toBe('val');
176
- });
177
-
178
- it('slot wins over userVarMap when mustache slot is non-empty', () => {
179
- expect(getFallbackResolvedContent('{{x}}', { '{{x}}_0': 'slot-val' }, { x: 'user-val' })).toBe('slot-val');
180
- });
181
-
182
- it('slot wins over userVarMap when DLT slot is non-empty', () => {
183
- expect(getFallbackResolvedContent('{#x#}', { '{#x#}_0': 'slot' }, { x: 'user' })).toBe('slot');
184
- });
185
-
186
- it('resolves dot-path suffix key from userVarMap', () => {
187
- expect(
188
- getFallbackResolvedContent('{{FORMAT_1}}', {}, { 'expiry.FORMAT_1': 'Dec 2025' }),
189
- ).toBe('Dec 2025');
190
- });
191
-
192
- it('userVarMap null behaves identically to the two-argument form', () => {
193
- expect(getFallbackResolvedContent('{{a}}', { '{{a}}_0': 'x' }, null)).toBe('x');
194
- });
195
-
196
- it('blank userVarMap value leaves mustache token as empty string', () => {
197
- expect(getFallbackResolvedContent('{{a}}', {}, { a: '' })).toBe('');
198
- });
199
-
200
- it('blank userVarMap value leaves DLT token as raw token', () => {
201
- expect(getFallbackResolvedContent('{#a#}', {}, { a: '' })).toBe('{#a#}');
202
- });
203
- });
204
- });
@@ -1,18 +0,0 @@
1
- diff a/app/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js b/app/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js (rejected hunks)
2
- @@ -226,11 +361,16 @@ const RcsPreviewContent = ({
3
- const timestamp = `${displayHours}:${displayMinutes} ${ampm}`;
4
-
5
- // Render normal RCS preview (same structure as SMS up to sms-message-container)
6
- + const hasCarousel = Array.isArray(content?.carouselData) && content.carouselData.length > 0;
7
- const hasMedia = !!(content?.rcsImageSrc || content?.rcsVideoSrc);
8
- + const contentToRender = hasCarousel
9
- + ? renderCarouselPreviewContent()
10
- + : (hasMedia ? renderMediaPreviewContent() : renderTextPreviewContent());
11
-
12
- return (
13
- + <CapRow
14
- + className={`sms-device-container rcs-device-container ${hasCarousel ? 'rcs-device-container-carousel' : ''}`}
15
- + >
16
- {/* Device Background Image */}
17
- <CapImage
18
- className="sms-device-image"
@@ -1,59 +0,0 @@
1
- /**
2
- * Helpers for Liquid `/preview` (updateEmailPreview) responses.
3
- * The API may nest the payload under `data` or return fields at the top level.
4
- * SMS responses often use `messageBody` instead of `resolvedBody`.
5
- */
6
-
7
- import { getFallbackResolvedContent } from '../../utils/templateVarUtils';
8
- import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from './constants';
9
-
10
- export function normalizePreviewApiPayload(raw) {
11
- if (!raw || typeof raw !== 'object') return raw;
12
- const next = { ...raw };
13
- if (next.resolvedBody == null) {
14
- const alt = next.messageBody ?? next.previewMessage ?? next.previewText;
15
- if (alt != null) next.resolvedBody = alt;
16
- }
17
- return next;
18
- }
19
-
20
- /**
21
- * Returns a normalized preview object suitable for Redux `previewData`, or null on error / empty.
22
- */
23
- export function extractPreviewFromLiquidResponse(response) {
24
- if (!response || response.error) return null;
25
- if (response.errors && Array.isArray(response.errors) && response.errors.length > 0) return null;
26
-
27
- let body;
28
- if (response.data !== undefined && response.data !== null && typeof response.data === 'object') {
29
- body = normalizePreviewApiPayload(response.data);
30
- } else if (typeof response === 'object' && !Array.isArray(response)) {
31
- body = normalizePreviewApiPayload(response);
32
- } else {
33
- return null;
34
- }
35
-
36
- if (!body) return null;
37
- if (body.resolvedBody === undefined && body.messageBody === undefined) {
38
- return null;
39
- }
40
- return body;
41
- }
42
-
43
- /**
44
- * RCS SMS fallback: merge template (`templateContent` / `content`) with VarSegment
45
- * `rcsSmsFallbackVarMapped` before Liquid /preview, tag extraction, or createMessageMeta.
46
- * Raw template alone is stale when the user edits slot values.
47
- */
48
- export function getSmsFallbackTextForTagExtraction(smsFallbackContext) {
49
- const rawTemplateBody =
50
- smsFallbackContext?.templateContent ?? smsFallbackContext?.content ?? '';
51
- if (!rawTemplateBody) return '';
52
- const rcsSmsFallbackVarMapped = smsFallbackContext?.[RCS_SMS_FALLBACK_VAR_MAPPED_PROP];
53
- const hasRcsSmsFallbackVarMappedEntries =
54
- Object.keys(rcsSmsFallbackVarMapped ?? {}).length > 0;
55
- if (hasRcsSmsFallbackVarMappedEntries) {
56
- return getFallbackResolvedContent(rawTemplateBody, rcsSmsFallbackVarMapped ?? {});
57
- }
58
- return rawTemplateBody;
59
- }
@@ -1,67 +0,0 @@
1
- import {
2
- normalizePreviewApiPayload,
3
- extractPreviewFromLiquidResponse,
4
- getSmsFallbackTextForTagExtraction,
5
- } from '../previewApiUtils';
6
- import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../constants';
7
-
8
- describe('previewApiUtils', () => {
9
- describe('normalizePreviewApiPayload', () => {
10
- it('maps messageBody to resolvedBody when resolvedBody is missing', () => {
11
- expect(normalizePreviewApiPayload({ messageBody: 'Hello' }).resolvedBody).toBe('Hello');
12
- });
13
- });
14
-
15
- describe('extractPreviewFromLiquidResponse', () => {
16
- it('accepts nested data shape', () => {
17
- const r = { data: { resolvedBody: 'ok' } };
18
- expect(extractPreviewFromLiquidResponse(r)).toEqual({ resolvedBody: 'ok' });
19
- });
20
-
21
- it('accepts top-level preview (typical SMS)', () => {
22
- const r = { messageBody: 'sms text' };
23
- expect(extractPreviewFromLiquidResponse(r)).toMatchObject({
24
- messageBody: 'sms text',
25
- resolvedBody: 'sms text',
26
- });
27
- });
28
-
29
- it('returns null when errors array is non-empty', () => {
30
- expect(extractPreviewFromLiquidResponse({ errors: [{ code: 1 }] })).toBeNull();
31
- });
32
- });
33
-
34
- describe('getSmsFallbackTextForTagExtraction', () => {
35
- it('returns empty string when context is missing or has no template body', () => {
36
- expect(getSmsFallbackTextForTagExtraction(null)).toBe('');
37
- expect(getSmsFallbackTextForTagExtraction({})).toBe('');
38
- expect(getSmsFallbackTextForTagExtraction({ templateContent: '', content: '' })).toBe('');
39
- });
40
-
41
- it('returns raw template when rcsSmsFallbackVarMapped is absent or empty', () => {
42
- const raw = '{{optout}} {{fullname}} test SMS';
43
- expect(getSmsFallbackTextForTagExtraction({ templateContent: raw })).toBe(raw);
44
- expect(getSmsFallbackTextForTagExtraction({
45
- content: raw,
46
- [RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: {},
47
- })).toBe(raw);
48
- });
49
-
50
- it('prefers templateContent over content when both are set', () => {
51
- expect(getSmsFallbackTextForTagExtraction({
52
- templateContent: 'A',
53
- content: 'B',
54
- })).toBe('A');
55
- });
56
-
57
- it('applies VarSegment slot map so preview / meta payloads are not stale vs raw template', () => {
58
- const rawTemplateWithSlots = '{{optout}} tail';
59
- const rcsSmsFallbackVarMappedSlots = { '{{optout}}_0': 'STOP' };
60
- const resolvedFallbackText = getSmsFallbackTextForTagExtraction({
61
- templateContent: rawTemplateWithSlots,
62
- [RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: rcsSmsFallbackVarMappedSlots,
63
- });
64
- expect(resolvedFallbackText).toBe('STOP tail');
65
- });
66
- });
67
- });