import {z} from 'zod' export type Metadata = {foo?: string | undefined}; export type SupporterFillable = {address1?: (string | null) | undefined, address2?: (string | null) | undefined, cell_phone?: (string | null) | undefined, city?: (string | null) | undefined, country?: (string | null) | undefined, email_address?: (string | null) | undefined, first_name?: (string | null) | undefined, gender?: (string | null) | undefined, last_name?: (string | null) | undefined, location?: (string | null) | undefined, metadata?: (Metadata | null) | undefined, nickname?: (string | null) | undefined, phone?: (string | null) | undefined, postal_code?: (string | null) | undefined, state?: (string | null) | undefined}; export type CreateApiOrganizationsOrganizationSupportersArgs = {organization: number, body: SupporterFillable}; export type CreateApiOrganizationsOrganizationSupportersOptions = {baseUrl?: string | undefined, OAuth2Member?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.object({foo: z.string().optional()}); export const supporter = z.object({address1: z.string().nullable().optional(), address2: z.string().nullable().optional(), birthday: z.string().max(5).nullable().optional(), cell_phone: z.string().nullable().optional(), city: z.string().nullable().optional(), country: z.string().nullable().optional(), created_at: z.string().optional(), email_address: z.string().optional(), first_name: z.string().nullable().optional(), gender: z.string().nullable().optional(), id: z.number().int().optional(), last_emailed_at: z.string().nullable().optional(), last_name: z.string().nullable().optional(), location: z.string().nullable().optional(), member_id: z.number().int().nullable().optional(), metadata: metadata.nullable().optional(), nickname: z.string().nullable().optional(), opt_in: z.boolean().optional(), origin: z.string().optional(), phone: z.string().nullable().optional(), postal_code: z.string().nullable().optional(), source_campaign_id: z.number().int().nullable().optional(), source_fundraising_page_id: z.number().int().nullable().optional(), source_member_id: z.number().int().nullable().optional(), source_organization_id: z.number().int().nullable().optional(), state: z.string().nullable().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 }; /** * createOrganizationSupporter * * POST /organizations/{organization}/supporters */ export const createApiOrganizationsOrganizationSupporters = async (args: CreateApiOrganizationsOrganizationSupportersArgs, options?: CreateApiOrganizationsOrganizationSupportersOptions) => { 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(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization))}/supporters${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(supporter, await res.json()) };