import {z} from 'zod' export type DEPWelcomeScreen = {title?: (string | null) | undefined, paragraph?: (string | null) | undefined, button?: (string | null) | undefined}; export type SetupAssistantOption = 'accessibility' | 'actionButton' | 'appearance' | 'appleID' | 'biometric' | 'cameraButton' | 'diagnostics' | 'displayTone' | 'enableLockdownMode' | 'fileVault' | 'icloudDiagnostics' | 'icloudStorage' | 'intelligence' | 'location' | 'payment' | 'privacy' | 'restore' | 'safety' | 'screenTime' | 'siri' | 'tos' | 'termsOfAddress' | 'appStore' | 'displayZoom' | 'deviceToDeviceMigration' | 'homeButton' | 'imessageAndFacetime' | 'messagingActivationUsingPhoneNumber' | 'moveFromAndroid' | 'passcode' | 'restoreComplete' | 'setupCellular' | 'softwareUpdate' | 'unlockWithWatch' | 'updateComplete' | 'wallpaper' | 'watchMigration' | 'welcome' | 'additionalPrivacySettings' | 'multitasking' | 'osShowcase' | 'webContentFiltering' | 'safetyAndHandling' | 'liquidGlass'; export type DEPSetupAssistantOption = {option?: SetupAssistantOption | undefined}; export type DEP = {welcomeScreen?: DEPWelcomeScreen | undefined, setupAssistantOptions?: Array | undefined, enableZeroTouchEnrollment?: boolean | undefined}; export type ADE = {welcomeScreen?: DEPWelcomeScreen | undefined, setupAssistantOptions?: Array | undefined, setupOptions?: Array | undefined, enableZeroTouchEnrollment?: boolean | undefined, defaultDeviceGroupObjectIds?: (Array | null) | undefined}; export type ADES = {macos?: ADE | undefined, ios?: ADE | undefined}; export type AppleMdmPatch = {appleSignedCert?: string | undefined, encryptedDepServerToken?: string | undefined, name?: string | undefined, defaultSystemGroupID?: string | undefined, defaultIosUserEnrollmentDeviceGroupID?: string | undefined, allowMobileUserEnrollment?: boolean | undefined, dep?: DEP | undefined, ades?: ADES | undefined, appleCertCreatorAppleID?: string | undefined}; export type UpdateApiApplemdmsIdArgs = {'x-org-id'?: string | undefined, body: AppleMdmPatch}; export type UpdateApiApplemdmsIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dEPWelcomeScreen = z.object({title: z.string().max(255).nullable().optional(), paragraph: z.string().max(1024).nullable().optional(), button: z.string().max(64).nullable().optional()}); export const setupAssistantOption = z.enum(["accessibility", "actionButton", "appearance", "appleID", "biometric", "cameraButton", "diagnostics", "displayTone", "enableLockdownMode", "fileVault", "icloudDiagnostics", "icloudStorage", "intelligence", "location", "payment", "privacy", "restore", "safety", "screenTime", "siri", "tos", "termsOfAddress", "appStore", "displayZoom", "deviceToDeviceMigration", "homeButton", "imessageAndFacetime", "messagingActivationUsingPhoneNumber", "moveFromAndroid", "passcode", "restoreComplete", "setupCellular", "softwareUpdate", "unlockWithWatch", "updateComplete", "wallpaper", "watchMigration", "welcome", "additionalPrivacySettings", "multitasking", "osShowcase", "webContentFiltering", "safetyAndHandling", "liquidGlass"]); export const dEPSetupAssistantOption = z.object({option: setupAssistantOption.optional()}); export const dEP = z.object({welcomeScreen: dEPWelcomeScreen.optional(), setupAssistantOptions: z.array(dEPSetupAssistantOption).optional(), enableZeroTouchEnrollment: z.boolean().optional()}); export const aDE = z.object({welcomeScreen: dEPWelcomeScreen.optional(), setupAssistantOptions: z.array(dEPSetupAssistantOption).optional(), setupOptions: z.array(setupAssistantOption).optional(), enableZeroTouchEnrollment: z.boolean().optional(), defaultDeviceGroupObjectIds: z.array(z.string()).nullable().optional()}); export const aDES = z.object({macos: aDE.optional(), ios: aDE.optional()}); export const appleMDM = z.object({apnsPushTopic: z.string().optional(), depServerTokenState: z.enum(["unknown", "missing", "valid", "expired"]).optional(), id: z.string(), name: z.string().max(255).optional(), organization: z.string().optional(), apnsCertExpiry: z.string().nullable().optional(), depAccessTokenExpiry: z.string().nullable().optional(), defaultSystemGroupID: z.string().nullable().optional(), defaultIosUserEnrollmentDeviceGroupID: z.string().nullable().optional(), dep: dEP.optional(), allowMobileUserEnrollment: z.boolean().nullable().optional(), ades: aDES.optional(), appleCertCreatorAppleID: z.string().optional(), appleCertSerialNumber: z.string().optional(), serviceDiscoveryEnabled: z.boolean().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 }; /** * Update an Apple MDM * * PUT /applemdms/{id} */ export const updateApiApplemdmsId = async (args: UpdateApiApplemdmsIdArgs, options?: UpdateApiApplemdmsIdOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", 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 (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/applemdms/${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(appleMDM, await res.json()) };