import {z} from 'zod' export type GetApiWorksitesArgs = {id__in?: string | undefined, id?: string | undefined, reported_by?: string | undefined, case_number?: string | undefined, name?: string | undefined, name__startswith?: string | undefined, address?: string | undefined, address__startswith?: string | undefined, city?: string | undefined, city__startswith?: string | undefined, county?: string | undefined, county__startswith?: string | undefined, state?: string | undefined, state__startswith?: string | undefined, postal_code?: string | undefined, postal_code__startswith?: string | undefined, created_at__gt?: string | undefined, created_at__lt?: string | undefined, updated_at__gt?: string | undefined, updated_at__lt?: string | undefined, phone1_dnis?: string | undefined, phone1_dnis__in?: string | undefined, phone2_dnis?: string | undefined, phone2_dnis__in?: string | undefined, search?: string | undefined, incident?: number | undefined, organization_bounds?: string | undefined, organization_primary_location?: string | undefined, organization_secondary_location?: string | undefined, work_type?: string | undefined, missing_work_type?: boolean | undefined, my_team?: boolean | undefined, member_of_my_organization?: boolean | undefined, form_data?: string | undefined, flags?: string | undefined, locations?: string | undefined, teams?: string | undefined, phone_number?: string | undefined, sort?: string | undefined, center_coordinates?: string | undefined, has_files?: boolean | undefined, feed?: string | undefined, include_lists?: string | undefined, exclude_lists?: string | undefined, limit?: number | undefined, offset?: number | undefined, fields?: string | undefined, status?: string | undefined, claimed_by?: number | undefined, geofence?: string | undefined}; export type GetApiWorksitesOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiWorksitesResponse = z.object({count: z.number().int().optional(), next: z.string().optional(), previous: z.string().optional(), results: z.array(z.object({})).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 worksites * * GET /worksites */ export const getApiWorksites = async (args: GetApiWorksitesArgs, options?: GetApiWorksitesOptions) => { 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__in != null) query.append("id__in", String(args.id__in)) if (args.id != null) query.append("id", String(args.id)) if (args.reported_by != null) query.append("reported_by", String(args.reported_by)) if (args.case_number != null) query.append("case_number", String(args.case_number)) if (args.name != null) query.append("name", String(args.name)) if (args.name__startswith != null) query.append("name__startswith", String(args.name__startswith)) if (args.address != null) query.append("address", String(args.address)) if (args.address__startswith != null) query.append("address__startswith", String(args.address__startswith)) if (args.city != null) query.append("city", String(args.city)) if (args.city__startswith != null) query.append("city__startswith", String(args.city__startswith)) if (args.county != null) query.append("county", String(args.county)) if (args.county__startswith != null) query.append("county__startswith", String(args.county__startswith)) if (args.state != null) query.append("state", String(args.state)) if (args.state__startswith != null) query.append("state__startswith", String(args.state__startswith)) if (args.postal_code != null) query.append("postal_code", String(args.postal_code)) if (args.postal_code__startswith != null) query.append("postal_code__startswith", String(args.postal_code__startswith)) if (args.created_at__gt != null) query.append("created_at__gt", String(args.created_at__gt)) if (args.created_at__lt != null) query.append("created_at__lt", String(args.created_at__lt)) if (args.updated_at__gt != null) query.append("updated_at__gt", String(args.updated_at__gt)) if (args.updated_at__lt != null) query.append("updated_at__lt", String(args.updated_at__lt)) if (args.phone1_dnis != null) query.append("phone1_dnis", String(args.phone1_dnis)) if (args.phone1_dnis__in != null) query.append("phone1_dnis__in", String(args.phone1_dnis__in)) if (args.phone2_dnis != null) query.append("phone2_dnis", String(args.phone2_dnis)) if (args.phone2_dnis__in != null) query.append("phone2_dnis__in", String(args.phone2_dnis__in)) if (args.search != null) query.append("search", String(args.search)) if (args.incident != null) query.append("incident", String(args.incident)) if (args.organization_bounds != null) query.append("organization_bounds", String(args.organization_bounds)) if (args.organization_primary_location != null) query.append("organization_primary_location", String(args.organization_primary_location)) if (args.organization_secondary_location != null) query.append("organization_secondary_location", String(args.organization_secondary_location)) if (args.work_type != null) query.append("work_type", String(args.work_type)) if (args.missing_work_type != null) query.append("missing_work_type", String(args.missing_work_type)) if (args.my_team != null) query.append("my_team", String(args.my_team)) if (args.member_of_my_organization != null) query.append("member_of_my_organization", String(args.member_of_my_organization)) if (args.form_data != null) query.append("form_data", String(args.form_data)) if (args.flags != null) query.append("flags", String(args.flags)) if (args.locations != null) query.append("locations", String(args.locations)) if (args.teams != null) query.append("teams", String(args.teams)) if (args.phone_number != null) query.append("phone_number", String(args.phone_number)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.center_coordinates != null) query.append("center_coordinates", String(args.center_coordinates)) if (args.has_files != null) query.append("has_files", String(args.has_files)) if (args.feed != null) query.append("feed", String(args.feed)) if (args.include_lists != null) query.append("include_lists", String(args.include_lists)) if (args.exclude_lists != null) query.append("exclude_lists", String(args.exclude_lists)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.status != null) query.append("status", String(args.status)) if (args.claimed_by != null) query.append("claimed_by", String(args.claimed_by)) if (args.geofence != null) query.append("geofence", String(args.geofence)) if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/worksites${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(getApiWorksitesResponse, await res.json()) };