import {z} from 'zod' export type DemProbeLocationType = 'REGION' | 'COUNTRY' | 'CITY'; export type DemTestFrom = {type: DemProbeLocationType, values: Array}; export type DemProbePlatform = 'AWS' | 'AZURE' | 'GOOGLE_CLOUD'; export type DemProbePlatformOptions = {probePlatforms: Array, testFromAll?: boolean | undefined}; export type DemFailingTestLocations = 'all' | 'any'; export type DemOutageConfiguration = {failingTestLocations: DemFailingTestLocations, consecutiveForDown: number}; export type DemTransactionTestInterval = number; export type DemWindowSize = {width: number, height: number}; export type DemTransactionCommandName = 'ASSERT_CHECKED' | 'ASSERT_ELEMENT_NOT_PRESENT' | 'ASSERT_ELEMENT_PRESENT' | 'ASSERT_NOT_CHECKED' | 'ASSERT_NOT_SELECTED_VALUE' | 'ASSERT_NOT_TEXT' | 'ASSERT_SELECTED_VALUE' | 'ASSERT_TEXT' | 'ASSERT_VALUE' | 'CHECK' | 'CLICK' | 'CLICK_AT' | 'OPEN' | 'PAUSE' | 'SWO_ASSERT_TEXT_CONTAINS' | 'SWO_ASSERT_TEXT_NOT_CONTAINS' | 'SWO_ASSERT_VALUE_CONTAINS' | 'SWO_ASSERT_VALUE_NOT_CONTAINS' | 'SELECT' | 'SELECT_FRAME' | 'SUBMIT' | 'SWO_ASSERT_URL' | 'SWO_WAIT_FOR_ELEMENT_TEXT_CONTAINS' | 'TYPE' | 'UNCHECK' | 'WAIT_FOR_ELEMENT_PRESENT'; export type DemTransactionCommand = {command: DemTransactionCommandName, target?: string | undefined, displayText?: string | undefined, value?: string | undefined, skipOnFailure?: (boolean | null) | undefined}; export type DemTransactionTestDefinition = {testFrom?: DemTestFrom | undefined, testFromPrivateProbeIds?: Array | undefined, platformOptions?: (DemProbePlatformOptions | null) | undefined, outageConfiguration?: (DemOutageConfiguration | null) | undefined, testIntervalInSeconds: DemTransactionTestInterval, windowSize: DemWindowSize, userAgent?: (string | null) | undefined, commands: Array, advancedDataDisabled?: (boolean | null) | undefined, timeoutInSeconds?: (number | null) | undefined}; export type CommonTag = {key: string, value: string}; export type DemTransaction = {name: string, description?: string | undefined, relatedEntityId?: string | undefined, testDefinition: DemTransactionTestDefinition, tags?: Array | undefined}; export type UpdateApiV1DemTransactionsEntityIdArgs = {entityId: string, body: DemTransaction}; export type UpdateApiV1DemTransactionsEntityIdOptions = {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 transaction monitoring configuration * * PUT /v1/dem/transactions/{entityId} */ export const updateApiV1DemTransactionsEntityId = async (args: UpdateApiV1DemTransactionsEntityIdArgs, options?: UpdateApiV1DemTransactionsEntityIdOptions) => { 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/transactions/${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()) };