@tryfinch/react-connect 2.8.1 → 3.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 +8 -1
- package/README.md +1 -1
- package/dist/index.d.ts +21 -22
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +90 -110
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +90 -110
- package/dist/index.js.map +1 -1
- package/package.json +16 -45
- package/rollup.config.js +9 -38
- package/src/index.ts +148 -0
- package/tsconfig.json +15 -0
- package/.babelrc +0 -9
- package/src/index.d.ts +0 -25
- package/src/index.js +0 -97
package/.eslintrc.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
extends: [
|
|
2
|
+
extends: [
|
|
3
|
+
'airbnb',
|
|
4
|
+
'plugin:prettier/recommended',
|
|
5
|
+
'prettier/react',
|
|
6
|
+
'plugin:@typescript-eslint/recommended',
|
|
7
|
+
],
|
|
8
|
+
parser: '@typescript-eslint/parser',
|
|
9
|
+
plugins: ['prettier', '@typescript-eslint'],
|
|
3
10
|
env: {
|
|
4
11
|
browser: true,
|
|
5
12
|
commonjs: true,
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tryfinch/react-connect
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@tryfinch/react-connect)
|
|
3
|
+
[](https://www.npmjs.com/package/@tryfinch/react-connect)
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
export type SuccessEvent = {
|
|
1
|
+
export type SuccessEvent = {
|
|
3
2
|
code: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type ErrorEvent = {
|
|
3
|
+
};
|
|
4
|
+
export type ErrorEvent = {
|
|
7
5
|
errorMessage: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
};
|
|
7
|
+
export type ConnectOptions = {
|
|
8
|
+
category: string | null;
|
|
11
9
|
clientId: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
10
|
+
manual: boolean;
|
|
11
|
+
onSuccess: (e: SuccessEvent) => void;
|
|
12
|
+
onError: (e: ErrorEvent) => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
payrollProvider: string | null;
|
|
15
|
+
products: string[];
|
|
16
|
+
sandbox: boolean;
|
|
17
|
+
zIndex: number;
|
|
18
|
+
};
|
|
19
|
+
type OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products'>>) => void;
|
|
20
|
+
export declare const useFinchConnect: (options: Partial<ConnectOptions>) => {
|
|
21
|
+
open: OpenFn;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,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,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,MAAM,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,KAAK,IAAI,CAAC;AA0D9E,eAAO,MAAM,eAAe,YAAa,QAAQ,cAAc,CAAC;UAAW,MAAM;CAkEhF,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,119 +1,99 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_options$mode = options.mode,
|
|
17
|
-
mode = _options$mode === void 0 ? 'employer' : _options$mode,
|
|
18
|
-
category = options.category,
|
|
19
|
-
_options$manual = options.manual,
|
|
20
|
-
manual = _options$manual === void 0 ? false : _options$manual,
|
|
21
|
-
_options$payrollProvi = options.payrollProvider,
|
|
22
|
-
payrollProvider = _options$payrollProvi === void 0 ? null : _options$payrollProvi,
|
|
23
|
-
_options$sandbox = options.sandbox,
|
|
24
|
-
sandbox = _options$sandbox === void 0 ? false : _options$sandbox,
|
|
25
|
-
_options$onSuccess = options.onSuccess,
|
|
26
|
-
onSuccess = _options$onSuccess === void 0 ? noop : _options$onSuccess,
|
|
27
|
-
_options$onError = options.onError,
|
|
28
|
-
onError = _options$onError === void 0 ? noop : _options$onError,
|
|
29
|
-
_options$onClose = options.onClose,
|
|
30
|
-
onClose = _options$onClose === void 0 ? noop : _options$onClose,
|
|
31
|
-
_options$zIndex = options.zIndex,
|
|
32
|
-
zIndex = _options$zIndex === void 0 ? 999 : _options$zIndex;
|
|
33
|
-
|
|
34
|
-
var _constructAuthUrl = function _constructAuthUrl(clientId, products) {
|
|
35
|
-
var authUrl = new URL("".concat(BASE_FINCH_CONNECT_URI, "/authorize"));
|
|
36
|
-
if (clientId) authUrl.searchParams.append('client_id', clientId);
|
|
37
|
-
if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
38
|
-
if (category) authUrl.searchParams.append('category', category);
|
|
39
|
-
authUrl.searchParams.append('products', products.join(' '));
|
|
3
|
+
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
4
|
+
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
5
|
+
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
6
|
+
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
|
|
7
|
+
const constructAuthUrl = ({ clientId, payrollProvider, category, products, manual, sandbox, }) => {
|
|
8
|
+
const authUrl = new URL(`${BASE_FINCH_CONNECT_URI}/authorize`);
|
|
9
|
+
if (clientId)
|
|
10
|
+
authUrl.searchParams.append('client_id', clientId);
|
|
11
|
+
if (payrollProvider)
|
|
12
|
+
authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
13
|
+
if (category)
|
|
14
|
+
authUrl.searchParams.append('category', category);
|
|
15
|
+
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' '));
|
|
40
16
|
authUrl.searchParams.append('app_type', 'spa');
|
|
41
17
|
authUrl.searchParams.append('redirect_uri', DEFAULT_FINCH_REDIRECT_URI);
|
|
42
|
-
authUrl.searchParams.append('mode',
|
|
43
|
-
if (manual)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
authUrl.searchParams.append('mode', 'employer');
|
|
19
|
+
if (manual)
|
|
20
|
+
authUrl.searchParams.append('manual', String(manual));
|
|
21
|
+
if (sandbox)
|
|
22
|
+
authUrl.searchParams.append('sandbox', String(sandbox));
|
|
23
|
+
// replace with actual SDK version by rollup
|
|
24
|
+
authUrl.searchParams.append('sdk_version', 'react-3.0.0');
|
|
48
25
|
return authUrl.href;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
26
|
+
};
|
|
27
|
+
const noop = () => {
|
|
28
|
+
// intentionally empty
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_OPTIONS = {
|
|
31
|
+
category: null,
|
|
32
|
+
manual: false,
|
|
33
|
+
onSuccess: noop,
|
|
34
|
+
onError: noop,
|
|
35
|
+
onClose: noop,
|
|
36
|
+
payrollProvider: null,
|
|
37
|
+
products: [],
|
|
38
|
+
sandbox: false,
|
|
39
|
+
zIndex: 999,
|
|
40
|
+
};
|
|
41
|
+
const useFinchConnect = (options) => {
|
|
42
|
+
if (!options.clientId)
|
|
43
|
+
throw new Error('must specify clientId in options for useFinchConnect');
|
|
44
|
+
const combinedOptions = Object.assign(Object.assign({ clientId: '' }, DEFAULT_OPTIONS), options);
|
|
45
|
+
const open = (overrides) => {
|
|
46
|
+
const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
|
|
47
|
+
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
48
|
+
const iframe = document.createElement('iframe');
|
|
49
|
+
iframe.src = constructAuthUrl(openOptions);
|
|
50
|
+
iframe.frameBorder = '0';
|
|
51
|
+
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
52
|
+
iframe.style.position = 'fixed';
|
|
53
|
+
iframe.style.zIndex = openOptions.zIndex.toString();
|
|
54
|
+
iframe.style.height = '100%';
|
|
55
|
+
iframe.style.width = '100%';
|
|
56
|
+
iframe.style.top = '0';
|
|
57
|
+
iframe.style.backgroundColor = 'none transparent';
|
|
58
|
+
iframe.style.border = 'none';
|
|
59
|
+
document.body.prepend(iframe);
|
|
60
|
+
document.body.style.overflow = 'hidden';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const close = () => {
|
|
64
|
+
var _a;
|
|
65
|
+
const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
|
|
66
|
+
if (frameToRemove) {
|
|
67
|
+
(_a = frameToRemove.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(frameToRemove);
|
|
68
|
+
document.body.style.overflow = 'inherit';
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
function handleFinchAuth(event) {
|
|
73
|
+
const handleFinchAuthSuccess = (code) => combinedOptions.onSuccess({ code });
|
|
74
|
+
const handleFinchAuthError = (error) => combinedOptions.onError({ errorMessage: error });
|
|
75
|
+
const handleFinchAuthClose = () => combinedOptions.onClose();
|
|
76
|
+
if (!event.data)
|
|
77
|
+
return;
|
|
78
|
+
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME)
|
|
79
|
+
return;
|
|
80
|
+
if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI))
|
|
81
|
+
return;
|
|
82
|
+
const { code, error, closed } = event.data;
|
|
83
|
+
close();
|
|
84
|
+
if (code)
|
|
85
|
+
handleFinchAuthSuccess(code);
|
|
86
|
+
else if (error)
|
|
87
|
+
handleFinchAuthError(error);
|
|
88
|
+
else if (closed)
|
|
89
|
+
handleFinchAuthClose();
|
|
90
|
+
}
|
|
91
|
+
window.addEventListener('message', handleFinchAuth);
|
|
92
|
+
return () => window.removeEventListener('message', handleFinchAuth);
|
|
93
|
+
}, [combinedOptions.onClose, combinedOptions.onError, combinedOptions.onSuccess]);
|
|
94
|
+
return {
|
|
95
|
+
open,
|
|
112
96
|
};
|
|
113
|
-
}, [onClose, onError, onSuccess]);
|
|
114
|
-
return {
|
|
115
|
-
open: open
|
|
116
|
-
};
|
|
117
97
|
};
|
|
118
98
|
|
|
119
99
|
export { useFinchConnect };
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAmCA,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAC9D,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAC1D,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AACvD,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAErD,MAAM,gBAAgB,GAAG,CAAC,EACxB,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACiB,KAAI;IAC5B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAG,EAAA,sBAAsB,CAAY,UAAA,CAAA,CAAC,CAAC;AAE/D,IAAA,IAAI,QAAQ;QAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACjE,IAAA,IAAI,eAAe;Q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,CAAC;AACR,YAAA,IAAI,IAAI;gBAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;AAClC,iBAAA,IAAI,KAAK;gBAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACvC,iBAAA,IAAI,MAAM;AAAE,gBAAA,oBAAoB,EAAE,CAAC;SACzC;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QACpD,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AACtE,KAAC,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;IAElF,OAAO;QACL,IAAI;KACL,CAAC;AACJ;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -4,120 +4,100 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_options$mode = options.mode,
|
|
21
|
-
mode = _options$mode === void 0 ? 'employer' : _options$mode,
|
|
22
|
-
category = options.category,
|
|
23
|
-
_options$manual = options.manual,
|
|
24
|
-
manual = _options$manual === void 0 ? false : _options$manual,
|
|
25
|
-
_options$payrollProvi = options.payrollProvider,
|
|
26
|
-
payrollProvider = _options$payrollProvi === void 0 ? null : _options$payrollProvi,
|
|
27
|
-
_options$sandbox = options.sandbox,
|
|
28
|
-
sandbox = _options$sandbox === void 0 ? false : _options$sandbox,
|
|
29
|
-
_options$onSuccess = options.onSuccess,
|
|
30
|
-
onSuccess = _options$onSuccess === void 0 ? noop : _options$onSuccess,
|
|
31
|
-
_options$onError = options.onError,
|
|
32
|
-
onError = _options$onError === void 0 ? noop : _options$onError,
|
|
33
|
-
_options$onClose = options.onClose,
|
|
34
|
-
onClose = _options$onClose === void 0 ? noop : _options$onClose,
|
|
35
|
-
_options$zIndex = options.zIndex,
|
|
36
|
-
zIndex = _options$zIndex === void 0 ? 999 : _options$zIndex;
|
|
37
|
-
|
|
38
|
-
var _constructAuthUrl = function _constructAuthUrl(clientId, products) {
|
|
39
|
-
var authUrl = new URL("".concat(BASE_FINCH_CONNECT_URI, "/authorize"));
|
|
40
|
-
if (clientId) authUrl.searchParams.append('client_id', clientId);
|
|
41
|
-
if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
42
|
-
if (category) authUrl.searchParams.append('category', category);
|
|
43
|
-
authUrl.searchParams.append('products', products.join(' '));
|
|
7
|
+
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
8
|
+
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
9
|
+
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
10
|
+
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
|
|
11
|
+
const constructAuthUrl = ({ clientId, payrollProvider, category, products, manual, sandbox, }) => {
|
|
12
|
+
const authUrl = new URL(`${BASE_FINCH_CONNECT_URI}/authorize`);
|
|
13
|
+
if (clientId)
|
|
14
|
+
authUrl.searchParams.append('client_id', clientId);
|
|
15
|
+
if (payrollProvider)
|
|
16
|
+
authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
17
|
+
if (category)
|
|
18
|
+
authUrl.searchParams.append('category', category);
|
|
19
|
+
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' '));
|
|
44
20
|
authUrl.searchParams.append('app_type', 'spa');
|
|
45
21
|
authUrl.searchParams.append('redirect_uri', DEFAULT_FINCH_REDIRECT_URI);
|
|
46
|
-
authUrl.searchParams.append('mode',
|
|
47
|
-
if (manual)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
22
|
+
authUrl.searchParams.append('mode', 'employer');
|
|
23
|
+
if (manual)
|
|
24
|
+
authUrl.searchParams.append('manual', String(manual));
|
|
25
|
+
if (sandbox)
|
|
26
|
+
authUrl.searchParams.append('sandbox', String(sandbox));
|
|
27
|
+
// replace with actual SDK version by rollup
|
|
28
|
+
authUrl.searchParams.append('sdk_version', 'react-3.0.0');
|
|
52
29
|
return authUrl.href;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
30
|
+
};
|
|
31
|
+
const noop = () => {
|
|
32
|
+
// intentionally empty
|
|
33
|
+
};
|
|
34
|
+
const DEFAULT_OPTIONS = {
|
|
35
|
+
category: null,
|
|
36
|
+
manual: false,
|
|
37
|
+
onSuccess: noop,
|
|
38
|
+
onError: noop,
|
|
39
|
+
onClose: noop,
|
|
40
|
+
payrollProvider: null,
|
|
41
|
+
products: [],
|
|
42
|
+
sandbox: false,
|
|
43
|
+
zIndex: 999,
|
|
44
|
+
};
|
|
45
|
+
const useFinchConnect = (options) => {
|
|
46
|
+
if (!options.clientId)
|
|
47
|
+
throw new Error('must specify clientId in options for useFinchConnect');
|
|
48
|
+
const combinedOptions = Object.assign(Object.assign({ clientId: '' }, DEFAULT_OPTIONS), options);
|
|
49
|
+
const open = (overrides) => {
|
|
50
|
+
const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
|
|
51
|
+
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
52
|
+
const iframe = document.createElement('iframe');
|
|
53
|
+
iframe.src = constructAuthUrl(openOptions);
|
|
54
|
+
iframe.frameBorder = '0';
|
|
55
|
+
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
56
|
+
iframe.style.position = 'fixed';
|
|
57
|
+
iframe.style.zIndex = openOptions.zIndex.toString();
|
|
58
|
+
iframe.style.height = '100%';
|
|
59
|
+
iframe.style.width = '100%';
|
|
60
|
+
iframe.style.top = '0';
|
|
61
|
+
iframe.style.backgroundColor = 'none transparent';
|
|
62
|
+
iframe.style.border = 'none';
|
|
63
|
+
document.body.prepend(iframe);
|
|
64
|
+
document.body.style.overflow = 'hidden';
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const close = () => {
|
|
68
|
+
var _a;
|
|
69
|
+
const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
|
|
70
|
+
if (frameToRemove) {
|
|
71
|
+
(_a = frameToRemove.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(frameToRemove);
|
|
72
|
+
document.body.style.overflow = 'inherit';
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
react.useEffect(() => {
|
|
76
|
+
function handleFinchAuth(event) {
|
|
77
|
+
const handleFinchAuthSuccess = (code) => combinedOptions.onSuccess({ code });
|
|
78
|
+
const handleFinchAuthError = (error) => combinedOptions.onError({ errorMessage: error });
|
|
79
|
+
const handleFinchAuthClose = () => combinedOptions.onClose();
|
|
80
|
+
if (!event.data)
|
|
81
|
+
return;
|
|
82
|
+
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME)
|
|
83
|
+
return;
|
|
84
|
+
if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI))
|
|
85
|
+
return;
|
|
86
|
+
const { code, error, closed } = event.data;
|
|
87
|
+
close();
|
|
88
|
+
if (code)
|
|
89
|
+
handleFinchAuthSuccess(code);
|
|
90
|
+
else if (error)
|
|
91
|
+
handleFinchAuthError(error);
|
|
92
|
+
else if (closed)
|
|
93
|
+
handleFinchAuthClose();
|
|
94
|
+
}
|
|
95
|
+
window.addEventListener('message', handleFinchAuth);
|
|
96
|
+
return () => window.removeEventListener('message', handleFinchAuth);
|
|
97
|
+
}, [combinedOptions.onClose, combinedOptions.onError, combinedOptions.onSuccess]);
|
|
98
|
+
return {
|
|
99
|
+
open,
|
|
116
100
|
};
|
|
117
|
-
}, [onClose, onError, onSuccess]);
|
|
118
|
-
return {
|
|
119
|
-
open: open
|
|
120
|
-
};
|
|
121
101
|
};
|
|
122
102
|
|
|
123
103
|
exports.useFinchConnect = useFinchConnect;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/index.ts"],"sourcesContent":[null],"names":["useEffect"],"mappings":";;;;;;AAmCA,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAC9D,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAC1D,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AACvD,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAErD,MAAM,gBAAgB,GAAG,CAAC,EACxB,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACiB,KAAI;IAC5B,MAAM,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B;gBAAE,OAAO;YACxD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,sBAAsB,CAAC;gBAAE,OAAO;YAE7D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC;AAE3C,YAAA,KAAK,EAAE,CAAC;AACR,YAAA,IAAI,IAAI;gBAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;AAClC,iBAAA,IAAI,KAAK;gBAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACvC,iBAAA,IAAI,MAAM;AAAE,gBAAA,oBAAoB,EAAE,CAAC;SACzC;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QACpD,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AACtE,KAAC,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;IAElF,OAAO;QACL,IAAI;KACL,CAAC;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryfinch/react-connect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Finch SDK for embedding Finch Connect in API React Single Page Applications (SPA)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"finch",
|
|
7
|
+
"sdk",
|
|
8
|
+
"payroll",
|
|
9
|
+
"react",
|
|
10
|
+
"oauth"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://tryfinch.com/",
|
|
5
13
|
"author": "",
|
|
6
14
|
"license": "MIT",
|
|
7
|
-
"repository": "Finch-API/react-
|
|
15
|
+
"repository": "Finch-API/react-connect",
|
|
8
16
|
"main": "dist/index.js",
|
|
9
17
|
"types": "dist/index.d.ts",
|
|
10
18
|
"module": "dist/index.es.js",
|
|
@@ -14,9 +22,8 @@
|
|
|
14
22
|
"npm": ">=5"
|
|
15
23
|
},
|
|
16
24
|
"scripts": {
|
|
17
|
-
"test": "cross-env CI=1 react-scripts test --env=jsdom",
|
|
18
|
-
"test:watch": "react-scripts test --env=jsdom",
|
|
19
25
|
"build": "rollup -c",
|
|
26
|
+
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
|
|
20
27
|
"start": "rollup -c -w",
|
|
21
28
|
"prepare": "npm run build",
|
|
22
29
|
"predeploy": "cd example && npm install && npm run build"
|
|
@@ -25,54 +32,18 @@
|
|
|
25
32
|
"react": ">=16.9.0"
|
|
26
33
|
},
|
|
27
34
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "^7.0.0",
|
|
29
|
-
"@babel/plugin-external-helpers": "^7.0.0",
|
|
30
|
-
"@babel/plugin-proposal-class-properties": "^7.0.0",
|
|
31
|
-
"@babel/plugin-proposal-decorators": "^7.0.0",
|
|
32
|
-
"@babel/plugin-proposal-do-expressions": "^7.0.0",
|
|
33
|
-
"@babel/plugin-proposal-export-default-from": "^7.0.0",
|
|
34
|
-
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
|
|
35
|
-
"@babel/plugin-proposal-function-bind": "^7.0.0",
|
|
36
|
-
"@babel/plugin-proposal-function-sent": "^7.0.0",
|
|
37
|
-
"@babel/plugin-proposal-json-strings": "^7.0.0",
|
|
38
|
-
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
|
|
39
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
|
|
40
|
-
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
|
|
41
|
-
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
|
|
42
|
-
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
|
|
43
|
-
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
|
|
44
|
-
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
|
45
|
-
"@babel/plugin-syntax-import-meta": "^7.0.0",
|
|
46
|
-
"@babel/preset-env": "^7.0.0",
|
|
47
|
-
"@babel/preset-react": "^7.0.0",
|
|
48
35
|
"@rollup/plugin-replace": "^4.0.0",
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
37
|
+
"@types/react": "^16.14.40",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.59.0",
|
|
52
40
|
"eslint": "^7.32.0",
|
|
53
41
|
"eslint-config-airbnb": "^18.2.0",
|
|
54
42
|
"eslint-config-prettier": "^6.11.0",
|
|
55
|
-
"eslint-config-standard": "^11.0.0",
|
|
56
|
-
"eslint-config-standard-react": "^6.0.0",
|
|
57
|
-
"eslint-plugin-import": "^2.22.0",
|
|
58
|
-
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
59
|
-
"eslint-plugin-node": "^7.0.1",
|
|
60
43
|
"eslint-plugin-prettier": "^3.1.4",
|
|
61
|
-
"eslint-plugin-promise": "^4.0.0",
|
|
62
|
-
"eslint-plugin-react": "^7.20.3",
|
|
63
|
-
"eslint-plugin-react-hooks": "^4.0.8",
|
|
64
|
-
"eslint-plugin-standard": "^3.1.0",
|
|
65
|
-
"gh-pages": "^2.0.1",
|
|
66
|
-
"prettier": "^2.0.5",
|
|
67
44
|
"react": "^16.9.0",
|
|
68
|
-
"react-scripts": "^5.0.1",
|
|
69
|
-
"react-test-renderer": "^16.9.0",
|
|
70
45
|
"rollup": "^2.75.7",
|
|
71
|
-
"rollup-plugin-babel": "^4.3.2",
|
|
72
|
-
"rollup-plugin-commonjs": "^9.2.0",
|
|
73
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
74
|
-
"rollup-plugin-node-resolve": "^4.0.0",
|
|
75
46
|
"rollup-plugin-peer-deps-external": "^2.2.0",
|
|
76
|
-
"
|
|
47
|
+
"typescript": "^4.9.5"
|
|
77
48
|
}
|
|
78
49
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,49 +1,20 @@
|
|
|
1
|
-
import babel from 'rollup-plugin-babel';
|
|
2
|
-
import commonjs from 'rollup-plugin-commonjs';
|
|
3
|
-
import dts from 'rollup-plugin-dts';
|
|
4
1
|
import external from 'rollup-plugin-peer-deps-external';
|
|
5
|
-
import resolve from 'rollup-plugin-node-resolve';
|
|
6
|
-
import url from 'rollup-plugin-url';
|
|
7
2
|
import replace from '@rollup/plugin-replace';
|
|
3
|
+
import typescript from '@rollup/plugin-typescript';
|
|
8
4
|
|
|
9
5
|
import pkg from './package.json';
|
|
10
6
|
|
|
7
|
+
const plugins = [external(), replace({ SDK_VERSION: pkg.version }), typescript()];
|
|
8
|
+
|
|
11
9
|
export default [
|
|
12
10
|
{
|
|
13
|
-
input: 'src/index.
|
|
14
|
-
output: [
|
|
15
|
-
|
|
16
|
-
file: pkg.main,
|
|
17
|
-
format: 'cjs',
|
|
18
|
-
sourcemap: true,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
file: pkg.module,
|
|
22
|
-
format: 'es',
|
|
23
|
-
sourcemap: true,
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
plugins: [
|
|
27
|
-
external(),
|
|
28
|
-
url({ exclude: ['**/*.svg'] }),
|
|
29
|
-
babel({
|
|
30
|
-
exclude: 'node_modules/**',
|
|
31
|
-
}),
|
|
32
|
-
resolve(),
|
|
33
|
-
commonjs(),
|
|
34
|
-
replace({
|
|
35
|
-
SDK_VERSION: JSON.stringify(pkg.version), // has to be stringified somehow
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
11
|
+
input: 'src/index.ts',
|
|
12
|
+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
|
|
13
|
+
plugins,
|
|
38
14
|
},
|
|
39
15
|
{
|
|
40
|
-
input: 'src/index.
|
|
41
|
-
output: [
|
|
42
|
-
|
|
43
|
-
file: pkg.types,
|
|
44
|
-
format: 'es',
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
plugins: [dts()],
|
|
16
|
+
input: 'src/index.ts',
|
|
17
|
+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
|
|
18
|
+
plugins,
|
|
48
19
|
},
|
|
49
20
|
];
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export type SuccessEvent = {
|
|
4
|
+
code: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ErrorEvent = {
|
|
8
|
+
errorMessage: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ConnectOptions = {
|
|
12
|
+
category: string | null;
|
|
13
|
+
clientId: string;
|
|
14
|
+
manual: boolean;
|
|
15
|
+
onSuccess: (e: SuccessEvent) => void;
|
|
16
|
+
onError: (e: ErrorEvent) => void;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
payrollProvider: string | null;
|
|
19
|
+
products: string[];
|
|
20
|
+
sandbox: boolean;
|
|
21
|
+
zIndex: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products'>>) => void;
|
|
25
|
+
|
|
26
|
+
interface FinchConnectPostMessage {
|
|
27
|
+
data: {
|
|
28
|
+
name: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
closed?: boolean;
|
|
32
|
+
};
|
|
33
|
+
origin: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
37
|
+
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
38
|
+
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
39
|
+
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
|
|
40
|
+
|
|
41
|
+
const constructAuthUrl = ({
|
|
42
|
+
clientId,
|
|
43
|
+
payrollProvider,
|
|
44
|
+
category,
|
|
45
|
+
products,
|
|
46
|
+
manual,
|
|
47
|
+
sandbox,
|
|
48
|
+
}: Partial<ConnectOptions>) => {
|
|
49
|
+
const authUrl = new URL(`${BASE_FINCH_CONNECT_URI}/authorize`);
|
|
50
|
+
|
|
51
|
+
if (clientId) authUrl.searchParams.append('client_id', clientId);
|
|
52
|
+
if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
53
|
+
if (category) authUrl.searchParams.append('category', category);
|
|
54
|
+
authUrl.searchParams.append('products', (products ?? []).join(' '));
|
|
55
|
+
authUrl.searchParams.append('app_type', 'spa');
|
|
56
|
+
authUrl.searchParams.append('redirect_uri', DEFAULT_FINCH_REDIRECT_URI);
|
|
57
|
+
authUrl.searchParams.append('mode', 'employer');
|
|
58
|
+
if (manual) authUrl.searchParams.append('manual', String(manual));
|
|
59
|
+
if (sandbox) authUrl.searchParams.append('sandbox', String(sandbox));
|
|
60
|
+
// replace with actual SDK version by rollup
|
|
61
|
+
authUrl.searchParams.append('sdk_version', 'react-SDK_VERSION');
|
|
62
|
+
|
|
63
|
+
return authUrl.href;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const noop = () => {
|
|
67
|
+
// intentionally empty
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const DEFAULT_OPTIONS: Omit<ConnectOptions, 'clientId'> = {
|
|
71
|
+
category: null,
|
|
72
|
+
manual: false,
|
|
73
|
+
onSuccess: noop,
|
|
74
|
+
onError: noop,
|
|
75
|
+
onClose: noop,
|
|
76
|
+
payrollProvider: null,
|
|
77
|
+
products: [],
|
|
78
|
+
sandbox: false,
|
|
79
|
+
zIndex: 999,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const useFinchConnect = (options: Partial<ConnectOptions>): { open: OpenFn } => {
|
|
83
|
+
if (!options.clientId) throw new Error('must specify clientId in options for useFinchConnect');
|
|
84
|
+
|
|
85
|
+
const combinedOptions: ConnectOptions = {
|
|
86
|
+
clientId: '',
|
|
87
|
+
...DEFAULT_OPTIONS,
|
|
88
|
+
...options,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const open: OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products'>>) => {
|
|
92
|
+
const openOptions: ConnectOptions = {
|
|
93
|
+
...combinedOptions,
|
|
94
|
+
...overrides,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
98
|
+
const iframe = document.createElement('iframe');
|
|
99
|
+
iframe.src = constructAuthUrl(openOptions);
|
|
100
|
+
iframe.frameBorder = '0';
|
|
101
|
+
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
102
|
+
iframe.style.position = 'fixed';
|
|
103
|
+
iframe.style.zIndex = openOptions.zIndex.toString();
|
|
104
|
+
iframe.style.height = '100%';
|
|
105
|
+
iframe.style.width = '100%';
|
|
106
|
+
iframe.style.top = '0';
|
|
107
|
+
iframe.style.backgroundColor = 'none transparent';
|
|
108
|
+
iframe.style.border = 'none';
|
|
109
|
+
document.body.prepend(iframe);
|
|
110
|
+
document.body.style.overflow = 'hidden';
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const close = () => {
|
|
115
|
+
const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
|
|
116
|
+
if (frameToRemove) {
|
|
117
|
+
frameToRemove.parentNode?.removeChild(frameToRemove);
|
|
118
|
+
document.body.style.overflow = 'inherit';
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
function handleFinchAuth(event: FinchConnectPostMessage) {
|
|
124
|
+
const handleFinchAuthSuccess = (code: string) => combinedOptions.onSuccess({ code });
|
|
125
|
+
const handleFinchAuthError = (error: string) =>
|
|
126
|
+
combinedOptions.onError({ errorMessage: error });
|
|
127
|
+
const handleFinchAuthClose = () => combinedOptions.onClose();
|
|
128
|
+
|
|
129
|
+
if (!event.data) return;
|
|
130
|
+
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return;
|
|
131
|
+
if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI)) return;
|
|
132
|
+
|
|
133
|
+
const { code, error, closed } = event.data;
|
|
134
|
+
|
|
135
|
+
close();
|
|
136
|
+
if (code) handleFinchAuthSuccess(code);
|
|
137
|
+
else if (error) handleFinchAuthError(error);
|
|
138
|
+
else if (closed) handleFinchAuthClose();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
window.addEventListener('message', handleFinchAuth);
|
|
142
|
+
return () => window.removeEventListener('message', handleFinchAuth);
|
|
143
|
+
}, [combinedOptions.onClose, combinedOptions.onError, combinedOptions.onSuccess]);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
open,
|
|
147
|
+
};
|
|
148
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"declarationMap": true,
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"outDir": "./",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"strict": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"],
|
|
14
|
+
"exclude": ["node_modules", "example/**/*"]
|
|
15
|
+
}
|
package/.babelrc
DELETED
package/src/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
declare module 'react-finch-connect' {
|
|
2
|
-
export type SuccessEvent = {
|
|
3
|
-
code: string;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type ErrorEvent = {
|
|
7
|
-
errorMessage: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type ConnectOptions = {
|
|
11
|
-
clientId: string;
|
|
12
|
-
products?: string[];
|
|
13
|
-
mode?: string;
|
|
14
|
-
manual?: boolean;
|
|
15
|
-
payrollProvider?: string;
|
|
16
|
-
sandbox?: boolean;
|
|
17
|
-
category?: string;
|
|
18
|
-
onSuccess?: (e: SuccessEvent) => void;
|
|
19
|
-
onError?: (e: ErrorEvent) => void;
|
|
20
|
-
onClose?: () => void;
|
|
21
|
-
zIndex?: bigint | string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function useFinchConnect(opts: ConnectOptions): { open: () => void };
|
|
25
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
|
|
4
|
-
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
|
|
5
|
-
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
|
|
6
|
-
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
|
|
7
|
-
|
|
8
|
-
const noop = () => {};
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
11
|
-
export const useFinchConnect = (options = {}) => {
|
|
12
|
-
const {
|
|
13
|
-
clientId,
|
|
14
|
-
products = [],
|
|
15
|
-
mode = 'employer',
|
|
16
|
-
category,
|
|
17
|
-
manual = false,
|
|
18
|
-
payrollProvider = null,
|
|
19
|
-
sandbox = false,
|
|
20
|
-
onSuccess = noop,
|
|
21
|
-
onError = noop,
|
|
22
|
-
onClose = noop,
|
|
23
|
-
zIndex = 999,
|
|
24
|
-
} = options;
|
|
25
|
-
|
|
26
|
-
const _constructAuthUrl = (clientId, products) => {
|
|
27
|
-
const authUrl = new URL(`${BASE_FINCH_CONNECT_URI}/authorize`);
|
|
28
|
-
|
|
29
|
-
if (clientId) authUrl.searchParams.append('client_id', clientId);
|
|
30
|
-
if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);
|
|
31
|
-
if (category) authUrl.searchParams.append('category', category);
|
|
32
|
-
authUrl.searchParams.append('products', products.join(' '));
|
|
33
|
-
authUrl.searchParams.append('app_type', 'spa');
|
|
34
|
-
authUrl.searchParams.append('redirect_uri', DEFAULT_FINCH_REDIRECT_URI);
|
|
35
|
-
authUrl.searchParams.append('mode', mode);
|
|
36
|
-
if (manual) authUrl.searchParams.append('manual', manual);
|
|
37
|
-
if (sandbox) authUrl.searchParams.append('sandbox', sandbox);
|
|
38
|
-
/* global SDK_VERSION */
|
|
39
|
-
if (SDK_VERSION) authUrl.searchParams.append('sdk_version', `react-${SDK_VERSION}`);
|
|
40
|
-
|
|
41
|
-
return authUrl.href;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const open = () => {
|
|
45
|
-
if (document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const iframe = document.createElement('iframe');
|
|
50
|
-
iframe.src = _constructAuthUrl(clientId, products);
|
|
51
|
-
iframe.frameBorder = '0';
|
|
52
|
-
iframe.id = FINCH_CONNECT_IFRAME_ID;
|
|
53
|
-
iframe.style.position = 'fixed';
|
|
54
|
-
iframe.style.zIndex = zIndex.toString();
|
|
55
|
-
iframe.style.height = '100%';
|
|
56
|
-
iframe.style.width = '100%';
|
|
57
|
-
iframe.style.top = '0';
|
|
58
|
-
iframe.style.backgroundColor = 'none transparent';
|
|
59
|
-
iframe.style.border = 'none';
|
|
60
|
-
document.body.prepend(iframe);
|
|
61
|
-
document.body.style.overflow = 'hidden';
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const close = () => {
|
|
65
|
-
const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
|
|
66
|
-
if (frameToRemove) {
|
|
67
|
-
frameToRemove.parentNode.removeChild(frameToRemove);
|
|
68
|
-
document.body.style.overflow = 'inherit';
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
function handleFinchAuth(event) {
|
|
74
|
-
const handleFinchAuthSuccess = (code) => onSuccess({ code });
|
|
75
|
-
const handleFinchAuthError = (error) => onError({ errorMessage: error });
|
|
76
|
-
const handleFinchAuthClose = () => onClose();
|
|
77
|
-
|
|
78
|
-
if (!event.data) return;
|
|
79
|
-
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return;
|
|
80
|
-
if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI)) return;
|
|
81
|
-
|
|
82
|
-
const { code, error, closed } = event.data;
|
|
83
|
-
|
|
84
|
-
close();
|
|
85
|
-
if (code) handleFinchAuthSuccess(code);
|
|
86
|
-
else if (error) handleFinchAuthError(error);
|
|
87
|
-
else if (closed) handleFinchAuthClose();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
window.addEventListener('message', handleFinchAuth);
|
|
91
|
-
return () => window.removeEventListener('message', handleFinchAuth);
|
|
92
|
-
}, [onClose, onError, onSuccess]);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
open,
|
|
96
|
-
};
|
|
97
|
-
};
|