@melio-eng/web-sdk 1.0.11 → 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/dist/index.js +42 -1
- package/dist/types.d.ts +25 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -100,6 +100,15 @@ class Flow {
|
|
|
100
100
|
case 'FLOW_NAVIGATED':
|
|
101
101
|
this.emit('navigated', data);
|
|
102
102
|
break;
|
|
103
|
+
case 'AUTHENTICATION_SUCCESS':
|
|
104
|
+
this.emit('authenticationSucceeded');
|
|
105
|
+
break;
|
|
106
|
+
case 'AUTHENTICATION_FAILED':
|
|
107
|
+
this.emit('authenticationFailed');
|
|
108
|
+
break;
|
|
109
|
+
case 'ONBOARDING_COMPLETED':
|
|
110
|
+
this.emit('completed', { flowName: 'onboarding', ...data });
|
|
111
|
+
break;
|
|
103
112
|
case 'HEIGHT_CHANGE':
|
|
104
113
|
if (this.iframe) {
|
|
105
114
|
this.iframe.style.height = `${data.height}px`;
|
|
@@ -151,6 +160,38 @@ class Flow {
|
|
|
151
160
|
this.eventListeners.clear();
|
|
152
161
|
}
|
|
153
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* OnboardingFlow subclass with custom URL construction
|
|
165
|
+
*/
|
|
166
|
+
class OnboardingFlow extends Flow {
|
|
167
|
+
constructor(containerId, config, partnerName, environment, branchOverride) {
|
|
168
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
169
|
+
const { userDetails, organizationDetails } = config;
|
|
170
|
+
this.preFilledParams = { userDetails, organizationDetails };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Construct the specific flow URL for onboarding
|
|
174
|
+
*/
|
|
175
|
+
constructFlowUrl(baseUrl) {
|
|
176
|
+
const params = Object.fromEntries(Object.entries(this.preFilledParams).filter(([_, v]) => v !== undefined));
|
|
177
|
+
let preFilledBase64 = '';
|
|
178
|
+
if (Object.keys(params).length > 0) {
|
|
179
|
+
try {
|
|
180
|
+
const json = JSON.stringify(params);
|
|
181
|
+
preFilledBase64 = btoa(unescape(encodeURIComponent(json)));
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
preFilledBase64 = '';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
let url = `${baseUrl}/${this.partnerName}/auth/demo/new`;
|
|
188
|
+
if (preFilledBase64) {
|
|
189
|
+
url += `?preFilledParams=${encodeURIComponent(preFilledBase64)}`;
|
|
190
|
+
}
|
|
191
|
+
return url;
|
|
192
|
+
return `${baseUrl}/${this.partnerName}/auth/demo/new`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
154
195
|
/**
|
|
155
196
|
* SinglePayFlow subclass with custom URL construction
|
|
156
197
|
*/
|
|
@@ -285,7 +326,7 @@ export class MelioSDK {
|
|
|
285
326
|
* Launch the onboarding flow
|
|
286
327
|
*/
|
|
287
328
|
openOnboarding(config) {
|
|
288
|
-
const flow = new
|
|
329
|
+
const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
289
330
|
flow.initialize();
|
|
290
331
|
return flow;
|
|
291
332
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -24,10 +24,29 @@ export interface BaseFlowConfig {
|
|
|
24
24
|
/** Optional authorization code for the flow */
|
|
25
25
|
authCode?: string;
|
|
26
26
|
}
|
|
27
|
+
export type BusinessType = 'partnership' | 'limitedLiabilityCompany' | 'corporation' | 'nonProfit';
|
|
28
|
+
export interface OrganizationDetails {
|
|
29
|
+
companyName?: string;
|
|
30
|
+
businessType?: BusinessType;
|
|
31
|
+
companyLegalName?: string;
|
|
32
|
+
taxId?: string;
|
|
33
|
+
legalDateOfBirth?: string;
|
|
34
|
+
website?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
contactPhone?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface UserDetails {
|
|
39
|
+
email?: string;
|
|
40
|
+
firstName?: string;
|
|
41
|
+
lastName?: string;
|
|
42
|
+
dateOfBirth?: string;
|
|
43
|
+
}
|
|
27
44
|
/**
|
|
28
45
|
* Configuration for onboarding flow
|
|
29
46
|
*/
|
|
30
47
|
export interface OnboardingConfig extends BaseFlowConfig {
|
|
48
|
+
userDetails?: UserDetails;
|
|
49
|
+
organizationDetails?: OrganizationDetails;
|
|
31
50
|
}
|
|
32
51
|
/**
|
|
33
52
|
* Configuration for single pay flow
|
|
@@ -54,9 +73,9 @@ export interface SettingsConfig extends BaseFlowConfig {
|
|
|
54
73
|
export interface PaymentsDashboardConfig extends BaseFlowConfig {
|
|
55
74
|
}
|
|
56
75
|
/**
|
|
57
|
-
* Event
|
|
76
|
+
* Event data for navigation events
|
|
58
77
|
*/
|
|
59
|
-
export interface
|
|
78
|
+
export interface NavigationData {
|
|
60
79
|
/** The target route or page the user navigated to */
|
|
61
80
|
target: string;
|
|
62
81
|
}
|
|
@@ -65,16 +84,17 @@ export interface NavigationPayload {
|
|
|
65
84
|
*/
|
|
66
85
|
export interface FlowCompletionData {
|
|
67
86
|
/** Any data returned from the completed flow */
|
|
87
|
+
flowName: 'onboarding' | 'payment';
|
|
68
88
|
[key: string]: any;
|
|
69
89
|
}
|
|
70
90
|
/**
|
|
71
91
|
* Event types that can be listened to
|
|
72
92
|
*/
|
|
73
|
-
export type FlowEventType = 'completed' | 'exit' | 'navigated';
|
|
93
|
+
export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed';
|
|
74
94
|
/**
|
|
75
95
|
* Event callback function types
|
|
76
96
|
*/
|
|
77
|
-
export type FlowEventCallback = ((data: FlowCompletionData
|
|
97
|
+
export type FlowEventCallback = ((data: FlowCompletionData | NavigationData) => void) | (() => void);
|
|
78
98
|
/**
|
|
79
99
|
* Flow instance interface for event handling
|
|
80
100
|
*/
|
|
@@ -86,7 +106,7 @@ export interface FlowInstance {
|
|
|
86
106
|
*/
|
|
87
107
|
on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
|
|
88
108
|
on(event: 'exit', callback: () => void): void;
|
|
89
|
-
on(event: 'navigated', callback: (payload:
|
|
109
|
+
on(event: 'navigated', callback: (payload: NavigationData) => void): void;
|
|
90
110
|
/**
|
|
91
111
|
* Remove an event listener for this flow
|
|
92
112
|
* @param event - The event type to remove listener for
|
package/package.json
CHANGED