@parafin/react 6.2.1 → 6.2.3

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/out/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  declare const ParafinWidget: (props: WidgetProps) => import("react/jsx-runtime").JSX.Element;
2
2
  export { ParafinWidget };
3
+ export type WidgetEvent = 'opted_in' | 'opted_out';
3
4
  export type WidgetProps = {
4
5
  token: string;
5
6
  product: 'capital' | 'spend_card' | 'cash_account';
6
7
  externalBusinessId?: string;
8
+ onEvent?: (eventType: WidgetEvent) => Promise<void> | void;
7
9
  onExit?: () => void;
10
+ /** @deprecated Use onEvent with 'opted_in' event type instead */
8
11
  onOptIn?: () => Promise<OptInFields>;
9
12
  openInNewTab?: boolean;
10
13
  };
package/out/index.js CHANGED
@@ -37,9 +37,11 @@ const openParafinDashboard = (props) => {
37
37
  }
38
38
  const frame = document.createElement('iframe');
39
39
  frame.id = 'parafin-dashboard';
40
- frame.style.position = 'fixed';
41
- frame.style.top = '0';
42
- frame.style.left = '0';
40
+ if (!props.dashboardTargetElementId) {
41
+ frame.style.position = 'fixed';
42
+ frame.style.top = '0';
43
+ frame.style.left = '0';
44
+ }
43
45
  frame.style.width = '100%';
44
46
  frame.style.height = '100%';
45
47
  frame.style.border = 'none';
@@ -49,6 +51,12 @@ const openParafinDashboard = (props) => {
49
51
  frame.style.transition = 'opacity 0.2s';
50
52
  frame.src = url;
51
53
  frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
54
+ const dashboardTargetElement = props.dashboardTargetElementId
55
+ ? document.getElementById(props.dashboardTargetElementId)
56
+ : document.body;
57
+ if (!dashboardTargetElement) {
58
+ throw new Error('Dashboard target element not found');
59
+ }
52
60
  const closeParafinDashboard = (e) => {
53
61
  if (e.origin === origin && e.data?.message === 'close-dashboard') {
54
62
  if ('orderId' in props) {
@@ -62,12 +70,18 @@ const openParafinDashboard = (props) => {
62
70
  }
63
71
  window.removeEventListener('message', closeParafinDashboard);
64
72
  frame.style.opacity = '0';
65
- setTimeout(() => document.body.removeChild(frame), 200);
73
+ setTimeout(() => {
74
+ dashboardTargetElement.removeChild(frame);
75
+ document.body.style.removeProperty('overflow');
76
+ }, 200);
66
77
  }
67
78
  };
68
79
  window.addEventListener('message', closeParafinDashboard);
69
- document.body.appendChild(frame);
70
- setTimeout(() => (frame.style.opacity = '1'), 1);
80
+ dashboardTargetElement.appendChild(frame);
81
+ setTimeout(() => {
82
+ frame.style.opacity = '1';
83
+ document.body.style.overflow = 'hidden';
84
+ }, 1);
71
85
  }
72
86
  catch (error) {
73
87
  console.error('Error loading Parafin dashboard', error);
@@ -114,8 +128,13 @@ const initializeWidget = (iframe, props) => {
114
128
  break;
115
129
  case 'opt-in':
116
130
  if (props.onOptIn) {
117
- const optInFields = await props.onOptIn();
118
- sendMessage({ message: 'opt-in', optInFields });
131
+ try {
132
+ const optInFields = await props.onOptIn();
133
+ sendMessage({ message: 'opt-in', optInFields });
134
+ }
135
+ catch {
136
+ sendMessage({ message: 'opt-in', optInFields: undefined });
137
+ }
119
138
  }
120
139
  else {
121
140
  sendMessage({ message: 'opt-in', optInFields: undefined });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/react",
3
- "version": "6.2.1",
3
+ "version": "6.2.3",
4
4
  "description": "Parafin React widget",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",