@circle-fin/app-kit 1.10.0 → 1.11.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.
@@ -16,6 +16,17 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ // Buffer polyfill setup - executes before any other code
20
+ // Ensures globalThis.Buffer is available for Solana libraries
21
+ import { Buffer } from 'buffer';
22
+ if (typeof globalThis !== 'undefined' && typeof globalThis.Buffer === 'undefined') {
23
+ globalThis.Buffer = Buffer;
24
+ }
25
+ if (typeof window !== 'undefined' && typeof window.Buffer === 'undefined') {
26
+ window.Buffer = Buffer;
27
+ }
28
+
29
+
19
30
  import { z } from 'zod';
20
31
  import { PublicKey } from '@solana/web3.js';
21
32
  import 'bn.js';
@@ -41,6 +52,27 @@ import { getAddress } from '@ethersproject/address';
41
52
  * }
42
53
  * ```
43
54
  */ const isNodeEnvironment = ()=>typeof process !== 'undefined' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
55
+ /**
56
+ * Return the SDK User-Agent request header only when running in Node.js.
57
+ *
58
+ * Browsers forbid manually setting `User-Agent`, and a custom fallback header
59
+ * can trigger CORS preflight. Non-Node server runtimes also omit this optional
60
+ * attribution header because they cannot set it reliably.
61
+ *
62
+ * @returns A User-Agent header in Node.js, or an empty object otherwise.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * import { getNodeUserAgentHeader } from '@core/utils'
67
+ *
68
+ * const headers = {
69
+ * 'Content-Type': 'application/json',
70
+ * ...getNodeUserAgentHeader(),
71
+ * }
72
+ * ```
73
+ */ const getNodeUserAgentHeader = ()=>isNodeEnvironment() ? {
74
+ 'User-Agent': getUserAgent()
75
+ } : {};
44
76
  /**
45
77
  * Detect the runtime environment and return a shortened identifier.
46
78
  *
@@ -7080,13 +7112,12 @@ const swapTokenEnumSchema = z.enum([
7080
7112
  headers: {
7081
7113
  ...DEFAULT_CONFIG.headers,
7082
7114
  ...config.headers ?? {},
7083
- // In browser environments, directly setting the 'User-Agent' or similar headers is restricted and may be ignored or cause errors.
7084
- // This is why we use the 'X-User-Agent' header instead.
7085
- ...typeof window === 'undefined' ? {
7086
- 'User-Agent': getUserAgent()
7087
- } : {
7088
- 'X-User-Agent': getUserAgent()
7089
- }
7115
+ // Browsers forbid setting a user-agent request header, and the custom
7116
+ // fallback header the SDK used instead trips CORS preflight against the
7117
+ // Circle APIs (it isn't in their `Access-Control-Allow-Headers`),
7118
+ // blocking the request. So send the SDK user agent only in Node;
7119
+ // browsers omit it entirely.
7120
+ ...getNodeUserAgentHeader()
7090
7121
  }
7091
7122
  };
7092
7123
  let lastError;
@@ -8358,6 +8389,7 @@ function parseOrThrow(value, schema, context) {
8358
8389
  if (payload.tokenIn !== undefined) safe['tokenIn'] = payload.tokenIn;
8359
8390
  if (payload.tokenOut !== undefined) safe['tokenOut'] = payload.tokenOut;
8360
8391
  if (payload.txHash !== undefined) safe['txHash'] = payload.txHash;
8392
+ if (payload.correlationId !== undefined) safe['correlationId'] = payload.correlationId;
8361
8393
  if (payload.errorDetails !== undefined) {
8362
8394
  const errorDetails = {
8363
8395
  ...payload.errorDetails.errorCode !== undefined && {
@@ -8428,18 +8460,15 @@ function parseOrThrow(value, schema, context) {
8428
8460
  timeoutHandle.unref();
8429
8461
  }
8430
8462
  try {
8431
- const isNode = isNodeEnvironment();
8432
- const userAgent = getUserAgent();
8433
8463
  await fetch(getLogsUrl(), {
8434
8464
  method: 'POST',
8435
8465
  headers: {
8436
8466
  'Content-Type': 'application/json',
8437
- // Browser restricts setting User-Agent; use X-User-Agent instead.
8438
- ...isNode ? {
8439
- 'User-Agent': userAgent
8440
- } : {
8441
- 'X-User-Agent': userAgent
8442
- }
8467
+ // Browsers forbid setting a user-agent request header, and the custom
8468
+ // fallback header the SDK used instead trips CORS preflight (it isn't
8469
+ // in the telemetry endpoint's `Access-Control-Allow-Headers`), so send
8470
+ // it only in Node; browsers omit it entirely.
8471
+ ...getNodeUserAgentHeader()
8443
8472
  },
8444
8473
  body: JSON.stringify(toSafePayload(payload)),
8445
8474
  signal: controller.signal
@@ -8652,7 +8681,7 @@ function parseOrThrow(value, schema, context) {
8652
8681
  // discards the stack trace, nested `cause`, and any custom Error
8653
8682
  // properties — exactly the context an on-call needs when a
8654
8683
  // resolver-closure regression triggers this path.
8655
- console.warn(`[stablecoin-kits telemetry] dropped error event '${eventType}':`, cause);
8684
+ console.warn(`[stablecoin-kits telemetry] dropped event '${eventType}':`, cause);
8656
8685
  } catch {
8657
8686
  // console.warn itself throwing is the user's environment; nothing more we
8658
8687
  // can do without risking the original operation error.
@@ -8668,7 +8697,9 @@ function parseOrThrow(value, schema, context) {
8668
8697
  sdkVersion: config.sdkVersion,
8669
8698
  eventType,
8670
8699
  timestamp: new Date().toISOString(),
8671
- errorDetails,
8700
+ ...errorDetails !== undefined && {
8701
+ errorDetails
8702
+ },
8672
8703
  clientContext: buildClientContext(),
8673
8704
  ...context?.sourceChain != null && {
8674
8705
  sourceChain: context.sourceChain
@@ -8684,6 +8715,9 @@ function parseOrThrow(value, schema, context) {
8684
8715
  },
8685
8716
  ...context?.txHash != null && {
8686
8717
  txHash: context.txHash
8718
+ },
8719
+ ...context?.correlationId != null && {
8720
+ correlationId: context.correlationId
8687
8721
  }
8688
8722
  };
8689
8723
  }
@@ -8745,7 +8779,7 @@ function parseOrThrow(value, schema, context) {
8745
8779
  }
8746
8780
 
8747
8781
  var name = "@circle-fin/unified-balance-kit";
8748
- var version = "1.3.0";
8782
+ var version = "1.3.1";
8749
8783
  var pkg = {
8750
8784
  name: name,
8751
8785
  version: version};
@@ -20423,7 +20457,11 @@ const removeFundParamsSchema = z.object({
20423
20457
  // Remove Fund Operations
20424
20458
  // ---------------------------------------------------------------------------
20425
20459
  /**
20426
- * Kick off a delayed fund removal from an account.
20460
+ * Kick off a delayed recovery fund removal from an account.
20461
+ *
20462
+ * Use `initiateRemoveFund` only as a trustless fallback when the normal spend
20463
+ * flow is unavailable. For day-to-day movement out of a Unified Balance, use
20464
+ * `spend`.
20427
20465
  *
20428
20466
  * Validates `from` and `amount`, resolves the chain and token via
20429
20467
  * {@link resolveRemoveFundParams}, selects the matching provider, then calls
@@ -20460,7 +20498,10 @@ const removeFundParamsSchema = z.object({
20460
20498
  return provider.initiateRemoveFund(resolved);
20461
20499
  }
20462
20500
  /**
20463
- * Complete a fund removal once the 7-day activation period has passed.
20501
+ * Complete a recovery fund removal once the 7-day withdrawal delay has passed.
20502
+ *
20503
+ * Use `removeFund` only as a trustless fallback when the normal spend flow is
20504
+ * unavailable. For day-to-day movement out of a Unified Balance, use `spend`.
20464
20505
  *
20465
20506
  * Validates `from`, resolves the chain and token via
20466
20507
  * {@link resolveRemoveFundParams}, selects the matching provider, then calls
@@ -20549,13 +20590,18 @@ const removeFundParamsSchema = z.object({
20549
20590
  /** SDK name used in telemetry payloads. */ const SDK_NAME = resolveKitSdkName(pkg.name);
20550
20591
  /**
20551
20592
  * A high-level class-based interface for cross-chain USDC deposits,
20552
- * spending, balance queries, delegation management, and withdrawals.
20593
+ * spending, balance queries, delegation management, and recovery fund removals.
20553
20594
  *
20554
20595
  * UnifiedBalanceKit provides a familiar class-based API for developers who
20555
20596
  * prefer traditional object-oriented patterns. The class maintains an
20556
20597
  * internal context and provides methods that delegate to the standalone
20557
20598
  * operation functions exported by this package.
20558
20599
  *
20600
+ * Use `spend` for normal movement out of a Unified Balance. `removeFund` is a
20601
+ * trustless recovery path for situations where the normal spend flow is
20602
+ * unavailable, and it requires a 7-day withdrawal delay before funds can be
20603
+ * removed.
20604
+ *
20559
20605
  * @remarks
20560
20606
  * For functional usage, import and use the operations directly:
20561
20607
  * ```typescript
@@ -20776,7 +20822,11 @@ const removeFundParamsSchema = z.object({
20776
20822
  });
20777
20823
  }
20778
20824
  /**
20779
- * Kick off a delayed fund removal from an account.
20825
+ * Kick off a delayed recovery fund removal from an account.
20826
+ *
20827
+ * Use this only as a trustless fallback when the normal spend flow is
20828
+ * unavailable. For day-to-day movement out of a Unified Balance, use
20829
+ * `spend`.
20780
20830
  *
20781
20831
  * @param params - The account owner's adapter context, amount, and
20782
20832
  * optional token type.
@@ -20790,7 +20840,12 @@ const removeFundParamsSchema = z.object({
20790
20840
  });
20791
20841
  }
20792
20842
  /**
20793
- * Complete a fund removal once the activation period has passed.
20843
+ * Complete a recovery fund removal once the 7-day withdrawal delay has
20844
+ * passed.
20845
+ *
20846
+ * Use this only as a trustless fallback when the normal spend flow is
20847
+ * unavailable. For day-to-day movement out of a Unified Balance, use
20848
+ * `spend`.
20794
20849
  *
20795
20850
  * @param params - The account owner context matching the original
20796
20851
  * fund removal initiation.
@@ -20917,6 +20972,11 @@ registerKit(`${pkg.name}/${pkg.version}`);
20917
20972
  * Internally holds a persistent {@link UnifiedBalanceKit} instance so that
20918
20973
  * event dispatchers and custom fee policies are preserved across calls.
20919
20974
  *
20975
+ * Use {@link AppKitUnifiedBalance.spend} for normal movement out of a Unified
20976
+ * Balance. {@link AppKitUnifiedBalance.removeFund} is a trustless recovery path
20977
+ * for situations where the normal spend flow is unavailable, and it requires a
20978
+ * 7-day withdrawal delay after {@link AppKitUnifiedBalance.initiateRemoveFund}.
20979
+ *
20920
20980
  * @example
20921
20981
  * ```typescript
20922
20982
  * import { AppKit } from '@circle-fin/app-kit'
@@ -21128,7 +21188,12 @@ registerKit(`${pkg.name}/${pkg.version}`);
21128
21188
  return this.kit.removeDelegate(params);
21129
21189
  }
21130
21190
  /**
21131
- * Kick off a delayed fund removal from an account.
21191
+ * Initiate a trustless recovery removal from an account.
21192
+ *
21193
+ * Use `spend` for normal movement out of a Unified Balance. `removeFund` is a
21194
+ * recovery path for situations where the normal spend flow is unavailable.
21195
+ * Calling this method starts the 7-day withdrawal delay before the removal can
21196
+ * be completed.
21132
21197
  *
21133
21198
  * @param params - The account owner's adapter context, amount, and token.
21134
21199
  * @returns Promise resolving to the initiation details.
@@ -21147,11 +21212,16 @@ registerKit(`${pkg.name}/${pkg.version}`);
21147
21212
  return this.kit.initiateRemoveFund(params);
21148
21213
  }
21149
21214
  /**
21150
- * Complete a fund removal once the activation period has passed.
21215
+ * Complete a trustless recovery removal after the withdrawal delay.
21216
+ *
21217
+ * Use `spend` for normal movement out of a Unified Balance. `removeFund` is a
21218
+ * recovery path for situations where the normal spend flow is unavailable.
21219
+ * Both EVM and Solana removals require a 7-day withdrawal delay after
21220
+ * `initiateRemoveFund` before funds can be removed.
21151
21221
  *
21152
21222
  * @param params - The account owner context matching the original initiation.
21153
21223
  * @returns Promise resolving to the fund removal details.
21154
- * @throws {KitError} If the activation period has not elapsed or the
21224
+ * @throws {KitError} If the withdrawal delay has not elapsed or the
21155
21225
  * on-chain transaction fails.
21156
21226
  *
21157
21227
  * @example