@parafin/core 0.0.1 → 1.0.1

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ## @parafin/core
2
+
3
+ Please refer to the [Parafin docs](https://docs.parafin.com/capital/present-offers/elements/reference) for more details.
package/index.ts CHANGED
@@ -1,54 +1,64 @@
1
1
  export const openParafinDashboard = (props: {
2
2
  token: string
3
+ product: 'capital' | 'banking'
3
4
  route?: string
4
- product?: string
5
5
  externalBusinessId?: string
6
6
  onExit?: () => void
7
7
  environment?: string
8
8
  }) => {
9
- const iframe = document.createElement('iframe')
10
- iframe.id = 'parafin-dashboard'
11
- iframe.style.position = 'fixed'
12
- iframe.style.top = '0'
13
- iframe.style.left = '0'
14
- iframe.style.width = '100%'
15
- iframe.style.height = '100%'
16
- iframe.style.border = 'none'
17
- iframe.style.zIndex = '2147483647'
18
- iframe.style.backgroundColor = '#fff'
19
- iframe.style.opacity = '0'
20
- iframe.style.transition = 'opacity 0.2s'
9
+ try {
10
+ const existingParafinDashboard =
11
+ document.getElementById('parafin-dashboard')
12
+ if (existingParafinDashboard) {
13
+ document.removeChild(existingParafinDashboard)
14
+ }
15
+
16
+ const iframe = document.createElement('iframe')
17
+ iframe.id = 'parafin-dashboard'
18
+ iframe.style.position = 'fixed'
19
+ iframe.style.top = '0'
20
+ iframe.style.left = '0'
21
+ iframe.style.width = '100%'
22
+ iframe.style.height = '100%'
23
+ iframe.style.border = 'none'
24
+ iframe.style.zIndex = '2147483647'
25
+ iframe.style.backgroundColor = '#fff'
26
+ iframe.style.opacity = '0'
27
+ iframe.style.transition = 'opacity 0.2s'
21
28
 
22
- const getBaseUrl = () => {
23
- switch (props.environment) {
24
- case 'local':
25
- return 'http://localhost:9000'
26
- case 'development':
27
- return 'https://app.dev.parafin.com'
28
- default:
29
- return 'https://app.parafin.com'
29
+ const getBaseUrl = () => {
30
+ switch (props.environment) {
31
+ case 'local':
32
+ return 'http://localhost:9000'
33
+ case 'development':
34
+ return 'https://app.dev.parafin.com'
35
+ default:
36
+ return 'https://app.parafin.com'
37
+ }
30
38
  }
31
- }
32
39
 
33
- const baseUrl = getBaseUrl()
34
- const route = props.route ?? '/'
35
- const token = `?token=${props.token}`
36
- const product = props.product ? `&product=${props.product}` : ''
37
- const externalBusinessId = props.externalBusinessId
38
- ? `&external_business_id=${props.externalBusinessId}`
39
- : ''
40
+ const baseUrl = getBaseUrl()
41
+ const route = props.route ?? '/'
42
+ const token = `?token=${props.token}`
43
+ const product = `&product=${props.product}`
44
+ const externalBusinessId = props.externalBusinessId
45
+ ? `&external_business_id=${props.externalBusinessId}`
46
+ : ''
40
47
 
41
- const closeParafinDashboard = ({ data, origin }: MessageEvent) => {
42
- if (origin === baseUrl && data?.message === 'close-dashboard') {
43
- props.onExit?.()
44
- window.removeEventListener('message', closeParafinDashboard)
45
- iframe.style.opacity = '0'
46
- setTimeout(() => document.body.removeChild(iframe), 200)
48
+ const closeParafinDashboard = ({ data, origin }: MessageEvent) => {
49
+ if (origin === baseUrl && data?.message === 'close-dashboard') {
50
+ props.onExit?.()
51
+ window.removeEventListener('message', closeParafinDashboard)
52
+ iframe.style.opacity = '0'
53
+ setTimeout(() => document.body.removeChild(iframe), 200)
54
+ }
47
55
  }
48
- }
49
56
 
50
- iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`
51
- window.addEventListener('message', closeParafinDashboard)
52
- document.body.appendChild(iframe)
53
- setTimeout(() => iframe.style.opacity = '1', 1)
54
- }
57
+ iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`
58
+ window.addEventListener('message', closeParafinDashboard)
59
+ document.body.appendChild(iframe)
60
+ setTimeout(() => (iframe.style.opacity = '1'), 1)
61
+ } catch (error) {
62
+ console.error('Error loading Parafin dashboard', error)
63
+ }
64
+ }
package/out/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare const openParafinDashboard: (props: {
2
2
  token: string;
3
+ product: 'capital' | 'banking';
3
4
  route?: string;
4
- product?: string;
5
5
  externalBusinessId?: string;
6
6
  onExit?: () => void;
7
7
  environment?: string;
package/out/index.js CHANGED
@@ -1,43 +1,52 @@
1
1
  export const openParafinDashboard = (props) => {
2
- const iframe = document.createElement('iframe');
3
- iframe.id = 'parafin-dashboard';
4
- iframe.style.position = 'fixed';
5
- iframe.style.top = '0';
6
- iframe.style.left = '0';
7
- iframe.style.width = '100%';
8
- iframe.style.height = '100%';
9
- iframe.style.border = 'none';
10
- iframe.style.zIndex = '2147483647';
11
- iframe.style.backgroundColor = '#fff';
12
- iframe.style.opacity = '0';
13
- iframe.style.transition = 'opacity 0.2s';
14
- const getBaseUrl = () => {
15
- switch (props.environment) {
16
- case 'local':
17
- return 'http://localhost:9000';
18
- case 'development':
19
- return 'https://app.dev.parafin.com';
20
- default:
21
- return 'https://app.parafin.com';
2
+ try {
3
+ const existingParafinDashboard = document.getElementById('parafin-dashboard');
4
+ if (existingParafinDashboard) {
5
+ document.removeChild(existingParafinDashboard);
22
6
  }
23
- };
24
- const baseUrl = getBaseUrl();
25
- const route = props.route ?? '/';
26
- const token = `?token=${props.token}`;
27
- const product = props.product ? `&product=${props.product}` : '';
28
- const externalBusinessId = props.externalBusinessId
29
- ? `&external_business_id=${props.externalBusinessId}`
30
- : '';
31
- const closeParafinDashboard = ({ data, origin }) => {
32
- if (origin === baseUrl && data?.message === 'close-dashboard') {
33
- props.onExit?.();
34
- window.removeEventListener('message', closeParafinDashboard);
35
- iframe.style.opacity = '0';
36
- setTimeout(() => document.body.removeChild(iframe), 200);
37
- }
38
- };
39
- iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`;
40
- window.addEventListener('message', closeParafinDashboard);
41
- document.body.appendChild(iframe);
42
- setTimeout(() => iframe.style.opacity = '1', 1);
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 'https://app.dev.parafin.com';
25
+ default:
26
+ return 'https://app.parafin.com';
27
+ }
28
+ };
29
+ const baseUrl = getBaseUrl();
30
+ const route = props.route ?? '/';
31
+ const token = `?token=${props.token}`;
32
+ const product = `&product=${props.product}`;
33
+ const externalBusinessId = props.externalBusinessId
34
+ ? `&external_business_id=${props.externalBusinessId}`
35
+ : '';
36
+ const closeParafinDashboard = ({ data, origin }) => {
37
+ if (origin === baseUrl && data?.message === 'close-dashboard') {
38
+ props.onExit?.();
39
+ window.removeEventListener('message', closeParafinDashboard);
40
+ iframe.style.opacity = '0';
41
+ setTimeout(() => document.body.removeChild(iframe), 200);
42
+ }
43
+ };
44
+ iframe.src = `${baseUrl}${route}${token}${product}${externalBusinessId}`;
45
+ window.addEventListener('message', closeParafinDashboard);
46
+ document.body.appendChild(iframe);
47
+ setTimeout(() => (iframe.style.opacity = '1'), 1);
48
+ }
49
+ catch (error) {
50
+ console.error('Error loading Parafin dashboard', error);
51
+ }
43
52
  };
package/package.json CHANGED
@@ -1,15 +1,8 @@
1
1
  {
2
2
  "name": "@parafin/core",
3
- "version": "0.0.1",
4
- "type": "module",
3
+ "version": "1.0.1",
5
4
  "description": "Parafin embedded core",
6
5
  "author": "Parafin (https://www.parafin.com)",
7
- "registry": "https://registry.npmjs.org",
8
- "files": [
9
- "index.ts",
10
- "out"
11
- ],
12
- "main": "out/index.js",
13
6
  "module": "out/index.js",
14
7
  "types": "out/index.d.ts",
15
8
  "license": "MIT",
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "declaration": true,
10
+ "outDir": "./out",
11
+ "declarationDir": "./out"
12
+ },
13
+ "include": ["./index.ts"]
14
+ }