@parafin/react 0.0.1
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/README.md +3 -0
- package/index.tsx +122 -0
- package/out/index.d.ts +32 -0
- package/out/index.js +78 -0
- package/package.json +20 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
package/index.tsx
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { openParafinDashboard } from '@parafin/core'
|
|
3
|
+
|
|
4
|
+
export { openParafinDashboard } from '@parafin/core'
|
|
5
|
+
|
|
6
|
+
export type OptInFields = {
|
|
7
|
+
businessExternalId: string
|
|
8
|
+
legalBusinessName: string
|
|
9
|
+
dbaName?: string
|
|
10
|
+
ownerFirstName: string
|
|
11
|
+
ownerLastName: string
|
|
12
|
+
accountManagers?: {
|
|
13
|
+
name: string
|
|
14
|
+
email: string
|
|
15
|
+
}[]
|
|
16
|
+
routingNumber?: string
|
|
17
|
+
accountNumberLastFour: string
|
|
18
|
+
email: string
|
|
19
|
+
phoneNumber: string
|
|
20
|
+
address: {
|
|
21
|
+
addressLine1: string
|
|
22
|
+
addressLine2?: string
|
|
23
|
+
city: string
|
|
24
|
+
state: string
|
|
25
|
+
postalCode: string
|
|
26
|
+
country: string
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const ParafinWidget = (props: {
|
|
31
|
+
token: string
|
|
32
|
+
product: 'capital' | 'banking'
|
|
33
|
+
externalBusinessId?: string
|
|
34
|
+
onExit?: () => void
|
|
35
|
+
onOptIn?: () => Promise<OptInFields>
|
|
36
|
+
environment?: string
|
|
37
|
+
}) => {
|
|
38
|
+
try {
|
|
39
|
+
const iframeRef = useRef<HTMLIFrameElement>(null)
|
|
40
|
+
const [iframeKey, setIframeKey] = useState(0)
|
|
41
|
+
const [iframeHeight, setIframeHeight] = useState('200px')
|
|
42
|
+
const [borderColor, setBorderColor] = useState('#E8E8E8')
|
|
43
|
+
const [borderRadius, setBorderRadius] = useState('16px')
|
|
44
|
+
|
|
45
|
+
const getBaseUrl = () => {
|
|
46
|
+
switch (props.environment) {
|
|
47
|
+
case 'local':
|
|
48
|
+
return 'http://localhost:9090'
|
|
49
|
+
case 'development':
|
|
50
|
+
return 'https://widget.dev.parafin.com'
|
|
51
|
+
default:
|
|
52
|
+
return 'https://widget.parafin.com'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const baseUrl = getBaseUrl()
|
|
57
|
+
const token = `?token=${props.token}`
|
|
58
|
+
const product = `&product=${props.product}`
|
|
59
|
+
const hasOptIn = `&hasOptIn=${props.onOptIn ? 'true' : 'false'}`
|
|
60
|
+
const host = `&host=${window.location.origin}`
|
|
61
|
+
const externalBusinessId = props.externalBusinessId
|
|
62
|
+
? `&external_business_id=${props.externalBusinessId}`
|
|
63
|
+
: ''
|
|
64
|
+
|
|
65
|
+
const messageListener = async ({ data, origin }: MessageEvent) => {
|
|
66
|
+
if (origin === baseUrl) {
|
|
67
|
+
switch (data?.message) {
|
|
68
|
+
case 'set-border':
|
|
69
|
+
if (data?.borderColor) setBorderColor(data.borderColor)
|
|
70
|
+
if (data?.borderRadius) setBorderRadius(data.borderRadius)
|
|
71
|
+
break
|
|
72
|
+
case 'open-dashboard':
|
|
73
|
+
openParafinDashboard({
|
|
74
|
+
...props,
|
|
75
|
+
route: data?.route,
|
|
76
|
+
onExit: () => {
|
|
77
|
+
setIframeKey((key) => key + 1)
|
|
78
|
+
props.onExit?.()
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
break
|
|
82
|
+
case 'opt-in':
|
|
83
|
+
if (props.onOptIn) {
|
|
84
|
+
const optInFields = await props.onOptIn()
|
|
85
|
+
iframeRef?.current?.contentWindow?.postMessage(
|
|
86
|
+
{ message: 'opt-in', optInFields: optInFields },
|
|
87
|
+
baseUrl
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
break
|
|
91
|
+
case 'set-height':
|
|
92
|
+
if (data?.height) setIframeHeight(data.height)
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
window.addEventListener('message', messageListener)
|
|
100
|
+
return () => window.removeEventListener('message', messageListener)
|
|
101
|
+
}, [])
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<iframe
|
|
105
|
+
key={iframeKey}
|
|
106
|
+
ref={iframeRef}
|
|
107
|
+
id={`parafin-${product}-widget`}
|
|
108
|
+
src={`${baseUrl}${token}${product}${hasOptIn}${host}${externalBusinessId}`}
|
|
109
|
+
style={{
|
|
110
|
+
width: '100%',
|
|
111
|
+
height: iframeHeight,
|
|
112
|
+
backgroundColor: '#fff',
|
|
113
|
+
border: `1px solid ${borderColor}`,
|
|
114
|
+
borderRadius: borderRadius,
|
|
115
|
+
boxSizing: 'border-box',
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
)
|
|
119
|
+
} catch {
|
|
120
|
+
console.error('Error loading Parafin widget')
|
|
121
|
+
}
|
|
122
|
+
}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { openParafinDashboard } from '@parafin/core';
|
|
2
|
+
export type OptInFields = {
|
|
3
|
+
businessExternalId: string;
|
|
4
|
+
legalBusinessName: string;
|
|
5
|
+
dbaName?: string;
|
|
6
|
+
ownerFirstName: string;
|
|
7
|
+
ownerLastName: string;
|
|
8
|
+
accountManagers?: {
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
}[];
|
|
12
|
+
routingNumber?: string;
|
|
13
|
+
accountNumberLastFour: string;
|
|
14
|
+
email: string;
|
|
15
|
+
phoneNumber: string;
|
|
16
|
+
address: {
|
|
17
|
+
addressLine1: string;
|
|
18
|
+
addressLine2?: string;
|
|
19
|
+
city: string;
|
|
20
|
+
state: string;
|
|
21
|
+
postalCode: string;
|
|
22
|
+
country: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const ParafinWidget: (props: {
|
|
26
|
+
token: string;
|
|
27
|
+
product: 'capital' | 'banking';
|
|
28
|
+
externalBusinessId?: string;
|
|
29
|
+
onExit?: () => void;
|
|
30
|
+
onOptIn?: () => Promise<OptInFields>;
|
|
31
|
+
environment?: string;
|
|
32
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
package/out/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { openParafinDashboard } from '@parafin/core';
|
|
4
|
+
export { openParafinDashboard } from '@parafin/core';
|
|
5
|
+
export const ParafinWidget = (props) => {
|
|
6
|
+
try {
|
|
7
|
+
const iframeRef = useRef(null);
|
|
8
|
+
const [iframeKey, setIframeKey] = useState(0);
|
|
9
|
+
const [iframeHeight, setIframeHeight] = useState('200px');
|
|
10
|
+
const [borderColor, setBorderColor] = useState('#E8E8E8');
|
|
11
|
+
const [borderRadius, setBorderRadius] = useState('16px');
|
|
12
|
+
const getBaseUrl = () => {
|
|
13
|
+
switch (props.environment) {
|
|
14
|
+
case 'local':
|
|
15
|
+
return 'http://localhost:9090';
|
|
16
|
+
case 'development':
|
|
17
|
+
return 'https://widget.dev.parafin.com';
|
|
18
|
+
default:
|
|
19
|
+
return 'https://widget.parafin.com';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const baseUrl = getBaseUrl();
|
|
23
|
+
const token = `?token=${props.token}`;
|
|
24
|
+
const product = `&product=${props.product}`;
|
|
25
|
+
const hasOptIn = `&hasOptIn=${props.onOptIn ? 'true' : 'false'}`;
|
|
26
|
+
const host = `&host=${window.location.origin}`;
|
|
27
|
+
const externalBusinessId = props.externalBusinessId
|
|
28
|
+
? `&external_business_id=${props.externalBusinessId}`
|
|
29
|
+
: '';
|
|
30
|
+
const messageListener = async ({ data, origin }) => {
|
|
31
|
+
if (origin === baseUrl) {
|
|
32
|
+
switch (data?.message) {
|
|
33
|
+
case 'set-border':
|
|
34
|
+
if (data?.borderColor)
|
|
35
|
+
setBorderColor(data.borderColor);
|
|
36
|
+
if (data?.borderRadius)
|
|
37
|
+
setBorderRadius(data.borderRadius);
|
|
38
|
+
break;
|
|
39
|
+
case 'open-dashboard':
|
|
40
|
+
openParafinDashboard({
|
|
41
|
+
...props,
|
|
42
|
+
route: data?.route,
|
|
43
|
+
onExit: () => {
|
|
44
|
+
setIframeKey((key) => key + 1);
|
|
45
|
+
props.onExit?.();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
case 'opt-in':
|
|
50
|
+
if (props.onOptIn) {
|
|
51
|
+
const optInFields = await props.onOptIn();
|
|
52
|
+
iframeRef?.current?.contentWindow?.postMessage({ message: 'opt-in', optInFields: optInFields }, baseUrl);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'set-height':
|
|
56
|
+
if (data?.height)
|
|
57
|
+
setIframeHeight(data.height);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
window.addEventListener('message', messageListener);
|
|
64
|
+
return () => window.removeEventListener('message', messageListener);
|
|
65
|
+
}, []);
|
|
66
|
+
return (_jsx("iframe", { ref: iframeRef, id: `parafin-${product}-widget`, src: `${baseUrl}${token}${product}${hasOptIn}${host}${externalBusinessId}`, style: {
|
|
67
|
+
width: '100%',
|
|
68
|
+
height: iframeHeight,
|
|
69
|
+
backgroundColor: '#fff',
|
|
70
|
+
border: `1px solid ${borderColor}`,
|
|
71
|
+
borderRadius: borderRadius,
|
|
72
|
+
boxSizing: 'border-box',
|
|
73
|
+
} }, iframeKey));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
console.error('Error loading Parafin widget');
|
|
77
|
+
}
|
|
78
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parafin/react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Parafin React widget",
|
|
5
|
+
"author": "Parafin (https://www.parafin.com)",
|
|
6
|
+
"module": "out/index.js",
|
|
7
|
+
"types": "out/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/react": "^18.2.55",
|
|
14
|
+
"typescript": "^4.9.5"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@parafin/core": "^1.0.0",
|
|
18
|
+
"react": "^18.2.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"outDir": "./out",
|
|
12
|
+
"declarationDir": "./out"
|
|
13
|
+
},
|
|
14
|
+
"include": ["./index.tsx"]
|
|
15
|
+
}
|