This commit is contained in:
boufni95 2023-12-09 20:34:09 +01:00
parent 93a1504aa3
commit 46c863721b
12 changed files with 2772 additions and 2605 deletions

View file

@ -90,6 +90,11 @@ The nostr server will send back a message response, and inside the body there wi
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
- output: [MigrationUpdate](#MigrationUpdate) - output: [MigrationUpdate](#MigrationUpdate)
- BatchUser
- auth type: __User__
- This methods has an __empty__ __request__ body
- This methods has an __empty__ __response__ body
# HTTP API DEFINITION # HTTP API DEFINITION
## Supported HTTP Auths ## Supported HTTP Auths
@ -390,54 +395,58 @@ The nostr server will send back a message response, and inside the body there wi
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
- output: [MigrationUpdate](#MigrationUpdate) - output: [MigrationUpdate](#MigrationUpdate)
- BatchUser
- auth type: __User__
- http method: __post__
- http route: __/api/user/batch__
- This methods has an __empty__ __request__ body
- This methods has an __empty__ __response__ body
# INPUTS AND OUTPUTS # INPUTS AND OUTPUTS
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### PayAddressResponse ### GetAppUserLNURLInfoRequest
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __base_url_override__: _string_
### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### NewAddressResponse ### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### RelaysMigration
- __relays__: ARRAY of: _string_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_
### PayAddressRequest
- __address__: _string_ - __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### DecodeInvoiceRequest
- __invoice__: _string_
### LnurlLinkResponse ### LnurlLinkResponse
- __lnurl__: _string_ - __lnurl__: _string_
- __k1__: _string_ - __k1__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### UserOperation ### UserOperation
- __paidAtUnix__: _number_ - __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_ - __type__: _[UserOperationType](#UserOperationType)_
@ -449,88 +458,34 @@ 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_
### GetProductBuyLinkResponse ### EncryptionExchangeRequest
- __link__: _string_ - __publicKey__: _string_
- __deviceId__: _string_
### Empty
### AuthAppRequest ### AuthAppRequest
- __name__: _string_ - __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional - __allow_user_creation__: _boolean_ *this field is optional
### AuthApp ### NewInvoiceRequest
- __app__: _[Application](#Application)_ - __amountSats__: _number_
- __auth_token__: _string_ - __memo__: _string_
### AppUser ### GetProductBuyLinkResponse
- __identifier__: _string_ - __link__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### SendAppUserToAppPaymentRequest ### LndGetInfoResponse
- __from_user_identifier__: _string_ - __alias__: _string_
- __amount__: _number_
### SetMockAppUserBalanceRequest ### GetAppUserRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __amount__: _number_
### RelaysMigration ### NewInvoiceResponse
- __relays__: ARRAY of: _string_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### SetMockAppBalanceRequest
- __amount__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### OpenChannelResponse
- __channelId__: _string_
### LnurlPayInfoResponse
- __tag__: _string_
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_
### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_
### OpenChannelRequest ### UserInfo
- __destination__: _string_ - __userId__: _string_
- __fundingAmount__: _number_ - __balance__: _number_
- __pushAmount__: _number_ - __max_withdrawable__: _number_
- __closeAddress__: _string_
### GetUserOperationsRequest ### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_ - __latestIncomingInvoice__: _number_
@ -540,14 +495,9 @@ The nostr server will send back a message response, and inside the body there wi
- __latestIncomingUserToUserPayment__: _number_ - __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_ - __latestOutgoingUserToUserPayment__: _number_
### Product ### MigrationUpdate
- __id__: _string_ - __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __name__: _string_ - __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
- __price_sats__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### AddAppUserInvoiceRequest ### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_ - __receiver_identifier__: _string_
@ -555,24 +505,26 @@ The nostr server will send back a message response, and inside the body there wi
- __http_callback_url__: _string_ - __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_ - __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SendAppUserToAppUserPaymentRequest ### PayAppUserInvoiceRequest
- __from_user_identifier__: _string_ - __user_identifier__: _string_
- __to_user_identifier__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### DecodeInvoiceRequest ### SetMockAppUserBalanceRequest
- __invoice__: _string_ - __user_identifier__: _string_
### DecodeInvoiceResponse
- __amount__: _number_ - __amount__: _number_
### UserInfo ### NewAddressResponse
- __userId__: _string_ - __address__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
### NewInvoiceResponse ### PayAddressResponse
- __invoice__: _string_ - __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### OpenChannelResponse
- __channelId__: _string_
### LnurlWithdrawInfoResponse ### LnurlWithdrawInfoResponse
- __tag__: _string_ - __tag__: _string_
@ -584,27 +536,84 @@ The nostr server will send back a message response, and inside the body there wi
- __balanceCheck__: _string_ - __balanceCheck__: _string_
- __payLink__: _string_ - __payLink__: _string_
### HandleLnurlPayResponse ### UserOperations
- __pr__: _string_ - __fromIndex__: _number_
- __routes__: ARRAY of: _[Empty](#Empty)_ - __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### MigrationUpdate ### AuthApp
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional - __app__: _[Application](#Application)_
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional - __auth_token__: _string_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### OpenChannelRequest
- __destination__: _string_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### Empty
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SendAppUserToAppUserPaymentRequest
- __from_user_identifier__: _string_
- __to_user_identifier__: _string_
- __amount__: _number_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### LnurlPayInfoResponse
- __tag__: _string_
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### LndGetInfoRequest ### LndGetInfoRequest
- __nodeId__: _number_ - __nodeId__: _number_
### LndGetInfoResponse ### LiveUserOperation
- __alias__: _string_ - __operation__: _[UserOperation](#UserOperation)_
### GetAppUserRequest ### DecodeInvoiceResponse
- __user_identifier__: _string_ - __amount__: _number_
### PayAddressRequest ### PayInvoiceResponse
- __address__: _string_ - __preimage__: _string_
- __amoutSats__: _number_ - __amount_paid__: _number_
- __satsPerVByte__: _number_ - __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### GetUserOperationsResponse ### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_ - __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
@ -614,8 +623,11 @@ 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)_
### LiveUserOperation ### ClosureMigration
- __operation__: _[UserOperation](#UserOperation)_ - __closes_at_unix__: _number_
### SetMockAppBalanceRequest
- __amount__: _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

@ -10,15 +10,12 @@ export type ServerOptions = {
allowNotImplementedMethods?: true allowNotImplementedMethods?: true
logger?: Logger logger?: Logger
throwErrors?: true throwErrors?: true
overrides?: MethodsOverride
logMethod?: true logMethod?: true
logBody?: true logBody?: true
GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext> GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext>
UserAuthGuard: (authorizationHeader?: string) => Promise<Types.UserContext> UserAuthGuard: (authorizationHeader?: string) => Promise<Types.UserContext>
AdminAuthGuard: (authorizationHeader?: string) => Promise<Types.AdminContext> AdminAuthGuard: (authorizationHeader?: string) => Promise<Types.AdminContext>
AppAuthGuard: (authorizationHeader?: string) => Promise<Types.AppContext> AppAuthGuard: (authorizationHeader?: string) => Promise<Types.AppContext>
decryptCallback: (encryptionDeviceId: string, body: any) => Promise<any>
encryptCallback: (encryptionDeviceId: string, plain: any) => Promise<any>
} }
const logErrorAndReturnResponse = (error: Error, response: string, res: Response, logger: Logger) => { logger.error(error.message || error); res.json({ status: 'ERROR', reason: response }) } const logErrorAndReturnResponse = (error: Error, response: string, res: Response, logger: Logger) => { logger.error(error.message || error); res.json({ status: 'ERROR', reason: response }) }
export default (methods: Types.ServerMethods, opts: ServerOptions) => { export default (methods: Types.ServerMethods, opts: ServerOptions) => {
@ -30,7 +27,6 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
app.use(json()) app.use(json())
app.use(urlencoded({ extended: true })) 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.logMethod) app.use((req, _, next) => { console.log(req.method, req.path); if (opts.logBody) console.log(req.body); next() })
const overrides = opts.overrides || {} as MethodsOverride
if (!opts.allowNotImplementedMethods && !methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented') if (!opts.allowNotImplementedMethods && !methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented')
app.post('/api/admin/lnd/getinfo', async (req, res) => { app.post('/api/admin/lnd/getinfo', async (req, res) => {
try { try {
@ -41,8 +37,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.LndGetInfo({ ...authContext, ...query, ...params }, request) const response = await methods.LndGetInfo({rpcName:'LndGetInfo', ctx:authContext , req: request})
if (overrides.LndGetInfo_Override) await overrides.LndGetInfo_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AddApp) throw new Error('method: AddApp is not implemented') if (!opts.allowNotImplementedMethods && !methods.AddApp) throw new Error('method: AddApp is not implemented')
@ -55,8 +51,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AddApp({ ...authContext, ...query, ...params }, request) const response = await methods.AddApp({rpcName:'AddApp', ctx:authContext , req: request})
if (overrides.AddApp_Override) await overrides.AddApp_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AuthApp) throw new Error('method: AuthApp is not implemented') if (!opts.allowNotImplementedMethods && !methods.AuthApp) throw new Error('method: AuthApp is not implemented')
@ -69,8 +65,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AuthApp({ ...authContext, ...query, ...params }, request) const response = await methods.AuthApp({rpcName:'AuthApp', ctx:authContext , req: request})
if (overrides.AuthApp_Override) await overrides.AuthApp_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.Health) throw new Error('method: Health is not implemented') if (!opts.allowNotImplementedMethods && !methods.Health) throw new Error('method: Health is not implemented')
@ -80,8 +76,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.Health({ ...authContext, ...query, ...params }) await methods.Health({rpcName:'Health', ctx:authContext })
if (overrides.Health_Override) await overrides.Health_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented') if (!opts.allowNotImplementedMethods && !methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented')
@ -94,8 +90,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.EncryptionExchange({ ...authContext, ...query, ...params }, request) await methods.EncryptionExchange({rpcName:'EncryptionExchange', ctx:authContext , req: request})
if (overrides.EncryptionExchange_Override) await overrides.EncryptionExchange_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.SetMockInvoiceAsPaid) throw new Error('method: SetMockInvoiceAsPaid is not implemented') if (!opts.allowNotImplementedMethods && !methods.SetMockInvoiceAsPaid) throw new Error('method: SetMockInvoiceAsPaid is not implemented')
@ -108,8 +104,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.SetMockInvoiceAsPaid({ ...authContext, ...query, ...params }, request) await methods.SetMockInvoiceAsPaid({rpcName:'SetMockInvoiceAsPaid', ctx:authContext , req: request})
if (overrides.SetMockInvoiceAsPaid_Override) await overrides.SetMockInvoiceAsPaid_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawInfo) throw new Error('method: GetLnurlWithdrawInfo is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawInfo) throw new Error('method: GetLnurlWithdrawInfo is not implemented')
@ -119,8 +115,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetLnurlWithdrawInfo({ ...authContext, ...query, ...params }) const response = await methods.GetLnurlWithdrawInfo({rpcName:'GetLnurlWithdrawInfo', ctx:authContext ,query: req.query})
if (overrides.GetLnurlWithdrawInfo_Override) await overrides.GetLnurlWithdrawInfo_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlWithdraw) throw new Error('method: HandleLnurlWithdraw is not implemented') if (!opts.allowNotImplementedMethods && !methods.HandleLnurlWithdraw) throw new Error('method: HandleLnurlWithdraw is not implemented')
@ -130,8 +126,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.HandleLnurlWithdraw({ ...authContext, ...query, ...params }) await methods.HandleLnurlWithdraw({rpcName:'HandleLnurlWithdraw', ctx:authContext ,query: req.query})
if (overrides.HandleLnurlWithdraw_Override) await overrides.HandleLnurlWithdraw_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayInfo) throw new Error('method: GetLnurlPayInfo is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayInfo) throw new Error('method: GetLnurlPayInfo is not implemented')
@ -141,8 +137,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetLnurlPayInfo({ ...authContext, ...query, ...params }) const response = await methods.GetLnurlPayInfo({rpcName:'GetLnurlPayInfo', ctx:authContext ,query: req.query})
if (overrides.GetLnurlPayInfo_Override) await overrides.GetLnurlPayInfo_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlPay) throw new Error('method: HandleLnurlPay is not implemented') if (!opts.allowNotImplementedMethods && !methods.HandleLnurlPay) throw new Error('method: HandleLnurlPay is not implemented')
@ -152,8 +148,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.HandleLnurlPay({ ...authContext, ...query, ...params }) const response = await methods.HandleLnurlPay({rpcName:'HandleLnurlPay', ctx:authContext ,query: req.query})
if (overrides.HandleLnurlPay_Override) await overrides.HandleLnurlPay_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.HandleLnurlAddress) throw new Error('method: HandleLnurlAddress is not implemented') if (!opts.allowNotImplementedMethods && !methods.HandleLnurlAddress) throw new Error('method: HandleLnurlAddress is not implemented')
@ -163,8 +159,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.GuestAuthGuard(req.headers['authorization']) const authContext = await opts.GuestAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.HandleLnurlAddress({ ...authContext, ...query, ...params }) const response = await methods.HandleLnurlAddress({rpcName:'HandleLnurlAddress', ctx:authContext ,params: req.params})
if (overrides.HandleLnurlAddress_Override) await overrides.HandleLnurlAddress_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetApp) throw new Error('method: GetApp is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetApp) throw new Error('method: GetApp is not implemented')
@ -174,8 +170,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.AppAuthGuard(req.headers['authorization']) const authContext = await opts.AppAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetApp({ ...authContext, ...query, ...params }) const response = await methods.GetApp({rpcName:'GetApp', ctx:authContext })
if (overrides.GetApp_Override) await overrides.GetApp_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AddAppUser) throw new Error('method: AddAppUser is not implemented') if (!opts.allowNotImplementedMethods && !methods.AddAppUser) throw new Error('method: AddAppUser is not implemented')
@ -188,8 +184,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AddAppUser({ ...authContext, ...query, ...params }, request) const response = await methods.AddAppUser({rpcName:'AddAppUser', ctx:authContext , req: request})
if (overrides.AddAppUser_Override) await overrides.AddAppUser_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AddAppInvoice) throw new Error('method: AddAppInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.AddAppInvoice) throw new Error('method: AddAppInvoice is not implemented')
@ -202,8 +198,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AddAppInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.AddAppInvoice({rpcName:'AddAppInvoice', ctx:authContext , req: request})
if (overrides.AddAppInvoice_Override) await overrides.AddAppInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AddAppUserInvoice) throw new Error('method: AddAppUserInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.AddAppUserInvoice) throw new Error('method: AddAppUserInvoice is not implemented')
@ -216,8 +212,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AddAppUserInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.AddAppUserInvoice({rpcName:'AddAppUserInvoice', ctx:authContext , req: request})
if (overrides.AddAppUserInvoice_Override) await overrides.AddAppUserInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetAppUser) throw new Error('method: GetAppUser is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetAppUser) throw new Error('method: GetAppUser is not implemented')
@ -230,8 +226,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetAppUser({ ...authContext, ...query, ...params }, request) const response = await methods.GetAppUser({rpcName:'GetAppUser', ctx:authContext , req: request})
if (overrides.GetAppUser_Override) await overrides.GetAppUser_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.PayAppUserInvoice) throw new Error('method: PayAppUserInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.PayAppUserInvoice) throw new Error('method: PayAppUserInvoice is not implemented')
@ -244,8 +240,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.PayAppUserInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.PayAppUserInvoice({rpcName:'PayAppUserInvoice', ctx:authContext , req: request})
if (overrides.PayAppUserInvoice_Override) await overrides.PayAppUserInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppUserPayment) throw new Error('method: SendAppUserToAppUserPayment is not implemented') if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppUserPayment) throw new Error('method: SendAppUserToAppUserPayment is not implemented')
@ -258,8 +254,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.SendAppUserToAppUserPayment({ ...authContext, ...query, ...params }, request) await methods.SendAppUserToAppUserPayment({rpcName:'SendAppUserToAppUserPayment', ctx:authContext , req: request})
if (overrides.SendAppUserToAppUserPayment_Override) await overrides.SendAppUserToAppUserPayment_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppPayment) throw new Error('method: SendAppUserToAppPayment is not implemented') if (!opts.allowNotImplementedMethods && !methods.SendAppUserToAppPayment) throw new Error('method: SendAppUserToAppPayment is not implemented')
@ -272,8 +268,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.SendAppUserToAppPayment({ ...authContext, ...query, ...params }, request) await methods.SendAppUserToAppPayment({rpcName:'SendAppUserToAppPayment', ctx:authContext , req: request})
if (overrides.SendAppUserToAppPayment_Override) await overrides.SendAppUserToAppPayment_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented')
@ -286,8 +282,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetAppUserLNURLInfo({ ...authContext, ...query, ...params }, request) const response = await methods.GetAppUserLNURLInfo({rpcName:'GetAppUserLNURLInfo', ctx:authContext , req: request})
if (overrides.GetAppUserLNURLInfo_Override) await overrides.GetAppUserLNURLInfo_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.SetMockAppUserBalance) throw new Error('method: SetMockAppUserBalance is not implemented') if (!opts.allowNotImplementedMethods && !methods.SetMockAppUserBalance) throw new Error('method: SetMockAppUserBalance is not implemented')
@ -300,8 +296,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.SetMockAppUserBalance({ ...authContext, ...query, ...params }, request) await methods.SetMockAppUserBalance({rpcName:'SetMockAppUserBalance', ctx:authContext , req: request})
if (overrides.SetMockAppUserBalance_Override) await overrides.SetMockAppUserBalance_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.SetMockAppBalance) throw new Error('method: SetMockAppBalance is not implemented') if (!opts.allowNotImplementedMethods && !methods.SetMockAppBalance) throw new Error('method: SetMockAppBalance is not implemented')
@ -314,8 +310,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
await methods.SetMockAppBalance({ ...authContext, ...query, ...params }, request) await methods.SetMockAppBalance({rpcName:'SetMockAppBalance', ctx:authContext , req: request})
if (overrides.SetMockAppBalance_Override) await overrides.SetMockAppBalance_Override(res); else res.json({status: 'OK'}) res.json({status: 'OK'})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); 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')
@ -325,8 +321,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.UserAuthGuard(req.headers['authorization']) const authContext = await opts.UserAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetUserInfo({ ...authContext, ...query, ...params }) const response = await methods.GetUserInfo({rpcName:'GetUserInfo', ctx:authContext })
if (overrides.GetUserInfo_Override) await overrides.GetUserInfo_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.AddProduct) throw new Error('method: AddProduct is not implemented') if (!opts.allowNotImplementedMethods && !methods.AddProduct) throw new Error('method: AddProduct is not implemented')
@ -339,8 +335,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.AddProduct({ ...authContext, ...query, ...params }, request) const response = await methods.AddProduct({rpcName:'AddProduct', ctx:authContext , req: request})
if (overrides.AddProduct_Override) await overrides.AddProduct_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented')
@ -350,8 +346,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.UserAuthGuard(req.headers['authorization']) const authContext = await opts.UserAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.NewProductInvoice({ ...authContext, ...query, ...params }) const response = await methods.NewProductInvoice({rpcName:'NewProductInvoice', ctx:authContext ,query: req.query})
if (overrides.NewProductInvoice_Override) await overrides.NewProductInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetUserOperations) throw new Error('method: GetUserOperations is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetUserOperations) throw new Error('method: GetUserOperations is not implemented')
@ -364,8 +360,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetUserOperations({ ...authContext, ...query, ...params }, request) const response = await methods.GetUserOperations({rpcName:'GetUserOperations', ctx:authContext , req: request})
if (overrides.GetUserOperations_Override) await overrides.GetUserOperations_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.NewAddress) throw new Error('method: NewAddress is not implemented') if (!opts.allowNotImplementedMethods && !methods.NewAddress) throw new Error('method: NewAddress is not implemented')
@ -378,8 +374,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.NewAddress({ ...authContext, ...query, ...params }, request) const response = await methods.NewAddress({rpcName:'NewAddress', ctx:authContext , req: request})
if (overrides.NewAddress_Override) await overrides.NewAddress_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.PayAddress) throw new Error('method: PayAddress is not implemented') if (!opts.allowNotImplementedMethods && !methods.PayAddress) throw new Error('method: PayAddress is not implemented')
@ -392,8 +388,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.PayAddress({ ...authContext, ...query, ...params }, request) const response = await methods.PayAddress({rpcName:'PayAddress', ctx:authContext , req: request})
if (overrides.PayAddress_Override) await overrides.PayAddress_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.NewInvoice) throw new Error('method: NewInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.NewInvoice) throw new Error('method: NewInvoice is not implemented')
@ -406,8 +402,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.NewInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.NewInvoice({rpcName:'NewInvoice', ctx:authContext , req: request})
if (overrides.NewInvoice_Override) await overrides.NewInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.DecodeInvoice) throw new Error('method: DecodeInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.DecodeInvoice) throw new Error('method: DecodeInvoice is not implemented')
@ -420,8 +416,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.DecodeInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.DecodeInvoice({rpcName:'DecodeInvoice', ctx:authContext , req: request})
if (overrides.DecodeInvoice_Override) await overrides.DecodeInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.PayInvoice) throw new Error('method: PayInvoice is not implemented') if (!opts.allowNotImplementedMethods && !methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
@ -434,8 +430,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.PayInvoice({ ...authContext, ...query, ...params }, request) const response = await methods.PayInvoice({rpcName:'PayInvoice', ctx:authContext , req: request})
if (overrides.PayInvoice_Override) await overrides.PayInvoice_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.OpenChannel) throw new Error('method: OpenChannel is not implemented') if (!opts.allowNotImplementedMethods && !methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
@ -448,8 +444,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.OpenChannel({ ...authContext, ...query, ...params }, request) const response = await methods.OpenChannel({rpcName:'OpenChannel', ctx:authContext , req: request})
if (overrides.OpenChannel_Override) await overrides.OpenChannel_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented')
@ -459,8 +455,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.UserAuthGuard(req.headers['authorization']) const authContext = await opts.UserAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetLnurlWithdrawLink({ ...authContext, ...query, ...params }) const response = await methods.GetLnurlWithdrawLink({rpcName:'GetLnurlWithdrawLink', ctx:authContext })
if (overrides.GetLnurlWithdrawLink_Override) await overrides.GetLnurlWithdrawLink_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented')
@ -470,8 +466,8 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.UserAuthGuard(req.headers['authorization']) const authContext = await opts.UserAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetLnurlPayLink({ ...authContext, ...query, ...params }) const response = await methods.GetLnurlPayLink({rpcName:'GetLnurlPayLink', ctx:authContext })
if (overrides.GetLnurlPayLink_Override) await overrides.GetLnurlPayLink_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (!opts.allowNotImplementedMethods && !methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented') if (!opts.allowNotImplementedMethods && !methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented')
@ -481,8 +477,118 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const authContext = await opts.UserAuthGuard(req.headers['authorization']) const authContext = await opts.UserAuthGuard(req.headers['authorization'])
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.GetLNURLChannelLink({ ...authContext, ...query, ...params }) const response = await methods.GetLNURLChannelLink({rpcName:'GetLNURLChannelLink', ctx:authContext })
if (overrides.GetLNURLChannelLink_Override) await overrides.GetLNURLChannelLink_Override(res, response); else res.json({status: 'OK', ...response}) res.json({status: 'OK', ...response})
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
})
app.post('/api/user/batch', async (req, res) => {
try {
const requests = req.body.requests as Types.UserMethodInputs[]
if (!Array.isArray(requests))throw new Error('invalid body, is not an array')
if (requests.length > 10) throw new Error('too many requests in the batch')
const ctx = await opts.UserAuthGuard(req.headers['authorization'])
const responses = []
for (let i = 0; i < requests.length; i++) {
const operation = requests[i]
try {
switch(operation.rpcName) {
case 'GetUserInfo':
if (!methods.GetUserInfo) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetUserInfo' })
} else {
const res = await methods.GetUserInfo({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'AddProduct':
if (!methods.AddProduct) {
responses.push({ status: 'ERROR', reason: 'method not defined: AddProduct' })
} else {
const res = await methods.AddProduct({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewProductInvoice':
if (!methods.NewProductInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewProductInvoice' })
} else {
const res = await methods.NewProductInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetUserOperations':
if (!methods.GetUserOperations) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetUserOperations' })
} else {
const res = await methods.GetUserOperations({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewAddress':
if (!methods.NewAddress) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewAddress' })
} else {
const res = await methods.NewAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'PayAddress':
if (!methods.PayAddress) {
responses.push({ status: 'ERROR', reason: 'method not defined: PayAddress' })
} else {
const res = await methods.PayAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewInvoice':
if (!methods.NewInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewInvoice' })
} else {
const res = await methods.NewInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'DecodeInvoice':
if (!methods.DecodeInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: DecodeInvoice' })
} else {
const res = await methods.DecodeInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'PayInvoice':
if (!methods.PayInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: PayInvoice' })
} else {
const res = await methods.PayInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'OpenChannel':
if (!methods.OpenChannel) {
responses.push({ status: 'ERROR', reason: 'method not defined: OpenChannel' })
} else {
const res = await methods.OpenChannel({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLnurlWithdrawLink':
if (!methods.GetLnurlWithdrawLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLnurlWithdrawLink' })
} else {
const res = await methods.GetLnurlWithdrawLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLnurlPayLink':
if (!methods.GetLnurlPayLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLnurlPayLink' })
} else {
const res = await methods.GetLnurlPayLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLNURLChannelLink':
if (!methods.GetLNURLChannelLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLNURLChannelLink' })
} else {
const res = await methods.GetLNURLChannelLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
default:
throw new Error('unkown rpcName')
}
} catch(ex) {const e = ex as any; logger.error(e.message || e); responses.push({ status: 'ERROR', reason: e.message || e })}
}
res.json({ status: 'OK', responses })
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
}) })
if (opts.staticFiles) { if (opts.staticFiles) {
@ -495,42 +601,3 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
Listen: (port: number) => { server = app.listen(port, () => logger.log('Example app listening on port ' + port)) } Listen: (port: number) => { server = app.listen(port, () => logger.log('Example app listening on port ' + port)) }
} }
} }
export type MethodsOverride = {
LndGetInfo_Override?: (httpRes:Response, handlerRes:Types.LndGetInfoResponse) => Promise<void>
AddApp_Override?: (httpRes:Response, handlerRes:Types.AuthApp) => Promise<void>
AuthApp_Override?: (httpRes:Response, handlerRes:Types.AuthApp) => Promise<void>
Health_Override?: (httpRes:Response) => Promise<void>
EncryptionExchange_Override?: (httpRes:Response) => Promise<void>
SetMockInvoiceAsPaid_Override?: (httpRes:Response) => Promise<void>
GetLnurlWithdrawInfo_Override?: (httpRes:Response, handlerRes:Types.LnurlWithdrawInfoResponse) => Promise<void>
HandleLnurlWithdraw_Override?: (httpRes:Response) => Promise<void>
GetLnurlPayInfo_Override?: (httpRes:Response, handlerRes:Types.LnurlPayInfoResponse) => Promise<void>
HandleLnurlPay_Override?: (httpRes:Response, handlerRes:Types.HandleLnurlPayResponse) => Promise<void>
HandleLnurlAddress_Override?: (httpRes:Response, handlerRes:Types.LnurlPayInfoResponse) => Promise<void>
GetApp_Override?: (httpRes:Response, handlerRes:Types.Application) => Promise<void>
AddAppUser_Override?: (httpRes:Response, handlerRes:Types.AppUser) => Promise<void>
AddAppInvoice_Override?: (httpRes:Response, handlerRes:Types.NewInvoiceResponse) => Promise<void>
AddAppUserInvoice_Override?: (httpRes:Response, handlerRes:Types.NewInvoiceResponse) => Promise<void>
GetAppUser_Override?: (httpRes:Response, handlerRes:Types.AppUser) => Promise<void>
PayAppUserInvoice_Override?: (httpRes:Response, handlerRes:Types.PayInvoiceResponse) => Promise<void>
SendAppUserToAppUserPayment_Override?: (httpRes:Response) => Promise<void>
SendAppUserToAppPayment_Override?: (httpRes:Response) => Promise<void>
GetAppUserLNURLInfo_Override?: (httpRes:Response, handlerRes:Types.LnurlPayInfoResponse) => Promise<void>
SetMockAppUserBalance_Override?: (httpRes:Response) => Promise<void>
SetMockAppBalance_Override?: (httpRes:Response) => Promise<void>
GetUserInfo_Override?: (httpRes:Response, handlerRes:Types.UserInfo) => Promise<void>
AddProduct_Override?: (httpRes:Response, handlerRes:Types.Product) => Promise<void>
NewProductInvoice_Override?: (httpRes:Response, handlerRes:Types.NewInvoiceResponse) => Promise<void>
GetUserOperations_Override?: (httpRes:Response, handlerRes:Types.GetUserOperationsResponse) => Promise<void>
NewAddress_Override?: (httpRes:Response, handlerRes:Types.NewAddressResponse) => Promise<void>
PayAddress_Override?: (httpRes:Response, handlerRes:Types.PayAddressResponse) => Promise<void>
NewInvoice_Override?: (httpRes:Response, handlerRes:Types.NewInvoiceResponse) => Promise<void>
DecodeInvoice_Override?: (httpRes:Response, handlerRes:Types.DecodeInvoiceResponse) => Promise<void>
PayInvoice_Override?: (httpRes:Response, handlerRes:Types.PayInvoiceResponse) => Promise<void>
OpenChannel_Override?: (httpRes:Response, handlerRes:Types.OpenChannelResponse) => Promise<void>
GetLnurlWithdrawLink_Override?: (httpRes:Response, handlerRes:Types.LnurlLinkResponse) => Promise<void>
GetLnurlPayLink_Override?: (httpRes:Response, handlerRes:Types.LnurlLinkResponse) => Promise<void>
GetLNURLChannelLink_Override?: (httpRes:Response, handlerRes:Types.LnurlLinkResponse) => Promise<void>
GetLiveUserOperations_Override?: (httpRes:Response, handlerRes:Types.LiveUserOperation) => Promise<void>
GetMigrationUpdate_Override?: (httpRes:Response, handlerRes:Types.MigrationUpdate) => Promise<void>
}

View file

@ -494,4 +494,15 @@ export default (params: ClientParams) => ({
}, },
GetLiveUserOperations: async (cb: (v:ResultError | ({ status: 'OK' }& Types.LiveUserOperation)) => void): Promise<void> => { throw new Error('http streams are not supported')}, GetLiveUserOperations: async (cb: (v:ResultError | ({ status: 'OK' }& Types.LiveUserOperation)) => void): Promise<void> => { throw new Error('http streams are not supported')},
GetMigrationUpdate: async (cb: (v:ResultError | ({ status: 'OK' }& Types.MigrationUpdate)) => void): Promise<void> => { throw new Error('http streams are not supported')}, GetMigrationUpdate: async (cb: (v:ResultError | ({ status: 'OK' }& Types.MigrationUpdate)) => void): Promise<void> => { throw new Error('http streams are not supported')},
BatchUser: async (requests:Types.UserMethodInputs): Promise<ResultError | ({ status: 'OK', responses:Types.UserMethodOutputs })> => {
const auth = await params.retrieveUserAuth()
if (auth === null) throw new Error('retrieveUserAuth() returned null')
let finalRoute = '/api/user/batch'
const { data } = await axios.post(params.baseUrl + finalRoute, {requests}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return { status: 'OK', ...data }
}
return { status: 'ERROR', reason: 'invalid response' }
}
}) })

View file

@ -230,4 +230,15 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
return cb({ status: 'ERROR', reason: 'invalid response' }) return cb({ status: 'ERROR', reason: 'invalid response' })
}) })
}, },
BatchUser: async (requests:Types.UserMethodInputs): Promise<ResultError | ({ status: 'OK', responses:Types.UserMethodOutputs })> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {body:{requests}}
const data = await send(params.pubDestination, {rpcName:'BatchUser',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' }
}
}) })

View file

@ -26,9 +26,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented') if (!methods.GetUserInfo) throw new Error('method: GetUserInfo is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query const response = await methods.GetUserInfo({rpcName:'GetUserInfo', ctx:authContext })
const params = req.params
const response = await methods.GetUserInfo({ ...authContext, ...query, ...params })
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -39,9 +37,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.AddProductRequestValidate(request) const error = Types.AddProductRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.AddProduct({rpcName:'AddProduct', ctx:authContext , req: request})
const params = req.params
const response = await methods.AddProduct({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -49,9 +45,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented') if (!methods.NewProductInvoice) throw new Error('method: NewProductInvoice is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query const response = await methods.NewProductInvoice({rpcName:'NewProductInvoice', ctx:authContext ,query: req.query||{}})
const params = req.params
const response = await methods.NewProductInvoice({ ...authContext, ...query, ...params })
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -62,9 +56,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.GetUserOperationsRequestValidate(request) const error = Types.GetUserOperationsRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.GetUserOperations({rpcName:'GetUserOperations', ctx:authContext , req: request})
const params = req.params
const response = await methods.GetUserOperations({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -75,9 +67,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.NewAddressRequestValidate(request) const error = Types.NewAddressRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.NewAddress({rpcName:'NewAddress', ctx:authContext , req: request})
const params = req.params
const response = await methods.NewAddress({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -88,9 +78,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.PayAddressRequestValidate(request) const error = Types.PayAddressRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.PayAddress({rpcName:'PayAddress', ctx:authContext , req: request})
const params = req.params
const response = await methods.PayAddress({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -101,9 +89,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.NewInvoiceRequestValidate(request) const error = Types.NewInvoiceRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.NewInvoice({rpcName:'NewInvoice', ctx:authContext , req: request})
const params = req.params
const response = await methods.NewInvoice({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -114,9 +100,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.DecodeInvoiceRequestValidate(request) const error = Types.DecodeInvoiceRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.DecodeInvoice({rpcName:'DecodeInvoice', ctx:authContext , req: request})
const params = req.params
const response = await methods.DecodeInvoice({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -127,9 +111,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.PayInvoiceRequestValidate(request) const error = Types.PayInvoiceRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.PayInvoice({rpcName:'PayInvoice', ctx:authContext , req: request})
const params = req.params
const response = await methods.PayInvoice({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -140,9 +122,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const request = req.body const request = req.body
const error = Types.OpenChannelRequestValidate(request) const error = Types.OpenChannelRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query const response = await methods.OpenChannel({rpcName:'OpenChannel', ctx:authContext , req: request})
const params = req.params
const response = await methods.OpenChannel({ ...authContext, ...query, ...params }, request)
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -150,9 +130,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented') if (!methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query const response = await methods.GetLnurlWithdrawLink({rpcName:'GetLnurlWithdrawLink', ctx:authContext })
const params = req.params
const response = await methods.GetLnurlWithdrawLink({ ...authContext, ...query, ...params })
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -160,9 +138,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented') if (!methods.GetLnurlPayLink) throw new Error('method: GetLnurlPayLink is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query const response = await methods.GetLnurlPayLink({rpcName:'GetLnurlPayLink', ctx:authContext })
const params = req.params
const response = await methods.GetLnurlPayLink({ ...authContext, ...query, ...params })
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -170,9 +146,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented') if (!methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query const response = await methods.GetLNURLChannelLink({rpcName:'GetLNURLChannelLink', ctx:authContext })
const params = req.params
const response = await methods.GetLNURLChannelLink({ ...authContext, ...query, ...params })
res({status: 'OK', ...response}) res({status: 'OK', ...response})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
@ -180,22 +154,128 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
try { try {
if (!methods.GetLiveUserOperations) throw new Error('method: GetLiveUserOperations is not implemented') if (!methods.GetLiveUserOperations) throw new Error('method: GetLiveUserOperations is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query methods.GetLiveUserOperations({rpcName:'GetLiveUserOperations', ctx:authContext ,cb: (response, err) => {
const params = req.params
methods.GetLiveUserOperations({ ...authContext, ...query, ...params }, (response, err) => {
if (err) { logErrorAndReturnResponse(err, err.message, res, logger)} else { res({status: 'OK', ...response})} if (err) { logErrorAndReturnResponse(err, err.message, res, logger)} else { res({status: 'OK', ...response})}
}) }})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break break
case 'GetMigrationUpdate': case 'GetMigrationUpdate':
try { try {
if (!methods.GetMigrationUpdate) throw new Error('method: GetMigrationUpdate is not implemented') if (!methods.GetMigrationUpdate) throw new Error('method: GetMigrationUpdate is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const query = req.query methods.GetMigrationUpdate({rpcName:'GetMigrationUpdate', ctx:authContext ,cb: (response, err) => {
const params = req.params
methods.GetMigrationUpdate({ ...authContext, ...query, ...params }, (response, err) => {
if (err) { logErrorAndReturnResponse(err, err.message, res, logger)} else { res({status: 'OK', ...response})} if (err) { logErrorAndReturnResponse(err, err.message, res, logger)} else { res({status: 'OK', ...response})}
}) }})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
break
case 'BatchUser':
try {
const requests = req.body.requests as Types.UserMethodInputs[]
if (!Array.isArray(requests))throw new Error('invalid body, is not an array')
if (requests.length > 10) throw new Error('too many requests in the batch')
const ctx = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
const responses = []
for (let i = 0; i < requests.length; i++) {
const operation = requests[i]
try {
switch(operation.rpcName) {
case 'GetUserInfo':
if (!methods.GetUserInfo) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetUserInfo' })
} else {
const res = await methods.GetUserInfo({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'AddProduct':
if (!methods.AddProduct) {
responses.push({ status: 'ERROR', reason: 'method not defined: AddProduct' })
} else {
const res = await methods.AddProduct({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewProductInvoice':
if (!methods.NewProductInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewProductInvoice' })
} else {
const res = await methods.NewProductInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetUserOperations':
if (!methods.GetUserOperations) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetUserOperations' })
} else {
const res = await methods.GetUserOperations({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewAddress':
if (!methods.NewAddress) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewAddress' })
} else {
const res = await methods.NewAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'PayAddress':
if (!methods.PayAddress) {
responses.push({ status: 'ERROR', reason: 'method not defined: PayAddress' })
} else {
const res = await methods.PayAddress({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'NewInvoice':
if (!methods.NewInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: NewInvoice' })
} else {
const res = await methods.NewInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'DecodeInvoice':
if (!methods.DecodeInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: DecodeInvoice' })
} else {
const res = await methods.DecodeInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'PayInvoice':
if (!methods.PayInvoice) {
responses.push({ status: 'ERROR', reason: 'method not defined: PayInvoice' })
} else {
const res = await methods.PayInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'OpenChannel':
if (!methods.OpenChannel) {
responses.push({ status: 'ERROR', reason: 'method not defined: OpenChannel' })
} else {
const res = await methods.OpenChannel({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLnurlWithdrawLink':
if (!methods.GetLnurlWithdrawLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLnurlWithdrawLink' })
} else {
const res = await methods.GetLnurlWithdrawLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLnurlPayLink':
if (!methods.GetLnurlPayLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLnurlPayLink' })
} else {
const res = await methods.GetLnurlPayLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
case 'GetLNURLChannelLink':
if (!methods.GetLNURLChannelLink) {
responses.push({ status: 'ERROR', reason: 'method not defined: GetLNURLChannelLink' })
} else {
const res = await methods.GetLNURLChannelLink({...operation, ctx}); responses.push({ status: 'OK', ...res })
}
break
default:
throw new Error('unkown rpcName')
}
} catch(ex) {const e = ex as any; logger.error(e.message || e); responses.push({ status: 'ERROR', reason: e.message || e })}
}
res({ status: 'OK', responses })
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); 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.

View file

@ -58,6 +58,7 @@ extend google.protobuf.MethodOptions { // TODO: move this stuff to dep repo?
string http_route = 50005; string http_route = 50005;
MethodQueryOptions query = 50006; MethodQueryOptions query = 50006;
bool nostr = 50007; bool nostr = 50007;
bool batch = 50008;
} }
@ -315,5 +316,12 @@ service LightningPub {
option (http_route) = "/api/user/migrations/sub"; option (http_route) = "/api/user/migrations/sub";
option (nostr) = true; option (nostr) = true;
} }
rpc BatchUser(structs.Empty) returns (structs.Empty){
option (auth_type) = "User";
option (http_method) = "post";
option (http_route) = "/api/user/batch";
option (nostr) = true;
option (batch) = true;
}
// </User> // </User>
} }

View file

@ -10,8 +10,6 @@ const serverOptions = (mainHandler: Main): ServerOptions => {
AppAuthGuard: async (authHeader) => { return { app_id: mainHandler.applicationManager.DecodeAppToken(stripBearer(authHeader)) } }, AppAuthGuard: async (authHeader) => { return { app_id: mainHandler.applicationManager.DecodeAppToken(stripBearer(authHeader)) } },
UserAuthGuard: async (authHeader) => { return mainHandler.appUserManager.DecodeUserToken(stripBearer(authHeader)) }, UserAuthGuard: async (authHeader) => { return mainHandler.appUserManager.DecodeUserToken(stripBearer(authHeader)) },
GuestAuthGuard: async (_) => ({}), GuestAuthGuard: async (_) => ({}),
encryptCallback: async (_, b) => b,
decryptCallback: async (_, b) => b,
//throwErrors: true //throwErrors: true
} }
} }

View file

@ -355,7 +355,7 @@ export default class {
return { pub: p[0], eventId: e.length > 0 ? e[0] : "", relays, description: event } return { pub: p[0], eventId: e.length > 0 ? e[0] : "", relays, description: event }
} }
async HandleLnurlPay(ctx: Types.HandleLnurlPay_Context): Promise<Types.HandleLnurlPayResponse> { async HandleLnurlPay(ctx: Types.HandleLnurlPay_Query): Promise<Types.HandleLnurlPayResponse> {
if (!ctx.k1 || !ctx.amount) { if (!ctx.k1 || !ctx.amount) {
throw new Error("invalid lnurl pay to handle") throw new Error("invalid lnurl pay to handle")
} }
@ -392,8 +392,8 @@ export default class {
} }
} }
async HandleLnurlAddress(ctx: Types.HandleLnurlAddress_Context): Promise<Types.LnurlPayInfoResponse> { async HandleLnurlAddress(addressName: string): Promise<Types.LnurlPayInfoResponse> {
const linkedUser = await this.storage.applicationStorage.FindNostrAppUser(ctx.address_name) const linkedUser = await this.storage.applicationStorage.FindNostrAppUser(addressName)
if (!linkedUser) { if (!linkedUser) {
throw new Error("this address is not linked to any user") throw new Error("this address is not linked to any user")
} }

View file

@ -3,24 +3,24 @@ import { getLogger } from '../helpers/logger.js'
import Main from '../main/index.js' import Main from '../main/index.js'
export default (mainHandler: Main): Types.ServerMethods => { export default (mainHandler: Main): Types.ServerMethods => {
return { return {
EncryptionExchange: async (ctx, req) => { }, EncryptionExchange: async () => { },
Health: async (ctx) => { await mainHandler.lnd.Health() }, Health: async () => { await mainHandler.lnd.Health() },
LndGetInfo: async (ctx) => { LndGetInfo: async ({ ctx }) => {
const info = await mainHandler.lnd.GetInfo() const info = await mainHandler.lnd.GetInfo()
return { alias: info.alias } return { alias: info.alias }
}, },
SetMockInvoiceAsPaid: async (ctx, req) => { SetMockInvoiceAsPaid: async ({ ctx, req }) => {
const err = Types.SetMockInvoiceAsPaidRequestValidate(req, { const err = Types.SetMockInvoiceAsPaidRequestValidate(req, {
invoice_CustomCheck: invoice => invoice !== '', invoice_CustomCheck: invoice => invoice !== '',
}) })
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)
}, },
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)
}, },
OpenChannel: async (ctx, req) => { OpenChannel: async ({ ctx, req }) => {
const err = Types.OpenChannelRequestValidate(req, { const err = Types.OpenChannelRequestValidate(req, {
fundingAmount_CustomCheck: amt => amt > 0, fundingAmount_CustomCheck: amt => amt > 0,
pushAmount_CustomCheck: amt => amt > 0, pushAmount_CustomCheck: amt => amt > 0,
@ -29,8 +29,8 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.paymentManager.OpenChannel(ctx.user_id, req) return mainHandler.paymentManager.OpenChannel(ctx.user_id, req)
}, },
NewAddress: (ctx, req) => mainHandler.paymentManager.NewAddress(ctx, req), NewAddress: ({ ctx, req }) => mainHandler.paymentManager.NewAddress(ctx, req),
PayAddress: async (ctx, req) => { PayAddress: async ({ ctx, req }) => {
const err = Types.PayAddressRequestValidate(req, { const err = Types.PayAddressRequestValidate(req, {
address_CustomCheck: addr => addr !== '', address_CustomCheck: addr => addr !== '',
amoutSats_CustomCheck: amt => amt > 0, amoutSats_CustomCheck: amt => amt > 0,
@ -39,90 +39,90 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.paymentManager.PayAddress(ctx, req) return mainHandler.paymentManager.PayAddress(ctx, req)
}, },
NewInvoice: (ctx, req) => mainHandler.appUserManager.NewInvoice(ctx, req), NewInvoice: ({ ctx, req }) => mainHandler.appUserManager.NewInvoice(ctx, req),
DecodeInvoice: async (ctx, req) => { DecodeInvoice: async ({ ctx, req }) => {
return mainHandler.paymentManager.DecodeInvoice(req) return mainHandler.paymentManager.DecodeInvoice(req)
}, },
PayInvoice: async (ctx, req) => { PayInvoice: async ({ ctx, req }) => {
const err = Types.PayInvoiceRequestValidate(req, { const err = Types.PayInvoiceRequestValidate(req, {
invoice_CustomCheck: invoice => invoice !== '' invoice_CustomCheck: invoice => invoice !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.appUserManager.PayInvoice(ctx, req) return mainHandler.appUserManager.PayInvoice(ctx, req)
}, },
GetLnurlWithdrawLink: (ctx) => mainHandler.paymentManager.GetLnurlWithdrawLink(ctx), GetLnurlWithdrawLink: ({ ctx }) => mainHandler.paymentManager.GetLnurlWithdrawLink(ctx),
GetLnurlWithdrawInfo: async (ctx) => { GetLnurlWithdrawInfo: async ({ ctx, query }) => {
if (!ctx.k1) { if (!query.k1) {
throw new Error("invalid lnurl withdraw to get info") throw new Error("invalid lnurl withdraw to get info")
} }
return mainHandler.paymentManager.GetLnurlWithdrawInfo(ctx.k1) return mainHandler.paymentManager.GetLnurlWithdrawInfo(query.k1)
}, },
HandleLnurlWithdraw: async (ctx) => { HandleLnurlWithdraw: async ({ query }) => {
if (!ctx.k1 || !ctx.pr) { if (!query.k1 || !query.pr) {
throw new Error("invalid lnurl withdraw to handle") throw new Error("invalid lnurl withdraw to handle")
} }
return mainHandler.paymentManager.HandleLnurlWithdraw(ctx.k1, ctx.pr) return mainHandler.paymentManager.HandleLnurlWithdraw(query.k1, query.pr)
}, },
GetLnurlPayLink: (ctx) => mainHandler.paymentManager.GetLnurlPayLink(ctx), GetLnurlPayLink: ({ ctx }) => mainHandler.paymentManager.GetLnurlPayLink(ctx),
GetLnurlPayInfo: async (ctx) => { GetLnurlPayInfo: async ({ ctx, query }) => {
if (!ctx.k1) { if (!query.k1) {
throw new Error("invalid lnurl pay to get info") throw new Error("invalid lnurl pay to get info")
} }
return mainHandler.paymentManager.GetLnurlPayInfo(ctx.k1) return mainHandler.paymentManager.GetLnurlPayInfo(query.k1)
}, },
HandleLnurlPay: async (ctx) => { HandleLnurlPay: async ({ ctx, query }) => {
return mainHandler.paymentManager.HandleLnurlPay(ctx) return mainHandler.paymentManager.HandleLnurlPay(query)
}, },
HandleLnurlAddress: async (ctx) => { HandleLnurlAddress: async ({ ctx, params }) => {
if (!ctx.address_name) { if (!params.address_name) {
throw new Error("invalid address_name to lnurl address") throw new Error("invalid address_name to lnurl address")
} }
return mainHandler.paymentManager.HandleLnurlAddress(ctx) return mainHandler.paymentManager.HandleLnurlAddress(params.address_name)
}, },
AddProduct: async (ctx, req) => { AddProduct: async ({ ctx, req }) => {
return mainHandler.productManager.AddProduct(ctx.user_id, req) return mainHandler.productManager.AddProduct(ctx.user_id, req)
}, },
NewProductInvoice: async (ctx) => { NewProductInvoice: async ({ query }) => {
if (!ctx.id) { if (!query.id) {
throw new Error("product id must be non empty") throw new Error("product id must be non empty")
} }
return mainHandler.productManager.NewProductInvoice(ctx.id) return mainHandler.productManager.NewProductInvoice(query.id)
}, },
GetLNURLChannelLink: async (ctx) => { GetLNURLChannelLink: async ({ ctx }) => {
throw new Error("unimplemented") throw new Error("unimplemented")
}, },
AddApp: async (ctx, req) => { AddApp: async ({ ctx, req }) => {
const err = Types.AuthAppRequestValidate(req, { const err = Types.AuthAppRequestValidate(req, {
name_CustomCheck: name => name !== '' name_CustomCheck: name => name !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.AddApp(req) return mainHandler.applicationManager.AddApp(req)
}, },
AuthApp: async (ctx, req) => { AuthApp: async ({ ctx, req }) => {
const err = Types.AuthAppRequestValidate(req, { const err = Types.AuthAppRequestValidate(req, {
name_CustomCheck: name => name !== '' name_CustomCheck: name => name !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.AuthApp(req) return mainHandler.applicationManager.AuthApp(req)
}, },
GetApp: async (ctx) => { GetApp: async ({ ctx }) => {
return mainHandler.applicationManager.GetApp(ctx.app_id) return mainHandler.applicationManager.GetApp(ctx.app_id)
}, },
AddAppUser: async (ctx, req) => { AddAppUser: async ({ ctx, req }) => {
const err = Types.AddAppUserRequestValidate(req, { const err = Types.AddAppUserRequestValidate(req, {
identifier_CustomCheck: id => id !== '' identifier_CustomCheck: id => id !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.AddAppUser(ctx.app_id, req) return mainHandler.applicationManager.AddAppUser(ctx.app_id, req)
}, },
AddAppInvoice: async (ctx, req) => { AddAppInvoice: async ({ ctx, req }) => {
const err = Types.AddAppInvoiceRequestValidate(req, { const err = Types.AddAppInvoiceRequestValidate(req, {
payer_identifier_CustomCheck: id => id !== '', payer_identifier_CustomCheck: id => id !== '',
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.AddAppInvoice(ctx.app_id, req) return mainHandler.applicationManager.AddAppInvoice(ctx.app_id, req)
}, },
AddAppUserInvoice: async (ctx, req) => { AddAppUserInvoice: async ({ ctx, req }) => {
const err = Types.AddAppUserInvoiceRequestValidate(req, { const err = Types.AddAppUserInvoiceRequestValidate(req, {
payer_identifier_CustomCheck: id => id !== '', payer_identifier_CustomCheck: id => id !== '',
receiver_identifier_CustomCheck: id => id !== '', receiver_identifier_CustomCheck: id => id !== '',
@ -130,21 +130,21 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.AddAppUserInvoice(ctx.app_id, req) return mainHandler.applicationManager.AddAppUserInvoice(ctx.app_id, req)
}, },
GetAppUser: async (ctx, req) => { GetAppUser: async ({ ctx, req }) => {
const err = Types.GetAppUserRequestValidate(req, { const err = Types.GetAppUserRequestValidate(req, {
user_identifier_CustomCheck: id => id !== '', user_identifier_CustomCheck: id => id !== '',
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.GetAppUser(ctx.app_id, req) return mainHandler.applicationManager.GetAppUser(ctx.app_id, req)
}, },
PayAppUserInvoice: async (ctx, req) => { PayAppUserInvoice: async ({ ctx, req }) => {
const err = Types.PayAppUserInvoiceRequestValidate(req, { const err = Types.PayAppUserInvoiceRequestValidate(req, {
user_identifier_CustomCheck: id => id !== '', user_identifier_CustomCheck: id => id !== '',
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.PayAppUserInvoice(ctx.app_id, req) return mainHandler.applicationManager.PayAppUserInvoice(ctx.app_id, req)
}, },
SendAppUserToAppUserPayment: async (ctx, req) => { SendAppUserToAppUserPayment: async ({ ctx, req }) => {
const err = Types.SendAppUserToAppUserPaymentRequestValidate(req, { const err = Types.SendAppUserToAppUserPaymentRequestValidate(req, {
to_user_identifier_CustomCheck: id => id !== '', to_user_identifier_CustomCheck: id => id !== '',
from_user_identifier_CustomCheck: id => id !== '', from_user_identifier_CustomCheck: id => id !== '',
@ -153,7 +153,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.applicationManager.SendAppUserToAppUserPayment(ctx.app_id, req) await mainHandler.applicationManager.SendAppUserToAppUserPayment(ctx.app_id, req)
}, },
SendAppUserToAppPayment: async (ctx, req) => { SendAppUserToAppPayment: async ({ ctx, req }) => {
const err = Types.SendAppUserToAppPaymentRequestValidate(req, { const err = Types.SendAppUserToAppPaymentRequestValidate(req, {
from_user_identifier_CustomCheck: id => id !== '', from_user_identifier_CustomCheck: id => id !== '',
amount_CustomCheck: amount => amount > 0 amount_CustomCheck: amount => amount > 0
@ -161,26 +161,26 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
await mainHandler.applicationManager.SendAppUserToAppPayment(ctx.app_id, req) await mainHandler.applicationManager.SendAppUserToAppPayment(ctx.app_id, req)
}, },
GetAppUserLNURLInfo: async (ctx, req) => { GetAppUserLNURLInfo: async ({ ctx, req }) => {
const err = Types.GetAppUserLNURLInfoRequestValidate(req, { const err = Types.GetAppUserLNURLInfoRequestValidate(req, {
user_identifier_CustomCheck: id => id !== '' user_identifier_CustomCheck: id => id !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.GetAppUserLNURLInfo(ctx.app_id, req) return mainHandler.applicationManager.GetAppUserLNURLInfo(ctx.app_id, req)
}, },
SetMockAppUserBalance: async (ctx, req) => { SetMockAppUserBalance: async ({ ctx, req }) => {
const err = Types.SetMockAppUserBalanceRequestValidate(req, { const err = Types.SetMockAppUserBalanceRequestValidate(req, {
user_identifier_CustomCheck: id => id !== '' user_identifier_CustomCheck: id => id !== ''
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
await mainHandler.applicationManager.SetMockAppUserBalance(ctx.app_id, req) await mainHandler.applicationManager.SetMockAppUserBalance(ctx.app_id, req)
}, },
SetMockAppBalance: async (ctx, req) => { SetMockAppBalance: async ({ ctx, req }) => {
await mainHandler.applicationManager.SetMockAppBalance(ctx.app_id, req) await mainHandler.applicationManager.SetMockAppBalance(ctx.app_id, req)
}, },
GetLiveUserOperations: async (ctx, cb) => { GetLiveUserOperations: async ({ ctx, cb }) => {
}, },
GetMigrationUpdate: async (ctx, cb) => { GetMigrationUpdate: async ({ ctx, cb }) => {
} }
} }
} }