import {z} from 'zod' export type CreateApiHubManagementOccupanciesEndUserThirdPartyArgs = {body: {phone_number: string, otp: string}}; export type CreateApiHubManagementOccupanciesEndUserThirdPartyOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiHubManagementOccupanciesEndUserThirdPartyResponse = z.object({uuid: z.string().optional(), picker: z.object({phone_number: z.string().max(128).nullable().optional(), full_name: z.string().max(256).nullable().optional()}).optional(), status: z.enum(["in_queue", "reserved", "occupied", "unoccupied", "returned", "canceled", "excepted", "expired", "blocked", "delayed", "notdropped", "notpacked", "recoordinated"]).optional(), process: z.string().optional(), expected_check_in: z.string(), expected_check_out: z.string(), check_in: z.string(), check_out: z.string(), station: z.object({uuid: z.string().optional(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), address: z.string().max(400).nullable().optional(), nickname: z.string().max(255).nullable().optional()}).optional(), shipment: z.object({supplier: z.string().optional(), external_id: z.string().max(128).nullable().optional(), parcels: z.array(z.object({external_id: z.string().max(128).nullable().optional(), dimension: z.object({width: z.number(), height: z.number(), length: z.number()})}))}).optional(), verbose_id: z.string().max(50).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 /hub-management/occupancies/end-user/third-party */ export const createApiHubManagementOccupanciesEndUserThirdParty = async (args: CreateApiHubManagementOccupanciesEndUserThirdPartyArgs, options?: CreateApiHubManagementOccupanciesEndUserThirdPartyOptions) => { 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(/\/+$/, '')}/hub-management/occupancies/end-user/third-party${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(createApiHubManagementOccupanciesEndUserThirdPartyResponse, await res.json()) };