import {z} from 'zod' export type GetApiApiV1ProjectsIdArgs = {id: string}; export type GetApiApiV1ProjectsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1ProjectsIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), jobRole: z.string(), jobNumber: z.string().nullable(), state: z.enum(["active", "closed", "on_hold", "talent_pool", "lead", "pitch", "opportunity"]), closeReason: z.enum(["filled", "worked_lost", "cancelled", "lead_lost", "opportunity_lost", "pitch_lost", "null"]).nullable(), jobDescription: z.string().nullable(), jobDescriptionFormatted: z.string().nullable(), public: z.boolean(), contractType: z.enum(["full_time", "part_time", "contract", "non_exec", "null"]).nullable(), workMode: z.enum(["office", "hybrid", "remote", "null"]).nullable(), seniority: z.enum(["partner", "board", "founder", "cxo", "vp", "director", "manager", "senior", "middle", "junior", "null"]).nullable(), func: z.string().nullable(), skills: z.array(z.string()).nullable(), hireTarget: z.number().int().nullable(), visaSupport: z.boolean().nullable(), salary: z.string().nullable(), salaryCurrency: z.string().nullable(), expectedFee: z.string().nullable(), expectedFeeCurrency: z.string().nullable(), feeTerms: z.string().nullable(), notes: z.string().nullable(), location: z.object({city: z.string().nullable(), region: z.string().nullable(), country: z.string().nullable(), formattedAddress: z.string().nullable()}).nullable(), company: z.object({id: z.string(), name: z.string(), industry: z.string().nullable(), size: z.string().nullable(), logoUrl: z.string().nullable()}).nullable(), endClient: z.object({id: z.string(), name: z.string()}).nullable(), owner: z.object({userId: z.string(), email: z.string(), name: z.string()}).nullable(), members: z.array(z.object({userId: z.string(), email: z.string(), name: z.string(), memberType: z.enum(["member", "lead"])})), companyContacts: z.array(z.object({id: z.string(), personId: z.string(), name: z.string().nullable()})), stages: z.array(z.object({id: z.string(), name: z.string(), type: z.string(), phase: z.string(), position: z.number().int(), statuses: z.array(z.object({id: z.string(), name: z.string(), type: z.string(), position: z.number().int()}))})), 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()})]))})), createdAt: z.string().nullable(), startedAt: z.string().nullable(), closedAt: 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 project details * * GET /api/v1/projects/{id} */ export const getApiApiV1ProjectsId = async (args: GetApiApiV1ProjectsIdArgs, options: GetApiApiV1ProjectsIdOptions) => { 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/projects/${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(getApiApiV1ProjectsIdResponse, await res.json()) };