import {z} from 'zod' export type GetApiAssetsDevicesIdHistoryArgs = {id: string, limit?: number | undefined, skip?: number | undefined}; export type GetApiAssetsDevicesIdHistoryOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudHttpAssetsChangeValue = z.object({value: z.unknown()}); export const jumpcloudHttpAssetsFieldChange = z.object({label: z.string(), oldValue: jumpcloudHttpAssetsChangeValue.optional(), newValue: jumpcloudHttpAssetsChangeValue.optional()}); export const jumpcloudHttpAssetsActor = z.object({id: z.string().optional(), name: z.string(), type: z.enum(["ACTOR_TYPE_USER", "ACTOR_TYPE_SYSTEM", "ACTOR_TYPE_SERVICE_ACCOUNT", "ACTOR_TYPE_SYSTEM_USER"])}); export const jumpcloudHttpAssetsAssetHistoryEvent = z.object({eventType: z.enum(["ASSET_HISTORY_EVENT_TYPE_CREATE", "ASSET_HISTORY_EVENT_TYPE_DELETE", "ASSET_HISTORY_EVENT_TYPE_UPDATE_FIELDS", "ASSET_HISTORY_EVENT_TYPE_UPDATE_STATUS", "ASSET_HISTORY_EVENT_TYPE_UPDATE_LOCATION", "ASSET_HISTORY_EVENT_TYPE_UPDATE_OWNER", "ASSET_HISTORY_EVENT_TYPE_UPDATE_AGENT_STATUS", "ASSET_HISTORY_EVENT_TYPE_UPDATE_MFA_STATUS", "ASSET_HISTORY_EVENT_TYPE_UPDATE_MDM_STATUS", "ASSET_HISTORY_EVENT_TYPE_NOTE"]), note: z.string().optional(), changedFields: z.array(jumpcloudHttpAssetsFieldChange).optional(), occurredAt: z.string(), actor: jumpcloudHttpAssetsActor, actionSource: z.enum(["ACTION_SOURCE_MANUAL", "ACTION_SOURCE_SYSTEM", "ACTION_SOURCE_IMPORT", "ACTION_SOURCE_API"])}); export const jumpcloudHttpAssetsAssetHistoryResponse = z.object({results: z.array(jumpcloudHttpAssetsAssetHistoryEvent), totalCount: z.number().int()}); 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 device asset history * * GET /assets/devices/{id}/history */ export const getApiAssetsDevicesIdHistory = async (args: GetApiAssetsDevicesIdHistoryArgs, options?: GetApiAssetsDevicesIdHistoryOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/assets/devices/${encodeURIComponent(String(args.id))}/history${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(jumpcloudHttpAssetsAssetHistoryResponse, await res.json()) };