This commit is contained in:
hatim boufnichel 2022-05-15 21:24:50 +02:00
parent 8bcb3a7e85
commit de2755f8ed
173 changed files with 47169 additions and 20113 deletions

View file

@ -0,0 +1,44 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
import axios from 'axios'
import * as Types from './types'
export type ResultError = { status: 'ERROR', reason: string }
export type ClientParams = {
baseUrl: string
retrieveNoAuthAuth: () => Promise<string | null>
retrieveGuestAuth: () => Promise<string | null>
retrieveAdminAuth: () => Promise<string | null>
}
export default (params: ClientParams) => ({
Health: async (): Promise<ResultError | { status: 'OK' }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.get(params.baseUrl + '/health', { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
EncryptionExchange: async (request: Types.EncryptionExchangeRequest): Promise<ResultError | { status: 'OK' }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.post(params.baseUrl + '/api/encryption/exchange', request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
LndGetInfo: async (): Promise<ResultError | { status: 'OK', result: Types.Empty }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.get(params.baseUrl + '/api/lnd/getinfo', { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const error = Types.LndGetInfoResponseValidate(data.result)
if (error === null) { return data } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
})