@melio-eng/web-sdk 1.0.38 โ†’ 1.0.39-pr.83.c745e85

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 (3) hide show
  1. package/README.md +112 -168
  2. package/dist/types.d.ts +1 -1
  3. package/package.json +6 -4
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
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
+ ## ๐Ÿ“š Documentation
6
+
7
+ - **[Pay Flow Integration Guide](./guides/pay-flow-integration.md)** โ€” the full end-to-end guide for embedding Melio payments (backend `prepare` call, auth code, SDK setup, events, testing checklist). **Start here.**
8
+ - **[SDK Reference](https://melio.github.io/web-sdk/)** โ€” auto-generated API reference for every class, config, and event.
9
+
5
10
  ## ๐Ÿš€ Quick Start
6
11
 
7
12
  ### Installation
@@ -19,42 +24,48 @@ import { MelioSDK } from "@melio-eng/web-sdk";
19
24
  const melioSDK = new MelioSDK();
20
25
 
21
26
  // Initialize the SDK with your authorization code
22
- await melioSDK.init("partner_auth_code", {
23
- partnerName: "your-partner-name",
24
- keepAlive: true,
25
- environment: 'production' // Optional: defaults to 'production'
27
+ const init = melioSDK.init("AUTH_CODE_FROM_YOUR_BACKEND", {
28
+ partnerName: "your-partner-name", // required
29
+ environment: "production", // optional โ€” defaults to 'production'
30
+ keepAlive: true, // optional โ€” keeps the session warm
26
31
  });
27
32
 
28
- // Launch onboarding flow
29
- const onboardingFlow = melioSDK.openOnboarding({
30
- containerId: "melio-onboarding-container"
33
+ init.on("authenticationSucceeded", () => {
34
+ // Open the Pay Flow with the Melio bill IDs returned by /pay-flow/prepare
35
+ const payFlow = melioSDK.openPayFlow({
36
+ containerId: "melio-payflow-container",
37
+ billIds: ["bill_abc123"],
38
+ });
39
+
40
+ payFlow.on("completed", (data) => {
41
+ console.log("Payment completed:", data);
42
+ });
31
43
  });
32
44
 
33
- // Listen for completion
34
- onboardingFlow.on("completed", (data) => {
35
- console.log("Onboarding completed:", data);
45
+ init.on("authenticationFailed", () => {
46
+ // Re-mint the auth code on your backend and retry
36
47
  });
37
48
  ```
38
49
 
50
+ > The full integration (backend `POST /pay-flow/prepare`, minting the auth code, and handling every event) is documented in the **[Pay Flow Integration Guide](./guides/pay-flow-integration.md)**.
51
+
39
52
  ## ๐Ÿ“– API Reference
40
53
 
41
54
  ### Initialization
42
55
 
43
56
  ```typescript
44
- await melioSDK.init(authorizationCode: string, options?: InitOptions): Promise<void>
57
+ melioSDK.init(authenticationCode: string, options: InitOptions): InitFlowInstance
45
58
  ```
46
59
 
47
60
  **Parameters:**
48
- - `authorizationCode` (string, required): OAuth code received from the partner
61
+ - `authenticationCode` (string, required): short-lived, user-scoped code minted on your backend
49
62
  - `options` (InitOptions, required): Configuration options
50
63
  - `partnerName` (string, required): The partner name for the SDK instance
51
64
  - `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:
53
- - `'production'` (default): Production environment
54
- - `'staging01'`: Staging environment
55
- - `'public-qa'`: Public QA environment
56
- - `'certification'`: Certification environment
57
- - `'localhost'`: Local development environment
65
+ - `environment` (Environment): The environment to use for API endpoints (defaults to `'production'`)
66
+ - `branchOverride` (string): Advanced/testing only
67
+
68
+ `init` returns an `InitFlowInstance` you can listen on for `authenticationSucceeded` / `authenticationFailed`.
58
69
 
59
70
  ### Environment Configuration
60
71
 
@@ -62,61 +73,59 @@ The SDK supports multiple environments to facilitate development and testing:
62
73
 
63
74
  ```typescript
64
75
  // Production (default)
65
- await melioSDK.init("auth_code", {
66
- partnerName: "your-partner-name",
67
- environment: 'production'
68
- });
76
+ melioSDK.init("auth_code", { partnerName: "your-partner-name", environment: "production" });
69
77
 
70
78
  // Staging
71
- await melioSDK.init("auth_code", {
72
- partnerName: "your-partner-name",
73
- environment: 'staging01'
74
- });
79
+ melioSDK.init("auth_code", { partnerName: "your-partner-name", environment: "staging01" });
75
80
 
76
81
  // Public QA
77
- await melioSDK.init("auth_code", {
78
- partnerName: "your-partner-name",
79
- environment: 'public-qa'
80
- });
82
+ melioSDK.init("auth_code", { partnerName: "your-partner-name", environment: "public-qa" });
81
83
 
82
84
  // Certification
83
- await melioSDK.init("auth_code", {
84
- partnerName: "your-partner-name",
85
- environment: 'certification'
86
- });
85
+ melioSDK.init("auth_code", { partnerName: "your-partner-name", environment: "certification" });
87
86
 
88
87
  // Localhost (for local development)
89
- await melioSDK.init("auth_code", {
90
- partnerName: "your-partner-name",
91
- environment: 'localhost'
92
- });
88
+ melioSDK.init("auth_code", { partnerName: "your-partner-name", environment: "localhost" });
93
89
  ```
94
90
 
95
- Each environment uses different base URLs:
96
- - **Production**: `https://partnerships.melioservices.com`
97
- - **Staging01**: `https://partnerships.staging01.melioservices.com`
98
- - **Public QA**: `https://partnerships.public-qa.melioservices.com`
99
- - **Certification**: `https://partnerships.certification.melioservices.com`
100
- - **Localhost**: `http://localhost:3005`
91
+ Each environment uses a different base URL:
92
+
93
+ | Environment | SDK `environment` | API base URL |
94
+ |---|---|---|
95
+ | Production | `production` (default) | `https://partnerships.melioservices.com` |
96
+ | Staging | `staging01` | `https://partnerships.staging01.melioservices.com` |
97
+ | Public QA | `public-qa` | `https://partnerships.public-qa.melioservices.com` |
98
+ | Certification | `certification` | `https://partnerships.certification.melioservices.com` |
99
+ | Localhost | `localhost` | `http://localhost:3005` |
101
100
 
102
101
  ### Flow Methods
103
102
 
104
- #### Onboarding Flow
103
+ #### Pay Flow
104
+ Pay one or more bills. Pass the **Melio bill IDs** returned by `POST /pay-flow/prepare`.
105
105
  ```typescript
106
- melioSDK.openOnboarding(config: OnboardingConfig): FlowInstance
106
+ melioSDK.openPayFlow(config: PayFlowConfig): FlowInstance
107
107
  ```
108
108
 
109
- #### Single Pay Flow
109
+ #### Just Pay Flow
110
+ Vendor-based payment (start from a vendor rather than a specific bill).
110
111
  ```typescript
111
- melioSDK.openSinglePayFlow(config: SinglePayFlowConfig): FlowInstance
112
+ melioSDK.openJustPayFlow(config: JustPayFlowConfig): FlowInstance
112
113
  ```
113
114
 
114
- #### Batch Pay Flow
115
+ #### Payments Dashboard Flow
116
+ Let users view and manage their payments inside your product.
115
117
  ```typescript
116
- melioSDK.openBatchPay(config: BatchPayConfig): FlowInstance
118
+ melioSDK.openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance
119
+ ```
120
+
121
+ #### Onboarding Flow
122
+ Collect any missing account / KYC information directly in Melio.
123
+ ```typescript
124
+ melioSDK.openOnboarding(config: OnboardingConfig): FlowInstance
117
125
  ```
118
126
 
119
127
  #### Settings Flow
128
+ Host Melio account settings within your product.
120
129
  ```typescript
121
130
  melioSDK.openSettings(config: SettingsConfig): FlowInstance
122
131
  ```
@@ -126,155 +135,90 @@ melioSDK.openSettings(config: SettingsConfig): FlowInstance
126
135
  Each flow method returns a `FlowInstance` that allows you to register event listeners:
127
136
 
128
137
  ```typescript
129
- const flow = melioSDK.openSinglePayFlow({
130
- billId: "melio_bill_123",
131
- containerId: "melio-payflow-container"
132
- });
133
-
134
- // Listen for completion
135
- flow.on("completed", (data) => {
136
- console.log("Flow completed:", data);
138
+ const flow = melioSDK.openPayFlow({
139
+ containerId: "melio-payflow-container",
140
+ billIds: ["bill_abc123"],
137
141
  });
138
142
 
139
- // Listen for exit
140
- flow.on("exit", () => {
141
- console.log("User exited the flow");
142
- });
143
-
144
- // Listen for navigation
145
- flow.on("navigated", (payload) => {
146
- console.log("Navigated to:", payload.target);
147
- });
143
+ flow.on("loaded", () => console.log("Flow rendered"));
144
+ flow.on("completed", (data) => console.log("Payment completed:", data));
145
+ flow.on("error", (err) => console.warn("Flow error:", err.errorCode));
146
+ flow.on("exit", () => console.log("User exited the flow"));
147
+ flow.on("navigated", (p) => console.log("Navigated to:", p.target));
148
148
  ```
149
149
 
150
150
  **Available Events:**
151
- - `completed`: Called when the user successfully finishes a flow
152
- - `exit`: Called when the user exits the iframe
153
- - `navigated`: Called when navigation occurs inside an iframe
151
+ - `loaded`: The flow iframe has rendered
152
+ - `completed`: The user successfully finished a flow
153
+ - `error`: A flow error occurred (e.g. `billsSyncFailed`)
154
+ - `exit`: The user exited the iframe
155
+ - `navigated`: Navigation occurred inside the iframe
156
+ - `authenticationSucceeded` / `authenticationFailed`: emitted on the `init` instance
154
157
 
155
158
  ## ๐Ÿ’ก Examples
156
159
 
157
- ### Basic Onboarding
160
+ ### Pay Flow
158
161
 
159
162
  ```typescript
160
- import { melioSDK } from "@melio-eng/web-sdk";
161
-
162
- // Initialize with production environment
163
- await melioSDK.init("your_auth_code", {
164
- partnerName: "your-partner-name",
165
- environment: 'production'
163
+ const payFlow = melioSDK.openPayFlow({
164
+ containerId: "melio-payflow-container",
165
+ billIds: ["bill_abc123", "bill_def456"], // Melio bill IDs from /pay-flow/prepare
166
166
  });
167
167
 
168
- // Launch onboarding
169
- const onboarding = melioSDK.openOnboarding({
170
- containerId: "onboarding-container"
168
+ payFlow.on("completed", (data) => {
169
+ console.log("Payment completed:", data);
171
170
  });
172
171
 
173
- onboarding.on("completed", (data) => {
174
- console.log("User completed onboarding:", data);
172
+ payFlow.on("exit", () => {
173
+ console.log("User exited the payment flow");
175
174
  });
176
175
  ```
177
176
 
178
177
  ### Development with Staging Environment
179
178
 
180
179
  ```typescript
181
- // Initialize with staging environment for development
182
- await melioSDK.init("your_auth_code", {
180
+ const init = melioSDK.init("your_auth_code", {
183
181
  partnerName: "your-partner-name",
184
- environment: 'staging01',
185
- keepAlive: true
186
- });
187
-
188
- const payFlow = melioSDK.openSinglePayFlow({
189
- billId: "melio_bill_123",
190
- containerId: "payment-container"
191
- });
192
- ```
193
-
194
- ### Single Payment Flow
195
-
196
- ```typescript
197
- const payFlow = melioSDK.openSinglePayFlow({
198
- billId: "melio_bill_123",
199
- containerId: "payment-container"
200
- });
201
-
202
- payFlow.on("completed", (data) => {
203
- console.log("Payment completed:", data);
182
+ environment: "staging01",
183
+ keepAlive: true,
204
184
  });
205
185
 
206
- payFlow.on("exit", () => {
207
- console.log("User exited payment flow");
186
+ init.on("authenticationSucceeded", () => {
187
+ melioSDK.openPayFlow({
188
+ containerId: "payment-container",
189
+ billIds: ["bill_abc123"],
190
+ });
208
191
  });
209
192
  ```
210
193
 
211
- ### Batch Payment Flow
194
+ ### Onboarding
212
195
 
213
196
  ```typescript
214
- const batchPayFlow = melioSDK.openBatchPay({
215
- bills: [
216
- { billId: "melio_bill_123" },
217
- { billId: "melio_bill_456" }
218
- ],
219
- containerId: "batch-pay-container"
197
+ const onboarding = melioSDK.openOnboarding({
198
+ containerId: "onboarding-container",
220
199
  });
221
200
 
222
- batchPayFlow.on("completed", (data) => {
223
- console.log("Batch payment completed:", data);
201
+ onboarding.on("completed", (data) => {
202
+ console.log("User completed onboarding:", data);
224
203
  });
225
204
  ```
226
205
 
227
- ## ๐Ÿงช Testing Examples
228
-
229
- ### Running the Examples Locally
206
+ ## ๐Ÿงช Running the Examples Locally
230
207
 
231
- The repository includes interactive examples that demonstrate the SDK functionality:
208
+ The repository includes interactive examples that demonstrate the SDK functionality. They render a partner-style accounting UI (navigation, tabs, a bills table with single and batch selection) and wire the SDK into it end-to-end.
232
209
 
233
- #### Basic Usage Example
234
- ```bash
235
- npm run examples:basic
236
- ```
237
- Opens `http://localhost:3000/examples/basic-usage.html`
238
-
239
- #### Xero-Style Bill Pay Example
240
- ```bash
241
- npm run examples:bill-pay
242
- ```
243
- Opens `http://localhost:3000/examples/bill-pay-example.html`
244
-
245
- This example demonstrates:
246
- - **Xero-inspired UI**: Professional accounting interface with navigation, tabs, and tables
247
- - **Automatic SDK Initialization**: SDK initializes immediately on page load
248
- - **Interactive Bill Management**:
249
- - Checkbox selection for batch payments
250
- - Individual "Pay bill" buttons for single payments
251
- - Real-time total calculation
252
- - Status updates after payment completion
253
- - **Full Integration**: Shows how the SDK integrates seamlessly into existing partner interfaces
254
- - **Responsive Design**: Modern UI with proper spacing, typography, and interactions
255
-
256
- #### All Examples Server
257
210
  ```bash
211
+ # Serve all examples in the /examples directory
258
212
  npm run examples
259
213
  ```
260
- Starts a server on port 3000 serving all examples in the `/examples` directory.
261
-
262
- ### Example Features
263
-
264
- The Xero-style example includes:
265
- - **Professional Header**: Company branding, navigation, and user controls
266
- - **Tab Navigation**: Filter bills by status (All, Draft, Awaiting payment, etc.)
267
- - **Search & Filters**: Date ranges, search functionality, and column controls
268
- - **Interactive Table**:
269
- - Checkbox selection with "Select All" functionality
270
- - Status tags (Awaiting payment, Paid)
271
- - Individual and batch payment options
272
- - Real-time status updates
273
- - **SDK Integration**:
274
- - Automatic initialization with demo auth code
275
- - Single payment flows for individual bills
276
- - Batch payment flows for multiple selected bills
277
- - Event logging and status management
214
+
215
+ Then open the example HTML files (e.g. `http://localhost:3009/examples/basic-usage.html` or `http://localhost:3009/examples/bill-pay-example.html`).
216
+
217
+ The bill-pay example demonstrates:
218
+ - **Automatic SDK initialization** on page load
219
+ - **Interactive bill management**: checkbox selection for batch payments, individual "Pay bill" buttons, real-time totals, and status updates after completion
220
+ - **Full integration**: how the SDK slots into an existing partner interface
221
+ - **Event logging** for every flow lifecycle event
278
222
 
279
223
  ## ๐Ÿ”„ Session Keep-Alive
280
224
 
@@ -290,14 +234,14 @@ This mechanism avoids redundant SSO handshakes and ensures seamless flow launche
290
234
 
291
235
  ### Session Initialization
292
236
  1. SDK uses the authorization code to perform a token exchange with Melio
293
- 2. Melio receives the user's email from the partner
237
+ 2. Melio receives the user's identity from the partner
294
238
  3. Melio generates a new access token and initializes the session used for iframe-based flows
295
239
  4. A valid session is stored in local/session storage
296
240
  5. All future flows reuse this session if it is still valid
297
241
 
298
242
  ### iframe Injection
299
243
  1. SDK creates and injects an iframe into the specified `containerId`
300
- 2. It builds an `authUrl` with token, target, entrypoint, and context (e.g., billId)
244
+ 2. It builds an `authUrl` with token, target, entrypoint, and context (e.g., billIds)
301
245
 
302
246
  ### Communication
303
247
  - SDK and Melio iframe communicate using `postMessage`
@@ -314,9 +258,9 @@ npm run build
314
258
  ### Documentation
315
259
 
316
260
  ```bash
317
- npm run docs
318
- npm run docs:serve # Generate docs and start local server
319
- npm run docs:view # Just view existing docs
261
+ npm run docs # generate the SDK reference + guides
262
+ npm run docs:serve # generate docs and start a local server
263
+ npm run docs:view # view already-generated docs
320
264
  ```
321
265
 
322
266
  ### Testing
@@ -336,7 +280,7 @@ npm test
336
280
  - All communication is done over HTTPS
337
281
  - Origin validation for postMessage communication
338
282
  - Session tokens are managed securely
339
- - No sensitive data is stored in localStorage
283
+ - Your API key is used server-to-server only โ€” never in the browser
340
284
 
341
285
  ## ๐Ÿค Support
342
286
 
@@ -344,4 +288,4 @@ For support, please contact the Melio team or create an issue in this repository
344
288
 
345
289
  ## ๐Ÿ“„ License
346
290
 
347
- MIT
291
+ MIT
package/dist/types.d.ts CHANGED
@@ -43,7 +43,7 @@ export interface UserDetails {
43
43
  }
44
44
  /**
45
45
  * Entry point context for the flow, used to construct the externalOrigin parameter.
46
- * When provided, the externalOrigin becomes `${partnerName}-${entryPoint}` (e.g., 'xero-contacts').
46
+ * When provided, the externalOrigin becomes `${partnerName}-${entryPoint}` (e.g., 'your-partner-name-contacts').
47
47
  */
48
48
  export type ExternalEntryPoint = 'contacts';
49
49
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.38",
3
+ "version": "1.0.39-pr.83.c745e85",
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",
@@ -9,7 +9,7 @@
9
9
  "scripts": {
10
10
  "build": "tsc",
11
11
  "dev": "tsc --watch",
12
- "docs": "typedoc --out docs src/index.ts",
12
+ "docs": "typedoc --out docs src/index.ts && node scripts/copy-api-explorer.mjs",
13
13
  "docs:watch": "typedoc --out docs --watch src/index.ts",
14
14
  "docs:serve": "npm run docs && serve docs -p 8000",
15
15
  "docs:view": "serve docs -p 8000",
@@ -45,8 +45,10 @@
45
45
  "jest-environment-jsdom": "^30.0.5",
46
46
  "serve": "^14.2.4",
47
47
  "ts-jest": "^29.1.0",
48
- "typedoc": "^0.25.0",
49
- "typescript": "^5.0.0"
48
+ "typedoc": "^0.26.11",
49
+ "typedoc-plugin-mermaid": "^1.12.0",
50
+ "typescript": "^5.0.0",
51
+ "yaml": "^2.9.0"
50
52
  },
51
53
  "files": [
52
54
  "dist",