import {z} from 'zod' export type SyncroMappingRequest = {data?: (Array<{organization: {id: string, name: string | null}, delete?: boolean | undefined, company: {id: string | null, name: string | null}, billingConfigurations?: ({fields?: ({line_item_name?: ({stringValue?: string | undefined, kind?: string | undefined}) | undefined, line_item_id?: ({numberValue?: number | undefined, kind?: string | undefined}) | undefined, schedule_name?: ({stringValue?: string | undefined, kind?: string | undefined}) | undefined, schedule_id?: ({numberValue?: number | undefined, kind?: string | undefined}) | undefined}) | undefined} | null) | undefined}>) | undefined}; export type PatchApiApiV2IntegrationsSyncroUUIDMappingsArgs = {body: SyncroMappingRequest}; export type PatchApiApiV2IntegrationsSyncroUUIDMappingsOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const syncroMappingRequest = z.object({data: z.array(z.object({organization: z.object({id: z.string().min(1), name: z.string().nullable()}), delete: z.boolean().optional(), company: z.object({id: z.string().nullable(), name: z.string().nullable()}), billingConfigurations: z.object({fields: z.object({line_item_name: z.object({stringValue: z.string().optional(), kind: z.string().optional()}).optional(), line_item_id: z.object({numberValue: z.number().optional(), kind: z.string().optional()}).optional(), schedule_name: z.object({stringValue: z.string().optional(), kind: z.string().optional()}).optional(), schedule_id: z.object({numberValue: z.number().optional(), kind: z.string().optional()}).optional()}).optional()}).nullable().optional()})).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, edit, and/or delete Syncro Mappings * * PATCH /api/v2/integrations/syncro/{UUID}/mappings */ export const patchApiApiV2IntegrationsSyncroUUIDMappings = async (args: PatchApiApiV2IntegrationsSyncroUUIDMappingsArgs, options?: PatchApiApiV2IntegrationsSyncroUUIDMappingsOptions) => { 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/integrations/syncro/${encodeURIComponent(String(args.UUID))}/mappings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(syncroMappingRequest, await res.json()) };