import {z} from 'zod' export type DspCustomerSetIdType = 'UNKNOWN_ID_TYPE' | 'GOOGLE_ADID' | 'APPLE_IDFA'; export type DspCustomerSetStatus = 'UNKNOWN_STATUS' | 'PREPARING' | 'READY' | 'FAILED'; export type FileUpdateInfoUpdateStatus = 'UNKNOWN_STATUS' | 'IN_PROGRESS' | 'SUCCESS' | 'FAILED'; export type CustomerSetFileUpdateInfo = {status?: FileUpdateInfoUpdateStatus | undefined, timestamp?: string | undefined, file_name?: string | undefined}; export type CustomerSetStatusDetailConnectionMethod = 'UNKNOWN_METHOD' | 'CLOUD_API' | 'MCP_UPLOAD' | 'AF_AUDIENCE_BUILDER' | 'BESPOKE'; export type CustomerSetStatusDetailErrorId = 'UNKNOWN_ERROR_ID' | 'TAGGING_ERROR' | 'REQUEST_ERROR' | 'PREPROCESSING_ERROR' | 'GENERIC_ERROR'; export type CustomerSetCustomerSetStatusDetail = {connection_method?: CustomerSetStatusDetailConnectionMethod | undefined, error_id?: CustomerSetStatusDetailErrorId | undefined, error_description?: string | undefined, csv_file_size?: number | undefined, aud_size?: number | undefined}; export type CustomerSetFileUpdateHistory = {status?: DspCustomerSetStatus | undefined, status_detail?: CustomerSetCustomerSetStatusDetail | undefined, updated_at?: string | undefined}; export type DspCustomerSet = {id?: string | undefined, title: string, description?: string | undefined, id_type: DspCustomerSetIdType, status?: DspCustomerSetStatus | undefined, data_file_path: string, is_upper?: boolean | undefined, auto_delete_at?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, recent_file_update_info?: CustomerSetFileUpdateInfo | undefined, status_detail?: CustomerSetCustomerSetStatusDetail | undefined, file_update_histories?: Array | undefined}; export type CreateApiCmV1CustomerSetsArgs = {ad_account_id: string, body: DspCustomerSet}; export type CreateApiCmV1CustomerSetsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dspCustomerSetIdType = z.enum(["UNKNOWN_ID_TYPE", "GOOGLE_ADID", "APPLE_IDFA"]); export const dspCustomerSetStatus = z.enum(["UNKNOWN_STATUS", "PREPARING", "READY", "FAILED"]); export const fileUpdateInfoUpdateStatus = z.enum(["UNKNOWN_STATUS", "IN_PROGRESS", "SUCCESS", "FAILED"]); export const customerSetFileUpdateInfo = z.object({status: fileUpdateInfoUpdateStatus.optional(), timestamp: z.string().optional(), file_name: z.string().optional()}); export const customerSetStatusDetailConnectionMethod = z.enum(["UNKNOWN_METHOD", "CLOUD_API", "MCP_UPLOAD", "AF_AUDIENCE_BUILDER", "BESPOKE"]); export const customerSetStatusDetailErrorId = z.enum(["UNKNOWN_ERROR_ID", "TAGGING_ERROR", "REQUEST_ERROR", "PREPROCESSING_ERROR", "GENERIC_ERROR"]); export const customerSetCustomerSetStatusDetail = z.object({connection_method: customerSetStatusDetailConnectionMethod.optional(), error_id: customerSetStatusDetailErrorId.optional(), error_description: z.string().optional(), csv_file_size: z.number().int().optional(), aud_size: z.number().int().optional()}); export const customerSetFileUpdateHistory = z.object({status: dspCustomerSetStatus.optional(), status_detail: customerSetCustomerSetStatusDetail.optional(), updated_at: z.string().optional()}); export const dspCustomerSet = z.object({id: z.string().optional(), title: z.string(), description: z.string().optional(), id_type: dspCustomerSetIdType, status: dspCustomerSetStatus.optional(), data_file_path: z.string(), is_upper: z.boolean().optional(), auto_delete_at: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), recent_file_update_info: customerSetFileUpdateInfo.optional(), status_detail: customerSetCustomerSetStatusDetail.optional(), file_update_histories: z.array(customerSetFileUpdateHistory).optional()}); export const messagesCreateCustomerSetResponse = z.object({customer_set: dspCustomerSet.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 CustomerSet. * * POST /cm/v1/customer-sets */ export const createApiCmV1CustomerSets = async (args: CreateApiCmV1CustomerSetsArgs, options?: CreateApiCmV1CustomerSetsOptions) => { 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/customer-sets${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(messagesCreateCustomerSetResponse, await res.json()) };