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 UpdateApiApiV2ExperimentsExposureSqlModelsExposureSqlModelIdArgs = {exposure_sql_model_id: string, include?: Array | undefined, body: ExperimentsCreateExposureSQLModelV2Request}; export type UpdateApiApiV2ExperimentsExposureSqlModelsExposureSqlModelIdOptions = {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 experimentsUpdateExposureSQLModelV2ResponseMeta = z.object({removed_property_names: z.array(z.string()).optional(), removed_subject_type_ids: z.array(z.string()).optional()}); export const experimentsUpdateExposureSQLModelV2Response = z.object({data: experimentsExposureSQLModelV2DTOData, meta: experimentsUpdateExposureSQLModelV2ResponseMeta.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 exposure SQL model * * PUT /api/v2/experiments/exposure-sql-models/{exposure_sql_model_id} * * Also accepts auth: AuthZ */ export const updateApiApiV2ExperimentsExposureSqlModelsExposureSqlModelId = async (args: UpdateApiApiV2ExperimentsExposureSqlModelsExposureSqlModelIdArgs, options?: UpdateApiApiV2ExperimentsExposureSqlModelsExposureSqlModelIdOptions) => { 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") for (const item of args.include ?? []) query.append("include", String(item)) 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/${encodeURIComponent(String(args.exposure_sql_model_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(experimentsUpdateExposureSQLModelV2Response, await res.json()) };