@melio-eng/web-sdk 1.0.22 → 1.0.23-pr.45.a9e1d28

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
@@ -7,7 +7,13 @@ export declare class MelioSDK implements MelioSDK {
7
7
  private environment;
8
8
  private partnerName;
9
9
  private branchOverride;
10
+ private isInitialized;
11
+ private currentInitFlow;
10
12
  constructor();
13
+ /**
14
+ * Check if SDK is initialized and throw error if not
15
+ */
16
+ private ensureInitialized;
11
17
  /**
12
18
  * Initialize the SDK by creating an authentication flow
13
19
  */
@@ -33,4 +39,4 @@ export declare class MelioSDK implements MelioSDK {
33
39
  * Export the SDK instance
34
40
  */
35
41
  export declare const melioSDK: MelioSDK;
36
- export * from './types.js';
42
+ export * from './types';
package/dist/index.js CHANGED
@@ -292,30 +292,67 @@ export class MelioSDK {
292
292
  this.environment = 'production';
293
293
  this.partnerName = '';
294
294
  this.branchOverride = undefined;
295
+ this.isInitialized = false;
296
+ this.currentInitFlow = null;
297
+ }
298
+ /**
299
+ * Check if SDK is initialized and throw error if not
300
+ */
301
+ ensureInitialized() {
302
+ if (!this.isInitialized) {
303
+ throw new Error('SDK must be initialized with init() before calling any flow methods');
304
+ }
295
305
  }
296
306
  /**
297
307
  * Initialize the SDK by creating an authentication flow
298
308
  */
299
309
  init(authenticationCode, options) {
300
- this.partnerName = options.partnerName;
301
- this.environment = options.environment || 'production';
302
- this.branchOverride = options.branchOverride;
303
- console.log('starting init flow', {
304
- partnerName: this.partnerName,
305
- environment: this.environment,
306
- });
307
- const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
308
- { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
309
- initFlow.initialize();
310
- console.log('InitFlow initialized successfully');
311
- if (options.keepAlive)
312
- initFlow.setupKeepAlive();
313
- return initFlow;
310
+ try {
311
+ if (this.currentInitFlow) {
312
+ this.currentInitFlow.close();
313
+ this.currentInitFlow = null;
314
+ }
315
+ this.partnerName = options.partnerName;
316
+ this.environment = options.environment || 'production';
317
+ this.branchOverride = options.branchOverride;
318
+ this.isInitialized = false;
319
+ console.log('starting init flow', {
320
+ partnerName: this.partnerName,
321
+ environment: this.environment,
322
+ });
323
+ const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
324
+ { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
325
+ this.currentInitFlow = initFlow;
326
+ initFlow.on('authenticationSucceeded', () => {
327
+ console.log('Authentication succeeded - SDK is now initialized');
328
+ if (this.currentInitFlow === initFlow) {
329
+ this.isInitialized = true;
330
+ }
331
+ });
332
+ initFlow.on('authenticationFailed', () => {
333
+ console.log('Authentication failed - resetting SDK initialization state');
334
+ if (this.currentInitFlow === initFlow) {
335
+ this.isInitialized = false;
336
+ this.currentInitFlow = null;
337
+ }
338
+ });
339
+ initFlow.initialize();
340
+ if (options.keepAlive)
341
+ initFlow.setupKeepAlive();
342
+ return initFlow;
343
+ }
344
+ catch (error) {
345
+ this.isInitialized = false;
346
+ this.currentInitFlow = null;
347
+ console.error('Failed to initialize SDK:', error);
348
+ throw error;
349
+ }
314
350
  }
315
351
  /**
316
352
  * Launch the onboarding flow
317
353
  */
318
354
  openOnboarding(config) {
355
+ this.ensureInitialized();
319
356
  const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
320
357
  flow.initialize();
321
358
  return flow;
@@ -324,6 +361,7 @@ export class MelioSDK {
324
361
  * Launch the pay flow
325
362
  */
326
363
  openPayFlow(config) {
364
+ this.ensureInitialized();
327
365
  const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
328
366
  flow.initialize();
329
367
  return flow;
@@ -332,6 +370,7 @@ export class MelioSDK {
332
370
  * Launch the settings flow
333
371
  */
334
372
  openSettings(config) {
373
+ this.ensureInitialized();
335
374
  const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
336
375
  flow.initialize();
337
376
  return flow;
@@ -340,6 +379,7 @@ export class MelioSDK {
340
379
  * Launch the payments dashboard flow
341
380
  */
342
381
  openPaymentsDashboard(config) {
382
+ this.ensureInitialized();
343
383
  const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
344
384
  flow.initialize();
345
385
  return flow;
@@ -350,4 +390,4 @@ export class MelioSDK {
350
390
  */
351
391
  export const melioSDK = new MelioSDK();
352
392
  // Export types for consumers
353
- export * from './types.js';
393
+ export * from './types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.22",
3
+ "version": "1.0.23-pr.45.a9e1d28",
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",