@thoughtspot/visual-embed-sdk 1.20.0-alpha.2 → 1.20.0-prerender.1
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/dist/src/auth.d.ts +75 -5
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/embed/app.d.ts +19 -7
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +39 -19
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +19 -7
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/search-bar.d.ts +7 -1
- package/dist/src/embed/search-bar.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +11 -3
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +76 -5
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mixpanel-service.d.ts +8 -0
- package/dist/src/mixpanel-service.d.ts.map +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/util.d.ts +4 -0
- package/dist/src/react/util.d.ts.map +1 -1
- package/dist/src/test/test-utils.d.ts +11 -2
- package/dist/src/test/test-utils.d.ts.map +1 -1
- package/dist/src/types.d.ts +429 -97
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/answerService.d.ts +7 -0
- package/dist/src/utils/answerService.d.ts.map +1 -1
- package/dist/src/utils/authService.d.ts +30 -0
- package/dist/src/utils/authService.d.ts.map +1 -1
- package/dist/src/utils/processData.d.ts +12 -0
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/src/utils/processTrigger.d.ts +7 -0
- package/dist/src/utils/processTrigger.d.ts.map +1 -1
- package/dist/src/utils.d.ts +12 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsembed.es.js +818 -285
- package/dist/tsembed.js +791 -284
- package/lib/package.json +4 -3
- package/lib/src/auth.d.ts +75 -5
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +86 -26
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +14 -5
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/config.d.ts +1 -0
- package/lib/src/config.d.ts.map +1 -1
- package/lib/src/config.js +5 -3
- package/lib/src/config.js.map +1 -1
- package/lib/src/config.spec.js.map +1 -1
- package/lib/src/embed/app.d.ts +19 -7
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +26 -16
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/app.spec.js +12 -12
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +39 -19
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +49 -15
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +2 -2
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +1 -1
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +19 -7
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +50 -38
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +37 -30
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/pinboard.spec.js +14 -26
- package/lib/src/embed/pinboard.spec.js.map +1 -1
- package/lib/src/embed/search-bar.d.ts +7 -1
- package/lib/src/embed/search-bar.d.ts.map +1 -1
- package/lib/src/embed/search-bar.js +6 -7
- package/lib/src/embed/search-bar.js.map +1 -1
- package/lib/src/embed/search.d.ts +11 -3
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +19 -15
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/search.spec.js +16 -19
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/searchEmbed-basic-auth.spec.js +4 -0
- package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +76 -5
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +150 -72
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +23 -24
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/errors.d.ts.map +1 -1
- package/lib/src/errors.js.map +1 -1
- package/lib/src/index.d.ts +3 -3
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +3 -3
- package/lib/src/index.js.map +1 -1
- package/lib/src/mixpanel-service.d.ts +8 -0
- package/lib/src/mixpanel-service.d.ts.map +1 -1
- package/lib/src/mixpanel-service.js +13 -1
- package/lib/src/mixpanel-service.js.map +1 -1
- package/lib/src/mixpanel-service.spec.js.map +1 -1
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +9 -7
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +29 -8
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/react/util.d.ts +4 -0
- package/lib/src/react/util.d.ts.map +1 -1
- package/lib/src/react/util.js +4 -0
- package/lib/src/react/util.js.map +1 -1
- package/lib/src/test/test-utils.d.ts +11 -2
- package/lib/src/test/test-utils.d.ts.map +1 -1
- package/lib/src/test/test-utils.js +36 -25
- package/lib/src/test/test-utils.js.map +1 -1
- package/lib/src/types.d.ts +429 -97
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +310 -72
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/answerService.d.ts +7 -0
- package/lib/src/utils/answerService.d.ts.map +1 -1
- package/lib/src/utils/answerService.js +7 -0
- package/lib/src/utils/answerService.js.map +1 -1
- package/lib/src/utils/answerService.spec.js.map +1 -1
- package/lib/src/utils/authService.d.ts +30 -0
- package/lib/src/utils/authService.d.ts.map +1 -1
- package/lib/src/utils/authService.js +39 -2
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/processData.d.ts +12 -0
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +33 -5
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils/processTrigger.d.ts +7 -0
- package/lib/src/utils/processTrigger.d.ts.map +1 -1
- package/lib/src/utils/processTrigger.js +17 -3
- package/lib/src/utils/processTrigger.js.map +1 -1
- package/lib/src/utils/processTrigger.spec.js.map +1 -1
- package/lib/src/utils.d.ts +12 -0
- package/lib/src/utils.d.ts.map +1 -1
- package/lib/src/utils.js +24 -19
- package/lib/src/utils.js.map +1 -1
- package/lib/src/utils.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +664 -141
- package/package.json +4 -3
- package/src/auth.spec.ts +68 -150
- package/src/auth.ts +141 -101
- package/src/config.spec.ts +2 -4
- package/src/config.ts +5 -3
- package/src/embed/app.spec.ts +25 -14
- package/src/embed/app.ts +49 -37
- package/src/embed/base.spec.ts +6 -12
- package/src/embed/base.ts +74 -57
- package/src/embed/embed.spec.ts +5 -6
- package/src/embed/liveboard.spec.ts +56 -37
- package/src/embed/liveboard.ts +67 -65
- package/src/embed/pinboard.spec.ts +26 -29
- package/src/embed/search-bar.tsx +14 -9
- package/src/embed/search.spec.ts +31 -21
- package/src/embed/search.ts +28 -22
- package/src/embed/searchEmbed-basic-auth.spec.ts +22 -28
- package/src/embed/ts-embed.spec.ts +70 -148
- package/src/embed/ts-embed.ts +180 -157
- package/src/errors.ts +3 -6
- package/src/index.ts +23 -7
- package/src/mixpanel-service.spec.ts +1 -3
- package/src/mixpanel-service.ts +13 -1
- package/src/react/index.spec.tsx +72 -15
- package/src/react/index.tsx +43 -54
- package/src/react/util.ts +8 -4
- package/src/test/test-utils.ts +43 -39
- package/src/types.ts +427 -97
- package/src/utils/answerService.spec.ts +3 -5
- package/src/utils/answerService.ts +21 -17
- package/src/utils/authService.spec.ts +26 -41
- package/src/utils/authService.ts +47 -21
- package/src/utils/processData.spec.ts +26 -59
- package/src/utils/processData.ts +36 -14
- package/src/utils/processTrigger.spec.ts +1 -6
- package/src/utils/processTrigger.ts +18 -9
- package/src/utils.spec.ts +8 -12
- package/src/utils.ts +25 -26
package/src/index.ts
CHANGED
|
@@ -7,17 +7,16 @@
|
|
|
7
7
|
* @summary ThoughtSpot Visual Embed SDK
|
|
8
8
|
* @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { AppEmbed, Page, AppViewConfig } from './embed/app';
|
|
12
|
-
import { init, prefetch, logout, getEmbedConfig } from './embed/base';
|
|
13
11
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from './embed/liveboard';
|
|
12
|
+
init, prefetch, logout, getEmbedConfig,
|
|
13
|
+
} from './embed/base';
|
|
14
|
+
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from './embed/liveboard';
|
|
18
15
|
import { SearchEmbed, SearchViewConfig } from './embed/search';
|
|
19
16
|
import { SearchBarEmbed, SearchBarViewConfig } from './embed/search-bar';
|
|
20
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
AuthFailureType, AuthStatus, AuthEvent, AuthEventEmitter, getSessionInfo,
|
|
19
|
+
} from './auth';
|
|
21
20
|
import {
|
|
22
21
|
AuthType,
|
|
23
22
|
RuntimeFilter,
|
|
@@ -28,6 +27,14 @@ import {
|
|
|
28
27
|
Action,
|
|
29
28
|
EmbedConfig,
|
|
30
29
|
PrefetchFeatures,
|
|
30
|
+
FrameParams,
|
|
31
|
+
DOMSelector,
|
|
32
|
+
MessageOptions,
|
|
33
|
+
MessageCallback,
|
|
34
|
+
MessagePayload,
|
|
35
|
+
CustomisationsInterface,
|
|
36
|
+
CustomStyles,
|
|
37
|
+
customCssInterface,
|
|
31
38
|
} from './types';
|
|
32
39
|
|
|
33
40
|
export {
|
|
@@ -44,6 +51,7 @@ export {
|
|
|
44
51
|
AuthFailureType,
|
|
45
52
|
AuthStatus,
|
|
46
53
|
AuthEvent,
|
|
54
|
+
AuthEventEmitter,
|
|
47
55
|
// types
|
|
48
56
|
Page,
|
|
49
57
|
AuthType,
|
|
@@ -59,4 +67,12 @@ export {
|
|
|
59
67
|
LiveboardViewConfig,
|
|
60
68
|
AppViewConfig,
|
|
61
69
|
PrefetchFeatures,
|
|
70
|
+
FrameParams,
|
|
71
|
+
DOMSelector,
|
|
72
|
+
MessageOptions,
|
|
73
|
+
MessageCallback,
|
|
74
|
+
MessagePayload,
|
|
75
|
+
CustomisationsInterface,
|
|
76
|
+
CustomStyles,
|
|
77
|
+
customCssInterface,
|
|
62
78
|
};
|
|
@@ -49,9 +49,7 @@ describe('Unit test for mixpanel', () => {
|
|
|
49
49
|
initMixpanel(sessionInfo);
|
|
50
50
|
|
|
51
51
|
expect(mixpanel.init).toHaveBeenCalledWith(sessionInfo.mixpanelToken);
|
|
52
|
-
expect(mixpanel.identify).not.toHaveBeenCalledWith(
|
|
53
|
-
sessionInfo.userGUID,
|
|
54
|
-
);
|
|
52
|
+
expect(mixpanel.identify).not.toHaveBeenCalledWith(sessionInfo.userGUID);
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
test('when not init, should queue events and flush on init', () => {
|
package/src/mixpanel-service.ts
CHANGED
|
@@ -19,6 +19,7 @@ let eventQueue: { eventId: string; eventProps: any }[] = [];
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Pushes the event with its Property key-value map to mixpanel.
|
|
22
|
+
*
|
|
22
23
|
* @param eventId
|
|
23
24
|
* @param eventProps
|
|
24
25
|
*/
|
|
@@ -30,6 +31,9 @@ export function uploadMixpanelEvent(eventId: string, eventProps = {}): void {
|
|
|
30
31
|
mixpanel.track(eventId, eventProps);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
33
37
|
function emptyQueue() {
|
|
34
38
|
if (!isMixpanelInitialized) {
|
|
35
39
|
return;
|
|
@@ -40,11 +44,16 @@ function emptyQueue() {
|
|
|
40
44
|
eventQueue = [];
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param sessionInfo
|
|
50
|
+
*/
|
|
43
51
|
export function initMixpanel(sessionInfo: any): void {
|
|
44
52
|
if (!sessionInfo || !sessionInfo.mixpanelToken) {
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
47
|
-
// On a public cluster the user is anonymous, so don't set the identify to
|
|
55
|
+
// On a public cluster the user is anonymous, so don't set the identify to
|
|
56
|
+
// userGUID
|
|
48
57
|
const isPublicCluster = !!sessionInfo.isPublicUser;
|
|
49
58
|
const token = sessionInfo.mixpanelToken;
|
|
50
59
|
if (token) {
|
|
@@ -57,6 +66,9 @@ export function initMixpanel(sessionInfo: any): void {
|
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
60
72
|
export function testResetMixpanel() {
|
|
61
73
|
isMixpanelInitialized = false;
|
|
62
74
|
eventQueue = [];
|
package/src/react/index.spec.tsx
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import '@testing-library/jest-dom';
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
cleanup, fireEvent, render, waitFor,
|
|
6
|
+
} from '@testing-library/react';
|
|
7
|
+
import {
|
|
8
|
+
Action, EmbedEvent, HostEvent, RuntimeFilterOp,
|
|
9
|
+
} from '../types';
|
|
6
10
|
import {
|
|
7
11
|
executeAfterWait,
|
|
8
12
|
getIFrameEl,
|
|
@@ -11,11 +15,7 @@ import {
|
|
|
11
15
|
mockMessageChannel,
|
|
12
16
|
} from '../test/test-utils';
|
|
13
17
|
import {
|
|
14
|
-
SearchEmbed,
|
|
15
|
-
AppEmbed,
|
|
16
|
-
LiveboardEmbed,
|
|
17
|
-
useEmbedRef,
|
|
18
|
-
SearchBarEmbed,
|
|
18
|
+
SearchEmbed, AppEmbed, LiveboardEmbed, useEmbedRef, SearchBarEmbed,
|
|
19
19
|
} from './index';
|
|
20
20
|
import { AuthType, init } from '../index';
|
|
21
21
|
|
|
@@ -41,7 +41,9 @@ describe('React Components', () => {
|
|
|
41
41
|
await waitFor(() => getIFrameEl(container));
|
|
42
42
|
|
|
43
43
|
expect(
|
|
44
|
-
getIFrameEl(container).classList.contains(
|
|
44
|
+
getIFrameEl(container).parentElement.classList.contains(
|
|
45
|
+
'embedClass',
|
|
46
|
+
),
|
|
45
47
|
).toBe(true);
|
|
46
48
|
expect(getIFrameSrc(container)).toBe(
|
|
47
49
|
`http://${thoughtSpotHost}/?hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=None&hideAction=[%22${Action.ReportError}%22,%22editACopy%22,%22saveAsView%22,%22updateTSL%22,%22editTSL%22,%22onDeleteAnswer%22]&dataSourceMode=hide&useLastSelectedSources=false&isSearchEmbed=true#/embed/answer`,
|
|
@@ -84,10 +86,7 @@ describe('React Components', () => {
|
|
|
84
86
|
const TestComponent = () => {
|
|
85
87
|
const embedRef = useEmbedRef();
|
|
86
88
|
const onLiveboardRendered = () => {
|
|
87
|
-
embedRef.current.trigger(HostEvent.SetVisibleVizs, [
|
|
88
|
-
'viz1',
|
|
89
|
-
'viz2',
|
|
90
|
-
]);
|
|
89
|
+
embedRef.current.trigger(HostEvent.SetVisibleVizs, ['viz1', 'viz2']);
|
|
91
90
|
};
|
|
92
91
|
|
|
93
92
|
return (
|
|
@@ -137,9 +136,65 @@ describe('React Components', () => {
|
|
|
137
136
|
);
|
|
138
137
|
|
|
139
138
|
await waitFor(() => getIFrameEl(container));
|
|
140
|
-
expect(getIFrameSrc(container)).toContain(
|
|
141
|
-
|
|
139
|
+
expect(getIFrameSrc(container)).toContain('col1=revenue&op1=EQ&val1=100');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('Should have the correct container element', async () => {
|
|
143
|
+
const { container } = render(
|
|
144
|
+
<LiveboardEmbed liveboardId="abcd" className="def" />,
|
|
142
145
|
);
|
|
146
|
+
|
|
147
|
+
await waitFor(() => getIFrameEl(container));
|
|
148
|
+
expect(container.querySelector('div')).not.toBe(null);
|
|
149
|
+
expect(
|
|
150
|
+
container.querySelector('div').classList.contains('def'),
|
|
151
|
+
).toBe(true);
|
|
152
|
+
|
|
153
|
+
const { container: containerSibling } = render(
|
|
154
|
+
<LiveboardEmbed
|
|
155
|
+
liveboardId="abcd"
|
|
156
|
+
className="def"
|
|
157
|
+
insertAsSibling={true}
|
|
158
|
+
/>,
|
|
159
|
+
);
|
|
160
|
+
await waitFor(() => getIFrameEl(containerSibling));
|
|
161
|
+
expect(containerSibling.querySelector('span')).not.toBe(null);
|
|
162
|
+
expect(containerSibling.querySelector('span').style.position).toBe(
|
|
163
|
+
'absolute',
|
|
164
|
+
);
|
|
165
|
+
expect(
|
|
166
|
+
getIFrameEl(containerSibling).classList.contains('def'),
|
|
167
|
+
).toBe(true);
|
|
168
|
+
expect(containerSibling.querySelector('div')).toBe(null);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('Should have the correct container element', async () => {
|
|
172
|
+
const { container } = render(
|
|
173
|
+
<LiveboardEmbed liveboardId="abcd" className="def" />,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
await waitFor(() => getIFrameEl(container));
|
|
177
|
+
expect(container.querySelector('div')).not.toBe(null);
|
|
178
|
+
expect(
|
|
179
|
+
container.querySelector('div').classList.contains('def'),
|
|
180
|
+
).toBe(true);
|
|
181
|
+
|
|
182
|
+
const { container: containerSibling } = render(
|
|
183
|
+
<LiveboardEmbed
|
|
184
|
+
liveboardId="abcd"
|
|
185
|
+
className="def"
|
|
186
|
+
insertAsSibling={true}
|
|
187
|
+
/>,
|
|
188
|
+
);
|
|
189
|
+
await waitFor(() => getIFrameEl(containerSibling));
|
|
190
|
+
expect(containerSibling.querySelector('span')).not.toBe(null);
|
|
191
|
+
expect(containerSibling.querySelector('span').style.position).toBe(
|
|
192
|
+
'absolute',
|
|
193
|
+
);
|
|
194
|
+
expect(
|
|
195
|
+
getIFrameEl(containerSibling).classList.contains('def'),
|
|
196
|
+
).toBe(true);
|
|
197
|
+
expect(containerSibling.querySelector('div')).toBe(null);
|
|
143
198
|
});
|
|
144
199
|
});
|
|
145
200
|
|
|
@@ -159,7 +214,9 @@ describe('React Components', () => {
|
|
|
159
214
|
await waitFor(() => getIFrameEl(container));
|
|
160
215
|
|
|
161
216
|
expect(
|
|
162
|
-
getIFrameEl(container).classList.contains(
|
|
217
|
+
getIFrameEl(container).parentElement.classList.contains(
|
|
218
|
+
'embedClass',
|
|
219
|
+
),
|
|
163
220
|
).toBe(true);
|
|
164
221
|
expect(getIFrameSrc(container)).toBe(
|
|
165
222
|
`http://${thoughtSpotHost}/?hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=None&hideAction=[%22${Action.ReportError}%22]&dataSources=[%22test%22]&searchTokenString=%5Brevenue%5D&executeSearch=true&useLastSelectedSources=false&isSearchEmbed=true#/embed/search-bar-embed`,
|
package/src/react/index.tsx
CHANGED
|
@@ -1,90 +1,81 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
3
3
|
import { deepMerge } from '../utils';
|
|
4
|
-
import {
|
|
5
|
-
SearchBarEmbed as _SearchBarEmbed,
|
|
6
|
-
SearchBarViewConfig,
|
|
7
|
-
} from '../embed/search-bar';
|
|
4
|
+
import { SearchBarEmbed as _SearchBarEmbed, SearchBarViewConfig } from '../embed/search-bar';
|
|
8
5
|
import { SearchEmbed as _SearchEmbed, SearchViewConfig } from '../embed/search';
|
|
9
6
|
import { AppEmbed as _AppEmbed, AppViewConfig } from '../embed/app';
|
|
10
|
-
import {
|
|
11
|
-
LiveboardEmbed as _LiveboardEmbed,
|
|
12
|
-
LiveboardViewConfig,
|
|
13
|
-
} from '../embed/liveboard';
|
|
7
|
+
import { LiveboardEmbed as _LiveboardEmbed, LiveboardViewConfig } from '../embed/liveboard';
|
|
14
8
|
import { TsEmbed } from '../embed/ts-embed';
|
|
15
9
|
|
|
16
10
|
import { EmbedEvent, ViewConfig } from '../types';
|
|
17
11
|
import { EmbedProps, getViewPropsAndListeners } from './util';
|
|
18
12
|
|
|
19
|
-
const componentFactory = <
|
|
20
|
-
T extends typeof TsEmbed,
|
|
21
|
-
U extends EmbedProps,
|
|
22
|
-
V extends ViewConfig
|
|
23
|
-
>(
|
|
13
|
+
const componentFactory = <T extends typeof TsEmbed, U extends EmbedProps, V extends ViewConfig>(
|
|
24
14
|
EmbedConstructor: T,
|
|
25
|
-
) =>
|
|
26
|
-
React.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const { viewConfig, listeners } = getViewPropsAndListeners<
|
|
15
|
+
) => React.forwardRef<TsEmbed, U>(
|
|
16
|
+
(props: U, forwardedRef: React.MutableRefObject<TsEmbed>) => {
|
|
17
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
18
|
+
const { className, ...embedProps } = props;
|
|
19
|
+
const { viewConfig, listeners } = getViewPropsAndListeners<
|
|
31
20
|
Omit<U, 'className'>,
|
|
32
21
|
V
|
|
33
22
|
>(embedProps);
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
useDeepCompareEffect(() => {
|
|
24
|
+
const tsEmbed = new EmbedConstructor(
|
|
36
25
|
ref!.current,
|
|
37
26
|
deepMerge(
|
|
38
27
|
{
|
|
39
28
|
insertAsSibling: viewConfig.insertAsSibling,
|
|
40
29
|
frameParams: {
|
|
41
|
-
class:
|
|
30
|
+
class: viewConfig.insertAsSibling
|
|
31
|
+
? className || ''
|
|
32
|
+
: '',
|
|
42
33
|
},
|
|
43
34
|
},
|
|
44
35
|
viewConfig,
|
|
45
36
|
),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
);
|
|
38
|
+
Object.keys(listeners).forEach((eventName) => {
|
|
39
|
+
tsEmbed.on(
|
|
49
40
|
eventName as EmbedEvent,
|
|
50
41
|
listeners[eventName as EmbedEvent],
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
tsEmbed.render();
|
|
45
|
+
if (forwardedRef) {
|
|
46
|
+
// eslint-disable-next-line no-param-reassign
|
|
47
|
+
forwardedRef.current = tsEmbed;
|
|
48
|
+
}
|
|
49
|
+
return () => {
|
|
50
|
+
tsEmbed.destroy();
|
|
51
|
+
};
|
|
52
|
+
}, [viewConfig, listeners]);
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
return (
|
|
55
|
+
(viewConfig.insertAsSibling)
|
|
56
|
+
? <span
|
|
65
57
|
data-testid="tsEmbed"
|
|
66
58
|
ref={ref}
|
|
67
59
|
style={{ position: 'absolute' }}
|
|
68
60
|
></span>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
: <div
|
|
62
|
+
data-testid="tsEmbed"
|
|
63
|
+
ref={ref}
|
|
64
|
+
className={className}>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
);
|
|
72
69
|
|
|
73
70
|
interface SearchProps extends EmbedProps, SearchViewConfig {}
|
|
74
71
|
|
|
75
|
-
export const SearchEmbed = componentFactory<
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
SearchViewConfig
|
|
79
|
-
>(_SearchEmbed);
|
|
72
|
+
export const SearchEmbed = componentFactory<typeof _SearchEmbed, SearchProps, SearchViewConfig>(
|
|
73
|
+
_SearchEmbed,
|
|
74
|
+
);
|
|
80
75
|
|
|
81
76
|
interface AppProps extends EmbedProps, AppViewConfig {}
|
|
82
77
|
|
|
83
|
-
export const AppEmbed = componentFactory<
|
|
84
|
-
typeof _AppEmbed,
|
|
85
|
-
AppProps,
|
|
86
|
-
AppViewConfig
|
|
87
|
-
>(_AppEmbed);
|
|
78
|
+
export const AppEmbed = componentFactory<typeof _AppEmbed, AppProps, AppViewConfig>(_AppEmbed);
|
|
88
79
|
|
|
89
80
|
interface LiveboardProps extends EmbedProps, LiveboardViewConfig {}
|
|
90
81
|
|
|
@@ -108,6 +99,4 @@ export const SearchBarEmbed = componentFactory<
|
|
|
108
99
|
SearchBarViewConfig
|
|
109
100
|
>(_SearchBarEmbed);
|
|
110
101
|
|
|
111
|
-
export const useEmbedRef = (): React.MutableRefObject<TsEmbed> =>
|
|
112
|
-
return React.useRef<TsEmbed>(null);
|
|
113
|
-
};
|
|
102
|
+
export const useEmbedRef = (): React.MutableRefObject<TsEmbed> => React.useRef<TsEmbed>(null);
|
package/src/react/util.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { EmbedEvent, MessageCallback, ViewConfig } from '../types';
|
|
2
2
|
|
|
3
|
-
// eslint-disable-next-line prettier/prettier
|
|
4
3
|
export type EmbedEventHandlers = { [key in keyof typeof EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback };
|
|
5
4
|
|
|
6
|
-
|
|
7
5
|
export interface EmbedProps extends ViewConfig, EmbedEventHandlers {
|
|
8
6
|
className?: string;
|
|
9
7
|
}
|
|
@@ -13,7 +11,13 @@ export interface ViewConfigAndListeners<T extends ViewConfig> {
|
|
|
13
11
|
listeners: { [key in EmbedEvent]?: MessageCallback };
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param props
|
|
17
|
+
*/
|
|
18
|
+
export function getViewPropsAndListeners<
|
|
19
|
+
T extends EmbedProps,
|
|
20
|
+
U extends ViewConfig>(props: T): ViewConfigAndListeners<U> {
|
|
17
21
|
return Object.keys(props).reduce(
|
|
18
22
|
(accu, key) => {
|
|
19
23
|
if (key.startsWith('on')) {
|
|
@@ -29,4 +33,4 @@ export function getViewPropsAndListeners<T extends EmbedProps, U extends ViewCon
|
|
|
29
33
|
listeners: {},
|
|
30
34
|
},
|
|
31
35
|
);
|
|
32
|
-
}
|
|
36
|
+
}
|
package/src/test/test-utils.ts
CHANGED
|
@@ -3,18 +3,15 @@ import { Action, AuthType } from '../types';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
Initialises fetch to the global object
|
|
6
|
-
*/
|
|
7
|
-
global.fetch = jest.fn(() =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}),
|
|
11
|
-
);
|
|
6
|
+
*/
|
|
7
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
8
|
+
json: () => ({ mixpanelAccessToken: '' }),
|
|
9
|
+
}));
|
|
12
10
|
|
|
13
11
|
export const defaultParamsWithoutHiddenActions = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=${AuthType.None}`;
|
|
14
12
|
export const defaultParams = `&${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22]`;
|
|
15
13
|
export const defaultParamsForPinboardEmbed = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=None&hideAction=[%22${Action.ReportError}%22]`;
|
|
16
|
-
export const getDocumentBody = () =>
|
|
17
|
-
'<div id="embed"></div><div id="embed-2"></div>';
|
|
14
|
+
export const getDocumentBody = () => '<div id="embed"></div><div id="embed-2"></div>';
|
|
18
15
|
|
|
19
16
|
type DOMElement = HTMLElement | Document;
|
|
20
17
|
|
|
@@ -22,40 +19,33 @@ export const getRootEl = () => document.getElementById('embed');
|
|
|
22
19
|
|
|
23
20
|
export const getRootEl2 = () => document.getElementById('embed-2');
|
|
24
21
|
|
|
25
|
-
export const getIFrameEl = (container: DOMElement = document) =>
|
|
26
|
-
return container.querySelector('iframe');
|
|
27
|
-
};
|
|
22
|
+
export const getIFrameEl = (container: DOMElement = document) => container.querySelector('iframe');
|
|
28
23
|
|
|
29
24
|
export const getAllIframeEl = () => document.querySelectorAll('iframe');
|
|
30
25
|
|
|
31
|
-
export const getIFrameSrc = (container: DOMElement = document) =>
|
|
32
|
-
getIFrameEl(container).src;
|
|
26
|
+
export const getIFrameSrc = (container: DOMElement = document) => getIFrameEl(container).src;
|
|
33
27
|
|
|
34
|
-
export const waitFor = (fn: () => boolean): Promise<void> => {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
};
|
|
28
|
+
export const waitFor = (fn: () => boolean): Promise<void> => new Promise((resolve) => {
|
|
29
|
+
const interval = setInterval(() => {
|
|
30
|
+
const value = fn();
|
|
31
|
+
if (value) {
|
|
32
|
+
clearInterval(interval);
|
|
33
|
+
resolve();
|
|
34
|
+
}
|
|
35
|
+
}, 100);
|
|
36
|
+
});
|
|
45
37
|
|
|
46
38
|
/**
|
|
47
39
|
* jsdom does not set event source, therefore we do it
|
|
48
40
|
* programmatically and use dispatchEvent instead of the
|
|
49
41
|
* postMessage API
|
|
50
42
|
* Reference: https://github.com/jsdom/jsdom/issues/2745
|
|
43
|
+
*
|
|
51
44
|
* @param window
|
|
52
45
|
* @param data
|
|
46
|
+
* @param port
|
|
53
47
|
*/
|
|
54
|
-
export const postMessageToParent = (
|
|
55
|
-
window: WindowProxy,
|
|
56
|
-
data: any,
|
|
57
|
-
port?: any,
|
|
58
|
-
) => {
|
|
48
|
+
export const postMessageToParent = (window: WindowProxy, data: any, port?: any) => {
|
|
59
49
|
const message = new MessageEvent('message', {
|
|
60
50
|
data,
|
|
61
51
|
source: window,
|
|
@@ -66,33 +56,37 @@ export const postMessageToParent = (
|
|
|
66
56
|
|
|
67
57
|
/**
|
|
68
58
|
* Execute a given function after a certain time has elapsed
|
|
59
|
+
*
|
|
69
60
|
* @param fn The function to be executed after the wait period
|
|
70
61
|
* @param waitTime The wait period in milliseconds
|
|
71
62
|
*/
|
|
72
63
|
export const executeAfterWait = (
|
|
73
64
|
fn: (...args: any[]) => void,
|
|
74
65
|
waitTime = 0,
|
|
75
|
-
) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
};
|
|
66
|
+
) => new Promise((resolve, reject) => {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
const value = fn();
|
|
69
|
+
resolve(value);
|
|
70
|
+
}, waitTime);
|
|
71
|
+
});
|
|
83
72
|
|
|
84
73
|
/**
|
|
85
74
|
* Time (in milliseconds) to wait for async events to be triggered
|
|
86
75
|
*/
|
|
87
76
|
export const EVENT_WAIT_TIME = 1000;
|
|
88
77
|
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param str
|
|
81
|
+
*/
|
|
89
82
|
export function fixedEncodeURI(str: string) {
|
|
90
83
|
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
|
|
91
84
|
}
|
|
92
85
|
|
|
93
86
|
/**
|
|
94
|
-
* MessageChannel is available in Node > 15.0.0. Since the current node
|
|
95
|
-
* used for github actions is not above 14, we are mocking this
|
|
87
|
+
* MessageChannel is available in Node > 15.0.0. Since the current node
|
|
88
|
+
* environment's used for github actions is not above 14, we are mocking this
|
|
89
|
+
* for the current unit tests.
|
|
96
90
|
*/
|
|
97
91
|
export const messageChannelMock: any = {
|
|
98
92
|
port1: {},
|
|
@@ -105,3 +99,13 @@ export const mockMessageChannel = () => {
|
|
|
105
99
|
return messageChannelMock;
|
|
106
100
|
} as any;
|
|
107
101
|
};
|
|
102
|
+
|
|
103
|
+
export const expectUrlMatchesWithParams = (source: string, target: string) => {
|
|
104
|
+
const sourceUrl = new URL(source);
|
|
105
|
+
const targetUrl = new URL(target);
|
|
106
|
+
expect(sourceUrl.origin).toBe(targetUrl.origin);
|
|
107
|
+
expect(sourceUrl.pathname).toBe(targetUrl.pathname);
|
|
108
|
+
const sourceParamsObj = Object.fromEntries(sourceUrl.searchParams);
|
|
109
|
+
const targetParamsObj = Object.fromEntries(targetUrl.searchParams);
|
|
110
|
+
expect(sourceParamsObj).toMatchObject(targetParamsObj);
|
|
111
|
+
};
|