@melio-eng/web-sdk 1.0.35-pr.65.956c3ca โ 1.0.35
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 +45 -214
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Melio Web SDK
|
|
2
2
|
|
|
3
|
-
The Melio Web SDK
|
|
3
|
+
The Melio Web SDK allows partners to embed core Melio workflows directly into the partner UI with minimal effort. It provides a high-level API for launching flows such as onboarding and pay flow, while managing authentication, lifecycle, and secure communication under the hood.
|
|
4
4
|
|
|
5
|
-
## Quick Start
|
|
5
|
+
## ๐ Quick Start
|
|
6
6
|
|
|
7
7
|
### Installation
|
|
8
8
|
|
|
@@ -19,21 +19,12 @@ import { MelioSDK } from "@melio-eng/web-sdk";
|
|
|
19
19
|
const melioSDK = new MelioSDK();
|
|
20
20
|
|
|
21
21
|
// Initialize the SDK with your authorization code
|
|
22
|
-
|
|
22
|
+
await melioSDK.init("partner_auth_code", {
|
|
23
23
|
partnerName: "your-partner-name",
|
|
24
24
|
keepAlive: true,
|
|
25
25
|
environment: 'production' // Optional: defaults to 'production'
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
// Listen for authentication events
|
|
29
|
-
initFlow.on("authenticationSucceeded", () => {
|
|
30
|
-
console.log("SDK initialized successfully");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
initFlow.on("authenticationFailed", () => {
|
|
34
|
-
console.error("SDK initialization failed");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
28
|
// Launch onboarding flow
|
|
38
29
|
const onboardingFlow = melioSDK.openOnboarding({
|
|
39
30
|
containerId: "melio-onboarding-container"
|
|
@@ -45,33 +36,25 @@ onboardingFlow.on("completed", (data) => {
|
|
|
45
36
|
});
|
|
46
37
|
```
|
|
47
38
|
|
|
48
|
-
## API Reference
|
|
39
|
+
## ๐ API Reference
|
|
49
40
|
|
|
50
41
|
### Initialization
|
|
51
42
|
|
|
52
43
|
```typescript
|
|
53
|
-
melioSDK.init(authorizationCode: string, options
|
|
44
|
+
await melioSDK.init(authorizationCode: string, options?: InitOptions): Promise<void>
|
|
54
45
|
```
|
|
55
46
|
|
|
56
47
|
**Parameters:**
|
|
57
48
|
- `authorizationCode` (string, required): OAuth code received from the partner
|
|
58
49
|
- `options` (InitOptions, required): Configuration options
|
|
59
50
|
- `partnerName` (string, required): The partner name for the SDK instance
|
|
60
|
-
- `keepAlive` (boolean
|
|
61
|
-
- `environment` (Environment
|
|
51
|
+
- `keepAlive` (boolean): If true, the session will be kept alive in the background via an invisible iframe
|
|
52
|
+
- `environment` (Environment): The environment to use for API endpoints. Available options:
|
|
62
53
|
- `'production'` (default): Production environment
|
|
63
54
|
- `'staging01'`: Staging environment
|
|
64
55
|
- `'public-qa'`: Public QA environment
|
|
65
56
|
- `'certification'`: Certification environment
|
|
66
|
-
- `'eilat'`: Eilat environment
|
|
67
57
|
- `'localhost'`: Local development environment
|
|
68
|
-
- `branchOverride` (string, optional): Override the CDN branch for non-production environments (useful for testing)
|
|
69
|
-
|
|
70
|
-
**Returns:** `InitFlowInstance` - An object with event handling methods:
|
|
71
|
-
- `on('authenticationSucceeded', callback)`: Called when authentication succeeds
|
|
72
|
-
- `on('authenticationFailed', callback)`: Called when authentication fails
|
|
73
|
-
- `off(event, callback)`: Remove an event listener
|
|
74
|
-
- `close()`: Close the flow and clean up resources
|
|
75
58
|
|
|
76
59
|
### Environment Configuration
|
|
77
60
|
|
|
@@ -123,76 +106,34 @@ Each environment uses different base URLs:
|
|
|
123
106
|
melioSDK.openOnboarding(config: OnboardingConfig): FlowInstance
|
|
124
107
|
```
|
|
125
108
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
**Configuration:**
|
|
129
|
-
- `containerId` (string, required): The ID of the DOM element to inject the flow iframe into
|
|
130
|
-
- `authCode` (string, optional): Override authorization code for this flow
|
|
131
|
-
- `userDetails` (object, optional): Pre-fill user information
|
|
132
|
-
- `email` (string): User's email address
|
|
133
|
-
- `firstName` (string): User's first name
|
|
134
|
-
- `lastName` (string): User's last name
|
|
135
|
-
- `dateOfBirth` (string): User's date of birth
|
|
136
|
-
- `organizationDetails` (object, optional): Pre-fill organization information
|
|
137
|
-
- `companyName` (string): Company name
|
|
138
|
-
- `businessType` (string): One of `'partnership'`, `'limitedLiabilityCompany'`, `'corporation'`, `'nonProfit'`
|
|
139
|
-
- `companyLegalName` (string): Legal company name
|
|
140
|
-
- `taxId` (string): Tax ID
|
|
141
|
-
- `legalDateOfBirth` (string): Legal date of birth
|
|
142
|
-
- `website` (string): Company website
|
|
143
|
-
- `description` (string): Company description
|
|
144
|
-
- `contactPhone` (string): Contact phone number
|
|
145
|
-
- `enforceOnboarding` (boolean, optional): If true, forces the onboarding flow even if user is already onboarded
|
|
146
|
-
|
|
147
|
-
#### Pay Flow
|
|
109
|
+
#### Single Pay Flow
|
|
148
110
|
```typescript
|
|
149
|
-
melioSDK.
|
|
111
|
+
melioSDK.openSinglePayFlow(config: SinglePayFlowConfig): FlowInstance
|
|
150
112
|
```
|
|
151
113
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
**Configuration:**
|
|
155
|
-
- `containerId` (string, required): The ID of the DOM element to inject the flow iframe into
|
|
156
|
-
- `authCode` (string, optional): Override authorization code for this flow
|
|
157
|
-
- `billIds` (string[], required): Array of bill IDs to pay. Pass a single ID for single payment, or multiple IDs for batch payment
|
|
158
|
-
|
|
159
|
-
#### Settings Flow
|
|
114
|
+
#### Batch Pay Flow
|
|
160
115
|
```typescript
|
|
161
|
-
melioSDK.
|
|
116
|
+
melioSDK.openBatchPay(config: BatchPayConfig): FlowInstance
|
|
162
117
|
```
|
|
163
118
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
**Configuration:**
|
|
167
|
-
- `containerId` (string, required): The ID of the DOM element to inject the flow iframe into
|
|
168
|
-
- `authCode` (string, optional): Override authorization code for this flow
|
|
169
|
-
|
|
170
|
-
#### Payments Dashboard Flow
|
|
119
|
+
#### Settings Flow
|
|
171
120
|
```typescript
|
|
172
|
-
melioSDK.
|
|
121
|
+
melioSDK.openSettings(config: SettingsConfig): FlowInstance
|
|
173
122
|
```
|
|
174
123
|
|
|
175
|
-
Launches the payments dashboard flow to view payment history and status.
|
|
176
|
-
|
|
177
|
-
**Configuration:**
|
|
178
|
-
- `containerId` (string, required): The ID of the DOM element to inject the flow iframe into
|
|
179
|
-
- `authCode` (string, optional): Override authorization code for this flow
|
|
180
|
-
- `paymentId` (string, optional): Navigate directly to a specific payment
|
|
181
|
-
|
|
182
124
|
### Event Handling
|
|
183
125
|
|
|
184
126
|
Each flow method returns a `FlowInstance` that allows you to register event listeners:
|
|
185
127
|
|
|
186
128
|
```typescript
|
|
187
|
-
const flow = melioSDK.
|
|
188
|
-
|
|
129
|
+
const flow = melioSDK.openSinglePayFlow({
|
|
130
|
+
billId: "melio_bill_123",
|
|
189
131
|
containerId: "melio-payflow-container"
|
|
190
132
|
});
|
|
191
133
|
|
|
192
134
|
// Listen for completion
|
|
193
135
|
flow.on("completed", (data) => {
|
|
194
136
|
console.log("Flow completed:", data);
|
|
195
|
-
// data.flowName: 'onboarding' | 'payment'
|
|
196
137
|
});
|
|
197
138
|
|
|
198
139
|
// Listen for exit
|
|
@@ -203,104 +144,34 @@ flow.on("exit", () => {
|
|
|
203
144
|
// Listen for navigation
|
|
204
145
|
flow.on("navigated", (payload) => {
|
|
205
146
|
console.log("Navigated to:", payload.target);
|
|
206
|
-
// payload.targetAction: 'schedulePayment' | 'scheduleBatchPayments' | 'viewSubscriptionPlans' | etc.
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// Listen for errors
|
|
210
|
-
flow.on("error", (data) => {
|
|
211
|
-
console.error("Flow error:", data.errorCode);
|
|
212
|
-
// data.errorCode: 'billsSyncFailed'
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// Listen for flow loaded
|
|
216
|
-
flow.on("loaded", () => {
|
|
217
|
-
console.log("Flow iframe loaded and ready");
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Listen for onboarding completion (specific to onboarding flow)
|
|
221
|
-
flow.on("onboardingCompleted", () => {
|
|
222
|
-
console.log("Onboarding completed");
|
|
223
147
|
});
|
|
224
148
|
```
|
|
225
149
|
|
|
226
150
|
**Available Events:**
|
|
227
|
-
- `completed`: Called when the user successfully finishes a flow
|
|
151
|
+
- `completed`: Called when the user successfully finishes a flow
|
|
228
152
|
- `exit`: Called when the user exits the iframe
|
|
229
|
-
- `navigated`: Called when navigation occurs inside an iframe
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
- `error`: Called when an error occurs. Returns `ErrorData` with `errorCode` (e.g., 'billsSyncFailed')
|
|
233
|
-
- `loaded`: Called when the flow iframe is loaded and ready for interaction
|
|
234
|
-
- `onboardingCompleted`: Called specifically when onboarding is completed
|
|
235
|
-
|
|
236
|
-
**Navigation Target Actions:**
|
|
237
|
-
- `schedulePayment`: User navigated to schedule a payment
|
|
238
|
-
- `scheduleBatchPayments`: User navigated to schedule batch payments
|
|
239
|
-
- `viewSubscriptionPlans`: User navigated to view subscription plans
|
|
240
|
-
- `viewSettingsCollaborators`: User navigated to settings collaborators
|
|
241
|
-
- `viewPayment`: User navigated to view a payment
|
|
242
|
-
- `viewPaidPayment`: User navigated to view a paid payment
|
|
243
|
-
- `viewBill`: User navigated to view a bill
|
|
244
|
-
- `addNewBill`: User navigated to add a new bill
|
|
245
|
-
- `viewVendors`: User navigated to view vendors
|
|
246
|
-
- `addVendor`: User navigated to add a vendor
|
|
247
|
-
- `viewSettings`: User navigated to view settings
|
|
248
|
-
- `viewArInvoices`: User navigated to view AR invoices
|
|
249
|
-
- `redirect`: User was redirected
|
|
250
|
-
|
|
251
|
-
**Error Codes:**
|
|
252
|
-
- `billsSyncFailed`: Bill sync failed. This can occur when:
|
|
253
|
-
- Trying to sync a non-USD bill
|
|
254
|
-
- Trying to sync an already paid bill or draft bill
|
|
255
|
-
- Trying to sync bills with an unsupported amount (amount 0 or greater than $1M)
|
|
256
|
-
|
|
257
|
-
## Examples
|
|
153
|
+
- `navigated`: Called when navigation occurs inside an iframe
|
|
154
|
+
|
|
155
|
+
## ๐ก Examples
|
|
258
156
|
|
|
259
157
|
### Basic Onboarding
|
|
260
158
|
|
|
261
159
|
```typescript
|
|
262
|
-
import {
|
|
263
|
-
|
|
264
|
-
const melioSDK = new MelioSDK();
|
|
160
|
+
import { melioSDK } from "@melio-eng/web-sdk";
|
|
265
161
|
|
|
266
162
|
// Initialize with production environment
|
|
267
|
-
|
|
163
|
+
await melioSDK.init("your_auth_code", {
|
|
268
164
|
partnerName: "your-partner-name",
|
|
269
165
|
environment: 'production'
|
|
270
166
|
});
|
|
271
167
|
|
|
272
|
-
|
|
273
|
-
// Launch onboarding after successful authentication
|
|
274
|
-
const onboarding = melioSDK.openOnboarding({
|
|
275
|
-
containerId: "onboarding-container"
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
onboarding.on("completed", (data) => {
|
|
279
|
-
console.log("User completed onboarding:", data);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Onboarding with Pre-filled User Details
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
168
|
+
// Launch onboarding
|
|
287
169
|
const onboarding = melioSDK.openOnboarding({
|
|
288
|
-
containerId: "onboarding-container"
|
|
289
|
-
userDetails: {
|
|
290
|
-
email: "user@example.com",
|
|
291
|
-
firstName: "John",
|
|
292
|
-
lastName: "Doe"
|
|
293
|
-
},
|
|
294
|
-
organizationDetails: {
|
|
295
|
-
companyName: "Acme Corp",
|
|
296
|
-
businessType: "corporation",
|
|
297
|
-
website: "https://acme.com"
|
|
298
|
-
},
|
|
299
|
-
enforceOnboarding: true
|
|
170
|
+
containerId: "onboarding-container"
|
|
300
171
|
});
|
|
301
172
|
|
|
302
|
-
onboarding.on("
|
|
303
|
-
console.log("
|
|
173
|
+
onboarding.on("completed", (data) => {
|
|
174
|
+
console.log("User completed onboarding:", data);
|
|
304
175
|
});
|
|
305
176
|
```
|
|
306
177
|
|
|
@@ -308,25 +179,23 @@ onboarding.on("onboardingCompleted", () => {
|
|
|
308
179
|
|
|
309
180
|
```typescript
|
|
310
181
|
// Initialize with staging environment for development
|
|
311
|
-
|
|
182
|
+
await melioSDK.init("your_auth_code", {
|
|
312
183
|
partnerName: "your-partner-name",
|
|
313
184
|
environment: 'staging01',
|
|
314
185
|
keepAlive: true
|
|
315
186
|
});
|
|
316
187
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
containerId: "payment-container"
|
|
321
|
-
});
|
|
188
|
+
const payFlow = melioSDK.openSinglePayFlow({
|
|
189
|
+
billId: "melio_bill_123",
|
|
190
|
+
containerId: "payment-container"
|
|
322
191
|
});
|
|
323
192
|
```
|
|
324
193
|
|
|
325
194
|
### Single Payment Flow
|
|
326
195
|
|
|
327
196
|
```typescript
|
|
328
|
-
const payFlow = melioSDK.
|
|
329
|
-
|
|
197
|
+
const payFlow = melioSDK.openSinglePayFlow({
|
|
198
|
+
billId: "melio_bill_123",
|
|
330
199
|
containerId: "payment-container"
|
|
331
200
|
});
|
|
332
201
|
|
|
@@ -337,17 +206,16 @@ payFlow.on("completed", (data) => {
|
|
|
337
206
|
payFlow.on("exit", () => {
|
|
338
207
|
console.log("User exited payment flow");
|
|
339
208
|
});
|
|
340
|
-
|
|
341
|
-
payFlow.on("error", (data) => {
|
|
342
|
-
console.error("Payment error:", data.errorCode);
|
|
343
|
-
});
|
|
344
209
|
```
|
|
345
210
|
|
|
346
211
|
### Batch Payment Flow
|
|
347
212
|
|
|
348
213
|
```typescript
|
|
349
|
-
const batchPayFlow = melioSDK.
|
|
350
|
-
|
|
214
|
+
const batchPayFlow = melioSDK.openBatchPay({
|
|
215
|
+
bills: [
|
|
216
|
+
{ billId: "melio_bill_123" },
|
|
217
|
+
{ billId: "melio_bill_456" }
|
|
218
|
+
],
|
|
351
219
|
containerId: "batch-pay-container"
|
|
352
220
|
});
|
|
353
221
|
|
|
@@ -356,44 +224,7 @@ batchPayFlow.on("completed", (data) => {
|
|
|
356
224
|
});
|
|
357
225
|
```
|
|
358
226
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
const settingsFlow = melioSDK.openSettings({
|
|
363
|
-
containerId: "settings-container"
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
settingsFlow.on("navigated", (payload) => {
|
|
367
|
-
console.log("User navigated to:", payload.target);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
settingsFlow.on("exit", () => {
|
|
371
|
-
console.log("User exited settings");
|
|
372
|
-
});
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
### Payments Dashboard Flow
|
|
376
|
-
|
|
377
|
-
```typescript
|
|
378
|
-
// View all payments
|
|
379
|
-
const dashboard = melioSDK.openPaymentsDashboard({
|
|
380
|
-
containerId: "dashboard-container"
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// Or navigate directly to a specific payment
|
|
384
|
-
const dashboardWithPayment = melioSDK.openPaymentsDashboard({
|
|
385
|
-
containerId: "dashboard-container",
|
|
386
|
-
paymentId: "payment_123"
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
dashboard.on("navigated", (payload) => {
|
|
390
|
-
if (payload.targetAction === "viewPayment") {
|
|
391
|
-
console.log("User viewing payment:", payload.target);
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
## Testing Examples
|
|
227
|
+
## ๐งช Testing Examples
|
|
397
228
|
|
|
398
229
|
### Running the Examples Locally
|
|
399
230
|
|
|
@@ -445,7 +276,7 @@ The Xero-style example includes:
|
|
|
445
276
|
- Batch payment flows for multiple selected bills
|
|
446
277
|
- Event logging and status management
|
|
447
278
|
|
|
448
|
-
## Session Keep-Alive
|
|
279
|
+
## ๐ Session Keep-Alive
|
|
449
280
|
|
|
450
281
|
When `keepAlive: true` is passed to `init()`, the SDK renders a hidden 1x1 pixel iframe that points to Melio's authentication endpoint. This iframe:
|
|
451
282
|
|
|
@@ -455,7 +286,7 @@ When `keepAlive: true` is passed to `init()`, the SDK renders a hidden 1x1 pixel
|
|
|
455
286
|
|
|
456
287
|
This mechanism avoids redundant SSO handshakes and ensures seamless flow launches without delays.
|
|
457
288
|
|
|
458
|
-
## How It Works
|
|
289
|
+
## ๐๏ธ How It Works
|
|
459
290
|
|
|
460
291
|
### Session Initialization
|
|
461
292
|
1. SDK uses the authorization code to perform a token exchange with Melio
|
|
@@ -472,7 +303,7 @@ This mechanism avoids redundant SSO handshakes and ensures seamless flow launche
|
|
|
472
303
|
- SDK and Melio iframe communicate using `postMessage`
|
|
473
304
|
- Navigation, height, session, and errors are synchronized
|
|
474
305
|
|
|
475
|
-
## Development
|
|
306
|
+
## ๐ ๏ธ Development
|
|
476
307
|
|
|
477
308
|
### Building
|
|
478
309
|
|
|
@@ -494,23 +325,23 @@ npm run docs:view # Just view existing docs
|
|
|
494
325
|
npm test
|
|
495
326
|
```
|
|
496
327
|
|
|
497
|
-
## Requirements
|
|
328
|
+
## ๐ Requirements
|
|
498
329
|
|
|
499
330
|
- Modern browser with ES2020 support
|
|
500
331
|
- HTTPS environment (required for iframe communication)
|
|
501
332
|
- Valid Melio partner authorization code
|
|
502
333
|
|
|
503
|
-
## Security
|
|
334
|
+
## ๐ Security
|
|
504
335
|
|
|
505
336
|
- All communication is done over HTTPS
|
|
506
337
|
- Origin validation for postMessage communication
|
|
507
338
|
- Session tokens are managed securely
|
|
508
339
|
- No sensitive data is stored in localStorage
|
|
509
340
|
|
|
510
|
-
## Support
|
|
341
|
+
## ๐ค Support
|
|
511
342
|
|
|
512
343
|
For support, please contact the Melio team or create an issue in this repository.
|
|
513
344
|
|
|
514
|
-
## License
|
|
345
|
+
## ๐ License
|
|
515
346
|
|
|
516
|
-
MIT
|
|
347
|
+
MIT
|
package/package.json
CHANGED