@0xsequence/indexer 3.0.0-beta.8 → 3.0.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.
@@ -1,79 +1,166 @@
1
1
  /* eslint-disable */
2
- // sequence-indexer v0.4.0 5be4a3e78d9c7e0cc378c675ec01c518e83772e3
2
+ // sequence-indexer v0.4.0 212120aad9a46e88ead9a2183c5717e9902d8c2b
3
3
  // --
4
- // Code generated by webrpc-gen@v0.21.1 with typescript generator. DO NOT EDIT.
4
+ // Code generated by Webrpc-gen@v0.31.2 with typescript generator. DO NOT EDIT.
5
5
  //
6
- // webrpc-gen -schema=indexer.ridl -service=IndexerGateway -target=typescript -client -out=./clients/indexergw.gen.ts
6
+ // webrpc-gen -schema=merged.gen.json -service=IndexerGateway -target=typescript -client -out=./clients/indexergw.gen.ts
7
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'
8
+ // Webrpc description and code-gen version
9
+ export const WebrpcVersion = 'v1'
14
10
 
15
11
  // Schema version of your RIDL schema
16
- export const WebRPCSchemaVersion = 'v0.4.0'
12
+ export const WebrpcSchemaVersion = 'v0.4.0'
17
13
 
18
14
  // Schema hash generated from your RIDL schema
19
- export const WebRPCSchemaHash = '5be4a3e78d9c7e0cc378c675ec01c518e83772e3'
15
+ export const WebrpcSchemaHash = '212120aad9a46e88ead9a2183c5717e9902d8c2b'
20
16
 
21
- type WebrpcGenVersions = {
22
- webrpcGenVersion: string
23
- codeGenName: string
24
- codeGenVersion: string
25
- schemaName: string
26
- schemaVersion: string
27
- }
17
+ //
18
+ // Client interface
19
+ //
28
20
 
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
- }
21
+ export interface IndexerGatewayClient {
22
+ /**
23
+ * GetTokenBalances returns a balance summary/details for an specific account
24
+ * on all indexer nodes. By default if accountAddress is left empty, it will
25
+ * use the account from the jwt session.
26
+ */
27
+ getBalanceUpdates(req: GetBalanceUpdatesRequest, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesResponse>
28
+
29
+ /**
30
+ * GetChains returns a list of chains with their ID and name
31
+ */
32
+ getChains(req: GetChainsRequest, headers?: object, signal?: AbortSignal): Promise<GetChainsResponse>
33
+
34
+ /**
35
+ * GetNativeTokenBalance queries indexer nodes for the latest native token
36
+ * account balance.
37
+ */
38
+ getNativeTokenBalance(
39
+ req: GetNativeTokenBalanceRequest,
40
+ headers?: object,
41
+ signal?: AbortSignal
42
+ ): Promise<GetNativeTokenBalanceResponse>
43
+
44
+ /**
45
+ * GetTokenBalances returns a balance summary/details for a specific account
46
+ * on all indexer nodes. By default if accountAddress is left empty, it will
47
+ * use the account from the jwt session.
48
+ *
49
+ * @deprecated Use GetTokenBalancesSummary or GetTokenBalancesDetails instead.
50
+ */
51
+ getTokenBalances(req: GetTokenBalancesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesResponse>
52
+
53
+ /**
54
+ * GetTokenBalancesByContract returns a balances for specific accounts and
55
+ * contracts on all indexer nodes. The collection ERC721 & ERC1155 tokens are
56
+ * represented as individual balances.
57
+ */
58
+ getTokenBalancesByContract(
59
+ req: GetTokenBalancesByContractRequest,
60
+ headers?: object,
61
+ signal?: AbortSignal
62
+ ): Promise<GetTokenBalancesByContractResponse>
63
+
64
+ /**
65
+ * GetTokenBalancesDetails returns a detailed balance summary for the given
66
+ * accounts on all indexer nodes. The collection ERC721 & ERC1155 tokens are
67
+ * represented as individual balances.
68
+ */
69
+ getTokenBalancesDetails(
70
+ req: GetTokenBalancesDetailsRequest,
71
+ headers?: object,
72
+ signal?: AbortSignal
73
+ ): Promise<GetTokenBalancesDetailsResponse>
74
+
75
+ /**
76
+ * GetTokenBalancesSummary returns a summary of token balances for the given
77
+ * accounts on all indexer nodes. The collection ERC721 & ERC1155 tokens are
78
+ * represented as a single aggregated balance.
79
+ */
80
+ getTokenBalancesSummary(
81
+ req: GetTokenBalancesSummaryRequest,
82
+ headers?: object,
83
+ signal?: AbortSignal
84
+ ): Promise<GetTokenBalancesSummaryResponse>
40
85
 
41
- return parseWebrpcGenVersions(headerValue)
42
- }
86
+ getTokenPrice(req: GetTokenPriceRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPriceResponse>
43
87
 
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
- }
88
+ getTokenPrices(req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse>
55
89
 
56
- const [_, webrpcGenVersion] = versions[0]!.split('@')
57
- const [codeGenName, codeGenVersion] = versions[1]!.split('@')
58
- const [schemaName, schemaVersion] = versions[2]!.split('@')
90
+ /**
91
+ * GetTransactionHistory returns the history of mined transactions for the
92
+ * given account on all indexer nodes, which includes a list of token transfer
93
+ * (sent/received) , and sent transactions from a Sequence wallet.
94
+ */
95
+ getTransactionHistory(
96
+ req: GetTransactionHistoryRequest,
97
+ headers?: object,
98
+ signal?: AbortSignal
99
+ ): Promise<GetTransactionHistoryResponse>
59
100
 
60
- return {
61
- webrpcGenVersion: webrpcGenVersion!,
62
- codeGenName: codeGenName!,
63
- codeGenVersion: codeGenVersion!,
64
- schemaName: schemaName!,
65
- schemaVersion: schemaVersion!,
66
- }
101
+ /**
102
+ * Ping the indexer
103
+ */
104
+ ping(headers?: object, signal?: AbortSignal): Promise<PingResponse>
105
+
106
+ /**
107
+ * Get the current runtime health status of the indexer gatewya
108
+ */
109
+ runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse>
110
+
111
+ /**
112
+ * Get the current version of the indexer
113
+ */
114
+ version(headers?: object, signal?: AbortSignal): Promise<VersionResponse>
67
115
  }
68
116
 
69
117
  //
70
- // Types
118
+ // Schema types
71
119
  //
72
120
 
73
- export enum ResourceStatus {
74
- NOT_AVAILABLE = 'NOT_AVAILABLE',
75
- REFRESHING = 'REFRESHING',
76
- AVAILABLE = 'AVAILABLE',
121
+ export interface Asset {
122
+ id: number
123
+ collectionId: number
124
+ tokenId?: string
125
+ url?: string
126
+ metadataField: string
127
+ name?: string
128
+ filesize?: number
129
+ mimeType?: string
130
+ width?: number
131
+ height?: number
132
+ updatedAt?: string
133
+ }
134
+
135
+ export enum BackupMode {
136
+ INCREMENTAL = 'INCREMENTAL',
137
+ COMPLETE = 'COMPLETE'
138
+ }
139
+
140
+ export interface BloomStats {
141
+ hitRatio: string
142
+ falsePositivesPercent: string
143
+ hitCount: number
144
+ missCount: number
145
+ falsePositives: number
146
+ }
147
+
148
+ export interface BloomStatus {
149
+ enabled: boolean
150
+ initialized: boolean
151
+ bloomInitElapsedTime: string
152
+ stats: BloomStats
153
+ }
154
+
155
+ export interface Bond {
156
+ pebble: PebbleMetrics
157
+ estimatedDiskUsagePerTable: any
158
+ estimatedDiskUsageTotal: string
159
+ }
160
+
161
+ export interface ChainInfo {
162
+ chainId: number
163
+ chainName: string
77
164
  }
78
165
 
79
166
  export interface ContractInfo {
@@ -93,56 +180,29 @@ export interface ContractInfo {
93
180
  status: ResourceStatus
94
181
  }
95
182
 
96
- export interface ContractInfoExtensions {
97
- link: string
98
- description: string
99
- categories: Array<string>
100
- ogImage: string
101
- ogName: string
102
- originChainId: number
103
- originAddress: string
104
- blacklist: boolean
105
- verified: boolean
106
- verifiedBy: string
107
- featured: boolean
108
- featureIndex: number
183
+ export interface ContractInfoExtensionBridgeInfo {
184
+ tokenAddress: string
109
185
  }
110
186
 
111
- export interface TokenMetadata {
112
- contractAddress?: string
113
- tokenId: string
114
- source: string
115
- name: string
116
- description?: string
117
- image?: string
118
- video?: string
119
- audio?: string
120
- properties?: { [key: string]: any }
121
- attributes: Array<{ [key: string]: any }>
122
- image_data?: string
123
- external_url?: string
124
- background_color?: string
125
- animation_url?: string
126
- decimals?: number
127
- updatedAt?: string
128
- assets?: Array<Asset>
129
- status: ResourceStatus
130
- queuedAt?: string
131
- lastFetched?: string
187
+ export interface ContractInfoExtensionIndexingInfo {
188
+ useOnChainBalance: boolean
132
189
  }
133
190
 
134
- export interface Asset {
135
- id: number
136
- collectionId: number
137
- tokenId?: string
138
- url?: string
139
- metadataField: string
140
- name?: string
141
- filesize?: number
142
- mimeType?: string
143
- width?: number
144
- height?: number
145
- updatedAt?: string
191
+ export interface ContractInfoExtensions {
192
+ link?: string
193
+ description?: string
194
+ categories?: Array<string>
195
+ bridgeInfo?: { [key: string]: ContractInfoExtensionBridgeInfo }
196
+ indexingInfo?: ContractInfoExtensionIndexingInfo
197
+ ogImage?: string
198
+ ogName?: string
199
+ originChainId?: number
200
+ originAddress?: string
201
+ blacklist?: boolean
202
+ verified?: boolean
203
+ verifiedBy?: string
204
+ featured?: boolean
205
+ featureIndex?: number
146
206
  }
147
207
 
148
208
  export enum ContractType {
@@ -156,72 +216,73 @@ export enum ContractType {
156
216
  ERC721_BRIDGE = 'ERC721_BRIDGE',
157
217
  ERC1155_BRIDGE = 'ERC1155_BRIDGE',
158
218
  SEQ_MARKETPLACE = 'SEQ_MARKETPLACE',
219
+ ERC6909 = 'ERC6909'
159
220
  }
160
221
 
161
- export enum EventLogType {
162
- UNKNOWN = 'UNKNOWN',
163
- BLOCK_ADDED = 'BLOCK_ADDED',
164
- BLOCK_REMOVED = 'BLOCK_REMOVED',
165
- }
166
-
167
- export enum EventLogDataType {
168
- EVENT = 'EVENT',
169
- TOKEN_TRANSFER = 'TOKEN_TRANSFER',
170
- NATIVE_TOKEN_TRANSFER = 'NATIVE_TOKEN_TRANSFER',
171
- SEQUENCE_TXN = 'SEQUENCE_TXN',
172
- }
173
-
174
- export enum OrderStatus {
175
- OPEN = 'OPEN',
176
- CLOSED = 'CLOSED',
177
- CANCELLED = 'CANCELLED',
222
+ export enum ContractVerificationStatus {
223
+ VERIFIED = 'VERIFIED',
224
+ UNVERIFIED = 'UNVERIFIED',
225
+ ALL = 'ALL'
178
226
  }
179
227
 
180
- export enum TxnTransferType {
181
- UNKNOWN = 'UNKNOWN',
182
- SEND = 'SEND',
183
- RECEIVE = 'RECEIVE',
228
+ export interface DiskUsage {
229
+ humanReadable: string
230
+ used: number
231
+ size: number
232
+ percent: number
233
+ dirs: { [key: string]: string }
184
234
  }
185
235
 
186
- export enum TransactionStatus {
187
- FAILED = 'FAILED',
188
- SUCCESSFUL = 'SUCCESSFUL',
236
+ export interface EtherBalance {
237
+ accountAddress: string
238
+ balanceWei: string
189
239
  }
190
240
 
191
- export enum TransactionType {
192
- LegacyTxnType = 'LegacyTxnType',
193
- AccessListTxnType = 'AccessListTxnType',
194
- DynamicFeeTxnType = 'DynamicFeeTxnType',
241
+ export interface EventDecoded {
242
+ topicHash: string
243
+ eventSig: string
244
+ types: Array<string>
245
+ names: Array<string>
246
+ values: Array<string>
195
247
  }
196
248
 
197
- export enum SortOrder {
198
- DESC = 'DESC',
199
- ASC = 'ASC',
249
+ export interface EventFilter {
250
+ events?: Array<string>
251
+ contractAddresses?: Array<string>
252
+ accounts?: Array<string>
253
+ tokenIDs?: Array<string>
200
254
  }
201
255
 
202
- export enum ContractVerificationStatus {
203
- VERIFIED = 'VERIFIED',
204
- UNVERIFIED = 'UNVERIFIED',
205
- ALL = 'ALL',
256
+ export interface EventLog {
257
+ id: number
258
+ uid: string
259
+ type: EventLogType
260
+ blockNumber: number
261
+ blockHash: string
262
+ parentBlockHash: string
263
+ contractAddress: string
264
+ contractType: ContractType
265
+ txnHash: string
266
+ txnIndex: number
267
+ txnLogIndex: number
268
+ logDataType: EventLogDataType
269
+ ts: string
270
+ txnInfo?: TxnInfo
271
+ rawLog?: { [key: string]: any }
272
+ event?: EventDecoded
206
273
  }
207
274
 
208
- export interface Version {
209
- webrpcVersion: string
210
- schemaVersion: string
211
- schemaHash: string
212
- appVersion: string
275
+ export enum EventLogDataType {
276
+ EVENT = 'EVENT',
277
+ TOKEN_TRANSFER = 'TOKEN_TRANSFER',
278
+ NATIVE_TOKEN_TRANSFER = 'NATIVE_TOKEN_TRANSFER',
279
+ SEQUENCE_TXN = 'SEQUENCE_TXN'
213
280
  }
214
281
 
215
- export interface RuntimeStatus {
216
- healthOK: boolean
217
- indexerEnabled: boolean
218
- startTime: string
219
- uptime: number
220
- ver: string
221
- branch: string
222
- commitHash: string
223
- chainID: number
224
- checks: RuntimeChecks
282
+ export enum EventLogType {
283
+ UNKNOWN = 'UNKNOWN',
284
+ BLOCK_ADDED = 'BLOCK_ADDED',
285
+ BLOCK_REMOVED = 'BLOCK_REMOVED'
225
286
  }
226
287
 
227
288
  export interface GatewayBackendResponseTime {
@@ -235,6 +296,30 @@ export interface GatewayBackendRuntimeStatus {
235
296
  responseTime: GatewayBackendResponseTime
236
297
  }
237
298
 
299
+ export interface GatewayEtherBalance {
300
+ chainId: number
301
+ errorReason?: string
302
+ result: EtherBalance
303
+ }
304
+
305
+ export interface GatewayNativeTokenBalance {
306
+ chainId: number
307
+ errorReason?: string
308
+ result: NativeTokenBalance
309
+ }
310
+
311
+ export interface GatewayNativeTokenBalances {
312
+ chainId: number
313
+ errorReason?: string
314
+ results: Array<NativeTokenBalance>
315
+ }
316
+
317
+ export interface GatewayPrice {
318
+ chainID: number
319
+ errorReason?: string
320
+ results: Array<Price>
321
+ }
322
+
238
323
  export interface GatewayRuntimeStatus {
239
324
  healthOK: boolean
240
325
  startTime: string
@@ -245,113 +330,173 @@ export interface GatewayRuntimeStatus {
245
330
  backends: Array<GatewayBackendRuntimeStatus>
246
331
  }
247
332
 
248
- export interface WALWriterRuntimeStatus {
249
- healthOK: boolean
250
- startTime: string
251
- uptime: number
252
- ver: string
253
- branch: string
254
- commitHash: string
333
+ export interface GatewayTokenBalance {
334
+ chainId: number
335
+ errorReason?: string
336
+ results: Array<TokenBalance>
337
+ }
338
+
339
+ export interface GatewayTokenPriceQuery {
255
340
  chainID: number
256
- percentWALWritten: number
341
+ queries: Array<TokenPriceQuery>
257
342
  }
258
343
 
259
- export interface RuntimeChecks {
260
- running: boolean
261
- runnables: any
262
- cgoEnabled: boolean
263
- quotaControlEnabled: boolean
264
- syncMode: string
265
- percentIndexed: number
344
+ export interface GatewayTransaction {
345
+ chainId: number
346
+ errorReason?: string
347
+ results: Array<Transaction>
348
+ }
349
+
350
+ export interface IndexState {
351
+ chainId: string
266
352
  lastBlockNum: number
267
- lastBlockNumWithState: number
268
- bloomStatus: BloomStatus
269
- bond: Bond
270
- diskUsage: DiskUsage
353
+ lastBlockHash: string
271
354
  }
272
355
 
273
- export interface DiskUsage {
274
- humanReadable: string
275
- used: number
276
- size: number
277
- percent: number
278
- dirs: { [key: string]: string }
356
+ export interface IndexedBlock {
357
+ blockNumber: number
358
+ blockShortHash: string
279
359
  }
280
360
 
281
- export interface Bond {
282
- pebble: PebbleMetrics
283
- estimatedDiskUsagePerTable: any
284
- estimatedDiskUsageTotal: string
361
+ export interface IndexerMetrics {
362
+ blocksPerSecond: number
363
+ eventsPerSecond: number
285
364
  }
286
365
 
287
- export interface PebbleMetrics {
288
- compactionCount: number
289
- compactionEstimatedDebt: number
290
- compactionInProgressBytes: number
291
- compactionNumInProgress: number
292
- compactionMarkedFiles: number
366
+ export interface MarketplaceOrder {
367
+ orderId: string
368
+ tokenContract: string
369
+ tokenId: string
370
+ isListing: boolean
371
+ quantity: string
372
+ quantityRemaining: string
373
+ currencyAddress: string
374
+ pricePerToken: string
375
+ expiry: string
376
+ orderStatus: OrderStatus
377
+ createdBy: string
378
+ blockNumber: number
379
+ orderbookContractAddress: string
380
+ createdAt: number
293
381
  }
294
382
 
295
- export interface BloomStatus {
296
- enabled: boolean
297
- initialized: boolean
298
- bloomInitElapsedTime: string
383
+ export interface MarketplaceOrderFilter {
384
+ isListing?: boolean
385
+ userAddresses?: Array<string>
386
+ currencyAddresses: Array<string>
387
+ orderIds: Array<string>
388
+ tokenIds: Array<string>
389
+ excludeUserAddresses?: Array<string>
390
+ blockNumberGt: number
391
+ createdAtAfter: number
392
+ orderStatuses: Array<OrderStatus>
393
+ returnExpired: boolean
299
394
  }
300
395
 
301
- export interface EtherBalance {
302
- accountAddress: string
303
- balanceWei: string
396
+ export interface MarketplaceTopOrdersFilter {
397
+ currencyAddresses: Array<string>
398
+ tokenIds: Array<string>
399
+ isListing: boolean
400
+ priceSort: SortOrder
401
+ excludeUser?: string
402
+ }
403
+
404
+ export interface MetadataOptions {
405
+ verifiedOnly?: boolean
406
+ unverifiedOnly?: boolean
407
+ includeContracts?: Array<string>
304
408
  }
305
409
 
306
410
  export interface NativeTokenBalance {
307
411
  accountAddress: string
308
412
  chainId: number
413
+ name: string
414
+ symbol: string
309
415
  balance: string
310
- error: string
416
+ balanceUSD: string
417
+ priceUSD: string
418
+ priceUpdatedAt?: string
419
+ errorReason?: string
311
420
  }
312
421
 
313
- export interface IndexState {
314
- chainId: string
315
- lastBlockNum: number
316
- lastBlockHash: string
422
+ export enum NetworkType {
423
+ MAINNETS = 'MAINNETS',
424
+ TESTNETS = 'TESTNETS',
425
+ ALL = 'ALL'
317
426
  }
318
427
 
319
- export interface IndexedBlock {
320
- blockNumber: number
321
- blockShortHash: string
428
+ export enum OrderStatus {
429
+ OPEN = 'OPEN',
430
+ CLOSED = 'CLOSED',
431
+ CANCELLED = 'CANCELLED'
322
432
  }
323
433
 
324
- export interface TxnInfo {
325
- from: string
326
- to: string
327
- value: string
434
+ export interface Page {
435
+ page?: number
436
+ column?: string
437
+ before?: any
438
+ after?: any
439
+ sort?: Array<SortBy>
440
+ pageSize?: number
441
+ more?: boolean
328
442
  }
329
443
 
330
- export interface EventLog {
331
- id: number
332
- uid: string
333
- type: EventLogType
334
- blockNumber: number
335
- blockHash: string
336
- parentBlockHash: string
444
+ export interface PebbleMetrics {
445
+ compactionCount: number
446
+ compactionEstimatedDebt: number
447
+ compactionInProgressBytes: number
448
+ compactionNumInProgress: number
449
+ compactionMarkedFiles: number
450
+ }
451
+
452
+ export interface Price {
337
453
  contractAddress: string
338
- contractType: ContractType
339
- txnHash: string
340
- txnIndex: number
341
- txnLogIndex: number
342
- logDataType: EventLogDataType
343
- ts: string
344
- txnInfo?: TxnInfo
345
- rawLog?: { [key: string]: any }
346
- event?: EventDecoded
454
+ tokenID?: string
455
+ priceUSD: string
456
+ updatedAt?: string
347
457
  }
348
458
 
349
- export interface EventDecoded {
350
- topicHash: string
351
- eventSig: string
352
- types: Array<string>
353
- names: Array<string>
354
- values: Array<string>
459
+ export enum ResourceStatus {
460
+ NOT_AVAILABLE = 'NOT_AVAILABLE',
461
+ REFRESHING = 'REFRESHING',
462
+ AVAILABLE = 'AVAILABLE'
463
+ }
464
+
465
+ export interface RuntimeChecks {
466
+ running: boolean
467
+ runnables: any
468
+ cgoEnabled: boolean
469
+ quotaControlEnabled: boolean
470
+ syncMode: string
471
+ percentIndexed: number
472
+ lastBlockNum: number
473
+ lastBlockNumWithState: number
474
+ bloomStatus: BloomStatus
475
+ bond: Bond
476
+ diskUsage: DiskUsage
477
+ metrics: IndexerMetrics
478
+ }
479
+
480
+ export interface RuntimeStatus {
481
+ healthOK: boolean
482
+ indexerEnabled: boolean
483
+ startTime: string
484
+ uptime: number
485
+ ver: string
486
+ branch: string
487
+ commitHash: string
488
+ chainID: number
489
+ checks: RuntimeChecks
490
+ }
491
+
492
+ export interface SortBy {
493
+ column: string
494
+ order: SortOrder
495
+ }
496
+
497
+ export enum SortOrder {
498
+ DESC = 'DESC',
499
+ ASC = 'ASC'
355
500
  }
356
501
 
357
502
  export interface TokenBalance {
@@ -360,6 +505,9 @@ export interface TokenBalance {
360
505
  accountAddress: string
361
506
  tokenID?: string
362
507
  balance: string
508
+ balanceUSD: string
509
+ priceUSD: string
510
+ priceUpdatedAt?: string
363
511
  blockHash: string
364
512
  blockNumber: number
365
513
  chainId: number
@@ -369,39 +517,32 @@ export interface TokenBalance {
369
517
  tokenMetadata?: TokenMetadata
370
518
  }
371
519
 
372
- export interface OrderbookOrder {
373
- orderId: string
374
- tokenContract: string
375
- tokenId: string
376
- isListing: boolean
377
- quantity: string
378
- quantityRemaining: string
379
- currencyAddress: string
380
- pricePerToken: string
381
- expiry: string
382
- orderStatus: OrderStatus
383
- createdBy: string
384
- blockNumber: number
385
- orderbookContractAddress: string
386
- createdAt: number
520
+ export interface TokenBalanceFilter {
521
+ contractAddress: string
522
+ sinceBlockNumber: number
387
523
  }
388
524
 
389
- export interface OrderbookOrderFilter {
390
- isListing?: boolean
391
- userAddresses?: Array<string>
392
- tokenIds: Array<string>
393
- excludeUserAddresses?: Array<string>
394
- afterBlockNumber: number
395
- afterCreatedAt: number
396
- beforeExpiry: number
397
- userAddress?: string
398
- excludeUserAddress?: string
525
+ export interface TokenBalancesByContractFilter {
526
+ contractAddresses: Array<string>
527
+ accountAddresses?: Array<string>
528
+ contractStatus?: ContractVerificationStatus
529
+ tokenIDs?: Array<string>
530
+ }
531
+
532
+ export interface TokenBalancesFilter {
533
+ accountAddresses: Array<string>
534
+ contractStatus?: ContractVerificationStatus
535
+ contractTypes?: Array<string>
536
+ contractWhitelist?: Array<string>
537
+ contractBlacklist?: Array<string>
538
+ omitNativeBalances: boolean
539
+ omitPrices?: boolean
540
+ tokenIDs?: Array<string>
399
541
  }
400
542
 
401
543
  export interface TokenHistory {
402
544
  blockNumber: number
403
545
  blockHash: string
404
- accountAddress: string
405
546
  contractAddress: string
406
547
  contractType: ContractType
407
548
  fromAddress: string
@@ -409,12 +550,45 @@ export interface TokenHistory {
409
550
  txnHash: string
410
551
  txnIndex: number
411
552
  txnLogIndex: number
412
- logData: string
413
553
  tokenIDs: string
414
- Amounts: string
554
+ amounts: string
415
555
  ts: string
416
556
  }
417
557
 
558
+ export interface TokenIDRange {
559
+ start: string
560
+ end: string
561
+ }
562
+
563
+ export interface TokenMetadata {
564
+ chainId?: number
565
+ contractAddress?: string
566
+ tokenId: string
567
+ source: string
568
+ name: string
569
+ description?: string
570
+ image?: string
571
+ video?: string
572
+ audio?: string
573
+ properties?: { [key: string]: any }
574
+ attributes: Array<{ [key: string]: any }>
575
+ image_data?: string
576
+ external_url?: string
577
+ background_color?: string
578
+ animation_url?: string
579
+ decimals?: number
580
+ updatedAt?: string
581
+ assets?: Array<Asset>
582
+ status: ResourceStatus
583
+ queuedAt?: string
584
+ lastFetched?: string
585
+ }
586
+
587
+ export interface TokenPriceQuery {
588
+ contractAddress: string
589
+ tokenID?: string
590
+ }
591
+
418
592
  export interface TokenSupply {
419
593
  tokenID: string
420
594
  supply: string
@@ -433,17 +607,12 @@ export interface Transaction {
433
607
  timestamp: string
434
608
  }
435
609
 
436
- export interface TxnTransfer {
437
- transferType: TxnTransferType
438
- contractAddress: string
439
- contractType: ContractType
440
- from: string
441
- to: string
442
- tokenIds?: Array<string>
443
- amounts: Array<string>
444
- logIndex: number
445
- contractInfo?: ContractInfo
446
- tokenMetadata?: { [key: string]: TokenMetadata }
610
+ export interface TransactionFilter {
611
+ txnHash?: string
612
+ from?: string
613
+ to?: string
614
+ contractAddress?: string
615
+ event?: string
447
616
  }
448
617
 
449
618
  export interface TransactionHistoryFilter {
@@ -456,14 +625,14 @@ export interface TransactionHistoryFilter {
456
625
  fromBlock?: number
457
626
  toBlock?: number
458
627
  tokenID?: string
628
+ omitPrices?: boolean
459
629
  }
460
630
 
461
- export interface TransactionFilter {
462
- txnHash?: string
463
- from?: string
464
- to?: string
465
- contractAddress?: string
466
- event?: string
631
+ export interface TransactionLog {
632
+ contractAddress: string
633
+ topics: Array<string>
634
+ data: string
635
+ index: number
467
636
  }
468
637
 
469
638
  export interface TransactionReceipt {
@@ -482,31 +651,60 @@ export interface TransactionReceipt {
482
651
  reorged: boolean
483
652
  }
484
653
 
485
- export interface TransactionLog {
654
+ export enum TransactionStatus {
655
+ FAILED = 'FAILED',
656
+ SUCCESSFUL = 'SUCCESSFUL'
657
+ }
658
+
659
+ export enum TransactionType {
660
+ LegacyTxnType = 'LegacyTxnType',
661
+ AccessListTxnType = 'AccessListTxnType',
662
+ DynamicFeeTxnType = 'DynamicFeeTxnType'
663
+ }
664
+
665
+ export interface TxnInfo {
666
+ from: string
667
+ to: string
668
+ value: string
669
+ }
670
+
671
+ export interface TxnTransfer {
672
+ transferType: TxnTransferType
486
673
  contractAddress: string
487
- topics: Array<string>
488
- data: string
489
- index: number
674
+ contractType: ContractType
675
+ from: string
676
+ to: string
677
+ tokenIds?: Array<string>
678
+ amounts: Array<string>
679
+ logIndex: number
680
+ amountsUSD?: Array<string>
681
+ pricesUSD?: Array<string>
682
+ contractInfo?: ContractInfo
683
+ tokenMetadata?: { [key: string]: TokenMetadata }
490
684
  }
491
685
 
492
- export interface TokenIDRange {
493
- start: string
494
- end: string
686
+ export enum TxnTransferType {
687
+ UNKNOWN = 'UNKNOWN',
688
+ SEND = 'SEND',
689
+ RECEIVE = 'RECEIVE'
495
690
  }
496
691
 
497
- export interface Page {
498
- page?: number
499
- column?: string
500
- before?: any
501
- after?: any
502
- sort?: Array<SortBy>
503
- pageSize?: number
504
- more?: boolean
692
+ export interface Version {
693
+ webrpcVersion: string
694
+ schemaVersion: string
695
+ schemaHash: string
696
+ appVersion: string
505
697
  }
506
698
 
507
- export interface SortBy {
508
- column: string
509
- order: SortOrder
699
+ export interface WALWriterRuntimeStatus {
700
+ healthOK: boolean
701
+ startTime: string
702
+ uptime: number
703
+ ver: string
704
+ branch: string
705
+ commitHash: string
706
+ chainID: number
707
+ percentWALWritten: number
510
708
  }
511
709
 
512
710
  export interface WebhookListener {
@@ -519,109 +717,45 @@ export interface WebhookListener {
519
717
  active: boolean
520
718
  }
521
719
 
522
- export interface EventFilter {
523
- events?: Array<string>
524
- contractAddresses?: Array<string>
525
- accounts?: Array<string>
526
- tokenIDs?: Array<string>
527
- }
528
-
529
- export interface TokenBalanceFilter {
720
+ export interface GetBalanceUpdatesRequest {
721
+ chainIds?: Array<number>
722
+ networks?: Array<string>
723
+ networkType?: NetworkType
530
724
  contractAddress: string
531
- sinceBlockNumber: number
532
- }
533
-
534
- export interface MetadataOptions {
535
- verifiedOnly?: boolean
536
- unverifiedOnly?: boolean
537
- includeContracts?: Array<string>
538
- }
539
-
540
- export interface TokenBalancesFilter {
541
- accountAddresses: Array<string>
542
- contractStatus?: ContractVerificationStatus
543
- contractTypes?: Array<string>
544
- contractWhitelist?: Array<string>
545
- contractBlacklist?: Array<string>
546
- omitNativeBalances: boolean
547
- }
548
-
549
- export interface TokenBalancesByContractFilter {
550
- contractAddresses: Array<string>
551
- accountAddresses?: Array<string>
552
- contractStatus?: ContractVerificationStatus
553
- }
554
-
555
- export interface GatewayEtherBalance {
556
- chainId: number
557
- error: string
558
- result: EtherBalance
559
- }
560
-
561
- export interface GatewayNativeTokenBalance {
562
- chainId: number
563
- error: string
564
- result: NativeTokenBalance
725
+ lastBlockNumber: number
726
+ lastBlockHash?: string
727
+ page?: Page
565
728
  }
566
729
 
567
- export interface GatewayNativeTokenBalances {
568
- chainId: number
569
- error: string
570
- results: Array<NativeTokenBalance>
730
+ export interface GetBalanceUpdatesResponse {
731
+ page: Page
732
+ balances: Array<GatewayTokenBalance>
571
733
  }
572
734
 
573
- export interface GatewayTokenBalance {
574
- chainId: number
575
- error: string
576
- results: Array<TokenBalance>
735
+ export interface GetChainsRequest {
736
+ networkType?: NetworkType
577
737
  }
578
738
 
579
- export interface IndexerGateway {
580
- getNativeTokenBalance(
581
- args: GetNativeTokenBalanceArgs,
582
- headers?: object,
583
- signal?: AbortSignal,
584
- ): Promise<GetNativeTokenBalanceReturn>
585
- getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn>
586
- getTokenBalancesSummary(
587
- args: GetTokenBalancesSummaryArgs,
588
- headers?: object,
589
- signal?: AbortSignal,
590
- ): Promise<GetTokenBalancesSummaryReturn>
591
- getTokenBalancesDetails(
592
- args: GetTokenBalancesDetailsArgs,
593
- headers?: object,
594
- signal?: AbortSignal,
595
- ): Promise<GetTokenBalancesDetailsReturn>
596
- getTokenBalancesByContract(
597
- args: GetTokenBalancesByContractArgs,
598
- headers?: object,
599
- signal?: AbortSignal,
600
- ): Promise<GetTokenBalancesByContractReturn>
601
- getBalanceUpdates(
602
- args: GetBalanceUpdatesArgs,
603
- headers?: object,
604
- signal?: AbortSignal,
605
- ): Promise<GetBalanceUpdatesReturn>
606
- ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>
607
- version(headers?: object, signal?: AbortSignal): Promise<VersionReturn>
608
- runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn>
739
+ export interface GetChainsResponse {
740
+ chains: Array<ChainInfo>
609
741
  }
610
742
 
611
- export interface GetNativeTokenBalanceArgs {
743
+ export interface GetNativeTokenBalanceRequest {
612
744
  chainIds?: Array<number>
613
745
  networks?: Array<string>
614
- testnets?: boolean
746
+ networkType?: NetworkType
615
747
  accountAddress?: string
748
+ omitPrices?: boolean
616
749
  }
617
750
 
618
- export interface GetNativeTokenBalanceReturn {
751
+ export interface GetNativeTokenBalanceResponse {
619
752
  balances: Array<GatewayNativeTokenBalance>
620
753
  }
621
- export interface GetTokenBalancesArgs {
754
+
755
+ export interface GetTokenBalancesRequest {
622
756
  chainIds?: Array<number>
623
757
  networks?: Array<string>
624
- testnets?: boolean
758
+ networkType?: NetworkType
625
759
  accountAddress?: string
626
760
  contractAddress?: string
627
761
  tokenID?: string
@@ -631,85 +765,109 @@ export interface GetTokenBalancesArgs {
631
765
  page?: Page
632
766
  }
633
767
 
634
- export interface GetTokenBalancesReturn {
768
+ export interface GetTokenBalancesResponse {
635
769
  page: Page
636
770
  balances: Array<GatewayTokenBalance>
637
771
  }
638
- export interface GetTokenBalancesSummaryArgs {
772
+
773
+ export interface GetTokenBalancesByContractRequest {
639
774
  chainIds?: Array<number>
640
775
  networks?: Array<string>
641
- testnets?: boolean
642
- filter: TokenBalancesFilter
776
+ networkType?: NetworkType
777
+ filter: TokenBalancesByContractFilter
643
778
  omitMetadata?: boolean
644
779
  page?: Page
645
780
  }
646
781
 
647
- export interface GetTokenBalancesSummaryReturn {
782
+ export interface GetTokenBalancesByContractResponse {
648
783
  page: Page
649
- nativeBalances: Array<GatewayNativeTokenBalances>
650
784
  balances: Array<GatewayTokenBalance>
651
785
  }
652
- export interface GetTokenBalancesDetailsArgs {
786
+
787
+ export interface GetTokenBalancesDetailsRequest {
653
788
  chainIds?: Array<number>
654
789
  networks?: Array<string>
655
- testnets?: boolean
790
+ networkType?: NetworkType
656
791
  filter: TokenBalancesFilter
657
792
  omitMetadata?: boolean
658
793
  page?: Page
659
794
  }
660
795
 
661
- export interface GetTokenBalancesDetailsReturn {
796
+ export interface GetTokenBalancesDetailsResponse {
662
797
  page: Page
663
798
  nativeBalances: Array<GatewayNativeTokenBalances>
664
799
  balances: Array<GatewayTokenBalance>
665
800
  }
666
- export interface GetTokenBalancesByContractArgs {
801
+
802
+ export interface GetTokenBalancesSummaryRequest {
667
803
  chainIds?: Array<number>
668
804
  networks?: Array<string>
669
- testnets?: boolean
670
- filter: TokenBalancesByContractFilter
805
+ networkType?: NetworkType
806
+ filter: TokenBalancesFilter
671
807
  omitMetadata?: boolean
672
808
  page?: Page
673
809
  }
674
810
 
675
- export interface GetTokenBalancesByContractReturn {
811
+ export interface GetTokenBalancesSummaryResponse {
676
812
  page: Page
813
+ nativeBalances: Array<GatewayNativeTokenBalances>
677
814
  balances: Array<GatewayTokenBalance>
678
815
  }
679
- export interface GetBalanceUpdatesArgs {
816
+
817
+ export interface GetTokenPriceRequest {
818
+ q: GatewayTokenPriceQuery
819
+ }
820
+
821
+ export interface GetTokenPriceResponse {
822
+ price: GatewayPrice
823
+ }
824
+
825
+ export interface GetTokenPricesRequest {
826
+ q: Array<GatewayTokenPriceQuery>
827
+ }
828
+
829
+ export interface GetTokenPricesResponse {
830
+ prices: Array<GatewayPrice>
831
+ }
832
+
833
+ export interface GetTransactionHistoryRequest {
680
834
  chainIds?: Array<number>
681
835
  networks?: Array<string>
682
- testnets?: boolean
683
- contractAddress: string
684
- lastBlockNumber: number
685
- lastBlockHash?: string
836
+ networkType?: NetworkType
837
+ filter: TransactionHistoryFilter
838
+ includeMetadata?: boolean
839
+ metadataOptions?: MetadataOptions
686
840
  page?: Page
687
841
  }
688
842
 
689
- export interface GetBalanceUpdatesReturn {
843
+ export interface GetTransactionHistoryResponse {
690
844
  page: Page
691
- balances: Array<GatewayTokenBalance>
845
+ transactions: Array<GatewayTransaction>
692
846
  }
693
- export interface PingArgs {}
694
847
 
695
- export interface PingReturn {
848
+ export interface PingRequest {}
849
+
850
+ export interface PingResponse {
696
851
  status: boolean
697
852
  }
698
- export interface VersionArgs {}
699
853
 
700
- export interface VersionReturn {
701
- version: Version
702
- }
703
- export interface RuntimeStatusArgs {}
854
+ export interface RuntimeStatusRequest {}
704
855
 
705
- export interface RuntimeStatusReturn {
856
+ export interface RuntimeStatusResponse {
706
857
  status: GatewayRuntimeStatus
707
858
  }
708
859
 
860
+ export interface VersionRequest {}
861
+
862
+ export interface VersionResponse {
863
+ version: Version
864
+ }
865
+
709
866
  //
710
867
  // Client
711
868
  //
712
- export class IndexerGateway implements IndexerGateway {
869
+
870
+ export class IndexerGateway implements IndexerGatewayClient {
713
871
  protected hostname: string
714
872
  protected fetch: Fetch
715
873
  protected path = '/rpc/IndexerGateway/'
@@ -723,198 +881,239 @@ export class IndexerGateway implements IndexerGateway {
723
881
  return this.hostname + this.path + name
724
882
  }
725
883
 
726
- getNativeTokenBalance = (
727
- args: GetNativeTokenBalanceArgs,
884
+ queryKey = {
885
+ getBalanceUpdates: (req: GetBalanceUpdatesRequest) => ['IndexerGateway', 'getBalanceUpdates', req] as const,
886
+ getChains: (req: GetChainsRequest) => ['IndexerGateway', 'getChains', req] as const,
887
+ getNativeTokenBalance: (req: GetNativeTokenBalanceRequest) => ['IndexerGateway', 'getNativeTokenBalance', req] as const,
888
+ getTokenBalances: (req: GetTokenBalancesRequest) => ['IndexerGateway', 'getTokenBalances', req] as const,
889
+ getTokenBalancesByContract: (req: GetTokenBalancesByContractRequest) =>
890
+ ['IndexerGateway', 'getTokenBalancesByContract', req] as const,
891
+ getTokenBalancesDetails: (req: GetTokenBalancesDetailsRequest) => ['IndexerGateway', 'getTokenBalancesDetails', req] as const,
892
+ getTokenBalancesSummary: (req: GetTokenBalancesSummaryRequest) => ['IndexerGateway', 'getTokenBalancesSummary', req] as const,
893
+ getTokenPrice: (req: GetTokenPriceRequest) => ['IndexerGateway', 'getTokenPrice', req] as const,
894
+ getTokenPrices: (req: GetTokenPricesRequest) => ['IndexerGateway', 'getTokenPrices', req] as const,
895
+ getTransactionHistory: (req: GetTransactionHistoryRequest) => ['IndexerGateway', 'getTransactionHistory', req] as const,
896
+ ping: () => ['IndexerGateway', 'ping'] as const,
897
+ runtimeStatus: () => ['IndexerGateway', 'runtimeStatus'] as const,
898
+ version: () => ['IndexerGateway', 'version'] as const
899
+ }
900
+
901
+ getBalanceUpdates = (
902
+ req: GetBalanceUpdatesRequest,
728
903
  headers?: object,
729
- signal?: AbortSignal,
730
- ): Promise<GetNativeTokenBalanceReturn> => {
731
- return this.fetch(this.url('GetNativeTokenBalance'), createHTTPRequest(args, headers, signal)).then(
732
- (res) => {
733
- return buildResponse(res).then((_data) => {
734
- return {
735
- balances: <Array<GatewayNativeTokenBalance>>_data.balances,
736
- }
904
+ signal?: AbortSignal
905
+ ): Promise<GetBalanceUpdatesResponse> => {
906
+ return this.fetch(this.url('GetBalanceUpdates'), createHttpRequest(JsonEncode(req), headers, signal)).then(
907
+ res => {
908
+ return buildResponse(res).then(_data => {
909
+ return JsonDecode<GetBalanceUpdatesResponse>(_data, 'GetBalanceUpdatesResponse')
737
910
  })
738
911
  },
739
- (error) => {
740
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
912
+ error => {
913
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
914
+ }
915
+ )
916
+ }
917
+
918
+ getChains = (req: GetChainsRequest, headers?: object, signal?: AbortSignal): Promise<GetChainsResponse> => {
919
+ return this.fetch(this.url('GetChains'), createHttpRequest(JsonEncode(req), headers, signal)).then(
920
+ res => {
921
+ return buildResponse(res).then(_data => {
922
+ return JsonDecode<GetChainsResponse>(_data, 'GetChainsResponse')
923
+ })
924
+ },
925
+ error => {
926
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
927
+ }
928
+ )
929
+ }
930
+
931
+ getNativeTokenBalance = (
932
+ req: GetNativeTokenBalanceRequest,
933
+ headers?: object,
934
+ signal?: AbortSignal
935
+ ): Promise<GetNativeTokenBalanceResponse> => {
936
+ return this.fetch(this.url('GetNativeTokenBalance'), createHttpRequest(JsonEncode(req), headers, signal)).then(
937
+ res => {
938
+ return buildResponse(res).then(_data => {
939
+ return JsonDecode<GetNativeTokenBalanceResponse>(_data, 'GetNativeTokenBalanceResponse')
940
+ })
741
941
  },
942
+ error => {
943
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
944
+ }
742
945
  )
743
946
  }
744
947
 
745
948
  getTokenBalances = (
746
- args: GetTokenBalancesArgs,
949
+ req: GetTokenBalancesRequest,
950
+ headers?: object,
951
+ signal?: AbortSignal
952
+ ): Promise<GetTokenBalancesResponse> => {
953
+ return this.fetch(this.url('GetTokenBalances'), createHttpRequest(JsonEncode(req), headers, signal)).then(
954
+ res => {
955
+ return buildResponse(res).then(_data => {
956
+ return JsonDecode<GetTokenBalancesResponse>(_data, 'GetTokenBalancesResponse')
957
+ })
958
+ },
959
+ error => {
960
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
961
+ }
962
+ )
963
+ }
964
+
965
+ getTokenBalancesByContract = (
966
+ req: GetTokenBalancesByContractRequest,
747
967
  headers?: object,
748
- signal?: AbortSignal,
749
- ): Promise<GetTokenBalancesReturn> => {
750
- return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(
751
- (res) => {
752
- return buildResponse(res).then((_data) => {
753
- return {
754
- page: <Page>_data.page,
755
- balances: <Array<GatewayTokenBalance>>_data.balances,
756
- }
968
+ signal?: AbortSignal
969
+ ): Promise<GetTokenBalancesByContractResponse> => {
970
+ return this.fetch(this.url('GetTokenBalancesByContract'), createHttpRequest(JsonEncode(req), headers, signal)).then(
971
+ res => {
972
+ return buildResponse(res).then(_data => {
973
+ return JsonDecode<GetTokenBalancesByContractResponse>(_data, 'GetTokenBalancesByContractResponse')
757
974
  })
758
975
  },
759
- (error) => {
760
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
976
+ error => {
977
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
978
+ }
979
+ )
980
+ }
981
+
982
+ getTokenBalancesDetails = (
983
+ req: GetTokenBalancesDetailsRequest,
984
+ headers?: object,
985
+ signal?: AbortSignal
986
+ ): Promise<GetTokenBalancesDetailsResponse> => {
987
+ return this.fetch(this.url('GetTokenBalancesDetails'), createHttpRequest(JsonEncode(req), headers, signal)).then(
988
+ res => {
989
+ return buildResponse(res).then(_data => {
990
+ return JsonDecode<GetTokenBalancesDetailsResponse>(_data, 'GetTokenBalancesDetailsResponse')
991
+ })
761
992
  },
993
+ error => {
994
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
995
+ }
762
996
  )
763
997
  }
764
998
 
765
999
  getTokenBalancesSummary = (
766
- args: GetTokenBalancesSummaryArgs,
1000
+ req: GetTokenBalancesSummaryRequest,
767
1001
  headers?: object,
768
- signal?: AbortSignal,
769
- ): Promise<GetTokenBalancesSummaryReturn> => {
770
- return this.fetch(this.url('GetTokenBalancesSummary'), createHTTPRequest(args, headers, signal)).then(
771
- (res) => {
772
- return buildResponse(res).then((_data) => {
773
- return {
774
- page: <Page>_data.page,
775
- nativeBalances: <Array<GatewayNativeTokenBalances>>_data.nativeBalances,
776
- balances: <Array<GatewayTokenBalance>>_data.balances,
777
- }
1002
+ signal?: AbortSignal
1003
+ ): Promise<GetTokenBalancesSummaryResponse> => {
1004
+ return this.fetch(this.url('GetTokenBalancesSummary'), createHttpRequest(JsonEncode(req), headers, signal)).then(
1005
+ res => {
1006
+ return buildResponse(res).then(_data => {
1007
+ return JsonDecode<GetTokenBalancesSummaryResponse>(_data, 'GetTokenBalancesSummaryResponse')
778
1008
  })
779
1009
  },
780
- (error) => {
781
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
782
- },
1010
+ error => {
1011
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1012
+ }
783
1013
  )
784
1014
  }
785
1015
 
786
- getTokenBalancesDetails = (
787
- args: GetTokenBalancesDetailsArgs,
788
- headers?: object,
789
- signal?: AbortSignal,
790
- ): Promise<GetTokenBalancesDetailsReturn> => {
791
- return this.fetch(this.url('GetTokenBalancesDetails'), createHTTPRequest(args, headers, signal)).then(
792
- (res) => {
793
- return buildResponse(res).then((_data) => {
794
- return {
795
- page: <Page>_data.page,
796
- nativeBalances: <Array<GatewayNativeTokenBalances>>_data.nativeBalances,
797
- balances: <Array<GatewayTokenBalance>>_data.balances,
798
- }
1016
+ getTokenPrice = (req: GetTokenPriceRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPriceResponse> => {
1017
+ return this.fetch(this.url('GetTokenPrice'), createHttpRequest(JsonEncode(req), headers, signal)).then(
1018
+ res => {
1019
+ return buildResponse(res).then(_data => {
1020
+ return JsonDecode<GetTokenPriceResponse>(_data, 'GetTokenPriceResponse')
799
1021
  })
800
1022
  },
801
- (error) => {
802
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
803
- },
1023
+ error => {
1024
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1025
+ }
804
1026
  )
805
1027
  }
806
1028
 
807
- getTokenBalancesByContract = (
808
- args: GetTokenBalancesByContractArgs,
809
- headers?: object,
810
- signal?: AbortSignal,
811
- ): Promise<GetTokenBalancesByContractReturn> => {
812
- return this.fetch(this.url('GetTokenBalancesByContract'), createHTTPRequest(args, headers, signal)).then(
813
- (res) => {
814
- return buildResponse(res).then((_data) => {
815
- return {
816
- page: <Page>_data.page,
817
- balances: <Array<GatewayTokenBalance>>_data.balances,
818
- }
1029
+ getTokenPrices = (req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse> => {
1030
+ return this.fetch(this.url('GetTokenPrices'), createHttpRequest(JsonEncode(req), headers, signal)).then(
1031
+ res => {
1032
+ return buildResponse(res).then(_data => {
1033
+ return JsonDecode<GetTokenPricesResponse>(_data, 'GetTokenPricesResponse')
819
1034
  })
820
1035
  },
821
- (error) => {
822
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
823
- },
1036
+ error => {
1037
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1038
+ }
824
1039
  )
825
1040
  }
826
1041
 
827
- getBalanceUpdates = (
828
- args: GetBalanceUpdatesArgs,
1042
+ getTransactionHistory = (
1043
+ req: GetTransactionHistoryRequest,
829
1044
  headers?: object,
830
- signal?: AbortSignal,
831
- ): Promise<GetBalanceUpdatesReturn> => {
832
- return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(
833
- (res) => {
834
- return buildResponse(res).then((_data) => {
835
- return {
836
- page: <Page>_data.page,
837
- balances: <Array<GatewayTokenBalance>>_data.balances,
838
- }
1045
+ signal?: AbortSignal
1046
+ ): Promise<GetTransactionHistoryResponse> => {
1047
+ return this.fetch(this.url('GetTransactionHistory'), createHttpRequest(JsonEncode(req), headers, signal)).then(
1048
+ res => {
1049
+ return buildResponse(res).then(_data => {
1050
+ return JsonDecode<GetTransactionHistoryResponse>(_data, 'GetTransactionHistoryResponse')
839
1051
  })
840
1052
  },
841
- (error) => {
842
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
843
- },
1053
+ error => {
1054
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1055
+ }
844
1056
  )
845
1057
  }
846
1058
 
847
- ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
848
- return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(
849
- (res) => {
850
- return buildResponse(res).then((_data) => {
851
- return {
852
- status: <boolean>_data.status,
853
- }
1059
+ ping = (headers?: object, signal?: AbortSignal): Promise<PingResponse> => {
1060
+ return this.fetch(this.url('Ping'), createHttpRequest('{}', headers, signal)).then(
1061
+ res => {
1062
+ return buildResponse(res).then(_data => {
1063
+ return JsonDecode<PingResponse>(_data, 'PingResponse')
854
1064
  })
855
1065
  },
856
- (error) => {
857
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
858
- },
1066
+ error => {
1067
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1068
+ }
859
1069
  )
860
1070
  }
861
1071
 
862
- version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => {
863
- return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(
864
- (res) => {
865
- return buildResponse(res).then((_data) => {
866
- return {
867
- version: <Version>_data.version,
868
- }
1072
+ runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse> => {
1073
+ return this.fetch(this.url('RuntimeStatus'), createHttpRequest('{}', headers, signal)).then(
1074
+ res => {
1075
+ return buildResponse(res).then(_data => {
1076
+ return JsonDecode<RuntimeStatusResponse>(_data, 'RuntimeStatusResponse')
869
1077
  })
870
1078
  },
871
- (error) => {
872
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
873
- },
1079
+ error => {
1080
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1081
+ }
874
1082
  )
875
1083
  }
876
1084
 
877
- runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => {
878
- return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(
879
- (res) => {
880
- return buildResponse(res).then((_data) => {
881
- return {
882
- status: <GatewayRuntimeStatus>_data.status,
883
- }
1085
+ version = (headers?: object, signal?: AbortSignal): Promise<VersionResponse> => {
1086
+ return this.fetch(this.url('Version'), createHttpRequest('{}', headers, signal)).then(
1087
+ res => {
1088
+ return buildResponse(res).then(_data => {
1089
+ return JsonDecode<VersionResponse>(_data, 'VersionResponse')
884
1090
  })
885
1091
  },
886
- (error) => {
887
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
888
- },
1092
+ error => {
1093
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1094
+ }
889
1095
  )
890
1096
  }
891
1097
  }
892
1098
 
893
- const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
894
- const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' }
895
- reqHeaders[WebrpcHeader] = WebrpcHeaderValue
896
-
897
- return {
898
- method: 'POST',
899
- headers: reqHeaders,
900
- body: JSON.stringify(body || {}),
901
- signal,
1099
+ const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
1100
+ const reqHeaders: { [key: string]: string } = {
1101
+ ...headers,
1102
+ 'Content-Type': 'application/json',
1103
+ [WebrpcHeader]: WebrpcHeaderValue
902
1104
  }
1105
+ return { method: 'POST', headers: reqHeaders, body, signal }
903
1106
  }
904
1107
 
905
1108
  const buildResponse = (res: Response): Promise<any> => {
906
- return res.text().then((text) => {
1109
+ return res.text().then(text => {
907
1110
  let data
908
1111
  try {
909
1112
  data = JSON.parse(text)
910
1113
  } catch (error) {
911
- let message = ''
912
- if (error instanceof Error) {
913
- message = error.message
914
- }
915
1114
  throw WebrpcBadResponseError.new({
916
1115
  status: res.status,
917
- cause: `JSON.parse(): ${message}: response text: ${text}`,
1116
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`
918
1117
  })
919
1118
  }
920
1119
  if (!res.ok) {
@@ -925,518 +1124,494 @@ const buildResponse = (res: Response): Promise<any> => {
925
1124
  })
926
1125
  }
927
1126
 
1127
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
1128
+
1129
+ export const JsonEncode = <T = any>(obj: T): string => {
1130
+ return JSON.stringify(obj)
1131
+ }
1132
+
1133
+ export const JsonDecode = <T = any>(data: string | any, _typ: string = ''): T => {
1134
+ let parsed: any = data
1135
+ if (typeof data === 'string') {
1136
+ try {
1137
+ parsed = JSON.parse(data)
1138
+ } catch (err) {
1139
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
1140
+ }
1141
+ }
1142
+ return parsed as T
1143
+ }
1144
+
928
1145
  //
929
1146
  // Errors
930
1147
  //
931
1148
 
1149
+ type WebrpcErrorParams = { name?: string; code?: number; message?: string; status?: number; cause?: string }
1150
+
932
1151
  export class WebrpcError extends Error {
933
- name: string
934
1152
  code: number
935
- message: string
936
1153
  status: number
937
- cause?: string
938
-
939
- /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
940
- msg: string
941
-
942
- constructor(name: string, code: number, message: string, status: number, cause?: string) {
943
- super(message)
944
- this.name = name || 'WebrpcError'
945
- this.code = typeof code === 'number' ? code : 0
946
- this.message = message || `endpoint error ${this.code}`
947
- this.msg = this.message
948
- this.status = typeof status === 'number' ? status : 0
949
- this.cause = cause
1154
+
1155
+ constructor(error: WebrpcErrorParams = {}) {
1156
+ super(error.message)
1157
+ this.name = error.name || 'WebrpcEndpointError'
1158
+ this.code = typeof error.code === 'number' ? error.code : 0
1159
+ this.message = error.message || `endpoint error`
1160
+ this.status = typeof error.status === 'number' ? error.status : 400
1161
+ if (error.cause !== undefined) this.cause = error.cause
950
1162
  Object.setPrototypeOf(this, WebrpcError.prototype)
951
1163
  }
952
1164
 
953
1165
  static new(payload: any): WebrpcError {
954
- return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
1166
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
955
1167
  }
956
1168
  }
957
1169
 
958
- // Webrpc errors
959
-
960
1170
  export class WebrpcEndpointError extends WebrpcError {
961
- constructor(
962
- name: string = 'WebrpcEndpoint',
963
- code: number = 0,
964
- message: string = 'endpoint error',
965
- status: number = 0,
966
- cause?: string,
967
- ) {
968
- super(name, code, message, status, cause)
1171
+ constructor(error: WebrpcErrorParams = {}) {
1172
+ super(error)
1173
+ this.name = error.name || 'WebrpcEndpoint'
1174
+ this.code = typeof error.code === 'number' ? error.code : 0
1175
+ this.message = error.message || `endpoint error`
1176
+ this.status = typeof error.status === 'number' ? error.status : 400
1177
+ if (error.cause !== undefined) this.cause = error.cause
969
1178
  Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
970
1179
  }
971
1180
  }
972
1181
 
973
1182
  export class WebrpcRequestFailedError extends WebrpcError {
974
- constructor(
975
- name: string = 'WebrpcRequestFailed',
976
- code: number = -1,
977
- message: string = 'request failed',
978
- status: number = 0,
979
- cause?: string,
980
- ) {
981
- super(name, code, message, status, cause)
1183
+ constructor(error: WebrpcErrorParams = {}) {
1184
+ super(error)
1185
+ this.name = error.name || 'WebrpcRequestFailed'
1186
+ this.code = typeof error.code === 'number' ? error.code : -1
1187
+ this.message = error.message || `request failed`
1188
+ this.status = typeof error.status === 'number' ? error.status : 400
1189
+ if (error.cause !== undefined) this.cause = error.cause
982
1190
  Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
983
1191
  }
984
1192
  }
985
1193
 
986
1194
  export class WebrpcBadRouteError extends WebrpcError {
987
- constructor(
988
- name: string = 'WebrpcBadRoute',
989
- code: number = -2,
990
- message: string = 'bad route',
991
- status: number = 0,
992
- cause?: string,
993
- ) {
994
- super(name, code, message, status, cause)
1195
+ constructor(error: WebrpcErrorParams = {}) {
1196
+ super(error)
1197
+ this.name = error.name || 'WebrpcBadRoute'
1198
+ this.code = typeof error.code === 'number' ? error.code : -2
1199
+ this.message = error.message || `bad route`
1200
+ this.status = typeof error.status === 'number' ? error.status : 404
1201
+ if (error.cause !== undefined) this.cause = error.cause
995
1202
  Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
996
1203
  }
997
1204
  }
998
1205
 
999
1206
  export class WebrpcBadMethodError extends WebrpcError {
1000
- constructor(
1001
- name: string = 'WebrpcBadMethod',
1002
- code: number = -3,
1003
- message: string = 'bad method',
1004
- status: number = 0,
1005
- cause?: string,
1006
- ) {
1007
- super(name, code, message, status, cause)
1207
+ constructor(error: WebrpcErrorParams = {}) {
1208
+ super(error)
1209
+ this.name = error.name || 'WebrpcBadMethod'
1210
+ this.code = typeof error.code === 'number' ? error.code : -3
1211
+ this.message = error.message || `bad method`
1212
+ this.status = typeof error.status === 'number' ? error.status : 405
1213
+ if (error.cause !== undefined) this.cause = error.cause
1008
1214
  Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
1009
1215
  }
1010
1216
  }
1011
1217
 
1012
1218
  export class WebrpcBadRequestError extends WebrpcError {
1013
- constructor(
1014
- name: string = 'WebrpcBadRequest',
1015
- code: number = -4,
1016
- message: string = 'bad request',
1017
- status: number = 0,
1018
- cause?: string,
1019
- ) {
1020
- super(name, code, message, status, cause)
1219
+ constructor(error: WebrpcErrorParams = {}) {
1220
+ super(error)
1221
+ this.name = error.name || 'WebrpcBadRequest'
1222
+ this.code = typeof error.code === 'number' ? error.code : -4
1223
+ this.message = error.message || `bad request`
1224
+ this.status = typeof error.status === 'number' ? error.status : 400
1225
+ if (error.cause !== undefined) this.cause = error.cause
1021
1226
  Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
1022
1227
  }
1023
1228
  }
1024
1229
 
1025
1230
  export class WebrpcBadResponseError extends WebrpcError {
1026
- constructor(
1027
- name: string = 'WebrpcBadResponse',
1028
- code: number = -5,
1029
- message: string = 'bad response',
1030
- status: number = 0,
1031
- cause?: string,
1032
- ) {
1033
- super(name, code, message, status, cause)
1231
+ constructor(error: WebrpcErrorParams = {}) {
1232
+ super(error)
1233
+ this.name = error.name || 'WebrpcBadResponse'
1234
+ this.code = typeof error.code === 'number' ? error.code : -5
1235
+ this.message = error.message || `bad response`
1236
+ this.status = typeof error.status === 'number' ? error.status : 500
1237
+ if (error.cause !== undefined) this.cause = error.cause
1034
1238
  Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
1035
1239
  }
1036
1240
  }
1037
1241
 
1038
1242
  export class WebrpcServerPanicError extends WebrpcError {
1039
- constructor(
1040
- name: string = 'WebrpcServerPanic',
1041
- code: number = -6,
1042
- message: string = 'server panic',
1043
- status: number = 0,
1044
- cause?: string,
1045
- ) {
1046
- super(name, code, message, status, cause)
1243
+ constructor(error: WebrpcErrorParams = {}) {
1244
+ super(error)
1245
+ this.name = error.name || 'WebrpcServerPanic'
1246
+ this.code = typeof error.code === 'number' ? error.code : -6
1247
+ this.message = error.message || `server panic`
1248
+ this.status = typeof error.status === 'number' ? error.status : 500
1249
+ if (error.cause !== undefined) this.cause = error.cause
1047
1250
  Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
1048
1251
  }
1049
1252
  }
1050
1253
 
1051
1254
  export class WebrpcInternalErrorError extends WebrpcError {
1052
- constructor(
1053
- name: string = 'WebrpcInternalError',
1054
- code: number = -7,
1055
- message: string = 'internal error',
1056
- status: number = 0,
1057
- cause?: string,
1058
- ) {
1059
- super(name, code, message, status, cause)
1255
+ constructor(error: WebrpcErrorParams = {}) {
1256
+ super(error)
1257
+ this.name = error.name || 'WebrpcInternalError'
1258
+ this.code = typeof error.code === 'number' ? error.code : -7
1259
+ this.message = error.message || `internal error`
1260
+ this.status = typeof error.status === 'number' ? error.status : 500
1261
+ if (error.cause !== undefined) this.cause = error.cause
1060
1262
  Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
1061
1263
  }
1062
1264
  }
1063
1265
 
1064
- export class WebrpcClientDisconnectedError extends WebrpcError {
1065
- constructor(
1066
- name: string = 'WebrpcClientDisconnected',
1067
- code: number = -8,
1068
- message: string = 'client disconnected',
1069
- status: number = 0,
1070
- cause?: string,
1071
- ) {
1072
- super(name, code, message, status, cause)
1073
- Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
1266
+ export class WebrpcClientAbortedError extends WebrpcError {
1267
+ constructor(error: WebrpcErrorParams = {}) {
1268
+ super(error)
1269
+ this.name = error.name || 'WebrpcClientAborted'
1270
+ this.code = typeof error.code === 'number' ? error.code : -8
1271
+ this.message = error.message || `request aborted by client`
1272
+ this.status = typeof error.status === 'number' ? error.status : 400
1273
+ if (error.cause !== undefined) this.cause = error.cause
1274
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
1074
1275
  }
1075
1276
  }
1076
1277
 
1077
1278
  export class WebrpcStreamLostError extends WebrpcError {
1078
- constructor(
1079
- name: string = 'WebrpcStreamLost',
1080
- code: number = -9,
1081
- message: string = 'stream lost',
1082
- status: number = 0,
1083
- cause?: string,
1084
- ) {
1085
- super(name, code, message, status, cause)
1279
+ constructor(error: WebrpcErrorParams = {}) {
1280
+ super(error)
1281
+ this.name = error.name || 'WebrpcStreamLost'
1282
+ this.code = typeof error.code === 'number' ? error.code : -9
1283
+ this.message = error.message || `stream lost`
1284
+ this.status = typeof error.status === 'number' ? error.status : 400
1285
+ if (error.cause !== undefined) this.cause = error.cause
1086
1286
  Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
1087
1287
  }
1088
1288
  }
1089
1289
 
1090
1290
  export class WebrpcStreamFinishedError extends WebrpcError {
1091
- constructor(
1092
- name: string = 'WebrpcStreamFinished',
1093
- code: number = -10,
1094
- message: string = 'stream finished',
1095
- status: number = 0,
1096
- cause?: string,
1097
- ) {
1098
- super(name, code, message, status, cause)
1291
+ constructor(error: WebrpcErrorParams = {}) {
1292
+ super(error)
1293
+ this.name = error.name || 'WebrpcStreamFinished'
1294
+ this.code = typeof error.code === 'number' ? error.code : -10
1295
+ this.message = error.message || `stream finished`
1296
+ this.status = typeof error.status === 'number' ? error.status : 200
1297
+ if (error.cause !== undefined) this.cause = error.cause
1099
1298
  Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
1100
1299
  }
1101
1300
  }
1102
1301
 
1302
+ //
1103
1303
  // Schema errors
1304
+ //
1104
1305
 
1105
- export class UnauthorizedError extends WebrpcError {
1106
- constructor(
1107
- name: string = 'Unauthorized',
1108
- code: number = 1000,
1109
- message: string = 'Unauthorized access',
1110
- status: number = 0,
1111
- cause?: string,
1112
- ) {
1113
- super(name, code, message, status, cause)
1114
- Object.setPrototypeOf(this, UnauthorizedError.prototype)
1306
+ export class AbortedError extends WebrpcError {
1307
+ constructor(error: WebrpcErrorParams = {}) {
1308
+ super(error)
1309
+ this.name = error.name || 'Aborted'
1310
+ this.code = typeof error.code === 'number' ? error.code : 1005
1311
+ this.message = error.message || `Request aborted`
1312
+ this.status = typeof error.status === 'number' ? error.status : 400
1313
+ if (error.cause !== undefined) this.cause = error.cause
1314
+ Object.setPrototypeOf(this, AbortedError.prototype)
1115
1315
  }
1116
1316
  }
1117
1317
 
1118
- export class PermissionDeniedError extends WebrpcError {
1119
- constructor(
1120
- name: string = 'PermissionDenied',
1121
- code: number = 1001,
1122
- message: string = 'Permission denied',
1123
- status: number = 0,
1124
- cause?: string,
1125
- ) {
1126
- super(name, code, message, status, cause)
1127
- Object.setPrototypeOf(this, PermissionDeniedError.prototype)
1318
+ export class AccessKeyMismatchError extends WebrpcError {
1319
+ constructor(error: WebrpcErrorParams = {}) {
1320
+ super(error)
1321
+ this.name = error.name || 'AccessKeyMismatch'
1322
+ this.code = typeof error.code === 'number' ? error.code : 1102
1323
+ this.message = error.message || `Access key mismatch`
1324
+ this.status = typeof error.status === 'number' ? error.status : 409
1325
+ if (error.cause !== undefined) this.cause = error.cause
1326
+ Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
1128
1327
  }
1129
1328
  }
1130
1329
 
1131
- export class SessionExpiredError extends WebrpcError {
1132
- constructor(
1133
- name: string = 'SessionExpired',
1134
- code: number = 1002,
1135
- message: string = 'Session expired',
1136
- status: number = 0,
1137
- cause?: string,
1138
- ) {
1139
- super(name, code, message, status, cause)
1140
- Object.setPrototypeOf(this, SessionExpiredError.prototype)
1330
+ export class AccessKeyNotFoundError extends WebrpcError {
1331
+ constructor(error: WebrpcErrorParams = {}) {
1332
+ super(error)
1333
+ this.name = error.name || 'AccessKeyNotFound'
1334
+ this.code = typeof error.code === 'number' ? error.code : 1101
1335
+ this.message = error.message || `Access key not found`
1336
+ this.status = typeof error.status === 'number' ? error.status : 401
1337
+ if (error.cause !== undefined) this.cause = error.cause
1338
+ Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
1141
1339
  }
1142
1340
  }
1143
1341
 
1144
- export class MethodNotFoundError extends WebrpcError {
1145
- constructor(
1146
- name: string = 'MethodNotFound',
1147
- code: number = 1003,
1148
- message: string = 'Method not found',
1149
- status: number = 0,
1150
- cause?: string,
1151
- ) {
1152
- super(name, code, message, status, cause)
1153
- Object.setPrototypeOf(this, MethodNotFoundError.prototype)
1342
+ export class AtLeastOneKeyError extends WebrpcError {
1343
+ constructor(error: WebrpcErrorParams = {}) {
1344
+ super(error)
1345
+ this.name = error.name || 'AtLeastOneKey'
1346
+ this.code = typeof error.code === 'number' ? error.code : 1302
1347
+ this.message = error.message || `You need at least one Access Key`
1348
+ this.status = typeof error.status === 'number' ? error.status : 403
1349
+ if (error.cause !== undefined) this.cause = error.cause
1350
+ Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
1154
1351
  }
1155
1352
  }
1156
1353
 
1157
- export class RequestConflictError extends WebrpcError {
1158
- constructor(
1159
- name: string = 'RequestConflict',
1160
- code: number = 1004,
1161
- message: string = 'Conflict with target resource',
1162
- status: number = 0,
1163
- cause?: string,
1164
- ) {
1165
- super(name, code, message, status, cause)
1166
- Object.setPrototypeOf(this, RequestConflictError.prototype)
1354
+ export class GeoblockedError extends WebrpcError {
1355
+ constructor(error: WebrpcErrorParams = {}) {
1356
+ super(error)
1357
+ this.name = error.name || 'Geoblocked'
1358
+ this.code = typeof error.code === 'number' ? error.code : 1006
1359
+ this.message = error.message || `Geoblocked region`
1360
+ this.status = typeof error.status === 'number' ? error.status : 451
1361
+ if (error.cause !== undefined) this.cause = error.cause
1362
+ Object.setPrototypeOf(this, GeoblockedError.prototype)
1167
1363
  }
1168
1364
  }
1169
1365
 
1170
- export class AbortedError extends WebrpcError {
1171
- constructor(
1172
- name: string = 'Aborted',
1173
- code: number = 1005,
1174
- message: string = 'Request aborted',
1175
- status: number = 0,
1176
- cause?: string,
1177
- ) {
1178
- super(name, code, message, status, cause)
1179
- Object.setPrototypeOf(this, AbortedError.prototype)
1366
+ export class InvalidArgumentError extends WebrpcError {
1367
+ constructor(error: WebrpcErrorParams = {}) {
1368
+ super(error)
1369
+ this.name = error.name || 'InvalidArgument'
1370
+ this.code = typeof error.code === 'number' ? error.code : 2001
1371
+ this.message = error.message || `Invalid argument`
1372
+ this.status = typeof error.status === 'number' ? error.status : 400
1373
+ if (error.cause !== undefined) this.cause = error.cause
1374
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
1180
1375
  }
1181
1376
  }
1182
1377
 
1183
- export class GeoblockedError extends WebrpcError {
1184
- constructor(
1185
- name: string = 'Geoblocked',
1186
- code: number = 1006,
1187
- message: string = 'Geoblocked region',
1188
- status: number = 0,
1189
- cause?: string,
1190
- ) {
1191
- super(name, code, message, status, cause)
1192
- Object.setPrototypeOf(this, GeoblockedError.prototype)
1378
+ export class InvalidOriginError extends WebrpcError {
1379
+ constructor(error: WebrpcErrorParams = {}) {
1380
+ super(error)
1381
+ this.name = error.name || 'InvalidOrigin'
1382
+ this.code = typeof error.code === 'number' ? error.code : 1103
1383
+ this.message = error.message || `Invalid origin for Access Key`
1384
+ this.status = typeof error.status === 'number' ? error.status : 403
1385
+ if (error.cause !== undefined) this.cause = error.cause
1386
+ Object.setPrototypeOf(this, InvalidOriginError.prototype)
1193
1387
  }
1194
1388
  }
1195
1389
 
1196
- export class RateLimitedError extends WebrpcError {
1197
- constructor(
1198
- name: string = 'RateLimited',
1199
- code: number = 1007,
1200
- message: string = 'Rate-limited. Please slow down.',
1201
- status: number = 0,
1202
- cause?: string,
1203
- ) {
1204
- super(name, code, message, status, cause)
1205
- Object.setPrototypeOf(this, RateLimitedError.prototype)
1390
+ export class InvalidServiceError extends WebrpcError {
1391
+ constructor(error: WebrpcErrorParams = {}) {
1392
+ super(error)
1393
+ this.name = error.name || 'InvalidService'
1394
+ this.code = typeof error.code === 'number' ? error.code : 1104
1395
+ this.message = error.message || `Service not enabled for Access key`
1396
+ this.status = typeof error.status === 'number' ? error.status : 403
1397
+ if (error.cause !== undefined) this.cause = error.cause
1398
+ Object.setPrototypeOf(this, InvalidServiceError.prototype)
1206
1399
  }
1207
1400
  }
1208
1401
 
1209
- export class ProjectNotFoundError extends WebrpcError {
1210
- constructor(
1211
- name: string = 'ProjectNotFound',
1212
- code: number = 1100,
1213
- message: string = 'Project not found',
1214
- status: number = 0,
1215
- cause?: string,
1216
- ) {
1217
- super(name, code, message, status, cause)
1218
- Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
1402
+ export class MaxAccessKeysError extends WebrpcError {
1403
+ constructor(error: WebrpcErrorParams = {}) {
1404
+ super(error)
1405
+ this.name = error.name || 'MaxAccessKeys'
1406
+ this.code = typeof error.code === 'number' ? error.code : 1301
1407
+ this.message = error.message || `Access keys limit reached`
1408
+ this.status = typeof error.status === 'number' ? error.status : 403
1409
+ if (error.cause !== undefined) this.cause = error.cause
1410
+ Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
1219
1411
  }
1220
1412
  }
1221
1413
 
1222
- export class AccessKeyNotFoundError extends WebrpcError {
1223
- constructor(
1224
- name: string = 'AccessKeyNotFound',
1225
- code: number = 1101,
1226
- message: string = 'Access key not found',
1227
- status: number = 0,
1228
- cause?: string,
1229
- ) {
1230
- super(name, code, message, status, cause)
1231
- Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
1414
+ export class MetadataCallFailedError extends WebrpcError {
1415
+ constructor(error: WebrpcErrorParams = {}) {
1416
+ super(error)
1417
+ this.name = error.name || 'MetadataCallFailed'
1418
+ this.code = typeof error.code === 'number' ? error.code : 3003
1419
+ this.message = error.message || `Metadata service call failed`
1420
+ this.status = typeof error.status === 'number' ? error.status : 400
1421
+ if (error.cause !== undefined) this.cause = error.cause
1422
+ Object.setPrototypeOf(this, MetadataCallFailedError.prototype)
1232
1423
  }
1233
1424
  }
1234
1425
 
1235
- export class AccessKeyMismatchError extends WebrpcError {
1236
- constructor(
1237
- name: string = 'AccessKeyMismatch',
1238
- code: number = 1102,
1239
- message: string = 'Access key mismatch',
1240
- status: number = 0,
1241
- cause?: string,
1242
- ) {
1243
- super(name, code, message, status, cause)
1244
- Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
1426
+ export class MethodNotFoundError extends WebrpcError {
1427
+ constructor(error: WebrpcErrorParams = {}) {
1428
+ super(error)
1429
+ this.name = error.name || 'MethodNotFound'
1430
+ this.code = typeof error.code === 'number' ? error.code : 1003
1431
+ this.message = error.message || `Method not found`
1432
+ this.status = typeof error.status === 'number' ? error.status : 404
1433
+ if (error.cause !== undefined) this.cause = error.cause
1434
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
1245
1435
  }
1246
1436
  }
1247
1437
 
1248
- export class InvalidOriginError extends WebrpcError {
1249
- constructor(
1250
- name: string = 'InvalidOrigin',
1251
- code: number = 1103,
1252
- message: string = 'Invalid origin for Access Key',
1253
- status: number = 0,
1254
- cause?: string,
1255
- ) {
1256
- super(name, code, message, status, cause)
1257
- Object.setPrototypeOf(this, InvalidOriginError.prototype)
1438
+ export class NoDefaultKeyError extends WebrpcError {
1439
+ constructor(error: WebrpcErrorParams = {}) {
1440
+ super(error)
1441
+ this.name = error.name || 'NoDefaultKey'
1442
+ this.code = typeof error.code === 'number' ? error.code : 1300
1443
+ this.message = error.message || `No default access key found`
1444
+ this.status = typeof error.status === 'number' ? error.status : 403
1445
+ if (error.cause !== undefined) this.cause = error.cause
1446
+ Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
1258
1447
  }
1259
1448
  }
1260
1449
 
1261
- export class InvalidServiceError extends WebrpcError {
1262
- constructor(
1263
- name: string = 'InvalidService',
1264
- code: number = 1104,
1265
- message: string = 'Service not enabled for Access key',
1266
- status: number = 0,
1267
- cause?: string,
1268
- ) {
1269
- super(name, code, message, status, cause)
1270
- Object.setPrototypeOf(this, InvalidServiceError.prototype)
1450
+ export class NotFoundError extends WebrpcError {
1451
+ constructor(error: WebrpcErrorParams = {}) {
1452
+ super(error)
1453
+ this.name = error.name || 'NotFound'
1454
+ this.code = typeof error.code === 'number' ? error.code : 3000
1455
+ this.message = error.message || `Resource not found`
1456
+ this.status = typeof error.status === 'number' ? error.status : 400
1457
+ if (error.cause !== undefined) this.cause = error.cause
1458
+ Object.setPrototypeOf(this, NotFoundError.prototype)
1271
1459
  }
1272
1460
  }
1273
1461
 
1274
- export class UnauthorizedUserError extends WebrpcError {
1275
- constructor(
1276
- name: string = 'UnauthorizedUser',
1277
- code: number = 1105,
1278
- message: string = 'Unauthorized user',
1279
- status: number = 0,
1280
- cause?: string,
1281
- ) {
1282
- super(name, code, message, status, cause)
1283
- Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
1462
+ export class PermissionDeniedError extends WebrpcError {
1463
+ constructor(error: WebrpcErrorParams = {}) {
1464
+ super(error)
1465
+ this.name = error.name || 'PermissionDenied'
1466
+ this.code = typeof error.code === 'number' ? error.code : 1001
1467
+ this.message = error.message || `Permission denied`
1468
+ this.status = typeof error.status === 'number' ? error.status : 403
1469
+ if (error.cause !== undefined) this.cause = error.cause
1470
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
1284
1471
  }
1285
1472
  }
1286
1473
 
1287
- export class QuotaExceededError extends WebrpcError {
1288
- constructor(
1289
- name: string = 'QuotaExceeded',
1290
- code: number = 1200,
1291
- message: string = 'Quota exceeded',
1292
- status: number = 0,
1293
- cause?: string,
1294
- ) {
1295
- super(name, code, message, status, cause)
1296
- Object.setPrototypeOf(this, QuotaExceededError.prototype)
1474
+ export class ProjectNotFoundError extends WebrpcError {
1475
+ constructor(error: WebrpcErrorParams = {}) {
1476
+ super(error)
1477
+ this.name = error.name || 'ProjectNotFound'
1478
+ this.code = typeof error.code === 'number' ? error.code : 1100
1479
+ this.message = error.message || `Project not found`
1480
+ this.status = typeof error.status === 'number' ? error.status : 401
1481
+ if (error.cause !== undefined) this.cause = error.cause
1482
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
1297
1483
  }
1298
1484
  }
1299
1485
 
1300
- export class RateLimitError extends WebrpcError {
1301
- constructor(
1302
- name: string = 'RateLimit',
1303
- code: number = 1201,
1304
- message: string = 'Rate limit exceeded',
1305
- status: number = 0,
1306
- cause?: string,
1307
- ) {
1308
- super(name, code, message, status, cause)
1309
- Object.setPrototypeOf(this, RateLimitError.prototype)
1486
+ export class QueryFailedError extends WebrpcError {
1487
+ constructor(error: WebrpcErrorParams = {}) {
1488
+ super(error)
1489
+ this.name = error.name || 'QueryFailed'
1490
+ this.code = typeof error.code === 'number' ? error.code : 2003
1491
+ this.message = error.message || `Query failed`
1492
+ this.status = typeof error.status === 'number' ? error.status : 400
1493
+ if (error.cause !== undefined) this.cause = error.cause
1494
+ Object.setPrototypeOf(this, QueryFailedError.prototype)
1310
1495
  }
1311
1496
  }
1312
1497
 
1313
- export class NoDefaultKeyError extends WebrpcError {
1314
- constructor(
1315
- name: string = 'NoDefaultKey',
1316
- code: number = 1300,
1317
- message: string = 'No default access key found',
1318
- status: number = 0,
1319
- cause?: string,
1320
- ) {
1321
- super(name, code, message, status, cause)
1322
- Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
1498
+ export class QuotaExceededError extends WebrpcError {
1499
+ constructor(error: WebrpcErrorParams = {}) {
1500
+ super(error)
1501
+ this.name = error.name || 'QuotaExceeded'
1502
+ this.code = typeof error.code === 'number' ? error.code : 1200
1503
+ this.message = error.message || `Quota exceeded`
1504
+ this.status = typeof error.status === 'number' ? error.status : 429
1505
+ if (error.cause !== undefined) this.cause = error.cause
1506
+ Object.setPrototypeOf(this, QuotaExceededError.prototype)
1323
1507
  }
1324
1508
  }
1325
1509
 
1326
- export class MaxAccessKeysError extends WebrpcError {
1327
- constructor(
1328
- name: string = 'MaxAccessKeys',
1329
- code: number = 1301,
1330
- message: string = 'Access keys limit reached',
1331
- status: number = 0,
1332
- cause?: string,
1333
- ) {
1334
- super(name, code, message, status, cause)
1335
- Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
1510
+ export class RateLimitError extends WebrpcError {
1511
+ constructor(error: WebrpcErrorParams = {}) {
1512
+ super(error)
1513
+ this.name = error.name || 'RateLimit'
1514
+ this.code = typeof error.code === 'number' ? error.code : 1201
1515
+ this.message = error.message || `Rate limit exceeded`
1516
+ this.status = typeof error.status === 'number' ? error.status : 429
1517
+ if (error.cause !== undefined) this.cause = error.cause
1518
+ Object.setPrototypeOf(this, RateLimitError.prototype)
1336
1519
  }
1337
1520
  }
1338
1521
 
1339
- export class AtLeastOneKeyError extends WebrpcError {
1340
- constructor(
1341
- name: string = 'AtLeastOneKey',
1342
- code: number = 1302,
1343
- message: string = 'You need at least one Access Key',
1344
- status: number = 0,
1345
- cause?: string,
1346
- ) {
1347
- super(name, code, message, status, cause)
1348
- Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
1522
+ export class RateLimitedError extends WebrpcError {
1523
+ constructor(error: WebrpcErrorParams = {}) {
1524
+ super(error)
1525
+ this.name = error.name || 'RateLimited'
1526
+ this.code = typeof error.code === 'number' ? error.code : 1007
1527
+ this.message = error.message || `Rate-limited. Please slow down.`
1528
+ this.status = typeof error.status === 'number' ? error.status : 429
1529
+ if (error.cause !== undefined) this.cause = error.cause
1530
+ Object.setPrototypeOf(this, RateLimitedError.prototype)
1349
1531
  }
1350
1532
  }
1351
1533
 
1352
- export class TimeoutError extends WebrpcError {
1353
- constructor(
1354
- name: string = 'Timeout',
1355
- code: number = 1900,
1356
- message: string = 'Request timed out',
1357
- status: number = 0,
1358
- cause?: string,
1359
- ) {
1360
- super(name, code, message, status, cause)
1361
- Object.setPrototypeOf(this, TimeoutError.prototype)
1534
+ export class RequestConflictError extends WebrpcError {
1535
+ constructor(error: WebrpcErrorParams = {}) {
1536
+ super(error)
1537
+ this.name = error.name || 'RequestConflict'
1538
+ this.code = typeof error.code === 'number' ? error.code : 1004
1539
+ this.message = error.message || `Conflict with target resource`
1540
+ this.status = typeof error.status === 'number' ? error.status : 409
1541
+ if (error.cause !== undefined) this.cause = error.cause
1542
+ Object.setPrototypeOf(this, RequestConflictError.prototype)
1362
1543
  }
1363
1544
  }
1364
1545
 
1365
- export class InvalidArgumentError extends WebrpcError {
1366
- constructor(
1367
- name: string = 'InvalidArgument',
1368
- code: number = 2001,
1369
- message: string = 'Invalid argument',
1370
- status: number = 0,
1371
- cause?: string,
1372
- ) {
1373
- super(name, code, message, status, cause)
1374
- Object.setPrototypeOf(this, InvalidArgumentError.prototype)
1546
+ export class ResourceExhaustedError extends WebrpcError {
1547
+ constructor(error: WebrpcErrorParams = {}) {
1548
+ super(error)
1549
+ this.name = error.name || 'ResourceExhausted'
1550
+ this.code = typeof error.code === 'number' ? error.code : 2004
1551
+ this.message = error.message || `Resource exhausted`
1552
+ this.status = typeof error.status === 'number' ? error.status : 400
1553
+ if (error.cause !== undefined) this.cause = error.cause
1554
+ Object.setPrototypeOf(this, ResourceExhaustedError.prototype)
1375
1555
  }
1376
1556
  }
1377
1557
 
1378
- export class UnavailableError extends WebrpcError {
1379
- constructor(
1380
- name: string = 'Unavailable',
1381
- code: number = 2002,
1382
- message: string = 'Unavailable resource',
1383
- status: number = 0,
1384
- cause?: string,
1385
- ) {
1386
- super(name, code, message, status, cause)
1387
- Object.setPrototypeOf(this, UnavailableError.prototype)
1558
+ export class SessionExpiredError extends WebrpcError {
1559
+ constructor(error: WebrpcErrorParams = {}) {
1560
+ super(error)
1561
+ this.name = error.name || 'SessionExpired'
1562
+ this.code = typeof error.code === 'number' ? error.code : 1002
1563
+ this.message = error.message || `Session expired`
1564
+ this.status = typeof error.status === 'number' ? error.status : 403
1565
+ if (error.cause !== undefined) this.cause = error.cause
1566
+ Object.setPrototypeOf(this, SessionExpiredError.prototype)
1388
1567
  }
1389
1568
  }
1390
1569
 
1391
- export class QueryFailedError extends WebrpcError {
1392
- constructor(
1393
- name: string = 'QueryFailed',
1394
- code: number = 2003,
1395
- message: string = 'Query failed',
1396
- status: number = 0,
1397
- cause?: string,
1398
- ) {
1399
- super(name, code, message, status, cause)
1400
- Object.setPrototypeOf(this, QueryFailedError.prototype)
1570
+ export class TimeoutError extends WebrpcError {
1571
+ constructor(error: WebrpcErrorParams = {}) {
1572
+ super(error)
1573
+ this.name = error.name || 'Timeout'
1574
+ this.code = typeof error.code === 'number' ? error.code : 1900
1575
+ this.message = error.message || `Request timed out`
1576
+ this.status = typeof error.status === 'number' ? error.status : 408
1577
+ if (error.cause !== undefined) this.cause = error.cause
1578
+ Object.setPrototypeOf(this, TimeoutError.prototype)
1401
1579
  }
1402
1580
  }
1403
1581
 
1404
- export class ResourceExhaustedError extends WebrpcError {
1405
- constructor(
1406
- name: string = 'ResourceExhausted',
1407
- code: number = 2004,
1408
- message: string = 'Resource exhausted',
1409
- status: number = 0,
1410
- cause?: string,
1411
- ) {
1412
- super(name, code, message, status, cause)
1413
- Object.setPrototypeOf(this, ResourceExhaustedError.prototype)
1582
+ export class UnauthorizedError extends WebrpcError {
1583
+ constructor(error: WebrpcErrorParams = {}) {
1584
+ super(error)
1585
+ this.name = error.name || 'Unauthorized'
1586
+ this.code = typeof error.code === 'number' ? error.code : 1000
1587
+ this.message = error.message || `Unauthorized access`
1588
+ this.status = typeof error.status === 'number' ? error.status : 401
1589
+ if (error.cause !== undefined) this.cause = error.cause
1590
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
1414
1591
  }
1415
1592
  }
1416
1593
 
1417
- export class NotFoundError extends WebrpcError {
1418
- constructor(
1419
- name: string = 'NotFound',
1420
- code: number = 3000,
1421
- message: string = 'Resource not found',
1422
- status: number = 0,
1423
- cause?: string,
1424
- ) {
1425
- super(name, code, message, status, cause)
1426
- Object.setPrototypeOf(this, NotFoundError.prototype)
1594
+ export class UnauthorizedUserError extends WebrpcError {
1595
+ constructor(error: WebrpcErrorParams = {}) {
1596
+ super(error)
1597
+ this.name = error.name || 'UnauthorizedUser'
1598
+ this.code = typeof error.code === 'number' ? error.code : 1105
1599
+ this.message = error.message || `Unauthorized user`
1600
+ this.status = typeof error.status === 'number' ? error.status : 403
1601
+ if (error.cause !== undefined) this.cause = error.cause
1602
+ Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
1427
1603
  }
1428
1604
  }
1429
1605
 
1430
- export class MetadataCallFailedError extends WebrpcError {
1431
- constructor(
1432
- name: string = 'MetadataCallFailed',
1433
- code: number = 3003,
1434
- message: string = 'Metadata service call failed',
1435
- status: number = 0,
1436
- cause?: string,
1437
- ) {
1438
- super(name, code, message, status, cause)
1439
- Object.setPrototypeOf(this, MetadataCallFailedError.prototype)
1606
+ export class UnavailableError extends WebrpcError {
1607
+ constructor(error: WebrpcErrorParams = {}) {
1608
+ super(error)
1609
+ this.name = error.name || 'Unavailable'
1610
+ this.code = typeof error.code === 'number' ? error.code : 2002
1611
+ this.message = error.message || `Unavailable resource`
1612
+ this.status = typeof error.status === 'number' ? error.status : 400
1613
+ if (error.cause !== undefined) this.cause = error.cause
1614
+ Object.setPrototypeOf(this, UnavailableError.prototype)
1440
1615
  }
1441
1616
  }
1442
1617
 
@@ -1449,38 +1624,78 @@ export enum errors {
1449
1624
  WebrpcBadResponse = 'WebrpcBadResponse',
1450
1625
  WebrpcServerPanic = 'WebrpcServerPanic',
1451
1626
  WebrpcInternalError = 'WebrpcInternalError',
1452
- WebrpcClientDisconnected = 'WebrpcClientDisconnected',
1627
+ WebrpcClientAborted = 'WebrpcClientAborted',
1453
1628
  WebrpcStreamLost = 'WebrpcStreamLost',
1454
1629
  WebrpcStreamFinished = 'WebrpcStreamFinished',
1455
- Unauthorized = 'Unauthorized',
1456
- PermissionDenied = 'PermissionDenied',
1457
- SessionExpired = 'SessionExpired',
1458
- MethodNotFound = 'MethodNotFound',
1459
- RequestConflict = 'RequestConflict',
1460
1630
  Aborted = 'Aborted',
1461
- Geoblocked = 'Geoblocked',
1462
- RateLimited = 'RateLimited',
1463
- ProjectNotFound = 'ProjectNotFound',
1464
- AccessKeyNotFound = 'AccessKeyNotFound',
1465
1631
  AccessKeyMismatch = 'AccessKeyMismatch',
1632
+ AccessKeyNotFound = 'AccessKeyNotFound',
1633
+ AtLeastOneKey = 'AtLeastOneKey',
1634
+ Geoblocked = 'Geoblocked',
1635
+ InvalidArgument = 'InvalidArgument',
1466
1636
  InvalidOrigin = 'InvalidOrigin',
1467
1637
  InvalidService = 'InvalidService',
1468
- UnauthorizedUser = 'UnauthorizedUser',
1469
- QuotaExceeded = 'QuotaExceeded',
1470
- RateLimit = 'RateLimit',
1471
- NoDefaultKey = 'NoDefaultKey',
1472
1638
  MaxAccessKeys = 'MaxAccessKeys',
1473
- AtLeastOneKey = 'AtLeastOneKey',
1474
- Timeout = 'Timeout',
1475
- InvalidArgument = 'InvalidArgument',
1476
- Unavailable = 'Unavailable',
1639
+ MetadataCallFailed = 'MetadataCallFailed',
1640
+ MethodNotFound = 'MethodNotFound',
1641
+ NoDefaultKey = 'NoDefaultKey',
1642
+ NotFound = 'NotFound',
1643
+ PermissionDenied = 'PermissionDenied',
1644
+ ProjectNotFound = 'ProjectNotFound',
1477
1645
  QueryFailed = 'QueryFailed',
1646
+ QuotaExceeded = 'QuotaExceeded',
1647
+ RateLimit = 'RateLimit',
1648
+ RateLimited = 'RateLimited',
1649
+ RequestConflict = 'RequestConflict',
1478
1650
  ResourceExhausted = 'ResourceExhausted',
1479
- NotFound = 'NotFound',
1480
- MetadataCallFailed = 'MetadataCallFailed',
1481
- }
1482
-
1483
- const webrpcErrorByCode: { [code: number]: any } = {
1651
+ SessionExpired = 'SessionExpired',
1652
+ Timeout = 'Timeout',
1653
+ Unauthorized = 'Unauthorized',
1654
+ UnauthorizedUser = 'UnauthorizedUser',
1655
+ Unavailable = 'Unavailable'
1656
+ }
1657
+
1658
+ export enum WebrpcErrorCodes {
1659
+ WebrpcEndpoint = 0,
1660
+ WebrpcRequestFailed = -1,
1661
+ WebrpcBadRoute = -2,
1662
+ WebrpcBadMethod = -3,
1663
+ WebrpcBadRequest = -4,
1664
+ WebrpcBadResponse = -5,
1665
+ WebrpcServerPanic = -6,
1666
+ WebrpcInternalError = -7,
1667
+ WebrpcClientAborted = -8,
1668
+ WebrpcStreamLost = -9,
1669
+ WebrpcStreamFinished = -10,
1670
+ Aborted = 1005,
1671
+ AccessKeyMismatch = 1102,
1672
+ AccessKeyNotFound = 1101,
1673
+ AtLeastOneKey = 1302,
1674
+ Geoblocked = 1006,
1675
+ InvalidArgument = 2001,
1676
+ InvalidOrigin = 1103,
1677
+ InvalidService = 1104,
1678
+ MaxAccessKeys = 1301,
1679
+ MetadataCallFailed = 3003,
1680
+ MethodNotFound = 1003,
1681
+ NoDefaultKey = 1300,
1682
+ NotFound = 3000,
1683
+ PermissionDenied = 1001,
1684
+ ProjectNotFound = 1100,
1685
+ QueryFailed = 2003,
1686
+ QuotaExceeded = 1200,
1687
+ RateLimit = 1201,
1688
+ RateLimited = 1007,
1689
+ RequestConflict = 1004,
1690
+ ResourceExhausted = 2004,
1691
+ SessionExpired = 1002,
1692
+ Timeout = 1900,
1693
+ Unauthorized = 1000,
1694
+ UnauthorizedUser = 1105,
1695
+ Unavailable = 2002
1696
+ }
1697
+
1698
+ export const webrpcErrorByCode: { [code: number]: any } = {
1484
1699
  [0]: WebrpcEndpointError,
1485
1700
  [-1]: WebrpcRequestFailedError,
1486
1701
  [-2]: WebrpcBadRouteError,
@@ -1489,35 +1704,89 @@ const webrpcErrorByCode: { [code: number]: any } = {
1489
1704
  [-5]: WebrpcBadResponseError,
1490
1705
  [-6]: WebrpcServerPanicError,
1491
1706
  [-7]: WebrpcInternalErrorError,
1492
- [-8]: WebrpcClientDisconnectedError,
1707
+ [-8]: WebrpcClientAbortedError,
1493
1708
  [-9]: WebrpcStreamLostError,
1494
1709
  [-10]: WebrpcStreamFinishedError,
1495
- [1000]: UnauthorizedError,
1496
- [1001]: PermissionDeniedError,
1497
- [1002]: SessionExpiredError,
1498
- [1003]: MethodNotFoundError,
1499
- [1004]: RequestConflictError,
1500
1710
  [1005]: AbortedError,
1501
- [1006]: GeoblockedError,
1502
- [1007]: RateLimitedError,
1503
- [1100]: ProjectNotFoundError,
1504
- [1101]: AccessKeyNotFoundError,
1505
1711
  [1102]: AccessKeyMismatchError,
1712
+ [1101]: AccessKeyNotFoundError,
1713
+ [1302]: AtLeastOneKeyError,
1714
+ [1006]: GeoblockedError,
1715
+ [2001]: InvalidArgumentError,
1506
1716
  [1103]: InvalidOriginError,
1507
1717
  [1104]: InvalidServiceError,
1508
- [1105]: UnauthorizedUserError,
1509
- [1200]: QuotaExceededError,
1510
- [1201]: RateLimitError,
1511
- [1300]: NoDefaultKeyError,
1512
1718
  [1301]: MaxAccessKeysError,
1513
- [1302]: AtLeastOneKeyError,
1514
- [1900]: TimeoutError,
1515
- [2001]: InvalidArgumentError,
1516
- [2002]: UnavailableError,
1719
+ [3003]: MetadataCallFailedError,
1720
+ [1003]: MethodNotFoundError,
1721
+ [1300]: NoDefaultKeyError,
1722
+ [3000]: NotFoundError,
1723
+ [1001]: PermissionDeniedError,
1724
+ [1100]: ProjectNotFoundError,
1517
1725
  [2003]: QueryFailedError,
1726
+ [1200]: QuotaExceededError,
1727
+ [1201]: RateLimitError,
1728
+ [1007]: RateLimitedError,
1729
+ [1004]: RequestConflictError,
1518
1730
  [2004]: ResourceExhaustedError,
1519
- [3000]: NotFoundError,
1520
- [3003]: MetadataCallFailedError,
1731
+ [1002]: SessionExpiredError,
1732
+ [1900]: TimeoutError,
1733
+ [1000]: UnauthorizedError,
1734
+ [1105]: UnauthorizedUserError,
1735
+ [2002]: UnavailableError
1521
1736
  }
1522
1737
 
1523
- export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
1738
+ //
1739
+ // Webrpc
1740
+ //
1741
+
1742
+ export const WebrpcHeader = 'Webrpc'
1743
+
1744
+ export const WebrpcHeaderValue = 'webrpc@v0.31.2;gen-typescript@v0.23.1;sequence-indexer@v0.4.0'
1745
+
1746
+ type WebrpcGenVersions = {
1747
+ WebrpcGenVersion: string
1748
+ codeGenName: string
1749
+ codeGenVersion: string
1750
+ schemaName: string
1751
+ schemaVersion: string
1752
+ }
1753
+
1754
+ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
1755
+ const headerValue = headers.get(WebrpcHeader)
1756
+ if (!headerValue) {
1757
+ return {
1758
+ WebrpcGenVersion: '',
1759
+ codeGenName: '',
1760
+ codeGenVersion: '',
1761
+ schemaName: '',
1762
+ schemaVersion: ''
1763
+ }
1764
+ }
1765
+
1766
+ return parseWebrpcGenVersions(headerValue)
1767
+ }
1768
+
1769
+ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
1770
+ const versions = header.split(';')
1771
+ if (versions.length < 3) {
1772
+ return {
1773
+ WebrpcGenVersion: '',
1774
+ codeGenName: '',
1775
+ codeGenVersion: '',
1776
+ schemaName: '',
1777
+ schemaVersion: ''
1778
+ }
1779
+ }
1780
+
1781
+ const [_, WebrpcGenVersion] = versions[0]!.split('@')
1782
+ const [codeGenName, codeGenVersion] = versions[1]!.split('@')
1783
+ const [schemaName, schemaVersion] = versions[2]!.split('@')
1784
+
1785
+ return {
1786
+ WebrpcGenVersion: WebrpcGenVersion ?? '',
1787
+ codeGenName: codeGenName ?? '',
1788
+ codeGenVersion: codeGenVersion ?? '',
1789
+ schemaName: schemaName ?? '',
1790
+ schemaVersion: schemaVersion ?? ''
1791
+ }
1792
+ }