@parafin/core 1.0.10 → 1.0.12

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
@@ -5,9 +5,27 @@ const openParafinDashboard = (
5
5
  route?: string
6
6
  externalBusinessId?: string
7
7
  onExit?: () => void
8
+ openInNewTab?: boolean
8
9
  } & Record<string, any>
9
10
  ) => {
10
11
  try {
12
+ const { origin, searchParams } = new URL(
13
+ props.dashboardUrlOverride ?? 'https://app.parafin.com'
14
+ )
15
+ const route = props.route ?? '/'
16
+ const query = {
17
+ token: props.token,
18
+ product: props.product,
19
+ externalBusinessId: props.externalBusinessId ?? '',
20
+ referrer: 'partner',
21
+ ...Object.fromEntries(searchParams),
22
+ }
23
+ const url = `${origin}${route}?${new URLSearchParams(query).toString()}`
24
+
25
+ if (props.openInNewTab) {
26
+ return window.open(url, '_blank')
27
+ }
28
+
11
29
  const existingParafinDashboard =
12
30
  document.getElementById('parafin-dashboard')
13
31
  if (existingParafinDashboard) {
@@ -26,18 +44,11 @@ const openParafinDashboard = (
26
44
  frame.style.backgroundColor = '#fff'
27
45
  frame.style.opacity = '0'
28
46
  frame.style.transition = 'opacity 0.2s'
47
+ frame.src = url
48
+ frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write'
29
49
 
30
- const url = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com')
31
- const route = props.route ?? '/'
32
- const query = {
33
- token: props.token,
34
- product: props.product,
35
- externalBusinessId: props.externalBusinessId ?? '',
36
- ...Object.fromEntries(url.searchParams),
37
- }
38
-
39
- const closeParafinDashboard = ({ data, origin }: MessageEvent) => {
40
- if (origin === url.origin && data?.message === 'close-dashboard') {
50
+ const closeParafinDashboard = (e: MessageEvent) => {
51
+ if (e.origin === origin && e.data?.message === 'close-dashboard') {
41
52
  props.onExit?.()
42
53
  window.removeEventListener('message', closeParafinDashboard)
43
54
  frame.style.opacity = '0'
@@ -45,7 +56,6 @@ const openParafinDashboard = (
45
56
  }
46
57
  }
47
58
 
48
- frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`
49
59
  window.addEventListener('message', closeParafinDashboard)
50
60
  document.body.appendChild(frame)
51
61
  setTimeout(() => (frame.style.opacity = '1'), 1)
package/out/index.d.ts CHANGED
@@ -4,5 +4,6 @@ declare const openParafinDashboard: (props: {
4
4
  route?: string;
5
5
  externalBusinessId?: string;
6
6
  onExit?: () => void;
7
- } & Record<string, any>) => void;
7
+ openInNewTab?: boolean;
8
+ } & Record<string, any>) => Window;
8
9
  export { openParafinDashboard };
package/out/index.js CHANGED
@@ -1,5 +1,18 @@
1
1
  const openParafinDashboard = (props) => {
2
2
  try {
3
+ const { origin, searchParams } = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com');
4
+ const route = props.route ?? '/';
5
+ const query = {
6
+ token: props.token,
7
+ product: props.product,
8
+ externalBusinessId: props.externalBusinessId ?? '',
9
+ referrer: 'partner',
10
+ ...Object.fromEntries(searchParams),
11
+ };
12
+ const url = `${origin}${route}?${new URLSearchParams(query).toString()}`;
13
+ if (props.openInNewTab) {
14
+ return window.open(url, '_blank');
15
+ }
3
16
  const existingParafinDashboard = document.getElementById('parafin-dashboard');
4
17
  if (existingParafinDashboard) {
5
18
  document.removeChild(existingParafinDashboard);
@@ -16,23 +29,16 @@ const openParafinDashboard = (props) => {
16
29
  frame.style.backgroundColor = '#fff';
17
30
  frame.style.opacity = '0';
18
31
  frame.style.transition = 'opacity 0.2s';
19
- const url = new URL(props.dashboardUrlOverride ?? 'https://app.parafin.com');
20
- const route = props.route ?? '/';
21
- const query = {
22
- token: props.token,
23
- product: props.product,
24
- externalBusinessId: props.externalBusinessId ?? '',
25
- ...Object.fromEntries(url.searchParams),
26
- };
27
- const closeParafinDashboard = ({ data, origin }) => {
28
- if (origin === url.origin && data?.message === 'close-dashboard') {
32
+ frame.src = url;
33
+ frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
34
+ const closeParafinDashboard = (e) => {
35
+ if (e.origin === origin && e.data?.message === 'close-dashboard') {
29
36
  props.onExit?.();
30
37
  window.removeEventListener('message', closeParafinDashboard);
31
38
  frame.style.opacity = '0';
32
39
  setTimeout(() => document.body.removeChild(frame), 200);
33
40
  }
34
41
  };
35
- frame.src = `${url.origin}${route}?${new URLSearchParams(query).toString()}`;
36
42
  window.addEventListener('message', closeParafinDashboard);
37
43
  document.body.appendChild(frame);
38
44
  setTimeout(() => (frame.style.opacity = '1'), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/core",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Parafin embedded core",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",