import {z} from 'zod' export type OIBusSouthType = 'opcua' | 'mqtt' | 'modbus' | 'oianalytics' | 'ads' | 'bacnet' | 'folder-scanner' | 'ftp' | 'influxdb' | 'mongodb' | 'mssql' | 'mysql' | 'odbc' | 'oledb' | 'opc' | 'oracle' | 'osisoft-pi' | 'postgresql' | 'rest' | 's7' | 'sftp' | 'sqlite'; export type SouthADSSettingsEnumAsText = 'text' | 'integer'; export type SouthADSSettingsBoolAsText = 'text' | 'integer'; export type SouthADSSettingsStructureFiltering = {name: string, fields: string}; export type SouthADSSettings = {netId: string, port: number, routerAddress: string | null, routerTcpPort: number | null, clientAmsNetId: string | null, clientAdsPort: number | null, retryInterval: number, plcName: string | null, enumAsText: SouthADSSettingsEnumAsText, boolAsText: SouthADSSettingsBoolAsText, structureFiltering: Array | null}; export type SouthBACnetSettingsDiscoveryMode = 'broadcast' | 'target-device' | 'router'; export type SouthBACnetSettingsBbmd = {enabled: boolean, address?: string | undefined, foreignDeviceTtl?: number | undefined}; export type SouthBACnetSettings = {port: number, apduTimeout: number, retryInterval: number, discoveryMode: SouthBACnetSettingsDiscoveryMode, discoveryTargetAddress?: string | undefined, discoveryTargetDeviceInstance?: number | undefined, discoveryRouterAddress?: string | undefined, broadcastAddress?: string | undefined, localInterface: string | null, maxParallelRun: number, maxObjectsPerRequest: number, covDefaultLifetime: number, covRenewalMargin: number, maxNumberOfMessages: number, flushMessageTimeout: number, bbmd: SouthBACnetSettingsBbmd}; export type SouthFolderScannerSettings = {inputFolder: string, username?: (string | null) | undefined, password?: (string | null) | undefined, domain?: (string | null) | undefined}; export type SouthFTPSettingsAuthentication = 'none' | 'password'; export type SouthFTPSettings = {host: string, port: number, authentication: SouthFTPSettingsAuthentication, username?: (string | null) | undefined, password?: (string | null) | undefined, retryInterval: number}; export type SouthInfluxDBSettingsConnectionSettingsVersion = '1' | '2' | '3'; export type SouthInfluxDBSettingsConnectionSettingsProtocol = 'http' | 'https'; export type SouthInfluxDBSettingsConnectionSettings = {version: SouthInfluxDBSettingsConnectionSettingsVersion, host?: string | undefined, port?: number | undefined, protocol?: SouthInfluxDBSettingsConnectionSettingsProtocol | undefined, database?: string | undefined, username?: (string | null) | undefined, password?: (string | null) | undefined, url?: string | undefined, token?: (string | null) | undefined, organisation?: string | undefined, bucket?: string | undefined}; export type SouthInfluxDBSettings = {connectionSettings: SouthInfluxDBSettingsConnectionSettings, maxParallelRun: number}; export type SouthModbusSettingsAddressOffset = 'modbus' | 'jbus'; export type SouthModbusSettingsEndianness = 'big-endian' | 'little-endian'; export type SouthModbusSettings = {host: string, port: number, connectTimeout: number, networkTimeout: number, retryInterval: number, slaveId: number, addressOffset: SouthModbusSettingsAddressOffset, endianness: SouthModbusSettingsEndianness, swapBytesInWords: boolean, swapWordsInDWords: boolean, batchQuery: boolean, groupingGap?: number | undefined}; export type SouthMongoDBSettings = {connectionString: string, connectionTimeout: number, username: string | null, password: string | null}; export type SouthMQTTSettingsQos = '0' | '1' | '2'; export type SouthMQTTSettingsAuthenticationType = 'none' | 'basic' | 'cert'; export type SouthMQTTSettingsAuthentication = {type: SouthMQTTSettingsAuthenticationType, username?: string | undefined, password?: (string | null) | undefined, certFilePath?: string | undefined, keyFilePath?: string | undefined, caFilePath?: string | undefined}; export type SouthMQTTSettings = {url: string, qos: SouthMQTTSettingsQos, persistent?: boolean | undefined, authentication: SouthMQTTSettingsAuthentication, rejectUnauthorized: boolean, reconnectPeriod: number, connectTimeout: number, maxNumberOfMessages: number, flushMessageTimeout: number}; export type SouthMSSQLSettingsConnectionSettings = {host: string, port: number, connectionTimeout: number, database: string, encryption: boolean, trustServerCertificate: boolean, username: string | null, password: string | null, domain: string | null, idleTimeout: number}; export type SouthMSSQLSettings = {connectionSettings: SouthMSSQLSettingsConnectionSettings, maxParallelRun: number}; export type SouthMySQLSettingsConnectionSettings = {host: string, port: number, connectionTimeout: number, database: string, username: string | null, password: string | null, idleTimeout: number}; export type SouthMySQLSettings = {connectionSettings: SouthMySQLSettingsConnectionSettings, maxParallelRun: number}; export type SouthODBCSettings = {connectionTimeout: number, connectionString: string, password: string | null, maxParallelRun: number}; export type SouthOIAnalyticsSettingsSpecificSettingsAuthentication = 'basic' | 'aad-client-secret' | 'aad-certificate'; export type SouthOIAnalyticsSettingsSpecificSettings = {host: string, acceptUnauthorized: boolean, authentication: SouthOIAnalyticsSettingsSpecificSettingsAuthentication, accessKey?: string | undefined, secretKey?: (string | null) | undefined, tenantId?: string | undefined, clientId?: string | undefined, clientSecret?: (string | null) | undefined, certificateId?: string | undefined, scope?: string | undefined, useProxy: boolean, proxyUrl?: string | undefined, proxyUsername?: string | undefined, proxyPassword?: (string | null) | undefined}; export type SouthOIAnalyticsSettings = {useOiaModule: boolean, timeout: number, specificSettings?: (SouthOIAnalyticsSettingsSpecificSettings | null) | undefined}; export type SouthOLEDBSettings = {connectionTimeout: number, retryInterval: number, requestTimeout: number, connectionString: string, password: string | null, maxParallelRun: number}; export type SouthOPCSettingsMode = 'hda' | 'da'; export type SouthOPCSettings = {retryInterval: number, host: string, serverName: string, mode: SouthOPCSettingsMode}; export type SouthOPCUASettingsSecurityMode = 'none' | 'sign' | 'sign-and-encrypt'; export type SouthOPCUASettingsSecurityPolicy = 'none' | 'basic128' | 'basic192' | 'basic256' | 'basic128-rsa15' | 'basic192-rsa15' | 'basic256-rsa15' | 'basic256-sha256' | 'aes128-sha256-rsa-oaep' | 'pub-sub-aes-128-ctr' | 'pub-sub-aes-256-ctr'; export type SouthOPCUASettingsAuthenticationType = 'none' | 'basic' | 'cert'; export type SouthOPCUASettingsAuthentication = {type: SouthOPCUASettingsAuthenticationType, username?: string | undefined, password?: (string | null) | undefined, certFilePath?: string | undefined, keyFilePath?: string | undefined}; export type SouthOPCUASettingsSubscription = {publishingInterval: number, maxKeepAliveCount: number, numberOfMessageBeforeFlush: number, delayBetweenFlush: number}; export type SouthOPCUASettings = {url: string, keepSessionAlive: boolean, connectionTimeout: number, retryInterval: number, securityMode: SouthOPCUASettingsSecurityMode, securityPolicy?: SouthOPCUASettingsSecurityPolicy | undefined, maxParallelRun: number, readTimeout: number, authentication: SouthOPCUASettingsAuthentication, subscription: SouthOPCUASettingsSubscription}; export type SouthOracleSettingsConnectionSettings = {thickMode: boolean, oracleClient?: string | undefined, host: string, port: number, connectionTimeout: number, database: string, username: string | null, password: string | null, idleTimeout: number}; export type SouthOracleSettings = {connectionSettings: SouthOracleSettingsConnectionSettings, maxParallelRun: number}; export type SouthPISettings = {serverName: string | null, retryInterval: number}; export type SouthPostgreSQLSettingsConnectionSettings = {host: string, port: number, sslMode: boolean, database: string, connectionTimeout: number, username: string | null, password: string | null, idleTimeout: number}; export type SouthPostgreSQLSettings = {connectionSettings: SouthPostgreSQLSettingsConnectionSettings, maxParallelRun: number}; export type SouthRestSettingsAuthenticationType = 'none' | 'basic' | 'bearer' | 'api-key'; export type SouthRestSettingsAuthenticationAddTo = 'header' | 'query-params'; export type SouthRestSettingsAuthentication = {type: SouthRestSettingsAuthenticationType, username?: string | undefined, password?: (string | null) | undefined, token?: (string | null) | undefined, apiKey?: string | undefined, apiValue?: (string | null) | undefined, addTo?: SouthRestSettingsAuthenticationAddTo | undefined}; export type SouthRestSettingsProxy = {useProxy: boolean, proxyUrl?: string | undefined, proxyUsername?: (string | null) | undefined, proxyPassword?: (string | null) | undefined}; export type SouthRestSettingsTestMethod = 'GET' | 'POST' | 'PUT'; export type SouthRestSettingsTest = {method: SouthRestSettingsTestMethod, endpoint: string, successCode: number, body?: (string | null) | undefined}; export type SouthRestSettings = {host: string, acceptUnauthorized: boolean, timeout: number, authentication: SouthRestSettingsAuthentication, proxy: SouthRestSettingsProxy, test: SouthRestSettingsTest}; export type SouthS7SettingsConnectionType = 'PG' | 'OP' | 'S7Basic'; export type SouthS7Settings = {host: string, port: number, connectionType: SouthS7SettingsConnectionType, rack: number, slot: number, connectTimeout: number, requestTimeout: number, retryInterval: number}; export type SouthSFTPSettingsAuthentication = 'password' | 'private-key'; export type SouthSFTPSettings = {host: string, port: number, authentication: SouthSFTPSettingsAuthentication, username: string, password?: (string | null) | undefined, privateKey?: string | undefined, passphrase?: (string | null) | undefined, retryInterval: number}; export type SouthSQLiteSettings = {databasePath: string}; export type SouthSettings = SouthADSSettings | SouthBACnetSettings | SouthFolderScannerSettings | SouthFTPSettings | SouthInfluxDBSettings | SouthModbusSettings | SouthMongoDBSettings | SouthMQTTSettings | SouthMSSQLSettings | SouthMySQLSettings | SouthODBCSettings | SouthOIAnalyticsSettings | SouthOLEDBSettings | SouthOPCSettings | SouthOPCUASettings | SouthOracleSettings | SouthPISettings | SouthPostgreSQLSettings | SouthRestSettings | SouthS7Settings | SouthSFTPSettings | SouthSQLiteSettings; export type CreateApiApiHistoryHistoryIdExploreArgs = {historyId: string, southType: OIBusSouthType, fromSouth: string, body: SouthSettings}; export type CreateApiApiHistoryHistoryIdExploreOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const recordStringStringOrNumber = z.record(z.string(), z.union([z.string(), z.number()])); export const southConnectorExploreFieldKind = z.enum(["instant", "size"]); export const partialRecordStringSouthConnectorExploreFieldKind = z.record(z.string(), southConnectorExploreFieldKind); export const southConnectorExploreEntry = z.object({id: z.string(), name: z.string(), metadata: recordStringStringOrNumber, metadataKinds: partialRecordStringSouthConnectorExploreFieldKind.optional(), hasChildren: z.boolean()}); export const southExploreStartResult = z.object({sessionId: z.string(), entries: z.array(southConnectorExploreEntry)}); 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 }; /** * Start south explore session * * POST /api/history/{historyId}/explore */ export const createApiApiHistoryHistoryIdExplore = async (args: CreateApiApiHistoryHistoryIdExploreArgs, options?: CreateApiApiHistoryHistoryIdExploreOptions) => { const {baseUrl = "http://localhost:2223", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.southType != null) query.append("southType", String(args.southType)) if (args.fromSouth != null) query.append("fromSouth", String(args.fromSouth)) const url = `${baseUrl.replace(/\/+$/, '')}/api/history/${encodeURIComponent(String(args.historyId))}/explore${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(southExploreStartResult, await res.json()) };