import {z} from 'zod' export type GetApiV2CompanyCompanyIdTaskListsArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, user_id?: number | undefined, location_id?: number | undefined, uuid?: string | undefined, active_on_date?: string | undefined}; export type GetApiV2CompanyCompanyIdTaskListsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdTaskListsResponse = z.object({object: z.literal("task_list"), data: z.array(z.object({id: z.number().int(), task_list_template_uuid: z.string(), title: z.string(), description: z.string(), start: z.string(), due: z.string(), due_date: z.object({start: z.string().nullable(), end: z.string().nullable()}), tasks: z.array(z.object({id: z.number().int(), task_template_uuid: z.string().optional(), title: z.string(), description: z.string().optional(), user_id: z.number().int().nullable(), completed_at: z.string().nullable(), tags: z.array(z.object({uuid: z.string(), user_id: z.number().int(), task_id: z.number().int()})).nullable().optional(), task_completion: z.object({type: z.enum(["NUMBER", "TEMPERATURE", "PHOTO", "STRING", "WEIGHT", "CHECKMARK"]), primitive_type: z.enum(["INTEGER", "DECIMAL", "FILE", "STRING", "BOOLEAN"]), unit: z.enum(["C", "F", "KG"]).nullable()}).nullable().optional(), task_completion_event: z.object({user_id: z.number().int(), completed_at: z.string(), completion_value: z.string().nullable()}).nullable().optional()})), recurrence: z.object({interval: z.string(), rrule: z.string()}), assignments: z.array(z.object({company_id: z.number().int(), location_id: z.number().int(), department_id: z.number().int().nullable().optional(), role_id: z.number().int().nullable().optional(), user_id: z.number().int().nullable().optional()})), time_frame: z.object({start: z.string().nullable(), end: z.string(), start_time: z.string().nullable(), end_time: z.string()}).nullable().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 Task Lists * * GET /v2/company/{company_id}/task_lists * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdTaskLists = async (args: GetApiV2CompanyCompanyIdTaskListsArgs, options?: GetApiV2CompanyCompanyIdTaskListsOptions) => { const {baseUrl = "https://api.7shifts.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-version'] != null) headers.set("x-api-version", String(args['x-api-version'])) if (args['x-company-guid'] != null) headers.set("x-company-guid", String(args['x-company-guid'])) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.uuid != null) query.append("uuid", String(args.uuid)) if (args.active_on_date != null) query.append("active_on_date", String(args.active_on_date)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/task_lists${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(getApiV2CompanyCompanyIdTaskListsResponse, await res.json()) };