import {z} from 'zod' export type GetApiListsArgs = {id?: string | undefined, id__in?: string | undefined, incident?: string | undefined, incident__in?: string | undefined, model?: string | undefined, model__in?: string | undefined, name?: string | undefined, name__icontains?: string | undefined, created_by?: number | undefined, created_by__in?: string | undefined, object_ids__contains?: string | undefined, search?: string | undefined, limit?: number | undefined, offset?: number | undefined, shared?: string | undefined}; export type GetApiListsOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; export const list = z.object({id: z.number().int().optional(), created_by: z.number().int().nullable().optional(), updated_by: z.number().int().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), parent: z.number().int().nullable().optional(), name: z.string().min(1).max(255), description: z.string().nullable().optional(), list_order: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), tags: z.object({}).nullable().optional(), model: z.string().min(1).max(255), object_ids: z.array(z.number().int().gte(-2147483648).lte(2147483647)).nullable().optional(), shared: z.enum(["private", "team", "organization", "groups_affiliates", "all", "public"]), permissions: z.enum(["read_write_delete_copy", "read_write_copy", "read_copy", "read_only"]), incident: z.number().int().nullable().optional(), invalidate_at: z.string().optional()}); export const getApiListsResponse = z.array(list); 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 shared lists * * GET /lists */ export const getApiLists = async (args: GetApiListsArgs, options?: GetApiListsOptions) => { const {baseUrl = "https://crisiscleanup-3-api-production.up.railway.app", fetch: fetchFn = fetch, Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.id__in != null) query.append("id__in", String(args.id__in)) if (args.incident != null) query.append("incident", String(args.incident)) if (args.incident__in != null) query.append("incident__in", String(args.incident__in)) if (args.model != null) query.append("model", String(args.model)) if (args.model__in != null) query.append("model__in", String(args.model__in)) if (args.name != null) query.append("name", String(args.name)) if (args.name__icontains != null) query.append("name__icontains", String(args.name__icontains)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.created_by__in != null) query.append("created_by__in", String(args.created_by__in)) if (args.object_ids__contains != null) query.append("object_ids__contains", String(args.object_ids__contains)) if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.shared != null) query.append("shared", String(args.shared)) if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/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(getApiListsResponse, await res.json()) };