import {z} from 'zod' export type ExternalConnectionCloudflareConfig = {api_token?: string | undefined}; export type ExternalConnectionMongoDbAtlasConfig = {client_id?: string | undefined, client_secret?: string | undefined}; export type Configv1ExternalConnectionHTTPConfigBasicAuth = {password?: string | undefined, username?: string | undefined}; export type Configv1ExternalConnectionHTTPConfigTLSConfig = {insecure_skip_verify?: boolean | undefined}; export type Configv1ExternalConnectionHTTPConfig = {basic_auth?: Configv1ExternalConnectionHTTPConfigBasicAuth | undefined, bearer_token?: string | undefined, tls_config?: Configv1ExternalConnectionHTTPConfigTLSConfig | undefined}; export type Configv1ExternalConnectionOpsGenieConfig = {api_key?: string | undefined, api_url?: string | undefined, http_config?: Configv1ExternalConnectionHTTPConfig | undefined}; export type Configv1PagerdutyEventsVersion = 'PAGERDUTY_EVENTS_VERSION_V1' | 'PAGERDUTY_EVENTS_VERSION_V2'; export type PagerdutyConfigPagerdutyEventsConfig = {api_key?: string | undefined, version?: Configv1PagerdutyEventsVersion | undefined}; export type PagerdutyConfigPagerdutyRESTConfig = {api_key?: string | undefined}; export type Configv1ExternalConnectionPagerdutyConfig = {events?: PagerdutyConfigPagerdutyEventsConfig | undefined, rest?: PagerdutyConfigPagerdutyRESTConfig | undefined}; export type ExternalConnectionSendgridConfig = {api_key?: string | undefined}; export type Configv1ExternalConnectionSlackConfig = {api_url?: string | undefined, token?: string | undefined}; export type Configv1ExternalConnectionVictorOpsConfig = {api_key?: string | undefined, api_url?: string | undefined}; export type Configv1ExternalConnectionWebhookConfig = {http_config?: Configv1ExternalConnectionHTTPConfig | undefined, url?: string | undefined}; export type Configv1ExternalConnection = {cloudflare?: ExternalConnectionCloudflareConfig | undefined, created_at?: string | undefined, mongodb_atlas?: ExternalConnectionMongoDbAtlasConfig | undefined, name: string, ops_genie?: Configv1ExternalConnectionOpsGenieConfig | undefined, pagerduty?: Configv1ExternalConnectionPagerdutyConfig | undefined, sendgrid?: ExternalConnectionSendgridConfig | undefined, slack?: Configv1ExternalConnectionSlackConfig | undefined, slug?: string | undefined, updated_at?: string | undefined, victor_ops?: Configv1ExternalConnectionVictorOpsConfig | undefined, webhook?: Configv1ExternalConnectionWebhookConfig | undefined}; export type ConfigV1UpdateExternalConnectionBody = {create_if_missing?: boolean | undefined, dry_run?: boolean | undefined, external_connection?: Configv1ExternalConnection | undefined}; export type UpdateApiApiV1ConfigExternalConnectionsSlugArgs = {slug: string, body: ConfigV1UpdateExternalConnectionBody}; export type UpdateApiApiV1ConfigExternalConnectionsSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const externalConnectionCloudflareConfig = z.object({api_token: z.string().optional()}); export const externalConnectionMongoDbAtlasConfig = z.object({client_id: z.string().optional(), client_secret: z.string().optional()}); export const configv1ExternalConnectionHTTPConfigBasicAuth = z.object({password: z.string().optional(), username: z.string().optional()}); export const configv1ExternalConnectionHTTPConfigTLSConfig = z.object({insecure_skip_verify: z.boolean().optional()}); export const configv1ExternalConnectionHTTPConfig = z.object({basic_auth: configv1ExternalConnectionHTTPConfigBasicAuth.optional(), bearer_token: z.string().optional(), tls_config: configv1ExternalConnectionHTTPConfigTLSConfig.optional()}); export const configv1ExternalConnectionOpsGenieConfig = z.object({api_key: z.string().optional(), api_url: z.string().optional(), http_config: configv1ExternalConnectionHTTPConfig.optional()}); export const configv1PagerdutyEventsVersion = z.enum(["PAGERDUTY_EVENTS_VERSION_V1", "PAGERDUTY_EVENTS_VERSION_V2"]); export const pagerdutyConfigPagerdutyEventsConfig = z.object({api_key: z.string().optional(), version: configv1PagerdutyEventsVersion.optional()}); export const pagerdutyConfigPagerdutyRESTConfig = z.object({api_key: z.string().optional()}); export const configv1ExternalConnectionPagerdutyConfig = z.object({events: pagerdutyConfigPagerdutyEventsConfig.optional(), rest: pagerdutyConfigPagerdutyRESTConfig.optional()}); export const externalConnectionSendgridConfig = z.object({api_key: z.string().optional()}); export const configv1ExternalConnectionSlackConfig = z.object({api_url: z.string().optional(), token: z.string().optional()}); export const configv1ExternalConnectionVictorOpsConfig = z.object({api_key: z.string().optional(), api_url: z.string().optional()}); export const configv1ExternalConnectionWebhookConfig = z.object({http_config: configv1ExternalConnectionHTTPConfig.optional(), url: z.string().optional()}); export const configv1ExternalConnection = z.object({cloudflare: externalConnectionCloudflareConfig.optional(), created_at: z.string().optional(), mongodb_atlas: externalConnectionMongoDbAtlasConfig.optional(), name: z.string(), ops_genie: configv1ExternalConnectionOpsGenieConfig.optional(), pagerduty: configv1ExternalConnectionPagerdutyConfig.optional(), sendgrid: externalConnectionSendgridConfig.optional(), slack: configv1ExternalConnectionSlackConfig.optional(), slug: z.string().optional(), updated_at: z.string().optional(), victor_ops: configv1ExternalConnectionVictorOpsConfig.optional(), webhook: configv1ExternalConnectionWebhookConfig.optional()}); export const configv1UpdateExternalConnectionResponse = z.object({external_connection: configv1ExternalConnection.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 }; /** * PUT /api/v1/config/external-connections/{slug} */ export const updateApiApiV1ConfigExternalConnectionsSlug = async (args: UpdateApiApiV1ConfigExternalConnectionsSlugArgs, options?: UpdateApiApiV1ConfigExternalConnectionsSlugOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = 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("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/external-connections/${encodeURIComponent(String(args.slug))}${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(configv1UpdateExternalConnectionResponse, await res.json()) };