import {z} from 'zod' export type Campaignv3ApprovalApprovalState = 'APPROVAL_STATE_PENDING' | 'APPROVAL_STATE_APPROVED' | 'APPROVAL_STATE_REJECTED'; export type Campaignv3Approval = {state?: Campaignv3ApprovalApprovalState | undefined, rejectionReason?: string | undefined}; 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 Campaignv3ProductCampaignServiceUpdateProductCampaignBody = {productCampaign?: ({updateTime?: string | undefined, name?: string | undefined, namespaceId?: string | undefined, approval?: Campaignv3Approval | 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}) | undefined, mask?: string | undefined}; export type PatchApiV3ProductCampaignsProductCampaignIdArgs = {'productCampaign.id': string, body: Campaignv3ProductCampaignServiceUpdateProductCampaignBody}; export type PatchApiV3ProductCampaignsProductCampaignIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const campaignv3ApprovalApprovalState = z.enum(["APPROVAL_STATE_PENDING", "APPROVAL_STATE_APPROVED", "APPROVAL_STATE_REJECTED"]); export const campaignv3Approval = z.object({state: campaignv3ApprovalApprovalState.optional(), rejectionReason: z.string().optional()}); export const campaignv3CampaignState = z.enum(["CAMPAIGN_STATE_UNSPECIFIED", "CAMPAIGN_STATE_ACTIVE", "CAMPAIGN_STATE_PAUSED", "CAMPAIGN_STATE_DRAFT", "CAMPAIGN_STATE_ARCHIVED"]); export const campaignv3CatalogProductSeller = z.object({catalogId: z.string().optional(), productCode: z.string().optional(), sellerId: z.string().optional()}); export const campaignv3AdvertisedProducts = z.object({productsByKey: z.array(campaignv3CatalogProductSeller).optional(), productGroupList: z.array(z.string()).optional()}); export const campaignv3SearchTermMatchType = z.enum(["MATCH_TYPE_UNSPECIFIED", "MATCH_TYPE_PHRASE_MATCH", "MATCH_TYPE_EXACT_MATCH"]); 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 campaignv3CrossSell = z.object({targetProductsByKey: z.array(campaignv3CatalogProductSeller).optional()}); export const campaignv3Upsell = z.object({targetProductsByKey: z.array(campaignv3CatalogProductSeller).optional()}); export const campaignv3TargetedFilter = z.object({catalogId: z.string().optional(), filter: z.string().optional()}); export const v3NegativeSearchTermMatchType = z.enum(["MATCH_TYPE_UNSPECIFIED", "MATCH_TYPE_EXACT_MATCH", "MATCH_TYPE_PHRASE_MATCH"]); export const v3NegativeSearchTerm = z.object({phrase: z.string().optional(), matchType: v3NegativeSearchTermMatchType.optional()}); export const v3SegmentsSet = z.object({segmentIds: z.array(z.string()).optional()}); export const v3Audience = z.object({includeSegmentsSets: z.array(v3SegmentsSet).optional()}); export const campaignv3Targeting = z.object({searchTerms: z.array(campaignv3SearchTerm).optional(), crossSell: campaignv3CrossSell.optional(), upsell: campaignv3Upsell.optional(), excludeFilters: z.array(campaignv3TargetedFilter).optional(), includeFilters: z.array(campaignv3TargetedFilter).optional(), negativeSearchTerms: z.array(v3NegativeSearchTerm).optional(), audience: v3Audience.optional()}); export const campaignv3SpendLimit = z.object({daily: z.string().optional(), total: z.string().optional()}); export const campaignv3Auction = z.object({maxBid: z.string().optional(), spendLimit: campaignv3SpendLimit.optional()}); export const campaignv3CatalogCost = z.object({catalogId: z.string().optional(), catalogCostPercentage: z.number().lte(1).optional()}); export const campaignv3FixedTenancy = z.object({cost: z.string().optional(), positions: z.array(z.number().int().gte(1)).optional(), catalogCosts: z.array(campaignv3CatalogCost).optional()}); export const campaignv3Strategy = z.object({auction: campaignv3Auction.optional(), fixedTenancy: campaignv3FixedTenancy.optional()}); export const campaignv3FixedCosts = z.object({dataCost: z.string().optional(), creativeCost: z.string().optional(), otherCost: z.string().optional()}); export const campaignv3CustomField = z.object({customFieldId: z.string().optional(), content: z.string().optional()}); export const campaignv3CustomQuestion = z.object({customQuestionId: z.string().optional(), answers: z.array(z.string()).optional()}); export const campaignv3ProductCampaign = z.object({id: z.string().optional(), updateTime: z.string().optional(), name: z.string(), namespaceId: z.string(), approval: campaignv3Approval.optional(), campaignState: campaignv3CampaignState, templateId: z.string().optional(), managerTeamId: z.string().optional(), teamId: z.string(), startTime: z.string().optional(), endTime: z.string().optional(), walletId: z.string(), placementId: z.string(), catalogIds: z.array(z.string()), advertisedProducts: campaignv3AdvertisedProducts.optional(), targeting: campaignv3Targeting.optional(), strategy: campaignv3Strategy, fixedCosts: campaignv3FixedCosts.optional(), customFields: z.array(campaignv3CustomField).optional(), customQuestions: z.array(campaignv3CustomQuestion).optional(), sellerId: z.string().optional()}); export const campaignv3UpdateProductCampaignResponse = z.object({productCampaign: campaignv3ProductCampaign}); 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 product campaign * * PATCH /v3/product-campaigns/{productCampaign.id} */ export const patchApiV3ProductCampaignsProductCampaignId = async (args: PatchApiV3ProductCampaignsProductCampaignIdArgs, options?: PatchApiV3ProductCampaignsProductCampaignIdOptions) => { 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/${encodeURIComponent(String(args['productCampaign.id']))}${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(campaignv3UpdateProductCampaignResponse, await res.json()) };