diff --git a/proto/autogenerated/client.md b/proto/autogenerated/client.md index 4c5b223f..b680cdbf 100644 --- a/proto/autogenerated/client.md +++ b/proto/autogenerated/client.md @@ -1120,6 +1120,7 @@ The nostr server will send back a message response, and inside the body there wi ### OfferConfig - __callback_url__: _string_ + - __default_offer__: _boolean_ - __expected_data__: MAP with key: _string_ and value: _[OfferDataType](#OfferDataType)_ - __label__: _string_ - __noffer__: _string_ diff --git a/proto/autogenerated/go/types.go b/proto/autogenerated/go/types.go index 1881e0be..27e77fd5 100644 --- a/proto/autogenerated/go/types.go +++ b/proto/autogenerated/go/types.go @@ -396,6 +396,7 @@ type NewInvoiceResponse struct { } type OfferConfig struct { Callback_url string `json:"callback_url"` + Default_offer bool `json:"default_offer"` Expected_data map[string]OfferDataType `json:"expected_data"` Label string `json:"label"` Noffer string `json:"noffer"` diff --git a/proto/autogenerated/ts/types.ts b/proto/autogenerated/ts/types.ts index 814ded3a..ef7d35cf 100644 --- a/proto/autogenerated/ts/types.ts +++ b/proto/autogenerated/ts/types.ts @@ -2244,6 +2244,7 @@ export const NewInvoiceResponseValidate = (o?: NewInvoiceResponse, opts: NewInvo export type OfferConfig = { callback_url: string + default_offer: boolean expected_data: Record label: string noffer: string @@ -2254,6 +2255,7 @@ export const OfferConfigOptionalFields: [] = [] export type OfferConfigOptions = OptionsBaseMessage & { checkOptionalsAreSet?: [] callback_url_CustomCheck?: (v: string) => boolean + default_offer_CustomCheck?: (v: boolean) => boolean expected_data_CustomCheck?: (v: Record) => boolean label_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 (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`) for (const key in o.expected_data) { if (!enumCheckOfferDataType(o.expected_data[key])) return new Error(`${path}.expected_data['${key}']: is not a OfferDataType`) diff --git a/proto/service/structs.proto b/proto/service/structs.proto index deebabe4..955b113a 100644 --- a/proto/service/structs.proto +++ b/proto/service/structs.proto @@ -636,6 +636,7 @@ message OfferConfig { string callback_url = 4; map expected_data = 5; string noffer = 6; + bool default_offer = 7; } message UserOffers { diff --git a/src/services/main/offerManager.ts b/src/services/main/offerManager.ts index 0a1fea96..52d0422d 100644 --- a/src/services/main/offerManager.ts +++ b/src/services/main/offerManager.ts @@ -18,7 +18,7 @@ import { DeepPartial } from 'typeorm'; import { nip19 } from 'nostr-tools'; 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) { const keys = Object.keys(offer.expected_data) for (const key of keys) { @@ -37,7 +37,8 @@ const mapToOfferConfig = (offer: UserOffer, { pubkey, relay }: { pubkey: string, callback_url: offer.callback_url, expected_data: (offer.expected_data || {}) as Record, offer_id: offer.offer_id, - noffer: noffer + noffer: noffer, + default_offer: appUserId === offer.app_user_id } } export class OfferManager { @@ -107,7 +108,7 @@ export class OfferManager { throw new Error("Offer not found") } 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 { @@ -118,7 +119,7 @@ export class OfferManager { const offers = await this.storage.offerStorage.GetUserOffers(ctx.app_user_id) const nostrSettings = LoadNosrtSettingsFromEnv() 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] })) } }