diff --git a/packages/api/src/api.gen.ts b/packages/api/src/api.gen.ts index 711f1f184..d9507163f 100644 --- a/packages/api/src/api.gen.ts +++ b/packages/api/src/api.gen.ts @@ -1,10 +1,14 @@ /* eslint-disable */ -// sequence-api v0.4.0 24814ebb88457c0545aa80e8388cb0f08ec59bec +// sequence-api v0.4.0 c3eb9010746703c095291691cd8f08dc04999062 // -- -// Code generated by webrpc-gen@v0.20.3 with typescript generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with typescript generator. DO NOT EDIT. // // webrpc-gen -schema=api.ridl -target=typescript -client -out=./clients/api.gen.ts +export const WebrpcHeader = 'Webrpc' + +export const WebrpcHeaderValue = 'webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-api@v0.4.0' + // WebRPC description and code-gen version export const WebRPCVersion = 'v1' @@ -12,7 +16,55 @@ export const WebRPCVersion = 'v1' export const WebRPCSchemaVersion = 'v0.4.0' // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = '24814ebb88457c0545aa80e8388cb0f08ec59bec' +export const WebRPCSchemaHash = 'c3eb9010746703c095291691cd8f08dc04999062' + +type WebrpcGenVersions = { + webrpcGenVersion: string + codeGenName: string + codeGenVersion: string + schemaName: string + schemaVersion: string +} + +export function VersionFromHeader(headers: Headers): WebrpcGenVersions { + const headerValue = headers.get(WebrpcHeader) + if (!headerValue) { + return { + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } + } + + return parseWebrpcGenVersions(headerValue) +} + +function parseWebrpcGenVersions(header: string): WebrpcGenVersions { + const versions = header.split(';') + if (versions.length < 3) { + return { + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } + } + + const [_, webrpcGenVersion] = versions[0].split('@') + const [codeGenName, codeGenVersion] = versions[1].split('@') + const [schemaName, schemaVersion] = versions[2].split('@') + + return { + webrpcGenVersion, + codeGenName, + codeGenVersion, + schemaName, + schemaVersion + } +} // // Types @@ -305,6 +357,12 @@ export interface SardineSupportedToken { tokenAddress: string } +export interface SardineSupportedTokenForSwap { + isSupported: boolean + isSupportedForAbstraction: boolean + currentBalance: string +} + export interface SardineEnabledToken { network: string assetSymbol: string @@ -506,6 +564,11 @@ export interface API { sardineGetSupportedRegions(headers?: object, signal?: AbortSignal): Promise sardineGetSupportedFiatCurrencies(headers?: object, signal?: AbortSignal): Promise sardineGetSupportedTokens(headers?: object, signal?: AbortSignal): Promise + sardineGetSupportedTokenForSwap( + args: SardineGetSupportedTokenForSwapArgs, + headers?: object, + signal?: AbortSignal + ): Promise sardineGetEnabledTokens(headers?: object, signal?: AbortSignal): Promise sardineGetQuote(args: SardineGetQuoteArgs, headers?: object, signal?: AbortSignal): Promise getSardineClientToken(headers?: object, signal?: AbortSignal): Promise @@ -855,6 +918,14 @@ export interface SardineGetSupportedTokensArgs {} export interface SardineGetSupportedTokensReturn { tokens: Array } +export interface SardineGetSupportedTokenForSwapArgs { + network: string + tokenAddress: string +} + +export interface SardineGetSupportedTokenForSwapReturn { + token: SardineSupportedTokenForSwap +} export interface SardineGetEnabledTokensArgs {} export interface SardineGetEnabledTokensReturn { @@ -1724,6 +1795,25 @@ export class API implements API { ) } + sardineGetSupportedTokenForSwap = ( + args: SardineGetSupportedTokenForSwapArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('SardineGetSupportedTokenForSwap'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + token: _data.token + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + sardineGetEnabledTokens = (headers?: object, signal?: AbortSignal): Promise => { return this.fetch(this.url('SardineGetEnabledTokens'), createHTTPRequest({}, headers, signal)).then( res => { @@ -2290,9 +2380,12 @@ export class API implements API { } const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { + const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' } + reqHeaders[WebrpcHeader] = WebrpcHeaderValue + return { method: 'POST', - headers: { ...headers, 'Content-Type': 'application/json' }, + headers: reqHeaders, body: JSON.stringify(body || {}), signal } @@ -2537,6 +2630,32 @@ export class SessionExpiredError extends WebrpcError { } } +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', @@ -2563,6 +2682,175 @@ export class GeoblockedError extends WebrpcError { } } +export class RateLimitedError extends WebrpcError { + constructor( + name: string = 'RateLimited', + code: number = 1007, + message: string = 'Rate-limited. Please slow down.', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, RateLimitedError.prototype) + } +} + +export class ProjectNotFoundError extends WebrpcError { + constructor( + name: string = 'ProjectNotFound', + code: number = 1008, + message: string = 'Project not found', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, ProjectNotFoundError.prototype) + } +} + +export class AccessKeyNotFoundError extends WebrpcError { + constructor( + name: string = 'AccessKeyNotFound', + code: number = 1101, + message: string = 'Access key not found', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype) + } +} + +export class AccessKeyMismatchError extends WebrpcError { + constructor( + name: string = 'AccessKeyMismatch', + code: number = 1102, + message: string = 'Access key mismatch', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, AccessKeyMismatchError.prototype) + } +} + +export class InvalidOriginError extends WebrpcError { + constructor( + name: string = 'InvalidOrigin', + code: number = 1103, + message: string = 'Invalid origin for Access Key', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, InvalidOriginError.prototype) + } +} + +export class InvalidServiceError extends WebrpcError { + constructor( + name: string = 'InvalidService', + code: number = 1104, + message: string = 'Service not enabled for Access key', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, InvalidServiceError.prototype) + } +} + +export class UnauthorizedUserError extends WebrpcError { + constructor( + name: string = 'UnauthorizedUser', + code: number = 1105, + message: string = 'Unauthorized user', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, UnauthorizedUserError.prototype) + } +} + +export class QuotaExceededError extends WebrpcError { + constructor( + name: string = 'QuotaExceeded', + code: number = 1200, + message: string = 'Quota request exceeded', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, QuotaExceededError.prototype) + } +} + +export class QuotaRateLimitError extends WebrpcError { + constructor( + name: string = 'QuotaRateLimit', + code: number = 1201, + message: string = 'Quota rate limit exceeded', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, QuotaRateLimitError.prototype) + } +} + +export class NoDefaultKeyError extends WebrpcError { + constructor( + name: string = 'NoDefaultKey', + code: number = 1300, + message: string = 'No default access key found', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, NoDefaultKeyError.prototype) + } +} + +export class MaxAccessKeysError extends WebrpcError { + constructor( + name: string = 'MaxAccessKeys', + code: number = 1301, + message: string = 'Access keys limit reached', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, MaxAccessKeysError.prototype) + } +} + +export class AtLeastOneKeyError extends WebrpcError { + constructor( + name: string = 'AtLeastOneKey', + code: number = 1302, + message: string = 'You need at least one Access Key', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, AtLeastOneKeyError.prototype) + } +} + +export class TimeoutError extends WebrpcError { + constructor( + name: string = 'Timeout', + code: number = 1900, + 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', @@ -2615,6 +2903,19 @@ export class NotFoundError extends WebrpcError { } } +export class UnsupportedNetworkError extends WebrpcError { + constructor( + name: string = 'UnsupportedNetwork', + code: number = 3008, + message: string = 'Unsupported network', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, UnsupportedNetworkError.prototype) + } +} + export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', WebrpcRequestFailed = 'WebrpcRequestFailed', @@ -2630,15 +2931,70 @@ export enum errors { Unauthorized = 'Unauthorized', PermissionDenied = 'PermissionDenied', SessionExpired = 'SessionExpired', + MethodNotFound = 'MethodNotFound', + RequestConflict = 'RequestConflict', Aborted = 'Aborted', Geoblocked = 'Geoblocked', + RateLimited = 'RateLimited', + ProjectNotFound = 'ProjectNotFound', + AccessKeyNotFound = 'AccessKeyNotFound', + AccessKeyMismatch = 'AccessKeyMismatch', + InvalidOrigin = 'InvalidOrigin', + InvalidService = 'InvalidService', + UnauthorizedUser = 'UnauthorizedUser', + QuotaExceeded = 'QuotaExceeded', + QuotaRateLimit = 'QuotaRateLimit', + NoDefaultKey = 'NoDefaultKey', + MaxAccessKeys = 'MaxAccessKeys', + AtLeastOneKey = 'AtLeastOneKey', + Timeout = 'Timeout', InvalidArgument = 'InvalidArgument', Unavailable = 'Unavailable', QueryFailed = 'QueryFailed', - NotFound = 'NotFound' -} - -const webrpcErrorByCode: { [code: number]: any } = { + NotFound = 'NotFound', + UnsupportedNetwork = 'UnsupportedNetwork' +} + +export enum WebrpcErrorCodes { + WebrpcEndpoint = 0, + WebrpcRequestFailed = -1, + WebrpcBadRoute = -2, + WebrpcBadMethod = -3, + WebrpcBadRequest = -4, + WebrpcBadResponse = -5, + WebrpcServerPanic = -6, + WebrpcInternalError = -7, + WebrpcClientDisconnected = -8, + WebrpcStreamLost = -9, + WebrpcStreamFinished = -10, + Unauthorized = 1000, + PermissionDenied = 1001, + SessionExpired = 1002, + MethodNotFound = 1003, + RequestConflict = 1004, + Aborted = 1005, + Geoblocked = 1006, + RateLimited = 1007, + ProjectNotFound = 1008, + AccessKeyNotFound = 1101, + AccessKeyMismatch = 1102, + InvalidOrigin = 1103, + InvalidService = 1104, + UnauthorizedUser = 1105, + QuotaExceeded = 1200, + QuotaRateLimit = 1201, + NoDefaultKey = 1300, + MaxAccessKeys = 1301, + AtLeastOneKey = 1302, + Timeout = 1900, + InvalidArgument = 2000, + Unavailable = 2002, + QueryFailed = 2003, + NotFound = 3000, + UnsupportedNetwork = 3008 +} + +export const webrpcErrorByCode: { [code: number]: any } = { [0]: WebrpcEndpointError, [-1]: WebrpcRequestFailedError, [-2]: WebrpcBadRouteError, @@ -2653,12 +3009,28 @@ const webrpcErrorByCode: { [code: number]: any } = { [1000]: UnauthorizedError, [1001]: PermissionDeniedError, [1002]: SessionExpiredError, + [1003]: MethodNotFoundError, + [1004]: RequestConflictError, [1005]: AbortedError, [1006]: GeoblockedError, + [1007]: RateLimitedError, + [1008]: ProjectNotFoundError, + [1101]: AccessKeyNotFoundError, + [1102]: AccessKeyMismatchError, + [1103]: InvalidOriginError, + [1104]: InvalidServiceError, + [1105]: UnauthorizedUserError, + [1200]: QuotaExceededError, + [1201]: QuotaRateLimitError, + [1300]: NoDefaultKeyError, + [1301]: MaxAccessKeysError, + [1302]: AtLeastOneKeyError, + [1900]: TimeoutError, [2000]: InvalidArgumentError, [2002]: UnavailableError, [2003]: QueryFailedError, - [3000]: NotFoundError + [3000]: NotFoundError, + [3008]: UnsupportedNetworkError } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise