import {z} from 'zod' export type GetApiV2CompanyCompanyIdTaskListTemplatesArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, location_id?: number | undefined, department_id?: number | undefined, role_id?: number | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiV2CompanyCompanyIdTaskListTemplatesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdTaskListTemplatesResponse = z.object({object: z.literal("task_list_templates"), data: z.array(z.object({id: z.number().int(), company_id: z.number().int(), uuid: z.string(), title: z.string(), description: z.string().nullable(), status: z.number().int().gte(0).lte(1), due: z.string().nullable().optional(), created: z.string().nullable(), activated_at: z.string().nullable(), task_templates: z.array(z.object({uuid: z.string().optional(), title: z.string(), description: z.string().nullable(), sort: z.number().int(), created: z.string().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()})), assignments: z.array(z.object({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()})), recurrence: z.string(), time_frame: z.object({start: z.string().nullable(), end: z.string()}).nullable().optional()})), meta: z.object({cursor: z.object({current: z.string().nullable(), prev: z.string().nullable(), next: z.string().nullable(), count: z.number().int().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 }; /** * List Task List Templates * * GET /v2/company/{company_id}/task_list_templates * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdTaskListTemplates = async (args: GetApiV2CompanyCompanyIdTaskListTemplatesArgs, options?: GetApiV2CompanyCompanyIdTaskListTemplatesOptions) => { 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.location_id != null) query.append("location_id", String(args.location_id)) if (args.department_id != null) query.append("department_id", String(args.department_id)) if (args.role_id != null) query.append("role_id", String(args.role_id)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/task_list_templates${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(getApiV2CompanyCompanyIdTaskListTemplatesResponse, await res.json()) };