import {z} from 'zod' export type JumpcloudGoogleEmmCreateEnterpriseRequest = {enrollmentToken?: string | undefined, signupUrlName?: string | undefined}; export type CreateApiApiV2GoogleEmmEnterprisesArgs = {body: JumpcloudGoogleEmmCreateEnterpriseRequest}; export type CreateApiApiV2GoogleEmmEnterprisesOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudGoogleEmmEnterpriseType = z.enum(["ENTERPRISE_TYPE_UNSPECIFIED", "MANAGED_GOOGLE_PLAY_ACCOUNTS_ENTERPRISE", "MANAGED_GOOGLE_DOMAIN"]); export const jumpcloudGoogleEmmGoogleAuthenticationRequired = z.enum(["GOOGLE_AUTHENTICATION_REQUIRED_UNSPECIFIED", "NOT_REQUIRED", "REQUIRED"]); export const jumpcloudGoogleEmmEnterprise = z.object({allowDeviceEnrollment: z.boolean().optional(), contactEmail: z.string().optional(), createdAt: z.string().optional(), deviceGroupId: z.string().optional(), displayName: z.string().optional(), enterpriseType: jumpcloudGoogleEmmEnterpriseType.optional(), googleAuthenticationRequired: jumpcloudGoogleEmmGoogleAuthenticationRequired.optional(), name: z.string().optional(), objectId: z.string().optional(), organizationObjectId: 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 a Google Enterprise * * POST /api/v2/google-emm/enterprises */ export const createApiApiV2GoogleEmmEnterprises = async (args: CreateApiApiV2GoogleEmmEnterprisesArgs, options?: CreateApiApiV2GoogleEmmEnterprisesOptions) => { 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${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(jumpcloudGoogleEmmEnterprise, await res.json()) };