import {z} from 'zod' export type Date = {day?: number | undefined, month?: number | undefined, year?: number | undefined}; export type UrlRestriction = {endDate?: Date | undefined, restrictionType?: ('RESTRICTION_TYPE_UNSPECIFIED' | 'CONTAINS' | 'EQUALS' | 'STARTS_WITH' | 'ENDS_WITH' | 'DOES_NOT_EQUAL' | 'DOES_NOT_CONTAIN' | 'DOES_NOT_START_WITH' | 'DOES_NOT_END_WITH') | undefined, startDate?: Date | undefined, url?: string | undefined}; export type UserList = {description?: string | undefined, displayName?: string | undefined, membershipDurationDays?: unknown | undefined, name?: string | undefined, status?: ('STATUS_UNSPECIFIED' | 'OPEN' | 'CLOSED') | undefined, urlRestriction?: UrlRestriction | undefined}; export type UpdateApiV1BuyersBuyersIdUserListsUserListsIdArgs = {buyersId: string, userListsId: string, body: UserList}; export type UpdateApiV1BuyersBuyersIdUserListsUserListsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const date = z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}); export const urlRestriction = z.object({endDate: date.optional(), restrictionType: z.enum(["RESTRICTION_TYPE_UNSPECIFIED", "CONTAINS", "EQUALS", "STARTS_WITH", "ENDS_WITH", "DOES_NOT_EQUAL", "DOES_NOT_CONTAIN", "DOES_NOT_START_WITH", "DOES_NOT_END_WITH"]).optional(), startDate: date.optional(), url: z.string().optional()}); export const userList = z.object({description: z.string().optional(), displayName: z.string().optional(), membershipDurationDays: z.string().optional(), name: z.string().optional(), status: z.enum(["STATUS_UNSPECIFIED", "OPEN", "CLOSED"]).optional(), urlRestriction: urlRestriction.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 the given user list. Only user lists with URLRestrictions can be updated. * * PUT /v1/buyers/{buyersId}/userLists/{userListsId} */ export const updateApiV1BuyersBuyersIdUserListsUserListsId = async (args: UpdateApiV1BuyersBuyersIdUserListsUserListsIdArgs, options?: UpdateApiV1BuyersBuyersIdUserListsUserListsIdOptions) => { const {baseUrl = "https://realtimebidding.googleapis.com", 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(/\/+$/, '')}/v1/buyers/${encodeURIComponent(String(args.buyersId))}/userLists/${encodeURIComponent(String(args.userListsId))}${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(userList, await res.json()) };