import {z} from 'zod' export type PatchApiApiV0ApplicationsApplicationIdPhaseArgs = {Authorization?: string | undefined, application_id: number, body: {phase_id: number, position?: number | undefined, expand?: Array | undefined, discard_reason?: string | undefined}}; export type PatchApiApiV0ApplicationsApplicationIdPhaseOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV0ApplicationsApplicationIdPhaseResponse = z.object({data: z.object({id: z.string(), type: z.string(), attributes: z.object({slug: z.string(), deleted: z.boolean(), read: z.boolean(), messages_count: z.number().int(), notes_count: z.number().int(), unlocked: z.boolean(), source_channel: z.enum(["boost", "talent_db", "invite", "getonbrd", "linkedin", "facebook", "twitter", "email", "chat", "slack", "notion", "github", "gitlab", "angel_list", "medium", "awesomefest", "blog", "youtube", "academy", "search", "instagram", "meetup", "google_jobs", "aggregator", "other", "null"]).nullable().optional(), unread_messages_from_webpro: z.number().int(), unread_messages_from_company: z.number().int(), discard_reason: z.string().nullable(), expected_salary: z.number().int(), reason_to_apply: z.string(), professional_background: z.string(), academic_background: z.string(), sent_at: z.number().int(), created_at: z.number().int(), updated_at: z.number().int(), job: z.object({data: z.object({id: z.number().int(), type: z.string()})}), phase: z.object({data: z.object({id: z.number().int(), type: z.string(), attributes: z.object({title: z.string(), position: z.number().int(), kind: z.string(), reserved: z.boolean(), created_at: z.number().int(), updated_at: z.number().int()}).optional()})}), professional: z.object({data: z.object({id: z.number().int(), type: z.string()})}), answers: z.object({data: z.array(z.unknown())}), messages: z.object({data: z.array(z.unknown())}), notes: z.object({data: z.array(z.unknown())})})})}); 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 }; /** * Move an application to another phase * * PATCH /api/v0/applications/{application_id}/phase */ export const patchApiApiV0ApplicationsApplicationIdPhase = async (args: PatchApiApiV0ApplicationsApplicationIdPhaseArgs, options?: PatchApiApiV0ApplicationsApplicationIdPhaseOptions) => { const {baseUrl = "https://www.getonbrd.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/applications/${encodeURIComponent(String(args.application_id))}/phase${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiApiV0ApplicationsApplicationIdPhaseResponse, await res.json()) };