@parafin/react 6.2.1-alpha.0 → 6.2.2
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 +3 -0
- package/out/index.js +17 -12
- package/package.json +1 -1
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
|
@@ -88,8 +88,8 @@ const initializeWidget = (iframe, props) => {
|
|
|
88
88
|
const iframeSrc = `${url.origin}?${new URLSearchParams(query).toString()}`;
|
|
89
89
|
iframe.id = `parafin-${props.product}-widget`;
|
|
90
90
|
iframe.src = iframeSrc;
|
|
91
|
-
const
|
|
92
|
-
iframe.contentWindow?.postMessage(
|
|
91
|
+
const sendMessage = (message) => {
|
|
92
|
+
iframe.contentWindow?.postMessage(message, url.origin);
|
|
93
93
|
};
|
|
94
94
|
const messageListener = async ({ data, origin }) => {
|
|
95
95
|
if (origin === url.origin && data?.product === props.product) {
|
|
@@ -114,39 +114,44 @@ const initializeWidget = (iframe, props) => {
|
|
|
114
114
|
break;
|
|
115
115
|
case 'opt-in':
|
|
116
116
|
if (props.onOptIn) {
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
try {
|
|
118
|
+
const optInFields = await props.onOptIn();
|
|
119
|
+
sendMessage({ message: 'opt-in', optInFields });
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
sendMessage({ message: 'opt-in', optInFields: undefined });
|
|
123
|
+
}
|
|
119
124
|
}
|
|
120
125
|
else {
|
|
121
|
-
|
|
126
|
+
sendMessage({ message: 'opt-in', optInFields: undefined });
|
|
122
127
|
}
|
|
123
128
|
break;
|
|
124
129
|
case 'person-opt-in':
|
|
125
130
|
if (props.onEvent) {
|
|
126
131
|
try {
|
|
127
132
|
await props.onEvent('opted_in');
|
|
128
|
-
|
|
133
|
+
sendMessage({ message: 'person-opt-in', state: 'success' });
|
|
129
134
|
}
|
|
130
135
|
catch {
|
|
131
|
-
|
|
136
|
+
sendMessage({ message: 'person-opt-in', state: 'error' });
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
else {
|
|
135
|
-
|
|
140
|
+
sendMessage({ message: 'person-opt-in', state: 'noop' });
|
|
136
141
|
}
|
|
137
142
|
break;
|
|
138
143
|
case 'person-opt-out':
|
|
139
144
|
if (props.onEvent) {
|
|
140
145
|
try {
|
|
141
|
-
await props.onEvent
|
|
142
|
-
|
|
146
|
+
await props.onEvent('opted_out');
|
|
147
|
+
sendMessage({ message: 'person-opt-out', state: 'success' });
|
|
143
148
|
}
|
|
144
149
|
catch {
|
|
145
|
-
|
|
150
|
+
sendMessage({ message: 'person-opt-out', state: 'error' });
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
else {
|
|
149
|
-
|
|
154
|
+
sendMessage({ message: 'person-opt-out', state: 'noop' });
|
|
150
155
|
}
|
|
151
156
|
break;
|
|
152
157
|
case 'set-height':
|