@melio-eng/web-sdk 1.0.33-pr.61.c0daefe → 1.0.33-pr.62.7fcb57a
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 +4 -2
- package/dist/flows/Flow.js +1 -0
- package/dist/flows/InitFlow.d.ts +36 -8
- package/dist/flows/InitFlow.js +82 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/types.d.ts +21 -1
- package/package.json +1 -1
package/dist/flows/Flow.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Flow implements FlowInstance {
|
|
|
12
12
|
protected container: HTMLElement | null;
|
|
13
13
|
private eventListeners;
|
|
14
14
|
protected keepAliveInterval: number | null;
|
|
15
|
-
|
|
15
|
+
private messageHandler;
|
|
16
16
|
constructor(containerId: string, config: BaseFlowConfig, partnerName: string, environment: Environment, branchOverride?: string | undefined);
|
|
17
17
|
/**
|
|
18
18
|
* Initialize the flow by creating and injecting the iframe
|
|
@@ -26,7 +26,7 @@ export declare class Flow implements FlowInstance {
|
|
|
26
26
|
* Create flow URL using partner name and environment
|
|
27
27
|
*/
|
|
28
28
|
protected createFlowUrl(): string;
|
|
29
|
-
|
|
29
|
+
private setupEventListeners;
|
|
30
30
|
/**
|
|
31
31
|
* Emit events to registered listeners
|
|
32
32
|
*/
|
|
@@ -37,6 +37,7 @@ export declare class Flow implements FlowInstance {
|
|
|
37
37
|
protected emit(event: 'authenticationSucceeded'): void;
|
|
38
38
|
protected emit(event: 'authenticationFailed'): void;
|
|
39
39
|
protected emit(event: 'error', data: ErrorData): void;
|
|
40
|
+
protected emit(event: 'onboarding_completed'): void;
|
|
40
41
|
/**
|
|
41
42
|
* Register an event listener
|
|
42
43
|
*/
|
|
@@ -47,6 +48,7 @@ export declare class Flow implements FlowInstance {
|
|
|
47
48
|
on(event: 'authenticationFailed', callback: () => void): void;
|
|
48
49
|
on(event: 'error', callback: (data: ErrorData) => void): void;
|
|
49
50
|
on(event: 'loaded', callback: () => void): void;
|
|
51
|
+
on(event: 'onboarding_completed', callback: () => void): void;
|
|
50
52
|
/**
|
|
51
53
|
* Remove an event listener
|
|
52
54
|
*/
|
package/dist/flows/Flow.js
CHANGED
package/dist/flows/InitFlow.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { InitConfig, Environment } from '../types.js';
|
|
2
|
-
import { Flow } from './Flow.js';
|
|
1
|
+
import { InitConfig, Environment, FlowEventType, FlowEventCallback, InitFlowInstance } from '../types.js';
|
|
3
2
|
/**
|
|
4
|
-
* InitFlow
|
|
3
|
+
* Standalone InitFlow class for handling initialization with callbacks
|
|
5
4
|
*/
|
|
6
|
-
export declare class InitFlow
|
|
5
|
+
export declare class InitFlow implements InitFlowInstance {
|
|
6
|
+
private iframe;
|
|
7
|
+
private container;
|
|
8
|
+
private eventListeners;
|
|
9
|
+
private keepAliveInterval;
|
|
10
|
+
private messageHandler;
|
|
7
11
|
private authorizationCode;
|
|
8
|
-
|
|
12
|
+
private config;
|
|
13
|
+
private partnerName;
|
|
14
|
+
private environment;
|
|
15
|
+
private branchOverride?;
|
|
16
|
+
constructor(config: InitConfig, partnerName: string, environment: Environment, branchOverride?: string);
|
|
9
17
|
/**
|
|
10
18
|
* Initialize the init flow by creating and injecting a hidden iframe
|
|
11
19
|
*/
|
|
@@ -13,10 +21,30 @@ export declare class InitFlow extends Flow {
|
|
|
13
21
|
/**
|
|
14
22
|
* Construct the specific flow URL for initialization
|
|
15
23
|
*/
|
|
16
|
-
|
|
24
|
+
private constructFlowUrl;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
26
|
+
* Create flow URL using partner name and environment
|
|
19
27
|
*/
|
|
20
|
-
|
|
28
|
+
private createFlowUrl;
|
|
29
|
+
/**
|
|
30
|
+
* Setup event listeners to only handle authentication events
|
|
31
|
+
*/
|
|
32
|
+
private setupEventListeners;
|
|
33
|
+
/**
|
|
34
|
+
* Emit events to registered listeners
|
|
35
|
+
*/
|
|
36
|
+
private emit;
|
|
37
|
+
/**
|
|
38
|
+
* Register an event listener
|
|
39
|
+
*/
|
|
40
|
+
on(event: 'authenticationSucceeded' | 'authenticationFailed', callback: FlowEventCallback): void;
|
|
41
|
+
/**
|
|
42
|
+
* Remove an event listener
|
|
43
|
+
*/
|
|
44
|
+
off(event: FlowEventType, callback: FlowEventCallback): void;
|
|
45
|
+
/**
|
|
46
|
+
* Close the flow and clean up resources
|
|
47
|
+
*/
|
|
48
|
+
close(): void;
|
|
21
49
|
setupKeepAlive(): void;
|
|
22
50
|
}
|
package/dist/flows/InitFlow.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isEmptyString } from './utils.js';
|
|
1
|
+
import { isEmptyString, getBaseUrl } from './utils.js';
|
|
3
2
|
/**
|
|
4
|
-
* InitFlow
|
|
3
|
+
* Standalone InitFlow class for handling initialization with callbacks
|
|
5
4
|
*/
|
|
6
|
-
export class InitFlow
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
5
|
+
export class InitFlow {
|
|
6
|
+
constructor(config, partnerName, environment, branchOverride) {
|
|
7
|
+
this.iframe = null;
|
|
8
|
+
this.container = null;
|
|
9
|
+
this.eventListeners = new Map();
|
|
10
|
+
this.keepAliveInterval = null;
|
|
11
|
+
this.messageHandler = null;
|
|
9
12
|
if (isEmptyString(config.authCode)) {
|
|
10
13
|
throw new Error('Authorization code is required for init flow');
|
|
11
14
|
}
|
|
12
15
|
this.authorizationCode = config.authCode;
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.partnerName = partnerName;
|
|
18
|
+
this.environment = environment;
|
|
19
|
+
this.branchOverride = branchOverride;
|
|
20
|
+
this.setupEventListeners();
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
23
|
* Initialize the init flow by creating and injecting a hidden iframe
|
|
@@ -36,7 +44,20 @@ export class InitFlow extends Flow {
|
|
|
36
44
|
return `${baseUrl}/${this.partnerName}/auth?${params.toString()}`;
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
39
|
-
*
|
|
47
|
+
* Create flow URL using partner name and environment
|
|
48
|
+
*/
|
|
49
|
+
createFlowUrl() {
|
|
50
|
+
const baseUrl = getBaseUrl(this.environment);
|
|
51
|
+
let finalUrl = this.constructFlowUrl(baseUrl);
|
|
52
|
+
// Add cdn_branch_override parameter for non-production environments
|
|
53
|
+
if (this.branchOverride && this.environment !== 'production') {
|
|
54
|
+
const separator = finalUrl.includes('?') ? '&' : '?';
|
|
55
|
+
finalUrl += `${separator}cdn_branch_override=${this.branchOverride}`;
|
|
56
|
+
}
|
|
57
|
+
return finalUrl;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Setup event listeners to only handle authentication events
|
|
40
61
|
*/
|
|
41
62
|
setupEventListeners() {
|
|
42
63
|
this.messageHandler = (event) => {
|
|
@@ -56,15 +77,64 @@ export class InitFlow extends Flow {
|
|
|
56
77
|
case 'AUTHENTICATION_ERROR':
|
|
57
78
|
this.emit('authenticationFailed');
|
|
58
79
|
break;
|
|
59
|
-
case 'HEIGHT_CHANGE':
|
|
60
|
-
if (this.iframe) {
|
|
61
|
-
this.iframe.style.height = `${data.height}px`;
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
80
|
}
|
|
65
81
|
};
|
|
66
82
|
window.addEventListener('message', this.messageHandler);
|
|
67
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Emit events to registered listeners
|
|
86
|
+
*/
|
|
87
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
88
|
+
emit(event, data) {
|
|
89
|
+
const listeners = this.eventListeners.get(event);
|
|
90
|
+
if (listeners) {
|
|
91
|
+
listeners.forEach((callback) => {
|
|
92
|
+
try {
|
|
93
|
+
callback(data);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Register an event listener
|
|
103
|
+
*/
|
|
104
|
+
on(event, callback) {
|
|
105
|
+
if (!this.eventListeners.has(event)) {
|
|
106
|
+
this.eventListeners.set(event, new Set());
|
|
107
|
+
}
|
|
108
|
+
this.eventListeners.get(event).add(callback);
|
|
109
|
+
}
|
|
110
|
+
/* eslint-enable no-dupe-class-members */
|
|
111
|
+
/**
|
|
112
|
+
* Remove an event listener
|
|
113
|
+
*/
|
|
114
|
+
off(event, callback) {
|
|
115
|
+
const listeners = this.eventListeners.get(event);
|
|
116
|
+
if (listeners) {
|
|
117
|
+
listeners.delete(callback);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Close the flow and clean up resources
|
|
122
|
+
*/
|
|
123
|
+
close() {
|
|
124
|
+
if (this.keepAliveInterval) {
|
|
125
|
+
clearInterval(this.keepAliveInterval);
|
|
126
|
+
this.keepAliveInterval = null;
|
|
127
|
+
}
|
|
128
|
+
if (this.iframe && this.container) {
|
|
129
|
+
this.container.removeChild(this.iframe);
|
|
130
|
+
this.iframe = null;
|
|
131
|
+
}
|
|
132
|
+
if (this.messageHandler) {
|
|
133
|
+
window.removeEventListener('message', this.messageHandler);
|
|
134
|
+
this.messageHandler = null;
|
|
135
|
+
}
|
|
136
|
+
this.eventListeners.clear();
|
|
137
|
+
}
|
|
68
138
|
setupKeepAlive() {
|
|
69
139
|
this.keepAliveInterval = window.setInterval(() => {
|
|
70
140
|
if (this.iframe && this.iframe.contentWindow) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, PayFlowConfig } from './types.js';
|
|
1
|
+
import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, PayFlowConfig, InitFlowInstance } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK implementation - now partner agnostic
|
|
4
4
|
*/
|
|
@@ -13,7 +13,7 @@ export declare class MelioSDK implements MelioSDK {
|
|
|
13
13
|
/**
|
|
14
14
|
* Initialize the SDK - triggers auth event without creating iframe
|
|
15
15
|
*/
|
|
16
|
-
init(authenticationCode: string, options: InitOptions):
|
|
16
|
+
init(authenticationCode: string, options: InitOptions): InitFlowInstance;
|
|
17
17
|
/**
|
|
18
18
|
* Launch the onboarding flow
|
|
19
19
|
*/
|
package/dist/index.js
CHANGED
|
@@ -27,8 +27,7 @@ export class MelioSDK {
|
|
|
27
27
|
partnerName: this.partnerName,
|
|
28
28
|
environment: this.environment,
|
|
29
29
|
});
|
|
30
|
-
const initFlow = new InitFlow(
|
|
31
|
-
{ authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
|
|
30
|
+
const initFlow = new InitFlow({ authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
|
|
32
31
|
initFlow.initialize();
|
|
33
32
|
console.log('InitFlow initialized successfully');
|
|
34
33
|
if (options.keepAlive)
|
package/dist/types.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export interface ErrorData {
|
|
|
101
101
|
/**
|
|
102
102
|
* Event types that can be listened to
|
|
103
103
|
*/
|
|
104
|
-
export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded';
|
|
104
|
+
export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboarding_completed';
|
|
105
105
|
/**
|
|
106
106
|
* Event callback function types
|
|
107
107
|
*/
|
|
@@ -122,6 +122,26 @@ export interface FlowInstance {
|
|
|
122
122
|
on(event: 'authenticationFailed', callback: () => void): void;
|
|
123
123
|
on(event: 'error', callback: (data: ErrorData) => void): void;
|
|
124
124
|
on(event: 'loaded', callback: () => void): void;
|
|
125
|
+
on(event: 'onboarding_completed', callback: () => void): void;
|
|
126
|
+
/**
|
|
127
|
+
* Remove an event listener for this flow
|
|
128
|
+
* @param event - The event type to remove listener for
|
|
129
|
+
* @param callback - The callback function to remove
|
|
130
|
+
*/
|
|
131
|
+
off(event: FlowEventType, callback: FlowEventCallback): void;
|
|
132
|
+
/**
|
|
133
|
+
* Close the flow and clean up resources
|
|
134
|
+
*/
|
|
135
|
+
close(): void;
|
|
136
|
+
}
|
|
137
|
+
export interface InitFlowInstance {
|
|
138
|
+
/**
|
|
139
|
+
* Register an event listener for this flow
|
|
140
|
+
* @param event - The event type to listen for
|
|
141
|
+
* @param callback - The callback function to execute when the event occurs
|
|
142
|
+
*/
|
|
143
|
+
on(event: 'authenticationSucceeded', callback: () => void): void;
|
|
144
|
+
on(event: 'authenticationFailed', callback: () => void): void;
|
|
125
145
|
/**
|
|
126
146
|
* Remove an event listener for this flow
|
|
127
147
|
* @param event - The event type to remove listener for
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melio-eng/web-sdk",
|
|
3
|
-
"version": "1.0.33-pr.
|
|
3
|
+
"version": "1.0.33-pr.62.7fcb57a",
|
|
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",
|