fix payment stream

This commit is contained in:
boufni95 2025-11-24 18:41:19 +00:00
parent e4033d4159
commit f7c26ee38a
17 changed files with 90 additions and 327 deletions

View file

@ -275,11 +275,6 @@ The nostr server will send back a message response, and inside the body there wi
- input: [PayInvoiceRequest](#PayInvoiceRequest)
- output: [PayInvoiceResponse](#PayInvoiceResponse)
- PayInvoiceStream
- auth type: __User__
- input: [PayInvoiceRequest](#PayInvoiceRequest)
- output: [InvoicePaymentStream](#InvoicePaymentStream)
- PingSubProcesses
- auth type: __Metrics__
- This methods has an __empty__ __request__ body
@ -865,13 +860,6 @@ The nostr server will send back a message response, and inside the body there wi
- input: [PayInvoiceRequest](#PayInvoiceRequest)
- output: [PayInvoiceResponse](#PayInvoiceResponse)
- PayInvoiceStream
- auth type: __User__
- http method: __post__
- http route: __/api/user/invoice/pay/stream__
- input: [PayInvoiceRequest](#PayInvoiceRequest)
- output: [InvoicePaymentStream](#InvoicePaymentStream)
- PingSubProcesses
- auth type: __Metrics__
- http method: __post__
@ -1280,9 +1268,6 @@ The nostr server will send back a message response, and inside the body there wi
- __token__: _string_
- __url__: _string_
### InvoicePaymentStream
- __update__: _[InvoicePaymentStream_update](#InvoicePaymentStream_update)_
### LatestBundleMetricReq
- __limit__: _number_ *this field is optional

View file

@ -121,7 +121,6 @@ type Client struct {
PayAddress func(req PayAddressRequest) (*PayAddressResponse, error)
PayAppUserInvoice func(req PayAppUserInvoiceRequest) (*PayInvoiceResponse, error)
PayInvoice func(req PayInvoiceRequest) (*PayInvoiceResponse, error)
PayInvoiceStream func(req PayInvoiceRequest) (*InvoicePaymentStream, error)
PingSubProcesses func() error
RequestNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
ResetDebit func(req DebitOperation) error
@ -1836,7 +1835,6 @@ func NewClient(params ClientParams) *Client {
}
return &res, nil
},
// server streaming method: PayInvoiceStream not implemented
PingSubProcesses: func() error {
auth, err := params.RetrieveMetricsAuth()
if err != nil {

View file

@ -353,9 +353,6 @@ type HttpCreds struct {
Token string `json:"token"`
Url string `json:"url"`
}
type InvoicePaymentStream struct {
Update *InvoicePaymentStream_update `json:"update"`
}
type LatestBundleMetricReq struct {
Limit int64 `json:"limit"`
}
@ -770,18 +767,6 @@ type DebitRule_rule struct {
Expiration_rule *DebitExpirationRule `json:"expiration_rule"`
Frequency_rule *FrequencyRule `json:"frequency_rule"`
}
type InvoicePaymentStream_update_type string
const (
ACK InvoicePaymentStream_update_type = "ack"
DONE InvoicePaymentStream_update_type = "done"
)
type InvoicePaymentStream_update struct {
Type InvoicePaymentStream_update_type `json:"type"`
Ack *Empty `json:"ack"`
Done *PayInvoiceResponse `json:"done"`
}
type LiveDebitRequest_debit_type string
const (

View file

@ -881,7 +881,6 @@ export default (params: ClientParams) => ({
}
return { status: 'ERROR', reason: 'invalid response' }
},
PayInvoiceStream: async (request: Types.PayInvoiceRequest, cb: (v:ResultError | ({ status: 'OK' }& Types.InvoicePaymentStream)) => void): Promise<void> => { throw new Error('http streams are not supported')},
PingSubProcesses: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveMetricsAuth()
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')

View file

@ -755,22 +755,6 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
}
return { status: 'ERROR', reason: 'invalid response' }
},
PayInvoiceStream: async (request: Types.PayInvoiceRequest, cb: (res:ResultError | ({ status: 'OK' }& Types.InvoicePaymentStream)) => void): Promise<void> => {
const auth = await params.retrieveNostrUserAuth()
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
const nostrRequest: NostrRequest = {}
nostrRequest.body = request
subscribe(params.pubDestination, {rpcName:'PayInvoiceStream',authIdentifier:auth, ...nostrRequest }, (data) => {
if (data.status === 'ERROR' && typeof data.reason === 'string') return cb(data)
if (data.status === 'OK') {
const result = data
if(!params.checkResult) return cb({ status: 'OK', ...result })
const error = Types.InvoicePaymentStreamValidate(result)
if (error === null) { return cb({ status: 'OK', ...result }) } else return cb({ status: 'ERROR', reason: error.message })
}
return cb({ status: 'ERROR', reason: 'invalid response' })
})
},
PingSubProcesses: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrMetricsAuth()
if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')

View file

@ -1190,22 +1190,6 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
break
case 'PayInvoiceStream':
try {
if (!methods.PayInvoiceStream) throw new Error('method: PayInvoiceStream is not implemented')
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
stats.guard = process.hrtime.bigint()
authCtx = authContext
const request = req.body
const error = Types.PayInvoiceRequestValidate(request)
stats.validate = process.hrtime.bigint()
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
methods.PayInvoiceStream({rpcName:'PayInvoiceStream', ctx:authContext , req: request ,cb: (response, err) => {
stats.handle = process.hrtime.bigint()
if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({status: 'OK', ...response});opts.metricsCallback([{ ...info, ...stats, ...authContext }])}
}})
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
break
case 'PingSubProcesses':
try {
if (!methods.PingSubProcesses) throw new Error('method: PingSubProcesses is not implemented')

View file

@ -262,9 +262,6 @@ export type PayAppUserInvoice_Output = ResultError | ({ status: 'OK' } & PayInvo
export type PayInvoice_Input = {rpcName:'PayInvoice', req: PayInvoiceRequest}
export type PayInvoice_Output = ResultError | ({ status: 'OK' } & PayInvoiceResponse)
export type PayInvoiceStream_Input = {rpcName:'PayInvoiceStream', req: PayInvoiceRequest, cb:(res: InvoicePaymentStream, err:Error|null)=> void}
export type PayInvoiceStream_Output = ResultError | { status: 'OK' }
export type PingSubProcesses_Input = {rpcName:'PingSubProcesses'}
export type PingSubProcesses_Output = ResultError | { status: 'OK' }
@ -392,7 +389,6 @@ export type ServerMethods = {
PayAddress?: (req: PayAddress_Input & {ctx: UserContext }) => Promise<PayAddressResponse>
PayAppUserInvoice?: (req: PayAppUserInvoice_Input & {ctx: AppContext }) => Promise<PayInvoiceResponse>
PayInvoice?: (req: PayInvoice_Input & {ctx: UserContext }) => Promise<PayInvoiceResponse>
PayInvoiceStream?: (req: PayInvoiceStream_Input & {ctx: UserContext }) => Promise<void>
PingSubProcesses?: (req: PingSubProcesses_Input & {ctx: MetricsContext }) => Promise<void>
RequestNPubLinkingToken?: (req: RequestNPubLinkingToken_Input & {ctx: AppContext }) => Promise<RequestNPubLinkingTokenResponse>
ResetDebit?: (req: ResetDebit_Input & {ctx: UserContext }) => Promise<void>
@ -2054,25 +2050,6 @@ export const HttpCredsValidate = (o?: HttpCreds, opts: HttpCredsOptions = {}, pa
return null
}
export type InvoicePaymentStream = {
update: InvoicePaymentStream_update
}
export const InvoicePaymentStreamOptionalFields: [] = []
export type InvoicePaymentStreamOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
update_Options?: InvoicePaymentStream_updateOptions
}
export const InvoicePaymentStreamValidate = (o?: InvoicePaymentStream, opts: InvoicePaymentStreamOptions = {}, path: string = 'InvoicePaymentStream::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
const updateErr = InvoicePaymentStream_updateValidate(o.update, opts.update_Options, `${path}.update`)
if (updateErr !== null) return updateErr
return null
}
export type LatestBundleMetricReq = {
limit?: number
}
@ -4435,43 +4412,6 @@ export const DebitRule_ruleValidate = (o?: DebitRule_rule, opts:DebitRule_ruleOp
if (frequency_ruleErr !== null) return frequency_ruleErr
break
default:
return new Error(path + ': unknown type '+ stringType)
}
return null
}
export enum InvoicePaymentStream_update_type {
ACK = 'ack',
DONE = 'done',
}
export const enumCheckInvoicePaymentStream_update_type = (e?: InvoicePaymentStream_update_type): boolean => {
for (const v in InvoicePaymentStream_update_type) if (e === v) return true
return false
}
export type InvoicePaymentStream_update =
{type:InvoicePaymentStream_update_type.ACK, ack:Empty}|
{type:InvoicePaymentStream_update_type.DONE, done:PayInvoiceResponse}
export type InvoicePaymentStream_updateOptions = {
ack_Options?: EmptyOptions
done_Options?: PayInvoiceResponseOptions
}
export const InvoicePaymentStream_updateValidate = (o?: InvoicePaymentStream_update, opts:InvoicePaymentStream_updateOptions = {}, path: string = 'InvoicePaymentStream_update::root.'): Error | null => {
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
const stringType: string = o.type
switch (o.type) {
case InvoicePaymentStream_update_type.ACK:
const ackErr = EmptyValidate(o.ack, opts.ack_Options, `${path}.ack`)
if (ackErr !== null) return ackErr
break
case InvoicePaymentStream_update_type.DONE:
const doneErr = PayInvoiceResponseValidate(o.done, opts.done_Options, `${path}.done`)
if (doneErr !== null) return doneErr
break
default:
return new Error(path + ': unknown type '+ stringType)