@viibe/impulse-integration-js 2.4.1 → 3.0.0
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/coverage/clover.xml +111 -6
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/index.html +21 -21
- package/coverage/lcov-report/index.js.html +1001 -11
- package/coverage/lcov.info +224 -182
- package/dist/index.js +1 -1
- package/package.json +5 -2
- package/src/index.js +23 -66
- package/test/dist.test.js +39 -4
- package/webpack.config.js +1 -1
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const qs = require('qs');
|
|
2
|
+
|
|
1
3
|
function isFromOrigin(origin) {
|
|
2
4
|
return function isEventFromOrigin(event) {
|
|
3
5
|
return Boolean(event.isTrusted && event.origin.indexOf(origin) === 0);
|
|
@@ -141,11 +143,11 @@ class Viibe {
|
|
|
141
143
|
*/
|
|
142
144
|
this.handlers = [];
|
|
143
145
|
this.host = options.host;
|
|
144
|
-
this.
|
|
146
|
+
this.viibeDomain = /^localhost/.test(this.host) ? `http://${this.host}` : `https://${this.host}`;
|
|
145
147
|
this.apiOrigin = /^localhost/.test(this.host) ? `http://${this.host}` : `https://api-${this.host}`;
|
|
146
148
|
this.source = options.source;
|
|
147
149
|
|
|
148
|
-
this.isViibeEvent = isFromOrigin(this.
|
|
150
|
+
this.isViibeEvent = isFromOrigin(this.viibeDomain);
|
|
149
151
|
|
|
150
152
|
window.addEventListener('message', this.onMessage.bind(this));
|
|
151
153
|
}
|
|
@@ -163,7 +165,7 @@ class Viibe {
|
|
|
163
165
|
|
|
164
166
|
iframe.name = `viibe-${Math.floor(Math.random() * IFRAME_NAME_RANGE)}`;
|
|
165
167
|
iframe.style = 'border: 0;width: 0;';
|
|
166
|
-
iframe.src = `${this.
|
|
168
|
+
iframe.src = `${this.viibeDomain}/integration/features/notifications`;
|
|
167
169
|
|
|
168
170
|
return iframe;
|
|
169
171
|
}
|
|
@@ -193,7 +195,6 @@ class Viibe {
|
|
|
193
195
|
|
|
194
196
|
generateIframeSrc(params = {}) {
|
|
195
197
|
const {
|
|
196
|
-
clipboard = false,
|
|
197
198
|
components,
|
|
198
199
|
links,
|
|
199
200
|
o2m = false,
|
|
@@ -204,75 +205,31 @@ class Viibe {
|
|
|
204
205
|
token,
|
|
205
206
|
} = params;
|
|
206
207
|
|
|
207
|
-
|
|
208
|
+
const src = `${this.viibeDomain}/integration/features/ticket`;
|
|
208
209
|
|
|
209
|
-
const urlParams =
|
|
210
|
+
const urlParams = {
|
|
211
|
+
version: '2.0.0',
|
|
210
212
|
origin: document.location.origin,
|
|
211
213
|
resize: 'true',
|
|
212
214
|
source: this.source,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (links) {
|
|
227
|
-
const linksParams = (links instanceof Array)
|
|
228
|
-
? links.map(link => `${link.category}:${link.value}`).join(',')
|
|
229
|
-
: String(links);
|
|
230
|
-
|
|
231
|
-
urlParams.set('links', linksParams);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (suggestions) {
|
|
235
|
-
const suggestionsParams = (suggestions instanceof Array)
|
|
236
|
-
? suggestions.map(({ category, value, description }) => {
|
|
237
|
-
let res = `${category}:${value}`;
|
|
238
|
-
|
|
239
|
-
if (description) {
|
|
240
|
-
res += `:${description}`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return res;
|
|
244
|
-
}).join(',')
|
|
245
|
-
: String(suggestions);
|
|
246
|
-
|
|
247
|
-
urlParams.set('suggestions', suggestionsParams);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (token) {
|
|
251
|
-
params.set('token', token);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (locale) {
|
|
255
|
-
urlParams.set('locale', locale);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (components) {
|
|
259
|
-
const componentsParams = (components instanceof Array)
|
|
260
|
-
? components.join(',')
|
|
261
|
-
: String(components);
|
|
262
|
-
|
|
263
|
-
urlParams.set('components', componentsParams);
|
|
264
|
-
}
|
|
215
|
+
title: ticket?.title,
|
|
216
|
+
thirdPartyId: ticket?.integration?.id,
|
|
217
|
+
custom: ticket?.integration?.customData,
|
|
218
|
+
links: links,
|
|
219
|
+
suggestions: suggestions,
|
|
220
|
+
token: token,
|
|
221
|
+
locale: locale,
|
|
222
|
+
components: components,
|
|
223
|
+
standalone: [true, false].includes(standalone) ? standalone : null,
|
|
224
|
+
o2m: [true, false].includes(o2m) ? o2m : null,
|
|
225
|
+
};
|
|
265
226
|
|
|
266
|
-
|
|
267
|
-
|
|
227
|
+
// Clean empty values
|
|
228
|
+
for (let key in urlParams) {
|
|
229
|
+
if ([null, undefined, ''].includes(urlParams[key])) delete urlParams[key]
|
|
268
230
|
}
|
|
269
231
|
|
|
270
|
-
|
|
271
|
-
urlParams.set('o2m', Boolean(o2m));
|
|
272
|
-
|
|
273
|
-
src += `?${urlParams}`;
|
|
274
|
-
|
|
275
|
-
return src;
|
|
232
|
+
return `${src}?${qs.stringify(urlParams)}`;
|
|
276
233
|
}
|
|
277
234
|
|
|
278
235
|
/**
|
package/test/dist.test.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const Viibe = require('../dist');
|
|
5
|
+
const Viibe = require('../src');
|
|
7
6
|
|
|
8
7
|
describe('dist', () => {
|
|
9
8
|
test('exposes Viibe constructor', () => {
|
|
@@ -34,13 +33,13 @@ describe('dist', () => {
|
|
|
34
33
|
|
|
35
34
|
expect(viibe.host).toBe('praxedo-qa.viibe.tech');
|
|
36
35
|
expect(viibe.source).toBe('jest');
|
|
37
|
-
expect(viibe.
|
|
36
|
+
expect(viibe.viibeDomain).toBe('https://praxedo-qa.viibe.tech');
|
|
38
37
|
|
|
39
38
|
const viibeLocalhost = new Viibe({
|
|
40
39
|
host: 'localhost:6666',
|
|
41
40
|
});
|
|
42
41
|
|
|
43
|
-
expect(viibeLocalhost.
|
|
42
|
+
expect(viibeLocalhost.viibeDomain).toBe('http://localhost:6666');
|
|
44
43
|
});
|
|
45
44
|
|
|
46
45
|
test('createNotificationIframe', () => {
|
|
@@ -71,4 +70,40 @@ describe('dist', () => {
|
|
|
71
70
|
expect(iframe.style.margin).toBe('0.5rem');
|
|
72
71
|
expect(iframe.style.width).toBe('calc(100% - 1rem)');
|
|
73
72
|
});
|
|
73
|
+
|
|
74
|
+
test('generateIframeSrc', () => {
|
|
75
|
+
const viibe = new Viibe({
|
|
76
|
+
host: 'praxedo-qa.viibe.tech',
|
|
77
|
+
source: 'jest',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const options = {
|
|
81
|
+
clipboard: true,
|
|
82
|
+
components: ['call', 'ticket', 'schedule'],
|
|
83
|
+
links: [{
|
|
84
|
+
category: 'phone',
|
|
85
|
+
value: '+33666666666'
|
|
86
|
+
},{
|
|
87
|
+
category: 'email',
|
|
88
|
+
value: 'test@test.fr'
|
|
89
|
+
}],
|
|
90
|
+
o2m: true,
|
|
91
|
+
ticket: {
|
|
92
|
+
title: 'Some title',
|
|
93
|
+
integration: {
|
|
94
|
+
id: 'ticket-1',
|
|
95
|
+
customData: {
|
|
96
|
+
entUuid: 'XYZ',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
locale: 'FR',
|
|
101
|
+
standalone: false,
|
|
102
|
+
suggestions: [],
|
|
103
|
+
}
|
|
104
|
+
const generatedURL = viibe.generateIframeSrc(options);
|
|
105
|
+
|
|
106
|
+
const expectedURL = 'https://praxedo-qa.viibe.tech/integration/features/ticket?version=2.0.0&origin=http://localhost&resize=true&source=jest&title=Some title&thirdPartyId=ticket-1&custom[entUuid]=XYZ&links[0][category]=phone&links[0][value]=+33666666666&links[1][category]=email&links[1][value]=test@test.fr&locale=FR&components[0]=call&components[1]=ticket&components[2]=schedule&standalone=false&o2m=true';
|
|
107
|
+
expect(decodeURIComponent(generatedURL)).toBe(expectedURL);
|
|
108
|
+
});
|
|
74
109
|
});
|