import {z} from 'zod' export type GetApiGsuitesGsuiteIdTranslationrulesIdOptions = {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 }; /** * Gets a specific G Suite translation rule * * GET /gsuites/{gsuite_id}/translationrules/{id} */ export const getApiGsuitesGsuiteIdTranslationrulesId = async (options?: GetApiGsuitesGsuiteIdTranslationrulesIdOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) 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()) };