@tryfinch/react-connect
Advanced tools
Comparing version 3.11.0 to 3.13.0
@@ -6,4 +6,6 @@ export type SuccessEvent = { | ||
}; | ||
type ErrorType = 'validation_error' | 'employer_connection_error'; | ||
export type ErrorEvent = { | ||
errorMessage: string; | ||
errorType?: ErrorType; | ||
}; | ||
@@ -33,2 +35,3 @@ export type Sandbox = 'finch' /** This is to enable the new Finch (simulated) Sandbox */ | 'provider' /** This is to enable the new Provider Sandbox */ | boolean /** This is the old sandbox flag retained for backwards compatibility */; | ||
clientName?: string; | ||
connectionId?: string; | ||
sandbox: Sandbox; | ||
@@ -35,0 +38,0 @@ }; |
import { useRef, useEffect } from 'react'; | ||
const POST_MESSAGE_NAME = 'finch-auth-message-v2'; | ||
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com'; | ||
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com'; | ||
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe'; | ||
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message'; | ||
const constructAuthUrl = (connectOptions) => { | ||
@@ -19,3 +19,3 @@ const { state, apiConfig } = connectOptions; | ||
else { | ||
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, } = connectOptions; | ||
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, connectionId, } = connectOptions; | ||
if (clientId) | ||
@@ -29,2 +29,4 @@ authUrl.searchParams.append('client_id', clientId); | ||
authUrl.searchParams.append('client_name', clientName); | ||
if (connectionId) | ||
authUrl.searchParams.append('connection_id', connectionId); | ||
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' ')); | ||
@@ -44,3 +46,3 @@ if (manual) | ||
// replace with actual SDK version by rollup | ||
authUrl.searchParams.append('sdk_version', 'react-3.11.0'); | ||
authUrl.searchParams.append('sdk_version', 'react-3.13.0'); | ||
return authUrl.href; | ||
@@ -110,11 +112,12 @@ }; | ||
function handleFinchAuth(event) { | ||
var _a; | ||
var _a, _b, _c, _d; | ||
const CONNECT_URL = ((_a = combinedOptions.apiConfig) === null || _a === void 0 ? void 0 : _a.connectUrl) || BASE_FINCH_CONNECT_URI; | ||
if (!event.data) | ||
return; | ||
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) | ||
if (event.data.name !== POST_MESSAGE_NAME) | ||
return; | ||
if (!event.origin.startsWith(CONNECT_URL)) | ||
return; | ||
close(); | ||
if (event.data.kind !== 'error') | ||
close(); | ||
switch (event.data.kind) { | ||
@@ -125,3 +128,8 @@ case 'closed': | ||
case 'error': | ||
combinedOptions.onError({ errorMessage: event.data.error }); | ||
if ((_b = event.data.error) === null || _b === void 0 ? void 0 : _b.shouldClose) | ||
close(); | ||
combinedOptions.onError({ | ||
errorMessage: (_c = event.data.error) === null || _c === void 0 ? void 0 : _c.message, | ||
errorType: (_d = event.data.error) === null || _d === void 0 ? void 0 : _d.type, | ||
}); | ||
break; | ||
@@ -128,0 +136,0 @@ case 'success': |
@@ -7,6 +7,6 @@ 'use strict'; | ||
const POST_MESSAGE_NAME = 'finch-auth-message-v2'; | ||
const BASE_FINCH_CONNECT_URI = 'https://connect.tryfinch.com'; | ||
const DEFAULT_FINCH_REDIRECT_URI = 'https://tryfinch.com'; | ||
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe'; | ||
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message'; | ||
const constructAuthUrl = (connectOptions) => { | ||
@@ -24,3 +24,3 @@ const { state, apiConfig } = connectOptions; | ||
else { | ||
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, } = connectOptions; | ||
const { clientId, payrollProvider, category, products, manual, sandbox, clientName, connectionId, } = connectOptions; | ||
if (clientId) | ||
@@ -34,2 +34,4 @@ authUrl.searchParams.append('client_id', clientId); | ||
authUrl.searchParams.append('client_name', clientName); | ||
if (connectionId) | ||
authUrl.searchParams.append('connection_id', connectionId); | ||
authUrl.searchParams.append('products', (products !== null && products !== void 0 ? products : []).join(' ')); | ||
@@ -49,3 +51,3 @@ if (manual) | ||
// replace with actual SDK version by rollup | ||
authUrl.searchParams.append('sdk_version', 'react-3.11.0'); | ||
authUrl.searchParams.append('sdk_version', 'react-3.13.0'); | ||
return authUrl.href; | ||
@@ -115,11 +117,12 @@ }; | ||
function handleFinchAuth(event) { | ||
var _a; | ||
var _a, _b, _c, _d; | ||
const CONNECT_URL = ((_a = combinedOptions.apiConfig) === null || _a === void 0 ? void 0 : _a.connectUrl) || BASE_FINCH_CONNECT_URI; | ||
if (!event.data) | ||
return; | ||
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) | ||
if (event.data.name !== POST_MESSAGE_NAME) | ||
return; | ||
if (!event.origin.startsWith(CONNECT_URL)) | ||
return; | ||
close(); | ||
if (event.data.kind !== 'error') | ||
close(); | ||
switch (event.data.kind) { | ||
@@ -130,3 +133,8 @@ case 'closed': | ||
case 'error': | ||
combinedOptions.onError({ errorMessage: event.data.error }); | ||
if ((_b = event.data.error) === null || _b === void 0 ? void 0 : _b.shouldClose) | ||
close(); | ||
combinedOptions.onError({ | ||
errorMessage: (_c = event.data.error) === null || _c === void 0 ? void 0 : _c.message, | ||
errorType: (_d = event.data.error) === null || _d === void 0 ? void 0 : _d.type, | ||
}); | ||
break; | ||
@@ -133,0 +141,0 @@ case 'success': |
{ | ||
"name": "@tryfinch/react-connect", | ||
"version": "3.11.0", | ||
"version": "3.13.0", | ||
"description": "Finch SDK for embedding Finch Connect in API React Single Page Applications (SPA)", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -21,3 +21,9 @@ # @tryfinch/react-connect | ||
const onSuccess = ({ code }) => setCode(code); | ||
const onError = ({ errorMessage }) => console.error(errorMessage); | ||
/** | ||
* @param {string} errorMessage - The error message | ||
* @param {'validation_error' | 'employer_error'} errorType - The type of error | ||
* - 'validation_error': Finch Connect failed to open due to validation error | ||
* - 'employer_connection_error': The errors employers see within the Finch Connect flow | ||
*/ | ||
const onError = ({ errorMessage, errorType }) => console.error(errorMessage, errorType); | ||
const onClose = () => console.log('User exited Finch Connect'); | ||
@@ -24,0 +30,0 @@ |
@@ -11,4 +11,7 @@ import { useEffect, useRef } from 'react'; | ||
type ErrorType = 'validation_error' | 'employer_connection_error'; | ||
export type ErrorEvent = { | ||
errorMessage: string; | ||
errorType?: ErrorType; | ||
}; | ||
@@ -47,2 +50,3 @@ | ||
clientName?: string; | ||
connectionId?: string; | ||
sandbox: Sandbox; | ||
@@ -55,3 +59,3 @@ }; | ||
const POST_MESSAGE_NAME = 'finch-auth-message' as const; | ||
const POST_MESSAGE_NAME = 'finch-auth-message-v2' as const; | ||
@@ -70,3 +74,3 @@ type FinchConnectAuthMessage = { name: typeof POST_MESSAGE_NAME } & ( | ||
kind: 'error'; | ||
error: string; | ||
error: { shouldClose: boolean; message: string; type: ErrorType }; | ||
} | ||
@@ -84,3 +88,2 @@ ); | ||
const FINCH_CONNECT_IFRAME_ID = 'finch-connect-iframe'; | ||
const FINCH_AUTH_MESSAGE_NAME = 'finch-auth-message'; | ||
@@ -108,2 +111,3 @@ const constructAuthUrl = (connectOptions: ConnectOptions) => { | ||
clientName, | ||
connectionId, | ||
} = connectOptions; | ||
@@ -115,2 +119,3 @@ | ||
if (clientName) authUrl.searchParams.append('client_name', clientName); | ||
if (connectionId) authUrl.searchParams.append('connection_id', connectionId); | ||
authUrl.searchParams.append('products', (products ?? []).join(' ')); | ||
@@ -229,6 +234,6 @@ if (manual) authUrl.searchParams.append('manual', String(manual)); | ||
if (!event.data) return; | ||
if (event.data.name !== FINCH_AUTH_MESSAGE_NAME) return; | ||
if (event.data.name !== POST_MESSAGE_NAME) return; | ||
if (!event.origin.startsWith(CONNECT_URL)) return; | ||
close(); | ||
if (event.data.kind !== 'error') close(); | ||
@@ -240,3 +245,8 @@ switch (event.data.kind) { | ||
case 'error': | ||
combinedOptions.onError({ errorMessage: event.data.error }); | ||
if (event.data.error?.shouldClose) close(); | ||
combinedOptions.onError({ | ||
errorMessage: event.data.error?.message, | ||
errorType: event.data.error?.type, | ||
}); | ||
break; | ||
@@ -243,0 +253,0 @@ case 'success': |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
946749
32286
57