import {z} from 'zod' export type GetApiIdentityriskEventsObjectIdArgs = {objectId: string}; export type GetApiIdentityriskEventsObjectIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudIdentityRiskIdentityType = z.enum(["IDENTITY_TYPE_UNSPECIFIED", "IDENTITY_TYPE_ADMIN", "IDENTITY_TYPE_USER"]); export const jumpcloudIdentityRiskRiskLevel = z.enum(["RISK_LEVEL_NONE", "RISK_LEVEL_LOW", "RISK_LEVEL_MEDIUM", "RISK_LEVEL_HIGH", "RISK_LEVEL_CRITICAL"]); export const jumpcloudIdentityRiskTargetResourceType = z.enum(["TARGET_RESOURCE_TYPE_UNSPECIFIED", "TARGET_RESOURCE_TYPE_USER_PORTAL", "TARGET_RESOURCE_TYPE_ADMIN_PORTAL", "TARGET_RESOURCE_TYPE_APPLICATION", "TARGET_RESOURCE_TYPE_DEVICE"]); export const jumpcloudIdentityRiskRiskResolutionState = z.enum(["RISK_RESOLUTION_STATE_UNSPECIFIED", "RISK_RESOLUTION_STATE_SAFE", "RISK_RESOLUTION_STATE_UNSAFE"]); export const jumpcloudIdentityRiskRiskResolutionStatus = z.enum(["RISK_RESOLUTION_STATUS_UNSPECIFIED", "RISK_RESOLUTION_STATUS_OPEN", "RISK_RESOLUTION_STATUS_RESOLVED", "RISK_RESOLUTION_STATUS_MFA_RESOLVED", "RISK_RESOLUTION_STATUS_DISMISSED"]); export const jumpcloudIdentityRiskRiskFactorType = z.enum(["RISK_FACTOR_TYPE_UNSPECIFIED", "RISK_FACTOR_TYPE_NEW_DEVICE_LOGIN", "RISK_FACTOR_TYPE_UNUSUAL_GEOLOCATION", "RISK_FACTOR_TYPE_UNUSUAL_LOGIN_TIME", "RISK_FACTOR_TYPE_UNUSUAL_USER_AGENT", "RISK_FACTOR_TYPE_IMPOSSIBLE_TRAVEL", "RISK_FACTOR_TYPE_DORMANT_ACCOUNT_LOGIN", "RISK_FACTOR_TYPE_NEW_ASN", "RISK_FACTOR_TYPE_EXCESSIVE_FAILED_LOGIN_ATTEMPTS", "RISK_FACTOR_TYPE_HIGH_VOLUME_LOGIN_ATTEMPTS", "RISK_FACTOR_TYPE_UNUSUAL_APPLICATION_LOGIN", "RISK_FACTOR_TYPE_UNUSUAL_BROWSER_ID", "RISK_FACTOR_TYPE_BROWSER_ENVIRONMENT_MISMATCH", "RISK_FACTOR_TYPE_NHI_SECURITY_CONTROL_CHANGED", "RISK_FACTOR_TYPE_NHI_SENSITIVE_ACTIVITY_NEW_NETWORK", "RISK_FACTOR_TYPE_NHI_UNFAMILIAR_SENSITIVE_ACTIVITY", "RISK_FACTOR_TYPE_NHI_SENSITIVE_ACTIVITY_NEW_CREDENTIAL", "RISK_FACTOR_TYPE_NHI_RESUMED_AFTER_INACTIVITY", "RISK_FACTOR_TYPE_NHI_UNUSUAL_SENSITIVE_SEQUENCE", "RISK_FACTOR_TYPE_NHI_UNUSUAL_ACTIVITY_VOLUME"]); export const jumpcloudIdentityRiskRiskFactorSeverity = z.enum(["RISK_FACTOR_SEVERITY_UNSPECIFIED", "RISK_FACTOR_SEVERITY_LOW", "RISK_FACTOR_SEVERITY_MEDIUM", "RISK_FACTOR_SEVERITY_HIGH", "RISK_FACTOR_SEVERITY_CRITICAL"]); export const jumpcloudIdentityRiskRiskFactor = z.object({description: z.string().optional(), metadata: z.object({}).optional(), severity: jumpcloudIdentityRiskRiskFactorSeverity.optional(), type: jumpcloudIdentityRiskRiskFactorType.optional(), weight: z.number().int().optional()}); export const jumpcloudIdentityRiskRiskEvent = z.object({applicationDisplayName: z.string().optional(), applicationName: z.string().optional(), city: z.string().optional(), clientIp: z.string().optional(), countryCode: z.string().optional(), createdAt: z.string().nullable().optional(), description: z.string().optional(), diEvent: z.object({}).optional(), firstOccurrenceAt: z.string().nullable().optional(), identityDisplayName: z.string().optional(), identityIdentifier: z.string().optional(), identityObjectId: z.string().optional(), identityType: jumpcloudIdentityRiskIdentityType.optional(), lastOccurrenceAt: z.string().nullable().optional(), level: jumpcloudIdentityRiskRiskLevel.optional(), location: z.string().optional(), loginResource: jumpcloudIdentityRiskTargetResourceType.optional(), loginStatus: z.boolean().optional(), mfaMethod: z.string().optional(), mfaStatus: z.boolean().optional(), objectId: z.string().optional(), occurrenceCount: z.number().int().optional(), regionName: z.string().optional(), resolutionNotes: z.string().optional(), resolutionState: jumpcloudIdentityRiskRiskResolutionState.optional(), resolutionStatus: jumpcloudIdentityRiskRiskResolutionStatus.optional(), resolvedAt: z.string().nullable().optional(), resolvedBy: z.string().nullable().optional(), resolvedByEmail: z.string().optional(), riskFactorTypes: z.array(jumpcloudIdentityRiskRiskFactorType).optional(), riskFactors: z.array(jumpcloudIdentityRiskRiskFactor).optional(), riskPolicyId: z.string().nullable().optional(), riskPolicyName: z.string().optional(), score: z.number().int().optional(), sourceEventObjectId: z.string().optional(), sourceEventTimestamp: z.string().nullable().optional(), sourceEventType: z.string().optional(), updatedAt: z.string().nullable().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 an identity risk event by object_id. * * GET /identityrisk/events/{objectId} */ export const getApiIdentityriskEventsObjectId = async (args: GetApiIdentityriskEventsObjectIdArgs, options?: GetApiIdentityriskEventsObjectIdOptions) => { 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 (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/identityrisk/events/${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(jumpcloudIdentityRiskRiskEvent, await res.json()) };