@melio-eng/web-sdk 1.1.0 → 1.2.0-pr.94.95a5a43

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/README.md CHANGED
@@ -178,8 +178,37 @@ flow.on("navigated", (p) => console.log("Navigated to:", p.target));
178
178
  - `error`: A flow error occurred (e.g. `billsSyncFailed`)
179
179
  - `exit`: The user exited the iframe
180
180
  - `navigated`: Navigation occurred inside the iframe
181
+ - `buttonClicked`: The user clicked a button whose destination is in your product (see below)
181
182
  - `authenticationSucceeded` / `authenticationFailed`: emitted on the `init` instance
182
183
 
184
+ #### Button clicks (`buttonClicked`)
185
+
186
+ Some Melio screens contain buttons whose destination lives in **your** product, not in Melio —
187
+ today the "+ Quick payment" button on the payments dashboard, which should take the user to
188
+ your own supplier selection page. Melio cannot navigate the host page, so it reports the click
189
+ and waits for you:
190
+
191
+ ```typescript
192
+ const dashboard = melioSDK.openPaymentsDashboard({
193
+ containerId: "melio-dashboard-container",
194
+ });
195
+
196
+ dashboard.on("buttonClicked", ({ type }) => {
197
+ if (type === "quickPayment") {
198
+ window.location.assign("/suppliers/select");
199
+ }
200
+ });
201
+ ```
202
+
203
+ | `type` | Emitted when | What you should do |
204
+ |---|---|---|
205
+ | `quickPayment` | The user clicks the quick payment button on the payments dashboard | Take them to your supplier selection page, then open a pay flow |
206
+
207
+ Without a listener the button does nothing at all. Only buttons whose destination is in your
208
+ product are reported here — buttons that end a flow keep their existing events, so "Back to
209
+ bills" still arrives as `completed`. Further button types ship in minor releases, so switch on
210
+ `type` and treat an unrecognised value as a no-op.
211
+
183
212
  ## 💡 Examples
184
213
 
185
214
  ### Pay Flow
@@ -1,4 +1,4 @@
1
- import { FlowInstance, FlowEventType, FlowEventCallback, FlowCompletionData, NavigationData, BaseFlowConfig, Environment, ErrorData } from '../types.js';
1
+ import { FlowInstance, FlowEventType, FlowEventCallback, FlowCompletionData, NavigationData, ButtonClickedData, BaseFlowConfig, Environment, ErrorData } from '../types.js';
2
2
  /**
3
3
  * Flow class implementation for handling iframe flows and events
4
4
  */
@@ -33,6 +33,7 @@ export declare class Flow implements FlowInstance {
33
33
  protected emit(event: 'completed', data: FlowCompletionData): void;
34
34
  protected emit(event: 'loaded'): void;
35
35
  protected emit(event: 'exit'): void;
36
+ protected emit(event: 'buttonClicked', data: ButtonClickedData): void;
36
37
  protected emit(event: 'navigated', data: NavigationData): void;
37
38
  protected emit(event: 'authenticationSucceeded'): void;
38
39
  protected emit(event: 'authenticationFailed'): void;
@@ -44,6 +45,7 @@ export declare class Flow implements FlowInstance {
44
45
  */
45
46
  on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
46
47
  on(event: 'exit', callback: () => void): void;
48
+ on(event: 'buttonClicked', callback: (data: ButtonClickedData) => void): void;
47
49
  on(event: 'navigated', callback: (payload: NavigationData) => void): void;
48
50
  on(event: 'authenticationSucceeded', callback: () => void): void;
49
51
  on(event: 'authenticationFailed', callback: () => void): void;
@@ -77,6 +77,11 @@ export class Flow {
77
77
  case 'FLOW_EXIT':
78
78
  this.emit('exit');
79
79
  break;
80
+ case 'PARTNER_ACTION_REQUIRED':
81
+ if (data.data?.requiredAction === 'NAVIGATE_TO_NEW_PAYMENT') {
82
+ this.emit('buttonClicked', { type: 'quickPayment' });
83
+ }
84
+ break;
80
85
  case 'NAVIGATED_TO_TARGET':
81
86
  this.emit('navigated', data);
82
87
  break;
package/dist/types.d.ts CHANGED
@@ -129,6 +129,23 @@ export interface NavigationData {
129
129
  target: string;
130
130
  targetAction: 'schedulePayment' | 'scheduleBatchPayments' | 'viewSubscriptionPlans' | 'viewSettingsCollaborators' | 'viewPayment' | 'viewPaidPayment' | 'viewBill' | 'addNewBill' | 'viewVendors' | 'addVendor' | 'viewSettings' | 'viewArInvoices' | 'redirect';
131
131
  }
132
+ /**
133
+ * Which button the user clicked inside the embedded Melio app, delivered by the
134
+ * `buttonClicked` event.
135
+ *
136
+ * `'quickPayment'` is the new payment button on the payments dashboard: take the user to
137
+ * your own supplier selection page, from which you open a payment flow.
138
+ *
139
+ * @remarks
140
+ * Buttons that end a flow keep their existing events — "Back to bills" still arrives as
141
+ * `completed`.
142
+ *
143
+ * Further button types are added in minor releases, so switch on `type` and treat an
144
+ * unrecognised value as a no-op rather than an error.
145
+ */
146
+ export interface ButtonClickedData {
147
+ type: 'quickPayment';
148
+ }
132
149
  /**
133
150
  * Flow completion data
134
151
  */
@@ -150,11 +167,11 @@ export interface ErrorData {
150
167
  /**
151
168
  * Event types that can be listened to
152
169
  */
153
- export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired';
170
+ export type FlowEventType = 'completed' | 'exit' | 'buttonClicked' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired';
154
171
  /**
155
172
  * Event callback function types
156
173
  */
157
- export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData) => void) | (() => void);
174
+ export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData | ButtonClickedData) => void) | (() => void);
158
175
  /**
159
176
  * Flow instance interface for event handling
160
177
  */
@@ -166,6 +183,7 @@ export interface FlowInstance {
166
183
  */
167
184
  on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
168
185
  on(event: 'exit', callback: () => void): void;
186
+ on(event: 'buttonClicked', callback: (data: ButtonClickedData) => void): void;
169
187
  on(event: 'navigated', callback: (payload: NavigationData) => void): void;
170
188
  on(event: 'authenticationSucceeded', callback: () => void): void;
171
189
  on(event: 'authenticationFailed', callback: () => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-pr.94.95a5a43",
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",