import {z} from 'zod' export type GetApiAsyncchangerequestsArgs = {ids?: string | undefined, parent_id?: number | undefined, orgid?: number | undefined, userid?: number | undefined, request_type?: ('plan_change' | 'euicc_audit' | 'sim_configuration_update' | 'sim_state_pause' | 'sim_state_unpause' | 'sim_state_activation') | undefined, reference_type?: ('device' | 'link' | 'simcard' | 'sim_configuration') | undefined, reference_id?: number | undefined, deviceids?: string | undefined, 'states[]'?: (Array<'initialized' | 'in_progress' | 'complete' | 'complete_with_errors' | 'partially_complete' | 'error' | 'canceled' | 'complete_after_cancel'>) | undefined, start_after?: string | undefined, start_before?: string | undefined, startafter?: number | undefined, limit?: number | undefined}; export type GetApiAsyncchangerequestsOptions = {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 listAsyncChangeRequestsResponse = z.object({success: successProperty.optional(), limit: z.number().int().optional(), size: z.number().int().optional(), continues: z.boolean().optional(), lastid: z.number().int().optional(), data: z.array(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 }; /** * List async change requests * * GET /asyncchangerequests */ export const getApiAsyncchangerequests = async (args: GetApiAsyncchangerequestsArgs, options?: GetApiAsyncchangerequestsOptions) => { 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 (args.ids != null) query.append("ids", String(args.ids)) if (args.parent_id != null) query.append("parent_id", String(args.parent_id)) if (args.orgid != null) query.append("orgid", String(args.orgid)) if (args.userid != null) query.append("userid", String(args.userid)) if (args.request_type != null) query.append("request_type", String(args.request_type)) if (args.reference_type != null) query.append("reference_type", String(args.reference_type)) if (args.reference_id != null) query.append("reference_id", String(args.reference_id)) if (args.deviceids != null) query.append("deviceids", String(args.deviceids)) for (const item of args['states[]'] ?? []) query.append("states[]", String(item)) if (args.start_after != null) query.append("start_after", String(args.start_after)) if (args.start_before != null) query.append("start_before", String(args.start_before)) if (args.startafter != null) query.append("startafter", String(args.startafter)) if (args.limit != null) query.append("limit", String(args.limit)) if (apiKeyAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKeyAuth.username}:${apiKeyAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/asyncchangerequests${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(listAsyncChangeRequestsResponse, await res.json()) };