import {z} from 'zod' export type CreateApiP2pDeliveryOccupancyOccupancyUuidReviveArgs = {body: {parcels?: Array | undefined}}; export type CreateApiP2pDeliveryOccupancyOccupancyUuidReviveOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiP2pDeliveryOccupancyOccupancyUuidReviveResponse = z.object({occupancy_uuid: z.string().optional(), shipment_id: z.string().optional(), external_id: z.string().optional(), parcels: z.array(z.object({id: z.number().int().optional(), submitter_id: z.string().optional(), weight: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), value: z.number().nullable().optional(), temp_size: z.object({uuid: z.string().optional(), name: z.string().max(100).nullable().optional(), length: z.number().optional(), width: z.number().optional(), height: z.number().optional()})})), status: z.enum(["reservable", "reserved", "failed_to_reserve", "canceled"]).optional(), logistic_company: z.object({pk: z.number().int(), uuid: z.string().optional(), name: z.string().max(50).optional()}), sender: z.object({phone_number: z.string().min(1), first_name: z.string().max(150).optional(), last_name: z.string().max(150).optional(), full_name: z.string().max(256).nullable().optional()}), recipient: z.object({phone_number: z.string().min(1), first_name: z.string().max(150).optional(), last_name: z.string().max(150).optional(), full_name: z.string().max(256).nullable().optional()}), destination_location: z.object({city: z.object({id: z.number().int().optional(), name: z.string().min(1).max(255), province: z.object({id: z.number().int().optional(), name: z.string().min(1).max(255)})}), address: z.string().min(1).max(400).optional(), latitude: z.number().nullable().optional(), longitude: z.number().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 }; /** * POST /p2p-delivery/occupancy/{occupancy_uuid}/revive */ export const createApiP2pDeliveryOccupancyOccupancyUuidRevive = async (args: CreateApiP2pDeliveryOccupancyOccupancyUuidReviveArgs, options?: CreateApiP2pDeliveryOccupancyOccupancyUuidReviveOptions) => { const {baseUrl = "https://api.ganje.net/v1.1", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/p2p-delivery/occupancy/${encodeURIComponent(String(args.occupancy_uuid))}/revive${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiP2pDeliveryOccupancyOccupancyUuidReviveResponse, await res.json()) };