import {z} from 'zod' export type SubmitAddressModel = {street?: (Array | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, postalCode?: (string | null) | undefined, countryCode?: (string | null) | undefined}; export type SalaryRatePer = 'Hour' | 'Day' | 'Week' | 'Month' | 'Year'; export type SubmitSalaryModel = {ratePer?: SalaryRatePer | undefined, rate?: number | undefined, currency?: (string | null) | undefined}; export type SubmitCurrentEmploymentModel = {employer?: (string | null) | undefined, position?: (string | null) | undefined, workTypeId?: (number | null) | undefined, salary?: SubmitSalaryModel | undefined}; export type SubmitSalaryRangeModel = {ratePer?: SalaryRatePer | undefined, rateLow?: number | undefined, rateHigh?: (number | null) | undefined, currency?: (string | null) | undefined}; export type SubmitIdealSalaryModel = {workTypeId?: (number | null) | undefined, salary?: SubmitSalaryRangeModel | undefined}; export type SubmitIdealEmploymentModel = {position?: (string | null) | undefined, workTypeId?: (number | null) | undefined, salary?: SubmitSalaryRangeModel | undefined, other?: (Array | null) | undefined}; export type CandidateEmploymentHistoryModel = {employer?: (string | null) | undefined, position?: (string | null) | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined, description?: (string | null) | undefined}; export type SubmitEmploymentModel = {current?: SubmitCurrentEmploymentModel | undefined, ideal?: SubmitIdealEmploymentModel | undefined, history?: (Array | null) | undefined}; export type RelativeStartUnit = 'Week' | 'Month'; export type SubmitRelativeStartModel = {period?: number | undefined, unit?: RelativeStartUnit | undefined}; export type SubmitCandidateAvailabilityModel = {immediate?: boolean | undefined, relative?: SubmitRelativeStartModel | undefined, date?: (string | null) | undefined}; export type SubmitCandidateEducationModel = {institution?: (string | null) | undefined, course?: (string | null) | undefined, date?: (string | null) | undefined}; export type SubmitScreeningQuesionAnswerModel = {question?: (string | null) | undefined, answer: unknown, score?: (number | null) | undefined}; export type SubmitScreeningQuesionResultsModel = {answers?: (Array | null) | undefined, score?: (number | null) | undefined}; export type SubmitCustomFieldValueModel = {fieldId: number, value: unknown}; export type SubmitJobApplicationCustomFieldsModel = {candidate?: (Array | null) | undefined, application?: (Array | null) | undefined}; export type SubmitJobApplicationCommand = {firstName: string, lastName: string, salutation?: (string | null) | undefined, email: string, phone?: (string | null) | undefined, mobile?: (string | null) | undefined, address?: SubmitAddressModel | undefined, social?: ({[key: string]: string} | null) | undefined, employment?: SubmitEmploymentModel | undefined, availability?: SubmitCandidateAvailabilityModel | undefined, education?: (Array | null) | undefined, skillTags?: (Array | null) | undefined, screening?: SubmitScreeningQuesionResultsModel | undefined, custom?: SubmitJobApplicationCustomFieldsModel | undefined}; export type CreateApiJobboardsBoardIdAdsAdIdApplicationsArgs = {boardId: number, adId: number, body: SubmitJobApplicationCommand}; export type CreateApiJobboardsBoardIdAdsAdIdApplicationsOptions = {baseUrl: string, jobadderIdentity?: string | undefined, fetch?: typeof fetch | undefined}; export const submittedJobApplicationLinks = z.object({resume: z.string().nullable().optional(), coverLetter: z.string().nullable().optional(), other: z.string().nullable().optional()}); export const submittedJobApplicationModel = z.object({applicationId: z.number().int().optional(), links: submittedJobApplicationLinks.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 }; /** * Submit a job application * * POST /jobboards/{boardId}/ads/{adId}/applications */ export const createApiJobboardsBoardIdAdsAdIdApplications = async (args: CreateApiJobboardsBoardIdAdsAdIdApplicationsArgs, options: CreateApiJobboardsBoardIdAdsAdIdApplicationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, jobadderIdentity} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (jobadderIdentity !== undefined) headers.set('authorization', `Bearer ${jobadderIdentity}`) const url = `${baseUrl.replace(/\/+$/, '')}/jobboards/${encodeURIComponent(String(args.boardId))}/ads/${encodeURIComponent(String(args.adId))}/applications${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(submittedJobApplicationModel, await res.json()) };