up
This commit is contained in:
parent
1bcdd7860f
commit
b41a867f53
6 changed files with 2588 additions and 2593 deletions
|
|
@ -414,153 +414,21 @@ 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
|
||||||
|
|
||||||
### LnurlLinkResponse
|
|
||||||
- __lnurl__: _string_
|
|
||||||
- __k1__: _string_
|
|
||||||
|
|
||||||
### RelaysMigration
|
|
||||||
- __relays__: ARRAY of: _string_
|
|
||||||
|
|
||||||
### LndGetInfoResponse
|
### LndGetInfoResponse
|
||||||
- __alias__: _string_
|
- __alias__: _string_
|
||||||
|
|
||||||
### SendAppUserToAppPaymentRequest
|
### AuthAppRequest
|
||||||
- __from_user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### NewAddressRequest
|
|
||||||
- __addressType__: _[AddressType](#AddressType)_
|
|
||||||
|
|
||||||
### PayAddressResponse
|
|
||||||
- __txId__: _string_
|
|
||||||
- __operation_id__: _string_
|
|
||||||
- __service_fee__: _number_
|
|
||||||
- __network_fee__: _number_
|
|
||||||
|
|
||||||
### UsageMetrics
|
|
||||||
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
|
|
||||||
|
|
||||||
### AddAppUserRequest
|
|
||||||
- __identifier__: _string_
|
|
||||||
- __fail_if_exists__: _boolean_
|
|
||||||
- __balance__: _number_
|
|
||||||
|
|
||||||
### AddAppUserInvoiceRequest
|
|
||||||
- __receiver_identifier__: _string_
|
|
||||||
- __payer_identifier__: _string_
|
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### LnurlPayInfoResponse
|
|
||||||
- __tag__: _string_
|
|
||||||
- __callback__: _string_
|
|
||||||
- __maxSendable__: _number_
|
|
||||||
- __minSendable__: _number_
|
|
||||||
- __metadata__: _string_
|
|
||||||
- __allowsNostr__: _boolean_
|
|
||||||
- __nostrPubkey__: _string_
|
|
||||||
|
|
||||||
### SetMockAppUserBalanceRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### DecodeInvoiceRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
|
|
||||||
### PayInvoiceRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### PayInvoiceResponse
|
|
||||||
- __preimage__: _string_
|
|
||||||
- __amount_paid__: _number_
|
|
||||||
- __operation_id__: _string_
|
|
||||||
- __service_fee__: _number_
|
|
||||||
- __network_fee__: _number_
|
|
||||||
|
|
||||||
### SetMockInvoiceAsPaidRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### AppUser
|
|
||||||
- __identifier__: _string_
|
|
||||||
- __info__: _[UserInfo](#UserInfo)_
|
|
||||||
- __max_withdrawable__: _number_
|
|
||||||
|
|
||||||
### GetAppUserRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
|
|
||||||
### GetAppUserLNURLInfoRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __base_url_override__: _string_
|
|
||||||
|
|
||||||
### HandleLnurlPayResponse
|
|
||||||
- __pr__: _string_
|
|
||||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
|
||||||
|
|
||||||
### UserInfo
|
|
||||||
- __userId__: _string_
|
|
||||||
- __balance__: _number_
|
|
||||||
- __max_withdrawable__: _number_
|
|
||||||
|
|
||||||
### UserOperations
|
|
||||||
- __fromIndex__: _number_
|
|
||||||
- __toIndex__: _number_
|
|
||||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
|
||||||
|
|
||||||
### Product
|
|
||||||
- __id__: _string_
|
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __price_sats__: _number_
|
- __allow_user_creation__: _boolean_ *this field is optional
|
||||||
|
|
||||||
|
### PayAddressRequest
|
||||||
|
- __address__: _string_
|
||||||
|
- __amoutSats__: _number_
|
||||||
|
- __satsPerVByte__: _number_
|
||||||
|
|
||||||
### OpenChannelResponse
|
### OpenChannelResponse
|
||||||
- __channelId__: _string_
|
- __channelId__: _string_
|
||||||
|
|
||||||
### AddProductRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __price_sats__: _number_
|
|
||||||
|
|
||||||
### UsageMetric
|
|
||||||
- __processed_at_nano__: _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_
|
|
||||||
|
|
||||||
### AddAppRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __allow_user_creation__: _boolean_
|
|
||||||
|
|
||||||
### AuthApp
|
|
||||||
- __app__: _[Application](#Application)_
|
|
||||||
- __auth_token__: _string_
|
|
||||||
|
|
||||||
### NewInvoiceResponse
|
|
||||||
- __invoice__: _string_
|
|
||||||
|
|
||||||
### AddAppInvoiceRequest
|
|
||||||
- __payer_identifier__: _string_
|
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### NewInvoiceRequest
|
|
||||||
- __amountSats__: _number_
|
|
||||||
- __memo__: _string_
|
|
||||||
|
|
||||||
### LnurlWithdrawInfoResponse
|
|
||||||
- __tag__: _string_
|
|
||||||
- __callback__: _string_
|
|
||||||
- __k1__: _string_
|
|
||||||
- __defaultDescription__: _string_
|
|
||||||
- __minWithdrawable__: _number_
|
|
||||||
- __maxWithdrawable__: _number_
|
|
||||||
- __balanceCheck__: _string_
|
|
||||||
- __payLink__: _string_
|
|
||||||
|
|
||||||
### UserOperation
|
### UserOperation
|
||||||
- __paidAtUnix__: _number_
|
- __paidAtUnix__: _number_
|
||||||
- __type__: _[UserOperationType](#UserOperationType)_
|
- __type__: _[UserOperationType](#UserOperationType)_
|
||||||
|
|
@ -572,28 +440,77 @@ 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_
|
||||||
|
|
||||||
### SendAppUserToAppUserPaymentRequest
|
### UserOperations
|
||||||
|
- __fromIndex__: _number_
|
||||||
|
- __toIndex__: _number_
|
||||||
|
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||||
|
|
||||||
|
### AddAppRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __allow_user_creation__: _boolean_
|
||||||
|
|
||||||
|
### AppUser
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __info__: _[UserInfo](#UserInfo)_
|
||||||
|
- __max_withdrawable__: _number_
|
||||||
|
|
||||||
|
### NewInvoiceRequest
|
||||||
|
- __amountSats__: _number_
|
||||||
|
- __memo__: _string_
|
||||||
|
|
||||||
|
### UserInfo
|
||||||
|
- __userId__: _string_
|
||||||
|
- __balance__: _number_
|
||||||
|
- __max_withdrawable__: _number_
|
||||||
|
|
||||||
|
### LnurlPayInfoResponse
|
||||||
|
- __tag__: _string_
|
||||||
|
- __callback__: _string_
|
||||||
|
- __maxSendable__: _number_
|
||||||
|
- __minSendable__: _number_
|
||||||
|
- __metadata__: _string_
|
||||||
|
- __allowsNostr__: _boolean_
|
||||||
|
- __nostrPubkey__: _string_
|
||||||
|
|
||||||
|
### HandleLnurlPayResponse
|
||||||
|
- __pr__: _string_
|
||||||
|
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||||
|
|
||||||
|
### SetMockInvoiceAsPaidRequest
|
||||||
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### AddAppUserInvoiceRequest
|
||||||
|
- __receiver_identifier__: _string_
|
||||||
|
- __payer_identifier__: _string_
|
||||||
|
- __http_callback_url__: _string_
|
||||||
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
|
|
||||||
|
### SendAppUserToAppPaymentRequest
|
||||||
- __from_user_identifier__: _string_
|
- __from_user_identifier__: _string_
|
||||||
- __to_user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
- __amount__: _number_
|
||||||
|
|
||||||
### SetMockAppBalanceRequest
|
### DecodeInvoiceRequest
|
||||||
- __amount__: _number_
|
- __invoice__: _string_
|
||||||
|
|
||||||
### LiveUserOperation
|
### OpenChannelRequest
|
||||||
- __operation__: _[UserOperation](#UserOperation)_
|
- __destination__: _string_
|
||||||
|
- __fundingAmount__: _number_
|
||||||
|
- __pushAmount__: _number_
|
||||||
|
- __closeAddress__: _string_
|
||||||
|
|
||||||
### ClosureMigration
|
### LnurlWithdrawInfoResponse
|
||||||
- __closes_at_unix__: _number_
|
- __tag__: _string_
|
||||||
|
- __callback__: _string_
|
||||||
|
- __k1__: _string_
|
||||||
|
- __defaultDescription__: _string_
|
||||||
|
- __minWithdrawable__: _number_
|
||||||
|
- __maxWithdrawable__: _number_
|
||||||
|
- __balanceCheck__: _string_
|
||||||
|
- __payLink__: _string_
|
||||||
|
|
||||||
### Empty
|
### GetProductBuyLinkResponse
|
||||||
|
- __link__: _string_
|
||||||
### EncryptionExchangeRequest
|
|
||||||
- __publicKey__: _string_
|
|
||||||
- __deviceId__: _string_
|
|
||||||
|
|
||||||
### LndGetInfoRequest
|
|
||||||
- __nodeId__: _number_
|
|
||||||
|
|
||||||
### Application
|
### Application
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
|
|
@ -601,6 +518,24 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __balance__: _number_
|
- __balance__: _number_
|
||||||
- __npub__: _string_
|
- __npub__: _string_
|
||||||
|
|
||||||
|
### SendAppUserToAppUserPaymentRequest
|
||||||
|
- __from_user_identifier__: _string_
|
||||||
|
- __to_user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### SetMockAppUserBalanceRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### SetMockAppBalanceRequest
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### PayAddressResponse
|
||||||
|
- __txId__: _string_
|
||||||
|
- __operation_id__: _string_
|
||||||
|
- __service_fee__: _number_
|
||||||
|
- __network_fee__: _number_
|
||||||
|
|
||||||
### GetUserOperationsResponse
|
### GetUserOperationsResponse
|
||||||
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
|
@ -609,23 +544,19 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
|
|
||||||
### GetProductBuyLinkResponse
|
### EncryptionExchangeRequest
|
||||||
- __link__: _string_
|
- __publicKey__: _string_
|
||||||
|
- __deviceId__: _string_
|
||||||
### MigrationUpdate
|
|
||||||
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
|
||||||
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
|
||||||
|
|
||||||
### PayAppUserInvoiceRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### NewAddressResponse
|
### NewAddressResponse
|
||||||
- __address__: _string_
|
- __address__: _string_
|
||||||
|
|
||||||
### DecodeInvoiceResponse
|
### NewInvoiceResponse
|
||||||
- __amount__: _number_
|
- __invoice__: _string_
|
||||||
|
|
||||||
|
### LnurlLinkResponse
|
||||||
|
- __lnurl__: _string_
|
||||||
|
- __k1__: _string_
|
||||||
|
|
||||||
### GetUserOperationsRequest
|
### GetUserOperationsRequest
|
||||||
- __latestIncomingInvoice__: _number_
|
- __latestIncomingInvoice__: _number_
|
||||||
|
|
@ -635,20 +566,89 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __latestIncomingUserToUserPayment__: _number_
|
- __latestIncomingUserToUserPayment__: _number_
|
||||||
- __latestOutgoingUserToUserPayment__: _number_
|
- __latestOutgoingUserToUserPayment__: _number_
|
||||||
|
|
||||||
### AuthAppRequest
|
### UsageMetric
|
||||||
|
- __processed_at_nano__: _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_
|
||||||
|
|
||||||
|
### UsageMetrics
|
||||||
|
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
|
||||||
|
|
||||||
|
### AuthApp
|
||||||
|
- __app__: _[Application](#Application)_
|
||||||
|
- __auth_token__: _string_
|
||||||
|
|
||||||
|
### AddAppUserRequest
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __fail_if_exists__: _boolean_
|
||||||
|
- __balance__: _number_
|
||||||
|
|
||||||
|
### NewAddressRequest
|
||||||
|
- __addressType__: _[AddressType](#AddressType)_
|
||||||
|
|
||||||
|
### DecodeInvoiceResponse
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### ClosureMigration
|
||||||
|
- __closes_at_unix__: _number_
|
||||||
|
|
||||||
|
### RelaysMigration
|
||||||
|
- __relays__: ARRAY of: _string_
|
||||||
|
|
||||||
|
### MigrationUpdate
|
||||||
|
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
||||||
|
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
||||||
|
|
||||||
|
### LndGetInfoRequest
|
||||||
|
- __nodeId__: _number_
|
||||||
|
|
||||||
|
### PayAppUserInvoiceRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### GetAppUserLNURLInfoRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __base_url_override__: _string_
|
||||||
|
|
||||||
|
### PayInvoiceResponse
|
||||||
|
- __preimage__: _string_
|
||||||
|
- __amount_paid__: _number_
|
||||||
|
- __operation_id__: _string_
|
||||||
|
- __service_fee__: _number_
|
||||||
|
- __network_fee__: _number_
|
||||||
|
|
||||||
|
### AddProductRequest
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __allow_user_creation__: _boolean_ *this field is optional
|
- __price_sats__: _number_
|
||||||
|
|
||||||
### PayAddressRequest
|
### Product
|
||||||
- __address__: _string_
|
- __id__: _string_
|
||||||
- __amoutSats__: _number_
|
- __name__: _string_
|
||||||
- __satsPerVByte__: _number_
|
- __price_sats__: _number_
|
||||||
|
|
||||||
### OpenChannelRequest
|
### Empty
|
||||||
- __destination__: _string_
|
|
||||||
- __fundingAmount__: _number_
|
### AddAppInvoiceRequest
|
||||||
- __pushAmount__: _number_
|
- __payer_identifier__: _string_
|
||||||
- __closeAddress__: _string_
|
- __http_callback_url__: _string_
|
||||||
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
|
|
||||||
|
### GetAppUserRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
|
### PayInvoiceRequest
|
||||||
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### LiveUserOperation
|
||||||
|
- __operation__: _[UserOperation](#UserOperation)_
|
||||||
## Enums
|
## Enums
|
||||||
### The enumerators used in the messages
|
### The enumerators used in the messages
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -16,14 +16,15 @@ export type NostrOptions = {
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
throwErrors?: true
|
throwErrors?: true
|
||||||
metricsCallback: (metrics: Types.RequestMetric[]) => void
|
metricsCallback: (metrics: Types.RequestMetric[]) => void
|
||||||
NostrUserAuthGuard: (appId?: string, identifier?: string) => Promise<Types.UserContext>
|
NostrUserAuthGuard: (appId?:string, identifier?: string) => Promise<Types.UserContext>
|
||||||
}
|
}
|
||||||
const logErrorAndReturnResponse = (error: Error, response: string, res: NostrResponse, logger: Logger, metric: Types.RequestMetric, metricsCallback: (metrics: Types.RequestMetric[]) => void) => {
|
const logErrorAndReturnResponse = (error: Error, response: string, res: NostrResponse, logger: Logger, metric: Types.RequestMetric, metricsCallback: (metrics: Types.RequestMetric[]) => void) => {
|
||||||
logger.error(error.message || error); metricsCallback([{ ...metric, error: response }]); res({ status: 'ERROR', reason: response })
|
logger.error(error.message || error); metricsCallback([{ ...metric, error: response }]); res({ status: 'ERROR', reason: response })
|
||||||
}
|
}
|
||||||
export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const logger = opts.logger || { log: console.log, error: console.error }
|
const logger = opts.logger || { log: console.log, error: console.error }
|
||||||
return async (req: NostrRequest, res: NostrResponse, startTime: bigint) => {
|
return async (req: NostrRequest, res: NostrResponse, startString: string) => {
|
||||||
|
const startTime = BigInt(startString)
|
||||||
const info: Types.RequestInfo = { rpcName: req.rpcName || 'unkown', batch: false, nostr: true, batchSize: 0 }
|
const info: Types.RequestInfo = { rpcName: req.rpcName || 'unkown', batch: false, nostr: true, batchSize: 0 }
|
||||||
const stats: Types.RequestStats = { start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
const stats: Types.RequestStats = { start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
||||||
let authCtx: Types.AuthContext = {}
|
let authCtx: Types.AuthContext = {}
|
||||||
|
|
@ -35,11 +36,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
const response = await methods.GetUserInfo({ rpcName: 'GetUserInfo', ctx: authContext })
|
const response = await methods.GetUserInfo({rpcName:'GetUserInfo', ctx:authContext })
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'AddProduct':
|
case 'AddProduct':
|
||||||
try {
|
try {
|
||||||
|
|
@ -51,11 +52,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.AddProductRequestValidate(request)
|
const error = Types.AddProductRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.AddProduct({ rpcName: 'AddProduct', ctx: authContext, req: request })
|
const response = await methods.AddProduct({rpcName:'AddProduct', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'NewProductInvoice':
|
case 'NewProductInvoice':
|
||||||
try {
|
try {
|
||||||
|
|
@ -64,11 +65,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
const response = await methods.NewProductInvoice({ rpcName: 'NewProductInvoice', ctx: authContext, query: req.query || {} })
|
const response = await methods.NewProductInvoice({rpcName:'NewProductInvoice', ctx:authContext ,query: req.query||{}})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'GetUserOperations':
|
case 'GetUserOperations':
|
||||||
try {
|
try {
|
||||||
|
|
@ -80,11 +81,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.GetUserOperationsRequestValidate(request)
|
const error = Types.GetUserOperationsRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.GetUserOperations({ rpcName: 'GetUserOperations', ctx: authContext, req: request })
|
const response = await methods.GetUserOperations({rpcName:'GetUserOperations', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'NewAddress':
|
case 'NewAddress':
|
||||||
try {
|
try {
|
||||||
|
|
@ -96,11 +97,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.NewAddressRequestValidate(request)
|
const error = Types.NewAddressRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.NewAddress({ rpcName: 'NewAddress', ctx: authContext, req: request })
|
const response = await methods.NewAddress({rpcName:'NewAddress', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'PayAddress':
|
case 'PayAddress':
|
||||||
try {
|
try {
|
||||||
|
|
@ -112,11 +113,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.PayAddressRequestValidate(request)
|
const error = Types.PayAddressRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.PayAddress({ rpcName: 'PayAddress', ctx: authContext, req: request })
|
const response = await methods.PayAddress({rpcName:'PayAddress', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'NewInvoice':
|
case 'NewInvoice':
|
||||||
try {
|
try {
|
||||||
|
|
@ -128,11 +129,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.NewInvoiceRequestValidate(request)
|
const error = Types.NewInvoiceRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.NewInvoice({ rpcName: 'NewInvoice', ctx: authContext, req: request })
|
const response = await methods.NewInvoice({rpcName:'NewInvoice', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'DecodeInvoice':
|
case 'DecodeInvoice':
|
||||||
try {
|
try {
|
||||||
|
|
@ -144,11 +145,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.DecodeInvoiceRequestValidate(request)
|
const error = Types.DecodeInvoiceRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.DecodeInvoice({ rpcName: 'DecodeInvoice', ctx: authContext, req: request })
|
const response = await methods.DecodeInvoice({rpcName:'DecodeInvoice', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'PayInvoice':
|
case 'PayInvoice':
|
||||||
try {
|
try {
|
||||||
|
|
@ -160,11 +161,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.PayInvoiceRequestValidate(request)
|
const error = Types.PayInvoiceRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.PayInvoice({ rpcName: 'PayInvoice', ctx: authContext, req: request })
|
const response = await methods.PayInvoice({rpcName:'PayInvoice', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'OpenChannel':
|
case 'OpenChannel':
|
||||||
try {
|
try {
|
||||||
|
|
@ -176,11 +177,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.OpenChannelRequestValidate(request)
|
const error = Types.OpenChannelRequestValidate(request)
|
||||||
stats.validate = process.hrtime.bigint()
|
stats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
const response = await methods.OpenChannel({ rpcName: 'OpenChannel', ctx: authContext, req: request })
|
const response = await methods.OpenChannel({rpcName:'OpenChannel', ctx:authContext , req: request})
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'GetLnurlWithdrawLink':
|
case 'GetLnurlWithdrawLink':
|
||||||
try {
|
try {
|
||||||
|
|
@ -189,11 +190,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
const response = await methods.GetLnurlWithdrawLink({ rpcName: 'GetLnurlWithdrawLink', ctx: authContext })
|
const response = await methods.GetLnurlWithdrawLink({rpcName:'GetLnurlWithdrawLink', ctx:authContext })
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'GetLnurlPayLink':
|
case 'GetLnurlPayLink':
|
||||||
try {
|
try {
|
||||||
|
|
@ -202,11 +203,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
const response = await methods.GetLnurlPayLink({ rpcName: 'GetLnurlPayLink', ctx: authContext })
|
const response = await methods.GetLnurlPayLink({rpcName:'GetLnurlPayLink', ctx:authContext })
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'GetLNURLChannelLink':
|
case 'GetLNURLChannelLink':
|
||||||
try {
|
try {
|
||||||
|
|
@ -215,11 +216,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
const response = await methods.GetLNURLChannelLink({ rpcName: 'GetLNURLChannelLink', ctx: authContext })
|
const response = await methods.GetLNURLChannelLink({rpcName:'GetLNURLChannelLink', ctx:authContext })
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
res({ status: 'OK', ...response })
|
res({status: 'OK', ...response})
|
||||||
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 }
|
||||||
break
|
break
|
||||||
case 'GetLiveUserOperations':
|
case 'GetLiveUserOperations':
|
||||||
try {
|
try {
|
||||||
|
|
@ -228,13 +229,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
methods.GetLiveUserOperations({
|
methods.GetLiveUserOperations({rpcName:'GetLiveUserOperations', ctx:authContext ,cb: (response, err) => {
|
||||||
rpcName: 'GetLiveUserOperations', ctx: authContext, cb: (response, err) => {
|
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) }
|
if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({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 }
|
||||||
} 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
|
break
|
||||||
case 'GetMigrationUpdate':
|
case 'GetMigrationUpdate':
|
||||||
try {
|
try {
|
||||||
|
|
@ -243,19 +242,17 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
stats.guard = process.hrtime.bigint()
|
stats.guard = process.hrtime.bigint()
|
||||||
authCtx = authContext
|
authCtx = authContext
|
||||||
stats.validate = stats.guard
|
stats.validate = stats.guard
|
||||||
methods.GetMigrationUpdate({
|
methods.GetMigrationUpdate({rpcName:'GetMigrationUpdate', ctx:authContext ,cb: (response, err) => {
|
||||||
rpcName: 'GetMigrationUpdate', ctx: authContext, cb: (response, err) => {
|
|
||||||
stats.handle = process.hrtime.bigint()
|
stats.handle = process.hrtime.bigint()
|
||||||
if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) }
|
if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({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 }
|
||||||
} 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
|
break
|
||||||
case 'BatchUser':
|
case 'BatchUser':
|
||||||
try {
|
try {
|
||||||
info.batch = true
|
info.batch = true
|
||||||
const requests = req.body.requests as Types.UserMethodInputs[]
|
const requests = req.body.requests as Types.UserMethodInputs[]
|
||||||
if (!Array.isArray(requests)) throw new Error('invalid body, is not an array')
|
if (!Array.isArray(requests))throw new Error('invalid body, is not an array')
|
||||||
info.batchSize = requests.length
|
info.batchSize = requests.length
|
||||||
if (requests.length > 10) throw new Error('too many requests in the batch')
|
if (requests.length > 10) throw new Error('too many requests in the batch')
|
||||||
const ctx = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
|
const ctx = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
|
||||||
|
|
@ -269,13 +266,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const opInfo: Types.RequestInfo = { rpcName: operation.rpcName, batch: true, nostr: true, batchSize: 0 }
|
const opInfo: Types.RequestInfo = { rpcName: operation.rpcName, batch: true, nostr: true, batchSize: 0 }
|
||||||
const opStats: Types.RequestStats = { start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
const opStats: Types.RequestStats = { start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
||||||
try {
|
try {
|
||||||
switch (operation.rpcName) {
|
switch(operation.rpcName) {
|
||||||
case 'GetUserInfo':
|
case 'GetUserInfo':
|
||||||
if (!methods.GetUserInfo) {
|
if (!methods.GetUserInfo) {
|
||||||
throw new Error('method not defined: GetUserInfo')
|
throw new Error('method not defined: GetUserInfo')
|
||||||
} else {
|
} else {
|
||||||
opStats.validate = opStats.guard
|
opStats.validate = opStats.guard
|
||||||
const res = await methods.GetUserInfo({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.GetUserInfo({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +284,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.AddProductRequestValidate(operation.req)
|
const error = Types.AddProductRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.AddProduct({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.AddProduct({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +294,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
throw new Error('method not defined: NewProductInvoice')
|
throw new Error('method not defined: NewProductInvoice')
|
||||||
} else {
|
} else {
|
||||||
opStats.validate = opStats.guard
|
opStats.validate = opStats.guard
|
||||||
const res = await methods.NewProductInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.NewProductInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +306,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.GetUserOperationsRequestValidate(operation.req)
|
const error = Types.GetUserOperationsRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.GetUserOperations({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.GetUserOperations({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -321,7 +318,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.NewAddressRequestValidate(operation.req)
|
const error = Types.NewAddressRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.NewAddress({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.NewAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -333,7 +330,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.PayAddressRequestValidate(operation.req)
|
const error = Types.PayAddressRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.PayAddress({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.PayAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -345,7 +342,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.NewInvoiceRequestValidate(operation.req)
|
const error = Types.NewInvoiceRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.NewInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.NewInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -357,7 +354,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.DecodeInvoiceRequestValidate(operation.req)
|
const error = Types.DecodeInvoiceRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.DecodeInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.DecodeInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -369,7 +366,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.PayInvoiceRequestValidate(operation.req)
|
const error = Types.PayInvoiceRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.PayInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.PayInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -381,7 +378,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const error = Types.OpenChannelRequestValidate(operation.req)
|
const error = Types.OpenChannelRequestValidate(operation.req)
|
||||||
opStats.validate = process.hrtime.bigint()
|
opStats.validate = process.hrtime.bigint()
|
||||||
if (error !== null) throw error
|
if (error !== null) throw error
|
||||||
const res = await methods.OpenChannel({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.OpenChannel({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -391,7 +388,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
throw new Error('method not defined: GetLnurlWithdrawLink')
|
throw new Error('method not defined: GetLnurlWithdrawLink')
|
||||||
} else {
|
} else {
|
||||||
opStats.validate = opStats.guard
|
opStats.validate = opStats.guard
|
||||||
const res = await methods.GetLnurlWithdrawLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.GetLnurlWithdrawLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +398,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
throw new Error('method not defined: GetLnurlPayLink')
|
throw new Error('method not defined: GetLnurlPayLink')
|
||||||
} else {
|
} else {
|
||||||
opStats.validate = opStats.guard
|
opStats.validate = opStats.guard
|
||||||
const res = await methods.GetLnurlPayLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.GetLnurlPayLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -411,7 +408,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
throw new Error('method not defined: GetLNURLChannelLink')
|
throw new Error('method not defined: GetLNURLChannelLink')
|
||||||
} else {
|
} else {
|
||||||
opStats.validate = opStats.guard
|
opStats.validate = opStats.guard
|
||||||
const res = await methods.GetLNURLChannelLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res })
|
const res = await methods.GetLNURLChannelLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||||
opStats.handle = process.hrtime.bigint()
|
opStats.handle = process.hrtime.bigint()
|
||||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
}
|
}
|
||||||
|
|
@ -419,13 +416,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
default:
|
default:
|
||||||
throw new Error('unkown rpcName')
|
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 }) }
|
} 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 })}
|
||||||
}
|
}
|
||||||
res({ status: 'OK', responses })
|
res({ status: 'OK', responses })
|
||||||
opts.metricsCallback([{ ...info, ...stats, ...ctx }, ...callsMetrics])
|
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 }
|
}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
|
break
|
||||||
default: logger.error('unknown rpc call name from nostr event:' + req.rpcName)
|
default: logger.error('unknown rpc call name from nostr event:'+req.rpcName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
|
@ -16,7 +16,7 @@ export type NostrEvent = {
|
||||||
pub: string
|
pub: string
|
||||||
content: string
|
content: string
|
||||||
appId: string
|
appId: string
|
||||||
startAtNano: bigint
|
startAtNano: string
|
||||||
}
|
}
|
||||||
type SettingsRequest = {
|
type SettingsRequest = {
|
||||||
type: 'settings'
|
type: 'settings'
|
||||||
|
|
@ -142,13 +142,11 @@ export default class Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handledEvents.push(eventId)
|
handledEvents.push(eventId)
|
||||||
const startAtNano = process.hrtime.bigint()
|
const startAtNano = process.hrtime.bigint().toString()
|
||||||
const decoded = decodePayload(e.content)
|
const decoded = decodePayload(e.content)
|
||||||
const content = await decryptData(decoded, getSharedSecret(app.privateKey, e.pubkey))
|
const content = await decryptData(decoded, getSharedSecret(app.privateKey, e.pubkey))
|
||||||
this.eventCallback({ id: eventId, content, pub: e.pubkey, appId: app.appId, startAtNano })
|
this.eventCallback({ id: eventId, content, pub: e.pubkey, appId: app.appId, startAtNano })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async Send(appId: string, data: SendData, relays?: string[]) {
|
async Send(appId: string, data: SendData, relays?: string[]) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue