@melio-eng/web-sdk 1.0.21 → 1.0.22-pr.42.0b9f393

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,11 +7,18 @@ export declare class MelioSDK implements MelioSDK {
7
7
  private environment;
8
8
  private partnerName;
9
9
  private branchOverride;
10
+ private isInitialized;
11
+ private initPromise;
10
12
  constructor();
11
13
  /**
12
14
  * Initialize the SDK by creating an authentication flow
13
15
  */
14
16
  init(authenticationCode: string, options: InitOptions): FlowInstance;
17
+ /**
18
+ * Check if the SDK has been successfully initialized
19
+ * @throws Error if SDK is not initialized
20
+ */
21
+ private ensureInitialized;
15
22
  /**
16
23
  * Launch the onboarding flow
17
24
  */
package/dist/index.js CHANGED
@@ -292,6 +292,8 @@ export class MelioSDK {
292
292
  this.environment = 'production';
293
293
  this.partnerName = '';
294
294
  this.branchOverride = undefined;
295
+ this.isInitialized = false;
296
+ this.initPromise = null;
295
297
  }
296
298
  /**
297
299
  * Initialize the SDK by creating an authentication flow
@@ -306,16 +308,37 @@ export class MelioSDK {
306
308
  });
307
309
  const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
308
310
  { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
311
+ this.initPromise = new Promise((resolve, reject) => {
312
+ initFlow.on('authenticationSucceeded', () => {
313
+ this.isInitialized = true;
314
+ console.log('SDK initialization completed successfully');
315
+ resolve();
316
+ });
317
+ initFlow.on('authenticationFailed', () => {
318
+ this.isInitialized = false;
319
+ console.error('SDK initialization failed - authentication failed');
320
+ reject(new Error('SDK initialization failed: Authentication failed'));
321
+ });
322
+ });
309
323
  initFlow.initialize();
310
- console.log('InitFlow initialized successfully');
311
324
  if (options.keepAlive)
312
325
  initFlow.setupKeepAlive();
313
326
  return initFlow;
314
327
  }
328
+ /**
329
+ * Check if the SDK has been successfully initialized
330
+ * @throws Error if SDK is not initialized
331
+ */
332
+ ensureInitialized() {
333
+ if (!this.isInitialized) {
334
+ throw new Error('SDK not initialized. Call init() first and wait for successful authentication.');
335
+ }
336
+ }
315
337
  /**
316
338
  * Launch the onboarding flow
317
339
  */
318
340
  openOnboarding(config) {
341
+ this.ensureInitialized();
319
342
  const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
320
343
  flow.initialize();
321
344
  return flow;
@@ -324,6 +347,7 @@ export class MelioSDK {
324
347
  * Launch the pay flow
325
348
  */
326
349
  openPayFlow(config) {
350
+ this.ensureInitialized();
327
351
  const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
328
352
  flow.initialize();
329
353
  return flow;
@@ -332,6 +356,7 @@ export class MelioSDK {
332
356
  * Launch the settings flow
333
357
  */
334
358
  openSettings(config) {
359
+ this.ensureInitialized();
335
360
  const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
336
361
  flow.initialize();
337
362
  return flow;
@@ -340,6 +365,7 @@ export class MelioSDK {
340
365
  * Launch the payments dashboard flow
341
366
  */
342
367
  openPaymentsDashboard(config) {
368
+ this.ensureInitialized();
343
369
  const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
344
370
  flow.initialize();
345
371
  return flow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.21",
3
+ "version": "1.0.22-pr.42.0b9f393",
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",