@melio-eng/web-sdk 1.0.5 → 1.0.7
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.d.ts +10 -2
- package/dist/index.js +46 -9
- package/dist/types.d.ts +24 -0
- package/package.json +1 -1
- package/dist/__tests__/setup.d.ts +0 -0
- package/dist/__tests__/setup.js +0 -33
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitOptions, OnboardingConfig, SinglePayFlowConfig, BatchPayConfig, SettingsConfig, FlowInstance } from './types';
|
|
1
|
+
import { InitOptions, OnboardingConfig, SinglePayFlowConfig, BatchPayConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, SinglePaymentConfig } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK implementation - now partner agnostic
|
|
4
4
|
*/
|
|
@@ -40,9 +40,17 @@ export declare class MelioSDK implements MelioSDK {
|
|
|
40
40
|
* Launch the settings flow
|
|
41
41
|
*/
|
|
42
42
|
openSettings(config: SettingsConfig): FlowInstance;
|
|
43
|
+
/**
|
|
44
|
+
* Launch the payments dashboard flow
|
|
45
|
+
*/
|
|
46
|
+
openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
|
|
47
|
+
/**
|
|
48
|
+
* Launch single payment details
|
|
49
|
+
*/
|
|
50
|
+
openSinglePayment(config: SinglePaymentConfig): FlowInstance;
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
45
53
|
* Export the SDK instance
|
|
46
54
|
*/
|
|
47
55
|
export declare const melioSDK: MelioSDK;
|
|
48
|
-
export * from
|
|
56
|
+
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -81,7 +81,11 @@ class Flow {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
const { type, data } = event.data;
|
|
84
|
-
console.log('📬 Received message from iframe:', {
|
|
84
|
+
console.log('📬 Received message from iframe:', {
|
|
85
|
+
type,
|
|
86
|
+
data,
|
|
87
|
+
origin: event.origin,
|
|
88
|
+
});
|
|
85
89
|
switch (type) {
|
|
86
90
|
case 'FLOW_COMPLETED':
|
|
87
91
|
this.emit('completed', data);
|
|
@@ -103,7 +107,7 @@ class Flow {
|
|
|
103
107
|
emit(event, data) {
|
|
104
108
|
const listeners = this.eventListeners.get(event);
|
|
105
109
|
if (listeners) {
|
|
106
|
-
listeners.forEach(callback => {
|
|
110
|
+
listeners.forEach((callback) => {
|
|
107
111
|
try {
|
|
108
112
|
callback(data);
|
|
109
113
|
}
|
|
@@ -155,7 +159,7 @@ class SinglePayFlow extends Flow {
|
|
|
155
159
|
* Construct the specific flow URL for bill payment
|
|
156
160
|
*/
|
|
157
161
|
constructFlowUrl(baseUrl) {
|
|
158
|
-
return `${baseUrl}/${this.partnerName}/payment/new?billId
|
|
162
|
+
return `${baseUrl}/${this.partnerName}/payment/new?billId=${this.billId}`;
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
@@ -170,7 +174,7 @@ class BatchPayFlow extends Flow {
|
|
|
170
174
|
* Construct the specific flow URL for batch payments
|
|
171
175
|
*/
|
|
172
176
|
constructFlowUrl(baseUrl) {
|
|
173
|
-
const billIds = this.bills.
|
|
177
|
+
const billIds = this.bills.join(',');
|
|
174
178
|
return `${baseUrl}/${this.partnerName}/batch-payments/${billIds}`;
|
|
175
179
|
}
|
|
176
180
|
}
|
|
@@ -178,14 +182,31 @@ class BatchPayFlow extends Flow {
|
|
|
178
182
|
* SettingsFlow subclass with custom URL construction
|
|
179
183
|
*/
|
|
180
184
|
class SettingsFlow extends Flow {
|
|
185
|
+
/**
|
|
186
|
+
* Construct the specific flow URL for settings
|
|
187
|
+
*/
|
|
188
|
+
constructFlowUrl(baseUrl) {
|
|
189
|
+
return `${baseUrl}/${this.partnerName}/settings`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class PaymentsDashboardFlow extends Flow {
|
|
193
|
+
/**
|
|
194
|
+
* Construct the specific flow URL for payments dashboard
|
|
195
|
+
*/
|
|
196
|
+
constructFlowUrl(baseUrl) {
|
|
197
|
+
return `${baseUrl}/${this.partnerName}/pay-dashboard/payments`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
class SinglePaymentFlow extends Flow {
|
|
181
201
|
constructor(containerId, config, partnerName, environment) {
|
|
182
202
|
super(containerId, config, partnerName, environment);
|
|
203
|
+
this.paymentId = config.paymentId;
|
|
183
204
|
}
|
|
184
205
|
/**
|
|
185
|
-
* Construct the specific flow URL for
|
|
206
|
+
* Construct the specific flow URL for single payment
|
|
186
207
|
*/
|
|
187
208
|
constructFlowUrl(baseUrl) {
|
|
188
|
-
return `${baseUrl}/${this.partnerName}/
|
|
209
|
+
return `${baseUrl}/${this.partnerName}/pay-dashboard/payments/${this.paymentId}`;
|
|
189
210
|
}
|
|
190
211
|
}
|
|
191
212
|
/**
|
|
@@ -241,7 +262,7 @@ export class MelioSDK {
|
|
|
241
262
|
createAuthInitUrl(authorizationCode) {
|
|
242
263
|
const params = new URLSearchParams({
|
|
243
264
|
code: authorizationCode,
|
|
244
|
-
theme: this.partnerName
|
|
265
|
+
theme: this.partnerName,
|
|
245
266
|
});
|
|
246
267
|
const baseUrl = getBaseUrl(this.environment);
|
|
247
268
|
let finalUrl = `${baseUrl}/${this.partnerName}/auth?${params.toString()}`;
|
|
@@ -256,7 +277,7 @@ export class MelioSDK {
|
|
|
256
277
|
this.keepAliveInterval = window.setInterval(() => {
|
|
257
278
|
if (this.keepAliveIframe && this.keepAliveIframe.contentWindow) {
|
|
258
279
|
this.keepAliveIframe.contentWindow.postMessage({
|
|
259
|
-
type: 'USER_ACTIVE_PING'
|
|
280
|
+
type: 'USER_ACTIVE_PING',
|
|
260
281
|
}, 'https://app.melio.com');
|
|
261
282
|
}
|
|
262
283
|
}, 30000); // Send ping every 30 seconds
|
|
@@ -293,10 +314,26 @@ export class MelioSDK {
|
|
|
293
314
|
flow.initialize();
|
|
294
315
|
return flow;
|
|
295
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Launch the payments dashboard flow
|
|
319
|
+
*/
|
|
320
|
+
openPaymentsDashboard(config) {
|
|
321
|
+
const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment);
|
|
322
|
+
flow.initialize();
|
|
323
|
+
return flow;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Launch single payment details
|
|
327
|
+
*/
|
|
328
|
+
openSinglePayment(config) {
|
|
329
|
+
const flow = new SinglePaymentFlow(config.containerId, config, this.partnerName, this.environment);
|
|
330
|
+
flow.initialize();
|
|
331
|
+
return flow;
|
|
332
|
+
}
|
|
296
333
|
}
|
|
297
334
|
/**
|
|
298
335
|
* Export the SDK instance
|
|
299
336
|
*/
|
|
300
337
|
export const melioSDK = new MelioSDK();
|
|
301
338
|
// Export types for consumers
|
|
302
|
-
export * from
|
|
339
|
+
export * from "./types.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -48,6 +48,18 @@ export interface BatchPayConfig extends BaseFlowConfig {
|
|
|
48
48
|
*/
|
|
49
49
|
export interface SettingsConfig extends BaseFlowConfig {
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for payments dashboard flow
|
|
53
|
+
*/
|
|
54
|
+
export interface PaymentsDashboardConfig extends BaseFlowConfig {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Configuration for single payment
|
|
58
|
+
*/
|
|
59
|
+
export interface SinglePaymentConfig extends BaseFlowConfig {
|
|
60
|
+
/** The Melio bill ID to pay */
|
|
61
|
+
paymentId: string;
|
|
62
|
+
}
|
|
51
63
|
/**
|
|
52
64
|
* Event payload for navigation events
|
|
53
65
|
*/
|
|
@@ -127,4 +139,16 @@ export interface MelioSDK {
|
|
|
127
139
|
* @returns Flow instance for event handling
|
|
128
140
|
*/
|
|
129
141
|
openSettings(config: SettingsConfig): FlowInstance;
|
|
142
|
+
/**
|
|
143
|
+
* Launch the payments dashboard flow
|
|
144
|
+
* @param config - Configuration for the payments dashboard flow
|
|
145
|
+
* @returns Flow instance for event handling
|
|
146
|
+
*/
|
|
147
|
+
openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
|
|
148
|
+
/**
|
|
149
|
+
* Launch the single payment flow
|
|
150
|
+
* @param config - Configuration for the single payment flow
|
|
151
|
+
* @returns Flow instance for event handling
|
|
152
|
+
*/
|
|
153
|
+
openSinglePayment(config: SinglePaymentConfig): FlowInstance;
|
|
130
154
|
}
|
package/package.json
CHANGED
|
File without changes
|
package/dist/__tests__/setup.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Test setup file for Jest
|
|
3
|
-
// This file is automatically loaded by Jest before running tests
|
|
4
|
-
// Mock fetch globally for tests
|
|
5
|
-
global.fetch = jest.fn();
|
|
6
|
-
// Mock window.postMessage for iframe communication tests
|
|
7
|
-
Object.defineProperty(window, 'postMessage', {
|
|
8
|
-
value: jest.fn(),
|
|
9
|
-
writable: true,
|
|
10
|
-
});
|
|
11
|
-
// Mock addEventListener for message events
|
|
12
|
-
Object.defineProperty(window, 'addEventListener', {
|
|
13
|
-
value: jest.fn(),
|
|
14
|
-
writable: true,
|
|
15
|
-
});
|
|
16
|
-
// Mock document methods
|
|
17
|
-
Object.defineProperty(document, 'getElementById', {
|
|
18
|
-
value: jest.fn(),
|
|
19
|
-
writable: true,
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(document, 'createElement', {
|
|
22
|
-
value: jest.fn(),
|
|
23
|
-
writable: true,
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(document, 'body', {
|
|
26
|
-
value: {
|
|
27
|
-
appendChild: jest.fn(),
|
|
28
|
-
},
|
|
29
|
-
writable: true,
|
|
30
|
-
});
|
|
31
|
-
// Mock setInterval and clearInterval
|
|
32
|
-
global.setInterval = jest.fn();
|
|
33
|
-
global.clearInterval = jest.fn();
|