@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 +6 -1
- package/dist/index.js +40 -15
- package/package.json +1 -1
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
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
|
378
|
+
export * from './types';
|
package/package.json
CHANGED