import {z} from 'zod' export type GetApiBountiesBountyIdSubmissionsArgs = {bounty_id: string, status?: ('submitted' | 'approved' | 'denied') | undefined, created_after?: string | undefined, created_before?: string | undefined, order?: ('created_at' | 'updated_at') | undefined, direction?: ('asc' | 'desc') | undefined, first?: number | undefined, after?: string | undefined, last?: number | undefined, before?: string | undefined}; export type GetApiBountiesBountyIdSubmissionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bountySubmissionLivestreamFeed = z.object({ended_at: z.string().nullable(), id: z.string(), recording_status: z.enum(["recording", "processing", "completed", "failed", "null"]).nullable(), recording_url: z.string().nullable(), started_at: z.string().nullable(), thumbnail_url: z.string().nullable(), title: z.string()}); export const userProfilePicture = z.object({url: z.string()}); export const userSummary = z.object({id: z.string(), name: z.string().nullable(), profile_picture: userProfilePicture, username: z.string()}); export const publicBountySubmission = z.object({bounty_id: z.string(), claimed_at: z.string().nullable(), created_at: z.string(), denial_reason: z.string().nullable(), id: z.string(), latest_proof_livestream_feed: bountySubmissionLivestreamFeed.nullable(), resolved_at: z.string().nullable(), status: z.enum(["submitted", "approved", "denied"]), submitted_at: z.string().nullable(), updated_at: z.string(), worker: userSummary}); export const getApiBountiesBountyIdSubmissionsResponse = z.object({data: z.array(publicBountySubmission), page_info: z.object({end_cursor: z.string().nullable(), has_next_page: z.boolean(), has_previous_page: z.boolean(), start_cursor: z.string().nullable()})}); 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 Public Submissions * * GET /bounties/{bounty_id}/submissions */ export const getApiBountiesBountyIdSubmissions = async (args: GetApiBountiesBountyIdSubmissionsArgs, options?: GetApiBountiesBountyIdSubmissionsOptions) => { const {baseUrl = "https://api.whop.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.order != null) query.append("order", String(args.order)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.first != null) query.append("first", String(args.first)) if (args.after != null) query.append("after", String(args.after)) if (args.last != null) query.append("last", String(args.last)) if (args.before != null) query.append("before", String(args.before)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/bounties/${encodeURIComponent(String(args.bounty_id))}/submissions${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(getApiBountiesBountyIdSubmissionsResponse, await res.json()) };