@melio-eng/web-sdk 1.0.24 → 1.0.25-pr.45.180a812
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
|
@@ -297,11 +297,31 @@ export class MelioSDK {
|
|
|
297
297
|
this.environment = 'production';
|
|
298
298
|
this.partnerName = '';
|
|
299
299
|
this.branchOverride = undefined;
|
|
300
|
+
this.isInitialized = false;
|
|
301
|
+
this.currentInitFlow = null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Check if SDK is initialized and throw error if not
|
|
305
|
+
*/
|
|
306
|
+
ensureInitialized() {
|
|
307
|
+
if (!this.isInitialized) {
|
|
308
|
+
throw new Error('SDK must be initialized with init() before calling any flow methods');
|
|
309
|
+
}
|
|
300
310
|
}
|
|
301
311
|
/**
|
|
302
312
|
* Initialize the SDK by creating an authentication flow
|
|
303
313
|
*/
|
|
304
314
|
init(authenticationCode, options) {
|
|
315
|
+
if (this.currentInitFlow) {
|
|
316
|
+
console.warn('SDK initialization already in progress. Cleaning up previous initialization...');
|
|
317
|
+
this.currentInitFlow.close();
|
|
318
|
+
this.currentInitFlow = null;
|
|
319
|
+
this.isInitialized = false;
|
|
320
|
+
}
|
|
321
|
+
else if (this.isInitialized) {
|
|
322
|
+
console.warn('SDK already initialized. Reinitializing with new configuration...');
|
|
323
|
+
this.isInitialized = false;
|
|
324
|
+
}
|
|
305
325
|
this.partnerName = options.partnerName;
|
|
306
326
|
this.environment = options.environment || 'production';
|
|
307
327
|
this.branchOverride = options.branchOverride;
|
|
@@ -311,8 +331,17 @@ export class MelioSDK {
|
|
|
311
331
|
});
|
|
312
332
|
const initFlow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
|
|
313
333
|
{ authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
|
|
334
|
+
this.currentInitFlow = initFlow;
|
|
335
|
+
initFlow.on('authenticationSucceeded', () => {
|
|
336
|
+
console.log('Authentication succeeded - SDK is now initialized');
|
|
337
|
+
this.isInitialized = true;
|
|
338
|
+
});
|
|
339
|
+
initFlow.on('authenticationFailed', () => {
|
|
340
|
+
console.log('Authentication failed - resetting SDK initialization state');
|
|
341
|
+
this.isInitialized = false;
|
|
342
|
+
this.currentInitFlow = null;
|
|
343
|
+
});
|
|
314
344
|
initFlow.initialize();
|
|
315
|
-
console.log('InitFlow initialized successfully');
|
|
316
345
|
if (options.keepAlive)
|
|
317
346
|
initFlow.setupKeepAlive();
|
|
318
347
|
return initFlow;
|
|
@@ -321,6 +350,7 @@ export class MelioSDK {
|
|
|
321
350
|
* Launch the onboarding flow
|
|
322
351
|
*/
|
|
323
352
|
openOnboarding(config) {
|
|
353
|
+
this.ensureInitialized();
|
|
324
354
|
const flow = new OnboardingFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
325
355
|
flow.initialize();
|
|
326
356
|
return flow;
|
|
@@ -329,6 +359,7 @@ export class MelioSDK {
|
|
|
329
359
|
* Launch the pay flow
|
|
330
360
|
*/
|
|
331
361
|
openPayFlow(config) {
|
|
362
|
+
this.ensureInitialized();
|
|
332
363
|
const flow = new PayFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
333
364
|
flow.initialize();
|
|
334
365
|
return flow;
|
|
@@ -337,6 +368,7 @@ export class MelioSDK {
|
|
|
337
368
|
* Launch the settings flow
|
|
338
369
|
*/
|
|
339
370
|
openSettings(config) {
|
|
371
|
+
this.ensureInitialized();
|
|
340
372
|
const flow = new SettingsFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
341
373
|
flow.initialize();
|
|
342
374
|
return flow;
|
|
@@ -345,6 +377,7 @@ export class MelioSDK {
|
|
|
345
377
|
* Launch the payments dashboard flow
|
|
346
378
|
*/
|
|
347
379
|
openPaymentsDashboard(config) {
|
|
380
|
+
this.ensureInitialized();
|
|
348
381
|
const flow = new PaymentsDashboardFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
|
|
349
382
|
flow.initialize();
|
|
350
383
|
return flow;
|
package/package.json
CHANGED