@zerohash-sdk/crypto-withdrawals-js 1.11.6 → 1.14.0

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
@@ -49,6 +49,10 @@ const cryptoWithdrawals = new CryptoWithdrawals({
49
49
  onCompleted: ({ withdrawalRequestId }) => {
50
50
  console.log('Withdrawal completed:', withdrawalRequestId);
51
51
  },
52
+ onFailed: ({ withdrawalRequestId, statusDetails }) => {
53
+ // statusDetails is the only explanation of the failure available.
54
+ console.log('Withdrawal failed:', withdrawalRequestId, statusDetails);
55
+ },
52
56
  onError: ({ errorCode, reason }) => {
53
57
  console.error('Error:', errorCode, 'Reason:', reason);
54
58
  },
@@ -89,6 +93,7 @@ await cryptoWithdrawals.render(document.getElementById('container')!);
89
93
  | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
90
94
  | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
91
95
  | `onCompleted` | `({ withdrawalRequestId }) => void` | No | - | Callback when the withdrawal flow completes successfully |
96
+ | `onFailed` | `({ withdrawalRequestId }) => void` | No | - | Callback when a withdrawal ends in a failed state |
92
97
  | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
93
98
  | `onClose` | `() => void` | No | - | Callback when the widget is closed |
94
99
  | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
@@ -113,6 +118,17 @@ await cryptoWithdrawals.render(document.getElementById('container')!);
113
118
  - Safari 14+
114
119
  - All modern browsers with Web Components support
115
120
 
121
+ ### `onFailed` and `onError` on a failed withdrawal
122
+
123
+ A failed withdrawal fires **both** `onFailed` and `onError`, so existing
124
+ integrations that only implemented `onError` keep working.
125
+
126
+ `onFailed` is the correct callback: it carries the withdrawal's details,
127
+ including `statusDetails`, the only explanation of the failure available. Build
128
+ against `onFailed`, and if you handle both, guard against counting one failure
129
+ twice. Firing `onError` for a failed withdrawal is deprecated and will be
130
+ removed in a future major version.
131
+
116
132
  ## More Information & Support
117
133
 
118
134
  For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
package/dist/index.d.ts CHANGED
@@ -24,7 +24,8 @@ declare type AppEvent<TType extends string = string, TData = Record<string, unkn
24
24
  */
25
25
  declare interface BaseConfig<TEvent = AppEvent> extends CommonCallbacks<TEvent> {
26
26
  /**
27
- * JWT token used for authentication
27
+ * JWT token used for authentication. Provide/update it via `setJWT`
28
+ * (`updateConfig({ jwt })`).
28
29
  */
29
30
  jwt: string;
30
31
 
@@ -119,7 +120,11 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
119
120
  }
120
121
 
121
122
  /**
122
- * Update the configuration of the widget
123
+ * Update the configuration of the widget (e.g. `theme`, or the `jwt`).
124
+ *
125
+ * Passing a `jwt` is the JS-SDK equivalent of `setJWT` — it provides the JWT
126
+ * used to authenticate.
127
+ *
123
128
  * @param config - Partial configuration to update
124
129
  * @returns void
125
130
  */
@@ -394,11 +399,36 @@ export default CryptoWithdrawals;
394
399
  declare type CryptoWithdrawalsCallbacks = CommonCallbacks<CryptoWithdrawalsEvent> & {
395
400
  /** Called when the withdrawal is successfully completed */
396
401
  onCompleted?: (data: CryptoWithdrawalsCompletedData) => void;
402
+ /**
403
+ * Called when a withdrawal reaches a terminal **failed** state, carrying the
404
+ * failed withdrawal's details.
405
+ *
406
+ * A failed withdrawal also fires `onError`, for backwards compatibility with
407
+ * hosts written before this callback existed — `onError` was this flow's only
408
+ * failure signal. Build against `onFailed`; if you handle both, guard against
409
+ * counting one failure twice. The compatibility `onError` is deprecated and
410
+ * will be removed in a future major version.
411
+ */
412
+ onFailed?: (data: CryptoWithdrawalsCompletedData) => void;
397
413
  };
398
414
 
399
415
  declare type CryptoWithdrawalsCompletedData = {
400
416
  /** The withdrawal request ID returned from the API */
401
417
  withdrawalRequestId: string;
418
+ /** Terminal status value, e.g. `CONFIRMED` or `FAILED` */
419
+ status?: string;
420
+ /**
421
+ * Human-readable reason for the status. On a failure this is the only
422
+ * explanation available anywhere in the stack, so surface it rather than
423
+ * reporting a bare id.
424
+ */
425
+ statusDetails?: string;
426
+ /** Asset identifier (e.g. 'btc', 'eth') */
427
+ assetId?: string;
428
+ /** Network identifier (e.g. 'bitcoin', 'ethereum') */
429
+ networkId?: string;
430
+ /** Amount withdrawn */
431
+ amount?: string;
402
432
  };
403
433
 
404
434
  export declare interface CryptoWithdrawalsConfig extends BaseConfig<CryptoWithdrawalsEvent>, CryptoWithdrawalsCallbacks {
package/dist/index.js CHANGED
@@ -169,7 +169,11 @@ class j {
169
169
  }
170
170
  }
171
171
  /**
172
- * Update the configuration of the widget
172
+ * Update the configuration of the widget (e.g. `theme`, or the `jwt`).
173
+ *
174
+ * Passing a `jwt` is the JS-SDK equivalent of `setJWT` — it provides the JWT
175
+ * used to authenticate.
176
+ *
173
177
  * @param config - Partial configuration to update
174
178
  * @returns void
175
179
  */
@@ -302,7 +306,10 @@ class H extends j {
302
306
  SCRIPT_LOAD_FAILED: "Failed to load the Connect CryptoWithdrawals script.",
303
307
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
304
308
  };
305
- scriptUrls = x("crypto-withdrawals-web", "index.js", { legacyAliases: !0, eu: !0 });
309
+ scriptUrls = x("crypto-withdrawals-web", "index.js", {
310
+ legacyAliases: !0,
311
+ eu: !0
312
+ });
306
313
  webComponentTag = "zerohash-crypto-withdrawals";
307
314
  /**
308
315
  * Render the CryptoWithdrawals widget to a container element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/crypto-withdrawals-js",
3
- "version": "1.11.6",
3
+ "version": "1.14.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",