@melio-eng/web-sdk 1.3.0-pr.96.0240f85 → 1.3.0-pr.97.57d4a09

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
@@ -185,7 +185,7 @@ flow.on("navigated", (p) => console.log("Navigated to:", p.target));
185
185
  **Available Events:**
186
186
  - `loaded`: The flow iframe has rendered
187
187
  - `completed`: The user successfully finished a flow
188
- - `error`: A flow error occurred (e.g. `billsSyncFailed`)
188
+ - `error`: A flow error occurred (`billsSyncFailed`, or `vendorsSyncFailed` in the Just Pay flow)
189
189
  - `exit`: The user exited the iframe
190
190
  - `navigated`: Navigation occurred inside the iframe
191
191
  - `buttonClicked`: The user clicked a button whose destination is in your product (see below)
@@ -1,5 +1,13 @@
1
1
  import { getBaseUrl } from './utils.js';
2
2
  import { logger, describeError, describeConfig, redactUrl } from './logger.js';
3
+ /**
4
+ * MELIO_ERROR codes the embedded app reports, mapped to the host-facing error
5
+ * codes the SDK emits. A code that is absent here is logged but not forwarded.
6
+ */
7
+ const HOST_FACING_ERROR_CODES = {
8
+ failed_to_sync_bills: 'billsSyncFailed',
9
+ failed_to_sync_vendors: 'vendorsSyncFailed',
10
+ };
3
11
  /**
4
12
  * Flow class implementation for handling iframe flows and events
5
13
  */
@@ -155,17 +163,18 @@ export class Flow {
155
163
  case 'PAYMENT_SCHEDULED':
156
164
  this.emit('completed', { flowName: 'payment', ...data });
157
165
  break;
158
- case 'MELIO_ERROR':
159
- // Only one code maps to a host-facing event, so an unmapped code would
160
- // otherwise be dropped silently.
166
+ case 'MELIO_ERROR': {
167
+ const errorCode = HOST_FACING_ERROR_CODES[data.code];
168
+ // Logged even when unmapped, so a new code cannot be dropped silently.
161
169
  logger.error('Embedded app reported MELIO_ERROR', {
162
170
  ...data,
163
- forwardedToHost: data.code === 'failed_to_sync_bills',
171
+ forwardedToHost: Boolean(errorCode),
164
172
  });
165
- if (data.code === 'failed_to_sync_bills') {
166
- this.emit('error', { errorCode: 'billsSyncFailed' });
173
+ if (errorCode) {
174
+ this.emit('error', { errorCode });
167
175
  }
168
176
  break;
177
+ }
169
178
  case 'HEIGHT_CHANGE':
170
179
  if (this.iframe) {
171
180
  this.iframe.style.height = `${data.height}px`;
package/dist/types.d.ts CHANGED
@@ -165,9 +165,13 @@ export interface FlowCompletionData {
165
165
  * 1. Trying to sync a non-USD bill
166
166
  * 2. Trying to sync an already paid bill / draft bill
167
167
  * 3. Trying to sync bills with an unsupported amount (amount 0 or greater than $1M)
168
+ *
169
+ * vendorsSyncFailed is returned when the Just Pay flow could not load any of the
170
+ * requested vendors from the accounting platform. The flow cannot continue, so
171
+ * close it and surface the failure in your own product.
168
172
  */
169
173
  export interface ErrorData {
170
- errorCode: 'billsSyncFailed';
174
+ errorCode: 'billsSyncFailed' | 'vendorsSyncFailed';
171
175
  }
172
176
  /**
173
177
  * Event types that can be listened to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melio-eng/web-sdk",
3
- "version": "1.3.0-pr.96.0240f85",
3
+ "version": "1.3.0-pr.97.57d4a09",
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",