2406 lines
175 KiB
TypeScript
2406 lines
175 KiB
TypeScript
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
|
|
|
import express, { Response, json, urlencoded } from 'express'
|
|
import cors from 'cors'
|
|
import * as Types from './types.js'
|
|
export type Logger = { log: (v: any) => void, error: (v: any) => void }
|
|
export type ServerOptions = {
|
|
allowCors?: true
|
|
staticFiles?: string
|
|
allowNotImplementedMethods?: true
|
|
logger?: Logger
|
|
throwErrors?: true
|
|
logMethod?: true
|
|
logBody?: true
|
|
metricsCallback: (metrics: Types.RequestMetric[]) => void
|
|
AdminAuthGuard: (authorizationHeader?: string) => Promise<Types.AdminContext>
|
|
AppAuthGuard: (authorizationHeader?: string) => Promise<Types.AppContext>
|
|
GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext>
|
|
GuestWithPubAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestWithPubContext>
|
|
MetricsAuthGuard: (authorizationHeader?: string) => Promise<Types.MetricsContext>
|
|
UserAuthGuard: (authorizationHeader?: string) => Promise<Types.UserContext>
|
|
}
|
|
declare module 'express-serve-static-core' { interface Request { startTime?: bigint, bodySize?: number, startTimeMs: number } }
|
|
const logErrorAndReturnResponse = (error: Error, response: string, res: Response, logger: Logger, metric: Types.RequestMetric, metricsCallback: (metrics: Types.RequestMetric[]) => void) => {
|
|
logger.error(error.message || error); metricsCallback([{ ...metric, error: response }]); res.json({ status: 'ERROR', reason: response })
|
|
}
|
|
export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|
const logger = opts.logger || { log: console.log, error: console.error }
|
|
const app = express()
|
|
if (opts.allowCors) {
|
|
app.use(cors())
|
|
}
|
|
app.use((req, _, next) => { req.startTime = process.hrtime.bigint(); req.startTimeMs = Date.now(); next() })
|
|
app.use(json())
|
|
app.use(urlencoded({ extended: true }))
|
|
if (opts.logMethod) app.use((req, _, next) => { console.log(req.method, req.path); if (opts.logBody) console.log(req.body); next() })
|
|
if (!opts.allowNotImplementedMethods && !methods.AddApp) throw new Error('method: AddApp is not implemented')
|
|
app.post('/api/admin/app/add', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddApp', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddApp) throw new Error('method: AddApp is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddAppRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddApp({rpcName:'AddApp', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddAppInvoice) throw new Error('method: AddAppInvoice is not implemented')
|
|
app.post('/api/app/add/invoice', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddAppInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddAppInvoice) throw new Error('method: AddAppInvoice is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddAppInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddAppInvoice({rpcName:'AddAppInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddAppUser) throw new Error('method: AddAppUser is not implemented')
|
|
app.post('/api/app/user/add', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddAppUser', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddAppUser) throw new Error('method: AddAppUser is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddAppUserRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddAppUser({rpcName:'AddAppUser', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddAppUserInvoice) throw new Error('method: AddAppUserInvoice is not implemented')
|
|
app.post('/api/app/user/add/invoice', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddAppUserInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddAppUserInvoice) throw new Error('method: AddAppUserInvoice is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddAppUserInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddAppUserInvoice({rpcName:'AddAppUserInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddPeer) throw new Error('method: AddPeer is not implemented')
|
|
app.post('/api/admin/peer', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddPeer', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddPeer) throw new Error('method: AddPeer is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddPeerRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.AddPeer({rpcName:'AddPeer', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddProduct) throw new Error('method: AddProduct is not implemented')
|
|
app.post('/api/user/product/add', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddProduct', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddProduct) throw new Error('method: AddProduct is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AddProductRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddProduct({rpcName:'AddProduct', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AddUserOffer) throw new Error('method: AddUserOffer is not implemented')
|
|
app.post('/api/user/offer/add', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AddUserOffer', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AddUserOffer) throw new Error('method: AddUserOffer is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.OfferConfigValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AddUserOffer({rpcName:'AddUserOffer', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AuthApp) throw new Error('method: AuthApp is not implemented')
|
|
app.post('/api/admin/app/auth', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AuthApp', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AuthApp) throw new Error('method: AuthApp is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AuthAppRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AuthApp({rpcName:'AuthApp', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.AuthorizeManage) throw new Error('method: AuthorizeManage is not implemented')
|
|
app.post('/api/user/manage/authorize', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'AuthorizeManage', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.AuthorizeManage) throw new Error('method: AuthorizeManage is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.ManageAuthorizationRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.AuthorizeManage({rpcName:'AuthorizeManage', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.BanDebit) throw new Error('method: BanDebit is not implemented')
|
|
app.post('/api/user/debit/ban', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'BanDebit', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.BanDebit) throw new Error('method: BanDebit is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.DebitOperationValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.BanDebit({rpcName:'BanDebit', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.BanUser) throw new Error('method: BanUser is not implemented')
|
|
app.post('/api/admin/user/ban', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'BanUser', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.BanUser) throw new Error('method: BanUser is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.BanUserRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.BanUser({rpcName:'BanUser', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
app.post('/api/user/batch', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'BatchUser', batch: true, nostr: false, batchSize: 1 }
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
const requests = req.body.requests as Types.UserMethodInputs[]
|
|
if (!Array.isArray(requests))throw new Error('invalid body, is not an array')
|
|
info.batchSize = requests.length
|
|
if (requests.length > 10) throw new Error('too many requests in the batch')
|
|
const ctx = await opts.UserAuthGuard(req.headers['authorization'])
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
authCtx = ctx
|
|
const responses = []
|
|
const callsMetrics: Types.RequestMetric[] = []
|
|
for (let i = 0; i < requests.length; i++) {
|
|
const operation = requests[i]
|
|
const opInfo: Types.RequestInfo = { rpcName: operation.rpcName, batch: true, nostr: false, batchSize: 0 }
|
|
const opStats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
|
try {
|
|
switch(operation.rpcName) {
|
|
case 'AddProduct':
|
|
if (!methods.AddProduct) {
|
|
throw new Error('method AddProduct not found' )
|
|
} else {
|
|
const error = Types.AddProductRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.AddProduct({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'AddUserOffer':
|
|
if (!methods.AddUserOffer) {
|
|
throw new Error('method AddUserOffer not found' )
|
|
} else {
|
|
const error = Types.OfferConfigValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.AddUserOffer({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'AuthorizeManage':
|
|
if (!methods.AuthorizeManage) {
|
|
throw new Error('method AuthorizeManage not found' )
|
|
} else {
|
|
const error = Types.ManageAuthorizationRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.AuthorizeManage({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'BanDebit':
|
|
if (!methods.BanDebit) {
|
|
throw new Error('method BanDebit not found' )
|
|
} else {
|
|
const error = Types.DebitOperationValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.BanDebit({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'DecodeInvoice':
|
|
if (!methods.DecodeInvoice) {
|
|
throw new Error('method DecodeInvoice not found' )
|
|
} else {
|
|
const error = Types.DecodeInvoiceRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.DecodeInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'DeleteUserOffer':
|
|
if (!methods.DeleteUserOffer) {
|
|
throw new Error('method DeleteUserOffer not found' )
|
|
} else {
|
|
const error = Types.OfferIdValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.DeleteUserOffer({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'EditDebit':
|
|
if (!methods.EditDebit) {
|
|
throw new Error('method EditDebit not found' )
|
|
} else {
|
|
const error = Types.DebitAuthorizationRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.EditDebit({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'EnrollAdminToken':
|
|
if (!methods.EnrollAdminToken) {
|
|
throw new Error('method EnrollAdminToken not found' )
|
|
} else {
|
|
const error = Types.EnrollAdminTokenRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.EnrollAdminToken({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'EnrollMessagingToken':
|
|
if (!methods.EnrollMessagingToken) {
|
|
throw new Error('method EnrollMessagingToken not found' )
|
|
} else {
|
|
const error = Types.MessagingTokenValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.EnrollMessagingToken({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetDebitAuthorizations':
|
|
if (!methods.GetDebitAuthorizations) {
|
|
throw new Error('method GetDebitAuthorizations not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetDebitAuthorizations({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetHttpCreds':
|
|
if (!methods.GetHttpCreds) {
|
|
throw new Error('method GetHttpCreds not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetHttpCreds({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetLNURLChannelLink':
|
|
if (!methods.GetLNURLChannelLink) {
|
|
throw new Error('method GetLNURLChannelLink not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetLNURLChannelLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetLnurlPayLink':
|
|
if (!methods.GetLnurlPayLink) {
|
|
throw new Error('method GetLnurlPayLink not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetLnurlPayLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetLnurlWithdrawLink':
|
|
if (!methods.GetLnurlWithdrawLink) {
|
|
throw new Error('method GetLnurlWithdrawLink not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetLnurlWithdrawLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetManageAuthorizations':
|
|
if (!methods.GetManageAuthorizations) {
|
|
throw new Error('method GetManageAuthorizations not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetManageAuthorizations({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetPaymentState':
|
|
if (!methods.GetPaymentState) {
|
|
throw new Error('method GetPaymentState not found' )
|
|
} else {
|
|
const error = Types.GetPaymentStateRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.GetPaymentState({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetTransactionSwapQuotes':
|
|
if (!methods.GetTransactionSwapQuotes) {
|
|
throw new Error('method GetTransactionSwapQuotes not found' )
|
|
} else {
|
|
const error = Types.TransactionSwapRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.GetTransactionSwapQuotes({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetUserInfo':
|
|
if (!methods.GetUserInfo) {
|
|
throw new Error('method GetUserInfo not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetUserInfo({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetUserOffer':
|
|
if (!methods.GetUserOffer) {
|
|
throw new Error('method GetUserOffer not found' )
|
|
} else {
|
|
const error = Types.OfferIdValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.GetUserOffer({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetUserOfferInvoices':
|
|
if (!methods.GetUserOfferInvoices) {
|
|
throw new Error('method GetUserOfferInvoices not found' )
|
|
} else {
|
|
const error = Types.GetUserOfferInvoicesReqValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.GetUserOfferInvoices({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetUserOffers':
|
|
if (!methods.GetUserOffers) {
|
|
throw new Error('method GetUserOffers not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.GetUserOffers({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'GetUserOperations':
|
|
if (!methods.GetUserOperations) {
|
|
throw new Error('method GetUserOperations not found' )
|
|
} else {
|
|
const error = Types.GetUserOperationsRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.GetUserOperations({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'ListTxSwaps':
|
|
if (!methods.ListTxSwaps) {
|
|
throw new Error('method ListTxSwaps not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.ListTxSwaps({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'NewAddress':
|
|
if (!methods.NewAddress) {
|
|
throw new Error('method NewAddress not found' )
|
|
} else {
|
|
const error = Types.NewAddressRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.NewAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'NewInvoice':
|
|
if (!methods.NewInvoice) {
|
|
throw new Error('method NewInvoice not found' )
|
|
} else {
|
|
const error = Types.NewInvoiceRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.NewInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'NewProductInvoice':
|
|
if (!methods.NewProductInvoice) {
|
|
throw new Error('method NewProductInvoice not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.NewProductInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'PayAddress':
|
|
if (!methods.PayAddress) {
|
|
throw new Error('method PayAddress not found' )
|
|
} else {
|
|
const error = Types.PayAddressRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.PayAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'PayInvoice':
|
|
if (!methods.PayInvoice) {
|
|
throw new Error('method PayInvoice not found' )
|
|
} else {
|
|
const error = Types.PayInvoiceRequestValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.PayInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'ResetDebit':
|
|
if (!methods.ResetDebit) {
|
|
throw new Error('method ResetDebit not found' )
|
|
} else {
|
|
const error = Types.DebitOperationValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.ResetDebit({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'ResetManage':
|
|
if (!methods.ResetManage) {
|
|
throw new Error('method ResetManage not found' )
|
|
} else {
|
|
const error = Types.ManageOperationValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.ResetManage({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'RespondToDebit':
|
|
if (!methods.RespondToDebit) {
|
|
throw new Error('method RespondToDebit not found' )
|
|
} else {
|
|
const error = Types.DebitResponseValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.RespondToDebit({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'UpdateCallbackUrl':
|
|
if (!methods.UpdateCallbackUrl) {
|
|
throw new Error('method UpdateCallbackUrl not found' )
|
|
} else {
|
|
const error = Types.CallbackUrlValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
const res = await methods.UpdateCallbackUrl({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'UpdateUserOffer':
|
|
if (!methods.UpdateUserOffer) {
|
|
throw new Error('method UpdateUserOffer not found' )
|
|
} else {
|
|
const error = Types.OfferConfigValidate(operation.req)
|
|
opStats.validate = process.hrtime.bigint()
|
|
if (error !== null) throw error
|
|
await methods.UpdateUserOffer({...operation, ctx}); responses.push({ status: 'OK' })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
case 'UserHealth':
|
|
if (!methods.UserHealth) {
|
|
throw new Error('method UserHealth not found' )
|
|
} else {
|
|
opStats.validate = opStats.guard
|
|
const res = await methods.UserHealth({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
|
opStats.handle = process.hrtime.bigint()
|
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
|
}
|
|
break
|
|
default:
|
|
throw new Error('unkown rpcName')
|
|
}
|
|
} catch(ex) {const e = ex as any; logger.error(e.message || e); callsMetrics.push({ ...opInfo, ...opStats, ...ctx, error: e.message }); responses.push({ status: 'ERROR', reason: e.message || e })}
|
|
}
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({ status: 'OK', responses })
|
|
opts.metricsCallback([{ ...info, ...stats, ...ctx }, ...callsMetrics])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.BumpTx) throw new Error('method: BumpTx is not implemented')
|
|
app.post('/api/admin/tx/bump', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'BumpTx', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.BumpTx) throw new Error('method: BumpTx is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.BumpTxValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.BumpTx({rpcName:'BumpTx', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.CloseChannel) throw new Error('method: CloseChannel is not implemented')
|
|
app.post('/api/admin/channel/close', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'CloseChannel', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.CloseChannel) throw new Error('method: CloseChannel is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.CloseChannelRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.CloseChannel({rpcName:'CloseChannel', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.CreateOneTimeInviteLink) throw new Error('method: CreateOneTimeInviteLink is not implemented')
|
|
app.post('/api/admin/app/invite/create', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'CreateOneTimeInviteLink', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.CreateOneTimeInviteLink) throw new Error('method: CreateOneTimeInviteLink is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.CreateOneTimeInviteLinkRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.CreateOneTimeInviteLink({rpcName:'CreateOneTimeInviteLink', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.DecodeInvoice) throw new Error('method: DecodeInvoice is not implemented')
|
|
app.post('/api/user/invoice/decode', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'DecodeInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.DecodeInvoice) throw new Error('method: DecodeInvoice is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.DecodeInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.DecodeInvoice({rpcName:'DecodeInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.DeleteUserOffer) throw new Error('method: DeleteUserOffer is not implemented')
|
|
app.post('/api/user/offer/delete', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'DeleteUserOffer', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.DeleteUserOffer) throw new Error('method: DeleteUserOffer is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.OfferIdValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.DeleteUserOffer({rpcName:'DeleteUserOffer', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.EditDebit) throw new Error('method: EditDebit is not implemented')
|
|
app.post('/api/user/debit/edit', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'EditDebit', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.EditDebit) throw new Error('method: EditDebit is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.DebitAuthorizationRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.EditDebit({rpcName:'EditDebit', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented')
|
|
app.post('/api/encryption/exchange', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'EncryptionExchange', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.EncryptionExchangeRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.EncryptionExchange({rpcName:'EncryptionExchange', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.EnrollAdminToken) throw new Error('method: EnrollAdminToken is not implemented')
|
|
app.post('/api/guest/npub/enroll/admin', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'EnrollAdminToken', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.EnrollAdminToken) throw new Error('method: EnrollAdminToken is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.EnrollAdminTokenRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.EnrollAdminToken({rpcName:'EnrollAdminToken', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.EnrollMessagingToken) throw new Error('method: EnrollMessagingToken is not implemented')
|
|
app.post('/api/user/messaging/enroll', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'EnrollMessagingToken', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.EnrollMessagingToken) throw new Error('method: EnrollMessagingToken is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.MessagingTokenValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.EnrollMessagingToken({rpcName:'EnrollMessagingToken', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAdminInvoiceSwapQuotes) throw new Error('method: GetAdminInvoiceSwapQuotes is not implemented')
|
|
app.post('/api/admin/swap/invoice/quote', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAdminInvoiceSwapQuotes', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAdminInvoiceSwapQuotes) throw new Error('method: GetAdminInvoiceSwapQuotes is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.InvoiceSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAdminInvoiceSwapQuotes({rpcName:'GetAdminInvoiceSwapQuotes', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAdminTransactionSwapQuotes) throw new Error('method: GetAdminTransactionSwapQuotes is not implemented')
|
|
app.post('/api/admin/swap/transaction/quote', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAdminTransactionSwapQuotes', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAdminTransactionSwapQuotes) throw new Error('method: GetAdminTransactionSwapQuotes is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.TransactionSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAdminTransactionSwapQuotes({rpcName:'GetAdminTransactionSwapQuotes', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetApp) throw new Error('method: GetApp is not implemented')
|
|
app.post('/api/app/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetApp', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetApp) throw new Error('method: GetApp is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetApp({rpcName:'GetApp', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAppUser) throw new Error('method: GetAppUser is not implemented')
|
|
app.post('/api/app/user/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAppUser', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAppUser) throw new Error('method: GetAppUser is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetAppUserRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAppUser({rpcName:'GetAppUser', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented')
|
|
app.post('/api/app/user/lnurl/pay/info', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAppUserLNURLInfo', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetAppUserLNURLInfoRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAppUserLNURLInfo({rpcName:'GetAppUserLNURLInfo', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAppsMetrics) throw new Error('method: GetAppsMetrics is not implemented')
|
|
app.post('/api/reports/apps', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAppsMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAppsMetrics) throw new Error('method: GetAppsMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AppsMetricsRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAppsMetrics({rpcName:'GetAppsMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetAssetsAndLiabilities) throw new Error('method: GetAssetsAndLiabilities is not implemented')
|
|
app.post('/api/admin/assets/liabilities', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetAssetsAndLiabilities', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetAssetsAndLiabilities) throw new Error('method: GetAssetsAndLiabilities is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.AssetsAndLiabilitiesReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetAssetsAndLiabilities({rpcName:'GetAssetsAndLiabilities', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetBundleMetrics) throw new Error('method: GetBundleMetrics is not implemented')
|
|
app.post('/api/reports/bundle', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetBundleMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetBundleMetrics) throw new Error('method: GetBundleMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LatestBundleMetricReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetBundleMetrics({rpcName:'GetBundleMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetDebitAuthorizations) throw new Error('method: GetDebitAuthorizations is not implemented')
|
|
app.get('/api/user/debit/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetDebitAuthorizations', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetDebitAuthorizations) throw new Error('method: GetDebitAuthorizations is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetDebitAuthorizations({rpcName:'GetDebitAuthorizations', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetErrorStats) throw new Error('method: GetErrorStats is not implemented')
|
|
app.post('/api/reports/errors', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetErrorStats', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetErrorStats) throw new Error('method: GetErrorStats is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetErrorStats({rpcName:'GetErrorStats', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetHttpCreds) throw new Error('method: GetHttpCreds is not implemented')
|
|
app.post('/api/user/http_creds', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetHttpCreds', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetHttpCreds) throw new Error('method: GetHttpCreds is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetHttpCreds({rpcName:'GetHttpCreds', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetInviteLinkState) throw new Error('method: GetInviteLinkState is not implemented')
|
|
app.post('/api/admin/app/invite/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetInviteLinkState', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetInviteLinkState) throw new Error('method: GetInviteLinkState is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetInviteTokenStateRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetInviteLinkState({rpcName:'GetInviteLinkState', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented')
|
|
app.post('/api/user/lnurl_channel/url', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLNURLChannelLink', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLNURLChannelLink({rpcName:'GetLNURLChannelLink', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLndForwardingMetrics) throw new Error('method: GetLndForwardingMetrics is not implemented')
|
|
app.post('/api/reports/lnd/forwarding', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLndForwardingMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLndForwardingMetrics) throw new Error('method: GetLndForwardingMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LndMetricsRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLndForwardingMetrics({rpcName:'GetLndForwardingMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLndMetrics) throw new Error('method: GetLndMetrics is not implemented')
|
|
app.post('/api/reports/lnd', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLndMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLndMetrics) throw new Error('method: GetLndMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LndMetricsRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLndMetrics({rpcName:'GetLndMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayInfo) throw new Error('method: GetLnurlPayInfo is not implemented')
|
|
app.get('/api/guest/lnurl_pay/info', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLnurlPayInfo', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLnurlPayInfo) throw new Error('method: GetLnurlPayInfo is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLnurlPayInfo({rpcName:'GetLnurlPayInfo', ctx:authContext ,query: req.query})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented')
|
|
app.get('/api/user/lnurl_pay/link', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLnurlPayLink', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLnurlPayLink({rpcName:'GetLnurlPayLink', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawInfo) throw new Error('method: GetLnurlWithdrawInfo is not implemented')
|
|
app.get('/api/guest/lnurl_withdraw/info', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLnurlWithdrawInfo', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLnurlWithdrawInfo) throw new Error('method: GetLnurlWithdrawInfo is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLnurlWithdrawInfo({rpcName:'GetLnurlWithdrawInfo', ctx:authContext ,query: req.query})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented')
|
|
app.get('/api/user/lnurl_withdraw/link', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetLnurlWithdrawLink', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetLnurlWithdrawLink({rpcName:'GetLnurlWithdrawLink', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetManageAuthorizations) throw new Error('method: GetManageAuthorizations is not implemented')
|
|
app.get('/api/user/manage/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetManageAuthorizations', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetManageAuthorizations) throw new Error('method: GetManageAuthorizations is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetManageAuthorizations({rpcName:'GetManageAuthorizations', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetNPubLinkingState) throw new Error('method: GetNPubLinkingState is not implemented')
|
|
app.post('/api/app/user/npub/state', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetNPubLinkingState', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetNPubLinkingState) throw new Error('method: GetNPubLinkingState is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetNPubLinkingValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetNPubLinkingState({rpcName:'GetNPubLinkingState', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetPaymentState) throw new Error('method: GetPaymentState is not implemented')
|
|
app.post('/api/user/payment/state', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetPaymentState', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetPaymentState) throw new Error('method: GetPaymentState is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetPaymentStateRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetPaymentState({rpcName:'GetPaymentState', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetProvidersDisruption) throw new Error('method: GetProvidersDisruption is not implemented')
|
|
app.post('/api/metrics/providers/disruption', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetProvidersDisruption', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetProvidersDisruption) throw new Error('method: GetProvidersDisruption is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetProvidersDisruption({rpcName:'GetProvidersDisruption', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetSeed) throw new Error('method: GetSeed is not implemented')
|
|
app.get('/api/admin/seed', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetSeed', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetSeed) throw new Error('method: GetSeed is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetSeed({rpcName:'GetSeed', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetSingleBundleMetrics) throw new Error('method: GetSingleBundleMetrics is not implemented')
|
|
app.post('/api/reports/bundle/single', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetSingleBundleMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetSingleBundleMetrics) throw new Error('method: GetSingleBundleMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SingleMetricReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetSingleBundleMetrics({rpcName:'GetSingleBundleMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetSingleUsageMetrics) throw new Error('method: GetSingleUsageMetrics is not implemented')
|
|
app.post('/api/reports/usage/single', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetSingleUsageMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetSingleUsageMetrics) throw new Error('method: GetSingleUsageMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SingleMetricReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetSingleUsageMetrics({rpcName:'GetSingleUsageMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetTransactionSwapQuotes) throw new Error('method: GetTransactionSwapQuotes is not implemented')
|
|
app.post('/api/user/swap/transaction/quote', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetTransactionSwapQuotes', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetTransactionSwapQuotes) throw new Error('method: GetTransactionSwapQuotes is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.TransactionSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetTransactionSwapQuotes({rpcName:'GetTransactionSwapQuotes', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUsageMetrics) throw new Error('method: GetUsageMetrics is not implemented')
|
|
app.post('/api/reports/usage', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUsageMetrics', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUsageMetrics) throw new Error('method: GetUsageMetrics is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LatestUsageMetricReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUsageMetrics({rpcName:'GetUsageMetrics', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented')
|
|
app.post('/api/user/info', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUserInfo', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUserInfo({rpcName:'GetUserInfo', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUserOffer) throw new Error('method: GetUserOffer is not implemented')
|
|
app.post('/api/user/offer/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUserOffer', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUserOffer) throw new Error('method: GetUserOffer is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.OfferIdValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUserOffer({rpcName:'GetUserOffer', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUserOfferInvoices) throw new Error('method: GetUserOfferInvoices is not implemented')
|
|
app.post('/api/user/offer/get/invoices', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUserOfferInvoices', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUserOfferInvoices) throw new Error('method: GetUserOfferInvoices is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetUserOfferInvoicesReqValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUserOfferInvoices({rpcName:'GetUserOfferInvoices', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUserOffers) throw new Error('method: GetUserOffers is not implemented')
|
|
app.get('/api/user/offers/get', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUserOffers', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUserOffers) throw new Error('method: GetUserOffers is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUserOffers({rpcName:'GetUserOffers', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.GetUserOperations) throw new Error('method: GetUserOperations is not implemented')
|
|
app.post('/api/user/operations', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'GetUserOperations', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.GetUserOperations) throw new Error('method: GetUserOperations is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.GetUserOperationsRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.GetUserOperations({rpcName:'GetUserOperations', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlAddress) throw new Error('method: HandleLnurlAddress is not implemented')
|
|
app.get('/.well-known/lnurlp/:address_name', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'HandleLnurlAddress', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.HandleLnurlAddress) throw new Error('method: HandleLnurlAddress is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.HandleLnurlAddress({rpcName:'HandleLnurlAddress', ctx:authContext ,params: req.params})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlPay) throw new Error('method: HandleLnurlPay is not implemented')
|
|
app.get('/api/guest/lnurl_pay/handle', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'HandleLnurlPay', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.HandleLnurlPay) throw new Error('method: HandleLnurlPay is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.HandleLnurlPay({rpcName:'HandleLnurlPay', ctx:authContext ,query: req.query})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlWithdraw) throw new Error('method: HandleLnurlWithdraw is not implemented')
|
|
app.get('/api/guest/lnurl_withdraw/handle', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'HandleLnurlWithdraw', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.HandleLnurlWithdraw) throw new Error('method: HandleLnurlWithdraw is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.HandleLnurlWithdraw({rpcName:'HandleLnurlWithdraw', ctx:authContext ,query: req.query})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.Health) throw new Error('method: Health is not implemented')
|
|
app.get('/api/health', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'Health', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.Health) throw new Error('method: Health is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.Health({rpcName:'Health', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.LinkNPubThroughToken) throw new Error('method: LinkNPubThroughToken is not implemented')
|
|
app.post('/api/guest/npub/link', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'LinkNPubThroughToken', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.LinkNPubThroughToken) throw new Error('method: LinkNPubThroughToken is not implemented')
|
|
const authContext = await opts.GuestWithPubAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LinkNPubThroughTokenRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.LinkNPubThroughToken({rpcName:'LinkNPubThroughToken', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ListAdminInvoiceSwaps) throw new Error('method: ListAdminInvoiceSwaps is not implemented')
|
|
app.post('/api/admin/swap/invoice/list', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ListAdminInvoiceSwaps', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ListAdminInvoiceSwaps) throw new Error('method: ListAdminInvoiceSwaps is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ListAdminInvoiceSwaps({rpcName:'ListAdminInvoiceSwaps', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ListAdminTxSwaps) throw new Error('method: ListAdminTxSwaps is not implemented')
|
|
app.post('/api/admin/swap/transaction/list', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ListAdminTxSwaps', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ListAdminTxSwaps) throw new Error('method: ListAdminTxSwaps is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ListAdminTxSwaps({rpcName:'ListAdminTxSwaps', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ListChannels) throw new Error('method: ListChannels is not implemented')
|
|
app.get('/api/admin/channels', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ListChannels', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ListChannels) throw new Error('method: ListChannels is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ListChannels({rpcName:'ListChannels', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ListTxSwaps) throw new Error('method: ListTxSwaps is not implemented')
|
|
app.post('/api/user/swap/transaction/list', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ListTxSwaps', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ListTxSwaps) throw new Error('method: ListTxSwaps is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ListTxSwaps({rpcName:'ListTxSwaps', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented')
|
|
app.post('/api/admin/lnd/getinfo', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'LndGetInfo', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.LndGetInfoRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.LndGetInfo({rpcName:'LndGetInfo', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.NewAddress) throw new Error('method: NewAddress is not implemented')
|
|
app.post('/api/user/chain/new', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'NewAddress', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.NewAddress) throw new Error('method: NewAddress is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.NewAddressRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.NewAddress({rpcName:'NewAddress', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.NewInvoice) throw new Error('method: NewInvoice is not implemented')
|
|
app.post('/api/user/invoice/new', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'NewInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.NewInvoice) throw new Error('method: NewInvoice is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.NewInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.NewInvoice({rpcName:'NewInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented')
|
|
app.get('/api/user/product/get/invoice', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'NewProductInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.NewProductInvoice({rpcName:'NewProductInvoice', ctx:authContext ,query: req.query})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
|
app.post('/api/admin/channel/open', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'OpenChannel', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.OpenChannelRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.OpenChannel({rpcName:'OpenChannel', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PayAddress) throw new Error('method: PayAddress is not implemented')
|
|
app.post('/api/user/chain/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PayAddress', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PayAddress) throw new Error('method: PayAddress is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.PayAddressRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.PayAddress({rpcName:'PayAddress', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PayAdminInvoiceSwap) throw new Error('method: PayAdminInvoiceSwap is not implemented')
|
|
app.post('/api/admin/swap/invoice/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PayAdminInvoiceSwap', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PayAdminInvoiceSwap) throw new Error('method: PayAdminInvoiceSwap is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.PayAdminInvoiceSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.PayAdminInvoiceSwap({rpcName:'PayAdminInvoiceSwap', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PayAdminTransactionSwap) throw new Error('method: PayAdminTransactionSwap is not implemented')
|
|
app.post('/api/admin/swap/transaction/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PayAdminTransactionSwap', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PayAdminTransactionSwap) throw new Error('method: PayAdminTransactionSwap is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.PayAdminTransactionSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.PayAdminTransactionSwap({rpcName:'PayAdminTransactionSwap', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PayAppUserInvoice) throw new Error('method: PayAppUserInvoice is not implemented')
|
|
app.post('/api/app/invoice/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PayAppUserInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PayAppUserInvoice) throw new Error('method: PayAppUserInvoice is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.PayAppUserInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.PayAppUserInvoice({rpcName:'PayAppUserInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
|
|
app.post('/api/user/invoice/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PayInvoice', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.PayInvoiceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.PayInvoice({rpcName:'PayInvoice', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.PingSubProcesses) throw new Error('method: PingSubProcesses is not implemented')
|
|
app.post('/api/metrics/ping', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'PingSubProcesses', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.PingSubProcesses) throw new Error('method: PingSubProcesses is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.PingSubProcesses({rpcName:'PingSubProcesses', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.RefundAdminInvoiceSwap) throw new Error('method: RefundAdminInvoiceSwap is not implemented')
|
|
app.post('/api/admin/swap/invoice/refund', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'RefundAdminInvoiceSwap', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.RefundAdminInvoiceSwap) throw new Error('method: RefundAdminInvoiceSwap is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.RefundAdminInvoiceSwapRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.RefundAdminInvoiceSwap({rpcName:'RefundAdminInvoiceSwap', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.RequestNPubLinkingToken) throw new Error('method: RequestNPubLinkingToken is not implemented')
|
|
app.post('/api/app/user/npub/token', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'RequestNPubLinkingToken', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.RequestNPubLinkingToken) throw new Error('method: RequestNPubLinkingToken is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.RequestNPubLinkingTokenRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.RequestNPubLinkingToken({rpcName:'RequestNPubLinkingToken', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ResetDebit) throw new Error('method: ResetDebit is not implemented')
|
|
app.post('/api/user/debit/reset', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ResetDebit', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ResetDebit) throw new Error('method: ResetDebit is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.DebitOperationValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.ResetDebit({rpcName:'ResetDebit', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ResetManage) throw new Error('method: ResetManage is not implemented')
|
|
app.post('/api/user/manage/reset', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ResetManage', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ResetManage) throw new Error('method: ResetManage is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.ManageOperationValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.ResetManage({rpcName:'ResetManage', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented')
|
|
app.post('/api/metrics/reset', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ResetMetricsStorages', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.ResetMetricsStorages({rpcName:'ResetMetricsStorages', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ResetNPubLinkingToken) throw new Error('method: ResetNPubLinkingToken is not implemented')
|
|
app.post('/api/app/user/npub/token/reset', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ResetNPubLinkingToken', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ResetNPubLinkingToken) throw new Error('method: ResetNPubLinkingToken is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.RequestNPubLinkingTokenRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ResetNPubLinkingToken({rpcName:'ResetNPubLinkingToken', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.RespondToDebit) throw new Error('method: RespondToDebit is not implemented')
|
|
app.post('/api/user/debit/finish', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'RespondToDebit', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.RespondToDebit) throw new Error('method: RespondToDebit is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.DebitResponseValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.RespondToDebit({rpcName:'RespondToDebit', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppPayment) throw new Error('method: SendAppUserToAppPayment is not implemented')
|
|
app.post('/api/app/internal/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SendAppUserToAppPayment', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SendAppUserToAppPayment) throw new Error('method: SendAppUserToAppPayment is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SendAppUserToAppPaymentRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.SendAppUserToAppPayment({rpcName:'SendAppUserToAppPayment', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppUserPayment) throw new Error('method: SendAppUserToAppUserPayment is not implemented')
|
|
app.post('/api/app/user/internal/pay', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SendAppUserToAppUserPayment', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SendAppUserToAppUserPayment) throw new Error('method: SendAppUserToAppUserPayment is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SendAppUserToAppUserPaymentRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.SendAppUserToAppUserPayment({rpcName:'SendAppUserToAppUserPayment', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SetMockAppBalance) throw new Error('method: SetMockAppBalance is not implemented')
|
|
app.post('/api/app/mock/blance/set', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SetMockAppBalance', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SetMockAppBalance) throw new Error('method: SetMockAppBalance is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SetMockAppBalanceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.SetMockAppBalance({rpcName:'SetMockAppBalance', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SetMockAppUserBalance) throw new Error('method: SetMockAppUserBalance is not implemented')
|
|
app.post('/api/app/mock/user/blance/set', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SetMockAppUserBalance', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SetMockAppUserBalance) throw new Error('method: SetMockAppUserBalance is not implemented')
|
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SetMockAppUserBalanceRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.SetMockAppUserBalance({rpcName:'SetMockAppUserBalance', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SetMockInvoiceAsPaid) throw new Error('method: SetMockInvoiceAsPaid is not implemented')
|
|
app.post('/api/lnd/mock/invoice/paid', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SetMockInvoiceAsPaid', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SetMockInvoiceAsPaid) throw new Error('method: SetMockInvoiceAsPaid is not implemented')
|
|
const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.SetMockInvoiceAsPaidRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.SetMockInvoiceAsPaid({rpcName:'SetMockInvoiceAsPaid', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.SubmitWebRtcMessage) throw new Error('method: SubmitWebRtcMessage is not implemented')
|
|
app.post('/api/upgrade/wrtc', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'SubmitWebRtcMessage', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.SubmitWebRtcMessage) throw new Error('method: SubmitWebRtcMessage is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.WebRtcMessageValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.SubmitWebRtcMessage({rpcName:'SubmitWebRtcMessage', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.UpdateCallbackUrl) throw new Error('method: UpdateCallbackUrl is not implemented')
|
|
app.post('/api/user/cb/update', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'UpdateCallbackUrl', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.UpdateCallbackUrl) throw new Error('method: UpdateCallbackUrl is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.CallbackUrlValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.UpdateCallbackUrl({rpcName:'UpdateCallbackUrl', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented')
|
|
app.post('/api/admin/channel/policy/update', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'UpdateChannelPolicy', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented')
|
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.UpdateChannelPolicyRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.UpdateChannelPolicy({rpcName:'UpdateChannelPolicy', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.UpdateUserOffer) throw new Error('method: UpdateUserOffer is not implemented')
|
|
app.post('/api/user/offer/update', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'UpdateUserOffer', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.UpdateUserOffer) throw new Error('method: UpdateUserOffer is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.OfferConfigValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.UpdateUserOffer({rpcName:'UpdateUserOffer', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
|
app.post('/api/guest/invite', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'UseInviteLink', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
|
const authContext = await opts.GuestWithPubAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
const request = req.body
|
|
const error = Types.UseInviteLinkRequestValidate(request)
|
|
stats.validate = process.hrtime.bigint()
|
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
|
const query = req.query
|
|
const params = req.params
|
|
await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request})
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK'})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.UserHealth) throw new Error('method: UserHealth is not implemented')
|
|
app.post('/api/user/health', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'UserHealth', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.UserHealth) throw new Error('method: UserHealth is not implemented')
|
|
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.UserHealth({rpcName:'UserHealth', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (!opts.allowNotImplementedMethods && !methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented')
|
|
app.post('/api/metrics/zip', async (req, res) => {
|
|
const info: Types.RequestInfo = { rpcName: 'ZipMetricsStorages', batch: false, nostr: false, batchSize: 0}
|
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
|
let authCtx: Types.AuthContext = {}
|
|
try {
|
|
if (!methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented')
|
|
const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
|
|
authCtx = authContext
|
|
stats.guard = process.hrtime.bigint()
|
|
stats.validate = stats.guard
|
|
const query = req.query
|
|
const params = req.params
|
|
const response = await methods.ZipMetricsStorages({rpcName:'ZipMetricsStorages', ctx:authContext })
|
|
stats.handle = process.hrtime.bigint()
|
|
res.json({status: 'OK', ...response})
|
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
|
})
|
|
if (opts.staticFiles) {
|
|
app.use(express.static(opts.staticFiles))
|
|
app.get('*', function (_, res) { res.sendFile('index.html', { root: opts.staticFiles })})
|
|
}
|
|
var server: { close: () => void } | undefined
|
|
return {
|
|
Close: () => { if (!server) { throw new Error('tried closing server before starting') } else server.close() },
|
|
Listen: (port: number) => { server = app.listen(port, () => logger.log('LightningPub listening on port ' + port)) }
|
|
}
|
|
}
|