@chainlink/ccip-sdk 0.91.0 → 0.92.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 +127 -80
- package/dist/aptos/hasher.d.ts.map +1 -1
- package/dist/aptos/hasher.js +7 -6
- package/dist/aptos/hasher.js.map +1 -1
- package/dist/aptos/index.d.ts +7 -2
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +29 -20
- package/dist/aptos/index.js.map +1 -1
- package/dist/aptos/logs.d.ts +5 -3
- package/dist/aptos/logs.d.ts.map +1 -1
- package/dist/aptos/logs.js +64 -27
- package/dist/aptos/logs.js.map +1 -1
- package/dist/aptos/token.d.ts.map +1 -1
- package/dist/aptos/token.js +2 -1
- package/dist/aptos/token.js.map +1 -1
- package/dist/aptos/types.js +6 -6
- package/dist/aptos/types.js.map +1 -1
- package/dist/chain.d.ts +36 -11
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +34 -2
- package/dist/chain.js.map +1 -1
- package/dist/commits.d.ts +2 -3
- package/dist/commits.d.ts.map +1 -1
- package/dist/commits.js +19 -8
- package/dist/commits.js.map +1 -1
- package/dist/errors/CCIPError.d.ts +48 -0
- package/dist/errors/CCIPError.d.ts.map +1 -0
- package/dist/errors/CCIPError.js +65 -0
- package/dist/errors/CCIPError.js.map +1 -0
- package/dist/errors/codes.d.ts +120 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/codes.js +156 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/errors/index.d.ts +26 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +51 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/recovery.d.ts +6 -0
- package/dist/errors/recovery.d.ts.map +1 -0
- package/dist/errors/recovery.js +118 -0
- package/dist/errors/recovery.js.map +1 -0
- package/dist/errors/specialized.d.ts +637 -0
- package/dist/errors/specialized.d.ts.map +1 -0
- package/dist/errors/specialized.js +1298 -0
- package/dist/errors/specialized.js.map +1 -0
- package/dist/errors/utils.d.ts +11 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +61 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/evm/abi/CommitStore_1_5.js +1 -1
- package/dist/evm/abi/LockReleaseTokenPool_1_5.js +1 -1
- package/dist/evm/abi/OffRamp_1_5.js +1 -1
- package/dist/evm/abi/OnRamp_1_5.js +1 -1
- package/dist/evm/abi/PriceRegistry_1_2.d.ts +443 -0
- package/dist/evm/abi/PriceRegistry_1_2.d.ts.map +1 -0
- package/dist/evm/abi/PriceRegistry_1_2.js +439 -0
- package/dist/evm/abi/PriceRegistry_1_2.js.map +1 -0
- package/dist/evm/const.d.ts +1 -0
- package/dist/evm/const.d.ts.map +1 -1
- package/dist/evm/const.js +2 -0
- package/dist/evm/const.js.map +1 -1
- package/dist/evm/hasher.d.ts.map +1 -1
- package/dist/evm/hasher.js +7 -6
- package/dist/evm/hasher.js.map +1 -1
- package/dist/evm/index.d.ts +9 -13
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +85 -68
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/logs.d.ts.map +1 -1
- package/dist/evm/logs.js +47 -16
- package/dist/evm/logs.js.map +1 -1
- package/dist/evm/messages.d.ts +7 -6
- package/dist/evm/messages.d.ts.map +1 -1
- package/dist/evm/offchain.js +1 -1
- package/dist/evm/offchain.js.map +1 -1
- package/dist/evm/types.d.ts +10 -0
- package/dist/evm/types.d.ts.map +1 -0
- package/dist/evm/types.js +2 -0
- package/dist/evm/types.js.map +1 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +9 -5
- package/dist/execution.js.map +1 -1
- package/dist/extra-args.d.ts.map +1 -1
- package/dist/extra-args.js +4 -3
- package/dist/extra-args.js.map +1 -1
- package/dist/gas.d.ts.map +1 -1
- package/dist/gas.js +3 -2
- package/dist/gas.js.map +1 -1
- package/dist/hasher/hasher.d.ts.map +1 -1
- package/dist/hasher/hasher.js +2 -1
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/merklemulti.d.ts.map +1 -1
- package/dist/hasher/merklemulti.js +9 -8
- package/dist/hasher/merklemulti.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/offchain.d.ts.map +1 -1
- package/dist/offchain.js +5 -8
- package/dist/offchain.js.map +1 -1
- package/dist/requests.d.ts +1 -1
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +37 -43
- package/dist/requests.js.map +1 -1
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +22 -0
- package/dist/selectors.js.map +1 -1
- package/dist/solana/cleanup.d.ts +2 -2
- package/dist/solana/cleanup.d.ts.map +1 -1
- package/dist/solana/cleanup.js +2 -3
- package/dist/solana/cleanup.js.map +1 -1
- package/dist/solana/exec.d.ts.map +1 -1
- package/dist/solana/exec.js +12 -12
- package/dist/solana/exec.js.map +1 -1
- package/dist/solana/hasher.d.ts.map +1 -1
- package/dist/solana/hasher.js +6 -5
- package/dist/solana/hasher.js.map +1 -1
- package/dist/solana/index.d.ts +30 -13
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +96 -143
- package/dist/solana/index.js.map +1 -1
- package/dist/solana/logs.d.ts +15 -0
- package/dist/solana/logs.d.ts.map +1 -0
- package/dist/solana/logs.js +106 -0
- package/dist/solana/logs.js.map +1 -0
- package/dist/solana/offchain.d.ts.map +1 -1
- package/dist/solana/offchain.js +6 -5
- package/dist/solana/offchain.js.map +1 -1
- package/dist/solana/patchBorsh.d.ts.map +1 -1
- package/dist/solana/patchBorsh.js +3 -2
- package/dist/solana/patchBorsh.js.map +1 -1
- package/dist/solana/send.d.ts.map +1 -1
- package/dist/solana/send.js +8 -7
- package/dist/solana/send.js.map +1 -1
- package/dist/solana/utils.d.ts +7 -8
- package/dist/solana/utils.d.ts.map +1 -1
- package/dist/solana/utils.js +23 -11
- package/dist/solana/utils.js.map +1 -1
- package/dist/sui/discovery.d.ts +18 -0
- package/dist/sui/discovery.d.ts.map +1 -0
- package/dist/sui/discovery.js +116 -0
- package/dist/sui/discovery.js.map +1 -0
- package/dist/sui/events.d.ts +36 -0
- package/dist/sui/events.d.ts.map +1 -0
- package/dist/sui/events.js +179 -0
- package/dist/sui/events.js.map +1 -0
- package/dist/sui/hasher.d.ts.map +1 -1
- package/dist/sui/hasher.js +6 -5
- package/dist/sui/hasher.js.map +1 -1
- package/dist/sui/index.d.ts +69 -41
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +402 -65
- package/dist/sui/index.js.map +1 -1
- package/dist/sui/manuallyExec/encoder.d.ts +8 -0
- package/dist/sui/manuallyExec/encoder.d.ts.map +1 -0
- package/dist/sui/manuallyExec/encoder.js +76 -0
- package/dist/sui/manuallyExec/encoder.js.map +1 -0
- package/dist/sui/manuallyExec/index.d.ts +37 -0
- package/dist/sui/manuallyExec/index.d.ts.map +1 -0
- package/dist/sui/manuallyExec/index.js +81 -0
- package/dist/sui/manuallyExec/index.js.map +1 -0
- package/dist/sui/objects.d.ts +46 -0
- package/dist/sui/objects.d.ts.map +1 -0
- package/dist/sui/objects.js +259 -0
- package/dist/sui/objects.js.map +1 -0
- package/dist/ton/bindings/offramp.d.ts +48 -0
- package/dist/ton/bindings/offramp.d.ts.map +1 -0
- package/dist/ton/bindings/offramp.js +63 -0
- package/dist/ton/bindings/offramp.js.map +1 -0
- package/dist/ton/bindings/onramp.d.ts +40 -0
- package/dist/ton/bindings/onramp.d.ts.map +1 -0
- package/dist/ton/bindings/onramp.js +51 -0
- package/dist/ton/bindings/onramp.js.map +1 -0
- package/dist/ton/bindings/router.d.ts +47 -0
- package/dist/ton/bindings/router.d.ts.map +1 -0
- package/dist/ton/bindings/router.js +51 -0
- package/dist/ton/bindings/router.js.map +1 -0
- package/dist/ton/exec.d.ts +18 -0
- package/dist/ton/exec.d.ts.map +1 -0
- package/dist/ton/exec.js +28 -0
- package/dist/ton/exec.js.map +1 -0
- package/dist/ton/hasher.d.ts +27 -0
- package/dist/ton/hasher.d.ts.map +1 -0
- package/dist/ton/hasher.js +134 -0
- package/dist/ton/hasher.js.map +1 -0
- package/dist/ton/index.d.ts +247 -0
- package/dist/ton/index.d.ts.map +1 -0
- package/dist/ton/index.js +781 -0
- package/dist/ton/index.js.map +1 -0
- package/dist/ton/logs.d.ts +26 -0
- package/dist/ton/logs.d.ts.map +1 -0
- package/dist/ton/logs.js +126 -0
- package/dist/ton/logs.js.map +1 -0
- package/dist/ton/types.d.ts +37 -0
- package/dist/ton/types.d.ts.map +1 -0
- package/dist/ton/types.js +92 -0
- package/dist/ton/types.js.map +1 -0
- package/dist/ton/utils.d.ts +67 -0
- package/dist/ton/utils.d.ts.map +1 -0
- package/dist/ton/utils.js +425 -0
- package/dist/ton/utils.js.map +1 -0
- package/dist/types.d.ts +4 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +52 -17
- package/dist/utils.js.map +1 -1
- package/package.json +12 -10
- package/src/aptos/hasher.ts +10 -6
- package/src/aptos/index.ts +50 -31
- package/src/aptos/logs.ts +85 -29
- package/src/aptos/token.ts +5 -1
- package/src/aptos/types.ts +6 -6
- package/src/chain.ts +83 -12
- package/src/commits.ts +23 -11
- package/src/errors/CCIPError.ts +86 -0
- package/src/errors/codes.ts +179 -0
- package/src/errors/index.ts +175 -0
- package/src/errors/recovery.ts +170 -0
- package/src/errors/specialized.ts +1655 -0
- package/src/errors/utils.ts +73 -0
- package/src/evm/abi/CommitStore_1_5.ts +1 -1
- package/src/evm/abi/LockReleaseTokenPool_1_5.ts +1 -1
- package/src/evm/abi/OffRamp_1_5.ts +1 -1
- package/src/evm/abi/OnRamp_1_5.ts +1 -1
- package/src/evm/abi/PriceRegistry_1_2.ts +438 -0
- package/src/evm/const.ts +2 -0
- package/src/evm/hasher.ts +7 -6
- package/src/evm/index.ts +104 -86
- package/src/evm/logs.ts +64 -16
- package/src/evm/messages.ts +14 -14
- package/src/evm/offchain.ts +1 -1
- package/src/evm/types.ts +11 -0
- package/src/execution.ts +13 -9
- package/src/extra-args.ts +4 -3
- package/src/gas.ts +10 -3
- package/src/hasher/hasher.ts +2 -1
- package/src/hasher/merklemulti.ts +18 -8
- package/src/index.ts +14 -2
- package/src/offchain.ts +10 -14
- package/src/requests.ts +51 -53
- package/src/selectors.ts +23 -0
- package/src/solana/cleanup.ts +2 -4
- package/src/solana/exec.ts +13 -13
- package/src/solana/hasher.ts +9 -5
- package/src/solana/index.ts +126 -200
- package/src/solana/logs.ts +155 -0
- package/src/solana/offchain.ts +10 -7
- package/src/solana/patchBorsh.ts +3 -2
- package/src/solana/send.ts +14 -7
- package/src/solana/utils.ts +31 -17
- package/src/sui/discovery.ts +163 -0
- package/src/sui/events.ts +328 -0
- package/src/sui/hasher.ts +6 -5
- package/src/sui/index.ts +528 -80
- package/src/sui/manuallyExec/encoder.ts +88 -0
- package/src/sui/manuallyExec/index.ts +137 -0
- package/src/sui/objects.ts +358 -0
- package/src/ton/bindings/offramp.ts +96 -0
- package/src/ton/bindings/onramp.ts +72 -0
- package/src/ton/bindings/router.ts +65 -0
- package/src/ton/exec.ts +44 -0
- package/src/ton/hasher.ts +184 -0
- package/src/ton/index.ts +989 -0
- package/src/ton/logs.ts +157 -0
- package/src/ton/types.ts +143 -0
- package/src/ton/utils.ts +514 -0
- package/src/types.ts +6 -2
- package/src/utils.ts +58 -23
- package/tsconfig.json +2 -1
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer'
|
|
2
|
-
|
|
3
1
|
import bs58 from 'bs58'
|
|
4
2
|
import {
|
|
5
3
|
type BigNumberish,
|
|
@@ -13,7 +11,16 @@ import {
|
|
|
13
11
|
} from 'ethers'
|
|
14
12
|
import { memoize } from 'micro-memoize'
|
|
15
13
|
|
|
16
|
-
import type { Chain } from './chain.ts'
|
|
14
|
+
import type { Chain, ChainStatic } from './chain.ts'
|
|
15
|
+
import {
|
|
16
|
+
CCIPBlockBeforeTimestampNotFoundError,
|
|
17
|
+
CCIPChainFamilyUnsupportedError,
|
|
18
|
+
CCIPChainNotFoundError,
|
|
19
|
+
CCIPDataFormatUnsupportedError,
|
|
20
|
+
CCIPError,
|
|
21
|
+
CCIPHttpError,
|
|
22
|
+
CCIPTypeVersionInvalidError,
|
|
23
|
+
} from './errors/index.ts'
|
|
17
24
|
import SELECTORS from './selectors.ts'
|
|
18
25
|
import { supportedChains } from './supported-chains.ts'
|
|
19
26
|
import { type NetworkInfo, type WithLogger, ChainFamily } from './types.ts'
|
|
@@ -55,7 +62,7 @@ export async function getSomeBlockNumberBefore(
|
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
if (beforeTimestamp > timestamp) {
|
|
58
|
-
throw new
|
|
65
|
+
throw new CCIPBlockBeforeTimestampNotFoundError(timestamp)
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
// now, bin-search based on timestamp proportions, looking for
|
|
@@ -96,7 +103,7 @@ export async function getSomeBlockNumberBefore(
|
|
|
96
103
|
// memoized so we always output the same object for a given chainId
|
|
97
104
|
const networkInfoFromChainId = memoize((chainId: NetworkInfo['chainId']): NetworkInfo => {
|
|
98
105
|
const sel = SELECTORS[chainId]
|
|
99
|
-
if (!sel?.name) throw new
|
|
106
|
+
if (!sel?.name) throw new CCIPChainNotFoundError(chainId)
|
|
100
107
|
return {
|
|
101
108
|
chainId: isNaN(+chainId) ? chainId : +chainId,
|
|
102
109
|
chainSelector: sel.selector,
|
|
@@ -118,14 +125,17 @@ const networkInfoFromChainId = memoize((chainId: NetworkInfo['chainId']): Networ
|
|
|
118
125
|
export const networkInfo = memoize(function networkInfo_(
|
|
119
126
|
selectorOrIdOrName: bigint | number | string,
|
|
120
127
|
): NetworkInfo {
|
|
121
|
-
let chainId
|
|
128
|
+
let chainId, match
|
|
122
129
|
if (typeof selectorOrIdOrName === 'number') {
|
|
123
130
|
chainId = selectorOrIdOrName
|
|
124
|
-
} else if (
|
|
125
|
-
selectorOrIdOrName
|
|
131
|
+
} else if (
|
|
132
|
+
typeof selectorOrIdOrName === 'string' &&
|
|
133
|
+
(match = selectorOrIdOrName.match(/^(-?\d+)n?$/))
|
|
134
|
+
) {
|
|
135
|
+
selectorOrIdOrName = BigInt(match[1])
|
|
126
136
|
}
|
|
127
137
|
if (typeof selectorOrIdOrName === 'bigint') {
|
|
128
|
-
// maybe we got a
|
|
138
|
+
// maybe we got a chainId deserialized as bigint
|
|
129
139
|
if (selectorOrIdOrName.toString() in SELECTORS) {
|
|
130
140
|
chainId = Number(selectorOrIdOrName)
|
|
131
141
|
} else {
|
|
@@ -135,10 +145,10 @@ export const networkInfo = memoize(function networkInfo_(
|
|
|
135
145
|
break
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
|
-
if (!chainId) throw new
|
|
148
|
+
if (!chainId) throw new CCIPChainNotFoundError(selectorOrIdOrName)
|
|
139
149
|
}
|
|
140
150
|
} else if (typeof selectorOrIdOrName === 'string') {
|
|
141
|
-
if (selectorOrIdOrName.includes('-')) {
|
|
151
|
+
if (selectorOrIdOrName.includes('-', 1)) {
|
|
142
152
|
for (const id in SELECTORS) {
|
|
143
153
|
if (SELECTORS[id].name === selectorOrIdOrName) {
|
|
144
154
|
chainId = id
|
|
@@ -212,10 +222,28 @@ export function bigIntReviver(_key: string, value: unknown): unknown {
|
|
|
212
222
|
**/
|
|
213
223
|
export function decodeAddress(address: BytesLike, family: ChainFamily = ChainFamily.EVM): string {
|
|
214
224
|
const chain = supportedChains[family]
|
|
215
|
-
if (!chain) throw new
|
|
225
|
+
if (!chain) throw new CCIPChainFamilyUnsupportedError(family)
|
|
216
226
|
return chain.getAddress(getAddressBytes(address))
|
|
217
227
|
}
|
|
218
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Validate a value is a txHash string in some supported chain family
|
|
231
|
+
**/
|
|
232
|
+
export function isSupportedTxHash(txHash: unknown, family?: ChainFamily): txHash is string {
|
|
233
|
+
let chains: ChainStatic[]
|
|
234
|
+
if (!family) chains = Object.values(supportedChains)
|
|
235
|
+
else if (family in supportedChains) chains = [supportedChains[family]!]
|
|
236
|
+
else throw new CCIPChainFamilyUnsupportedError(family)
|
|
237
|
+
for (const C of chains) {
|
|
238
|
+
try {
|
|
239
|
+
if (C.isTxHash(txHash)) return true
|
|
240
|
+
} catch (_) {
|
|
241
|
+
// continue
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return false
|
|
245
|
+
}
|
|
246
|
+
|
|
219
247
|
/**
|
|
220
248
|
* Version of decodeAddress which is aware of custom cross-chain OnRamp formats
|
|
221
249
|
**/
|
|
@@ -247,7 +275,6 @@ export function leToBigInt(data: BytesLike | readonly number[]): bigint {
|
|
|
247
275
|
export function toLeArray(value: BigNumberish, width?: Numeric): Uint8Array {
|
|
248
276
|
return toBeArray(value, width).reverse()
|
|
249
277
|
}
|
|
250
|
-
|
|
251
278
|
/**
|
|
252
279
|
* Checks if the given data is a valid Base64 encoded string.
|
|
253
280
|
* @param data - Data to check.
|
|
@@ -274,10 +301,19 @@ export function getDataBytes(data: BytesLike | readonly number[]): Uint8Array {
|
|
|
274
301
|
} else if (isBase64(data)) {
|
|
275
302
|
return decodeBase64(data)
|
|
276
303
|
} else {
|
|
277
|
-
throw new
|
|
304
|
+
throw new CCIPDataFormatUnsupportedError(util.inspect(data))
|
|
278
305
|
}
|
|
279
306
|
}
|
|
280
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Converts bytes to a Node.js Buffer.
|
|
310
|
+
* @param bytes - Bytes to convert (hex string, Uint8Array, Base64, etc).
|
|
311
|
+
* @returns Node.js Buffer.
|
|
312
|
+
*/
|
|
313
|
+
export function bytesToBuffer(bytes: BytesLike | readonly number[]): Buffer {
|
|
314
|
+
return Buffer.from(getDataBytes(bytes))
|
|
315
|
+
}
|
|
316
|
+
|
|
281
317
|
/**
|
|
282
318
|
* Extracts address bytes, handling both hex and Base58 formats.
|
|
283
319
|
* @param address - Address in hex or Base58 format.
|
|
@@ -349,10 +385,7 @@ export function parseTypeAndVersion(
|
|
|
349
385
|
typeAndVersion: string,
|
|
350
386
|
): Awaited<ReturnType<Chain['typeAndVersion']>> {
|
|
351
387
|
const match = typeAndVersion.match(/^(\w.+\S)\s+v?(\d+\.\d+(?:\.\d+)?)([^\d.].*)?$/)
|
|
352
|
-
if (!match)
|
|
353
|
-
throw new Error(
|
|
354
|
-
`Invalid typeAndVersion: "${typeAndVersion}", len=${typeAndVersion.length}, hex=0x${Buffer.from(typeAndVersion).toString('hex')}`,
|
|
355
|
-
)
|
|
388
|
+
if (!match) throw new CCIPTypeVersionInvalidError(typeAndVersion)
|
|
356
389
|
const [, typeRaw, version] = match
|
|
357
390
|
// some string normalization
|
|
358
391
|
const type = typeRaw
|
|
@@ -414,6 +447,7 @@ export function createRateLimitedFetch(
|
|
|
414
447
|
if (method && methodRateLimits[method]) {
|
|
415
448
|
while (isMethodRateLimited(method)) {
|
|
416
449
|
const oldestRequest = methodRateLimits[method].queue[0]
|
|
450
|
+
if (!oldestRequest) break // Queue was cleaned, no longer rate limited
|
|
417
451
|
const waitTime = windowMs - (Date.now() - oldestRequest.timestamp)
|
|
418
452
|
if (waitTime > 0) {
|
|
419
453
|
await sleep(waitTime + 100) // Add small buffer
|
|
@@ -424,6 +458,7 @@ export function createRateLimitedFetch(
|
|
|
424
458
|
// Wait for global rate limit
|
|
425
459
|
while (isRateLimited()) {
|
|
426
460
|
const oldestRequest = requestQueue[0]
|
|
461
|
+
if (!oldestRequest) break // Queue was cleaned, no longer rate limited
|
|
427
462
|
const waitTime = windowMs - (Date.now() - oldestRequest.timestamp)
|
|
428
463
|
if (waitTime > 0) {
|
|
429
464
|
await sleep(waitTime + 100) // Add small buffer
|
|
@@ -484,7 +519,7 @@ export function createRateLimitedFetch(
|
|
|
484
519
|
recordRequest(method)
|
|
485
520
|
// logger.debug('__fetching', input, init?.body)
|
|
486
521
|
|
|
487
|
-
const response = await fetch(input, init)
|
|
522
|
+
const response = await globalThis.fetch(input, init)
|
|
488
523
|
|
|
489
524
|
// Update method rate limits from response headers
|
|
490
525
|
updateMethodRateLimits(response, method)
|
|
@@ -497,15 +532,15 @@ export function createRateLimitedFetch(
|
|
|
497
532
|
|
|
498
533
|
// For 429 responses, throw an error to trigger retry
|
|
499
534
|
if (response.status === 429) {
|
|
500
|
-
throw new
|
|
535
|
+
throw new CCIPHttpError(response.status, response.statusText)
|
|
501
536
|
}
|
|
502
537
|
|
|
503
538
|
// For other non-2xx responses, don't retry
|
|
504
539
|
logger.debug('fetch non-retryable error', input, response.status, init?.body)
|
|
505
|
-
throw new
|
|
540
|
+
throw new CCIPHttpError(response.status, response.statusText)
|
|
506
541
|
} catch (error) {
|
|
507
542
|
logger.debug('fetch errored', attempt, error, input, init?.body)
|
|
508
|
-
lastError = error instanceof Error ? error :
|
|
543
|
+
lastError = error instanceof Error ? error : CCIPError.from(error, 'HTTP_ERROR')
|
|
509
544
|
|
|
510
545
|
// Only retry on rate limit errors
|
|
511
546
|
if (!isRateLimitError(lastError)) {
|
|
@@ -519,7 +554,7 @@ export function createRateLimitedFetch(
|
|
|
519
554
|
}
|
|
520
555
|
}
|
|
521
556
|
|
|
522
|
-
throw lastError ||
|
|
557
|
+
throw lastError || CCIPError.from('Request failed after all retries', 'HTTP_ERROR')
|
|
523
558
|
}
|
|
524
559
|
}
|
|
525
560
|
|