@melio-eng/web-sdk 1.0.15 → 1.0.16-pr.31.3d6cae4

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
@@ -3,27 +3,16 @@ import { InitOptions, OnboardingConfig, SettingsConfig, FlowInstance, PaymentsDa
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(authenticationCode: string, options: InitOptions): FlowInstance;
27
16
  private setupKeepAlive;
28
17
  /**
29
18
  * Launch the onboarding flow
package/dist/index.js CHANGED
@@ -81,7 +81,10 @@ class Flow {
81
81
  // Also need to implement callbacks for flow completed exit etc in the platform-app
82
82
  window.addEventListener('message', (event) => {
83
83
  // Verify origin for security
84
- if (event.origin !== 'https://app.melio.com') {
84
+ // if (event.origin !== 'https://app.melio.com') {
85
+ // return;
86
+ // }
87
+ if (event.origin === 'http://localhost:3001') {
85
88
  return;
86
89
  }
87
90
  const { type, data } = event.data;
@@ -231,69 +234,63 @@ class PaymentsDashboardFlow extends Flow {
231
234
  return `${baseUrl}/${this.partnerName}/pay-dashboard/payments`;
232
235
  }
233
236
  }
237
+ /**
238
+ * InitFlow subclass for handling initialization with callbacks
239
+ */
240
+ class InitFlow extends Flow {
241
+ constructor(containerId, config, partnerName, environment, branchOverride) {
242
+ super(containerId, config, partnerName, environment, branchOverride);
243
+ this.authorizationCode = config.authCode;
244
+ }
245
+ /**
246
+ * Initialize the init flow by creating and injecting a hidden iframe
247
+ */
248
+ async initialize() {
249
+ // For init flow, we create a hidden iframe instead of a visible one
250
+ this.iframe = document.createElement('iframe');
251
+ this.iframe.src = this.createFlowUrl();
252
+ this.iframe.style.width = '1px';
253
+ this.iframe.style.height = '1px';
254
+ this.iframe.style.position = 'absolute';
255
+ this.iframe.style.left = '-9999px';
256
+ this.iframe.style.top = '-9999px';
257
+ document.body.appendChild(this.iframe);
258
+ }
259
+ /**
260
+ * Construct the specific flow URL for initialization
261
+ */
262
+ constructFlowUrl(baseUrl) {
263
+ const params = new URLSearchParams({
264
+ token: this.authorizationCode,
265
+ theme: this.partnerName,
266
+ });
267
+ return `${baseUrl}/${this.partnerName}/start?${params.toString()}`;
268
+ }
269
+ }
234
270
  /**
235
271
  * Main SDK implementation - now partner agnostic
236
272
  */
237
273
  export class MelioSDK {
238
274
  constructor() {
239
- this.isInitialized = false;
240
- this.authIframe = null;
241
275
  this.keepAliveIframe = null;
242
276
  this.keepAliveInterval = null;
243
- this.initPromise = null;
244
277
  this.environment = 'production';
245
278
  this.partnerName = '';
246
279
  this.branchOverride = undefined;
247
280
  }
248
281
  /**
249
- * Initialize the SDK by creating an authentication iframe
282
+ * Initialize the SDK by creating an authentication flow
250
283
  */
251
- async init(authorizationCode, options) {
252
- // Prevent multiple simultaneous init calls
253
- if (this.initPromise) {
254
- return this.initPromise;
255
- }
284
+ init(authenticationCode, options) {
256
285
  // Set partner name and environment from options
257
286
  this.partnerName = options.partnerName;
258
287
  this.environment = options.environment || 'production';
259
288
  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;
289
+ const flow = new InitFlow('', // no need container id for init flow as it is created inside the initialization
290
+ { authCode: authenticationCode, containerId: '' }, this.partnerName, this.environment, this.branchOverride);
291
+ flow.initialize();
292
+ this.setupKeepAlive();
293
+ return flow;
297
294
  }
298
295
  setupKeepAlive() {
299
296
  // Send periodic pings to keep session alive
package/dist/types.d.ts CHANGED
@@ -64,6 +64,12 @@ 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
+ authCode: string;
72
+ }
67
73
  /**
68
74
  * Event data for navigation events
69
75
  */
@@ -99,6 +105,8 @@ export interface FlowInstance {
99
105
  on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
100
106
  on(event: 'exit', callback: () => void): void;
101
107
  on(event: 'navigated', callback: (payload: NavigationData) => void): void;
108
+ on(event: 'authenticationSucceeded', callback: () => void): void;
109
+ on(event: 'authenticationFailed', callback: () => void): void;
102
110
  /**
103
111
  * Remove an event listener for this flow
104
112
  * @param event - The event type to remove listener for
@@ -118,8 +126,9 @@ export interface MelioSDK {
118
126
  * Initialize the SDK with the provided authorization code
119
127
  * @param authorizationCode - OAuth code received from the partner
120
128
  * @param options - Initialization options
129
+ * @returns Flow instance for event handling
121
130
  */
122
- init(authorizationCode: string, options: InitOptions): Promise<void>;
131
+ init(authorizationCode: string, options: InitOptions): FlowInstance;
123
132
  /**
124
133
  * Launch the onboarding flow
125
134
  * @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.3d6cae4",
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",