import {z} from 'zod' export type CommonDeviceOs = 'UNKNOWN_DEVICE_OS' | 'ANDROID' | 'IOS' | 'VERSATILE' | 'MOBILE_WEB' | 'MACOS' | 'WINDOWS' | 'NEXT_VERSATILE'; export type DspProductType = 'UNKNOWN_TYPE' | 'APP' | 'WEB'; export type AdcloudcommonTrackingCompany = 'UNKNOWN_TRACKING_COMPANY' | 'KOCHAVA' | 'ADJUST' | 'MAT' | 'MOLOCO_PIXEL' | 'APPSFLYER' | 'ADBRIX' | 'WEB' | 'GENERIC' | 'TRACKFNT' | 'AIRBRIDGE' | 'MOLOCO_E2E' | 'APSALAR' | 'BRANCH' | 'TENJIN' | 'SINGULAR' | 'ADBRIX_V2' | 'TRAFFICGUARD' | 'GAMELOFT' | 'SKADNETWORK' | 'MYTRACKER' | 'MOLOCO_RMP' | 'MOLOCO_PIXEL_V2' | 'JUSTTRACK' | 'SHOPEE' | 'KOCHAVA_FOR_PUBLISHER' | 'GAMESIGHT' | 'CAULY' | 'HASOFFER' | 'ADACTION' | 'CURATE'; export type DspPostbackIntegration = {mmp?: AdcloudcommonTrackingCompany | undefined, bundle_id?: string | undefined}; export type DspMmpIntegrationStatus = 'UNKNOWN_STATUS' | 'UNDER_REVIEW' | 'DENIED' | 'ACTIVE'; export type ConversionValueConfigurationItemConversionValueScheme = 'UNKNOWN_CONVERSION_VALUE_SCHEME' | 'CONVERSION_VALUE_SCHEME_SINGLE_EVENT' | 'CONVERSION_VALUE_SCHEME_MULTIPLE_EVENTS' | 'CONVERSION_VALUE_SCHEME_CUSTOM_EVENTS' | 'CONVERSION_VALUE_SCHEME_SKAN_V4_EVENTS'; export type AdcloudcommonFloatingPointRange = {start?: number | undefined, end?: number | undefined}; export type ConversionValueConfigurationItemCvConfigurationForSingleEventEventInfo = {event_name?: string | undefined, revenue_interval?: AdcloudcommonFloatingPointRange | undefined}; export type ConversionValueConfigurationItemCvConfigurationForSingleEvent = {cv_revenue_events?: {[key: string]: ConversionValueConfigurationItemCvConfigurationForSingleEventEventInfo} | undefined}; export type ConversionValueConfigurationItemCvConfigurationForMultipleEvents = {cv_events?: {[key: string]: string} | undefined}; export type ConversionValueConfigurationItemCvConfigurationForCustomEventsEventInfo = {event_name: string, event_value?: string | undefined, revenue_interval?: AdcloudcommonFloatingPointRange | undefined, predict_revenue_interval?: AdcloudcommonFloatingPointRange | undefined, event_counter: number, hours_from_install: number}; export type CvConfigurationForCustomEventsEventList = {events?: Array | undefined}; export type ConversionValueConfigurationItemCvConfigurationForCustomEvents = {cv_events?: {[key: string]: CvConfigurationForCustomEventsEventList} | undefined}; export type CvConfigurationForSkanV4EventsPostback = {postback_sequence_index?: number | undefined, measurement_window?: number | undefined, coarse_grained_values?: {[key: string]: CvConfigurationForCustomEventsEventList} | undefined, fine_grained_values?: {[key: string]: CvConfigurationForCustomEventsEventList} | undefined}; export type ConversionValueConfigurationItemCvConfigurationForSkanV4Events = {postbacks?: Array | undefined}; export type CvConfigurationAutoRefreshAutoRefreshResult = 'UNKNOWN' | 'OK' | 'ERROR'; export type ConversionValueConfigurationItemCvConfigurationAutoRefresh = {enable_auto_refresh?: boolean | undefined, refresh_result?: CvConfigurationAutoRefreshAutoRefreshResult | undefined, refresh_error_message?: string | undefined, last_auto_refreshed_at?: string | undefined}; export type MmpIntegrationConversionValueConfigurationItem = {effective_date?: string | undefined, scheme?: ConversionValueConfigurationItemConversionValueScheme | undefined, cv_single?: ConversionValueConfigurationItemCvConfigurationForSingleEvent | undefined, cv_multi?: ConversionValueConfigurationItemCvConfigurationForMultipleEvents | undefined, cv_custom?: ConversionValueConfigurationItemCvConfigurationForCustomEvents | undefined, cv_skan_v4?: ConversionValueConfigurationItemCvConfigurationForSkanV4Events | undefined, auto_refresh?: ConversionValueConfigurationItemCvConfigurationAutoRefresh | undefined}; export type MmpContextAdjustContext = {url_host_universal_link?: string | undefined, url_host_branded_link?: string | undefined}; export type MmpIntegrationMmpContext = {adjust?: MmpContextAdjustContext | undefined}; export type DspMmpIntegration = {id?: string | undefined, mmp_bundle_id?: string | undefined, mmp?: AdcloudcommonTrackingCompany | undefined, ownership?: boolean | undefined, status?: DspMmpIntegrationStatus | undefined, denied_reason?: string | undefined, cv_config_item?: MmpIntegrationConversionValueConfigurationItem | undefined, mmp_context?: MmpIntegrationMmpContext | undefined, updated_at?: string | undefined, allow_fingerprinting?: boolean | undefined, fingerprinting_last_auto_refreshed_at?: string | undefined}; export type AppPropertiesAppScreenshots = {urls?: Array | undefined}; export type AppPropertiesAppEventType = 'UNKNOWN' | 'IN_APP_ADVERTISING' | 'IN_APP_PURCHASE' | 'SIGN_UP' | 'SUBSCRIPTION' | 'PREDICTED_LIFETIME_VALUE' | 'ACHIEVE_LEVEL' | 'START_TRIAL' | 'ADD_PAYMENT_INFO' | 'VIEW_PRODUCT_OR_CONTENT' | 'ADD_TO_WISHLIST' | 'SEARCH' | 'ADD_TO_CART' | 'BEGIN_CHECKOUT' | 'FIRST_DEPOSIT' | 'FIRST_TRADE' | 'OTHER'; export type AppPropertiesIosPrimaryMeasurement = 'IOS_PRIMARY_MEASUREMENT_UNKNOWN' | 'IOS_PRIMARY_MEASUREMENT_NONE' | 'IOS_PRIMARY_MEASUREMENT_SKAN' | 'IOS_PRIMARY_MEASUREMENT_MMP'; export type AppPropertiesIosSecondaryMeasurement = 'IOS_SECONDARY_MEASUREMENT_UNKNOWN' | 'IOS_SECONDARY_MEASUREMENT_NONE' | 'IOS_SECONDARY_MEASUREMENT_NA' | 'IOS_SECONDARY_MEASUREMENT_SKAN' | 'IOS_SECONDARY_MEASUREMENT_MMP' | 'IOS_SECONDARY_MEASUREMENT_OTHER_MMP' | 'IOS_SECONDARY_MEASUREMENT_OTHER_3P' | 'IOS_SECONDARY_MEASUREMENT_INCREMENTALITY' | 'IOS_SECONDARY_MEASUREMENT_CUSTOM'; export type ProductAppProperties = {bundle_id: string, category?: string | undefined, categories?: Array | undefined, category_readable?: string | undefined, rating?: number | undefined, rating_cnt?: unknown | undefined, app_store_url?: string | undefined, available_countries?: Array | undefined, unavailable_countries?: Array | undefined, rtb_bundle_ids?: Array | undefined, postback_integration?: DspPostbackIntegration | undefined, mmp_integration?: DspMmpIntegration | undefined, skadn_mmp_integration?: DspMmpIntegration | undefined, content_rating?: string | undefined, storekit_enabled?: boolean | undefined, autoinline_enabled?: boolean | undefined, localized_app_name?: {[key: string]: string} | undefined, localized_app_icon_url?: {[key: string]: string} | undefined, localized_app_screenshots?: {[key: string]: AppPropertiesAppScreenshots} | undefined, app_event_types?: {[key: string]: AppPropertiesAppEventType} | undefined, description?: string | undefined, short_description?: string | undefined, ios_primary_measurement?: AppPropertiesIosPrimaryMeasurement | undefined, ios_secondary_measurement?: AppPropertiesIosSecondaryMeasurement | undefined, ios_custom_measurement?: string | undefined}; export type ProductWebProperties = {category?: string | undefined, landing_url?: string | undefined, categories?: Array | undefined}; export type ProductDynamicCreativeProperty = {permission?: boolean | undefined}; export type ProductSuspensionActionKind = 'UNKNOWN_KIND' | 'CREATE' | 'UPDATE'; export type ProductSuspensionActionType = 'UNKNOWN_TYPE' | 'SUSPEND_UNTIL' | 'SUSPEND_INDEFINITELY' | 'STOP_SUSPENSION'; export type ProductSuspensionAction = {user_name?: string | undefined, user_email?: string | undefined, reason?: string | undefined, kind?: ProductSuspensionActionKind | undefined, type?: ProductSuspensionActionType | undefined, effective_from?: string | undefined, effective_until?: string | undefined, created_at?: string | undefined}; export type DspProduct = {id?: string | undefined, ad_account_id?: string | undefined, title: string, description?: string | undefined, advertiser_domain: string, allow_empty_advertiser_domain?: boolean | undefined, device_os?: CommonDeviceOs | undefined, developer_name?: string | undefined, type: DspProductType, app?: ProductAppProperties | undefined, web?: ProductWebProperties | undefined, dynamic_creative_property?: ProductDynamicCreativeProperty | undefined, suspension_history?: Array | undefined, created_at?: string | undefined, updated_at?: string | undefined}; export type CreateApiCmV1ProductsArgs = {ad_account_id: string, body: DspProduct}; export type CreateApiCmV1ProductsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const commonDeviceOs = z.enum(["UNKNOWN_DEVICE_OS", "ANDROID", "IOS", "VERSATILE", "MOBILE_WEB", "MACOS", "WINDOWS", "NEXT_VERSATILE"]); export const dspProductType = z.enum(["UNKNOWN_TYPE", "APP", "WEB"]); export const adcloudcommonTrackingCompany = z.enum(["UNKNOWN_TRACKING_COMPANY", "KOCHAVA", "ADJUST", "MAT", "MOLOCO_PIXEL", "APPSFLYER", "ADBRIX", "WEB", "GENERIC", "TRACKFNT", "AIRBRIDGE", "MOLOCO_E2E", "APSALAR", "BRANCH", "TENJIN", "SINGULAR", "ADBRIX_V2", "TRAFFICGUARD", "GAMELOFT", "SKADNETWORK", "MYTRACKER", "MOLOCO_RMP", "MOLOCO_PIXEL_V2", "JUSTTRACK", "SHOPEE", "KOCHAVA_FOR_PUBLISHER", "GAMESIGHT", "CAULY", "HASOFFER", "ADACTION", "CURATE"]); export const dspPostbackIntegration = z.object({mmp: adcloudcommonTrackingCompany.optional(), bundle_id: z.string().optional()}); export const dspMmpIntegrationStatus = z.enum(["UNKNOWN_STATUS", "UNDER_REVIEW", "DENIED", "ACTIVE"]); export const conversionValueConfigurationItemConversionValueScheme = z.enum(["UNKNOWN_CONVERSION_VALUE_SCHEME", "CONVERSION_VALUE_SCHEME_SINGLE_EVENT", "CONVERSION_VALUE_SCHEME_MULTIPLE_EVENTS", "CONVERSION_VALUE_SCHEME_CUSTOM_EVENTS", "CONVERSION_VALUE_SCHEME_SKAN_V4_EVENTS"]); export const adcloudcommonFloatingPointRange = z.object({start: z.number().optional(), end: z.number().optional()}); export const conversionValueConfigurationItemCvConfigurationForSingleEventEventInfo = z.object({event_name: z.string().optional(), revenue_interval: adcloudcommonFloatingPointRange.optional()}); export const conversionValueConfigurationItemCvConfigurationForSingleEvent = z.object({cv_revenue_events: z.record(z.string(), conversionValueConfigurationItemCvConfigurationForSingleEventEventInfo).optional()}); export const conversionValueConfigurationItemCvConfigurationForMultipleEvents = z.object({cv_events: z.record(z.string(), z.string()).optional()}); export const conversionValueConfigurationItemCvConfigurationForCustomEventsEventInfo = z.object({event_name: z.string(), event_value: z.string().optional(), revenue_interval: adcloudcommonFloatingPointRange.optional(), predict_revenue_interval: adcloudcommonFloatingPointRange.optional(), event_counter: z.number().int(), hours_from_install: z.number().int()}); export const cvConfigurationForCustomEventsEventList = z.object({events: z.array(conversionValueConfigurationItemCvConfigurationForCustomEventsEventInfo).optional()}); export const conversionValueConfigurationItemCvConfigurationForCustomEvents = z.object({cv_events: z.record(z.string(), cvConfigurationForCustomEventsEventList).optional()}); export const cvConfigurationForSkanV4EventsPostback = z.object({postback_sequence_index: z.number().int().optional(), measurement_window: z.number().int().optional(), coarse_grained_values: z.record(z.string(), cvConfigurationForCustomEventsEventList).optional(), fine_grained_values: z.record(z.string(), cvConfigurationForCustomEventsEventList).optional()}); export const conversionValueConfigurationItemCvConfigurationForSkanV4Events = z.object({postbacks: z.array(cvConfigurationForSkanV4EventsPostback).optional()}); export const cvConfigurationAutoRefreshAutoRefreshResult = z.enum(["UNKNOWN", "OK", "ERROR"]); export const conversionValueConfigurationItemCvConfigurationAutoRefresh = z.object({enable_auto_refresh: z.boolean().optional(), refresh_result: cvConfigurationAutoRefreshAutoRefreshResult.optional(), refresh_error_message: z.string().optional(), last_auto_refreshed_at: z.string().optional()}); export const mmpIntegrationConversionValueConfigurationItem = z.object({effective_date: z.string().optional(), scheme: conversionValueConfigurationItemConversionValueScheme.optional(), cv_single: conversionValueConfigurationItemCvConfigurationForSingleEvent.optional(), cv_multi: conversionValueConfigurationItemCvConfigurationForMultipleEvents.optional(), cv_custom: conversionValueConfigurationItemCvConfigurationForCustomEvents.optional(), cv_skan_v4: conversionValueConfigurationItemCvConfigurationForSkanV4Events.optional(), auto_refresh: conversionValueConfigurationItemCvConfigurationAutoRefresh.optional()}); export const mmpContextAdjustContext = z.object({url_host_universal_link: z.string().optional(), url_host_branded_link: z.string().optional()}); export const mmpIntegrationMmpContext = z.object({adjust: mmpContextAdjustContext.optional()}); export const dspMmpIntegration = z.object({id: z.string().optional(), mmp_bundle_id: z.string().optional(), mmp: adcloudcommonTrackingCompany.optional(), ownership: z.boolean().optional(), status: dspMmpIntegrationStatus.optional(), denied_reason: z.string().optional(), cv_config_item: mmpIntegrationConversionValueConfigurationItem.optional(), mmp_context: mmpIntegrationMmpContext.optional(), updated_at: z.string().optional(), allow_fingerprinting: z.boolean().optional(), fingerprinting_last_auto_refreshed_at: z.string().optional()}); export const appPropertiesAppScreenshots = z.object({urls: z.array(z.string()).optional()}); export const appPropertiesAppEventType = z.enum(["UNKNOWN", "IN_APP_ADVERTISING", "IN_APP_PURCHASE", "SIGN_UP", "SUBSCRIPTION", "PREDICTED_LIFETIME_VALUE", "ACHIEVE_LEVEL", "START_TRIAL", "ADD_PAYMENT_INFO", "VIEW_PRODUCT_OR_CONTENT", "ADD_TO_WISHLIST", "SEARCH", "ADD_TO_CART", "BEGIN_CHECKOUT", "FIRST_DEPOSIT", "FIRST_TRADE", "OTHER"]); export const appPropertiesIosPrimaryMeasurement = z.enum(["IOS_PRIMARY_MEASUREMENT_UNKNOWN", "IOS_PRIMARY_MEASUREMENT_NONE", "IOS_PRIMARY_MEASUREMENT_SKAN", "IOS_PRIMARY_MEASUREMENT_MMP"]); export const appPropertiesIosSecondaryMeasurement = z.enum(["IOS_SECONDARY_MEASUREMENT_UNKNOWN", "IOS_SECONDARY_MEASUREMENT_NONE", "IOS_SECONDARY_MEASUREMENT_NA", "IOS_SECONDARY_MEASUREMENT_SKAN", "IOS_SECONDARY_MEASUREMENT_MMP", "IOS_SECONDARY_MEASUREMENT_OTHER_MMP", "IOS_SECONDARY_MEASUREMENT_OTHER_3P", "IOS_SECONDARY_MEASUREMENT_INCREMENTALITY", "IOS_SECONDARY_MEASUREMENT_CUSTOM"]); export const productAppProperties = z.object({bundle_id: z.string(), category: z.string().optional(), categories: z.array(z.string()).optional(), category_readable: z.string().optional(), rating: z.number().optional(), rating_cnt: z.string().optional(), app_store_url: z.string().optional(), available_countries: z.array(z.string()).optional(), unavailable_countries: z.array(z.string()).optional(), rtb_bundle_ids: z.array(z.string()).optional(), postback_integration: dspPostbackIntegration.optional(), mmp_integration: dspMmpIntegration.optional(), skadn_mmp_integration: dspMmpIntegration.optional(), content_rating: z.string().optional(), storekit_enabled: z.boolean().optional(), autoinline_enabled: z.boolean().optional(), localized_app_name: z.record(z.string(), z.string()).optional(), localized_app_icon_url: z.record(z.string(), z.string()).optional(), localized_app_screenshots: z.record(z.string(), appPropertiesAppScreenshots).optional(), app_event_types: z.record(z.string(), appPropertiesAppEventType).optional(), description: z.string().optional(), short_description: z.string().optional(), ios_primary_measurement: appPropertiesIosPrimaryMeasurement.optional(), ios_secondary_measurement: appPropertiesIosSecondaryMeasurement.optional(), ios_custom_measurement: z.string().optional()}); export const productWebProperties = z.object({category: z.string().optional(), landing_url: z.string().optional(), categories: z.array(z.string()).optional()}); export const productDynamicCreativeProperty = z.object({permission: z.boolean().optional()}); export const productSuspensionActionKind = z.enum(["UNKNOWN_KIND", "CREATE", "UPDATE"]); export const productSuspensionActionType = z.enum(["UNKNOWN_TYPE", "SUSPEND_UNTIL", "SUSPEND_INDEFINITELY", "STOP_SUSPENSION"]); export const productSuspensionAction = z.object({user_name: z.string().optional(), user_email: z.string().optional(), reason: z.string().optional(), kind: productSuspensionActionKind.optional(), type: productSuspensionActionType.optional(), effective_from: z.string().optional(), effective_until: z.string().optional(), created_at: z.string().optional()}); export const dspProduct = z.object({id: z.string().optional(), ad_account_id: z.string().optional(), title: z.string(), description: z.string().optional(), advertiser_domain: z.string(), allow_empty_advertiser_domain: z.boolean().optional(), device_os: commonDeviceOs.optional(), developer_name: z.string().optional(), type: dspProductType, app: productAppProperties.optional(), web: productWebProperties.optional(), dynamic_creative_property: productDynamicCreativeProperty.optional(), suspension_history: z.array(productSuspensionAction).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const dspPostbackIntegrationStatus = z.object({device_os: commonDeviceOs.optional(), country: z.string().optional(), complete_percentage: z.number().optional(), integration_success: z.boolean().optional()}); export const messagesCreateProductResponse = z.object({product: dspProduct.optional(), postback_integration_statuses: z.array(dspPostbackIntegrationStatus).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 }; /** * Create a new Product. * * POST /cm/v1/products */ export const createApiCmV1Products = async (args: CreateApiCmV1ProductsArgs, options?: CreateApiCmV1ProductsOptions) => { const {baseUrl = "https://api.moloco.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.ad_account_id != null) query.append("ad_account_id", String(args.ad_account_id)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/cm/v1/products${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(messagesCreateProductResponse, await res.json()) };