default offer flag
This commit is contained in:
parent
1f5c3041bd
commit
eba8ee75e0
5 changed files with 13 additions and 4 deletions
|
|
@ -1120,6 +1120,7 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
|
|
||||||
### OfferConfig
|
### OfferConfig
|
||||||
- __callback_url__: _string_
|
- __callback_url__: _string_
|
||||||
|
- __default_offer__: _boolean_
|
||||||
- __expected_data__: MAP with key: _string_ and value: _[OfferDataType](#OfferDataType)_
|
- __expected_data__: MAP with key: _string_ and value: _[OfferDataType](#OfferDataType)_
|
||||||
- __label__: _string_
|
- __label__: _string_
|
||||||
- __noffer__: _string_
|
- __noffer__: _string_
|
||||||
|
|
|
||||||
|
|
@ -396,6 +396,7 @@ type NewInvoiceResponse struct {
|
||||||
}
|
}
|
||||||
type OfferConfig struct {
|
type OfferConfig struct {
|
||||||
Callback_url string `json:"callback_url"`
|
Callback_url string `json:"callback_url"`
|
||||||
|
Default_offer bool `json:"default_offer"`
|
||||||
Expected_data map[string]OfferDataType `json:"expected_data"`
|
Expected_data map[string]OfferDataType `json:"expected_data"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Noffer string `json:"noffer"`
|
Noffer string `json:"noffer"`
|
||||||
|
|
|
||||||
|
|
@ -2244,6 +2244,7 @@ export const NewInvoiceResponseValidate = (o?: NewInvoiceResponse, opts: NewInvo
|
||||||
|
|
||||||
export type OfferConfig = {
|
export type OfferConfig = {
|
||||||
callback_url: string
|
callback_url: string
|
||||||
|
default_offer: boolean
|
||||||
expected_data: Record<string, OfferDataType>
|
expected_data: Record<string, OfferDataType>
|
||||||
label: string
|
label: string
|
||||||
noffer: string
|
noffer: string
|
||||||
|
|
@ -2254,6 +2255,7 @@ export const OfferConfigOptionalFields: [] = []
|
||||||
export type OfferConfigOptions = OptionsBaseMessage & {
|
export type OfferConfigOptions = OptionsBaseMessage & {
|
||||||
checkOptionalsAreSet?: []
|
checkOptionalsAreSet?: []
|
||||||
callback_url_CustomCheck?: (v: string) => boolean
|
callback_url_CustomCheck?: (v: string) => boolean
|
||||||
|
default_offer_CustomCheck?: (v: boolean) => boolean
|
||||||
expected_data_CustomCheck?: (v: Record<string, OfferDataType>) => boolean
|
expected_data_CustomCheck?: (v: Record<string, OfferDataType>) => boolean
|
||||||
label_CustomCheck?: (v: string) => boolean
|
label_CustomCheck?: (v: string) => boolean
|
||||||
noffer_CustomCheck?: (v: string) => boolean
|
noffer_CustomCheck?: (v: string) => boolean
|
||||||
|
|
@ -2267,6 +2269,9 @@ export const OfferConfigValidate = (o?: OfferConfig, opts: OfferConfigOptions =
|
||||||
if (typeof o.callback_url !== 'string') return new Error(`${path}.callback_url: is not a string`)
|
if (typeof o.callback_url !== 'string') return new Error(`${path}.callback_url: is not a string`)
|
||||||
if (opts.callback_url_CustomCheck && !opts.callback_url_CustomCheck(o.callback_url)) return new Error(`${path}.callback_url: custom check failed`)
|
if (opts.callback_url_CustomCheck && !opts.callback_url_CustomCheck(o.callback_url)) return new Error(`${path}.callback_url: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.default_offer !== 'boolean') return new Error(`${path}.default_offer: is not a boolean`)
|
||||||
|
if (opts.default_offer_CustomCheck && !opts.default_offer_CustomCheck(o.default_offer)) return new Error(`${path}.default_offer: custom check failed`)
|
||||||
|
|
||||||
if (typeof o.expected_data !== 'object' || o.expected_data === null) return new Error(`${path}.expected_data: is not an object or is null`)
|
if (typeof o.expected_data !== 'object' || o.expected_data === null) return new Error(`${path}.expected_data: is not an object or is null`)
|
||||||
for (const key in o.expected_data) {
|
for (const key in o.expected_data) {
|
||||||
if (!enumCheckOfferDataType(o.expected_data[key])) return new Error(`${path}.expected_data['${key}']: is not a OfferDataType`)
|
if (!enumCheckOfferDataType(o.expected_data[key])) return new Error(`${path}.expected_data['${key}']: is not a OfferDataType`)
|
||||||
|
|
|
||||||
|
|
@ -636,6 +636,7 @@ message OfferConfig {
|
||||||
string callback_url = 4;
|
string callback_url = 4;
|
||||||
map<string, OfferDataType> expected_data = 5;
|
map<string, OfferDataType> expected_data = 5;
|
||||||
string noffer = 6;
|
string noffer = 6;
|
||||||
|
bool default_offer = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UserOffers {
|
message UserOffers {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import { DeepPartial } from 'typeorm';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { LoadNosrtSettingsFromEnv } from '../nostr/index.js';
|
import { LoadNosrtSettingsFromEnv } from '../nostr/index.js';
|
||||||
|
|
||||||
const mapToOfferConfig = (offer: UserOffer, { pubkey, relay }: { pubkey: string, relay: string }): Types.OfferConfig => {
|
const mapToOfferConfig = (appUserId: string, offer: UserOffer, { pubkey, relay }: { pubkey: string, relay: string }): Types.OfferConfig => {
|
||||||
if (offer.expected_data) {
|
if (offer.expected_data) {
|
||||||
const keys = Object.keys(offer.expected_data)
|
const keys = Object.keys(offer.expected_data)
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
|
|
@ -37,7 +37,8 @@ const mapToOfferConfig = (offer: UserOffer, { pubkey, relay }: { pubkey: string,
|
||||||
callback_url: offer.callback_url,
|
callback_url: offer.callback_url,
|
||||||
expected_data: (offer.expected_data || {}) as Record<string, Types.OfferDataType>,
|
expected_data: (offer.expected_data || {}) as Record<string, Types.OfferDataType>,
|
||||||
offer_id: offer.offer_id,
|
offer_id: offer.offer_id,
|
||||||
noffer: noffer
|
noffer: noffer,
|
||||||
|
default_offer: appUserId === offer.app_user_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class OfferManager {
|
export class OfferManager {
|
||||||
|
|
@ -107,7 +108,7 @@ export class OfferManager {
|
||||||
throw new Error("Offer not found")
|
throw new Error("Offer not found")
|
||||||
}
|
}
|
||||||
const nostrSettings = LoadNosrtSettingsFromEnv()
|
const nostrSettings = LoadNosrtSettingsFromEnv()
|
||||||
return mapToOfferConfig(offer, { pubkey: app.npub, relay: nostrSettings.relays[0] })
|
return mapToOfferConfig(ctx.app_user_id, offer, { pubkey: app.npub, relay: nostrSettings.relays[0] })
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetUserOffers(ctx: Types.UserContext): Promise<Types.UserOffers> {
|
async GetUserOffers(ctx: Types.UserContext): Promise<Types.UserOffers> {
|
||||||
|
|
@ -118,7 +119,7 @@ export class OfferManager {
|
||||||
const offers = await this.storage.offerStorage.GetUserOffers(ctx.app_user_id)
|
const offers = await this.storage.offerStorage.GetUserOffers(ctx.app_user_id)
|
||||||
const nostrSettings = LoadNosrtSettingsFromEnv()
|
const nostrSettings = LoadNosrtSettingsFromEnv()
|
||||||
return {
|
return {
|
||||||
offers: offers.map(o => mapToOfferConfig(o, { pubkey: app.npub, relay: nostrSettings.relays[0] }))
|
offers: offers.map(o => mapToOfferConfig(ctx.app_user_id, o, { pubkey: app.npub, relay: nostrSettings.relays[0] }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue