import {z} from 'zod' export type Campaignv3CampaignState = 'CAMPAIGN_STATE_UNSPECIFIED' | 'CAMPAIGN_STATE_ACTIVE' | 'CAMPAIGN_STATE_PAUSED' | 'CAMPAIGN_STATE_DRAFT' | 'CAMPAIGN_STATE_ARCHIVED'; export type Campaignv3CatalogProductSeller = {catalogId?: string | undefined, productCode?: string | undefined, sellerId?: string | undefined}; export type Campaignv3AdvertisedProducts = {productsByKey?: Array | undefined, productGroupList?: Array | undefined}; export type Campaignv3SearchTermMatchType = 'MATCH_TYPE_UNSPECIFIED' | 'MATCH_TYPE_PHRASE_MATCH' | 'MATCH_TYPE_EXACT_MATCH'; 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 Campaignv3CrossSell = {targetProductsByKey?: Array | undefined}; export type Campaignv3Upsell = {targetProductsByKey?: Array | undefined}; export type Campaignv3TargetedFilter = {catalogId?: string | undefined, filter?: string | undefined}; export type V3NegativeSearchTermMatchType = 'MATCH_TYPE_UNSPECIFIED' | 'MATCH_TYPE_EXACT_MATCH' | 'MATCH_TYPE_PHRASE_MATCH'; export type V3NegativeSearchTerm = {phrase?: string | undefined, matchType?: V3NegativeSearchTermMatchType | undefined}; export type V3SegmentsSet = {segmentIds?: Array | undefined}; export type V3Audience = {includeSegmentsSets?: Array | undefined}; export type Campaignv3Targeting = {searchTerms?: Array | undefined, crossSell?: Campaignv3CrossSell | undefined, upsell?: Campaignv3Upsell | undefined, excludeFilters?: Array | undefined, includeFilters?: Array | undefined, negativeSearchTerms?: Array | undefined, audience?: V3Audience | undefined}; export type Campaignv3SpendLimit = {daily?: string | undefined, total?: string | undefined}; export type Campaignv3Auction = {maxBid?: string | undefined, spendLimit?: Campaignv3SpendLimit | undefined}; export type Campaignv3CatalogCost = {catalogId?: string | undefined, catalogCostPercentage?: number | undefined}; export type Campaignv3FixedTenancy = {cost?: string | undefined, positions?: Array | undefined, catalogCosts?: Array | undefined}; export type Campaignv3Strategy = {auction?: Campaignv3Auction | undefined, fixedTenancy?: Campaignv3FixedTenancy | undefined}; export type Campaignv3FixedCosts = {dataCost?: string | undefined, creativeCost?: string | undefined, otherCost?: string | undefined}; export type Campaignv3CustomField = {customFieldId?: string | undefined, content?: string | undefined}; export type Campaignv3CustomQuestion = {customQuestionId?: string | undefined, answers?: Array | undefined}; export type BannerXConfigBannerXSlotType = 'BANNER_X_SLOT_TYPE_UNSPECIFIED' | 'BANNER_X_SLOT_TYPE_BANNER' | 'BANNER_X_SLOT_TYPE_SINGLE_TILE' | 'BANNER_X_SLOT_TYPE_DOUBLE_TILE'; export type V3BannerXConfigBannerXBackgroundImagePosition = 'BANNER_X_BACKGROUND_IMAGE_POSITION_UNSPECIFIED' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_REPEATING' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_LEFTALIGNED' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_RIGHTALIGNED' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_TOPALIGNED' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_BOTTOMALIGNED' | 'BANNER_X_BACKGROUND_IMAGE_POSITION_FILL'; export type V3BannerXConfigBannerXHeroImageMode = 'BANNER_X_HERO_IMAGE_MODE_UNSPECIFIED' | 'BANNER_X_HERO_IMAGE_MODE_BLOCK' | 'BANNER_X_HERO_IMAGE_MODE_LANDSCAPE' | 'BANNER_X_HERO_IMAGE_MODE_PORTRAIT'; export type V3AdditionalFields = {id?: string | undefined, value?: string | undefined}; export type TrackingTagTrackingTagProvider = 'TRACKING_TAG_PROVIDER_UNSPECIFIED' | 'TRACKING_TAG_PROVIDER_DV' | 'TRACKING_TAG_PROVIDER_DCM_CLICK' | 'TRACKING_TAG_PROVIDER_DCM_IMPRESSION' | 'TRACKING_TAG_PROVIDER_MOAT' | 'TRACKING_TAG_PROVIDER_IAS' | 'TRACKING_TAG_PROVIDER_GTM360' | 'TRACKING_TAG_PROVIDER_SIZMEK' | 'TRACKING_TAG_PROVIDER_ADFORM_CLICK' | 'TRACKING_TAG_PROVIDER_ADFORM_IMPRESSION' | 'TRACKING_TAG_PROVIDER_DV_IMAGE'; export type V3TrackingTag = {provider?: TrackingTagTrackingTagProvider | undefined, content?: string | undefined}; export type BannerXConfigVideoConfig = {fileId?: string | undefined}; export type V3BannerXConfig = {contentStandardId?: string | undefined, slotId?: string | undefined, slotType?: BannerXConfigBannerXSlotType | undefined, headingText?: string | undefined, bannerText?: string | undefined, bannerTextColourHex?: string | undefined, ctaFlag?: boolean | undefined, ctaText?: string | undefined, ctaTextAccessibility?: string | undefined, ctaLink?: string | undefined, backgroundColourHex?: string | undefined, backgroundImageId?: string | undefined, backgroundImagePosition?: V3BannerXConfigBannerXBackgroundImagePosition | undefined, secondaryBackgroundImageId?: string | undefined, secondaryBackgroundImagePosition?: V3BannerXConfigBannerXBackgroundImagePosition | undefined, heroImageId?: string | undefined, heroImageAltText?: string | undefined, heroMode?: V3BannerXConfigBannerXHeroImageMode | undefined, secondaryHeroImageId?: string | undefined, secondaryHeroImageAltText?: string | undefined, secondaryHeroMode?: V3BannerXConfigBannerXHeroImageMode | undefined, additionalFields?: Array | undefined, trackingTagProvider?: Array | undefined, primaryVideoConfig?: BannerXConfigVideoConfig | undefined, companionProducts?: Array | undefined}; export type V3SlotsConfiguration = {slotId?: string | undefined, artworkImageId?: string | undefined, link?: string | undefined, altText?: string | undefined, text?: string | undefined, trackingTagProvider?: Array | undefined}; export type V3BannerConfig = {contentStandardId?: string | undefined, slotsConfiguration?: Array | undefined}; export type V3Campaign = {id: string, updateTime?: string | undefined, name?: string | undefined, namespaceId?: string | undefined, campaignState?: Campaignv3CampaignState | undefined, templateId?: string | undefined, managerTeamId?: string | undefined, teamId?: string | undefined, startTime?: string | undefined, endTime?: string | undefined, walletId?: string | undefined, placementId?: string | undefined, catalogIds?: Array | undefined, advertisedProducts?: Campaignv3AdvertisedProducts | undefined, targeting?: Campaignv3Targeting | undefined, strategy?: Campaignv3Strategy | undefined, fixedCosts?: Campaignv3FixedCosts | undefined, customFields?: Array | undefined, customQuestions?: Array | undefined, sellerId?: string | undefined, bannerXConfig?: V3BannerXConfig | undefined, bannerConfig?: V3BannerConfig | undefined}; export type V3BulkUpdateCampaignRequestBodyCampaignType = 'CAMPAIGN_TYPE_UNSPECIFIED' | 'CAMPAIGN_TYPE_DISPLAY' | 'CAMPAIGN_TYPE_BANNER' | 'CAMPAIGN_TYPE_BANNERX'; export type V3BulkUpdateCampaignRequestBody = {campaign: V3Campaign, mask: string, campaignType: V3BulkUpdateCampaignRequestBodyCampaignType}; export type V3BulkUpdateCampaignRequest = {campaigns?: Array | undefined}; export type PatchApiV3CampaignsBulkUpdateArgs = {body: V3BulkUpdateCampaignRequest}; export type PatchApiV3CampaignsBulkUpdateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1BulkOperationStatus = z.enum(["BULK_OPERATION_SUBMITTED", "BULK_OPERATION_IN_PROGRESS", "BULK_OPERATION_COMPLETED", "BULK_OPERATION_FAILED"]); export const v3BulkUpdateCampaignResponse = z.object({bulkId: z.string().optional(), status: v1BulkOperationStatus.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 campaigns in bulk * * PATCH /v3/campaigns/bulk/update */ export const patchApiV3CampaignsBulkUpdate = async (args: PatchApiV3CampaignsBulkUpdateArgs, options?: PatchApiV3CampaignsBulkUpdateOptions) => { 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/campaigns/bulk/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(v3BulkUpdateCampaignResponse, await res.json()) };