@melio-eng/web-sdk 1.1.0 → 1.2.0-pr.94.cf53d50

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,13 @@ export class Flow {
77
77
  case 'FLOW_EXIT':
78
78
  this.emit('exit');
79
79
  break;
80
+ case 'PARTNER_ACTION_REQUIRED':
81
+ // Only the quick payment button is reported today; every other
82
+ // requiredAction is ignored until the SDK declares a type for it.
83
+ if (data.data?.requiredAction === 'NAVIGATE_TO_NEW_PAYMENT') {
84
+ this.emit('buttonClicked', { type: 'quickPayment' });
85
+ }
86
+ break;
80
87
  case 'NAVIGATED_TO_TARGET':
81
88
  this.emit('navigated', data);
82
89
  break;
package/dist/types.d.ts CHANGED
@@ -129,6 +129,26 @@ 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
+ * Melio cannot navigate your page, so a button with no listener registered visibly does
141
+ * nothing when clicked.
142
+ *
143
+ * Only buttons whose destination lives in your product are reported here. Buttons that end
144
+ * a flow keep their existing events — "Back to bills" still arrives as `completed`.
145
+ *
146
+ * Further button types are added in minor releases, so switch on `type` and treat an
147
+ * unrecognised value as a no-op rather than an error.
148
+ */
149
+ export interface ButtonClickedData {
150
+ type: 'quickPayment';
151
+ }
132
152
  /**
133
153
  * Flow completion data
134
154
  */
@@ -150,11 +170,11 @@ export interface ErrorData {
150
170
  /**
151
171
  * Event types that can be listened to
152
172
  */
153
- export type FlowEventType = 'completed' | 'exit' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired';
173
+ export type FlowEventType = 'completed' | 'exit' | 'buttonClicked' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired';
154
174
  /**
155
175
  * Event callback function types
156
176
  */
157
- export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData) => void) | (() => void);
177
+ export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData | ButtonClickedData) => void) | (() => void);
158
178
  /**
159
179
  * Flow instance interface for event handling
160
180
  */
@@ -166,6 +186,7 @@ export interface FlowInstance {
166
186
  */
167
187
  on(event: 'completed', callback: (data: FlowCompletionData) => void): void;
168
188
  on(event: 'exit', callback: () => void): void;
189
+ on(event: 'buttonClicked', callback: (data: ButtonClickedData) => void): void;
169
190
  on(event: 'navigated', callback: (payload: NavigationData) => void): void;
170
191
  on(event: 'authenticationSucceeded', callback: () => void): void;
171
192
  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.cf53d50",
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",