import {z} from 'zod' export type GetApiAsyncchangerequestsRequestIdArgs = {requestId: number}; export type GetApiAsyncchangerequestsRequestIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const successProperty = z.boolean(); export const asyncChangeRequest = z.object({id: z.number().int().optional(), parent_id: z.number().int().nullable().optional(), orgid: z.number().int().nullable().optional(), userid: z.number().int().nullable().optional(), request_type: z.enum(["plan_change", "euicc_audit", "sim_configuration_update", "sim_state_pause", "sim_state_unpause", "sim_state_activation"]).optional(), reference_type: z.enum(["device", "link", "simcard", "sim_configuration"]).optional(), reference_id: z.number().int().optional(), state: z.enum(["initialized", "in_progress", "complete", "complete_with_errors", "partially_complete", "error", "canceled", "complete_after_cancel"]).optional(), start_time: z.string().nullable().optional(), update_time: z.string().nullable().optional(), metadata: z.object({}).nullable().optional(), child_ids: z.array(z.number().int()).optional()}); export const asyncChangeRequestResponse = z.object({success: successProperty.optional(), data: asyncChangeRequest.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 }; /** * Get a single async change request by ID * * GET /asyncchangerequests/{requestId} */ export const getApiAsyncchangerequestsRequestId = async (args: GetApiAsyncchangerequestsRequestIdArgs, options?: GetApiAsyncchangerequestsRequestIdOptions) => { const {baseUrl = "https://dashboard.hologram.io/api/1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKeyAuth.username}:${apiKeyAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/asyncchangerequests/${encodeURIComponent(String(args.requestId))}${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(asyncChangeRequestResponse, await res.json()) };