@0xtrails/api 0.6.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/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-test.log +5 -0
- package/.turbo/turbo-typecheck.log +5 -0
- package/CHANGELOG.md +219 -0
- package/LICENSE +202 -0
- package/README.md +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/trails-api.gen.d.ts +720 -0
- package/dist/trails-api.gen.d.ts.map +1 -0
- package/dist/trails-api.gen.js +1048 -0
- package/package.json +27 -0
- package/src/index.ts +46 -0
- package/src/trails-api.gen.ts +1620 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,1620 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// trails-api v1-25.11.17+822fb49 cb1f8c28a73c79a0ae2436bad0e1206f204bc835
|
|
3
|
+
// --
|
|
4
|
+
// Code generated by Webrpc-gen@v0.31.2 with typescript@v0.23.1 generator. DO NOT EDIT.
|
|
5
|
+
//
|
|
6
|
+
// webrpc-gen -schema=trails-api.ridl -target=typescript@v0.23.1 -client -out=./clients/trails-api.gen.ts
|
|
7
|
+
|
|
8
|
+
// Webrpc description and code-gen version
|
|
9
|
+
export const WebrpcVersion = 'v1'
|
|
10
|
+
|
|
11
|
+
// Schema version of your RIDL schema
|
|
12
|
+
export const WebrpcSchemaVersion = 'v1-25.11.17+822fb49'
|
|
13
|
+
|
|
14
|
+
// Schema hash generated from your RIDL schema
|
|
15
|
+
export const WebrpcSchemaHash = 'cb1f8c28a73c79a0ae2436bad0e1206f204bc835'
|
|
16
|
+
|
|
17
|
+
//
|
|
18
|
+
// Client interface
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
export interface TrailsClient {
|
|
22
|
+
ping(headers?: object, signal?: AbortSignal): Promise<PingResponse>
|
|
23
|
+
|
|
24
|
+
version(headers?: object, signal?: AbortSignal): Promise<VersionResponse>
|
|
25
|
+
|
|
26
|
+
runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse>
|
|
27
|
+
|
|
28
|
+
clock(headers?: object, signal?: AbortSignal): Promise<ClockResponse>
|
|
29
|
+
|
|
30
|
+
quoteIntent(req: QuoteIntentRequest, headers?: object, signal?: AbortSignal): Promise<QuoteIntentResponse>
|
|
31
|
+
|
|
32
|
+
commitIntent(req: CommitIntentRequest, headers?: object, signal?: AbortSignal): Promise<CommitIntentResponse>
|
|
33
|
+
|
|
34
|
+
executeIntent(req: ExecuteIntentRequest, headers?: object, signal?: AbortSignal): Promise<ExecuteIntentResponse>
|
|
35
|
+
|
|
36
|
+
waitIntentReceipt(req: WaitIntentReceiptRequest, headers?: object, signal?: AbortSignal): Promise<WaitIntentReceiptResponse>
|
|
37
|
+
|
|
38
|
+
getIntentReceipt(req: GetIntentReceiptRequest, headers?: object, signal?: AbortSignal): Promise<GetIntentReceiptResponse>
|
|
39
|
+
|
|
40
|
+
getIntent(req: GetIntentRequest, headers?: object, signal?: AbortSignal): Promise<GetIntentResponse>
|
|
41
|
+
|
|
42
|
+
searchIntents(req: SearchIntentsRequest, headers?: object, signal?: AbortSignal): Promise<SearchIntentsResponse>
|
|
43
|
+
|
|
44
|
+
getIntentTransactionHistory(
|
|
45
|
+
req: GetIntentTransactionHistoryRequest,
|
|
46
|
+
headers?: object,
|
|
47
|
+
signal?: AbortSignal
|
|
48
|
+
): Promise<GetIntentTransactionHistoryResponse>
|
|
49
|
+
|
|
50
|
+
getTokenPrices(req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//
|
|
54
|
+
// Schema types
|
|
55
|
+
//
|
|
56
|
+
|
|
57
|
+
export enum TradeType {
|
|
58
|
+
EXACT_INPUT = 'EXACT_INPUT',
|
|
59
|
+
EXACT_OUTPUT = 'EXACT_OUTPUT'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export enum QuoteProviderType {
|
|
63
|
+
RELAY = 'RELAY',
|
|
64
|
+
CCTPV2 = 'CCTPV2',
|
|
65
|
+
LIFI = 'LIFI'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export enum IntentStatus {
|
|
69
|
+
QUOTED = 'QUOTED',
|
|
70
|
+
COMMITTED = 'COMMITTED',
|
|
71
|
+
EXECUTING = 'EXECUTING',
|
|
72
|
+
FAILED = 'FAILED',
|
|
73
|
+
SUCCEEDED = 'SUCCEEDED'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export enum TransactionType {
|
|
77
|
+
UNKNOWN = 'UNKNOWN',
|
|
78
|
+
DEPOSIT = 'DEPOSIT',
|
|
79
|
+
ORIGIN = 'ORIGIN',
|
|
80
|
+
DESTINATION = 'DESTINATION',
|
|
81
|
+
ROUTE = 'ROUTE'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export enum TransactionContext {
|
|
85
|
+
NONE = 'NONE',
|
|
86
|
+
CCTPV2_MESSAGE = 'CCTPV2_MESSAGE'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export enum TransactionStatus {
|
|
90
|
+
UNKNOWN = 'UNKNOWN',
|
|
91
|
+
ON_HOLD = 'ON_HOLD',
|
|
92
|
+
PENDING = 'PENDING',
|
|
93
|
+
RELAYING = 'RELAYING',
|
|
94
|
+
SENT = 'SENT',
|
|
95
|
+
ERRORED = 'ERRORED',
|
|
96
|
+
MINING = 'MINING',
|
|
97
|
+
SUCCEEDED = 'SUCCEEDED',
|
|
98
|
+
FAILED = 'FAILED',
|
|
99
|
+
ABORTED = 'ABORTED'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export enum ChainGasUsageStatus {
|
|
103
|
+
NORMAL = 'NORMAL',
|
|
104
|
+
BUSY = 'BUSY',
|
|
105
|
+
VERY_BUSY = 'VERY_BUSY'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface QuoteIntentRequest {
|
|
109
|
+
ownerAddress: string
|
|
110
|
+
originChainId: number
|
|
111
|
+
originTokenAddress: string
|
|
112
|
+
destinationChainId: number
|
|
113
|
+
destinationTokenAddress: string
|
|
114
|
+
destinationToAddress?: string
|
|
115
|
+
destinationCallData?: string
|
|
116
|
+
destinationCallValue?: bigint
|
|
117
|
+
originTokenAmount?: bigint
|
|
118
|
+
destinationTokenAmount?: bigint
|
|
119
|
+
tradeType?: TradeType
|
|
120
|
+
onlyNativeGasFee?: boolean
|
|
121
|
+
options?: QuoteIntentRequestOptions
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface QuoteIntentRequestOptions {
|
|
125
|
+
quoteProvider?: string
|
|
126
|
+
slippageTolerance?: number
|
|
127
|
+
trailsAddressOverrides?: TrailsAddressOverrides
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface Intent {
|
|
131
|
+
intentId: string
|
|
132
|
+
status: IntentStatus
|
|
133
|
+
quoteRequest: QuoteIntentRequest
|
|
134
|
+
ownerAddress: string
|
|
135
|
+
originChainId: number
|
|
136
|
+
destinationChainId: number
|
|
137
|
+
originIntentAddress: string
|
|
138
|
+
destinationIntentAddress?: string
|
|
139
|
+
salt: bigint
|
|
140
|
+
depositTransaction: DepositTransaction
|
|
141
|
+
originCalls: IntentCalls
|
|
142
|
+
destinationCalls?: IntentCalls
|
|
143
|
+
originPrecondition: TransactionPrecondition
|
|
144
|
+
destinationPrecondition?: TransactionPrecondition
|
|
145
|
+
originMetaTxn: MetaTxn
|
|
146
|
+
destinationMetaTxn?: MetaTxn
|
|
147
|
+
quote: IntentProviderQuote
|
|
148
|
+
fees: IntentFees
|
|
149
|
+
trailsVersion: string
|
|
150
|
+
expiresAt: string
|
|
151
|
+
updatedAt?: string
|
|
152
|
+
createdAt?: string
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface DepositTransaction {
|
|
156
|
+
toAddress: string
|
|
157
|
+
tokenAddress: string
|
|
158
|
+
decimals?: number
|
|
159
|
+
amount: bigint
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface IntentCalls {
|
|
163
|
+
chainId: number
|
|
164
|
+
space?: bigint
|
|
165
|
+
nonce?: bigint
|
|
166
|
+
calls: Array<TransactionCall>
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface TransactionCall {
|
|
170
|
+
to: string
|
|
171
|
+
value?: bigint
|
|
172
|
+
data?: string
|
|
173
|
+
gasLimit?: bigint
|
|
174
|
+
delegateCall?: boolean
|
|
175
|
+
onlyFallback?: boolean
|
|
176
|
+
behaviorOnError?: number
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface TransactionPrecondition {
|
|
180
|
+
type: string
|
|
181
|
+
chainId: number
|
|
182
|
+
ownerAddress: string
|
|
183
|
+
tokenAddress: string
|
|
184
|
+
minAmount: bigint
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface MetaTxn {
|
|
188
|
+
id: string
|
|
189
|
+
chainId: number
|
|
190
|
+
walletAddress: string
|
|
191
|
+
contract: string
|
|
192
|
+
input: string
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface IntentReceipt {
|
|
196
|
+
intentId: string
|
|
197
|
+
status: IntentStatus
|
|
198
|
+
ownerAddress: string
|
|
199
|
+
originChainId: number
|
|
200
|
+
destinationChainId: number
|
|
201
|
+
depositTransaction: IntentTransaction
|
|
202
|
+
originTransaction: IntentTransaction
|
|
203
|
+
destinationTransaction?: IntentTransaction
|
|
204
|
+
updatedAt?: string
|
|
205
|
+
createdAt?: string
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface IntentTransaction {
|
|
209
|
+
intentId: string
|
|
210
|
+
chainId: number
|
|
211
|
+
type: TransactionType
|
|
212
|
+
context: TransactionContext
|
|
213
|
+
fromAddress: string
|
|
214
|
+
toAddress: string
|
|
215
|
+
tokenAddress: string
|
|
216
|
+
tokenAmount: bigint
|
|
217
|
+
metaTxnId?: string
|
|
218
|
+
metaTxnFeeQuote?: string
|
|
219
|
+
precondition?: TransactionPrecondition
|
|
220
|
+
depositIntentEntry?: DepositIntentEntry
|
|
221
|
+
txnHash?: string
|
|
222
|
+
txnMinedAt?: string
|
|
223
|
+
status: TransactionStatus
|
|
224
|
+
statusReason?: string
|
|
225
|
+
updatedAt?: string
|
|
226
|
+
createdAt?: string
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface IntentProviderQuote {
|
|
230
|
+
quoteProvider: string
|
|
231
|
+
quoteProviderRequestId: string
|
|
232
|
+
quoteProviderFeeUsd: number
|
|
233
|
+
fromAmount: bigint
|
|
234
|
+
fromAmountMin: bigint
|
|
235
|
+
toAmount: bigint
|
|
236
|
+
toAmountMin: bigint
|
|
237
|
+
maxSlippage: number
|
|
238
|
+
priceImpact: number
|
|
239
|
+
priceImpactUsd: number
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface IntentFees {
|
|
243
|
+
originGas: IntentTransactionGasFee
|
|
244
|
+
destinationGas?: IntentTransactionGasFee
|
|
245
|
+
provider: IntentProviderFees
|
|
246
|
+
feeTokenAddress: string
|
|
247
|
+
feeTokenTotal: bigint
|
|
248
|
+
totalFeeAmount: bigint
|
|
249
|
+
totalFeeUsd: number
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface IntentProviderFees {
|
|
253
|
+
quoteProvider: string
|
|
254
|
+
quoteProviderFee: bigint
|
|
255
|
+
quoteProviderFeeUsd: number
|
|
256
|
+
trailsFee: bigint
|
|
257
|
+
trailsFeeUsd: number
|
|
258
|
+
totalFeeAmount: bigint
|
|
259
|
+
totalFeeUsd: number
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface IntentTransactionGasFee {
|
|
263
|
+
chainId: number
|
|
264
|
+
totalGasLimit: bigint
|
|
265
|
+
gasPrice: bigint
|
|
266
|
+
nativeTokenSymbol: string
|
|
267
|
+
nativeTokenPriceUsd?: number
|
|
268
|
+
chainGasUsageStatus: ChainGasUsageStatus
|
|
269
|
+
totalFeeAmount: bigint
|
|
270
|
+
totalFeeUsd: string
|
|
271
|
+
metaTxnFeeDetails: MetaTxnFeeDetails
|
|
272
|
+
metaTxnGasQuote: string
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface MetaTxnFeeDetails {
|
|
276
|
+
metaTxnId: string
|
|
277
|
+
estimatedGasLimit: bigint
|
|
278
|
+
feeNative: bigint
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface IntentSummary {
|
|
282
|
+
intentId: string
|
|
283
|
+
status: IntentStatus
|
|
284
|
+
ownerAddress: string
|
|
285
|
+
originChainId: number
|
|
286
|
+
destinationChainId: number
|
|
287
|
+
originIntentAddress: string
|
|
288
|
+
destinationIntentAddress: string
|
|
289
|
+
depositTransactionHash?: string
|
|
290
|
+
depositTransactionStatus: TransactionStatus
|
|
291
|
+
originTransactionHash?: string
|
|
292
|
+
originTransactionStatus: TransactionStatus
|
|
293
|
+
destinationTransactionHash?: string
|
|
294
|
+
destinationTransactionStatus: TransactionStatus
|
|
295
|
+
originTokenAddress: string
|
|
296
|
+
originTokenAmount: bigint
|
|
297
|
+
originTokenMetadata: TokenMetadata
|
|
298
|
+
destinationTokenAddress: string
|
|
299
|
+
destinationTokenAmount: bigint
|
|
300
|
+
destinationTokenMetadata: TokenMetadata
|
|
301
|
+
updatedAt?: string
|
|
302
|
+
createdAt: string
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface ChainMetadata {
|
|
306
|
+
chainId: number
|
|
307
|
+
name: string
|
|
308
|
+
logoUri?: string
|
|
309
|
+
testnet?: boolean
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface TokenMetadata {
|
|
313
|
+
chainId: number
|
|
314
|
+
tokenAddress: string
|
|
315
|
+
name: string
|
|
316
|
+
symbol: string
|
|
317
|
+
decimals?: number
|
|
318
|
+
logoUri?: string
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface Token {
|
|
322
|
+
chainId: number
|
|
323
|
+
tokenAddress: string
|
|
324
|
+
tokenSymbol?: string
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface TokenPrice {
|
|
328
|
+
token: Token
|
|
329
|
+
priceUsd?: number
|
|
330
|
+
updatedAt: string
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface CCTPTransfer {
|
|
334
|
+
id: string
|
|
335
|
+
sourceTxHash: string
|
|
336
|
+
sourceChainId: number
|
|
337
|
+
destinationChainId: number
|
|
338
|
+
message: string
|
|
339
|
+
attestation: string
|
|
340
|
+
status: string
|
|
341
|
+
updatedAt?: string
|
|
342
|
+
createdAt?: string
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface GasFeeOptions {
|
|
346
|
+
gasEstimate: GasEstimate
|
|
347
|
+
feeOptions: Array<FeeOption>
|
|
348
|
+
expiresAt: string
|
|
349
|
+
feeCollectorAddress: string
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface GasEstimate {
|
|
353
|
+
totalGas: number
|
|
354
|
+
gasPrice: string
|
|
355
|
+
nativeCost: string
|
|
356
|
+
nativeCostUsd: number
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface FeeOption {
|
|
360
|
+
tokenAddress: string
|
|
361
|
+
tokenSymbol: string
|
|
362
|
+
tokenDecimals: number
|
|
363
|
+
amount: bigint
|
|
364
|
+
amountUsd: number
|
|
365
|
+
feeCollectorAddress: string
|
|
366
|
+
is2612: boolean
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface DepositSignature {
|
|
370
|
+
intentSignature: string
|
|
371
|
+
permitSignature?: string
|
|
372
|
+
permitDeadline?: number
|
|
373
|
+
permitAmount?: bigint
|
|
374
|
+
selectedGasFeeOption: FeeOption
|
|
375
|
+
userNonce: number
|
|
376
|
+
deadline: number
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface DepositIntentEntry {
|
|
380
|
+
intentSignature: string
|
|
381
|
+
permitSignature?: string
|
|
382
|
+
permitDeadline?: number
|
|
383
|
+
permitAmount?: bigint
|
|
384
|
+
feeAmount: string
|
|
385
|
+
feeToken: string
|
|
386
|
+
feeCollector: string
|
|
387
|
+
userNonce: number
|
|
388
|
+
deadline: number
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface TrailsAddressOverrides {
|
|
392
|
+
sequenceWalletFactoryAddress?: string
|
|
393
|
+
sequenceWalletMainModuleAddress?: string
|
|
394
|
+
sequenceWalletMainModuleUpgradableAddress?: string
|
|
395
|
+
sequenceWalletGuestModuleAddress?: string
|
|
396
|
+
sequenceWalletUtilsAddress?: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export enum SortOrder {
|
|
400
|
+
DESC = 'DESC',
|
|
401
|
+
ASC = 'ASC'
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export interface Version {
|
|
405
|
+
webrpcVersion: string
|
|
406
|
+
schemaVersion: string
|
|
407
|
+
schemaHash: string
|
|
408
|
+
appVersion: string
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export interface RuntimeStatus {
|
|
412
|
+
healthOK: boolean
|
|
413
|
+
startTime: string
|
|
414
|
+
uptime: number
|
|
415
|
+
ver: string
|
|
416
|
+
branch: string
|
|
417
|
+
commitHash: string
|
|
418
|
+
runnables: any
|
|
419
|
+
services: Array<ServiceStatus>
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export interface ServiceStatus {
|
|
423
|
+
name: string
|
|
424
|
+
healthy: boolean
|
|
425
|
+
error?: string
|
|
426
|
+
latency: string
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export interface QuoteIntentResponse {
|
|
430
|
+
intent: Intent
|
|
431
|
+
gasFeeOptions: GasFeeOptions
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface CommitIntentRequest {
|
|
435
|
+
intent: Intent
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface CommitIntentResponse {
|
|
439
|
+
intentId: string
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export interface ExecuteIntentRequest {
|
|
443
|
+
intentId: string
|
|
444
|
+
depositTransactionHash?: string
|
|
445
|
+
depositSignature?: DepositSignature
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export interface ExecuteIntentResponse {
|
|
449
|
+
intentId: string
|
|
450
|
+
intentStatus: IntentStatus
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface GetIntentReceiptRequest {
|
|
454
|
+
intentId: string
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export interface GetIntentReceiptResponse {
|
|
458
|
+
intentReceipt: IntentReceipt
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface WaitIntentReceiptRequest {
|
|
462
|
+
intentId: string
|
|
463
|
+
lastReceiptStates?: Array<TransactionStatus>
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface WaitIntentReceiptResponse {
|
|
467
|
+
intentReceipt: IntentReceipt
|
|
468
|
+
receiptStates: Array<TransactionStatus>
|
|
469
|
+
done: boolean
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export interface GetIntentRequest {
|
|
473
|
+
intentId: string
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface GetIntentResponse {
|
|
477
|
+
intent: Intent
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export interface SearchIntentsRequest {
|
|
481
|
+
byIntentId?: string
|
|
482
|
+
byProjectId?: number
|
|
483
|
+
byTransactionHash?: string
|
|
484
|
+
byOwnerAddress?: string
|
|
485
|
+
byOriginIntentAddress?: string
|
|
486
|
+
byDestinationIntentAddress?: string
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export interface SearchIntentsResponse {
|
|
490
|
+
intents: Array<Intent>
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export interface GetIntentTransactionHistoryRequest {
|
|
494
|
+
page?: Page
|
|
495
|
+
byProjectId?: number
|
|
496
|
+
byOwnerAddress?: string
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface GetIntentTransactionHistoryResponse {
|
|
500
|
+
intents: Array<IntentSummary>
|
|
501
|
+
nextPage?: Page
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export interface Page {
|
|
505
|
+
column?: string
|
|
506
|
+
before?: number
|
|
507
|
+
after?: number
|
|
508
|
+
sort?: Array<SortBy>
|
|
509
|
+
pageSize?: number
|
|
510
|
+
more?: boolean
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export interface SortBy {
|
|
514
|
+
column: string
|
|
515
|
+
order: SortOrder
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export interface PingRequest {}
|
|
519
|
+
|
|
520
|
+
export interface PingResponse {
|
|
521
|
+
status: boolean
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export interface VersionRequest {}
|
|
525
|
+
|
|
526
|
+
export interface VersionResponse {
|
|
527
|
+
version: Version
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export interface RuntimeStatusRequest {}
|
|
531
|
+
|
|
532
|
+
export interface RuntimeStatusResponse {
|
|
533
|
+
status: RuntimeStatus
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export interface ClockRequest {}
|
|
537
|
+
|
|
538
|
+
export interface ClockResponse {
|
|
539
|
+
serverTime: string
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export interface GetTokenPricesRequest {
|
|
543
|
+
tokens: Array<Token>
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export interface GetTokenPricesResponse {
|
|
547
|
+
tokenPrices: Array<TokenPrice>
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
//
|
|
551
|
+
// Client
|
|
552
|
+
//
|
|
553
|
+
|
|
554
|
+
export class Trails implements TrailsClient {
|
|
555
|
+
protected hostname: string
|
|
556
|
+
protected fetch: Fetch
|
|
557
|
+
protected path = '/rpc/Trails/'
|
|
558
|
+
|
|
559
|
+
constructor(hostname: string, fetch: Fetch) {
|
|
560
|
+
this.hostname = hostname.replace(/\/*$/, '')
|
|
561
|
+
this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private url(name: string): string {
|
|
565
|
+
return this.hostname + this.path + name
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
queryKey = {
|
|
569
|
+
ping: () => ['Trails', 'ping'] as const,
|
|
570
|
+
version: () => ['Trails', 'version'] as const,
|
|
571
|
+
runtimeStatus: () => ['Trails', 'runtimeStatus'] as const,
|
|
572
|
+
clock: () => ['Trails', 'clock'] as const,
|
|
573
|
+
quoteIntent: (req: QuoteIntentRequest) => ['Trails', 'quoteIntent', req] as const,
|
|
574
|
+
commitIntent: (req: CommitIntentRequest) => ['Trails', 'commitIntent', req] as const,
|
|
575
|
+
executeIntent: (req: ExecuteIntentRequest) => ['Trails', 'executeIntent', req] as const,
|
|
576
|
+
waitIntentReceipt: (req: WaitIntentReceiptRequest) => ['Trails', 'waitIntentReceipt', req] as const,
|
|
577
|
+
getIntentReceipt: (req: GetIntentReceiptRequest) => ['Trails', 'getIntentReceipt', req] as const,
|
|
578
|
+
getIntent: (req: GetIntentRequest) => ['Trails', 'getIntent', req] as const,
|
|
579
|
+
searchIntents: (req: SearchIntentsRequest) => ['Trails', 'searchIntents', req] as const,
|
|
580
|
+
getIntentTransactionHistory: (req: GetIntentTransactionHistoryRequest) =>
|
|
581
|
+
['Trails', 'getIntentTransactionHistory', req] as const,
|
|
582
|
+
getTokenPrices: (req: GetTokenPricesRequest) => ['Trails', 'getTokenPrices', req] as const
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
ping = (headers?: object, signal?: AbortSignal): Promise<PingResponse> => {
|
|
586
|
+
return this.fetch(this.url('Ping'), createHttpRequest('{}', headers, signal)).then(
|
|
587
|
+
res => {
|
|
588
|
+
return buildResponse(res).then(_data => {
|
|
589
|
+
return JsonDecode<PingResponse>(_data, 'PingResponse')
|
|
590
|
+
})
|
|
591
|
+
},
|
|
592
|
+
error => {
|
|
593
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
version = (headers?: object, signal?: AbortSignal): Promise<VersionResponse> => {
|
|
599
|
+
return this.fetch(this.url('Version'), createHttpRequest('{}', headers, signal)).then(
|
|
600
|
+
res => {
|
|
601
|
+
return buildResponse(res).then(_data => {
|
|
602
|
+
return JsonDecode<VersionResponse>(_data, 'VersionResponse')
|
|
603
|
+
})
|
|
604
|
+
},
|
|
605
|
+
error => {
|
|
606
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
607
|
+
}
|
|
608
|
+
)
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse> => {
|
|
612
|
+
return this.fetch(this.url('RuntimeStatus'), createHttpRequest('{}', headers, signal)).then(
|
|
613
|
+
res => {
|
|
614
|
+
return buildResponse(res).then(_data => {
|
|
615
|
+
return JsonDecode<RuntimeStatusResponse>(_data, 'RuntimeStatusResponse')
|
|
616
|
+
})
|
|
617
|
+
},
|
|
618
|
+
error => {
|
|
619
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
620
|
+
}
|
|
621
|
+
)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
clock = (headers?: object, signal?: AbortSignal): Promise<ClockResponse> => {
|
|
625
|
+
return this.fetch(this.url('Clock'), createHttpRequest('{}', headers, signal)).then(
|
|
626
|
+
res => {
|
|
627
|
+
return buildResponse(res).then(_data => {
|
|
628
|
+
return JsonDecode<ClockResponse>(_data, 'ClockResponse')
|
|
629
|
+
})
|
|
630
|
+
},
|
|
631
|
+
error => {
|
|
632
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
633
|
+
}
|
|
634
|
+
)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
quoteIntent = (req: QuoteIntentRequest, headers?: object, signal?: AbortSignal): Promise<QuoteIntentResponse> => {
|
|
638
|
+
return this.fetch(this.url('QuoteIntent'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
639
|
+
res => {
|
|
640
|
+
return buildResponse(res).then(_data => {
|
|
641
|
+
return JsonDecode<QuoteIntentResponse>(_data, 'QuoteIntentResponse')
|
|
642
|
+
})
|
|
643
|
+
},
|
|
644
|
+
error => {
|
|
645
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
646
|
+
}
|
|
647
|
+
)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
commitIntent = (req: CommitIntentRequest, headers?: object, signal?: AbortSignal): Promise<CommitIntentResponse> => {
|
|
651
|
+
return this.fetch(this.url('CommitIntent'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
652
|
+
res => {
|
|
653
|
+
return buildResponse(res).then(_data => {
|
|
654
|
+
return JsonDecode<CommitIntentResponse>(_data, 'CommitIntentResponse')
|
|
655
|
+
})
|
|
656
|
+
},
|
|
657
|
+
error => {
|
|
658
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
659
|
+
}
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
executeIntent = (req: ExecuteIntentRequest, headers?: object, signal?: AbortSignal): Promise<ExecuteIntentResponse> => {
|
|
664
|
+
return this.fetch(this.url('ExecuteIntent'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
665
|
+
res => {
|
|
666
|
+
return buildResponse(res).then(_data => {
|
|
667
|
+
return JsonDecode<ExecuteIntentResponse>(_data, 'ExecuteIntentResponse')
|
|
668
|
+
})
|
|
669
|
+
},
|
|
670
|
+
error => {
|
|
671
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
672
|
+
}
|
|
673
|
+
)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
waitIntentReceipt = (
|
|
677
|
+
req: WaitIntentReceiptRequest,
|
|
678
|
+
headers?: object,
|
|
679
|
+
signal?: AbortSignal
|
|
680
|
+
): Promise<WaitIntentReceiptResponse> => {
|
|
681
|
+
return this.fetch(this.url('WaitIntentReceipt'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
682
|
+
res => {
|
|
683
|
+
return buildResponse(res).then(_data => {
|
|
684
|
+
return JsonDecode<WaitIntentReceiptResponse>(_data, 'WaitIntentReceiptResponse')
|
|
685
|
+
})
|
|
686
|
+
},
|
|
687
|
+
error => {
|
|
688
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
689
|
+
}
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
getIntentReceipt = (
|
|
694
|
+
req: GetIntentReceiptRequest,
|
|
695
|
+
headers?: object,
|
|
696
|
+
signal?: AbortSignal
|
|
697
|
+
): Promise<GetIntentReceiptResponse> => {
|
|
698
|
+
return this.fetch(this.url('GetIntentReceipt'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
699
|
+
res => {
|
|
700
|
+
return buildResponse(res).then(_data => {
|
|
701
|
+
return JsonDecode<GetIntentReceiptResponse>(_data, 'GetIntentReceiptResponse')
|
|
702
|
+
})
|
|
703
|
+
},
|
|
704
|
+
error => {
|
|
705
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
706
|
+
}
|
|
707
|
+
)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
getIntent = (req: GetIntentRequest, headers?: object, signal?: AbortSignal): Promise<GetIntentResponse> => {
|
|
711
|
+
return this.fetch(this.url('GetIntent'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
712
|
+
res => {
|
|
713
|
+
return buildResponse(res).then(_data => {
|
|
714
|
+
return JsonDecode<GetIntentResponse>(_data, 'GetIntentResponse')
|
|
715
|
+
})
|
|
716
|
+
},
|
|
717
|
+
error => {
|
|
718
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
719
|
+
}
|
|
720
|
+
)
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
searchIntents = (req: SearchIntentsRequest, headers?: object, signal?: AbortSignal): Promise<SearchIntentsResponse> => {
|
|
724
|
+
return this.fetch(this.url('SearchIntents'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
725
|
+
res => {
|
|
726
|
+
return buildResponse(res).then(_data => {
|
|
727
|
+
return JsonDecode<SearchIntentsResponse>(_data, 'SearchIntentsResponse')
|
|
728
|
+
})
|
|
729
|
+
},
|
|
730
|
+
error => {
|
|
731
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
732
|
+
}
|
|
733
|
+
)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
getIntentTransactionHistory = (
|
|
737
|
+
req: GetIntentTransactionHistoryRequest,
|
|
738
|
+
headers?: object,
|
|
739
|
+
signal?: AbortSignal
|
|
740
|
+
): Promise<GetIntentTransactionHistoryResponse> => {
|
|
741
|
+
return this.fetch(this.url('GetIntentTransactionHistory'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
742
|
+
res => {
|
|
743
|
+
return buildResponse(res).then(_data => {
|
|
744
|
+
return JsonDecode<GetIntentTransactionHistoryResponse>(_data, 'GetIntentTransactionHistoryResponse')
|
|
745
|
+
})
|
|
746
|
+
},
|
|
747
|
+
error => {
|
|
748
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
749
|
+
}
|
|
750
|
+
)
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
getTokenPrices = (req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse> => {
|
|
754
|
+
return this.fetch(this.url('GetTokenPrices'), createHttpRequest(JsonEncode(req), headers, signal)).then(
|
|
755
|
+
res => {
|
|
756
|
+
return buildResponse(res).then(_data => {
|
|
757
|
+
return JsonDecode<GetTokenPricesResponse>(_data, 'GetTokenPricesResponse')
|
|
758
|
+
})
|
|
759
|
+
},
|
|
760
|
+
error => {
|
|
761
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
762
|
+
}
|
|
763
|
+
)
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
|
|
768
|
+
const reqHeaders: { [key: string]: string } = {
|
|
769
|
+
...headers,
|
|
770
|
+
'Content-Type': 'application/json',
|
|
771
|
+
[WebrpcHeader]: WebrpcHeaderValue
|
|
772
|
+
}
|
|
773
|
+
return { method: 'POST', headers: reqHeaders, body, signal }
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const buildResponse = (res: Response): Promise<any> => {
|
|
777
|
+
return res.text().then(text => {
|
|
778
|
+
let data
|
|
779
|
+
try {
|
|
780
|
+
data = JSON.parse(text)
|
|
781
|
+
} catch (error) {
|
|
782
|
+
throw WebrpcBadResponseError.new({
|
|
783
|
+
status: res.status,
|
|
784
|
+
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`
|
|
785
|
+
})
|
|
786
|
+
}
|
|
787
|
+
if (!res.ok) {
|
|
788
|
+
const code: number = typeof data.code === 'number' ? data.code : 0
|
|
789
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data)
|
|
790
|
+
}
|
|
791
|
+
return data
|
|
792
|
+
})
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
|
|
796
|
+
|
|
797
|
+
//
|
|
798
|
+
// BigInt helpers
|
|
799
|
+
//
|
|
800
|
+
|
|
801
|
+
const BIG_INT_FIELDS: { [typ: string]: (string | [string, string])[] } = {
|
|
802
|
+
CommitIntentRequest: [['intent', 'Intent']],
|
|
803
|
+
DepositIntentEntry: ['permitAmount'],
|
|
804
|
+
DepositSignature: ['permitAmount', ['selectedGasFeeOption', 'FeeOption']],
|
|
805
|
+
DepositTransaction: ['amount'],
|
|
806
|
+
ExecuteIntentRequest: [['depositSignature', 'DepositSignature']],
|
|
807
|
+
FeeOption: ['amount'],
|
|
808
|
+
GasFeeOptions: [['feeOptions', 'FeeOption[]']],
|
|
809
|
+
GetIntentReceiptResponse: [['intentReceipt', 'IntentReceipt']],
|
|
810
|
+
GetIntentResponse: [['intent', 'Intent']],
|
|
811
|
+
GetIntentTransactionHistoryResponse: [['intents', 'IntentSummary[]']],
|
|
812
|
+
Intent: [
|
|
813
|
+
['quoteRequest', 'QuoteIntentRequest'],
|
|
814
|
+
'salt',
|
|
815
|
+
['depositTransaction', 'DepositTransaction'],
|
|
816
|
+
['originCalls', 'IntentCalls'],
|
|
817
|
+
['destinationCalls', 'IntentCalls'],
|
|
818
|
+
['originPrecondition', 'TransactionPrecondition'],
|
|
819
|
+
['destinationPrecondition', 'TransactionPrecondition'],
|
|
820
|
+
['quote', 'IntentProviderQuote'],
|
|
821
|
+
['fees', 'IntentFees']
|
|
822
|
+
],
|
|
823
|
+
IntentCalls: ['space', 'nonce', ['calls', 'TransactionCall[]']],
|
|
824
|
+
IntentFees: [
|
|
825
|
+
['originGas', 'IntentTransactionGasFee'],
|
|
826
|
+
['destinationGas', 'IntentTransactionGasFee'],
|
|
827
|
+
['provider', 'IntentProviderFees'],
|
|
828
|
+
'feeTokenTotal',
|
|
829
|
+
'totalFeeAmount'
|
|
830
|
+
],
|
|
831
|
+
IntentProviderFees: ['quoteProviderFee', 'trailsFee', 'totalFeeAmount'],
|
|
832
|
+
IntentProviderQuote: ['fromAmount', 'fromAmountMin', 'toAmount', 'toAmountMin'],
|
|
833
|
+
IntentReceipt: [
|
|
834
|
+
['depositTransaction', 'IntentTransaction'],
|
|
835
|
+
['originTransaction', 'IntentTransaction'],
|
|
836
|
+
['destinationTransaction', 'IntentTransaction']
|
|
837
|
+
],
|
|
838
|
+
IntentSummary: ['originTokenAmount', 'destinationTokenAmount'],
|
|
839
|
+
IntentTransaction: ['tokenAmount', ['precondition', 'TransactionPrecondition'], ['depositIntentEntry', 'DepositIntentEntry']],
|
|
840
|
+
IntentTransactionGasFee: ['totalGasLimit', 'gasPrice', 'totalFeeAmount', ['metaTxnFeeDetails', 'MetaTxnFeeDetails']],
|
|
841
|
+
MetaTxnFeeDetails: ['estimatedGasLimit', 'feeNative'],
|
|
842
|
+
QuoteIntentRequest: ['destinationCallValue', 'originTokenAmount', 'destinationTokenAmount'],
|
|
843
|
+
QuoteIntentResponse: [
|
|
844
|
+
['intent', 'Intent'],
|
|
845
|
+
['gasFeeOptions', 'GasFeeOptions']
|
|
846
|
+
],
|
|
847
|
+
SearchIntentsResponse: [['intents', 'Intent[]']],
|
|
848
|
+
TransactionCall: ['value', 'gasLimit'],
|
|
849
|
+
TransactionPrecondition: ['minAmount'],
|
|
850
|
+
WaitIntentReceiptResponse: [['intentReceipt', 'IntentReceipt']]
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// Decode in-place: mutate object graph; throw if expected numeric string is invalid.
|
|
854
|
+
function decodeType(typ: string, obj: any): any {
|
|
855
|
+
if (obj == null || typeof obj !== 'object') return obj
|
|
856
|
+
const descs = BIG_INT_FIELDS[typ] || []
|
|
857
|
+
if (!descs.length) return obj
|
|
858
|
+
for (const d of descs) {
|
|
859
|
+
if (Array.isArray(d)) {
|
|
860
|
+
const [fieldName, nestedType] = d
|
|
861
|
+
if (fieldName.endsWith('[]')) {
|
|
862
|
+
const base = fieldName.slice(0, -2)
|
|
863
|
+
const arr = obj[base]
|
|
864
|
+
if (Array.isArray(arr)) {
|
|
865
|
+
for (let i = 0; i < arr.length; i++) arr[i] = decodeType(nestedType, arr[i])
|
|
866
|
+
}
|
|
867
|
+
} else if (obj[fieldName]) {
|
|
868
|
+
// Handle nestedType that might be an array type like 'Message[]'
|
|
869
|
+
if (nestedType.endsWith('[]')) {
|
|
870
|
+
const baseType = nestedType.slice(0, -2)
|
|
871
|
+
const arr = obj[fieldName]
|
|
872
|
+
if (Array.isArray(arr)) {
|
|
873
|
+
for (let i = 0; i < arr.length; i++) arr[i] = decodeType(baseType, arr[i])
|
|
874
|
+
}
|
|
875
|
+
} else {
|
|
876
|
+
obj[fieldName] = decodeType(nestedType, obj[fieldName])
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
continue
|
|
880
|
+
}
|
|
881
|
+
if (d.endsWith('[]')) {
|
|
882
|
+
const base = d.slice(0, -2)
|
|
883
|
+
const arr = obj[base]
|
|
884
|
+
if (Array.isArray(arr)) {
|
|
885
|
+
for (let i = 0; i < arr.length; i++) {
|
|
886
|
+
const v = arr[i]
|
|
887
|
+
if (typeof v === 'string') {
|
|
888
|
+
try {
|
|
889
|
+
arr[i] = BigInt(v)
|
|
890
|
+
} catch (e) {
|
|
891
|
+
throw WebrpcBadResponseError.new({ cause: `Invalid bigint value for ${base}[${i}]: ${v}` })
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
continue
|
|
897
|
+
}
|
|
898
|
+
const v = obj[d]
|
|
899
|
+
if (typeof v === 'string') {
|
|
900
|
+
try {
|
|
901
|
+
obj[d] = BigInt(v)
|
|
902
|
+
} catch (e) {
|
|
903
|
+
throw WebrpcBadResponseError.new({ cause: `Invalid bigint value for ${d}: ${v}` })
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return obj
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Encode object to JSON with BigInts converted to decimal strings.
|
|
911
|
+
export const JsonEncode = <T = any>(obj: T): string => {
|
|
912
|
+
return JSON.stringify(obj, (key, value) => (typeof value === 'bigint' ? value.toString() : value))
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// Decode data (JSON string or already-parsed object) and convert declared BigInt string fields back to BigInt.
|
|
916
|
+
export const JsonDecode = <T = any>(data: string | any, typ: string = ''): T => {
|
|
917
|
+
let parsed: any = data
|
|
918
|
+
if (typeof data === 'string') {
|
|
919
|
+
try {
|
|
920
|
+
parsed = JSON.parse(data)
|
|
921
|
+
} catch (err) {
|
|
922
|
+
throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return decodeType(typ, parsed) as T
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
//
|
|
929
|
+
// Errors
|
|
930
|
+
//
|
|
931
|
+
|
|
932
|
+
type WebrpcErrorParams = { name?: string; code?: number; message?: string; status?: number; cause?: string }
|
|
933
|
+
|
|
934
|
+
export class WebrpcError extends Error {
|
|
935
|
+
code: number
|
|
936
|
+
status: number
|
|
937
|
+
|
|
938
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
939
|
+
super(error.message)
|
|
940
|
+
this.name = error.name || 'WebrpcEndpointError'
|
|
941
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
942
|
+
this.message = error.message || `endpoint error`
|
|
943
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
944
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
945
|
+
Object.setPrototypeOf(this, WebrpcError.prototype)
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
static new(payload: any): WebrpcError {
|
|
949
|
+
return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export class WebrpcEndpointError extends WebrpcError {
|
|
954
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
955
|
+
super(error)
|
|
956
|
+
this.name = error.name || 'WebrpcEndpoint'
|
|
957
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
958
|
+
this.message = error.message || `endpoint error`
|
|
959
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
960
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
961
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
export class WebrpcRequestFailedError extends WebrpcError {
|
|
966
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
967
|
+
super(error)
|
|
968
|
+
this.name = error.name || 'WebrpcRequestFailed'
|
|
969
|
+
this.code = typeof error.code === 'number' ? error.code : -1
|
|
970
|
+
this.message = error.message || `request failed`
|
|
971
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
972
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
973
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
export class WebrpcBadRouteError extends WebrpcError {
|
|
978
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
979
|
+
super(error)
|
|
980
|
+
this.name = error.name || 'WebrpcBadRoute'
|
|
981
|
+
this.code = typeof error.code === 'number' ? error.code : -2
|
|
982
|
+
this.message = error.message || `bad route`
|
|
983
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
984
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
985
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
export class WebrpcBadMethodError extends WebrpcError {
|
|
990
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
991
|
+
super(error)
|
|
992
|
+
this.name = error.name || 'WebrpcBadMethod'
|
|
993
|
+
this.code = typeof error.code === 'number' ? error.code : -3
|
|
994
|
+
this.message = error.message || `bad method`
|
|
995
|
+
this.status = typeof error.status === 'number' ? error.status : 405
|
|
996
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
997
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
export class WebrpcBadRequestError extends WebrpcError {
|
|
1002
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1003
|
+
super(error)
|
|
1004
|
+
this.name = error.name || 'WebrpcBadRequest'
|
|
1005
|
+
this.code = typeof error.code === 'number' ? error.code : -4
|
|
1006
|
+
this.message = error.message || `bad request`
|
|
1007
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1008
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1009
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
export class WebrpcBadResponseError extends WebrpcError {
|
|
1014
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1015
|
+
super(error)
|
|
1016
|
+
this.name = error.name || 'WebrpcBadResponse'
|
|
1017
|
+
this.code = typeof error.code === 'number' ? error.code : -5
|
|
1018
|
+
this.message = error.message || `bad response`
|
|
1019
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1020
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1021
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export class WebrpcServerPanicError extends WebrpcError {
|
|
1026
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1027
|
+
super(error)
|
|
1028
|
+
this.name = error.name || 'WebrpcServerPanic'
|
|
1029
|
+
this.code = typeof error.code === 'number' ? error.code : -6
|
|
1030
|
+
this.message = error.message || `server panic`
|
|
1031
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1032
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1033
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
export class WebrpcInternalErrorError extends WebrpcError {
|
|
1038
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1039
|
+
super(error)
|
|
1040
|
+
this.name = error.name || 'WebrpcInternalError'
|
|
1041
|
+
this.code = typeof error.code === 'number' ? error.code : -7
|
|
1042
|
+
this.message = error.message || `internal error`
|
|
1043
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1044
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1045
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
export class WebrpcClientAbortedError extends WebrpcError {
|
|
1050
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1051
|
+
super(error)
|
|
1052
|
+
this.name = error.name || 'WebrpcClientAborted'
|
|
1053
|
+
this.code = typeof error.code === 'number' ? error.code : -8
|
|
1054
|
+
this.message = error.message || `request aborted by client`
|
|
1055
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1056
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1057
|
+
Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
export class WebrpcStreamLostError extends WebrpcError {
|
|
1062
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1063
|
+
super(error)
|
|
1064
|
+
this.name = error.name || 'WebrpcStreamLost'
|
|
1065
|
+
this.code = typeof error.code === 'number' ? error.code : -9
|
|
1066
|
+
this.message = error.message || `stream lost`
|
|
1067
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1068
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1069
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
export class WebrpcStreamFinishedError extends WebrpcError {
|
|
1074
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1075
|
+
super(error)
|
|
1076
|
+
this.name = error.name || 'WebrpcStreamFinished'
|
|
1077
|
+
this.code = typeof error.code === 'number' ? error.code : -10
|
|
1078
|
+
this.message = error.message || `stream finished`
|
|
1079
|
+
this.status = typeof error.status === 'number' ? error.status : 200
|
|
1080
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1081
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
//
|
|
1086
|
+
// Schema errors
|
|
1087
|
+
//
|
|
1088
|
+
|
|
1089
|
+
export class UnauthorizedError extends WebrpcError {
|
|
1090
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1091
|
+
super(error)
|
|
1092
|
+
this.name = error.name || 'Unauthorized'
|
|
1093
|
+
this.code = typeof error.code === 'number' ? error.code : 1000
|
|
1094
|
+
this.message = error.message || `Unauthorized access`
|
|
1095
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
1096
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1097
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype)
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
export class PermissionDeniedError extends WebrpcError {
|
|
1102
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1103
|
+
super(error)
|
|
1104
|
+
this.name = error.name || 'PermissionDenied'
|
|
1105
|
+
this.code = typeof error.code === 'number' ? error.code : 1001
|
|
1106
|
+
this.message = error.message || `Permission denied`
|
|
1107
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1108
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1109
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
export class SessionExpiredError extends WebrpcError {
|
|
1114
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1115
|
+
super(error)
|
|
1116
|
+
this.name = error.name || 'SessionExpired'
|
|
1117
|
+
this.code = typeof error.code === 'number' ? error.code : 1002
|
|
1118
|
+
this.message = error.message || `Session expired`
|
|
1119
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1120
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1121
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype)
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
export class MethodNotFoundError extends WebrpcError {
|
|
1126
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1127
|
+
super(error)
|
|
1128
|
+
this.name = error.name || 'MethodNotFound'
|
|
1129
|
+
this.code = typeof error.code === 'number' ? error.code : 1003
|
|
1130
|
+
this.message = error.message || `Method not found`
|
|
1131
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
1132
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1133
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype)
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
export class RequestConflictError extends WebrpcError {
|
|
1138
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1139
|
+
super(error)
|
|
1140
|
+
this.name = error.name || 'RequestConflict'
|
|
1141
|
+
this.code = typeof error.code === 'number' ? error.code : 1004
|
|
1142
|
+
this.message = error.message || `Conflict with target resource`
|
|
1143
|
+
this.status = typeof error.status === 'number' ? error.status : 409
|
|
1144
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1145
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype)
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
export class AbortedError extends WebrpcError {
|
|
1150
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1151
|
+
super(error)
|
|
1152
|
+
this.name = error.name || 'Aborted'
|
|
1153
|
+
this.code = typeof error.code === 'number' ? error.code : 1005
|
|
1154
|
+
this.message = error.message || `Request aborted`
|
|
1155
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1156
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1157
|
+
Object.setPrototypeOf(this, AbortedError.prototype)
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
export class GeoblockedError extends WebrpcError {
|
|
1162
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1163
|
+
super(error)
|
|
1164
|
+
this.name = error.name || 'Geoblocked'
|
|
1165
|
+
this.code = typeof error.code === 'number' ? error.code : 1006
|
|
1166
|
+
this.message = error.message || `Geoblocked region`
|
|
1167
|
+
this.status = typeof error.status === 'number' ? error.status : 451
|
|
1168
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1169
|
+
Object.setPrototypeOf(this, GeoblockedError.prototype)
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
export class RateLimitedError extends WebrpcError {
|
|
1174
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1175
|
+
super(error)
|
|
1176
|
+
this.name = error.name || 'RateLimited'
|
|
1177
|
+
this.code = typeof error.code === 'number' ? error.code : 1007
|
|
1178
|
+
this.message = error.message || `Rate-limited. Please slow down.`
|
|
1179
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
1180
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1181
|
+
Object.setPrototypeOf(this, RateLimitedError.prototype)
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
export class ProjectNotFoundError extends WebrpcError {
|
|
1186
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1187
|
+
super(error)
|
|
1188
|
+
this.name = error.name || 'ProjectNotFound'
|
|
1189
|
+
this.code = typeof error.code === 'number' ? error.code : 1008
|
|
1190
|
+
this.message = error.message || `Project not found`
|
|
1191
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
1192
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1193
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
export class AccessKeyNotFoundError extends WebrpcError {
|
|
1198
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1199
|
+
super(error)
|
|
1200
|
+
this.name = error.name || 'AccessKeyNotFound'
|
|
1201
|
+
this.code = typeof error.code === 'number' ? error.code : 1101
|
|
1202
|
+
this.message = error.message || `Access key not found`
|
|
1203
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
1204
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1205
|
+
Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
export class AccessKeyMismatchError extends WebrpcError {
|
|
1210
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1211
|
+
super(error)
|
|
1212
|
+
this.name = error.name || 'AccessKeyMismatch'
|
|
1213
|
+
this.code = typeof error.code === 'number' ? error.code : 1102
|
|
1214
|
+
this.message = error.message || `Access key mismatch`
|
|
1215
|
+
this.status = typeof error.status === 'number' ? error.status : 409
|
|
1216
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1217
|
+
Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
export class InvalidOriginError extends WebrpcError {
|
|
1222
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1223
|
+
super(error)
|
|
1224
|
+
this.name = error.name || 'InvalidOrigin'
|
|
1225
|
+
this.code = typeof error.code === 'number' ? error.code : 1103
|
|
1226
|
+
this.message = error.message || `Invalid origin for Access Key`
|
|
1227
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1228
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1229
|
+
Object.setPrototypeOf(this, InvalidOriginError.prototype)
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
export class InvalidServiceError extends WebrpcError {
|
|
1234
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1235
|
+
super(error)
|
|
1236
|
+
this.name = error.name || 'InvalidService'
|
|
1237
|
+
this.code = typeof error.code === 'number' ? error.code : 1104
|
|
1238
|
+
this.message = error.message || `Service not enabled for Access key`
|
|
1239
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1240
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1241
|
+
Object.setPrototypeOf(this, InvalidServiceError.prototype)
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
export class UnauthorizedUserError extends WebrpcError {
|
|
1246
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1247
|
+
super(error)
|
|
1248
|
+
this.name = error.name || 'UnauthorizedUser'
|
|
1249
|
+
this.code = typeof error.code === 'number' ? error.code : 1105
|
|
1250
|
+
this.message = error.message || `Unauthorized user`
|
|
1251
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1252
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1253
|
+
Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
export class QuotaExceededError extends WebrpcError {
|
|
1258
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1259
|
+
super(error)
|
|
1260
|
+
this.name = error.name || 'QuotaExceeded'
|
|
1261
|
+
this.code = typeof error.code === 'number' ? error.code : 1200
|
|
1262
|
+
this.message = error.message || `Quota request exceeded`
|
|
1263
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
1264
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1265
|
+
Object.setPrototypeOf(this, QuotaExceededError.prototype)
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
export class QuotaRateLimitError extends WebrpcError {
|
|
1270
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1271
|
+
super(error)
|
|
1272
|
+
this.name = error.name || 'QuotaRateLimit'
|
|
1273
|
+
this.code = typeof error.code === 'number' ? error.code : 1201
|
|
1274
|
+
this.message = error.message || `Quota rate limit exceeded`
|
|
1275
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
1276
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1277
|
+
Object.setPrototypeOf(this, QuotaRateLimitError.prototype)
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
export class NoDefaultKeyError extends WebrpcError {
|
|
1282
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1283
|
+
super(error)
|
|
1284
|
+
this.name = error.name || 'NoDefaultKey'
|
|
1285
|
+
this.code = typeof error.code === 'number' ? error.code : 1300
|
|
1286
|
+
this.message = error.message || `No default access key found`
|
|
1287
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1288
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1289
|
+
Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
export class MaxAccessKeysError extends WebrpcError {
|
|
1294
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1295
|
+
super(error)
|
|
1296
|
+
this.name = error.name || 'MaxAccessKeys'
|
|
1297
|
+
this.code = typeof error.code === 'number' ? error.code : 1301
|
|
1298
|
+
this.message = error.message || `Access keys limit reached`
|
|
1299
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1300
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1301
|
+
Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
export class AtLeastOneKeyError extends WebrpcError {
|
|
1306
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1307
|
+
super(error)
|
|
1308
|
+
this.name = error.name || 'AtLeastOneKey'
|
|
1309
|
+
this.code = typeof error.code === 'number' ? error.code : 1302
|
|
1310
|
+
this.message = error.message || `You need at least one Access Key`
|
|
1311
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1312
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1313
|
+
Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
export class TimeoutError extends WebrpcError {
|
|
1318
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1319
|
+
super(error)
|
|
1320
|
+
this.name = error.name || 'Timeout'
|
|
1321
|
+
this.code = typeof error.code === 'number' ? error.code : 1900
|
|
1322
|
+
this.message = error.message || `Request timed out`
|
|
1323
|
+
this.status = typeof error.status === 'number' ? error.status : 408
|
|
1324
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1325
|
+
Object.setPrototypeOf(this, TimeoutError.prototype)
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export class InvalidArgumentError extends WebrpcError {
|
|
1330
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1331
|
+
super(error)
|
|
1332
|
+
this.name = error.name || 'InvalidArgument'
|
|
1333
|
+
this.code = typeof error.code === 'number' ? error.code : 2000
|
|
1334
|
+
this.message = error.message || `Invalid argument`
|
|
1335
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1336
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1337
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype)
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
export class UnexpectedError extends WebrpcError {
|
|
1342
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1343
|
+
super(error)
|
|
1344
|
+
this.name = error.name || 'Unexpected'
|
|
1345
|
+
this.code = typeof error.code === 'number' ? error.code : 2001
|
|
1346
|
+
this.message = error.message || `Unexpected server error`
|
|
1347
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1348
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1349
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype)
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
export class UnavailableError extends WebrpcError {
|
|
1354
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1355
|
+
super(error)
|
|
1356
|
+
this.name = error.name || 'Unavailable'
|
|
1357
|
+
this.code = typeof error.code === 'number' ? error.code : 2002
|
|
1358
|
+
this.message = error.message || `Unavailable resource`
|
|
1359
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1360
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1361
|
+
Object.setPrototypeOf(this, UnavailableError.prototype)
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
export class QueryFailedError extends WebrpcError {
|
|
1366
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1367
|
+
super(error)
|
|
1368
|
+
this.name = error.name || 'QueryFailed'
|
|
1369
|
+
this.code = typeof error.code === 'number' ? error.code : 2003
|
|
1370
|
+
this.message = error.message || `Query failed`
|
|
1371
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1372
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1373
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype)
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
export class IntentStatusError extends WebrpcError {
|
|
1378
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1379
|
+
super(error)
|
|
1380
|
+
this.name = error.name || 'IntentStatus'
|
|
1381
|
+
this.code = typeof error.code === 'number' ? error.code : 2004
|
|
1382
|
+
this.message = error.message || `Invalid intent status`
|
|
1383
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
1384
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1385
|
+
Object.setPrototypeOf(this, IntentStatusError.prototype)
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
export class NotFoundError extends WebrpcError {
|
|
1390
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1391
|
+
super(error)
|
|
1392
|
+
this.name = error.name || 'NotFound'
|
|
1393
|
+
this.code = typeof error.code === 'number' ? error.code : 8000
|
|
1394
|
+
this.message = error.message || `Resource not found`
|
|
1395
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1396
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1397
|
+
Object.setPrototypeOf(this, NotFoundError.prototype)
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
export class UnsupportedNetworkError extends WebrpcError {
|
|
1402
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1403
|
+
super(error)
|
|
1404
|
+
this.name = error.name || 'UnsupportedNetwork'
|
|
1405
|
+
this.code = typeof error.code === 'number' ? error.code : 8008
|
|
1406
|
+
this.message = error.message || `Unsupported network`
|
|
1407
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
1408
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1409
|
+
Object.setPrototypeOf(this, UnsupportedNetworkError.prototype)
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
export class IntentsSkippedError extends WebrpcError {
|
|
1414
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1415
|
+
super(error)
|
|
1416
|
+
this.name = error.name || 'IntentsSkipped'
|
|
1417
|
+
this.code = typeof error.code === 'number' ? error.code : 7000
|
|
1418
|
+
this.message = error.message || `Intents skipped as client is attempting a transaction that does not require intents`
|
|
1419
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1420
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1421
|
+
Object.setPrototypeOf(this, IntentsSkippedError.prototype)
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
export class IntentsDisabledError extends WebrpcError {
|
|
1426
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1427
|
+
super(error)
|
|
1428
|
+
this.name = error.name || 'IntentsDisabled'
|
|
1429
|
+
this.code = typeof error.code === 'number' ? error.code : 9000
|
|
1430
|
+
this.message = error.message || `Intents service is currently unavailable`
|
|
1431
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1432
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1433
|
+
Object.setPrototypeOf(this, IntentsDisabledError.prototype)
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
export enum errors {
|
|
1438
|
+
WebrpcEndpoint = 'WebrpcEndpoint',
|
|
1439
|
+
WebrpcRequestFailed = 'WebrpcRequestFailed',
|
|
1440
|
+
WebrpcBadRoute = 'WebrpcBadRoute',
|
|
1441
|
+
WebrpcBadMethod = 'WebrpcBadMethod',
|
|
1442
|
+
WebrpcBadRequest = 'WebrpcBadRequest',
|
|
1443
|
+
WebrpcBadResponse = 'WebrpcBadResponse',
|
|
1444
|
+
WebrpcServerPanic = 'WebrpcServerPanic',
|
|
1445
|
+
WebrpcInternalError = 'WebrpcInternalError',
|
|
1446
|
+
WebrpcClientAborted = 'WebrpcClientAborted',
|
|
1447
|
+
WebrpcStreamLost = 'WebrpcStreamLost',
|
|
1448
|
+
WebrpcStreamFinished = 'WebrpcStreamFinished',
|
|
1449
|
+
Unauthorized = 'Unauthorized',
|
|
1450
|
+
PermissionDenied = 'PermissionDenied',
|
|
1451
|
+
SessionExpired = 'SessionExpired',
|
|
1452
|
+
MethodNotFound = 'MethodNotFound',
|
|
1453
|
+
RequestConflict = 'RequestConflict',
|
|
1454
|
+
Aborted = 'Aborted',
|
|
1455
|
+
Geoblocked = 'Geoblocked',
|
|
1456
|
+
RateLimited = 'RateLimited',
|
|
1457
|
+
ProjectNotFound = 'ProjectNotFound',
|
|
1458
|
+
AccessKeyNotFound = 'AccessKeyNotFound',
|
|
1459
|
+
AccessKeyMismatch = 'AccessKeyMismatch',
|
|
1460
|
+
InvalidOrigin = 'InvalidOrigin',
|
|
1461
|
+
InvalidService = 'InvalidService',
|
|
1462
|
+
UnauthorizedUser = 'UnauthorizedUser',
|
|
1463
|
+
QuotaExceeded = 'QuotaExceeded',
|
|
1464
|
+
QuotaRateLimit = 'QuotaRateLimit',
|
|
1465
|
+
NoDefaultKey = 'NoDefaultKey',
|
|
1466
|
+
MaxAccessKeys = 'MaxAccessKeys',
|
|
1467
|
+
AtLeastOneKey = 'AtLeastOneKey',
|
|
1468
|
+
Timeout = 'Timeout',
|
|
1469
|
+
InvalidArgument = 'InvalidArgument',
|
|
1470
|
+
Unexpected = 'Unexpected',
|
|
1471
|
+
Unavailable = 'Unavailable',
|
|
1472
|
+
QueryFailed = 'QueryFailed',
|
|
1473
|
+
IntentStatus = 'IntentStatus',
|
|
1474
|
+
NotFound = 'NotFound',
|
|
1475
|
+
UnsupportedNetwork = 'UnsupportedNetwork',
|
|
1476
|
+
IntentsSkipped = 'IntentsSkipped',
|
|
1477
|
+
IntentsDisabled = 'IntentsDisabled'
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
export enum WebrpcErrorCodes {
|
|
1481
|
+
WebrpcEndpoint = 0,
|
|
1482
|
+
WebrpcRequestFailed = -1,
|
|
1483
|
+
WebrpcBadRoute = -2,
|
|
1484
|
+
WebrpcBadMethod = -3,
|
|
1485
|
+
WebrpcBadRequest = -4,
|
|
1486
|
+
WebrpcBadResponse = -5,
|
|
1487
|
+
WebrpcServerPanic = -6,
|
|
1488
|
+
WebrpcInternalError = -7,
|
|
1489
|
+
WebrpcClientAborted = -8,
|
|
1490
|
+
WebrpcStreamLost = -9,
|
|
1491
|
+
WebrpcStreamFinished = -10,
|
|
1492
|
+
Unauthorized = 1000,
|
|
1493
|
+
PermissionDenied = 1001,
|
|
1494
|
+
SessionExpired = 1002,
|
|
1495
|
+
MethodNotFound = 1003,
|
|
1496
|
+
RequestConflict = 1004,
|
|
1497
|
+
Aborted = 1005,
|
|
1498
|
+
Geoblocked = 1006,
|
|
1499
|
+
RateLimited = 1007,
|
|
1500
|
+
ProjectNotFound = 1008,
|
|
1501
|
+
AccessKeyNotFound = 1101,
|
|
1502
|
+
AccessKeyMismatch = 1102,
|
|
1503
|
+
InvalidOrigin = 1103,
|
|
1504
|
+
InvalidService = 1104,
|
|
1505
|
+
UnauthorizedUser = 1105,
|
|
1506
|
+
QuotaExceeded = 1200,
|
|
1507
|
+
QuotaRateLimit = 1201,
|
|
1508
|
+
NoDefaultKey = 1300,
|
|
1509
|
+
MaxAccessKeys = 1301,
|
|
1510
|
+
AtLeastOneKey = 1302,
|
|
1511
|
+
Timeout = 1900,
|
|
1512
|
+
InvalidArgument = 2000,
|
|
1513
|
+
Unexpected = 2001,
|
|
1514
|
+
Unavailable = 2002,
|
|
1515
|
+
QueryFailed = 2003,
|
|
1516
|
+
IntentStatus = 2004,
|
|
1517
|
+
NotFound = 8000,
|
|
1518
|
+
UnsupportedNetwork = 8008,
|
|
1519
|
+
IntentsSkipped = 7000,
|
|
1520
|
+
IntentsDisabled = 9000
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
export const webrpcErrorByCode: { [code: number]: any } = {
|
|
1524
|
+
[0]: WebrpcEndpointError,
|
|
1525
|
+
[-1]: WebrpcRequestFailedError,
|
|
1526
|
+
[-2]: WebrpcBadRouteError,
|
|
1527
|
+
[-3]: WebrpcBadMethodError,
|
|
1528
|
+
[-4]: WebrpcBadRequestError,
|
|
1529
|
+
[-5]: WebrpcBadResponseError,
|
|
1530
|
+
[-6]: WebrpcServerPanicError,
|
|
1531
|
+
[-7]: WebrpcInternalErrorError,
|
|
1532
|
+
[-8]: WebrpcClientAbortedError,
|
|
1533
|
+
[-9]: WebrpcStreamLostError,
|
|
1534
|
+
[-10]: WebrpcStreamFinishedError,
|
|
1535
|
+
[1000]: UnauthorizedError,
|
|
1536
|
+
[1001]: PermissionDeniedError,
|
|
1537
|
+
[1002]: SessionExpiredError,
|
|
1538
|
+
[1003]: MethodNotFoundError,
|
|
1539
|
+
[1004]: RequestConflictError,
|
|
1540
|
+
[1005]: AbortedError,
|
|
1541
|
+
[1006]: GeoblockedError,
|
|
1542
|
+
[1007]: RateLimitedError,
|
|
1543
|
+
[1008]: ProjectNotFoundError,
|
|
1544
|
+
[1101]: AccessKeyNotFoundError,
|
|
1545
|
+
[1102]: AccessKeyMismatchError,
|
|
1546
|
+
[1103]: InvalidOriginError,
|
|
1547
|
+
[1104]: InvalidServiceError,
|
|
1548
|
+
[1105]: UnauthorizedUserError,
|
|
1549
|
+
[1200]: QuotaExceededError,
|
|
1550
|
+
[1201]: QuotaRateLimitError,
|
|
1551
|
+
[1300]: NoDefaultKeyError,
|
|
1552
|
+
[1301]: MaxAccessKeysError,
|
|
1553
|
+
[1302]: AtLeastOneKeyError,
|
|
1554
|
+
[1900]: TimeoutError,
|
|
1555
|
+
[2000]: InvalidArgumentError,
|
|
1556
|
+
[2001]: UnexpectedError,
|
|
1557
|
+
[2002]: UnavailableError,
|
|
1558
|
+
[2003]: QueryFailedError,
|
|
1559
|
+
[2004]: IntentStatusError,
|
|
1560
|
+
[8000]: NotFoundError,
|
|
1561
|
+
[8008]: UnsupportedNetworkError,
|
|
1562
|
+
[7000]: IntentsSkippedError,
|
|
1563
|
+
[9000]: IntentsDisabledError
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
//
|
|
1567
|
+
// Webrpc
|
|
1568
|
+
//
|
|
1569
|
+
|
|
1570
|
+
export const WebrpcHeader = 'Webrpc'
|
|
1571
|
+
|
|
1572
|
+
export const WebrpcHeaderValue = 'webrpc@v0.31.2;gen-typescript@v0.23.1;trails-api@v1-25.11.17+822fb49'
|
|
1573
|
+
|
|
1574
|
+
type WebrpcGenVersions = {
|
|
1575
|
+
WebrpcGenVersion: string
|
|
1576
|
+
codeGenName: string
|
|
1577
|
+
codeGenVersion: string
|
|
1578
|
+
schemaName: string
|
|
1579
|
+
schemaVersion: string
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
|
|
1583
|
+
const headerValue = headers.get(WebrpcHeader)
|
|
1584
|
+
if (!headerValue) {
|
|
1585
|
+
return {
|
|
1586
|
+
WebrpcGenVersion: '',
|
|
1587
|
+
codeGenName: '',
|
|
1588
|
+
codeGenVersion: '',
|
|
1589
|
+
schemaName: '',
|
|
1590
|
+
schemaVersion: ''
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
return parseWebrpcGenVersions(headerValue)
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
1598
|
+
const versions = header.split(';')
|
|
1599
|
+
if (versions.length < 3) {
|
|
1600
|
+
return {
|
|
1601
|
+
WebrpcGenVersion: '',
|
|
1602
|
+
codeGenName: '',
|
|
1603
|
+
codeGenVersion: '',
|
|
1604
|
+
schemaName: '',
|
|
1605
|
+
schemaVersion: ''
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
const [_, WebrpcGenVersion] = versions[0]!.split('@')
|
|
1610
|
+
const [codeGenName, codeGenVersion] = versions[1]!.split('@')
|
|
1611
|
+
const [schemaName, schemaVersion] = versions[2]!.split('@')
|
|
1612
|
+
|
|
1613
|
+
return {
|
|
1614
|
+
WebrpcGenVersion: WebrpcGenVersion ?? '',
|
|
1615
|
+
codeGenName: codeGenName ?? '',
|
|
1616
|
+
codeGenVersion: codeGenVersion ?? '',
|
|
1617
|
+
schemaName: schemaName ?? '',
|
|
1618
|
+
schemaVersion: schemaVersion ?? ''
|
|
1619
|
+
}
|
|
1620
|
+
}
|