@parafin/react 6.1.0 → 6.2.1-alpha.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/out/index.d.ts +48 -2
- package/out/index.js +49 -11
- package/package.json +1 -1
package/out/index.d.ts
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
|
-
import { WidgetProps, OptInFields } from '@parafin/widget';
|
|
2
1
|
declare const ParafinWidget: (props: WidgetProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
2
|
export { ParafinWidget };
|
|
4
|
-
export type
|
|
3
|
+
export type WidgetProps = {
|
|
4
|
+
token: string;
|
|
5
|
+
product: 'capital' | 'spend_card' | 'cash_account';
|
|
6
|
+
externalBusinessId?: string;
|
|
7
|
+
onExit?: () => void;
|
|
8
|
+
onOptIn?: () => Promise<OptInFields>;
|
|
9
|
+
openInNewTab?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type USStates = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'DC' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY';
|
|
12
|
+
type USTerritories = 'AS' | 'GU' | 'MP' | 'PR' | 'VI';
|
|
13
|
+
type CanadianProvinces = 'AB' | 'BC' | 'MB' | 'NB' | 'NL' | 'NS' | 'QC' | 'ON' | 'PE' | 'SK';
|
|
14
|
+
type CanadianTerritories = 'NT' | 'NU' | 'YT';
|
|
15
|
+
type Address = {
|
|
16
|
+
addressLine1: string;
|
|
17
|
+
addressLine2?: string;
|
|
18
|
+
city: string;
|
|
19
|
+
state: USStates | USTerritories | CanadianProvinces | CanadianTerritories;
|
|
20
|
+
postalCode: string;
|
|
21
|
+
country: 'US' | 'CA';
|
|
22
|
+
};
|
|
23
|
+
export type OptInFields = {
|
|
24
|
+
businessExternalId: string;
|
|
25
|
+
accountManagers?: {
|
|
26
|
+
name: string;
|
|
27
|
+
email: string;
|
|
28
|
+
}[];
|
|
29
|
+
owner: {
|
|
30
|
+
firstName: string;
|
|
31
|
+
lastName: string;
|
|
32
|
+
email: string;
|
|
33
|
+
phoneNumber?: string;
|
|
34
|
+
/** yyyy-mm-dd */
|
|
35
|
+
dateOfBirth?: string;
|
|
36
|
+
address?: Address;
|
|
37
|
+
};
|
|
38
|
+
business: {
|
|
39
|
+
legalName: string;
|
|
40
|
+
dbaName?: string;
|
|
41
|
+
address?: Address;
|
|
42
|
+
/** yyyy-mm-dd */
|
|
43
|
+
dateEstablished?: string;
|
|
44
|
+
};
|
|
45
|
+
bank?: {
|
|
46
|
+
routingNumber?: string;
|
|
47
|
+
accountNumberLastFour?: string;
|
|
48
|
+
currencyCode?: 'USD' | 'CAD';
|
|
49
|
+
};
|
|
50
|
+
};
|
package/out/index.js
CHANGED
|
@@ -11,12 +11,13 @@ const openParafinDashboard = (props) => {
|
|
|
11
11
|
product: props.product,
|
|
12
12
|
referrer: 'partner',
|
|
13
13
|
...('token' in props && { token: props.token }),
|
|
14
|
+
...('partner' in props && { partner: props.partner }),
|
|
14
15
|
...('externalBusinessId' in props && {
|
|
15
16
|
externalBusinessId: props.externalBusinessId,
|
|
16
17
|
}),
|
|
17
18
|
...('orderId' in props && { orderId: props.orderId }),
|
|
18
|
-
...('
|
|
19
|
-
|
|
19
|
+
...('lineOfCreditApplicationId' in props && {
|
|
20
|
+
lineOfCreditApplicationId: props.lineOfCreditApplicationId,
|
|
20
21
|
}),
|
|
21
22
|
...('additionalQueryParams' in props && props.additionalQueryParams),
|
|
22
23
|
...Object.fromEntries(searchParams),
|
|
@@ -26,6 +27,10 @@ const openParafinDashboard = (props) => {
|
|
|
26
27
|
window.open(url, '_blank');
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
30
|
+
if ('mode' in props && props.mode === 'redirect') {
|
|
31
|
+
window.location.href = url;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
29
34
|
const existingParafinDashboard = document.getElementById('parafin-dashboard');
|
|
30
35
|
if (existingParafinDashboard) {
|
|
31
36
|
document.removeChild(existingParafinDashboard);
|
|
@@ -44,11 +49,13 @@ const openParafinDashboard = (props) => {
|
|
|
44
49
|
frame.style.transition = 'opacity 0.2s';
|
|
45
50
|
frame.src = url;
|
|
46
51
|
frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
|
|
47
|
-
const parse = (message) => (message ? JSON.parse(message) : undefined);
|
|
48
52
|
const closeParafinDashboard = (e) => {
|
|
49
53
|
if (e.origin === origin && e.data?.message === 'close-dashboard') {
|
|
50
|
-
if (
|
|
51
|
-
props.onExit(
|
|
54
|
+
if ('orderId' in props) {
|
|
55
|
+
props.onExit?.(props.orderId);
|
|
56
|
+
}
|
|
57
|
+
else if ('lineOfCreditApplicationId' in props) {
|
|
58
|
+
props.onExit?.(props.lineOfCreditApplicationId);
|
|
52
59
|
}
|
|
53
60
|
else {
|
|
54
61
|
props.onExit?.();
|
|
@@ -78,12 +85,12 @@ const initializeWidget = (iframe, props) => {
|
|
|
78
85
|
externalBusinessId: props.externalBusinessId ?? '',
|
|
79
86
|
...Object.fromEntries(url.searchParams),
|
|
80
87
|
};
|
|
88
|
+
const iframeSrc = `${url.origin}?${new URLSearchParams(query).toString()}`;
|
|
81
89
|
iframe.id = `parafin-${props.product}-widget`;
|
|
82
|
-
iframe.src =
|
|
83
|
-
const
|
|
84
|
-
iframe.
|
|
90
|
+
iframe.src = iframeSrc;
|
|
91
|
+
const sendMessageToWidget = (message, data) => {
|
|
92
|
+
iframe.contentWindow?.postMessage({ message, data }, url.origin);
|
|
85
93
|
};
|
|
86
|
-
// Message handler
|
|
87
94
|
const messageListener = async ({ data, origin }) => {
|
|
88
95
|
if (origin === url.origin && data?.product === props.product) {
|
|
89
96
|
switch (data?.message) {
|
|
@@ -100,7 +107,7 @@ const initializeWidget = (iframe, props) => {
|
|
|
100
107
|
...props,
|
|
101
108
|
route: data?.route,
|
|
102
109
|
onExit: () => {
|
|
103
|
-
|
|
110
|
+
iframe.src = iframeSrc;
|
|
104
111
|
props.onExit?.();
|
|
105
112
|
},
|
|
106
113
|
});
|
|
@@ -108,7 +115,38 @@ const initializeWidget = (iframe, props) => {
|
|
|
108
115
|
case 'opt-in':
|
|
109
116
|
if (props.onOptIn) {
|
|
110
117
|
const optInFields = await props.onOptIn();
|
|
111
|
-
|
|
118
|
+
sendMessageToWidget('opt-in', optInFields);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
sendMessageToWidget('opt-in', undefined);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'person-opt-in':
|
|
125
|
+
if (props.onEvent) {
|
|
126
|
+
try {
|
|
127
|
+
await props.onEvent('opted_in');
|
|
128
|
+
sendMessageToWidget('person-opt-in', { state: 'success' });
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
sendMessageToWidget('person-opt-in', { state: 'error' });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
sendMessageToWidget('person-opt-in', { state: 'noop' });
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case 'person-opt-out':
|
|
139
|
+
if (props.onEvent) {
|
|
140
|
+
try {
|
|
141
|
+
await props.onEvent?.('opted_out');
|
|
142
|
+
sendMessageToWidget('person-opt-out', { state: 'success' });
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
sendMessageToWidget('person-opt-out', { state: 'error' });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
sendMessageToWidget('person-opt-out', { state: 'noop' });
|
|
112
150
|
}
|
|
113
151
|
break;
|
|
114
152
|
case 'set-height':
|