@melio-eng/web-sdk 1.0.22-pr.42.b297eba → 1.0.22-pr.45.8de7c41

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 CHANGED
@@ -8,48 +8,34 @@ export declare class MelioSDK implements MelioSDK {
8
8
  private partnerName;
9
9
  private branchOverride;
10
10
  private isInitialized;
11
- private initPromise;
12
11
  constructor();
13
12
  /**
14
- * Check if the SDK is currently initialized
13
+ * Check if SDK is initialized and throw error if not
15
14
  */
16
- isReady(): boolean;
17
- /**
18
- * Get a promise that resolves when initialization is complete
19
- */
20
- waitForInitialization(): Promise<void>;
21
- /**
22
- * Reset the SDK state to allow re-initialization after a failed attempt
23
- */
24
- reset(): void;
15
+ private ensureInitialized;
25
16
  /**
26
17
  * Initialize the SDK by creating an authentication flow
27
18
  */
28
19
  init(authenticationCode: string, options: InitOptions): FlowInstance;
29
- /**
30
- * Check if the SDK has been successfully initialized
31
- * @throws Error if SDK is not initialized
32
- */
33
- private ensureInitialized;
34
20
  /**
35
21
  * Launch the onboarding flow
36
22
  */
37
- openOnboarding(config: OnboardingConfig): Promise<FlowInstance>;
23
+ openOnboarding(config: OnboardingConfig): FlowInstance;
38
24
  /**
39
25
  * Launch the pay flow
40
26
  */
41
- openPayFlow(config: PayFlowConfig): Promise<FlowInstance>;
27
+ openPayFlow(config: PayFlowConfig): FlowInstance;
42
28
  /**
43
29
  * Launch the settings flow
44
30
  */
45
- openSettings(config: SettingsConfig): Promise<FlowInstance>;
31
+ openSettings(config: SettingsConfig): FlowInstance;
46
32
  /**
47
33
  * Launch the payments dashboard flow
48
34
  */
49
- openPaymentsDashboard(config: PaymentsDashboardConfig): Promise<FlowInstance>;
35
+ openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
50
36
  }
51
37
  /**
52
38
  * Export the SDK instance
53
39
  */
54
40
  export declare const melioSDK: MelioSDK;
55
- export * from './types.js';
41
+ export * from './types';
package/dist/index.js CHANGED
@@ -83,7 +83,7 @@ class Flow {
83
83
  if (!/melio\.com|melioservices\.com/.test(event.origin)) {
84
84
  return;
85
85
  }
86
- const { type, data } = event.data;
86
+ const { type, ...data } = event.data;
87
87
  console.log('📬 Received message from iframe:', {
88
88
  type,
89
89
  data,
@@ -96,7 +96,7 @@ class Flow {
96
96
  case 'FLOW_EXIT':
97
97
  this.emit('exit');
98
98
  break;
99
- case 'FLOW_NAVIGATED':
99
+ case 'NAVIGATED_TO_TARGET':
100
100
  this.emit('navigated', data);
101
101
  break;
102
102
  case 'AUTHENTICATION_SUCCESS':
@@ -293,131 +293,81 @@ export class MelioSDK {
293
293
  this.partnerName = '';
294
294
  this.branchOverride = undefined;
295
295
  this.isInitialized = false;
296
- this.initPromise = null;
297
296
  }
298
297
  /**
299
- * Check if the SDK is currently initialized
298
+ * Check if SDK is initialized and throw error if not
300
299
  */
301
- isReady() {
302
- return this.isInitialized;
303
- }
304
- /**
305
- * Get a promise that resolves when initialization is complete
306
- */
307
- async waitForInitialization() {
308
- if (!this.initPromise) {
309
- throw new Error('SDK not initialized. Call init() first.');
310
- }
311
- await this.initPromise;
312
- }
313
- /**
314
- * Reset the SDK state to allow re-initialization after a failed attempt
315
- */
316
- reset() {
317
- this.isInitialized = false;
318
- this.initPromise = null;
319
- this.partnerName = '';
320
- this.environment = 'production';
321
- this.branchOverride = undefined;
322
- if (this.keepAliveInterval) {
323
- clearInterval(this.keepAliveInterval);
324
- this.keepAliveInterval = null;
300
+ ensureInitialized() {
301
+ if (!this.isInitialized) {
302
+ throw new Error('SDK must be initialized with init() before calling any flow methods');
325
303
  }
326
304
  }
327
305
  /**
328
306
  * Initialize the SDK by creating an authentication flow
329
307
  */
330
308
  init(authenticationCode, options) {
331
- if (this.initPromise) {
332
- throw new Error('SDK initialization is already in progress or completed. Call reset() first if you need to reinitialize.');
333
- }
334
- this.partnerName = options.partnerName;
335
- this.environment = options.environment || 'production';
336
- this.branchOverride = options.branchOverride;
337
- console.log('starting init flow', {
338
- partnerName: this.partnerName,
339
- environment: this.environment,
340
- });
341
- const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
342
- { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
343
- this.initPromise = new Promise((resolve, reject) => {
344
- initFlow.on('authenticationSucceeded', () => {
345
- this.isInitialized = true;
346
- console.log('SDK initialization completed successfully');
347
- resolve();
309
+ try {
310
+ this.partnerName = options.partnerName;
311
+ this.environment = options.environment || 'production';
312
+ this.branchOverride = options.branchOverride;
313
+ console.log('starting init flow', {
314
+ partnerName: this.partnerName,
315
+ environment: this.environment,
348
316
  });
317
+ const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
318
+ { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
319
+ initFlow.initialize();
320
+ console.log('InitFlow initialized successfully');
321
+ this.isInitialized = true;
322
+ // Listen for authentication failure and reset initialization state
349
323
  initFlow.on('authenticationFailed', () => {
324
+ console.log('Authentication failed - resetting SDK initialization state');
350
325
  this.isInitialized = false;
351
- console.error('SDK initialization failed - authentication failed');
352
- reject(new Error('SDK initialization failed: Authentication failed'));
353
326
  });
354
- try {
355
- initFlow.initialize();
356
- }
357
- catch (error) {
358
- this.isInitialized = false;
359
- console.error('SDK initialization failed - initialization error:', error);
360
- reject(error instanceof Error
361
- ? error
362
- : new Error('SDK initialization failed: Unknown error'));
363
- }
364
- });
365
- if (options.keepAlive)
366
- initFlow.setupKeepAlive();
367
- return initFlow;
368
- }
369
- /**
370
- * Check if the SDK has been successfully initialized
371
- * @throws Error if SDK is not initialized
372
- */
373
- async ensureInitialized() {
374
- if (!this.initPromise) {
375
- throw new Error('SDK not initialized. Call init() first.');
376
- }
377
- try {
378
- await this.initPromise;
327
+ if (options.keepAlive)
328
+ initFlow.setupKeepAlive();
329
+ return initFlow;
379
330
  }
380
331
  catch (error) {
381
- throw new Error('SDK initialization failed. Please call init() again.');
382
- }
383
- if (!this.isInitialized) {
384
- throw new Error('SDK not initialized. Call init() first and wait for successful authentication.');
332
+ this.isInitialized = false;
333
+ console.error('Failed to initialize SDK:', error);
334
+ throw error;
385
335
  }
386
336
  }
387
337
  /**
388
338
  * Launch the onboarding flow
389
339
  */
390
- async openOnboarding(config) {
391
- await this.ensureInitialized();
340
+ openOnboarding(config) {
341
+ this.ensureInitialized();
392
342
  const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
393
- await flow.initialize();
343
+ flow.initialize();
394
344
  return flow;
395
345
  }
396
346
  /**
397
347
  * Launch the pay flow
398
348
  */
399
- async openPayFlow(config) {
400
- await this.ensureInitialized();
349
+ openPayFlow(config) {
350
+ this.ensureInitialized();
401
351
  const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
402
- await flow.initialize();
352
+ flow.initialize();
403
353
  return flow;
404
354
  }
405
355
  /**
406
356
  * Launch the settings flow
407
357
  */
408
- async openSettings(config) {
409
- await this.ensureInitialized();
358
+ openSettings(config) {
359
+ this.ensureInitialized();
410
360
  const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
411
- await flow.initialize();
361
+ flow.initialize();
412
362
  return flow;
413
363
  }
414
364
  /**
415
365
  * Launch the payments dashboard flow
416
366
  */
417
- async openPaymentsDashboard(config) {
418
- await this.ensureInitialized();
367
+ openPaymentsDashboard(config) {
368
+ this.ensureInitialized();
419
369
  const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
420
- await flow.initialize();
370
+ flow.initialize();
421
371
  return flow;
422
372
  }
423
373
  }
@@ -426,4 +376,4 @@ export class MelioSDK {
426
376
  */
427
377
  export const melioSDK = new MelioSDK();
428
378
  // Export types for consumers
429
- export * from './types.js';
379
+ export * from './types';
package/dist/types.d.ts CHANGED
@@ -77,6 +77,7 @@ export interface InitConfig extends BaseFlowConfig {
77
77
  export interface NavigationData {
78
78
  /** The target route or page the user navigated to */
79
79
  target: string;
80
+ targetAction: 'schedulePayment' | 'scheduleBatchPayments' | 'viewSubscriptionPlans' | 'viewSettingsCollaborators' | 'viewPayment' | 'viewPaidPayment' | 'viewBill' | 'addNewBill' | 'viewVendors' | 'addVendor' | 'viewSettings' | 'viewArInvoices' | 'redirect';
80
81
  }
81
82
  /**
82
83
  * Flow completion data
@@ -130,42 +131,22 @@ export interface MelioSDK {
130
131
  * @returns Flow instance for event handling
131
132
  */
132
133
  init(authorizationCode: string, options: InitOptions): FlowInstance;
133
- /**
134
- * Check if the SDK is currently initialized
135
- * @returns true if initialized, false otherwise
136
- */
137
- isReady(): boolean;
138
- /**
139
- * Get a promise that resolves when initialization is complete
140
- * @throws Error if init() was never called
141
- */
142
- waitForInitialization(): Promise<void>;
143
- /**
144
- * Reset the SDK state to allow re-initialization after a failed attempt
145
- */
146
- reset(): void;
147
134
  /**
148
135
  * Launch the onboarding flow
149
136
  * @param config - Configuration for the onboarding flow
150
- * @returns Promise that resolves to flow instance for event handling
151
- */
152
- openOnboarding(config: OnboardingConfig): Promise<FlowInstance>;
153
- /**
154
- * Launch the pay flow
155
- * @param config - Configuration for the pay flow
156
- * @returns Promise that resolves to flow instance for event handling
137
+ * @returns Flow instance for event handling
157
138
  */
158
- openPayFlow(config: PayFlowConfig): Promise<FlowInstance>;
139
+ openOnboarding(config: OnboardingConfig): FlowInstance;
159
140
  /**
160
141
  * Launch the settings flow
161
142
  * @param config - Configuration for the settings flow
162
- * @returns Promise that resolves to flow instance for event handling
143
+ * @returns Flow instance for event handling
163
144
  */
164
- openSettings(config: SettingsConfig): Promise<FlowInstance>;
145
+ openSettings(config: SettingsConfig): FlowInstance;
165
146
  /**
166
147
  * Launch the payments dashboard flow
167
148
  * @param config - Configuration for the payments dashboard flow
168
- * @returns Promise that resolves to flow instance for event handling
149
+ * @returns Flow instance for event handling
169
150
  */
170
- openPaymentsDashboard(config: PaymentsDashboardConfig): Promise<FlowInstance>;
151
+ openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance;
171
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.22-pr.42.b297eba",
3
+ "version": "1.0.22-pr.45.8de7c41",
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",