import {z} from 'zod' export type CompanyUserAccessDTO = {trackersRead?: (boolean | null) | undefined, trackersWrite?: (boolean | null) | undefined, trackersDelete?: (boolean | null) | undefined, trackersShowOwnOnly?: (boolean | null) | undefined, balancesRead?: (boolean | null) | undefined, balancesWrite?: (boolean | null) | undefined, balancesDelete?: (boolean | null) | undefined, landingsRead?: (boolean | null) | undefined, landingsWrite?: (boolean | null) | undefined, landingsDelete?: (boolean | null) | undefined, landingsShowOwnOnly?: (boolean | null) | undefined, pwaRead?: (boolean | null) | undefined, pwaWrite?: (boolean | null) | undefined, pwaDelete?: (boolean | null) | undefined, pwaShowOwnOnly?: (boolean | null) | undefined, pushRead?: (boolean | null) | undefined, pushWrite?: (boolean | null) | undefined, pushDelete?: (boolean | null) | undefined, pushShowOwnOnly?: (boolean | null) | undefined, pixelsRead?: (boolean | null) | undefined, pixelsWrite?: (boolean | null) | undefined, pixelsDelete?: (boolean | null) | undefined, pixelsShowOwnOnly?: (boolean | null) | undefined, offersRead?: (boolean | null) | undefined, offersWrite?: (boolean | null) | undefined, offersDelete?: (boolean | null) | undefined, offersShowOwnOnly?: (boolean | null) | undefined, appEventsRead?: (boolean | null) | undefined, appEventsShowOwnOnly?: (boolean | null) | undefined, teamsRead?: (boolean | null) | undefined, teamsWrite?: (boolean | null) | undefined, teamsDelete?: (boolean | null) | undefined, membersRead?: (boolean | null) | undefined, membersWrite?: (boolean | null) | undefined, membersDelete?: (boolean | null) | undefined}; export type CompanyUserDTO = {username?: (string | null) | undefined, email?: (string | null) | undefined, teamId?: (string | null) | undefined, rolePresetSlug?: (string | null) | undefined, companyId?: (string | null) | undefined, accessList?: (CompanyUserAccessDTO | null) | undefined}; export type PatchApiApiV1CompanyUserCompanyUserIdArgs = {company_user_id: string, body: CompanyUserDTO}; export type PatchApiApiV1CompanyUserCompanyUserIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV1CompanyUserCompanyUserIdResponse = z.unknown(); 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 company user * * PATCH /api/v1/company-user/{company_user_id} */ export const patchApiApiV1CompanyUserCompanyUserId = async (args: PatchApiApiV1CompanyUserCompanyUserIdArgs, options: PatchApiApiV1CompanyUserCompanyUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/company-user/${encodeURIComponent(String(args.company_user_id))}${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(patchApiApiV1CompanyUserCompanyUserIdResponse, await res.json()) };