@melio-eng/web-sdk 1.0.23-pr.45.7e7fc86 → 1.0.23-pr.45.99d35aa

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,6 +8,7 @@ export declare class MelioSDK implements MelioSDK {
8
8
  private partnerName;
9
9
  private branchOverride;
10
10
  private isInitialized;
11
+ private currentInitFlow;
11
12
  constructor();
12
13
  /**
13
14
  * Check if SDK is initialized and throw error if not
@@ -38,4 +39,4 @@ export declare class MelioSDK implements MelioSDK {
38
39
  * Export the SDK instance
39
40
  */
40
41
  export declare const melioSDK: MelioSDK;
41
- export * from './types';
42
+ export * from './types.js';
package/dist/index.js CHANGED
@@ -293,6 +293,7 @@ export class MelioSDK {
293
293
  this.partnerName = '';
294
294
  this.branchOverride = undefined;
295
295
  this.isInitialized = false;
296
+ this.currentInitFlow = null;
296
297
  }
297
298
  /**
298
299
  * Check if SDK is initialized and throw error if not
@@ -306,32 +307,39 @@ export class MelioSDK {
306
307
  * Initialize the SDK by creating an authentication flow
307
308
  */
308
309
  init(authenticationCode, options) {
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,
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
- this.isInitialized = true;
321
- // Listen for authentication failure and reset initialization state
322
- initFlow.on('authenticationFailed', () => {
323
- console.log('Authentication failed - resetting SDK initialization state');
324
- this.isInitialized = false;
325
- });
326
- if (options.keepAlive)
327
- initFlow.setupKeepAlive();
328
- return initFlow;
310
+ if (this.currentInitFlow) {
311
+ console.warn('SDK initialization already in progress. Cleaning up previous initialization...');
312
+ this.currentInitFlow.close();
313
+ this.currentInitFlow = null;
314
+ this.isInitialized = false;
329
315
  }
330
- catch (error) {
316
+ else if (this.isInitialized) {
317
+ console.warn('SDK already initialized. Reinitializing with new configuration...');
331
318
  this.isInitialized = false;
332
- console.error('Failed to initialize SDK:', error);
333
- throw error;
334
319
  }
320
+ this.partnerName = options.partnerName;
321
+ this.environment = options.environment || 'production';
322
+ this.branchOverride = options.branchOverride;
323
+ console.log('starting init flow', {
324
+ partnerName: this.partnerName,
325
+ environment: this.environment,
326
+ });
327
+ const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
328
+ { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
329
+ this.currentInitFlow = initFlow;
330
+ initFlow.on('authenticationSucceeded', () => {
331
+ console.log('Authentication succeeded - SDK is now initialized');
332
+ this.isInitialized = true;
333
+ });
334
+ initFlow.on('authenticationFailed', () => {
335
+ console.log('Authentication failed - resetting SDK initialization state');
336
+ this.isInitialized = false;
337
+ this.currentInitFlow = null;
338
+ });
339
+ initFlow.initialize();
340
+ if (options.keepAlive)
341
+ initFlow.setupKeepAlive();
342
+ return initFlow;
335
343
  }
336
344
  /**
337
345
  * Launch the onboarding flow
@@ -375,4 +383,4 @@ export class MelioSDK {
375
383
  */
376
384
  export const melioSDK = new MelioSDK();
377
385
  // Export types for consumers
378
- export * from './types';
386
+ export * from './types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.23-pr.45.7e7fc86",
3
+ "version": "1.0.23-pr.45.99d35aa",
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",