import {z} from 'zod' export type PatchApiApiV1PlacementsIdArgs = {id: string, body: {startDate?: (string | null) | undefined, salary?: ({value: string, currency: 'USD' | 'EUR' | 'JPY' | 'GBP' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'HKD' | 'NZD' | 'SEK' | 'NOK' | 'MXN' | 'SGD' | 'RUB' | 'ZAR' | 'TRY' | 'BRL' | 'INR' | 'KRW' | 'DKK' | 'PLN' | 'ILS' | 'HUF' | 'CZK' | 'RON' | 'THB' | 'MYR' | 'IDR' | 'VND' | 'PHP' | 'SAR' | 'AED' | 'QAR' | 'KWD' | 'JOD' | 'CLP' | 'COP' | 'PEN' | 'ARS' | 'UYU' | 'CRC' | 'PKR' | 'BDT' | 'LKR' | 'EGP' | 'NGN' | 'TWD' | 'KES' | 'GHS' | 'UGX' | 'TZS' | 'MAD' | 'BWP' | 'BGN' | 'UAH' | 'KZT' | 'GEL' | 'ISK' | 'BHD' | 'OMR'} | null) | undefined, bonus?: (string | null) | undefined, feeIncludesBonus?: boolean | undefined, commissionRate?: (string | null) | undefined, companyContactId?: (string | null) | undefined, customAttributes?: (Array<{customAttributeId: string, optionId?: (string | null) | undefined, value?: (string | number | null) | undefined}>) | undefined, addFeeIds?: Array | undefined, removeFeeIds?: Array | undefined}}; export type PatchApiApiV1PlacementsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV1PlacementsIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), type: z.enum(["permanent", "contract", "null"]).nullable(), startDate: z.string().nullable(), salary: z.object({value: z.string(), currency: z.string()}).nullable(), bonus: z.string().nullable(), feeIncludesBonus: z.boolean(), commissionRate: z.string().nullable(), approvalStatus: z.enum(["pending", "approved", "null"]).nullable(), owner: z.object({id: z.string(), name: z.string(), email: z.string().nullable()}).nullable(), candidate: z.object({id: z.string(), personId: z.string().nullable(), name: z.string().nullable(), role: z.string().nullable(), company: z.string().nullable(), owner: z.object({id: z.string(), name: z.string()}).nullable()}), project: z.object({id: z.string(), owner: z.object({id: z.string(), name: z.string()}).nullable()}), client: z.object({company: z.object({id: z.string(), name: z.string().nullable()}).nullable(), companyContact: z.object({id: z.string(), name: z.string().nullable()}).nullable()}), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), fees: z.array(z.object({id: z.string(), placementId: z.string().nullable(), feeType: z.object({id: z.string(), name: z.string().nullable()}).nullable(), feeDate: z.string().nullable(), amount: z.object({value: z.string(), currency: z.string()}).nullable(), amountInAgencyCurrency: z.object({value: z.string(), currency: z.string()}).nullable(), projectFeeStatus: z.enum(["projected", "earned", "invoiced", "paid"]), notes: z.string().nullable(), externalInvoiceNumber: z.string().nullable(), invoiceAccountCode: z.string().nullable(), createdBy: z.object({id: z.string(), name: z.string()}).nullable(), paidAt: z.string().nullable(), invoicedAt: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), splits: z.array(z.object({id: z.string(), feeEarner: z.object({id: z.string(), name: z.string(), email: z.string().nullable()}).nullable(), feeType: z.object({id: z.string(), name: z.string().nullable()}).nullable(), share: z.string().nullable(), notes: z.string().nullable()}))})), customAttributes: z.array(z.object({attributeId: z.string(), attributeName: z.string().nullable(), attributeType: z.enum(["options", "text_block", "text_line", "number_input", "integer", "date", "null"]).nullable(), values: z.array(z.union([z.string(), z.number(), z.object({optionId: z.string(), optionValue: 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 }; /** * Update a placement * * PATCH /api/v1/placements/{id} */ export const patchApiApiV1PlacementsId = async (args: PatchApiApiV1PlacementsIdArgs, options: PatchApiApiV1PlacementsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/placements/${encodeURIComponent(String(args.id))}${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(patchApiApiV1PlacementsIdResponse, await res.json()) };