@capillarytech/creatives-library 8.0.77 → 8.0.78
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
package/services/api.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* Created by vivek on 3/5/17.
|
|
3
3
|
*/
|
|
4
4
|
import 'whatwg-fetch';
|
|
5
|
-
import { GA, decompressJsonObject } from '@capillarytech/cap-ui-utils';
|
|
6
|
-
import { get } from 'lodash';
|
|
7
5
|
import { loadItem, clearItem } from './localStorageApi';
|
|
8
6
|
import config from '../config/app';
|
|
9
7
|
import pathConfig from '../config/path';
|
|
10
8
|
import getSchema from './getSchema';
|
|
11
9
|
import * as API from '../utils/ApiCaller';
|
|
10
|
+
import { GA, decompressJsonObject } from '@capillarytech/cap-ui-utils';
|
|
12
11
|
import { addBaseToTemplate } from '../utils/commonUtils';
|
|
13
12
|
import { EMAIL, SMS } from '../v2Containers/CreativesContainer/constants';
|
|
14
13
|
let API_ENDPOINT = config.development.api_endpoint;
|
|
@@ -301,17 +300,15 @@ export const getAllAssets = ({assetType, queryParams = {}}) => {
|
|
|
301
300
|
});
|
|
302
301
|
// const url = `https://nightly.capillary.in/arya/api/v1/creatives/assets/${assetType}?query=${JSON.stringify(queryParams)}`;
|
|
303
302
|
return request(url, getAPICallObject('GET'));
|
|
304
|
-
}
|
|
305
|
-
|
|
303
|
+
}
|
|
304
|
+
;
|
|
306
305
|
export const deleteAssetById = ({assetId, assetType}) => {
|
|
307
306
|
const url = `${API_ENDPOINT}/assets/${assetId}/${assetType}`;
|
|
308
307
|
return request(url, getAPICallObject('DELETE'));
|
|
309
308
|
// return API.deleteResource(url);
|
|
310
309
|
};
|
|
311
310
|
|
|
312
|
-
export const uploadFile = ({
|
|
313
|
-
file, assetType, fileParams, mode, wechatParams, whatsappParams,
|
|
314
|
-
}) => {
|
|
311
|
+
export const uploadFile = ({file, assetType, fileParams, mode, wechatParams, whatsappParams}) => {
|
|
315
312
|
const data = new FormData();
|
|
316
313
|
let fileName = '';
|
|
317
314
|
try {
|
|
@@ -406,20 +403,14 @@ export const getCmsData = (cmsType, projectId, langId) => {
|
|
|
406
403
|
return API.get(url);
|
|
407
404
|
};
|
|
408
405
|
|
|
409
|
-
export const getEdmTemplates =
|
|
406
|
+
export const getEdmTemplates = () => {
|
|
410
407
|
const url = `${API_ENDPOINT}/templates/email/default`;
|
|
411
|
-
|
|
412
|
-
const response = get(compressedEdmTemplates, 'response', '');
|
|
413
|
-
const decompressedEdmTemplates = decompressJsonObject(response);
|
|
414
|
-
return { ...compressedEdmTemplates, response: addBaseToTemplate(decompressedEdmTemplates) };
|
|
408
|
+
return request(url, getAPICallObject('GET'));
|
|
415
409
|
};
|
|
416
410
|
|
|
417
|
-
export const getDefaultBeeTemplates =
|
|
411
|
+
export const getDefaultBeeTemplates = () => {
|
|
418
412
|
const url = `${API_ENDPOINT}/templates/v2/email/default`;
|
|
419
|
-
|
|
420
|
-
const response = get(compressedDefaultBeeTemplates, 'response', '');
|
|
421
|
-
const decompressedBeeTemplates = decompressJsonObject(response);
|
|
422
|
-
return { ...compressedDefaultBeeTemplates, response: addBaseToTemplate(decompressedBeeTemplates) };
|
|
413
|
+
return request(url, getAPICallObject('GET'));
|
|
423
414
|
};
|
|
424
415
|
|
|
425
416
|
// All about line
|
|
@@ -12,22 +12,17 @@ import {
|
|
|
12
12
|
askAiraForLiquid,
|
|
13
13
|
getLiquidTags,
|
|
14
14
|
fetchSchemaForEntity,
|
|
15
|
-
getDefaultBeeTemplates,
|
|
16
|
-
getEdmTemplates,
|
|
17
15
|
} from '../api';
|
|
18
16
|
import { mockData } from './mockData';
|
|
19
17
|
import getSchema from '../getSchema';
|
|
20
18
|
const sampleFile = require('../../assets/line.png');
|
|
21
19
|
|
|
22
20
|
let mockDecompressJsonObject;
|
|
23
|
-
let mockAddBaseToTemplate;
|
|
24
21
|
jest.mock('@capillarytech/cap-ui-utils', () => {
|
|
25
22
|
mockDecompressJsonObject = jest.fn();
|
|
26
|
-
mockAddBaseToTemplate = jest.fn();
|
|
27
23
|
return {
|
|
28
24
|
...jest.requireActual('@capillarytech/cap-ui-utils'),
|
|
29
25
|
decompressJsonObject: mockDecompressJsonObject,
|
|
30
|
-
addBaseToTemplate: mockAddBaseToTemplate,
|
|
31
26
|
};
|
|
32
27
|
});
|
|
33
28
|
|
|
@@ -141,7 +136,7 @@ describe('getAllTemplates -- Test with valid responses', () => {
|
|
|
141
136
|
global.fetch.mockReturnValue(Promise.resolve({json: () => Promise.resolve(),}));
|
|
142
137
|
mockDecompressJsonObject.mockReturnValue();
|
|
143
138
|
expect(await getAllTemplates({channel: 'email'})).toEqual({
|
|
144
|
-
response: undefined,
|
|
139
|
+
"response": undefined,
|
|
145
140
|
});
|
|
146
141
|
});
|
|
147
142
|
|
|
@@ -498,114 +493,3 @@ describe('fetchSchemaForEntity', () => {
|
|
|
498
493
|
expect(console.error).toHaveBeenCalledWith(mockError);
|
|
499
494
|
});
|
|
500
495
|
});
|
|
501
|
-
|
|
502
|
-
describe('Email Template APIs', () => {
|
|
503
|
-
beforeEach(() => {
|
|
504
|
-
global.fetch = jest.fn();
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
afterEach(() => {
|
|
508
|
-
jest.restoreAllMocks();
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
const sharedTests = (apiFunction, functionName) => {
|
|
512
|
-
it('should handle successful response', async () => {
|
|
513
|
-
const mockResponse = { response: 'compressed-data' };
|
|
514
|
-
const mockDecompressed = { template: 'decompressed-data' };
|
|
515
|
-
const mockWithBase = { template: 'data-with-base' };
|
|
516
|
-
|
|
517
|
-
global.fetch.mockReturnValue(Promise.resolve({
|
|
518
|
-
status: 200,
|
|
519
|
-
json: () => Promise.resolve(mockResponse),
|
|
520
|
-
}));
|
|
521
|
-
mockDecompressJsonObject.mockReturnValue(mockDecompressed);
|
|
522
|
-
mockAddBaseToTemplate.mockReturnValue(mockWithBase);
|
|
523
|
-
|
|
524
|
-
const result = await apiFunction();
|
|
525
|
-
expect(result).toEqual({
|
|
526
|
-
...mockResponse,
|
|
527
|
-
response: mockDecompressed,
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
it('should handle response property as empty object', async () => {
|
|
532
|
-
const mockResponse = { response: {} };
|
|
533
|
-
|
|
534
|
-
global.fetch.mockReturnValue(Promise.resolve({
|
|
535
|
-
status: 200,
|
|
536
|
-
json: () => Promise.resolve(mockResponse),
|
|
537
|
-
}));
|
|
538
|
-
mockDecompressJsonObject.mockReturnValue({});
|
|
539
|
-
mockAddBaseToTemplate.mockReturnValue({});
|
|
540
|
-
|
|
541
|
-
const result = await apiFunction();
|
|
542
|
-
expect(result).toEqual({
|
|
543
|
-
...mockResponse,
|
|
544
|
-
response: {},
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
it('should handle missing response property', async () => {
|
|
549
|
-
const mockResponse = {};
|
|
550
|
-
|
|
551
|
-
global.fetch.mockReturnValue(Promise.resolve({
|
|
552
|
-
status: 200,
|
|
553
|
-
json: () => Promise.resolve(mockResponse),
|
|
554
|
-
}));
|
|
555
|
-
mockDecompressJsonObject.mockReturnValue('');
|
|
556
|
-
mockAddBaseToTemplate.mockReturnValue('');
|
|
557
|
-
|
|
558
|
-
const result = await apiFunction();
|
|
559
|
-
expect(result).toEqual({
|
|
560
|
-
response: '',
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
it('should handle null response', async () => {
|
|
565
|
-
global.fetch.mockReturnValue(Promise.resolve({
|
|
566
|
-
json: () => Promise.resolve(null),
|
|
567
|
-
}));
|
|
568
|
-
mockDecompressJsonObject.mockReturnValue('');
|
|
569
|
-
mockAddBaseToTemplate.mockReturnValue('');
|
|
570
|
-
|
|
571
|
-
const result = await apiFunction();
|
|
572
|
-
expect(result).toEqual({
|
|
573
|
-
response: '',
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
it('should handle undefined response', async () => {
|
|
578
|
-
global.fetch.mockReturnValue(Promise.resolve({
|
|
579
|
-
json: () => Promise.resolve(undefined),
|
|
580
|
-
}));
|
|
581
|
-
mockDecompressJsonObject.mockReturnValue('');
|
|
582
|
-
mockAddBaseToTemplate.mockReturnValue('');
|
|
583
|
-
|
|
584
|
-
const result = await apiFunction();
|
|
585
|
-
expect(result).toEqual({
|
|
586
|
-
response: '',
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
it('should handle fetch failure', async () => {
|
|
591
|
-
global.fetch.mockRejectedValue(new Error('Network error'));
|
|
592
|
-
mockDecompressJsonObject.mockReturnValue(undefined);
|
|
593
|
-
mockAddBaseToTemplate.mockReturnValue(undefined);
|
|
594
|
-
console.error = jest.fn();
|
|
595
|
-
|
|
596
|
-
const result = await apiFunction();
|
|
597
|
-
|
|
598
|
-
expect(result).toEqual({
|
|
599
|
-
response: undefined,
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
describe('getEdmTemplates', () => {
|
|
605
|
-
sharedTests(getEdmTemplates, 'getEdmTemplates');
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
describe('getDefaultBeeTemplates', () => {
|
|
609
|
-
sharedTests(getDefaultBeeTemplates, 'getDefaultBeeTemplates');
|
|
610
|
-
});
|
|
611
|
-
});
|
package/utils/tagValidations.js
CHANGED
|
@@ -315,7 +315,7 @@ export const getTagMapValue = (object = {}) => {
|
|
|
315
315
|
return Object.values(
|
|
316
316
|
object
|
|
317
317
|
).reduce((acc, current) => {
|
|
318
|
-
return { ...acc
|
|
318
|
+
return { ...acc, ...current?.subtags ?? {} };
|
|
319
319
|
}, {});
|
|
320
320
|
};
|
|
321
321
|
|
|
@@ -498,6 +498,27 @@ describe("getTagMapValue", () => {
|
|
|
498
498
|
name: "233",
|
|
499
499
|
},
|
|
500
500
|
},
|
|
501
|
+
"key 2": {
|
|
502
|
+
name: "24",
|
|
503
|
+
subtags: {
|
|
504
|
+
tagName: "234",
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
const result = getTagMapValue(object);
|
|
509
|
+
expect(result).toEqual({ name: "233", tagName: "234", });
|
|
510
|
+
});
|
|
511
|
+
it("should return the tag map value when an object is provided but subtag is not present in one of the obj", () => {
|
|
512
|
+
const object = {
|
|
513
|
+
"key 1": {
|
|
514
|
+
name: "23",
|
|
515
|
+
subtags: {
|
|
516
|
+
name: "233",
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
"key 2": {
|
|
520
|
+
name: "24",
|
|
521
|
+
},
|
|
501
522
|
};
|
|
502
523
|
const result = getTagMapValue(object);
|
|
503
524
|
expect(result).toEqual({ name: "233" });
|
|
@@ -199,9 +199,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
199
199
|
this.setState({isDragDrop: true});
|
|
200
200
|
}
|
|
201
201
|
if (this.props.params.id) {
|
|
202
|
-
this.props.actions.getCmsSetting(BEE_PLUGIN,
|
|
202
|
+
this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'open', undefined, isBEESupport, isBEEAppEnable);
|
|
203
203
|
} else if (this.props.location.query.module !== "library" || (this.props.location.query.module === "library" && !this.props.templateData)) {
|
|
204
|
-
this.props.actions.getCmsSetting(BEE_PLUGIN,
|
|
204
|
+
this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'create', undefined, isBEESupport, isBEEAppEnable);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
this.setState({ content: (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''), formData});
|
|
@@ -227,6 +227,8 @@ export class EmailWrapper extends React.Component { // eslint-disable-line react
|
|
|
227
227
|
moduleType,
|
|
228
228
|
showLiquidErrorInFooter,
|
|
229
229
|
eventContextTags,
|
|
230
|
+
// Flag to enable loyalty module specific features in the email editor
|
|
231
|
+
isLoyaltyModule,
|
|
230
232
|
} = this.props;
|
|
231
233
|
const {
|
|
232
234
|
templateName,
|
|
@@ -300,6 +302,7 @@ export class EmailWrapper extends React.Component { // eslint-disable-line react
|
|
|
300
302
|
editor={editor}
|
|
301
303
|
moduleType={moduleType}
|
|
302
304
|
eventContextTags={eventContextTags}
|
|
305
|
+
isLoyaltyModule={isLoyaltyModule}
|
|
303
306
|
/>}
|
|
304
307
|
{!isShowEmailCreate && (
|
|
305
308
|
<CmsTemplatesComponent
|
|
@@ -346,6 +349,7 @@ EmailWrapper.propTypes = {
|
|
|
346
349
|
onEnterTemplateName: PropTypes.func,
|
|
347
350
|
onRemoveTemplateName: PropTypes.func,
|
|
348
351
|
eventContextTags: PropTypes.array,
|
|
352
|
+
isLoyaltyModule: PropTypes.bool,
|
|
349
353
|
};
|
|
350
354
|
|
|
351
355
|
const mapStateToProps = createStructuredSelector({
|