@parafin/core 1.0.10 → 1.0.11
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/index.ts +21 -12
- package/out/index.d.ts +2 -1
- package/out/index.js +16 -11
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -5,9 +5,27 @@ const openParafinDashboard = (
|
|
|
5
5
|
route?: string
|
|
6
6
|
externalBusinessId?: string
|
|
7
7
|
onExit?: () => void
|
|
8
|
+
openInNewTab?: boolean
|
|
8
9
|
} & Record<string, any>
|
|
9
10
|
) => {
|
|
10
11
|
try {
|
|
12
|
+
const { origin, searchParams } = new URL(
|
|
13
|
+
props.dashboardUrlOverride ?? 'https://app.parafin.com'
|
|
14
|
+
)
|
|
15
|
+
const route = props.route ?? '/'
|
|
16
|
+
const query = {
|
|
17
|
+
token: props.token,
|
|
18
|
+
product: props.product,
|
|
19
|
+
externalBusinessId: props.externalBusinessId ?? '',
|
|
20
|
+
referrer: 'partner',
|
|
21
|
+
...Object.fromEntries(searchParams),
|
|
22
|
+
}
|
|
23
|
+
const url = `${origin}${route}?${new URLSearchParams(query).toString()}`
|
|
24
|
+
|
|
25
|
+
if (props.openInNewTab) {
|
|
26
|
+
return window.open(url, '_blank')
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
const existingParafinDashboard =
|
|
12
30
|
document.getElementById('parafin-dashboard')
|
|
13
31
|
if (existingParafinDashboard) {
|
|
@@ -26,18 +44,10 @@ const openParafinDashboard = (
|
|
|
26
44
|
frame.style.backgroundColor = '#fff'
|
|
27
45
|
frame.style.opacity = '0'
|
|
28
46
|
frame.style.transition = 'opacity 0.2s'
|
|
47
|
+
frame.src = url
|
|
29
48
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const query = {
|
|
33
|
-
token: props.token,
|
|
34
|
-
product: props.product,
|
|
35
|
-
externalBusinessId: props.externalBusinessId ?? '',
|
|
36
|
-
...Object.fromEntries(url.searchParams),
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const closeParafinDashboard = ({ data, origin }: MessageEvent) => {
|
|
40
|
-
if (origin === url.origin && data?.message === 'close-dashboard') {
|
|
49
|
+
const closeParafinDashboard = (e: MessageEvent) => {
|
|
50
|
+
if (e.origin === origin && e.data?.message === 'close-dashboard') {
|
|
41
51
|
props.onExit?.()
|
|
42
52
|
window.removeEventListener('message', closeParafinDashboard)
|
|
43
53
|
frame.style.opacity = '0'
|
|
@@ -45,7 +55,6 @@ const openParafinDashboard = (
|
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`
|
|
49
58
|
window.addEventListener('message', closeParafinDashboard)
|
|
50
59
|
document.body.appendChild(frame)
|
|
51
60
|
setTimeout(() => (frame.style.opacity = '1'), 1)
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
const openParafinDashboard = (props) => {
|
|
2
2
|
try {
|
|
3
|
+
const { origin, searchParams } = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com');
|
|
4
|
+
const route = props.route ?? '/';
|
|
5
|
+
const query = {
|
|
6
|
+
token: props.token,
|
|
7
|
+
product: props.product,
|
|
8
|
+
externalBusinessId: props.externalBusinessId ?? '',
|
|
9
|
+
referrer: 'partner',
|
|
10
|
+
...Object.fromEntries(searchParams),
|
|
11
|
+
};
|
|
12
|
+
const url = `${origin}${route}?${new URLSearchParams(query).toString()}`;
|
|
13
|
+
if (props.openInNewTab) {
|
|
14
|
+
return window.open(url, '_blank');
|
|
15
|
+
}
|
|
3
16
|
const existingParafinDashboard = document.getElementById('parafin-dashboard');
|
|
4
17
|
if (existingParafinDashboard) {
|
|
5
18
|
document.removeChild(existingParafinDashboard);
|
|
@@ -16,23 +29,15 @@ const openParafinDashboard = (props) => {
|
|
|
16
29
|
frame.style.backgroundColor = '#fff';
|
|
17
30
|
frame.style.opacity = '0';
|
|
18
31
|
frame.style.transition = 'opacity 0.2s';
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
token: props.token,
|
|
23
|
-
product: props.product,
|
|
24
|
-
externalBusinessId: props.externalBusinessId ?? '',
|
|
25
|
-
...Object.fromEntries(url.searchParams),
|
|
26
|
-
};
|
|
27
|
-
const closeParafinDashboard = ({ data, origin }) => {
|
|
28
|
-
if (origin === url.origin && data?.message === 'close-dashboard') {
|
|
32
|
+
frame.src = url;
|
|
33
|
+
const closeParafinDashboard = (e) => {
|
|
34
|
+
if (e.origin === origin && e.data?.message === 'close-dashboard') {
|
|
29
35
|
props.onExit?.();
|
|
30
36
|
window.removeEventListener('message', closeParafinDashboard);
|
|
31
37
|
frame.style.opacity = '0';
|
|
32
38
|
setTimeout(() => document.body.removeChild(frame), 200);
|
|
33
39
|
}
|
|
34
40
|
};
|
|
35
|
-
frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`;
|
|
36
41
|
window.addEventListener('message', closeParafinDashboard);
|
|
37
42
|
document.body.appendChild(frame);
|
|
38
43
|
setTimeout(() => (frame.style.opacity = '1'), 1);
|