export type FullNameMatchBatchJobColumnRequest = {prefix: string, type: 'FULL_NAME_MATCH', validation_policy: 'OPTIONAL' | 'REQUIRED_COLUMN' | 'REQUIRED_VALUE', name: string}; export type PatternNameMatchBatchJobColumnRequest = {prefix: string, type: 'PATTERN_NAME_MATCH', validation_policy: 'OPTIONAL' | 'REQUIRED_COLUMN' | 'REQUIRED_VALUE', name_pattern: Record}; export type BatchJobColumnRequest = FullNameMatchBatchJobColumnRequest | PatternNameMatchBatchJobColumnRequest; export type AudienceListBatchJobDataSourceRequest = {type: 'AUDIENCE_LIST', audience_list_id: string}; export type FileAssetBatchJobDataSourceRequest = {type: 'FILE_ASSET', file_asset_id: string}; export type ReportBatchJobDataSourceRequest = {type: 'REPORT', report_id: string}; export type BatchJobDataSourceRequest = AudienceListBatchJobDataSourceRequest | FileAssetBatchJobDataSourceRequest | ReportBatchJobDataSourceRequest; export type BatchJobCreateRequest = {columns?: Array | undefined, data_source: BatchJobDataSourceRequest, default_event_name?: string | undefined, event_columns?: Array | undefined, event_data?: {[key: string]: string} | undefined, event_name?: string | undefined, name?: string | undefined, scopes?: (Array<'CLIENT_ADMIN' | 'CLIENT_SUPERUSER'>) | undefined, tags?: Array | undefined}; export type CreateApiV6BatchesArgs = {body: BatchJobCreateRequest}; export type CreateApiV6BatchesOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a batch job * * POST /v6/batches * * Also accepts auth: QUERY, COOKIE */ export const createApiV6Batches = async (args: CreateApiV6BatchesArgs, options?: CreateApiV6BatchesOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v6/batches${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 undefined };