import {z} from 'zod' export type GetApiApiV1PlacementsIdArgs = {id: string}; export type GetApiApiV1PlacementsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PlacementsIdResponse = 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 }; /** * Get placement details * * GET /api/v1/placements/{id} */ export const getApiApiV1PlacementsId = async (args: GetApiApiV1PlacementsIdArgs, options: GetApiApiV1PlacementsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1PlacementsIdResponse, await res.json()) };