import {z} from 'zod' export type UpdateApiApiV0ApplicationsIdArgs = {Authorization?: string | undefined, id: number, body: {job_id: string, email: string, description: string, professional_background: string, answers?: string | undefined}}; export type UpdateApiApiV0ApplicationsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV0ApplicationsIdResponse = 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.unknown(), 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()})}), professional: z.object({data: z.object({id: z.number().int(), type: z.string()})}), answers: z.object({data: z.array(z.object({id: z.number().int(), type: z.string()}))}), 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 }; /** * Update an application * * PUT /api/v0/applications/{id} */ export const updateApiApiV0ApplicationsId = async (args: UpdateApiApiV0ApplicationsIdArgs, options?: UpdateApiApiV0ApplicationsIdOptions) => { 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.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV0ApplicationsIdResponse, await res.json()) };