import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdPlacementGroupsPlacementGroupsIdArgs = {userprofilesId: string, placementGroupsId: string}; export type GetApiUserprofilesUserprofilesIdPlacementGroupsPlacementGroupsIdOptions = {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 }; /** * Gets one placement group by ID. * * GET /userprofiles/{userprofilesId}/placementGroups/{placementGroupsId} */ export const getApiUserprofilesUserprofilesIdPlacementGroupsPlacementGroupsId = async (args: GetApiUserprofilesUserprofilesIdPlacementGroupsPlacementGroupsIdArgs, options?: GetApiUserprofilesUserprofilesIdPlacementGroupsPlacementGroupsIdOptions) => { const {baseUrl = "https://dfareporting.googleapis.com/dfareporting/v5", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/${encodeURIComponent(String(args.placementGroupsId))}${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(placementGroup, await res.json()) };