@parafin/core 1.0.12 → 1.1.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/index.ts +65 -17
- package/out/index.d.ts +34 -5
- package/out/index.js +24 -9
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,29 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
type CapitalOrWalletProps = {
|
|
2
|
+
product: 'capital' | 'wallet'
|
|
3
|
+
token?: string
|
|
4
|
+
route?: string
|
|
5
|
+
externalBusinessId?: string
|
|
6
|
+
additionalQueryParams?: Record<string, string>
|
|
7
|
+
openInNewTab?: boolean
|
|
8
|
+
onExit?: () => Promise<void> | void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type BNPLProps = {
|
|
12
|
+
product: 'bnpl'
|
|
13
|
+
} & (
|
|
14
|
+
| {
|
|
15
|
+
flow: 'checkout'
|
|
16
|
+
orderId: string
|
|
17
|
+
orderAmount: number
|
|
18
|
+
onExit: (order?: ParafinOrder) => Promise<void> | void
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
flow: 'log_in'
|
|
22
|
+
onExit: () => Promise<void> | void
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export type ParafinOrder = {
|
|
27
|
+
id: string
|
|
28
|
+
status: 'opened' | 'accepted' | 'canceled' | 'declined' | 'finalized'
|
|
29
|
+
amount: number
|
|
30
|
+
partner_id: string
|
|
31
|
+
business_id: string | null
|
|
32
|
+
external_id: string | null
|
|
33
|
+
capital_product_id: string | null
|
|
34
|
+
capital_product_offer_collection_id: string | null
|
|
35
|
+
currency_code: 'USD' | 'CAD'
|
|
36
|
+
opened_at: string
|
|
37
|
+
accepted_at: string | null
|
|
38
|
+
canceled_at: string | null
|
|
39
|
+
declined_at: string | null
|
|
40
|
+
finalized_at: string | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const openParafinDashboard = (
|
|
44
|
+
props: CapitalOrWalletProps | BNPLProps
|
|
10
45
|
) => {
|
|
11
46
|
try {
|
|
12
47
|
const { origin, searchParams } = new URL(
|
|
48
|
+
// @ts-ignore
|
|
13
49
|
props.dashboardUrlOverride ?? 'https://app.parafin.com'
|
|
14
50
|
)
|
|
15
|
-
const route = props.route
|
|
51
|
+
const route = 'route' in props ? props.route : '/'
|
|
16
52
|
const query = {
|
|
17
|
-
token: props.token,
|
|
18
53
|
product: props.product,
|
|
19
|
-
externalBusinessId: props.externalBusinessId ?? '',
|
|
20
54
|
referrer: 'partner',
|
|
55
|
+
...('token' in props && { token: props.token }),
|
|
56
|
+
...('externalBusinessId' in props && {
|
|
57
|
+
externalBusinessId: props.externalBusinessId,
|
|
58
|
+
}),
|
|
59
|
+
...('orderId' in props && { orderId: props.orderId }),
|
|
60
|
+
...('orderAmount' in props && {
|
|
61
|
+
orderAmount: props.orderAmount.toString(),
|
|
62
|
+
}),
|
|
63
|
+
...('additionalQueryParams' in props && props.additionalQueryParams),
|
|
21
64
|
...Object.fromEntries(searchParams),
|
|
22
65
|
}
|
|
23
66
|
const url = `${origin}${route}?${new URLSearchParams(query).toString()}`
|
|
24
67
|
|
|
25
|
-
if (props.openInNewTab) {
|
|
26
|
-
|
|
68
|
+
if ('openInNewTab' in props && props.openInNewTab) {
|
|
69
|
+
window.open(url, '_blank')
|
|
70
|
+
return
|
|
27
71
|
}
|
|
28
72
|
|
|
29
73
|
const existingParafinDashboard =
|
|
@@ -47,9 +91,15 @@ const openParafinDashboard = (
|
|
|
47
91
|
frame.src = url
|
|
48
92
|
frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write'
|
|
49
93
|
|
|
94
|
+
const parse = (message: any) => (message ? JSON.parse(message) : undefined)
|
|
95
|
+
|
|
50
96
|
const closeParafinDashboard = (e: MessageEvent) => {
|
|
51
97
|
if (e.origin === origin && e.data?.message === 'close-dashboard') {
|
|
52
|
-
props.
|
|
98
|
+
if (props.product === 'bnpl' && props.flow === 'checkout') {
|
|
99
|
+
props.onExit(parse(e.data.order))
|
|
100
|
+
} else {
|
|
101
|
+
props.onExit?.()
|
|
102
|
+
}
|
|
53
103
|
window.removeEventListener('message', closeParafinDashboard)
|
|
54
104
|
frame.style.opacity = '0'
|
|
55
105
|
setTimeout(() => document.body.removeChild(frame), 200)
|
|
@@ -63,5 +113,3 @@ const openParafinDashboard = (
|
|
|
63
113
|
console.error('Error loading Parafin dashboard', error)
|
|
64
114
|
}
|
|
65
115
|
}
|
|
66
|
-
|
|
67
|
-
export { openParafinDashboard }
|
package/out/index.d.ts
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
token: string;
|
|
1
|
+
type CapitalOrWalletProps = {
|
|
3
2
|
product: 'capital' | 'wallet';
|
|
3
|
+
token?: string;
|
|
4
4
|
route?: string;
|
|
5
5
|
externalBusinessId?: string;
|
|
6
|
-
|
|
6
|
+
additionalQueryParams?: Record<string, string>;
|
|
7
7
|
openInNewTab?: boolean;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
onExit?: () => Promise<void> | void;
|
|
9
|
+
};
|
|
10
|
+
type BNPLProps = {
|
|
11
|
+
product: 'bnpl';
|
|
12
|
+
} & ({
|
|
13
|
+
flow: 'checkout';
|
|
14
|
+
orderId: string;
|
|
15
|
+
orderAmount: number;
|
|
16
|
+
onExit: (order?: ParafinOrder) => Promise<void> | void;
|
|
17
|
+
} | {
|
|
18
|
+
flow: 'log_in';
|
|
19
|
+
onExit: () => Promise<void> | void;
|
|
20
|
+
});
|
|
21
|
+
export type ParafinOrder = {
|
|
22
|
+
id: string;
|
|
23
|
+
status: 'opened' | 'accepted' | 'canceled' | 'declined' | 'finalized';
|
|
24
|
+
amount: number;
|
|
25
|
+
partner_id: string;
|
|
26
|
+
business_id: string | null;
|
|
27
|
+
external_id: string | null;
|
|
28
|
+
capital_product_id: string | null;
|
|
29
|
+
capital_product_offer_collection_id: string | null;
|
|
30
|
+
currency_code: 'USD' | 'CAD';
|
|
31
|
+
opened_at: string;
|
|
32
|
+
accepted_at: string | null;
|
|
33
|
+
canceled_at: string | null;
|
|
34
|
+
declined_at: string | null;
|
|
35
|
+
finalized_at: string | null;
|
|
36
|
+
};
|
|
37
|
+
export declare const openParafinDashboard: (props: CapitalOrWalletProps | BNPLProps) => void;
|
|
38
|
+
export {};
|
package/out/index.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
const openParafinDashboard = (props) => {
|
|
1
|
+
export const openParafinDashboard = (props) => {
|
|
2
2
|
try {
|
|
3
|
-
const { origin, searchParams } = new URL(
|
|
4
|
-
|
|
3
|
+
const { origin, searchParams } = new URL(
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
props.dashboardUrlOverride ?? 'https://app.parafin.com');
|
|
6
|
+
const route = 'route' in props ? props.route : '/';
|
|
5
7
|
const query = {
|
|
6
|
-
token: props.token,
|
|
7
8
|
product: props.product,
|
|
8
|
-
externalBusinessId: props.externalBusinessId ?? '',
|
|
9
9
|
referrer: 'partner',
|
|
10
|
+
...('token' in props && { token: props.token }),
|
|
11
|
+
...('externalBusinessId' in props && {
|
|
12
|
+
externalBusinessId: props.externalBusinessId,
|
|
13
|
+
}),
|
|
14
|
+
...('orderId' in props && { orderId: props.orderId }),
|
|
15
|
+
...('orderAmount' in props && {
|
|
16
|
+
orderAmount: props.orderAmount.toString(),
|
|
17
|
+
}),
|
|
18
|
+
...('additionalQueryParams' in props && props.additionalQueryParams),
|
|
10
19
|
...Object.fromEntries(searchParams),
|
|
11
20
|
};
|
|
12
21
|
const url = `${origin}${route}?${new URLSearchParams(query).toString()}`;
|
|
13
|
-
if (props.openInNewTab) {
|
|
14
|
-
|
|
22
|
+
if ('openInNewTab' in props && props.openInNewTab) {
|
|
23
|
+
window.open(url, '_blank');
|
|
24
|
+
return;
|
|
15
25
|
}
|
|
16
26
|
const existingParafinDashboard = document.getElementById('parafin-dashboard');
|
|
17
27
|
if (existingParafinDashboard) {
|
|
@@ -31,9 +41,15 @@ const openParafinDashboard = (props) => {
|
|
|
31
41
|
frame.style.transition = 'opacity 0.2s';
|
|
32
42
|
frame.src = url;
|
|
33
43
|
frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
|
|
44
|
+
const parse = (message) => (message ? JSON.parse(message) : undefined);
|
|
34
45
|
const closeParafinDashboard = (e) => {
|
|
35
46
|
if (e.origin === origin && e.data?.message === 'close-dashboard') {
|
|
36
|
-
props.
|
|
47
|
+
if (props.product === 'bnpl' && props.flow === 'checkout') {
|
|
48
|
+
props.onExit(parse(e.data.order));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
props.onExit?.();
|
|
52
|
+
}
|
|
37
53
|
window.removeEventListener('message', closeParafinDashboard);
|
|
38
54
|
frame.style.opacity = '0';
|
|
39
55
|
setTimeout(() => document.body.removeChild(frame), 200);
|
|
@@ -47,4 +63,3 @@ const openParafinDashboard = (props) => {
|
|
|
47
63
|
console.error('Error loading Parafin dashboard', error);
|
|
48
64
|
}
|
|
49
65
|
};
|
|
50
|
-
export { openParafinDashboard };
|