import {z} from 'zod' export type TicketTypeFillable = {commitment?: ({deadline?: string | undefined, value?: number | undefined} | null) | undefined, description?: (string | null) | undefined, ended_at?: (string | null) | undefined, entries_per_ticket?: number | undefined, is_active?: boolean | undefined, max_per_transaction?: number | undefined, name?: string | undefined, org_percent?: (number | null) | undefined, deductible_amount?: (number | null) | undefined, deductible_percent?: (number | null) | undefined, price?: number | undefined, quantity_available?: (number | null) | undefined, started_at?: (string | null) | undefined, weight?: (number | null) | undefined}; export type CreateApiCampaignsCampaignTicketTypesArgs = {campaign: number, body: TicketTypeFillable}; export type CreateApiCampaignsCampaignTicketTypesOptions = {baseUrl?: string | undefined, OAuth2Member?: string | undefined, fetch?: typeof fetch | undefined}; export const ticketType = z.object({commitment: z.object({deadline: z.string().optional(), value: z.number().gte(1).optional()}).nullable().optional(), description: z.string().max(900).nullable().optional(), ended_at: z.string().nullable().optional(), entries_per_ticket: z.number().int().gte(1).optional(), is_active: z.boolean().optional(), max_per_transaction: z.number().int().gte(1).optional(), name: z.string().max(100).optional(), org_percent: z.number().nullable().optional(), deductible_amount: z.number().nullable().optional(), deductible_percent: z.number().nullable().optional(), price: z.number().gte(0).optional(), quantity_available: z.number().int().gte(-1).nullable().optional(), started_at: z.string().nullable().optional(), weight: z.number().int().gte(0).nullable().optional(), campaign_id: z.number().int().optional(), commitment_id: z.number().int().nullable().optional(), created_at: z.string().optional(), id: z.number().int().optional(), is_classy_mode: z.boolean().optional(), min_per_transaction: z.number().int().nullable().optional(), quantity_reserved: z.number().int().optional(), quantity_sold: z.number().int().optional(), updated_at: z.string().optional()}); 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 }; /** * createTicketType * * POST /campaigns/{campaign}/ticket-types */ export const createApiCampaignsCampaignTicketTypes = async (args: CreateApiCampaignsCampaignTicketTypesArgs, options?: CreateApiCampaignsCampaignTicketTypesOptions) => { const {baseUrl = "https://pro.gofundme.com/api/2.0", fetch: fetchFn = fetch, OAuth2Member} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2Member !== undefined) headers.set('authorization', `Bearer ${OAuth2Member}`) const url = `${baseUrl.replace(/\/+$/, '')}/campaigns/${encodeURIComponent(String(args.campaign))}/ticket-types${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(ticketType, await res.json()) };