@exodus/bitcoin-api 4.14.3 → 4.14.5

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/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.14.5](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.14.4...@exodus/bitcoin-api@4.14.5) (2026-04-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix: enforce fetch timeouts in insight and mempool clients (#7854)
13
+
14
+
15
+
16
+ ## [4.14.4](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.14.3...@exodus/bitcoin-api@4.14.4) (2026-04-23)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+
22
+ * fix: append valid path for btc mempool websocket url (#7851)
23
+
24
+
25
+
6
26
  ## [4.14.3](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.14.2...@exodus/bitcoin-api@4.14.3) (2026-04-15)
7
27
 
8
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "4.14.3",
3
+ "version": "4.14.5",
4
4
  "description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -63,5 +63,5 @@
63
63
  "type": "git",
64
64
  "url": "git+https://github.com/ExodusMovement/assets.git"
65
65
  },
66
- "gitHead": "166b906440f92ef09d2f2563fec9d9a365a81015"
66
+ "gitHead": "c420214d58816a0f5aa682822b066309d796fe30"
67
67
  }
@@ -0,0 +1,34 @@
1
+ const isPositiveTimeout = (timeout) => Number.isFinite(timeout) && timeout > 0
2
+
3
+ export default async function fetchWithTimeout(url, fetchOptions) {
4
+ const { timeout, signal, ...restFetchOptions } = fetchOptions || Object.create(null)
5
+ const hasFetchOptions = signal !== undefined || Object.keys(restFetchOptions).length > 0
6
+ const normalizedFetchOptions = hasFetchOptions
7
+ ? signal
8
+ ? { ...restFetchOptions, signal }
9
+ : restFetchOptions
10
+ : undefined
11
+
12
+ if (!isPositiveTimeout(timeout) || typeof AbortController !== 'function') {
13
+ return fetch(url, normalizedFetchOptions)
14
+ }
15
+
16
+ const controller = new AbortController()
17
+ const abort = () => controller.abort()
18
+ const timeoutId = setTimeout(abort, timeout)
19
+
20
+ if (signal) {
21
+ if (signal.aborted) {
22
+ abort()
23
+ } else {
24
+ signal.addEventListener('abort', abort, { once: true })
25
+ }
26
+ }
27
+
28
+ try {
29
+ return await fetch(url, { ...restFetchOptions, signal: controller.signal })
30
+ } finally {
31
+ clearTimeout(timeoutId)
32
+ signal?.removeEventListener?.('abort', abort)
33
+ }
34
+ }
@@ -5,6 +5,8 @@ import delay from 'delay'
5
5
  import lodash from 'lodash'
6
6
  import urlJoin from 'url-join'
7
7
 
8
+ import fetchWithTimeout from './fetch-with-timeout.js'
9
+
8
10
  const { isEmpty } = lodash
9
11
 
10
12
  const INSIGHT_HTTP_ERROR_MESSAGE = safeString`insight-api-http-error`
@@ -40,7 +42,7 @@ const fetchJson = async (
40
42
  nullWhen404,
41
43
  httpErrorMessage = INSIGHT_HTTP_ERROR_MESSAGE
42
44
  ) => {
43
- const response = await fetch(url, fetchOptions)
45
+ const response = await fetchWithTimeout(url, fetchOptions)
44
46
 
45
47
  if (nullWhen404 && response.status === 404) {
46
48
  return null
@@ -4,6 +4,8 @@ import { TraceId } from '@exodus/traceparent'
4
4
  import delay from 'delay'
5
5
  import urlJoin from 'url-join'
6
6
 
7
+ import fetchWithTimeout from './fetch-with-timeout.js'
8
+
7
9
  const API_PAGE_SIZE = 25
8
10
  const DEFAULT_PAGE_SIZE = 10
9
11
  const RETRY_WAIT_TIMES = ['5s', '10s', '20s', '30s']
@@ -109,7 +111,7 @@ async function withRetry(fn, args = [], { waitTimes = RETRY_WAIT_TIMES } = {}) {
109
111
  }
110
112
 
111
113
  async function fetchJson(url, fetchOptions, { nullWhen404 = false, httpErrorMessage } = {}) {
112
- const response = await fetch(url, fetchOptions)
114
+ const response = await fetchWithTimeout(url, fetchOptions)
113
115
  if (nullWhen404 && response.status === 404) {
114
116
  return null
115
117
  }
@@ -132,7 +134,7 @@ async function fetchJson(url, fetchOptions, { nullWhen404 = false, httpErrorMess
132
134
  }
133
135
 
134
136
  async function fetchText(url, fetchOptions, { nullWhen404 = false, httpErrorMessage } = {}) {
135
- const response = await fetch(url, fetchOptions)
137
+ const response = await fetchWithTimeout(url, fetchOptions)
136
138
  if (nullWhen404 && response.status === 404) {
137
139
  return null
138
140
  }
@@ -80,12 +80,12 @@ export function orderTxs(txs) {
80
80
  }
81
81
 
82
82
  /**
83
- * It concerts an api URL to a WS service URL.
83
+ * Strips a service URL down to its origin while preserving the scheme.
84
84
  *
85
85
  * https://somebtc.a.exodus.io/insight/ => https://somebtc.a.exodus.io
86
86
  *
87
87
  * @param {string} apiUrl the original apiUrl
88
- * @returns {string} a WS url without the paths.
88
+ * @returns {string} a service origin URL.
89
89
  */
90
90
  export function toWSUrl(apiUrl) {
91
91
  if (!apiUrl) {
@@ -106,12 +106,21 @@ export function toWSUrl(apiUrl) {
106
106
  }
107
107
  }
108
108
 
109
+ export function toMempoolWebSocketUrl(apiUrl) {
110
+ const wsUrl = toWSUrl(apiUrl)
111
+ if (typeof wsUrl !== 'string') {
112
+ return wsUrl
113
+ }
114
+
115
+ return `${wsUrl}/api/v1/ws`
116
+ }
117
+
109
118
  export function normalizeInsightConfig(config, monitorType) {
110
119
  const apiUrl = config?.insightServers?.[0]
111
120
  const mempoolApiUrl = config?.mempoolServer
112
121
  const wsUrl =
113
122
  monitorType === 'mempool'
114
- ? config?.mempoolServerWS || toWSUrl(mempoolApiUrl)
123
+ ? config?.mempoolServerWS || toMempoolWebSocketUrl(mempoolApiUrl)
115
124
  : config?.insightServersWS?.[0] || toWSUrl(apiUrl)
116
125
  return { apiUrl, mempoolApiUrl, wsUrl }
117
126
  }
@@ -5,7 +5,11 @@ import assert from 'minimalistic-assert'
5
5
  import ms from 'ms'
6
6
 
7
7
  import MempoolWSClient from '../insight-api-client/mempool-ws-client.js'
8
- import { normalizeInsightConfig, toWSUrl } from '../insight-api-client/util.js'
8
+ import {
9
+ normalizeInsightConfig,
10
+ toMempoolWebSocketUrl,
11
+ toWSUrl,
12
+ } from '../insight-api-client/util.js'
9
13
  import InsightWSClient from '../insight-api-client/ws.js'
10
14
  import { resolveUnconfirmedAncestorData } from '../unconfirmed-ancestor-data.js'
11
15
  import { BitcoinMonitorScanner } from './bitcoin-monitor-scanner.js'
@@ -103,7 +107,9 @@ export class Monitor extends BaseMonitor {
103
107
  this.#connectWS(
104
108
  wsUrl ||
105
109
  this.#wsUrl ||
106
- toWSUrl(this.#monitorType === 'mempool' ? this.#mempoolApiUrl : this.#apiUrl)
110
+ (this.#monitorType === 'mempool'
111
+ ? toMempoolWebSocketUrl(this.#mempoolApiUrl)
112
+ : toWSUrl(this.#apiUrl))
107
113
  )
108
114
  }
109
115
  }