@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.39 → 9.2.0

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 (87) hide show
  1. package/constants/unified.js +4 -0
  2. package/package.json +1 -1
  3. package/translations/en.json +1 -0
  4. package/translations/ja-JP.json +1 -0
  5. package/translations/zh.json +1 -0
  6. package/utils/common.js +6 -0
  7. package/utils/createMobilePushPayload.js +33 -50
  8. package/utils/tagValidations.js +35 -4
  9. package/utils/templateVarUtils.js +49 -0
  10. package/utils/tests/createMobilePushPayload.test.js +8 -113
  11. package/utils/tests/tagValidations.test.js +48 -0
  12. package/utils/tests/templateVarUtils.test.js +89 -0
  13. package/v2Components/CapMpushCTA/index.js +9 -10
  14. package/v2Components/CapMpushCTA/index.scss +3 -29
  15. package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
  16. package/v2Components/CapTagList/constants.js +5 -0
  17. package/v2Components/CapTagList/index.js +46 -7
  18. package/v2Components/CapTagList/messages.js +44 -0
  19. package/v2Components/CapTagList/style.scss +113 -1
  20. package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
  21. package/v2Components/CapTagList/utils.js +17 -0
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +12 -20
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
  24. package/v2Components/CommonTestAndPreview/constants.js +3 -2
  25. package/v2Components/CommonTestAndPreview/index.js +61 -61
  26. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -81
  27. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
  28. package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
  29. package/v2Components/CommonTestAndPreview/utils.js +42 -3
  30. package/v2Components/FormBuilder/Classic.js +24 -14
  31. package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
  32. package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
  33. package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
  34. package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
  35. package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
  36. package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
  37. package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
  38. package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
  39. package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
  40. package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
  41. package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
  42. package/v2Components/TemplatePreview/index.js +16 -24
  43. package/v2Components/TemplatePreview/tests/index.test.js +0 -68
  44. package/v2Containers/Cap/messages.js +4 -0
  45. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
  46. package/v2Containers/CreativesContainer/SlideBoxContent.js +6 -4
  47. package/v2Containers/CreativesContainer/index.js +1 -2
  48. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
  49. package/v2Containers/InApp/index.js +4 -1
  50. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
  51. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
  52. package/v2Containers/Line/Container/Text/index.js +3 -1
  53. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
  54. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
  55. package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
  56. package/v2Containers/MobilePushNew/components/MediaUploaders.js +216 -297
  57. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +125 -158
  58. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
  59. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +108 -464
  60. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +35 -106
  61. package/v2Containers/MobilePushNew/constants.js +0 -5
  62. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
  63. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
  64. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
  65. package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
  66. package/v2Containers/MobilePushNew/index.js +239 -488
  67. package/v2Containers/MobilePushNew/index.scss +4 -205
  68. package/v2Containers/MobilePushNew/messages.js +6 -106
  69. package/v2Containers/MobilePushNew/tests/index.test.js +1 -469
  70. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -70
  71. package/v2Containers/MobilePushNew/utils.js +0 -56
  72. package/v2Containers/Rcs/index.js +8 -1
  73. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
  74. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
  75. package/v2Containers/SmsTrai/Edit/index.js +17 -7
  76. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
  77. package/v2Containers/Templates/_templates.scss +2 -10
  78. package/v2Containers/Templates/index.js +81 -83
  79. package/v2Containers/Templates/tests/index.test.js +0 -68
  80. package/v2Containers/Viber/index.js +3 -1
  81. package/v2Containers/WebPush/Create/utils/validation.js +6 -0
  82. package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
  83. package/v2Containers/Whatsapp/index.js +9 -5
  84. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
  85. package/v2Containers/Zalo/index.js +4 -1
  86. package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
  87. package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
@@ -46,6 +46,7 @@ export const HOSPITALITY_BASED_SCOPE = 'HOSPITALITY_BASED_SCOPE';
46
46
  export const REGISTRATION_CUSTOM_FIELD = 'Registration custom fields';
47
47
  export const GIFT_CARDS = 'GIFT_CARDS';
48
48
  export const PROMO_ENGINE = 'PROMO_ENGINE';
49
+ export const ENABLE_NEW_MPUSH = 'ENABLE_NEW_MPUSH';
49
50
  export const ENABLE_NEW_EDITOR_FLOW_INAPP = 'ENABLE_NEW_EDITOR_FLOW_INAPP';
50
51
  // Per-channel flags for the FormBuilder V3 migration. Each routes its channel to
51
52
  // the new functional FormBuilder; later channels get their own flags (…_EMAIL).
@@ -160,6 +161,9 @@ export const UNSUBSCRIBE_TAG = 'unsubscribe';
160
161
  export const UNSUBSCRIBE_TAG_REGEX = new RegExp(`\\{\\{\\s*${UNSUBSCRIBE_TAG}\\s*\\}\\}`);
161
162
  /** Matches {{ ... }} and captures the inner tag content (for scanning content for tags). */
162
163
  export const TAG_CONTENT_REGEX = /{{([^}]+)}}/g;
164
+ // `default:` filter inside a tag, and the same filter with a quoted value e.g. default: 'x'
165
+ export const DEFAULT_FILTER_REGEX = /^\s*default\s*:/;
166
+ export const QUOTED_DEFAULT_REGEX = /^\s*default\s*:\s*('[^']*'|"[^"]*")\s*$/;
163
167
  export const ENTRY_TRIGGER_TAG_REGEX = /\bentryTrigger\.\w+(?:\.\w+)?(?:\(\w+\))?/g;
164
168
  /** Strips characters not allowed in a downloaded file name, keeping alphanumerics, `-`, `_` and spaces. */
165
169
  export const SAFE_FILE_NAME_REGEX = /[^a-zA-Z0-9-_ ]/g;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "9.1.8-alpha.sprint-cap-214249.39",
4
+ "version": "9.2.0",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -317,6 +317,7 @@
317
317
  "creatives.componentsV2.TopBar.profile": "Profile",
318
318
  "creatives.componentsV2.TopBar.settings": "Settings",
319
319
  "creatives.componentsV2.unbalanacedCurlyBraces": "Invalid label, please close all curly braces",
320
+ "creatives.componentsV2.unquotedTagDefaultValue": "Invalid label, default value must be within quotes",
320
321
  "creatives.componentsv2.MobilePushPreviewV2.header": "This is the MobilePushPreviewV2 component !",
321
322
  "creatives.containers.Assets.Gallery.alphabetically": "Alphabetically",
322
323
  "creatives.containers.Assets.Gallery.assetDeleteFailed": "Image deletion failed.",
@@ -316,6 +316,7 @@
316
316
  "creatives.componentsV2.TopBar.profile": "",
317
317
  "creatives.componentsV2.TopBar.settings": "",
318
318
  "creatives.componentsV2.unbalanacedCurlyBraces": "",
319
+ "creatives.componentsV2.unquotedTagDefaultValue": "",
319
320
  "creatives.componentsv2.MobilePushPreviewV2.header": "",
320
321
  "creatives.containers.Assets.Gallery.alphabetically": "",
321
322
  "creatives.containers.Assets.Gallery.assetDeleteFailed": "",
@@ -316,6 +316,7 @@
316
316
  "creatives.componentsV2.TopBar.profile": "",
317
317
  "creatives.componentsV2.TopBar.settings": "",
318
318
  "creatives.componentsV2.unbalanacedCurlyBraces": "",
319
+ "creatives.componentsV2.unquotedTagDefaultValue": "",
319
320
  "creatives.componentsv2.MobilePushPreviewV2.header": "",
320
321
  "creatives.containers.Assets.Gallery.alphabetically": "",
321
322
  "creatives.containers.Assets.Gallery.assetDeleteFailed": "",
package/utils/common.js CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  ENABLE_WECHAT,
25
25
  ENABLE_WEBPUSH,
26
26
  SUPPORT_CK_EDITOR,
27
+ ENABLE_NEW_MPUSH,
27
28
  ENABLE_NEW_EDITOR_FLOW_INAPP,
28
29
  ENABLE_NEW_FORMBUILDER_SMS,
29
30
  ENABLE_NEW_FORMBUILDER_MPUSH,
@@ -143,6 +144,11 @@ export const isEmailUnsubscribeTagOptional = Auth.hasFeatureAccess.bind(
143
144
  EMAIL_UNSUBSCRIBE_TAG_MANDATORY,
144
145
  );
145
146
 
147
+ export const hasNewMobilePushFeatureEnabled = Auth.hasFeatureAccess.bind(
148
+ null,
149
+ ENABLE_NEW_MPUSH,
150
+ );
151
+
146
152
  export const hasNewEditorFlowInAppEnabled = Auth.hasFeatureAccess.bind(
147
153
  null,
148
154
  ENABLE_NEW_EDITOR_FLOW_INAPP,
@@ -27,7 +27,6 @@ import messages from '../v2Containers/MobilePushNew/messages';
27
27
  * @param {Object} params.accountData - Account data for the payload
28
28
  * @param {boolean} params.sameContent - Whether content is shared between platforms
29
29
  * @param {Object} params.options - Additional options
30
- * @param {string} [params.options.skipPlatform] - ANDROID or IOS: leave out a supported platform the user chose not to configure
31
30
  * @param {Object} params.intl - Internationalization object for messages
32
31
  */
33
32
  const createMobilePushPayload = ({
@@ -42,8 +41,8 @@ const createMobilePushPayload = ({
42
41
  intl,
43
42
  }) => {
44
43
  // Platform support checks must be at the top
45
- const isAndroidSupported = accountData?.configs?.android === '1' && options?.skipPlatform !== ANDROID;
46
- const isIosSupported = accountData?.configs?.ios === '1' && options?.skipPlatform !== IOS;
44
+ const isAndroidSupported = accountData?.configs?.android === '1';
45
+ const isIosSupported = accountData?.configs?.ios === '1';
47
46
 
48
47
  const {
49
48
  accountId: accountIdFromAccountData, id, licenseCode: licenseCodeFromAccountData, sourceAccountIdentifier, sourceType: sourceTypeFromAccountData, sourceTypeName,
@@ -122,47 +121,6 @@ const createMobilePushPayload = ({
122
121
  return payload;
123
122
  };
124
123
 
125
- /**
126
- * Carousel cards as Save sends them (also used by the Test & Preview payload)
127
- * @param {Array} carouselData - Editor carousel cards
128
- * @returns {Array} Cards with deep link keys appended to button links
129
- */
130
- export function buildCarouselCards(carouselData = []) {
131
- return (carouselData || []).map((card) => {
132
- const {
133
- mediaType,
134
- imageUrl,
135
- videoSrc,
136
- videoPreviewImg,
137
- buttons,
138
- } = card || {};
139
-
140
- return {
141
- mediaType: mediaType || IMAGE.toLowerCase(),
142
- imageUrl: imageUrl || '',
143
- videoSrc: videoSrc || '',
144
- // Thumbnail, so the phone preview can show the video card when editing
145
- ...(videoPreviewImg && { videoPreviewImg }),
146
- buttons: buttons ? buttons.map((button) => {
147
- if (!button) return button;
148
- // isSaved is the editor's own Save state; it doesn't go to the backend
149
- const { isSaved, ...buttonData } = button;
150
- const { linkType: buttonLinkType, deepLinkKeys, deepLinkValue: buttonDeepLinkValue } = buttonData;
151
- if (buttonLinkType === DEEP_LINK && deepLinkKeys && buttonDeepLinkValue) {
152
- const deepLinkKeysArray = Array.isArray(deepLinkKeys) ? deepLinkKeys : [deepLinkKeys];
153
- const updatedDeepLinkValue = appendDeepLinkKeysToUrl(buttonDeepLinkValue, deepLinkKeysArray);
154
-
155
- return {
156
- ...buttonData,
157
- deepLinkValue: updatedDeepLinkValue,
158
- };
159
- }
160
- return buttonData;
161
- }) : [],
162
- };
163
- });
164
- }
165
-
166
124
  /**
167
125
  * Builds platform-specific content for the payload
168
126
  * @param {Object} content - Platform content (Android/iOS)
@@ -171,7 +129,7 @@ export function buildCarouselCards(carouselData = []) {
171
129
  * @param {string} platform - Platform (ANDROID/IOS)
172
130
  * @returns {Object} Platform-specific content
173
131
  */
174
- export function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platform) {
132
+ function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platform) {
175
133
  const {
176
134
  title = '',
177
135
  message = '',
@@ -226,8 +184,7 @@ export function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview,
226
184
  platformContent.expandableDetails.style = VIDEO;
227
185
  platformContent.expandableDetails.message = message;
228
186
  platformContent.expandableDetails.media = [{
229
- // This platform's own video; mpushVideoSrcAndPreview is shared by both tabs
230
- url: content?.videoSrc || content?.mediaList?.[0]?.url || '',
187
+ url: mpushVideoSrcAndPreview.mpushVideoSrc || (content?.mediaList?.[0]?.url || ''),
231
188
  text: content?.mediaList?.[0]?.text || '',
232
189
  type: VIDEO,
233
190
  }];
@@ -244,11 +201,11 @@ export function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview,
244
201
  type: type.toLowerCase(),
245
202
  }];
246
203
  } else {
247
- // No mediaList: use this platform's own GIF
204
+ // If no mediaList but mpushVideoSrc exists
248
205
  platformContent.expandableDetails.style = GIF;
249
206
  platformContent.expandableDetails.message = message;
250
207
  platformContent.expandableDetails.media = [{
251
- url: content?.videoSrc || '',
208
+ url: mpushVideoSrcAndPreview.mpushVideoSrc,
252
209
  text: '',
253
210
  type: GIF, // Backend expects GIF type for GIFs
254
211
  }];
@@ -261,7 +218,33 @@ export function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview,
261
218
 
262
219
  // Handle carouselData
263
220
  if (content?.carouselData?.length > 0) {
264
- platformContent.expandableDetails.carouselData = buildCarouselCards(content.carouselData);
221
+ platformContent.expandableDetails.carouselData = content.carouselData.map((card) => {
222
+ const {
223
+ mediaType,
224
+ imageUrl,
225
+ videoSrc,
226
+ buttons,
227
+ } = card || {};
228
+
229
+ return {
230
+ mediaType: mediaType || IMAGE.toLowerCase(),
231
+ imageUrl: imageUrl || '',
232
+ videoSrc: videoSrc || '',
233
+ buttons: buttons ? buttons.map((button) => {
234
+ const { linkType: buttonLinkType, deepLinkKeys, deepLinkValue: buttonDeepLinkValue } = button || {};
235
+ if (buttonLinkType === DEEP_LINK && deepLinkKeys && buttonDeepLinkValue) {
236
+ const deepLinkKeysArray = Array.isArray(deepLinkKeys) ? deepLinkKeys : [deepLinkKeys];
237
+ const updatedDeepLinkValue = appendDeepLinkKeysToUrl(buttonDeepLinkValue, deepLinkKeysArray);
238
+
239
+ return {
240
+ ...button,
241
+ deepLinkValue: updatedDeepLinkValue,
242
+ };
243
+ }
244
+ return button;
245
+ }) : [],
246
+ };
247
+ });
265
248
  }
266
249
 
267
250
  // Handle mediaList
@@ -8,7 +8,15 @@
8
8
 
9
9
  import lodashForEach from 'lodash/forEach';
10
10
  import lodashCloneDeep from 'lodash/cloneDeep';
11
- import { ENTRY_TRIGGER_TAG_REGEX, SKIP_TAGS_REGEX_GROUPS, TAG_CONTENT_REGEX, UNSUBSCRIBE_TAG, UNSUBSCRIBE_TAG_REGEX } from '../constants/unified';
11
+ import {
12
+ ENTRY_TRIGGER_TAG_REGEX,
13
+ SKIP_TAGS_REGEX_GROUPS,
14
+ TAG_CONTENT_REGEX,
15
+ UNSUBSCRIBE_TAG,
16
+ UNSUBSCRIBE_TAG_REGEX,
17
+ DEFAULT_FILTER_REGEX,
18
+ QUOTED_DEFAULT_REGEX,
19
+ } from '../constants/unified';
12
20
 
13
21
  const DEFAULT = 'default';
14
22
  const SUBTAGS = 'subtags';
@@ -89,9 +97,8 @@ export const validateTagsCore = ({
89
97
  }
90
98
 
91
99
  response.isBraceError = !validateIfTagClosed(contentForBraceCheck);
92
- if (response.isBraceError) {
93
- response.valid = false;
94
- } else if (response?.missingTags?.length > 0) {
100
+ response.isDefaultQuoteError = !response.isBraceError && hasUnquotedTagDefault(contentForBraceCheck);
101
+ if (response.isBraceError || response.isDefaultQuoteError || response?.missingTags?.length > 0) {
95
102
  response.valid = false;
96
103
  }
97
104
  return response;
@@ -203,6 +210,30 @@ export const validateIfTagClosed = (value) => {
203
210
  return (l1 == l2 && l2 == l3 && l1 == l3);
204
211
  };
205
212
 
213
+ // Splits a tag body into filters on `|` outside quotes (Liquid has no escaped quotes).
214
+ const splitTagFilters = (body) => {
215
+ const filters = [''];
216
+ let quote = null;
217
+ [...body].forEach((char) => {
218
+ if (quote) {
219
+ if (char === quote) quote = null;
220
+ } else if (char === "'" || char === '"') {
221
+ quote = char;
222
+ } else if (char === '|') {
223
+ filters.push('');
224
+ return;
225
+ }
226
+ filters[filters.length - 1] += char;
227
+ });
228
+ return filters;
229
+ };
230
+
231
+ // `default:` inside a {{ }} tag must be followed by a quoted value, e.g. {{tag | default: 'x'}}
232
+ export const hasUnquotedTagDefault = (value = '') =>
233
+ (String(value).match(/{{.*?}}/g) || []).some((tag) => splitTagFilters(tag.slice(2, -2))
234
+ .slice(1)
235
+ .some((filter) => DEFAULT_FILTER_REGEX.test(filter) && !QUOTED_DEFAULT_REGEX.test(filter)));
236
+
206
237
  //replaces encoded string with their respective characters
207
238
  export const preprocessHtml = (content) => {
208
239
  const replacements = {
@@ -13,6 +13,7 @@ import {
13
13
  MUSTACHE_VAR_NAME_CAPTURE_REGEX,
14
14
  MUSTACHE_VAR_TOKEN_FULL_STRING_REGEX,
15
15
  } from '../constants/unified';
16
+ import { HORIZONTAL_WHITESPACE_ONLY_REGEX, SMS_TRAI_VAR } from '../v2Containers/SmsTrai/Edit/constants';
16
17
 
17
18
  export { COMBINED_SMS_TEMPLATE_VAR_REGEX, DEFAULT_MUSTACHE_VAR_REGEX } from '../constants/unified';
18
19
 
@@ -131,6 +132,54 @@ export const reconcileVarMapToSlotFormat = (rawVarMap = {}, segments = [], regex
131
132
  return slotMap;
132
133
  };
133
134
 
135
+ export const getDltSlotKey = (segmentIndex) => `${SMS_TRAI_VAR}_${segmentIndex}`;
136
+
137
+ const isHorizontalWhitespaceOnly = (segment) => (
138
+ typeof segment === 'string' && segment.replace(HORIZONTAL_WHITESPACE_ONLY_REGEX, '') === ''
139
+ );
140
+
141
+ export const collectDltSlotRuns = (text) => {
142
+ if (!text || typeof text !== 'string') return [];
143
+ const segments = splitTemplateVarString(text, DLT_VAR_BODY_CAPTURE_REGEX);
144
+ const runs = [];
145
+ let runLength = 1;
146
+ let horizontalSpaceCount = 0;
147
+ for (let i = 0; i < (segments?.length ?? 0); i += 1) {
148
+ if (!isDltHashVarToken(segments[i])) continue;
149
+ const nextElem = segments[i === segments.length - 1 ? -1 : i + 1];
150
+ if (isHorizontalWhitespaceOnly(nextElem)) horizontalSpaceCount += 1;
151
+ if (segments[i] !== nextElem && !isHorizontalWhitespaceOnly(nextElem)) {
152
+ const keyIndex = i - runLength - horizontalSpaceCount + 1;
153
+ runs.push({
154
+ token: segments[keyIndex],
155
+ firstIndex: keyIndex,
156
+ endIndex: i + 1,
157
+ });
158
+ runLength = 1;
159
+ horizontalSpaceCount = 0;
160
+ } else {
161
+ runLength += 1;
162
+ }
163
+ }
164
+ return runs;
165
+ };
166
+
167
+ export const resolveDltSmsTemplate = (templateStr = '', slotValues = {}) => {
168
+ if (!templateStr || typeof templateStr !== 'string') return templateStr;
169
+ const runs = collectDltSlotRuns(templateStr);
170
+ if (runs.length === 0) return templateStr;
171
+ const resolved = splitTemplateVarString(templateStr, DLT_VAR_BODY_CAPTURE_REGEX);
172
+ runs.forEach((run) => {
173
+ const value = slotValues?.[getDltSlotKey(run.firstIndex)];
174
+ if (value === null || value === undefined || value === '') return;
175
+ for (let i = run.firstIndex; i < run.endIndex; i += 1) {
176
+ if (i === run.firstIndex) resolved[i] = String(value);
177
+ else if (isDltHashVarToken(resolved[i])) resolved[i] = '';
178
+ }
179
+ });
180
+ return resolved.join('');
181
+ };
182
+
134
183
  /**
135
184
  * Looks up the inner name of a `{{name}}` or `{#name#}` token in a flat key→value map.
136
185
  * Handles both exact matches and dot-path suffixes (e.g. `tag.FORMAT_1` → name `FORMAT_1`).
@@ -1,5 +1,5 @@
1
1
  import { IntlProvider } from 'react-intl';
2
- import createMobilePushPayload, { buildCarouselCards } from '../createMobilePushPayload';
2
+ import createMobilePushPayload from '../createMobilePushPayload';
3
3
  import messages from '../../v2Containers/MobilePushNew/messages';
4
4
 
5
5
  // Create a mock intl object
@@ -48,7 +48,6 @@ jest.mock('../createMobilePushPayload', () => {
48
48
  __esModule: true,
49
49
  default: mockCreateMobilePushPayload,
50
50
  appendDeepLinkKeysToUrl: originalModule.appendDeepLinkKeysToUrl,
51
- buildCarouselCards: originalModule.buildCarouselCards,
52
51
  };
53
52
  });
54
53
 
@@ -262,21 +261,6 @@ describe('createMobilePushPayload', () => {
262
261
  accountData: unsupportedAccountData,
263
262
  })).not.toThrow();
264
263
  });
265
-
266
- it.each([
267
- ['IOS', 'ANDROID', { androidContent: { title: 'Title', message: 'Message' }, iosContent: { title: '', message: '' } }],
268
- ['ANDROID', 'IOS', { androidContent: { title: '', message: '' }, iosContent: { title: 'Title', message: 'Message' } }],
269
- ])('leaves out a supported platform passed as skipPlatform (%s)', (skipPlatform, keptPlatform, content) => {
270
- const result = callWithIntl({
271
- templateName: 'Test',
272
- ...content,
273
- accountData: mockAccountData,
274
- options: { skipPlatform },
275
- });
276
-
277
- expect(result.versions.base[skipPlatform]).toBeUndefined();
278
- expect(result.versions.base[keptPlatform]).toBeDefined();
279
- });
280
264
  });
281
265
 
282
266
  // Account Data Validation Tests
@@ -351,67 +335,33 @@ describe('createMobilePushPayload', () => {
351
335
  expect(result.versions.base.ANDROID.expandableDetails.image).toBe('test-image.jpg');
352
336
  });
353
337
 
354
- it('should handle VIDEO media type with the platform videoSrc', () => {
338
+ it('should handle VIDEO media type with mpushVideoSrc', () => {
355
339
  const result = callWithIntl({
356
340
  templateName: 'Test',
357
341
  androidContent: {
358
342
  title: 'Title',
359
343
  message: 'Message',
360
344
  mediaType: 'VIDEO',
361
- videoSrc: 'test-video.mp4',
362
345
  },
363
346
  iosContent: { title: 'Title', message: 'Message' },
364
347
  accountData: mockAccountData,
365
- // The shared slot is ignored; it can hold the other tab's video
366
- mpushVideoSrcAndPreview: { mpushVideoSrc: 'other-tab.mp4' },
348
+ mpushVideoSrcAndPreview: { mpushVideoSrc: 'test-video.mp4' },
367
349
  });
368
350
  expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('test-video.mp4');
369
351
  expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('VIDEO');
370
352
  });
371
353
 
372
- it('should fall back to mediaList for a VIDEO with no videoSrc', () => {
373
- const result = callWithIntl({
374
- templateName: 'Test',
375
- androidContent: {
376
- title: 'Title',
377
- message: 'Message',
378
- mediaType: 'VIDEO',
379
- mediaList: [{ url: 'saved.mp4', text: 'Saved' }],
380
- },
381
- iosContent: { title: 'Title', message: 'Message' },
382
- accountData: mockAccountData,
383
- });
384
- expect(result.versions.base.ANDROID.expandableDetails.media[0]).toEqual({ url: 'saved.mp4', text: 'Saved', type: 'VIDEO' });
385
- });
386
-
387
- it('saves each platform its own video', () => {
388
- const result = callWithIntl({
389
- templateName: 'Test',
390
- androidContent: {
391
- title: 'Title', message: 'Message', mediaType: 'VIDEO', videoSrc: 'a.mp4',
392
- },
393
- iosContent: {
394
- title: 'Title', message: 'Message', mediaType: 'VIDEO', videoSrc: 'b.mp4',
395
- },
396
- accountData: mockAccountData,
397
- mpushVideoSrcAndPreview: { mpushVideoSrc: 'b.mp4' },
398
- });
399
- expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('a.mp4');
400
- expect(result.versions.base.IOS.expandableDetails.media[0].url).toBe('b.mp4');
401
- });
402
-
403
- it('should handle GIF media type with the platform videoSrc', () => {
354
+ it('should handle GIF media type with mpushVideoSrc', () => {
404
355
  const result = callWithIntl({
405
356
  templateName: 'Test',
406
357
  androidContent: {
407
358
  title: 'Title',
408
359
  message: 'Message',
409
360
  mediaType: 'GIF',
410
- videoSrc: 'test-gif.gif',
411
361
  },
412
362
  iosContent: { title: 'Title', message: 'Message' },
413
363
  accountData: mockAccountData,
414
- mpushVideoSrcAndPreview: { mpushVideoSrc: 'other-tab.gif' },
364
+ mpushVideoSrcAndPreview: { mpushVideoSrc: 'test-gif.gif' },
415
365
  });
416
366
  expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('test-gif.gif');
417
367
  expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('GIF');
@@ -910,12 +860,13 @@ describe('createMobilePushPayload', () => {
910
860
  title: 'Title',
911
861
  message: 'Message',
912
862
  mediaType: 'GIF',
913
- videoSrc: 'test-gif.gif',
914
863
  },
915
864
  iosContent: { title: 'Title', message: 'Message' },
916
865
  accountData: mockAccountData,
866
+ mpushVideoSrcAndPreview: { mpushVideoSrc: 'test-gif.gif' },
917
867
  });
918
- expect(result.versions.base.ANDROID.expandableDetails.media[0]).toEqual({ url: 'test-gif.gif', text: '', type: 'GIF' });
868
+ // When mediaType is GIF and mpushVideoSrc is provided, it converts to VIDEO for backend compatibility
869
+ expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('GIF');
919
870
  });
920
871
 
921
872
  it('should handle options with custom mode', () => {
@@ -1371,59 +1322,3 @@ describe('createMobilePushPayload', () => {
1371
1322
  });
1372
1323
  });
1373
1324
  });
1374
-
1375
- describe('buildCarouselCards', () => {
1376
- it.each([
1377
- ['no argument', undefined],
1378
- ['null', null],
1379
- ['an empty array', []],
1380
- ])('returns [] for %s', (_label, input) => {
1381
- expect(buildCarouselCards(input)).toEqual([]);
1382
- });
1383
-
1384
- it('fills defaults for a missing card', () => {
1385
- expect(buildCarouselCards([null])).toEqual([
1386
- { mediaType: 'image', imageUrl: '', videoSrc: '', buttons: [] },
1387
- ]);
1388
- });
1389
-
1390
- it('leaves the editor-only isSaved flag out of card buttons', () => {
1391
- const [card] = buildCarouselCards([{
1392
- mediaType: 'image',
1393
- imageUrl: 'a.jpg',
1394
- buttons: [{
1395
- actionOnClick: true, linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://a.com', isSaved: true,
1396
- }],
1397
- }]);
1398
- expect(card.buttons[0]).toEqual({ actionOnClick: true, linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://a.com' });
1399
- });
1400
-
1401
- it('keeps the video thumbnail only when there is one', () => {
1402
- const [withThumb, withoutThumb] = buildCarouselCards([
1403
- { mediaType: 'video', videoSrc: 'a.mp4', videoPreviewImg: 'a.png' },
1404
- { mediaType: 'video', videoSrc: 'b.mp4', videoPreviewImg: '' },
1405
- ]);
1406
-
1407
- expect(withThumb).toEqual({ mediaType: 'video', imageUrl: '', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [] });
1408
- expect(withoutThumb).toEqual({ mediaType: 'video', imageUrl: '', videoSrc: 'b.mp4', buttons: [] });
1409
- });
1410
-
1411
- it('appends deep link keys and leaves other buttons as they are', () => {
1412
- const externalButton = { linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://x.com' };
1413
- const [card] = buildCarouselCards([{
1414
- mediaType: 'image',
1415
- imageUrl: 'a.jpg',
1416
- buttons: [
1417
- { linkType: 'DEEP_LINK', deepLinkValue: 'app://home', deepLinkKeys: 'id' },
1418
- externalButton,
1419
- null,
1420
- ],
1421
- }]);
1422
-
1423
- expect(card.buttons).toEqual([
1424
- { linkType: 'DEEP_LINK', deepLinkValue: 'app://home?id=id', deepLinkKeys: 'id' },
1425
- externalButton,
1426
- null,
1427
- ]);
1428
- });
1429
- });
@@ -11,6 +11,7 @@ import {
11
11
  skipTags,
12
12
  checkIfSupportedTag,
13
13
  transformInjectedTags,
14
+ hasUnquotedTagDefault,
14
15
  } from '../tagValidations';
15
16
  import { containsBase64Images } from '../content';
16
17
 
@@ -193,6 +194,53 @@ describe("check if curly brackets are balanced", () => {
193
194
  })
194
195
  })
195
196
 
197
+ describe('hasUnquotedTagDefault', () => {
198
+ it('allows tags without default and defaults within quotes', () => {
199
+ expect(hasUnquotedTagDefault('{{badge_description}}')).toBe(false);
200
+ expect(hasUnquotedTagDefault("{{badge_description | default: ''}}")).toBe(false);
201
+ expect(hasUnquotedTagDefault("{{badge_description | default: 'Rafeeq'}}")).toBe(false);
202
+ expect(hasUnquotedTagDefault('{{badge_description | default: "Rafeeq\'s"}}')).toBe(false);
203
+ expect(hasUnquotedTagDefault("Hi {{a|default:' '}} {{b}} plain text")).toBe(false);
204
+ });
205
+
206
+ it('flags default with missing or unquoted value', () => {
207
+ expect(hasUnquotedTagDefault('{{badge_description | default: }}')).toBe(true);
208
+ expect(hasUnquotedTagDefault('{{badge_description | default: Rafeeq}}')).toBe(true);
209
+ expect(hasUnquotedTagDefault("{{badge_description | default: 'Rafeeq}}")).toBe(true);
210
+ expect(hasUnquotedTagDefault("{{a}} {{b | default: 'x' y}}")).toBe(true);
211
+ });
212
+
213
+ it('ignores pipes inside quotes and allows chained filters', () => {
214
+ expect(hasUnquotedTagDefault("{{name | replace: '| default:', 'x'}}")).toBe(false);
215
+ expect(hasUnquotedTagDefault("{{name | default: 'a | default: b'}}")).toBe(false);
216
+ expect(hasUnquotedTagDefault("{{name | default: 'a|b'}}")).toBe(false);
217
+ expect(hasUnquotedTagDefault("{{name | default: 'x' | append: '!'}}")).toBe(false);
218
+ expect(hasUnquotedTagDefault("{{name | append: 'x' | default: 'y'}}")).toBe(false);
219
+ });
220
+
221
+ it('rejects backslash-escaped quotes since Liquid has no escapes', () => {
222
+ expect(hasUnquotedTagDefault("{{name | default: 'it\\'s'}}")).toBe(true);
223
+ });
224
+ });
225
+
226
+ describe('validateTagsCore default quote check', () => {
227
+ const run = (content) => validateTagsCore({
228
+ contentForBraceCheck: content, contentForUnsubscribeScan: content, tags: null, currentModule: 'default', isFullMode: true,
229
+ });
230
+
231
+ it('marks unquoted default as invalid with isDefaultQuoteError', () => {
232
+ expect(run('{{name | default: Rafeeq}}')).toEqual(expect.objectContaining({ valid: false, isBraceError: false, isDefaultQuoteError: true }));
233
+ });
234
+
235
+ it('keeps quoted default valid', () => {
236
+ expect(run("{{name | default: 'Rafeeq'}}")).toEqual(expect.objectContaining({ valid: true, isDefaultQuoteError: false }));
237
+ });
238
+
239
+ it('reports only brace error when braces are not closed', () => {
240
+ expect(run('{{name | default: Rafeeq}')).toEqual(expect.objectContaining({ isBraceError: true, isDefaultQuoteError: false }));
241
+ });
242
+ });
243
+
196
244
  describe("validateTags", () => {
197
245
  const tagsParam = [
198
246
  {