@melio-eng/web-sdk 1.0.36-pr.69.b96ac0b → 1.0.36-pr.72.aa9151a
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/flows/Flow.d.ts +1 -12
- package/dist/flows/Flow.js +1 -22
- package/dist/flows/ViewPaymentFlow.d.ts +14 -0
- package/dist/flows/ViewPaymentFlow.js +23 -0
- package/dist/flows/index.d.ts +1 -1
- package/dist/flows/index.js +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.js +6 -16
- package/dist/types.d.ts +11 -35
- package/package.json +2 -3
- package/dist/flows/CheckoutFlow.d.ts +0 -15
- package/dist/flows/CheckoutFlow.js +0 -22
package/dist/flows/Flow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlowInstance, FlowEventType, FlowEventCallback, FlowCompletionData, NavigationData, BaseFlowConfig, Environment, ErrorData
|
|
1
|
+
import { FlowInstance, FlowEventType, FlowEventCallback, FlowCompletionData, NavigationData, BaseFlowConfig, Environment, ErrorData } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Flow class implementation for handling iframe flows and events
|
|
4
4
|
*/
|
|
@@ -39,9 +39,6 @@ export declare class Flow implements FlowInstance {
|
|
|
39
39
|
protected emit(event: 'error', data: ErrorData): void;
|
|
40
40
|
protected emit(event: 'onboardingCompleted'): void;
|
|
41
41
|
protected emit(event: 'onboardingRequired'): void;
|
|
42
|
-
protected emit(event: 'paymentSucceeded', data: FlowCompletionData): void;
|
|
43
|
-
protected emit(event: 'paymentFailed', data: ErrorData): void;
|
|
44
|
-
protected emit(event: 'checkoutSubmit', data: CheckoutSubmitData): void;
|
|
45
42
|
/**
|
|
46
43
|
* Register an event listener
|
|
47
44
|
*/
|
|
@@ -54,9 +51,6 @@ export declare class Flow implements FlowInstance {
|
|
|
54
51
|
on(event: 'loaded', callback: () => void): void;
|
|
55
52
|
on(event: 'onboardingCompleted', callback: () => void): void;
|
|
56
53
|
on(event: 'onboardingRequired', callback: () => void): void;
|
|
57
|
-
on(event: 'paymentSucceeded', callback: (data: FlowCompletionData) => void): void;
|
|
58
|
-
on(event: 'paymentFailed', callback: (data: ErrorData) => void): void;
|
|
59
|
-
on(event: 'checkoutSubmit', callback: (data: CheckoutSubmitData) => void): void;
|
|
60
54
|
/**
|
|
61
55
|
* Remove an event listener
|
|
62
56
|
*/
|
|
@@ -65,9 +59,4 @@ export declare class Flow implements FlowInstance {
|
|
|
65
59
|
* Close the flow and clean up resources
|
|
66
60
|
*/
|
|
67
61
|
close(): void;
|
|
68
|
-
/**
|
|
69
|
-
* Send the paymentIntent JWT token to the checkout iframe to trigger submission.
|
|
70
|
-
* @param token - The paymentIntent JWT token created by the partner's backend via Melio API
|
|
71
|
-
*/
|
|
72
|
-
submit(token: string): void;
|
|
73
62
|
}
|
package/dist/flows/Flow.js
CHANGED
|
@@ -61,10 +61,7 @@ export class Flow {
|
|
|
61
61
|
// Add post message handlers for internal events - setHeight, scroll etc
|
|
62
62
|
// Also need to implement callbacks for flow completed exit etc in the platform-app
|
|
63
63
|
this.messageHandler = (event) => {
|
|
64
|
-
if (!/melio\.com|melioservices\.com
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (this.iframe && event.source !== this.iframe.contentWindow) {
|
|
64
|
+
if (!/melio\.com|melioservices\.com/.test(event.origin)) {
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
70
67
|
const { type, ...data } = event.data;
|
|
@@ -95,15 +92,6 @@ export class Flow {
|
|
|
95
92
|
case 'PAYMENT_SCHEDULED':
|
|
96
93
|
this.emit('completed', { flowName: 'payment', ...data });
|
|
97
94
|
break;
|
|
98
|
-
case 'PAYMENT_SUCCEEDED':
|
|
99
|
-
this.emit('paymentSucceeded', data);
|
|
100
|
-
break;
|
|
101
|
-
case 'PAYMENT_FAILED':
|
|
102
|
-
this.emit('paymentFailed', data);
|
|
103
|
-
break;
|
|
104
|
-
case 'CHECKOUT_SUBMIT_RESULT':
|
|
105
|
-
this.emit('checkoutSubmit', data);
|
|
106
|
-
break;
|
|
107
95
|
case 'MELIO_ERROR':
|
|
108
96
|
if (data.code === 'failed_to_sync_bills') {
|
|
109
97
|
this.emit('error', { errorCode: 'billsSyncFailed' });
|
|
@@ -165,13 +153,4 @@ export class Flow {
|
|
|
165
153
|
}
|
|
166
154
|
this.eventListeners.clear();
|
|
167
155
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Send the paymentIntent JWT token to the checkout iframe to trigger submission.
|
|
170
|
-
* @param token - The paymentIntent JWT token created by the partner's backend via Melio API
|
|
171
|
-
*/
|
|
172
|
-
submit(token) {
|
|
173
|
-
if (this.iframe?.contentWindow) {
|
|
174
|
-
this.iframe.contentWindow.postMessage({ type: 'CHECKOUT_SUBMIT', payload: { token } }, '*');
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
156
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ViewPaymentConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* ViewPaymentFlow subclass with custom URL construction for deep linking into a specific payment
|
|
5
|
+
*/
|
|
6
|
+
export declare class ViewPaymentFlow extends Flow {
|
|
7
|
+
private paymentId;
|
|
8
|
+
private authCode;
|
|
9
|
+
constructor(containerId: string, config: ViewPaymentConfig, partnerName: string, environment: Environment, authCode: string, branchOverride?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Construct the specific flow URL for viewing a payment - goes through /auth
|
|
12
|
+
*/
|
|
13
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Flow } from './Flow.js';
|
|
2
|
+
import { isEmptyString } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* ViewPaymentFlow subclass with custom URL construction for deep linking into a specific payment
|
|
5
|
+
*/
|
|
6
|
+
export class ViewPaymentFlow extends Flow {
|
|
7
|
+
constructor(containerId, config, partnerName, environment, authCode, branchOverride) {
|
|
8
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
9
|
+
this.paymentId = config.paymentId;
|
|
10
|
+
this.authCode = authCode;
|
|
11
|
+
if (isEmptyString(this.authCode)) {
|
|
12
|
+
throw new Error('Authorization code is required for view payment flow. Please call init() before opening view payment flow.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Construct the specific flow URL for viewing a payment - goes through /auth
|
|
17
|
+
*/
|
|
18
|
+
constructFlowUrl(baseUrl) {
|
|
19
|
+
const target = `/pay-dashboard/payments/${this.paymentId}`;
|
|
20
|
+
const encodedTarget = encodeURIComponent(target);
|
|
21
|
+
return `${baseUrl}/${this.partnerName}/auth?token=${this.authCode}&redirectUrl=${encodedTarget}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/flows/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { CheckoutFlow } from './CheckoutFlow.js';
|
|
2
1
|
export { Flow } from './Flow.js';
|
|
3
2
|
export { InitFlow } from './InitFlow.js';
|
|
4
3
|
export { OnboardingFlow } from './OnboardingFlow.js';
|
|
5
4
|
export { PayFlow } from './PayFlow.js';
|
|
6
5
|
export { SettingsFlow } from './SettingsFlow.js';
|
|
7
6
|
export { PaymentsDashboardFlow } from './PaymentsDashboardFlow.js';
|
|
7
|
+
export { ViewPaymentFlow } from './ViewPaymentFlow.js';
|
|
8
8
|
export { getBaseUrl, isEmptyString } from './utils.js';
|
package/dist/flows/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { CheckoutFlow } from './CheckoutFlow.js';
|
|
2
1
|
export { Flow } from './Flow.js';
|
|
3
2
|
export { InitFlow } from './InitFlow.js';
|
|
4
3
|
export { OnboardingFlow } from './OnboardingFlow.js';
|
|
5
4
|
export { PayFlow } from './PayFlow.js';
|
|
6
5
|
export { SettingsFlow } from './SettingsFlow.js';
|
|
7
6
|
export { PaymentsDashboardFlow } from './PaymentsDashboardFlow.js';
|
|
7
|
+
export { ViewPaymentFlow } from './ViewPaymentFlow.js';
|
|
8
8
|
export { getBaseUrl, isEmptyString } from './utils.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig,
|
|
1
|
+
import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, ViewPaymentConfig, PayFlowConfig, InitFlowInstance } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK implementation - now partner agnostic
|
|
4
4
|
*/
|
|
@@ -10,11 +10,6 @@ export declare class MelioSDK implements MelioSDK {
|
|
|
10
10
|
private authCode;
|
|
11
11
|
private initFlow;
|
|
12
12
|
constructor();
|
|
13
|
-
/**
|
|
14
|
-
* Configure the SDK without triggering authentication.
|
|
15
|
-
* Use this for unauthenticated flows like checkout.
|
|
16
|
-
*/
|
|
17
|
-
configure(options: Pick<InitOptions, 'partnerName' | 'environment' | 'branchOverride'>): void;
|
|
18
13
|
/**
|
|
19
14
|
* Initialize the SDK - triggers auth event without creating iframe
|
|
20
15
|
*/
|
|
@@ -36,10 +31,9 @@ export declare class MelioSDK implements MelioSDK {
|
|
|
36
31
|
*/
|
|
37
32
|
openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
|
|
38
33
|
/**
|
|
39
|
-
* Launch the
|
|
40
|
-
* Does not require init().
|
|
34
|
+
* Launch the view payment flow to deep link into a specific payment
|
|
41
35
|
*/
|
|
42
|
-
|
|
36
|
+
openViewPayment(config: ViewPaymentConfig): FlowInstance;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* Export the SDK instance
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InitFlow, OnboardingFlow, PayFlow, SettingsFlow, PaymentsDashboardFlow, ViewPaymentFlow, isEmptyString, } from './flows/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK implementation - now partner agnostic
|
|
4
4
|
*/
|
|
@@ -11,15 +11,6 @@ export class MelioSDK {
|
|
|
11
11
|
this.authCode = '';
|
|
12
12
|
this.initFlow = null;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Configure the SDK without triggering authentication.
|
|
16
|
-
* Use this for unauthenticated flows like checkout.
|
|
17
|
-
*/
|
|
18
|
-
configure(options) {
|
|
19
|
-
this.partnerName = options.partnerName;
|
|
20
|
-
this.environment = options.environment || 'production';
|
|
21
|
-
this.branchOverride = options.branchOverride;
|
|
22
|
-
}
|
|
23
14
|
/**
|
|
24
15
|
* Initialize the SDK - triggers auth event without creating iframe
|
|
25
16
|
*/
|
|
@@ -89,14 +80,13 @@ export class MelioSDK {
|
|
|
89
80
|
return flow;
|
|
90
81
|
}
|
|
91
82
|
/**
|
|
92
|
-
* Launch the
|
|
93
|
-
* Does not require init().
|
|
83
|
+
* Launch the view payment flow to deep link into a specific payment
|
|
94
84
|
*/
|
|
95
|
-
|
|
96
|
-
if (isEmptyString(this.
|
|
97
|
-
throw new Error('
|
|
85
|
+
openViewPayment(config) {
|
|
86
|
+
if (isEmptyString(this.authCode)) {
|
|
87
|
+
throw new Error('SDK not initialized. Please call init() before opening view payment flow.');
|
|
98
88
|
}
|
|
99
|
-
const flow = new
|
|
89
|
+
const flow = new ViewPaymentFlow(config.containerId, config, this.partnerName, this.environment, this.authCode, this.branchOverride);
|
|
100
90
|
flow.initialize();
|
|
101
91
|
return flow;
|
|
102
92
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -55,19 +55,6 @@ export interface OnboardingConfig extends BaseFlowConfig {
|
|
|
55
55
|
export interface PayFlowConfig extends BaseFlowConfig {
|
|
56
56
|
billIds: Array<string>;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Allowed payment methods for the checkout flow
|
|
60
|
-
*/
|
|
61
|
-
export type AllowedPaymentMethod = 'card' | 'ach';
|
|
62
|
-
/**
|
|
63
|
-
* Configuration for checkout flow.
|
|
64
|
-
* Used by partners (e.g. Xero) to embed the payment checkout in their payer experience.
|
|
65
|
-
* Does not require prior authentication.
|
|
66
|
-
*/
|
|
67
|
-
export interface CheckoutFlowConfig extends BaseFlowConfig {
|
|
68
|
-
/** Allowed payment methods. Defaults to ['card', 'ach'] if not specified */
|
|
69
|
-
allowPaymentMethod?: AllowedPaymentMethod[];
|
|
70
|
-
}
|
|
71
58
|
/**
|
|
72
59
|
* Configuration for settings flow
|
|
73
60
|
*/
|
|
@@ -79,6 +66,12 @@ export interface SettingsConfig extends BaseFlowConfig {
|
|
|
79
66
|
export interface PaymentsDashboardConfig extends BaseFlowConfig {
|
|
80
67
|
paymentId?: string;
|
|
81
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Configuration for view payment flow (deep link into a specific payment)
|
|
71
|
+
*/
|
|
72
|
+
export interface ViewPaymentConfig extends BaseFlowConfig {
|
|
73
|
+
paymentId: string;
|
|
74
|
+
}
|
|
82
75
|
/**
|
|
83
76
|
* Configuration for init flow
|
|
84
77
|
*/
|
|
@@ -101,13 +94,6 @@ export interface FlowCompletionData {
|
|
|
101
94
|
flowName: 'onboarding' | 'payment';
|
|
102
95
|
[key: string]: any;
|
|
103
96
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Data returned when checkout submission is complete.
|
|
106
|
-
*/
|
|
107
|
-
export interface CheckoutSubmitData {
|
|
108
|
-
/** Result payload from the checkout submission */
|
|
109
|
-
[key: string]: any;
|
|
110
|
-
}
|
|
111
97
|
/**
|
|
112
98
|
* Flow error data.
|
|
113
99
|
* billsSyncFailed could be returned if the following cases:
|
|
@@ -121,11 +107,11 @@ export interface ErrorData {
|
|
|
121
107
|
/**
|
|
122
108
|
* Event types that can be listened to
|
|
123
109
|
*/
|
|
124
|
-
export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired'
|
|
110
|
+
export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired';
|
|
125
111
|
/**
|
|
126
112
|
* Event callback function types
|
|
127
113
|
*/
|
|
128
|
-
export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData
|
|
114
|
+
export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData) => void) | (() => void);
|
|
129
115
|
/**
|
|
130
116
|
* Flow instance interface for event handling
|
|
131
117
|
*/
|
|
@@ -144,9 +130,6 @@ export interface FlowInstance {
|
|
|
144
130
|
on(event: 'loaded', callback: () => void): void;
|
|
145
131
|
on(event: 'onboardingCompleted', callback: () => void): void;
|
|
146
132
|
on(event: 'onboardingRequired', callback: () => void): void;
|
|
147
|
-
on(event: 'paymentSucceeded', callback: (data: FlowCompletionData) => void): void;
|
|
148
|
-
on(event: 'paymentFailed', callback: (data: ErrorData) => void): void;
|
|
149
|
-
on(event: 'checkoutSubmit', callback: (data: CheckoutSubmitData) => void): void;
|
|
150
133
|
/**
|
|
151
134
|
* Remove an event listener for this flow
|
|
152
135
|
* @param event - The event type to remove listener for
|
|
@@ -157,12 +140,6 @@ export interface FlowInstance {
|
|
|
157
140
|
* Close the flow and clean up resources
|
|
158
141
|
*/
|
|
159
142
|
close(): void;
|
|
160
|
-
/**
|
|
161
|
-
* Trigger the checkout submit from the host.
|
|
162
|
-
* Sends the paymentIntent JWT token to the checkout component.
|
|
163
|
-
* @param token - The paymentIntent JWT token created by the partner's backend via Melio API
|
|
164
|
-
*/
|
|
165
|
-
submit(token: string): void;
|
|
166
143
|
}
|
|
167
144
|
export interface InitFlowInstance {
|
|
168
145
|
/**
|
|
@@ -213,10 +190,9 @@ export interface MelioSDK {
|
|
|
213
190
|
*/
|
|
214
191
|
openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
|
|
215
192
|
/**
|
|
216
|
-
* Launch the
|
|
217
|
-
*
|
|
218
|
-
* @param config - Configuration for the checkout flow
|
|
193
|
+
* Launch the view payment flow to deep link into a specific payment
|
|
194
|
+
* @param config - Configuration for the view payment flow
|
|
219
195
|
* @returns Flow instance for event handling
|
|
220
196
|
*/
|
|
221
|
-
|
|
197
|
+
openViewPayment(config: ViewPaymentConfig): FlowInstance;
|
|
222
198
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melio-eng/web-sdk",
|
|
3
|
-
"version": "1.0.36-pr.
|
|
3
|
+
"version": "1.0.36-pr.72.aa9151a",
|
|
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",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"prepublishOnly": "npm run build && npm run docs",
|
|
21
21
|
"examples": "serve . -p 3009",
|
|
22
22
|
"examples:basic": "serve . -p 3009 && echo 'Open http://localhost:3009/examples/basic-usage.html'",
|
|
23
|
-
"examples:bill-pay": "serve . -p 3009 && echo 'Open http://localhost:3009/examples/bill-pay-example.html'"
|
|
24
|
-
"examples:checkout": "serve . -p 3009 && echo 'Open http://localhost:3009/examples/checkout-example.html'"
|
|
23
|
+
"examples:bill-pay": "serve . -p 3009 && echo 'Open http://localhost:3009/examples/bill-pay-example.html'"
|
|
25
24
|
},
|
|
26
25
|
"keywords": [
|
|
27
26
|
"melio",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CheckoutFlowConfig, Environment } from '../types.js';
|
|
2
|
-
import { Flow } from './Flow.js';
|
|
3
|
-
/**
|
|
4
|
-
* CheckoutFlow - loads the Melio checkout experience without requiring authentication.
|
|
5
|
-
* Used by partners (e.g. Xero) to embed the payment checkout in their payer experience.
|
|
6
|
-
*
|
|
7
|
-
* The host page can call `submit()` on this flow instance to trigger the checkout submission.
|
|
8
|
-
* The component will then emit a 'checkoutSubmit' event with a JWT token containing the
|
|
9
|
-
* tokenized payment details.
|
|
10
|
-
*/
|
|
11
|
-
export declare class CheckoutFlow extends Flow {
|
|
12
|
-
private allowPaymentMethod;
|
|
13
|
-
constructor(containerId: string, config: CheckoutFlowConfig, partnerName: string, environment: Environment, branchOverride?: string);
|
|
14
|
-
protected constructFlowUrl(baseUrl: string): string;
|
|
15
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Flow } from './Flow.js';
|
|
2
|
-
/**
|
|
3
|
-
* CheckoutFlow - loads the Melio checkout experience without requiring authentication.
|
|
4
|
-
* Used by partners (e.g. Xero) to embed the payment checkout in their payer experience.
|
|
5
|
-
*
|
|
6
|
-
* The host page can call `submit()` on this flow instance to trigger the checkout submission.
|
|
7
|
-
* The component will then emit a 'checkoutSubmit' event with a JWT token containing the
|
|
8
|
-
* tokenized payment details.
|
|
9
|
-
*/
|
|
10
|
-
export class CheckoutFlow extends Flow {
|
|
11
|
-
constructor(containerId, config, partnerName, environment, branchOverride) {
|
|
12
|
-
super(containerId, config, partnerName, environment, branchOverride);
|
|
13
|
-
this.allowPaymentMethod = config.allowPaymentMethod || ['card', 'ach'];
|
|
14
|
-
}
|
|
15
|
-
constructFlowUrl(baseUrl) {
|
|
16
|
-
const params = new URLSearchParams({
|
|
17
|
-
externalOrigin: this.partnerName,
|
|
18
|
-
allowPaymentMethod: this.allowPaymentMethod.join(','),
|
|
19
|
-
});
|
|
20
|
-
return `${baseUrl}/${this.partnerName}/ar/checkout?${params.toString()}`;
|
|
21
|
-
}
|
|
22
|
-
}
|