@melio-eng/web-sdk 1.0.29 → 1.0.30
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 +57 -0
- package/dist/flows/Flow.js +149 -0
- package/dist/flows/InitFlow.d.ts +18 -0
- package/dist/flows/InitFlow.js +37 -0
- package/dist/flows/OnboardingFlow.d.ts +15 -0
- package/dist/flows/OnboardingFlow.js +44 -0
- package/dist/flows/PayFlow.d.ts +14 -0
- package/dist/flows/PayFlow.js +24 -0
- package/dist/flows/PaymentsDashboardFlow.d.ts +14 -0
- package/dist/flows/PaymentsDashboardFlow.js +23 -0
- package/dist/flows/SettingsFlow.d.ts +13 -0
- package/dist/flows/SettingsFlow.js +22 -0
- package/dist/flows/index.d.ts +7 -0
- package/dist/flows/index.js +7 -0
- package/dist/flows/utils.d.ts +6 -0
- package/dist/flows/utils.js +24 -0
- package/dist/index.js +15 -6
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FlowInstance, FlowEventType, FlowEventCallback, FlowCompletionData, NavigationData, BaseFlowConfig, Environment, ErrorData } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flow class implementation for handling iframe flows and events
|
|
4
|
+
*/
|
|
5
|
+
export declare class Flow implements FlowInstance {
|
|
6
|
+
private containerId;
|
|
7
|
+
protected config: BaseFlowConfig;
|
|
8
|
+
protected partnerName: string;
|
|
9
|
+
protected environment: Environment;
|
|
10
|
+
protected branchOverride?: string | undefined;
|
|
11
|
+
protected iframe: HTMLIFrameElement | null;
|
|
12
|
+
private container;
|
|
13
|
+
private eventListeners;
|
|
14
|
+
protected keepAliveInterval: number | null;
|
|
15
|
+
constructor(containerId: string, config: BaseFlowConfig, partnerName: string, environment: Environment, branchOverride?: string | undefined);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the flow by creating and injecting the iframe
|
|
18
|
+
*/
|
|
19
|
+
initialize(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Construct the specific flow URL - can be overridden by subclasses
|
|
22
|
+
*/
|
|
23
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Create flow URL using partner name and environment
|
|
26
|
+
*/
|
|
27
|
+
protected createFlowUrl(): string;
|
|
28
|
+
private setupEventListeners;
|
|
29
|
+
/**
|
|
30
|
+
* Emit events to registered listeners
|
|
31
|
+
*/
|
|
32
|
+
protected emit(event: 'completed', data: FlowCompletionData): void;
|
|
33
|
+
protected emit(event: 'loaded'): void;
|
|
34
|
+
protected emit(event: 'exit'): void;
|
|
35
|
+
protected emit(event: 'navigated', data: NavigationData): void;
|
|
36
|
+
protected emit(event: 'authenticationSucceeded'): void;
|
|
37
|
+
protected emit(event: 'authenticationFailed'): void;
|
|
38
|
+
protected emit(event: 'error', data: ErrorData): void;
|
|
39
|
+
/**
|
|
40
|
+
* Register an event listener
|
|
41
|
+
*/
|
|
42
|
+
on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
|
|
43
|
+
on(event: 'exit', callback: () => void): void;
|
|
44
|
+
on(event: 'navigated', callback: (payload: NavigationData) => void): void;
|
|
45
|
+
on(event: 'authenticationSucceeded', callback: () => void): void;
|
|
46
|
+
on(event: 'authenticationFailed', callback: () => void): void;
|
|
47
|
+
on(event: 'error', callback: (data: ErrorData) => void): void;
|
|
48
|
+
on(event: 'loaded', callback: () => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Remove an event listener
|
|
51
|
+
*/
|
|
52
|
+
off(event: FlowEventType, callback: FlowEventCallback): void;
|
|
53
|
+
/**
|
|
54
|
+
* Close the flow and clean up resources
|
|
55
|
+
*/
|
|
56
|
+
close(): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { getBaseUrl } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flow class implementation for handling iframe flows and events
|
|
4
|
+
*/
|
|
5
|
+
export class Flow {
|
|
6
|
+
constructor(containerId, config, partnerName, environment, branchOverride) {
|
|
7
|
+
this.containerId = containerId;
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.partnerName = partnerName;
|
|
10
|
+
this.environment = environment;
|
|
11
|
+
this.branchOverride = branchOverride;
|
|
12
|
+
this.iframe = null;
|
|
13
|
+
this.container = null;
|
|
14
|
+
this.eventListeners = new Map();
|
|
15
|
+
this.keepAliveInterval = null;
|
|
16
|
+
this.setupEventListeners();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the flow by creating and injecting the iframe
|
|
20
|
+
*/
|
|
21
|
+
async initialize() {
|
|
22
|
+
this.container = document.getElementById(this.containerId);
|
|
23
|
+
if (!this.container) {
|
|
24
|
+
throw new Error(`Container with ID "${this.containerId}" not found`);
|
|
25
|
+
}
|
|
26
|
+
this.iframe = document.createElement('iframe');
|
|
27
|
+
this.iframe.src = this.createFlowUrl();
|
|
28
|
+
this.iframe.style.width = '100%';
|
|
29
|
+
this.iframe.style.height = '1000px';
|
|
30
|
+
this.iframe.style.border = 'none';
|
|
31
|
+
this.iframe.style.display = 'block';
|
|
32
|
+
this.container.appendChild(this.iframe);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Construct the specific flow URL - can be overridden by subclasses
|
|
36
|
+
*/
|
|
37
|
+
constructFlowUrl(baseUrl) {
|
|
38
|
+
return `${baseUrl}/${this.partnerName}/auth`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create flow URL using partner name and environment
|
|
42
|
+
*/
|
|
43
|
+
createFlowUrl() {
|
|
44
|
+
console.log('🔧 Creating flow URL...');
|
|
45
|
+
console.log('📝 Config:', this.config);
|
|
46
|
+
console.log('🏢 Partner:', this.partnerName);
|
|
47
|
+
console.log('🌍 Environment:', this.environment);
|
|
48
|
+
console.log('🔝 Branch Override:', this.branchOverride);
|
|
49
|
+
const baseUrl = getBaseUrl(this.environment);
|
|
50
|
+
let finalUrl = this.constructFlowUrl(baseUrl);
|
|
51
|
+
// Add cdn_branch_override parameter for non-production environments
|
|
52
|
+
if (this.branchOverride && this.environment !== 'production') {
|
|
53
|
+
const separator = finalUrl.includes('?') ? '&' : '?';
|
|
54
|
+
finalUrl += `${separator}cdn_branch_override=${this.branchOverride}`;
|
|
55
|
+
}
|
|
56
|
+
console.log('🌐 Final URL:', finalUrl);
|
|
57
|
+
return finalUrl;
|
|
58
|
+
}
|
|
59
|
+
setupEventListeners() {
|
|
60
|
+
// Add post message handlers for internal events - setHeight, scroll etc
|
|
61
|
+
// Also need to implement callbacks for flow completed exit etc in the platform-app
|
|
62
|
+
window.addEventListener('message', (event) => {
|
|
63
|
+
if (!/melio\.com|melioservices\.com/.test(event.origin)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const { type, ...data } = event.data;
|
|
67
|
+
console.log('📬 Received message from iframe:', {
|
|
68
|
+
type,
|
|
69
|
+
data,
|
|
70
|
+
origin: event.origin,
|
|
71
|
+
});
|
|
72
|
+
switch (type) {
|
|
73
|
+
case 'FLOW_COMPLETED':
|
|
74
|
+
this.emit('completed', data);
|
|
75
|
+
break;
|
|
76
|
+
case 'FLOW_EXIT':
|
|
77
|
+
this.emit('exit');
|
|
78
|
+
break;
|
|
79
|
+
case 'NAVIGATED_TO_TARGET':
|
|
80
|
+
this.emit('navigated', data);
|
|
81
|
+
break;
|
|
82
|
+
case 'AUTHENTICATION_SUCCESS':
|
|
83
|
+
this.emit('authenticationSucceeded');
|
|
84
|
+
break;
|
|
85
|
+
case 'AUTHENTICATION_ERROR':
|
|
86
|
+
this.emit('authenticationFailed');
|
|
87
|
+
break;
|
|
88
|
+
case 'ONBOARDING_COMPLETED':
|
|
89
|
+
this.emit('completed', { flowName: 'onboarding', ...data });
|
|
90
|
+
break;
|
|
91
|
+
case 'READY_FOR_INTERACTION':
|
|
92
|
+
this.emit('loaded');
|
|
93
|
+
break;
|
|
94
|
+
case 'MELIO_ERROR':
|
|
95
|
+
if (data.code === 'failed_to_sync_bills') {
|
|
96
|
+
this.emit('error', { errorCode: 'billsSyncFailed' });
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case 'HEIGHT_CHANGE':
|
|
100
|
+
if (this.iframe) {
|
|
101
|
+
this.iframe.style.height = `${data.height}px`;
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
emit(event, data) {
|
|
108
|
+
const listeners = this.eventListeners.get(event);
|
|
109
|
+
if (listeners) {
|
|
110
|
+
listeners.forEach((callback) => {
|
|
111
|
+
try {
|
|
112
|
+
callback(data);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
on(event, callback) {
|
|
121
|
+
if (!this.eventListeners.has(event)) {
|
|
122
|
+
this.eventListeners.set(event, new Set());
|
|
123
|
+
}
|
|
124
|
+
this.eventListeners.get(event).add(callback);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove an event listener
|
|
128
|
+
*/
|
|
129
|
+
off(event, callback) {
|
|
130
|
+
const listeners = this.eventListeners.get(event);
|
|
131
|
+
if (listeners) {
|
|
132
|
+
listeners.delete(callback);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Close the flow and clean up resources
|
|
137
|
+
*/
|
|
138
|
+
close() {
|
|
139
|
+
if (this.keepAliveInterval) {
|
|
140
|
+
clearInterval(this.keepAliveInterval);
|
|
141
|
+
this.keepAliveInterval = null;
|
|
142
|
+
}
|
|
143
|
+
if (this.iframe && this.container) {
|
|
144
|
+
this.container.removeChild(this.iframe);
|
|
145
|
+
this.iframe = null;
|
|
146
|
+
}
|
|
147
|
+
this.eventListeners.clear();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InitConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* InitFlow subclass for handling initialization with callbacks
|
|
5
|
+
*/
|
|
6
|
+
export declare class InitFlow extends Flow {
|
|
7
|
+
private authorizationCode;
|
|
8
|
+
constructor(containerId: string, config: InitConfig, partnerName: string, environment: Environment, branchOverride?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Initialize the init flow by creating and injecting a hidden iframe
|
|
11
|
+
*/
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Construct the specific flow URL for initialization
|
|
15
|
+
*/
|
|
16
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
17
|
+
setupKeepAlive(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Flow } from './Flow.js';
|
|
2
|
+
import { isEmptyString } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* InitFlow subclass for handling initialization with callbacks
|
|
5
|
+
*/
|
|
6
|
+
export class InitFlow extends Flow {
|
|
7
|
+
constructor(containerId, config, partnerName, environment, branchOverride) {
|
|
8
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
9
|
+
if (isEmptyString(config.authCode)) {
|
|
10
|
+
throw new Error('Authorization code is required for init flow');
|
|
11
|
+
}
|
|
12
|
+
this.authorizationCode = config.authCode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the init flow by creating and injecting a hidden iframe
|
|
16
|
+
*/
|
|
17
|
+
async initialize() {
|
|
18
|
+
this.emit('authenticationSucceeded');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Construct the specific flow URL for initialization
|
|
22
|
+
*/
|
|
23
|
+
constructFlowUrl(baseUrl) {
|
|
24
|
+
const params = new URLSearchParams({
|
|
25
|
+
token: this.authorizationCode,
|
|
26
|
+
theme: this.partnerName,
|
|
27
|
+
});
|
|
28
|
+
return `${baseUrl}/${this.partnerName}/auth?${params.toString()}`;
|
|
29
|
+
}
|
|
30
|
+
setupKeepAlive() {
|
|
31
|
+
this.keepAliveInterval = window.setInterval(() => {
|
|
32
|
+
if (this.iframe && this.iframe.contentWindow) {
|
|
33
|
+
this.iframe.contentWindow.postMessage({ type: 'USER_ACTIVE_PING' }, '*');
|
|
34
|
+
}
|
|
35
|
+
}, 30000); // Send ping every 30 seconds
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OnboardingConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* OnboardingFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export declare class OnboardingFlow extends Flow {
|
|
7
|
+
private preFilledParams;
|
|
8
|
+
private enforceOnboarding?;
|
|
9
|
+
private authCode;
|
|
10
|
+
constructor(containerId: string, config: OnboardingConfig, partnerName: string, environment: Environment, authCode: string, branchOverride?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Construct the specific flow URL for onboarding - now goes through /auth
|
|
13
|
+
*/
|
|
14
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Flow } from './Flow.js';
|
|
2
|
+
import { isEmptyString } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* OnboardingFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export class OnboardingFlow extends Flow {
|
|
7
|
+
constructor(containerId, config, partnerName, environment, authCode, branchOverride) {
|
|
8
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
9
|
+
const { userDetails, organizationDetails, enforceOnboarding } = config;
|
|
10
|
+
this.preFilledParams = { userDetails, organizationDetails };
|
|
11
|
+
this.enforceOnboarding = enforceOnboarding;
|
|
12
|
+
this.authCode = authCode;
|
|
13
|
+
if (isEmptyString(this.authCode)) {
|
|
14
|
+
throw new Error('Authorization code is required for onboarding flow. Please call init() before opening onboarding flow.');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Construct the specific flow URL for onboarding - now goes through /auth
|
|
19
|
+
*/
|
|
20
|
+
constructFlowUrl(baseUrl) {
|
|
21
|
+
const params = Object.fromEntries(Object.entries(this.preFilledParams).filter(([_, v]) => v !== undefined));
|
|
22
|
+
let preFilledBase64 = '';
|
|
23
|
+
if (Object.keys(params).length > 0) {
|
|
24
|
+
try {
|
|
25
|
+
const json = JSON.stringify(params);
|
|
26
|
+
preFilledBase64 = btoa(unescape(encodeURIComponent(json)));
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
preFilledBase64 = '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const targetQueryParams = [];
|
|
33
|
+
if (preFilledBase64) {
|
|
34
|
+
targetQueryParams.push(`preFilledParams=${encodeURIComponent(preFilledBase64)}`);
|
|
35
|
+
}
|
|
36
|
+
if (this.enforceOnboarding !== undefined) {
|
|
37
|
+
targetQueryParams.push(`enforceOnboarding=${this.enforceOnboarding}`);
|
|
38
|
+
}
|
|
39
|
+
targetQueryParams.push(`externalOrigin=${this.partnerName}`);
|
|
40
|
+
const target = `/welcome?${targetQueryParams.join('&')}`;
|
|
41
|
+
const encodedTarget = encodeURIComponent(target);
|
|
42
|
+
return `${baseUrl}/${this.partnerName}/auth?token=${this.authCode}&redirectUrl=${encodedTarget}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PayFlowConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* PayFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export declare class PayFlow extends Flow {
|
|
7
|
+
private billIds;
|
|
8
|
+
private authCode;
|
|
9
|
+
constructor(containerId: string, config: PayFlowConfig, partnerName: string, environment: Environment, authCode: string, branchOverride?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Construct the specific flow URL for bill payment - now goes through /auth
|
|
12
|
+
*/
|
|
13
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Flow } from './Flow.js';
|
|
2
|
+
import { isEmptyString } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* PayFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export class PayFlow extends Flow {
|
|
7
|
+
constructor(containerId, config, partnerName, environment, authCode, branchOverride) {
|
|
8
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
9
|
+
this.billIds = config.billIds;
|
|
10
|
+
this.authCode = authCode;
|
|
11
|
+
if (isEmptyString(this.authCode)) {
|
|
12
|
+
throw new Error('Authorization code is required for pay flow. Please call init() before opening pay flow.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Construct the specific flow URL for bill payment - now goes through /auth
|
|
17
|
+
*/
|
|
18
|
+
constructFlowUrl(baseUrl) {
|
|
19
|
+
const billIdsParam = this.billIds.join(',');
|
|
20
|
+
const target = `/external-entries/payment-flow?billIds=${billIdsParam}&externalOrigin=${this.partnerName}`;
|
|
21
|
+
const encodedTarget = encodeURIComponent(target);
|
|
22
|
+
return `${baseUrl}/${this.partnerName}/auth?token=${this.authCode}&redirectUrl=${encodedTarget}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PaymentsDashboardConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* PaymentsDashboardFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export declare class PaymentsDashboardFlow extends Flow {
|
|
7
|
+
private paymentId?;
|
|
8
|
+
private authCode;
|
|
9
|
+
constructor(containerId: string, config: PaymentsDashboardConfig, partnerName: string, environment: Environment, authCode: string, branchOverride?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Construct the specific flow URL for payments dashboard - now 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
|
+
* PaymentsDashboardFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export class PaymentsDashboardFlow 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 payments dashboard flow. Please call init() before opening payments dashboard flow.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Construct the specific flow URL for payments dashboard - now goes through /auth
|
|
17
|
+
*/
|
|
18
|
+
constructFlowUrl(baseUrl) {
|
|
19
|
+
const target = `/pay-dashboard/payments${this.paymentId ? `/${this.paymentId}` : ''}`;
|
|
20
|
+
const encodedTarget = encodeURIComponent(target);
|
|
21
|
+
return `${baseUrl}/${this.partnerName}/auth?token=${this.authCode}&redirectUrl=${encodedTarget}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SettingsConfig, Environment } from '../types.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* SettingsFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export declare class SettingsFlow extends Flow {
|
|
7
|
+
private authCode;
|
|
8
|
+
constructor(containerId: string, config: SettingsConfig, partnerName: string, environment: Environment, authCode: string, branchOverride?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Construct the specific flow URL for settings - now goes through /auth
|
|
11
|
+
*/
|
|
12
|
+
protected constructFlowUrl(baseUrl: string): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Flow } from './Flow.js';
|
|
2
|
+
import { isEmptyString } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* SettingsFlow subclass with custom URL construction
|
|
5
|
+
*/
|
|
6
|
+
export class SettingsFlow extends Flow {
|
|
7
|
+
constructor(containerId, config, partnerName, environment, authCode, branchOverride) {
|
|
8
|
+
super(containerId, config, partnerName, environment, branchOverride);
|
|
9
|
+
this.authCode = authCode;
|
|
10
|
+
if (isEmptyString(this.authCode)) {
|
|
11
|
+
throw new Error('Authorization code is required for settings flow. Please call init() before opening settings flow.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Construct the specific flow URL for settings - now goes through /auth
|
|
16
|
+
*/
|
|
17
|
+
constructFlowUrl(baseUrl) {
|
|
18
|
+
const target = '/view-settings';
|
|
19
|
+
const encodedTarget = encodeURIComponent(target);
|
|
20
|
+
return `${baseUrl}/${this.partnerName}/auth?token=${this.authCode}&redirectUrl=${encodedTarget}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Flow } from './Flow.js';
|
|
2
|
+
export { InitFlow } from './InitFlow.js';
|
|
3
|
+
export { OnboardingFlow } from './OnboardingFlow.js';
|
|
4
|
+
export { PayFlow } from './PayFlow.js';
|
|
5
|
+
export { SettingsFlow } from './SettingsFlow.js';
|
|
6
|
+
export { PaymentsDashboardFlow } from './PaymentsDashboardFlow.js';
|
|
7
|
+
export { getBaseUrl, isEmptyString } from './utils.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Flow } from './Flow.js';
|
|
2
|
+
export { InitFlow } from './InitFlow.js';
|
|
3
|
+
export { OnboardingFlow } from './OnboardingFlow.js';
|
|
4
|
+
export { PayFlow } from './PayFlow.js';
|
|
5
|
+
export { SettingsFlow } from './SettingsFlow.js';
|
|
6
|
+
export { PaymentsDashboardFlow } from './PaymentsDashboardFlow.js';
|
|
7
|
+
export { getBaseUrl, isEmptyString } from './utils.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function to get the base URL for a given environment
|
|
3
|
+
*/
|
|
4
|
+
export function getBaseUrl(environment) {
|
|
5
|
+
switch (environment) {
|
|
6
|
+
case 'production':
|
|
7
|
+
return 'https://partnerships.production.melioservices.com';
|
|
8
|
+
case 'staging01':
|
|
9
|
+
return 'https://partnerships.staging01.melioservices.com';
|
|
10
|
+
case 'public-qa':
|
|
11
|
+
return 'https://partnerships.public-qa.melioservices.com';
|
|
12
|
+
case 'certification':
|
|
13
|
+
return 'https://partnerships.certification.melioservices.com';
|
|
14
|
+
case 'eilat':
|
|
15
|
+
return 'https://partnerships.eilat.melioservices.com';
|
|
16
|
+
case 'localhost':
|
|
17
|
+
return 'http://localhost:3005';
|
|
18
|
+
default:
|
|
19
|
+
return 'https://partnerships.melioservices.com';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const isEmptyString = (str) => {
|
|
23
|
+
return !str?.trim();
|
|
24
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -287,7 +287,17 @@ class InitFlow extends Flow {
|
|
|
287
287
|
* Initialize the init flow by creating and injecting a hidden iframe
|
|
288
288
|
*/
|
|
289
289
|
async initialize() {
|
|
290
|
-
|
|
290
|
+
// For init flow, we create a hidden iframe instead of a visible one
|
|
291
|
+
// Set container to document.body so parent's close() method can remove it
|
|
292
|
+
this.container = document.body;
|
|
293
|
+
this.iframe = document.createElement('iframe');
|
|
294
|
+
this.iframe.src = this.createFlowUrl();
|
|
295
|
+
this.iframe.style.width = '1px';
|
|
296
|
+
this.iframe.style.height = '1px';
|
|
297
|
+
this.iframe.style.position = 'absolute';
|
|
298
|
+
this.iframe.style.left = '-9999px';
|
|
299
|
+
this.iframe.style.top = '-9999px';
|
|
300
|
+
this.container.appendChild(this.iframe);
|
|
291
301
|
}
|
|
292
302
|
/**
|
|
293
303
|
* Construct the specific flow URL for initialization
|
|
@@ -332,11 +342,10 @@ export class MelioSDK {
|
|
|
332
342
|
});
|
|
333
343
|
const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
|
|
334
344
|
{ authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}, 0);
|
|
345
|
+
initFlow.initialize();
|
|
346
|
+
console.log('InitFlow initialized successfully');
|
|
347
|
+
if (options.keepAlive)
|
|
348
|
+
initFlow.setupKeepAlive();
|
|
340
349
|
return initFlow;
|
|
341
350
|
}
|
|
342
351
|
/**
|
package/package.json
CHANGED