import {z} from 'zod' export type DimensionValue = {dimensionName?: string | undefined, etag?: string | undefined, id?: string | undefined, kind?: string | undefined, matchType?: ('EXACT' | 'BEGINS_WITH' | 'CONTAINS' | 'WILDCARD_EXPRESSION') | undefined, value?: string | undefined}; export type ListPopulationTerm = {contains?: boolean | undefined, negation?: boolean | undefined, operator?: ('NUM_EQUALS' | 'NUM_LESS_THAN' | 'NUM_LESS_THAN_EQUAL' | 'NUM_GREATER_THAN' | 'NUM_GREATER_THAN_EQUAL' | 'STRING_EQUALS' | 'STRING_CONTAINS') | undefined, remarketingListId?: unknown | undefined, type?: ('CUSTOM_VARIABLE_TERM' | 'LIST_MEMBERSHIP_TERM' | 'REFERRER_TERM') | undefined, value?: string | undefined, variableFriendlyName?: string | undefined, variableName?: string | undefined}; export type ListPopulationClause = {terms?: Array | undefined}; export type ListPopulationRule = {floodlightActivityId?: unknown | undefined, floodlightActivityName?: string | undefined, listPopulationClauses?: Array | undefined}; export type RemarketingList = {accountId?: unknown | undefined, active?: boolean | undefined, advertiserId?: unknown | undefined, advertiserIdDimensionValue?: DimensionValue | undefined, description?: string | undefined, id?: unknown | undefined, kind?: string | undefined, lifeSpan?: unknown | undefined, listPopulationRule?: ListPopulationRule | undefined, listSize?: unknown | undefined, listSource?: ('REMARKETING_LIST_SOURCE_OTHER' | 'REMARKETING_LIST_SOURCE_ADX' | 'REMARKETING_LIST_SOURCE_DFP' | 'REMARKETING_LIST_SOURCE_XFP' | 'REMARKETING_LIST_SOURCE_DFA' | 'REMARKETING_LIST_SOURCE_GA' | 'REMARKETING_LIST_SOURCE_YOUTUBE' | 'REMARKETING_LIST_SOURCE_DBM' | 'REMARKETING_LIST_SOURCE_GPLUS' | 'REMARKETING_LIST_SOURCE_DMP' | 'REMARKETING_LIST_SOURCE_PLAY_STORE') | undefined, name?: string | undefined, subaccountId?: unknown | undefined}; export type CreateApiUserprofilesUserprofilesIdRemarketingListsArgs = {userprofilesId: string, body: RemarketingList}; export type CreateApiUserprofilesUserprofilesIdRemarketingListsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const dimensionValue = z.object({dimensionName: z.string().optional(), etag: z.string().optional(), id: z.string().optional(), kind: z.string().optional(), matchType: z.enum(["EXACT", "BEGINS_WITH", "CONTAINS", "WILDCARD_EXPRESSION"]).optional(), value: z.string().optional()}); export const listPopulationTerm = z.object({contains: z.boolean().optional(), negation: z.boolean().optional(), operator: z.enum(["NUM_EQUALS", "NUM_LESS_THAN", "NUM_LESS_THAN_EQUAL", "NUM_GREATER_THAN", "NUM_GREATER_THAN_EQUAL", "STRING_EQUALS", "STRING_CONTAINS"]).optional(), remarketingListId: z.string().optional(), type: z.enum(["CUSTOM_VARIABLE_TERM", "LIST_MEMBERSHIP_TERM", "REFERRER_TERM"]).optional(), value: z.string().optional(), variableFriendlyName: z.string().optional(), variableName: z.string().optional()}); export const listPopulationClause = z.object({terms: z.array(listPopulationTerm).optional()}); export const listPopulationRule = z.object({floodlightActivityId: z.string().optional(), floodlightActivityName: z.string().optional(), listPopulationClauses: z.array(listPopulationClause).optional()}); export const remarketingList = z.object({accountId: z.string().optional(), active: z.boolean().optional(), advertiserId: z.string().optional(), advertiserIdDimensionValue: dimensionValue.optional(), description: z.string().optional(), id: z.string().optional(), kind: z.string().optional(), lifeSpan: z.string().optional(), listPopulationRule: listPopulationRule.optional(), listSize: z.string().optional(), listSource: z.enum(["REMARKETING_LIST_SOURCE_OTHER", "REMARKETING_LIST_SOURCE_ADX", "REMARKETING_LIST_SOURCE_DFP", "REMARKETING_LIST_SOURCE_XFP", "REMARKETING_LIST_SOURCE_DFA", "REMARKETING_LIST_SOURCE_GA", "REMARKETING_LIST_SOURCE_YOUTUBE", "REMARKETING_LIST_SOURCE_DBM", "REMARKETING_LIST_SOURCE_GPLUS", "REMARKETING_LIST_SOURCE_DMP", "REMARKETING_LIST_SOURCE_PLAY_STORE"]).optional(), name: z.string().optional(), subaccountId: 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 }; /** * Inserts a new remarketing list. * * POST /userprofiles/{userprofilesId}/remarketingLists */ export const createApiUserprofilesUserprofilesIdRemarketingLists = async (args: CreateApiUserprofilesUserprofilesIdRemarketingListsArgs, options?: CreateApiUserprofilesUserprofilesIdRemarketingListsOptions) => { const {baseUrl = "https://dfareporting.googleapis.com/dfareporting/v5", 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 (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/userprofiles/${encodeURIComponent(String(args.userprofilesId))}/remarketingLists${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(remarketingList, await res.json()) };