@capillarytech/creatives-library 7.12.120 → 7.13.5
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 +1 -2
- package/routes.js +0 -1
- package/services/api.js +1 -6
- package/v2Components/FormBuilder/index.js +13 -18
- package/v2Components/NewCallTask/index.js +1 -3
- package/v2Components/TemplatePreview/index.js +2 -1
- package/v2Containers/CallTask/index.js +2 -4
- package/v2Containers/Cap/actions.js +1 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -0
- package/v2Containers/CreativesContainer/actions.js +1 -1
- package/v2Containers/CreativesContainer/index.js +2 -6
- package/v2Containers/CreativesContainer/tests/index.test.js +0 -4
- package/v2Containers/Email/index.js +1 -4
- package/v2Containers/Facebook/Advertisement/index.js +4 -4
- package/v2Containers/Line/Container/Image/index.js +4 -5
- package/v2Containers/Line/Container/ImageCarousel/index.js +5 -6
- package/v2Containers/Line/Container/ImageMap/index.js +1 -2
- package/v2Containers/MobilePush/Create/index.js +8 -5
- package/v2Containers/MobilePush/Edit/index.js +4 -4
- package/v2Containers/MobilePush/initialSchema.js +0 -4
- package/v2Containers/MobilepushWrapper/index.js +1 -0
- package/v2Containers/Rcs/index.js +1 -2
- package/v2Containers/Templates/actions.js +0 -6
- package/v2Containers/Templates/constants.js +0 -4
- package/v2Containers/Templates/sagas.js +0 -25
- package/v2Containers/TemplatesV2/index.js +1 -5
- package/v2Containers/Viber/index.js +2 -11
- package/v2Containers/WeChat/RichmediaTemplates/Create/index.js +1 -3
- package/v2Containers/Whatsapp/index.js +2 -4
- package/utils/cdnTransformation.js +0 -419
- package/utils/tests/__snapshots__/cdnTransformation.test.js.snap +0 -298
- package/utils/tests/cdnTransformation.mockdata.js +0 -301
- package/utils/tests/cdnTransformation.test.js +0 -305
- package/v2Components/FormBuilder/tests/index.test.js +0 -41
- package/v2Components/FormBuilder/tests/mockData.js +0 -120
- package/v2Components/NewCallTask/tests/index.test.js +0 -36
- package/v2Components/NewCallTask/tests/mockData.js +0 -20
|
@@ -19,7 +19,6 @@ import { UserIsAuthenticated } from '../../utils/authWrapper';
|
|
|
19
19
|
import { makeSelectTemplates, makeSelectTemplatesResponse } from '../Templates/selectors';
|
|
20
20
|
import messages from './messages';
|
|
21
21
|
import * as actions from './actions';
|
|
22
|
-
import * as templateActions from '../Templates/actions';
|
|
23
22
|
import Templates from '../Templates';
|
|
24
23
|
import CallTask from '../CallTask';
|
|
25
24
|
import Facebook from '../Facebook';
|
|
@@ -140,9 +139,6 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
|
|
|
140
139
|
if (queryItems.channel === WHATSAPP) {
|
|
141
140
|
this.channelChange(WHATSAPP);
|
|
142
141
|
}
|
|
143
|
-
if(this.props?.isFullMode){
|
|
144
|
-
this.props.templateActions.getCdnTransformationConfig();
|
|
145
|
-
}
|
|
146
142
|
}
|
|
147
143
|
|
|
148
144
|
componentWillReceiveProps(nextProps) {
|
|
@@ -260,6 +256,7 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
|
|
|
260
256
|
handlePeviewTemplate={this.props.handlePeviewTemplate}
|
|
261
257
|
messageStrategy={this.props.messageStrategy}
|
|
262
258
|
smsRegister={smsRegister}
|
|
259
|
+
hideTestAndPreviewBtnJourney={this.props.hideTestAndPreviewBtnJourney}
|
|
263
260
|
/>);
|
|
264
261
|
}
|
|
265
262
|
}
|
|
@@ -354,7 +351,6 @@ const mapStateToProps = createStructuredSelector({
|
|
|
354
351
|
function mapDispatchToProps(dispatch) {
|
|
355
352
|
return {
|
|
356
353
|
actions: bindActionCreators(actions, dispatch),
|
|
357
|
-
templateActions: bindActionCreators(templateActions, dispatch),
|
|
358
354
|
};
|
|
359
355
|
}
|
|
360
356
|
|
|
@@ -53,12 +53,9 @@ import { GA } from '@capillarytech/cap-ui-utils';
|
|
|
53
53
|
import { CREATE, EDIT, TRACK_CREATE_VIBER, TRACK_EDIT_VIBER } from '../App/constants';
|
|
54
54
|
import { gtmPush } from '../../utils/gtmTrackers';
|
|
55
55
|
import { VIBER } from '../CreativesContainer/constants';
|
|
56
|
-
import { getCdnUrl } from '../../utils/cdnTransformation';
|
|
57
|
-
|
|
58
56
|
const { CapHeadingSpan } = CapHeading;
|
|
59
57
|
const { TextArea } = CapInput;
|
|
60
58
|
|
|
61
|
-
|
|
62
59
|
const Viber = (props) => {
|
|
63
60
|
const {
|
|
64
61
|
intl,
|
|
@@ -81,7 +78,7 @@ const Viber = (props) => {
|
|
|
81
78
|
const { formatMessage } = intl;
|
|
82
79
|
const [isImageError, updateImageErrorMessage] = useState(false);
|
|
83
80
|
const [isImage, updateImageStatus] = useState(false);
|
|
84
|
-
const [imageSrc,
|
|
81
|
+
const [imageSrc, updateImageSrc] = useState();
|
|
85
82
|
const [isDrawerRequired, updateDrawerRequirement] = useState(false);
|
|
86
83
|
const [messageContent, updateTextMessageContent] = useState('');
|
|
87
84
|
const [buttonText, updateButtonText] = useState('');
|
|
@@ -95,12 +92,6 @@ const Viber = (props) => {
|
|
|
95
92
|
const [buttonURLErrorMessage, updateButtonURLErrorMessage] = useState(false);
|
|
96
93
|
const [accountName, updateAccountName] = useState("");
|
|
97
94
|
|
|
98
|
-
|
|
99
|
-
const updateImageSrc = React.useCallback((url)=>{
|
|
100
|
-
const newUrl = getCdnUrl({url, channelName: 'VIBER'});
|
|
101
|
-
setImageSrc(newUrl);
|
|
102
|
-
},[]);
|
|
103
|
-
|
|
104
95
|
const StyledHeader = styled(CapHeader)`
|
|
105
96
|
margin-bottom: 14px;
|
|
106
97
|
`;
|
|
@@ -750,4 +741,4 @@ export default withCreatives({
|
|
|
750
741
|
mapStateToProps,
|
|
751
742
|
mapDispatchToProps,
|
|
752
743
|
userAuth: true,
|
|
753
|
-
});
|
|
744
|
+
});
|
|
@@ -32,8 +32,6 @@ import { GA } from '@capillarytech/cap-ui-utils';
|
|
|
32
32
|
import { CREATE, EDIT, TRACK_CREATE_WECHAT, TRACK_EDIT_WECHAT } from '../../../App/constants';
|
|
33
33
|
import { gtmPush } from '../../../../utils/gtmTrackers';
|
|
34
34
|
import { WECHAT } from '../../../CreativesContainer/constants';
|
|
35
|
-
import { getCdnUrl } from '../../../../utils/cdnTransformation';
|
|
36
|
-
|
|
37
35
|
export class Create extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
38
36
|
constructor(props) {
|
|
39
37
|
super(props);
|
|
@@ -480,7 +478,7 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
480
478
|
need_open_comment: postCommentsData.need_open_comment,
|
|
481
479
|
only_fans_can_comment: postCommentsData.only_fans_can_comment,
|
|
482
480
|
thumb_media_id: contentData.mediaId,
|
|
483
|
-
image_url:
|
|
481
|
+
image_url: contentData.imageUrl,
|
|
484
482
|
};
|
|
485
483
|
mediaList.push(filteredContent);
|
|
486
484
|
});
|
|
@@ -74,8 +74,6 @@ import {
|
|
|
74
74
|
PHONE_NUMBER,
|
|
75
75
|
WEBSITE,
|
|
76
76
|
} from '../../v2Components/CapWhatsappCTA/constants';
|
|
77
|
-
import { getCdnUrl } from '../../utils/cdnTransformation';
|
|
78
|
-
|
|
79
77
|
let varMap = {};
|
|
80
78
|
let editContent = {};
|
|
81
79
|
let tagValidationResponse = {};
|
|
@@ -857,7 +855,7 @@ export const Whatsapp = (props) => {
|
|
|
857
855
|
}),
|
|
858
856
|
mediaType: templateMediaType,
|
|
859
857
|
...(isMediaTypeImage && {
|
|
860
|
-
imageUrl:
|
|
858
|
+
imageUrl: whatsappImageSrc,
|
|
861
859
|
karixFileHandle,
|
|
862
860
|
}),
|
|
863
861
|
varMapped: !isFullMode ? varMap : {},
|
|
@@ -1441,4 +1439,4 @@ export default withCreatives({
|
|
|
1441
1439
|
mapStateToProps,
|
|
1442
1440
|
mapDispatchToProps,
|
|
1443
1441
|
userAuth: true,
|
|
1444
|
-
});
|
|
1442
|
+
});
|
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
-
import isEmpty from "lodash/isEmpty";
|
|
3
|
-
import forOwn from "lodash/forOwn";
|
|
4
|
-
import isNumber from "lodash/isNumber";
|
|
5
|
-
import Bugsnag from '@bugsnag/js';
|
|
6
|
-
|
|
7
|
-
/* eslint-disable no-unused-expressions */
|
|
8
|
-
import { parse } from "node-html-parser";
|
|
9
|
-
import { EMAIL } from '../v2Containers/CreativesContainer/constants';
|
|
10
|
-
|
|
11
|
-
// example cdn url
|
|
12
|
-
// https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=100,height=100,quality=75,format=auto/intouch_creative_assets/005710a7-6412-44fe-a19f-e72456b1.jpg
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* regex tests presence of intouch_creative_assets in the url.
|
|
16
|
-
* We are not testing for extensions such as jpg/png because some channels like LINE - IMAGEMAP url doesn't contain extension.
|
|
17
|
-
*/
|
|
18
|
-
const SPECIFIED = "specified";
|
|
19
|
-
const FORMAT_TYPES = { AUTO: "auto" };
|
|
20
|
-
const QUALITY_TYPE = {
|
|
21
|
-
DECREASE: "decrease",
|
|
22
|
-
PRESERVE: "preserve",
|
|
23
|
-
};
|
|
24
|
-
const CREATIVES_CDN_BASE_URL_KEY = 'CREATIVES_CDN_BASE_URL';
|
|
25
|
-
const CREATIVES_S3_BUCKET_PATH_KEY = 'CREATIVES_S3_BUCKET_PATH';
|
|
26
|
-
const CREATIVES_CDN_QUALITY_CONFIG_KEY = 'CREATIVES_CDN_QUALITY_CONFIG';
|
|
27
|
-
const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY = 'CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX';
|
|
28
|
-
|
|
29
|
-
const HTTPS_STR = "https://"
|
|
30
|
-
const ALLOWED_EXTENSIONS_STR = ".*(?:jpg|png|jpeg|gif)$"
|
|
31
|
-
const ANY_STR = ".*"
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* CHANNEL_CONFIGS maintains the transformation details for each channel (and optionally subchannel ex. FACEBOOK/LINE)
|
|
35
|
-
* In case of SUBCHANNELS, they are nested inside CHANNEL.
|
|
36
|
-
*/
|
|
37
|
-
const CHANNEL_CONFIGS = {
|
|
38
|
-
EMAIL: {
|
|
39
|
-
transformations: {
|
|
40
|
-
width: SPECIFIED,
|
|
41
|
-
height: SPECIFIED,
|
|
42
|
-
format: FORMAT_TYPES.AUTO,
|
|
43
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
RCS: {
|
|
47
|
-
transformations: {
|
|
48
|
-
width: 1440,
|
|
49
|
-
height: 720,
|
|
50
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
VIBER: {
|
|
54
|
-
transformations: {
|
|
55
|
-
width: 300,
|
|
56
|
-
height: 400,
|
|
57
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
WHATSAPP: {
|
|
61
|
-
transformations: {
|
|
62
|
-
quality: QUALITY_TYPE.DECREASE, //TODO whatsapp itself might reduce quality. To be checked
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
MOBILE_PUSH: {
|
|
66
|
-
transformations: {
|
|
67
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
FACEBOOK: {
|
|
71
|
-
IMAGE: {
|
|
72
|
-
transformations: {
|
|
73
|
-
width: 1080,
|
|
74
|
-
height: 1080,
|
|
75
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
LINE: {
|
|
80
|
-
IMAGE: {
|
|
81
|
-
transformations: {
|
|
82
|
-
width: 300,
|
|
83
|
-
height: 400,
|
|
84
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
CARD: {
|
|
88
|
-
transformations: {
|
|
89
|
-
width: 1024,
|
|
90
|
-
height: 1024,
|
|
91
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
RICH_MESSAGE: {
|
|
95
|
-
//Rich Message in Line has Square and Custom templates.
|
|
96
|
-
//Width (1040px) is same in both whereas height varies. Hence including width only.
|
|
97
|
-
transformations: {
|
|
98
|
-
width: 1040,
|
|
99
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
WECHAT: {
|
|
104
|
-
transformations: {
|
|
105
|
-
quality: QUALITY_TYPE.DECREASE,
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @param {string} url : required
|
|
113
|
-
* @param {number} height : optional | required when height needs to be manually specified for channels such as email.
|
|
114
|
-
* @param {number} width : optional | required when width needs to be manually specified for channels such as email.
|
|
115
|
-
* @param {string} channelName : required
|
|
116
|
-
* @param {string} channelSubType : optional | required when channel has multiple subtypes
|
|
117
|
-
*
|
|
118
|
-
* @returns
|
|
119
|
-
* getCdnUrl : utility function to replace and return s3/cdn url with cdn url.
|
|
120
|
-
* Step 1. Basic validations:
|
|
121
|
-
* a) If data type of cdn items stored in local storage is incorrect(maybe as a result of manual modification), the received url in param is returned.
|
|
122
|
-
* b) If cdn local storage items are emtpy then received url in param is returned.
|
|
123
|
-
* c) If url doesn't match with regex.
|
|
124
|
-
* d) Channel/Subchannel not present in CHANNEL_CONFIGS
|
|
125
|
-
* e) No quality and default quality mentioned in CHANNEL_CONFIGS for given channel.
|
|
126
|
-
* f) If channels quality is non numeric(maybe as a result of manual modification) then quality=100 is returned.
|
|
127
|
-
*
|
|
128
|
-
* Step 2. The CHANNEL_CONFIGS determine the applicableTransformations.
|
|
129
|
-
* Step 3. If applicable transformations are present `CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX` is appended to cdn url and transformation properties are added.
|
|
130
|
-
* Step 4. The original s3 file name is appened at the end of the url to get complete cdn url and value is returned.
|
|
131
|
-
*
|
|
132
|
-
* Error handling:
|
|
133
|
-
* In case of any unknown exception, url received in param is returned.
|
|
134
|
-
*/
|
|
135
|
-
export const getCdnUrl = ({
|
|
136
|
-
url,
|
|
137
|
-
height,
|
|
138
|
-
width,
|
|
139
|
-
channelName: receivedChannelName,
|
|
140
|
-
channelSubType: receivedChannelSubType,
|
|
141
|
-
}) => {
|
|
142
|
-
try{
|
|
143
|
-
const channelName = receivedChannelName?.toUpperCase();
|
|
144
|
-
const channelSubType = receivedChannelSubType?.toUpperCase();
|
|
145
|
-
|
|
146
|
-
const CREATIVES_CDN_BASE_URL = getLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
147
|
-
const CREATIVES_CDN_QUALITY_CONFIG = getLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY, true);
|
|
148
|
-
const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX = getLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
149
|
-
let CREATIVES_S3_BUCKET_PATH = getLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
150
|
-
|
|
151
|
-
//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.
|
|
152
|
-
CREATIVES_S3_BUCKET_PATH = CREATIVES_S3_BUCKET_PATH?.replace(/^\/|\/$/g, '');
|
|
153
|
-
|
|
154
|
-
//Basic validations on data stored in local storage.
|
|
155
|
-
if (
|
|
156
|
-
typeof CREATIVES_CDN_QUALITY_CONFIG !== "object" ||
|
|
157
|
-
Array.isArray(CREATIVES_CDN_QUALITY_CONFIG) ||
|
|
158
|
-
CREATIVES_CDN_QUALITY_CONFIG === null ||
|
|
159
|
-
typeof CREATIVES_CDN_BASE_URL !== "string" ||
|
|
160
|
-
typeof CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX !== "string" ||
|
|
161
|
-
typeof CREATIVES_S3_BUCKET_PATH !== 'string'
|
|
162
|
-
)
|
|
163
|
-
return url;
|
|
164
|
-
|
|
165
|
-
const QUALITY = CREATIVES_CDN_QUALITY_CONFIG?.[channelName] || CREATIVES_CDN_QUALITY_CONFIG?.DEFAULT;
|
|
166
|
-
|
|
167
|
-
const regexWithExtension = new RegExp(HTTPS_STR + ANY_STR + CREATIVES_S3_BUCKET_PATH + ANY_STR + ALLOWED_EXTENSIONS_STR)
|
|
168
|
-
const regexWithoutExtension = new RegExp(HTTPS_STR + ANY_STR + CREATIVES_S3_BUCKET_PATH + ANY_STR);
|
|
169
|
-
|
|
170
|
-
let skipTransformations = true;
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
!regexWithoutExtension.test(url) ||
|
|
174
|
-
!CHANNEL_CONFIGS?.[channelName] ||
|
|
175
|
-
(channelSubType && !CHANNEL_CONFIGS?.[channelName]?.[channelSubType]) ||
|
|
176
|
-
!CREATIVES_CDN_BASE_URL ||
|
|
177
|
-
!CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX ||
|
|
178
|
-
!QUALITY
|
|
179
|
-
)
|
|
180
|
-
return url;
|
|
181
|
-
|
|
182
|
-
//Skip transformations if extensions are not proper. Else consider transformations if available.
|
|
183
|
-
if(regexWithExtension.test(url)){
|
|
184
|
-
skipTransformations = false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const [, assetKey] = url.split(CREATIVES_S3_BUCKET_PATH);
|
|
188
|
-
|
|
189
|
-
let newUrl = `${CREATIVES_CDN_BASE_URL}`;
|
|
190
|
-
|
|
191
|
-
let applicableTransformations;
|
|
192
|
-
|
|
193
|
-
if (channelSubType) {
|
|
194
|
-
applicableTransformations =
|
|
195
|
-
CHANNEL_CONFIGS?.[channelName]?.[channelSubType]?.transformations;
|
|
196
|
-
} else {
|
|
197
|
-
applicableTransformations = CHANNEL_CONFIGS?.[channelName]?.transformations;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (!isEmpty(applicableTransformations) && !skipTransformations) {
|
|
201
|
-
|
|
202
|
-
newUrl += `/${CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX}/`;
|
|
203
|
-
|
|
204
|
-
// Object.keys(applicableTransformations)?.forEach((transformationParam) => {
|
|
205
|
-
forOwn(applicableTransformations, (transformationParamVal, transformationParam)=>{
|
|
206
|
-
try {
|
|
207
|
-
switch (transformationParam) {
|
|
208
|
-
case "height":
|
|
209
|
-
if (transformationParamVal === SPECIFIED && height) {
|
|
210
|
-
newUrl += `${transformationParam}=${height},`;
|
|
211
|
-
} else if(transformationParamVal !== SPECIFIED && isNumber(transformationParamVal)) {
|
|
212
|
-
newUrl += `${transformationParam}=${transformationParamVal},`;
|
|
213
|
-
}
|
|
214
|
-
break;
|
|
215
|
-
case "width":
|
|
216
|
-
if (transformationParamVal === SPECIFIED && width) {
|
|
217
|
-
newUrl += `${transformationParam}=${width},`;
|
|
218
|
-
} else if(transformationParamVal !== SPECIFIED && isNumber(transformationParamVal)) {
|
|
219
|
-
newUrl += `${transformationParam}=${transformationParamVal},`;
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
case "format":
|
|
223
|
-
if(transformationParamVal){
|
|
224
|
-
newUrl += `${transformationParam}=${transformationParamVal},`;
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
case "quality":
|
|
228
|
-
if (transformationParamVal === QUALITY_TYPE?.DECREASE && QUALITY && typeof QUALITY === "number") {
|
|
229
|
-
newUrl += `${transformationParam}=${QUALITY},`;
|
|
230
|
-
} else {
|
|
231
|
-
newUrl += `${transformationParam}=100,`;
|
|
232
|
-
}
|
|
233
|
-
break;
|
|
234
|
-
default:
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
} catch (e) {
|
|
238
|
-
Bugsnag.leaveBreadcrumb("some error occured while applying transformation")
|
|
239
|
-
Bugsnag.notify(e, (event) => {
|
|
240
|
-
event.severity = "error";
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
newUrl += `/${CREATIVES_S3_BUCKET_PATH}${assetKey}`;
|
|
246
|
-
return newUrl;
|
|
247
|
-
|
|
248
|
-
}catch(e){
|
|
249
|
-
Bugsnag.leaveBreadcrumb("Some exception occurred in getCdnUrl");
|
|
250
|
-
Bugsnag.notify(e, (event) => {
|
|
251
|
-
event.severity = "error";
|
|
252
|
-
});
|
|
253
|
-
return url;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
*
|
|
259
|
-
* @param {string} htmlContents accepts htmlContents - strigified.
|
|
260
|
-
* @returns htmlContents with updated urls in image tag
|
|
261
|
-
*/
|
|
262
|
-
export const updateImagesInHtml = (htmlContents) => {
|
|
263
|
-
if(!htmlContents || typeof htmlContents !== "string"){
|
|
264
|
-
return htmlContents;
|
|
265
|
-
}
|
|
266
|
-
const copiedHtmlContents = htmlContents;
|
|
267
|
-
try {
|
|
268
|
-
const root = parse(htmlContents);
|
|
269
|
-
root?.querySelectorAll("img")?.forEach((element) => {
|
|
270
|
-
const imageSrc = element.getAttribute("src");
|
|
271
|
-
const height = element.getAttribute("height");
|
|
272
|
-
const width = element.getAttribute("width");
|
|
273
|
-
const newUrl = getCdnUrl({
|
|
274
|
-
url: imageSrc,
|
|
275
|
-
height,
|
|
276
|
-
width,
|
|
277
|
-
channelName: EMAIL,
|
|
278
|
-
});
|
|
279
|
-
element.setAttribute("src", newUrl);
|
|
280
|
-
});
|
|
281
|
-
return root.toString();
|
|
282
|
-
} catch (e) {
|
|
283
|
-
Bugsnag.leaveBreadcrumb("An error occured while updating images in html")
|
|
284
|
-
Bugsnag.notify(e, (event) => {
|
|
285
|
-
event.severity = "error";
|
|
286
|
-
});
|
|
287
|
-
return copiedHtmlContents; //return received input directly in case an exception is thrown
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
*
|
|
293
|
-
* @param {*} contents
|
|
294
|
-
* @returns
|
|
295
|
-
* Transforms the email template's html by images replacing the s3 url / cdn url with cdn url.
|
|
296
|
-
*/
|
|
297
|
-
export const transformEmailTemplates = (contents) => {
|
|
298
|
-
const contentsCopy = cloneDeep(contents);
|
|
299
|
-
try {
|
|
300
|
-
const base = contentsCopy?.versions?.base;
|
|
301
|
-
const languages = base?.selectedLanguages;
|
|
302
|
-
languages?.forEach((lang) => {
|
|
303
|
-
const htmlContents = base?.[lang]?.["template-content"];
|
|
304
|
-
const newHtmlContents = updateImagesInHtml(htmlContents);
|
|
305
|
-
base[lang]["template-content"] = newHtmlContents;
|
|
306
|
-
});
|
|
307
|
-
return contentsCopy;
|
|
308
|
-
} catch (e) {
|
|
309
|
-
Bugsnag.leaveBreadcrumb(
|
|
310
|
-
"Some error has occured while transforming email templates"
|
|
311
|
-
);
|
|
312
|
-
Bugsnag.notify(e, (event) => {
|
|
313
|
-
event.severity = "error";
|
|
314
|
-
});
|
|
315
|
-
return contents; //return received input directly in case an exception is thrown
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
*
|
|
322
|
-
* @param {*} key
|
|
323
|
-
* @param {*} parse
|
|
324
|
-
* @returns Localstorage item with mentioned key. Parses the value if second param `parse` is true.
|
|
325
|
-
*/
|
|
326
|
-
export function getLocalStorageItem(key, parse = false){
|
|
327
|
-
const val = localStorage.getItem(key);
|
|
328
|
-
if(parse){
|
|
329
|
-
return JSON.parse(val);
|
|
330
|
-
}
|
|
331
|
-
return val;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Removes specified key from local storage.
|
|
336
|
-
*/
|
|
337
|
-
export function removeLocalStorageItem(key) {
|
|
338
|
-
localStorage.removeItem(key);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Util function. Removes all cdn related local storage items.
|
|
344
|
-
*/
|
|
345
|
-
export function removeAllCdnLocalStorageItems() {
|
|
346
|
-
try{
|
|
347
|
-
removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
348
|
-
removeLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY);
|
|
349
|
-
removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
350
|
-
removeLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
351
|
-
}catch(e){
|
|
352
|
-
Bugsnag.leaveBreadcrumb("some error occured while deleting all keys for cdn");
|
|
353
|
-
Bugsnag.notify(e, (event) => {
|
|
354
|
-
event.severity = "error";
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
*
|
|
361
|
-
* @param {*} configsResponse
|
|
362
|
-
* This util function saves the getCdnConfigs response into the local storage.
|
|
363
|
-
* The following response items are mapped into the following keys in local storage:
|
|
364
|
-
* hostname -> CREATIVES_CDN_BASE_URL
|
|
365
|
-
* qualityCfg ->CREATIVES_CDN_QUALITY_CONFIG
|
|
366
|
-
* transformationUrlSuffix -> CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX
|
|
367
|
-
*
|
|
368
|
-
* 1. If configsReponse is empty. All above mentioned keys are deleted from localstorage.
|
|
369
|
-
* 2. If any one of the above keys is missing. The respective keys are deleted from localstorage.
|
|
370
|
-
* 3. Else it is saved into the localstorage.
|
|
371
|
-
*/
|
|
372
|
-
export function saveCdnConfigs(configsResponse) {
|
|
373
|
-
try {
|
|
374
|
-
//If no response from api, then remove localStorage items if they were set previously
|
|
375
|
-
if (isEmpty(configsResponse)) {
|
|
376
|
-
removeAllCdnLocalStorageItems();
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (configsResponse?.hostname) {
|
|
381
|
-
localStorage.setItem(
|
|
382
|
-
CREATIVES_CDN_BASE_URL_KEY,
|
|
383
|
-
configsResponse?.hostname
|
|
384
|
-
);
|
|
385
|
-
} else {
|
|
386
|
-
removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (configsResponse?.bucketPath) {
|
|
390
|
-
localStorage.setItem(
|
|
391
|
-
CREATIVES_S3_BUCKET_PATH_KEY,
|
|
392
|
-
configsResponse?.bucketPath
|
|
393
|
-
);
|
|
394
|
-
} else {
|
|
395
|
-
removeLocalStorageItem(CREATIVES_S3_BUCKET_PATH_KEY);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (!isEmpty(configsResponse?.qualityCfg)) {
|
|
399
|
-
const qualityString = JSON.stringify(configsResponse?.qualityCfg);
|
|
400
|
-
localStorage.setItem(CREATIVES_CDN_QUALITY_CONFIG_KEY, qualityString);
|
|
401
|
-
} else {
|
|
402
|
-
removeLocalStorageItem(CREATIVES_CDN_QUALITY_CONFIG_KEY);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (configsResponse?.transformationUrlSuffix) {
|
|
406
|
-
localStorage.setItem(
|
|
407
|
-
CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY,
|
|
408
|
-
configsResponse?.transformationUrlSuffix
|
|
409
|
-
);
|
|
410
|
-
} else {
|
|
411
|
-
removeLocalStorageItem(CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY);
|
|
412
|
-
}
|
|
413
|
-
} catch (e) {
|
|
414
|
-
Bugsnag.leaveBreadcrumb("some error while setting localstorage cdn configs");
|
|
415
|
-
Bugsnag.notify(e, (event) => {
|
|
416
|
-
event.severity = "error";
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
}
|