import {z} from 'zod' export type GetApiOrganizationsOrganizationQuestionsArgs = {organization: number, page?: number | undefined, per_page?: number | undefined}; export type GetApiOrganizationsOrganizationQuestionsOptions = {baseUrl?: string | undefined, OAuth2Application?: string | undefined, fetch?: typeof fetch | undefined}; export const paginationLink = z.object({label: z.string().optional(), url: z.string().nullable().optional(), active: z.boolean().optional()}); export const getApiOrganizationsOrganizationQuestionsResponse = z.object({current_page: z.number().int().optional(), data: z.array(z.object({campaign_id: z.number().int().optional(), created_at: z.string().optional(), deleted_at: z.string().nullable().optional(), id: z.number().int().optional(), is_deleted: z.boolean().optional(), is_required: z.boolean().optional(), is_pre_conversion: z.boolean().optional(), label: z.string(), location: z.enum(["donation_page", "team_creation", "page_creation", "campaign_registration", "hidden"]), product_id: z.number().int().nullable().optional(), tag: z.enum(["address", "address2", "address_type", "birthdate", "blog", "cellphone", "city", "company_name", "country", "email_address", "email_type", "emergency_first_name", "emergency_last_name", "emergency_phone", "event_waiver", "first_name", "gender", "pronoun", "homephone", "last_name", "middle_name", "postal_code", "prefix", "run_walk", "shirt_size", "state", "suffix", "text_opt_in", "website"]).nullable().optional(), type: z.enum(["boolean", "integer", "currency", "enum", "text", "string", "date", "yes_no"]), updated_at: z.string().nullable().optional(), weight: z.number().int().nullable().optional()})).optional(), first_page_url: z.string().nullable().optional(), from: z.number().int().nullable().optional(), last_page: z.number().int().optional(), last_page_url: z.string().nullable().optional(), next_page_url: z.string().nullable().optional(), path: z.string().nullable().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().nullable().optional(), links: z.array(paginationLink).optional(), to: z.number().int().nullable().optional(), total: z.number().int().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 }; /** * listOrganizationQuestions * * GET /organizations/{organization}/questions * * Also accepts auth: OAuth2Member */ export const getApiOrganizationsOrganizationQuestions = async (args: GetApiOrganizationsOrganizationQuestionsArgs, options?: GetApiOrganizationsOrganizationQuestionsOptions) => { const {baseUrl = "https://pro.gofundme.com/api/2.0", fetch: fetchFn = fetch, OAuth2Application} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (OAuth2Application !== undefined) headers.set('authorization', `Bearer ${OAuth2Application}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization))}/questions${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(getApiOrganizationsOrganizationQuestionsResponse, await res.json()) };