import {z} from 'zod' export type DemProbePlatform = 'AWS' | 'AZURE' | 'GOOGLE_CLOUD'; export type DemProbePlatformOptions = {probePlatforms: Array, testFromAll?: boolean | undefined}; export type DemProbeLocationType = 'REGION' | 'COUNTRY' | 'CITY'; export type DemTestFrom = {type: DemProbeLocationType, values: Array}; export type DemSyntheticTestInterval = number; export type DemFailingTestLocations = 'all' | 'any'; export type DemOutageConfiguration = {failingTestLocations: DemFailingTestLocations, consecutiveForDown: number}; export type DemCheckForStringOperator = 'CONTAINS' | 'DOES_NOT_CONTAIN'; export type DemCheckForString = {operator: DemCheckForStringOperator, value: string}; export type DemWebsiteProtocol = 'HTTP' | 'HTTPS'; export type DemSslMonitoring = {enabled?: (boolean | null) | undefined, daysPriorToExpiration?: (number | null) | undefined, ignoreIntermediateCertificates?: (boolean | null) | undefined}; export type DemCustomHeaders = {name: string, value: string}; export type DemBasicAuthentication = {username: string, credentialId?: (string | null) | undefined}; export type DemAvailabilityCheckSettings = {platformOptions?: (DemProbePlatformOptions | null) | undefined, testFrom?: DemTestFrom | undefined, testFromPrivateProbeIds?: Array | undefined, testIntervalInSeconds: DemSyntheticTestInterval, outageConfiguration?: (DemOutageConfiguration | null) | undefined, checkForString?: (DemCheckForString | null) | undefined, protocols: Array, ssl?: (DemSslMonitoring | null) | undefined, customHeaders?: (Array | null) | undefined, allowInsecureRenegotiation?: boolean | undefined, postData?: (string | null) | undefined, authentication?: (DemBasicAuthentication | null) | undefined}; export type CommonTag = {key: string, value: string}; export type DemWebsite = {name: string, url: string, availabilityCheckSettings?: (DemAvailabilityCheckSettings | null) | undefined, tags?: Array | undefined, rum?: ({apdexTimeInSeconds?: number | undefined, spa: boolean}) | undefined}; export type UpdateApiV1DemWebsitesEntityIdArgs = {entityId: string, body: DemWebsite}; export type UpdateApiV1DemWebsitesEntityIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const commonEntityId = z.object({id: z.string()}); 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 website monitoring configuration * * PUT /v1/dem/websites/{entityId} */ export const updateApiV1DemWebsitesEntityId = async (args: UpdateApiV1DemWebsitesEntityIdArgs, options?: UpdateApiV1DemWebsitesEntityIdOptions) => { const {baseUrl = "https://api.na-01.cloud.solarwinds.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dem/websites/${encodeURIComponent(String(args.entityId))}${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(commonEntityId, await res.json()) };