@capillarytech/creatives-library 7.12.113 → 7.12.115
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": "7.12.
|
|
4
|
+
"version": "7.12.115",
|
|
5
5
|
"description": "Capillary creatives ui",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"module": "./index.es.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"jest-date-mock": "^1.0.8",
|
|
25
25
|
"jquery": "^3.3.1",
|
|
26
26
|
"load-script": "^1.0.0",
|
|
27
|
+
"node-html-parser": "^5.4.2-0",
|
|
27
28
|
"normalizr": "^3.2.3",
|
|
28
29
|
"papaparse": "^5.3.1",
|
|
29
30
|
"pre-push": "^0.1.2",
|
|
@@ -12,8 +12,6 @@ import { parse } from "node-html-parser";
|
|
|
12
12
|
* regex tests presence of intouch_creative_assets in the url.
|
|
13
13
|
* We are not testing for extensions such as jpg/png because some channels like LINE - IMAGEMAP url doesn't contain extension.
|
|
14
14
|
*/
|
|
15
|
-
const regex = /https:\/\/.*intouch_creative_assets.*$/;
|
|
16
|
-
const INTOUCH_CREATIVE_ASSETS = "intouch_creative_assets";
|
|
17
15
|
const SPECIFIED = "specified";
|
|
18
16
|
const FORMAT_TYPES = { AUTO: "auto" };
|
|
19
17
|
const QUALITY_TYPE = {
|
|
@@ -21,9 +19,13 @@ const QUALITY_TYPE = {
|
|
|
21
19
|
PRESERVE: "preserve",
|
|
22
20
|
};
|
|
23
21
|
const CREATIVES_CDN_BASE_URL_KEY = 'CREATIVES_CDN_BASE_URL';
|
|
22
|
+
const CREATIVES_S3_BUCKET_PATH_KEY = 'CREATIVES_S3_BUCKET_PATH';
|
|
24
23
|
const CREATIVES_CDN_QUALITY_CONFIG_KEY = 'CREATIVES_CDN_QUALITY_CONFIG';
|
|
25
24
|
const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY = 'CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX';
|
|
26
25
|
|
|
26
|
+
const HTTPS_STR = "https://"
|
|
27
|
+
const ALLOWED_EXTENSIONS_STR = ".*(?:jpg|png|jpeg)$"
|
|
28
|
+
const ANY_STR = ".*"
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* CHANNEL_CONFIGS maintains the transformation details for each channel (and optionally subchannel ex. FACEBOOK/LINE)
|
|
@@ -141,21 +143,31 @@ export const getCdnUrl = ({
|
|
|
141
143
|
const CREATIVES_CDN_BASE_URL = getLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
142
144
|
const CREATIVES_CDN_QUALITY_CONFIG = getLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY, true);
|
|
143
145
|
const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX = getLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
144
|
-
|
|
146
|
+
let CREATIVES_S3_BUCKET_PATH = getLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
147
|
+
|
|
148
|
+
//remove all leading and trailing forward slash with empty string, if leading/trailing forward slash is present in node env by mistake then url will not be correct hence removing them.
|
|
149
|
+
CREATIVES_S3_BUCKET_PATH = CREATIVES_S3_BUCKET_PATH.replace(/^\/|\/$/g, '');
|
|
150
|
+
|
|
145
151
|
//Basic validations on data stored in local storage.
|
|
146
152
|
if (
|
|
147
153
|
typeof CREATIVES_CDN_QUALITY_CONFIG !== "object" ||
|
|
148
154
|
Array.isArray(CREATIVES_CDN_QUALITY_CONFIG) ||
|
|
149
155
|
CREATIVES_CDN_QUALITY_CONFIG === null ||
|
|
150
156
|
typeof CREATIVES_CDN_BASE_URL !== "string" ||
|
|
151
|
-
typeof CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX !== "string"
|
|
157
|
+
typeof CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX !== "string" ||
|
|
158
|
+
typeof CREATIVES_S3_BUCKET_PATH !== 'string'
|
|
152
159
|
)
|
|
153
160
|
return url;
|
|
154
161
|
|
|
155
162
|
const QUALITY = CREATIVES_CDN_QUALITY_CONFIG?.[channelName] || CREATIVES_CDN_QUALITY_CONFIG?.DEFAULT;
|
|
156
163
|
|
|
164
|
+
const regexWithExtension = new RegExp(HTTPS_STR + ANY_STR + CREATIVES_S3_BUCKET_PATH + ANY_STR + ALLOWED_EXTENSIONS_STR)
|
|
165
|
+
const regexWithoutExtension = new RegExp(HTTPS_STR + ANY_STR + CREATIVES_S3_BUCKET_PATH + ANY_STR);
|
|
166
|
+
|
|
167
|
+
let skipTransformations = true;
|
|
168
|
+
|
|
157
169
|
if (
|
|
158
|
-
!
|
|
170
|
+
!regexWithoutExtension.test(url) ||
|
|
159
171
|
!CHANNEL_CONFIGS?.[channelName] ||
|
|
160
172
|
(channelSubType && !CHANNEL_CONFIGS?.[channelName]?.[channelSubType]) ||
|
|
161
173
|
!CREATIVES_CDN_BASE_URL ||
|
|
@@ -163,8 +175,13 @@ export const getCdnUrl = ({
|
|
|
163
175
|
!QUALITY
|
|
164
176
|
)
|
|
165
177
|
return url;
|
|
166
|
-
|
|
167
|
-
|
|
178
|
+
|
|
179
|
+
//Skip transformations if extensions are not proper. Else consider transformations if available.
|
|
180
|
+
if(regexWithExtension.test(url)){
|
|
181
|
+
skipTransformations = false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const [, assetKey] = url.split(CREATIVES_S3_BUCKET_PATH);
|
|
168
185
|
|
|
169
186
|
let newUrl = `${CREATIVES_CDN_BASE_URL}`;
|
|
170
187
|
|
|
@@ -177,7 +194,7 @@ export const getCdnUrl = ({
|
|
|
177
194
|
applicableTransformations = CHANNEL_CONFIGS?.[channelName]?.transformations;
|
|
178
195
|
}
|
|
179
196
|
|
|
180
|
-
if (!isEmpty(applicableTransformations)) {
|
|
197
|
+
if (!isEmpty(applicableTransformations) && !skipTransformations) {
|
|
181
198
|
|
|
182
199
|
newUrl += `/${CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX}/`;
|
|
183
200
|
|
|
@@ -215,15 +232,15 @@ export const getCdnUrl = ({
|
|
|
215
232
|
break;
|
|
216
233
|
}
|
|
217
234
|
} catch (e) {
|
|
218
|
-
console.
|
|
235
|
+
console.error("some error occured while applying transformation",e);
|
|
219
236
|
}
|
|
220
237
|
})
|
|
221
238
|
}
|
|
222
|
-
newUrl += `/${
|
|
239
|
+
newUrl += `/${CREATIVES_S3_BUCKET_PATH}${assetKey}`;
|
|
223
240
|
return newUrl;
|
|
224
241
|
|
|
225
242
|
}catch(e){
|
|
226
|
-
console.
|
|
243
|
+
console.error('Some exception occurred in getCdnUrl',e);
|
|
227
244
|
return url;
|
|
228
245
|
}
|
|
229
246
|
};
|
|
@@ -237,24 +254,21 @@ export const updateImagesInHtml = (htmlContents) => {
|
|
|
237
254
|
const copiedHtmlContents = htmlContents;
|
|
238
255
|
try {
|
|
239
256
|
const root = parse(htmlContents);
|
|
240
|
-
root
|
|
257
|
+
root?.querySelectorAll("img")?.forEach((element) => {
|
|
241
258
|
const imageSrc = element.getAttribute("src");
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
});
|
|
252
|
-
element.setAttribute("src", newUrl);
|
|
253
|
-
}
|
|
259
|
+
const height = element.getAttribute("height");
|
|
260
|
+
const width = element.getAttribute("width");
|
|
261
|
+
const newUrl = getCdnUrl({
|
|
262
|
+
url: imageSrc,
|
|
263
|
+
height,
|
|
264
|
+
width,
|
|
265
|
+
channelName: "EMAIL",
|
|
266
|
+
});
|
|
267
|
+
element.setAttribute("src", newUrl);
|
|
254
268
|
});
|
|
255
269
|
return root.toString();
|
|
256
270
|
} catch (e) {
|
|
257
|
-
console.
|
|
271
|
+
console.error("An error occured while updating images in html", e);
|
|
258
272
|
return copiedHtmlContents; //return received input directly in case an exception is thrown
|
|
259
273
|
}
|
|
260
274
|
};
|
|
@@ -277,7 +291,7 @@ export const transformEmailTemplates = (contents) => {
|
|
|
277
291
|
});
|
|
278
292
|
return contentsCopy;
|
|
279
293
|
} catch (e) {
|
|
280
|
-
console.
|
|
294
|
+
console.error("Some error has occured while transforming email templates", e);
|
|
281
295
|
return contents; //return received input directly in case an exception is thrown
|
|
282
296
|
}
|
|
283
297
|
};
|
|
@@ -313,8 +327,9 @@ export function removeAllCdnLocalStorageItems() {
|
|
|
313
327
|
removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
314
328
|
removeLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY);
|
|
315
329
|
removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
330
|
+
removeLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
316
331
|
}catch(e){
|
|
317
|
-
console.
|
|
332
|
+
console.error('some error occured while deleting all keys for cdn', e);
|
|
318
333
|
}
|
|
319
334
|
}
|
|
320
335
|
|
|
@@ -348,6 +363,15 @@ export function saveCdnConfigs(configsResponse) {
|
|
|
348
363
|
removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
349
364
|
}
|
|
350
365
|
|
|
366
|
+
if (configsResponse?.bucketPath) {
|
|
367
|
+
localStorage.setItem(
|
|
368
|
+
CREATIVES_S3_BUCKET_PATH_KEY,
|
|
369
|
+
configsResponse?.bucketPath
|
|
370
|
+
);
|
|
371
|
+
} else {
|
|
372
|
+
removeLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
373
|
+
}
|
|
374
|
+
|
|
351
375
|
if (!isEmpty(configsResponse?.qualityCfg)) {
|
|
352
376
|
const qualityString = JSON.stringify(configsResponse?.qualityCfg);
|
|
353
377
|
localStorage.setItem(CREATIVES_CDN_QUALITY_CONFIG_KEY, qualityString);
|
|
@@ -364,6 +388,6 @@ export function saveCdnConfigs(configsResponse) {
|
|
|
364
388
|
removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
365
389
|
}
|
|
366
390
|
} catch (e) {
|
|
367
|
-
console.
|
|
391
|
+
console.error("some error while setting localstorage cdn configs");
|
|
368
392
|
}
|
|
369
393
|
}
|
|
@@ -5,6 +5,7 @@ beforeEach(() => {
|
|
|
5
5
|
var localStorageMock = (function () {
|
|
6
6
|
var store = {
|
|
7
7
|
CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX: "cdn-cgi/image",
|
|
8
|
+
CREATIVES_S3_BUCKET_PATH: "intouch_creative_assets",
|
|
8
9
|
CREATIVES_CDN_BASE_URL: "https://storage.crm.n.content-cdn.io",
|
|
9
10
|
CREATIVES_CDN_QUALITY_CONFIG:
|
|
10
11
|
'{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}',
|
|
@@ -32,6 +33,9 @@ afterEach(() => {
|
|
|
32
33
|
"CREATIVES_CDN_QUALITY_CONFIG",
|
|
33
34
|
'{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}'
|
|
34
35
|
);
|
|
36
|
+
localStorage.setItem(
|
|
37
|
+
"CREATIVES_S3_BUCKET_PATH", "intouch_creative_assets"
|
|
38
|
+
);
|
|
35
39
|
});
|
|
36
40
|
|
|
37
41
|
describe("cdnTransformationTests", () => {
|
|
@@ -83,6 +87,44 @@ describe("cdnTransformationTests", () => {
|
|
|
83
87
|
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
84
88
|
});
|
|
85
89
|
|
|
90
|
+
it("Should replace s3 url with cdn url for email when bucket name is other than intouch_creatives_assets in case of prod.", () => {
|
|
91
|
+
localStorage.setItem("CREATIVES_S3_BUCKET_PATH", "fileservice.in/intouch_creative_assets");
|
|
92
|
+
const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/fileservice.in/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
|
|
93
|
+
const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
|
|
94
|
+
url: TEST_S3_URL,
|
|
95
|
+
channelName: "EMAIL",
|
|
96
|
+
height: 100,
|
|
97
|
+
width: 200,
|
|
98
|
+
});
|
|
99
|
+
const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=200,height=100,format=auto,quality=75,/fileservice.in/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
|
|
100
|
+
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it.only("Should replace s3 url with cdn url for email when bucket name is other than intouch_creatives_assets in case of prod. It should remove leading/trailing forward slashes from bucket path", () => {
|
|
104
|
+
localStorage.setItem("CREATIVES_S3_BUCKET_PATH", "/fileservice.in/intouch_creative_assets/");
|
|
105
|
+
const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/fileservice.in/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
|
|
106
|
+
const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
|
|
107
|
+
url: TEST_S3_URL,
|
|
108
|
+
channelName: "EMAIL",
|
|
109
|
+
height: 100,
|
|
110
|
+
width: 200,
|
|
111
|
+
});
|
|
112
|
+
const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=200,height=100,format=auto,quality=75,/fileservice.in/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
|
|
113
|
+
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("Should replace s3 url with cdn url for email without transformation for formats other than jpg/png/jpeg", () => {
|
|
117
|
+
const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.avif`; //this is random url
|
|
118
|
+
const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
|
|
119
|
+
url: TEST_S3_URL,
|
|
120
|
+
channelName: "EMAIL",
|
|
121
|
+
height: 100,
|
|
122
|
+
width: 200,
|
|
123
|
+
});
|
|
124
|
+
const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.avif`;
|
|
125
|
+
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
126
|
+
});
|
|
127
|
+
|
|
86
128
|
it("should replace cdn url with new cdn url for email incase h/w etc changed", () => {
|
|
87
129
|
const TEST_S3_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=200,height=100,format=auto,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
|
|
88
130
|
const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
|
|
@@ -95,14 +137,14 @@ describe("cdnTransformationTests", () => {
|
|
|
95
137
|
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
96
138
|
});
|
|
97
139
|
|
|
98
|
-
it("should replace cdn url with new cdn url incase channelName is LINE and channelSubType is RICH_MESSAGE ", () => {
|
|
140
|
+
it("should replace cdn url with new cdn url incase channelName is LINE and channelSubType is RICH_MESSAGE without transformation", () => {
|
|
99
141
|
const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`;
|
|
100
142
|
const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
|
|
101
143
|
url: TEST_S3_URL,
|
|
102
144
|
channelName: "LINE",
|
|
103
145
|
channelSubType: "RICH_MESSAGE",
|
|
104
146
|
});
|
|
105
|
-
const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/
|
|
147
|
+
const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`;
|
|
106
148
|
expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
|
|
107
149
|
});
|
|
108
150
|
|
|
@@ -1690,7 +1690,7 @@ export const response = {
|
|
|
1690
1690
|
},
|
|
1691
1691
|
submitAction: "addSecondaryCtaIos",
|
|
1692
1692
|
supportedEvents: [
|
|
1693
|
-
"addSecondaryCtaIos"
|
|
1693
|
+
"addSecondaryCtaIos",
|
|
1694
1694
|
],
|
|
1695
1695
|
disabled: true,
|
|
1696
1696
|
hoverText: "This section is being revamped. Till then it will remain disabled.",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is not an integration test rather it's created to run the integration test script for now.
|
|
3
|
-
* The tests case and file name will be re-written as per the requirement in future.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
describe('Create Templates ', () => {
|
|
7
|
-
it('Should pass the test case for truthy values', async () => {
|
|
8
|
-
expect(true).toBeTruthy();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('Should pass the test case for falsy values', async () => {
|
|
12
|
-
expect(false).toBeFalsy();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('Should pass the test case for falsy values', async () => {
|
|
16
|
-
expect({}).toEqual({});
|
|
17
|
-
});
|
|
18
|
-
});
|