import {z} from 'zod' export type CommonDeviceOs = 'UNKNOWN_DEVICE_OS' | 'ANDROID' | 'IOS' | 'VERSATILE' | 'MOBILE_WEB' | 'MACOS' | 'WINDOWS' | 'NEXT_VERSATILE'; export type TrackingLinkUrlDataVerificationStatus = 'UNKNOWN_VERIFICATION_STATUS' | 'UNVERIFIED' | 'VERIFYING' | 'VERIFIED'; export type UrlDataUnverifiedStatusData = {stored_at?: string | undefined, user_id?: string | undefined}; export type UrlDataVerifyingStatusData = {attempt_ids?: Array | undefined}; export type TrackingLinkVerificationAttemptUrlDataType = 'UNKNOWN_URL_DATA_TYPE' | 'CT_LINK' | 'VT_LINK'; export type DspTrackingLinkVerificationAttempt = {id?: string | undefined, ad_account_id?: string | undefined, tracking_link_id?: string | undefined, url_data_type?: TrackingLinkVerificationAttemptUrlDataType | undefined, user_id?: string | undefined, user_email?: string | undefined, user_name?: string | undefined, tracking_bundle_id?: string | undefined, resolved_url?: string | undefined, resolved_idfa?: string | undefined, started_at?: string | undefined, verified_at?: string | undefined}; export type UrlDataVerifiedStatusData = {verified_attempt?: DspTrackingLinkVerificationAttempt | undefined}; export type TrackingLinkUrlData = {url: string, status?: TrackingLinkUrlDataVerificationStatus | undefined, unverified_status_data?: UrlDataUnverifiedStatusData | undefined, verifying_status_data?: UrlDataVerifyingStatusData | undefined, verified_status_data?: UrlDataVerifiedStatusData | undefined}; 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 DspTrackingLink = {id?: string | undefined, ad_account_id?: string | undefined, product_id?: string | undefined, title: string, description?: string | undefined, device_os: CommonDeviceOs, click_through_link: TrackingLinkUrlData, view_through_link?: TrackingLinkUrlData | undefined, ctv_adjust_dual_vt_link?: TrackingLinkUrlData | undefined, tracking_company?: AdcloudcommonTrackingCompany | undefined, created_at?: string | undefined, updated_at?: string | undefined}; export type CreateApiCmV1TrackingLinksValidateArgs = {ad_account_id: string, body: DspTrackingLink}; export type CreateApiCmV1TrackingLinksValidateOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const messagesValidateTrackingLinkResponseStatus = z.enum(["UNKNOWN_VALIDATION_STATUS", "PASSED", "FAILED"]); export const trackingLinkValidationErrorErrorCode = z.enum(["UNKNOWN_VALIDATION_ERROR", "INVALID_LINK", "INVALID_SCHEME", "INVALID_HOST", "INVALID_PATH", "INVALID_QUERY_PARAM", "MISSING_REQUIRED_QUERY_PARAM", "NOT_ALLOWED_QUERY_PARAM", "INVALID_QUERY_PARAM_ENCODED_MACRO", "DUPLICATE_QUERY_PARAM", "NOT_SUPPORTED_MACRO", "CONTAINS_LEGACY_MACRO", "ADJUST_BRANDED_LINK_HOST_MISMATCH", "ADJUST_UNIVERSAL_LINK_HOST_MISMATCH", "AF_TRACKING_BUNDLE_MISMATCH", "ADJUST_UNSEEN_TRACKER_TOKEN", "ADJUST_CT_VT_TOKEN_MISMATCH", "ADJUST_MISSING_BRANDED_LINK_HOST", "ADJUST_MISSING_UNIVERSAL_LINK_HOST", "ADJUST_CTV_MULTI_TOKEN", "AF_AGENCY_TOKEN_MISMATCH", "EMPTY_AF_AGENCY_TOKEN", "EMPTY_AF_SITEID"]); export const validateTrackingLinkResponseTrackingLinkValidationError = z.object({error_code: trackingLinkValidationErrorErrorCode.optional(), params: z.record(z.string(), z.string()).optional(), context: z.string().optional(), error_msg: z.string().optional()}); export const messagesValidateTrackingLinkResponse = z.object({status: messagesValidateTrackingLinkResponseStatus.optional(), validation_errors: z.array(validateTrackingLinkResponseTrackingLinkValidationError).optional(), validation_errors_click_through_link: z.array(validateTrackingLinkResponseTrackingLinkValidationError).optional(), validation_errors_view_through_link: z.array(validateTrackingLinkResponseTrackingLinkValidationError).optional(), validation_warnings_click_through_link: z.array(validateTrackingLinkResponseTrackingLinkValidationError).optional(), validation_warnings_view_through_link: z.array(validateTrackingLinkResponseTrackingLinkValidationError).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 }; /** * Validate a TrackingLink. * * POST /cm/v1/tracking-links/validate */ export const createApiCmV1TrackingLinksValidate = async (args: CreateApiCmV1TrackingLinksValidateArgs, options?: CreateApiCmV1TrackingLinksValidateOptions) => { 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/tracking-links/validate${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(messagesValidateTrackingLinkResponse, await res.json()) };