import {z} from 'zod' export type TargetingSpec = {userOs?: Array | undefined, userDevice?: Array | undefined, countries?: Array | undefined, regions?: (Array) | undefined, cities?: (Array) | undefined, zips?: (Array<{key: string, name?: string | undefined}>) | undefined, metros?: (Array<{key: string, name?: string | undefined}>) | undefined, countryGroups?: (Array<'africa' | 'asia' | 'europe' | 'north_america' | 'south_america' | 'oceania' | 'central_america' | 'caribbean' | 'eea' | 'euro_area' | 'nafta' | 'mercosur' | 'afta' | 'apec' | 'gcc' | 'cisfta' | 'emerging_markets' | 'itunes_app_store' | 'android_free_store' | 'android_paid_store'>) | undefined, customLocations?: (Array<{latitude: number, longitude: number, radius: number, distanceUnit: 'mile' | 'kilometer', name?: string | undefined, address?: string | undefined}>) | undefined, excludedLocations?: ({countries?: Array | undefined, countryGroups?: (Array<'africa' | 'asia' | 'europe' | 'north_america' | 'south_america' | 'oceania' | 'central_america' | 'caribbean' | 'eea' | 'euro_area' | 'nafta' | 'mercosur' | 'afta' | 'apec' | 'gcc' | 'cisfta' | 'emerging_markets' | 'itunes_app_store' | 'android_free_store' | 'android_paid_store'>) | undefined, regions?: (Array<{key: string, name?: string | undefined}>) | undefined, cities?: (Array<{key: string, radius?: number | undefined, distanceUnit?: ('mile' | 'kilometer') | undefined}>) | undefined, zips?: (Array<{key: string, name?: string | undefined}>) | undefined, places?: Array<{key: string}> | undefined, neighborhoods?: Array<{key: string}> | undefined, customLocations?: (Array<{latitude: number, longitude: number, radius: number, distanceUnit: 'mile' | 'kilometer', name?: string | undefined, address?: string | undefined}>) | undefined}) | undefined, ageMin?: number | undefined, ageMax?: number | undefined, gender?: ('all' | 'male' | 'female') | undefined, incomeTier?: ('top_5' | 'top_10' | 'top_10_25' | 'top_25_50') | undefined, languages?: Array | undefined, interests?: (Array<{id: string, name?: string | undefined}>) | undefined, behaviors?: (Array<{id: string, name?: string | undefined}>) | undefined, workPositions?: (Array<{id: string, name?: string | undefined}>) | undefined, workEmployers?: (Array<{id: string, name?: string | undefined}>) | undefined, workIndustries?: (Array<{id: string, name?: string | undefined}>) | undefined, industries?: Array | undefined, companySizes?: Array | undefined, seniorities?: Array | undefined, jobFunctions?: Array | undefined, skills?: Array | undefined, audienceInclude?: Array | undefined, audienceExclude?: Array | undefined, communities?: Array | undefined, excludedCommunities?: Array | undefined, conversationKeywords?: Array | undefined, excludedConversationKeywords?: Array | undefined}; export type UpdateApiV1AdsAudiencesAudienceIdArgs = {audienceId: string, body: {name?: string | undefined, description?: string | undefined, spec?: TargetingSpec | undefined}}; export type UpdateApiV1AdsAudiencesAudienceIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1AdsAudiencesAudienceIdResponse = z.object({audience: z.object({}).optional(), message: 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 }; /** * Update an audience * * PUT /v1/ads/audiences/{audienceId} */ export const updateApiV1AdsAudiencesAudienceId = async (args: UpdateApiV1AdsAudiencesAudienceIdArgs, options?: UpdateApiV1AdsAudiencesAudienceIdOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ads/audiences/${encodeURIComponent(String(args.audienceId))}${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(updateApiV1AdsAudiencesAudienceIdResponse, await res.json()) };