import {z} from 'zod' export type JumpcloudGoogleEmmAllowPersonalUsage = 'PERSONAL_USAGE_ALLOWED' | 'PERSONAL_USAGE_DISALLOWED' | 'PERSONAL_USAGE_DISALLOWED_USERLESS'; export type JumpcloudGoogleEmmCreatedWhere = 'API' | 'ADMIN_PORTAL' | 'USER_PORTAL'; export type JumpcloudGoogleEmmEnrollmentType = 'WORK_PROFILE' | 'FULLY_MANAGED' | 'DEDICATED' | 'BYOD' | 'COPE'; export type JumpcloudGoogleEmmWifiSecurityType = 'NONE' | 'WPA' | 'WEP'; export type JumpcloudGoogleEmmProvisioningExtras = {allowOfflineProvisioning?: boolean | undefined, enableSystemApps?: boolean | undefined, keepScreenOn?: boolean | undefined, language?: string | undefined, skipEducationScreens?: boolean | undefined, timeZone?: string | undefined, useMobileNetworkForProvisioning?: boolean | undefined, wifiHiddenNetwork?: boolean | undefined, wifiPassword?: string | undefined, wifiSecurityType?: JumpcloudGoogleEmmWifiSecurityType | undefined, wifiSsid?: string | undefined}; export type CreateApiApiV2GoogleEmmEnterprisesEnterpriseObjectIdEnrollmentTokensArgs = {enterpriseObjectId: string, body: {allowPersonalUsage?: JumpcloudGoogleEmmAllowPersonalUsage | undefined, createdWhere?: JumpcloudGoogleEmmCreatedWhere | undefined, displayName?: string | undefined, duration?: string | undefined, enrollmentType?: JumpcloudGoogleEmmEnrollmentType | undefined, oneTimeOnly?: boolean | undefined, provisioningExtras?: JumpcloudGoogleEmmProvisioningExtras | undefined, userObjectId?: string | undefined, zeroTouch?: boolean | undefined}}; export type CreateApiApiV2GoogleEmmEnterprisesEnterpriseObjectIdEnrollmentTokensOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudGoogleEmmEnrollmentToken = z.object({createdBy: z.string().optional(), createdWhere: z.string().optional(), displayName: z.string().optional(), enrollmentLink: z.string().optional(), enrollmentType: z.string().optional(), expirationTime: z.string().optional(), id: z.string().optional(), metadata: z.string().optional(), name: z.string().optional(), oneTimeOnly: z.boolean().optional(), organizationObjectId: z.string().optional(), qrCodeImage: z.string().optional(), value: z.string().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 }; /** * Create an enrollment token for a given enterprise * * POST /api/v2/google-emm/enterprises/{enterpriseObjectId}/enrollment-tokens */ export const createApiApiV2GoogleEmmEnterprisesEnterpriseObjectIdEnrollmentTokens = async (args: CreateApiApiV2GoogleEmmEnterprisesEnterpriseObjectIdEnrollmentTokensArgs, options?: CreateApiApiV2GoogleEmmEnterprisesEnterpriseObjectIdEnrollmentTokensOptions) => { 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 (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/google-emm/enterprises/${encodeURIComponent(String(args.enterpriseObjectId))}/enrollment-tokens${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(jumpcloudGoogleEmmEnrollmentToken, await res.json()) };