import {z} from 'zod' export type GetApiApiV2GcepSystemsSystemObjectIdDeviceStateArgs = {systemObjectId: string}; export type GetApiApiV2GcepSystemsSystemObjectIdDeviceStateOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudPartnersDeviceUser = z.object({deviceUserId: z.string().optional(), googleEmail: z.string().optional(), lastSuccessfulReportedTime: z.string().nullable().optional(), localDeviceUsername: z.string().optional()}); export const jumpcloudPartnersManagementStatus = z.enum(["managed_unspecified", "managed", "not_managed"]); export const jumpcloudPartnersRegistrationStatus = z.enum(["not_registered", "registered"]); export const jumpcloudPartnersGetDeviceStateResponse = z.object({deviceUsers: z.array(jumpcloudPartnersDeviceUser).optional(), managementStatus: jumpcloudPartnersManagementStatus.optional(), registrationStatus: jumpcloudPartnersRegistrationStatus.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 }; /** * Returns GCEP device trust state from the partners sync mirror for a system. * * GET /api/v2/gcep/systems/{systemObjectId}/device-state */ export const getApiApiV2GcepSystemsSystemObjectIdDeviceState = async (args: GetApiApiV2GcepSystemsSystemObjectIdDeviceStateArgs, options?: GetApiApiV2GcepSystemsSystemObjectIdDeviceStateOptions) => { const {baseUrl = "https://console.jumpcloud.com", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/gcep/systems/${encodeURIComponent(String(args.systemObjectId))}/device-state${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(jumpcloudPartnersGetDeviceStateResponse, await res.json()) };