import {z} from 'zod' export type GetApiAdminBillingProductsFunnelfoxPricePointsArgs = {ident?: string | undefined, currencyCode?: string | undefined, featureIdent?: string | undefined}; export type GetApiAdminBillingProductsFunnelfoxPricePointsOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyDto = z.object({code: z.string(), minorUnits: z.number(), title: z.string(), symbol: z.string()}); export const pricePointDto = z.object({ident: z.string(), currency: currencyDto, introType: z.enum(["no_intro", "free_trial", "paid_trial"]).optional(), lifetimePrice: z.object({}).optional(), introFreeTrialPeriod: z.number().optional(), introFreeTrialPeriodDuration: z.enum(["minutes", "days", "weeks", "months", "years"]).optional(), introPaidTrialPrice: z.object({}).optional(), introPaidTrialPeriod: z.number().optional(), introPaidTrialPeriodDuration: z.enum(["minutes", "days", "weeks", "months", "years"]).optional(), nextPrice: z.object({}).optional(), nextPeriod: z.number().optional(), nextPeriodDuration: z.enum(["minutes", "days", "weeks", "months", "years"]).optional(), features: z.array(z.string())}); export const getApiAdminBillingProductsFunnelfoxPricePointsResponse = z.array(pricePointDto); 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 }; /** * List FunnelFox price points * * GET /admin/billing-products/funnelfox/price-points */ export const getApiAdminBillingProductsFunnelfoxPricePoints = async (args: GetApiAdminBillingProductsFunnelfoxPricePointsArgs, options: GetApiAdminBillingProductsFunnelfoxPricePointsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ident != null) query.append("ident", String(args.ident)) if (args.currencyCode != null) query.append("currencyCode", String(args.currencyCode)) if (args.featureIdent != null) query.append("featureIdent", String(args.featureIdent)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/admin/billing-products/funnelfox/price-points${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(getApiAdminBillingProductsFunnelfoxPricePointsResponse, await res.json()) };