import {z} from 'zod' export type ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType = 'STRING' | 'INTEGER' | 'FLOAT' | 'BOOLEAN' | 'DATE' | 'TIMESTAMP'; export type ExperimentsSQLModelPropertyInput = {column_name: string, column_type?: ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType | undefined, description?: (string | null) | undefined, migration_metadata: unknown, name: string}; export type ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems = {column_name: string, subject_type_id: string}; export type ExperimentsUpdateExposureSQLModelV2RequestDataAttributes = {date_partition_column?: (string | null) | undefined, experiment_column: string, migration_metadata: unknown, name: string, properties?: Array | undefined, sql: string, subject_types: Array, timestamp_column: string, variant_column: string}; export type ExperimentsUpdateExposureSQLModelV2RequestDataType = 'exposure-sql-models'; export type ExperimentsCreateExposureSQLModelV2RequestData = {attributes: ExperimentsUpdateExposureSQLModelV2RequestDataAttributes, id?: string | undefined, type: ExperimentsUpdateExposureSQLModelV2RequestDataType}; export type ExperimentsCreateExposureSQLModelV2Request = {data: ExperimentsCreateExposureSQLModelV2RequestData}; export type CreateApiApiV2ExperimentsExposureSqlModelsArgs = {body: ExperimentsCreateExposureSQLModelV2Request}; export type CreateApiApiV2ExperimentsExposureSqlModelsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const experimentsExposureSQLModelV2DTODataAttributesItems = z.object({column_name: z.string().optional(), column_type: z.string().optional(), description: z.string().optional(), id: z.string().optional(), migration_metadata: z.unknown(), name: z.string().optional(), pipeline_column_suffix: z.string().optional()}); export const experimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems = z.object({column_name: z.string(), subject_type_id: z.string()}); export const experimentsExposureSQLModelV2DTODataAttributes = z.object({archived_at: z.string().nullable().optional(), created_at: z.string().optional(), date_partition_column: z.string().nullable().optional(), experiment_column: z.string().optional(), experiment_count: z.number().int().nullable().optional(), migration_metadata: z.unknown(), name: z.string().optional(), properties: z.array(experimentsExposureSQLModelV2DTODataAttributesItems).optional(), sql: z.string().optional(), subject_types: z.array(experimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems).optional(), timestamp_column: z.string().optional(), updated_at: z.string().optional(), variant_column: z.string().optional()}); export const experimentsUpdateExposureSQLModelV2RequestDataType = z.literal("exposure-sql-models"); export const experimentsExposureSQLModelV2DTOData = z.object({attributes: experimentsExposureSQLModelV2DTODataAttributes.optional(), id: z.string(), type: experimentsUpdateExposureSQLModelV2RequestDataType}); export const experimentsExposureSQLModelV2DTO = z.object({data: experimentsExposureSQLModelV2DTOData}); 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 exposure SQL model * * POST /api/v2/experiments/exposure-sql-models * * Also accepts auth: AuthZ */ export const createApiApiV2ExperimentsExposureSqlModels = async (args: CreateApiApiV2ExperimentsExposureSqlModelsArgs, options?: CreateApiApiV2ExperimentsExposureSqlModelsOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/experiments/exposure-sql-models${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(experimentsExposureSQLModelV2DTO, await res.json()) };