import {z} from 'zod' export type AgencyUpdate = {ads_txt_verified?: ('ANY' | 'AUTHORIZED_ONLY' | 'AUTHORIZED_DIRECT_ONLY' | 'NONE') | undefined, allow_x_adv_optimization?: boolean | undefined, allow_x_adv_pixels?: boolean | undefined, dmp_enabled?: ('disabled' | 'inherits') | undefined, eligible_for_data_sharing?: boolean | undefined, name?: string | undefined, status?: boolean | undefined, logo?: string | undefined, mfa_avoidance?: ('INHERIT' | 'ALLOW_ALL' | 'EXCLUDE_MFA') | undefined, version?: number | undefined}; export type CreateApiAgenciesAgencyIdArgs = {agency_id: number, body: AgencyUpdate}; export type CreateApiAgenciesAgencyIdOptions = {baseUrl?: string | undefined, Auth0?: string | undefined, fetch?: typeof fetch | undefined}; export const singleMetadata = z.object({status: z.string()}); export const agencyResponse = z.object({data: z.object({ads_txt_verified: z.enum(["ANY", "AUTHORIZED_ONLY", "AUTHORIZED_DIRECT_ONLY", "NONE"]).optional(), allow_x_adv_optimization: z.boolean().optional(), allow_x_adv_pixels: z.boolean().optional(), dmp_enabled: z.enum(["disabled", "inherits"]).optional(), eligible_for_data_sharing: z.boolean().optional(), name: z.string().min(1).max(64).optional(), status: z.boolean().optional(), logo: z.string().max(1024).optional(), mfa_avoidance: z.enum(["INHERIT", "ALLOW_ALL", "EXCLUDE_MFA"]).optional(), id: z.number().int().optional(), created_on: z.string().optional(), entity_type: z.string().optional(), organization_id: z.number().int().gte(1).optional(), updated_on: z.string().optional(), version: z.number().int().optional(), sales_contact_id: z.number().int().optional(), billing_contact_id: z.number().int().optional(), traffic_contact_id: z.number().int().optional(), inherited_mfa_avoidance: z.enum(["INHERIT", "ALLOW_ALL", "EXCLUDE_MFA"]).optional(), inherited_mfa_from: z.enum(["Organization", "Agency"]).optional()}).optional(), meta: singleMetadata.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 }; /** * Update an Agency * * POST /agencies/{agency_id} */ export const createApiAgenciesAgencyId = async (args: CreateApiAgenciesAgencyIdArgs, options?: CreateApiAgenciesAgencyIdOptions) => { const {baseUrl = "https://api.mediamath.com/api/v3.0", fetch: fetchFn = fetch, Auth0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Auth0 !== undefined) headers.set('authorization', `Bearer ${Auth0}`) const url = `${baseUrl.replace(/\/+$/, '')}/agencies/${encodeURIComponent(String(args.agency_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(agencyResponse, await res.json()) };