import {z} from 'zod' export type ExchangeSeat = {supply_source_id: number, seat_identifier: string, bill_media_to_client?: (boolean | null) | undefined, rmx_exchange_cost_unit?: (string | null) | undefined, rmx_exchange_cost_cpm?: (number | null) | undefined, rmx_exchange_cost_pct?: (number | null) | undefined, status?: (boolean | null) | undefined}; export type OrganizationUpdate = {name?: string | undefined, org_type?: (Array<'buyer' | 'partner'>) | undefined, status?: boolean | undefined, website?: (string | null) | undefined, facebook?: (string | null) | undefined, linkedin?: (string | null) | undefined, twitter?: (string | null) | undefined, allow_x_agency_pixels?: boolean | undefined, allow_byo_price?: boolean | undefined, opt_out_connected_id?: boolean | undefined, opt_out_connected_id_mathid?: boolean | undefined, override_suspicious_traffic_filter?: boolean | undefined, restrict_targeting_to_same_device_id?: boolean | undefined, restrict_targeting_to_deterministic_id?: boolean | undefined, suspicious_traffic_filter_level?: number | undefined, use_ads_txt?: boolean | undefined, use_evidon_optout?: (boolean | null) | undefined, eligible_for_data_sharing?: boolean | undefined, holding_org_id?: (number | null) | undefined, service_provider_ccpa?: boolean | undefined, mfa_avoidance?: ('ALLOW_ALL' | 'EXCLUDE_MFA') | undefined, mm_contact_name?: string | undefined, adx_seat_account_id?: number | undefined, connected_id_type?: 'DETERMINISTIC_FIRST' | undefined, contact_name?: string | undefined, address_1?: string | undefined, address_2?: (string | null) | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined, phone?: string | undefined, currency_code?: string | undefined, billing_country_code?: string | undefined, dmp_enabled?: ('enabled' | 'disabled') | undefined, seats?: (Array | null) | undefined, mcp_enabled?: boolean | undefined, mcp_access_level?: ('read_only' | 'read_write') | undefined, inf_business_unit?: (string | null) | undefined, environment?: (string | null) | undefined, terminated?: boolean | undefined, version?: number | undefined}; export type CreateApiOrganizationsOrganizationIdArgs = {organization_id: number, body: OrganizationUpdate}; export type CreateApiOrganizationsOrganizationIdOptions = {baseUrl?: string | undefined, Auth0?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationResponse = z.object({data: z.object({name: z.string().min(1).max(64), org_type: z.array(z.enum(["buyer", "partner"])).optional(), status: z.boolean(), website: z.string().max(512).nullable().optional(), facebook: z.string().max(512).nullable().optional(), linkedin: z.string().max(512).nullable().optional(), twitter: z.string().max(512).nullable().optional(), allow_x_agency_pixels: z.boolean().optional(), allow_byo_price: z.boolean().optional(), opt_out_connected_id: z.boolean().optional(), opt_out_connected_id_mathid: z.boolean().optional(), override_suspicious_traffic_filter: z.boolean().optional(), restrict_targeting_to_same_device_id: z.boolean().optional(), restrict_targeting_to_deterministic_id: z.boolean().optional(), suspicious_traffic_filter_level: z.number().int().gte(0).lte(100).optional(), use_ads_txt: z.boolean().optional(), use_evidon_optout: z.boolean().nullable().optional(), eligible_for_data_sharing: z.boolean().optional(), holding_org_id: z.number().int().nullable().optional(), service_provider_ccpa: z.boolean().optional(), mfa_avoidance: z.enum(["ALLOW_ALL", "EXCLUDE_MFA"]).optional(), mm_contact_name: z.string().max(64), adx_seat_account_id: z.number().int().gte(1), connected_id_type: z.literal("DETERMINISTIC_FIRST"), contact_name: z.string().max(64), address_1: z.string().max(256), address_2: z.string().max(256).nullable().optional(), city: z.string().max(32), state: z.string().max(2), zip: z.string().max(10), country: z.string().max(2), phone: z.string().max(24), currency_code: z.string().max(3), billing_country_code: z.string(), dmp_enabled: z.enum(["enabled", "disabled"]), seats: z.array(z.object({supply_source_id: z.number().int(), seat_identifier: z.string(), bill_media_to_client: z.boolean().nullable().optional(), rmx_exchange_cost_unit: z.string().nullable().optional(), rmx_exchange_cost_cpm: z.number().gte(0).lte(9999999.99).nullable().optional(), rmx_exchange_cost_pct: z.number().gte(0).lte(100).nullable().optional(), status: z.boolean().nullable().optional(), data: z.object({supply_source_id: z.number().int(), seat_identifier: z.string(), bill_media_to_client: z.boolean().nullable().optional(), rmx_exchange_cost_unit: z.string().nullable().optional(), rmx_exchange_cost_cpm: z.number().gte(0).lte(9999999.99).nullable().optional(), rmx_exchange_cost_pct: z.number().gte(0).lte(100).nullable().optional(), status: z.boolean().nullable().optional(), id: z.number().int().optional(), version: z.number().int().optional(), created_on: z.string().optional(), updated_on: z.string().optional()}).optional()})).nullable().optional(), mcp_enabled: z.boolean().optional(), mcp_access_level: z.enum(["read_only", "read_write"]).optional(), inf_business_unit: z.string().nullable().optional(), environment: z.string().nullable().optional(), id: z.number().int().optional(), created_on: z.string().optional(), entity_type: z.string().optional(), terminated: z.boolean().optional(), updated_on: z.string().optional(), version: z.number().int().optional()}).optional(), meta: z.object({status: z.string().optional()}).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 Organization * * POST /organizations/{organization_id} */ export const createApiOrganizationsOrganizationId = async (args: CreateApiOrganizationsOrganizationIdArgs, options?: CreateApiOrganizationsOrganizationIdOptions) => { 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(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_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(organizationResponse, await res.json()) };