@capillarytech/creatives-library 8.0.222 → 8.0.223
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/config/app.js +0 -1
- package/package.json +1 -1
- package/services/api.js +0 -2
- package/utils/commonUtils.js +2 -2
- package/utils/tagValidations.js +9 -14
- package/utils/tests/commonUtil.test.js +145 -0
- package/utils/tests/tagValidations.test.js +86 -0
- package/v2Components/FormBuilder/index.js +6 -13
package/config/app.js
CHANGED
|
@@ -21,7 +21,6 @@ const config = {
|
|
|
21
21
|
},
|
|
22
22
|
development: {
|
|
23
23
|
api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/creatives',
|
|
24
|
-
// api_endpoint: 'http://localhost:2022/arya/api/v1/creatives',
|
|
25
24
|
campaigns_api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/campaigns',
|
|
26
25
|
campaigns_api_org_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/org/campaign',
|
|
27
26
|
auth_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/auth',
|
package/package.json
CHANGED
package/services/api.js
CHANGED
|
@@ -264,7 +264,6 @@ export const getUserData = () => {
|
|
|
264
264
|
|
|
265
265
|
export const createTemplate = ({template}) => {
|
|
266
266
|
const url = `${API_ENDPOINT}/templates/SMS`;
|
|
267
|
-
console.log("creating template",template);
|
|
268
267
|
return request(url, getAPICallObject('POST', template));
|
|
269
268
|
};
|
|
270
269
|
|
|
@@ -347,7 +346,6 @@ export const getAllTemplates = async ({channel, queryParams = {}}) => {
|
|
|
347
346
|
|
|
348
347
|
export const deleteTemplate = ({channel, id}) => {
|
|
349
348
|
const url = `${API_ENDPOINT}/templates/${id}/${channel}`;
|
|
350
|
-
console.log("deleting template", url);
|
|
351
349
|
return request(url, getAPICallObject('DELETE'));
|
|
352
350
|
//return API.deleteResource(url);
|
|
353
351
|
};
|
package/utils/commonUtils.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
IOS,
|
|
17
17
|
} from "../v2Containers/CreativesContainer/constants";
|
|
18
18
|
import { GLOBAL_CONVERT_OPTIONS } from "../v2Components/FormBuilder/constants";
|
|
19
|
-
import { checkSupport, extractNames } from "./tagValidations";
|
|
19
|
+
import { checkSupport, extractNames, skipTags as defaultSkipTags } from "./tagValidations";
|
|
20
20
|
import { SMS_TRAI_VAR } from '../v2Containers/SmsTrai/Edit/constants';
|
|
21
21
|
export const apiMessageFormatHandler = (id, fallback) => (
|
|
22
22
|
<FormattedMessage id={id} defaultMessage={fallback} />
|
|
@@ -146,7 +146,7 @@ export const validateLiquidTemplateContent = async (
|
|
|
146
146
|
isLiquidFlow,
|
|
147
147
|
forwardedTags = {},
|
|
148
148
|
tabType,
|
|
149
|
-
skipTags =
|
|
149
|
+
skipTags = defaultSkipTags,
|
|
150
150
|
} = options;
|
|
151
151
|
const emptyBodyError = formatMessage(messages?.emailBodyEmptyError);
|
|
152
152
|
const somethingWrongMsg = formatMessage(messages?.somethingWentWrong);
|
package/utils/tagValidations.js
CHANGED
|
@@ -221,7 +221,7 @@ export const validateTags = ({
|
|
|
221
221
|
/**
|
|
222
222
|
* Checks if the given tag is supported based on the injected tags.
|
|
223
223
|
* @param {string} checkingTag - The tag to check.
|
|
224
|
-
* @param {
|
|
224
|
+
* @param {Object} injectedTags - The injected tags.
|
|
225
225
|
* @returns {boolean} - True if the tag is supported, false otherwise.
|
|
226
226
|
*/
|
|
227
227
|
export const checkIfSupportedTag = (checkingTag, injectedTags) => {
|
|
@@ -235,7 +235,7 @@ export const checkIfSupportedTag = (checkingTag, injectedTags) => {
|
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
return result;
|
|
238
|
-
}
|
|
238
|
+
};
|
|
239
239
|
|
|
240
240
|
const indexOfEnd = (targetString, string) => {
|
|
241
241
|
let io = targetString.indexOf(string);
|
|
@@ -247,19 +247,14 @@ export const skipTags = (tag) => {
|
|
|
247
247
|
if (tag?.match(ENTRY_TRIGGER_TAG_REGEX)) {
|
|
248
248
|
return false;
|
|
249
249
|
}
|
|
250
|
-
const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)","Link_to_[a-zA-z]","SURVEY.*.TOKEN", "^[A-Za-z].*\\([a-zA-Z\\d]*\\)"];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
skipped = true;
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
return true;
|
|
250
|
+
const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)", "Link_to_[a-zA-z]", "SURVEY.*.TOKEN", "^[A-Za-z].*\\([a-zA-Z\\d]*\\)", "referral_unique_(code|url).*userid"];
|
|
251
|
+
// Use some() to check if any pattern matches (stops on first match)
|
|
252
|
+
return regexGroups.some((group) => {
|
|
253
|
+
// Create a new RegExp for each test to avoid state issues with global flag
|
|
254
|
+
const groupRegex = new RegExp(group);
|
|
255
|
+
return groupRegex.test(tag);
|
|
260
256
|
});
|
|
261
|
-
|
|
262
|
-
}
|
|
257
|
+
};
|
|
263
258
|
|
|
264
259
|
export const transformInjectedTags = (tags) => {
|
|
265
260
|
lodashForEach(tags, (tag) => {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
addBaseToTemplate,
|
|
8
8
|
validateCarouselCards,
|
|
9
9
|
} from "../commonUtils";
|
|
10
|
+
import { skipTags } from "../tagValidations";
|
|
10
11
|
import { SMS_TRAI_VAR } from '../../v2Containers/SmsTrai/Edit/constants';
|
|
11
12
|
import { ANDROID, IOS } from '../../v2Containers/CreativesContainer/constants';
|
|
12
13
|
|
|
@@ -122,6 +123,150 @@ describe("validateLiquidTemplateContent", () => {
|
|
|
122
123
|
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
123
124
|
});
|
|
124
125
|
|
|
126
|
+
it("should skip referral_unique_code tags and not trigger unsupported tag error", async () => {
|
|
127
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
128
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_code_C6SOE_userid" }] }, isError: false })
|
|
129
|
+
);
|
|
130
|
+
await validateLiquidTemplateContent("foo", {
|
|
131
|
+
getLiquidTags,
|
|
132
|
+
formatMessage,
|
|
133
|
+
messages,
|
|
134
|
+
onError,
|
|
135
|
+
onSuccess,
|
|
136
|
+
tagLookupMap,
|
|
137
|
+
eventContextTags,
|
|
138
|
+
skipTags
|
|
139
|
+
});
|
|
140
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
141
|
+
expect(onError).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should skip referral_unique_url tags and not trigger unsupported tag error", async () => {
|
|
145
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
146
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_url_C6SOE_userid" }] }, isError: false })
|
|
147
|
+
);
|
|
148
|
+
await validateLiquidTemplateContent("foo", {
|
|
149
|
+
getLiquidTags,
|
|
150
|
+
formatMessage,
|
|
151
|
+
messages,
|
|
152
|
+
onError,
|
|
153
|
+
onSuccess,
|
|
154
|
+
tagLookupMap,
|
|
155
|
+
eventContextTags,
|
|
156
|
+
skipTags
|
|
157
|
+
});
|
|
158
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
159
|
+
expect(onError).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("should skip referral_unique_code tags with different codes", async () => {
|
|
163
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
164
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_code_ABC123_userid" }] }, isError: false })
|
|
165
|
+
);
|
|
166
|
+
await validateLiquidTemplateContent("foo", {
|
|
167
|
+
getLiquidTags,
|
|
168
|
+
formatMessage,
|
|
169
|
+
messages,
|
|
170
|
+
onError,
|
|
171
|
+
onSuccess,
|
|
172
|
+
tagLookupMap,
|
|
173
|
+
eventContextTags,
|
|
174
|
+
skipTags
|
|
175
|
+
});
|
|
176
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
177
|
+
expect(onError).not.toHaveBeenCalled();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("should skip referral_unique_url tags with different codes", async () => {
|
|
181
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
182
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_url_ABC123_userid" }] }, isError: false })
|
|
183
|
+
);
|
|
184
|
+
await validateLiquidTemplateContent("foo", {
|
|
185
|
+
getLiquidTags,
|
|
186
|
+
formatMessage,
|
|
187
|
+
messages,
|
|
188
|
+
onError,
|
|
189
|
+
onSuccess,
|
|
190
|
+
tagLookupMap,
|
|
191
|
+
eventContextTags,
|
|
192
|
+
skipTags
|
|
193
|
+
});
|
|
194
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
195
|
+
expect(onError).not.toHaveBeenCalled();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should skip referral_unique_code tags with alphanumeric codes", async () => {
|
|
199
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
200
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_code_XYZ789_userid" }] }, isError: false })
|
|
201
|
+
);
|
|
202
|
+
await validateLiquidTemplateContent("foo", {
|
|
203
|
+
getLiquidTags,
|
|
204
|
+
formatMessage,
|
|
205
|
+
messages,
|
|
206
|
+
onError,
|
|
207
|
+
onSuccess,
|
|
208
|
+
tagLookupMap,
|
|
209
|
+
eventContextTags,
|
|
210
|
+
skipTags
|
|
211
|
+
});
|
|
212
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
213
|
+
expect(onError).not.toHaveBeenCalled();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should skip referral_unique_url tags with alphanumeric codes", async () => {
|
|
217
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
218
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_url_XYZ789_userid" }] }, isError: false })
|
|
219
|
+
);
|
|
220
|
+
await validateLiquidTemplateContent("foo", {
|
|
221
|
+
getLiquidTags,
|
|
222
|
+
formatMessage,
|
|
223
|
+
messages,
|
|
224
|
+
onError,
|
|
225
|
+
onSuccess,
|
|
226
|
+
tagLookupMap,
|
|
227
|
+
eventContextTags,
|
|
228
|
+
skipTags
|
|
229
|
+
});
|
|
230
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
231
|
+
expect(onError).not.toHaveBeenCalled();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should skip both referral_unique_code and referral_unique_url tags in the same content", async () => {
|
|
235
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
236
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_code_C6SOE_userid" }, { name: "referral_unique_url_C6SOE_userid" }] }, isError: false })
|
|
237
|
+
);
|
|
238
|
+
await validateLiquidTemplateContent("foo", {
|
|
239
|
+
getLiquidTags,
|
|
240
|
+
formatMessage,
|
|
241
|
+
messages,
|
|
242
|
+
onError,
|
|
243
|
+
onSuccess,
|
|
244
|
+
tagLookupMap,
|
|
245
|
+
eventContextTags,
|
|
246
|
+
skipTags
|
|
247
|
+
});
|
|
248
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
249
|
+
expect(onError).not.toHaveBeenCalled();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("should skip referral_unique_code_632L7_userid tag (real-world example)", async () => {
|
|
253
|
+
const getLiquidTags = jest.fn((content, cb) =>
|
|
254
|
+
cb({ askAiraResponse: { errors: [], data: [{ name: "referral_unique_code_632L7_userid" }] }, isError: false })
|
|
255
|
+
);
|
|
256
|
+
await validateLiquidTemplateContent("foo", {
|
|
257
|
+
getLiquidTags,
|
|
258
|
+
formatMessage,
|
|
259
|
+
messages,
|
|
260
|
+
onError,
|
|
261
|
+
onSuccess,
|
|
262
|
+
tagLookupMap,
|
|
263
|
+
eventContextTags,
|
|
264
|
+
skipTags
|
|
265
|
+
});
|
|
266
|
+
expect(onSuccess).toHaveBeenCalledWith("foo", undefined);
|
|
267
|
+
expect(onError).not.toHaveBeenCalled();
|
|
268
|
+
});
|
|
269
|
+
|
|
125
270
|
it("calls onError with emailBodyEmptyError when validString is falsy", async () => {
|
|
126
271
|
const getLiquidTags = jest.fn((content, cb) => cb({ askAiraResponse: { errors: [], data: [] }, isError: false }));
|
|
127
272
|
const formatMessage = jest.fn((msg) => msg.id);
|
|
@@ -952,6 +952,92 @@ describe("skipTags", () => {
|
|
|
952
952
|
const result = skipTags(tag);
|
|
953
953
|
expect(result).toEqual(true);
|
|
954
954
|
});
|
|
955
|
+
|
|
956
|
+
it("should return true for referral unique code tags with userid", () => {
|
|
957
|
+
const tag = "referral_unique_code_C6SOE_userid";
|
|
958
|
+
const result = skipTags(tag);
|
|
959
|
+
expect(result).toEqual(true);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
it("should return true for referral unique url tags with userid", () => {
|
|
963
|
+
const tag = "referral_unique_url_C6SOE_userid";
|
|
964
|
+
const result = skipTags(tag);
|
|
965
|
+
expect(result).toEqual(true);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
it("should return true for referral unique code tags with different codes", () => {
|
|
969
|
+
const tag = "referral_unique_code_ABC123_userid";
|
|
970
|
+
const result = skipTags(tag);
|
|
971
|
+
expect(result).toEqual(true);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
it("should return true for referral unique url tags with different codes", () => {
|
|
975
|
+
const tag = "referral_unique_url_ABC123_userid";
|
|
976
|
+
const result = skipTags(tag);
|
|
977
|
+
expect(result).toEqual(true);
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
it("should return true for referral unique code tags with alphanumeric codes", () => {
|
|
981
|
+
const tag = "referral_unique_code_XYZ789_userid";
|
|
982
|
+
const result = skipTags(tag);
|
|
983
|
+
expect(result).toEqual(true);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
it("should return true for referral unique url tags with alphanumeric codes", () => {
|
|
987
|
+
const tag = "referral_unique_url_XYZ789_userid";
|
|
988
|
+
const result = skipTags(tag);
|
|
989
|
+
expect(result).toEqual(true);
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
it("should return false for tags that don't match referral pattern", () => {
|
|
993
|
+
const tag = "referral_code_userid";
|
|
994
|
+
const result = skipTags(tag);
|
|
995
|
+
expect(result).toEqual(false);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it("should return false for tags with referral but missing unique_code or unique_url", () => {
|
|
999
|
+
const tag = "referral_C6SOE_userid";
|
|
1000
|
+
const result = skipTags(tag);
|
|
1001
|
+
expect(result).toEqual(false);
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
it("should return false for tags with referral_unique_code but missing userid", () => {
|
|
1005
|
+
const tag = "referral_unique_code_C6SOE";
|
|
1006
|
+
const result = skipTags(tag);
|
|
1007
|
+
expect(result).toEqual(false);
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it("should return false for tags with referral_unique_url but missing userid", () => {
|
|
1011
|
+
const tag = "referral_unique_url_C6SOE";
|
|
1012
|
+
const result = skipTags(tag);
|
|
1013
|
+
expect(result).toEqual(false);
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
it("should return true for referral_unique_code tags with numeric codes like 632L7", () => {
|
|
1017
|
+
const tag = "referral_unique_code_632L7_userid";
|
|
1018
|
+
const result = skipTags(tag);
|
|
1019
|
+
expect(result).toEqual(true);
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
it("should return true for referral_unique_url tags with numeric codes like 632L7", () => {
|
|
1023
|
+
const tag = "referral_unique_url_632L7_userid";
|
|
1024
|
+
const result = skipTags(tag);
|
|
1025
|
+
expect(result).toEqual(true);
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it("should return true for referral tags with various token formats", () => {
|
|
1029
|
+
const tags = [
|
|
1030
|
+
"referral_unique_code_123_userid",
|
|
1031
|
+
"referral_unique_code_ABC_userid",
|
|
1032
|
+
"referral_unique_code_123ABC_userid",
|
|
1033
|
+
"referral_unique_url_456_userid",
|
|
1034
|
+
"referral_unique_url_DEF_userid",
|
|
1035
|
+
"referral_unique_url_456DEF_userid",
|
|
1036
|
+
];
|
|
1037
|
+
tags.forEach((tag) => {
|
|
1038
|
+
expect(skipTags(tag)).toEqual(true);
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
955
1041
|
});
|
|
956
1042
|
|
|
957
1043
|
|
|
@@ -1491,20 +1491,13 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
1491
1491
|
if (tag?.match(ENTRY_TRIGGER_TAG_REGEX)) {
|
|
1492
1492
|
return false;
|
|
1493
1493
|
}
|
|
1494
|
-
const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)","Link_to_[a-zA-z]","SURVEY.*.TOKEN","^[A-Za-z].*\\([a-zA-Z\\d]*\\)"];
|
|
1495
|
-
//
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
let match = groupRegex.exec(tag);
|
|
1501
|
-
if (match !== null ) {
|
|
1502
|
-
skipped = true;
|
|
1503
|
-
return true;
|
|
1504
|
-
}
|
|
1505
|
-
return true;
|
|
1494
|
+
const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)", "Link_to_[a-zA-z]", "SURVEY.*.TOKEN", "^[A-Za-z].*\\([a-zA-Z\\d]*\\)", "referral_unique_(code|url).*userid"];
|
|
1495
|
+
// Use some() to check if any pattern matches (stops on first match)
|
|
1496
|
+
return regexGroups.some((group) => {
|
|
1497
|
+
// Create a new RegExp for each test to avoid state issues with global flag
|
|
1498
|
+
const groupRegex = new RegExp(group);
|
|
1499
|
+
return groupRegex.test(tag);
|
|
1506
1500
|
});
|
|
1507
|
-
return skipped;
|
|
1508
1501
|
}
|
|
1509
1502
|
|
|
1510
1503
|
validateTags(content, tagsParam, injectedTagsParams, isEmail = false) {
|