import {z} from 'zod' export type GetApiApiV1ContractsIdArgs = {id: string}; export type GetApiApiV1ContractsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1ContractsIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), status: z.enum(["draft", "scheduled", "active", "ended", "terminated", "cancelled"]), createdAt: z.string(), updatedAt: z.string(), owner: z.object({id: z.string(), email: z.string(), name: z.string()}), createdBy: z.object({id: z.string(), email: z.string(), name: z.string()}).nullable(), approvedAt: z.string().nullable(), approvedBy: z.object({id: z.string(), email: z.string(), name: z.string()}).nullable(), clientCompany: z.object({id: z.string(), name: z.string()}), companyLocation: z.object({id: z.string(), name: z.string()}).nullable(), project: z.object({id: z.string(), jobRole: z.string()}), contractor: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), email: z.string().nullable()}), contractTypes: z.array(z.object({id: z.string(), name: z.string()})), assignment: z.string().nullable(), purchaseOrderNumber: z.string().nullable(), startDate: z.string(), endDate: z.string().nullable(), daysPerWeek: z.number().int().nullable(), hoursPerDay: z.number().nullable(), fixedDaysOverride: z.boolean(), fixedDays: z.array(z.string()).nullable(), durationDays: z.number().int().nullable(), parentContractId: z.string().nullable(), extendedBy: z.object({id: z.string(), email: z.string(), name: z.string()}).nullable(), extendedAt: z.string().nullable(), payor: z.enum(["project_company", "third_party", "null"]).nullable(), payorCompany: z.object({id: z.string(), name: z.string()}).nullable(), payorInvoiceFrequency: z.enum(["daily", "weekly", "biweekly", "monthly", "quarterly", "null"]).nullable(), payorPaymentTermsDays: z.number().int().nullable(), payorNoticePeriodDays: z.number().int().nullable(), payee: z.enum(["umbrella", "contractor_company", "payroll", "none", "null"]).nullable(), payeeCompany: z.object({id: z.string(), name: z.string()}).nullable(), payeeContractorCompany: z.object({id: z.string(), entityName: z.string(), registrationNumber: z.string().nullable()}).nullable(), payeePayInvoiceFrequency: z.enum(["daily", "weekly", "biweekly", "monthly", "quarterly", "null"]).nullable(), payeePaymentTermsDays: z.number().int().nullable(), payeeNoticePeriodDays: z.number().int().nullable(), terminationDate: z.string().nullable(), terminationInitiatedBy: z.enum(["agency", "client", "contractor", "null"]).nullable(), terminationActionedBy: z.object({id: z.string(), email: z.string(), name: z.string()}).nullable(), terminationReason: z.object({id: z.string(), name: z.string()}).nullable(), terminationReasonNotes: z.string().nullable(), weeklyRevenue: z.string().nullable(), weeklyGp: z.string().nullable(), monthlyRevenue: z.string().nullable(), monthlyGp: z.string().nullable(), revenue: z.string().nullable(), grossMarginPercent: z.string().nullable(), rates: z.array(z.object({id: z.string(), rateType: z.object({id: z.string(), name: z.string()}).nullable(), isBase: z.boolean(), unit: z.enum(["hourly", "daily", "weekly", "monthly", "project"]), chargeRate: z.string().nullable(), chargeCurrency: z.string(), payRate: z.string().nullable(), payCurrency: z.string(), baseCurrency: z.string().nullable(), baseChargeRate: z.string().nullable(), basePayRate: z.string().nullable(), marginPercent: z.string().nullable(), payBundle: z.object({id: z.string(), name: z.string()}).nullable()})), contacts: z.array(z.object({id: z.string(), person: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), email: z.string().nullable()}).nullable(), email: z.string().nullable(), role: z.object({id: z.string(), name: z.string()}).nullable()})), attributions: z.array(z.object({id: z.string(), feeEarner: z.object({id: z.string(), name: z.string().nullable(), email: z.string().nullable()}), feeType: z.object({id: z.string(), name: z.string()}).nullable(), share: z.string().nullable(), notes: z.string().nullable()})), allowances: z.array(z.object({id: z.string(), allowanceType: z.enum(["travel", "food", "accommodation", "materials", "equipment", "mileage", "other"]), amount: z.string().nullable(), currency: z.string(), unit: z.enum(["per_day", "per_week", "per_month", "fixed_total", "per_mile", "per_km"]), capAmount: z.string().nullable(), capUnit: z.enum(["per_day", "per_week", "per_month", "fixed_total", "per_mile", "per_km", "null"]).nullable(), notes: 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 contract details * * GET /api/v1/contracts/{id} */ export const getApiApiV1ContractsId = async (args: GetApiApiV1ContractsIdArgs, options: GetApiApiV1ContractsIdOptions) => { 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/contracts/${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(getApiApiV1ContractsIdResponse, await res.json()) };