@parafin/react 5.0.0 → 6.0.0-alpha.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/index.tsx CHANGED
@@ -1,194 +1,23 @@
1
- import { useEffect, useRef, useState } from 'react'
2
- import { openParafinDashboard } from '@parafin/core'
3
-
4
- const ParafinWidget = (
5
- props: {
6
- token: string
7
- product: 'capital' | 'wallet'
8
- externalBusinessId?: string
9
- onExit?: () => void
10
- onOptIn?: () => Promise<OptInFields>
11
- openInNewTab?: boolean
12
- } & Record<string, any>
13
- ) => {
1
+ import { useEffect, useRef } from 'react'
2
+ import {
3
+ initializeWidget,
4
+ defaultWidgetStyles,
5
+ WidgetProps,
6
+ OptInFields,
7
+ } from '@parafin/widget'
8
+
9
+ const ParafinWidget = (props: WidgetProps) => {
14
10
  const frameRef = useRef<HTMLIFrameElement>(null)
15
- const [frameKey, setFrameKey] = useState(0)
16
- const [frameHeight, setFrameHeight] = useState('258px')
17
- const [borderColor, setBorderColor] = useState('#E8E8E8')
18
- const [borderRadius, setBorderRadius] = useState('16px')
19
-
20
- const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com')
21
- const query = {
22
- token: props.token,
23
- product: props.product,
24
- hasOptIn: props.onOptIn ? 'true' : 'false',
25
- host: window.location.origin,
26
- externalBusinessId: props.externalBusinessId ?? '',
27
- ...Object.fromEntries(url.searchParams),
28
- }
29
-
30
- const messageListener = async ({ data, origin }: MessageEvent) => {
31
- if (origin === url.origin && data?.product === props.product) {
32
- switch (data?.message) {
33
- case 'set-border':
34
- if (data?.borderColor) setBorderColor(data.borderColor)
35
- if (data?.borderRadius) setBorderRadius(data.borderRadius)
36
- break
37
- case 'open-dashboard':
38
- openParafinDashboard({
39
- ...props,
40
- route: data?.route,
41
- onExit: () => {
42
- setFrameKey((key) => key + 1)
43
- props.onExit?.()
44
- },
45
- })
46
- break
47
- case 'opt-in':
48
- if (props.onOptIn) {
49
- const optInFields = await props.onOptIn()
50
- frameRef?.current?.contentWindow?.postMessage(
51
- { message: 'opt-in', optInFields: optInFields },
52
- url.origin
53
- )
54
- }
55
- break
56
- case 'set-height':
57
- if (data?.height) setFrameHeight(data.height)
58
- break
59
- }
60
- }
61
- }
62
11
 
63
12
  useEffect(() => {
64
- window.addEventListener('message', messageListener)
65
- return () => window.removeEventListener('message', messageListener)
66
- }, [])
67
-
68
- return (
69
- <iframe
70
- key={frameKey}
71
- ref={frameRef}
72
- id={`parafin-${props.product}-widget`}
73
- src={`${url.origin}?${new URLSearchParams(query).toString()}`}
74
- style={{
75
- width: '100%',
76
- height: frameHeight,
77
- backgroundColor: '#fff',
78
- border: `1px solid ${borderColor}`,
79
- borderRadius: borderRadius,
80
- transition: 'border 0.2s, border-radius 0.2s',
81
- boxSizing: 'border-box',
82
- }}
83
- />
84
- )
85
- }
86
-
87
- export { OptInFields, ParafinWidget }
88
-
89
- type USStates =
90
- | 'AL'
91
- | 'AK'
92
- | 'AZ'
93
- | 'AR'
94
- | 'CA'
95
- | 'CO'
96
- | 'CT'
97
- | 'DE'
98
- | 'DC'
99
- | 'FL'
100
- | 'GA'
101
- | 'HI'
102
- | 'ID'
103
- | 'IL'
104
- | 'IN'
105
- | 'IA'
106
- | 'KS'
107
- | 'KY'
108
- | 'LA'
109
- | 'ME'
110
- | 'MD'
111
- | 'MA'
112
- | 'MI'
113
- | 'MN'
114
- | 'MS'
115
- | 'MO'
116
- | 'MT'
117
- | 'NE'
118
- | 'NV'
119
- | 'NH'
120
- | 'NJ'
121
- | 'NM'
122
- | 'NY'
123
- | 'NC'
124
- | 'ND'
125
- | 'OH'
126
- | 'OK'
127
- | 'OR'
128
- | 'PA'
129
- | 'RI'
130
- | 'SC'
131
- | 'SD'
132
- | 'TN'
133
- | 'TX'
134
- | 'UT'
135
- | 'VT'
136
- | 'VA'
137
- | 'WA'
138
- | 'WV'
139
- | 'WI'
140
- | 'WY'
141
-
142
- type USTerritories = 'AS' | 'GU' | 'MP' | 'PR' | 'VI'
143
-
144
- type CanadianProvinces =
145
- | 'AB'
146
- | 'BC'
147
- | 'MB'
148
- | 'NB'
149
- | 'NL'
150
- | 'NS'
151
- | 'QC'
152
- | 'ON'
153
- | 'PE'
154
- | 'SK'
155
-
156
- type CanadianTerritories = 'NT' | 'NU' | 'YT'
13
+ if (frameRef.current) {
14
+ const cleanup = initializeWidget(frameRef.current, props)
15
+ return cleanup
16
+ }
17
+ }, [props])
157
18
 
158
- type Address = {
159
- addressLine1: string
160
- addressLine2?: string
161
- city: string
162
- state: USStates | USTerritories | CanadianProvinces | CanadianTerritories
163
- postalCode: string
164
- country: 'US' | 'CA'
19
+ return <iframe ref={frameRef} style={defaultWidgetStyles} />
165
20
  }
166
21
 
167
- type OptInFields = {
168
- businessExternalId: string
169
- accountManagers?: {
170
- name: string
171
- email: string
172
- }[]
173
- owner: {
174
- firstName: string
175
- lastName: string
176
- email: string
177
- phoneNumber?: string
178
- /** yyyy-mm-dd */
179
- dateOfBirth?: string
180
- address?: Address
181
- }
182
- business: {
183
- legalName: string
184
- dbaName?: string
185
- address?: Address
186
- /** yyyy-mm-dd */
187
- dateEstablished?: string
188
- }
189
- bank?: {
190
- routingNumber?: string
191
- accountNumberLastFour?: string
192
- currencyCode?: 'USD' | 'CAD'
193
- }
194
- }
22
+ export { ParafinWidget }
23
+ export type { OptInFields }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@parafin/react",
3
- "version": "5.0.0",
3
+ "version": "6.0.0-alpha.1",
4
4
  "description": "Parafin React widget",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",
7
7
  "types": "out/index.d.ts",
8
+ "type": "module",
8
9
  "license": "MIT",
9
10
  "scripts": {
10
- "build": "tsc"
11
+ "build": "npx rollup -c",
12
+ "dev": "npx rollup -c -w"
11
13
  },
12
14
  "peerDependencies": {
13
15
  "react": ">=16.8.0"
@@ -17,6 +19,6 @@
17
19
  "typescript": "^4.9.5"
18
20
  },
19
21
  "dependencies": {
20
- "@parafin/core": "^1.0.12"
22
+ "@parafin/widget": "*"
21
23
  }
22
24
  }
@@ -0,0 +1,34 @@
1
+ import resolve from '@rollup/plugin-node-resolve'
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import typescript from '@rollup/plugin-typescript'
4
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external'
5
+ import { fileURLToPath } from 'url'
6
+ import { dirname } from 'path'
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = dirname(__filename)
10
+
11
+ export default {
12
+ input: './index.tsx',
13
+ output: [
14
+ {
15
+ file: './out/index.js',
16
+ format: 'esm',
17
+ sourcemap: false,
18
+ },
19
+ ],
20
+ external: ['react', 'react-dom'],
21
+ plugins: [
22
+ peerDepsExternal(),
23
+ resolve({
24
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
25
+ }),
26
+ commonjs(),
27
+ typescript({
28
+ tsconfig: `${__dirname}/tsconfig.json`,
29
+ declaration: true,
30
+ declarationDir: './out',
31
+ rootDir: './',
32
+ }),
33
+ ],
34
+ }
package/tsconfig.json CHANGED
@@ -9,7 +9,11 @@
9
9
  "forceConsistentCasingInFileNames": true,
10
10
  "declaration": true,
11
11
  "outDir": "./out",
12
- "declarationDir": "./out"
12
+ "declarationDir": "./out",
13
+ "isolatedModules": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "resolveJsonModule": true,
16
+ "strict": true
13
17
  },
14
18
  "include": ["./index.tsx"]
15
19
  }
package/out/index.d.ts DELETED
@@ -1,49 +0,0 @@
1
- declare const ParafinWidget: (props: {
2
- token: string;
3
- product: 'capital' | 'wallet';
4
- externalBusinessId?: string;
5
- onExit?: () => void;
6
- onOptIn?: () => Promise<OptInFields>;
7
- openInNewTab?: boolean;
8
- } & Record<string, any>) => import("react/jsx-runtime").JSX.Element;
9
- export { OptInFields, ParafinWidget };
10
- 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';
11
- type USTerritories = 'AS' | 'GU' | 'MP' | 'PR' | 'VI';
12
- type CanadianProvinces = 'AB' | 'BC' | 'MB' | 'NB' | 'NL' | 'NS' | 'QC' | 'ON' | 'PE' | 'SK';
13
- type CanadianTerritories = 'NT' | 'NU' | 'YT';
14
- type Address = {
15
- addressLine1: string;
16
- addressLine2?: string;
17
- city: string;
18
- state: USStates | USTerritories | CanadianProvinces | CanadianTerritories;
19
- postalCode: string;
20
- country: 'US' | 'CA';
21
- };
22
- type OptInFields = {
23
- businessExternalId: string;
24
- accountManagers?: {
25
- name: string;
26
- email: string;
27
- }[];
28
- owner: {
29
- firstName: string;
30
- lastName: string;
31
- email: string;
32
- phoneNumber?: string;
33
- /** yyyy-mm-dd */
34
- dateOfBirth?: string;
35
- address?: Address;
36
- };
37
- business: {
38
- legalName: string;
39
- dbaName?: string;
40
- address?: Address;
41
- /** yyyy-mm-dd */
42
- dateEstablished?: string;
43
- };
44
- bank?: {
45
- routingNumber?: string;
46
- accountNumberLastFour?: string;
47
- currencyCode?: 'USD' | 'CAD';
48
- };
49
- };
package/out/index.js DELETED
@@ -1,65 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from 'react';
3
- import { openParafinDashboard } from '@parafin/core';
4
- const ParafinWidget = (props) => {
5
- const frameRef = useRef(null);
6
- const [frameKey, setFrameKey] = useState(0);
7
- const [frameHeight, setFrameHeight] = useState('258px');
8
- const [borderColor, setBorderColor] = useState('#E8E8E8');
9
- const [borderRadius, setBorderRadius] = useState('16px');
10
- const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com');
11
- const query = {
12
- token: props.token,
13
- product: props.product,
14
- hasOptIn: props.onOptIn ? 'true' : 'false',
15
- host: window.location.origin,
16
- externalBusinessId: props.externalBusinessId ?? '',
17
- ...Object.fromEntries(url.searchParams),
18
- };
19
- const messageListener = async ({ data, origin }) => {
20
- if (origin === url.origin && data?.product === props.product) {
21
- switch (data?.message) {
22
- case 'set-border':
23
- if (data?.borderColor)
24
- setBorderColor(data.borderColor);
25
- if (data?.borderRadius)
26
- setBorderRadius(data.borderRadius);
27
- break;
28
- case 'open-dashboard':
29
- openParafinDashboard({
30
- ...props,
31
- route: data?.route,
32
- onExit: () => {
33
- setFrameKey((key) => key + 1);
34
- props.onExit?.();
35
- },
36
- });
37
- break;
38
- case 'opt-in':
39
- if (props.onOptIn) {
40
- const optInFields = await props.onOptIn();
41
- frameRef?.current?.contentWindow?.postMessage({ message: 'opt-in', optInFields: optInFields }, url.origin);
42
- }
43
- break;
44
- case 'set-height':
45
- if (data?.height)
46
- setFrameHeight(data.height);
47
- break;
48
- }
49
- }
50
- };
51
- useEffect(() => {
52
- window.addEventListener('message', messageListener);
53
- return () => window.removeEventListener('message', messageListener);
54
- }, []);
55
- return (_jsx("iframe", { ref: frameRef, id: `parafin-${props.product}-widget`, src: `${url.origin}?${new URLSearchParams(query).toString()}`, style: {
56
- width: '100%',
57
- height: frameHeight,
58
- backgroundColor: '#fff',
59
- border: `1px solid ${borderColor}`,
60
- borderRadius: borderRadius,
61
- transition: 'border 0.2s, border-radius 0.2s',
62
- boxSizing: 'border-box',
63
- } }, frameKey));
64
- };
65
- export { ParafinWidget };