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 LastModifiedInfo = {time?: unknown | undefined}; export type PricingSchedulePricingPeriod = {endDate?: string | undefined, pricingComment?: string | undefined, rateOrCostNanos?: unknown | undefined, startDate?: string | undefined, units?: unknown | undefined}; export type PricingSchedule = {capCostOption?: ('CAP_COST_NONE' | 'CAP_COST_MONTHLY' | 'CAP_COST_CUMULATIVE') | undefined, endDate?: string | undefined, flighted?: boolean | undefined, floodlightActivityId?: unknown | undefined, pricingPeriods?: Array | undefined, pricingType?: ('PRICING_TYPE_CPM' | 'PRICING_TYPE_CPC' | 'PRICING_TYPE_CPA' | 'PRICING_TYPE_FLAT_RATE_IMPRESSIONS' | 'PRICING_TYPE_FLAT_RATE_CLICKS' | 'PRICING_TYPE_CPM_ACTIVEVIEW') | undefined, startDate?: string | undefined, testingStartDate?: string | undefined}; export type PlacementGroup = {accountId?: unknown | undefined, activeStatus?: ('PLACEMENT_STATUS_UNKNOWN' | 'PLACEMENT_STATUS_ACTIVE' | 'PLACEMENT_STATUS_INACTIVE' | 'PLACEMENT_STATUS_ARCHIVED' | 'PLACEMENT_STATUS_PERMANENTLY_ARCHIVED') | undefined, advertiserId?: unknown | undefined, advertiserIdDimensionValue?: DimensionValue | undefined, campaignId?: unknown | undefined, campaignIdDimensionValue?: DimensionValue | undefined, childPlacementIds?: Array | undefined, comment?: string | undefined, contentCategoryId?: unknown | undefined, createInfo?: LastModifiedInfo | undefined, directorySiteId?: unknown | undefined, directorySiteIdDimensionValue?: DimensionValue | undefined, externalId?: string | undefined, id?: unknown | undefined, idDimensionValue?: DimensionValue | undefined, kind?: string | undefined, lastModifiedInfo?: LastModifiedInfo | undefined, name?: string | undefined, placementGroupType?: ('PLACEMENT_PACKAGE' | 'PLACEMENT_ROADBLOCK') | undefined, placementStrategyId?: unknown | undefined, pricingSchedule?: PricingSchedule | undefined, primaryPlacementId?: unknown | undefined, primaryPlacementIdDimensionValue?: DimensionValue | undefined, siteId?: unknown | undefined, siteIdDimensionValue?: DimensionValue | undefined, subaccountId?: unknown | undefined}; export type CreateApiUserprofilesUserprofilesIdPlacementGroupsArgs = {userprofilesId: string, body: PlacementGroup}; export type CreateApiUserprofilesUserprofilesIdPlacementGroupsOptions = {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 lastModifiedInfo = z.object({time: z.string().optional()}); export const pricingSchedulePricingPeriod = z.object({endDate: z.string().optional(), pricingComment: z.string().optional(), rateOrCostNanos: z.string().optional(), startDate: z.string().optional(), units: z.string().optional()}); export const pricingSchedule = z.object({capCostOption: z.enum(["CAP_COST_NONE", "CAP_COST_MONTHLY", "CAP_COST_CUMULATIVE"]).optional(), endDate: z.string().optional(), flighted: z.boolean().optional(), floodlightActivityId: z.string().optional(), pricingPeriods: z.array(pricingSchedulePricingPeriod).optional(), pricingType: z.enum(["PRICING_TYPE_CPM", "PRICING_TYPE_CPC", "PRICING_TYPE_CPA", "PRICING_TYPE_FLAT_RATE_IMPRESSIONS", "PRICING_TYPE_FLAT_RATE_CLICKS", "PRICING_TYPE_CPM_ACTIVEVIEW"]).optional(), startDate: z.string().optional(), testingStartDate: z.string().optional()}); export const placementGroup = z.object({accountId: z.string().optional(), activeStatus: z.enum(["PLACEMENT_STATUS_UNKNOWN", "PLACEMENT_STATUS_ACTIVE", "PLACEMENT_STATUS_INACTIVE", "PLACEMENT_STATUS_ARCHIVED", "PLACEMENT_STATUS_PERMANENTLY_ARCHIVED"]).optional(), advertiserId: z.string().optional(), advertiserIdDimensionValue: dimensionValue.optional(), campaignId: z.string().optional(), campaignIdDimensionValue: dimensionValue.optional(), childPlacementIds: z.array(z.string()).optional(), comment: z.string().optional(), contentCategoryId: z.string().optional(), createInfo: lastModifiedInfo.optional(), directorySiteId: z.string().optional(), directorySiteIdDimensionValue: dimensionValue.optional(), externalId: z.string().optional(), id: z.string().optional(), idDimensionValue: dimensionValue.optional(), kind: z.string().optional(), lastModifiedInfo: lastModifiedInfo.optional(), name: z.string().optional(), placementGroupType: z.enum(["PLACEMENT_PACKAGE", "PLACEMENT_ROADBLOCK"]).optional(), placementStrategyId: z.string().optional(), pricingSchedule: pricingSchedule.optional(), primaryPlacementId: z.string().optional(), primaryPlacementIdDimensionValue: dimensionValue.optional(), siteId: z.string().optional(), siteIdDimensionValue: dimensionValue.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 placement group. * * POST /userprofiles/{userprofilesId}/placementGroups */ export const createApiUserprofilesUserprofilesIdPlacementGroups = async (args: CreateApiUserprofilesUserprofilesIdPlacementGroupsArgs, options?: CreateApiUserprofilesUserprofilesIdPlacementGroupsOptions) => { 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))}/placementGroups${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(placementGroup, await res.json()) };