import {z} from 'zod' export type GSuiteBuiltinTranslation = 'user_home_addresses' | 'user_work_addresses' | 'user_other_addresses' | 'user_home_phone_numbers' | 'user_mobile_phone_numbers' | 'user_other_phone_numbers' | 'user_work_phone_numbers' | 'user_work_fax_phone_numbers' | 'user_work_mobile_phone_numbers' | 'user_manager' | 'user_alternate_email' | 'user_primary_organization_cost_center' | 'user_primary_organization_department' | 'user_primary_organization_description' | 'user_primary_organization_employee_id' | 'user_primary_organization_title' | 'user_status' | 'user_password'; export type GSuiteDirectionTranslation = 'export' | 'import'; export type GSuiteTranslationRuleRequest = {builtIn?: GSuiteBuiltinTranslation | undefined, direction?: GSuiteDirectionTranslation | undefined}; export type CreateApiGsuitesGsuiteIdTranslationrulesArgs = {body: GSuiteTranslationRuleRequest}; export type CreateApiGsuitesGsuiteIdTranslationrulesOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const gSuiteBuiltinTranslation = z.enum(["user_home_addresses", "user_work_addresses", "user_other_addresses", "user_home_phone_numbers", "user_mobile_phone_numbers", "user_other_phone_numbers", "user_work_phone_numbers", "user_work_fax_phone_numbers", "user_work_mobile_phone_numbers", "user_manager", "user_alternate_email", "user_primary_organization_cost_center", "user_primary_organization_department", "user_primary_organization_description", "user_primary_organization_employee_id", "user_primary_organization_title", "user_status", "user_password"]); export const gSuiteDirectionTranslation = z.enum(["export", "import"]); export const gSuiteTranslationRule = z.object({builtIn: gSuiteBuiltinTranslation.optional(), direction: gSuiteDirectionTranslation.optional(), id: 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 new G Suite Translation Rule * * POST /gsuites/{gsuite_id}/translationrules */ export const createApiGsuitesGsuiteIdTranslationrules = async (args: CreateApiGsuitesGsuiteIdTranslationrulesArgs, options?: CreateApiGsuitesGsuiteIdTranslationrulesOptions) => { 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 (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/gsuites/${encodeURIComponent(String(args.gsuite_id))}/translationrules${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(gSuiteTranslationRule, await res.json()) };