import {z} from 'zod' export type GetApiApiMarketingSalesApplicableArgs = {audience?: string | undefined, country?: string | undefined}; export type GetApiApiMarketingSalesApplicableOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiMarketingSalesApplicableResponse = z.object({data: z.object({sale: z.object({name: z.string().nullable(), intervalTagline: z.string().nullable(), stripeCouponIds: z.array(z.string()), colorScheme: z.string().nullable(), beginDate: z.string().nullable(), endDate: z.string().nullable(), audiences: z.array(z.string()), hasCountdown: z.boolean(), isPublic: z.boolean(), countries: z.array(z.string()), id: z.string(), createdAt: z.string(), updatedAt: z.string(), heroTheme: z.string().nullable(), heroMode: z.string().nullable(), heroConfig: z.object({home: z.object({badge: z.string().optional(), h1: z.string().optional(), sub: z.string().nullable().optional(), primaryCta: z.object({label: z.string().min(1), href: z.string().min(1)}).optional(), secondaryCta: z.object({label: z.string().min(1), href: z.string().min(1)}).nullable().optional()}).optional(), pricing: z.object({h1: z.string().optional(), sub: z.string().nullable().optional(), bonusTagline: z.string().optional(), annualOnly: z.boolean().optional(), ctaLabel: z.string().optional(), discountFirst: z.boolean().optional()}).optional(), homePricing: z.object({h1: z.string().optional(), sub: z.string().nullable().optional()}).optional(), seasonal: z.object({season: z.enum(["winter", "spring", "summer", "fall"]).optional(), accent: z.string().optional(), emoji: z.string().optional()}).optional(), prelaunch: z.object({enabled: z.boolean(), beginDate: z.string().nullable().optional(), h1: z.string().optional(), sub: z.string().nullable().optional(), notifyTag: z.string().optional()}).optional()}).nullable(), perks: z.record(z.string(), z.object({purchase: z.object({freeMonths: z.number().int().gte(0).lte(24).optional(), aiCredits: z.number().int().gte(0).lte(100000000).optional()}).optional(), stacking: z.array(z.object({freeMonths: z.number().int().gte(0).lte(24).optional(), aiCredits: z.number().int().gte(0).lte(100000000).optional(), years: z.number().int().gte(2).lte(10)})).optional(), maxButton: z.object({enabled: z.boolean(), bonus: z.object({freeMonths: z.number().int().gte(0).lte(24).optional(), aiCredits: z.number().int().gte(0).lte(100000000).optional()}).optional()}).optional()})).nullable(), phases: z.array(z.object({label: z.string(), displayPercent: z.number(), stripeCouponIds: z.array(z.string()), beginDate: z.string(), id: z.string(), sortOrder: z.number()})), banner: z.object({content: z.string(), linkUrl: z.string().nullable(), colorScheme: z.string().nullable(), beginDate: z.string().nullable(), endDate: z.string().nullable(), audiences: z.array(z.string()), isPublic: z.boolean(), countries: z.array(z.string()), surface: z.enum(["bar", "hero_pill", "app_bar"]), targetPathnames: z.array(z.string()), id: z.string(), saleId: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()}).nullable()}).nullable(), activePhase: z.object({label: z.string(), displayPercent: z.number(), stripeCouponIds: z.array(z.string()), beginDate: z.string(), id: z.string(), sortOrder: z.number()}).nullable(), effectiveStripeCouponIds: z.array(z.string())}), errors: z.unknown()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Public: get the currently applicable sale for an audience * * GET /api/marketing/sales/applicable */ export const getApiApiMarketingSalesApplicable = async (args: GetApiApiMarketingSalesApplicableArgs, options?: GetApiApiMarketingSalesApplicableOptions) => { const {baseUrl = "https://app.luxalgo.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.audience != null) query.append("audience", String(args.audience)) if (args.country != null) query.append("country", String(args.country)) const url = `${baseUrl.replace(/\/+$/, '')}/api/marketing/sales/applicable${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiMarketingSalesApplicableResponse, await res.json()) };