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

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,12 @@ export declare class MelioSDK implements MelioSDK {
7
7
  private environment;
8
8
  private partnerName;
9
9
  private branchOverride;
10
+ private isInitialized;
10
11
  constructor();
12
+ /**
13
+ * Check if SDK is initialized and throw error if not
14
+ */
15
+ private ensureInitialized;
11
16
  /**
12
17
  * Initialize the SDK by creating an authentication flow
13
18
  */
@@ -33,4 +38,4 @@ export declare class MelioSDK implements MelioSDK {
33
38
  * Export the SDK instance
34
39
  */
35
40
  export declare const melioSDK: MelioSDK;
36
- export * from './types.js';
41
+ export * from './types';
package/dist/index.js CHANGED
@@ -292,30 +292,52 @@ export class MelioSDK {
292
292
  this.environment = 'production';
293
293
  this.partnerName = '';
294
294
  this.branchOverride = undefined;
295
+ this.isInitialized = false;
296
+ }
297
+ /**
298
+ * Check if SDK is initialized and throw error if not
299
+ */
300
+ ensureInitialized() {
301
+ if (!this.isInitialized) {
302
+ throw new Error('SDK must be initialized with init() before calling any flow methods');
303
+ }
295
304
  }
296
305
  /**
297
306
  * Initialize the SDK by creating an authentication flow
298
307
  */
299
308
  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;
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;
329
+ }
330
+ catch (error) {
331
+ this.isInitialized = false;
332
+ console.error('Failed to initialize SDK:', error);
333
+ throw error;
334
+ }
314
335
  }
315
336
  /**
316
337
  * Launch the onboarding flow
317
338
  */
318
339
  openOnboarding(config) {
340
+ this.ensureInitialized();
319
341
  const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
320
342
  flow.initialize();
321
343
  return flow;
@@ -324,6 +346,7 @@ export class MelioSDK {
324
346
  * Launch the pay flow
325
347
  */
326
348
  openPayFlow(config) {
349
+ this.ensureInitialized();
327
350
  const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
328
351
  flow.initialize();
329
352
  return flow;
@@ -332,6 +355,7 @@ export class MelioSDK {
332
355
  * Launch the settings flow
333
356
  */
334
357
  openSettings(config) {
358
+ this.ensureInitialized();
335
359
  const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
336
360
  flow.initialize();
337
361
  return flow;
@@ -340,6 +364,7 @@ export class MelioSDK {
340
364
  * Launch the payments dashboard flow
341
365
  */
342
366
  openPaymentsDashboard(config) {
367
+ this.ensureInitialized();
343
368
  const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
344
369
  flow.initialize();
345
370
  return flow;
@@ -350,4 +375,4 @@ export class MelioSDK {
350
375
  */
351
376
  export const melioSDK = new MelioSDK();
352
377
  // Export types for consumers
353
- export * from './types.js';
378
+ 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.7e7fc86",
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",