@0xsequence/indexer
Advanced tools
Comparing version 1.9.24 to 1.9.25
@@ -21,7 +21,7 @@ 'use strict'; | ||
/* eslint-disable */ | ||
// sequence-indexer v0.4.0 83530970d81179658f6546c87fc4352280dbd287 | ||
// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e | ||
// -- | ||
// Code generated by webrpc-gen@v0.14.0-dev with typescript@v0.10.0 generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=indexer.ridl -target=typescript@v0.10.0 -client -out=./clients/indexer.gen.ts | ||
// webrpc-gen -schema=indexer.ridl -target=typescript -client -out=./clients/indexer.gen.ts | ||
@@ -35,3 +35,3 @@ // WebRPC description and code-gen version | ||
// Schema hash generated from your RIDL schema | ||
const WebRPCSchemaHash = '83530970d81179658f6546c87fc4352280dbd287'; | ||
const WebRPCSchemaHash = 'd33d29bc84a4439a42a4e1533035bc80c4ea226e'; | ||
@@ -104,4 +104,4 @@ // | ||
this.path = '/rpc/Indexer/'; | ||
this.ping = headers => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => { | ||
this.ping = (headers, signal) => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -112,6 +112,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.version = headers => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => { | ||
this.version = (headers, signal) => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -122,6 +126,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.runtimeStatus = headers => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => { | ||
this.runtimeStatus = (headers, signal) => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -132,6 +140,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getChainID = headers => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => { | ||
this.getChainID = (headers, signal) => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -142,6 +154,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getEtherBalance = (args, headers) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.getEtherBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -152,6 +168,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenBalances = (args, headers) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenBalances = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -163,6 +183,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSupplies = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSupplies = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -175,6 +199,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSuppliesMap = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSuppliesMap = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -185,6 +213,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getBalanceUpdates = (args, headers) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers)).then(res => { | ||
this.getBalanceUpdates = (args, headers, signal) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -196,6 +228,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTransactionHistory = (args, headers) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTransactionHistory = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -207,13 +243,21 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.syncBalance = (args, headers) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.syncBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return {}; | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceipt = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceipt = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -224,6 +268,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getOrderbookOrders = (args, headers) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getOrderbookOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -235,6 +283,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTopOrders = (args, headers) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTopOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -245,6 +297,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceiptWithFilter = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceiptWithFilter = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -255,6 +311,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getAllWebhookListeners = (args, headers) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers)).then(res => { | ||
this.getAllWebhookListeners = (args, headers, signal) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -265,6 +325,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.getWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -275,6 +339,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.addWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.addWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -286,6 +354,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.updateWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.updateWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -296,6 +368,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.removeWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.removeWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -306,4 +382,24 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.subscribeReceipts = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.subscribeEvents = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.hostname = hostname; | ||
@@ -316,3 +412,117 @@ this.fetch = (input, init) => fetch(input, init); | ||
} | ||
const createHTTPRequest = (body = {}, headers = {}) => { | ||
const sseResponse = async (res, options, retryFetch) => { | ||
const { | ||
onMessage, | ||
onOpen, | ||
onClose, | ||
onError | ||
} = options; | ||
if (!res.ok) { | ||
try { | ||
await buildResponse(res); | ||
} catch (error) { | ||
// @ts-ignore | ||
onError(error, retryFetch); | ||
} | ||
return; | ||
} | ||
if (!res.body) { | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: 'Invalid response, missing body' | ||
}), retryFetch); | ||
return; | ||
} | ||
onOpen && onOpen(); | ||
const reader = res.body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let buffer = ''; | ||
let lastReadTime = Date.now(); | ||
const timeout = (10 + 1) * 1000; | ||
let intervalId; | ||
try { | ||
intervalId = setInterval(() => { | ||
if (Date.now() - lastReadTime > timeout) { | ||
throw WebrpcStreamLostError.new({ | ||
cause: 'Stream timed out' | ||
}); | ||
} | ||
}, timeout); | ||
while (true) { | ||
let value; | ||
let done; | ||
try { | ||
; | ||
({ | ||
value, | ||
done | ||
} = await reader.read()); | ||
lastReadTime = Date.now(); | ||
buffer += decoder.decode(value, { | ||
stream: true | ||
}); | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
if (error instanceof DOMException && error.name === 'AbortError') { | ||
onError(WebrpcRequestFailedError.new({ | ||
message: 'AbortError', | ||
cause: `AbortError: ${message}` | ||
}), () => { | ||
throw new Error('Abort signal cannot be used to reconnect'); | ||
}); | ||
} else { | ||
onError(WebrpcStreamLostError.new({ | ||
cause: `reader.read(): ${message}` | ||
}), retryFetch); | ||
} | ||
return; | ||
} | ||
let lines = buffer.split('\n'); | ||
for (let i = 0; i < lines.length - 1; i++) { | ||
if (lines[i].length == 0) { | ||
continue; | ||
} | ||
let data; | ||
try { | ||
data = JSON.parse(lines[i]); | ||
if (data.hasOwnProperty('webrpcError')) { | ||
const error = data.webrpcError; | ||
const code = typeof error.code === 'number' ? error.code : 0; | ||
onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch); | ||
return; | ||
} | ||
} catch (error) { | ||
if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') { | ||
throw error; | ||
} | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
// @ts-ignore | ||
cause: `JSON.parse(): ${error.message}` | ||
}), retryFetch); | ||
} | ||
onMessage(data); | ||
} | ||
if (!done) { | ||
buffer = lines[lines.length - 1]; | ||
continue; | ||
} | ||
onClose && onClose(); | ||
return; | ||
} | ||
} catch (error) { | ||
// @ts-ignore | ||
if (error instanceof WebrpcStreamLostError) { | ||
onError(error, retryFetch); | ||
} else { | ||
throw error; | ||
} | ||
} finally { | ||
clearInterval(intervalId); | ||
} | ||
}; | ||
const createHTTPRequest = (body = {}, headers = {}, signal = null) => { | ||
return { | ||
@@ -323,3 +533,4 @@ method: 'POST', | ||
}), | ||
body: JSON.stringify(body || {}) | ||
body: JSON.stringify(body || {}), | ||
signal | ||
}; | ||
@@ -332,11 +543,15 @@ }; | ||
data = JSON.parse(text); | ||
} catch (err) { | ||
throw { | ||
code: 'unknown', | ||
msg: `expecting JSON, got: ${text}`, | ||
status: res.status | ||
}; | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
throw WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: `JSON.parse(): ${message}: response text: ${text}` | ||
}); | ||
} | ||
if (!res.ok) { | ||
throw data; // webrpc error response | ||
const code = typeof data.code === 'number' ? data.code : 0; | ||
throw (webrpcErrorByCode[code] || WebrpcError).new(data); | ||
} | ||
@@ -347,2 +562,232 @@ return data; | ||
// | ||
// Errors | ||
// | ||
class WebrpcError extends Error { | ||
constructor(name, code, message, status, cause) { | ||
super(message); | ||
this.name = void 0; | ||
this.code = void 0; | ||
this.message = void 0; | ||
this.status = void 0; | ||
this.cause = void 0; | ||
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ | ||
this.msg = void 0; | ||
this.name = name || 'WebrpcError'; | ||
this.code = typeof code === 'number' ? code : 0; | ||
this.message = message || `endpoint error ${this.code}`; | ||
this.msg = this.message; | ||
this.status = typeof status === 'number' ? status : 0; | ||
this.cause = cause; | ||
Object.setPrototypeOf(this, WebrpcError.prototype); | ||
} | ||
static new(payload) { | ||
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause); | ||
} | ||
} | ||
// Webrpc errors | ||
class WebrpcEndpointError extends WebrpcError { | ||
constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcEndpointError.prototype); | ||
} | ||
} | ||
class WebrpcRequestFailedError extends WebrpcError { | ||
constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype); | ||
} | ||
} | ||
class WebrpcBadRouteError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype); | ||
} | ||
} | ||
class WebrpcBadMethodError extends WebrpcError { | ||
constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype); | ||
} | ||
} | ||
class WebrpcBadRequestError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype); | ||
} | ||
} | ||
class WebrpcBadResponseError extends WebrpcError { | ||
constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype); | ||
} | ||
} | ||
class WebrpcServerPanicError extends WebrpcError { | ||
constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype); | ||
} | ||
} | ||
class WebrpcInternalErrorError extends WebrpcError { | ||
constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype); | ||
} | ||
} | ||
class WebrpcClientDisconnectedError extends WebrpcError { | ||
constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype); | ||
} | ||
} | ||
class WebrpcStreamLostError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype); | ||
} | ||
} | ||
class WebrpcStreamFinishedError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype); | ||
} | ||
} | ||
// Schema errors | ||
class UnauthorizedError extends WebrpcError { | ||
constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype); | ||
} | ||
} | ||
class PermissionDeniedError extends WebrpcError { | ||
constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, PermissionDeniedError.prototype); | ||
} | ||
} | ||
class SessionExpiredError extends WebrpcError { | ||
constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, SessionExpiredError.prototype); | ||
} | ||
} | ||
class MethodNotFoundError extends WebrpcError { | ||
constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MethodNotFoundError.prototype); | ||
} | ||
} | ||
class RequestConflictError extends WebrpcError { | ||
constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, RequestConflictError.prototype); | ||
} | ||
} | ||
class AbortedError extends WebrpcError { | ||
constructor(name = 'Aborted', code = 1005, message = 'Request aborted', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, AbortedError.prototype); | ||
} | ||
} | ||
class TimeoutError extends WebrpcError { | ||
constructor(name = 'Timeout', code = 2000, message = 'Request timed out', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, TimeoutError.prototype); | ||
} | ||
} | ||
class InvalidArgumentError extends WebrpcError { | ||
constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, InvalidArgumentError.prototype); | ||
} | ||
} | ||
class UnavailableError extends WebrpcError { | ||
constructor(name = 'Unavailable', code = 2002, message = 'Unavailable resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnavailableError.prototype); | ||
} | ||
} | ||
class QueryFailedError extends WebrpcError { | ||
constructor(name = 'QueryFailed', code = 2003, message = 'Query failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, QueryFailedError.prototype); | ||
} | ||
} | ||
class NotFoundError extends WebrpcError { | ||
constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, NotFoundError.prototype); | ||
} | ||
} | ||
class ProjectNotFoundError extends WebrpcError { | ||
constructor(name = 'ProjectNotFound', code = 3002, message = 'Project not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, ProjectNotFoundError.prototype); | ||
} | ||
} | ||
class MetadataCallFailedError extends WebrpcError { | ||
constructor(name = 'MetadataCallFailed', code = 3003, message = 'Metadata service call failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MetadataCallFailedError.prototype); | ||
} | ||
} | ||
let errors = /*#__PURE__*/function (errors) { | ||
errors["WebrpcEndpoint"] = "WebrpcEndpoint"; | ||
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed"; | ||
errors["WebrpcBadRoute"] = "WebrpcBadRoute"; | ||
errors["WebrpcBadMethod"] = "WebrpcBadMethod"; | ||
errors["WebrpcBadRequest"] = "WebrpcBadRequest"; | ||
errors["WebrpcBadResponse"] = "WebrpcBadResponse"; | ||
errors["WebrpcServerPanic"] = "WebrpcServerPanic"; | ||
errors["WebrpcInternalError"] = "WebrpcInternalError"; | ||
errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected"; | ||
errors["WebrpcStreamLost"] = "WebrpcStreamLost"; | ||
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished"; | ||
errors["Unauthorized"] = "Unauthorized"; | ||
errors["PermissionDenied"] = "PermissionDenied"; | ||
errors["SessionExpired"] = "SessionExpired"; | ||
errors["MethodNotFound"] = "MethodNotFound"; | ||
errors["RequestConflict"] = "RequestConflict"; | ||
errors["Aborted"] = "Aborted"; | ||
errors["Timeout"] = "Timeout"; | ||
errors["InvalidArgument"] = "InvalidArgument"; | ||
errors["Unavailable"] = "Unavailable"; | ||
errors["QueryFailed"] = "QueryFailed"; | ||
errors["NotFound"] = "NotFound"; | ||
errors["ProjectNotFound"] = "ProjectNotFound"; | ||
errors["MetadataCallFailed"] = "MetadataCallFailed"; | ||
return errors; | ||
}({}); | ||
const webrpcErrorByCode = { | ||
[0]: WebrpcEndpointError, | ||
[-1]: WebrpcRequestFailedError, | ||
[-2]: WebrpcBadRouteError, | ||
[-3]: WebrpcBadMethodError, | ||
[-4]: WebrpcBadRequestError, | ||
[-5]: WebrpcBadResponseError, | ||
[-6]: WebrpcServerPanicError, | ||
[-7]: WebrpcInternalErrorError, | ||
[-8]: WebrpcClientDisconnectedError, | ||
[-9]: WebrpcStreamLostError, | ||
[-10]: WebrpcStreamFinishedError, | ||
[1000]: UnauthorizedError, | ||
[1001]: PermissionDeniedError, | ||
[1002]: SessionExpiredError, | ||
[1003]: MethodNotFoundError, | ||
[1004]: RequestConflictError, | ||
[1005]: AbortedError, | ||
[2000]: TimeoutError, | ||
[2001]: InvalidArgumentError, | ||
[2002]: UnavailableError, | ||
[2003]: QueryFailedError, | ||
[3000]: NotFoundError, | ||
[3002]: ProjectNotFoundError, | ||
[3003]: MetadataCallFailedError | ||
}; | ||
const fetch = typeof global === 'object' ? global.fetch : window.fetch; | ||
@@ -375,2 +820,3 @@ class SequenceIndexer extends Indexer { | ||
exports.AbortedError = AbortedError; | ||
exports.ContractType = ContractType; | ||
@@ -380,10 +826,35 @@ exports.EventLogDataType = EventLogDataType; | ||
exports.Indexer = Indexer; | ||
exports.InvalidArgumentError = InvalidArgumentError; | ||
exports.MetadataCallFailedError = MetadataCallFailedError; | ||
exports.MethodNotFoundError = MethodNotFoundError; | ||
exports.NotFoundError = NotFoundError; | ||
exports.OrderStatus = OrderStatus; | ||
exports.PermissionDeniedError = PermissionDeniedError; | ||
exports.ProjectNotFoundError = ProjectNotFoundError; | ||
exports.QueryFailedError = QueryFailedError; | ||
exports.RequestConflictError = RequestConflictError; | ||
exports.SequenceIndexer = SequenceIndexer; | ||
exports.SessionExpiredError = SessionExpiredError; | ||
exports.SortOrder = SortOrder; | ||
exports.TimeoutError = TimeoutError; | ||
exports.TransactionStatus = TransactionStatus; | ||
exports.TransactionType = TransactionType; | ||
exports.TxnTransferType = TxnTransferType; | ||
exports.UnauthorizedError = UnauthorizedError; | ||
exports.UnavailableError = UnavailableError; | ||
exports.WebRPCSchemaHash = WebRPCSchemaHash; | ||
exports.WebRPCSchemaVersion = WebRPCSchemaVersion; | ||
exports.WebRPCVersion = WebRPCVersion; | ||
exports.WebrpcBadMethodError = WebrpcBadMethodError; | ||
exports.WebrpcBadRequestError = WebrpcBadRequestError; | ||
exports.WebrpcBadResponseError = WebrpcBadResponseError; | ||
exports.WebrpcBadRouteError = WebrpcBadRouteError; | ||
exports.WebrpcClientDisconnectedError = WebrpcClientDisconnectedError; | ||
exports.WebrpcEndpointError = WebrpcEndpointError; | ||
exports.WebrpcError = WebrpcError; | ||
exports.WebrpcInternalErrorError = WebrpcInternalErrorError; | ||
exports.WebrpcRequestFailedError = WebrpcRequestFailedError; | ||
exports.WebrpcServerPanicError = WebrpcServerPanicError; | ||
exports.WebrpcStreamFinishedError = WebrpcStreamFinishedError; | ||
exports.WebrpcStreamLostError = WebrpcStreamLostError; | ||
exports.errors = errors; |
@@ -21,7 +21,7 @@ 'use strict'; | ||
/* eslint-disable */ | ||
// sequence-indexer v0.4.0 83530970d81179658f6546c87fc4352280dbd287 | ||
// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e | ||
// -- | ||
// Code generated by webrpc-gen@v0.14.0-dev with typescript@v0.10.0 generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=indexer.ridl -target=typescript@v0.10.0 -client -out=./clients/indexer.gen.ts | ||
// webrpc-gen -schema=indexer.ridl -target=typescript -client -out=./clients/indexer.gen.ts | ||
@@ -35,3 +35,3 @@ // WebRPC description and code-gen version | ||
// Schema hash generated from your RIDL schema | ||
const WebRPCSchemaHash = '83530970d81179658f6546c87fc4352280dbd287'; | ||
const WebRPCSchemaHash = 'd33d29bc84a4439a42a4e1533035bc80c4ea226e'; | ||
@@ -104,4 +104,4 @@ // | ||
this.path = '/rpc/Indexer/'; | ||
this.ping = headers => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => { | ||
this.ping = (headers, signal) => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -112,6 +112,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.version = headers => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => { | ||
this.version = (headers, signal) => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -122,6 +126,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.runtimeStatus = headers => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => { | ||
this.runtimeStatus = (headers, signal) => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -132,6 +140,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getChainID = headers => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => { | ||
this.getChainID = (headers, signal) => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -142,6 +154,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getEtherBalance = (args, headers) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.getEtherBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -152,6 +168,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenBalances = (args, headers) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenBalances = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -163,6 +183,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSupplies = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSupplies = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -175,6 +199,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSuppliesMap = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSuppliesMap = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -185,6 +213,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getBalanceUpdates = (args, headers) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers)).then(res => { | ||
this.getBalanceUpdates = (args, headers, signal) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -196,6 +228,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTransactionHistory = (args, headers) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTransactionHistory = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -207,13 +243,21 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.syncBalance = (args, headers) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.syncBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return {}; | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceipt = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceipt = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -224,6 +268,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getOrderbookOrders = (args, headers) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getOrderbookOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -235,6 +283,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTopOrders = (args, headers) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTopOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -245,6 +297,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceiptWithFilter = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceiptWithFilter = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -255,6 +311,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getAllWebhookListeners = (args, headers) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers)).then(res => { | ||
this.getAllWebhookListeners = (args, headers, signal) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -265,6 +325,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.getWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -275,6 +339,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.addWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.addWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -286,6 +354,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.updateWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.updateWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -296,6 +368,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.removeWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.removeWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -306,4 +382,24 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.subscribeReceipts = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.subscribeEvents = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.hostname = hostname; | ||
@@ -316,3 +412,117 @@ this.fetch = (input, init) => fetch(input, init); | ||
} | ||
const createHTTPRequest = (body = {}, headers = {}) => { | ||
const sseResponse = async (res, options, retryFetch) => { | ||
const { | ||
onMessage, | ||
onOpen, | ||
onClose, | ||
onError | ||
} = options; | ||
if (!res.ok) { | ||
try { | ||
await buildResponse(res); | ||
} catch (error) { | ||
// @ts-ignore | ||
onError(error, retryFetch); | ||
} | ||
return; | ||
} | ||
if (!res.body) { | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: 'Invalid response, missing body' | ||
}), retryFetch); | ||
return; | ||
} | ||
onOpen && onOpen(); | ||
const reader = res.body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let buffer = ''; | ||
let lastReadTime = Date.now(); | ||
const timeout = (10 + 1) * 1000; | ||
let intervalId; | ||
try { | ||
intervalId = setInterval(() => { | ||
if (Date.now() - lastReadTime > timeout) { | ||
throw WebrpcStreamLostError.new({ | ||
cause: 'Stream timed out' | ||
}); | ||
} | ||
}, timeout); | ||
while (true) { | ||
let value; | ||
let done; | ||
try { | ||
; | ||
({ | ||
value, | ||
done | ||
} = await reader.read()); | ||
lastReadTime = Date.now(); | ||
buffer += decoder.decode(value, { | ||
stream: true | ||
}); | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
if (error instanceof DOMException && error.name === 'AbortError') { | ||
onError(WebrpcRequestFailedError.new({ | ||
message: 'AbortError', | ||
cause: `AbortError: ${message}` | ||
}), () => { | ||
throw new Error('Abort signal cannot be used to reconnect'); | ||
}); | ||
} else { | ||
onError(WebrpcStreamLostError.new({ | ||
cause: `reader.read(): ${message}` | ||
}), retryFetch); | ||
} | ||
return; | ||
} | ||
let lines = buffer.split('\n'); | ||
for (let i = 0; i < lines.length - 1; i++) { | ||
if (lines[i].length == 0) { | ||
continue; | ||
} | ||
let data; | ||
try { | ||
data = JSON.parse(lines[i]); | ||
if (data.hasOwnProperty('webrpcError')) { | ||
const error = data.webrpcError; | ||
const code = typeof error.code === 'number' ? error.code : 0; | ||
onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch); | ||
return; | ||
} | ||
} catch (error) { | ||
if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') { | ||
throw error; | ||
} | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
// @ts-ignore | ||
cause: `JSON.parse(): ${error.message}` | ||
}), retryFetch); | ||
} | ||
onMessage(data); | ||
} | ||
if (!done) { | ||
buffer = lines[lines.length - 1]; | ||
continue; | ||
} | ||
onClose && onClose(); | ||
return; | ||
} | ||
} catch (error) { | ||
// @ts-ignore | ||
if (error instanceof WebrpcStreamLostError) { | ||
onError(error, retryFetch); | ||
} else { | ||
throw error; | ||
} | ||
} finally { | ||
clearInterval(intervalId); | ||
} | ||
}; | ||
const createHTTPRequest = (body = {}, headers = {}, signal = null) => { | ||
return { | ||
@@ -323,3 +533,4 @@ method: 'POST', | ||
}), | ||
body: JSON.stringify(body || {}) | ||
body: JSON.stringify(body || {}), | ||
signal | ||
}; | ||
@@ -332,11 +543,15 @@ }; | ||
data = JSON.parse(text); | ||
} catch (err) { | ||
throw { | ||
code: 'unknown', | ||
msg: `expecting JSON, got: ${text}`, | ||
status: res.status | ||
}; | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
throw WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: `JSON.parse(): ${message}: response text: ${text}` | ||
}); | ||
} | ||
if (!res.ok) { | ||
throw data; // webrpc error response | ||
const code = typeof data.code === 'number' ? data.code : 0; | ||
throw (webrpcErrorByCode[code] || WebrpcError).new(data); | ||
} | ||
@@ -347,2 +562,232 @@ return data; | ||
// | ||
// Errors | ||
// | ||
class WebrpcError extends Error { | ||
constructor(name, code, message, status, cause) { | ||
super(message); | ||
this.name = void 0; | ||
this.code = void 0; | ||
this.message = void 0; | ||
this.status = void 0; | ||
this.cause = void 0; | ||
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ | ||
this.msg = void 0; | ||
this.name = name || 'WebrpcError'; | ||
this.code = typeof code === 'number' ? code : 0; | ||
this.message = message || `endpoint error ${this.code}`; | ||
this.msg = this.message; | ||
this.status = typeof status === 'number' ? status : 0; | ||
this.cause = cause; | ||
Object.setPrototypeOf(this, WebrpcError.prototype); | ||
} | ||
static new(payload) { | ||
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause); | ||
} | ||
} | ||
// Webrpc errors | ||
class WebrpcEndpointError extends WebrpcError { | ||
constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcEndpointError.prototype); | ||
} | ||
} | ||
class WebrpcRequestFailedError extends WebrpcError { | ||
constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype); | ||
} | ||
} | ||
class WebrpcBadRouteError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype); | ||
} | ||
} | ||
class WebrpcBadMethodError extends WebrpcError { | ||
constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype); | ||
} | ||
} | ||
class WebrpcBadRequestError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype); | ||
} | ||
} | ||
class WebrpcBadResponseError extends WebrpcError { | ||
constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype); | ||
} | ||
} | ||
class WebrpcServerPanicError extends WebrpcError { | ||
constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype); | ||
} | ||
} | ||
class WebrpcInternalErrorError extends WebrpcError { | ||
constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype); | ||
} | ||
} | ||
class WebrpcClientDisconnectedError extends WebrpcError { | ||
constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype); | ||
} | ||
} | ||
class WebrpcStreamLostError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype); | ||
} | ||
} | ||
class WebrpcStreamFinishedError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype); | ||
} | ||
} | ||
// Schema errors | ||
class UnauthorizedError extends WebrpcError { | ||
constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype); | ||
} | ||
} | ||
class PermissionDeniedError extends WebrpcError { | ||
constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, PermissionDeniedError.prototype); | ||
} | ||
} | ||
class SessionExpiredError extends WebrpcError { | ||
constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, SessionExpiredError.prototype); | ||
} | ||
} | ||
class MethodNotFoundError extends WebrpcError { | ||
constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MethodNotFoundError.prototype); | ||
} | ||
} | ||
class RequestConflictError extends WebrpcError { | ||
constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, RequestConflictError.prototype); | ||
} | ||
} | ||
class AbortedError extends WebrpcError { | ||
constructor(name = 'Aborted', code = 1005, message = 'Request aborted', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, AbortedError.prototype); | ||
} | ||
} | ||
class TimeoutError extends WebrpcError { | ||
constructor(name = 'Timeout', code = 2000, message = 'Request timed out', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, TimeoutError.prototype); | ||
} | ||
} | ||
class InvalidArgumentError extends WebrpcError { | ||
constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, InvalidArgumentError.prototype); | ||
} | ||
} | ||
class UnavailableError extends WebrpcError { | ||
constructor(name = 'Unavailable', code = 2002, message = 'Unavailable resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnavailableError.prototype); | ||
} | ||
} | ||
class QueryFailedError extends WebrpcError { | ||
constructor(name = 'QueryFailed', code = 2003, message = 'Query failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, QueryFailedError.prototype); | ||
} | ||
} | ||
class NotFoundError extends WebrpcError { | ||
constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, NotFoundError.prototype); | ||
} | ||
} | ||
class ProjectNotFoundError extends WebrpcError { | ||
constructor(name = 'ProjectNotFound', code = 3002, message = 'Project not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, ProjectNotFoundError.prototype); | ||
} | ||
} | ||
class MetadataCallFailedError extends WebrpcError { | ||
constructor(name = 'MetadataCallFailed', code = 3003, message = 'Metadata service call failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MetadataCallFailedError.prototype); | ||
} | ||
} | ||
let errors = /*#__PURE__*/function (errors) { | ||
errors["WebrpcEndpoint"] = "WebrpcEndpoint"; | ||
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed"; | ||
errors["WebrpcBadRoute"] = "WebrpcBadRoute"; | ||
errors["WebrpcBadMethod"] = "WebrpcBadMethod"; | ||
errors["WebrpcBadRequest"] = "WebrpcBadRequest"; | ||
errors["WebrpcBadResponse"] = "WebrpcBadResponse"; | ||
errors["WebrpcServerPanic"] = "WebrpcServerPanic"; | ||
errors["WebrpcInternalError"] = "WebrpcInternalError"; | ||
errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected"; | ||
errors["WebrpcStreamLost"] = "WebrpcStreamLost"; | ||
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished"; | ||
errors["Unauthorized"] = "Unauthorized"; | ||
errors["PermissionDenied"] = "PermissionDenied"; | ||
errors["SessionExpired"] = "SessionExpired"; | ||
errors["MethodNotFound"] = "MethodNotFound"; | ||
errors["RequestConflict"] = "RequestConflict"; | ||
errors["Aborted"] = "Aborted"; | ||
errors["Timeout"] = "Timeout"; | ||
errors["InvalidArgument"] = "InvalidArgument"; | ||
errors["Unavailable"] = "Unavailable"; | ||
errors["QueryFailed"] = "QueryFailed"; | ||
errors["NotFound"] = "NotFound"; | ||
errors["ProjectNotFound"] = "ProjectNotFound"; | ||
errors["MetadataCallFailed"] = "MetadataCallFailed"; | ||
return errors; | ||
}({}); | ||
const webrpcErrorByCode = { | ||
[0]: WebrpcEndpointError, | ||
[-1]: WebrpcRequestFailedError, | ||
[-2]: WebrpcBadRouteError, | ||
[-3]: WebrpcBadMethodError, | ||
[-4]: WebrpcBadRequestError, | ||
[-5]: WebrpcBadResponseError, | ||
[-6]: WebrpcServerPanicError, | ||
[-7]: WebrpcInternalErrorError, | ||
[-8]: WebrpcClientDisconnectedError, | ||
[-9]: WebrpcStreamLostError, | ||
[-10]: WebrpcStreamFinishedError, | ||
[1000]: UnauthorizedError, | ||
[1001]: PermissionDeniedError, | ||
[1002]: SessionExpiredError, | ||
[1003]: MethodNotFoundError, | ||
[1004]: RequestConflictError, | ||
[1005]: AbortedError, | ||
[2000]: TimeoutError, | ||
[2001]: InvalidArgumentError, | ||
[2002]: UnavailableError, | ||
[2003]: QueryFailedError, | ||
[3000]: NotFoundError, | ||
[3002]: ProjectNotFoundError, | ||
[3003]: MetadataCallFailedError | ||
}; | ||
const fetch = typeof global === 'object' ? global.fetch : window.fetch; | ||
@@ -375,2 +820,3 @@ class SequenceIndexer extends Indexer { | ||
exports.AbortedError = AbortedError; | ||
exports.ContractType = ContractType; | ||
@@ -380,10 +826,35 @@ exports.EventLogDataType = EventLogDataType; | ||
exports.Indexer = Indexer; | ||
exports.InvalidArgumentError = InvalidArgumentError; | ||
exports.MetadataCallFailedError = MetadataCallFailedError; | ||
exports.MethodNotFoundError = MethodNotFoundError; | ||
exports.NotFoundError = NotFoundError; | ||
exports.OrderStatus = OrderStatus; | ||
exports.PermissionDeniedError = PermissionDeniedError; | ||
exports.ProjectNotFoundError = ProjectNotFoundError; | ||
exports.QueryFailedError = QueryFailedError; | ||
exports.RequestConflictError = RequestConflictError; | ||
exports.SequenceIndexer = SequenceIndexer; | ||
exports.SessionExpiredError = SessionExpiredError; | ||
exports.SortOrder = SortOrder; | ||
exports.TimeoutError = TimeoutError; | ||
exports.TransactionStatus = TransactionStatus; | ||
exports.TransactionType = TransactionType; | ||
exports.TxnTransferType = TxnTransferType; | ||
exports.UnauthorizedError = UnauthorizedError; | ||
exports.UnavailableError = UnavailableError; | ||
exports.WebRPCSchemaHash = WebRPCSchemaHash; | ||
exports.WebRPCSchemaVersion = WebRPCSchemaVersion; | ||
exports.WebRPCVersion = WebRPCVersion; | ||
exports.WebrpcBadMethodError = WebrpcBadMethodError; | ||
exports.WebrpcBadRequestError = WebrpcBadRequestError; | ||
exports.WebrpcBadResponseError = WebrpcBadResponseError; | ||
exports.WebrpcBadRouteError = WebrpcBadRouteError; | ||
exports.WebrpcClientDisconnectedError = WebrpcClientDisconnectedError; | ||
exports.WebrpcEndpointError = WebrpcEndpointError; | ||
exports.WebrpcError = WebrpcError; | ||
exports.WebrpcInternalErrorError = WebrpcInternalErrorError; | ||
exports.WebrpcRequestFailedError = WebrpcRequestFailedError; | ||
exports.WebrpcServerPanicError = WebrpcServerPanicError; | ||
exports.WebrpcStreamFinishedError = WebrpcStreamFinishedError; | ||
exports.WebrpcStreamLostError = WebrpcStreamLostError; | ||
exports.errors = errors; |
@@ -17,7 +17,7 @@ function _extends() { | ||
/* eslint-disable */ | ||
// sequence-indexer v0.4.0 83530970d81179658f6546c87fc4352280dbd287 | ||
// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e | ||
// -- | ||
// Code generated by webrpc-gen@v0.14.0-dev with typescript@v0.10.0 generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=indexer.ridl -target=typescript@v0.10.0 -client -out=./clients/indexer.gen.ts | ||
// webrpc-gen -schema=indexer.ridl -target=typescript -client -out=./clients/indexer.gen.ts | ||
@@ -31,3 +31,3 @@ // WebRPC description and code-gen version | ||
// Schema hash generated from your RIDL schema | ||
const WebRPCSchemaHash = '83530970d81179658f6546c87fc4352280dbd287'; | ||
const WebRPCSchemaHash = 'd33d29bc84a4439a42a4e1533035bc80c4ea226e'; | ||
@@ -100,4 +100,4 @@ // | ||
this.path = '/rpc/Indexer/'; | ||
this.ping = headers => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => { | ||
this.ping = (headers, signal) => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -108,6 +108,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.version = headers => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => { | ||
this.version = (headers, signal) => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -118,6 +122,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.runtimeStatus = headers => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => { | ||
this.runtimeStatus = (headers, signal) => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -128,6 +136,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getChainID = headers => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => { | ||
this.getChainID = (headers, signal) => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -138,6 +150,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getEtherBalance = (args, headers) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.getEtherBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -148,6 +164,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenBalances = (args, headers) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenBalances = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -159,6 +179,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSupplies = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSupplies = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -171,6 +195,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTokenSuppliesMap = (args, headers) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTokenSuppliesMap = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -181,6 +209,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getBalanceUpdates = (args, headers) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers)).then(res => { | ||
this.getBalanceUpdates = (args, headers, signal) => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -192,6 +224,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTransactionHistory = (args, headers) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTransactionHistory = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -203,13 +239,21 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.syncBalance = (args, headers) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers)).then(res => { | ||
this.syncBalance = (args, headers, signal) => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return {}; | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceipt = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceipt = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -220,6 +264,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getOrderbookOrders = (args, headers) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getOrderbookOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -231,6 +279,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getTopOrders = (args, headers) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers)).then(res => { | ||
this.getTopOrders = (args, headers, signal) => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -241,6 +293,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.fetchTransactionReceiptWithFilter = (args, headers) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers)).then(res => { | ||
this.fetchTransactionReceiptWithFilter = (args, headers, signal) => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -251,6 +307,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getAllWebhookListeners = (args, headers) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers)).then(res => { | ||
this.getAllWebhookListeners = (args, headers, signal) => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -261,6 +321,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.getWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.getWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -271,6 +335,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.addWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.addWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -282,6 +350,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.updateWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.updateWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -292,6 +364,10 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.removeWebhookListener = (args, headers) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
this.removeWebhookListener = (args, headers, signal) => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
@@ -302,4 +378,24 @@ return { | ||
}); | ||
}, error => { | ||
throw WebrpcRequestFailedError.new({ | ||
cause: `fetch(): ${error.message || ''}` | ||
}); | ||
}); | ||
}; | ||
this.subscribeReceipts = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.subscribeEvents = (args, options) => { | ||
const _fetch = () => this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) { | ||
await sseResponse(res, options, _fetch); | ||
}, error => { | ||
options.onError(error, _fetch); | ||
}); | ||
return _fetch(); | ||
}; | ||
this.hostname = hostname; | ||
@@ -312,3 +408,117 @@ this.fetch = (input, init) => fetch(input, init); | ||
} | ||
const createHTTPRequest = (body = {}, headers = {}) => { | ||
const sseResponse = async (res, options, retryFetch) => { | ||
const { | ||
onMessage, | ||
onOpen, | ||
onClose, | ||
onError | ||
} = options; | ||
if (!res.ok) { | ||
try { | ||
await buildResponse(res); | ||
} catch (error) { | ||
// @ts-ignore | ||
onError(error, retryFetch); | ||
} | ||
return; | ||
} | ||
if (!res.body) { | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: 'Invalid response, missing body' | ||
}), retryFetch); | ||
return; | ||
} | ||
onOpen && onOpen(); | ||
const reader = res.body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let buffer = ''; | ||
let lastReadTime = Date.now(); | ||
const timeout = (10 + 1) * 1000; | ||
let intervalId; | ||
try { | ||
intervalId = setInterval(() => { | ||
if (Date.now() - lastReadTime > timeout) { | ||
throw WebrpcStreamLostError.new({ | ||
cause: 'Stream timed out' | ||
}); | ||
} | ||
}, timeout); | ||
while (true) { | ||
let value; | ||
let done; | ||
try { | ||
; | ||
({ | ||
value, | ||
done | ||
} = await reader.read()); | ||
lastReadTime = Date.now(); | ||
buffer += decoder.decode(value, { | ||
stream: true | ||
}); | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
if (error instanceof DOMException && error.name === 'AbortError') { | ||
onError(WebrpcRequestFailedError.new({ | ||
message: 'AbortError', | ||
cause: `AbortError: ${message}` | ||
}), () => { | ||
throw new Error('Abort signal cannot be used to reconnect'); | ||
}); | ||
} else { | ||
onError(WebrpcStreamLostError.new({ | ||
cause: `reader.read(): ${message}` | ||
}), retryFetch); | ||
} | ||
return; | ||
} | ||
let lines = buffer.split('\n'); | ||
for (let i = 0; i < lines.length - 1; i++) { | ||
if (lines[i].length == 0) { | ||
continue; | ||
} | ||
let data; | ||
try { | ||
data = JSON.parse(lines[i]); | ||
if (data.hasOwnProperty('webrpcError')) { | ||
const error = data.webrpcError; | ||
const code = typeof error.code === 'number' ? error.code : 0; | ||
onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch); | ||
return; | ||
} | ||
} catch (error) { | ||
if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') { | ||
throw error; | ||
} | ||
onError(WebrpcBadResponseError.new({ | ||
status: res.status, | ||
// @ts-ignore | ||
cause: `JSON.parse(): ${error.message}` | ||
}), retryFetch); | ||
} | ||
onMessage(data); | ||
} | ||
if (!done) { | ||
buffer = lines[lines.length - 1]; | ||
continue; | ||
} | ||
onClose && onClose(); | ||
return; | ||
} | ||
} catch (error) { | ||
// @ts-ignore | ||
if (error instanceof WebrpcStreamLostError) { | ||
onError(error, retryFetch); | ||
} else { | ||
throw error; | ||
} | ||
} finally { | ||
clearInterval(intervalId); | ||
} | ||
}; | ||
const createHTTPRequest = (body = {}, headers = {}, signal = null) => { | ||
return { | ||
@@ -319,3 +529,4 @@ method: 'POST', | ||
}), | ||
body: JSON.stringify(body || {}) | ||
body: JSON.stringify(body || {}), | ||
signal | ||
}; | ||
@@ -328,11 +539,15 @@ }; | ||
data = JSON.parse(text); | ||
} catch (err) { | ||
throw { | ||
code: 'unknown', | ||
msg: `expecting JSON, got: ${text}`, | ||
status: res.status | ||
}; | ||
} catch (error) { | ||
let message = ''; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
throw WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: `JSON.parse(): ${message}: response text: ${text}` | ||
}); | ||
} | ||
if (!res.ok) { | ||
throw data; // webrpc error response | ||
const code = typeof data.code === 'number' ? data.code : 0; | ||
throw (webrpcErrorByCode[code] || WebrpcError).new(data); | ||
} | ||
@@ -343,2 +558,232 @@ return data; | ||
// | ||
// Errors | ||
// | ||
class WebrpcError extends Error { | ||
constructor(name, code, message, status, cause) { | ||
super(message); | ||
this.name = void 0; | ||
this.code = void 0; | ||
this.message = void 0; | ||
this.status = void 0; | ||
this.cause = void 0; | ||
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ | ||
this.msg = void 0; | ||
this.name = name || 'WebrpcError'; | ||
this.code = typeof code === 'number' ? code : 0; | ||
this.message = message || `endpoint error ${this.code}`; | ||
this.msg = this.message; | ||
this.status = typeof status === 'number' ? status : 0; | ||
this.cause = cause; | ||
Object.setPrototypeOf(this, WebrpcError.prototype); | ||
} | ||
static new(payload) { | ||
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause); | ||
} | ||
} | ||
// Webrpc errors | ||
class WebrpcEndpointError extends WebrpcError { | ||
constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcEndpointError.prototype); | ||
} | ||
} | ||
class WebrpcRequestFailedError extends WebrpcError { | ||
constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype); | ||
} | ||
} | ||
class WebrpcBadRouteError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype); | ||
} | ||
} | ||
class WebrpcBadMethodError extends WebrpcError { | ||
constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype); | ||
} | ||
} | ||
class WebrpcBadRequestError extends WebrpcError { | ||
constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype); | ||
} | ||
} | ||
class WebrpcBadResponseError extends WebrpcError { | ||
constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype); | ||
} | ||
} | ||
class WebrpcServerPanicError extends WebrpcError { | ||
constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype); | ||
} | ||
} | ||
class WebrpcInternalErrorError extends WebrpcError { | ||
constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype); | ||
} | ||
} | ||
class WebrpcClientDisconnectedError extends WebrpcError { | ||
constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype); | ||
} | ||
} | ||
class WebrpcStreamLostError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype); | ||
} | ||
} | ||
class WebrpcStreamFinishedError extends WebrpcError { | ||
constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype); | ||
} | ||
} | ||
// Schema errors | ||
class UnauthorizedError extends WebrpcError { | ||
constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype); | ||
} | ||
} | ||
class PermissionDeniedError extends WebrpcError { | ||
constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, PermissionDeniedError.prototype); | ||
} | ||
} | ||
class SessionExpiredError extends WebrpcError { | ||
constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, SessionExpiredError.prototype); | ||
} | ||
} | ||
class MethodNotFoundError extends WebrpcError { | ||
constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MethodNotFoundError.prototype); | ||
} | ||
} | ||
class RequestConflictError extends WebrpcError { | ||
constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, RequestConflictError.prototype); | ||
} | ||
} | ||
class AbortedError extends WebrpcError { | ||
constructor(name = 'Aborted', code = 1005, message = 'Request aborted', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, AbortedError.prototype); | ||
} | ||
} | ||
class TimeoutError extends WebrpcError { | ||
constructor(name = 'Timeout', code = 2000, message = 'Request timed out', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, TimeoutError.prototype); | ||
} | ||
} | ||
class InvalidArgumentError extends WebrpcError { | ||
constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, InvalidArgumentError.prototype); | ||
} | ||
} | ||
class UnavailableError extends WebrpcError { | ||
constructor(name = 'Unavailable', code = 2002, message = 'Unavailable resource', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, UnavailableError.prototype); | ||
} | ||
} | ||
class QueryFailedError extends WebrpcError { | ||
constructor(name = 'QueryFailed', code = 2003, message = 'Query failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, QueryFailedError.prototype); | ||
} | ||
} | ||
class NotFoundError extends WebrpcError { | ||
constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, NotFoundError.prototype); | ||
} | ||
} | ||
class ProjectNotFoundError extends WebrpcError { | ||
constructor(name = 'ProjectNotFound', code = 3002, message = 'Project not found', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, ProjectNotFoundError.prototype); | ||
} | ||
} | ||
class MetadataCallFailedError extends WebrpcError { | ||
constructor(name = 'MetadataCallFailed', code = 3003, message = 'Metadata service call failed', status = 0, cause) { | ||
super(name, code, message, status, cause); | ||
Object.setPrototypeOf(this, MetadataCallFailedError.prototype); | ||
} | ||
} | ||
let errors = /*#__PURE__*/function (errors) { | ||
errors["WebrpcEndpoint"] = "WebrpcEndpoint"; | ||
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed"; | ||
errors["WebrpcBadRoute"] = "WebrpcBadRoute"; | ||
errors["WebrpcBadMethod"] = "WebrpcBadMethod"; | ||
errors["WebrpcBadRequest"] = "WebrpcBadRequest"; | ||
errors["WebrpcBadResponse"] = "WebrpcBadResponse"; | ||
errors["WebrpcServerPanic"] = "WebrpcServerPanic"; | ||
errors["WebrpcInternalError"] = "WebrpcInternalError"; | ||
errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected"; | ||
errors["WebrpcStreamLost"] = "WebrpcStreamLost"; | ||
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished"; | ||
errors["Unauthorized"] = "Unauthorized"; | ||
errors["PermissionDenied"] = "PermissionDenied"; | ||
errors["SessionExpired"] = "SessionExpired"; | ||
errors["MethodNotFound"] = "MethodNotFound"; | ||
errors["RequestConflict"] = "RequestConflict"; | ||
errors["Aborted"] = "Aborted"; | ||
errors["Timeout"] = "Timeout"; | ||
errors["InvalidArgument"] = "InvalidArgument"; | ||
errors["Unavailable"] = "Unavailable"; | ||
errors["QueryFailed"] = "QueryFailed"; | ||
errors["NotFound"] = "NotFound"; | ||
errors["ProjectNotFound"] = "ProjectNotFound"; | ||
errors["MetadataCallFailed"] = "MetadataCallFailed"; | ||
return errors; | ||
}({}); | ||
const webrpcErrorByCode = { | ||
[0]: WebrpcEndpointError, | ||
[-1]: WebrpcRequestFailedError, | ||
[-2]: WebrpcBadRouteError, | ||
[-3]: WebrpcBadMethodError, | ||
[-4]: WebrpcBadRequestError, | ||
[-5]: WebrpcBadResponseError, | ||
[-6]: WebrpcServerPanicError, | ||
[-7]: WebrpcInternalErrorError, | ||
[-8]: WebrpcClientDisconnectedError, | ||
[-9]: WebrpcStreamLostError, | ||
[-10]: WebrpcStreamFinishedError, | ||
[1000]: UnauthorizedError, | ||
[1001]: PermissionDeniedError, | ||
[1002]: SessionExpiredError, | ||
[1003]: MethodNotFoundError, | ||
[1004]: RequestConflictError, | ||
[1005]: AbortedError, | ||
[2000]: TimeoutError, | ||
[2001]: InvalidArgumentError, | ||
[2002]: UnavailableError, | ||
[2003]: QueryFailedError, | ||
[3000]: NotFoundError, | ||
[3002]: ProjectNotFoundError, | ||
[3003]: MetadataCallFailedError | ||
}; | ||
const fetch = typeof global === 'object' ? global.fetch : window.fetch; | ||
@@ -371,2 +816,2 @@ class SequenceIndexer extends Indexer { | ||
export { ContractType, EventLogDataType, EventLogType, Indexer, OrderStatus, SequenceIndexer, SortOrder, TransactionStatus, TransactionType, TxnTransferType, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion }; | ||
export { AbortedError, ContractType, EventLogDataType, EventLogType, Indexer, InvalidArgumentError, MetadataCallFailedError, MethodNotFoundError, NotFoundError, OrderStatus, PermissionDeniedError, ProjectNotFoundError, QueryFailedError, RequestConflictError, SequenceIndexer, SessionExpiredError, SortOrder, TimeoutError, TransactionStatus, TransactionType, TxnTransferType, UnauthorizedError, UnavailableError, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion, WebrpcBadMethodError, WebrpcBadRequestError, WebrpcBadResponseError, WebrpcBadRouteError, WebrpcClientDisconnectedError, WebrpcEndpointError, WebrpcError, WebrpcInternalErrorError, WebrpcRequestFailedError, WebrpcServerPanicError, WebrpcStreamFinishedError, WebrpcStreamLostError, errors }; |
export declare const WebRPCVersion = "v1"; | ||
export declare const WebRPCSchemaVersion = "v0.4.0"; | ||
export declare const WebRPCSchemaHash = "83530970d81179658f6546c87fc4352280dbd287"; | ||
export declare const WebRPCSchemaHash = "d33d29bc84a4439a42a4e1533035bc80c4ea226e"; | ||
export interface ContractInfo { | ||
@@ -29,21 +29,34 @@ chainId: number; | ||
tokenId: string; | ||
contractAddress: string; | ||
name: string; | ||
description: string; | ||
image: string; | ||
decimals: number; | ||
properties: { | ||
description?: string; | ||
image?: string; | ||
video?: string; | ||
audio?: string; | ||
properties?: { | ||
[key: string]: any; | ||
}; | ||
video: string; | ||
audio: string; | ||
image_data: string; | ||
external_url: string; | ||
background_color: string; | ||
animation_url: string; | ||
attributes: Array<{ | ||
[key: string]: any; | ||
}>; | ||
updatedAt: string; | ||
image_data?: string; | ||
external_url?: string; | ||
background_color?: string; | ||
animation_url?: string; | ||
decimals?: number; | ||
updatedAt?: string; | ||
assets?: Array<Asset>; | ||
} | ||
export interface Asset { | ||
id: number; | ||
collectionId: number; | ||
tokenId: string; | ||
url?: string; | ||
metadataField: string; | ||
name?: string; | ||
filesize?: number; | ||
mimeType?: string; | ||
width?: number; | ||
height?: number; | ||
updatedAt?: string; | ||
} | ||
export declare enum ContractType { | ||
@@ -132,4 +145,13 @@ UNKNOWN = "UNKNOWN", | ||
bond: Bond; | ||
diskUsage: string; | ||
diskUsage: DiskUsage; | ||
} | ||
export interface DiskUsage { | ||
humanReadable: string; | ||
used: number; | ||
size: number; | ||
percent: number; | ||
dirs: { | ||
[key: string]: string; | ||
}; | ||
} | ||
export interface Bond { | ||
@@ -276,3 +298,3 @@ pebble: PebbleMetrics; | ||
} | ||
export interface Filter { | ||
export interface TransactionFilter { | ||
txnHash?: string; | ||
@@ -282,3 +304,4 @@ from?: string; | ||
contractAddress?: string; | ||
logTopic?: string; | ||
event?: string; | ||
topicHash?: string; | ||
} | ||
@@ -323,6 +346,8 @@ export interface TransactionReceipt { | ||
url: string; | ||
filters: WebhookEventFilter; | ||
filters: EventFilter; | ||
updatedAt: string; | ||
} | ||
export interface WebhookEventFilter { | ||
export interface EventFilter { | ||
events?: Array<string>; | ||
topicHashes?: Array<string>; | ||
contractAddresses?: Array<string>; | ||
@@ -338,22 +363,24 @@ tokenIDs?: Array<string>; | ||
export interface Indexer { | ||
ping(headers?: object): Promise<PingReturn>; | ||
version(headers?: object): Promise<VersionReturn>; | ||
runtimeStatus(headers?: object): Promise<RuntimeStatusReturn>; | ||
getChainID(headers?: object): Promise<GetChainIDReturn>; | ||
getEtherBalance(args: GetEtherBalanceArgs, headers?: object): Promise<GetEtherBalanceReturn>; | ||
getTokenBalances(args: GetTokenBalancesArgs, headers?: object): Promise<GetTokenBalancesReturn>; | ||
getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object): Promise<GetTokenSuppliesReturn>; | ||
getTokenSuppliesMap(args: GetTokenSuppliesMapArgs, headers?: object): Promise<GetTokenSuppliesMapReturn>; | ||
getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object): Promise<GetBalanceUpdatesReturn>; | ||
getTransactionHistory(args: GetTransactionHistoryArgs, headers?: object): Promise<GetTransactionHistoryReturn>; | ||
syncBalance(args: SyncBalanceArgs, headers?: object): Promise<SyncBalanceReturn>; | ||
fetchTransactionReceipt(args: FetchTransactionReceiptArgs, headers?: object): Promise<FetchTransactionReceiptReturn>; | ||
getOrderbookOrders(args: GetOrderbookOrdersArgs, headers?: object): Promise<GetOrderbookOrdersReturn>; | ||
getTopOrders(args: GetTopOrdersArgs, headers?: object): Promise<GetTopOrdersReturn>; | ||
fetchTransactionReceiptWithFilter(args: FetchTransactionReceiptWithFilterArgs, headers?: object): Promise<FetchTransactionReceiptWithFilterReturn>; | ||
getAllWebhookListeners(args: GetAllWebhookListenersArgs, headers?: object): Promise<GetAllWebhookListenersReturn>; | ||
getWebhookListener(args: GetWebhookListenerArgs, headers?: object): Promise<GetWebhookListenerReturn>; | ||
addWebhookListener(args: AddWebhookListenerArgs, headers?: object): Promise<AddWebhookListenerReturn>; | ||
updateWebhookListener(args: UpdateWebhookListenerArgs, headers?: object): Promise<UpdateWebhookListenerReturn>; | ||
removeWebhookListener(args: RemoveWebhookListenerArgs, headers?: object): Promise<RemoveWebhookListenerReturn>; | ||
ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>; | ||
version(headers?: object, signal?: AbortSignal): Promise<VersionReturn>; | ||
runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn>; | ||
getChainID(headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn>; | ||
getEtherBalance(args: GetEtherBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceReturn>; | ||
getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn>; | ||
getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesReturn>; | ||
getTokenSuppliesMap(args: GetTokenSuppliesMapArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesMapReturn>; | ||
getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn>; | ||
getTransactionHistory(args: GetTransactionHistoryArgs, headers?: object, signal?: AbortSignal): Promise<GetTransactionHistoryReturn>; | ||
syncBalance(args: SyncBalanceArgs, headers?: object, signal?: AbortSignal): Promise<SyncBalanceReturn>; | ||
fetchTransactionReceipt(args: FetchTransactionReceiptArgs, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptReturn>; | ||
getOrderbookOrders(args: GetOrderbookOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetOrderbookOrdersReturn>; | ||
getTopOrders(args: GetTopOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetTopOrdersReturn>; | ||
fetchTransactionReceiptWithFilter(args: FetchTransactionReceiptWithFilterArgs, headers?: object, signal?: AbortSignal): Promise<FetchTransactionReceiptWithFilterReturn>; | ||
getAllWebhookListeners(args: GetAllWebhookListenersArgs, headers?: object, signal?: AbortSignal): Promise<GetAllWebhookListenersReturn>; | ||
getWebhookListener(args: GetWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<GetWebhookListenerReturn>; | ||
addWebhookListener(args: AddWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<AddWebhookListenerReturn>; | ||
updateWebhookListener(args: UpdateWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<UpdateWebhookListenerReturn>; | ||
removeWebhookListener(args: RemoveWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<RemoveWebhookListenerReturn>; | ||
subscribeReceipts(args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>): Promise<void>; | ||
subscribeEvents(args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>): Promise<void>; | ||
} | ||
@@ -482,3 +509,3 @@ export interface PingArgs { | ||
export interface FetchTransactionReceiptWithFilterArgs { | ||
filter: Filter; | ||
filter: TransactionFilter; | ||
maxBlockWait?: number; | ||
@@ -504,3 +531,3 @@ } | ||
url: string; | ||
filters: WebhookEventFilter; | ||
filters: EventFilter; | ||
projectId?: number; | ||
@@ -526,2 +553,14 @@ } | ||
} | ||
export interface SubscribeReceiptsArgs { | ||
filter: TransactionFilter; | ||
} | ||
export interface SubscribeReceiptsReturn { | ||
receipt: TransactionReceipt; | ||
} | ||
export interface SubscribeEventsArgs { | ||
filter: EventFilter; | ||
} | ||
export interface SubscribeEventsReturn { | ||
log: EventLog; | ||
} | ||
export declare class Indexer implements Indexer { | ||
@@ -533,28 +572,144 @@ protected hostname: string; | ||
private url; | ||
ping: (headers?: object | undefined) => Promise<PingReturn>; | ||
version: (headers?: object | undefined) => Promise<VersionReturn>; | ||
runtimeStatus: (headers?: object | undefined) => Promise<RuntimeStatusReturn>; | ||
getChainID: (headers?: object | undefined) => Promise<GetChainIDReturn>; | ||
getEtherBalance: (args: GetEtherBalanceArgs, headers?: object | undefined) => Promise<GetEtherBalanceReturn>; | ||
getTokenBalances: (args: GetTokenBalancesArgs, headers?: object | undefined) => Promise<GetTokenBalancesReturn>; | ||
getTokenSupplies: (args: GetTokenSuppliesArgs, headers?: object | undefined) => Promise<GetTokenSuppliesReturn>; | ||
getTokenSuppliesMap: (args: GetTokenSuppliesMapArgs, headers?: object | undefined) => Promise<GetTokenSuppliesMapReturn>; | ||
getBalanceUpdates: (args: GetBalanceUpdatesArgs, headers?: object | undefined) => Promise<GetBalanceUpdatesReturn>; | ||
getTransactionHistory: (args: GetTransactionHistoryArgs, headers?: object | undefined) => Promise<GetTransactionHistoryReturn>; | ||
syncBalance: (args: SyncBalanceArgs, headers?: object | undefined) => Promise<SyncBalanceReturn>; | ||
fetchTransactionReceipt: (args: FetchTransactionReceiptArgs, headers?: object | undefined) => Promise<FetchTransactionReceiptReturn>; | ||
getOrderbookOrders: (args: GetOrderbookOrdersArgs, headers?: object | undefined) => Promise<GetOrderbookOrdersReturn>; | ||
getTopOrders: (args: GetTopOrdersArgs, headers?: object | undefined) => Promise<GetTopOrdersReturn>; | ||
fetchTransactionReceiptWithFilter: (args: FetchTransactionReceiptWithFilterArgs, headers?: object | undefined) => Promise<FetchTransactionReceiptWithFilterReturn>; | ||
getAllWebhookListeners: (args: GetAllWebhookListenersArgs, headers?: object | undefined) => Promise<GetAllWebhookListenersReturn>; | ||
getWebhookListener: (args: GetWebhookListenerArgs, headers?: object | undefined) => Promise<GetWebhookListenerReturn>; | ||
addWebhookListener: (args: AddWebhookListenerArgs, headers?: object | undefined) => Promise<AddWebhookListenerReturn>; | ||
updateWebhookListener: (args: UpdateWebhookListenerArgs, headers?: object | undefined) => Promise<UpdateWebhookListenerReturn>; | ||
removeWebhookListener: (args: RemoveWebhookListenerArgs, headers?: object | undefined) => Promise<RemoveWebhookListenerReturn>; | ||
ping: (headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<PingReturn>; | ||
version: (headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<VersionReturn>; | ||
runtimeStatus: (headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<RuntimeStatusReturn>; | ||
getChainID: (headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetChainIDReturn>; | ||
getEtherBalance: (args: GetEtherBalanceArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetEtherBalanceReturn>; | ||
getTokenBalances: (args: GetTokenBalancesArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetTokenBalancesReturn>; | ||
getTokenSupplies: (args: GetTokenSuppliesArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetTokenSuppliesReturn>; | ||
getTokenSuppliesMap: (args: GetTokenSuppliesMapArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetTokenSuppliesMapReturn>; | ||
getBalanceUpdates: (args: GetBalanceUpdatesArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetBalanceUpdatesReturn>; | ||
getTransactionHistory: (args: GetTransactionHistoryArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetTransactionHistoryReturn>; | ||
syncBalance: (args: SyncBalanceArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<SyncBalanceReturn>; | ||
fetchTransactionReceipt: (args: FetchTransactionReceiptArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<FetchTransactionReceiptReturn>; | ||
getOrderbookOrders: (args: GetOrderbookOrdersArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetOrderbookOrdersReturn>; | ||
getTopOrders: (args: GetTopOrdersArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetTopOrdersReturn>; | ||
fetchTransactionReceiptWithFilter: (args: FetchTransactionReceiptWithFilterArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<FetchTransactionReceiptWithFilterReturn>; | ||
getAllWebhookListeners: (args: GetAllWebhookListenersArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetAllWebhookListenersReturn>; | ||
getWebhookListener: (args: GetWebhookListenerArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<GetWebhookListenerReturn>; | ||
addWebhookListener: (args: AddWebhookListenerArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<AddWebhookListenerReturn>; | ||
updateWebhookListener: (args: UpdateWebhookListenerArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<UpdateWebhookListenerReturn>; | ||
removeWebhookListener: (args: RemoveWebhookListenerArgs, headers?: object | undefined, signal?: AbortSignal | undefined) => Promise<RemoveWebhookListenerReturn>; | ||
subscribeReceipts: (args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>) => Promise<void>; | ||
subscribeEvents: (args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>) => Promise<void>; | ||
} | ||
export interface WebRPCError extends Error { | ||
code: string; | ||
export declare class WebrpcError extends Error { | ||
name: string; | ||
code: number; | ||
message: string; | ||
status: number; | ||
cause?: string; | ||
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ | ||
msg: string; | ||
status: number; | ||
constructor(name: string, code: number, message: string, status: number, cause?: string); | ||
static new(payload: any): WebrpcError; | ||
} | ||
export declare class WebrpcEndpointError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcRequestFailedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcBadRouteError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcBadMethodError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcBadRequestError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcBadResponseError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcServerPanicError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcInternalErrorError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcClientDisconnectedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcStreamLostError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class WebrpcStreamFinishedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class UnauthorizedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class PermissionDeniedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class SessionExpiredError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class MethodNotFoundError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class RequestConflictError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class AbortedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class TimeoutError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class InvalidArgumentError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class UnavailableError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class QueryFailedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class NotFoundError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class ProjectNotFoundError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare class MetadataCallFailedError extends WebrpcError { | ||
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string); | ||
} | ||
export declare enum errors { | ||
WebrpcEndpoint = "WebrpcEndpoint", | ||
WebrpcRequestFailed = "WebrpcRequestFailed", | ||
WebrpcBadRoute = "WebrpcBadRoute", | ||
WebrpcBadMethod = "WebrpcBadMethod", | ||
WebrpcBadRequest = "WebrpcBadRequest", | ||
WebrpcBadResponse = "WebrpcBadResponse", | ||
WebrpcServerPanic = "WebrpcServerPanic", | ||
WebrpcInternalError = "WebrpcInternalError", | ||
WebrpcClientDisconnected = "WebrpcClientDisconnected", | ||
WebrpcStreamLost = "WebrpcStreamLost", | ||
WebrpcStreamFinished = "WebrpcStreamFinished", | ||
Unauthorized = "Unauthorized", | ||
PermissionDenied = "PermissionDenied", | ||
SessionExpired = "SessionExpired", | ||
MethodNotFound = "MethodNotFound", | ||
RequestConflict = "RequestConflict", | ||
Aborted = "Aborted", | ||
Timeout = "Timeout", | ||
InvalidArgument = "InvalidArgument", | ||
Unavailable = "Unavailable", | ||
QueryFailed = "QueryFailed", | ||
NotFound = "NotFound", | ||
ProjectNotFound = "ProjectNotFound", | ||
MetadataCallFailed = "MetadataCallFailed" | ||
} | ||
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>; | ||
export interface WebrpcStreamOptions<T> extends WebrpcOptions { | ||
onMessage: (message: T) => void; | ||
onError: (error: WebrpcError, reconnect: () => void) => void; | ||
onOpen?: () => void; | ||
onClose?: () => void; | ||
} | ||
export interface WebrpcOptions { | ||
headers?: HeadersInit; | ||
signal?: AbortSignal; | ||
} |
{ | ||
"name": "@0xsequence/indexer", | ||
"version": "1.9.24", | ||
"version": "1.9.25", | ||
"description": "indexer sub-package for Sequence", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/indexer", |
/* eslint-disable */ | ||
// sequence-indexer v0.4.0 83530970d81179658f6546c87fc4352280dbd287 | ||
// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e | ||
// -- | ||
// Code generated by webrpc-gen@v0.14.0-dev with typescript@v0.10.0 generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=indexer.ridl -target=typescript@v0.10.0 -client -out=./clients/indexer.gen.ts | ||
// webrpc-gen -schema=indexer.ridl -target=typescript -client -out=./clients/indexer.gen.ts | ||
@@ -15,3 +15,3 @@ // WebRPC description and code-gen version | ||
// Schema hash generated from your RIDL schema | ||
export const WebRPCSchemaHash = '83530970d81179658f6546c87fc4352280dbd287' | ||
export const WebRPCSchemaHash = 'd33d29bc84a4439a42a4e1533035bc80c4ea226e' | ||
@@ -33,3 +33,2 @@ // | ||
extensions: ContractInfoExtensions | ||
updatedAt: string | ||
@@ -51,17 +50,32 @@ } | ||
tokenId: string | ||
contractAddress: string | ||
name: string | ||
description: string | ||
image: string | ||
decimals: number | ||
properties: { [key: string]: any } | ||
video: string | ||
audio: string | ||
image_data: string | ||
external_url: string | ||
background_color: string | ||
animation_url: string | ||
description?: string | ||
image?: string | ||
video?: string | ||
audio?: string | ||
properties?: { [key: string]: any } | ||
attributes: Array<{ [key: string]: any }> | ||
updatedAt: string | ||
image_data?: string | ||
external_url?: string | ||
background_color?: string | ||
animation_url?: string | ||
decimals?: number | ||
updatedAt?: string | ||
assets?: Array<Asset> | ||
} | ||
export interface Asset { | ||
id: number | ||
collectionId: number | ||
tokenId: string | ||
url?: string | ||
metadataField: string | ||
name?: string | ||
filesize?: number | ||
mimeType?: string | ||
width?: number | ||
height?: number | ||
updatedAt?: string | ||
} | ||
export enum ContractType { | ||
@@ -79,2 +93,3 @@ UNKNOWN = 'UNKNOWN', | ||
} | ||
export enum EventLogType { | ||
@@ -85,2 +100,3 @@ UNKNOWN = 'UNKNOWN', | ||
} | ||
export enum EventLogDataType { | ||
@@ -92,2 +108,3 @@ UNKNOWN = 'UNKNOWN', | ||
} | ||
export enum OrderStatus { | ||
@@ -98,2 +115,3 @@ OPEN = 'OPEN', | ||
} | ||
export enum TxnTransferType { | ||
@@ -104,2 +122,3 @@ UNKNOWN = 'UNKNOWN', | ||
} | ||
export enum TransactionStatus { | ||
@@ -109,2 +128,3 @@ FAILED = 'FAILED', | ||
} | ||
export enum TransactionType { | ||
@@ -115,2 +135,3 @@ LegacyTxnType = 'LegacyTxnType', | ||
} | ||
export enum SortOrder { | ||
@@ -161,5 +182,13 @@ DESC = 'DESC', | ||
bond: Bond | ||
diskUsage: string | ||
diskUsage: DiskUsage | ||
} | ||
export interface DiskUsage { | ||
humanReadable: string | ||
used: number | ||
size: number | ||
percent: number | ||
dirs: { [key: string]: string } | ||
} | ||
export interface Bond { | ||
@@ -233,3 +262,2 @@ pebble: PebbleMetrics | ||
chainId: number | ||
contractInfo?: ContractInfo | ||
@@ -322,3 +350,3 @@ tokenMetadata?: TokenMetadata | ||
export interface Filter { | ||
export interface TransactionFilter { | ||
txnHash?: string | ||
@@ -328,3 +356,4 @@ from?: string | ||
contractAddress?: string | ||
logTopic?: string | ||
event?: string | ||
topicHash?: string | ||
} | ||
@@ -374,7 +403,9 @@ | ||
url: string | ||
filters: WebhookEventFilter | ||
filters: EventFilter | ||
updatedAt: string | ||
} | ||
export interface WebhookEventFilter { | ||
export interface EventFilter { | ||
events?: Array<string> | ||
topicHashes?: Array<string> | ||
contractAddresses?: Array<string> | ||
@@ -392,25 +423,48 @@ tokenIDs?: Array<string> | ||
export interface Indexer { | ||
ping(headers?: object): Promise<PingReturn> | ||
version(headers?: object): Promise<VersionReturn> | ||
runtimeStatus(headers?: object): Promise<RuntimeStatusReturn> | ||
getChainID(headers?: object): Promise<GetChainIDReturn> | ||
getEtherBalance(args: GetEtherBalanceArgs, headers?: object): Promise<GetEtherBalanceReturn> | ||
getTokenBalances(args: GetTokenBalancesArgs, headers?: object): Promise<GetTokenBalancesReturn> | ||
getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object): Promise<GetTokenSuppliesReturn> | ||
getTokenSuppliesMap(args: GetTokenSuppliesMapArgs, headers?: object): Promise<GetTokenSuppliesMapReturn> | ||
getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object): Promise<GetBalanceUpdatesReturn> | ||
getTransactionHistory(args: GetTransactionHistoryArgs, headers?: object): Promise<GetTransactionHistoryReturn> | ||
syncBalance(args: SyncBalanceArgs, headers?: object): Promise<SyncBalanceReturn> | ||
fetchTransactionReceipt(args: FetchTransactionReceiptArgs, headers?: object): Promise<FetchTransactionReceiptReturn> | ||
getOrderbookOrders(args: GetOrderbookOrdersArgs, headers?: object): Promise<GetOrderbookOrdersReturn> | ||
getTopOrders(args: GetTopOrdersArgs, headers?: object): Promise<GetTopOrdersReturn> | ||
ping(headers?: object, signal?: AbortSignal): Promise<PingReturn> | ||
version(headers?: object, signal?: AbortSignal): Promise<VersionReturn> | ||
runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> | ||
getChainID(headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn> | ||
getEtherBalance(args: GetEtherBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceReturn> | ||
getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn> | ||
getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesReturn> | ||
getTokenSuppliesMap(args: GetTokenSuppliesMapArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesMapReturn> | ||
getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn> | ||
getTransactionHistory( | ||
args: GetTransactionHistoryArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetTransactionHistoryReturn> | ||
syncBalance(args: SyncBalanceArgs, headers?: object, signal?: AbortSignal): Promise<SyncBalanceReturn> | ||
fetchTransactionReceipt( | ||
args: FetchTransactionReceiptArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<FetchTransactionReceiptReturn> | ||
getOrderbookOrders(args: GetOrderbookOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetOrderbookOrdersReturn> | ||
getTopOrders(args: GetTopOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetTopOrdersReturn> | ||
fetchTransactionReceiptWithFilter( | ||
args: FetchTransactionReceiptWithFilterArgs, | ||
headers?: object | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<FetchTransactionReceiptWithFilterReturn> | ||
getAllWebhookListeners(args: GetAllWebhookListenersArgs, headers?: object): Promise<GetAllWebhookListenersReturn> | ||
getWebhookListener(args: GetWebhookListenerArgs, headers?: object): Promise<GetWebhookListenerReturn> | ||
addWebhookListener(args: AddWebhookListenerArgs, headers?: object): Promise<AddWebhookListenerReturn> | ||
updateWebhookListener(args: UpdateWebhookListenerArgs, headers?: object): Promise<UpdateWebhookListenerReturn> | ||
removeWebhookListener(args: RemoveWebhookListenerArgs, headers?: object): Promise<RemoveWebhookListenerReturn> | ||
getAllWebhookListeners( | ||
args: GetAllWebhookListenersArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetAllWebhookListenersReturn> | ||
getWebhookListener(args: GetWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<GetWebhookListenerReturn> | ||
addWebhookListener(args: AddWebhookListenerArgs, headers?: object, signal?: AbortSignal): Promise<AddWebhookListenerReturn> | ||
updateWebhookListener( | ||
args: UpdateWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<UpdateWebhookListenerReturn> | ||
removeWebhookListener( | ||
args: RemoveWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<RemoveWebhookListenerReturn> | ||
subscribeReceipts(args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>): Promise<void> | ||
subscribeEvents(args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>): Promise<void> | ||
} | ||
@@ -545,3 +599,3 @@ | ||
export interface FetchTransactionReceiptWithFilterArgs { | ||
filter: Filter | ||
filter: TransactionFilter | ||
maxBlockWait?: number | ||
@@ -570,3 +624,3 @@ } | ||
url: string | ||
filters: WebhookEventFilter | ||
filters: EventFilter | ||
projectId?: number | ||
@@ -595,3 +649,17 @@ } | ||
} | ||
export interface SubscribeReceiptsArgs { | ||
filter: TransactionFilter | ||
} | ||
export interface SubscribeReceiptsReturn { | ||
receipt: TransactionReceipt | ||
} | ||
export interface SubscribeEventsArgs { | ||
filter: EventFilter | ||
} | ||
export interface SubscribeEventsReturn { | ||
log: EventLog | ||
} | ||
// | ||
@@ -614,144 +682,230 @@ // Client | ||
ping = (headers?: object): Promise<PingReturn> => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
} | ||
}) | ||
}) | ||
ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => { | ||
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
version = (headers?: object): Promise<VersionReturn> => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
version: <Version>_data.version | ||
} | ||
}) | ||
}) | ||
version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => { | ||
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
version: <Version>_data.version | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
runtimeStatus = (headers?: object): Promise<RuntimeStatusReturn> => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <RuntimeStatus>_data.status | ||
} | ||
}) | ||
}) | ||
runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => { | ||
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <RuntimeStatus>_data.status | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getChainID = (headers?: object): Promise<GetChainIDReturn> => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
chainID: <number>_data.chainID | ||
} | ||
}) | ||
}) | ||
getChainID = (headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn> => { | ||
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
chainID: <number>_data.chainID | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getEtherBalance = (args: GetEtherBalanceArgs, headers?: object): Promise<GetEtherBalanceReturn> => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
balance: <EtherBalance>_data.balance | ||
} | ||
}) | ||
}) | ||
getEtherBalance = (args: GetEtherBalanceArgs, headers?: object, signal?: AbortSignal): Promise<GetEtherBalanceReturn> => { | ||
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
balance: <EtherBalance>_data.balance | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getTokenBalances = (args: GetTokenBalancesArgs, headers?: object): Promise<GetTokenBalancesReturn> => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
balances: <Array<TokenBalance>>_data.balances | ||
} | ||
}) | ||
}) | ||
getTokenBalances = (args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenBalancesReturn> => { | ||
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
balances: <Array<TokenBalance>>_data.balances | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getTokenSupplies = (args: GetTokenSuppliesArgs, headers?: object): Promise<GetTokenSuppliesReturn> => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
contractType: <ContractType>_data.contractType, | ||
tokenIDs: <Array<TokenSupply>>_data.tokenIDs | ||
} | ||
}) | ||
}) | ||
getTokenSupplies = (args: GetTokenSuppliesArgs, headers?: object, signal?: AbortSignal): Promise<GetTokenSuppliesReturn> => { | ||
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
contractType: <ContractType>_data.contractType, | ||
tokenIDs: <Array<TokenSupply>>_data.tokenIDs | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getTokenSuppliesMap = (args: GetTokenSuppliesMapArgs, headers?: object): Promise<GetTokenSuppliesMapReturn> => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
supplies: <{ [key: string]: Array<TokenSupply> }>_data.supplies | ||
} | ||
}) | ||
}) | ||
getTokenSuppliesMap = ( | ||
args: GetTokenSuppliesMapArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetTokenSuppliesMapReturn> => { | ||
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
supplies: <{ [key: string]: Array<TokenSupply> }>_data.supplies | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object): Promise<GetBalanceUpdatesReturn> => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
balances: <Array<TokenBalance>>_data.balances | ||
} | ||
}) | ||
}) | ||
getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise<GetBalanceUpdatesReturn> => { | ||
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
balances: <Array<TokenBalance>>_data.balances | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getTransactionHistory = (args: GetTransactionHistoryArgs, headers?: object): Promise<GetTransactionHistoryReturn> => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
transactions: <Array<Transaction>>_data.transactions | ||
} | ||
}) | ||
}) | ||
getTransactionHistory = ( | ||
args: GetTransactionHistoryArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetTransactionHistoryReturn> => { | ||
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
transactions: <Array<Transaction>>_data.transactions | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
syncBalance = (args: SyncBalanceArgs, headers?: object): Promise<SyncBalanceReturn> => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return {} | ||
}) | ||
}) | ||
syncBalance = (args: SyncBalanceArgs, headers?: object, signal?: AbortSignal): Promise<SyncBalanceReturn> => { | ||
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return {} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
fetchTransactionReceipt = (args: FetchTransactionReceiptArgs, headers?: object): Promise<FetchTransactionReceiptReturn> => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
receipt: <TransactionReceipt>_data.receipt | ||
} | ||
}) | ||
}) | ||
fetchTransactionReceipt = ( | ||
args: FetchTransactionReceiptArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<FetchTransactionReceiptReturn> => { | ||
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
receipt: <TransactionReceipt>_data.receipt | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getOrderbookOrders = (args: GetOrderbookOrdersArgs, headers?: object): Promise<GetOrderbookOrdersReturn> => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
orders: <Array<OrderbookOrder>>_data.orders | ||
} | ||
}) | ||
}) | ||
getOrderbookOrders = ( | ||
args: GetOrderbookOrdersArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetOrderbookOrdersReturn> => { | ||
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
page: <Page>_data.page, | ||
orders: <Array<OrderbookOrder>>_data.orders | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getTopOrders = (args: GetTopOrdersArgs, headers?: object): Promise<GetTopOrdersReturn> => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
orders: <Array<OrderbookOrder>>_data.orders | ||
} | ||
}) | ||
}) | ||
getTopOrders = (args: GetTopOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetTopOrdersReturn> => { | ||
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
orders: <Array<OrderbookOrder>>_data.orders | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
@@ -761,76 +915,271 @@ | ||
args: FetchTransactionReceiptWithFilterArgs, | ||
headers?: object | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<FetchTransactionReceiptWithFilterReturn> => { | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
receipt: <TransactionReceipt>_data.receipt | ||
} | ||
}) | ||
}) | ||
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
receipt: <TransactionReceipt>_data.receipt | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getAllWebhookListeners = (args: GetAllWebhookListenersArgs, headers?: object): Promise<GetAllWebhookListenersReturn> => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
listeners: <Array<WebhookListener>>_data.listeners | ||
} | ||
}) | ||
}) | ||
getAllWebhookListeners = ( | ||
args: GetAllWebhookListenersArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetAllWebhookListenersReturn> => { | ||
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
listeners: <Array<WebhookListener>>_data.listeners | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
getWebhookListener = (args: GetWebhookListenerArgs, headers?: object): Promise<GetWebhookListenerReturn> => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
listener: <WebhookListener>_data.listener | ||
} | ||
}) | ||
}) | ||
getWebhookListener = ( | ||
args: GetWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<GetWebhookListenerReturn> => { | ||
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
listener: <WebhookListener>_data.listener | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
addWebhookListener = (args: AddWebhookListenerArgs, headers?: object): Promise<AddWebhookListenerReturn> => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status, | ||
listener: <WebhookListener>_data.listener | ||
} | ||
}) | ||
}) | ||
addWebhookListener = ( | ||
args: AddWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<AddWebhookListenerReturn> => { | ||
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status, | ||
listener: <WebhookListener>_data.listener | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
updateWebhookListener = (args: UpdateWebhookListenerArgs, headers?: object): Promise<UpdateWebhookListenerReturn> => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
} | ||
}) | ||
}) | ||
updateWebhookListener = ( | ||
args: UpdateWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<UpdateWebhookListenerReturn> => { | ||
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
removeWebhookListener = (args: RemoveWebhookListenerArgs, headers?: object): Promise<RemoveWebhookListenerReturn> => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers)).then(res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
removeWebhookListener = ( | ||
args: RemoveWebhookListenerArgs, | ||
headers?: object, | ||
signal?: AbortSignal | ||
): Promise<RemoveWebhookListenerReturn> => { | ||
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then( | ||
res => { | ||
return buildResponse(res).then(_data => { | ||
return { | ||
status: <boolean>_data.status | ||
} | ||
}) | ||
}, | ||
error => { | ||
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) | ||
} | ||
) | ||
} | ||
subscribeReceipts = (args: SubscribeReceiptsArgs, options: WebrpcStreamOptions<SubscribeReceiptsReturn>): Promise<void> => { | ||
const _fetch = () => | ||
this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then( | ||
async res => { | ||
await sseResponse(res, options, _fetch) | ||
}, | ||
error => { | ||
options.onError(error, _fetch) | ||
} | ||
}) | ||
}) | ||
) | ||
return _fetch() | ||
} | ||
subscribeEvents = (args: SubscribeEventsArgs, options: WebrpcStreamOptions<SubscribeEventsReturn>): Promise<void> => { | ||
const _fetch = () => | ||
this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then( | ||
async res => { | ||
await sseResponse(res, options, _fetch) | ||
}, | ||
error => { | ||
options.onError(error, _fetch) | ||
} | ||
) | ||
return _fetch() | ||
} | ||
} | ||
export interface WebRPCError extends Error { | ||
code: string | ||
msg: string | ||
status: number | ||
const sseResponse = async (res: Response, options: WebrpcStreamOptions<any>, retryFetch: () => Promise<void>) => { | ||
const { onMessage, onOpen, onClose, onError } = options | ||
if (!res.ok) { | ||
try { | ||
await buildResponse(res) | ||
} catch (error) { | ||
// @ts-ignore | ||
onError(error, retryFetch) | ||
} | ||
return | ||
} | ||
if (!res.body) { | ||
onError( | ||
WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: 'Invalid response, missing body' | ||
}), | ||
retryFetch | ||
) | ||
return | ||
} | ||
onOpen && onOpen() | ||
const reader = res.body.getReader() | ||
const decoder = new TextDecoder() | ||
let buffer = '' | ||
let lastReadTime = Date.now() | ||
const timeout = (10 + 1) * 1000 | ||
let intervalId: any | ||
try { | ||
intervalId = setInterval(() => { | ||
if (Date.now() - lastReadTime > timeout) { | ||
throw WebrpcStreamLostError.new({ cause: 'Stream timed out' }) | ||
} | ||
}, timeout) | ||
while (true) { | ||
let value | ||
let done | ||
try { | ||
;({ value, done } = await reader.read()) | ||
lastReadTime = Date.now() | ||
buffer += decoder.decode(value, { stream: true }) | ||
} catch (error) { | ||
let message = '' | ||
if (error instanceof Error) { | ||
message = error.message | ||
} | ||
if (error instanceof DOMException && error.name === 'AbortError') { | ||
onError( | ||
WebrpcRequestFailedError.new({ | ||
message: 'AbortError', | ||
cause: `AbortError: ${message}` | ||
}), | ||
() => { | ||
throw new Error('Abort signal cannot be used to reconnect') | ||
} | ||
) | ||
} else { | ||
onError( | ||
WebrpcStreamLostError.new({ | ||
cause: `reader.read(): ${message}` | ||
}), | ||
retryFetch | ||
) | ||
} | ||
return | ||
} | ||
let lines = buffer.split('\n') | ||
for (let i = 0; i < lines.length - 1; i++) { | ||
if (lines[i].length == 0) { | ||
continue | ||
} | ||
let data: any | ||
try { | ||
data = JSON.parse(lines[i]) | ||
if (data.hasOwnProperty('webrpcError')) { | ||
const error = data.webrpcError | ||
const code: number = typeof error.code === 'number' ? error.code : 0 | ||
onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch) | ||
return | ||
} | ||
} catch (error) { | ||
if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') { | ||
throw error | ||
} | ||
onError( | ||
WebrpcBadResponseError.new({ | ||
status: res.status, | ||
// @ts-ignore | ||
cause: `JSON.parse(): ${error.message}` | ||
}), | ||
retryFetch | ||
) | ||
} | ||
onMessage(data) | ||
} | ||
if (!done) { | ||
buffer = lines[lines.length - 1] | ||
continue | ||
} | ||
onClose && onClose() | ||
return | ||
} | ||
} catch (error) { | ||
// @ts-ignore | ||
if (error instanceof WebrpcStreamLostError) { | ||
onError(error, retryFetch) | ||
} else { | ||
throw error | ||
} | ||
} finally { | ||
clearInterval(intervalId) | ||
} | ||
} | ||
const createHTTPRequest = (body: object = {}, headers: object = {}): object => { | ||
const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { | ||
return { | ||
method: 'POST', | ||
headers: { ...headers, 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(body || {}) | ||
body: JSON.stringify(body || {}), | ||
signal | ||
} | ||
@@ -844,7 +1193,15 @@ } | ||
data = JSON.parse(text) | ||
} catch (err) { | ||
throw { code: 'unknown', msg: `expecting JSON, got: ${text}`, status: res.status } as WebRPCError | ||
} catch (error) { | ||
let message = '' | ||
if (error instanceof Error) { | ||
message = error.message | ||
} | ||
throw WebrpcBadResponseError.new({ | ||
status: res.status, | ||
cause: `JSON.parse(): ${message}: response text: ${text}` | ||
}) | ||
} | ||
if (!res.ok) { | ||
throw data // webrpc error response | ||
const code: number = typeof data.code === 'number' ? data.code : 0 | ||
throw (webrpcErrorByCode[code] || WebrpcError).new(data) | ||
} | ||
@@ -855,2 +1212,413 @@ return data | ||
// | ||
// Errors | ||
// | ||
export class WebrpcError extends Error { | ||
name: string | ||
code: number | ||
message: string | ||
status: number | ||
cause?: string | ||
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ | ||
msg: string | ||
constructor(name: string, code: number, message: string, status: number, cause?: string) { | ||
super(message) | ||
this.name = name || 'WebrpcError' | ||
this.code = typeof code === 'number' ? code : 0 | ||
this.message = message || `endpoint error ${this.code}` | ||
this.msg = this.message | ||
this.status = typeof status === 'number' ? status : 0 | ||
this.cause = cause | ||
Object.setPrototypeOf(this, WebrpcError.prototype) | ||
} | ||
static new(payload: any): WebrpcError { | ||
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause) | ||
} | ||
} | ||
// Webrpc errors | ||
export class WebrpcEndpointError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcEndpoint', | ||
code: number = 0, | ||
message: string = 'endpoint error', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcEndpointError.prototype) | ||
} | ||
} | ||
export class WebrpcRequestFailedError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcRequestFailed', | ||
code: number = -1, | ||
message: string = 'request failed', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype) | ||
} | ||
} | ||
export class WebrpcBadRouteError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcBadRoute', | ||
code: number = -2, | ||
message: string = 'bad route', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype) | ||
} | ||
} | ||
export class WebrpcBadMethodError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcBadMethod', | ||
code: number = -3, | ||
message: string = 'bad method', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype) | ||
} | ||
} | ||
export class WebrpcBadRequestError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcBadRequest', | ||
code: number = -4, | ||
message: string = 'bad request', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype) | ||
} | ||
} | ||
export class WebrpcBadResponseError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcBadResponse', | ||
code: number = -5, | ||
message: string = 'bad response', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype) | ||
} | ||
} | ||
export class WebrpcServerPanicError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcServerPanic', | ||
code: number = -6, | ||
message: string = 'server panic', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype) | ||
} | ||
} | ||
export class WebrpcInternalErrorError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcInternalError', | ||
code: number = -7, | ||
message: string = 'internal error', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype) | ||
} | ||
} | ||
export class WebrpcClientDisconnectedError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcClientDisconnected', | ||
code: number = -8, | ||
message: string = 'client disconnected', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype) | ||
} | ||
} | ||
export class WebrpcStreamLostError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcStreamLost', | ||
code: number = -9, | ||
message: string = 'stream lost', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype) | ||
} | ||
} | ||
export class WebrpcStreamFinishedError extends WebrpcError { | ||
constructor( | ||
name: string = 'WebrpcStreamFinished', | ||
code: number = -10, | ||
message: string = 'stream finished', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype) | ||
} | ||
} | ||
// Schema errors | ||
export class UnauthorizedError extends WebrpcError { | ||
constructor( | ||
name: string = 'Unauthorized', | ||
code: number = 1000, | ||
message: string = 'Unauthorized access', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype) | ||
} | ||
} | ||
export class PermissionDeniedError extends WebrpcError { | ||
constructor( | ||
name: string = 'PermissionDenied', | ||
code: number = 1001, | ||
message: string = 'Permission denied', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, PermissionDeniedError.prototype) | ||
} | ||
} | ||
export class SessionExpiredError extends WebrpcError { | ||
constructor( | ||
name: string = 'SessionExpired', | ||
code: number = 1002, | ||
message: string = 'Session expired', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, SessionExpiredError.prototype) | ||
} | ||
} | ||
export class MethodNotFoundError extends WebrpcError { | ||
constructor( | ||
name: string = 'MethodNotFound', | ||
code: number = 1003, | ||
message: string = 'Method not found', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, MethodNotFoundError.prototype) | ||
} | ||
} | ||
export class RequestConflictError extends WebrpcError { | ||
constructor( | ||
name: string = 'RequestConflict', | ||
code: number = 1004, | ||
message: string = 'Conflict with target resource', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, RequestConflictError.prototype) | ||
} | ||
} | ||
export class AbortedError extends WebrpcError { | ||
constructor( | ||
name: string = 'Aborted', | ||
code: number = 1005, | ||
message: string = 'Request aborted', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, AbortedError.prototype) | ||
} | ||
} | ||
export class TimeoutError extends WebrpcError { | ||
constructor( | ||
name: string = 'Timeout', | ||
code: number = 2000, | ||
message: string = 'Request timed out', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, TimeoutError.prototype) | ||
} | ||
} | ||
export class InvalidArgumentError extends WebrpcError { | ||
constructor( | ||
name: string = 'InvalidArgument', | ||
code: number = 2001, | ||
message: string = 'Invalid argument', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, InvalidArgumentError.prototype) | ||
} | ||
} | ||
export class UnavailableError extends WebrpcError { | ||
constructor( | ||
name: string = 'Unavailable', | ||
code: number = 2002, | ||
message: string = 'Unavailable resource', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, UnavailableError.prototype) | ||
} | ||
} | ||
export class QueryFailedError extends WebrpcError { | ||
constructor( | ||
name: string = 'QueryFailed', | ||
code: number = 2003, | ||
message: string = 'Query failed', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, QueryFailedError.prototype) | ||
} | ||
} | ||
export class NotFoundError extends WebrpcError { | ||
constructor( | ||
name: string = 'NotFound', | ||
code: number = 3000, | ||
message: string = 'Resource not found', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, NotFoundError.prototype) | ||
} | ||
} | ||
export class ProjectNotFoundError extends WebrpcError { | ||
constructor( | ||
name: string = 'ProjectNotFound', | ||
code: number = 3002, | ||
message: string = 'Project not found', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, ProjectNotFoundError.prototype) | ||
} | ||
} | ||
export class MetadataCallFailedError extends WebrpcError { | ||
constructor( | ||
name: string = 'MetadataCallFailed', | ||
code: number = 3003, | ||
message: string = 'Metadata service call failed', | ||
status: number = 0, | ||
cause?: string | ||
) { | ||
super(name, code, message, status, cause) | ||
Object.setPrototypeOf(this, MetadataCallFailedError.prototype) | ||
} | ||
} | ||
export enum errors { | ||
WebrpcEndpoint = 'WebrpcEndpoint', | ||
WebrpcRequestFailed = 'WebrpcRequestFailed', | ||
WebrpcBadRoute = 'WebrpcBadRoute', | ||
WebrpcBadMethod = 'WebrpcBadMethod', | ||
WebrpcBadRequest = 'WebrpcBadRequest', | ||
WebrpcBadResponse = 'WebrpcBadResponse', | ||
WebrpcServerPanic = 'WebrpcServerPanic', | ||
WebrpcInternalError = 'WebrpcInternalError', | ||
WebrpcClientDisconnected = 'WebrpcClientDisconnected', | ||
WebrpcStreamLost = 'WebrpcStreamLost', | ||
WebrpcStreamFinished = 'WebrpcStreamFinished', | ||
Unauthorized = 'Unauthorized', | ||
PermissionDenied = 'PermissionDenied', | ||
SessionExpired = 'SessionExpired', | ||
MethodNotFound = 'MethodNotFound', | ||
RequestConflict = 'RequestConflict', | ||
Aborted = 'Aborted', | ||
Timeout = 'Timeout', | ||
InvalidArgument = 'InvalidArgument', | ||
Unavailable = 'Unavailable', | ||
QueryFailed = 'QueryFailed', | ||
NotFound = 'NotFound', | ||
ProjectNotFound = 'ProjectNotFound', | ||
MetadataCallFailed = 'MetadataCallFailed' | ||
} | ||
const webrpcErrorByCode: { [code: number]: any } = { | ||
[0]: WebrpcEndpointError, | ||
[-1]: WebrpcRequestFailedError, | ||
[-2]: WebrpcBadRouteError, | ||
[-3]: WebrpcBadMethodError, | ||
[-4]: WebrpcBadRequestError, | ||
[-5]: WebrpcBadResponseError, | ||
[-6]: WebrpcServerPanicError, | ||
[-7]: WebrpcInternalErrorError, | ||
[-8]: WebrpcClientDisconnectedError, | ||
[-9]: WebrpcStreamLostError, | ||
[-10]: WebrpcStreamFinishedError, | ||
[1000]: UnauthorizedError, | ||
[1001]: PermissionDeniedError, | ||
[1002]: SessionExpiredError, | ||
[1003]: MethodNotFoundError, | ||
[1004]: RequestConflictError, | ||
[1005]: AbortedError, | ||
[2000]: TimeoutError, | ||
[2001]: InvalidArgumentError, | ||
[2002]: UnavailableError, | ||
[2003]: QueryFailedError, | ||
[3000]: NotFoundError, | ||
[3002]: ProjectNotFoundError, | ||
[3003]: MetadataCallFailedError | ||
} | ||
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response> | ||
export interface WebrpcStreamOptions<T> extends WebrpcOptions { | ||
onMessage: (message: T) => void | ||
onError: (error: WebrpcError, reconnect: () => void) => void | ||
onOpen?: () => void | ||
onClose?: () => void | ||
} | ||
export interface WebrpcOptions { | ||
headers?: HeadersInit | ||
signal?: AbortSignal | ||
} |
167718
4617