import {z} from 'zod' export type Endpoint = {bidProtocol?: ('BID_PROTOCOL_UNSPECIFIED' | 'GOOGLE_RTB' | 'OPENRTB_JSON' | 'OPENRTB_PROTOBUF') | undefined, maximumQps?: unknown | undefined, name?: string | undefined, tradingLocation?: ('TRADING_LOCATION_UNSPECIFIED' | 'US_WEST' | 'US_EAST' | 'EUROPE' | 'ASIA') | undefined, url?: string | undefined}; export type PatchApiV1BiddersBiddersIdEndpointsEndpointsIdArgs = {biddersId: string, endpointsId: string, updateMask?: unknown | undefined, body: Endpoint}; export type PatchApiV1BiddersBiddersIdEndpointsEndpointsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const endpoint = z.object({bidProtocol: z.enum(["BID_PROTOCOL_UNSPECIFIED", "GOOGLE_RTB", "OPENRTB_JSON", "OPENRTB_PROTOBUF"]).optional(), maximumQps: z.string().optional(), name: z.string().optional(), tradingLocation: z.enum(["TRADING_LOCATION_UNSPECIFIED", "US_WEST", "US_EAST", "EUROPE", "ASIA"]).optional(), url: 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 a bidder's endpoint. * * PATCH /v1/bidders/{biddersId}/endpoints/{endpointsId} */ export const patchApiV1BiddersBiddersIdEndpointsEndpointsId = async (args: PatchApiV1BiddersBiddersIdEndpointsEndpointsIdArgs, options?: PatchApiV1BiddersBiddersIdEndpointsEndpointsIdOptions) => { 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 (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bidders/${encodeURIComponent(String(args.biddersId))}/endpoints/${encodeURIComponent(String(args.endpointsId))}${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(endpoint, await res.json()) };