@parafin/core 1.2.0 → 2.0.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 CHANGED
@@ -1,6 +1,7 @@
1
+ type BaseProps = { token: string } | { partner: string }
2
+
1
3
  type CapitalOrSpendProps = {
2
- product: 'capital' | 'spend'
3
- token?: string
4
+ product: 'capital' | 'spend_card'
4
5
  route?: string
5
6
  externalBusinessId?: string
6
7
  additionalQueryParams?: Record<string, string>
@@ -10,38 +11,14 @@ type CapitalOrSpendProps = {
10
11
 
11
12
  type BNPLProps = {
12
13
  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
14
+ mode?: 'modal' | 'redirect'
15
+ orderId?: string
16
+ lineOfCreditApplicationId?: string
17
+ onExit?: (id?: string) => Promise<void> | void
41
18
  }
42
19
 
43
20
  export const openParafinDashboard = (
44
- props: CapitalOrSpendProps | BNPLProps
21
+ props: BaseProps & (CapitalOrSpendProps | BNPLProps)
45
22
  ) => {
46
23
  try {
47
24
  const { origin, searchParams } = new URL(
@@ -53,12 +30,13 @@ export const openParafinDashboard = (
53
30
  product: props.product,
54
31
  referrer: 'partner',
55
32
  ...('token' in props && { token: props.token }),
33
+ ...('partner' in props && { partner: props.partner }),
56
34
  ...('externalBusinessId' in props && {
57
35
  externalBusinessId: props.externalBusinessId,
58
36
  }),
59
37
  ...('orderId' in props && { orderId: props.orderId }),
60
- ...('orderAmount' in props && {
61
- orderAmount: props.orderAmount.toString(),
38
+ ...('lineOfCreditApplicationId' in props && {
39
+ lineOfCreditApplicationId: props.lineOfCreditApplicationId,
62
40
  }),
63
41
  ...('additionalQueryParams' in props && props.additionalQueryParams),
64
42
  ...Object.fromEntries(searchParams),
@@ -70,6 +48,11 @@ export const openParafinDashboard = (
70
48
  return
71
49
  }
72
50
 
51
+ if ('mode' in props && props.mode === 'redirect') {
52
+ window.open(url)
53
+ return
54
+ }
55
+
73
56
  const existingParafinDashboard =
74
57
  document.getElementById('parafin-dashboard')
75
58
  if (existingParafinDashboard) {
@@ -91,12 +74,12 @@ export const openParafinDashboard = (
91
74
  frame.src = url
92
75
  frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write'
93
76
 
94
- const parse = (message: any) => (message ? JSON.parse(message) : undefined)
95
-
96
77
  const closeParafinDashboard = (e: MessageEvent) => {
97
78
  if (e.origin === origin && e.data?.message === 'close-dashboard') {
98
- if (props.product === 'bnpl' && props.flow === 'checkout') {
99
- props.onExit(parse(e.data.order))
79
+ if ('orderId' in props) {
80
+ props.onExit?.(props.orderId)
81
+ } else if ('lineOfCreditApplicationId' in props) {
82
+ props.onExit?.(props.lineOfCreditApplicationId)
100
83
  } else {
101
84
  props.onExit?.()
102
85
  }
package/out/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
+ type BaseProps = {
2
+ token: string;
3
+ } | {
4
+ partner: string;
5
+ };
1
6
  type CapitalOrSpendProps = {
2
- product: 'capital' | 'spend';
3
- token?: string;
7
+ product: 'capital' | 'spend_card';
4
8
  route?: string;
5
9
  externalBusinessId?: string;
6
10
  additionalQueryParams?: Record<string, string>;
@@ -9,30 +13,10 @@ type CapitalOrSpendProps = {
9
13
  };
10
14
  type BNPLProps = {
11
15
  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;
16
+ mode?: 'modal' | 'redirect';
17
+ orderId?: string;
18
+ lineOfCreditApplicationId?: string;
19
+ onExit?: (id?: string) => Promise<void> | void;
36
20
  };
37
- export declare const openParafinDashboard: (props: CapitalOrSpendProps | BNPLProps) => void;
21
+ export declare const openParafinDashboard: (props: BaseProps & (CapitalOrSpendProps | BNPLProps)) => void;
38
22
  export {};
package/out/index.js CHANGED
@@ -8,12 +8,13 @@ export const openParafinDashboard = (props) => {
8
8
  product: props.product,
9
9
  referrer: 'partner',
10
10
  ...('token' in props && { token: props.token }),
11
+ ...('partner' in props && { partner: props.partner }),
11
12
  ...('externalBusinessId' in props && {
12
13
  externalBusinessId: props.externalBusinessId,
13
14
  }),
14
15
  ...('orderId' in props && { orderId: props.orderId }),
15
- ...('orderAmount' in props && {
16
- orderAmount: props.orderAmount.toString(),
16
+ ...('lineOfCreditApplicationId' in props && {
17
+ lineOfCreditApplicationId: props.lineOfCreditApplicationId,
17
18
  }),
18
19
  ...('additionalQueryParams' in props && props.additionalQueryParams),
19
20
  ...Object.fromEntries(searchParams),
@@ -23,6 +24,10 @@ export const openParafinDashboard = (props) => {
23
24
  window.open(url, '_blank');
24
25
  return;
25
26
  }
27
+ if ('mode' in props && props.mode === 'redirect') {
28
+ window.open(url);
29
+ return;
30
+ }
26
31
  const existingParafinDashboard = document.getElementById('parafin-dashboard');
27
32
  if (existingParafinDashboard) {
28
33
  document.removeChild(existingParafinDashboard);
@@ -41,11 +46,13 @@ export const openParafinDashboard = (props) => {
41
46
  frame.style.transition = 'opacity 0.2s';
42
47
  frame.src = url;
43
48
  frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
44
- const parse = (message) => (message ? JSON.parse(message) : undefined);
45
49
  const closeParafinDashboard = (e) => {
46
50
  if (e.origin === origin && e.data?.message === 'close-dashboard') {
47
- if (props.product === 'bnpl' && props.flow === 'checkout') {
48
- props.onExit(parse(e.data.order));
51
+ if ('orderId' in props) {
52
+ props.onExit?.(props.orderId);
53
+ }
54
+ else if ('lineOfCreditApplicationId' in props) {
55
+ props.onExit?.(props.lineOfCreditApplicationId);
49
56
  }
50
57
  else {
51
58
  props.onExit?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/core",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "Parafin embedded core",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",