@parafin/react 6.3.1 → 6.4.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/out/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  declare const ParafinWidget: (props: WidgetProps) => import("react/jsx-runtime").JSX.Element;
2
2
  export { ParafinWidget };
3
3
  export type WidgetEvent = 'opted_in' | 'opted_out';
4
+ export type LinkOpenedMetadata = {
5
+ type: 'auth' | 'document' | 'webpage' | 'phone' | 'email';
6
+ };
4
7
  export type WidgetProps = {
5
8
  token: string;
6
9
  product: 'capital' | 'spend_card' | 'cash_account';
@@ -10,7 +13,8 @@ export type WidgetProps = {
10
13
  /** @deprecated Use onEvent with 'opted_in' event type instead */
11
14
  onOptIn?: () => Promise<OptInFields>;
12
15
  openInNewTab?: boolean;
13
- onLinkOpened?: (url: string) => void;
16
+ onLinkOpened?: (url: string, metadata: LinkOpenedMetadata) => void;
17
+ inWebView?: boolean;
14
18
  };
15
19
  type USStates = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'DC' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY';
16
20
  type USTerritories = 'AS' | 'GU' | 'MP' | 'PR' | 'VI';
package/out/index.js CHANGED
@@ -7,19 +7,23 @@ const openParafinDashboard = (props) => {
7
7
  // @ts-ignore
8
8
  props.dashboardUrlOverride ?? 'https://app.parafin.com');
9
9
  const route = 'route' in props ? props.route : '/';
10
+ const addPropIfExists = (key) => {
11
+ if (key in props && props[key] !== undefined && props[key] !== null) {
12
+ return { [key]: props[key] };
13
+ }
14
+ else {
15
+ return {};
16
+ }
17
+ };
10
18
  const query = {
11
19
  product: props.product,
12
20
  referrer: 'partner',
13
- ...('token' in props && { token: props.token }),
14
- ...('partner' in props && { partner: props.partner }),
15
- ...('externalBusinessId' in props && {
16
- externalBusinessId: props.externalBusinessId,
17
- }),
18
- ...('orderId' in props && { orderId: props.orderId }),
19
- ...('lineOfCreditApplicationId' in props && {
20
- lineOfCreditApplicationId: props.lineOfCreditApplicationId,
21
- }),
22
- ...('additionalQueryParams' in props && props.additionalQueryParams),
21
+ ...addPropIfExists('token'),
22
+ ...addPropIfExists('partner'),
23
+ ...addPropIfExists('externalBusinessId'),
24
+ ...addPropIfExists('orderId'),
25
+ ...addPropIfExists('lineOfCreditApplicationId'),
26
+ ...addPropIfExists('inWebView'),
23
27
  ...Object.fromEntries(searchParams),
24
28
  };
25
29
  const url = `${origin}${route}?${new URLSearchParams(query).toString()}`;
@@ -57,29 +61,32 @@ const openParafinDashboard = (props) => {
57
61
  if (!dashboardTargetElement) {
58
62
  throw new Error('Dashboard target element not found');
59
63
  }
64
+ const onExit = () => {
65
+ if ('orderId' in props) {
66
+ props.onExit?.(props.orderId);
67
+ }
68
+ else if ('lineOfCreditApplicationId' in props) {
69
+ props.onExit?.(props.lineOfCreditApplicationId);
70
+ }
71
+ else {
72
+ props.onExit?.();
73
+ }
74
+ };
60
75
  const messageListener = async (event) => {
61
76
  if (event.origin === origin) {
62
77
  switch (event.data?.message) {
63
78
  case 'close-dashboard':
64
- if ('orderId' in props) {
65
- props.onExit?.(props.orderId);
66
- }
67
- else if ('lineOfCreditApplicationId' in props) {
68
- props.onExit?.(props.lineOfCreditApplicationId);
69
- }
70
- else {
71
- props.onExit?.();
72
- }
73
79
  window.removeEventListener('message', messageListener);
74
80
  frame.style.opacity = '0';
75
81
  setTimeout(() => {
82
+ onExit();
76
83
  dashboardTargetElement.removeChild(frame);
77
84
  document.body.style.removeProperty('overflow');
78
85
  }, 200);
79
86
  break;
80
87
  case 'link-opened':
81
- if (props.onLinkOpened && event.data?.url) {
82
- props.onLinkOpened(event.data.url);
88
+ if (props.onLinkOpened && event.data?.url && event.data?.metadata) {
89
+ props.onLinkOpened(event.data.url, event.data.metadata);
83
90
  }
84
91
  break;
85
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/react",
3
- "version": "6.3.1",
3
+ "version": "6.4.0",
4
4
  "description": "Parafin React widget",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",