Skip to content

Commit

Permalink
Merge pull request #356 from shocknet/offers-ui
Browse files Browse the repository at this point in the history
offers ui
  • Loading branch information
shocknet-justin authored Jan 11, 2025
2 parents be92bb9 + 83895e2 commit ee4f105
Show file tree
Hide file tree
Showing 12 changed files with 1,476 additions and 83 deletions.
1 change: 1 addition & 0 deletions src/Api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const getHttpClient = (url: string, { adminToken, metricsToken }: { admin
const c = NewHttpClient({
baseUrl: url,
retrieveGuestAuth: async () => { return "" },
retrieveGuestWithPubAuth: async () => { return "" },
retrieveMetricsAuth: async () => { return metricsToken || "" },
retrieveAdminAuth: async () => { return adminToken || "" },
retrieveAppAuth: async () => { throw new Error("application routes not enabled") },
Expand Down
101 changes: 98 additions & 3 deletions src/Api/pub/autogenerated/ts/http_client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
import axios from 'axios'
import * as Types from './types'
import * as Types from './types.js'
export type ResultError = { status: 'ERROR', reason: string }

export type ClientParams = {
Expand Down Expand Up @@ -98,6 +98,20 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
AddUserOffer: async (request: Types.OfferConfig): Promise<ResultError | ({ status: 'OK' } & Types.OfferId)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offer/add'
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferIdValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
AuthApp: async (request: Types.AuthAppRequest): Promise<ResultError | ({ status: 'OK' } & Types.AuthApp)> => {
const auth = await params.retrieveAdminAuth()
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
Expand Down Expand Up @@ -204,6 +218,17 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
DeleteUserOffer: async (request: Types.OfferId): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offer/delete'
const { data } = await axios.post(params.baseUrl + finalRoute, 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' }
},
EditDebit: async (request: Types.DebitAuthorizationRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
Expand Down Expand Up @@ -307,6 +332,20 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetErrorStats: async (): Promise<ResultError | ({ status: 'OK' } & Types.ErrorStats)> => {
const auth = await params.retrieveMetricsAuth()
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
let finalRoute = '/api/reports/errors'
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.ErrorStatsValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetHttpCreds: async (cb: (v: ResultError | ({ status: 'OK' } & Types.HttpCreds)) => void): Promise<void> => { throw new Error('http streams are not supported') },
GetInviteLinkState: async (request: Types.GetInviteTokenStateRequest): Promise<ResultError | ({ status: 'OK' } & Types.GetInviteTokenStateResponse)> => {
const auth = await params.retrieveAdminAuth()
Expand Down Expand Up @@ -483,6 +522,48 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOffer: async (request: Types.OfferId): Promise<ResultError | ({ status: 'OK' } & Types.OfferConfig)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offer/get'
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferConfigValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOfferInvoices: async (request: Types.GetUserOfferInvoicesReq): Promise<ResultError | ({ status: 'OK' } & Types.OfferInvoices)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offer/get/invoices'
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferInvoicesValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOffers: async (): Promise<ResultError | ({ status: 'OK' } & Types.UserOffers)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offers/get'
const { data } = await axios.get(params.baseUrl + finalRoute, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.UserOffersValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise<ResultError | ({ status: 'OK' } & Types.GetUserOperationsResponse)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
Expand Down Expand Up @@ -821,6 +902,17 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
UpdateUserOffer: async (request: Types.OfferConfig): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/offer/update'
const { data } = await axios.post(params.baseUrl + finalRoute, 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' }
},
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveGuestWithPubAuth()
if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null')
Expand All @@ -832,14 +924,17 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
UserHealth: async (): Promise<ResultError | ({ status: 'OK' } & Types.UserHealthState)> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/health'
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.UserHealthStateValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
Expand Down
108 changes: 104 additions & 4 deletions src/Api/pub/autogenerated/ts/nostr_client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
import { NostrRequest } from './nostr_transport'
import * as Types from './types'
import { NostrRequest } from './nostr_transport.js'
import * as Types from './types.js'
export type ResultError = { status: 'ERROR', reason: string }

export type NostrClientParams = {
Expand Down Expand Up @@ -54,6 +54,21 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
AddUserOffer: async (request: Types.OfferConfig): Promise<ResultError | ({ status: 'OK' } & Types.OfferId)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
const data = await send(params.pubDestination, { rpcName: 'AddUserOffer', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferIdValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
AuthApp: async (request: Types.AuthAppRequest): Promise<ResultError | ({ status: 'OK' } & Types.AuthApp)> => {
const auth = await params.retrieveNostrAdminAuth()
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
Expand Down Expand Up @@ -167,6 +182,18 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
DeleteUserOffer: async (request: Types.OfferId): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
const data = await send(params.pubDestination, { rpcName: 'DeleteUserOffer', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
EditDebit: async (request: Types.DebitAuthorizationRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
Expand Down Expand Up @@ -220,6 +247,20 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetErrorStats: async (): Promise<ResultError | ({ status: 'OK' } & Types.ErrorStats)> => {
const auth = await params.retrieveNostrMetricsAuth()
if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')
const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, { rpcName: 'GetErrorStats', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.ErrorStatsValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetHttpCreds: async (cb: (res: ResultError | ({ status: 'OK' } & Types.HttpCreds)) => void): Promise<void> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
Expand Down Expand Up @@ -409,6 +450,50 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOffer: async (request: Types.OfferId): Promise<ResultError | ({ status: 'OK' } & Types.OfferConfig)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
const data = await send(params.pubDestination, { rpcName: 'GetUserOffer', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferConfigValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOfferInvoices: async (request: Types.GetUserOfferInvoicesReq): Promise<ResultError | ({ status: 'OK' } & Types.OfferInvoices)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
const data = await send(params.pubDestination, { rpcName: 'GetUserOfferInvoices', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.OfferInvoicesValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOffers: async (): Promise<ResultError | ({ status: 'OK' } & Types.UserOffers)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, { rpcName: 'GetUserOffers', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.UserOffersValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise<ResultError | ({ status: 'OK' } & Types.GetUserOperationsResponse)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
Expand Down Expand Up @@ -606,6 +691,18 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
UpdateUserOffer: async (request: Types.OfferConfig): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
const data = await send(params.pubDestination, { rpcName: 'UpdateUserOffer', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrGuestWithPubAuth()
if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null')
Expand All @@ -618,14 +715,17 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
UserHealth: async (): Promise<ResultError | ({ status: 'OK' } & Types.UserHealthState)> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, { rpcName: 'UserHealth', authIdentifier: auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
const result = data
if (!params.checkResult) return { status: 'OK', ...result }
const error = Types.UserHealthStateValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
Expand Down
Loading

0 comments on commit ee4f105

Please sign in to comment.