@tryfinch/react-connect 2.8.1 → 3.1.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  module.exports = {
2
- extends: ['airbnb', 'plugin:prettier/recommended', 'prettier/react'],
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
- [![NPM](https://img.shields.io/npm/v/@tryfinch/react-connect)](https://www.npmjs.com/package/@tryfinch/react-connect) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3
+ [![NPM](https://img.shields.io/npm/v/@tryfinch/react-connect)](https://www.npmjs.com/package/@tryfinch/react-connect)
4
4
 
5
5
  ## Install
6
6
 
package/dist/index.d.ts CHANGED
@@ -1,25 +1,26 @@
1
- declare module 'react-finch-connect' {
2
- export type SuccessEvent = {
1
+ export type SuccessEvent = {
3
2
  code: string;
4
- };
5
-
6
- export type ErrorEvent = {
3
+ state?: string;
4
+ };
5
+ export type ErrorEvent = {
7
6
  errorMessage: string;
8
- };
9
-
10
- export type ConnectOptions = {
7
+ };
8
+ export type ConnectOptions = {
9
+ category: string | null;
11
10
  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
- }
11
+ manual: boolean;
12
+ state: string | null;
13
+ onSuccess: (e: SuccessEvent) => void;
14
+ onError: (e: ErrorEvent) => void;
15
+ onClose: () => void;
16
+ payrollProvider: string | null;
17
+ products: string[];
18
+ sandbox: boolean;
19
+ zIndex: number;
20
+ };
21
+ type OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products'>>) => void;
22
+ export declare const useFinchConnect: (options: Partial<ConnectOptions>) => {
23
+ open: OpenFn;
24
+ };
25
+ export {};
26
+ //# 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;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,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,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,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;AAwE9E,eAAO,MAAM,eAAe,YAAa,QAAQ,cAAc,CAAC;UAAW,MAAM;CA+EhF,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,119 +1,112 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
- var BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
4
- var DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
5
- var FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
6
- var FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
7
-
8
- var noop = function noop() {}; // eslint-disable-next-line import/prefer-default-export
9
-
10
-
11
- var useFinchConnect = function useFinchConnect() {
12
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
13
- var clientId = options.clientId,
14
- _options$products = options.products,
15
- products = _options$products === void 0 ? [] : _options$products,
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, state, }) => {
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', mode);
43
- if (manual) authUrl.searchParams.append('manual', manual);
44
- if (sandbox) authUrl.searchParams.append('sandbox', sandbox);
45
- /* global "2.8.1" */
46
-
47
- authUrl.searchParams.append('sdk_version', "react-".concat("2.8.1"));
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
+ if (state)
24
+ authUrl.searchParams.append('state', state);
25
+ // replace with actual SDK version by rollup
26
+ authUrl.searchParams.append('sdk_version', 'react-3.1.0');
48
27
  return authUrl.href;
49
- };
50
-
51
- var open = function open() {
52
- if (document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
53
- return null;
54
- }
55
-
56
- var iframe = document.createElement('iframe');
57
- iframe.src = _constructAuthUrl(clientId, products);
58
- iframe.frameBorder = '0';
59
- iframe.id = FINCH_CONNECT_IFRAME_ID;
60
- iframe.style.position = 'fixed';
61
- iframe.style.zIndex = zIndex.toString();
62
- iframe.style.height = '100%';
63
- iframe.style.width = '100%';
64
- iframe.style.top = '0';
65
- iframe.style.backgroundColor = 'none transparent';
66
- iframe.style.border = 'none';
67
- document.body.prepend(iframe);
68
- document.body.style.overflow = 'hidden';
69
- };
70
-
71
- var close = function close() {
72
- var frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
73
-
74
- if (frameToRemove) {
75
- frameToRemove.parentNode.removeChild(frameToRemove);
76
- document.body.style.overflow = 'inherit';
77
- }
78
- };
79
-
80
- useEffect(function () {
81
- function handleFinchAuth(event) {
82
- var handleFinchAuthSuccess = function handleFinchAuthSuccess(code) {
83
- return onSuccess({
84
- code: code
85
- });
86
- };
87
-
88
- var handleFinchAuthError = function handleFinchAuthError(error) {
89
- return onError({
90
- errorMessage: error
91
- });
92
- };
93
-
94
- var handleFinchAuthClose = function handleFinchAuthClose() {
95
- return onClose();
96
- };
97
-
98
- if (!event.data) return;
99
- if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return;
100
- if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI)) return;
101
- var _event$data = event.data,
102
- code = _event$data.code,
103
- error = _event$data.error,
104
- closed = _event$data.closed;
105
- close();
106
- if (code) handleFinchAuthSuccess(code);else if (error) handleFinchAuthError(error);else if (closed) handleFinchAuthClose();
107
- }
108
-
109
- window.addEventListener('message', handleFinchAuth);
110
- return function () {
111
- return window.removeEventListener('message', handleFinchAuth);
28
+ };
29
+ const noop = () => {
30
+ // intentionally empty
31
+ };
32
+ const DEFAULT_OPTIONS = {
33
+ category: null,
34
+ manual: false,
35
+ onSuccess: noop,
36
+ onError: noop,
37
+ onClose: noop,
38
+ payrollProvider: null,
39
+ products: [],
40
+ sandbox: false,
41
+ state: null,
42
+ zIndex: 999,
43
+ };
44
+ const useFinchConnect = (options) => {
45
+ if (!options.clientId)
46
+ throw new Error('must specify clientId in options for useFinchConnect');
47
+ const combinedOptions = Object.assign(Object.assign({ clientId: '' }, DEFAULT_OPTIONS), options);
48
+ const open = (overrides) => {
49
+ const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
50
+ if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
51
+ const iframe = document.createElement('iframe');
52
+ iframe.src = constructAuthUrl(openOptions);
53
+ iframe.frameBorder = '0';
54
+ iframe.id = FINCH_CONNECT_IFRAME_ID;
55
+ iframe.style.position = 'fixed';
56
+ iframe.style.zIndex = openOptions.zIndex.toString();
57
+ iframe.style.height = '100%';
58
+ iframe.style.width = '100%';
59
+ iframe.style.top = '0';
60
+ iframe.style.backgroundColor = 'none transparent';
61
+ iframe.style.border = 'none';
62
+ document.body.prepend(iframe);
63
+ document.body.style.overflow = 'hidden';
64
+ }
65
+ };
66
+ const close = () => {
67
+ var _a;
68
+ const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
69
+ if (frameToRemove) {
70
+ (_a = frameToRemove.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(frameToRemove);
71
+ document.body.style.overflow = 'inherit';
72
+ }
73
+ };
74
+ useEffect(() => {
75
+ function handleFinchAuth(event) {
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
+ close();
83
+ switch (event.data.kind) {
84
+ case 'closed':
85
+ combinedOptions.onClose();
86
+ break;
87
+ case 'error':
88
+ combinedOptions.onError({ errorMessage: event.data.error });
89
+ break;
90
+ case 'success':
91
+ combinedOptions.onSuccess({
92
+ code: event.data.code,
93
+ state: event.data.state,
94
+ });
95
+ break;
96
+ default: {
97
+ // This case should never happen, if it does it should be reported to us
98
+ combinedOptions.onError({
99
+ errorMessage: `Report to developers@tryfinch.com: unable to handle window.postMessage for: ${JSON.stringify(event.data)}`,
100
+ });
101
+ }
102
+ }
103
+ }
104
+ window.addEventListener('message', handleFinchAuth);
105
+ return () => window.removeEventListener('message', handleFinchAuth);
106
+ }, [combinedOptions.onClose, combinedOptions.onError, combinedOptions.onSuccess]);
107
+ return {
108
+ open,
112
109
  };
113
- }, [onClose, onError, onSuccess]);
114
- return {
115
- open: open
116
- };
117
110
  };
118
111
 
119
112
  export { useFinchConnect };
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/index.js"],"sourcesContent":["import { useEffect } from 'react';\n\nconst BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';\nconst DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';\nconst FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';\nconst FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';\n\nconst noop = () => {};\n\n// eslint-disable-next-line import/prefer-default-export\nexport const useFinchConnect = (options = {}) => {\n const {\n clientId,\n products = [],\n mode = 'employer',\n category,\n manual = false,\n payrollProvider = null,\n sandbox = false,\n onSuccess = noop,\n onError = noop,\n onClose = noop,\n zIndex = 999,\n } = options;\n\n const _constructAuthUrl = (clientId, products) => {\n const authUrl = new URL(`${BASE_FINCH_CONNECT_URI}/authorize`);\n\n if (clientId) authUrl.searchParams.append('client_id', clientId);\n if (payrollProvider) authUrl.searchParams.append('payroll_provider', payrollProvider);\n if (category) authUrl.searchParams.append('category', category);\n authUrl.searchParams.append('products', products.join(' '));\n authUrl.searchParams.append('app_type', 'spa');\n authUrl.searchParams.append('redirect_uri', DEFAULT_FINCH_REDIRECT_URI);\n authUrl.searchParams.append('mode', mode);\n if (manual) authUrl.searchParams.append('manual', manual);\n if (sandbox) authUrl.searchParams.append('sandbox', sandbox);\n /* global SDK_VERSION */\n if (SDK_VERSION) authUrl.searchParams.append('sdk_version', `react-${SDK_VERSION}`);\n\n return authUrl.href;\n };\n\n const open = () => {\n if (document.getElementById(FINCH_CONNECT_IFRAME_ID)) {\n return null;\n }\n\n const iframe = document.createElement('iframe');\n iframe.src = _constructAuthUrl(clientId, products);\n iframe.frameBorder = '0';\n iframe.id = FINCH_CONNECT_IFRAME_ID;\n iframe.style.position = 'fixed';\n iframe.style.zIndex = zIndex.toString();\n iframe.style.height = '100%';\n iframe.style.width = '100%';\n iframe.style.top = '0';\n iframe.style.backgroundColor = 'none transparent';\n iframe.style.border = 'none';\n document.body.prepend(iframe);\n document.body.style.overflow = 'hidden';\n };\n\n const close = () => {\n const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);\n if (frameToRemove) {\n frameToRemove.parentNode.removeChild(frameToRemove);\n document.body.style.overflow = 'inherit';\n }\n };\n\n useEffect(() => {\n function handleFinchAuth(event) {\n const handleFinchAuthSuccess = (code) => onSuccess({ code });\n const handleFinchAuthError = (error) => onError({ errorMessage: error });\n const handleFinchAuthClose = () => onClose();\n\n if (!event.data) return;\n if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return;\n if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI)) return;\n\n const { code, error, closed } = event.data;\n\n close();\n if (code) handleFinchAuthSuccess(code);\n else if (error) handleFinchAuthError(error);\n else if (closed) handleFinchAuthClose();\n }\n\n window.addEventListener('message', handleFinchAuth);\n return () => window.removeEventListener('message', handleFinchAuth);\n }, [onClose, onError, onSuccess]);\n\n return {\n open,\n };\n};\n"],"names":["BASE_FINCH_CONNECT_URI","DEFAULT_FINCH_REDIRECT_URI","FINCH_CONNECT_IFRAME_ID","FINCH_AUTH_MESSAGE_NAME","noop","useFinchConnect","options","clientId","products","mode","category","manual","payrollProvider","sandbox","onSuccess","onError","onClose","zIndex","_constructAuthUrl","authUrl","URL","searchParams","append","join","SDK_VERSION","href","open","document","getElementById","iframe","createElement","src","frameBorder","id","style","position","toString","height","width","top","backgroundColor","border","body","prepend","overflow","close","frameToRemove","parentNode","removeChild","useEffect","handleFinchAuth","event","handleFinchAuthSuccess","code","handleFinchAuthError","error","errorMessage","handleFinchAuthClose","data","name","origin","startsWith","closed","window","addEventListener","removeEventListener"],"mappings":";;AAEA,IAAMA,sBAAsB,GAAG,8BAA/B,CAAA;AACA,IAAMC,0BAA0B,GAAG,sBAAnC,CAAA;AACA,IAAMC,uBAAuB,GA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AM,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,113 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
 
7
- var BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com';
8
- var DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com';
9
- var FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe';
10
- var FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message';
11
-
12
- var noop = function noop() {}; // eslint-disable-next-line import/prefer-default-export
13
-
14
-
15
- var useFinchConnect = function useFinchConnect() {
16
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
- var clientId = options.clientId,
18
- _options$products = options.products,
19
- products = _options$products === void 0 ? [] : _options$products,
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, state, }) => {
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', mode);
47
- if (manual) authUrl.searchParams.append('manual', manual);
48
- if (sandbox) authUrl.searchParams.append('sandbox', sandbox);
49
- /* global "2.8.1" */
50
-
51
- authUrl.searchParams.append('sdk_version', "react-".concat("2.8.1"));
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
+ if (state)
28
+ authUrl.searchParams.append('state', state);
29
+ // replace with actual SDK version by rollup
30
+ authUrl.searchParams.append('sdk_version', 'react-3.1.0');
52
31
  return authUrl.href;
53
- };
54
-
55
- var open = function open() {
56
- if (document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
57
- return null;
58
- }
59
-
60
- var iframe = document.createElement('iframe');
61
- iframe.src = _constructAuthUrl(clientId, products);
62
- iframe.frameBorder = '0';
63
- iframe.id = FINCH_CONNECT_IFRAME_ID;
64
- iframe.style.position = 'fixed';
65
- iframe.style.zIndex = zIndex.toString();
66
- iframe.style.height = '100%';
67
- iframe.style.width = '100%';
68
- iframe.style.top = '0';
69
- iframe.style.backgroundColor = 'none transparent';
70
- iframe.style.border = 'none';
71
- document.body.prepend(iframe);
72
- document.body.style.overflow = 'hidden';
73
- };
74
-
75
- var close = function close() {
76
- var frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
77
-
78
- if (frameToRemove) {
79
- frameToRemove.parentNode.removeChild(frameToRemove);
80
- document.body.style.overflow = 'inherit';
81
- }
82
- };
83
-
84
- react.useEffect(function () {
85
- function handleFinchAuth(event) {
86
- var handleFinchAuthSuccess = function handleFinchAuthSuccess(code) {
87
- return onSuccess({
88
- code: code
89
- });
90
- };
91
-
92
- var handleFinchAuthError = function handleFinchAuthError(error) {
93
- return onError({
94
- errorMessage: error
95
- });
96
- };
97
-
98
- var handleFinchAuthClose = function handleFinchAuthClose() {
99
- return onClose();
100
- };
101
-
102
- if (!event.data) return;
103
- if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return;
104
- if (!event.origin.startsWith(BASE_FINCH_CONNECT_URI)) return;
105
- var _event$data = event.data,
106
- code = _event$data.code,
107
- error = _event$data.error,
108
- closed = _event$data.closed;
109
- close();
110
- if (code) handleFinchAuthSuccess(code);else if (error) handleFinchAuthError(error);else if (closed) handleFinchAuthClose();
111
- }
112
-
113
- window.addEventListener('message', handleFinchAuth);
114
- return function () {
115
- return window.removeEventListener('message', handleFinchAuth);
32
+ };
33
+ const noop = () => {
34
+ // intentionally empty
35
+ };
36
+ const DEFAULT_OPTIONS = {
37
+ category: null,
38
+ manual: false,
39
+ onSuccess: noop,
40
+ onError: noop,
41
+ onClose: noop,
42
+ payrollProvider: null,
43
+ products: [],
44
+ sandbox: false,
45
+ state: null,
46
+ zIndex: 999,
47
+ };
48
+ const useFinchConnect = (options) => {
49
+ if (!options.clientId)
50
+ throw new Error('must specify clientId in options for useFinchConnect');
51
+ const combinedOptions = Object.assign(Object.assign({ clientId: '' }, DEFAULT_OPTIONS), options);
52
+ const open = (overrides) => {
53
+ const openOptions = Object.assign(Object.assign({}, combinedOptions), overrides);
54
+ if (!document.getElementById(FINCH_CONNECT_IFRAME_ID)) {
55
+ const iframe = document.createElement('iframe');
56
+ iframe.src = constructAuthUrl(openOptions);
57
+ iframe.frameBorder = '0';
58
+ iframe.id = FINCH_CONNECT_IFRAME_ID;
59
+ iframe.style.position = 'fixed';
60
+ iframe.style.zIndex = openOptions.zIndex.toString();
61
+ iframe.style.height = '100%';
62
+ iframe.style.width = '100%';
63
+ iframe.style.top = '0';
64
+ iframe.style.backgroundColor = 'none transparent';
65
+ iframe.style.border = 'none';
66
+ document.body.prepend(iframe);
67
+ document.body.style.overflow = 'hidden';
68
+ }
69
+ };
70
+ const close = () => {
71
+ var _a;
72
+ const frameToRemove = document.getElementById(FINCH_CONNECT_IFRAME_ID);
73
+ if (frameToRemove) {
74
+ (_a = frameToRemove.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(frameToRemove);
75
+ document.body.style.overflow = 'inherit';
76
+ }
77
+ };
78
+ react.useEffect(() => {
79
+ function handleFinchAuth(event) {
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
+ close();
87
+ switch (event.data.kind) {
88
+ case 'closed':
89
+ combinedOptions.onClose();
90
+ break;
91
+ case 'error':
92
+ combinedOptions.onError({ errorMessage: event.data.error });
93
+ break;
94
+ case 'success':
95
+ combinedOptions.onSuccess({
96
+ code: event.data.code,
97
+ state: event.data.state,
98
+ });
99
+ break;
100
+ default: {
101
+ // This case should never happen, if it does it should be reported to us
102
+ combinedOptions.onError({
103
+ errorMessage: `Report to developers@tryfinch.com: unable to handle window.postMessage for: ${JSON.stringify(event.data)}`,
104
+ });
105
+ }
106
+ }
107
+ }
108
+ window.addEventListener('message', handleFinchAuth);
109
+ return () => window.removeEventListener('message', handleFinchAuth);
110
+ }, [combinedOptions.onClose, combinedOptions.onError, combinedOptions.onSuccess]);
111
+ return {
112
+ open,
116
113
  };
117
- }, [onClose, onError, onSuccess]);
118
- return {
119
- open: open
120
- };
121
114
  };
122
115
 
123
116
  exports.useFinchConnect = useFinchConnect;