import {z} from 'zod' export type EventUnitV3 = 0 | 1 | 2; export type GetApiApiV3WorkcycleExceptionsArgs = {fields?: (Array<'id' | 'name' | 'url' | 'ownerId' | 'owner.id' | 'owner.name' | 'owner.url' | 'owner.firstName' | 'owner.lastName' | 'isAm' | 'unit' | 'startsAt' | 'endsAt' | 'durationInMinutes' | 'duration' | 'authorId' | 'createdAt' | 'modifierId' | 'modifiedAt' | 'deletedById' | 'deletedAt' | 'collection.count'>) | undefined, id?: Array | undefined, ownerId?: Array | undefined, isAm?: boolean | undefined, startsAt?: string | undefined, deletedAt?: ('notequal,null' | 'null') | undefined, unit?: EventUnitV3 | undefined, paging?: string | undefined, orderBy?: (Array<'id,asc' | 'id,desc' | 'startsAt,asc' | 'startsAt,desc'>) | undefined}; export type GetApiApiV3WorkcycleExceptionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const workCycleException = z.unknown(); export const getApiApiV3WorkcycleExceptionsResponse = z.object({data: z.object({count: z.number().int().gte(0).optional(), items: z.array(workCycleException).optional()}).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 }; /** * List WorkCycleExceptions. * * GET /api/v3/workcycleExceptions */ export const getApiApiV3WorkcycleExceptions = async (args: GetApiApiV3WorkcycleExceptionsArgs, options?: GetApiApiV3WorkcycleExceptionsOptions) => { const {baseUrl = "https://example.ilucca.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fields != null) query.append("fields", args.fields.join(',')) if (args.id != null) query.append("id", args.id.join(',')) if (args.ownerId != null) query.append("ownerId", args.ownerId.join(',')) if (args.isAm != null) query.append("isAm", String(args.isAm)) if (args.startsAt != null) query.append("startsAt", String(args.startsAt)) if (args.deletedAt != null) query.append("deletedAt", String(args.deletedAt)) if (args.unit != null) query.append("unit", String(args.unit)) if (args.paging != null) query.append("paging", String(args.paging)) if (args.orderBy != null) query.append("orderBy", args.orderBy.join(',')) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/workcycleExceptions${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(getApiApiV3WorkcycleExceptionsResponse, await res.json()) };