@melio-eng/web-sdk 1.0.35-pr.64.8d96d38 โ†’ 1.0.35-pr.65.956c3ca

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.
Files changed (2) hide show
  1. package/README.md +214 -45
  2. 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 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.
3
+ The Melio Web SDK (`@melio-eng/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, payments, settings, and payments dashboard, 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,12 +19,21 @@ 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
- await melioSDK.init("partner_auth_code", {
22
+ const initFlow = 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
+
28
37
  // Launch onboarding flow
29
38
  const onboardingFlow = melioSDK.openOnboarding({
30
39
  containerId: "melio-onboarding-container"
@@ -36,25 +45,33 @@ onboardingFlow.on("completed", (data) => {
36
45
  });
37
46
  ```
38
47
 
39
- ## ๐Ÿ“– API Reference
48
+ ## API Reference
40
49
 
41
50
  ### Initialization
42
51
 
43
52
  ```typescript
44
- await melioSDK.init(authorizationCode: string, options?: InitOptions): Promise<void>
53
+ melioSDK.init(authorizationCode: string, options: InitOptions): InitFlowInstance
45
54
  ```
46
55
 
47
56
  **Parameters:**
48
57
  - `authorizationCode` (string, required): OAuth code received from the partner
49
58
  - `options` (InitOptions, required): Configuration options
50
59
  - `partnerName` (string, required): The partner name for the SDK instance
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:
60
+ - `keepAlive` (boolean, optional): If true, the session will be kept alive in the background via an invisible iframe
61
+ - `environment` (Environment, optional): The environment to use for API endpoints. Defaults to `'production'`. Available options:
53
62
  - `'production'` (default): Production environment
54
63
  - `'staging01'`: Staging environment
55
64
  - `'public-qa'`: Public QA environment
56
65
  - `'certification'`: Certification environment
66
+ - `'eilat'`: Eilat environment
57
67
  - `'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
58
75
 
59
76
  ### Environment Configuration
60
77
 
@@ -106,34 +123,76 @@ Each environment uses different base URLs:
106
123
  melioSDK.openOnboarding(config: OnboardingConfig): FlowInstance
107
124
  ```
108
125
 
109
- #### Single Pay Flow
126
+ Launches the user onboarding flow for new Melio users.
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
110
148
  ```typescript
111
- melioSDK.openSinglePayFlow(config: SinglePayFlowConfig): FlowInstance
149
+ melioSDK.openPayFlow(config: PayFlowConfig): FlowInstance
112
150
  ```
113
151
 
114
- #### Batch Pay Flow
115
- ```typescript
116
- melioSDK.openBatchPay(config: BatchPayConfig): FlowInstance
117
- ```
152
+ Launches the payment flow for one or more bills. This method handles both single and batch payments.
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
118
158
 
119
159
  #### Settings Flow
120
160
  ```typescript
121
161
  melioSDK.openSettings(config: SettingsConfig): FlowInstance
122
162
  ```
123
163
 
164
+ Launches the user settings management flow.
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
171
+ ```typescript
172
+ melioSDK.openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance
173
+ ```
174
+
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
+
124
182
  ### Event Handling
125
183
 
126
184
  Each flow method returns a `FlowInstance` that allows you to register event listeners:
127
185
 
128
186
  ```typescript
129
- const flow = melioSDK.openSinglePayFlow({
130
- billId: "melio_bill_123",
187
+ const flow = melioSDK.openPayFlow({
188
+ billIds: ["melio_bill_123"],
131
189
  containerId: "melio-payflow-container"
132
190
  });
133
191
 
134
192
  // Listen for completion
135
193
  flow.on("completed", (data) => {
136
194
  console.log("Flow completed:", data);
195
+ // data.flowName: 'onboarding' | 'payment'
137
196
  });
138
197
 
139
198
  // Listen for exit
@@ -144,34 +203,104 @@ flow.on("exit", () => {
144
203
  // Listen for navigation
145
204
  flow.on("navigated", (payload) => {
146
205
  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");
147
223
  });
148
224
  ```
149
225
 
150
226
  **Available Events:**
151
- - `completed`: Called when the user successfully finishes a flow
227
+ - `completed`: Called when the user successfully finishes a flow. Returns `FlowCompletionData` with `flowName` ('onboarding' | 'payment')
152
228
  - `exit`: Called when the user exits the iframe
153
- - `navigated`: Called when navigation occurs inside an iframe
154
-
155
- ## ๐Ÿ’ก Examples
229
+ - `navigated`: Called when navigation occurs inside an iframe. Returns `NavigationData` with `target` and `targetAction`
230
+ - `authenticationSucceeded`: Called when authentication succeeds
231
+ - `authenticationFailed`: Called when authentication fails
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
156
258
 
157
259
  ### Basic Onboarding
158
260
 
159
261
  ```typescript
160
- import { melioSDK } from "@melio-eng/web-sdk";
262
+ import { MelioSDK } from "@melio-eng/web-sdk";
263
+
264
+ const melioSDK = new MelioSDK();
161
265
 
162
266
  // Initialize with production environment
163
- await melioSDK.init("your_auth_code", {
267
+ const initFlow = melioSDK.init("your_auth_code", {
164
268
  partnerName: "your-partner-name",
165
269
  environment: 'production'
166
270
  });
167
271
 
168
- // Launch onboarding
272
+ initFlow.on("authenticationSucceeded", () => {
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
169
287
  const onboarding = melioSDK.openOnboarding({
170
- containerId: "onboarding-container"
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
171
300
  });
172
301
 
173
- onboarding.on("completed", (data) => {
174
- console.log("User completed onboarding:", data);
302
+ onboarding.on("onboardingCompleted", () => {
303
+ console.log("Onboarding completed");
175
304
  });
176
305
  ```
177
306
 
@@ -179,23 +308,25 @@ onboarding.on("completed", (data) => {
179
308
 
180
309
  ```typescript
181
310
  // Initialize with staging environment for development
182
- await melioSDK.init("your_auth_code", {
311
+ const initFlow = melioSDK.init("your_auth_code", {
183
312
  partnerName: "your-partner-name",
184
313
  environment: 'staging01',
185
314
  keepAlive: true
186
315
  });
187
316
 
188
- const payFlow = melioSDK.openSinglePayFlow({
189
- billId: "melio_bill_123",
190
- containerId: "payment-container"
317
+ initFlow.on("authenticationSucceeded", () => {
318
+ const payFlow = melioSDK.openPayFlow({
319
+ billIds: ["melio_bill_123"],
320
+ containerId: "payment-container"
321
+ });
191
322
  });
192
323
  ```
193
324
 
194
325
  ### Single Payment Flow
195
326
 
196
327
  ```typescript
197
- const payFlow = melioSDK.openSinglePayFlow({
198
- billId: "melio_bill_123",
328
+ const payFlow = melioSDK.openPayFlow({
329
+ billIds: ["melio_bill_123"],
199
330
  containerId: "payment-container"
200
331
  });
201
332
 
@@ -206,16 +337,17 @@ payFlow.on("completed", (data) => {
206
337
  payFlow.on("exit", () => {
207
338
  console.log("User exited payment flow");
208
339
  });
340
+
341
+ payFlow.on("error", (data) => {
342
+ console.error("Payment error:", data.errorCode);
343
+ });
209
344
  ```
210
345
 
211
346
  ### Batch Payment Flow
212
347
 
213
348
  ```typescript
214
- const batchPayFlow = melioSDK.openBatchPay({
215
- bills: [
216
- { billId: "melio_bill_123" },
217
- { billId: "melio_bill_456" }
218
- ],
349
+ const batchPayFlow = melioSDK.openPayFlow({
350
+ billIds: ["melio_bill_123", "melio_bill_456", "melio_bill_789"],
219
351
  containerId: "batch-pay-container"
220
352
  });
221
353
 
@@ -224,7 +356,44 @@ batchPayFlow.on("completed", (data) => {
224
356
  });
225
357
  ```
226
358
 
227
- ## ๐Ÿงช Testing Examples
359
+ ### Settings Flow
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
228
397
 
229
398
  ### Running the Examples Locally
230
399
 
@@ -276,7 +445,7 @@ The Xero-style example includes:
276
445
  - Batch payment flows for multiple selected bills
277
446
  - Event logging and status management
278
447
 
279
- ## ๐Ÿ”„ Session Keep-Alive
448
+ ## Session Keep-Alive
280
449
 
281
450
  When `keepAlive: true` is passed to `init()`, the SDK renders a hidden 1x1 pixel iframe that points to Melio's authentication endpoint. This iframe:
282
451
 
@@ -286,7 +455,7 @@ When `keepAlive: true` is passed to `init()`, the SDK renders a hidden 1x1 pixel
286
455
 
287
456
  This mechanism avoids redundant SSO handshakes and ensures seamless flow launches without delays.
288
457
 
289
- ## ๐Ÿ—๏ธ How It Works
458
+ ## How It Works
290
459
 
291
460
  ### Session Initialization
292
461
  1. SDK uses the authorization code to perform a token exchange with Melio
@@ -303,7 +472,7 @@ This mechanism avoids redundant SSO handshakes and ensures seamless flow launche
303
472
  - SDK and Melio iframe communicate using `postMessage`
304
473
  - Navigation, height, session, and errors are synchronized
305
474
 
306
- ## ๐Ÿ› ๏ธ Development
475
+ ## Development
307
476
 
308
477
  ### Building
309
478
 
@@ -325,23 +494,23 @@ npm run docs:view # Just view existing docs
325
494
  npm test
326
495
  ```
327
496
 
328
- ## ๐Ÿ“‹ Requirements
497
+ ## Requirements
329
498
 
330
499
  - Modern browser with ES2020 support
331
500
  - HTTPS environment (required for iframe communication)
332
501
  - Valid Melio partner authorization code
333
502
 
334
- ## ๐Ÿ”’ Security
503
+ ## Security
335
504
 
336
505
  - All communication is done over HTTPS
337
506
  - Origin validation for postMessage communication
338
507
  - Session tokens are managed securely
339
508
  - No sensitive data is stored in localStorage
340
509
 
341
- ## ๐Ÿค Support
510
+ ## Support
342
511
 
343
512
  For support, please contact the Melio team or create an issue in this repository.
344
513
 
345
- ## ๐Ÿ“„ License
514
+ ## License
346
515
 
347
- MIT
516
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.35-pr.64.8d96d38",
3
+ "version": "1.0.35-pr.65.956c3ca",
4
4
  "description": "Melio Web SDK - Embed core Melio workflows directly into partner UI with minimal effort",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",