@parafin/core 2.1.0 → 2.2.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/index.ts +25 -15
- package/out/index.d.ts +1 -0
- package/out/index.js +26 -17
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
type BaseProps = ({ token: string } | { partner: string }) & {
|
|
2
2
|
dashboardTargetElementId?: string
|
|
3
|
+
onLinkOpened?: (url: string) => void
|
|
3
4
|
}
|
|
4
5
|
|
|
5
6
|
type CapitalOrSpendProps = {
|
|
@@ -86,25 +87,34 @@ export const openParafinDashboard = (
|
|
|
86
87
|
throw new Error('Dashboard target element not found')
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
const messageListener = async (event: MessageEvent) => {
|
|
91
|
+
if (event.origin === origin) {
|
|
92
|
+
switch (event.data?.message) {
|
|
93
|
+
case 'close-dashboard':
|
|
94
|
+
if ('orderId' in props) {
|
|
95
|
+
props.onExit?.(props.orderId)
|
|
96
|
+
} else if ('lineOfCreditApplicationId' in props) {
|
|
97
|
+
props.onExit?.(props.lineOfCreditApplicationId)
|
|
98
|
+
} else {
|
|
99
|
+
props.onExit?.()
|
|
100
|
+
}
|
|
101
|
+
window.removeEventListener('message', messageListener)
|
|
102
|
+
frame.style.opacity = '0'
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
dashboardTargetElement.removeChild(frame)
|
|
105
|
+
document.body.style.removeProperty('overflow')
|
|
106
|
+
}, 200)
|
|
107
|
+
break
|
|
108
|
+
case 'link-opened':
|
|
109
|
+
if (props.onLinkOpened && event.data?.url) {
|
|
110
|
+
props.onLinkOpened(event.data.url)
|
|
111
|
+
}
|
|
112
|
+
break
|
|
97
113
|
}
|
|
98
|
-
window.removeEventListener('message', closeParafinDashboard)
|
|
99
|
-
frame.style.opacity = '0'
|
|
100
|
-
setTimeout(() => {
|
|
101
|
-
dashboardTargetElement.removeChild(frame)
|
|
102
|
-
document.body.style.removeProperty('overflow')
|
|
103
|
-
}, 200)
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
|
|
107
|
-
window.addEventListener('message',
|
|
117
|
+
window.addEventListener('message', messageListener)
|
|
108
118
|
dashboardTargetElement.appendChild(frame)
|
|
109
119
|
setTimeout(() => {
|
|
110
120
|
frame.style.opacity = '1'
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -54,26 +54,35 @@ export const openParafinDashboard = (props) => {
|
|
|
54
54
|
if (!dashboardTargetElement) {
|
|
55
55
|
throw new Error('Dashboard target element not found');
|
|
56
56
|
}
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const messageListener = async (event) => {
|
|
58
|
+
if (event.origin === origin) {
|
|
59
|
+
switch (event.data?.message) {
|
|
60
|
+
case 'close-dashboard':
|
|
61
|
+
if ('orderId' in props) {
|
|
62
|
+
props.onExit?.(props.orderId);
|
|
63
|
+
}
|
|
64
|
+
else if ('lineOfCreditApplicationId' in props) {
|
|
65
|
+
props.onExit?.(props.lineOfCreditApplicationId);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
props.onExit?.();
|
|
69
|
+
}
|
|
70
|
+
window.removeEventListener('message', messageListener);
|
|
71
|
+
frame.style.opacity = '0';
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
dashboardTargetElement.removeChild(frame);
|
|
74
|
+
document.body.style.removeProperty('overflow');
|
|
75
|
+
}, 200);
|
|
76
|
+
break;
|
|
77
|
+
case 'link-opened':
|
|
78
|
+
if (props.onLinkOpened && event.data?.url) {
|
|
79
|
+
props.onLinkOpened(event.data.url);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
61
82
|
}
|
|
62
|
-
else if ('lineOfCreditApplicationId' in props) {
|
|
63
|
-
props.onExit?.(props.lineOfCreditApplicationId);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
props.onExit?.();
|
|
67
|
-
}
|
|
68
|
-
window.removeEventListener('message', closeParafinDashboard);
|
|
69
|
-
frame.style.opacity = '0';
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
dashboardTargetElement.removeChild(frame);
|
|
72
|
-
document.body.style.removeProperty('overflow');
|
|
73
|
-
}, 200);
|
|
74
83
|
}
|
|
75
84
|
};
|
|
76
|
-
window.addEventListener('message',
|
|
85
|
+
window.addEventListener('message', messageListener);
|
|
77
86
|
dashboardTargetElement.appendChild(frame);
|
|
78
87
|
setTimeout(() => {
|
|
79
88
|
frame.style.opacity = '1';
|