@melio-eng/web-sdk 1.0.15 → 1.0.16-pr.31.45a86e9

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
@@ -1,29 +1,18 @@
1
- import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, PayFlowConfig } from './types.js';
1
+ import { InitOptions, InitConfig, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDashboardConfig, PayFlowConfig } from './types.js';
2
2
  /**
3
3
  * Main SDK implementation - now partner agnostic
4
4
  */
5
5
  export declare class MelioSDK implements MelioSDK {
6
- private isInitialized;
7
- private authIframe;
8
6
  private keepAliveIframe;
9
7
  private keepAliveInterval;
10
- private initPromise;
11
8
  private environment;
12
9
  private partnerName;
13
10
  private branchOverride;
14
11
  constructor();
15
12
  /**
16
- * Initialize the SDK by creating an authentication iframe
13
+ * Initialize the SDK by creating an authentication flow
17
14
  */
18
- init(authorizationCode: string, options: InitOptions): Promise<void>;
19
- /**
20
- * Perform the actual initialization
21
- */
22
- private performInit;
23
- /**
24
- * Create authentication initialization URL using partner name and environment
25
- */
26
- private createAuthInitUrl;
15
+ init(config: InitConfig, options: InitOptions): FlowInstance;
27
16
  private setupKeepAlive;
28
17
  /**
29
18
  * Launch the onboarding flow
package/dist/index.js CHANGED
@@ -231,69 +231,62 @@ class PaymentsDashboardFlow extends Flow {
231
231
  return `${baseUrl}/${this.partnerName}/pay-dashboard/payments`;
232
232
  }
233
233
  }
234
+ /**
235
+ * InitFlow subclass for handling initialization with callbacks
236
+ */
237
+ class InitFlow extends Flow {
238
+ constructor(containerId, config, partnerName, environment, branchOverride) {
239
+ super(containerId, config, partnerName, environment, branchOverride);
240
+ this.authorizationCode = config.authorizationCode;
241
+ }
242
+ /**
243
+ * Initialize the init flow by creating and injecting a hidden iframe
244
+ */
245
+ async initialize() {
246
+ // For init flow, we create a hidden iframe instead of a visible one
247
+ this.iframe = document.createElement('iframe');
248
+ this.iframe.src = this.createFlowUrl();
249
+ this.iframe.style.width = '1px';
250
+ this.iframe.style.height = '1px';
251
+ this.iframe.style.position = 'absolute';
252
+ this.iframe.style.left = '-9999px';
253
+ this.iframe.style.top = '-9999px';
254
+ document.body.appendChild(this.iframe);
255
+ }
256
+ /**
257
+ * Construct the specific flow URL for initialization
258
+ */
259
+ constructFlowUrl(baseUrl) {
260
+ const params = new URLSearchParams({
261
+ token: this.authorizationCode,
262
+ theme: this.partnerName,
263
+ });
264
+ return `${baseUrl}/${this.partnerName}/start?${params.toString()}`;
265
+ }
266
+ }
234
267
  /**
235
268
  * Main SDK implementation - now partner agnostic
236
269
  */
237
270
  export class MelioSDK {
238
271
  constructor() {
239
- this.isInitialized = false;
240
- this.authIframe = null;
241
272
  this.keepAliveIframe = null;
242
273
  this.keepAliveInterval = null;
243
- this.initPromise = null;
244
274
  this.environment = 'production';
245
275
  this.partnerName = '';
246
276
  this.branchOverride = undefined;
247
277
  }
248
278
  /**
249
- * Initialize the SDK by creating an authentication iframe
279
+ * Initialize the SDK by creating an authentication flow
250
280
  */
251
- async init(authorizationCode, options) {
252
- // Prevent multiple simultaneous init calls
253
- if (this.initPromise) {
254
- return this.initPromise;
255
- }
281
+ init(config, options) {
256
282
  // Set partner name and environment from options
257
283
  this.partnerName = options.partnerName;
258
284
  this.environment = options.environment || 'production';
259
285
  this.branchOverride = options.branchOverride;
260
- this.initPromise = this.performInit(authorizationCode, options);
261
- return this.initPromise;
262
- }
263
- /**
264
- * Perform the actual initialization
265
- */
266
- async performInit(authorizationCode, options) {
267
- if (this.isInitialized) {
268
- return;
269
- }
270
- return new Promise((resolve, reject) => {
271
- // Create hidden iframe for authentication
272
- this.authIframe = document.createElement('iframe');
273
- this.authIframe.src = this.createAuthInitUrl(authorizationCode);
274
- this.authIframe.style.width = '1px';
275
- this.authIframe.style.height = '1px';
276
- // Add iframe to document
277
- document.body.appendChild(this.authIframe);
278
- this.setupKeepAlive();
279
- resolve();
280
- });
281
- }
282
- /**
283
- * Create authentication initialization URL using partner name and environment
284
- */
285
- createAuthInitUrl(authorizationCode) {
286
- const params = new URLSearchParams({
287
- token: authorizationCode,
288
- theme: this.partnerName,
289
- });
290
- const baseUrl = getBaseUrl(this.environment);
291
- let finalUrl = `${baseUrl}/${this.partnerName}/start?${params.toString()}`;
292
- // Add cdn_branch_override parameter for non-production environments
293
- if (this.branchOverride && this.environment !== 'production') {
294
- finalUrl += `&cdn_branch_override=${this.branchOverride}`;
295
- }
296
- return finalUrl;
286
+ const flow = new InitFlow(config.containerId, config, this.partnerName, this.environment, this.branchOverride);
287
+ flow.initialize();
288
+ this.setupKeepAlive();
289
+ return flow;
297
290
  }
298
291
  setupKeepAlive() {
299
292
  // Send periodic pings to keep session alive
package/dist/types.d.ts CHANGED
@@ -64,6 +64,13 @@ export interface SettingsConfig extends BaseFlowConfig {
64
64
  */
65
65
  export interface PaymentsDashboardConfig extends BaseFlowConfig {
66
66
  }
67
+ /**
68
+ * Configuration for init flow
69
+ */
70
+ export interface InitConfig extends BaseFlowConfig {
71
+ /** The authorization code for initialization */
72
+ authorizationCode: string;
73
+ }
67
74
  /**
68
75
  * Event data for navigation events
69
76
  */
@@ -99,6 +106,8 @@ export interface FlowInstance {
99
106
  on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
100
107
  on(event: 'exit', callback: () => void): void;
101
108
  on(event: 'navigated', callback: (payload: NavigationData) => void): void;
109
+ on(event: 'authenticationSucceeded', callback: () => void): void;
110
+ on(event: 'authenticationFailed', callback: () => void): void;
102
111
  /**
103
112
  * Remove an event listener for this flow
104
113
  * @param event - The event type to remove listener for
@@ -116,10 +125,11 @@ export interface FlowInstance {
116
125
  export interface MelioSDK {
117
126
  /**
118
127
  * Initialize the SDK with the provided authorization code
119
- * @param authorizationCode - OAuth code received from the partner
128
+ * @param config - Configuration for the init flow
120
129
  * @param options - Initialization options
130
+ * @returns Flow instance for event handling
121
131
  */
122
- init(authorizationCode: string, options: InitOptions): Promise<void>;
132
+ init(config: InitConfig, options: InitOptions): FlowInstance;
123
133
  /**
124
134
  * Launch the onboarding flow
125
135
  * @param config - Configuration for the onboarding flow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.16-pr.31.45a86e9",
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",