This commit is contained in:
Mothana 2024-07-23 22:23:01 +04:00
parent e2c20eb9ac
commit 9645ac7337
11 changed files with 4849 additions and 4898 deletions

View file

@ -71,7 +71,7 @@ The nostr server will send back a message response, and inside the body there wi
- UseInviteLink - UseInviteLink
- auth type: __GuestWithPub__ - auth type: __GuestWithPub__
- input: [UseInviteLinkRequest](#UseInviteLinkRequest) - input: [UseInviteLinkRequest](#UseInviteLinkRequest)
- output: [UseInviteLinkResponse](#UseInviteLinkResponse) - This methods has an __empty__ __response__ body
- UserHealth - UserHealth
- auth type: __User__ - auth type: __User__
@ -351,7 +351,7 @@ The nostr server will send back a message response, and inside the body there wi
- http method: __post__ - http method: __post__
- http route: __/api/guest/invite__ - http route: __/api/guest/invite__
- input: [UseInviteLinkRequest](#UseInviteLinkRequest) - input: [UseInviteLinkRequest](#UseInviteLinkRequest)
- output: [UseInviteLinkResponse](#UseInviteLinkResponse) - This methods has an __empty__ __response__ body
- GetApp - GetApp
- auth type: __App__ - auth type: __App__
@ -570,144 +570,337 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### OpenChannelRequest ### AddAppUserRequest
- __destination__: _string_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### RelaysMigration
- __relays__: ARRAY of: _string_
### Empty
### DecodeInvoiceRequest
- __invoice__: _string_
### LnurlPayInfoResponse
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
- __tag__: _string_
### UserOperation
- __paidAtUnix__: _number_
- __identifier__: _string_ - __identifier__: _string_
- __network_fee__: _number_ - __fail_if_exists__: _boolean_
- __tx_hash__: _string_ - __balance__: _number_
- __internal__: _boolean_
- __type__: _[UserOperationType](#UserOperationType)_
- __inbound__: _boolean_
- __amount__: _number_
- __operationId__: _string_
- __service_fee__: _number_
- __confirmed__: _boolean_
### Product ### GetProductBuyLinkResponse
- __price_sats__: _number_ - __link__: _string_
- __id__: _string_
- __name__: _string_
### UsageMetric ### CreateOneTimeInviteLinkResponse
- __processed_at_ms__: _number_ - __invitation_link__: _string_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_ ### AppMetrics
- __validate_in_nano__: _number_ - __users__: _[UsersInfo](#UsersInfo)_
- __handle_in_nano__: _number_ - __fees__: _number_
- __rpc_name__: _string_ - __total_fees__: _number_
- __batch__: _boolean_ - __app__: _[Application](#Application)_
- __nostr__: _boolean_ - __spent__: _number_
- __batch_size__: _number_ - __available__: _number_
- __invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
- __received__: _number_
### AddAppInvoiceRequest ### AddAppInvoiceRequest
- __payer_identifier__: _string_ - __payer_identifier__: _string_
- __http_callback_url__: _string_ - __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_ - __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### NewAddressResponse ### NewInvoiceResponse
- __invoice__: _string_
### EnrollAdminTokenRequest
- __admin_token__: _string_
### GetInviteTokenStateRequest
- __invite_token__: _string_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### GetAppUserLNURLInfoRequest
- __base_url_override__: _string_
- __user_identifier__: _string_
### PayAddressRequest
- __address__: _string_ - __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### UserOperations
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
- __fromIndex__: _number_
- __toIndex__: _number_
### RequestNPubLinkingTokenRequest ### RequestNPubLinkingTokenRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
### CreateOneTimeInviteLinkRequest ### UseInviteLinkRequest
- __sats__: _number_ *this field is optional - __invite_token__: _string_
### CreateOneTimeInviteLinkResponse ### UsersInfo
- __invitation_link__: _string_ - __balance_median__: _number_
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
### Application ### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### GetAppUserRequest
- __user_identifier__: _string_
### NewAddressResponse
- __address__: _string_
### OpenChannelResponse
- __channelId__: _string_
### AddProductRequest
- __name__: _string_ - __name__: _string_
- __id__: _string_ - __price_sats__: _number_
- __balance__: _number_
- __npub__: _string_ ### AppsMetricsRequest
- __include_operations__: _boolean_ *this field is optional
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
- __max_size__: _number_
### UserOperation
- __type__: _[UserOperationType](#UserOperationType)_
- __operationId__: _string_
- __tx_hash__: _string_
- __internal__: _boolean_
- __paidAtUnix__: _number_
- __inbound__: _boolean_
- __amount__: _number_
- __identifier__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
### RequestNPubLinkingTokenResponse
- __token__: _string_
### BanUserResponse
- __balance_sats__: _number_
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
### SendAppUserToAppPaymentRequest ### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_ - __from_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### OpenChannelResponse ### AuthAppRequest
- __channelId__: _string_ - __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### GetInviteTokenStateRequest
- __invite_token__: _string_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### NewAddressRequest ### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_ - __addressType__: _[AddressType](#AddressType)_
### RequestNPubLinkingTokenResponse ### PayInvoiceResponse
- __token__: _string_ - __network_fee__: _number_
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
### LinkNPubThroughTokenRequest ### LiveUserOperation
- __token__: _string_ - __operation__: _[UserOperation](#UserOperation)_
- __nostr_pub__: _string_
### HttpCreds ### ClosureMigration
- __url__: _string_ - __closes_at_unix__: _number_
- __token__: _string_
### LndMetrics ### GetInviteTokenStateResponse
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_ - __used__: _boolean_
### RoutingEvent
- __outgoing_amt_msat__: _number_
- __failure_string__: _string_
- __incoming_htlc_id__: _number_
- __outgoing_htlc_id__: _number_
- __event_type__: _string_
- __incoming_amt_msat__: _number_
- __offchain__: _boolean_
- __forward_fail_event__: _boolean_
- __incoming_channel_id__: _number_
- __outgoing_channel_id__: _number_
- __timestamp_ns__: _number_
- __settled__: _boolean_
### LndGetInfoResponse
- __alias__: _string_
### CreateOneTimeInviteLinkRequest
- __sats__: _number_ *this field is optional
### Empty
### GetUserOperationsResponse
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### PayInvoiceRequest ### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### RoutingEvent ### LnurlPayInfoResponse
- __incoming_htlc_id__: _number_ - __nostrPubkey__: _string_
- __outgoing_channel_id__: _number_ - __tag__: _string_
- __outgoing_htlc_id__: _number_ - __callback__: _string_
- __event_type__: _string_ - __maxSendable__: _number_
- __settled__: _boolean_ - __minSendable__: _number_
- __offchain__: _boolean_ - __metadata__: _string_
- __forward_fail_event__: _boolean_ - __allowsNostr__: _boolean_
- __incoming_channel_id__: _number_
- __timestamp_ns__: _number_
- __incoming_amt_msat__: _number_
- __outgoing_amt_msat__: _number_
- __failure_string__: _string_
### GetProductBuyLinkResponse ### RelaysMigration
- __link__: _string_ - __relays__: ARRAY of: _string_
### AuthAppRequest ### BannedAppUser
- __allow_user_creation__: _boolean_ *this field is optional - __user_identifier__: _string_
- __nostr_pub__: _string_
- __app_name__: _string_
- __app_id__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### BanUserRequest
- __user_id__: _string_
### DecodeInvoiceResponse
- __amount__: _number_
### OpenChannelRequest
- __pushAmount__: _number_
- __closeAddress__: _string_
- __destination__: _string_
- __fundingAmount__: _number_
### Product
- __price_sats__: _number_
- __id__: _string_
- __name__: _string_ - __name__: _string_
### SetMockAppUserBalanceRequest ### MigrationUpdate
- __user_identifier__: _string_ - __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### UsageMetric
- __processed_at_ms__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __nostr__: _boolean_
- __batch_size__: _number_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### LndNodeMetrics
- __closing_channels__: _number_
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __pending_channels__: _number_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### DecodeInvoiceRequest
- __invoice__: _string_
### LnurlWithdrawInfoResponse
- __payLink__: _string_
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
### LinkNPubThroughTokenRequest
- __token__: _string_
- __nostr_pub__: _string_
### Application
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
- __name__: _string_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### LndGetInfoRequest
- __nodeId__: _number_
### SetMockAppBalanceRequest
- __amount__: _number_ - __amount__: _number_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### UserInfo ### UserInfo
- __userId__: _string_ - __userId__: _string_
- __balance__: _number_ - __balance__: _number_
@ -717,245 +910,49 @@ The nostr server will send back a message response, and inside the body there wi
- __network_max_fee_bps__: _number_ - __network_max_fee_bps__: _number_
- __network_max_fee_fixed__: _number_ - __network_max_fee_fixed__: _number_
### GetUserOperationsResponse ### HttpCreds
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_ - __url__: _string_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_ - __token__: _string_
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
### AppsMetricsRequest ### AppsMetrics
- __from_unix__: _number_ *this field is optional - __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### OpenChannel ### LndMetrics
- __remote_balance__: _number_ - __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### ChannelRouting
- __forward_errors_as_input__: _number_
- __missed_forward_fee_as_input__: _number_
- __forward_fee_as_output__: _number_
- __channel_id__: _string_ - __channel_id__: _string_
- __capacity__: _number_ - __send_errors__: _number_
- __active__: _boolean_ - __missed_forward_fee_as_output__: _number_
- __lifetime__: _number_ - __forward_fee_as_input__: _number_
- __local_balance__: _number_ - __events_number__: _number_
- __receive_errors__: _number_
- __forward_errors_as_output__: _number_
### AddAppRequest ### AddAppRequest
- __name__: _string_ - __name__: _string_
- __allow_user_creation__: _boolean_ - __allow_user_creation__: _boolean_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### AddAppUserInvoiceRequest
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### GetInviteTokenStateResponse
- __used__: _boolean_
### EncryptionExchangeRequest
- __deviceId__: _string_
- __publicKey__: _string_
### LndGetInfoRequest
- __nodeId__: _number_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### PayInvoiceResponse
- __network_fee__: _number_
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
### GetAppUserRequest
- __user_identifier__: _string_
### NewInvoiceResponse
- __invoice__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### EnrollAdminTokenRequest
- __admin_token__: _string_
### SendAppUserToAppUserPaymentRequest ### SendAppUserToAppUserPaymentRequest
- __from_user_identifier__: _string_ - __from_user_identifier__: _string_
- __to_user_identifier__: _string_ - __to_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### PayAddressResponse ### OpenChannel
- __txId__: _string_ - __local_balance__: _number_
- __operation_id__: _string_ - __remote_balance__: _number_
- __service_fee__: _number_
- __network_fee__: _number_
### LndGetInfoResponse
- __alias__: _string_
### BannedAppUser
- __nostr_pub__: _string_
- __app_name__: _string_
- __app_id__: _string_
- __user_identifier__: _string_
### BanUserResponse
- __balance_sats__: _number_
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### UseInviteLinkResponse
- __nostr_secret__: _string_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### ChannelBalanceEvent
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
- __block_height__: _number_
- __channel_id__: _string_ - __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
### BanUserRequest ### ClosedChannel
- __user_id__: _string_
### LnurlWithdrawInfoResponse
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
- __payLink__: _string_
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
### AppMetrics
- __spent__: _number_
- __available__: _number_
- __total_fees__: _number_
- __users__: _[UsersInfo](#UsersInfo)_
- __received__: _number_
- __invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
- __app__: _[Application](#Application)_
- __fees__: _number_
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### GetUserOperationsRequest
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
- __max_size__: _number_
- __latestIncomingInvoice__: _number_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### UsersInfo
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
- __total__: _number_
- __no_balance__: _number_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### SetMockAppBalanceRequest
- __amount__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### LndNodeMetrics
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### UseInviteLinkRequest
- __invite_token__: _string_
### ChannelRouting
- __missed_forward_fee_as_output__: _number_
- __channel_id__: _string_ - __channel_id__: _string_
- __forward_errors_as_output__: _number_ - __capacity__: _number_
- __forward_errors_as_input__: _number_ - __closed_height__: _number_
- __missed_forward_fee_as_input__: _number_
- __forward_fee_as_input__: _number_
- __forward_fee_as_output__: _number_
- __events_number__: _number_
- __send_errors__: _number_
- __receive_errors__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __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

@ -447,9 +447,9 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
const query = req.query const query = req.query
const params = req.params const params = req.params
const response = await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request}) await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request})
stats.handle = process.hrtime.bigint() stats.handle = process.hrtime.bigint()
res.json({status: 'OK', ...response}) res.json({status: 'OK'})
opts.metricsCallback([{ ...info, ...stats, ...authContext }]) opts.metricsCallback([{ ...info, ...stats, ...authContext }])
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
}) })

View file

@ -274,17 +274,14 @@ export default (params: ClientParams) => ({
} }
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' }& Types.UseInviteLinkResponse)> => { UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveGuestWithPubAuth() const auth = await params.retrieveGuestWithPubAuth()
if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null') if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null')
let finalRoute = '/api/guest/invite' let finalRoute = '/api/guest/invite'
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } }) const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') { if (data.status === 'OK') {
const result = data return data
if(!params.checkResult) return { status: 'OK', ...result }
const error = Types.UseInviteLinkResponseValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
} }
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },

View file

@ -5,10 +5,10 @@ export type ResultError = { status: 'ERROR', reason: string }
export type NostrClientParams = { export type NostrClientParams = {
pubDestination: string pubDestination: string
retrieveNostrGuestWithPubAuth: () => Promise<string | null>
retrieveNostrAdminAuth: () => Promise<string | null> retrieveNostrAdminAuth: () => Promise<string | null>
retrieveNostrMetricsAuth: () => Promise<string | null> retrieveNostrMetricsAuth: () => Promise<string | null>
retrieveNostrUserAuth: () => Promise<string | null> retrieveNostrUserAuth: () => Promise<string | null>
retrieveNostrGuestWithPubAuth: () => Promise<string | null>
checkResult?: true checkResult?: true
} }
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({ export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({
@ -170,7 +170,7 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
} }
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' }& Types.UseInviteLinkResponse)> => { UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrGuestWithPubAuth() const auth = await params.retrieveNostrGuestWithPubAuth()
if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null') if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null')
const nostrRequest: NostrRequest = {} const nostrRequest: NostrRequest = {}
@ -178,10 +178,7 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
const data = await send(params.pubDestination, {rpcName:'UseInviteLink',authIdentifier:auth, ...nostrRequest }) const data = await send(params.pubDestination, {rpcName:'UseInviteLink',authIdentifier:auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') { if (data.status === 'OK') {
const result = data return data
if(!params.checkResult) return { status: 'OK', ...result }
const error = Types.UseInviteLinkResponseValidate(result)
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
} }
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },

View file

@ -215,9 +215,9 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
const error = Types.UseInviteLinkRequestValidate(request) const error = Types.UseInviteLinkRequestValidate(request)
stats.validate = process.hrtime.bigint() stats.validate = process.hrtime.bigint()
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
const response = await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request}) await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request})
stats.handle = process.hrtime.bigint() stats.handle = process.hrtime.bigint()
res({status: 'OK', ...response}) res({status: 'OK'})
opts.metricsCallback([{ ...info, ...stats, ...authContext }]) opts.metricsCallback([{ ...info, ...stats, ...authContext }])
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
break break

File diff suppressed because it is too large Load diff

View file

@ -232,7 +232,7 @@ service LightningPub {
option (nostr) = true; option (nostr) = true;
} }
rpc UseInviteLink(structs.UseInviteLinkRequest) returns (structs.UseInviteLinkResponse) { rpc UseInviteLink(structs.UseInviteLinkRequest) returns (structs.Empty) {
option (auth_type) = "GuestWithPub"; option (auth_type) = "GuestWithPub";
option (http_method) = "post"; option (http_method) = "post";
option (http_route) = "/api/guest/invite"; option (http_route) = "/api/guest/invite";

View file

@ -467,9 +467,6 @@ message UseInviteLinkRequest {
string invite_token = 1; string invite_token = 1;
} }
message UseInviteLinkResponse {
string nostr_secret = 1;
}
message GetInviteTokenStateRequest { message GetInviteTokenStateRequest {
string invite_token = 1; string invite_token = 1;

View file

@ -8,7 +8,6 @@ import { ApplicationUser } from '../storage/entity/ApplicationUser.js'
import { PubLogger, getLogger } from '../helpers/logger.js' import { PubLogger, getLogger } from '../helpers/logger.js'
import crypto from 'crypto' import crypto from 'crypto'
import { Application } from '../storage/entity/Application.js' import { Application } from '../storage/entity/Application.js'
import { generatePrivateKey, getPublicKey } from '../nostr/tools/keys.js'
const TOKEN_EXPIRY_TIME = 2 * 60 * 1000 // 2 minutes, in milliseconds const TOKEN_EXPIRY_TIME = 2 * 60 * 1000 // 2 minutes, in milliseconds
@ -260,18 +259,14 @@ export default class {
} }
} }
async UseInviteLink(ctx: Types.GuestWithPubContext, req: Types.UseInviteLinkRequest): Promise<Types.UseInviteLinkResponse> { async UseInviteLink(ctx: Types.GuestWithPubContext, req: Types.UseInviteLinkRequest): Promise<void> {
const app = await this.storage.applicationStorage.GetApplication(ctx.app_id); const app = await this.storage.applicationStorage.GetApplication(ctx.app_id);
const inviteToken = await this.storage.applicationStorage.FindInviteToken(req.invite_token); const inviteToken = await this.storage.applicationStorage.FindInviteToken(req.invite_token);
if (!inviteToken || inviteToken.used || inviteToken.application.app_id !== ctx.app_id) { if (!inviteToken || inviteToken.used || inviteToken.application.app_id !== ctx.app_id) {
throw new Error("Invite token not found"); throw new Error("Invite token not found");
} }
const nostrPriv = generatePrivateKey(); await this.storage.applicationStorage.AddApplicationUser(app, crypto.randomBytes(32).toString('hex'), 0, ctx.pub)
const nostrPub = getPublicKey(nostrPriv);
const appUser = await this.storage.applicationStorage.AddApplicationUser(app, crypto.randomBytes(32).toString('hex'), 0, nostrPub)
await this.storage.applicationStorage.SetInviteTokenAsUsed(inviteToken); await this.storage.applicationStorage.SetInviteTokenAsUsed(inviteToken);
return {
nostr_secret: nostrPriv
}
} }
} }

View file

@ -173,7 +173,9 @@ export default class {
async AddInviteToken(app: Application, sats?: number) { async AddInviteToken(app: Application, sats?: number) {
return this.DB.transaction(async tx => { return this.txQueue.PushToQueue({
dbTx: true,
exec:async tx => {
const inviteRepo = tx.getRepository(InviteToken); const inviteRepo = tx.getRepository(InviteToken);
const newInviteToken = inviteRepo.create({ const newInviteToken = inviteRepo.create({
inviteToken: crypto.randomBytes(32).toString('hex'), inviteToken: crypto.randomBytes(32).toString('hex'),
@ -183,6 +185,7 @@ export default class {
}); });
return inviteRepo.save(newInviteToken) return inviteRepo.save(newInviteToken)
}
}) })
} }
@ -192,8 +195,7 @@ export default class {
async SetInviteTokenAsUsed(inviteToken: InviteToken) { async SetInviteTokenAsUsed(inviteToken: InviteToken) {
return this.DB.transaction(async tx => { return this.DB.getRepository(InviteToken).update(inviteToken, { used: true });
return tx.getRepository(InviteToken).update(inviteToken, { used: true });
})
} }
} }