@melio-eng/web-sdk 1.0.22 → 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 +6 -0
- package/dist/index.js +34 -1
- package/package.json +1 -1
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
|
*/
|
package/dist/index.js
CHANGED
|
@@ -292,11 +292,31 @@ 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) {
|
|
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;
|
|
315
|
+
}
|
|
316
|
+
else if (this.isInitialized) {
|
|
317
|
+
console.warn('SDK already initialized. Reinitializing with new configuration...');
|
|
318
|
+
this.isInitialized = false;
|
|
319
|
+
}
|
|
300
320
|
this.partnerName = options.partnerName;
|
|
301
321
|
this.environment = options.environment || 'production';
|
|
302
322
|
this.branchOverride = options.branchOverride;
|
|
@@ -306,8 +326,17 @@ export class MelioSDK {
|
|
|
306
326
|
});
|
|
307
327
|
const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
|
|
308
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
|
+
});
|
|
309
339
|
initFlow.initialize();
|
|
310
|
-
console.log('InitFlow initialized successfully');
|
|
311
340
|
if (options.keepAlive)
|
|
312
341
|
initFlow.setupKeepAlive();
|
|
313
342
|
return initFlow;
|
|
@@ -316,6 +345,7 @@ export class MelioSDK {
|
|
|
316
345
|
* Launch the onboarding flow
|
|
317
346
|
*/
|
|
318
347
|
openOnboarding(config) {
|
|
348
|
+
this.ensureInitialized();
|
|
319
349
|
const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
320
350
|
flow.initialize();
|
|
321
351
|
return flow;
|
|
@@ -324,6 +354,7 @@ export class MelioSDK {
|
|
|
324
354
|
* Launch the pay flow
|
|
325
355
|
*/
|
|
326
356
|
openPayFlow(config) {
|
|
357
|
+
this.ensureInitialized();
|
|
327
358
|
const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
328
359
|
flow.initialize();
|
|
329
360
|
return flow;
|
|
@@ -332,6 +363,7 @@ export class MelioSDK {
|
|
|
332
363
|
* Launch the settings flow
|
|
333
364
|
*/
|
|
334
365
|
openSettings(config) {
|
|
366
|
+
this.ensureInitialized();
|
|
335
367
|
const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
336
368
|
flow.initialize();
|
|
337
369
|
return flow;
|
|
@@ -340,6 +372,7 @@ export class MelioSDK {
|
|
|
340
372
|
* Launch the payments dashboard flow
|
|
341
373
|
*/
|
|
342
374
|
openPaymentsDashboard(config) {
|
|
375
|
+
this.ensureInitialized();
|
|
343
376
|
const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
344
377
|
flow.initialize();
|
|
345
378
|
return flow;
|
package/package.json
CHANGED