@capillarytech/creatives-library 7.12.81 → 7.12.83
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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
/* eslint-disable no-unused-expressions */
|
|
3
|
+
import { parse } from 'node-html-parser';
|
|
4
|
+
|
|
5
|
+
// 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
|
|
6
|
+
|
|
7
|
+
const CDN_BASE_URL = `https://storage.crm.n.content-cdn.io`;
|
|
8
|
+
const CDN_TRANSFORMATION_URL_SUFFIX = `/cdn-cgi/image/`;
|
|
9
|
+
const QUALITY = 75;
|
|
10
|
+
// const regex = /https:\/\/.*intouch_creative_assets.*(?:jpg|png|jpeg|gif)$/;
|
|
11
|
+
const regex = /https:\/\/.*intouch_creative_assets.*$/;
|
|
12
|
+
const INTOUCH_CREATIVE_ASSETS = 'intouch_creative_assets';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* getCdnUrl : utility function to replace and return s3/cdn url with cdn url.
|
|
16
|
+
*/
|
|
17
|
+
export const getCdnUrl = ({url, height, width, transformationEnabled = false, reduceQuality = true}) => {
|
|
18
|
+
if (!url.includes(INTOUCH_CREATIVE_ASSETS)) return url;
|
|
19
|
+
|
|
20
|
+
const [, assetKey] = url.split(INTOUCH_CREATIVE_ASSETS);
|
|
21
|
+
let newUrl = `${CDN_BASE_URL}`;
|
|
22
|
+
if (transformationEnabled || reduceQuality) {
|
|
23
|
+
newUrl += CDN_TRANSFORMATION_URL_SUFFIX;
|
|
24
|
+
if (height) {
|
|
25
|
+
newUrl += `height=${height},`;
|
|
26
|
+
}
|
|
27
|
+
if (width) {
|
|
28
|
+
newUrl += `width=${width},`;
|
|
29
|
+
}
|
|
30
|
+
newUrl += `quality=${QUALITY}`;
|
|
31
|
+
}
|
|
32
|
+
newUrl += `/intouch_creative_assets${assetKey}`;
|
|
33
|
+
return newUrl;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {*} htmlContents
|
|
39
|
+
* @returns htmlContents with updated urls in image tag
|
|
40
|
+
*/
|
|
41
|
+
export const updateImagesInHtml = (htmlContents) => {
|
|
42
|
+
const copiedHtmlContents = htmlContents;
|
|
43
|
+
try {
|
|
44
|
+
const root = parse(htmlContents);
|
|
45
|
+
root.querySelectorAll('img').forEach((element) => {
|
|
46
|
+
const imageSrc = element.getAttribute('src');
|
|
47
|
+
const isAsset = regex.test(imageSrc);
|
|
48
|
+
if (isAsset) {
|
|
49
|
+
const height = element.getAttribute('height');
|
|
50
|
+
const width = element.getAttribute('width');
|
|
51
|
+
const newUrl = getCdnUrl({url: imageSrc, height, width, transformationEnabled: true, reduceQuality: true});
|
|
52
|
+
element.setAttribute('src', newUrl);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return root.toString();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.log('An error occured while updating images in html', e);
|
|
58
|
+
return copiedHtmlContents; //return received input directly in case an exception is thrown
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {*} contents
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
export const transformEmailTemplates = (contents) => {
|
|
68
|
+
const contentsCopy = cloneDeep(contents);
|
|
69
|
+
try {
|
|
70
|
+
const base = contentsCopy?.versions?.base;
|
|
71
|
+
const languages = base?.selectedLanguages;
|
|
72
|
+
languages?.forEach((lang) => {
|
|
73
|
+
const htmlContents = base?.[lang]?.['template-content'];
|
|
74
|
+
const newHtmlContents = updateImagesInHtml(htmlContents);
|
|
75
|
+
base[lang]['template-content'] = newHtmlContents;
|
|
76
|
+
});
|
|
77
|
+
return contentsCopy;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.log('Some error has occured while transforming email templates', e);
|
|
80
|
+
return contents; //return received input directly in case an exception is thrown
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// export const transformRcsTemplates = (contents) => {
|
|
85
|
+
// const contentsCopy = cloneDeep(contents);
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// {
|
|
90
|
+
// "name": "test 1",
|
|
91
|
+
// "versions": {
|
|
92
|
+
// "base": {
|
|
93
|
+
// "content": {
|
|
94
|
+
// "RCS": {
|
|
95
|
+
// "cardContent": [
|
|
96
|
+
// {
|
|
97
|
+
// "title": "asdf",
|
|
98
|
+
// "description": "asdf",
|
|
99
|
+
// "mediaType": "NONE"
|
|
100
|
+
// }
|
|
101
|
+
// ],
|
|
102
|
+
// "cardSettings": {
|
|
103
|
+
// "cardOrientation": "VERTICAL"
|
|
104
|
+
// },
|
|
105
|
+
// "cardType": "STANDALONE",
|
|
106
|
+
// "contentType": "RICHCARD",
|
|
107
|
+
// "smsFallBackContent": {
|
|
108
|
+
// "message": ""
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
// },
|
|
114
|
+
// "type": "RCS"
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// {
|
|
119
|
+
// "name": "test 2",
|
|
120
|
+
// "versions": {
|
|
121
|
+
// "base": {
|
|
122
|
+
// "content": {
|
|
123
|
+
// "RCS": {
|
|
124
|
+
// "cardContent": [
|
|
125
|
+
// {
|
|
126
|
+
// "title": "asdfasdf",
|
|
127
|
+
// "description": "asdfadsf",
|
|
128
|
+
// "mediaType": "IMAGE",
|
|
129
|
+
// "suggestions": [
|
|
130
|
+
// {
|
|
131
|
+
// "type": "CTA",
|
|
132
|
+
// "text": "fasdf",
|
|
133
|
+
// "url": "https://www.google.com"
|
|
134
|
+
// }
|
|
135
|
+
// ],
|
|
136
|
+
// "media": {
|
|
137
|
+
// "mediaUrl": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/820a9ff9-ad5b-410e-b471-75c2e1a9.jpg",
|
|
138
|
+
// "height": "MEDIUM"
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
// ],
|
|
142
|
+
// "cardSettings": {
|
|
143
|
+
// "cardOrientation": "VERTICAL"
|
|
144
|
+
// },
|
|
145
|
+
// "cardType": "STANDALONE",
|
|
146
|
+
// "contentType": "RICHCARD",
|
|
147
|
+
// "smsFallBackContent": {
|
|
148
|
+
// "message": "asdf"
|
|
149
|
+
// }
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
|
+
// },
|
|
154
|
+
// "type": "RCS"
|
|
155
|
+
// }
|
|
@@ -99,7 +99,7 @@ class NewCallTask extends React.Component { // eslint-disable-line react/prefer-
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
render() {
|
|
102
|
-
const { intl, isLoading, metaEntities, selectedOfferDetails } = this.props;
|
|
102
|
+
const { intl, isLoading, metaEntities, selectedOfferDetails , injectedTags} = this.props;
|
|
103
103
|
const { formatMessage } = intl;
|
|
104
104
|
const { subject, messageBody, description, callTaskActionType } = this.state;
|
|
105
105
|
const tags = metaEntities && metaEntities.tags ? metaEntities.tags.standard : [];
|
|
@@ -125,6 +125,7 @@ class NewCallTask extends React.Component { // eslint-disable-line react/prefer-
|
|
|
125
125
|
tags={tags}
|
|
126
126
|
onTagSelect={this.onTagSelect}
|
|
127
127
|
selectedOfferDetails={selectedOfferDetails}
|
|
128
|
+
injectedTags={injectedTags}
|
|
128
129
|
/>
|
|
129
130
|
<CapInput.TextArea
|
|
130
131
|
setInputRef={this.setInputRef}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from '@capillarytech/cap-ui-library';
|
|
17
17
|
import { injectIntl, intlShape } from 'react-intl';
|
|
18
18
|
import { createStructuredSelector } from 'reselect';
|
|
19
|
-
import { makeSelectMetaEntities, isLoadingMetaEntities } from '../Cap/selectors';
|
|
19
|
+
import { makeSelectMetaEntities, isLoadingMetaEntities, setInjectedTags } from '../Cap/selectors';
|
|
20
20
|
import * as globalActions from '../Cap/actions';
|
|
21
21
|
import * as actions from "./actions";
|
|
22
22
|
import makeSelectCallTask from './selectors';
|
|
@@ -71,7 +71,7 @@ export class CallTask extends React.Component { // eslint-disable-line react/pre
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
render() {
|
|
74
|
-
const { intl, onCallTaskSubmit, templateData, loadingMetaEntities, metaEntities, selectedOfferDetails, messageDetails } = this.props;
|
|
74
|
+
const { intl, onCallTaskSubmit, templateData, loadingMetaEntities, metaEntities, selectedOfferDetails, messageDetails, injectedTags } = this.props;
|
|
75
75
|
const { formatMessage } = intl;
|
|
76
76
|
const { mode } = this.state;
|
|
77
77
|
return (
|
|
@@ -85,6 +85,7 @@ export class CallTask extends React.Component { // eslint-disable-line react/pre
|
|
|
85
85
|
onCallTaskSubmit={onCallTaskSubmit}
|
|
86
86
|
selectedOfferDetails={selectedOfferDetails}
|
|
87
87
|
messageDetails={messageDetails}
|
|
88
|
+
injectedTags={injectedTags || {}}
|
|
88
89
|
/>
|
|
89
90
|
:
|
|
90
91
|
<div>
|
|
@@ -144,6 +145,7 @@ const mapStateToProps = createStructuredSelector({
|
|
|
144
145
|
CallTask: makeSelectCallTask(),
|
|
145
146
|
metaEntities: makeSelectMetaEntities(),
|
|
146
147
|
loadingMetaEntities: isLoadingMetaEntities(),
|
|
148
|
+
injectedTags: setInjectedTags(),
|
|
147
149
|
});
|
|
148
150
|
|
|
149
151
|
function mapDispatchToProps(dispatch) {
|