@tryfinch/react-connect 3.15.1 → 4.0.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/.eslintrc.js +11 -0
- package/CHANGELOG.md +6 -0
- package/README.md +17 -10
- package/dist/index.d.ts +15 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +19 -62
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +19 -61
- package/dist/index.js.map +1 -1
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/example/package-lock.json +13 -1
- package/example/src/App.tsx +37 -10
- package/jest.config.js +7 -0
- package/package.json +9 -1
- package/src/index.test.ts +54 -0
- package/src/index.ts +33 -120
package/.eslintrc.js
CHANGED
|
@@ -21,6 +21,7 @@ module.exports = {
|
|
|
21
21
|
'import/resolver': {
|
|
22
22
|
node: {
|
|
23
23
|
paths: ['src'],
|
|
24
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
24
25
|
},
|
|
25
26
|
},
|
|
26
27
|
},
|
|
@@ -32,6 +33,16 @@ module.exports = {
|
|
|
32
33
|
'jsx-a11y/anchor-is-valid': 'off',
|
|
33
34
|
'react/jsx-props-no-spreading': 'off',
|
|
34
35
|
'no-underscore-dangle': 'off',
|
|
36
|
+
'import/extensions': [
|
|
37
|
+
'error',
|
|
38
|
+
'ignorePackages',
|
|
39
|
+
{
|
|
40
|
+
js: 'never',
|
|
41
|
+
jsx: 'never',
|
|
42
|
+
ts: 'never',
|
|
43
|
+
tsx: 'never',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
35
46
|
'max-len': [
|
|
36
47
|
'warn',
|
|
37
48
|
{
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# v4.0.0
|
|
2
|
+
|
|
3
|
+
## ⚠️ Breaking Changes
|
|
4
|
+
- A session ID is now required when calling the `open` method to launch Finch Connect. You can create a session using the [Connect session endpoint](https://developer.tryfinch.com/api-reference/connect/new-session) on the Finch API.
|
|
5
|
+
- The `state` parameter has been moved from the `initialize` call to the `open` call
|
|
6
|
+
- The `open` call no longer allows overriding values for the auth session, all values must be set in the session created by calling the API
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ npm install --save @tryfinch/react-connect
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
See the example app at `example/src` for a functional example
|
|
14
|
+
|
|
13
15
|
```jsx
|
|
14
16
|
import React, { useState } from 'react';
|
|
15
17
|
import { useFinchConnect } from '@tryfinch/react-connect';
|
|
@@ -17,33 +19,38 @@ import { useFinchConnect } from '@tryfinch/react-connect';
|
|
|
17
19
|
const App = () => {
|
|
18
20
|
const [code, setCode] = useState(null);
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
// Define callbacks
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} code - The authorization code to exchange for an access token
|
|
26
|
+
* @param {string?} state - The state value that was provided when launching Connect
|
|
27
|
+
*/
|
|
28
|
+
const onSuccess = ({ code, state }) => setCode(code);
|
|
21
29
|
/**
|
|
22
30
|
* @param {string} errorMessage - The error message
|
|
23
31
|
* @param {'validation_error' | 'employer_error'} errorType - The type of error
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* - 'validation_error': Finch Connect failed to open due to validation error
|
|
33
|
+
* - 'employer_connection_error': The errors employers see within the Finch Connect flow
|
|
26
34
|
*/
|
|
27
35
|
const onError = ({ errorMessage, errorType }) => console.error(errorMessage, errorType);
|
|
28
36
|
const onClose = () => console.log('User exited Finch Connect');
|
|
29
37
|
|
|
30
|
-
//
|
|
31
|
-
// See the docs here https://developer.tryfinch.com/api-reference/connect/new-session#create-a-new-connect-session
|
|
32
|
-
const sessionId = '';
|
|
33
|
-
|
|
38
|
+
// Initialize the FinchConnect hook
|
|
34
39
|
const { open } = useFinchConnect({
|
|
35
|
-
sessionId,
|
|
36
|
-
// zIndex: 999, // Set this to change the z-index of the Connect iframe, defaults to 999
|
|
37
40
|
onSuccess,
|
|
38
41
|
onError,
|
|
39
42
|
onClose,
|
|
40
43
|
});
|
|
41
44
|
|
|
45
|
+
// Generate a session ID using the /connect/sessions endpoint on the Finch API
|
|
46
|
+
// See the docs here https://developer.tryfinch.com/api-reference/connect/new-session#create-a-new-connect-session
|
|
47
|
+
const sessionId = '';
|
|
48
|
+
|
|
42
49
|
return (
|
|
43
50
|
<div>
|
|
44
51
|
<header>
|
|
45
52
|
<p>Code: {code}</p>
|
|
46
|
-
<button type="button" onClick={() => open()}>
|
|
53
|
+
<button type="button" onClick={() => open({ sessionId })}>
|
|
47
54
|
Open Finch Connect
|
|
48
55
|
</button>
|
|
49
56
|
</header>
|
package/dist/index.d.ts
CHANGED
|
@@ -8,35 +8,27 @@ export type ErrorEvent = {
|
|
|
8
8
|
errorMessage: string;
|
|
9
9
|
errorType?: ErrorType;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type ApiConfig = {
|
|
12
|
+
connectUrl: string;
|
|
13
|
+
};
|
|
14
|
+
export type ConnectInitializeArgs = {
|
|
14
15
|
onSuccess: (e: SuccessEvent) => void;
|
|
15
16
|
onError: (e: ErrorEvent) => void;
|
|
16
17
|
onClose: () => void;
|
|
17
|
-
|
|
18
|
-
apiConfig?: {
|
|
19
|
-
connectUrl: string;
|
|
20
|
-
redirectUrl: string;
|
|
21
|
-
};
|
|
18
|
+
apiConfig?: ApiConfig;
|
|
22
19
|
};
|
|
23
|
-
type
|
|
20
|
+
export type ConnectLaunchArgs = {
|
|
24
21
|
sessionId: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type ConnectOptionsWithClientId = BaseConnectOptions & {
|
|
28
|
-
category: string | null;
|
|
29
|
-
clientId: string;
|
|
30
|
-
manual: boolean;
|
|
31
|
-
payrollProvider: string | null;
|
|
32
|
-
products: string[];
|
|
33
|
-
clientName?: string;
|
|
34
|
-
connectionId?: string;
|
|
35
|
-
sandbox: Sandbox;
|
|
22
|
+
state?: string;
|
|
23
|
+
zIndex?: number;
|
|
36
24
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
type OpenFn = (args: ConnectLaunchArgs) => void;
|
|
26
|
+
export declare const constructAuthUrl: ({ sessionId, state, apiConfig, }: {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
state?: string | undefined;
|
|
29
|
+
apiConfig?: ApiConfig | undefined;
|
|
30
|
+
}) => string;
|
|
31
|
+
export declare const useFinchConnect: (initializeArgs: ConnectInitializeArgs) => {
|
|
40
32
|
open: OpenFn;
|
|
41
33
|
};
|
|
42
34
|
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"./","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"./","sources":["index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,SAAS,GAAG,kBAAkB,GAAG,2BAA2B,CAAC;AAClE,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;AA6BhD,eAAO,MAAM,gBAAgB;eAKhB,MAAM;;;YAkBlB,CAAC;AAIF,eAAO,MAAM,eAAe,mBAAoB,qBAAqB;UAAW,MAAM;CAkGrF,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -2,68 +2,23 @@ import { useRef, useEffect } from 'react';
|
|
|
2
2
|
|
|
3
3
|
const POST_MESSAGE_NAME = 'finch-auth-message-v2';
|
|
4
4
|
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
5
|
-
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
6
5
|
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
7
|
-
const constructAuthUrl = (
|
|
8
|
-
const { state, apiConfig } = connectOptions;
|
|
6
|
+
const constructAuthUrl = ({ sessionId, state, apiConfig, }) => {
|
|
9
7
|
const CONNECT_URL = (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.connectUrl) || BASE_FINCH_CONNECT_URI;
|
|
10
|
-
const REDIRECT_URL = (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.redirectUrl) || DEFAULT_FINCH_REDIRECT_URI;
|
|
11
8
|
const authUrl = new URL(`${CONNECT_URL}/authorize`);
|
|
12
|
-
|
|
13
|
-
const { sessionId, products } = connectOptions;
|
|
14
|
-
authUrl.searchParams.append('session', sessionId);
|
|
15
|
-
if (products)
|
|
16
|
-
authUrl.searchParams.append('products', products.join(' '));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, connectionId, } = connectOptions;
|
|
20
|
-
if (clientId)
|
|
21
|
-
authUrl.searchParams.append('client_id', clientId);
|
|
22
|
-
if (payrollProvider)
|
|
23
|
-
authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
24
|
-
if (category)
|
|
25
|
-
authUrl.searchParams.append('category', category);
|
|
26
|
-
if (clientName)
|
|
27
|
-
authUrl.searchParams.append('client_name', clientName);
|
|
28
|
-
if (connectionId)
|
|
29
|
-
authUrl.searchParams.append('connection_id', connectionId);
|
|
30
|
-
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' '));
|
|
31
|
-
if (manual)
|
|
32
|
-
authUrl.searchParams.append('manual', String(manual));
|
|
33
|
-
if (sandbox)
|
|
34
|
-
authUrl.searchParams.append('sandbox', String(sandbox));
|
|
35
|
-
}
|
|
9
|
+
authUrl.searchParams.append('session', sessionId);
|
|
36
10
|
authUrl.searchParams.append('app_type', 'spa');
|
|
37
|
-
authUrl.searchParams.append('redirect_uri', REDIRECT_URL);
|
|
38
11
|
/** The host URL of the SDK. This is used to store the referrer for postMessage purposes */
|
|
39
12
|
authUrl.searchParams.append('sdk_host_url', window.location.origin);
|
|
40
13
|
authUrl.searchParams.append('mode', 'employer');
|
|
41
14
|
if (state)
|
|
42
15
|
authUrl.searchParams.append('state', state);
|
|
43
16
|
// replace with actual SDK version by rollup
|
|
44
|
-
authUrl.searchParams.append('sdk_version', 'react-
|
|
17
|
+
authUrl.searchParams.append('sdk_version', 'react-4.0.0');
|
|
45
18
|
return authUrl.href;
|
|
46
19
|
};
|
|
47
|
-
const noop = () => {
|
|
48
|
-
// intentionally empty
|
|
49
|
-
};
|
|
50
|
-
const BASE_DEFAULTS = {
|
|
51
|
-
onSuccess: noop,
|
|
52
|
-
onError: noop,
|
|
53
|
-
onClose: noop,
|
|
54
|
-
state: null,
|
|
55
|
-
zIndex: 999,
|
|
56
|
-
};
|
|
57
|
-
const DEFAULT_OPTIONS_WITH_CLIENT_ID = Object.assign(Object.assign({}, BASE_DEFAULTS), { clientId: '', category: null, manual: false, payrollProvider: null, products: [], clientName: undefined, sandbox: false });
|
|
58
|
-
const DEFAULT_OPTIONS_WITH_SESSION_ID = Object.assign(Object.assign({}, BASE_DEFAULTS), { sessionId: '' });
|
|
59
20
|
let isUseFinchConnectInitialized = false;
|
|
60
|
-
const useFinchConnect = (
|
|
61
|
-
if (!('sessionId' in options) && !('clientId' in options)) {
|
|
62
|
-
throw new Error('must specify either sessionId or clientId in options for useFinchConnect');
|
|
63
|
-
}
|
|
64
|
-
if ('sessionId' in options && 'clientId' in options) {
|
|
65
|
-
throw new Error('cannot specify both sessionId and clientId in options for useFinchConnect');
|
|
66
|
-
}
|
|
21
|
+
const useFinchConnect = (initializeArgs) => {
|
|
67
22
|
const isHookMounted = useRef(false);
|
|
68
23
|
useEffect(() => {
|
|
69
24
|
if (!isHookMounted.current) {
|
|
@@ -76,17 +31,19 @@ const useFinchConnect = (options) => {
|
|
|
76
31
|
isHookMounted.current = true;
|
|
77
32
|
}
|
|
78
33
|
}, []);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const open = (overrides) => {
|
|
82
|
-
const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
|
|
34
|
+
const open = (launchArgs) => {
|
|
35
|
+
var _a;
|
|
83
36
|
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
84
37
|
const iframe = document.createElement('iframe');
|
|
85
|
-
iframe.src = constructAuthUrl(
|
|
38
|
+
iframe.src = constructAuthUrl({
|
|
39
|
+
sessionId: launchArgs.sessionId,
|
|
40
|
+
state: launchArgs.state,
|
|
41
|
+
apiConfig: initializeArgs.apiConfig,
|
|
42
|
+
});
|
|
86
43
|
iframe.frameBorder = '0';
|
|
87
44
|
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
88
45
|
iframe.style.position = 'fixed';
|
|
89
|
-
iframe.style.zIndex =
|
|
46
|
+
iframe.style.zIndex = ((_a = launchArgs.zIndex) === null || _a === void 0 ? void 0 : _a.toString()) || '999';
|
|
90
47
|
iframe.style.height = '100%';
|
|
91
48
|
iframe.style.width = '100%';
|
|
92
49
|
iframe.style.top = '0';
|
|
@@ -108,7 +65,7 @@ const useFinchConnect = (options) => {
|
|
|
108
65
|
useEffect(() => {
|
|
109
66
|
function handleFinchAuth(event) {
|
|
110
67
|
var _a, _b, _c, _d;
|
|
111
|
-
const CONNECT_URL = ((_a =
|
|
68
|
+
const CONNECT_URL = ((_a = initializeArgs.apiConfig) === null || _a === void 0 ? void 0 : _a.connectUrl) || BASE_FINCH_CONNECT_URI;
|
|
112
69
|
if (!event.data)
|
|
113
70
|
return;
|
|
114
71
|
if (event.data.name !== POST_MESSAGE_NAME)
|
|
@@ -119,18 +76,18 @@ const useFinchConnect = (options) => {
|
|
|
119
76
|
close();
|
|
120
77
|
switch (event.data.kind) {
|
|
121
78
|
case 'closed':
|
|
122
|
-
|
|
79
|
+
initializeArgs.onClose();
|
|
123
80
|
break;
|
|
124
81
|
case 'error':
|
|
125
82
|
if ((_b = event.data.error) === null || _b === void 0 ? void 0 : _b.shouldClose)
|
|
126
83
|
close();
|
|
127
|
-
|
|
84
|
+
initializeArgs.onError({
|
|
128
85
|
errorMessage: (_c = event.data.error) === null || _c === void 0 ? void 0 : _c.message,
|
|
129
86
|
errorType: (_d = event.data.error) === null || _d === void 0 ? void 0 : _d.type,
|
|
130
87
|
});
|
|
131
88
|
break;
|
|
132
89
|
case 'success':
|
|
133
|
-
|
|
90
|
+
initializeArgs.onSuccess({
|
|
134
91
|
code: event.data.code,
|
|
135
92
|
state: event.data.state,
|
|
136
93
|
idpRedirectUri: event.data.idpRedirectUri,
|
|
@@ -138,7 +95,7 @@ const useFinchConnect = (options) => {
|
|
|
138
95
|
break;
|
|
139
96
|
default: {
|
|
140
97
|
// This case should never happen, if it does it should be reported to us
|
|
141
|
-
|
|
98
|
+
initializeArgs.onError({
|
|
142
99
|
errorMessage: `Report to developers@tryfinch.com: unable to handle window.postMessage for: ${JSON.stringify(event.data)}`,
|
|
143
100
|
});
|
|
144
101
|
}
|
|
@@ -149,11 +106,11 @@ const useFinchConnect = (options) => {
|
|
|
149
106
|
window.removeEventListener('message', handleFinchAuth);
|
|
150
107
|
isUseFinchConnectInitialized = false;
|
|
151
108
|
};
|
|
152
|
-
}, [
|
|
109
|
+
}, [initializeArgs.onClose, initializeArgs.onError, initializeArgs.onSuccess]);
|
|
153
110
|
return {
|
|
154
111
|
open,
|
|
155
112
|
};
|
|
156
113
|
};
|
|
157
114
|
|
|
158
|
-
export { useFinchConnect };
|
|
115
|
+
export { constructAuthUrl, useFinchConnect };
|
|
159
116
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAiCA,MAAM,iBAAiB,GAAG,uBAAgC,CAAC;AAuB3D,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAE9D,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAEhD,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,KAAK,EACL,SAAS,GAKV,KAAI;AACH,IAAA,MAAM,WAAW,GAAG,CAAA,SAAS,KAAT,IAAA,IAAA,SAAS,KAAT,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,SAAS,CAAE,UAAU,KAAI,sBAAsB,CAAC;IAEpE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAG,EAAA,WAAW,CAAY,UAAA,CAAA,CAAC,CAAC;IAEpD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAClD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;;AAE/C,IAAA,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,C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AS;;oBAEP,cAAc,CAAC,OAAO,CAAC;wBACrB,YAAY,EAAE,CAAgF,6EAAA,EAAA,IAAI,CAAC,SAAS,CAC1G,KAAK,CAAC,IAAI,CACX,CAAE,CAAA;AACJ,qBAAA,CAAC,CAAC;AACJ,iBAAA;AACF,aAAA;SACF;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AACpD,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACvD,4BAA4B,GAAG,KAAK,CAAC;AACvC,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;IAE/E,OAAO;QACL,IAAI;KACL,CAAC;AACJ;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -6,68 +6,23 @@ var react = require('react');
|
|
|
6
6
|
|
|
7
7
|
const POST_MESSAGE_NAME = 'finch-auth-message-v2';
|
|
8
8
|
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
9
|
-
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
10
9
|
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
11
|
-
const constructAuthUrl = (
|
|
12
|
-
const { state, apiConfig } = connectOptions;
|
|
10
|
+
const constructAuthUrl = ({ sessionId, state, apiConfig, }) => {
|
|
13
11
|
const CONNECT_URL = (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.connectUrl) || BASE_FINCH_CONNECT_URI;
|
|
14
|
-
const REDIRECT_URL = (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.redirectUrl) || DEFAULT_FINCH_REDIRECT_URI;
|
|
15
12
|
const authUrl = new URL(`${CONNECT_URL}/authorize`);
|
|
16
|
-
|
|
17
|
-
const { sessionId, products } = connectOptions;
|
|
18
|
-
authUrl.searchParams.append('session', sessionId);
|
|
19
|
-
if (products)
|
|
20
|
-
authUrl.searchParams.append('products', products.join(' '));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, connectionId, } = connectOptions;
|
|
24
|
-
if (clientId)
|
|
25
|
-
authUrl.searchParams.append('client_id', clientId);
|
|
26
|
-
if (payrollProvider)
|
|
27
|
-
authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
28
|
-
if (category)
|
|
29
|
-
authUrl.searchParams.append('category', category);
|
|
30
|
-
if (clientName)
|
|
31
|
-
authUrl.searchParams.append('client_name', clientName);
|
|
32
|
-
if (connectionId)
|
|
33
|
-
authUrl.searchParams.append('connection_id', connectionId);
|
|
34
|
-
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' '));
|
|
35
|
-
if (manual)
|
|
36
|
-
authUrl.searchParams.append('manual', String(manual));
|
|
37
|
-
if (sandbox)
|
|
38
|
-
authUrl.searchParams.append('sandbox', String(sandbox));
|
|
39
|
-
}
|
|
13
|
+
authUrl.searchParams.append('session', sessionId);
|
|
40
14
|
authUrl.searchParams.append('app_type', 'spa');
|
|
41
|
-
authUrl.searchParams.append('redirect_uri', REDIRECT_URL);
|
|
42
15
|
/** The host URL of the SDK. This is used to store the referrer for postMessage purposes */
|
|
43
16
|
authUrl.searchParams.append('sdk_host_url', window.location.origin);
|
|
44
17
|
authUrl.searchParams.append('mode', 'employer');
|
|
45
18
|
if (state)
|
|
46
19
|
authUrl.searchParams.append('state', state);
|
|
47
20
|
// replace with actual SDK version by rollup
|
|
48
|
-
authUrl.searchParams.append('sdk_version', 'react-
|
|
21
|
+
authUrl.searchParams.append('sdk_version', 'react-4.0.0');
|
|
49
22
|
return authUrl.href;
|
|
50
23
|
};
|
|
51
|
-
const noop = () => {
|
|
52
|
-
// intentionally empty
|
|
53
|
-
};
|
|
54
|
-
const BASE_DEFAULTS = {
|
|
55
|
-
onSuccess: noop,
|
|
56
|
-
onError: noop,
|
|
57
|
-
onClose: noop,
|
|
58
|
-
state: null,
|
|
59
|
-
zIndex: 999,
|
|
60
|
-
};
|
|
61
|
-
const DEFAULT_OPTIONS_WITH_CLIENT_ID = Object.assign(Object.assign({}, BASE_DEFAULTS), { clientId: '', category: null, manual: false, payrollProvider: null, products: [], clientName: undefined, sandbox: false });
|
|
62
|
-
const DEFAULT_OPTIONS_WITH_SESSION_ID = Object.assign(Object.assign({}, BASE_DEFAULTS), { sessionId: '' });
|
|
63
24
|
let isUseFinchConnectInitialized = false;
|
|
64
|
-
const useFinchConnect = (
|
|
65
|
-
if (!('sessionId' in options) && !('clientId' in options)) {
|
|
66
|
-
throw new Error('must specify either sessionId or clientId in options for useFinchConnect');
|
|
67
|
-
}
|
|
68
|
-
if ('sessionId' in options && 'clientId' in options) {
|
|
69
|
-
throw new Error('cannot specify both sessionId and clientId in options for useFinchConnect');
|
|
70
|
-
}
|
|
25
|
+
const useFinchConnect = (initializeArgs) => {
|
|
71
26
|
const isHookMounted = react.useRef(false);
|
|
72
27
|
react.useEffect(() => {
|
|
73
28
|
if (!isHookMounted.current) {
|
|
@@ -80,17 +35,19 @@ const useFinchConnect = (options) => {
|
|
|
80
35
|
isHookMounted.current = true;
|
|
81
36
|
}
|
|
82
37
|
}, []);
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const open = (overrides) => {
|
|
86
|
-
const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
|
|
38
|
+
const open = (launchArgs) => {
|
|
39
|
+
var _a;
|
|
87
40
|
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
88
41
|
const iframe = document.createElement('iframe');
|
|
89
|
-
iframe.src = constructAuthUrl(
|
|
42
|
+
iframe.src = constructAuthUrl({
|
|
43
|
+
sessionId: launchArgs.sessionId,
|
|
44
|
+
state: launchArgs.state,
|
|
45
|
+
apiConfig: initializeArgs.apiConfig,
|
|
46
|
+
});
|
|
90
47
|
iframe.frameBorder = '0';
|
|
91
48
|
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
92
49
|
iframe.style.position = 'fixed';
|
|
93
|
-
iframe.style.zIndex =
|
|
50
|
+
iframe.style.zIndex = ((_a = launchArgs.zIndex) === null || _a === void 0 ? void 0 : _a.toString()) || '999';
|
|
94
51
|
iframe.style.height = '100%';
|
|
95
52
|
iframe.style.width = '100%';
|
|
96
53
|
iframe.style.top = '0';
|
|
@@ -112,7 +69,7 @@ const useFinchConnect = (options) => {
|
|
|
112
69
|
react.useEffect(() => {
|
|
113
70
|
function handleFinchAuth(event) {
|
|
114
71
|
var _a, _b, _c, _d;
|
|
115
|
-
const CONNECT_URL = ((_a =
|
|
72
|
+
const CONNECT_URL = ((_a = initializeArgs.apiConfig) === null || _a === void 0 ? void 0 : _a.connectUrl) || BASE_FINCH_CONNECT_URI;
|
|
116
73
|
if (!event.data)
|
|
117
74
|
return;
|
|
118
75
|
if (event.data.name !== POST_MESSAGE_NAME)
|
|
@@ -123,18 +80,18 @@ const useFinchConnect = (options) => {
|
|
|
123
80
|
close();
|
|
124
81
|
switch (event.data.kind) {
|
|
125
82
|
case 'closed':
|
|
126
|
-
|
|
83
|
+
initializeArgs.onClose();
|
|
127
84
|
break;
|
|
128
85
|
case 'error':
|
|
129
86
|
if ((_b = event.data.error) === null || _b === void 0 ? void 0 : _b.shouldClose)
|
|
130
87
|
close();
|
|
131
|
-
|
|
88
|
+
initializeArgs.onError({
|
|
132
89
|
errorMessage: (_c = event.data.error) === null || _c === void 0 ? void 0 : _c.message,
|
|
133
90
|
errorType: (_d = event.data.error) === null || _d === void 0 ? void 0 : _d.type,
|
|
134
91
|
});
|
|
135
92
|
break;
|
|
136
93
|
case 'success':
|
|
137
|
-
|
|
94
|
+
initializeArgs.onSuccess({
|
|
138
95
|
code: event.data.code,
|
|
139
96
|
state: event.data.state,
|
|
140
97
|
idpRedirectUri: event.data.idpRedirectUri,
|
|
@@ -142,7 +99,7 @@ const useFinchConnect = (options) => {
|
|
|
142
99
|
break;
|
|
143
100
|
default: {
|
|
144
101
|
// This case should never happen, if it does it should be reported to us
|
|
145
|
-
|
|
102
|
+
initializeArgs.onError({
|
|
146
103
|
errorMessage: `Report to developers@tryfinch.com: unable to handle window.postMessage for: ${JSON.stringify(event.data)}`,
|
|
147
104
|
});
|
|
148
105
|
}
|
|
@@ -153,11 +110,12 @@ const useFinchConnect = (options) => {
|
|
|
153
110
|
window.removeEventListener('message', handleFinchAuth);
|
|
154
111
|
isUseFinchConnectInitialized = false;
|
|
155
112
|
};
|
|
156
|
-
}, [
|
|
113
|
+
}, [initializeArgs.onClose, initializeArgs.onError, initializeArgs.onSuccess]);
|
|
157
114
|
return {
|
|
158
115
|
open,
|
|
159
116
|
};
|
|
160
117
|
};
|
|
161
118
|
|
|
119
|
+
exports.constructAuthUrl = constructAuthUrl;
|
|
162
120
|
exports.useFinchConnect = useFinchConnect;
|
|
163
121
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":["useRef","useEffect"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":["useRef","useEffect"],"mappings":";;;;;;AAiCA,MAAM,iBAAiB,GAAG,uBAAgC,CAAC;AAuB3D,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAE9D,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAEhD,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,KAAK,EACL,SAAS,GAKV,KAAI;AACH,IAAA,MAAM,WAAW,GAAG,CAAA,SAAS,KAAT,IAAA,IAAA,SAAS,KAAT,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,SAAS,CAAE,UAAU,KAAI,sBAAsB,CAAC;IAEpE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAG,EAA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,SAAS;oBACZ,cAAc,CAAC,SAAS,CAAC;AACvB,wBAAA,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;AACrB,wBAAA,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;AACvB,wBAAA,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc;AAC1C,qBAAA,CAAC,CAAC;oBACH,MAAM;AACR,gBAAA,SAAS;;oBAEP,cAAc,CAAC,OAAO,CAAC;wBACrB,YAAY,EAAE,CAAgF,6EAAA,EAAA,IAAI,CAAC,SAAS,CAC1G,KAAK,CAAC,IAAI,CACX,CAAE,CAAA;AACJ,qBAAA,CAAC,CAAC;AACJ,iBAAA;AACF,aAAA;SACF;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AACpD,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACvD,4BAA4B,GAAG,KAAK,CAAC;AACvC,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;IAE/E,OAAO;QACL,IAAI;KACL,CAAC;AACJ;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"./","sources":["index.test.ts"],"names":[],"mappings":""}
|
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"..": {
|
|
23
23
|
"name": "@tryfinch/react-connect",
|
|
24
|
-
"version": "
|
|
24
|
+
"version": "4.0.0",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rollup/plugin-replace": "^4.0.0",
|
|
28
28
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
29
30
|
"@types/react": "^16.14.40",
|
|
30
31
|
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
31
32
|
"@typescript-eslint/parser": "^5.59.0",
|
|
@@ -33,9 +34,14 @@
|
|
|
33
34
|
"eslint-config-airbnb": "^18.2.0",
|
|
34
35
|
"eslint-config-prettier": "^6.11.0",
|
|
35
36
|
"eslint-plugin-prettier": "^3.1.4",
|
|
37
|
+
"jest": "^30.0.5",
|
|
38
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
39
|
+
"jsdom": "^26.1.0",
|
|
36
40
|
"react": "^16.9.0",
|
|
37
41
|
"rollup": "^2.75.7",
|
|
38
42
|
"rollup-plugin-peer-deps-external": "^2.2.0",
|
|
43
|
+
"ts-jest": "^29.4.1",
|
|
44
|
+
"tslib": "^2.8.1",
|
|
39
45
|
"typescript": "^4.9.5"
|
|
40
46
|
},
|
|
41
47
|
"engines": {
|
|
@@ -21321,6 +21327,7 @@
|
|
|
21321
21327
|
"requires": {
|
|
21322
21328
|
"@rollup/plugin-replace": "^4.0.0",
|
|
21323
21329
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
21330
|
+
"@types/jest": "^30.0.0",
|
|
21324
21331
|
"@types/react": "^16.14.40",
|
|
21325
21332
|
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
21326
21333
|
"@typescript-eslint/parser": "^5.59.0",
|
|
@@ -21328,9 +21335,14 @@
|
|
|
21328
21335
|
"eslint-config-airbnb": "^18.2.0",
|
|
21329
21336
|
"eslint-config-prettier": "^6.11.0",
|
|
21330
21337
|
"eslint-plugin-prettier": "^3.1.4",
|
|
21338
|
+
"jest": "^30.0.5",
|
|
21339
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
21340
|
+
"jsdom": "^26.1.0",
|
|
21331
21341
|
"react": "^16.9.0",
|
|
21332
21342
|
"rollup": "^2.75.7",
|
|
21333
21343
|
"rollup-plugin-peer-deps-external": "^2.2.0",
|
|
21344
|
+
"ts-jest": "^29.4.1",
|
|
21345
|
+
"tslib": "^2.8.1",
|
|
21334
21346
|
"typescript": "^4.9.5"
|
|
21335
21347
|
},
|
|
21336
21348
|
"dependencies": {
|
package/example/src/App.tsx
CHANGED
|
@@ -6,36 +6,61 @@ import Result, { ResultContainer } from './Result';
|
|
|
6
6
|
import './App.css';
|
|
7
7
|
|
|
8
8
|
const App = () => {
|
|
9
|
+
const [sessionId, setSessionId] = useState<string>('');
|
|
9
10
|
const [sendState, setSendState] = useState<boolean>(false);
|
|
10
11
|
const [result, setResult] = useState<ResultContainer>();
|
|
11
12
|
|
|
13
|
+
// Define callbacks
|
|
12
14
|
const onSuccess = (value: SuccessEvent) => setResult({ kind: 'success', value });
|
|
13
15
|
const onError = (value: ErrorEvent) => setResult({ kind: 'error', value });
|
|
14
16
|
const onClose = () => setResult({ kind: 'closed' });
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
// Initialize the FinchConnect hook
|
|
18
19
|
const { open } = useFinchConnect({
|
|
19
|
-
sessionId,
|
|
20
20
|
onSuccess,
|
|
21
21
|
onError,
|
|
22
22
|
onClose,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
// Call the open method when submitting the form
|
|
26
|
+
const submissionHandler: React.FormEventHandler<HTMLFormElement> = (e) => {
|
|
26
27
|
e.preventDefault();
|
|
27
28
|
open({
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// Generate a session ID using the /connect/sessions endpoint on the Finch API
|
|
30
|
+
// See the docs here https://developer.tryfinch.com/api-reference/connect/new-session#create-a-new-connect-session
|
|
31
|
+
sessionId: sessionId.trim(),
|
|
32
|
+
// An optional state parameter can be passed
|
|
33
|
+
// https://datatracker.ietf.org/doc/html/rfc6749#section-10.12
|
|
34
|
+
...(sendState ? { state: new Date().toISOString() } : {}),
|
|
35
|
+
// An optional value for the z-index of the Finch Connect iframe
|
|
36
|
+
// Defaults to 999 if not provided
|
|
37
|
+
// zIndex: 998,
|
|
38
|
+
});
|
|
30
39
|
};
|
|
31
40
|
|
|
32
41
|
return (
|
|
33
42
|
<div className="container">
|
|
34
|
-
<h2
|
|
43
|
+
<h2>
|
|
44
|
+
<a href="https://www.npmjs.com/package/@tryfinch/react-connect">@tryfinch/react-connect</a>{' '}
|
|
45
|
+
Example App
|
|
46
|
+
</h2>
|
|
35
47
|
<form className="actions" onSubmit={submissionHandler}>
|
|
48
|
+
<div className="row">
|
|
49
|
+
<label className="top-label">Session UUID:</label>
|
|
50
|
+
<input
|
|
51
|
+
type="text"
|
|
52
|
+
placeholder="Enter session UUID"
|
|
53
|
+
value={sessionId}
|
|
54
|
+
onChange={(e) => setSessionId(e.target.value)}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
36
57
|
<div className="row">
|
|
37
58
|
<label className="top-label">Include State:</label>
|
|
38
|
-
<input
|
|
59
|
+
<input
|
|
60
|
+
type="checkbox"
|
|
61
|
+
checked={sendState}
|
|
62
|
+
onChange={() => setSendState((prev) => !prev)}
|
|
63
|
+
/>
|
|
39
64
|
</div>
|
|
40
65
|
<div className="row">
|
|
41
66
|
<button className="cta" type="submit">
|
|
@@ -44,8 +69,10 @@ const App = () => {
|
|
|
44
69
|
</div>
|
|
45
70
|
</form>
|
|
46
71
|
<div className="results">
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
{!result && (
|
|
73
|
+
<p>Complete a Finch Connect session and the success event will be displayed here</p>
|
|
74
|
+
)}
|
|
75
|
+
{result && <Result result={result} />}
|
|
49
76
|
</div>
|
|
50
77
|
</div>
|
|
51
78
|
);
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryfinch/react-connect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Finch SDK for embedding Finch Connect in API React Single Page Applications (SPA)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"finch",
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"build": "rollup -c",
|
|
26
26
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
|
|
27
27
|
"start": "rollup -c -w",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
28
30
|
"prepare": "npm run build",
|
|
29
31
|
"predeploy": "cd example && npm install && npm run build"
|
|
30
32
|
},
|
|
@@ -34,6 +36,7 @@
|
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@rollup/plugin-replace": "^4.0.0",
|
|
36
38
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
39
|
+
"@types/jest": "^30.0.0",
|
|
37
40
|
"@types/react": "^16.14.40",
|
|
38
41
|
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
39
42
|
"@typescript-eslint/parser": "^5.59.0",
|
|
@@ -41,9 +44,14 @@
|
|
|
41
44
|
"eslint-config-airbnb": "^18.2.0",
|
|
42
45
|
"eslint-config-prettier": "^6.11.0",
|
|
43
46
|
"eslint-plugin-prettier": "^3.1.4",
|
|
47
|
+
"jest": "^30.0.5",
|
|
48
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
49
|
+
"jsdom": "^26.1.0",
|
|
44
50
|
"react": "^16.9.0",
|
|
45
51
|
"rollup": "^2.75.7",
|
|
46
52
|
"rollup-plugin-peer-deps-external": "^2.2.0",
|
|
53
|
+
"ts-jest": "^29.4.1",
|
|
54
|
+
"tslib": "^2.8.1",
|
|
47
55
|
"typescript": "^4.9.5"
|
|
48
56
|
}
|
|
49
57
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { constructAuthUrl } from './index';
|
|
2
|
+
|
|
3
|
+
const NOOP_CALLBACKS = {
|
|
4
|
+
onSuccess: jest.fn(),
|
|
5
|
+
onError: jest.fn(),
|
|
6
|
+
onClose: jest.fn(),
|
|
7
|
+
zIndex: 999,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('Finch React SDK', () => {
|
|
11
|
+
describe('constructAuthUrl', () => {
|
|
12
|
+
it('adds the session parameter', () => {
|
|
13
|
+
const authUrl = constructAuthUrl({
|
|
14
|
+
sessionId: 'test-session-id',
|
|
15
|
+
});
|
|
16
|
+
expect(authUrl).toContain('session=test-session-id');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('adds all the expected base parameters to the auth URL', () => {
|
|
20
|
+
const expectedParameters = {
|
|
21
|
+
app_type: 'spa',
|
|
22
|
+
sdk_host_url: encodeURIComponent('http://localhost'),
|
|
23
|
+
mode: 'employer',
|
|
24
|
+
sdk_version: 'react-SDK_VERSION',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const authUrl = constructAuthUrl({
|
|
28
|
+
sessionId: 'test-session-id',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
Object.entries(expectedParameters).forEach(([key, value]) => {
|
|
32
|
+
expect(authUrl).toContain(`${key}=${value}`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('adds the state parameter if it is provided', () => {
|
|
37
|
+
const testOptions = { sessionId: 'test-session-id', state: 'test-state', ...NOOP_CALLBACKS };
|
|
38
|
+
const authUrl = constructAuthUrl(testOptions);
|
|
39
|
+
|
|
40
|
+
expect(authUrl).toContain('state=test-state');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('uses the provided connectUrl if provided', () => {
|
|
44
|
+
const authUrl = constructAuthUrl({
|
|
45
|
+
sessionId: '123',
|
|
46
|
+
apiConfig: {
|
|
47
|
+
connectUrl: 'https://cool.site',
|
|
48
|
+
},
|
|
49
|
+
...NOOP_CALLBACKS,
|
|
50
|
+
});
|
|
51
|
+
expect(authUrl.startsWith('https://cool.site/authorize?')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
type HasKey<T, K extends PropertyKey> = T extends Record<K, unknown> ? T : never;
|
|
4
|
-
|
|
5
3
|
export type SuccessEvent = {
|
|
6
4
|
code: string;
|
|
7
5
|
state?: string;
|
|
@@ -9,50 +7,29 @@ export type SuccessEvent = {
|
|
|
9
7
|
};
|
|
10
8
|
|
|
11
9
|
type ErrorType = 'validation_error' | 'employer_connection_error';
|
|
12
|
-
|
|
13
10
|
export type ErrorEvent = {
|
|
14
11
|
errorMessage: string;
|
|
15
12
|
errorType?: ErrorType;
|
|
16
13
|
};
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
| boolean /** This is the old sandbox flag retained for backwards compatibility */;
|
|
15
|
+
type ApiConfig = {
|
|
16
|
+
connectUrl: string;
|
|
17
|
+
};
|
|
22
18
|
|
|
23
|
-
type
|
|
24
|
-
state: string | null;
|
|
19
|
+
export type ConnectInitializeArgs = {
|
|
25
20
|
onSuccess: (e: SuccessEvent) => void;
|
|
26
21
|
onError: (e: ErrorEvent) => void;
|
|
27
22
|
onClose: () => void;
|
|
28
|
-
|
|
29
|
-
apiConfig?: {
|
|
30
|
-
connectUrl: string;
|
|
31
|
-
redirectUrl: string;
|
|
32
|
-
};
|
|
23
|
+
apiConfig?: ApiConfig;
|
|
33
24
|
};
|
|
34
25
|
|
|
35
|
-
type
|
|
36
|
-
// Use this option if you have a Finch Connect sessionID from the IDP redirect flow
|
|
26
|
+
export type ConnectLaunchArgs = {
|
|
37
27
|
sessionId: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type ConnectOptionsWithClientId = BaseConnectOptions & {
|
|
43
|
-
category: string | null;
|
|
44
|
-
clientId: string;
|
|
45
|
-
manual: boolean;
|
|
46
|
-
payrollProvider: string | null;
|
|
47
|
-
products: string[];
|
|
48
|
-
clientName?: string;
|
|
49
|
-
connectionId?: string;
|
|
50
|
-
sandbox: Sandbox;
|
|
28
|
+
state?: string;
|
|
29
|
+
zIndex?: number;
|
|
51
30
|
};
|
|
52
31
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
type OpenFn = (overrides?: Partial<ConnectOptions>) => void;
|
|
32
|
+
type OpenFn = (args: ConnectLaunchArgs) => void;
|
|
56
33
|
|
|
57
34
|
const POST_MESSAGE_NAME = 'finch-auth-message-v2' as const;
|
|
58
35
|
|
|
@@ -78,46 +55,24 @@ interface FinchConnectPostMessage {
|
|
|
78
55
|
}
|
|
79
56
|
|
|
80
57
|
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
81
|
-
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
82
58
|
|
|
83
59
|
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
84
60
|
|
|
85
|
-
const constructAuthUrl = (
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
export const constructAuthUrl = ({
|
|
62
|
+
sessionId,
|
|
63
|
+
state,
|
|
64
|
+
apiConfig,
|
|
65
|
+
}: {
|
|
66
|
+
sessionId: string;
|
|
67
|
+
state?: string;
|
|
68
|
+
apiConfig?: ApiConfig;
|
|
69
|
+
}) => {
|
|
88
70
|
const CONNECT_URL = apiConfig?.connectUrl || BASE_FINCH_CONNECT_URI;
|
|
89
|
-
const REDIRECT_URL = apiConfig?.redirectUrl || DEFAULT_FINCH_REDIRECT_URI;
|
|
90
71
|
|
|
91
72
|
const authUrl = new URL(`${CONNECT_URL}/authorize`);
|
|
92
73
|
|
|
93
|
-
|
|
94
|
-
const { sessionId, products } = connectOptions;
|
|
95
|
-
authUrl.searchParams.append('session', sessionId);
|
|
96
|
-
if (products) authUrl.searchParams.append('products', products.join(' '));
|
|
97
|
-
} else {
|
|
98
|
-
const {
|
|
99
|
-
clientId,
|
|
100
|
-
payrollProvider,
|
|
101
|
-
category,
|
|
102
|
-
products,
|
|
103
|
-
manual,
|
|
104
|
-
sandbox,
|
|
105
|
-
clientName,
|
|
106
|
-
connectionId,
|
|
107
|
-
} = connectOptions;
|
|
108
|
-
|
|
109
|
-
if (clientId) authUrl.searchParams.append('client_id', clientId);
|
|
110
|
-
if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
111
|
-
if (category) authUrl.searchParams.append('category', category);
|
|
112
|
-
if (clientName) authUrl.searchParams.append('client_name', clientName);
|
|
113
|
-
if (connectionId) authUrl.searchParams.append('connection_id', connectionId);
|
|
114
|
-
authUrl.searchParams.append('products', (products ?? []).join(' '));
|
|
115
|
-
if (manual) authUrl.searchParams.append('manual', String(manual));
|
|
116
|
-
if (sandbox) authUrl.searchParams.append('sandbox', String(sandbox));
|
|
117
|
-
}
|
|
118
|
-
|
|
74
|
+
authUrl.searchParams.append('session', sessionId);
|
|
119
75
|
authUrl.searchParams.append('app_type', 'spa');
|
|
120
|
-
authUrl.searchParams.append('redirect_uri', REDIRECT_URL);
|
|
121
76
|
/** The host URL of the SDK. This is used to store the referrer for postMessage purposes */
|
|
122
77
|
authUrl.searchParams.append('sdk_host_url', window.location.origin);
|
|
123
78
|
authUrl.searchParams.append('mode', 'employer');
|
|
@@ -128,45 +83,9 @@ const constructAuthUrl = (connectOptions: ConnectOptions) => {
|
|
|
128
83
|
return authUrl.href;
|
|
129
84
|
};
|
|
130
85
|
|
|
131
|
-
const noop = () => {
|
|
132
|
-
// intentionally empty
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const BASE_DEFAULTS = {
|
|
136
|
-
onSuccess: noop,
|
|
137
|
-
onError: noop,
|
|
138
|
-
onClose: noop,
|
|
139
|
-
state: null,
|
|
140
|
-
zIndex: 999,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const DEFAULT_OPTIONS_WITH_CLIENT_ID: HasKey<ConnectOptions, 'clientId'> = {
|
|
144
|
-
...BASE_DEFAULTS,
|
|
145
|
-
clientId: '',
|
|
146
|
-
category: null,
|
|
147
|
-
manual: false,
|
|
148
|
-
payrollProvider: null,
|
|
149
|
-
products: [],
|
|
150
|
-
clientName: undefined,
|
|
151
|
-
sandbox: false,
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const DEFAULT_OPTIONS_WITH_SESSION_ID: HasKey<ConnectOptions, 'sessionId'> = {
|
|
155
|
-
...BASE_DEFAULTS,
|
|
156
|
-
sessionId: '',
|
|
157
|
-
};
|
|
158
|
-
|
|
159
86
|
let isUseFinchConnectInitialized = false;
|
|
160
87
|
|
|
161
|
-
export const useFinchConnect = (
|
|
162
|
-
if (!('sessionId' in options) && !('clientId' in options)) {
|
|
163
|
-
throw new Error('must specify either sessionId or clientId in options for useFinchConnect');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if ('sessionId' in options && 'clientId' in options) {
|
|
167
|
-
throw new Error('cannot specify both sessionId and clientId in options for useFinchConnect');
|
|
168
|
-
}
|
|
169
|
-
|
|
88
|
+
export const useFinchConnect = (initializeArgs: ConnectInitializeArgs): { open: OpenFn } => {
|
|
170
89
|
const isHookMounted = useRef(false);
|
|
171
90
|
|
|
172
91
|
useEffect(() => {
|
|
@@ -183,24 +102,18 @@ export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenF
|
|
|
183
102
|
}
|
|
184
103
|
}, []);
|
|
185
104
|
|
|
186
|
-
const
|
|
187
|
-
'sessionId' in options
|
|
188
|
-
? { ...DEFAULT_OPTIONS_WITH_SESSION_ID, ...options }
|
|
189
|
-
: { ...DEFAULT_OPTIONS_WITH_CLIENT_ID, ...options };
|
|
190
|
-
|
|
191
|
-
const open: OpenFn = (overrides) => {
|
|
192
|
-
const openOptions: ConnectOptions = {
|
|
193
|
-
...combinedOptions,
|
|
194
|
-
...overrides,
|
|
195
|
-
};
|
|
196
|
-
|
|
105
|
+
const open: OpenFn = (launchArgs) => {
|
|
197
106
|
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
198
107
|
const iframe = document.createElement('iframe');
|
|
199
|
-
iframe.src = constructAuthUrl(
|
|
108
|
+
iframe.src = constructAuthUrl({
|
|
109
|
+
sessionId: launchArgs.sessionId,
|
|
110
|
+
state: launchArgs.state,
|
|
111
|
+
apiConfig: initializeArgs.apiConfig,
|
|
112
|
+
});
|
|
200
113
|
iframe.frameBorder = '0';
|
|
201
114
|
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
202
115
|
iframe.style.position = 'fixed';
|
|
203
|
-
iframe.style.zIndex =
|
|
116
|
+
iframe.style.zIndex = launchArgs.zIndex?.toString() || '999';
|
|
204
117
|
iframe.style.height = '100%';
|
|
205
118
|
iframe.style.width = '100%';
|
|
206
119
|
iframe.style.top = '0';
|
|
@@ -222,7 +135,7 @@ export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenF
|
|
|
222
135
|
|
|
223
136
|
useEffect(() => {
|
|
224
137
|
function handleFinchAuth(event: FinchConnectPostMessage) {
|
|
225
|
-
const CONNECT_URL =
|
|
138
|
+
const CONNECT_URL = initializeArgs.apiConfig?.connectUrl || BASE_FINCH_CONNECT_URI;
|
|
226
139
|
|
|
227
140
|
if (!event.data) return;
|
|
228
141
|
if (event.data.name !== POST_MESSAGE_NAME) return;
|
|
@@ -232,18 +145,18 @@ export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenF
|
|
|
232
145
|
|
|
233
146
|
switch (event.data.kind) {
|
|
234
147
|
case 'closed':
|
|
235
|
-
|
|
148
|
+
initializeArgs.onClose();
|
|
236
149
|
break;
|
|
237
150
|
case 'error':
|
|
238
151
|
if (event.data.error?.shouldClose) close();
|
|
239
152
|
|
|
240
|
-
|
|
153
|
+
initializeArgs.onError({
|
|
241
154
|
errorMessage: event.data.error?.message,
|
|
242
155
|
errorType: event.data.error?.type,
|
|
243
156
|
});
|
|
244
157
|
break;
|
|
245
158
|
case 'success':
|
|
246
|
-
|
|
159
|
+
initializeArgs.onSuccess({
|
|
247
160
|
code: event.data.code,
|
|
248
161
|
state: event.data.state,
|
|
249
162
|
idpRedirectUri: event.data.idpRedirectUri,
|
|
@@ -251,7 +164,7 @@ export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenF
|
|
|
251
164
|
break;
|
|
252
165
|
default: {
|
|
253
166
|
// This case should never happen, if it does it should be reported to us
|
|
254
|
-
|
|
167
|
+
initializeArgs.onError({
|
|
255
168
|
errorMessage: `Report to developers@tryfinch.com: unable to handle window.postMessage for: ${JSON.stringify(
|
|
256
169
|
event.data
|
|
257
170
|
)}`,
|
|
@@ -265,7 +178,7 @@ export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenF
|
|
|
265
178
|
window.removeEventListener('message', handleFinchAuth);
|
|
266
179
|
isUseFinchConnectInitialized = false;
|
|
267
180
|
};
|
|
268
|
-
}, [
|
|
181
|
+
}, [initializeArgs.onClose, initializeArgs.onError, initializeArgs.onSuccess]);
|
|
269
182
|
|
|
270
183
|
return {
|
|
271
184
|
open,
|