@parafin/core 0.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/index.ts +54 -0
- package/out/index.d.ts +8 -0
- package/out/index.js +43 -0
- package/package.json +22 -0
package/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const openParafinDashboard = (props: {
|
|
2
|
+
token: string
|
|
3
|
+
route?: string
|
|
4
|
+
product?: string
|
|
5
|
+
externalBusinessId?: string
|
|
6
|
+
onExit?: () => void
|
|
7
|
+
environment?: string
|
|
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'
|
|
21
|
+
|
|
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'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
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
|
+
|
|
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)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
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
|
+
}
|
package/out/index.d.ts
ADDED
package/out/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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';
|
|
22
|
+
}
|
|
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);
|
|
43
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parafin/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Parafin embedded core",
|
|
6
|
+
"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
|
+
"module": "out/index.js",
|
|
14
|
+
"types": "out/index.d.ts",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^4.9.5"
|
|
21
|
+
}
|
|
22
|
+
}
|