@0xsequence/indexer 2.3.39 → 2.3.41

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,315 @@
1
1
  /* eslint-disable */
2
- // sequence-indexer v0.4.0 f9220b18008af826218980db21a68ec39989fb80
2
+ // sequence-indexer v0.4.0 caf5c4c3677ac2dce41858dce7cd727a7810845f
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=Indexer -target=typescript -client -out=./clients/indexer.gen.ts
6
+ // webrpc-gen -schema=merged.gen.json -service=Indexer -target=typescript -client -out=./clients/indexer.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 = 'f9220b18008af826218980db21a68ec39989fb80'
15
+ export const WebrpcSchemaHash = "caf5c4c3677ac2dce41858dce7cd727a7810845f"
20
16
 
21
- type WebrpcGenVersions = {
22
- webrpcGenVersion: string
23
- codeGenName: string
24
- codeGenVersion: string
25
- schemaName: string
26
- schemaVersion: string
17
+ //
18
+ // Client interface
19
+ //
20
+
21
+ export interface IndexerClient {
22
+ addWebhookListener(req: AddWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<AddWebhookListenerResponse>
23
+
24
+ /**
25
+ * Fetches a single receipt and then will stop the subscription
26
+ */
27
+ fetchTransactionReceipt(req: FetchTransactionReceiptRequest, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptResponse>
28
+
29
+ /**
30
+ * Fetches a single receipt with filter and then will stop the subscription
31
+ */
32
+ fetchTransactionReceiptWithFilter(req: FetchTransactionReceiptWithFilterRequest, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptWithFilterResponse>
33
+
34
+ /**
35
+ * Webhooks
36
+ */
37
+ getAllWebhookListeners(req: GetAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<GetAllWebhookListenersResponse>
38
+
39
+ /**
40
+ * Get balance update aggregate values -- useful for syncing balance details of a contract, ie. from Skyweaver.
41
+ * Also consider using SubscribeBalanceUpdates or SubscribeEvents as other alternatives.
42
+ */
43
+ getBalanceUpdates(req: GetBalanceUpdatesRequest, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesResponse>
44
+
45
+ /**
46
+ * Get the chain ID of the indexer
47
+ */
48
+ getChainID(headers?: object, signal?: AbortSignal): Promise<GetChainIDResponse>
49
+
50
+ /**
51
+ * Queries an ethereum node for the latest and confirm ETH balances
52
+ * DEPRECATED: use GetNativeTokenBalance instead
53
+ *
54
+ * @deprecated GetNativeTokenBalance
55
+ */
56
+ getEtherBalance(req: GetEtherBalanceRequest, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceResponse>
57
+
58
+ /**
59
+ * GetMarketplaceOrders queries marketplace orders with filtering and pagination.
60
+ *
61
+ * Retrieves buy orders (offers) and sell orders (listings) from a specific marketplace
62
+ * and collection with comprehensive filtering options.
63
+ *
64
+ * Parameters:
65
+ * marketplaceContractAddress: Target marketplace contract (required)
66
+ * collectionAddress: NFT collection contract (required)
67
+ * filter: MarketplaceOrderFilter with options:
68
+ * - isListing: true=listings, false=offers, omit=both
69
+ * - userAddresses: Include specific users
70
+ * - currencyAddresses: Filter by currencies (empty=all)
71
+ * - orderIds: Filter by specific order ids (empty=all)
72
+ * - tokenIds: Filter by specific tokens (empty=all)
73
+ * - excludeUserAddresses: Exclude specific users
74
+ * - blockNumberGt: Orders greater than block number
75
+ * - createdAtAfter: Orders after timestamp
76
+ * - orderStatuses: Filter by status (OPEN, CLOSED, CANCELLED)
77
+ * - returnExpired: Include expired orders
78
+ * page: Pagination control (optional)
79
+ *
80
+ * Returns: Updated pagination info and array of matching orders
81
+ */
82
+ getMarketplaceOrders(req: GetMarketplaceOrdersRequest, headers?: object, signal?: AbortSignal): Promise<GetMarketplaceOrdersResponse>
83
+
84
+ /**
85
+ * GetMarketplaceTopOrders finds the most competitive orders for specific tokens.
86
+ *
87
+ * Optimized for price discovery, returns the best available orders for each token.
88
+ * Useful for displaying current market prices and finding trading opportunities.
89
+ *
90
+ * Parameters:
91
+ * marketplaceContractAddress: Target marketplace contract (required)
92
+ * collectionAddress: NFT collection contract (required)
93
+ * filter: MarketplaceTopOrdersFilter with options:
94
+ * - currencyAddresses: Consider specific currencies (empty=all)
95
+ * - tokenIds: Target token IDs (required, non-empty)
96
+ * - isListing: true=listings/sell orders, false=offers/buy orders
97
+ * - priceSort: ASC=lowest first, DESC=highest first
98
+ * - excludeUser: Hide orders from specific user
99
+ *
100
+ * Returns: Array of top-priced active orders, sorted by priceSort preference
101
+ */
102
+ getMarketplaceTopOrders(req: GetMarketplaceTopOrdersRequest, headers?: object, signal?: AbortSignal): Promise<GetMarketplaceTopOrdersResponse>
103
+
104
+ /**
105
+ * GetNativeTokenBalance queries an ethereum node for the latest native token account balance.
106
+ * The native token is the token of the chain the indexer is connected to, for example, ETH on Ethereum
107
+ * and POL on Polygon.
108
+ */
109
+ getNativeTokenBalance(req: GetNativeTokenBalanceRequest, headers?: object, signal?: AbortSignal): Promise<GetNativeTokenBalanceResponse>
110
+
111
+ /**
112
+ * GetTokenBalances returns a balance summary/details for a specific account. By default
113
+ * if accountAddress is left empty, it will use the account from the jwt session.
114
+ *
115
+ * Also, if contractAddress is undefined, then it will list all current user coins/collectibles.
116
+ * But, if contractAddress is provided, then it will return the token balances for the contract, this is
117
+ * only useful for 1155, but for other tokens, it can act as a filter for the single balance.
118
+ *
119
+ * DEPRECATED: use GetTokenBalancesSummary / GetTokenBalancesDetails
120
+ *
121
+ * @deprecated GetTokenBalancesSummary
122
+ */
123
+ getTokenBalances(req: GetTokenBalancesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesResponse>
124
+
125
+ /**
126
+ * GetTokenBalancesByContract returns a balances for a specific accounts and
127
+ * contracts. The collection ERC721 & ERC1155 tokens are represented as
128
+ * individual balances.
129
+ *
130
+ * If `filter` is not provided, it will error out as it requires at least
131
+ * contract address.
132
+ *
133
+ * If `filter.contractStatus` is not provided, it will include verified only
134
+ * tokens.
135
+ */
136
+ getTokenBalancesByContract(req: GetTokenBalancesByContractRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesByContractResponse>
137
+
138
+ /**
139
+ * GetTokenBalancesDetails returns a detailed balance summary for a specific
140
+ * accounts. The collection ERC721 & ERC1155 tokens are represented as
141
+ * individual balances.
142
+ *
143
+ * If `filter` is not provided, it will use the filter with account from the
144
+ * jwt session.
145
+ *
146
+ * If `filter.contractStatus` is not provided, it will include verified only
147
+ * tokens.
148
+ */
149
+ getTokenBalancesDetails(req: GetTokenBalancesDetailsRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesDetailsResponse>
150
+
151
+ /**
152
+ * GetTokenBalancesSummary returns a summary of token balances for a specific
153
+ * accounts. The collection ERC721 & ERC1155 tokens are represented as a
154
+ * single aggregated balance.
155
+ *
156
+ * If `filter` is not provided, it will use the filter with account from the
157
+ * jwt session.
158
+ *
159
+ * If `filter.contractStatus` is not provided, it will include verified only
160
+ * tokens.
161
+ */
162
+ getTokenBalancesSummary(req: GetTokenBalancesSummaryRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesSummaryResponse>
163
+
164
+ /**
165
+ * GetTokenIDRanges returns the range of tokenIDs for a token collection contract.
166
+ * This is useful for ERC-721 and ERC-1155 contracts to get the range of valid tokenIDs. It is similar to
167
+ * GetTokenIDs, but returns the range of tokenIDs instead of the list of tokenIDs, which is more efficient
168
+ * for large collections and very easy to the caller to expand the range into a list of tokenIDs.
169
+ *
170
+ * NOTE: this method will only return up to 15,000 ranges, if there are more ranges, it will return
171
+ * a boolean to indicate there are more ranges beyond the first 15,000. Therefore, if `moreRanges` is
172
+ * false then you have all the ranges, but if true, you need to make a follow up call to fetch the next
173
+ * page of ranges.
174
+ *
175
+ * As an example, if a NFT collection of 100,000 tokens uses ids from 1,2,3,...,100_000 then this endpoint
176
+ * will return just a single range from [1,100_000], but if there are gaps between the sequence, then
177
+ * those will be broken into separate range entries.
178
+ */
179
+ getTokenIDRanges(req: GetTokenIDRangesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenIDRangesResponse>
180
+
181
+ /**
182
+ * GetTokenIDs returns the list of each individual token id for a token collection contract.
183
+ * This is useful for ERC-721 and ERC-1155 contracts to get the list of valid tokenIDs.
184
+ */
185
+ getTokenIDs(req: GetTokenIDsRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenIDsResponse>
186
+
187
+ getTokenPrice(req: GetTokenPriceRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPriceResponse>
188
+
189
+ getTokenPrices(req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse>
190
+
191
+ /**
192
+ * GetTokenSupplies returns the set of tokenIDs used by a contract address, supporting ERC-20, ERC-721, and ERC-1155
193
+ * contracts, and their respective supply as well.
194
+ */
195
+ getTokenSupplies(req: GetTokenSuppliesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesResponse>
196
+
197
+ /**
198
+ * GetTokenSuppliesMap returns the token supplies of ERC-20 and ERC-1155 tokens as requested in the `tokenMap`
199
+ * represented as a map of contractAddress :: []tokenIDs.
200
+ *
201
+ * For an ERC-20 specify tokenIDs as an empty array or [0], for example, { '0xdef': [] } or { '0xdef': [0] }
202
+ * For ERC-1155 pass the array of tokens are strings, ie. { '0xabc': ['1', '2', '3'] }
203
+ */
204
+ getTokenSuppliesMap(req: GetTokenSuppliesMapRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesMapResponse>
205
+
206
+ /**
207
+ * History of mined transactions for the account which includes a list of token transfers (sent/recieved)
208
+ * and sent transactions from a Sequence wallet
209
+ */
210
+ getTransactionHistory(req: GetTransactionHistoryRequest, headers?: object, signal?: AbortSignal): Promise<GetTransactionHistoryResponse>
211
+
212
+ getWebhookListener(req: GetWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<GetWebhookListenerResponse>
213
+
214
+ listTokenPrices(req: ListTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<ListTokenPricesResponse>
215
+
216
+ pauseAllWebhookListeners(req: PauseAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<PauseAllWebhookListenersResponse>
217
+
218
+ /**
219
+ * Ping the indexer
220
+ */
221
+ ping(headers?: object, signal?: AbortSignal): Promise<PingResponse>
222
+
223
+ removeAllWebhookListeners(req: RemoveAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<RemoveAllWebhookListenersResponse>
224
+
225
+ removeWebhookListener(req: RemoveWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<RemoveWebhookListenerResponse>
226
+
227
+ resumeAllWebhookListeners(req: ResumeAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<ResumeAllWebhookListenersResponse>
228
+
229
+ /**
230
+ * Get the current runtime health status of the indexer
231
+ */
232
+ runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse>
233
+
234
+ /**
235
+ * SubscribeBalanceUpdates listens to balance updates for a specific contract address
236
+ */
237
+ subscribeBalanceUpdates(req: SubscribeBalanceUpdatesRequest, options: WebrpcStreamOptions<SubscribeBalanceUpdatesResponse>): WebrpcStreamController
238
+
239
+ /**
240
+ * SubscribeEvents listens to events on-chain based on the filter criteria
241
+ *
242
+ * TODO: some additional options can be passed such as block, reorg true, etc.
243
+ * or stay behind, etc.
244
+ */
245
+ subscribeEvents(req: SubscribeEventsRequest, options: WebrpcStreamOptions<SubscribeEventsResponse>): WebrpcStreamController
246
+
247
+ /**
248
+ * Listen to transaction receipts on-chain based on the filter criteria
249
+ */
250
+ subscribeReceipts(req: SubscribeReceiptsRequest, options: WebrpcStreamOptions<SubscribeReceiptsResponse>): WebrpcStreamController
251
+
252
+ /**
253
+ * Re-sync an incorrect token balance with the correct on-chain balance
254
+ * NOTE: this method is almost never used, but we've marked it internal in case
255
+ * we ever want to use it again. This method was written a very long time ago in
256
+ * scenarios when the indexer had little bugs, but now its solid.
257
+ */
258
+ syncBalance(req: SyncBalanceRequest, headers?: object, signal?: AbortSignal): Promise<SyncBalanceResponse>
259
+
260
+ toggleWebhookListener(req: ToggleWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<ToggleWebhookListenerResponse>
261
+
262
+ updateWebhookListener(req: UpdateWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<UpdateWebhookListenerResponse>
263
+
264
+ /**
265
+ * Get the current version of the indexer
266
+ */
267
+ version(headers?: object, signal?: AbortSignal): Promise<VersionResponse>
27
268
  }
28
269
 
29
- export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
30
- const headerValue = headers.get(WebrpcHeader)
31
- if (!headerValue) {
32
- return {
33
- webrpcGenVersion: '',
34
- codeGenName: '',
35
- codeGenVersion: '',
36
- schemaName: '',
37
- schemaVersion: ''
38
- }
39
- }
40
270
 
41
- return parseWebrpcGenVersions(headerValue)
42
- }
271
+ //
272
+ // Schema types
273
+ //
43
274
 
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
- }
275
+ export interface Asset {
276
+ id: number
277
+ collectionId: number
278
+ tokenId?: string
279
+ url?: string
280
+ metadataField: string
281
+ name?: string
282
+ filesize?: number
283
+ mimeType?: string
284
+ width?: number
285
+ height?: number
286
+ updatedAt?: string
287
+ }
55
288
 
56
- const [_, webrpcGenVersion] = versions[0].split('@')
57
- const [codeGenName, codeGenVersion] = versions[1].split('@')
58
- const [schemaName, schemaVersion] = versions[2].split('@')
289
+ export interface BloomStats {
290
+ hitRatio: string
291
+ falsePositivesPercent: string
292
+ hitCount: number
293
+ missCount: number
294
+ falsePositives: number
295
+ }
59
296
 
60
- return {
61
- webrpcGenVersion,
62
- codeGenName,
63
- codeGenVersion,
64
- schemaName,
65
- schemaVersion
66
- }
297
+ export interface BloomStatus {
298
+ enabled: boolean
299
+ initialized: boolean
300
+ bloomInitElapsedTime: string
301
+ stats: BloomStats
67
302
  }
68
303
 
69
- //
70
- // Types
71
- //
304
+ export interface Bond {
305
+ pebble: PebbleMetrics
306
+ estimatedDiskUsagePerTable: any
307
+ estimatedDiskUsageTotal: string
308
+ }
72
309
 
73
- export enum ResourceStatus {
74
- NOT_AVAILABLE = 'NOT_AVAILABLE',
75
- REFRESHING = 'REFRESHING',
76
- AVAILABLE = 'AVAILABLE'
310
+ export interface ChainInfo {
311
+ chainId: number
312
+ chainName: string
77
313
  }
78
314
 
79
315
  export interface ContractInfo {
@@ -93,56 +329,29 @@ export interface ContractInfo {
93
329
  status: ResourceStatus
94
330
  }
95
331
 
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
332
+ export interface ContractInfoExtensionBridgeInfo {
333
+ tokenAddress: string
109
334
  }
110
335
 
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
336
+ export interface ContractInfoExtensionIndexingInfo {
337
+ useOnChainBalance: boolean
132
338
  }
133
339
 
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
340
+ export interface ContractInfoExtensions {
341
+ link?: string
342
+ description?: string
343
+ categories?: Array<string>
344
+ bridgeInfo?: {[key: string]: ContractInfoExtensionBridgeInfo}
345
+ indexingInfo?: ContractInfoExtensionIndexingInfo
346
+ ogImage?: string
347
+ ogName?: string
348
+ originChainId?: number
349
+ originAddress?: string
350
+ blacklist?: boolean
351
+ verified?: boolean
352
+ verifiedBy?: string
353
+ featured?: boolean
354
+ featureIndex?: number
146
355
  }
147
356
 
148
357
  export enum ContractType {
@@ -155,90 +364,109 @@ export enum ContractType {
155
364
  ERC20_BRIDGE = 'ERC20_BRIDGE',
156
365
  ERC721_BRIDGE = 'ERC721_BRIDGE',
157
366
  ERC1155_BRIDGE = 'ERC1155_BRIDGE',
158
- SEQ_MARKETPLACE = 'SEQ_MARKETPLACE'
367
+ SEQ_MARKETPLACE = 'SEQ_MARKETPLACE',
368
+ ERC6909 = 'ERC6909'
159
369
  }
160
370
 
161
- export enum EventLogType {
162
- UNKNOWN = 'UNKNOWN',
163
- BLOCK_ADDED = 'BLOCK_ADDED',
164
- BLOCK_REMOVED = 'BLOCK_REMOVED'
371
+ export enum ContractVerificationStatus {
372
+ VERIFIED = 'VERIFIED',
373
+ UNVERIFIED = 'UNVERIFIED',
374
+ ALL = 'ALL'
165
375
  }
166
376
 
167
- export enum EventLogDataType {
168
- EVENT = 'EVENT',
169
- TOKEN_TRANSFER = 'TOKEN_TRANSFER',
170
- NATIVE_TOKEN_TRANSFER = 'NATIVE_TOKEN_TRANSFER',
171
- SEQUENCE_TXN = 'SEQUENCE_TXN'
377
+ export interface DiskUsage {
378
+ humanReadable: string
379
+ used: number
380
+ size: number
381
+ percent: number
382
+ dirs: {[key: string]: string}
172
383
  }
173
384
 
174
- export enum OrderStatus {
175
- OPEN = 'OPEN',
176
- CLOSED = 'CLOSED',
177
- CANCELLED = 'CANCELLED'
385
+ export interface EtherBalance {
386
+ accountAddress: string
387
+ balanceWei: string
178
388
  }
179
389
 
180
- export enum TxnTransferType {
181
- UNKNOWN = 'UNKNOWN',
182
- SEND = 'SEND',
183
- RECEIVE = 'RECEIVE'
390
+ export interface EventDecoded {
391
+ topicHash: string
392
+ eventSig: string
393
+ types: Array<string>
394
+ names: Array<string>
395
+ values: Array<string>
184
396
  }
185
397
 
186
- export enum TransactionStatus {
187
- FAILED = 'FAILED',
188
- SUCCESSFUL = 'SUCCESSFUL'
398
+ export interface EventFilter {
399
+ events?: Array<string>
400
+ contractAddresses?: Array<string>
401
+ accounts?: Array<string>
402
+ tokenIDs?: Array<string>
189
403
  }
190
404
 
191
- export enum TransactionType {
192
- LegacyTxnType = 'LegacyTxnType',
193
- AccessListTxnType = 'AccessListTxnType',
194
- DynamicFeeTxnType = 'DynamicFeeTxnType'
405
+ export interface EventLog {
406
+ id: number
407
+ uid: string
408
+ type: EventLogType
409
+ blockNumber: number
410
+ blockHash: string
411
+ parentBlockHash: string
412
+ contractAddress: string
413
+ contractType: ContractType
414
+ txnHash: string
415
+ txnIndex: number
416
+ txnLogIndex: number
417
+ logDataType: EventLogDataType
418
+ ts: string
419
+ txnInfo?: TxnInfo
420
+ rawLog?: {[key: string]: any}
421
+ event?: EventDecoded
195
422
  }
196
423
 
197
- export enum SortOrder {
198
- DESC = 'DESC',
199
- ASC = 'ASC'
424
+ export enum EventLogDataType {
425
+ EVENT = 'EVENT',
426
+ TOKEN_TRANSFER = 'TOKEN_TRANSFER',
427
+ NATIVE_TOKEN_TRANSFER = 'NATIVE_TOKEN_TRANSFER',
428
+ SEQUENCE_TXN = 'SEQUENCE_TXN'
200
429
  }
201
430
 
202
- export enum ContractVerificationStatus {
203
- VERIFIED = 'VERIFIED',
204
- UNVERIFIED = 'UNVERIFIED',
205
- ALL = 'ALL'
431
+ export enum EventLogType {
432
+ UNKNOWN = 'UNKNOWN',
433
+ BLOCK_ADDED = 'BLOCK_ADDED',
434
+ BLOCK_REMOVED = 'BLOCK_REMOVED'
206
435
  }
207
436
 
208
- export enum NetworkType {
209
- MAINNETS = 'MAINNETS',
210
- TESTNETS = 'TESTNETS',
211
- ALL = 'ALL'
437
+ export interface GatewayBackendResponseTime {
438
+ percentiles: {[key: string]: number}
439
+ average: number
212
440
  }
213
441
 
214
- export interface Version {
215
- webrpcVersion: string
216
- schemaVersion: string
217
- schemaHash: string
218
- appVersion: string
442
+ export interface GatewayBackendRuntimeStatus {
443
+ name: string
444
+ chainId: number
445
+ responseTime: GatewayBackendResponseTime
219
446
  }
220
447
 
221
- export interface RuntimeStatus {
222
- healthOK: boolean
223
- indexerEnabled: boolean
224
- startTime: string
225
- uptime: number
226
- ver: string
227
- branch: string
228
- commitHash: string
229
- chainID: number
230
- checks: RuntimeChecks
448
+ export interface GatewayEtherBalance {
449
+ chainId: number
450
+ errorReason?: string
451
+ result: EtherBalance
231
452
  }
232
453
 
233
- export interface GatewayBackendResponseTime {
234
- percentiles: { [key: string]: number }
235
- average: number
454
+ export interface GatewayNativeTokenBalance {
455
+ chainId: number
456
+ errorReason?: string
457
+ result: NativeTokenBalance
236
458
  }
237
459
 
238
- export interface GatewayBackendRuntimeStatus {
239
- name: string
460
+ export interface GatewayNativeTokenBalances {
240
461
  chainId: number
241
- responseTime: GatewayBackendResponseTime
462
+ errorReason?: string
463
+ results: Array<NativeTokenBalance>
464
+ }
465
+
466
+ export interface GatewayPrice {
467
+ chainID: number
468
+ errorReason?: string
469
+ results: Array<Price>
242
470
  }
243
471
 
244
472
  export interface GatewayRuntimeStatus {
@@ -251,113 +479,173 @@ export interface GatewayRuntimeStatus {
251
479
  backends: Array<GatewayBackendRuntimeStatus>
252
480
  }
253
481
 
254
- export interface WALWriterRuntimeStatus {
255
- healthOK: boolean
256
- startTime: string
257
- uptime: number
258
- ver: string
259
- branch: string
260
- commitHash: string
482
+ export interface GatewayTokenBalance {
483
+ chainId: number
484
+ errorReason?: string
485
+ results: Array<TokenBalance>
486
+ }
487
+
488
+ export interface GatewayTokenPriceQuery {
261
489
  chainID: number
262
- percentWALWritten: number
490
+ queries: Array<TokenPriceQuery>
263
491
  }
264
492
 
265
- export interface RuntimeChecks {
266
- running: boolean
267
- runnables: any
268
- cgoEnabled: boolean
269
- quotaControlEnabled: boolean
270
- syncMode: string
271
- percentIndexed: number
493
+ export interface GatewayTransaction {
494
+ chainId: number
495
+ errorReason?: string
496
+ results: Array<Transaction>
497
+ }
498
+
499
+ export interface IndexState {
500
+ chainId: string
272
501
  lastBlockNum: number
273
- lastBlockNumWithState: number
274
- bloomStatus: BloomStatus
275
- bond: Bond
276
- diskUsage: DiskUsage
502
+ lastBlockHash: string
277
503
  }
278
504
 
279
- export interface DiskUsage {
280
- humanReadable: string
281
- used: number
282
- size: number
283
- percent: number
284
- dirs: { [key: string]: string }
505
+ export interface IndexedBlock {
506
+ blockNumber: number
507
+ blockShortHash: string
285
508
  }
286
509
 
287
- export interface Bond {
288
- pebble: PebbleMetrics
289
- estimatedDiskUsagePerTable: any
290
- estimatedDiskUsageTotal: string
510
+ export interface IndexerMetrics {
511
+ blocksPerSecond: number
512
+ eventsPerSecond: number
291
513
  }
292
514
 
293
- export interface PebbleMetrics {
294
- compactionCount: number
295
- compactionEstimatedDebt: number
296
- compactionInProgressBytes: number
297
- compactionNumInProgress: number
298
- compactionMarkedFiles: number
515
+ export interface MarketplaceOrder {
516
+ orderId: string
517
+ tokenContract: string
518
+ tokenId: string
519
+ isListing: boolean
520
+ quantity: string
521
+ quantityRemaining: string
522
+ currencyAddress: string
523
+ pricePerToken: string
524
+ expiry: string
525
+ orderStatus: OrderStatus
526
+ createdBy: string
527
+ blockNumber: number
528
+ orderbookContractAddress: string
529
+ createdAt: number
299
530
  }
300
531
 
301
- export interface BloomStatus {
302
- enabled: boolean
303
- initialized: boolean
304
- bloomInitElapsedTime: string
532
+ export interface MarketplaceOrderFilter {
533
+ isListing?: boolean
534
+ userAddresses?: Array<string>
535
+ currencyAddresses: Array<string>
536
+ orderIds: Array<string>
537
+ tokenIds: Array<string>
538
+ excludeUserAddresses?: Array<string>
539
+ blockNumberGt: number
540
+ createdAtAfter: number
541
+ orderStatuses: Array<OrderStatus>
542
+ returnExpired: boolean
305
543
  }
306
544
 
307
- export interface EtherBalance {
308
- accountAddress: string
309
- balanceWei: string
545
+ export interface MarketplaceTopOrdersFilter {
546
+ currencyAddresses: Array<string>
547
+ tokenIds: Array<string>
548
+ isListing: boolean
549
+ priceSort: SortOrder
550
+ excludeUser?: string
551
+ }
552
+
553
+ export interface MetadataOptions {
554
+ verifiedOnly?: boolean
555
+ unverifiedOnly?: boolean
556
+ includeContracts?: Array<string>
310
557
  }
311
558
 
312
559
  export interface NativeTokenBalance {
313
560
  accountAddress: string
314
561
  chainId: number
562
+ name: string
563
+ symbol: string
315
564
  balance: string
565
+ balanceUSD: string
566
+ priceUSD: string
567
+ priceUpdatedAt?: string
316
568
  errorReason?: string
317
569
  }
318
570
 
319
- export interface IndexState {
320
- chainId: string
321
- lastBlockNum: number
322
- lastBlockHash: string
571
+ export enum NetworkType {
572
+ MAINNETS = 'MAINNETS',
573
+ TESTNETS = 'TESTNETS',
574
+ ALL = 'ALL'
323
575
  }
324
576
 
325
- export interface IndexedBlock {
326
- blockNumber: number
327
- blockShortHash: string
577
+ export enum OrderStatus {
578
+ OPEN = 'OPEN',
579
+ CLOSED = 'CLOSED',
580
+ CANCELLED = 'CANCELLED'
328
581
  }
329
582
 
330
- export interface TxnInfo {
331
- from: string
332
- to: string
333
- value: string
583
+ export interface Page {
584
+ page?: number
585
+ column?: string
586
+ before?: any
587
+ after?: any
588
+ sort?: Array<SortBy>
589
+ pageSize?: number
590
+ more?: boolean
334
591
  }
335
592
 
336
- export interface EventLog {
337
- id: number
338
- uid: string
339
- type: EventLogType
340
- blockNumber: number
341
- blockHash: string
342
- parentBlockHash: string
593
+ export interface PebbleMetrics {
594
+ compactionCount: number
595
+ compactionEstimatedDebt: number
596
+ compactionInProgressBytes: number
597
+ compactionNumInProgress: number
598
+ compactionMarkedFiles: number
599
+ }
600
+
601
+ export interface Price {
343
602
  contractAddress: string
344
- contractType: ContractType
345
- txnHash: string
346
- txnIndex: number
347
- txnLogIndex: number
348
- logDataType: EventLogDataType
349
- ts: string
350
- txnInfo?: TxnInfo
351
- rawLog?: { [key: string]: any }
352
- event?: EventDecoded
603
+ tokenID?: string
604
+ priceUSD: string
605
+ updatedAt?: string
353
606
  }
354
607
 
355
- export interface EventDecoded {
356
- topicHash: string
357
- eventSig: string
358
- types: Array<string>
359
- names: Array<string>
360
- values: Array<string>
608
+ export enum ResourceStatus {
609
+ NOT_AVAILABLE = 'NOT_AVAILABLE',
610
+ REFRESHING = 'REFRESHING',
611
+ AVAILABLE = 'AVAILABLE'
612
+ }
613
+
614
+ export interface RuntimeChecks {
615
+ running: boolean
616
+ runnables: any
617
+ cgoEnabled: boolean
618
+ quotaControlEnabled: boolean
619
+ syncMode: string
620
+ percentIndexed: number
621
+ lastBlockNum: number
622
+ lastBlockNumWithState: number
623
+ bloomStatus: BloomStatus
624
+ bond: Bond
625
+ diskUsage: DiskUsage
626
+ metrics: IndexerMetrics
627
+ }
628
+
629
+ export interface RuntimeStatus {
630
+ healthOK: boolean
631
+ indexerEnabled: boolean
632
+ startTime: string
633
+ uptime: number
634
+ ver: string
635
+ branch: string
636
+ commitHash: string
637
+ chainID: number
638
+ checks: RuntimeChecks
639
+ }
640
+
641
+ export interface SortBy {
642
+ column: string
643
+ order: SortOrder
644
+ }
645
+
646
+ export enum SortOrder {
647
+ DESC = 'DESC',
648
+ ASC = 'ASC'
361
649
  }
362
650
 
363
651
  export interface TokenBalance {
@@ -366,48 +654,44 @@ export interface TokenBalance {
366
654
  accountAddress: string
367
655
  tokenID?: string
368
656
  balance: string
657
+ balanceUSD: string
658
+ priceUSD: string
659
+ priceUpdatedAt?: string
369
660
  blockHash: string
370
- blockNumber: number
371
- chainId: number
372
- uniqueCollectibles: string
373
- isSummary: boolean
374
- contractInfo?: ContractInfo
375
- tokenMetadata?: TokenMetadata
376
- }
377
-
378
- export interface OrderbookOrder {
379
- orderId: string
380
- tokenContract: string
381
- tokenId: string
382
- isListing: boolean
383
- quantity: string
384
- quantityRemaining: string
385
- currencyAddress: string
386
- pricePerToken: string
387
- expiry: string
388
- orderStatus: OrderStatus
389
- createdBy: string
390
- blockNumber: number
391
- orderbookContractAddress: string
392
- createdAt: number
661
+ blockNumber: number
662
+ chainId: number
663
+ uniqueCollectibles: string
664
+ isSummary: boolean
665
+ contractInfo?: ContractInfo
666
+ tokenMetadata?: TokenMetadata
393
667
  }
394
668
 
395
- export interface OrderbookOrderFilter {
396
- isListing?: boolean
397
- userAddresses?: Array<string>
398
- tokenIds: Array<string>
399
- excludeUserAddresses?: Array<string>
400
- afterBlockNumber: number
401
- afterCreatedAt: number
402
- beforeExpiry: number
403
- userAddress?: string
404
- excludeUserAddress?: string
669
+ export interface TokenBalanceFilter {
670
+ contractAddress: string
671
+ sinceBlockNumber: number
672
+ }
673
+
674
+ export interface TokenBalancesByContractFilter {
675
+ contractAddresses: Array<string>
676
+ accountAddresses?: Array<string>
677
+ contractStatus?: ContractVerificationStatus
678
+ tokenIDs?: Array<string>
679
+ }
680
+
681
+ export interface TokenBalancesFilter {
682
+ accountAddresses: Array<string>
683
+ contractStatus?: ContractVerificationStatus
684
+ contractTypes?: Array<string>
685
+ contractWhitelist?: Array<string>
686
+ contractBlacklist?: Array<string>
687
+ omitNativeBalances: boolean
688
+ omitPrices?: boolean
689
+ tokenIDs?: Array<string>
405
690
  }
406
691
 
407
692
  export interface TokenHistory {
408
693
  blockNumber: number
409
694
  blockHash: string
410
- accountAddress: string
411
695
  contractAddress: string
412
696
  contractType: ContractType
413
697
  fromAddress: string
@@ -415,12 +699,45 @@ export interface TokenHistory {
415
699
  txnHash: string
416
700
  txnIndex: number
417
701
  txnLogIndex: number
418
- logData: string
419
702
  tokenIDs: string
420
- Amounts: string
703
+ amounts: string
421
704
  ts: string
422
705
  }
423
706
 
707
+ export interface TokenIDRange {
708
+ start: string
709
+ end: string
710
+ }
711
+
712
+ export interface TokenMetadata {
713
+ chainId?: number
714
+ contractAddress?: string
715
+ tokenId: string
716
+ source: string
717
+ name: string
718
+ description?: string
719
+ image?: string
720
+ video?: string
721
+ audio?: string
722
+ properties?: {[key: string]: any}
723
+ attributes: Array<{[key: string]: any}>
724
+ image_data?: string
725
+ external_url?: string
726
+ background_color?: string
727
+ animation_url?: string
728
+ decimals?: number
729
+ updatedAt?: string
730
+ assets?: Array<Asset>
731
+ status: ResourceStatus
732
+ queuedAt?: string
733
+ lastFetched?: string
734
+ }
735
+
736
+ export interface TokenPriceQuery {
737
+ contractAddress: string
738
+ tokenID?: string
739
+ }
740
+
424
741
  export interface TokenSupply {
425
742
  tokenID: string
426
743
  supply: string
@@ -439,17 +756,12 @@ export interface Transaction {
439
756
  timestamp: string
440
757
  }
441
758
 
442
- export interface TxnTransfer {
443
- transferType: TxnTransferType
444
- contractAddress: string
445
- contractType: ContractType
446
- from: string
447
- to: string
448
- tokenIds?: Array<string>
449
- amounts: Array<string>
450
- logIndex: number
451
- contractInfo?: ContractInfo
452
- tokenMetadata?: { [key: string]: TokenMetadata }
759
+ export interface TransactionFilter {
760
+ txnHash?: string
761
+ from?: string
762
+ to?: string
763
+ contractAddress?: string
764
+ event?: string
453
765
  }
454
766
 
455
767
  export interface TransactionHistoryFilter {
@@ -462,14 +774,14 @@ export interface TransactionHistoryFilter {
462
774
  fromBlock?: number
463
775
  toBlock?: number
464
776
  tokenID?: string
777
+ omitPrices?: boolean
465
778
  }
466
779
 
467
- export interface TransactionFilter {
468
- txnHash?: string
469
- from?: string
470
- to?: string
471
- contractAddress?: string
472
- event?: string
780
+ export interface TransactionLog {
781
+ contractAddress: string
782
+ topics: Array<string>
783
+ data: string
784
+ index: number
473
785
  }
474
786
 
475
787
  export interface TransactionReceipt {
@@ -488,31 +800,60 @@ export interface TransactionReceipt {
488
800
  reorged: boolean
489
801
  }
490
802
 
491
- export interface TransactionLog {
803
+ export enum TransactionStatus {
804
+ FAILED = 'FAILED',
805
+ SUCCESSFUL = 'SUCCESSFUL'
806
+ }
807
+
808
+ export enum TransactionType {
809
+ LegacyTxnType = 'LegacyTxnType',
810
+ AccessListTxnType = 'AccessListTxnType',
811
+ DynamicFeeTxnType = 'DynamicFeeTxnType'
812
+ }
813
+
814
+ export interface TxnInfo {
815
+ from: string
816
+ to: string
817
+ value: string
818
+ }
819
+
820
+ export interface TxnTransfer {
821
+ transferType: TxnTransferType
492
822
  contractAddress: string
493
- topics: Array<string>
494
- data: string
495
- index: number
823
+ contractType: ContractType
824
+ from: string
825
+ to: string
826
+ tokenIds?: Array<string>
827
+ amounts: Array<string>
828
+ logIndex: number
829
+ amountsUSD?: Array<string>
830
+ pricesUSD?: Array<string>
831
+ contractInfo?: ContractInfo
832
+ tokenMetadata?: {[key: string]: TokenMetadata}
496
833
  }
497
834
 
498
- export interface TokenIDRange {
499
- start: string
500
- end: string
835
+ export enum TxnTransferType {
836
+ UNKNOWN = 'UNKNOWN',
837
+ SEND = 'SEND',
838
+ RECEIVE = 'RECEIVE'
501
839
  }
502
840
 
503
- export interface Page {
504
- page?: number
505
- column?: string
506
- before?: any
507
- after?: any
508
- sort?: Array<SortBy>
509
- pageSize?: number
510
- more?: boolean
841
+ export interface Version {
842
+ webrpcVersion: string
843
+ schemaVersion: string
844
+ schemaHash: string
845
+ appVersion: string
511
846
  }
512
847
 
513
- export interface SortBy {
514
- column: string
515
- order: SortOrder
848
+ export interface WALWriterRuntimeStatus {
849
+ healthOK: boolean
850
+ startTime: string
851
+ uptime: number
852
+ ver: string
853
+ branch: string
854
+ commitHash: string
855
+ chainID: number
856
+ percentWALWritten: number
516
857
  }
517
858
 
518
859
  export interface WebhookListener {
@@ -525,454 +866,352 @@ export interface WebhookListener {
525
866
  active: boolean
526
867
  }
527
868
 
528
- export interface EventFilter {
529
- events?: Array<string>
530
- contractAddresses?: Array<string>
531
- accounts?: Array<string>
532
- tokenIDs?: Array<string>
869
+ export interface AddWebhookListenerRequest {
870
+ url: string
871
+ filters: EventFilter
872
+ projectId?: number
533
873
  }
534
874
 
535
- export interface TokenBalanceFilter {
536
- contractAddress: string
537
- sinceBlockNumber: number
875
+ export interface AddWebhookListenerResponse {
876
+ status: boolean
877
+ listener: WebhookListener
538
878
  }
539
879
 
540
- export interface MetadataOptions {
541
- verifiedOnly?: boolean
542
- unverifiedOnly?: boolean
543
- includeContracts?: Array<string>
880
+ export interface FetchTransactionReceiptRequest {
881
+ txnHash: string
882
+ maxBlockWait?: number
544
883
  }
545
884
 
546
- export interface TokenBalancesFilter {
547
- accountAddresses: Array<string>
548
- contractStatus?: ContractVerificationStatus
549
- contractTypes?: Array<string>
550
- contractWhitelist?: Array<string>
551
- contractBlacklist?: Array<string>
552
- omitNativeBalances: boolean
885
+ export interface FetchTransactionReceiptResponse {
886
+ receipt: TransactionReceipt
553
887
  }
554
888
 
555
- export interface TokenBalancesByContractFilter {
556
- contractAddresses: Array<string>
557
- accountAddresses?: Array<string>
558
- contractStatus?: ContractVerificationStatus
889
+ export interface FetchTransactionReceiptWithFilterRequest {
890
+ filter: TransactionFilter
891
+ maxBlockWait?: number
559
892
  }
560
893
 
561
- export interface GatewayEtherBalance {
562
- chainId: number
563
- errorReason?: string
564
- result: EtherBalance
894
+ export interface FetchTransactionReceiptWithFilterResponse {
895
+ receipt: TransactionReceipt
565
896
  }
566
897
 
567
- export interface GatewayNativeTokenBalance {
568
- chainId: number
569
- errorReason?: string
570
- result: NativeTokenBalance
898
+ export interface GetAllWebhookListenersRequest {
899
+ projectId?: number
571
900
  }
572
901
 
573
- export interface GatewayNativeTokenBalances {
574
- chainId: number
575
- errorReason?: string
576
- results: Array<NativeTokenBalance>
902
+ export interface GetAllWebhookListenersResponse {
903
+ listeners: Array<WebhookListener>
577
904
  }
578
905
 
579
- export interface GatewayTokenBalance {
580
- chainId: number
581
- errorReason?: string
582
- results: Array<TokenBalance>
906
+ export interface GetBalanceUpdatesRequest {
907
+ contractAddress: string
908
+ lastBlockNumber: number
909
+ lastBlockHash?: string
910
+ page?: Page
583
911
  }
584
912
 
585
- export interface ChainInfo {
586
- chainId: number
587
- chainName: string
913
+ export interface GetBalanceUpdatesResponse {
914
+ page: Page
915
+ balances: Array<TokenBalance>
588
916
  }
589
917
 
590
- export interface Indexer {
591
- ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>
592
- version(headers?: object, signal?: AbortSignal): Promise<VersionReturn>
593
- runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn>
594
- getChainID(headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn>
595
- getEtherBalance(args: GetEtherBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceReturn>
596
- getNativeTokenBalance(
597
- args: GetNativeTokenBalanceArgs,
598
- headers?: object,
599
- signal?: AbortSignal
600
- ): Promise<GetNativeTokenBalanceReturn>
601
- getTokenBalancesSummary(
602
- args: GetTokenBalancesSummaryArgs,
603
- headers?: object,
604
- signal?: AbortSignal
605
- ): Promise<GetTokenBalancesSummaryReturn>
606
- getTokenBalancesDetails(
607
- args: GetTokenBalancesDetailsArgs,
608
- headers?: object,
609
- signal?: AbortSignal
610
- ): Promise<GetTokenBalancesDetailsReturn>
611
- getTokenBalancesByContract(
612
- args: GetTokenBalancesByContractArgs,
613
- headers?: object,
614
- signal?: AbortSignal
615
- ): Promise<GetTokenBalancesByContractReturn>
616
- getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn>
617
- getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesReturn>
618
- getTokenSuppliesMap(args: GetTokenSuppliesMapArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesMapReturn>
619
- getTokenIDs(args: GetTokenIDsArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenIDsReturn>
620
- getTokenIDRanges(args: GetTokenIDRangesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenIDRangesReturn>
621
- getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn>
622
- getTransactionHistory(
623
- args: GetTransactionHistoryArgs,
624
- headers?: object,
625
- signal?: AbortSignal
626
- ): Promise<GetTransactionHistoryReturn>
627
- fetchTransactionReceipt(
628
- args: FetchTransactionReceiptArgs,
629
- headers?: object,
630
- signal?: AbortSignal
631
- ): Promise<FetchTransactionReceiptReturn>
632
- fetchTransactionReceiptWithFilter(
633
- args: FetchTransactionReceiptWithFilterArgs,
634
- headers?: object,
635
- signal?: AbortSignal
636
- ): Promise<FetchTransactionReceiptWithFilterReturn>
637
- subscribeReceipts(args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>): Promise<void>
638
- subscribeEvents(args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>): Promise<void>
639
- subscribeBalanceUpdates(
640
- args: SubscribeBalanceUpdatesArgs,
641
- options: WebrpcStreamOptions<SubscribeBalanceUpdatesReturn>
642
- ): Promise<void>
643
- syncBalance(args: SyncBalanceArgs, headers?: object, signal?: AbortSignal): Promise<SyncBalanceReturn>
644
- getAllWebhookListeners(
645
- args: GetAllWebhookListenersArgs,
646
- headers?: object,
647
- signal?: AbortSignal
648
- ): Promise<GetAllWebhookListenersReturn>
649
- getWebhookListener(args: GetWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<GetWebhookListenerReturn>
650
- addWebhookListener(args: AddWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<AddWebhookListenerReturn>
651
- updateWebhookListener(
652
- args: UpdateWebhookListenerArgs,
653
- headers?: object,
654
- signal?: AbortSignal
655
- ): Promise<UpdateWebhookListenerReturn>
656
- removeWebhookListener(
657
- args: RemoveWebhookListenerArgs,
658
- headers?: object,
659
- signal?: AbortSignal
660
- ): Promise<RemoveWebhookListenerReturn>
661
- removeAllWebhookListeners(
662
- args: RemoveAllWebhookListenersArgs,
663
- headers?: object,
664
- signal?: AbortSignal
665
- ): Promise<RemoveAllWebhookListenersReturn>
666
- toggleWebhookListener(
667
- args: ToggleWebhookListenerArgs,
668
- headers?: object,
669
- signal?: AbortSignal
670
- ): Promise<ToggleWebhookListenerReturn>
671
- pauseAllWebhookListeners(
672
- args: PauseAllWebhookListenersArgs,
673
- headers?: object,
674
- signal?: AbortSignal
675
- ): Promise<PauseAllWebhookListenersReturn>
676
- resumeAllWebhookListeners(
677
- args: ResumeAllWebhookListenersArgs,
678
- headers?: object,
679
- signal?: AbortSignal
680
- ): Promise<ResumeAllWebhookListenersReturn>
681
- getOrderbookOrders(args: GetOrderbookOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetOrderbookOrdersReturn>
682
- getTopOrders(args: GetTopOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetTopOrdersReturn>
683
- }
684
-
685
- export interface PingArgs {}
686
-
687
- export interface PingReturn {
688
- status: boolean
918
+ export interface GetChainIDRequest {
689
919
  }
690
- export interface VersionArgs {}
691
920
 
692
- export interface VersionReturn {
693
- version: Version
921
+ export interface GetChainIDResponse {
922
+ chainID: number
694
923
  }
695
- export interface RuntimeStatusArgs {}
696
924
 
697
- export interface RuntimeStatusReturn {
698
- status: RuntimeStatus
925
+ export interface GetEtherBalanceRequest {
926
+ accountAddress?: string
699
927
  }
700
- export interface GetChainIDArgs {}
701
928
 
702
- export interface GetChainIDReturn {
703
- chainID: number
929
+ export interface GetEtherBalanceResponse {
930
+ balance: EtherBalance
704
931
  }
705
- export interface GetEtherBalanceArgs {
706
- accountAddress?: string
932
+
933
+ export interface GetMarketplaceOrdersRequest {
934
+ marketplaceContractAddress: string
935
+ collectionAddress: string
936
+ filter?: MarketplaceOrderFilter
937
+ page?: Page
707
938
  }
708
939
 
709
- export interface GetEtherBalanceReturn {
710
- balance: EtherBalance
940
+ export interface GetMarketplaceOrdersResponse {
941
+ page?: Page
942
+ orders: Array<MarketplaceOrder>
711
943
  }
712
- export interface GetNativeTokenBalanceArgs {
713
- accountAddress?: string
944
+
945
+ export interface GetMarketplaceTopOrdersRequest {
946
+ marketplaceContractAddress: string
947
+ collectionAddress: string
948
+ filter: MarketplaceTopOrdersFilter
714
949
  }
715
950
 
716
- export interface GetNativeTokenBalanceReturn {
717
- balance: NativeTokenBalance
951
+ export interface GetMarketplaceTopOrdersResponse {
952
+ orders: Array<MarketplaceOrder>
718
953
  }
719
- export interface GetTokenBalancesSummaryArgs {
720
- filter: TokenBalancesFilter
721
- omitMetadata?: boolean
722
- page?: Page
954
+
955
+ export interface GetNativeTokenBalanceRequest {
956
+ accountAddress?: string
957
+ omitPrices?: boolean
723
958
  }
724
959
 
725
- export interface GetTokenBalancesSummaryReturn {
726
- page: Page
727
- nativeBalances: Array<NativeTokenBalance>
728
- balances: Array<TokenBalance>
960
+ export interface GetNativeTokenBalanceResponse {
961
+ balance: NativeTokenBalance
729
962
  }
730
- export interface GetTokenBalancesDetailsArgs {
731
- filter: TokenBalancesFilter
732
- omitMetadata?: boolean
963
+
964
+ export interface GetTokenBalancesRequest {
965
+ accountAddress?: string
966
+ contractAddress?: string
967
+ tokenID?: string
968
+ includeMetadata?: boolean
969
+ metadataOptions?: MetadataOptions
970
+ includeCollectionTokens?: boolean
733
971
  page?: Page
734
972
  }
735
973
 
736
- export interface GetTokenBalancesDetailsReturn {
974
+ export interface GetTokenBalancesResponse {
737
975
  page: Page
738
- nativeBalances: Array<NativeTokenBalance>
739
976
  balances: Array<TokenBalance>
740
977
  }
741
- export interface GetTokenBalancesByContractArgs {
978
+
979
+ export interface GetTokenBalancesByContractRequest {
742
980
  filter: TokenBalancesByContractFilter
743
981
  omitMetadata?: boolean
744
982
  page?: Page
745
983
  }
746
984
 
747
- export interface GetTokenBalancesByContractReturn {
985
+ export interface GetTokenBalancesByContractResponse {
748
986
  page: Page
749
987
  balances: Array<TokenBalance>
750
988
  }
751
- export interface GetTokenBalancesArgs {
752
- accountAddress?: string
753
- contractAddress?: string
754
- tokenID?: string
755
- includeMetadata?: boolean
756
- metadataOptions?: MetadataOptions
757
- includeCollectionTokens?: boolean
989
+
990
+ export interface GetTokenBalancesDetailsRequest {
991
+ filter: TokenBalancesFilter
992
+ omitMetadata?: boolean
758
993
  page?: Page
759
994
  }
760
995
 
761
- export interface GetTokenBalancesReturn {
996
+ export interface GetTokenBalancesDetailsResponse {
762
997
  page: Page
998
+ nativeBalances: Array<NativeTokenBalance>
763
999
  balances: Array<TokenBalance>
764
1000
  }
765
- export interface GetTokenSuppliesArgs {
766
- contractAddress: string
767
- includeMetadata?: boolean
768
- metadataOptions?: MetadataOptions
1001
+
1002
+ export interface GetTokenBalancesSummaryRequest {
1003
+ filter: TokenBalancesFilter
1004
+ omitMetadata?: boolean
769
1005
  page?: Page
770
1006
  }
771
1007
 
772
- export interface GetTokenSuppliesReturn {
1008
+ export interface GetTokenBalancesSummaryResponse {
773
1009
  page: Page
774
- contractType: ContractType
775
- tokenIDs: Array<TokenSupply>
1010
+ nativeBalances: Array<NativeTokenBalance>
1011
+ balances: Array<TokenBalance>
776
1012
  }
777
- export interface GetTokenSuppliesMapArgs {
778
- tokenMap: { [key: string]: Array<string> }
779
- includeMetadata?: boolean
780
- metadataOptions?: MetadataOptions
1013
+
1014
+ export interface GetTokenIDRangesRequest {
1015
+ contractAddress: string
1016
+ lastTokenID?: string
781
1017
  }
782
1018
 
783
- export interface GetTokenSuppliesMapReturn {
784
- supplies: { [key: string]: Array<TokenSupply> }
1019
+ export interface GetTokenIDRangesResponse {
1020
+ contractType: ContractType
1021
+ tokenIDRanges: Array<TokenIDRange>
1022
+ moreRanges: boolean
785
1023
  }
786
- export interface GetTokenIDsArgs {
1024
+
1025
+ export interface GetTokenIDsRequest {
787
1026
  contractAddress: string
788
1027
  page?: Page
789
1028
  }
790
1029
 
791
- export interface GetTokenIDsReturn {
1030
+ export interface GetTokenIDsResponse {
792
1031
  page: Page
793
1032
  contractType: ContractType
794
1033
  tokenIDs: Array<string>
795
1034
  }
796
- export interface GetTokenIDRangesArgs {
797
- contractAddress: string
1035
+
1036
+ export interface GetTokenPriceRequest {
1037
+ q: TokenPriceQuery
798
1038
  }
799
1039
 
800
- export interface GetTokenIDRangesReturn {
801
- contractType: ContractType
802
- tokenIDRanges: Array<TokenIDRange>
803
- moreRanges: boolean
1040
+ export interface GetTokenPriceResponse {
1041
+ price: Price
1042
+ }
1043
+
1044
+ export interface GetTokenPricesRequest {
1045
+ q: Array<TokenPriceQuery>
1046
+ }
1047
+
1048
+ export interface GetTokenPricesResponse {
1049
+ prices: Array<Price>
804
1050
  }
805
- export interface GetBalanceUpdatesArgs {
1051
+
1052
+ export interface GetTokenSuppliesRequest {
806
1053
  contractAddress: string
807
- lastBlockNumber: number
808
- lastBlockHash?: string
1054
+ includeMetadata?: boolean
809
1055
  page?: Page
810
1056
  }
811
1057
 
812
- export interface GetBalanceUpdatesReturn {
1058
+ export interface GetTokenSuppliesResponse {
813
1059
  page: Page
814
- balances: Array<TokenBalance>
1060
+ contractType: ContractType
1061
+ tokenIDs: Array<TokenSupply>
1062
+ }
1063
+
1064
+ export interface GetTokenSuppliesMapRequest {
1065
+ tokenMap: {[key: string]: Array<string>}
1066
+ includeMetadata?: boolean
1067
+ }
1068
+
1069
+ export interface GetTokenSuppliesMapResponse {
1070
+ supplies: {[key: string]: Array<TokenSupply>}
815
1071
  }
816
- export interface GetTransactionHistoryArgs {
1072
+
1073
+ export interface GetTransactionHistoryRequest {
817
1074
  filter: TransactionHistoryFilter
818
1075
  page?: Page
819
1076
  includeMetadata?: boolean
820
1077
  metadataOptions?: MetadataOptions
821
1078
  }
822
1079
 
823
- export interface GetTransactionHistoryReturn {
1080
+ export interface GetTransactionHistoryResponse {
824
1081
  page: Page
825
1082
  transactions: Array<Transaction>
826
1083
  }
827
- export interface FetchTransactionReceiptArgs {
828
- txnHash: string
829
- maxBlockWait?: number
830
- }
831
1084
 
832
- export interface FetchTransactionReceiptReturn {
833
- receipt: TransactionReceipt
834
- }
835
- export interface FetchTransactionReceiptWithFilterArgs {
836
- filter: TransactionFilter
837
- maxBlockWait?: number
1085
+ export interface GetWebhookListenerRequest {
1086
+ id: number
1087
+ projectId?: number
838
1088
  }
839
1089
 
840
- export interface FetchTransactionReceiptWithFilterReturn {
841
- receipt: TransactionReceipt
842
- }
843
- export interface SubscribeReceiptsArgs {
844
- filter: TransactionFilter
1090
+ export interface GetWebhookListenerResponse {
1091
+ listener: WebhookListener
845
1092
  }
846
1093
 
847
- export interface SubscribeReceiptsReturn {
848
- receipt: TransactionReceipt
1094
+ export interface ListTokenPricesRequest {
1095
+ page?: Page
849
1096
  }
850
- export interface SubscribeEventsArgs {
851
- filter: EventFilter
1097
+
1098
+ export interface ListTokenPricesResponse {
1099
+ page: Page
1100
+ prices: Array<Price>
852
1101
  }
853
1102
 
854
- export interface SubscribeEventsReturn {
855
- log: EventLog
1103
+ export interface PauseAllWebhookListenersRequest {
1104
+ projectId?: number
856
1105
  }
857
- export interface SubscribeBalanceUpdatesArgs {
858
- contractAddress: string
1106
+
1107
+ export interface PauseAllWebhookListenersResponse {
1108
+ status: boolean
859
1109
  }
860
1110
 
861
- export interface SubscribeBalanceUpdatesReturn {
862
- balance: TokenBalance
1111
+ export interface PingRequest {
863
1112
  }
864
- export interface SyncBalanceArgs {
865
- accountAddress: string
866
- contractAddress: string
867
- tokenID?: string
1113
+
1114
+ export interface PingResponse {
1115
+ status: boolean
868
1116
  }
869
1117
 
870
- export interface SyncBalanceReturn {}
871
- export interface GetAllWebhookListenersArgs {
1118
+ export interface RemoveAllWebhookListenersRequest {
872
1119
  projectId?: number
873
1120
  }
874
1121
 
875
- export interface GetAllWebhookListenersReturn {
876
- listeners: Array<WebhookListener>
1122
+ export interface RemoveAllWebhookListenersResponse {
1123
+ status: boolean
877
1124
  }
878
- export interface GetWebhookListenerArgs {
1125
+
1126
+ export interface RemoveWebhookListenerRequest {
879
1127
  id: number
880
1128
  projectId?: number
881
1129
  }
882
1130
 
883
- export interface GetWebhookListenerReturn {
884
- listener: WebhookListener
1131
+ export interface RemoveWebhookListenerResponse {
1132
+ status: boolean
885
1133
  }
886
- export interface AddWebhookListenerArgs {
887
- url: string
888
- filters: EventFilter
1134
+
1135
+ export interface ResumeAllWebhookListenersRequest {
889
1136
  projectId?: number
890
1137
  }
891
1138
 
892
- export interface AddWebhookListenerReturn {
1139
+ export interface ResumeAllWebhookListenersResponse {
893
1140
  status: boolean
894
- listener: WebhookListener
895
1141
  }
896
- export interface UpdateWebhookListenerArgs {
897
- listener: WebhookListener
898
- projectId?: number
1142
+
1143
+ export interface RuntimeStatusRequest {
899
1144
  }
900
1145
 
901
- export interface UpdateWebhookListenerReturn {
902
- status: boolean
1146
+ export interface RuntimeStatusResponse {
1147
+ status: RuntimeStatus
903
1148
  }
904
- export interface RemoveWebhookListenerArgs {
905
- id: number
906
- projectId?: number
1149
+
1150
+ export interface SubscribeBalanceUpdatesRequest {
1151
+ contractAddress: string
907
1152
  }
908
1153
 
909
- export interface RemoveWebhookListenerReturn {
910
- status: boolean
1154
+ export interface SubscribeBalanceUpdatesResponse {
1155
+ balance: TokenBalance
911
1156
  }
912
- export interface RemoveAllWebhookListenersArgs {
913
- projectId?: number
1157
+
1158
+ export interface SubscribeEventsRequest {
1159
+ filter: EventFilter
914
1160
  }
915
1161
 
916
- export interface RemoveAllWebhookListenersReturn {
917
- status: boolean
1162
+ export interface SubscribeEventsResponse {
1163
+ log: EventLog
918
1164
  }
919
- export interface ToggleWebhookListenerArgs {
920
- id: number
921
- projectId?: number
1165
+
1166
+ export interface SubscribeReceiptsRequest {
1167
+ filter: TransactionFilter
922
1168
  }
923
1169
 
924
- export interface ToggleWebhookListenerReturn {
925
- webhookListener: WebhookListener
1170
+ export interface SubscribeReceiptsResponse {
1171
+ receipt: TransactionReceipt
926
1172
  }
927
- export interface PauseAllWebhookListenersArgs {
928
- projectId?: number
1173
+
1174
+ export interface SyncBalanceRequest {
1175
+ accountAddress: string
1176
+ contractAddress: string
1177
+ tokenID?: string
929
1178
  }
930
1179
 
931
- export interface PauseAllWebhookListenersReturn {
932
- status: boolean
1180
+ export interface SyncBalanceResponse {
933
1181
  }
934
- export interface ResumeAllWebhookListenersArgs {
1182
+
1183
+ export interface ToggleWebhookListenerRequest {
1184
+ id: number
935
1185
  projectId?: number
936
1186
  }
937
1187
 
938
- export interface ResumeAllWebhookListenersReturn {
939
- status: boolean
1188
+ export interface ToggleWebhookListenerResponse {
1189
+ webhookListener: WebhookListener
940
1190
  }
941
- export interface GetOrderbookOrdersArgs {
942
- page?: Page
943
- orderbookContractAddress: string
944
- collectionAddress: string
945
- currencyAddresses: Array<string>
946
- filter: OrderbookOrderFilter
947
- orderStatuses: Array<OrderStatus>
948
- filters: Array<OrderbookOrderFilter>
949
- beforeExpiryTimestamp: number
950
- blockNumberAfter: number
951
- createdAtAfter: number
1191
+
1192
+ export interface UpdateWebhookListenerRequest {
1193
+ listener: WebhookListener
1194
+ projectId?: number
952
1195
  }
953
1196
 
954
- export interface GetOrderbookOrdersReturn {
955
- page?: Page
956
- orders: Array<OrderbookOrder>
1197
+ export interface UpdateWebhookListenerResponse {
1198
+ status: boolean
957
1199
  }
958
- export interface GetTopOrdersArgs {
959
- orderbookContractAddress: string
960
- collectionAddress: string
961
- currencyAddresses: Array<string>
962
- tokenIDs: Array<string>
963
- isListing: boolean
964
- priceSort: SortOrder
965
- excludeUser?: string
1200
+
1201
+ export interface VersionRequest {
966
1202
  }
967
1203
 
968
- export interface GetTopOrdersReturn {
969
- orders: Array<OrderbookOrder>
1204
+ export interface VersionResponse {
1205
+ version: Version
970
1206
  }
971
1207
 
1208
+
1209
+
972
1210
  //
973
1211
  // Client
974
1212
  //
975
- export class Indexer implements Indexer {
1213
+
1214
+ export class Indexer implements IndexerClient {
976
1215
  protected hostname: string
977
1216
  protected fetch: Fetch
978
1217
  protected path = '/rpc/Indexer/'
@@ -985,708 +1224,643 @@ export class Indexer implements Indexer {
985
1224
  private url(name: string): string {
986
1225
  return this.hostname + this.path + name
987
1226
  }
1227
+
1228
+ queryKey = {
1229
+ addWebhookListener: (req: AddWebhookListenerRequest) => ['Indexer', 'addWebhookListener', req] as const,
1230
+ fetchTransactionReceipt: (req: FetchTransactionReceiptRequest) => ['Indexer', 'fetchTransactionReceipt', req] as const,
1231
+ fetchTransactionReceiptWithFilter: (req: FetchTransactionReceiptWithFilterRequest) => ['Indexer', 'fetchTransactionReceiptWithFilter', req] as const,
1232
+ getAllWebhookListeners: (req: GetAllWebhookListenersRequest) => ['Indexer', 'getAllWebhookListeners', req] as const,
1233
+ getBalanceUpdates: (req: GetBalanceUpdatesRequest) => ['Indexer', 'getBalanceUpdates', req] as const,
1234
+ getChainID: () => ['Indexer', 'getChainID'] as const,
1235
+ getEtherBalance: (req: GetEtherBalanceRequest) => ['Indexer', 'getEtherBalance', req] as const,
1236
+ getMarketplaceOrders: (req: GetMarketplaceOrdersRequest) => ['Indexer', 'getMarketplaceOrders', req] as const,
1237
+ getMarketplaceTopOrders: (req: GetMarketplaceTopOrdersRequest) => ['Indexer', 'getMarketplaceTopOrders', req] as const,
1238
+ getNativeTokenBalance: (req: GetNativeTokenBalanceRequest) => ['Indexer', 'getNativeTokenBalance', req] as const,
1239
+ getTokenBalances: (req: GetTokenBalancesRequest) => ['Indexer', 'getTokenBalances', req] as const,
1240
+ getTokenBalancesByContract: (req: GetTokenBalancesByContractRequest) => ['Indexer', 'getTokenBalancesByContract', req] as const,
1241
+ getTokenBalancesDetails: (req: GetTokenBalancesDetailsRequest) => ['Indexer', 'getTokenBalancesDetails', req] as const,
1242
+ getTokenBalancesSummary: (req: GetTokenBalancesSummaryRequest) => ['Indexer', 'getTokenBalancesSummary', req] as const,
1243
+ getTokenIDRanges: (req: GetTokenIDRangesRequest) => ['Indexer', 'getTokenIDRanges', req] as const,
1244
+ getTokenIDs: (req: GetTokenIDsRequest) => ['Indexer', 'getTokenIDs', req] as const,
1245
+ getTokenPrice: (req: GetTokenPriceRequest) => ['Indexer', 'getTokenPrice', req] as const,
1246
+ getTokenPrices: (req: GetTokenPricesRequest) => ['Indexer', 'getTokenPrices', req] as const,
1247
+ getTokenSupplies: (req: GetTokenSuppliesRequest) => ['Indexer', 'getTokenSupplies', req] as const,
1248
+ getTokenSuppliesMap: (req: GetTokenSuppliesMapRequest) => ['Indexer', 'getTokenSuppliesMap', req] as const,
1249
+ getTransactionHistory: (req: GetTransactionHistoryRequest) => ['Indexer', 'getTransactionHistory', req] as const,
1250
+ getWebhookListener: (req: GetWebhookListenerRequest) => ['Indexer', 'getWebhookListener', req] as const,
1251
+ listTokenPrices: (req: ListTokenPricesRequest) => ['Indexer', 'listTokenPrices', req] as const,
1252
+ pauseAllWebhookListeners: (req: PauseAllWebhookListenersRequest) => ['Indexer', 'pauseAllWebhookListeners', req] as const,
1253
+ ping: () => ['Indexer', 'ping'] as const,
1254
+ removeAllWebhookListeners: (req: RemoveAllWebhookListenersRequest) => ['Indexer', 'removeAllWebhookListeners', req] as const,
1255
+ removeWebhookListener: (req: RemoveWebhookListenerRequest) => ['Indexer', 'removeWebhookListener', req] as const,
1256
+ resumeAllWebhookListeners: (req: ResumeAllWebhookListenersRequest) => ['Indexer', 'resumeAllWebhookListeners', req] as const,
1257
+ runtimeStatus: () => ['Indexer', 'runtimeStatus'] as const,
1258
+ subscribeBalanceUpdates: (req: SubscribeBalanceUpdatesRequest) => ['Indexer', 'subscribeBalanceUpdates', req] as const,
1259
+ subscribeEvents: (req: SubscribeEventsRequest) => ['Indexer', 'subscribeEvents', req] as const,
1260
+ subscribeReceipts: (req: SubscribeReceiptsRequest) => ['Indexer', 'subscribeReceipts', req] as const,
1261
+ syncBalance: (req: SyncBalanceRequest) => ['Indexer', 'syncBalance', req] as const,
1262
+ toggleWebhookListener: (req: ToggleWebhookListenerRequest) => ['Indexer', 'toggleWebhookListener', req] as const,
1263
+ updateWebhookListener: (req: UpdateWebhookListenerRequest) => ['Indexer', 'updateWebhookListener', req] as const,
1264
+ version: () => ['Indexer', 'version'] as const,
1265
+ }
1266
+
1267
+ addWebhookListener = (req: AddWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<AddWebhookListenerResponse> => {
1268
+ return this.fetch(
1269
+ this.url('AddWebhookListener'),
1270
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1271
+ return buildResponse(res).then(_data => {
1272
+ return JsonDecode<AddWebhookListenerResponse>(_data, 'AddWebhookListenerResponse')
1273
+ })
1274
+ }, (error) => {
1275
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1276
+ })
1277
+ }
988
1278
 
989
- ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
990
- return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(
991
- res => {
992
- return buildResponse(res).then(_data => {
993
- return {
994
- status: <boolean>_data.status
995
- }
996
- })
997
- },
998
- error => {
999
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1000
- }
1001
- )
1002
- }
1003
-
1004
- version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => {
1005
- return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(
1006
- res => {
1007
- return buildResponse(res).then(_data => {
1008
- return {
1009
- version: <Version>_data.version
1010
- }
1011
- })
1012
- },
1013
- error => {
1014
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1015
- }
1016
- )
1017
- }
1018
-
1019
- runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => {
1020
- return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(
1021
- res => {
1022
- return buildResponse(res).then(_data => {
1023
- return {
1024
- status: <RuntimeStatus>_data.status
1025
- }
1026
- })
1027
- },
1028
- error => {
1029
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1030
- }
1031
- )
1032
- }
1033
-
1034
- getChainID = (headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn> => {
1035
- return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(
1036
- res => {
1037
- return buildResponse(res).then(_data => {
1038
- return {
1039
- chainID: <number>_data.chainID
1040
- }
1041
- })
1042
- },
1043
- error => {
1044
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1045
- }
1046
- )
1047
- }
1048
-
1049
- getEtherBalance = (args: GetEtherBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceReturn> => {
1050
- return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then(
1051
- res => {
1052
- return buildResponse(res).then(_data => {
1053
- return {
1054
- balance: <EtherBalance>_data.balance
1055
- }
1056
- })
1057
- },
1058
- error => {
1059
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1060
- }
1061
- )
1062
- }
1063
-
1064
- getNativeTokenBalance = (
1065
- args: GetNativeTokenBalanceArgs,
1066
- headers?: object,
1067
- signal?: AbortSignal
1068
- ): Promise<GetNativeTokenBalanceReturn> => {
1069
- return this.fetch(this.url('GetNativeTokenBalance'), createHTTPRequest(args, headers, signal)).then(
1070
- res => {
1071
- return buildResponse(res).then(_data => {
1072
- return {
1073
- balance: <NativeTokenBalance>_data.balance
1074
- }
1075
- })
1076
- },
1077
- error => {
1078
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1079
- }
1080
- )
1081
- }
1082
-
1083
- getTokenBalancesSummary = (
1084
- args: GetTokenBalancesSummaryArgs,
1085
- headers?: object,
1086
- signal?: AbortSignal
1087
- ): Promise<GetTokenBalancesSummaryReturn> => {
1088
- return this.fetch(this.url('GetTokenBalancesSummary'), createHTTPRequest(args, headers, signal)).then(
1089
- res => {
1090
- return buildResponse(res).then(_data => {
1091
- return {
1092
- page: <Page>_data.page,
1093
- nativeBalances: <Array<NativeTokenBalance>>_data.nativeBalances,
1094
- balances: <Array<TokenBalance>>_data.balances
1095
- }
1096
- })
1097
- },
1098
- error => {
1099
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1100
- }
1101
- )
1102
- }
1103
-
1104
- getTokenBalancesDetails = (
1105
- args: GetTokenBalancesDetailsArgs,
1106
- headers?: object,
1107
- signal?: AbortSignal
1108
- ): Promise<GetTokenBalancesDetailsReturn> => {
1109
- return this.fetch(this.url('GetTokenBalancesDetails'), createHTTPRequest(args, headers, signal)).then(
1110
- res => {
1111
- return buildResponse(res).then(_data => {
1112
- return {
1113
- page: <Page>_data.page,
1114
- nativeBalances: <Array<NativeTokenBalance>>_data.nativeBalances,
1115
- balances: <Array<TokenBalance>>_data.balances
1116
- }
1117
- })
1118
- },
1119
- error => {
1120
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1121
- }
1122
- )
1123
- }
1124
-
1125
- getTokenBalancesByContract = (
1126
- args: GetTokenBalancesByContractArgs,
1127
- headers?: object,
1128
- signal?: AbortSignal
1129
- ): Promise<GetTokenBalancesByContractReturn> => {
1130
- return this.fetch(this.url('GetTokenBalancesByContract'), createHTTPRequest(args, headers, signal)).then(
1131
- res => {
1132
- return buildResponse(res).then(_data => {
1133
- return {
1134
- page: <Page>_data.page,
1135
- balances: <Array<TokenBalance>>_data.balances
1136
- }
1137
- })
1138
- },
1139
- error => {
1140
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1141
- }
1142
- )
1143
- }
1144
-
1145
- getTokenBalances = (args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn> => {
1146
- return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(
1147
- res => {
1148
- return buildResponse(res).then(_data => {
1149
- return {
1150
- page: <Page>_data.page,
1151
- balances: <Array<TokenBalance>>_data.balances
1152
- }
1153
- })
1154
- },
1155
- error => {
1156
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1157
- }
1158
- )
1159
- }
1160
-
1161
- getTokenSupplies = (args: GetTokenSuppliesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesReturn> => {
1162
- return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then(
1163
- res => {
1164
- return buildResponse(res).then(_data => {
1165
- return {
1166
- page: <Page>_data.page,
1167
- contractType: <ContractType>_data.contractType,
1168
- tokenIDs: <Array<TokenSupply>>_data.tokenIDs
1169
- }
1170
- })
1171
- },
1172
- error => {
1173
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1174
- }
1175
- )
1176
- }
1177
-
1178
- getTokenSuppliesMap = (
1179
- args: GetTokenSuppliesMapArgs,
1180
- headers?: object,
1181
- signal?: AbortSignal
1182
- ): Promise<GetTokenSuppliesMapReturn> => {
1183
- return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then(
1184
- res => {
1185
- return buildResponse(res).then(_data => {
1186
- return {
1187
- supplies: <{ [key: string]: Array<TokenSupply> }>_data.supplies
1188
- }
1189
- })
1190
- },
1191
- error => {
1192
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1193
- }
1194
- )
1195
- }
1196
-
1197
- getTokenIDs = (args: GetTokenIDsArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenIDsReturn> => {
1198
- return this.fetch(this.url('GetTokenIDs'), createHTTPRequest(args, headers, signal)).then(
1199
- res => {
1200
- return buildResponse(res).then(_data => {
1201
- return {
1202
- page: <Page>_data.page,
1203
- contractType: <ContractType>_data.contractType,
1204
- tokenIDs: <Array<string>>_data.tokenIDs
1205
- }
1206
- })
1207
- },
1208
- error => {
1209
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1210
- }
1211
- )
1212
- }
1213
-
1214
- getTokenIDRanges = (args: GetTokenIDRangesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenIDRangesReturn> => {
1215
- return this.fetch(this.url('GetTokenIDRanges'), createHTTPRequest(args, headers, signal)).then(
1216
- res => {
1217
- return buildResponse(res).then(_data => {
1218
- return {
1219
- contractType: <ContractType>_data.contractType,
1220
- tokenIDRanges: <Array<TokenIDRange>>_data.tokenIDRanges,
1221
- moreRanges: <boolean>_data.moreRanges
1222
- }
1223
- })
1224
- },
1225
- error => {
1226
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1227
- }
1228
- )
1229
- }
1230
-
1231
- getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn> => {
1232
- return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(
1233
- res => {
1234
- return buildResponse(res).then(_data => {
1235
- return {
1236
- page: <Page>_data.page,
1237
- balances: <Array<TokenBalance>>_data.balances
1238
- }
1239
- })
1240
- },
1241
- error => {
1242
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1243
- }
1244
- )
1245
- }
1246
-
1247
- getTransactionHistory = (
1248
- args: GetTransactionHistoryArgs,
1249
- headers?: object,
1250
- signal?: AbortSignal
1251
- ): Promise<GetTransactionHistoryReturn> => {
1252
- return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then(
1253
- res => {
1254
- return buildResponse(res).then(_data => {
1255
- return {
1256
- page: <Page>_data.page,
1257
- transactions: <Array<Transaction>>_data.transactions
1258
- }
1259
- })
1260
- },
1261
- error => {
1262
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1263
- }
1264
- )
1265
- }
1266
-
1267
- fetchTransactionReceipt = (
1268
- args: FetchTransactionReceiptArgs,
1269
- headers?: object,
1270
- signal?: AbortSignal
1271
- ): Promise<FetchTransactionReceiptReturn> => {
1272
- return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then(
1273
- res => {
1274
- return buildResponse(res).then(_data => {
1275
- return {
1276
- receipt: <TransactionReceipt>_data.receipt
1277
- }
1278
- })
1279
- },
1280
- error => {
1281
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1282
- }
1283
- )
1284
- }
1285
-
1286
- fetchTransactionReceiptWithFilter = (
1287
- args: FetchTransactionReceiptWithFilterArgs,
1288
- headers?: object,
1289
- signal?: AbortSignal
1290
- ): Promise<FetchTransactionReceiptWithFilterReturn> => {
1291
- return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then(
1292
- res => {
1293
- return buildResponse(res).then(_data => {
1294
- return {
1295
- receipt: <TransactionReceipt>_data.receipt
1296
- }
1297
- })
1298
- },
1299
- error => {
1300
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1301
- }
1302
- )
1303
- }
1304
-
1305
- subscribeReceipts = (args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>): Promise<void> => {
1306
- const _fetch = () =>
1307
- this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then(
1308
- async res => {
1309
- await sseResponse(res, options, _fetch)
1310
- },
1311
- error => {
1312
- options.onError(error, _fetch)
1313
- }
1314
- )
1315
- return _fetch()
1316
- }
1317
- subscribeEvents = (args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>): Promise<void> => {
1318
- const _fetch = () =>
1319
- this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then(
1320
- async res => {
1321
- await sseResponse(res, options, _fetch)
1322
- },
1323
- error => {
1324
- options.onError(error, _fetch)
1325
- }
1326
- )
1327
- return _fetch()
1328
- }
1329
- subscribeBalanceUpdates = (
1330
- args: SubscribeBalanceUpdatesArgs,
1331
- options: WebrpcStreamOptions<SubscribeBalanceUpdatesReturn>
1332
- ): Promise<void> => {
1333
- const _fetch = () =>
1334
- this.fetch(this.url('SubscribeBalanceUpdates'), createHTTPRequest(args, options.headers, options.signal)).then(
1335
- async res => {
1336
- await sseResponse(res, options, _fetch)
1337
- },
1338
- error => {
1339
- options.onError(error, _fetch)
1340
- }
1341
- )
1342
- return _fetch()
1343
- }
1344
- syncBalance = (args: SyncBalanceArgs, headers?: object, signal?: AbortSignal): Promise<SyncBalanceReturn> => {
1345
- return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then(
1346
- res => {
1347
- return buildResponse(res).then(_data => {
1348
- return {}
1349
- })
1350
- },
1351
- error => {
1352
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1353
- }
1354
- )
1355
- }
1356
-
1357
- getAllWebhookListeners = (
1358
- args: GetAllWebhookListenersArgs,
1359
- headers?: object,
1360
- signal?: AbortSignal
1361
- ): Promise<GetAllWebhookListenersReturn> => {
1362
- return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(
1363
- res => {
1364
- return buildResponse(res).then(_data => {
1365
- return {
1366
- listeners: <Array<WebhookListener>>_data.listeners
1367
- }
1368
- })
1369
- },
1370
- error => {
1371
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1372
- }
1373
- )
1374
- }
1375
-
1376
- getWebhookListener = (
1377
- args: GetWebhookListenerArgs,
1378
- headers?: object,
1379
- signal?: AbortSignal
1380
- ): Promise<GetWebhookListenerReturn> => {
1381
- return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then(
1382
- res => {
1383
- return buildResponse(res).then(_data => {
1384
- return {
1385
- listener: <WebhookListener>_data.listener
1386
- }
1387
- })
1388
- },
1389
- error => {
1390
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1391
- }
1392
- )
1393
- }
1394
-
1395
- addWebhookListener = (
1396
- args: AddWebhookListenerArgs,
1397
- headers?: object,
1398
- signal?: AbortSignal
1399
- ): Promise<AddWebhookListenerReturn> => {
1400
- return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then(
1401
- res => {
1402
- return buildResponse(res).then(_data => {
1403
- return {
1404
- status: <boolean>_data.status,
1405
- listener: <WebhookListener>_data.listener
1406
- }
1407
- })
1408
- },
1409
- error => {
1410
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1411
- }
1412
- )
1413
- }
1414
-
1415
- updateWebhookListener = (
1416
- args: UpdateWebhookListenerArgs,
1417
- headers?: object,
1418
- signal?: AbortSignal
1419
- ): Promise<UpdateWebhookListenerReturn> => {
1420
- return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then(
1421
- res => {
1422
- return buildResponse(res).then(_data => {
1423
- return {
1424
- status: <boolean>_data.status
1425
- }
1426
- })
1427
- },
1428
- error => {
1429
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1430
- }
1431
- )
1432
- }
1433
-
1434
- removeWebhookListener = (
1435
- args: RemoveWebhookListenerArgs,
1436
- headers?: object,
1437
- signal?: AbortSignal
1438
- ): Promise<RemoveWebhookListenerReturn> => {
1439
- return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then(
1440
- res => {
1441
- return buildResponse(res).then(_data => {
1442
- return {
1443
- status: <boolean>_data.status
1444
- }
1445
- })
1446
- },
1447
- error => {
1448
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1449
- }
1450
- )
1451
- }
1452
-
1453
- removeAllWebhookListeners = (
1454
- args: RemoveAllWebhookListenersArgs,
1455
- headers?: object,
1456
- signal?: AbortSignal
1457
- ): Promise<RemoveAllWebhookListenersReturn> => {
1458
- return this.fetch(this.url('RemoveAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(
1459
- res => {
1460
- return buildResponse(res).then(_data => {
1461
- return {
1462
- status: <boolean>_data.status
1463
- }
1464
- })
1465
- },
1466
- error => {
1467
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1468
- }
1469
- )
1470
- }
1471
-
1472
- toggleWebhookListener = (
1473
- args: ToggleWebhookListenerArgs,
1474
- headers?: object,
1475
- signal?: AbortSignal
1476
- ): Promise<ToggleWebhookListenerReturn> => {
1477
- return this.fetch(this.url('ToggleWebhookListener'), createHTTPRequest(args, headers, signal)).then(
1478
- res => {
1479
- return buildResponse(res).then(_data => {
1480
- return {
1481
- webhookListener: <WebhookListener>_data.webhookListener
1482
- }
1483
- })
1484
- },
1485
- error => {
1486
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1487
- }
1488
- )
1489
- }
1490
-
1491
- pauseAllWebhookListeners = (
1492
- args: PauseAllWebhookListenersArgs,
1493
- headers?: object,
1494
- signal?: AbortSignal
1495
- ): Promise<PauseAllWebhookListenersReturn> => {
1496
- return this.fetch(this.url('PauseAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(
1497
- res => {
1498
- return buildResponse(res).then(_data => {
1499
- return {
1500
- status: <boolean>_data.status
1501
- }
1502
- })
1503
- },
1504
- error => {
1505
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1506
- }
1507
- )
1508
- }
1509
-
1510
- resumeAllWebhookListeners = (
1511
- args: ResumeAllWebhookListenersArgs,
1512
- headers?: object,
1513
- signal?: AbortSignal
1514
- ): Promise<ResumeAllWebhookListenersReturn> => {
1515
- return this.fetch(this.url('ResumeAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(
1516
- res => {
1517
- return buildResponse(res).then(_data => {
1518
- return {
1519
- status: <boolean>_data.status
1520
- }
1521
- })
1522
- },
1523
- error => {
1524
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1525
- }
1526
- )
1527
- }
1528
-
1529
- getOrderbookOrders = (
1530
- args: GetOrderbookOrdersArgs,
1531
- headers?: object,
1532
- signal?: AbortSignal
1533
- ): Promise<GetOrderbookOrdersReturn> => {
1534
- return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then(
1535
- res => {
1536
- return buildResponse(res).then(_data => {
1537
- return {
1538
- page: <Page>_data.page,
1539
- orders: <Array<OrderbookOrder>>_data.orders
1540
- }
1541
- })
1542
- },
1543
- error => {
1544
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1545
- }
1546
- )
1547
- }
1548
-
1549
- getTopOrders = (args: GetTopOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetTopOrdersReturn> => {
1550
- return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then(
1551
- res => {
1552
- return buildResponse(res).then(_data => {
1553
- return {
1554
- orders: <Array<OrderbookOrder>>_data.orders
1555
- }
1556
- })
1557
- },
1558
- error => {
1559
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1560
- }
1561
- )
1562
- }
1563
- }
1564
-
1565
- const sseResponse = async (res: Response, options: WebrpcStreamOptions<any>, retryFetch: () => Promise<void>) => {
1566
- const { onMessage, onOpen, onClose, onError } = options
1567
-
1568
- if (!res.ok) {
1569
- try {
1570
- await buildResponse(res)
1571
- } catch (error) {
1572
- // @ts-ignore
1573
- onError(error, retryFetch)
1279
+ fetchTransactionReceipt = (req: FetchTransactionReceiptRequest, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptResponse> => {
1280
+ return this.fetch(
1281
+ this.url('FetchTransactionReceipt'),
1282
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1283
+ return buildResponse(res).then(_data => {
1284
+ return JsonDecode<FetchTransactionReceiptResponse>(_data, 'FetchTransactionReceiptResponse')
1285
+ })
1286
+ }, (error) => {
1287
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1288
+ })
1289
+ }
1290
+
1291
+ fetchTransactionReceiptWithFilter = (req: FetchTransactionReceiptWithFilterRequest, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptWithFilterResponse> => {
1292
+ return this.fetch(
1293
+ this.url('FetchTransactionReceiptWithFilter'),
1294
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1295
+ return buildResponse(res).then(_data => {
1296
+ return JsonDecode<FetchTransactionReceiptWithFilterResponse>(_data, 'FetchTransactionReceiptWithFilterResponse')
1297
+ })
1298
+ }, (error) => {
1299
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1300
+ })
1301
+ }
1302
+
1303
+ getAllWebhookListeners = (req: GetAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<GetAllWebhookListenersResponse> => {
1304
+ return this.fetch(
1305
+ this.url('GetAllWebhookListeners'),
1306
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1307
+ return buildResponse(res).then(_data => {
1308
+ return JsonDecode<GetAllWebhookListenersResponse>(_data, 'GetAllWebhookListenersResponse')
1309
+ })
1310
+ }, (error) => {
1311
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1312
+ })
1313
+ }
1314
+
1315
+ getBalanceUpdates = (req: GetBalanceUpdatesRequest, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesResponse> => {
1316
+ return this.fetch(
1317
+ this.url('GetBalanceUpdates'),
1318
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1319
+ return buildResponse(res).then(_data => {
1320
+ return JsonDecode<GetBalanceUpdatesResponse>(_data, 'GetBalanceUpdatesResponse')
1321
+ })
1322
+ }, (error) => {
1323
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1324
+ })
1325
+ }
1326
+
1327
+ getChainID = (headers?: object, signal?: AbortSignal): Promise<GetChainIDResponse> => {
1328
+ return this.fetch(
1329
+ this.url('GetChainID'),
1330
+ createHttpRequest('{}', headers, signal)).then((res) => {
1331
+ return buildResponse(res).then(_data => {
1332
+ return JsonDecode<GetChainIDResponse>(_data, 'GetChainIDResponse')
1333
+ })
1334
+ }, (error) => {
1335
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1336
+ })
1337
+ }
1338
+
1339
+ getEtherBalance = (req: GetEtherBalanceRequest, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceResponse> => {
1340
+ return this.fetch(
1341
+ this.url('GetEtherBalance'),
1342
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1343
+ return buildResponse(res).then(_data => {
1344
+ return JsonDecode<GetEtherBalanceResponse>(_data, 'GetEtherBalanceResponse')
1345
+ })
1346
+ }, (error) => {
1347
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1348
+ })
1349
+ }
1350
+
1351
+ getMarketplaceOrders = (req: GetMarketplaceOrdersRequest, headers?: object, signal?: AbortSignal): Promise<GetMarketplaceOrdersResponse> => {
1352
+ return this.fetch(
1353
+ this.url('GetMarketplaceOrders'),
1354
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1355
+ return buildResponse(res).then(_data => {
1356
+ return JsonDecode<GetMarketplaceOrdersResponse>(_data, 'GetMarketplaceOrdersResponse')
1357
+ })
1358
+ }, (error) => {
1359
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1360
+ })
1361
+ }
1362
+
1363
+ getMarketplaceTopOrders = (req: GetMarketplaceTopOrdersRequest, headers?: object, signal?: AbortSignal): Promise<GetMarketplaceTopOrdersResponse> => {
1364
+ return this.fetch(
1365
+ this.url('GetMarketplaceTopOrders'),
1366
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1367
+ return buildResponse(res).then(_data => {
1368
+ return JsonDecode<GetMarketplaceTopOrdersResponse>(_data, 'GetMarketplaceTopOrdersResponse')
1369
+ })
1370
+ }, (error) => {
1371
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1372
+ })
1373
+ }
1374
+
1375
+ getNativeTokenBalance = (req: GetNativeTokenBalanceRequest, headers?: object, signal?: AbortSignal): Promise<GetNativeTokenBalanceResponse> => {
1376
+ return this.fetch(
1377
+ this.url('GetNativeTokenBalance'),
1378
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1379
+ return buildResponse(res).then(_data => {
1380
+ return JsonDecode<GetNativeTokenBalanceResponse>(_data, 'GetNativeTokenBalanceResponse')
1381
+ })
1382
+ }, (error) => {
1383
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1384
+ })
1385
+ }
1386
+
1387
+ getTokenBalances = (req: GetTokenBalancesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesResponse> => {
1388
+ return this.fetch(
1389
+ this.url('GetTokenBalances'),
1390
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1391
+ return buildResponse(res).then(_data => {
1392
+ return JsonDecode<GetTokenBalancesResponse>(_data, 'GetTokenBalancesResponse')
1393
+ })
1394
+ }, (error) => {
1395
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1396
+ })
1397
+ }
1398
+
1399
+ getTokenBalancesByContract = (req: GetTokenBalancesByContractRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesByContractResponse> => {
1400
+ return this.fetch(
1401
+ this.url('GetTokenBalancesByContract'),
1402
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1403
+ return buildResponse(res).then(_data => {
1404
+ return JsonDecode<GetTokenBalancesByContractResponse>(_data, 'GetTokenBalancesByContractResponse')
1405
+ })
1406
+ }, (error) => {
1407
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1408
+ })
1409
+ }
1410
+
1411
+ getTokenBalancesDetails = (req: GetTokenBalancesDetailsRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesDetailsResponse> => {
1412
+ return this.fetch(
1413
+ this.url('GetTokenBalancesDetails'),
1414
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1415
+ return buildResponse(res).then(_data => {
1416
+ return JsonDecode<GetTokenBalancesDetailsResponse>(_data, 'GetTokenBalancesDetailsResponse')
1417
+ })
1418
+ }, (error) => {
1419
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1420
+ })
1421
+ }
1422
+
1423
+ getTokenBalancesSummary = (req: GetTokenBalancesSummaryRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesSummaryResponse> => {
1424
+ return this.fetch(
1425
+ this.url('GetTokenBalancesSummary'),
1426
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1427
+ return buildResponse(res).then(_data => {
1428
+ return JsonDecode<GetTokenBalancesSummaryResponse>(_data, 'GetTokenBalancesSummaryResponse')
1429
+ })
1430
+ }, (error) => {
1431
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1432
+ })
1433
+ }
1434
+
1435
+ getTokenIDRanges = (req: GetTokenIDRangesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenIDRangesResponse> => {
1436
+ return this.fetch(
1437
+ this.url('GetTokenIDRanges'),
1438
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1439
+ return buildResponse(res).then(_data => {
1440
+ return JsonDecode<GetTokenIDRangesResponse>(_data, 'GetTokenIDRangesResponse')
1441
+ })
1442
+ }, (error) => {
1443
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1444
+ })
1445
+ }
1446
+
1447
+ getTokenIDs = (req: GetTokenIDsRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenIDsResponse> => {
1448
+ return this.fetch(
1449
+ this.url('GetTokenIDs'),
1450
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1451
+ return buildResponse(res).then(_data => {
1452
+ return JsonDecode<GetTokenIDsResponse>(_data, 'GetTokenIDsResponse')
1453
+ })
1454
+ }, (error) => {
1455
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1456
+ })
1457
+ }
1458
+
1459
+ getTokenPrice = (req: GetTokenPriceRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPriceResponse> => {
1460
+ return this.fetch(
1461
+ this.url('GetTokenPrice'),
1462
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1463
+ return buildResponse(res).then(_data => {
1464
+ return JsonDecode<GetTokenPriceResponse>(_data, 'GetTokenPriceResponse')
1465
+ })
1466
+ }, (error) => {
1467
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1468
+ })
1469
+ }
1470
+
1471
+ getTokenPrices = (req: GetTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenPricesResponse> => {
1472
+ return this.fetch(
1473
+ this.url('GetTokenPrices'),
1474
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1475
+ return buildResponse(res).then(_data => {
1476
+ return JsonDecode<GetTokenPricesResponse>(_data, 'GetTokenPricesResponse')
1477
+ })
1478
+ }, (error) => {
1479
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1480
+ })
1481
+ }
1482
+
1483
+ getTokenSupplies = (req: GetTokenSuppliesRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesResponse> => {
1484
+ return this.fetch(
1485
+ this.url('GetTokenSupplies'),
1486
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1487
+ return buildResponse(res).then(_data => {
1488
+ return JsonDecode<GetTokenSuppliesResponse>(_data, 'GetTokenSuppliesResponse')
1489
+ })
1490
+ }, (error) => {
1491
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1492
+ })
1493
+ }
1494
+
1495
+ getTokenSuppliesMap = (req: GetTokenSuppliesMapRequest, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesMapResponse> => {
1496
+ return this.fetch(
1497
+ this.url('GetTokenSuppliesMap'),
1498
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1499
+ return buildResponse(res).then(_data => {
1500
+ return JsonDecode<GetTokenSuppliesMapResponse>(_data, 'GetTokenSuppliesMapResponse')
1501
+ })
1502
+ }, (error) => {
1503
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1504
+ })
1505
+ }
1506
+
1507
+ getTransactionHistory = (req: GetTransactionHistoryRequest, headers?: object, signal?: AbortSignal): Promise<GetTransactionHistoryResponse> => {
1508
+ return this.fetch(
1509
+ this.url('GetTransactionHistory'),
1510
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1511
+ return buildResponse(res).then(_data => {
1512
+ return JsonDecode<GetTransactionHistoryResponse>(_data, 'GetTransactionHistoryResponse')
1513
+ })
1514
+ }, (error) => {
1515
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1516
+ })
1517
+ }
1518
+
1519
+ getWebhookListener = (req: GetWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<GetWebhookListenerResponse> => {
1520
+ return this.fetch(
1521
+ this.url('GetWebhookListener'),
1522
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1523
+ return buildResponse(res).then(_data => {
1524
+ return JsonDecode<GetWebhookListenerResponse>(_data, 'GetWebhookListenerResponse')
1525
+ })
1526
+ }, (error) => {
1527
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1528
+ })
1529
+ }
1530
+
1531
+ listTokenPrices = (req: ListTokenPricesRequest, headers?: object, signal?: AbortSignal): Promise<ListTokenPricesResponse> => {
1532
+ return this.fetch(
1533
+ this.url('ListTokenPrices'),
1534
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1535
+ return buildResponse(res).then(_data => {
1536
+ return JsonDecode<ListTokenPricesResponse>(_data, 'ListTokenPricesResponse')
1537
+ })
1538
+ }, (error) => {
1539
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1540
+ })
1541
+ }
1542
+
1543
+ pauseAllWebhookListeners = (req: PauseAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<PauseAllWebhookListenersResponse> => {
1544
+ return this.fetch(
1545
+ this.url('PauseAllWebhookListeners'),
1546
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1547
+ return buildResponse(res).then(_data => {
1548
+ return JsonDecode<PauseAllWebhookListenersResponse>(_data, 'PauseAllWebhookListenersResponse')
1549
+ })
1550
+ }, (error) => {
1551
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1552
+ })
1553
+ }
1554
+
1555
+ ping = (headers?: object, signal?: AbortSignal): Promise<PingResponse> => {
1556
+ return this.fetch(
1557
+ this.url('Ping'),
1558
+ createHttpRequest('{}', headers, signal)).then((res) => {
1559
+ return buildResponse(res).then(_data => {
1560
+ return JsonDecode<PingResponse>(_data, 'PingResponse')
1561
+ })
1562
+ }, (error) => {
1563
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1564
+ })
1565
+ }
1566
+
1567
+ removeAllWebhookListeners = (req: RemoveAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<RemoveAllWebhookListenersResponse> => {
1568
+ return this.fetch(
1569
+ this.url('RemoveAllWebhookListeners'),
1570
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1571
+ return buildResponse(res).then(_data => {
1572
+ return JsonDecode<RemoveAllWebhookListenersResponse>(_data, 'RemoveAllWebhookListenersResponse')
1573
+ })
1574
+ }, (error) => {
1575
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1576
+ })
1577
+ }
1578
+
1579
+ removeWebhookListener = (req: RemoveWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<RemoveWebhookListenerResponse> => {
1580
+ return this.fetch(
1581
+ this.url('RemoveWebhookListener'),
1582
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1583
+ return buildResponse(res).then(_data => {
1584
+ return JsonDecode<RemoveWebhookListenerResponse>(_data, 'RemoveWebhookListenerResponse')
1585
+ })
1586
+ }, (error) => {
1587
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1588
+ })
1589
+ }
1590
+
1591
+ resumeAllWebhookListeners = (req: ResumeAllWebhookListenersRequest, headers?: object, signal?: AbortSignal): Promise<ResumeAllWebhookListenersResponse> => {
1592
+ return this.fetch(
1593
+ this.url('ResumeAllWebhookListeners'),
1594
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1595
+ return buildResponse(res).then(_data => {
1596
+ return JsonDecode<ResumeAllWebhookListenersResponse>(_data, 'ResumeAllWebhookListenersResponse')
1597
+ })
1598
+ }, (error) => {
1599
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1600
+ })
1601
+ }
1602
+
1603
+ runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusResponse> => {
1604
+ return this.fetch(
1605
+ this.url('RuntimeStatus'),
1606
+ createHttpRequest('{}', headers, signal)).then((res) => {
1607
+ return buildResponse(res).then(_data => {
1608
+ return JsonDecode<RuntimeStatusResponse>(_data, 'RuntimeStatusResponse')
1609
+ })
1610
+ }, (error) => {
1611
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1612
+ })
1613
+ }
1614
+
1615
+ subscribeBalanceUpdates = (req: SubscribeBalanceUpdatesRequest, options: WebrpcStreamOptions<SubscribeBalanceUpdatesResponse>): WebrpcStreamController => {
1616
+ const abortController = new AbortController()
1617
+ const abortSignal = abortController.signal
1618
+
1619
+ if (options.signal) {
1620
+ abortSignal.addEventListener("abort", () => abortController.abort(options.signal?.reason), {
1621
+ signal: options.signal,
1622
+ })
1623
+ }
1624
+
1625
+ const _fetch = () => this.fetch(this.url('SubscribeBalanceUpdates'),
1626
+ createHttpRequest(JsonEncode(req), options.headers, abortSignal)
1627
+ ).then(async (res) => {
1628
+ await sseResponse(res, options, _fetch)
1629
+ }, (error) => {
1630
+ options.onError(error, _fetch)
1631
+ })
1632
+
1633
+ const resp = _fetch()
1634
+ return {
1635
+ abort: abortController.abort.bind(abortController),
1636
+ closed: resp
1637
+ }
1638
+ }
1639
+ subscribeEvents = (req: SubscribeEventsRequest, options: WebrpcStreamOptions<SubscribeEventsResponse>): WebrpcStreamController => {
1640
+ const abortController = new AbortController()
1641
+ const abortSignal = abortController.signal
1642
+
1643
+ if (options.signal) {
1644
+ abortSignal.addEventListener("abort", () => abortController.abort(options.signal?.reason), {
1645
+ signal: options.signal,
1646
+ })
1647
+ }
1648
+
1649
+ const _fetch = () => this.fetch(this.url('SubscribeEvents'),
1650
+ createHttpRequest(JsonEncode(req), options.headers, abortSignal)
1651
+ ).then(async (res) => {
1652
+ await sseResponse(res, options, _fetch)
1653
+ }, (error) => {
1654
+ options.onError(error, _fetch)
1655
+ })
1656
+
1657
+ const resp = _fetch()
1658
+ return {
1659
+ abort: abortController.abort.bind(abortController),
1660
+ closed: resp
1661
+ }
1662
+ }
1663
+ subscribeReceipts = (req: SubscribeReceiptsRequest, options: WebrpcStreamOptions<SubscribeReceiptsResponse>): WebrpcStreamController => {
1664
+ const abortController = new AbortController()
1665
+ const abortSignal = abortController.signal
1666
+
1667
+ if (options.signal) {
1668
+ abortSignal.addEventListener("abort", () => abortController.abort(options.signal?.reason), {
1669
+ signal: options.signal,
1670
+ })
1671
+ }
1672
+
1673
+ const _fetch = () => this.fetch(this.url('SubscribeReceipts'),
1674
+ createHttpRequest(JsonEncode(req), options.headers, abortSignal)
1675
+ ).then(async (res) => {
1676
+ await sseResponse(res, options, _fetch)
1677
+ }, (error) => {
1678
+ options.onError(error, _fetch)
1679
+ })
1680
+
1681
+ const resp = _fetch()
1682
+ return {
1683
+ abort: abortController.abort.bind(abortController),
1684
+ closed: resp
1574
1685
  }
1575
- return
1686
+ }
1687
+ syncBalance = (req: SyncBalanceRequest, headers?: object, signal?: AbortSignal): Promise<SyncBalanceResponse> => {
1688
+ return this.fetch(
1689
+ this.url('SyncBalance'),
1690
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1691
+ return buildResponse(res).then(_data => {
1692
+ return JsonDecode<SyncBalanceResponse>(_data, 'SyncBalanceResponse')
1693
+ })
1694
+ }, (error) => {
1695
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1696
+ })
1697
+ }
1698
+
1699
+ toggleWebhookListener = (req: ToggleWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<ToggleWebhookListenerResponse> => {
1700
+ return this.fetch(
1701
+ this.url('ToggleWebhookListener'),
1702
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1703
+ return buildResponse(res).then(_data => {
1704
+ return JsonDecode<ToggleWebhookListenerResponse>(_data, 'ToggleWebhookListenerResponse')
1705
+ })
1706
+ }, (error) => {
1707
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1708
+ })
1709
+ }
1710
+
1711
+ updateWebhookListener = (req: UpdateWebhookListenerRequest, headers?: object, signal?: AbortSignal): Promise<UpdateWebhookListenerResponse> => {
1712
+ return this.fetch(
1713
+ this.url('UpdateWebhookListener'),
1714
+ createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
1715
+ return buildResponse(res).then(_data => {
1716
+ return JsonDecode<UpdateWebhookListenerResponse>(_data, 'UpdateWebhookListenerResponse')
1717
+ })
1718
+ }, (error) => {
1719
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1720
+ })
1576
1721
  }
1577
1722
 
1578
- if (!res.body) {
1579
- onError(
1580
- WebrpcBadResponseError.new({
1581
- status: res.status,
1582
- cause: 'Invalid response, missing body'
1583
- }),
1584
- retryFetch
1585
- )
1586
- return
1587
- }
1588
-
1589
- onOpen && onOpen()
1590
-
1591
- const reader = res.body.getReader()
1592
- const decoder = new TextDecoder()
1593
- let buffer = ''
1594
- let lastReadTime = Date.now()
1595
- const timeout = (10 + 1) * 1000
1596
- let timeoutError = false
1597
- const intervalId = setInterval(() => {
1598
- if (Date.now() - lastReadTime > timeout) {
1599
- timeoutError = true
1600
- clearInterval(intervalId)
1601
- reader.releaseLock()
1723
+ version = (headers?: object, signal?: AbortSignal): Promise<VersionResponse> => {
1724
+ return this.fetch(
1725
+ this.url('Version'),
1726
+ createHttpRequest('{}', headers, signal)).then((res) => {
1727
+ return buildResponse(res).then(_data => {
1728
+ return JsonDecode<VersionResponse>(_data, 'VersionResponse')
1729
+ })
1730
+ }, (error) => {
1731
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
1732
+ })
1733
+ }
1734
+
1735
+ }
1736
+
1737
+ const sseResponse = async (
1738
+ res: Response,
1739
+ options: WebrpcStreamOptions<any>,
1740
+ retryFetch: () => Promise<void>
1741
+ ) => {
1742
+ const {onMessage, onOpen, onClose, onError} = options;
1743
+
1744
+ if (!res.ok) {
1745
+ try {
1746
+ await buildResponse(res)
1747
+ } catch (error) {
1748
+ // @ts-ignore
1749
+ onError(error, retryFetch)
1750
+ }
1751
+ return;
1602
1752
  }
1603
- }, timeout)
1604
1753
 
1605
- while (true) {
1606
- let value
1607
- let done
1608
- try {
1609
- ;({ value, done } = await reader.read())
1610
- if (timeoutError) throw new Error('Timeout, no data or heartbeat received')
1611
- lastReadTime = Date.now()
1612
- buffer += decoder.decode(value, { stream: true })
1613
- } catch (error) {
1614
- let message = ''
1615
- if (error instanceof Error) {
1616
- message = error.message
1617
- }
1618
-
1619
- if (error instanceof DOMException && error.name === 'AbortError') {
1754
+ if (!res.body) {
1620
1755
  onError(
1621
- WebrpcRequestFailedError.new({
1622
- message: 'AbortError',
1623
- cause: `AbortError: ${message}`
1624
- }),
1625
- () => {
1626
- throw new Error('Abort signal cannot be used to reconnect')
1627
- }
1756
+ WebrpcBadResponseError.new({
1757
+ status: res.status,
1758
+ cause: "Invalid response, missing body",
1759
+ }),
1760
+ retryFetch
1628
1761
  )
1629
- } else {
1630
- onError(
1631
- WebrpcStreamLostError.new({
1632
- cause: `reader.read(): ${message}`
1633
- }),
1634
- retryFetch
1635
- )
1636
- }
1637
- return
1762
+ return;
1638
1763
  }
1639
1764
 
1640
- let lines = buffer.split('\n')
1641
- for (let i = 0; i < lines.length - 1; i++) {
1642
- if (lines[i].length == 0) {
1643
- continue
1644
- }
1645
- let data: any
1646
- try {
1647
- data = JSON.parse(lines[i])
1648
- if (data.hasOwnProperty('webrpcError')) {
1649
- const error = data.webrpcError
1650
- const code: number = typeof error.code === 'number' ? error.code : 0
1651
- onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch)
1652
- return
1765
+ onOpen && onOpen()
1766
+
1767
+ const reader = res.body.getReader()
1768
+ const decoder = new TextDecoder()
1769
+ let buffer = "";
1770
+ let lastReadTime = Date.now()
1771
+ const timeout = (10 + 1) * 1000;
1772
+ let timeoutError = false
1773
+ const intervalId = setInterval(() => {
1774
+ if (Date.now() - lastReadTime > timeout) {
1775
+ timeoutError = true
1776
+ clearInterval(intervalId)
1777
+ reader.releaseLock()
1653
1778
  }
1654
- } catch (error) {
1655
- if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') {
1656
- throw error
1779
+ }, timeout)
1780
+
1781
+ while (true) {
1782
+ let value;
1783
+ let done;
1784
+ try {
1785
+ ({value, done} = await reader.read())
1786
+ if (timeoutError) throw new Error("Timeout, no data or heartbeat received")
1787
+ lastReadTime = Date.now()
1788
+ buffer += decoder.decode(value, {stream: true})
1789
+ } catch (error) {
1790
+ if (error instanceof DOMException && error.name === "AbortError") {
1791
+ onError(
1792
+ WebrpcClientAbortedError.new({
1793
+ message: "AbortError",
1794
+ cause: `AbortError: ${error instanceof Error ? error.message : String(error)}`,
1795
+ }),
1796
+ () => {
1797
+ throw new Error("Abort signal cannot be used to reconnect")
1798
+ }
1799
+ )
1800
+ } else {
1801
+ onError(
1802
+ WebrpcStreamLostError.new({
1803
+ cause: `reader.read(): ${error instanceof Error ? error.message : String(error)}`,
1804
+ }),
1805
+ retryFetch
1806
+ )
1807
+ }
1808
+ return;
1809
+ }
1810
+
1811
+ let lines = buffer.split("\n")
1812
+ for (let i = 0; i < lines.length - 1; i++) {
1813
+ const line = lines[i];
1814
+ if (line?.length === 0) {
1815
+ continue;
1816
+ }
1817
+ let data: any;
1818
+ try {
1819
+ data = JSON.parse(line)
1820
+ if (data.hasOwnProperty("webrpcError")) {
1821
+ const error = data.webrpcError;
1822
+ const code: number =
1823
+ typeof error.code === "number" ? error.code : 0;
1824
+ onError(
1825
+ (webrpcErrorByCode[code] || WebrpcError).new(error),
1826
+ retryFetch
1827
+ )
1828
+ return;
1829
+ }
1830
+ } catch (error) {
1831
+ if (
1832
+ error instanceof Error &&
1833
+ error.message === "Abort signal cannot be used to reconnect"
1834
+ ) {
1835
+ throw error;
1836
+ }
1837
+ onError(
1838
+ WebrpcBadResponseError.new({
1839
+ status: res.status,
1840
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}`,
1841
+ }),
1842
+ retryFetch
1843
+ )
1844
+ }
1845
+ onMessage(data)
1657
1846
  }
1658
- onError(
1659
- WebrpcBadResponseError.new({
1660
- status: res.status,
1661
- // @ts-ignore
1662
- cause: `JSON.parse(): ${error.message}`
1663
- }),
1664
- retryFetch
1665
- )
1666
- }
1667
- onMessage(data)
1668
- }
1669
1847
 
1670
- if (!done) {
1671
- buffer = lines[lines.length - 1]
1672
- continue
1848
+ if (!done) {
1849
+ const lastLine = lines[lines.length - 1];
1850
+ buffer = lastLine || "";
1851
+ continue;
1852
+ }
1853
+
1854
+ onClose && onClose()
1855
+ return;
1673
1856
  }
1857
+ };
1674
1858
 
1675
- onClose && onClose()
1676
- return
1677
- }
1678
- }
1679
1859
 
1680
- const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
1681
- const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' }
1682
- reqHeaders[WebrpcHeader] = WebrpcHeaderValue
1683
1860
 
1684
- return {
1685
- method: 'POST',
1686
- headers: reqHeaders,
1687
- body: JSON.stringify(body || {}),
1688
- signal
1689
- }
1861
+ const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
1862
+ const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json', [WebrpcHeader]: WebrpcHeaderValue }
1863
+ return { method: 'POST', headers: reqHeaders, body, signal }
1690
1864
  }
1691
1865
 
1692
1866
  const buildResponse = (res: Response): Promise<any> => {
@@ -1694,539 +1868,535 @@ const buildResponse = (res: Response): Promise<any> => {
1694
1868
  let data
1695
1869
  try {
1696
1870
  data = JSON.parse(text)
1697
- } catch (error) {
1698
- let message = ''
1699
- if (error instanceof Error) {
1700
- message = error.message
1701
- }
1871
+ } catch(error) {
1702
1872
  throw WebrpcBadResponseError.new({
1703
1873
  status: res.status,
1704
- cause: `JSON.parse(): ${message}: response text: ${text}`
1705
- })
1874
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`},
1875
+ )
1706
1876
  }
1707
1877
  if (!res.ok) {
1708
- const code: number = typeof data.code === 'number' ? data.code : 0
1878
+ const code: number = (typeof data.code === 'number') ? data.code : 0
1709
1879
  throw (webrpcErrorByCode[code] || WebrpcError).new(data)
1710
1880
  }
1711
1881
  return data
1712
1882
  })
1713
1883
  }
1714
1884
 
1885
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
1886
+
1887
+
1888
+ export interface WebrpcStreamOptions<T> extends WebrpcOptions {
1889
+ onMessage: (message: T) => void;
1890
+ onError: (error: WebrpcError, reconnect: () => void) => void;
1891
+ onOpen?: () => void;
1892
+ onClose?: () => void;
1893
+ }
1894
+
1895
+ export interface WebrpcOptions {
1896
+ headers?: HeadersInit;
1897
+ signal?: AbortSignal;
1898
+ }
1899
+
1900
+ export interface WebrpcStreamController {
1901
+ abort: (reason?: any) => void;
1902
+ closed: Promise<void>;
1903
+ }
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+ export const JsonEncode = <T = any>(obj: T): string => {
1910
+ return JSON.stringify(obj)
1911
+ }
1912
+
1913
+ export const JsonDecode = <T = any>(data: string | any, _typ: string = ''): T => {
1914
+ let parsed: any = data
1915
+ if (typeof data === 'string') {
1916
+ try { parsed = JSON.parse(data) } catch (err) {
1917
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
1918
+ }
1919
+ }
1920
+ return parsed as T
1921
+ }
1922
+
1923
+
1715
1924
  //
1716
1925
  // Errors
1717
1926
  //
1718
1927
 
1928
+ type WebrpcErrorParams = { name?: string, code?: number, message?: string, status?: number, cause?: string }
1929
+
1719
1930
  export class WebrpcError extends Error {
1720
- name: string
1721
1931
  code: number
1722
- message: string
1723
1932
  status: number
1724
- cause?: string
1725
-
1726
- /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
1727
- msg: string
1728
-
1729
- constructor(name: string, code: number, message: string, status: number, cause?: string) {
1730
- super(message)
1731
- this.name = name || 'WebrpcError'
1732
- this.code = typeof code === 'number' ? code : 0
1733
- this.message = message || `endpoint error ${this.code}`
1734
- this.msg = this.message
1735
- this.status = typeof status === 'number' ? status : 0
1736
- this.cause = cause
1933
+
1934
+ constructor(error: WebrpcErrorParams = {}) {
1935
+ super(error.message)
1936
+ this.name = error.name || 'WebrpcEndpointError'
1937
+ this.code = typeof error.code === 'number' ? error.code : 0
1938
+ this.message = error.message || `endpoint error`
1939
+ this.status = typeof error.status === 'number' ? error.status : 400
1940
+ if (error.cause !== undefined) this.cause = error.cause
1737
1941
  Object.setPrototypeOf(this, WebrpcError.prototype)
1738
1942
  }
1739
1943
 
1740
1944
  static new(payload: any): WebrpcError {
1741
- return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
1945
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
1742
1946
  }
1743
1947
  }
1744
1948
 
1745
- // Webrpc errors
1746
1949
 
1747
1950
  export class WebrpcEndpointError extends WebrpcError {
1748
- constructor(
1749
- name: string = 'WebrpcEndpoint',
1750
- code: number = 0,
1751
- message: string = 'endpoint error',
1752
- status: number = 0,
1753
- cause?: string
1754
- ) {
1755
- super(name, code, message, status, cause)
1951
+ constructor(error: WebrpcErrorParams = {}) {
1952
+ super(error)
1953
+ this.name = error.name || 'WebrpcEndpoint'
1954
+ this.code = typeof error.code === 'number' ? error.code : 0
1955
+ this.message = error.message || `endpoint error`
1956
+ this.status = typeof error.status === 'number' ? error.status : 400
1957
+ if (error.cause !== undefined) this.cause = error.cause
1756
1958
  Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
1757
1959
  }
1758
1960
  }
1759
1961
 
1760
1962
  export class WebrpcRequestFailedError extends WebrpcError {
1761
- constructor(
1762
- name: string = 'WebrpcRequestFailed',
1763
- code: number = -1,
1764
- message: string = 'request failed',
1765
- status: number = 0,
1766
- cause?: string
1767
- ) {
1768
- super(name, code, message, status, cause)
1963
+ constructor(error: WebrpcErrorParams = {}) {
1964
+ super(error)
1965
+ this.name = error.name || 'WebrpcRequestFailed'
1966
+ this.code = typeof error.code === 'number' ? error.code : -1
1967
+ this.message = error.message || `request failed`
1968
+ this.status = typeof error.status === 'number' ? error.status : 400
1969
+ if (error.cause !== undefined) this.cause = error.cause
1769
1970
  Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
1770
1971
  }
1771
1972
  }
1772
1973
 
1773
1974
  export class WebrpcBadRouteError extends WebrpcError {
1774
- constructor(
1775
- name: string = 'WebrpcBadRoute',
1776
- code: number = -2,
1777
- message: string = 'bad route',
1778
- status: number = 0,
1779
- cause?: string
1780
- ) {
1781
- super(name, code, message, status, cause)
1975
+ constructor(error: WebrpcErrorParams = {}) {
1976
+ super(error)
1977
+ this.name = error.name || 'WebrpcBadRoute'
1978
+ this.code = typeof error.code === 'number' ? error.code : -2
1979
+ this.message = error.message || `bad route`
1980
+ this.status = typeof error.status === 'number' ? error.status : 404
1981
+ if (error.cause !== undefined) this.cause = error.cause
1782
1982
  Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
1783
1983
  }
1784
1984
  }
1785
1985
 
1786
1986
  export class WebrpcBadMethodError extends WebrpcError {
1787
- constructor(
1788
- name: string = 'WebrpcBadMethod',
1789
- code: number = -3,
1790
- message: string = 'bad method',
1791
- status: number = 0,
1792
- cause?: string
1793
- ) {
1794
- super(name, code, message, status, cause)
1987
+ constructor(error: WebrpcErrorParams = {}) {
1988
+ super(error)
1989
+ this.name = error.name || 'WebrpcBadMethod'
1990
+ this.code = typeof error.code === 'number' ? error.code : -3
1991
+ this.message = error.message || `bad method`
1992
+ this.status = typeof error.status === 'number' ? error.status : 405
1993
+ if (error.cause !== undefined) this.cause = error.cause
1795
1994
  Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
1796
1995
  }
1797
1996
  }
1798
1997
 
1799
1998
  export class WebrpcBadRequestError extends WebrpcError {
1800
- constructor(
1801
- name: string = 'WebrpcBadRequest',
1802
- code: number = -4,
1803
- message: string = 'bad request',
1804
- status: number = 0,
1805
- cause?: string
1806
- ) {
1807
- super(name, code, message, status, cause)
1999
+ constructor(error: WebrpcErrorParams = {}) {
2000
+ super(error)
2001
+ this.name = error.name || 'WebrpcBadRequest'
2002
+ this.code = typeof error.code === 'number' ? error.code : -4
2003
+ this.message = error.message || `bad request`
2004
+ this.status = typeof error.status === 'number' ? error.status : 400
2005
+ if (error.cause !== undefined) this.cause = error.cause
1808
2006
  Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
1809
2007
  }
1810
2008
  }
1811
2009
 
1812
2010
  export class WebrpcBadResponseError extends WebrpcError {
1813
- constructor(
1814
- name: string = 'WebrpcBadResponse',
1815
- code: number = -5,
1816
- message: string = 'bad response',
1817
- status: number = 0,
1818
- cause?: string
1819
- ) {
1820
- super(name, code, message, status, cause)
2011
+ constructor(error: WebrpcErrorParams = {}) {
2012
+ super(error)
2013
+ this.name = error.name || 'WebrpcBadResponse'
2014
+ this.code = typeof error.code === 'number' ? error.code : -5
2015
+ this.message = error.message || `bad response`
2016
+ this.status = typeof error.status === 'number' ? error.status : 500
2017
+ if (error.cause !== undefined) this.cause = error.cause
1821
2018
  Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
1822
2019
  }
1823
2020
  }
1824
2021
 
1825
2022
  export class WebrpcServerPanicError extends WebrpcError {
1826
- constructor(
1827
- name: string = 'WebrpcServerPanic',
1828
- code: number = -6,
1829
- message: string = 'server panic',
1830
- status: number = 0,
1831
- cause?: string
1832
- ) {
1833
- super(name, code, message, status, cause)
2023
+ constructor(error: WebrpcErrorParams = {}) {
2024
+ super(error)
2025
+ this.name = error.name || 'WebrpcServerPanic'
2026
+ this.code = typeof error.code === 'number' ? error.code : -6
2027
+ this.message = error.message || `server panic`
2028
+ this.status = typeof error.status === 'number' ? error.status : 500
2029
+ if (error.cause !== undefined) this.cause = error.cause
1834
2030
  Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
1835
2031
  }
1836
2032
  }
1837
2033
 
1838
2034
  export class WebrpcInternalErrorError extends WebrpcError {
1839
- constructor(
1840
- name: string = 'WebrpcInternalError',
1841
- code: number = -7,
1842
- message: string = 'internal error',
1843
- status: number = 0,
1844
- cause?: string
1845
- ) {
1846
- super(name, code, message, status, cause)
2035
+ constructor(error: WebrpcErrorParams = {}) {
2036
+ super(error)
2037
+ this.name = error.name || 'WebrpcInternalError'
2038
+ this.code = typeof error.code === 'number' ? error.code : -7
2039
+ this.message = error.message || `internal error`
2040
+ this.status = typeof error.status === 'number' ? error.status : 500
2041
+ if (error.cause !== undefined) this.cause = error.cause
1847
2042
  Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
1848
2043
  }
1849
2044
  }
1850
2045
 
1851
- export class WebrpcClientDisconnectedError extends WebrpcError {
1852
- constructor(
1853
- name: string = 'WebrpcClientDisconnected',
1854
- code: number = -8,
1855
- message: string = 'client disconnected',
1856
- status: number = 0,
1857
- cause?: string
1858
- ) {
1859
- super(name, code, message, status, cause)
1860
- Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
2046
+ export class WebrpcClientAbortedError extends WebrpcError {
2047
+ constructor(error: WebrpcErrorParams = {}) {
2048
+ super(error)
2049
+ this.name = error.name || 'WebrpcClientAborted'
2050
+ this.code = typeof error.code === 'number' ? error.code : -8
2051
+ this.message = error.message || `request aborted by client`
2052
+ this.status = typeof error.status === 'number' ? error.status : 400
2053
+ if (error.cause !== undefined) this.cause = error.cause
2054
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
1861
2055
  }
1862
2056
  }
1863
2057
 
1864
2058
  export class WebrpcStreamLostError extends WebrpcError {
1865
- constructor(
1866
- name: string = 'WebrpcStreamLost',
1867
- code: number = -9,
1868
- message: string = 'stream lost',
1869
- status: number = 0,
1870
- cause?: string
1871
- ) {
1872
- super(name, code, message, status, cause)
2059
+ constructor(error: WebrpcErrorParams = {}) {
2060
+ super(error)
2061
+ this.name = error.name || 'WebrpcStreamLost'
2062
+ this.code = typeof error.code === 'number' ? error.code : -9
2063
+ this.message = error.message || `stream lost`
2064
+ this.status = typeof error.status === 'number' ? error.status : 400
2065
+ if (error.cause !== undefined) this.cause = error.cause
1873
2066
  Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
1874
2067
  }
1875
2068
  }
1876
2069
 
1877
2070
  export class WebrpcStreamFinishedError extends WebrpcError {
1878
- constructor(
1879
- name: string = 'WebrpcStreamFinished',
1880
- code: number = -10,
1881
- message: string = 'stream finished',
1882
- status: number = 0,
1883
- cause?: string
1884
- ) {
1885
- super(name, code, message, status, cause)
2071
+ constructor(error: WebrpcErrorParams = {}) {
2072
+ super(error)
2073
+ this.name = error.name || 'WebrpcStreamFinished'
2074
+ this.code = typeof error.code === 'number' ? error.code : -10
2075
+ this.message = error.message || `stream finished`
2076
+ this.status = typeof error.status === 'number' ? error.status : 200
2077
+ if (error.cause !== undefined) this.cause = error.cause
1886
2078
  Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
1887
2079
  }
1888
2080
  }
1889
2081
 
2082
+
2083
+ //
1890
2084
  // Schema errors
2085
+ //
1891
2086
 
1892
- export class UnauthorizedError extends WebrpcError {
1893
- constructor(
1894
- name: string = 'Unauthorized',
1895
- code: number = 1000,
1896
- message: string = 'Unauthorized access',
1897
- status: number = 0,
1898
- cause?: string
1899
- ) {
1900
- super(name, code, message, status, cause)
1901
- Object.setPrototypeOf(this, UnauthorizedError.prototype)
2087
+ export class AbortedError extends WebrpcError {
2088
+ constructor(error: WebrpcErrorParams = {}) {
2089
+ super(error)
2090
+ this.name = error.name || 'Aborted'
2091
+ this.code = typeof error.code === 'number' ? error.code : 1005
2092
+ this.message = error.message || `Request aborted`
2093
+ this.status = typeof error.status === 'number' ? error.status : 400
2094
+ if (error.cause !== undefined) this.cause = error.cause
2095
+ Object.setPrototypeOf(this, AbortedError.prototype)
1902
2096
  }
1903
2097
  }
1904
2098
 
1905
- export class PermissionDeniedError extends WebrpcError {
1906
- constructor(
1907
- name: string = 'PermissionDenied',
1908
- code: number = 1001,
1909
- message: string = 'Permission denied',
1910
- status: number = 0,
1911
- cause?: string
1912
- ) {
1913
- super(name, code, message, status, cause)
1914
- Object.setPrototypeOf(this, PermissionDeniedError.prototype)
2099
+ export class AccessKeyMismatchError extends WebrpcError {
2100
+ constructor(error: WebrpcErrorParams = {}) {
2101
+ super(error)
2102
+ this.name = error.name || 'AccessKeyMismatch'
2103
+ this.code = typeof error.code === 'number' ? error.code : 1102
2104
+ this.message = error.message || `Access key mismatch`
2105
+ this.status = typeof error.status === 'number' ? error.status : 409
2106
+ if (error.cause !== undefined) this.cause = error.cause
2107
+ Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
1915
2108
  }
1916
2109
  }
1917
2110
 
1918
- export class SessionExpiredError extends WebrpcError {
1919
- constructor(
1920
- name: string = 'SessionExpired',
1921
- code: number = 1002,
1922
- message: string = 'Session expired',
1923
- status: number = 0,
1924
- cause?: string
1925
- ) {
1926
- super(name, code, message, status, cause)
1927
- Object.setPrototypeOf(this, SessionExpiredError.prototype)
2111
+ export class AccessKeyNotFoundError extends WebrpcError {
2112
+ constructor(error: WebrpcErrorParams = {}) {
2113
+ super(error)
2114
+ this.name = error.name || 'AccessKeyNotFound'
2115
+ this.code = typeof error.code === 'number' ? error.code : 1101
2116
+ this.message = error.message || `Access key not found`
2117
+ this.status = typeof error.status === 'number' ? error.status : 401
2118
+ if (error.cause !== undefined) this.cause = error.cause
2119
+ Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
1928
2120
  }
1929
2121
  }
1930
2122
 
1931
- export class MethodNotFoundError extends WebrpcError {
1932
- constructor(
1933
- name: string = 'MethodNotFound',
1934
- code: number = 1003,
1935
- message: string = 'Method not found',
1936
- status: number = 0,
1937
- cause?: string
1938
- ) {
1939
- super(name, code, message, status, cause)
1940
- Object.setPrototypeOf(this, MethodNotFoundError.prototype)
2123
+ export class AtLeastOneKeyError extends WebrpcError {
2124
+ constructor(error: WebrpcErrorParams = {}) {
2125
+ super(error)
2126
+ this.name = error.name || 'AtLeastOneKey'
2127
+ this.code = typeof error.code === 'number' ? error.code : 1302
2128
+ this.message = error.message || `You need at least one Access Key`
2129
+ this.status = typeof error.status === 'number' ? error.status : 403
2130
+ if (error.cause !== undefined) this.cause = error.cause
2131
+ Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
1941
2132
  }
1942
2133
  }
1943
2134
 
1944
- export class RequestConflictError extends WebrpcError {
1945
- constructor(
1946
- name: string = 'RequestConflict',
1947
- code: number = 1004,
1948
- message: string = 'Conflict with target resource',
1949
- status: number = 0,
1950
- cause?: string
1951
- ) {
1952
- super(name, code, message, status, cause)
1953
- Object.setPrototypeOf(this, RequestConflictError.prototype)
2135
+ export class GeoblockedError extends WebrpcError {
2136
+ constructor(error: WebrpcErrorParams = {}) {
2137
+ super(error)
2138
+ this.name = error.name || 'Geoblocked'
2139
+ this.code = typeof error.code === 'number' ? error.code : 1006
2140
+ this.message = error.message || `Geoblocked region`
2141
+ this.status = typeof error.status === 'number' ? error.status : 451
2142
+ if (error.cause !== undefined) this.cause = error.cause
2143
+ Object.setPrototypeOf(this, GeoblockedError.prototype)
1954
2144
  }
1955
2145
  }
1956
2146
 
1957
- export class AbortedError extends WebrpcError {
1958
- constructor(
1959
- name: string = 'Aborted',
1960
- code: number = 1005,
1961
- message: string = 'Request aborted',
1962
- status: number = 0,
1963
- cause?: string
1964
- ) {
1965
- super(name, code, message, status, cause)
1966
- Object.setPrototypeOf(this, AbortedError.prototype)
2147
+ export class InvalidArgumentError extends WebrpcError {
2148
+ constructor(error: WebrpcErrorParams = {}) {
2149
+ super(error)
2150
+ this.name = error.name || 'InvalidArgument'
2151
+ this.code = typeof error.code === 'number' ? error.code : 2001
2152
+ this.message = error.message || `Invalid argument`
2153
+ this.status = typeof error.status === 'number' ? error.status : 400
2154
+ if (error.cause !== undefined) this.cause = error.cause
2155
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
1967
2156
  }
1968
2157
  }
1969
2158
 
1970
- export class GeoblockedError extends WebrpcError {
1971
- constructor(
1972
- name: string = 'Geoblocked',
1973
- code: number = 1006,
1974
- message: string = 'Geoblocked region',
1975
- status: number = 0,
1976
- cause?: string
1977
- ) {
1978
- super(name, code, message, status, cause)
1979
- Object.setPrototypeOf(this, GeoblockedError.prototype)
2159
+ export class InvalidOriginError extends WebrpcError {
2160
+ constructor(error: WebrpcErrorParams = {}) {
2161
+ super(error)
2162
+ this.name = error.name || 'InvalidOrigin'
2163
+ this.code = typeof error.code === 'number' ? error.code : 1103
2164
+ this.message = error.message || `Invalid origin for Access Key`
2165
+ this.status = typeof error.status === 'number' ? error.status : 403
2166
+ if (error.cause !== undefined) this.cause = error.cause
2167
+ Object.setPrototypeOf(this, InvalidOriginError.prototype)
1980
2168
  }
1981
2169
  }
1982
2170
 
1983
- export class RateLimitedError extends WebrpcError {
1984
- constructor(
1985
- name: string = 'RateLimited',
1986
- code: number = 1007,
1987
- message: string = 'Rate-limited. Please slow down.',
1988
- status: number = 0,
1989
- cause?: string
1990
- ) {
1991
- super(name, code, message, status, cause)
1992
- Object.setPrototypeOf(this, RateLimitedError.prototype)
2171
+ export class InvalidServiceError extends WebrpcError {
2172
+ constructor(error: WebrpcErrorParams = {}) {
2173
+ super(error)
2174
+ this.name = error.name || 'InvalidService'
2175
+ this.code = typeof error.code === 'number' ? error.code : 1104
2176
+ this.message = error.message || `Service not enabled for Access key`
2177
+ this.status = typeof error.status === 'number' ? error.status : 403
2178
+ if (error.cause !== undefined) this.cause = error.cause
2179
+ Object.setPrototypeOf(this, InvalidServiceError.prototype)
1993
2180
  }
1994
2181
  }
1995
2182
 
1996
- export class ProjectNotFoundError extends WebrpcError {
1997
- constructor(
1998
- name: string = 'ProjectNotFound',
1999
- code: number = 1100,
2000
- message: string = 'Project not found',
2001
- status: number = 0,
2002
- cause?: string
2003
- ) {
2004
- super(name, code, message, status, cause)
2005
- Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
2183
+ export class MaxAccessKeysError extends WebrpcError {
2184
+ constructor(error: WebrpcErrorParams = {}) {
2185
+ super(error)
2186
+ this.name = error.name || 'MaxAccessKeys'
2187
+ this.code = typeof error.code === 'number' ? error.code : 1301
2188
+ this.message = error.message || `Access keys limit reached`
2189
+ this.status = typeof error.status === 'number' ? error.status : 403
2190
+ if (error.cause !== undefined) this.cause = error.cause
2191
+ Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
2006
2192
  }
2007
2193
  }
2008
2194
 
2009
- export class AccessKeyNotFoundError extends WebrpcError {
2010
- constructor(
2011
- name: string = 'AccessKeyNotFound',
2012
- code: number = 1101,
2013
- message: string = 'Access key not found',
2014
- status: number = 0,
2015
- cause?: string
2016
- ) {
2017
- super(name, code, message, status, cause)
2018
- Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
2195
+ export class MetadataCallFailedError extends WebrpcError {
2196
+ constructor(error: WebrpcErrorParams = {}) {
2197
+ super(error)
2198
+ this.name = error.name || 'MetadataCallFailed'
2199
+ this.code = typeof error.code === 'number' ? error.code : 3003
2200
+ this.message = error.message || `Metadata service call failed`
2201
+ this.status = typeof error.status === 'number' ? error.status : 400
2202
+ if (error.cause !== undefined) this.cause = error.cause
2203
+ Object.setPrototypeOf(this, MetadataCallFailedError.prototype)
2019
2204
  }
2020
2205
  }
2021
2206
 
2022
- export class AccessKeyMismatchError extends WebrpcError {
2023
- constructor(
2024
- name: string = 'AccessKeyMismatch',
2025
- code: number = 1102,
2026
- message: string = 'Access key mismatch',
2027
- status: number = 0,
2028
- cause?: string
2029
- ) {
2030
- super(name, code, message, status, cause)
2031
- Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
2207
+ export class MethodNotFoundError extends WebrpcError {
2208
+ constructor(error: WebrpcErrorParams = {}) {
2209
+ super(error)
2210
+ this.name = error.name || 'MethodNotFound'
2211
+ this.code = typeof error.code === 'number' ? error.code : 1003
2212
+ this.message = error.message || `Method not found`
2213
+ this.status = typeof error.status === 'number' ? error.status : 404
2214
+ if (error.cause !== undefined) this.cause = error.cause
2215
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
2032
2216
  }
2033
2217
  }
2034
2218
 
2035
- export class InvalidOriginError extends WebrpcError {
2036
- constructor(
2037
- name: string = 'InvalidOrigin',
2038
- code: number = 1103,
2039
- message: string = 'Invalid origin for Access Key',
2040
- status: number = 0,
2041
- cause?: string
2042
- ) {
2043
- super(name, code, message, status, cause)
2044
- Object.setPrototypeOf(this, InvalidOriginError.prototype)
2219
+ export class NoDefaultKeyError extends WebrpcError {
2220
+ constructor(error: WebrpcErrorParams = {}) {
2221
+ super(error)
2222
+ this.name = error.name || 'NoDefaultKey'
2223
+ this.code = typeof error.code === 'number' ? error.code : 1300
2224
+ this.message = error.message || `No default access key found`
2225
+ this.status = typeof error.status === 'number' ? error.status : 403
2226
+ if (error.cause !== undefined) this.cause = error.cause
2227
+ Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
2045
2228
  }
2046
2229
  }
2047
2230
 
2048
- export class InvalidServiceError extends WebrpcError {
2049
- constructor(
2050
- name: string = 'InvalidService',
2051
- code: number = 1104,
2052
- message: string = 'Service not enabled for Access key',
2053
- status: number = 0,
2054
- cause?: string
2055
- ) {
2056
- super(name, code, message, status, cause)
2057
- Object.setPrototypeOf(this, InvalidServiceError.prototype)
2231
+ export class NotFoundError extends WebrpcError {
2232
+ constructor(error: WebrpcErrorParams = {}) {
2233
+ super(error)
2234
+ this.name = error.name || 'NotFound'
2235
+ this.code = typeof error.code === 'number' ? error.code : 3000
2236
+ this.message = error.message || `Resource not found`
2237
+ this.status = typeof error.status === 'number' ? error.status : 400
2238
+ if (error.cause !== undefined) this.cause = error.cause
2239
+ Object.setPrototypeOf(this, NotFoundError.prototype)
2058
2240
  }
2059
2241
  }
2060
2242
 
2061
- export class UnauthorizedUserError extends WebrpcError {
2062
- constructor(
2063
- name: string = 'UnauthorizedUser',
2064
- code: number = 1105,
2065
- message: string = 'Unauthorized user',
2066
- status: number = 0,
2067
- cause?: string
2068
- ) {
2069
- super(name, code, message, status, cause)
2070
- Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
2243
+ export class PermissionDeniedError extends WebrpcError {
2244
+ constructor(error: WebrpcErrorParams = {}) {
2245
+ super(error)
2246
+ this.name = error.name || 'PermissionDenied'
2247
+ this.code = typeof error.code === 'number' ? error.code : 1001
2248
+ this.message = error.message || `Permission denied`
2249
+ this.status = typeof error.status === 'number' ? error.status : 403
2250
+ if (error.cause !== undefined) this.cause = error.cause
2251
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
2071
2252
  }
2072
2253
  }
2073
2254
 
2074
- export class QuotaExceededError extends WebrpcError {
2075
- constructor(
2076
- name: string = 'QuotaExceeded',
2077
- code: number = 1200,
2078
- message: string = 'Quota exceeded',
2079
- status: number = 0,
2080
- cause?: string
2081
- ) {
2082
- super(name, code, message, status, cause)
2083
- Object.setPrototypeOf(this, QuotaExceededError.prototype)
2255
+ export class ProjectNotFoundError extends WebrpcError {
2256
+ constructor(error: WebrpcErrorParams = {}) {
2257
+ super(error)
2258
+ this.name = error.name || 'ProjectNotFound'
2259
+ this.code = typeof error.code === 'number' ? error.code : 1100
2260
+ this.message = error.message || `Project not found`
2261
+ this.status = typeof error.status === 'number' ? error.status : 401
2262
+ if (error.cause !== undefined) this.cause = error.cause
2263
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
2084
2264
  }
2085
2265
  }
2086
2266
 
2087
- export class RateLimitError extends WebrpcError {
2088
- constructor(
2089
- name: string = 'RateLimit',
2090
- code: number = 1201,
2091
- message: string = 'Rate limit exceeded',
2092
- status: number = 0,
2093
- cause?: string
2094
- ) {
2095
- super(name, code, message, status, cause)
2096
- Object.setPrototypeOf(this, RateLimitError.prototype)
2267
+ export class QueryFailedError extends WebrpcError {
2268
+ constructor(error: WebrpcErrorParams = {}) {
2269
+ super(error)
2270
+ this.name = error.name || 'QueryFailed'
2271
+ this.code = typeof error.code === 'number' ? error.code : 2003
2272
+ this.message = error.message || `Query failed`
2273
+ this.status = typeof error.status === 'number' ? error.status : 400
2274
+ if (error.cause !== undefined) this.cause = error.cause
2275
+ Object.setPrototypeOf(this, QueryFailedError.prototype)
2097
2276
  }
2098
2277
  }
2099
2278
 
2100
- export class NoDefaultKeyError extends WebrpcError {
2101
- constructor(
2102
- name: string = 'NoDefaultKey',
2103
- code: number = 1300,
2104
- message: string = 'No default access key found',
2105
- status: number = 0,
2106
- cause?: string
2107
- ) {
2108
- super(name, code, message, status, cause)
2109
- Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
2279
+ export class QuotaExceededError extends WebrpcError {
2280
+ constructor(error: WebrpcErrorParams = {}) {
2281
+ super(error)
2282
+ this.name = error.name || 'QuotaExceeded'
2283
+ this.code = typeof error.code === 'number' ? error.code : 1200
2284
+ this.message = error.message || `Quota exceeded`
2285
+ this.status = typeof error.status === 'number' ? error.status : 429
2286
+ if (error.cause !== undefined) this.cause = error.cause
2287
+ Object.setPrototypeOf(this, QuotaExceededError.prototype)
2110
2288
  }
2111
2289
  }
2112
2290
 
2113
- export class MaxAccessKeysError extends WebrpcError {
2114
- constructor(
2115
- name: string = 'MaxAccessKeys',
2116
- code: number = 1301,
2117
- message: string = 'Access keys limit reached',
2118
- status: number = 0,
2119
- cause?: string
2120
- ) {
2121
- super(name, code, message, status, cause)
2122
- Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
2291
+ export class RateLimitError extends WebrpcError {
2292
+ constructor(error: WebrpcErrorParams = {}) {
2293
+ super(error)
2294
+ this.name = error.name || 'RateLimit'
2295
+ this.code = typeof error.code === 'number' ? error.code : 1201
2296
+ this.message = error.message || `Rate limit exceeded`
2297
+ this.status = typeof error.status === 'number' ? error.status : 429
2298
+ if (error.cause !== undefined) this.cause = error.cause
2299
+ Object.setPrototypeOf(this, RateLimitError.prototype)
2123
2300
  }
2124
2301
  }
2125
2302
 
2126
- export class AtLeastOneKeyError extends WebrpcError {
2127
- constructor(
2128
- name: string = 'AtLeastOneKey',
2129
- code: number = 1302,
2130
- message: string = 'You need at least one Access Key',
2131
- status: number = 0,
2132
- cause?: string
2133
- ) {
2134
- super(name, code, message, status, cause)
2135
- Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
2303
+ export class RateLimitedError extends WebrpcError {
2304
+ constructor(error: WebrpcErrorParams = {}) {
2305
+ super(error)
2306
+ this.name = error.name || 'RateLimited'
2307
+ this.code = typeof error.code === 'number' ? error.code : 1007
2308
+ this.message = error.message || `Rate-limited. Please slow down.`
2309
+ this.status = typeof error.status === 'number' ? error.status : 429
2310
+ if (error.cause !== undefined) this.cause = error.cause
2311
+ Object.setPrototypeOf(this, RateLimitedError.prototype)
2136
2312
  }
2137
2313
  }
2138
2314
 
2139
- export class TimeoutError extends WebrpcError {
2140
- constructor(
2141
- name: string = 'Timeout',
2142
- code: number = 1900,
2143
- message: string = 'Request timed out',
2144
- status: number = 0,
2145
- cause?: string
2146
- ) {
2147
- super(name, code, message, status, cause)
2148
- Object.setPrototypeOf(this, TimeoutError.prototype)
2315
+ export class RequestConflictError extends WebrpcError {
2316
+ constructor(error: WebrpcErrorParams = {}) {
2317
+ super(error)
2318
+ this.name = error.name || 'RequestConflict'
2319
+ this.code = typeof error.code === 'number' ? error.code : 1004
2320
+ this.message = error.message || `Conflict with target resource`
2321
+ this.status = typeof error.status === 'number' ? error.status : 409
2322
+ if (error.cause !== undefined) this.cause = error.cause
2323
+ Object.setPrototypeOf(this, RequestConflictError.prototype)
2149
2324
  }
2150
2325
  }
2151
2326
 
2152
- export class InvalidArgumentError extends WebrpcError {
2153
- constructor(
2154
- name: string = 'InvalidArgument',
2155
- code: number = 2001,
2156
- message: string = 'Invalid argument',
2157
- status: number = 0,
2158
- cause?: string
2159
- ) {
2160
- super(name, code, message, status, cause)
2161
- Object.setPrototypeOf(this, InvalidArgumentError.prototype)
2327
+ export class ResourceExhaustedError extends WebrpcError {
2328
+ constructor(error: WebrpcErrorParams = {}) {
2329
+ super(error)
2330
+ this.name = error.name || 'ResourceExhausted'
2331
+ this.code = typeof error.code === 'number' ? error.code : 2004
2332
+ this.message = error.message || `Resource exhausted`
2333
+ this.status = typeof error.status === 'number' ? error.status : 400
2334
+ if (error.cause !== undefined) this.cause = error.cause
2335
+ Object.setPrototypeOf(this, ResourceExhaustedError.prototype)
2162
2336
  }
2163
2337
  }
2164
2338
 
2165
- export class UnavailableError extends WebrpcError {
2166
- constructor(
2167
- name: string = 'Unavailable',
2168
- code: number = 2002,
2169
- message: string = 'Unavailable resource',
2170
- status: number = 0,
2171
- cause?: string
2172
- ) {
2173
- super(name, code, message, status, cause)
2174
- Object.setPrototypeOf(this, UnavailableError.prototype)
2339
+ export class SessionExpiredError extends WebrpcError {
2340
+ constructor(error: WebrpcErrorParams = {}) {
2341
+ super(error)
2342
+ this.name = error.name || 'SessionExpired'
2343
+ this.code = typeof error.code === 'number' ? error.code : 1002
2344
+ this.message = error.message || `Session expired`
2345
+ this.status = typeof error.status === 'number' ? error.status : 403
2346
+ if (error.cause !== undefined) this.cause = error.cause
2347
+ Object.setPrototypeOf(this, SessionExpiredError.prototype)
2175
2348
  }
2176
2349
  }
2177
2350
 
2178
- export class QueryFailedError extends WebrpcError {
2179
- constructor(
2180
- name: string = 'QueryFailed',
2181
- code: number = 2003,
2182
- message: string = 'Query failed',
2183
- status: number = 0,
2184
- cause?: string
2185
- ) {
2186
- super(name, code, message, status, cause)
2187
- Object.setPrototypeOf(this, QueryFailedError.prototype)
2351
+ export class TimeoutError extends WebrpcError {
2352
+ constructor(error: WebrpcErrorParams = {}) {
2353
+ super(error)
2354
+ this.name = error.name || 'Timeout'
2355
+ this.code = typeof error.code === 'number' ? error.code : 1900
2356
+ this.message = error.message || `Request timed out`
2357
+ this.status = typeof error.status === 'number' ? error.status : 408
2358
+ if (error.cause !== undefined) this.cause = error.cause
2359
+ Object.setPrototypeOf(this, TimeoutError.prototype)
2188
2360
  }
2189
2361
  }
2190
2362
 
2191
- export class ResourceExhaustedError extends WebrpcError {
2192
- constructor(
2193
- name: string = 'ResourceExhausted',
2194
- code: number = 2004,
2195
- message: string = 'Resource exhausted',
2196
- status: number = 0,
2197
- cause?: string
2198
- ) {
2199
- super(name, code, message, status, cause)
2200
- Object.setPrototypeOf(this, ResourceExhaustedError.prototype)
2363
+ export class UnauthorizedError extends WebrpcError {
2364
+ constructor(error: WebrpcErrorParams = {}) {
2365
+ super(error)
2366
+ this.name = error.name || 'Unauthorized'
2367
+ this.code = typeof error.code === 'number' ? error.code : 1000
2368
+ this.message = error.message || `Unauthorized access`
2369
+ this.status = typeof error.status === 'number' ? error.status : 401
2370
+ if (error.cause !== undefined) this.cause = error.cause
2371
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
2201
2372
  }
2202
2373
  }
2203
2374
 
2204
- export class NotFoundError extends WebrpcError {
2205
- constructor(
2206
- name: string = 'NotFound',
2207
- code: number = 3000,
2208
- message: string = 'Resource not found',
2209
- status: number = 0,
2210
- cause?: string
2211
- ) {
2212
- super(name, code, message, status, cause)
2213
- Object.setPrototypeOf(this, NotFoundError.prototype)
2375
+ export class UnauthorizedUserError extends WebrpcError {
2376
+ constructor(error: WebrpcErrorParams = {}) {
2377
+ super(error)
2378
+ this.name = error.name || 'UnauthorizedUser'
2379
+ this.code = typeof error.code === 'number' ? error.code : 1105
2380
+ this.message = error.message || `Unauthorized user`
2381
+ this.status = typeof error.status === 'number' ? error.status : 403
2382
+ if (error.cause !== undefined) this.cause = error.cause
2383
+ Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
2214
2384
  }
2215
2385
  }
2216
2386
 
2217
- export class MetadataCallFailedError extends WebrpcError {
2218
- constructor(
2219
- name: string = 'MetadataCallFailed',
2220
- code: number = 3003,
2221
- message: string = 'Metadata service call failed',
2222
- status: number = 0,
2223
- cause?: string
2224
- ) {
2225
- super(name, code, message, status, cause)
2226
- Object.setPrototypeOf(this, MetadataCallFailedError.prototype)
2387
+ export class UnavailableError extends WebrpcError {
2388
+ constructor(error: WebrpcErrorParams = {}) {
2389
+ super(error)
2390
+ this.name = error.name || 'Unavailable'
2391
+ this.code = typeof error.code === 'number' ? error.code : 2002
2392
+ this.message = error.message || `Unavailable resource`
2393
+ this.status = typeof error.status === 'number' ? error.status : 400
2394
+ if (error.cause !== undefined) this.cause = error.cause
2395
+ Object.setPrototypeOf(this, UnavailableError.prototype)
2227
2396
  }
2228
2397
  }
2229
2398
 
2399
+
2230
2400
  export enum errors {
2231
2401
  WebrpcEndpoint = 'WebrpcEndpoint',
2232
2402
  WebrpcRequestFailed = 'WebrpcRequestFailed',
@@ -2236,38 +2406,78 @@ export enum errors {
2236
2406
  WebrpcBadResponse = 'WebrpcBadResponse',
2237
2407
  WebrpcServerPanic = 'WebrpcServerPanic',
2238
2408
  WebrpcInternalError = 'WebrpcInternalError',
2239
- WebrpcClientDisconnected = 'WebrpcClientDisconnected',
2409
+ WebrpcClientAborted = 'WebrpcClientAborted',
2240
2410
  WebrpcStreamLost = 'WebrpcStreamLost',
2241
2411
  WebrpcStreamFinished = 'WebrpcStreamFinished',
2242
- Unauthorized = 'Unauthorized',
2243
- PermissionDenied = 'PermissionDenied',
2244
- SessionExpired = 'SessionExpired',
2245
- MethodNotFound = 'MethodNotFound',
2246
- RequestConflict = 'RequestConflict',
2247
2412
  Aborted = 'Aborted',
2248
- Geoblocked = 'Geoblocked',
2249
- RateLimited = 'RateLimited',
2250
- ProjectNotFound = 'ProjectNotFound',
2251
- AccessKeyNotFound = 'AccessKeyNotFound',
2252
2413
  AccessKeyMismatch = 'AccessKeyMismatch',
2414
+ AccessKeyNotFound = 'AccessKeyNotFound',
2415
+ AtLeastOneKey = 'AtLeastOneKey',
2416
+ Geoblocked = 'Geoblocked',
2417
+ InvalidArgument = 'InvalidArgument',
2253
2418
  InvalidOrigin = 'InvalidOrigin',
2254
2419
  InvalidService = 'InvalidService',
2255
- UnauthorizedUser = 'UnauthorizedUser',
2420
+ MaxAccessKeys = 'MaxAccessKeys',
2421
+ MetadataCallFailed = 'MetadataCallFailed',
2422
+ MethodNotFound = 'MethodNotFound',
2423
+ NoDefaultKey = 'NoDefaultKey',
2424
+ NotFound = 'NotFound',
2425
+ PermissionDenied = 'PermissionDenied',
2426
+ ProjectNotFound = 'ProjectNotFound',
2427
+ QueryFailed = 'QueryFailed',
2256
2428
  QuotaExceeded = 'QuotaExceeded',
2257
2429
  RateLimit = 'RateLimit',
2258
- NoDefaultKey = 'NoDefaultKey',
2259
- MaxAccessKeys = 'MaxAccessKeys',
2260
- AtLeastOneKey = 'AtLeastOneKey',
2430
+ RateLimited = 'RateLimited',
2431
+ RequestConflict = 'RequestConflict',
2432
+ ResourceExhausted = 'ResourceExhausted',
2433
+ SessionExpired = 'SessionExpired',
2261
2434
  Timeout = 'Timeout',
2262
- InvalidArgument = 'InvalidArgument',
2435
+ Unauthorized = 'Unauthorized',
2436
+ UnauthorizedUser = 'UnauthorizedUser',
2263
2437
  Unavailable = 'Unavailable',
2264
- QueryFailed = 'QueryFailed',
2265
- ResourceExhausted = 'ResourceExhausted',
2266
- NotFound = 'NotFound',
2267
- MetadataCallFailed = 'MetadataCallFailed'
2268
2438
  }
2269
2439
 
2270
- const webrpcErrorByCode: { [code: number]: any } = {
2440
+ export enum WebrpcErrorCodes {
2441
+ WebrpcEndpoint = 0,
2442
+ WebrpcRequestFailed = -1,
2443
+ WebrpcBadRoute = -2,
2444
+ WebrpcBadMethod = -3,
2445
+ WebrpcBadRequest = -4,
2446
+ WebrpcBadResponse = -5,
2447
+ WebrpcServerPanic = -6,
2448
+ WebrpcInternalError = -7,
2449
+ WebrpcClientAborted = -8,
2450
+ WebrpcStreamLost = -9,
2451
+ WebrpcStreamFinished = -10,
2452
+ Aborted = 1005,
2453
+ AccessKeyMismatch = 1102,
2454
+ AccessKeyNotFound = 1101,
2455
+ AtLeastOneKey = 1302,
2456
+ Geoblocked = 1006,
2457
+ InvalidArgument = 2001,
2458
+ InvalidOrigin = 1103,
2459
+ InvalidService = 1104,
2460
+ MaxAccessKeys = 1301,
2461
+ MetadataCallFailed = 3003,
2462
+ MethodNotFound = 1003,
2463
+ NoDefaultKey = 1300,
2464
+ NotFound = 3000,
2465
+ PermissionDenied = 1001,
2466
+ ProjectNotFound = 1100,
2467
+ QueryFailed = 2003,
2468
+ QuotaExceeded = 1200,
2469
+ RateLimit = 1201,
2470
+ RateLimited = 1007,
2471
+ RequestConflict = 1004,
2472
+ ResourceExhausted = 2004,
2473
+ SessionExpired = 1002,
2474
+ Timeout = 1900,
2475
+ Unauthorized = 1000,
2476
+ UnauthorizedUser = 1105,
2477
+ Unavailable = 2002,
2478
+ }
2479
+
2480
+ export const webrpcErrorByCode: { [code: number]: any } = {
2271
2481
  [0]: WebrpcEndpointError,
2272
2482
  [-1]: WebrpcRequestFailedError,
2273
2483
  [-2]: WebrpcBadRouteError,
@@ -2276,46 +2486,92 @@ const webrpcErrorByCode: { [code: number]: any } = {
2276
2486
  [-5]: WebrpcBadResponseError,
2277
2487
  [-6]: WebrpcServerPanicError,
2278
2488
  [-7]: WebrpcInternalErrorError,
2279
- [-8]: WebrpcClientDisconnectedError,
2489
+ [-8]: WebrpcClientAbortedError,
2280
2490
  [-9]: WebrpcStreamLostError,
2281
2491
  [-10]: WebrpcStreamFinishedError,
2282
- [1000]: UnauthorizedError,
2283
- [1001]: PermissionDeniedError,
2284
- [1002]: SessionExpiredError,
2285
- [1003]: MethodNotFoundError,
2286
- [1004]: RequestConflictError,
2287
2492
  [1005]: AbortedError,
2288
- [1006]: GeoblockedError,
2289
- [1007]: RateLimitedError,
2290
- [1100]: ProjectNotFoundError,
2291
- [1101]: AccessKeyNotFoundError,
2292
2493
  [1102]: AccessKeyMismatchError,
2494
+ [1101]: AccessKeyNotFoundError,
2495
+ [1302]: AtLeastOneKeyError,
2496
+ [1006]: GeoblockedError,
2497
+ [2001]: InvalidArgumentError,
2293
2498
  [1103]: InvalidOriginError,
2294
2499
  [1104]: InvalidServiceError,
2295
- [1105]: UnauthorizedUserError,
2500
+ [1301]: MaxAccessKeysError,
2501
+ [3003]: MetadataCallFailedError,
2502
+ [1003]: MethodNotFoundError,
2503
+ [1300]: NoDefaultKeyError,
2504
+ [3000]: NotFoundError,
2505
+ [1001]: PermissionDeniedError,
2506
+ [1100]: ProjectNotFoundError,
2507
+ [2003]: QueryFailedError,
2296
2508
  [1200]: QuotaExceededError,
2297
2509
  [1201]: RateLimitError,
2298
- [1300]: NoDefaultKeyError,
2299
- [1301]: MaxAccessKeysError,
2300
- [1302]: AtLeastOneKeyError,
2510
+ [1007]: RateLimitedError,
2511
+ [1004]: RequestConflictError,
2512
+ [2004]: ResourceExhaustedError,
2513
+ [1002]: SessionExpiredError,
2301
2514
  [1900]: TimeoutError,
2302
- [2001]: InvalidArgumentError,
2515
+ [1000]: UnauthorizedError,
2516
+ [1105]: UnauthorizedUserError,
2303
2517
  [2002]: UnavailableError,
2304
- [2003]: QueryFailedError,
2305
- [2004]: ResourceExhaustedError,
2306
- [3000]: NotFoundError,
2307
- [3003]: MetadataCallFailedError
2308
2518
  }
2309
2519
 
2310
- export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
2311
2520
 
2312
- export interface WebrpcStreamOptions<T> extends WebrpcOptions {
2313
- onMessage: (message: T) => void
2314
- onError: (error: WebrpcError, reconnect: () => void) => void
2315
- onOpen?: () => void
2316
- onClose?: () => void
2521
+
2522
+ //
2523
+ // Webrpc
2524
+ //
2525
+
2526
+ export const WebrpcHeader = "Webrpc"
2527
+
2528
+ export const WebrpcHeaderValue = "webrpc@v0.31.2;gen-typescript@v0.23.1;sequence-indexer@v0.4.0"
2529
+
2530
+ type WebrpcGenVersions = {
2531
+ WebrpcGenVersion: string;
2532
+ codeGenName: string;
2533
+ codeGenVersion: string;
2534
+ schemaName: string;
2535
+ schemaVersion: string;
2536
+ };
2537
+
2538
+ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
2539
+ const headerValue = headers.get(WebrpcHeader)
2540
+ if (!headerValue) {
2541
+ return {
2542
+ WebrpcGenVersion: "",
2543
+ codeGenName: "",
2544
+ codeGenVersion: "",
2545
+ schemaName: "",
2546
+ schemaVersion: "",
2547
+ };
2548
+ }
2549
+
2550
+ return parseWebrpcGenVersions(headerValue)
2317
2551
  }
2318
- export interface WebrpcOptions {
2319
- headers?: HeadersInit
2320
- signal?: AbortSignal
2552
+
2553
+ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
2554
+ const versions = header.split(";")
2555
+ if (versions.length < 3) {
2556
+ return {
2557
+ WebrpcGenVersion: "",
2558
+ codeGenName: "",
2559
+ codeGenVersion: "",
2560
+ schemaName: "",
2561
+ schemaVersion: "",
2562
+ };
2563
+ }
2564
+
2565
+ const [_, WebrpcGenVersion] = versions[0]!.split("@")
2566
+ const [codeGenName, codeGenVersion] = versions[1]!.split("@")
2567
+ const [schemaName, schemaVersion] = versions[2]!.split("@")
2568
+
2569
+ return {
2570
+ WebrpcGenVersion: WebrpcGenVersion ?? "",
2571
+ codeGenName: codeGenName ?? "",
2572
+ codeGenVersion: codeGenVersion ?? "",
2573
+ schemaName: schemaName ?? "",
2574
+ schemaVersion: schemaVersion ?? "",
2575
+ };
2321
2576
  }
2577
+