nip69 server

This commit is contained in:
boufni95 2024-08-31 15:04:55 +00:00
parent 8e18e67995
commit 747bce3cf1
9 changed files with 130 additions and 37 deletions

View file

@ -652,6 +652,7 @@ The nostr server will send back a message response, and inside the body there wi
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
- __noffer__: _string_
### Application
- __balance__: _number_
@ -897,6 +898,7 @@ The nostr server will send back a message response, and inside the body there wi
### Product
- __id__: _string_
- __name__: _string_
- __noffer__: _string_
- __price_sats__: _number_
### RelaysMigration

View file

@ -510,6 +510,7 @@ export type AppUser = {
identifier: string
info: UserInfo
max_withdrawable: number
noffer: string
}
export const AppUserOptionalFields: [] = []
export type AppUserOptions = OptionsBaseMessage & {
@ -517,6 +518,7 @@ export type AppUserOptions = OptionsBaseMessage & {
identifier_CustomCheck?: (v: string) => boolean
info_Options?: UserInfoOptions
max_withdrawable_CustomCheck?: (v: number) => boolean
noffer_CustomCheck?: (v: string) => boolean
}
export const AppUserValidate = (o?: AppUser, opts: AppUserOptions = {}, path: string = 'AppUser::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
@ -532,6 +534,9 @@ export const AppUserValidate = (o?: AppUser, opts: AppUserOptions = {}, path: st
if (typeof o.max_withdrawable !== 'number') return new Error(`${path}.max_withdrawable: is not a number`)
if (opts.max_withdrawable_CustomCheck && !opts.max_withdrawable_CustomCheck(o.max_withdrawable)) return new Error(`${path}.max_withdrawable: custom check failed`)
if (typeof o.noffer !== 'string') return new Error(`${path}.noffer: is not a string`)
if (opts.noffer_CustomCheck && !opts.noffer_CustomCheck(o.noffer)) return new Error(`${path}.noffer: custom check failed`)
return null
}
@ -1977,6 +1982,7 @@ export const PaymentStateValidate = (o?: PaymentState, opts: PaymentStateOptions
export type Product = {
id: string
name: string
noffer: string
price_sats: number
}
export const ProductOptionalFields: [] = []
@ -1984,6 +1990,7 @@ export type ProductOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
id_CustomCheck?: (v: string) => boolean
name_CustomCheck?: (v: string) => boolean
noffer_CustomCheck?: (v: string) => boolean
price_sats_CustomCheck?: (v: number) => boolean
}
export const ProductValidate = (o?: Product, opts: ProductOptions = {}, path: string = 'Product::root.'): Error | null => {
@ -1996,6 +2003,9 @@ export const ProductValidate = (o?: Product, opts: ProductOptions = {}, path: st
if (typeof o.name !== 'string') return new Error(`${path}.name: is not a string`)
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
if (typeof o.noffer !== 'string') return new Error(`${path}.noffer: is not a string`)
if (opts.noffer_CustomCheck && !opts.noffer_CustomCheck(o.noffer)) return new Error(`${path}.noffer: custom check failed`)
if (typeof o.price_sats !== 'number') return new Error(`${path}.price_sats: is not a number`)
if (opts.price_sats_CustomCheck && !opts.price_sats_CustomCheck(o.price_sats)) return new Error(`${path}.price_sats: custom check failed`)