nostr health

This commit is contained in:
boufni95 2024-01-15 19:49:29 +01:00
parent d1126940c3
commit b579974013
9 changed files with 3357 additions and 3229 deletions

View file

@ -13,6 +13,11 @@ The nostr server will send back a message response, and inside the body there wi
## NOSTR Methods ## NOSTR Methods
### These are the nostr methods the client implements to communicate with the API via nostr ### These are the nostr methods the client implements to communicate with the API via nostr
- UserHealth
- auth type: __User__
- This methods has an __empty__ __request__ body
- This methods has an __empty__ __response__ body
- GetUserInfo - GetUserInfo
- auth type: __User__ - auth type: __User__
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
@ -105,9 +110,9 @@ The nostr server will send back a message response, and inside the body there wi
- __User__: - __User__:
- expected context content - expected context content
- __app_user_id__: _string_
- __user_id__: _string_ - __user_id__: _string_
- __app_id__: _string_ - __app_id__: _string_
- __app_user_id__: _string_
- __Admin__: - __Admin__:
- expected context content - expected context content
@ -313,6 +318,13 @@ The nostr server will send back a message response, and inside the body there wi
- input: [SetMockAppBalanceRequest](#SetMockAppBalanceRequest) - input: [SetMockAppBalanceRequest](#SetMockAppBalanceRequest)
- This methods has an __empty__ __response__ body - This methods has an __empty__ __response__ body
- UserHealth
- auth type: __User__
- http method: __post__
- http route: __/api/user/health__
- This methods has an __empty__ __request__ body
- This methods has an __empty__ __response__ body
- GetUserInfo - GetUserInfo
- auth type: __User__ - auth type: __User__
- http method: __post__ - http method: __post__
@ -432,130 +444,29 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_
### OpenChannelResponse
- __channelId__: _string_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### GetAppUserRequest
- __user_identifier__: _string_
### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### Application ### Application
- __name__: _string_ - __name__: _string_
- __id__: _string_ - __id__: _string_
- __balance__: _number_ - __balance__: _number_
- __npub__: _string_ - __npub__: _string_
### AddAppUserInvoiceRequest ### NewAddressResponse
- __receiver_identifier__: _string_ - __address__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### PayInvoiceRequest ### LiveUserOperation
- __invoice__: _string_ - __operation__: _[UserOperation](#UserOperation)_
- __amount__: _number_
### OpenChannelRequest ### UsageMetrics
- __destination__: _string_ - __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### SetMockAppUserBalanceRequest ### SetMockAppUserBalanceRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### Empty ### ClosedChannel
- __channel_id__: _string_
### ChainBalanceEvent - __capacity__: _number_
- __block_height__: _number_ - __closed_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### NewAddressResponse
- __address__: _string_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### DecodeInvoiceRequest
- __invoice__: _string_
### RoutingEvent ### RoutingEvent
- __incoming_channel_id__: _number_ - __incoming_channel_id__: _number_
@ -571,21 +482,11 @@ The nostr server will send back a message response, and inside the body there wi
- __offchain__: _boolean_ - __offchain__: _boolean_
- __forward_fail_event__: _boolean_ - __forward_fail_event__: _boolean_
### LndNodeMetrics ### LndGetInfoResponse
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_ - __alias__: _string_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
### SendAppUserToAppUserPaymentRequest ### GetAppUserRequest
- __from_user_identifier__: _string_ - __user_identifier__: _string_
- __to_user_identifier__: _string_
- __amount__: _number_
### LnurlWithdrawInfoResponse ### LnurlWithdrawInfoResponse
- __tag__: _string_ - __tag__: _string_
@ -597,53 +498,176 @@ The nostr server will send back a message response, and inside the body there wi
- __balanceCheck__: _string_ - __balanceCheck__: _string_
- __payLink__: _string_ - __payLink__: _string_
### Empty
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### OpenChannelResponse
- __channelId__: _string_
### AddProductRequest ### AddProductRequest
- __name__: _string_ - __name__: _string_
- __price_sats__: _number_ - __price_sats__: _number_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### PayInvoiceRequest
- __invoice__: _string_
- __amount__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### SetMockAppBalanceRequest
- __amount__: _number_
### NewInvoiceResponse ### NewInvoiceResponse
- __invoice__: _string_ - __invoice__: _string_
### LndMetrics ### DecodeInvoiceResponse
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_ - __amount__: _number_
### AuthApp ### SetMockInvoiceAsPaidRequest
- __app__: _[Application](#Application)_ - __invoice__: _string_
- __auth_token__: _string_ - __amount__: _number_
### AddAppInvoiceRequest ### LndMetricsRequest
- __payer_identifier__: _string_ - __from_unix__: _number_ *this field is optional
- __http_callback_url__: _string_ - __to_unix__: _number_ *this field is optional
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### UsageMetric
- __processed_at_ms__: _number_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### RelaysMigration
- __relays__: ARRAY of: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AppsMetricsRequest ### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional - __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional - __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional - __include_operations__: _boolean_ *this field is optional
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### OpenChannelRequest
- __destination__: _string_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### AddAppRequest ### AddAppRequest
- __name__: _string_ - __name__: _string_
- __allow_user_creation__: _boolean_ - __allow_user_creation__: _boolean_
### SetMockAppBalanceRequest ### LndNodeMetrics
- __amount__: _number_ - __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### DecodeInvoiceRequest
- __invoice__: _string_
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### LnurlPayInfoResponse ### LnurlPayInfoResponse
- __tag__: _string_ - __tag__: _string_
@ -665,10 +689,24 @@ The nostr server will send back a message response, and inside the body there wi
- __network_fee__: _number_ - __network_fee__: _number_
- __confirmed__: _boolean_ - __confirmed__: _boolean_
### Product ### UserOperations
- __id__: _string_ - __fromIndex__: _number_
- __name__: _string_ - __toIndex__: _number_
- __price_sats__: _number_ - __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### GetProductBuyLinkResponse
- __link__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### UsersInfo ### UsersInfo
- __total__: _number_ - __total__: _number_
@ -678,41 +716,6 @@ The nostr server will send back a message response, and inside the body there wi
- __balance_avg__: _number_ - __balance_avg__: _number_
- __balance_median__: _number_ - __balance_median__: _number_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AppMetrics ### AppMetrics
- __app__: _[Application](#Application)_ - __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_ - __users__: _[UsersInfo](#UsersInfo)_
@ -722,33 +725,42 @@ The nostr server will send back a message response, and inside the body there wi
- __unpaid_invoices__: _number_ - __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_ - __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### DecodeInvoiceResponse ### LndMetrics
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SendAppUserToAppUserPaymentRequest
- __from_user_identifier__: _string_
- __to_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### GetUserOperationsRequest ### UserInfo
- __latestIncomingInvoice__: _number_ - __userId__: _string_
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
### LndGetInfoResponse
- __alias__: _string_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_ - __balance__: _number_
- __max_withdrawable__: _number_
### PayAddressRequest ### RelaysMigration
- __address__: _string_ - __relays__: ARRAY of: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### NewInvoiceRequest ### UsageMetric
- __amountSats__: _number_ - __processed_at_ms__: _number_
- __memo__: _string_ - __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
## Enums ## Enums
### The enumerators used in the messages ### The enumerators used in the messages

File diff suppressed because it is too large Load diff

View file

@ -559,6 +559,25 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
opts.metricsCallback([{ ...info, ...stats, ...authContext }]) 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 } } 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
await methods.UserHealth({rpcName:'UserHealth', 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.GetUserInfo) throw new Error('method: GetUserInfo is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented')
app.post('/api/user/info', async (req, res) => { app.post('/api/user/info', async (req, res) => {
const info: Types.RequestInfo = { rpcName: 'GetUserInfo', batch: false, nostr: false, batchSize: 0} const info: Types.RequestInfo = { rpcName: 'GetUserInfo', batch: false, nostr: false, batchSize: 0}
@ -851,6 +870,16 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const opStats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n } const opStats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
try { try {
switch(operation.rpcName) { switch(operation.rpcName) {
case 'UserHealth':
if (!methods.UserHealth) {
throw new Error('method UserHealth not found' )
} else {
opStats.validate = opStats.guard
await methods.UserHealth({...operation, ctx}); responses.push({ status: 'OK' })
opStats.handle = process.hrtime.bigint()
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
}
break
case 'GetUserInfo': case 'GetUserInfo':
if (!methods.GetUserInfo) { if (!methods.GetUserInfo) {
throw new Error('method GetUserInfo not found' ) throw new Error('method GetUserInfo not found' )

View file

@ -351,6 +351,17 @@ export default (params: ClientParams) => ({
} }
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/health'
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserInfo: async (): Promise<ResultError | ({ status: 'OK' }& Types.UserInfo)> => { GetUserInfo: async (): Promise<ResultError | ({ status: 'OK' }& Types.UserInfo)> => {
const auth = await params.retrieveUserAuth() const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null') if (auth === null) throw new Error('retrieveUserAuth() returned null')

View file

@ -9,6 +9,17 @@ export type NostrClientParams = {
checkResult?: true checkResult?: true
} }
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({ export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, {rpcName:'UserHealth',authIdentifier:auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
GetUserInfo: async (): Promise<ResultError | ({ status: 'OK' }& Types.UserInfo)> => { GetUserInfo: async (): Promise<ResultError | ({ status: 'OK' }& Types.UserInfo)> => {
const auth = await params.retrieveNostrUserAuth() const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')

View file

@ -29,6 +29,19 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const stats: Types.RequestStats = { startMs, start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n } const stats: Types.RequestStats = { startMs, start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
let authCtx: Types.AuthContext = {} let authCtx: Types.AuthContext = {}
switch (req.rpcName) { switch (req.rpcName) {
case 'UserHealth':
try {
if (!methods.UserHealth) throw new Error('method: UserHealth is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
stats.guard = process.hrtime.bigint()
authCtx = authContext
stats.validate = stats.guard
await methods.UserHealth({rpcName:'UserHealth', ctx:authContext })
stats.handle = process.hrtime.bigint()
res({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 }
break
case 'GetUserInfo': case 'GetUserInfo':
try { try {
if (!methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented') if (!methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented')
@ -267,6 +280,16 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const opStats: Types.RequestStats = { startMs, start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n } const opStats: Types.RequestStats = { startMs, start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
try { try {
switch(operation.rpcName) { switch(operation.rpcName) {
case 'UserHealth':
if (!methods.UserHealth) {
throw new Error('method not defined: UserHealth')
} else {
opStats.validate = opStats.guard
await methods.UserHealth({...operation, ctx}); responses.push({ status: 'OK' })
opStats.handle = process.hrtime.bigint()
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
}
break
case 'GetUserInfo': case 'GetUserInfo':
if (!methods.GetUserInfo) { if (!methods.GetUserInfo) {
throw new Error('method not defined: GetUserInfo') throw new Error('method not defined: GetUserInfo')

File diff suppressed because it is too large Load diff

View file

@ -240,6 +240,12 @@ service LightningPub {
// </App> // </App>
// <User> // <User>
rpc UserHealth(structs.Empty)returns(structs.Empty){
option (auth_type) = "User";
option (http_method) = "post";
option (http_route) = "/api/user/health";
option (nostr) = true;
}
rpc GetUserInfo(structs.Empty)returns(structs.UserInfo){ rpc GetUserInfo(structs.Empty)returns(structs.UserInfo){
option (auth_type) = "User"; option (auth_type) = "User";
option (http_method) = "post"; option (http_method) = "post";

View file

@ -26,6 +26,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
await mainHandler.paymentManager.SetMockInvoiceAsPaid(req) await mainHandler.paymentManager.SetMockInvoiceAsPaid(req)
}, },
UserHealth: async () => { },
GetUserInfo: ({ ctx }) => mainHandler.appUserManager.GetUserInfo(ctx), GetUserInfo: ({ ctx }) => mainHandler.appUserManager.GetUserInfo(ctx),
GetUserOperations: async ({ ctx, req }) => { GetUserOperations: async ({ ctx, req }) => {
return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req) return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req)