@capillarytech/creatives-library 7.13.32-alpha.1 → 7.13.32
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 +1 -2
- package/package.json +1 -1
- package/services/api.js +0 -5
- package/utils/cdnTransformation.js +21 -93
- package/v2Containers/CreativesContainer/index.js +4 -9
- package/v2Containers/Email/actions.js +0 -8
- package/v2Containers/Email/constants.js +0 -1
- package/v2Containers/Email/index.js +2 -4
- package/v2Containers/Email/reducer.js +0 -2
- package/v2Containers/Email/sagas.js +1 -18
- package/v2Containers/SmsTrai/Create/selectors.js +1 -1
package/config/app.js
CHANGED
|
@@ -16,8 +16,7 @@ const config = {
|
|
|
16
16
|
accountConfig: (strs, accountId) => `${window.location.origin}/org/config/AccountAdd?q=a&channelId=2&accountId=${accountId}&edit=1`,
|
|
17
17
|
},
|
|
18
18
|
development: {
|
|
19
|
-
api_endpoint: '
|
|
20
|
-
// api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/creatives',
|
|
19
|
+
api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/creatives',
|
|
21
20
|
campaigns_api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/campaigns',
|
|
22
21
|
campaigns_api_org_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/org/campaign',
|
|
23
22
|
auth_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/auth',
|
package/package.json
CHANGED
package/services/api.js
CHANGED
|
@@ -489,9 +489,4 @@ export const getSenderDetails = (channel, orgUnitId) => {
|
|
|
489
489
|
export const getCdnTransformationConfig = () => {
|
|
490
490
|
const url = `${API_ENDPOINT}/common/getCdnTransformationConfig`;
|
|
491
491
|
return request(url, getAPICallObject('GET'));
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export const getS3UrlFileSizes = (data) => {
|
|
495
|
-
const url = `${API_ENDPOINT}/assets/files/metadata`;
|
|
496
|
-
return request(url, getAPICallObject('POST', data));
|
|
497
492
|
}
|
|
@@ -3,7 +3,7 @@ import isEmpty from "lodash/isEmpty";
|
|
|
3
3
|
import forOwn from "lodash/forOwn";
|
|
4
4
|
import isNumber from "lodash/isNumber";
|
|
5
5
|
import Bugsnag from '@bugsnag/js';
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
/* eslint-disable no-unused-expressions */
|
|
8
8
|
import { parse } from "node-html-parser";
|
|
9
9
|
import { EMAIL } from '../v2Containers/CreativesContainer/constants';
|
|
@@ -266,21 +266,16 @@ export const getCdnUrl = ({
|
|
|
266
266
|
/**
|
|
267
267
|
*
|
|
268
268
|
* @param {string} htmlContents accepts htmlContents - strigified.
|
|
269
|
-
* @returns
|
|
269
|
+
* @returns htmlContents with updated urls in image tag
|
|
270
270
|
*/
|
|
271
|
-
export const updateImagesInHtml =
|
|
271
|
+
export const updateImagesInHtml = (htmlContents) => {
|
|
272
272
|
if(!htmlContents || typeof htmlContents !== "string"){
|
|
273
273
|
return htmlContents;
|
|
274
274
|
}
|
|
275
275
|
const copiedHtmlContents = htmlContents;
|
|
276
276
|
try {
|
|
277
277
|
const root = parse(htmlContents);
|
|
278
|
-
const isEmailQualityOverridden = getLocalStorageItem(CREATIVES_CDN_OVERRIDE_DEFAULT_EMAIL_QUALITY_KEY)
|
|
279
|
-
let urlQualityMappings;
|
|
280
|
-
if(isEmailQualityOverridden){
|
|
281
|
-
const urlList = root?.querySelectorAll("img")?.map(element=>element.getAttribute("src"));
|
|
282
|
-
urlQualityMappings = await getUrlsToQualityMapping(urlList);
|
|
283
|
-
}
|
|
278
|
+
const isEmailQualityOverridden = getLocalStorageItem(CREATIVES_CDN_OVERRIDE_DEFAULT_EMAIL_QUALITY_KEY)
|
|
284
279
|
root?.querySelectorAll("img")?.forEach((element) => {
|
|
285
280
|
const imageSrc = element.getAttribute("src");
|
|
286
281
|
const height = element.getAttribute("height");
|
|
@@ -288,8 +283,8 @@ export const updateImagesInHtml = async (htmlContents) => {
|
|
|
288
283
|
|
|
289
284
|
let emailOverrideQuality = null;
|
|
290
285
|
if (isEmailQualityOverridden) {
|
|
291
|
-
const tempQuality =
|
|
292
|
-
if (tempQuality
|
|
286
|
+
const tempQuality = overrideEmailQuality(imageSrc);
|
|
287
|
+
if (tempQuality !== -1) {
|
|
293
288
|
emailOverrideQuality = tempQuality;
|
|
294
289
|
}
|
|
295
290
|
}
|
|
@@ -319,21 +314,17 @@ export const updateImagesInHtml = async (htmlContents) => {
|
|
|
319
314
|
* @returns
|
|
320
315
|
* Transforms the email template's html by images replacing the s3 url / cdn url with cdn url.
|
|
321
316
|
*/
|
|
322
|
-
export
|
|
317
|
+
export const transformEmailTemplates = (contents) => {
|
|
323
318
|
const contentsCopy = cloneDeep(contents);
|
|
324
319
|
try {
|
|
325
320
|
const base = contentsCopy?.versions?.base;
|
|
326
321
|
const languages = base?.selectedLanguages;
|
|
327
|
-
let promises = [];
|
|
328
322
|
languages?.forEach((lang) => {
|
|
329
323
|
const htmlContents = base?.[lang]?.["template-content"];
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
base[lang]["template-content"] = newHtmlContents;
|
|
333
|
-
})
|
|
334
|
-
)
|
|
324
|
+
const newHtmlContents = updateImagesInHtml(htmlContents);
|
|
325
|
+
base[lang]["template-content"] = newHtmlContents;
|
|
335
326
|
});
|
|
336
|
-
return
|
|
327
|
+
return contentsCopy;
|
|
337
328
|
} catch (e) {
|
|
338
329
|
Bugsnag.leaveBreadcrumb(
|
|
339
330
|
"Some error has occured while transforming email templates"
|
|
@@ -517,12 +508,11 @@ export function checkValidUrl(url){
|
|
|
517
508
|
|
|
518
509
|
const isValidUrl = regexWithExtension.test(url);
|
|
519
510
|
const isCdnUrl = url.includes(CREATIVES_CDN_BASE_URL);
|
|
520
|
-
|
|
511
|
+
|
|
521
512
|
|
|
522
513
|
return {
|
|
523
514
|
isValidUrl,
|
|
524
515
|
isCdnUrl,
|
|
525
|
-
isS3Url,
|
|
526
516
|
}
|
|
527
517
|
}
|
|
528
518
|
|
|
@@ -558,24 +548,23 @@ export function getCdnEmailImageQuality(url) {
|
|
|
558
548
|
* 1. If it is s3 url, it returns quality inversly proportional to its filesize.
|
|
559
549
|
* 2. If it is cdn url, it extracts quality from url and returns the same.
|
|
560
550
|
*/
|
|
561
|
-
export function
|
|
551
|
+
export function overrideEmailQuality(url){
|
|
562
552
|
if(!url || typeof url !== "string") return -1;
|
|
563
553
|
|
|
554
|
+
const {isValidUrl, isCdnUrl} = checkValidUrl(url);
|
|
555
|
+
|
|
556
|
+
if(!isValidUrl) return -1;
|
|
557
|
+
|
|
558
|
+
if(isCdnUrl){
|
|
559
|
+
return getCdnEmailImageQuality(url);
|
|
560
|
+
}
|
|
561
|
+
|
|
564
562
|
const fileSize = getFizeSizeFromUrl(url);
|
|
565
563
|
|
|
566
|
-
if(!fileSize) return;
|
|
564
|
+
if(!fileSize) return -1;
|
|
567
565
|
|
|
568
566
|
return getEmailImageOverrideQuality(fileSize);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
export function getS3EmailImageQualityMapping(urlToFileSizeMapping){
|
|
572
|
-
if(typeof urlToFileSizeMapping !== "object" || !urlToFileSizeMapping) return {};
|
|
573
567
|
|
|
574
|
-
const urlToImageQualityMapping = {};
|
|
575
|
-
for (let url of Object.keys(urlToFileSizeMapping)) {
|
|
576
|
-
urlToImageQualityMapping[url] = getEmailImageOverrideQuality(urlToFileSizeMapping[url]);
|
|
577
|
-
}
|
|
578
|
-
return urlToImageQualityMapping;
|
|
579
568
|
}
|
|
580
569
|
|
|
581
570
|
/**
|
|
@@ -626,65 +615,4 @@ export function getEmailImageOverrideQuality(fileSize) {
|
|
|
626
615
|
} catch (e) {
|
|
627
616
|
return -1;
|
|
628
617
|
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
*
|
|
633
|
-
* @param {array} urlList ex ['1.jpg','2.jpg'] // these can be any urls (s3, cdn or others)
|
|
634
|
-
*
|
|
635
|
-
*/
|
|
636
|
-
export async function getUrlsToQualityMapping(urlList){
|
|
637
|
-
if(!urlList?.length) return {};
|
|
638
|
-
|
|
639
|
-
const urlQualityMapping = {};
|
|
640
|
-
|
|
641
|
-
const nonSelectedS3Urls = []; //we do not know file sizes of these s3 urls yet.
|
|
642
|
-
|
|
643
|
-
urlList?.forEach(url=>{
|
|
644
|
-
const {isS3Url, isCdnUrl} = checkValidUrl(url);
|
|
645
|
-
|
|
646
|
-
if (isCdnUrl){
|
|
647
|
-
urlQualityMapping[url] = getCdnEmailImageQuality(url);
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
if(isS3Url){
|
|
651
|
-
const s3FileQuality = getS3EmailImageQuality(url);
|
|
652
|
-
if(s3FileQuality){
|
|
653
|
-
urlQualityMapping[url] = s3FileQuality;
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
if(!s3FileQuality){
|
|
657
|
-
nonSelectedS3Urls.push(url)
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
if(nonSelectedS3Urls?.length){
|
|
663
|
-
let nonSelectedS3UrlMapping = await getS3FileSizesFromUrl(nonSelectedS3Urls)
|
|
664
|
-
const nonSelectedS3UrlQualityMapping = getS3EmailImageQualityMapping(nonSelectedS3UrlMapping)
|
|
665
|
-
let x = {...urlQualityMapping,...nonSelectedS3UrlQualityMapping};
|
|
666
|
-
return x;
|
|
667
|
-
}
|
|
668
|
-
return urlQualityMapping;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
export async function getS3FileSizesFromUrl(urlList) {
|
|
672
|
-
if(!urlList?.length){
|
|
673
|
-
return {}
|
|
674
|
-
}
|
|
675
|
-
try{
|
|
676
|
-
let data = await Api.getS3UrlFileSizes({ keys: urlList });
|
|
677
|
-
if (data?.status?.code === 200 && data?.success && data?.response) {
|
|
678
|
-
const result = data?.response;
|
|
679
|
-
const urlMapping = {};
|
|
680
|
-
for (let url of Object.keys(result)) {
|
|
681
|
-
urlMapping[url] = result[url];
|
|
682
|
-
}
|
|
683
|
-
return urlMapping;
|
|
684
|
-
} else {
|
|
685
|
-
return {};
|
|
686
|
-
}
|
|
687
|
-
}catch(e){
|
|
688
|
-
return {};
|
|
689
|
-
}
|
|
690
618
|
}
|
|
@@ -460,7 +460,7 @@ export class Creatives extends React.Component {
|
|
|
460
460
|
return templateData || null;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
getCreativesData =
|
|
463
|
+
getCreativesData = (channel, template, templateRecords) => { //from creatives to consumers
|
|
464
464
|
let templateData = { channel };
|
|
465
465
|
switch (channel) {
|
|
466
466
|
case constants.SMS:
|
|
@@ -499,7 +499,7 @@ export class Creatives extends React.Component {
|
|
|
499
499
|
if (!html_content) {
|
|
500
500
|
emailBase = templateRecords.base;
|
|
501
501
|
}
|
|
502
|
-
const newHtmlContent =
|
|
502
|
+
const newHtmlContent = updateImagesInHtml(html_content);
|
|
503
503
|
templateData = {...templateData, ...emailBase, emailBody: newHtmlContent, emailSubject: (emailBase && emailBase.subject) ? emailBase.subject : ''};
|
|
504
504
|
delete templateData.html_content;
|
|
505
505
|
delete templateData.subject;
|
|
@@ -821,16 +821,11 @@ export class Creatives extends React.Component {
|
|
|
821
821
|
isGetFormData: false,
|
|
822
822
|
},
|
|
823
823
|
() => {
|
|
824
|
-
console.log("hello getFormData")
|
|
825
824
|
const templateData = this.state.templateData ? this.state.templateData : template; //select existing or create new content
|
|
826
825
|
const channel = templateData.type;
|
|
827
|
-
// this.props.actions.showCreativesContainerLoader();
|
|
828
826
|
const creativesData = this.getCreativesData(channel, template, templateData );// convers data to consumer understandable format
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
this.props.getCreativesData(data);// send data to consumer
|
|
832
|
-
// this.props.actions.hideCreativesContanerLoader();
|
|
833
|
-
})
|
|
827
|
+
this.logGTMEvent(channel, creativesData);
|
|
828
|
+
this.props.getCreativesData(creativesData);// send data to consumer
|
|
834
829
|
},
|
|
835
830
|
);
|
|
836
831
|
}
|
|
@@ -36,4 +36,3 @@ export const DUPLICATE_TEMPLATE_REQUEST = 'app/v2Containers/Email/DUPLICATE_TEMP
|
|
|
36
36
|
export const DUPLICATE_TEMPLATE_SUCCESS = 'app/v2Containers/Email/DUPLICATE_TEMPLATE_SUCCESS';
|
|
37
37
|
export const DUPLICATE_TEMPLATE_FAILURE = 'app/v2Containers/Email/DUPLICATE_TEMPLATE_FAILURE';
|
|
38
38
|
|
|
39
|
-
export const TRANSFORM_EMAIL_TEMPLATE_REQUEST = 'app/v2Containers/Email/TRANSFORM_EMAIL_TEMPLATE_REQUEST';
|
|
@@ -2403,10 +2403,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2403
2403
|
|
|
2404
2404
|
// if (saveCount === 0) {
|
|
2405
2405
|
|
|
2406
|
-
|
|
2407
|
-
this.props.actions.
|
|
2408
|
-
this.props.actions.createTemplate(newEmail, this.onUpdateTemplateComplete);
|
|
2409
|
-
});
|
|
2406
|
+
const newEmail = transformEmailTemplates(obj);
|
|
2407
|
+
this.props.actions.createTemplate(newEmail, this.onUpdateTemplateComplete);
|
|
2410
2408
|
// } else {
|
|
2411
2409
|
// this.setState({saveObj: obj, targetSaveCount: saveCount, mode: "save", saveEdmDataMode: 'save'}, () => {
|
|
2412
2410
|
// _.forEach(data.selectedLanguages, (language, langIndex) => {
|
|
@@ -140,8 +140,6 @@ function emailReducer(state = initialState, action) {
|
|
|
140
140
|
.set('fetchingCmsData', false)
|
|
141
141
|
.set('duplicateResponse', fromJS({}))
|
|
142
142
|
.set('cmsData', '');
|
|
143
|
-
case types.TRANSFORM_EMAIL_TEMPLATE_REQUEST:
|
|
144
|
-
return state.set("createTemplateInProgress", true);
|
|
145
143
|
default:
|
|
146
144
|
return state;
|
|
147
145
|
}
|
|
@@ -2,7 +2,7 @@ import { take, cancel, call, put, takeLatest, takeEvery } from 'redux-saga/effec
|
|
|
2
2
|
import { LOCATION_CHANGE } from 'react-router-redux';
|
|
3
3
|
import * as Api from '../../services/api';
|
|
4
4
|
import * as types from './constants';
|
|
5
|
-
import {
|
|
5
|
+
import { storeS3FileSizeDetails } from '../../utils/cdnTransformation';
|
|
6
6
|
|
|
7
7
|
export function* createTemplate(template) {
|
|
8
8
|
let errorMsg;
|
|
@@ -20,15 +20,6 @@ export function* createTemplate(template) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function* transformEmailTemplate({template, callback}) {
|
|
24
|
-
try {
|
|
25
|
-
const result = yield call(transformEmailTemplates, template);
|
|
26
|
-
yield callback(result);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
yield callback(template);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
23
|
export function* duplicateTemplate(id, channel) {
|
|
33
24
|
let errorMsg;
|
|
34
25
|
try {
|
|
@@ -98,13 +89,6 @@ function* watchCreateTemplate() {
|
|
|
98
89
|
yield cancel(watcher);
|
|
99
90
|
}
|
|
100
91
|
|
|
101
|
-
function* watchTransformEmailTemplate() {
|
|
102
|
-
const watcher = yield takeLatest(types.TRANSFORM_EMAIL_TEMPLATE_REQUEST, transformEmailTemplate);
|
|
103
|
-
yield take(LOCATION_CHANGE);
|
|
104
|
-
yield cancel(watcher);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
92
|
function* watchGetTemplateDetails() {
|
|
109
93
|
const watcher = yield takeLatest(types.GET_TEMPLATE_DETAILS_REQUEST, getTemplateDetails);
|
|
110
94
|
yield take(LOCATION_CHANGE);
|
|
@@ -144,7 +128,6 @@ function* watchDuplicateTemplate() {
|
|
|
144
128
|
// All sagas to be loaded
|
|
145
129
|
export default [
|
|
146
130
|
watchCreateTemplate,
|
|
147
|
-
watchTransformEmailTemplate,
|
|
148
131
|
watchGetTemplateDetails,
|
|
149
132
|
watchGetAllAssets,
|
|
150
133
|
watchGetCmsSetting,
|