import {z} from 'zod' export type ObjectFilter = {kind?: string | undefined, objectIds?: Array | undefined, status?: ('NONE' | 'ASSIGNED' | 'ALL') | undefined}; export type AccountUserProfile = {accountId?: unknown | undefined, active?: boolean | undefined, advertiserFilter?: ObjectFilter | undefined, campaignFilter?: ObjectFilter | undefined, comments?: string | undefined, email?: string | undefined, id?: unknown | undefined, kind?: string | undefined, locale?: string | undefined, name?: string | undefined, siteFilter?: ObjectFilter | undefined, subaccountId?: unknown | undefined, traffickerType?: ('INTERNAL_NON_TRAFFICKER' | 'INTERNAL_TRAFFICKER' | 'EXTERNAL_TRAFFICKER') | undefined, userAccessType?: ('NORMAL_USER' | 'SUPER_USER' | 'INTERNAL_ADMINISTRATOR' | 'READ_ONLY_SUPER_USER') | undefined, userRoleFilter?: ObjectFilter | undefined, userRoleId?: unknown | undefined}; export type UpdateApiUserprofilesUserprofilesIdAccountUserProfilesArgs = {userprofilesId: string, body: AccountUserProfile}; export type UpdateApiUserprofilesUserprofilesIdAccountUserProfilesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const objectFilter = z.object({kind: z.string().optional(), objectIds: z.array(z.string()).optional(), status: z.enum(["NONE", "ASSIGNED", "ALL"]).optional()}); export const accountUserProfile = z.object({accountId: z.string().optional(), active: z.boolean().optional(), advertiserFilter: objectFilter.optional(), campaignFilter: objectFilter.optional(), comments: z.string().optional(), email: z.string().optional(), id: z.string().optional(), kind: z.string().optional(), locale: z.string().optional(), name: z.string().optional(), siteFilter: objectFilter.optional(), subaccountId: z.string().optional(), traffickerType: z.enum(["INTERNAL_NON_TRAFFICKER", "INTERNAL_TRAFFICKER", "EXTERNAL_TRAFFICKER"]).optional(), userAccessType: z.enum(["NORMAL_USER", "SUPER_USER", "INTERNAL_ADMINISTRATOR", "READ_ONLY_SUPER_USER"]).optional(), userRoleFilter: objectFilter.optional(), userRoleId: 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 }; /** * Updates an existing account user profile. * * PUT /userprofiles/{userprofilesId}/accountUserProfiles */ export const updateApiUserprofilesUserprofilesIdAccountUserProfiles = async (args: UpdateApiUserprofilesUserprofilesIdAccountUserProfilesArgs, options?: UpdateApiUserprofilesUserprofilesIdAccountUserProfilesOptions) => { const {baseUrl = "https://dfareporting.googleapis.com/dfareporting/v5", fetch: fetchFn = fetch, Oauth2, Oauth2c} = 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}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/userprofiles/${encodeURIComponent(String(args.userprofilesId))}/accountUserProfiles${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(accountUserProfile, await res.json()) };