import {z} from 'zod' export type RoleModel = {id?: number | undefined, description?: string | undefined, hourlyFactor?: number | undefined, hourlyRate?: number | undefined, isActive?: boolean | undefined, isExcludedFromNewContracts?: boolean | undefined, isSystemRole?: boolean | undefined, name?: string | undefined, quoteItemDefaultTaxCategoryId?: number | undefined, roleType?: number | undefined}; export type UpdateApiV10RolesArgs = {ApiIntegrationCode: string, UserName: string, Secret: string, ImpersonationResourceId?: string | undefined, body: RoleModel}; export type UpdateApiV10RolesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const object = z.object({}); export const operationResultModel = z.object({itemId: object.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 }; /** * PUT /V1.0/Roles */ export const updateApiV10Roles = async (args: UpdateApiV10RolesArgs, options?: UpdateApiV10RolesOptions) => { const {baseUrl = "https://webservices5.autotask.net/ATServicesRest", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.ApiIntegrationCode != null) headers.set("ApiIntegrationCode", String(args.ApiIntegrationCode)) if (args.UserName != null) headers.set("UserName", String(args.UserName)) if (args.Secret != null) headers.set("Secret", String(args.Secret)) if (args.ImpersonationResourceId != null) headers.set("ImpersonationResourceId", String(args.ImpersonationResourceId)) const url = `${baseUrl.replace(/\/+$/, '')}/V1.0/Roles${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(operationResultModel, await res.json()) };