@parafin/core 1.0.8 → 1.0.10

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/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  const openParafinDashboard = (
2
2
  props: {
3
3
  token: string
4
- product: 'capital' | 'banking'
4
+ product: 'capital' | 'wallet'
5
5
  route?: string
6
6
  externalBusinessId?: string
7
7
  onExit?: () => void
@@ -14,51 +14,41 @@ const openParafinDashboard = (
14
14
  document.removeChild(existingParafinDashboard)
15
15
  }
16
16
 
17
- const iframe = document.createElement('iframe')
18
- iframe.id = 'parafin-dashboard'
19
- iframe.style.position = 'fixed'
20
- iframe.style.top = '0'
21
- iframe.style.left = '0'
22
- iframe.style.width = '100%'
23
- iframe.style.height = '100%'
24
- iframe.style.border = 'none'
25
- iframe.style.zIndex = '2147483647'
26
- iframe.style.backgroundColor = '#fff'
27
- iframe.style.opacity = '0'
28
- iframe.style.transition = 'opacity 0.2s'
17
+ const frame = document.createElement('iframe')
18
+ frame.id = 'parafin-dashboard'
19
+ frame.style.position = 'fixed'
20
+ frame.style.top = '0'
21
+ frame.style.left = '0'
22
+ frame.style.width = '100%'
23
+ frame.style.height = '100%'
24
+ frame.style.border = 'none'
25
+ frame.style.zIndex = '2147483647'
26
+ frame.style.backgroundColor = '#fff'
27
+ frame.style.opacity = '0'
28
+ frame.style.transition = 'opacity 0.2s'
29
29
 
30
- const getBaseUrl = () => {
31
- switch (props.environment) {
32
- case 'local':
33
- return 'http://localhost:9000'
34
- case 'development':
35
- return props.dashboardUrlOverride ?? 'https://app.dev.parafin.com'
36
- default:
37
- return 'https://app.parafin.com'
38
- }
39
- }
40
-
41
- const baseUrl = getBaseUrl()
30
+ const url = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com')
42
31
  const route = props.route ?? '/'
43
- const token = `?token=${props.token}`
44
- const product = `&product=${props.product}`
45
- const externalBusinessId = props.externalBusinessId
46
- ? `&externalBusinessId=${props.externalBusinessId}`
47
- : ''
32
+ const query = {
33
+ token: props.token,
34
+ product: props.product,
35
+ externalBusinessId: props.externalBusinessId ?? '',
36
+ ...Object.fromEntries(url.searchParams),
37
+ }
48
38
 
49
39
  const closeParafinDashboard = ({ data, origin }: MessageEvent) => {
50
- if (origin === baseUrl && data?.message === 'close-dashboard') {
40
+ if (origin === url.origin && data?.message === 'close-dashboard') {
51
41
  props.onExit?.()
52
42
  window.removeEventListener('message', closeParafinDashboard)
53
- iframe.style.opacity = '0'
54
- setTimeout(() => document.body.removeChild(iframe), 200)
43
+ frame.style.opacity = '0'
44
+ setTimeout(() => document.body.removeChild(frame), 200)
55
45
  }
56
46
  }
57
47
 
58
- iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`
48
+ frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`
59
49
  window.addEventListener('message', closeParafinDashboard)
60
- document.body.appendChild(iframe)
61
- setTimeout(() => (iframe.style.opacity = '1'), 1)
50
+ document.body.appendChild(frame)
51
+ setTimeout(() => (frame.style.opacity = '1'), 1)
62
52
  } catch (error) {
63
53
  console.error('Error loading Parafin dashboard', error)
64
54
  }
package/out/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare const openParafinDashboard: (props: {
2
2
  token: string;
3
- product: 'capital' | 'banking';
3
+ product: 'capital' | 'wallet';
4
4
  route?: string;
5
5
  externalBusinessId?: string;
6
6
  onExit?: () => void;
package/out/index.js CHANGED
@@ -4,47 +4,38 @@ const openParafinDashboard = (props) => {
4
4
  if (existingParafinDashboard) {
5
5
  document.removeChild(existingParafinDashboard);
6
6
  }
7
- const iframe = document.createElement('iframe');
8
- iframe.id = 'parafin-dashboard';
9
- iframe.style.position = 'fixed';
10
- iframe.style.top = '0';
11
- iframe.style.left = '0';
12
- iframe.style.width = '100%';
13
- iframe.style.height = '100%';
14
- iframe.style.border = 'none';
15
- iframe.style.zIndex = '2147483647';
16
- iframe.style.backgroundColor = '#fff';
17
- iframe.style.opacity = '0';
18
- iframe.style.transition = 'opacity 0.2s';
19
- const getBaseUrl = () => {
20
- switch (props.environment) {
21
- case 'local':
22
- return 'http://localhost:9000';
23
- case 'development':
24
- return props.dashboardUrlOverride ?? 'https://app.dev.parafin.com';
25
- default:
26
- return 'https://app.parafin.com';
27
- }
28
- };
29
- const baseUrl = getBaseUrl();
7
+ const frame = document.createElement('iframe');
8
+ frame.id = 'parafin-dashboard';
9
+ frame.style.position = 'fixed';
10
+ frame.style.top = '0';
11
+ frame.style.left = '0';
12
+ frame.style.width = '100%';
13
+ frame.style.height = '100%';
14
+ frame.style.border = 'none';
15
+ frame.style.zIndex = '2147483647';
16
+ frame.style.backgroundColor = '#fff';
17
+ frame.style.opacity = '0';
18
+ frame.style.transition = 'opacity 0.2s';
19
+ const url = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com');
30
20
  const route = props.route ?? '/';
31
- const token = `?token=${props.token}`;
32
- const product = `&product=${props.product}`;
33
- const externalBusinessId = props.externalBusinessId
34
- ? `&externalBusinessId=${props.externalBusinessId}`
35
- : '';
21
+ const query = {
22
+ token: props.token,
23
+ product: props.product,
24
+ externalBusinessId: props.externalBusinessId ?? '',
25
+ ...Object.fromEntries(url.searchParams),
26
+ };
36
27
  const closeParafinDashboard = ({ data, origin }) => {
37
- if (origin === baseUrl && data?.message === 'close-dashboard') {
28
+ if (origin === url.origin && data?.message === 'close-dashboard') {
38
29
  props.onExit?.();
39
30
  window.removeEventListener('message', closeParafinDashboard);
40
- iframe.style.opacity = '0';
41
- setTimeout(() => document.body.removeChild(iframe), 200);
31
+ frame.style.opacity = '0';
32
+ setTimeout(() => document.body.removeChild(frame), 200);
42
33
  }
43
34
  };
44
- iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`;
35
+ frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`;
45
36
  window.addEventListener('message', closeParafinDashboard);
46
- document.body.appendChild(iframe);
47
- setTimeout(() => (iframe.style.opacity = '1'), 1);
37
+ document.body.appendChild(frame);
38
+ setTimeout(() => (frame.style.opacity = '1'), 1);
48
39
  }
49
40
  catch (error) {
50
41
  console.error('Error loading Parafin dashboard', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/core",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Parafin embedded core",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",