import {z} from 'zod' export type SyncFrequency = 0 | 3600000000000 | 86400000000000 | 604800000000000; export type DatabricksClusterConfig = {spark_version?: string | undefined, node_type_id?: string | undefined, driver_node_type_id?: (string | null) | undefined, num_workers?: number | undefined, autoscale?: ({min_workers?: number | undefined, max_workers?: number | undefined} | null) | undefined, spark_conf?: ({[key: string]: string} | null) | undefined, spark_env_vars?: ({[key: string]: string} | null) | undefined, data_security_mode?: ('USER_ISOLATION' | 'SINGLE_USER' | 'NONE' | 'LEGACY_TABLE_ACL' | 'LEGACY_PASSTHROUGH' | 'LEGACY_SINGLE_USER' | 'LEGACY_SINGLE_USER_STANDARD' | null) | undefined, single_user_name?: (string | null) | undefined, custom_tags?: ({[key: string]: string} | null) | undefined, policy_id?: (string | null) | undefined, instance_pool_id?: (string | null) | undefined, driver_instance_pool_id?: (string | null) | undefined, enable_elastic_disk?: (boolean | null) | undefined, runtime_engine?: ('STANDARD' | 'PHOTON' | null) | undefined, aws_attributes?: (Record | null) | undefined, azure_attributes?: (Record | null) | undefined, gcp_attributes?: (Record | null) | undefined, init_scripts?: (Array> | null) | undefined} | null; export type DatabricksParams = {export_cluster_config?: DatabricksClusterConfig | undefined} | null; export type PatchWarehouseImportRequest = {paused: boolean, run_every: SyncFrequency, databricks_params?: DatabricksParams | undefined}; export type PatchApiProjectsProjectIdWarehouseSourcesImportsImportIdArgs = {projectId: number, importId: number, body: PatchWarehouseImportRequest}; export type PatchApiProjectsProjectIdWarehouseSourcesImportsImportIdOptions = {baseUrl?: string | undefined, ServiceAccount?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const importType = z.enum(["event_sync", "event_stream", "people", "groups", "lookup_table"]); export const syncMode = z.enum(["time_based", "mirror_mode", "full_sync", "one_time"]); export const tableParams = z.object({}); export const syncFrequency = z.union([z.literal(0), z.literal(3600000000000), z.literal(86400000000000), z.literal(604800000000000)]); export const propertyMappings = z.record(z.string(), z.string()).nullable(); export const databricksClusterConfig = z.object({spark_version: z.string().optional(), node_type_id: z.string().optional(), driver_node_type_id: z.string().nullable().optional(), num_workers: z.number().int().gte(0).optional(), autoscale: z.object({min_workers: z.number().int().gte(0).optional(), max_workers: z.number().int().gte(1).optional()}).nullable().optional(), spark_conf: z.record(z.string(), z.string()).nullable().optional(), spark_env_vars: z.record(z.string(), z.string()).nullable().optional(), data_security_mode: z.enum(["USER_ISOLATION", "SINGLE_USER", "NONE", "LEGACY_TABLE_ACL", "LEGACY_PASSTHROUGH", "LEGACY_SINGLE_USER", "LEGACY_SINGLE_USER_STANDARD"]).nullable().optional(), single_user_name: z.string().nullable().optional(), custom_tags: z.record(z.string(), z.string()).nullable().optional(), policy_id: z.string().nullable().optional(), instance_pool_id: z.string().nullable().optional(), driver_instance_pool_id: z.string().nullable().optional(), enable_elastic_disk: z.boolean().nullable().optional(), runtime_engine: z.enum(["STANDARD", "PHOTON"]).nullable().optional(), aws_attributes: z.object({}).nullable().optional(), azure_attributes: z.object({}).nullable().optional(), gcp_attributes: z.object({}).nullable().optional(), init_scripts: z.array(z.object({})).nullable().optional()}).nullable(); export const databricksParams = z.object({export_cluster_config: databricksClusterConfig.optional()}).nullable(); export const warehouseImportDetail = z.object({id: z.number().int().optional(), import_type: importType.optional(), sync_mode: syncMode.optional(), created: z.string().optional(), creator_id: z.number().int().optional(), creator_name: z.string().optional(), creator_email: z.string().optional(), warehouse_source_id: z.number().int().optional(), table_params: tableParams.optional(), paused: z.boolean().optional(), run_every: syncFrequency.optional(), last_dispatch: z.number().int().nullable().optional(), is_deleted: z.boolean().optional(), event_name: z.string().nullable().optional(), event_column_name: z.string().nullable().optional(), time_column_name: z.string().nullable().optional(), user_column_name: z.string().nullable().optional(), insert_time_column_name: z.string().nullable().optional(), property_mappings: propertyMappings.optional(), group_key: z.string().nullable().optional(), group_id_column: z.string().nullable().optional(), databricks_params: databricksParams.optional()}); export const patchApiProjectsProjectIdWarehouseSourcesImportsImportIdResponse = z.object({status: z.literal("ok").optional(), results: warehouseImportDetail.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 }; /** * Update a warehouse import * * PATCH /projects/{projectId}/warehouse-sources/imports/{importId} * * Also accepts auth: ProjectSecret */ export const patchApiProjectsProjectIdWarehouseSourcesImportsImportId = async (args: PatchApiProjectsProjectIdWarehouseSourcesImportsImportIdArgs, options?: PatchApiProjectsProjectIdWarehouseSourcesImportsImportIdOptions) => { const {baseUrl = "https://mixpanel.com/api/query", fetch: fetchFn = fetch, ServiceAccount} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ServiceAccount !== undefined) headers.set('authorization', `Basic ${btoa(`${ServiceAccount.username}:${ServiceAccount.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/warehouse-sources/imports/${encodeURIComponent(String(args.importId))}${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(patchApiProjectsProjectIdWarehouseSourcesImportsImportIdResponse, await res.json()) };