@0xsequence/indexer 2.1.8 → 2.2.1
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/dist/0xsequence-indexer.cjs.dev.js +935 -225
- package/dist/0xsequence-indexer.cjs.prod.js +935 -225
- package/dist/0xsequence-indexer.esm.js +895 -187
- package/dist/declarations/src/index.d.ts +8 -0
- package/dist/declarations/src/indexergw.gen.d.ts +697 -0
- package/package.json +1 -1
- package/src/index.ts +35 -0
- package/src/indexergw.gen.ts +1419 -0
|
@@ -0,0 +1,1419 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// sequence-indexer v0.4.0 71cd081c5ca2372bf92a897ae1aa4ebf93ffd0fc
|
|
3
|
+
// --
|
|
4
|
+
// Code generated by webrpc-gen@v0.21.1 with typescript generator. DO NOT EDIT.
|
|
5
|
+
//
|
|
6
|
+
// webrpc-gen -schema=indexer.ridl -service=IndexerGateway -target=typescript -client -out=./clients/indexergw/indexer.gen.ts
|
|
7
|
+
|
|
8
|
+
export const WebrpcHeader = "Webrpc"
|
|
9
|
+
|
|
10
|
+
export const WebrpcHeaderValue = "webrpc@v0.21.1;gen-typescript@v0.15.1;sequence-indexer@v0.4.0"
|
|
11
|
+
|
|
12
|
+
// WebRPC description and code-gen version
|
|
13
|
+
export const WebRPCVersion = "v1"
|
|
14
|
+
|
|
15
|
+
// Schema version of your RIDL schema
|
|
16
|
+
export const WebRPCSchemaVersion = "v0.4.0"
|
|
17
|
+
|
|
18
|
+
// Schema hash generated from your RIDL schema
|
|
19
|
+
export const WebRPCSchemaHash = "71cd081c5ca2372bf92a897ae1aa4ebf93ffd0fc"
|
|
20
|
+
|
|
21
|
+
type WebrpcGenVersions = {
|
|
22
|
+
webrpcGenVersion: string;
|
|
23
|
+
codeGenName: string;
|
|
24
|
+
codeGenVersion: string;
|
|
25
|
+
schemaName: string;
|
|
26
|
+
schemaVersion: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
|
|
30
|
+
const headerValue = headers.get(WebrpcHeader);
|
|
31
|
+
if (!headerValue) {
|
|
32
|
+
return {
|
|
33
|
+
webrpcGenVersion: "",
|
|
34
|
+
codeGenName: "",
|
|
35
|
+
codeGenVersion: "",
|
|
36
|
+
schemaName: "",
|
|
37
|
+
schemaVersion: "",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return parseWebrpcGenVersions(headerValue);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
45
|
+
const versions = header.split(";");
|
|
46
|
+
if (versions.length < 3) {
|
|
47
|
+
return {
|
|
48
|
+
webrpcGenVersion: "",
|
|
49
|
+
codeGenName: "",
|
|
50
|
+
codeGenVersion: "",
|
|
51
|
+
schemaName: "",
|
|
52
|
+
schemaVersion: "",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [_, webrpcGenVersion] = versions[0].split("@");
|
|
57
|
+
const [codeGenName, codeGenVersion] = versions[1].split("@");
|
|
58
|
+
const [schemaName, schemaVersion] = versions[2].split("@");
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
webrpcGenVersion,
|
|
62
|
+
codeGenName,
|
|
63
|
+
codeGenVersion,
|
|
64
|
+
schemaName,
|
|
65
|
+
schemaVersion,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//
|
|
70
|
+
// Types
|
|
71
|
+
//
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export interface ContractInfo {
|
|
75
|
+
chainId: number
|
|
76
|
+
address: string
|
|
77
|
+
name: string
|
|
78
|
+
type: string
|
|
79
|
+
symbol: string
|
|
80
|
+
decimals?: number
|
|
81
|
+
logoURI: string
|
|
82
|
+
deployed: boolean
|
|
83
|
+
bytecodeHash: string
|
|
84
|
+
extensions: ContractInfoExtensions
|
|
85
|
+
updatedAt: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ContractInfoExtensions {
|
|
89
|
+
link: string
|
|
90
|
+
description: string
|
|
91
|
+
ogImage: string
|
|
92
|
+
originChainId: number
|
|
93
|
+
originAddress: string
|
|
94
|
+
blacklist: boolean
|
|
95
|
+
verified: boolean
|
|
96
|
+
verifiedBy: string
|
|
97
|
+
featured: boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface TokenMetadata {
|
|
101
|
+
tokenId: string
|
|
102
|
+
name: string
|
|
103
|
+
description?: string
|
|
104
|
+
image?: string
|
|
105
|
+
video?: string
|
|
106
|
+
audio?: string
|
|
107
|
+
properties?: {[key: string]: any}
|
|
108
|
+
attributes: Array<{[key: string]: any}>
|
|
109
|
+
image_data?: string
|
|
110
|
+
external_url?: string
|
|
111
|
+
background_color?: string
|
|
112
|
+
animation_url?: string
|
|
113
|
+
decimals?: number
|
|
114
|
+
updatedAt?: string
|
|
115
|
+
assets?: Array<Asset>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface Asset {
|
|
119
|
+
id: number
|
|
120
|
+
collectionId: number
|
|
121
|
+
tokenId?: string
|
|
122
|
+
url?: string
|
|
123
|
+
metadataField: string
|
|
124
|
+
name?: string
|
|
125
|
+
filesize?: number
|
|
126
|
+
mimeType?: string
|
|
127
|
+
width?: number
|
|
128
|
+
height?: number
|
|
129
|
+
updatedAt?: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export enum ContractType {
|
|
133
|
+
UNKNOWN = 'UNKNOWN',
|
|
134
|
+
NATIVE = 'NATIVE',
|
|
135
|
+
ERC20 = 'ERC20',
|
|
136
|
+
ERC721 = 'ERC721',
|
|
137
|
+
ERC1155 = 'ERC1155',
|
|
138
|
+
SEQUENCE_WALLET = 'SEQUENCE_WALLET',
|
|
139
|
+
ERC20_BRIDGE = 'ERC20_BRIDGE',
|
|
140
|
+
ERC721_BRIDGE = 'ERC721_BRIDGE',
|
|
141
|
+
ERC1155_BRIDGE = 'ERC1155_BRIDGE',
|
|
142
|
+
SEQ_MARKETPLACE = 'SEQ_MARKETPLACE'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export enum EventLogType {
|
|
146
|
+
UNKNOWN = 'UNKNOWN',
|
|
147
|
+
BLOCK_ADDED = 'BLOCK_ADDED',
|
|
148
|
+
BLOCK_REMOVED = 'BLOCK_REMOVED'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export enum EventLogDataType {
|
|
152
|
+
EVENT = 'EVENT',
|
|
153
|
+
TOKEN_TRANSFER = 'TOKEN_TRANSFER',
|
|
154
|
+
NATIVE_TOKEN_TRANSFER = 'NATIVE_TOKEN_TRANSFER',
|
|
155
|
+
SEQUENCE_TXN = 'SEQUENCE_TXN'
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export enum OrderStatus {
|
|
159
|
+
OPEN = 'OPEN',
|
|
160
|
+
CLOSED = 'CLOSED',
|
|
161
|
+
CANCELLED = 'CANCELLED'
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export enum TxnTransferType {
|
|
165
|
+
UNKNOWN = 'UNKNOWN',
|
|
166
|
+
SEND = 'SEND',
|
|
167
|
+
RECEIVE = 'RECEIVE'
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export enum TransactionStatus {
|
|
171
|
+
FAILED = 'FAILED',
|
|
172
|
+
SUCCESSFUL = 'SUCCESSFUL'
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export enum TransactionType {
|
|
176
|
+
LegacyTxnType = 'LegacyTxnType',
|
|
177
|
+
AccessListTxnType = 'AccessListTxnType',
|
|
178
|
+
DynamicFeeTxnType = 'DynamicFeeTxnType'
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export enum SortOrder {
|
|
182
|
+
DESC = 'DESC',
|
|
183
|
+
ASC = 'ASC'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export enum ContractVerificationStatus {
|
|
187
|
+
VERIFIED = 'VERIFIED',
|
|
188
|
+
UNVERIFIED = 'UNVERIFIED',
|
|
189
|
+
ALL = 'ALL'
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface Version {
|
|
193
|
+
webrpcVersion: string
|
|
194
|
+
schemaVersion: string
|
|
195
|
+
schemaHash: string
|
|
196
|
+
appVersion: string
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface RuntimeStatus {
|
|
200
|
+
healthOK: boolean
|
|
201
|
+
indexerEnabled: boolean
|
|
202
|
+
startTime: string
|
|
203
|
+
uptime: number
|
|
204
|
+
ver: string
|
|
205
|
+
branch: string
|
|
206
|
+
commitHash: string
|
|
207
|
+
chainID: number
|
|
208
|
+
checks: RuntimeChecks
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface WALWriterRuntimeStatus {
|
|
212
|
+
healthOK: boolean
|
|
213
|
+
startTime: string
|
|
214
|
+
uptime: number
|
|
215
|
+
ver: string
|
|
216
|
+
branch: string
|
|
217
|
+
commitHash: string
|
|
218
|
+
chainID: number
|
|
219
|
+
percentWALWritten: number
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface RuntimeChecks {
|
|
223
|
+
running: boolean
|
|
224
|
+
runnables: any
|
|
225
|
+
cgoEnabled: boolean
|
|
226
|
+
quotaControlEnabled: boolean
|
|
227
|
+
syncMode: string
|
|
228
|
+
percentIndexed: number
|
|
229
|
+
lastBlockNum: number
|
|
230
|
+
lastBlockNumWithState: number
|
|
231
|
+
bloomStatus: BloomStatus
|
|
232
|
+
bond: Bond
|
|
233
|
+
diskUsage: DiskUsage
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface DiskUsage {
|
|
237
|
+
humanReadable: string
|
|
238
|
+
used: number
|
|
239
|
+
size: number
|
|
240
|
+
percent: number
|
|
241
|
+
dirs: {[key: string]: string}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface Bond {
|
|
245
|
+
pebble: PebbleMetrics
|
|
246
|
+
estimatedDiskUsagePerTable: any
|
|
247
|
+
estimatedDiskUsageTotal: string
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface PebbleMetrics {
|
|
251
|
+
compactionCount: number
|
|
252
|
+
compactionEstimatedDebt: number
|
|
253
|
+
compactionInProgressBytes: number
|
|
254
|
+
compactionNumInProgress: number
|
|
255
|
+
compactionMarkedFiles: number
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface BloomStatus {
|
|
259
|
+
enabled: boolean
|
|
260
|
+
initialized: boolean
|
|
261
|
+
bloomInitElapsedTime: string
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface EtherBalance {
|
|
265
|
+
accountAddress: string
|
|
266
|
+
balanceWei: string
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface NativeTokenBalance {
|
|
270
|
+
accountAddress: string
|
|
271
|
+
balance: string
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface IndexState {
|
|
275
|
+
chainId: string
|
|
276
|
+
lastBlockNum: number
|
|
277
|
+
lastBlockHash: string
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface IndexedBlock {
|
|
281
|
+
blockNumber: number
|
|
282
|
+
blockShortHash: string
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface TxnInfo {
|
|
286
|
+
from: string
|
|
287
|
+
to: string
|
|
288
|
+
value: string
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface EventLog {
|
|
292
|
+
id: number
|
|
293
|
+
uid: string
|
|
294
|
+
type: EventLogType
|
|
295
|
+
blockNumber: number
|
|
296
|
+
blockHash: string
|
|
297
|
+
parentBlockHash: string
|
|
298
|
+
contractAddress: string
|
|
299
|
+
contractType: ContractType
|
|
300
|
+
txnHash: string
|
|
301
|
+
txnIndex: number
|
|
302
|
+
txnLogIndex: number
|
|
303
|
+
logDataType: EventLogDataType
|
|
304
|
+
ts: string
|
|
305
|
+
txnInfo?: TxnInfo
|
|
306
|
+
rawLog?: {[key: string]: any}
|
|
307
|
+
event?: EventDecoded
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface EventDecoded {
|
|
311
|
+
topicHash: string
|
|
312
|
+
eventSig: string
|
|
313
|
+
types: Array<string>
|
|
314
|
+
names: Array<string>
|
|
315
|
+
values: Array<string>
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface TokenBalance {
|
|
319
|
+
contractType: ContractType
|
|
320
|
+
contractAddress: string
|
|
321
|
+
accountAddress: string
|
|
322
|
+
tokenID?: string
|
|
323
|
+
balance: string
|
|
324
|
+
blockHash: string
|
|
325
|
+
blockNumber: number
|
|
326
|
+
chainId: number
|
|
327
|
+
uniqueCollectibles: string
|
|
328
|
+
isSummary: boolean
|
|
329
|
+
contractInfo?: ContractInfo
|
|
330
|
+
tokenMetadata?: TokenMetadata
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface OrderbookOrder {
|
|
334
|
+
orderId: string
|
|
335
|
+
tokenContract: string
|
|
336
|
+
tokenId: string
|
|
337
|
+
isListing: boolean
|
|
338
|
+
quantity: string
|
|
339
|
+
quantityRemaining: string
|
|
340
|
+
currencyAddress: string
|
|
341
|
+
pricePerToken: string
|
|
342
|
+
expiry: string
|
|
343
|
+
orderStatus: OrderStatus
|
|
344
|
+
createdBy: string
|
|
345
|
+
blockNumber: number
|
|
346
|
+
orderbookContractAddress: string
|
|
347
|
+
createdAt: number
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface OrderbookOrderFilter {
|
|
351
|
+
isListing?: boolean
|
|
352
|
+
userAddresses?: Array<string>
|
|
353
|
+
tokenIds: Array<string>
|
|
354
|
+
excludeUserAddresses?: Array<string>
|
|
355
|
+
afterBlockNumber: number
|
|
356
|
+
afterCreatedAt: number
|
|
357
|
+
beforeExpiry: number
|
|
358
|
+
userAddress?: string
|
|
359
|
+
excludeUserAddress?: string
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface TokenHistory {
|
|
363
|
+
blockNumber: number
|
|
364
|
+
blockHash: string
|
|
365
|
+
accountAddress: string
|
|
366
|
+
contractAddress: string
|
|
367
|
+
contractType: ContractType
|
|
368
|
+
fromAddress: string
|
|
369
|
+
toAddress: string
|
|
370
|
+
txnHash: string
|
|
371
|
+
txnIndex: number
|
|
372
|
+
txnLogIndex: number
|
|
373
|
+
logData: string
|
|
374
|
+
tokenIDs: string
|
|
375
|
+
Amounts: string
|
|
376
|
+
ts: string
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface TokenSupply {
|
|
380
|
+
tokenID: string
|
|
381
|
+
supply: string
|
|
382
|
+
chainId: number
|
|
383
|
+
contractInfo?: ContractInfo
|
|
384
|
+
tokenMetadata?: TokenMetadata
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface Transaction {
|
|
388
|
+
txnHash: string
|
|
389
|
+
blockNumber: number
|
|
390
|
+
blockHash: string
|
|
391
|
+
chainId: number
|
|
392
|
+
metaTxnID?: string
|
|
393
|
+
transfers?: Array<TxnTransfer>
|
|
394
|
+
timestamp: string
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface TxnTransfer {
|
|
398
|
+
transferType: TxnTransferType
|
|
399
|
+
contractAddress: string
|
|
400
|
+
contractType: ContractType
|
|
401
|
+
from: string
|
|
402
|
+
to: string
|
|
403
|
+
tokenIds?: Array<string>
|
|
404
|
+
amounts: Array<string>
|
|
405
|
+
logIndex: number
|
|
406
|
+
contractInfo?: ContractInfo
|
|
407
|
+
tokenMetadata?: {[key: string]: TokenMetadata}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface TransactionHistoryFilter {
|
|
411
|
+
accountAddress?: string
|
|
412
|
+
contractAddress?: string
|
|
413
|
+
accountAddresses?: Array<string>
|
|
414
|
+
contractAddresses?: Array<string>
|
|
415
|
+
transactionHashes?: Array<string>
|
|
416
|
+
metaTransactionIDs?: Array<string>
|
|
417
|
+
fromBlock?: number
|
|
418
|
+
toBlock?: number
|
|
419
|
+
tokenID?: string
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export interface TransactionFilter {
|
|
423
|
+
txnHash?: string
|
|
424
|
+
from?: string
|
|
425
|
+
to?: string
|
|
426
|
+
contractAddress?: string
|
|
427
|
+
event?: string
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export interface TransactionReceipt {
|
|
431
|
+
txnHash: string
|
|
432
|
+
txnStatus: TransactionStatus
|
|
433
|
+
txnIndex: number
|
|
434
|
+
txnType: TransactionType
|
|
435
|
+
blockHash: string
|
|
436
|
+
blockNumber: number
|
|
437
|
+
gasUsed: number
|
|
438
|
+
effectiveGasPrice: string
|
|
439
|
+
from: string
|
|
440
|
+
to: string
|
|
441
|
+
logs: Array<TransactionLog>
|
|
442
|
+
final: boolean
|
|
443
|
+
reorged: boolean
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface TransactionLog {
|
|
447
|
+
contractAddress: string
|
|
448
|
+
topics: Array<string>
|
|
449
|
+
data: string
|
|
450
|
+
index: number
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface TokenIDRange {
|
|
454
|
+
start: string
|
|
455
|
+
end: string
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface Page {
|
|
459
|
+
page?: number
|
|
460
|
+
column?: string
|
|
461
|
+
before?: any
|
|
462
|
+
after?: any
|
|
463
|
+
sort?: Array<SortBy>
|
|
464
|
+
pageSize?: number
|
|
465
|
+
more?: boolean
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export interface SortBy {
|
|
469
|
+
column: string
|
|
470
|
+
order: SortOrder
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export interface WebhookListener {
|
|
474
|
+
id: number
|
|
475
|
+
projectID: number
|
|
476
|
+
url: string
|
|
477
|
+
filters: EventFilter
|
|
478
|
+
name: string
|
|
479
|
+
updatedAt: string
|
|
480
|
+
active: boolean
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export interface EventFilter {
|
|
484
|
+
events?: Array<string>
|
|
485
|
+
contractAddresses?: Array<string>
|
|
486
|
+
accounts?: Array<string>
|
|
487
|
+
tokenIDs?: Array<string>
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export interface TokenBalanceFilter {
|
|
491
|
+
contractAddress: string
|
|
492
|
+
sinceBlockNumber: number
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export interface MetadataOptions {
|
|
496
|
+
verifiedOnly?: boolean
|
|
497
|
+
unverifiedOnly?: boolean
|
|
498
|
+
includeContracts?: Array<string>
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export interface TokenBalancesFilter {
|
|
502
|
+
accountAddresses: Array<string>
|
|
503
|
+
contractStatus?: ContractVerificationStatus
|
|
504
|
+
contractWhitelist?: Array<string>
|
|
505
|
+
contractBlacklist?: Array<string>
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export interface TokenBalancesByContractFilter {
|
|
509
|
+
contractAddresses: Array<string>
|
|
510
|
+
accountAddresses?: Array<string>
|
|
511
|
+
contractStatus?: ContractVerificationStatus
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export interface GatewayEtherBalance {
|
|
515
|
+
chainId: number
|
|
516
|
+
error: string
|
|
517
|
+
result: EtherBalance
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export interface GatewayNativeTokenBalance {
|
|
521
|
+
chainId: number
|
|
522
|
+
error: string
|
|
523
|
+
result: NativeTokenBalance
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export interface GatewayTokenBalance {
|
|
527
|
+
chainId: number
|
|
528
|
+
error: string
|
|
529
|
+
results: Array<TokenBalance>
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export interface IndexerGateway {
|
|
533
|
+
getNativeTokenBalance(args: GetNativeTokenBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetNativeTokenBalanceReturn>
|
|
534
|
+
getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn>
|
|
535
|
+
getTokenBalancesSummary(args: GetTokenBalancesSummaryArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesSummaryReturn>
|
|
536
|
+
getTokenBalancesDetails(args: GetTokenBalancesDetailsArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesDetailsReturn>
|
|
537
|
+
getTokenBalancesByContract(args: GetTokenBalancesByContractArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesByContractReturn>
|
|
538
|
+
getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn>
|
|
539
|
+
ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>
|
|
540
|
+
version(headers?: object, signal?: AbortSignal): Promise<VersionReturn>
|
|
541
|
+
runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn>
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export interface GetNativeTokenBalanceArgs {
|
|
545
|
+
chainIds?: Array<number>
|
|
546
|
+
accountAddress?: string
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface GetNativeTokenBalanceReturn {
|
|
550
|
+
balances: Array<GatewayNativeTokenBalance>
|
|
551
|
+
}
|
|
552
|
+
export interface GetTokenBalancesArgs {
|
|
553
|
+
chainIds?: Array<number>
|
|
554
|
+
accountAddress?: string
|
|
555
|
+
contractAddress?: string
|
|
556
|
+
tokenID?: string
|
|
557
|
+
includeMetadata?: boolean
|
|
558
|
+
metadataOptions?: MetadataOptions
|
|
559
|
+
includeCollectionTokens?: boolean
|
|
560
|
+
page?: Page
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export interface GetTokenBalancesReturn {
|
|
564
|
+
page: Page
|
|
565
|
+
balances: Array<GatewayTokenBalance>
|
|
566
|
+
}
|
|
567
|
+
export interface GetTokenBalancesSummaryArgs {
|
|
568
|
+
chainIds?: Array<number>
|
|
569
|
+
filter: TokenBalancesFilter
|
|
570
|
+
omitMetadata?: boolean
|
|
571
|
+
page?: Page
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export interface GetTokenBalancesSummaryReturn {
|
|
575
|
+
page: Page
|
|
576
|
+
balances: Array<GatewayTokenBalance>
|
|
577
|
+
}
|
|
578
|
+
export interface GetTokenBalancesDetailsArgs {
|
|
579
|
+
chainIds?: Array<number>
|
|
580
|
+
filter: TokenBalancesFilter
|
|
581
|
+
omitMetadata?: boolean
|
|
582
|
+
page?: Page
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export interface GetTokenBalancesDetailsReturn {
|
|
586
|
+
page: Page
|
|
587
|
+
balances: Array<GatewayTokenBalance>
|
|
588
|
+
}
|
|
589
|
+
export interface GetTokenBalancesByContractArgs {
|
|
590
|
+
chainIds?: Array<number>
|
|
591
|
+
filter: TokenBalancesByContractFilter
|
|
592
|
+
omitMetadata?: boolean
|
|
593
|
+
page?: Page
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export interface GetTokenBalancesByContractReturn {
|
|
597
|
+
page: Page
|
|
598
|
+
balances: Array<GatewayTokenBalance>
|
|
599
|
+
}
|
|
600
|
+
export interface GetBalanceUpdatesArgs {
|
|
601
|
+
chainIds?: Array<number>
|
|
602
|
+
contractAddress: string
|
|
603
|
+
lastBlockNumber: number
|
|
604
|
+
lastBlockHash?: string
|
|
605
|
+
page?: Page
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export interface GetBalanceUpdatesReturn {
|
|
609
|
+
page: Page
|
|
610
|
+
balances: Array<GatewayTokenBalance>
|
|
611
|
+
}
|
|
612
|
+
export interface PingArgs {
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export interface PingReturn {
|
|
616
|
+
status: boolean
|
|
617
|
+
}
|
|
618
|
+
export interface VersionArgs {
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export interface VersionReturn {
|
|
622
|
+
version: Version
|
|
623
|
+
}
|
|
624
|
+
export interface RuntimeStatusArgs {
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export interface RuntimeStatusReturn {
|
|
628
|
+
status: RuntimeStatus
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
//
|
|
634
|
+
// Client
|
|
635
|
+
//
|
|
636
|
+
export class IndexerGateway implements IndexerGateway {
|
|
637
|
+
protected hostname: string
|
|
638
|
+
protected fetch: Fetch
|
|
639
|
+
protected path = '/rpc/IndexerGateway/'
|
|
640
|
+
|
|
641
|
+
constructor(hostname: string, fetch: Fetch) {
|
|
642
|
+
this.hostname = hostname.replace(/\/*$/, '')
|
|
643
|
+
this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
private url(name: string): string {
|
|
647
|
+
return this.hostname + this.path + name
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
getNativeTokenBalance = (args: GetNativeTokenBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetNativeTokenBalanceReturn> => {
|
|
651
|
+
return this.fetch(
|
|
652
|
+
this.url('GetNativeTokenBalance'),
|
|
653
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
654
|
+
return buildResponse(res).then(_data => {
|
|
655
|
+
return {
|
|
656
|
+
balances: <Array<GatewayNativeTokenBalance>>(_data.balances),
|
|
657
|
+
}
|
|
658
|
+
})
|
|
659
|
+
}, (error) => {
|
|
660
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
661
|
+
})
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
getTokenBalances = (args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn> => {
|
|
665
|
+
return this.fetch(
|
|
666
|
+
this.url('GetTokenBalances'),
|
|
667
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
668
|
+
return buildResponse(res).then(_data => {
|
|
669
|
+
return {
|
|
670
|
+
page: <Page>(_data.page),
|
|
671
|
+
balances: <Array<GatewayTokenBalance>>(_data.balances),
|
|
672
|
+
}
|
|
673
|
+
})
|
|
674
|
+
}, (error) => {
|
|
675
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
676
|
+
})
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
getTokenBalancesSummary = (args: GetTokenBalancesSummaryArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesSummaryReturn> => {
|
|
680
|
+
return this.fetch(
|
|
681
|
+
this.url('GetTokenBalancesSummary'),
|
|
682
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
683
|
+
return buildResponse(res).then(_data => {
|
|
684
|
+
return {
|
|
685
|
+
page: <Page>(_data.page),
|
|
686
|
+
balances: <Array<GatewayTokenBalance>>(_data.balances),
|
|
687
|
+
}
|
|
688
|
+
})
|
|
689
|
+
}, (error) => {
|
|
690
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
691
|
+
})
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
getTokenBalancesDetails = (args: GetTokenBalancesDetailsArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesDetailsReturn> => {
|
|
695
|
+
return this.fetch(
|
|
696
|
+
this.url('GetTokenBalancesDetails'),
|
|
697
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
698
|
+
return buildResponse(res).then(_data => {
|
|
699
|
+
return {
|
|
700
|
+
page: <Page>(_data.page),
|
|
701
|
+
balances: <Array<GatewayTokenBalance>>(_data.balances),
|
|
702
|
+
}
|
|
703
|
+
})
|
|
704
|
+
}, (error) => {
|
|
705
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
706
|
+
})
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
getTokenBalancesByContract = (args: GetTokenBalancesByContractArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesByContractReturn> => {
|
|
710
|
+
return this.fetch(
|
|
711
|
+
this.url('GetTokenBalancesByContract'),
|
|
712
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
713
|
+
return buildResponse(res).then(_data => {
|
|
714
|
+
return {
|
|
715
|
+
page: <Page>(_data.page),
|
|
716
|
+
balances: <Array<GatewayTokenBalance>>(_data.balances),
|
|
717
|
+
}
|
|
718
|
+
})
|
|
719
|
+
}, (error) => {
|
|
720
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
721
|
+
})
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn> => {
|
|
725
|
+
return this.fetch(
|
|
726
|
+
this.url('GetBalanceUpdates'),
|
|
727
|
+
createHTTPRequest(args, headers, signal)).then((res) => {
|
|
728
|
+
return buildResponse(res).then(_data => {
|
|
729
|
+
return {
|
|
730
|
+
page: <Page>(_data.page),
|
|
731
|
+
balances: <Array<GatewayTokenBalance>>(_data.balances),
|
|
732
|
+
}
|
|
733
|
+
})
|
|
734
|
+
}, (error) => {
|
|
735
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
|
|
740
|
+
return this.fetch(
|
|
741
|
+
this.url('Ping'),
|
|
742
|
+
createHTTPRequest({}, headers, signal)
|
|
743
|
+
).then((res) => {
|
|
744
|
+
return buildResponse(res).then(_data => {
|
|
745
|
+
return {
|
|
746
|
+
status: <boolean>(_data.status),
|
|
747
|
+
}
|
|
748
|
+
})
|
|
749
|
+
}, (error) => {
|
|
750
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
751
|
+
})
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => {
|
|
755
|
+
return this.fetch(
|
|
756
|
+
this.url('Version'),
|
|
757
|
+
createHTTPRequest({}, headers, signal)
|
|
758
|
+
).then((res) => {
|
|
759
|
+
return buildResponse(res).then(_data => {
|
|
760
|
+
return {
|
|
761
|
+
version: <Version>(_data.version),
|
|
762
|
+
}
|
|
763
|
+
})
|
|
764
|
+
}, (error) => {
|
|
765
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
766
|
+
})
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => {
|
|
770
|
+
return this.fetch(
|
|
771
|
+
this.url('RuntimeStatus'),
|
|
772
|
+
createHTTPRequest({}, headers, signal)
|
|
773
|
+
).then((res) => {
|
|
774
|
+
return buildResponse(res).then(_data => {
|
|
775
|
+
return {
|
|
776
|
+
status: <RuntimeStatus>(_data.status),
|
|
777
|
+
}
|
|
778
|
+
})
|
|
779
|
+
}, (error) => {
|
|
780
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
781
|
+
})
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
|
|
787
|
+
const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' }
|
|
788
|
+
reqHeaders[WebrpcHeader] = WebrpcHeaderValue
|
|
789
|
+
|
|
790
|
+
return {
|
|
791
|
+
method: 'POST',
|
|
792
|
+
headers: reqHeaders,
|
|
793
|
+
body: JSON.stringify(body || {}),
|
|
794
|
+
signal
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const buildResponse = (res: Response): Promise<any> => {
|
|
799
|
+
return res.text().then(text => {
|
|
800
|
+
let data
|
|
801
|
+
try {
|
|
802
|
+
data = JSON.parse(text)
|
|
803
|
+
} catch(error) {
|
|
804
|
+
let message = ''
|
|
805
|
+
if (error instanceof Error) {
|
|
806
|
+
message = error.message
|
|
807
|
+
}
|
|
808
|
+
throw WebrpcBadResponseError.new({
|
|
809
|
+
status: res.status,
|
|
810
|
+
cause: `JSON.parse(): ${message}: response text: ${text}`},
|
|
811
|
+
)
|
|
812
|
+
}
|
|
813
|
+
if (!res.ok) {
|
|
814
|
+
const code: number = (typeof data.code === 'number') ? data.code : 0
|
|
815
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data)
|
|
816
|
+
}
|
|
817
|
+
return data
|
|
818
|
+
})
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
//
|
|
822
|
+
// Errors
|
|
823
|
+
//
|
|
824
|
+
|
|
825
|
+
export class WebrpcError extends Error {
|
|
826
|
+
name: string
|
|
827
|
+
code: number
|
|
828
|
+
message: string
|
|
829
|
+
status: number
|
|
830
|
+
cause?: string
|
|
831
|
+
|
|
832
|
+
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
|
|
833
|
+
msg: string
|
|
834
|
+
|
|
835
|
+
constructor(name: string, code: number, message: string, status: number, cause?: string) {
|
|
836
|
+
super(message)
|
|
837
|
+
this.name = name || 'WebrpcError'
|
|
838
|
+
this.code = typeof code === 'number' ? code : 0
|
|
839
|
+
this.message = message || `endpoint error ${this.code}`
|
|
840
|
+
this.msg = this.message
|
|
841
|
+
this.status = typeof status === 'number' ? status : 0
|
|
842
|
+
this.cause = cause
|
|
843
|
+
Object.setPrototypeOf(this, WebrpcError.prototype)
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
static new(payload: any): WebrpcError {
|
|
847
|
+
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// Webrpc errors
|
|
852
|
+
|
|
853
|
+
export class WebrpcEndpointError extends WebrpcError {
|
|
854
|
+
constructor(
|
|
855
|
+
name: string = 'WebrpcEndpoint',
|
|
856
|
+
code: number = 0,
|
|
857
|
+
message: string = 'endpoint error',
|
|
858
|
+
status: number = 0,
|
|
859
|
+
cause?: string
|
|
860
|
+
) {
|
|
861
|
+
super(name, code, message, status, cause)
|
|
862
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
export class WebrpcRequestFailedError extends WebrpcError {
|
|
867
|
+
constructor(
|
|
868
|
+
name: string = 'WebrpcRequestFailed',
|
|
869
|
+
code: number = -1,
|
|
870
|
+
message: string = 'request failed',
|
|
871
|
+
status: number = 0,
|
|
872
|
+
cause?: string
|
|
873
|
+
) {
|
|
874
|
+
super(name, code, message, status, cause)
|
|
875
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export class WebrpcBadRouteError extends WebrpcError {
|
|
880
|
+
constructor(
|
|
881
|
+
name: string = 'WebrpcBadRoute',
|
|
882
|
+
code: number = -2,
|
|
883
|
+
message: string = 'bad route',
|
|
884
|
+
status: number = 0,
|
|
885
|
+
cause?: string
|
|
886
|
+
) {
|
|
887
|
+
super(name, code, message, status, cause)
|
|
888
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
export class WebrpcBadMethodError extends WebrpcError {
|
|
893
|
+
constructor(
|
|
894
|
+
name: string = 'WebrpcBadMethod',
|
|
895
|
+
code: number = -3,
|
|
896
|
+
message: string = 'bad method',
|
|
897
|
+
status: number = 0,
|
|
898
|
+
cause?: string
|
|
899
|
+
) {
|
|
900
|
+
super(name, code, message, status, cause)
|
|
901
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export class WebrpcBadRequestError extends WebrpcError {
|
|
906
|
+
constructor(
|
|
907
|
+
name: string = 'WebrpcBadRequest',
|
|
908
|
+
code: number = -4,
|
|
909
|
+
message: string = 'bad request',
|
|
910
|
+
status: number = 0,
|
|
911
|
+
cause?: string
|
|
912
|
+
) {
|
|
913
|
+
super(name, code, message, status, cause)
|
|
914
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
export class WebrpcBadResponseError extends WebrpcError {
|
|
919
|
+
constructor(
|
|
920
|
+
name: string = 'WebrpcBadResponse',
|
|
921
|
+
code: number = -5,
|
|
922
|
+
message: string = 'bad response',
|
|
923
|
+
status: number = 0,
|
|
924
|
+
cause?: string
|
|
925
|
+
) {
|
|
926
|
+
super(name, code, message, status, cause)
|
|
927
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
export class WebrpcServerPanicError extends WebrpcError {
|
|
932
|
+
constructor(
|
|
933
|
+
name: string = 'WebrpcServerPanic',
|
|
934
|
+
code: number = -6,
|
|
935
|
+
message: string = 'server panic',
|
|
936
|
+
status: number = 0,
|
|
937
|
+
cause?: string
|
|
938
|
+
) {
|
|
939
|
+
super(name, code, message, status, cause)
|
|
940
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export class WebrpcInternalErrorError extends WebrpcError {
|
|
945
|
+
constructor(
|
|
946
|
+
name: string = 'WebrpcInternalError',
|
|
947
|
+
code: number = -7,
|
|
948
|
+
message: string = 'internal error',
|
|
949
|
+
status: number = 0,
|
|
950
|
+
cause?: string
|
|
951
|
+
) {
|
|
952
|
+
super(name, code, message, status, cause)
|
|
953
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
export class WebrpcClientDisconnectedError extends WebrpcError {
|
|
958
|
+
constructor(
|
|
959
|
+
name: string = 'WebrpcClientDisconnected',
|
|
960
|
+
code: number = -8,
|
|
961
|
+
message: string = 'client disconnected',
|
|
962
|
+
status: number = 0,
|
|
963
|
+
cause?: string
|
|
964
|
+
) {
|
|
965
|
+
super(name, code, message, status, cause)
|
|
966
|
+
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
export class WebrpcStreamLostError extends WebrpcError {
|
|
971
|
+
constructor(
|
|
972
|
+
name: string = 'WebrpcStreamLost',
|
|
973
|
+
code: number = -9,
|
|
974
|
+
message: string = 'stream lost',
|
|
975
|
+
status: number = 0,
|
|
976
|
+
cause?: string
|
|
977
|
+
) {
|
|
978
|
+
super(name, code, message, status, cause)
|
|
979
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export class WebrpcStreamFinishedError extends WebrpcError {
|
|
984
|
+
constructor(
|
|
985
|
+
name: string = 'WebrpcStreamFinished',
|
|
986
|
+
code: number = -10,
|
|
987
|
+
message: string = 'stream finished',
|
|
988
|
+
status: number = 0,
|
|
989
|
+
cause?: string
|
|
990
|
+
) {
|
|
991
|
+
super(name, code, message, status, cause)
|
|
992
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
// Schema errors
|
|
998
|
+
|
|
999
|
+
export class UnauthorizedError extends WebrpcError {
|
|
1000
|
+
constructor(
|
|
1001
|
+
name: string = 'Unauthorized',
|
|
1002
|
+
code: number = 1000,
|
|
1003
|
+
message: string = 'Unauthorized access',
|
|
1004
|
+
status: number = 0,
|
|
1005
|
+
cause?: string
|
|
1006
|
+
) {
|
|
1007
|
+
super(name, code, message, status, cause)
|
|
1008
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype)
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
export class PermissionDeniedError extends WebrpcError {
|
|
1013
|
+
constructor(
|
|
1014
|
+
name: string = 'PermissionDenied',
|
|
1015
|
+
code: number = 1001,
|
|
1016
|
+
message: string = 'Permission denied',
|
|
1017
|
+
status: number = 0,
|
|
1018
|
+
cause?: string
|
|
1019
|
+
) {
|
|
1020
|
+
super(name, code, message, status, cause)
|
|
1021
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export class SessionExpiredError extends WebrpcError {
|
|
1026
|
+
constructor(
|
|
1027
|
+
name: string = 'SessionExpired',
|
|
1028
|
+
code: number = 1002,
|
|
1029
|
+
message: string = 'Session expired',
|
|
1030
|
+
status: number = 0,
|
|
1031
|
+
cause?: string
|
|
1032
|
+
) {
|
|
1033
|
+
super(name, code, message, status, cause)
|
|
1034
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype)
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
export class MethodNotFoundError extends WebrpcError {
|
|
1039
|
+
constructor(
|
|
1040
|
+
name: string = 'MethodNotFound',
|
|
1041
|
+
code: number = 1003,
|
|
1042
|
+
message: string = 'Method not found',
|
|
1043
|
+
status: number = 0,
|
|
1044
|
+
cause?: string
|
|
1045
|
+
) {
|
|
1046
|
+
super(name, code, message, status, cause)
|
|
1047
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype)
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
export class RequestConflictError extends WebrpcError {
|
|
1052
|
+
constructor(
|
|
1053
|
+
name: string = 'RequestConflict',
|
|
1054
|
+
code: number = 1004,
|
|
1055
|
+
message: string = 'Conflict with target resource',
|
|
1056
|
+
status: number = 0,
|
|
1057
|
+
cause?: string
|
|
1058
|
+
) {
|
|
1059
|
+
super(name, code, message, status, cause)
|
|
1060
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype)
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
export class AbortedError extends WebrpcError {
|
|
1065
|
+
constructor(
|
|
1066
|
+
name: string = 'Aborted',
|
|
1067
|
+
code: number = 1005,
|
|
1068
|
+
message: string = 'Request aborted',
|
|
1069
|
+
status: number = 0,
|
|
1070
|
+
cause?: string
|
|
1071
|
+
) {
|
|
1072
|
+
super(name, code, message, status, cause)
|
|
1073
|
+
Object.setPrototypeOf(this, AbortedError.prototype)
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
export class GeoblockedError extends WebrpcError {
|
|
1078
|
+
constructor(
|
|
1079
|
+
name: string = 'Geoblocked',
|
|
1080
|
+
code: number = 1006,
|
|
1081
|
+
message: string = 'Geoblocked region',
|
|
1082
|
+
status: number = 0,
|
|
1083
|
+
cause?: string
|
|
1084
|
+
) {
|
|
1085
|
+
super(name, code, message, status, cause)
|
|
1086
|
+
Object.setPrototypeOf(this, GeoblockedError.prototype)
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
export class RateLimitedError extends WebrpcError {
|
|
1091
|
+
constructor(
|
|
1092
|
+
name: string = 'RateLimited',
|
|
1093
|
+
code: number = 1007,
|
|
1094
|
+
message: string = 'Rate-limited. Please slow down.',
|
|
1095
|
+
status: number = 0,
|
|
1096
|
+
cause?: string
|
|
1097
|
+
) {
|
|
1098
|
+
super(name, code, message, status, cause)
|
|
1099
|
+
Object.setPrototypeOf(this, RateLimitedError.prototype)
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
export class ProjectNotFoundError extends WebrpcError {
|
|
1104
|
+
constructor(
|
|
1105
|
+
name: string = 'ProjectNotFound',
|
|
1106
|
+
code: number = 1100,
|
|
1107
|
+
message: string = 'Project not found',
|
|
1108
|
+
status: number = 0,
|
|
1109
|
+
cause?: string
|
|
1110
|
+
) {
|
|
1111
|
+
super(name, code, message, status, cause)
|
|
1112
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
export class AccessKeyNotFoundError extends WebrpcError {
|
|
1117
|
+
constructor(
|
|
1118
|
+
name: string = 'AccessKeyNotFound',
|
|
1119
|
+
code: number = 1101,
|
|
1120
|
+
message: string = 'Access key not found',
|
|
1121
|
+
status: number = 0,
|
|
1122
|
+
cause?: string
|
|
1123
|
+
) {
|
|
1124
|
+
super(name, code, message, status, cause)
|
|
1125
|
+
Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
export class AccessKeyMismatchError extends WebrpcError {
|
|
1130
|
+
constructor(
|
|
1131
|
+
name: string = 'AccessKeyMismatch',
|
|
1132
|
+
code: number = 1102,
|
|
1133
|
+
message: string = 'Access key mismatch',
|
|
1134
|
+
status: number = 0,
|
|
1135
|
+
cause?: string
|
|
1136
|
+
) {
|
|
1137
|
+
super(name, code, message, status, cause)
|
|
1138
|
+
Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
export class InvalidOriginError extends WebrpcError {
|
|
1143
|
+
constructor(
|
|
1144
|
+
name: string = 'InvalidOrigin',
|
|
1145
|
+
code: number = 1103,
|
|
1146
|
+
message: string = 'Invalid origin for Access Key',
|
|
1147
|
+
status: number = 0,
|
|
1148
|
+
cause?: string
|
|
1149
|
+
) {
|
|
1150
|
+
super(name, code, message, status, cause)
|
|
1151
|
+
Object.setPrototypeOf(this, InvalidOriginError.prototype)
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
export class InvalidServiceError extends WebrpcError {
|
|
1156
|
+
constructor(
|
|
1157
|
+
name: string = 'InvalidService',
|
|
1158
|
+
code: number = 1104,
|
|
1159
|
+
message: string = 'Service not enabled for Access key',
|
|
1160
|
+
status: number = 0,
|
|
1161
|
+
cause?: string
|
|
1162
|
+
) {
|
|
1163
|
+
super(name, code, message, status, cause)
|
|
1164
|
+
Object.setPrototypeOf(this, InvalidServiceError.prototype)
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
export class UnauthorizedUserError extends WebrpcError {
|
|
1169
|
+
constructor(
|
|
1170
|
+
name: string = 'UnauthorizedUser',
|
|
1171
|
+
code: number = 1105,
|
|
1172
|
+
message: string = 'Unauthorized user',
|
|
1173
|
+
status: number = 0,
|
|
1174
|
+
cause?: string
|
|
1175
|
+
) {
|
|
1176
|
+
super(name, code, message, status, cause)
|
|
1177
|
+
Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
export class QuotaExceededError extends WebrpcError {
|
|
1182
|
+
constructor(
|
|
1183
|
+
name: string = 'QuotaExceeded',
|
|
1184
|
+
code: number = 1200,
|
|
1185
|
+
message: string = 'Quota exceeded',
|
|
1186
|
+
status: number = 0,
|
|
1187
|
+
cause?: string
|
|
1188
|
+
) {
|
|
1189
|
+
super(name, code, message, status, cause)
|
|
1190
|
+
Object.setPrototypeOf(this, QuotaExceededError.prototype)
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
export class RateLimitError extends WebrpcError {
|
|
1195
|
+
constructor(
|
|
1196
|
+
name: string = 'RateLimit',
|
|
1197
|
+
code: number = 1201,
|
|
1198
|
+
message: string = 'Rate limit exceeded',
|
|
1199
|
+
status: number = 0,
|
|
1200
|
+
cause?: string
|
|
1201
|
+
) {
|
|
1202
|
+
super(name, code, message, status, cause)
|
|
1203
|
+
Object.setPrototypeOf(this, RateLimitError.prototype)
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export class NoDefaultKeyError extends WebrpcError {
|
|
1208
|
+
constructor(
|
|
1209
|
+
name: string = 'NoDefaultKey',
|
|
1210
|
+
code: number = 1300,
|
|
1211
|
+
message: string = 'No default access key found',
|
|
1212
|
+
status: number = 0,
|
|
1213
|
+
cause?: string
|
|
1214
|
+
) {
|
|
1215
|
+
super(name, code, message, status, cause)
|
|
1216
|
+
Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
export class MaxAccessKeysError extends WebrpcError {
|
|
1221
|
+
constructor(
|
|
1222
|
+
name: string = 'MaxAccessKeys',
|
|
1223
|
+
code: number = 1301,
|
|
1224
|
+
message: string = 'Access keys limit reached',
|
|
1225
|
+
status: number = 0,
|
|
1226
|
+
cause?: string
|
|
1227
|
+
) {
|
|
1228
|
+
super(name, code, message, status, cause)
|
|
1229
|
+
Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
export class AtLeastOneKeyError extends WebrpcError {
|
|
1234
|
+
constructor(
|
|
1235
|
+
name: string = 'AtLeastOneKey',
|
|
1236
|
+
code: number = 1302,
|
|
1237
|
+
message: string = 'You need at least one Access Key',
|
|
1238
|
+
status: number = 0,
|
|
1239
|
+
cause?: string
|
|
1240
|
+
) {
|
|
1241
|
+
super(name, code, message, status, cause)
|
|
1242
|
+
Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
export class TimeoutError extends WebrpcError {
|
|
1247
|
+
constructor(
|
|
1248
|
+
name: string = 'Timeout',
|
|
1249
|
+
code: number = 1900,
|
|
1250
|
+
message: string = 'Request timed out',
|
|
1251
|
+
status: number = 0,
|
|
1252
|
+
cause?: string
|
|
1253
|
+
) {
|
|
1254
|
+
super(name, code, message, status, cause)
|
|
1255
|
+
Object.setPrototypeOf(this, TimeoutError.prototype)
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
export class InvalidArgumentError extends WebrpcError {
|
|
1260
|
+
constructor(
|
|
1261
|
+
name: string = 'InvalidArgument',
|
|
1262
|
+
code: number = 2001,
|
|
1263
|
+
message: string = 'Invalid argument',
|
|
1264
|
+
status: number = 0,
|
|
1265
|
+
cause?: string
|
|
1266
|
+
) {
|
|
1267
|
+
super(name, code, message, status, cause)
|
|
1268
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype)
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
export class UnavailableError extends WebrpcError {
|
|
1273
|
+
constructor(
|
|
1274
|
+
name: string = 'Unavailable',
|
|
1275
|
+
code: number = 2002,
|
|
1276
|
+
message: string = 'Unavailable resource',
|
|
1277
|
+
status: number = 0,
|
|
1278
|
+
cause?: string
|
|
1279
|
+
) {
|
|
1280
|
+
super(name, code, message, status, cause)
|
|
1281
|
+
Object.setPrototypeOf(this, UnavailableError.prototype)
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
export class QueryFailedError extends WebrpcError {
|
|
1286
|
+
constructor(
|
|
1287
|
+
name: string = 'QueryFailed',
|
|
1288
|
+
code: number = 2003,
|
|
1289
|
+
message: string = 'Query failed',
|
|
1290
|
+
status: number = 0,
|
|
1291
|
+
cause?: string
|
|
1292
|
+
) {
|
|
1293
|
+
super(name, code, message, status, cause)
|
|
1294
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype)
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
export class ResourceExhaustedError extends WebrpcError {
|
|
1299
|
+
constructor(
|
|
1300
|
+
name: string = 'ResourceExhausted',
|
|
1301
|
+
code: number = 2004,
|
|
1302
|
+
message: string = 'Resource exhausted',
|
|
1303
|
+
status: number = 0,
|
|
1304
|
+
cause?: string
|
|
1305
|
+
) {
|
|
1306
|
+
super(name, code, message, status, cause)
|
|
1307
|
+
Object.setPrototypeOf(this, ResourceExhaustedError.prototype)
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
export class NotFoundError extends WebrpcError {
|
|
1312
|
+
constructor(
|
|
1313
|
+
name: string = 'NotFound',
|
|
1314
|
+
code: number = 3000,
|
|
1315
|
+
message: string = 'Resource not found',
|
|
1316
|
+
status: number = 0,
|
|
1317
|
+
cause?: string
|
|
1318
|
+
) {
|
|
1319
|
+
super(name, code, message, status, cause)
|
|
1320
|
+
Object.setPrototypeOf(this, NotFoundError.prototype)
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
export class MetadataCallFailedError extends WebrpcError {
|
|
1325
|
+
constructor(
|
|
1326
|
+
name: string = 'MetadataCallFailed',
|
|
1327
|
+
code: number = 3003,
|
|
1328
|
+
message: string = 'Metadata service call failed',
|
|
1329
|
+
status: number = 0,
|
|
1330
|
+
cause?: string
|
|
1331
|
+
) {
|
|
1332
|
+
super(name, code, message, status, cause)
|
|
1333
|
+
Object.setPrototypeOf(this, MetadataCallFailedError.prototype)
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
export enum errors {
|
|
1339
|
+
WebrpcEndpoint = 'WebrpcEndpoint',
|
|
1340
|
+
WebrpcRequestFailed = 'WebrpcRequestFailed',
|
|
1341
|
+
WebrpcBadRoute = 'WebrpcBadRoute',
|
|
1342
|
+
WebrpcBadMethod = 'WebrpcBadMethod',
|
|
1343
|
+
WebrpcBadRequest = 'WebrpcBadRequest',
|
|
1344
|
+
WebrpcBadResponse = 'WebrpcBadResponse',
|
|
1345
|
+
WebrpcServerPanic = 'WebrpcServerPanic',
|
|
1346
|
+
WebrpcInternalError = 'WebrpcInternalError',
|
|
1347
|
+
WebrpcClientDisconnected = 'WebrpcClientDisconnected',
|
|
1348
|
+
WebrpcStreamLost = 'WebrpcStreamLost',
|
|
1349
|
+
WebrpcStreamFinished = 'WebrpcStreamFinished',
|
|
1350
|
+
Unauthorized = 'Unauthorized',
|
|
1351
|
+
PermissionDenied = 'PermissionDenied',
|
|
1352
|
+
SessionExpired = 'SessionExpired',
|
|
1353
|
+
MethodNotFound = 'MethodNotFound',
|
|
1354
|
+
RequestConflict = 'RequestConflict',
|
|
1355
|
+
Aborted = 'Aborted',
|
|
1356
|
+
Geoblocked = 'Geoblocked',
|
|
1357
|
+
RateLimited = 'RateLimited',
|
|
1358
|
+
ProjectNotFound = 'ProjectNotFound',
|
|
1359
|
+
AccessKeyNotFound = 'AccessKeyNotFound',
|
|
1360
|
+
AccessKeyMismatch = 'AccessKeyMismatch',
|
|
1361
|
+
InvalidOrigin = 'InvalidOrigin',
|
|
1362
|
+
InvalidService = 'InvalidService',
|
|
1363
|
+
UnauthorizedUser = 'UnauthorizedUser',
|
|
1364
|
+
QuotaExceeded = 'QuotaExceeded',
|
|
1365
|
+
RateLimit = 'RateLimit',
|
|
1366
|
+
NoDefaultKey = 'NoDefaultKey',
|
|
1367
|
+
MaxAccessKeys = 'MaxAccessKeys',
|
|
1368
|
+
AtLeastOneKey = 'AtLeastOneKey',
|
|
1369
|
+
Timeout = 'Timeout',
|
|
1370
|
+
InvalidArgument = 'InvalidArgument',
|
|
1371
|
+
Unavailable = 'Unavailable',
|
|
1372
|
+
QueryFailed = 'QueryFailed',
|
|
1373
|
+
ResourceExhausted = 'ResourceExhausted',
|
|
1374
|
+
NotFound = 'NotFound',
|
|
1375
|
+
MetadataCallFailed = 'MetadataCallFailed',
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
const webrpcErrorByCode: { [code: number]: any } = {
|
|
1379
|
+
[0]: WebrpcEndpointError,
|
|
1380
|
+
[-1]: WebrpcRequestFailedError,
|
|
1381
|
+
[-2]: WebrpcBadRouteError,
|
|
1382
|
+
[-3]: WebrpcBadMethodError,
|
|
1383
|
+
[-4]: WebrpcBadRequestError,
|
|
1384
|
+
[-5]: WebrpcBadResponseError,
|
|
1385
|
+
[-6]: WebrpcServerPanicError,
|
|
1386
|
+
[-7]: WebrpcInternalErrorError,
|
|
1387
|
+
[-8]: WebrpcClientDisconnectedError,
|
|
1388
|
+
[-9]: WebrpcStreamLostError,
|
|
1389
|
+
[-10]: WebrpcStreamFinishedError,
|
|
1390
|
+
[1000]: UnauthorizedError,
|
|
1391
|
+
[1001]: PermissionDeniedError,
|
|
1392
|
+
[1002]: SessionExpiredError,
|
|
1393
|
+
[1003]: MethodNotFoundError,
|
|
1394
|
+
[1004]: RequestConflictError,
|
|
1395
|
+
[1005]: AbortedError,
|
|
1396
|
+
[1006]: GeoblockedError,
|
|
1397
|
+
[1007]: RateLimitedError,
|
|
1398
|
+
[1100]: ProjectNotFoundError,
|
|
1399
|
+
[1101]: AccessKeyNotFoundError,
|
|
1400
|
+
[1102]: AccessKeyMismatchError,
|
|
1401
|
+
[1103]: InvalidOriginError,
|
|
1402
|
+
[1104]: InvalidServiceError,
|
|
1403
|
+
[1105]: UnauthorizedUserError,
|
|
1404
|
+
[1200]: QuotaExceededError,
|
|
1405
|
+
[1201]: RateLimitError,
|
|
1406
|
+
[1300]: NoDefaultKeyError,
|
|
1407
|
+
[1301]: MaxAccessKeysError,
|
|
1408
|
+
[1302]: AtLeastOneKeyError,
|
|
1409
|
+
[1900]: TimeoutError,
|
|
1410
|
+
[2001]: InvalidArgumentError,
|
|
1411
|
+
[2002]: UnavailableError,
|
|
1412
|
+
[2003]: QueryFailedError,
|
|
1413
|
+
[2004]: ResourceExhaustedError,
|
|
1414
|
+
[3000]: NotFoundError,
|
|
1415
|
+
[3003]: MetadataCallFailedError,
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
|
|
1419
|
+
|