import {z} from 'zod' export type OfferSchema = {createdAt?: (number | null) | undefined, stockVestingFrequency?: (string | null) | undefined, versions?: (Array | null) | undefined, payGradeExternalId?: (string | null) | undefined, stockOptionsType?: (string | null) | undefined, offerStatus?: (string | null) | undefined, profileId?: (string | null) | undefined, candidateAddress?: (string | null) | undefined, currency?: (string | null) | undefined, version?: (string | null) | undefined, groupId?: (string | null) | undefined, relocationBonus?: (number | null) | undefined, jobTitle?: (string | null) | undefined, workplaceType?: ('remote_global' | 'remote_local' | 'hybrid' | 'onsite' | null) | undefined, displayOfferId?: (string | null) | undefined, payGradeId?: (number | null) | undefined, variableBonus?: (number | null) | undefined, note?: (string | null) | undefined, customInfo?: (Record | null) | undefined, jobLocation?: (string | null) | undefined, bonusPayFrequency?: (string | null) | undefined, joiningDate?: (string | null) | undefined, offerId?: (number | null) | undefined, templateId?: (number | null) | undefined, countryCode?: (string | null) | undefined, offerLetter?: (Record | null) | undefined, stockOptionsDescription?: (string | null) | undefined, candidateEmail?: (string | null) | undefined, visaType?: (string | null) | undefined, isPeopleManagerRole?: (boolean | null) | undefined, stockOptionsTotalVestingYears?: (number | null) | undefined, isRehire?: (boolean | null) | undefined, watchers?: (Array | null) | undefined, updatedAt?: (number | null) | undefined, salaryAmount?: (number | null) | undefined, shiftAllowance?: (number | null) | undefined, stockOptionsAmount?: (number | null) | undefined, totalCompensation?: (number | null) | undefined, createdBy?: (string | null) | undefined, basePayFrequency?: (string | null) | undefined, candidateFullName?: (string | null) | undefined, joiningBonus?: (number | null) | undefined, stockOptionsPercentageVesting?: (string | null) | undefined, positionId?: (number | null) | undefined, stockVestingStartDate?: (string | null) | undefined, applicationId?: (number | null) | undefined}; export type PatchApiApiV2AtsOffersOfferIdArgs = {Authorization: string, offerId: string, body: OfferSchema}; export type PatchApiApiV2AtsOffersOfferIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const offerSchema = z.object({createdAt: z.number().int().nullable().optional(), stockVestingFrequency: z.string().nullable().optional(), versions: z.array(z.string()).nullable().optional(), payGradeExternalId: z.string().nullable().optional(), stockOptionsType: z.string().nullable().optional(), offerStatus: z.string().nullable().optional(), profileId: z.string().nullable().optional(), candidateAddress: z.string().nullable().optional(), currency: z.string().nullable().optional(), version: z.string().nullable().optional(), groupId: z.string().nullable().optional(), relocationBonus: z.number().nullable().optional(), jobTitle: z.string().nullable().optional(), workplaceType: z.enum(["remote_global", "remote_local", "hybrid", "onsite"]).nullable().optional(), displayOfferId: z.string().nullable().optional(), payGradeId: z.number().int().nullable().optional(), variableBonus: z.number().nullable().optional(), note: z.string().nullable().optional(), customInfo: z.object({}).nullable().optional(), jobLocation: z.string().nullable().optional(), bonusPayFrequency: z.string().nullable().optional(), joiningDate: z.string().nullable().optional(), offerId: z.number().int().nullable().optional(), templateId: z.number().int().nullable().optional(), countryCode: z.string().nullable().optional(), offerLetter: z.object({}).nullable().optional(), stockOptionsDescription: z.string().nullable().optional(), candidateEmail: z.string().nullable().optional(), visaType: z.string().nullable().optional(), isPeopleManagerRole: z.boolean().nullable().optional(), stockOptionsTotalVestingYears: z.number().int().nullable().optional(), isRehire: z.boolean().nullable().optional(), watchers: z.array(z.string()).nullable().optional(), updatedAt: z.number().int().nullable().optional(), salaryAmount: z.number().nullable().optional(), shiftAllowance: z.number().nullable().optional(), stockOptionsAmount: z.number().nullable().optional(), totalCompensation: z.number().nullable().optional(), createdBy: z.string().nullable().optional(), basePayFrequency: z.string().nullable().optional(), candidateFullName: z.string().nullable().optional(), joiningBonus: z.number().nullable().optional(), stockOptionsPercentageVesting: z.string().nullable().optional(), positionId: z.number().int().nullable().optional(), stockVestingStartDate: z.string().nullable().optional(), applicationId: z.number().int().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 }; /** * Patch Offer * * PATCH /api/v2/ats/offers/{offerId} */ export const patchApiApiV2AtsOffersOfferId = async (args: PatchApiApiV2AtsOffersOfferIdArgs, options?: PatchApiApiV2AtsOffersOfferIdOptions) => { const {baseUrl = "https://apiv2.eightfold.ai", fetch: fetchFn = fetch} = 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)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/ats/offers/${encodeURIComponent(String(args.offerId))}${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(offerSchema, await res.json()) };