import {z} from 'zod' export type ServiceChannelServicesMessagingUsersDashboardInfo = {Id?: number | undefined, Name?: string | undefined, RedirectToDashboard?: boolean | undefined}; export type ServiceChannelServicesMessagingUsersAccessOptions = {Locations?: Array | undefined, Districts?: Array | undefined, Regions?: Array | undefined, Trades?: Array | undefined}; export type ServiceChannelServicesMessagingUsersLimit = {Amount?: number | undefined, CurrencyId?: number | undefined}; export type ServiceChannelServicesMessagingUsersLimitOptions = {NteLimit?: ServiceChannelServicesMessagingUsersLimit | undefined, ProposalLimit?: ServiceChannelServicesMessagingUsersLimit | undefined, InvoiceLimit?: ServiceChannelServicesMessagingUsersLimit | undefined}; export type ServiceChannelServicesMessagingUsersMliUserInfo = {Id?: number | undefined, MliLevel?: string | undefined, MliLocations?: Array | undefined}; export type ServiceChannelServicesMessagingUsersMlpUserInfo = {Id?: number | undefined, MlpLevel?: string | undefined, MlpLocations?: Array | undefined}; export type ServiceChannelServicesMessagingUsersUser = {Id?: number | undefined, SubscriberId?: number | undefined, UserName?: string | undefined, FullName?: string | undefined, Email?: string | undefined, PsmEmail?: string | undefined, Disabled?: boolean | undefined, IsLocked?: boolean | undefined, Roles?: Array | undefined, Permissions?: Array | undefined, UserType?: ('Corporate' | 'Dashboard' | 'ServiceChannel') | undefined, Dashboard?: ServiceChannelServicesMessagingUsersDashboardInfo | undefined, Access?: ServiceChannelServicesMessagingUsersAccessOptions | undefined, Limits?: ServiceChannelServicesMessagingUsersLimitOptions | undefined, FeedRole?: string | undefined, MliUserInfo?: ServiceChannelServicesMessagingUsersMliUserInfo | undefined, MlpUserInfo?: ServiceChannelServicesMessagingUsersMlpUserInfo | undefined}; export type ServiceChannelServicesMessagingUsersUpdateUserRequest = {Id?: number | undefined, InfoSubscriberId?: number | undefined, UserName?: string | undefined, Password?: string | undefined, Email?: string | undefined, LocationAccess?: string | undefined, FeedRole?: string | undefined, User?: ServiceChannelServicesMessagingUsersUser | undefined}; export type UpdateApiUsersIdArgs = {id: number, body: ServiceChannelServicesMessagingUsersUpdateUserRequest}; export type UpdateApiUsersIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const systemObject = z.object({}); 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 }; /** * Update a user * * PUT /users/{id} */ export const updateApiUsersId = async (args: UpdateApiUsersIdArgs, options?: UpdateApiUsersIdOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.id))}${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(systemObject, await res.json()) };