diff --git a/packages/sessions/src/trackers/remote/sessions.gen.ts b/packages/sessions/src/trackers/remote/sessions.gen.ts index 68d1dccf1..a7202099b 100644 --- a/packages/sessions/src/trackers/remote/sessions.gen.ts +++ b/packages/sessions/src/trackers/remote/sessions.gen.ts @@ -1,27 +1,76 @@ /* eslint-disable */ -// sessions v0.0.1 67f782e8acfe452f905078a7423ed5d27c6639a8 +// sessions v0.0.1 48681273e3b0249c5feb593b9af1b59dc6a14869 // -- -// Code generated by webrpc-gen@v0.21.3 with typescript generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.1 with typescript generator. DO NOT EDIT. // // webrpc-gen -schema=sessions.ridl -target=typescript -client -out=./clients/sessions.gen.ts -export const WebrpcHeader = 'Webrpc' +export const WebrpcHeader = "Webrpc" -export const WebrpcHeaderValue = 'webrpc@v0.21.3;gen-typescript@v0.16.0;sessions@v0.0.1' +export const WebrpcHeaderValue = "webrpc@v0.22.1;gen-typescript@v0.16.2;sessions@v0.0.1" // WebRPC description and code-gen version -export const WebRPCVersion = 'v1' +export const WebRPCVersion = "v1" // Schema version of your RIDL schema -export const WebRPCSchemaVersion = 'v0.0.1' +export const WebRPCSchemaVersion = "v0.0.1" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = '67f782e8acfe452f905078a7423ed5d27c6639a8' +export const WebRPCSchemaHash = "48681273e3b0249c5feb593b9af1b59dc6a14869" + +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 // + export enum SignatureType { EIP712 = 'EIP712', EthSign = 'EthSign', @@ -54,10 +103,10 @@ export interface ArweaveStatus { } export interface Info { - wallets: { [key: string]: number } - configs: { [key: string]: number } + wallets: {[key: string]: number} + configs: {[key: string]: number} configTrees: number - migrations: { [key: string]: number } + migrations: {[key: string]: number} signatures: number digests: number recorder: RecorderInfo @@ -69,7 +118,7 @@ export interface RecorderInfo { buffer: number lastFlush?: string lastFlushSeconds?: number - endpoints: { [key: string]: number } + endpoints: {[key: string]: number} } export interface ArweaveInfo { @@ -131,7 +180,6 @@ export interface Signature { } export interface SignerSignature { - referenceChainID?: string signer?: string signature: string referenceChainID?: string @@ -168,29 +216,23 @@ export interface Sessions { saveConfig(args: SaveConfigArgs, headers?: object, signal?: AbortSignal): Promise saveWallet(args: SaveWalletArgs, headers?: object, signal?: AbortSignal): Promise saveSignature(args: SaveSignatureArgs, headers?: object, signal?: AbortSignal): Promise - saveSignerSignatures( - args: SaveSignerSignaturesArgs, - headers?: object, - signal?: AbortSignal - ): Promise - saveSignerSignatures2( - args: SaveSignerSignatures2Args, - headers?: object, - signal?: AbortSignal - ): Promise + saveSignerSignatures(args: SaveSignerSignaturesArgs, headers?: object, signal?: AbortSignal): Promise + saveSignerSignatures2(args: SaveSignerSignatures2Args, headers?: object, signal?: AbortSignal): Promise saveMigration(args: SaveMigrationArgs, headers?: object, signal?: AbortSignal): Promise } -export interface PingArgs {} +export interface PingArgs { +} -export interface PingReturn {} +export interface PingReturn { +} export interface ConfigArgs { imageHash: string } export interface ConfigReturn { version: number - config: any + config: any } export interface WalletsArgs { signer: string @@ -199,8 +241,8 @@ export interface WalletsArgs { } export interface WalletsReturn { - wallets: { [key: string]: Signature } - cursor: number + wallets: {[key: string]: Signature} + cursor: number } export interface DeployHashArgs { wallet: string @@ -208,7 +250,7 @@ export interface DeployHashArgs { export interface DeployHashReturn { deployHash: string - context: Context + context: Context } export interface ConfigUpdatesArgs { wallet: string @@ -217,7 +259,7 @@ export interface ConfigUpdatesArgs { } export interface ConfigUpdatesReturn { - updates: Array + updates: Array } export interface MigrationsArgs { wallet: string @@ -227,20 +269,22 @@ export interface MigrationsArgs { } export interface MigrationsReturn { - migrations: { [key: string]: { [key: number]: { [key: string]: TransactionBundle } } } + migrations: {[key: string]: {[key: number]: {[key: string]: TransactionBundle}}} } export interface SaveConfigArgs { version: number config: any } -export interface SaveConfigReturn {} +export interface SaveConfigReturn { +} export interface SaveWalletArgs { version: number deployConfig: any } -export interface SaveWalletReturn {} +export interface SaveWalletReturn { +} export interface SaveSignatureArgs { wallet: string digest: string @@ -250,7 +294,8 @@ export interface SaveSignatureArgs { referenceChainID?: string } -export interface SaveSignatureReturn {} +export interface SaveSignatureReturn { +} export interface SaveSignerSignaturesArgs { wallet: string digest: string @@ -259,7 +304,8 @@ export interface SaveSignerSignaturesArgs { toConfig?: any } -export interface SaveSignerSignaturesReturn {} +export interface SaveSignerSignaturesReturn { +} export interface SaveSignerSignatures2Args { wallet: string digest: string @@ -268,7 +314,8 @@ export interface SaveSignerSignatures2Args { toConfig?: any } -export interface SaveSignerSignatures2Return {} +export interface SaveSignerSignatures2Return { +} export interface SaveMigrationArgs { wallet: string fromVersion: number @@ -281,8 +328,11 @@ export interface SaveMigrationArgs { chainID?: string } -export interface SaveMigrationReturn {} +export interface SaveMigrationReturn { +} + + // // Client // @@ -299,187 +349,169 @@ export class Sessions implements Sessions { private url(name: string): string { return this.hostname + this.path + name } - + ping = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('Ping'), + createHTTPRequest({}, headers, signal) + ).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + config = (args: ConfigArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('Config'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return { - version: _data.version, - config: _data.config - } - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('Config'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return { + version: (_data.version), + config: (_data.config), + } + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + wallets = (args: WalletsArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('Wallets'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return { - wallets: <{ [key: string]: Signature }>_data.wallets, - cursor: _data.cursor - } - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('Wallets'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return { + wallets: <{[key: string]: Signature}>(_data.wallets), + cursor: (_data.cursor), + } + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + deployHash = (args: DeployHashArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('DeployHash'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return { - deployHash: _data.deployHash, - context: _data.context - } - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('DeployHash'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return { + deployHash: (_data.deployHash), + context: (_data.context), + } + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + configUpdates = (args: ConfigUpdatesArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('ConfigUpdates'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return { - updates: >_data.updates - } - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('ConfigUpdates'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return { + updates: >(_data.updates), + } + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + migrations = (args: MigrationsArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('Migrations'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return { - migrations: <{ [key: string]: { [key: number]: { [key: string]: TransactionBundle } } }>_data.migrations - } - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('Migrations'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return { + migrations: <{[key: string]: {[key: number]: {[key: string]: TransactionBundle}}}>(_data.migrations), + } + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + saveConfig = (args: SaveConfigArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('SaveConfig'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('SaveConfig'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + saveWallet = (args: SaveWalletArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('SaveWallet'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('SaveWallet'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + saveSignature = (args: SaveSignatureArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('SaveSignature'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) - } - - saveSignerSignatures = ( - args: SaveSignerSignaturesArgs, - headers?: object, - signal?: AbortSignal - ): Promise => { - return this.fetch(this.url('SaveSignerSignatures'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) - } - - saveSignerSignatures2 = ( - args: SaveSignerSignatures2Args, - headers?: object, - signal?: AbortSignal - ): Promise => { - return this.fetch(this.url('SaveSignerSignatures2'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('SaveSignature'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } - + + saveSignerSignatures = (args: SaveSignerSignaturesArgs, headers?: object, signal?: AbortSignal): Promise => { + return this.fetch( + this.url('SaveSignerSignatures'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) + } + + saveSignerSignatures2 = (args: SaveSignerSignatures2Args, headers?: object, signal?: AbortSignal): Promise => { + return this.fetch( + this.url('SaveSignerSignatures2'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) + } + saveMigration = (args: SaveMigrationArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch(this.url('SaveMigration'), createHTTPRequest(args, headers, signal)).then( - res => { - return buildResponse(res).then(_data => { - return {} - }) - }, - error => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - } - ) + return this.fetch( + this.url('SaveMigration'), + createHTTPRequest(args, headers, signal)).then((res) => { + return buildResponse(res).then(_data => { + return {} + }) + }, (error) => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + }) } + } -const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { - const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' } + 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 { @@ -495,18 +527,18 @@ const buildResponse = (res: Response): Promise => { let data try { data = JSON.parse(text) - } catch (error) { + } catch(error) { let message = '' - if (error instanceof Error) { + if (error instanceof Error) { message = error.message } throw WebrpcBadResponseError.new({ status: res.status, - cause: `JSON.parse(): ${message}: response text: ${text}` - }) + cause: `JSON.parse(): ${message}: response text: ${text}`}, + ) } if (!res.ok) { - const code: number = typeof data.code === 'number' ? data.code : 0 + const code: number = (typeof data.code === 'number') ? data.code : 0 throw (webrpcErrorByCode[code] || WebrpcError).new(data) } return data @@ -549,7 +581,7 @@ export class WebrpcEndpointError extends WebrpcError { constructor( name: string = 'WebrpcEndpoint', code: number = 0, - message: string = 'endpoint error', + message: string = `endpoint error`, status: number = 0, cause?: string ) { @@ -562,7 +594,7 @@ export class WebrpcRequestFailedError extends WebrpcError { constructor( name: string = 'WebrpcRequestFailed', code: number = -1, - message: string = 'request failed', + message: string = `request failed`, status: number = 0, cause?: string ) { @@ -575,7 +607,7 @@ export class WebrpcBadRouteError extends WebrpcError { constructor( name: string = 'WebrpcBadRoute', code: number = -2, - message: string = 'bad route', + message: string = `bad route`, status: number = 0, cause?: string ) { @@ -588,7 +620,7 @@ export class WebrpcBadMethodError extends WebrpcError { constructor( name: string = 'WebrpcBadMethod', code: number = -3, - message: string = 'bad method', + message: string = `bad method`, status: number = 0, cause?: string ) { @@ -601,7 +633,7 @@ export class WebrpcBadRequestError extends WebrpcError { constructor( name: string = 'WebrpcBadRequest', code: number = -4, - message: string = 'bad request', + message: string = `bad request`, status: number = 0, cause?: string ) { @@ -614,7 +646,7 @@ export class WebrpcBadResponseError extends WebrpcError { constructor( name: string = 'WebrpcBadResponse', code: number = -5, - message: string = 'bad response', + message: string = `bad response`, status: number = 0, cause?: string ) { @@ -627,7 +659,7 @@ export class WebrpcServerPanicError extends WebrpcError { constructor( name: string = 'WebrpcServerPanic', code: number = -6, - message: string = 'server panic', + message: string = `server panic`, status: number = 0, cause?: string ) { @@ -640,7 +672,7 @@ export class WebrpcInternalErrorError extends WebrpcError { constructor( name: string = 'WebrpcInternalError', code: number = -7, - message: string = 'internal error', + message: string = `internal error`, status: number = 0, cause?: string ) { @@ -653,7 +685,7 @@ export class WebrpcClientDisconnectedError extends WebrpcError { constructor( name: string = 'WebrpcClientDisconnected', code: number = -8, - message: string = 'client disconnected', + message: string = `client disconnected`, status: number = 0, cause?: string ) { @@ -666,7 +698,7 @@ export class WebrpcStreamLostError extends WebrpcError { constructor( name: string = 'WebrpcStreamLost', code: number = -9, - message: string = 'stream lost', + message: string = `stream lost`, status: number = 0, cause?: string ) { @@ -679,7 +711,7 @@ export class WebrpcStreamFinishedError extends WebrpcError { constructor( name: string = 'WebrpcStreamFinished', code: number = -10, - message: string = 'stream finished', + message: string = `stream finished`, status: number = 0, cause?: string ) { @@ -688,13 +720,14 @@ export class WebrpcStreamFinishedError extends WebrpcError { } } + // Schema errors export class InvalidArgumentError extends WebrpcError { constructor( name: string = 'InvalidArgument', code: number = 1, - message: string = 'invalid argument', + message: string = `invalid argument`, status: number = 0, cause?: string ) { @@ -704,12 +737,19 @@ export class InvalidArgumentError extends WebrpcError { } export class NotFoundError extends WebrpcError { - constructor(name: string = 'NotFound', code: number = 2, message: string = 'not found', status: number = 0, cause?: string) { + constructor( + name: string = 'NotFound', + code: number = 2, + message: string = `not found`, + status: number = 0, + cause?: string + ) { super(name, code, message, status, cause) Object.setPrototypeOf(this, NotFoundError.prototype) } } + export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', WebrpcRequestFailed = 'WebrpcRequestFailed', @@ -723,10 +763,26 @@ export enum errors { WebrpcStreamLost = 'WebrpcStreamLost', WebrpcStreamFinished = 'WebrpcStreamFinished', InvalidArgument = 'InvalidArgument', - NotFound = 'NotFound' -} - -const webrpcErrorByCode: { [code: number]: any } = { + NotFound = 'NotFound', +} + +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, + InvalidArgument = 1, + NotFound = 2, +} + +export const webrpcErrorByCode: { [code: number]: any } = { [0]: WebrpcEndpointError, [-1]: WebrpcRequestFailedError, [-2]: WebrpcBadRouteError, @@ -739,7 +795,8 @@ const webrpcErrorByCode: { [code: number]: any } = { [-9]: WebrpcStreamLostError, [-10]: WebrpcStreamFinishedError, [1]: InvalidArgumentError, - [2]: NotFoundError + [2]: NotFoundError, } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise +