import {z} from 'zod' export type GetApiApiV2IdentityriskIdentitiesObjectIdArgs = {objectId: string}; export type GetApiApiV2IdentityriskIdentitiesObjectIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudIdentityRiskDevice = z.object({isPrimary: z.boolean().optional(), name: z.string().optional(), operatingSystem: z.string().optional(), osVersion: z.string().optional()}); export const jumpcloudIdentityRiskBrowser = z.object({isPrimary: z.boolean().optional(), name: z.string().optional()}); export const jumpcloudIdentityRiskTypicalLoginHour = z.object({count: z.number().int().optional(), hour: z.string().optional()}); export const jumpcloudIdentityRiskLoginLocation = z.object({city: z.string().optional(), countryName: z.string().optional(), isPrimary: z.boolean().optional(), percentage: z.string().optional()}); export const jumpcloudIdentityRiskNetwork = z.object({isPrimary: z.boolean().optional(), network: z.string().optional(), networkType: z.string().optional()}); export const jumpcloudIdentityRiskProfile = z.object({applications: z.array(z.string()).optional(), avgLoginSessionCountPerDay: z.number().int().optional(), deviceIds: z.array(z.string()).optional(), devices: z.array(jumpcloudIdentityRiskDevice).optional(), objectId: z.string().optional(), profileData: z.object({}).optional(), typicalBrowsers: z.array(jumpcloudIdentityRiskBrowser).optional(), typicalLoginDays: z.array(z.string()).optional(), typicalLoginHours: z.array(jumpcloudIdentityRiskTypicalLoginHour).optional(), typicalLoginHoursEnd: z.string().optional(), typicalLoginHoursStart: z.string().optional(), typicalLoginLocations: z.array(jumpcloudIdentityRiskLoginLocation).optional(), typicalNetworks: z.array(jumpcloudIdentityRiskNetwork).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 identity profile by object_id. * * GET /api/v2/identityrisk/identities/{objectId} */ export const getApiApiV2IdentityriskIdentitiesObjectId = async (args: GetApiApiV2IdentityriskIdentitiesObjectIdArgs, options?: GetApiApiV2IdentityriskIdentitiesObjectIdOptions) => { 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/identityrisk/identities/${encodeURIComponent(String(args.objectId))}${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(jumpcloudIdentityRiskProfile, await res.json()) };