import {z} from 'zod' export type Campaignv3SearchTermMatchType = 'MATCH_TYPE_UNSPECIFIED' | 'MATCH_TYPE_PHRASE_MATCH' | 'MATCH_TYPE_EXACT_MATCH'; export type Campaignv3CatalogProductSeller = {catalogId?: string | undefined, productCode?: string | undefined, sellerId?: string | undefined}; export type Campaignv3SearchTerm = {phrase?: string | undefined, matchType?: Campaignv3SearchTermMatchType | undefined, collectionName?: string | undefined, suggested?: boolean | undefined, excludedProducts?: Array | undefined, maxBid?: string | undefined, treatAsCustom?: boolean | undefined}; export type Campaignv3TargetedFilter = {catalogId?: string | undefined, filter?: string | undefined}; export type Campaignv3CheckProductCampaignFixedTenancyAvailableRequest = {campaignId?: string | undefined, placementId: string, catalogIds: Array, startTime: string, endTime: string, searchTerms?: Array | undefined, filters?: Array | undefined, positions: Array}; export type CreateApiV3ProductCampaignsCheckFixedTenancyAvailableArgs = {body: Campaignv3CheckProductCampaignFixedTenancyAvailableRequest}; export type CreateApiV3ProductCampaignsCheckFixedTenancyAvailableOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const campaignv3SearchTermMatchType = z.enum(["MATCH_TYPE_UNSPECIFIED", "MATCH_TYPE_PHRASE_MATCH", "MATCH_TYPE_EXACT_MATCH"]); export const campaignv3CatalogProductSeller = z.object({catalogId: z.string().optional(), productCode: z.string().optional(), sellerId: z.string().optional()}); export const campaignv3SearchTerm = z.object({phrase: z.string().optional(), matchType: campaignv3SearchTermMatchType.optional(), collectionName: z.string().optional(), suggested: z.boolean().optional(), excludedProducts: z.array(campaignv3CatalogProductSeller).optional(), maxBid: z.string().optional(), treatAsCustom: z.boolean().optional()}); export const campaignv3TargetedFilter = z.object({catalogId: z.string().optional(), filter: z.string().optional()}); export const campaignv3CheckProductCampaignFixedTenancyAvailableResponseFixedTenancyConflict = z.object({searchTerm: campaignv3SearchTerm.optional(), filter: campaignv3TargetedFilter.optional(), startTime: z.string().optional(), endTime: z.string().optional(), campaignIds: z.array(z.string()).optional(), catalogId: z.string().optional(), placementId: z.string().optional()}); export const campaignv3CheckProductCampaignFixedTenancyAvailableResponse = z.object({available: z.boolean().optional(), conflicts: z.array(campaignv3CheckProductCampaignFixedTenancyAvailableResponseFixedTenancyConflict).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 }; /** * Check fixed tenancy campaign availability * * POST /v3/product-campaigns:checkFixedTenancyAvailable */ export const createApiV3ProductCampaignsCheckFixedTenancyAvailable = async (args: CreateApiV3ProductCampaignsCheckFixedTenancyAvailableArgs, options?: CreateApiV3ProductCampaignsCheckFixedTenancyAvailableOptions) => { const {baseUrl = "https://auth..citrusad.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v3/product-campaigns:checkFixedTenancyAvailable${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(campaignv3CheckProductCampaignFixedTenancyAvailableResponse, await res.json()) };