import {z} from 'zod' export type GetApiHubManagementOccupanciesUuidOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiHubManagementOccupanciesUuidResponse = z.object({pk: z.number().int().optional(), uuid: z.string().optional(), verbose_id: z.string().min(1).max(50).optional(), status: z.string().optional(), process: z.string().optional(), station: z.object({uuid: z.string().optional(), address: z.string().max(400).nullable().optional(), location: z.string().optional(), nickname: z.string().max(255).nullable().optional(), postal_code: z.string().max(10).nullable().optional(), images: z.array(z.string()).optional(), districts: z.object({}).nullable().optional()}).optional(), shipment_external_id: z.string().min(1).optional(), picker_phone_number: z.string().min(1).optional(), picker_first_name: z.string().min(1).optional(), picker_last_name: z.string().min(1).optional(), picker_full_name: z.string().min(1).optional(), dropper_phone_number: z.string().min(1).optional(), dropper_first_name: z.string().min(1).optional(), dropper_last_name: z.string().min(1).optional(), users: z.object({supplier: z.string().optional(), picker: z.string().optional(), dropper: z.string().optional()}).optional(), dates: z.object({time_scope: z.object({expected_check_in: z.string(), expected_duration: z.string()}).optional(), order_date: z.string().optional(), check_in: z.string().optional(), check_out: z.string().optional(), cancel_date: z.string().optional(), extend_date: z.string().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 }; /** * Shows an occupancy's detail. * * GET /hub-management/occupancies/{uuid} */ export const getApiHubManagementOccupanciesUuid = async (options?: GetApiHubManagementOccupanciesUuidOptions) => { const {baseUrl = "https://api.ganje.net/v1.1", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/hub-management/occupancies/${encodeURIComponent(String(args.uuid))}${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(getApiHubManagementOccupanciesUuidResponse, await res.json()) };