import {z} from 'zod' export type GetApiSupplySourcesSupplySourceIdArgs = {supply_source_id: number}; export type GetApiSupplySourcesSupplySourceIdOptions = {baseUrl?: string | undefined, Auth0?: string | undefined, fetch?: typeof fetch | undefined}; export const supplySourceResponse = z.object({id: z.number().int().optional(), version: z.number().int().optional(), name: z.string().optional(), supply_type: z.string().optional(), status: z.boolean().optional(), created_on: z.string().optional(), updated_on: z.string().optional(), rtb_enabled: z.boolean().optional(), mm_safe: z.boolean().optional(), pixel_tag: z.string().optional(), distribute: z.boolean().optional(), use_pool: z.boolean().optional(), code: z.string().optional(), is_proservice: z.boolean().optional(), default_seat_identifier: z.string().optional(), seat_enabled: z.boolean().optional(), bidder_exchange_identifier: z.number().int().optional(), pmp_enabled: z.boolean().optional(), rtb_type: z.string().optional(), parent_supply_id: z.number().int().optional(), has_display: z.boolean().optional(), has_mobile_display: z.boolean().optional(), has_video: z.boolean().optional(), has_mobile_video: z.boolean().optional(), requires_creative_audit: z.boolean().optional(), has_desktop_video: z.boolean().optional(), has_connected_tv: z.boolean().optional(), attribution_group: z.string().optional(), fraud_filter: z.boolean().optional(), mma_free: z.boolean().optional(), private: z.boolean().optional(), mkt_sell_price: z.number().nullable().optional(), mkt_sell_price_currency_code: z.string().nullable().optional()}); export const singleMetadata = z.object({status: z.string()}); export const getApiSupplySourcesSupplySourceIdResponse = z.object({data: supplySourceResponse.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 }; /** * Get a Supply Source * * GET /supply_sources/{supply_source_id} */ export const getApiSupplySourcesSupplySourceId = async (args: GetApiSupplySourcesSupplySourceIdArgs, options?: GetApiSupplySourcesSupplySourceIdOptions) => { const {baseUrl = "https://api.mediamath.com/api/v3.0", fetch: fetchFn = fetch, Auth0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Auth0 !== undefined) headers.set('authorization', `Bearer ${Auth0}`) const url = `${baseUrl.replace(/\/+$/, '')}/supply_sources/${encodeURIComponent(String(args.supply_source_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSupplySourcesSupplySourceIdResponse, await res.json()) };