@capillarytech/creatives-library 7.12.105 → 7.12.106

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.105",
4
+ "version": "7.12.106",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/routes.js CHANGED
@@ -13,6 +13,8 @@ import * as emailSagas from 'containers/Email/sagas';
13
13
  import * as templateSagas from 'containers/Templates/sagas';
14
14
  import * as lineSagas from 'containers/Line/Create/sagas';
15
15
  import * as languageSaga from './v2Containers/LanguageProvider/sagas';
16
+ import * as templatesV2Saga from './v2Containers/TemplatesV2/sagas';
17
+
16
18
  import pathConfig from './config/path';
17
19
 
18
20
  import {updateCharCount} from './utils/smsCharCountV2';
@@ -37,6 +39,7 @@ export default function createRoutes(store) {
37
39
  const { injectReducer, injectSagas } = getAsyncInjectors(store); // eslint-disable-line no-unused-vars
38
40
  injectSagas(rootSaga.default);
39
41
  injectSagas(languageSaga.default);
42
+ injectSagas(templatesV2Saga.default);
40
43
  return [
41
44
  {
42
45
  path: '/',
@@ -263,20 +263,54 @@ export function getLocalStorageItem(key, parse = false){
263
263
  return val;
264
264
  }
265
265
 
266
- export function saveCdnConfigs(configsResponse){
266
+ export function removeLocalStorageItem(key) {
267
+ localStorage.removeItem(key);
268
+ return;
269
+ }
270
+
271
+ export function removeAllCdnLocalStorageItems() {
267
272
  try{
268
- if(isEmpty(configsResponse)) return;
269
- if(configsResponse?.hostname){
270
- localStorage.setItem(CREATIVES_CDN_BASE_URL_KEY, configsResponse?.hostname);
273
+ removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
274
+ removeLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY);
275
+ removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
276
+ }catch(e){
277
+ console.log('some error occured while deleting all keys for cdn', e);
278
+ }
279
+ }
280
+
281
+ export function saveCdnConfigs(configsResponse) {
282
+ try {
283
+ //If no response from api, then remove localStorage items if they were set previously
284
+ if (isEmpty(configsResponse)) {
285
+ removeAllCdnLocalStorageItems();
286
+ return;
287
+ }
288
+
289
+ if (configsResponse?.hostname) {
290
+ localStorage.setItem(
291
+ CREATIVES_CDN_BASE_URL_KEY,
292
+ configsResponse?.hostname
293
+ );
294
+ } else {
295
+ removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
271
296
  }
272
- if(!isEmpty(configsResponse?.qualityCfg)){
297
+
298
+ if (!isEmpty(configsResponse?.qualityCfg)) {
273
299
  const qualityString = JSON.stringify(configsResponse?.qualityCfg);
274
300
  localStorage.setItem(CREATIVES_CDN_QUALITY_CONFIG_KEY, qualityString);
301
+ } else {
302
+ removeLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY);
275
303
  }
276
- if(configsResponse?.transformationUrlSuffix){
277
- localStorage.setItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY, configsResponse?.transformationUrlSuffix);
304
+
305
+ if (configsResponse?.transformationUrlSuffix) {
306
+ localStorage.setItem(
307
+ CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY,
308
+ configsResponse?.transformationUrlSuffix
309
+ );
310
+ } else {
311
+ removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
278
312
  }
279
- }catch(e){
280
- console.log('some error while setting localstorage cdn configs')
313
+ } catch (e) {
314
+ console.log("some error while setting localstorage cdn configs");
281
315
  }
282
316
  }
@@ -1,126 +1,245 @@
1
- import * as cdnUtils from '../cdnTransformation';
2
- import * as mockdata from './cdnTransformation.mockdata';
3
-
4
- beforeEach(()=>{
5
- var localStorageMock = (function() {
6
- var store = {
7
- CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX: "cdn-cgi/image",
8
- CREATIVES_CDN_BASE_URL: "https://storage.crm.n.content-cdn.io",
9
- CREATIVES_CDN_QUALITY_CONFIG: '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}',
10
- };
11
- return {
12
- getItem: function(key) {
13
- return store[key];
14
- },
15
- setItem: function(key, value) {
16
- store[key] = value.toString();
17
- },
18
- clear: function() {
19
- store = {};
20
- },
21
- removeItem: function(key) {
22
- delete store[key];
23
- }
24
- };
25
- })();
26
- Object.defineProperty(window, 'localStorage', { value: localStorageMock });
27
- })
28
-
29
- afterEach(()=>{
30
- localStorage.setItem('CREATIVES_CDN_QUALITY_CONFIG', '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}')
31
- })
32
-
33
- describe('cdnTransformationTests',()=>{
34
- describe('getCdnUrl()',()=>{
35
-
36
- it('should return s3 url if bucket subfolder doesn\'t contain intouch_creative_assets',()=>{
37
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/test/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
38
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL'});
39
- expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
40
- })
41
-
42
- it('should return s3 if channelName is not defined',()=>{
43
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
44
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL});
45
- expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
46
- })
47
-
48
- it('should return s3 if specified channelSubType doesn\'t exist',()=>{
49
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
50
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'LINE', channelSubType: 'ABC'});
51
- expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
52
- })
53
-
54
- it('Should replace s3 url with cdn url for email when h/w are not provided',()=>{
55
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
56
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL'})
57
- const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/format=auto,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`
58
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
59
- })
60
-
61
- it('Should replace s3 url with cdn url for email when h/w are provided',()=>{
62
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
63
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL', height: 100, width: 200})
64
- const EXPECTED_CDN_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`
65
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
66
- })
67
-
68
- it('should replace cdn url with new cdn url for email incase h/w etc changed', ()=>{
69
- 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`
70
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL', height: 400, width: 500})
71
- const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=500,height=400,format=auto,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`
72
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
73
- })
74
-
75
- it('should replace cdn url with new cdn url incase channelName is LINE and channelSubType is RICH_MESSAGE ',()=>{
76
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`;
77
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'LINE', channelSubType: 'RICH_MESSAGE'})
78
- const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=1040,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`
79
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
80
- })
81
-
82
- it('should replace cdn url with new cdn url for channels which has predefined h/w for channel', ()=>{
83
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
84
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'RCS'})
85
- const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=1440,height=720,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`
86
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
87
- })
88
-
89
- it('should return url directly if typeof CREATIVES_CDN_QUALITY_CONFIG is not object',()=>{
90
- localStorage.setItem('CREATIVES_CDN_QUALITY_CONFIG', 'a')
91
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
92
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL'});
93
- expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
94
- })
95
-
96
- it('should return cdn url with full quality if quality is not number',()=>{
97
- localStorage.setItem('CREATIVES_CDN_QUALITY_CONFIG', '{"EMAIL":"a","RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}')
98
-
99
- const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
100
- const GENERATED_CDN_URL = cdnUtils.getCdnUrl({url: TEST_S3_URL, channelName: 'EMAIL', height: 100, width: 200})
101
- const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=200,height=100,format=auto,quality=100,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`
102
-
103
- expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
104
- })
105
- })
106
-
107
-
108
- describe('updateImagesInHtml()',()=>{
109
- it('should update images in html',()=>{
110
- const htmlContentsInput = mockdata.emailRawInput;
111
- const htmlContentsOutput = cdnUtils.updateImagesInHtml(htmlContentsInput);
112
- const expected = mockdata.emailRawTransformed;
113
- expect(htmlContentsOutput).toEqual(expected);
114
- })
115
- })
116
-
117
-
118
- describe('transformEmailTemplate()',()=>{
119
- it('should transform email template',()=>{
120
- const emailTemplateInput = mockdata.emailTemplateRaw;
121
- const emailTemplateOutput = cdnUtils.transformEmailTemplates(emailTemplateInput);
122
- expect(emailTemplateOutput).toMatchSnapshot();
123
- })
124
- })
125
- })
1
+ import * as cdnUtils from "../cdnTransformation";
2
+ import * as mockdata from "./cdnTransformation.mockdata";
126
3
 
4
+ beforeEach(() => {
5
+ var localStorageMock = (function () {
6
+ var store = {
7
+ CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX: "cdn-cgi/image",
8
+ CREATIVES_CDN_BASE_URL: "https://storage.crm.n.content-cdn.io",
9
+ CREATIVES_CDN_QUALITY_CONFIG:
10
+ '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}',
11
+ };
12
+ return {
13
+ getItem: function (key) {
14
+ return store[key];
15
+ },
16
+ setItem: function (key, value) {
17
+ store[key] = value.toString();
18
+ },
19
+ clear: function () {
20
+ store = {};
21
+ },
22
+ removeItem: function (key) {
23
+ delete store[key];
24
+ },
25
+ };
26
+ })();
27
+ Object.defineProperty(window, "localStorage", { value: localStorageMock });
28
+ });
29
+
30
+ afterEach(() => {
31
+ localStorage.setItem(
32
+ "CREATIVES_CDN_QUALITY_CONFIG",
33
+ '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}'
34
+ );
35
+ });
36
+
37
+ describe("cdnTransformationTests", () => {
38
+ describe("getCdnUrl()", () => {
39
+ it("should return s3 url if bucket subfolder doesn't contain intouch_creative_assets", () => {
40
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/test/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
41
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
42
+ url: TEST_S3_URL,
43
+ channelName: "EMAIL",
44
+ });
45
+ expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
46
+ });
47
+
48
+ it("should return s3 if channelName is not defined", () => {
49
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
50
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({ url: TEST_S3_URL });
51
+ expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
52
+ });
53
+
54
+ it("should return s3 if specified channelSubType doesn't exist", () => {
55
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
56
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
57
+ url: TEST_S3_URL,
58
+ channelName: "LINE",
59
+ channelSubType: "ABC",
60
+ });
61
+ expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
62
+ });
63
+
64
+ it("Should replace s3 url with cdn url for email when h/w are not provided", () => {
65
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
66
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
67
+ url: TEST_S3_URL,
68
+ channelName: "EMAIL",
69
+ });
70
+ const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/format=auto,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
71
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
72
+ });
73
+
74
+ it("Should replace s3 url with cdn url for email when h/w are provided", () => {
75
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
76
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
77
+ url: TEST_S3_URL,
78
+ channelName: "EMAIL",
79
+ height: 100,
80
+ width: 200,
81
+ });
82
+ const EXPECTED_CDN_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`;
83
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
84
+ });
85
+
86
+ it("should replace cdn url with new cdn url for email incase h/w etc changed", () => {
87
+ 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
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
89
+ url: TEST_S3_URL,
90
+ channelName: "EMAIL",
91
+ height: 400,
92
+ width: 500,
93
+ });
94
+ const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=500,height=400,format=auto,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
95
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
96
+ });
97
+
98
+ it("should replace cdn url with new cdn url incase channelName is LINE and channelSubType is RICH_MESSAGE ", () => {
99
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`;
100
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
101
+ url: TEST_S3_URL,
102
+ channelName: "LINE",
103
+ channelSubType: "RICH_MESSAGE",
104
+ });
105
+ const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=1040,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8`;
106
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
107
+ });
108
+
109
+ it("should replace cdn url with new cdn url for channels which has predefined h/w for channel", () => {
110
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
111
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
112
+ url: TEST_S3_URL,
113
+ channelName: "RCS",
114
+ });
115
+ const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=1440,height=720,quality=75,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
116
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
117
+ });
118
+
119
+ it("should return url directly if typeof CREATIVES_CDN_QUALITY_CONFIG is not object", () => {
120
+ localStorage.setItem("CREATIVES_CDN_QUALITY_CONFIG", "a");
121
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
122
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
123
+ url: TEST_S3_URL,
124
+ channelName: "EMAIL",
125
+ });
126
+ expect(GENERATED_CDN_URL).toEqual(TEST_S3_URL);
127
+ });
128
+
129
+ it("should return cdn url with full quality if quality is not number", () => {
130
+ localStorage.setItem(
131
+ "CREATIVES_CDN_QUALITY_CONFIG",
132
+ '{"EMAIL":"a","RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}'
133
+ );
134
+
135
+ const TEST_S3_URL = `https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
136
+ const GENERATED_CDN_URL = cdnUtils.getCdnUrl({
137
+ url: TEST_S3_URL,
138
+ channelName: "EMAIL",
139
+ height: 100,
140
+ width: 200,
141
+ });
142
+ const EXPECTED_CDN_URL = `https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=200,height=100,format=auto,quality=100,/intouch_creative_assets/2c9233ed-0959-4aff-b749-9171b5c8.jpg`;
143
+
144
+ expect(GENERATED_CDN_URL).toEqual(EXPECTED_CDN_URL);
145
+ });
146
+ });
147
+
148
+ describe("updateImagesInHtml()", () => {
149
+ it("should update images in html", () => {
150
+ const htmlContentsInput = mockdata.emailRawInput;
151
+ const htmlContentsOutput = cdnUtils.updateImagesInHtml(htmlContentsInput);
152
+ const expected = mockdata.emailRawTransformed;
153
+ expect(htmlContentsOutput).toEqual(expected);
154
+ });
155
+ });
156
+
157
+ describe("transformEmailTemplate()", () => {
158
+ it("should transform email template", () => {
159
+ const emailTemplateInput = mockdata.emailTemplateRaw;
160
+ const emailTemplateOutput =
161
+ cdnUtils.transformEmailTemplates(emailTemplateInput);
162
+ expect(emailTemplateOutput).toMatchSnapshot();
163
+ });
164
+ });
165
+
166
+ describe("saveCdnConfigs()", () => {
167
+ it("should set received input values in localStorage", () => {
168
+ const cdnConfigs = {
169
+ transformationUrlSuffix: "cdn-cgi/image",
170
+ hostname: "https://storage.crm.n.content-cdn.io",
171
+ qualityCfg: {
172
+ EMAIL: 75,
173
+ RCS: 75,
174
+ VIBER: 75,
175
+ WHATSAPP: 75,
176
+ MOBILE_PUSH: 75,
177
+ FACEBOOK: 75,
178
+ LINE: 75,
179
+ DEFAULT: 75,
180
+ },
181
+ };
182
+
183
+ const expected = {
184
+ CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX: "cdn-cgi/image",
185
+ CREATIVES_CDN_BASE_URL: "https://storage.crm.n.content-cdn.io",
186
+ CREATIVES_CDN_QUALITY_CONFIG:
187
+ '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}',
188
+ };
189
+ cdnUtils.saveCdnConfigs(cdnConfigs);
190
+
191
+ expect(
192
+ localStorage.getItem("CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX")
193
+ ).toBe(expected.CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX);
194
+ expect(localStorage.getItem("CREATIVES_CDN_BASE_URL")).toBe(
195
+ expected.CREATIVES_CDN_BASE_URL
196
+ );
197
+ expect(localStorage.getItem("CREATIVES_CDN_QUALITY_CONFIG")).toBe(
198
+ expected.CREATIVES_CDN_QUALITY_CONFIG
199
+ );
200
+ });
201
+
202
+ it("should clear items from localStorage if input does not contain hostname or transformationUrlSuffix", () => {
203
+ const cdnConfigs = {
204
+ qualityCfg: {
205
+ EMAIL: 75,
206
+ RCS: 75,
207
+ VIBER: 75,
208
+ WHATSAPP: 75,
209
+ MOBILE_PUSH: 75,
210
+ FACEBOOK: 75,
211
+ LINE: 75,
212
+ DEFAULT: 75,
213
+ },
214
+ };
215
+
216
+ const expected = {
217
+ CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX: "cdn-cgi/image",
218
+ CREATIVES_CDN_BASE_URL: "https://storage.crm.n.content-cdn.io",
219
+ CREATIVES_CDN_QUALITY_CONFIG:
220
+ '{"EMAIL":75,"RCS":75,"VIBER":75,"WHATSAPP":75,"MOBILE_PUSH":75,"FACEBOOK":75,"LINE":75,"DEFAULT":75}',
221
+ };
222
+ cdnUtils.saveCdnConfigs(cdnConfigs);
223
+
224
+ expect(
225
+ localStorage.getItem("CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX")
226
+ ).toBe(undefined);
227
+ expect(localStorage.getItem("CREATIVES_CDN_BASE_URL")).toBe(undefined);
228
+ expect(localStorage.getItem("CREATIVES_CDN_QUALITY_CONFIG")).toBe(
229
+ expected.CREATIVES_CDN_QUALITY_CONFIG
230
+ );
231
+ });
232
+
233
+ it("should clear items from localStorage if input is null or empty object", () => {
234
+ const cdnConfigs = {};
235
+
236
+ cdnUtils.saveCdnConfigs(cdnConfigs);
237
+
238
+ expect(
239
+ localStorage.getItem("CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX")
240
+ ).toBe(undefined);
241
+ expect(localStorage.getItem("CREATIVES_CDN_BASE_URL")).toBe(undefined);
242
+ expect(localStorage.getItem("CREATIVES_CDN_QUALITY_CONFIG")).toBe(undefined);
243
+ });
244
+ });
245
+ });
@@ -73,9 +73,3 @@ export function clearTopbarMenuData() {
73
73
  type: types.CLEAR_TOPBAR_MENU_DATA,
74
74
  };
75
75
  }
76
-
77
- export function getCdnTransformationConfig() {
78
- return {
79
- type: types.GET_CDN_TRANSFORMATION_CONFIG_REQUEST,
80
- }
81
- }
@@ -37,7 +37,3 @@ export const LOYALTY_HELP_URL = 'https://docs.capillarytech.com/docs/loyalty-ove
37
37
 
38
38
  export const ORG_REFRESH_SEC = 10;
39
39
  export const ORG_CHANGED = 'ORG_CHANGED';
40
-
41
- export const GET_CDN_TRANSFORMATION_CONFIG_REQUEST = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_REQUEST/V2';
42
- export const GET_CDN_TRANSFORMATION_CONFIG_SUCCESS = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_SUCCESS/V2';
43
- export const GET_CDN_TRANSFORMATION_CONFIG_FAILURE = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_FAILURE/V2';
@@ -119,7 +119,6 @@ export class Cap extends React.Component { // eslint-disable-line react/prefer-s
119
119
  );
120
120
  window.addEventListener('pageshow', this.tabOnloadEventHandler, false);
121
121
  window.addEventListener('pagehide', tabBeforeUnloadEventHandler, false);
122
- this.props.actions.getCdnTransformationConfig();
123
122
  }
124
123
 
125
124
  componentWillReceiveProps(nextProps) {
@@ -13,7 +13,6 @@ import {
13
13
  } from '../../v2Containers/App/constants';
14
14
  // import {makeSelectOrgId} from './selectors';
15
15
 
16
- import { saveCdnConfigs } from '../../utils/cdnTransformation';
17
16
 
18
17
  function* authorize(user) {
19
18
  try {
@@ -43,18 +42,6 @@ function* switchOrg({orgID}) {
43
42
  }
44
43
  }
45
44
 
46
- function* getCdnTransformationConfig() {
47
- try {
48
- const res = yield call(Api.getCdnTransformationConfig);
49
-
50
- if(res?.success && res?.status?.code === 200){
51
- const cdnConfigs = res?.response;
52
- saveCdnConfigs(cdnConfigs);
53
- }
54
- } catch (error) {
55
- console.log('some error occured during getCdnTransformationConfig call')
56
- }
57
- }
58
45
 
59
46
  function* loginFlow() {
60
47
  const condition = true;
@@ -191,10 +178,6 @@ function* watchGetTopbarMenuData() {
191
178
  }
192
179
 
193
180
 
194
- function* watchGetCdnTransformationConfig() {
195
- yield takeLatest(types.GET_CDN_TRANSFORMATION_CONFIG_REQUEST, getCdnTransformationConfig);
196
- }
197
-
198
181
  export default [
199
182
  loginFlow,
200
183
  watchForOrgChange,
@@ -202,6 +185,5 @@ export default [
202
185
  watchForFetchUserInfo,
203
186
  watchFetchSchemaForEntity,
204
187
  watchGetTopbarMenuData,
205
- watchGetCdnTransformationConfig,
206
188
  ];
207
189
 
@@ -41,7 +41,6 @@ exports[`<Cap /> should render correct component 1`] = `
41
41
  "clearMetaEntities": [Function],
42
42
  "clearTopbarMenuData": [Function],
43
43
  "fetchSchemaForEntity": [Function],
44
- "getCdnTransformationConfig": [Function],
45
44
  "getTopbarMenuData": [Function],
46
45
  "getUserData": [Function],
47
46
  "logout": [Function],
@@ -14,3 +14,9 @@ export function getTemplates({channel, query}) {
14
14
  query,
15
15
  };
16
16
  }
17
+
18
+ export function getCdnTransformationConfig() {
19
+ return {
20
+ type: types.GET_CDN_TRANSFORMATION_CONFIG_REQUEST,
21
+ }
22
+ }
@@ -8,3 +8,7 @@ export const DEFAULT_ACTION = 'app/TemplatesV2/DEFAULT_ACTION';
8
8
  export const GET_TEMPLATES_REQUEST = 'app/TemplatesV2/GET_TEMPLATES_REQUEST';
9
9
  export const GET_TEMPLATES_SUCESS = 'app/TemplatesV2/GET_TEMPLATES_SUCESS';
10
10
  export const GET_TEMPLATES_FAILURE = 'app/TemplatesV2/GET_TEMPLATES_FAILURE';
11
+
12
+ export const GET_CDN_TRANSFORMATION_CONFIG_REQUEST = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_REQUEST/V2';
13
+ export const GET_CDN_TRANSFORMATION_CONFIG_SUCCESS = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_SUCCESS/V2';
14
+ export const GET_CDN_TRANSFORMATION_CONFIG_FAILURE = 'creatives/GET_CDN_TRANSFORMATION_CONFIG_FAILURE/V2';
@@ -139,6 +139,7 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
139
139
  if (queryItems.channel === WHATSAPP) {
140
140
  this.channelChange(WHATSAPP);
141
141
  }
142
+ this.props.actions.getCdnTransformationConfig();
142
143
  }
143
144
 
144
145
  componentWillReceiveProps(nextProps) {
@@ -0,0 +1,27 @@
1
+ import { call, takeLatest } from "redux-saga/effects";
2
+ import * as Api from "../../services/api";
3
+ import * as types from "./constants";
4
+ import { saveCdnConfigs, removeAllCdnLocalStorageItems } from '../../utils/cdnTransformation';
5
+
6
+ function* getCdnTransformationConfig() {
7
+ try {
8
+ const res = yield call(Api.getCdnTransformationConfig);
9
+
10
+ if (res?.success && res?.status?.code === 200) {
11
+ const cdnConfigs = res?.response;
12
+ saveCdnConfigs(cdnConfigs);
13
+ }
14
+ } catch (error) {
15
+ console.log("some error occured during getCdnTransformationConfig call");
16
+ removeAllCdnLocalStorageItems();
17
+ }
18
+ }
19
+
20
+ function* watchGetCdnTransformationConfig() {
21
+ yield takeLatest(
22
+ types.GET_CDN_TRANSFORMATION_CONFIG_REQUEST,
23
+ getCdnTransformationConfig
24
+ );
25
+ }
26
+
27
+ export default [watchGetCdnTransformationConfig];