@capillarytech/creatives-library 7.12.109 → 7.12.110

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.109",
4
+ "version": "7.12.110",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -5,9 +5,13 @@ import isNumber from "lodash/isNumber";
5
5
  /* eslint-disable no-unused-expressions */
6
6
  import { parse } from "node-html-parser";
7
7
 
8
- // https://storage.crm.n.content-cdn.io/cdn-cgi/image/width=100,height=100,quality=75,fit=cover,g=top,format=auto/intouch_creative_assets/005710a7-6412-44fe-a19f-e72456b1.jpg
8
+ // example cdn url
9
+ // 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
9
10
 
10
- // const regex = /https:\/\/.*intouch_creative_assets.*(?:jpg|png|jpeg|gif)$/;
11
+ /**
12
+ * regex tests presence of intouch_creative_assets in the url.
13
+ * We are not testing for extensions such as jpg/png because some channels like LINE - IMAGEMAP url doesn't contain extension.
14
+ */
11
15
  const regex = /https:\/\/.*intouch_creative_assets.*$/;
12
16
  const INTOUCH_CREATIVE_ASSETS = "intouch_creative_assets";
13
17
  const SPECIFIED = "specified";
@@ -16,7 +20,15 @@ const QUALITY_TYPE = {
16
20
  DECREASE: "decrease",
17
21
  PRESERVE: "preserve",
18
22
  };
23
+ const CREATIVES_CDN_BASE_URL_KEY = 'CREATIVES_CDN_BASE_URL';
24
+ const CREATIVES_CDN_QUALITY_CONFIG_KEY = 'CREATIVES_CDN_QUALITY_CONFIG';
25
+ const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY = 'CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX';
19
26
 
27
+
28
+ /**
29
+ * CHANNEL_CONFIGS maintains the transformation details for each channel (and optionally subchannel ex. FACEBOOK/LINE)
30
+ * In case of SUBCHANNELS, they are nested inside CHANNEL.
31
+ */
20
32
  const CHANNEL_CONFIGS = {
21
33
  EMAIL: {
22
34
  transformations: {
@@ -85,19 +97,35 @@ const CHANNEL_CONFIGS = {
85
97
  },
86
98
  WECHAT: {
87
99
  transformations: {
88
- width: 360,
89
- height: 200,
90
100
  quality: QUALITY_TYPE.DECREASE,
91
-
92
101
  }
93
102
  }
94
103
  };
95
104
 
96
- const CREATIVES_CDN_BASE_URL_KEY = 'CREATIVES_CDN_BASE_URL';
97
- const CREATIVES_CDN_QUALITY_CONFIG_KEY = 'CREATIVES_CDN_QUALITY_CONFIG';
98
- const CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX_KEY = 'CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX';
99
105
  /**
106
+ *
107
+ * @param {string} url : required
108
+ * @param {number} height : optional | required when height needs to be manually specified for channels such as email.
109
+ * @param {number} width : optional | required when width needs to be manually specified for channels such as email.
110
+ * @param {string} channelName : required
111
+ * @param {string} channelSubType : optional | required when channel has multiple subtypes
112
+ *
113
+ * @returns
100
114
  * getCdnUrl : utility function to replace and return s3/cdn url with cdn url.
115
+ * Step 1. Basic validations:
116
+ * 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.
117
+ * b) If cdn local storage items are emtpy then received url in param is returned.
118
+ * c) If url doesn't match with regex.
119
+ * d) Channel/Subchannel not present in CHANNEL_CONFIGS
120
+ * e) No quality and default quality mentioned in CHANNEL_CONFIGS for given channel.
121
+ * f) If channels quality is non numeric(maybe as a result of manual modification) then quality=100 is returned.
122
+ *
123
+ * Step 2. The CHANNEL_CONFIGS determine the applicableTransformations.
124
+ * Step 3. If applicable transformations are present `CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX` is appended to cdn url and transformation properties are added.
125
+ * Step 4. The original s3 file name is appened at the end of the url to get complete cdn url and value is returned.
126
+ *
127
+ * Error handling:
128
+ * In case of any unknown exception, url received in param is returned.
101
129
  */
102
130
  export const getCdnUrl = ({
103
131
  url,
@@ -202,7 +230,7 @@ export const getCdnUrl = ({
202
230
 
203
231
  /**
204
232
  *
205
- * @param {*} htmlContents
233
+ * @param {string} htmlContents accepts htmlContents - strigified.
206
234
  * @returns htmlContents with updated urls in image tag
207
235
  */
208
236
  export const updateImagesInHtml = (htmlContents) => {
@@ -235,6 +263,7 @@ export const updateImagesInHtml = (htmlContents) => {
235
263
  *
236
264
  * @param {*} contents
237
265
  * @returns
266
+ * Transforms the email template's html by images replacing the s3 url / cdn url with cdn url.
238
267
  */
239
268
  export const transformEmailTemplates = (contents) => {
240
269
  const contentsCopy = cloneDeep(contents);
@@ -254,7 +283,12 @@ export const transformEmailTemplates = (contents) => {
254
283
  };
255
284
 
256
285
 
257
-
286
+ /**
287
+ *
288
+ * @param {*} key
289
+ * @param {*} parse
290
+ * @returns Localstorage item with mentioned key. Parses the value if second param `parse` is true.
291
+ */
258
292
  export function getLocalStorageItem(key, parse = false){
259
293
  const val = localStorage.getItem(key);
260
294
  if(parse){
@@ -263,11 +297,17 @@ export function getLocalStorageItem(key, parse = false){
263
297
  return val;
264
298
  }
265
299
 
300
+ /**
301
+ * Removes specified key from local storage.
302
+ */
266
303
  export function removeLocalStorageItem(key) {
267
304
  localStorage.removeItem(key);
268
305
  return;
269
306
  }
270
307
 
308
+ /**
309
+ * Util function. Removes all cdn related local storage items.
310
+ */
271
311
  export function removeAllCdnLocalStorageItems() {
272
312
  try{
273
313
  removeLocalStorageItem(CREATIVES_CDN_BASE_URL_KEY);
@@ -278,6 +318,19 @@ export function removeAllCdnLocalStorageItems() {
278
318
  }
279
319
  }
280
320
 
321
+ /**
322
+ *
323
+ * @param {*} configsResponse
324
+ * This util function saves the getCdnConfigs response into the local storage.
325
+ * The following response items are mapped into the following keys in local storage:
326
+ * hostname -> CREATIVES_CDN_BASE_URL
327
+ * qualityCfg ->CREATIVES_CDN_QUALITY_CONFIG
328
+ * transformationUrlSuffix -> CREATIVES_CDN_TRANSFORMATION_URL_SUFFIX
329
+ *
330
+ * 1. If configsReponse is empty. All above mentioned keys are deleted from localstorage.
331
+ * 2. If any one of the above keys is missing. The respective keys are deleted from localstorage.
332
+ * 3. Else it is saved into the localstorage.
333
+ */
281
334
  export function saveCdnConfigs(configsResponse) {
282
335
  try {
283
336
  //If no response from api, then remove localStorage items if they were set previously