import {z} from 'zod' export type CreateApiOrganizationsOrganizationIdFeedItemsArgs = {organization_id: number, body: {comment?: string | undefined}}; export type CreateApiOrganizationsOrganizationIdFeedItemsOptions = {baseUrl?: string | undefined, OAuth2Member?: string | undefined, fetch?: typeof fetch | undefined}; export const comment = z.object({body: z.string().optional(), commentable_id: z.number().int().optional(), commentable_type: z.enum(["feed_item", "update", "story"]).optional(), commenter_name: z.string().optional(), author_display_name: z.string().nullable().optional(), created_at: z.string().optional(), id: z.number().int().optional(), likes_count: z.number().int().optional(), member_id: z.number().int().optional(), updated_at: z.string().optional()}); export const feedItemComment = z.object({id: z.number().int().optional(), agent_id: z.number().int().nullable().optional(), agent_type: z.enum(["member", "business"]).nullable().optional(), agent_name: z.string().nullable().optional(), member_name: z.string().nullable().optional(), feedable_id: z.number().int().optional(), feedable_type: z.string().optional(), feedable_value: z.string().nullable().optional(), linkable_id: z.number().int().nullable().optional(), linkable_type: z.string().nullable().optional(), linkable_value: z.string().nullable().optional(), linkable_effective_at: z.string().optional(), type: z.enum(["comment", "onboarding", "creation", "update", "association"]).optional(), comment: z.string().optional(), comments_count: z.number().int().nullable().optional(), likes_count: z.number().int().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), visibility: z.enum(["public", "admin"]).optional(), latest_comments: z.array(comment).optional(), author_display_name: z.string().nullable().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 }; /** * createOrganizationFeedItem * * POST /organizations/{organization_id}/feed-items */ export const createApiOrganizationsOrganizationIdFeedItems = async (args: CreateApiOrganizationsOrganizationIdFeedItemsArgs, options?: CreateApiOrganizationsOrganizationIdFeedItemsOptions) => { 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_id))}/feed-items${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(feedItemComment, await res.json()) };