import {z} from 'zod' export type Externallymanagedpropertyinfo = boolean; export type Mfa = {configured?: boolean | undefined, exclusion?: boolean | undefined, exclusionUntil?: string | undefined, exclusionDays?: number | undefined}; export type Sshkeypost = {name: string, public_key: string}; export type RestrictedField = {field?: ('addresses' | 'company' | 'costCenter' | 'department' | 'description' | 'displayname' | 'email' | 'employeeIdentifier' | 'employeeType' | 'firstname' | 'jobTitle' | 'lastname' | 'location' | 'middlename' | 'password' | 'phoneNumbers' | 'sudo' | 'username') | undefined, type?: ('active_directory' | 'federated_identity_provider' | 'scim') | undefined, id?: string | undefined}; export type Systemuserput = {account_locked?: boolean | undefined, addresses?: (Array<{country?: string | undefined, extendedAddress?: string | undefined, locality?: string | undefined, poBox?: string | undefined, postalCode?: string | undefined, region?: string | undefined, streetAddress?: string | undefined, type?: string | undefined}>) | undefined, allow_public_key?: boolean | undefined, alternateEmail?: string | undefined, attributes?: (Array<{name?: string | undefined, value?: string | undefined}>) | undefined, company?: string | undefined, costCenter?: string | undefined, department?: string | undefined, description?: string | undefined, disableDeviceMaxLoginAttempts?: boolean | undefined, displayname?: string | undefined, email?: string | undefined, employeeIdentifier?: string | undefined, employeeType?: string | undefined, enable_managed_uid?: boolean | undefined, enable_user_portal_multifactor?: boolean | undefined, external_dn?: string | undefined, external_password_expiration_date?: string | undefined, external_source_type?: string | undefined, externally_managed?: Externallymanagedpropertyinfo | undefined, firstname?: string | undefined, jobTitle?: string | undefined, lastname?: string | undefined, ldap_binding_user?: boolean | undefined, location?: string | undefined, manager?: string | undefined, mfa?: Mfa | undefined, middlename?: string | undefined, password?: string | undefined, password_never_expires?: boolean | undefined, phoneNumbers?: (Array<{number?: string | undefined, type?: string | undefined}>) | undefined, public_key?: string | undefined, relationships?: (Array<{type?: string | undefined, value?: string | undefined}>) | undefined, samba_service_user?: boolean | undefined, ssh_keys?: Array | undefined, state?: ('ACTIVATED' | 'SUSPENDED') | undefined, sudo?: boolean | undefined, suspended?: boolean | undefined, tags?: Array | undefined, unix_guid?: number | undefined, unix_uid?: number | undefined, username?: string | undefined, managedAppleId?: string | undefined, delegatedAuthority?: ({name?: 'ActiveDirectory' | undefined, id?: string | undefined} | null) | undefined, restrictedFields?: Array | undefined}; export type UpdateApiApiSystemusersIdArgs = {'x-org-id'?: string | undefined, fullValidationDetails?: string | undefined, body: Systemuserput}; export type UpdateApiApiSystemusersIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const attribute = z.object({name: z.string().optional(), value: z.string().max(1024).optional()}); export const externallymanagedpropertyinfo = z.boolean(); export const mfa = z.object({configured: z.boolean().optional(), exclusion: z.boolean().optional(), exclusionUntil: z.string().optional(), exclusionDays: z.number().int().gte(1).optional()}); export const mfaEnrollmentStatus = z.enum(["NOT_ENROLLED", "DISABLED", "PENDING_ACTIVATION", "ENROLLMENT_EXPIRED", "IN_ENROLLMENT", "PRE_ENROLLMENT", "ENROLLED"]); export const mfaEnrollment = z.object({totpStatus: mfaEnrollmentStatus.optional(), webAuthnStatus: mfaEnrollmentStatus.optional(), pushStatus: mfaEnrollmentStatus.optional(), smsStatus: mfaEnrollmentStatus.optional(), overallStatus: mfaEnrollmentStatus.optional(), jcGoStatus: mfaEnrollmentStatus.optional()}); export const sshkeylist = z.object({_id: z.string().optional(), create_date: z.string().optional(), name: z.string().optional(), public_key: z.string().optional()}); export const restrictedField = z.object({field: z.enum(["addresses", "company", "costCenter", "department", "description", "displayname", "email", "employeeIdentifier", "employeeType", "firstname", "jobTitle", "lastname", "location", "middlename", "password", "phoneNumbers", "sudo", "username"]).max(32).optional(), type: z.enum(["active_directory", "federated_identity_provider", "scim"]).max(128).optional(), id: z.string().max(24).optional()}); export const systemuserreturn = z.object({_id: z.string().optional(), account_locked: z.boolean().optional(), account_locked_date: z.string().nullable().optional(), activated: z.boolean().optional(), admin: z.object({id: z.string().optional(), roleName: z.string().optional(), roleNames: z.array(z.string()).optional()}).nullable().optional(), addresses: z.array(z.object({country: z.string().max(1024).optional(), extendedAddress: z.string().max(1024).optional(), id: z.string().optional(), locality: z.string().max(1024).optional(), poBox: z.string().max(1024).optional(), postalCode: z.string().max(1024).optional(), region: z.string().max(1024).optional(), streetAddress: z.string().max(1024).optional(), type: z.string().max(1024).optional()})).optional(), allow_public_key: z.boolean().optional(), alternateEmail: z.string().optional(), attributes: z.array(attribute).optional(), badLoginAttempts: z.number().int().gte(0).optional(), company: z.string().max(1024).optional(), costCenter: z.string().max(1024).optional(), created: z.string().optional(), department: z.string().max(1024).optional(), description: z.string().max(1024).optional(), disableDeviceMaxLoginAttempts: z.boolean().optional(), displayname: z.string().max(1024).optional(), email: z.string().max(1024).optional(), employeeIdentifier: z.string().max(256).optional(), employeeType: z.string().max(1024).optional(), enable_managed_uid: z.boolean().optional(), enable_user_portal_multifactor: z.boolean().optional(), external_dn: z.string().optional(), external_password_expiration_date: z.string().optional(), external_source_type: z.string().optional(), externally_managed: externallymanagedpropertyinfo.optional(), firstname: z.string().max(1024).optional(), jobTitle: z.string().max(1024).optional(), lastname: z.string().max(1024).optional(), ldap_binding_user: z.boolean().optional(), location: z.string().max(1024).optional(), manager: z.string().optional(), mfa: mfa.optional(), mfaEnrollment: mfaEnrollment.optional(), middlename: z.string().max(1024).optional(), organization: z.string().optional(), password_date: z.string().nullable().optional(), password_expiration_date: z.string().nullable().optional(), password_expired: z.boolean().optional(), password_never_expires: z.boolean().optional(), passwordless_sudo: z.boolean().optional(), phoneNumbers: z.array(z.object({id: z.string().optional(), number: z.string().max(1024).optional(), type: z.string().max(1024).optional()})).optional(), public_key: z.string().optional(), recoveryEmail: z.object({address: z.string().optional(), verified: z.boolean().optional(), verifiedAt: z.string().optional()}).optional(), relationships: z.array(z.object({type: z.string().optional(), value: z.string().optional()})).optional(), samba_service_user: z.boolean().optional(), ssh_keys: z.array(sshkeylist).optional(), state: z.enum(["STAGED", "ACTIVATED", "SUSPENDED"]).optional(), sudo: z.boolean().optional(), suspended: z.boolean().optional(), tags: z.array(z.string()).optional(), totp_enabled: z.boolean().optional(), unix_guid: z.number().int().gte(1).optional(), unix_uid: z.number().int().gte(1).optional(), username: z.string().max(1024).optional(), managedAppleId: z.string().max(1024).optional(), creationSource: z.string().max(1024).optional(), delegatedAuthority: z.object({name: z.literal("ActiveDirectory").optional(), id: z.string().optional()}).nullable().optional(), restrictedFields: z.array(restrictedField).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 }; /** * Update a system user * * PUT /api/systemusers/{id} */ export const updateApiApiSystemusersId = async (args: UpdateApiApiSystemusersIdArgs, options?: UpdateApiApiSystemusersIdOptions) => { const {baseUrl = "https://console.jumpcloud.com", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-org-id'] != null) headers.set("x-org-id", String(args['x-org-id'])) if (args.fullValidationDetails != null) query.append("fullValidationDetails", String(args.fullValidationDetails)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/systemusers/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(systemuserreturn, await res.json()) };