UNPKG

@kaaiot/services

Version:

Type definitions for KaaIoT platform REST API service communication

541 lines (540 loc) 18 kB
import { PaginatedResponse } from "../epr/EPRClient.types"; export declare enum RuleState { Enabled = "ENABLED", Disabled = "DISABLED" } export interface Rule { id: string; name: string; expression: string; uiMetadata?: string; createdAt: string; updatedAt: string; state?: RuleState; description?: string; statistics?: Statistics; } export interface Statistics { count: number; minDuration: number; maxDuration: number; avgDuration: number; lastDuration: number; } export interface ListItemsResponse<T> { content: T; totalElements: number; } export declare type CreateRulePayload = Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>; export declare enum AttachedRuleActionType { CommandInvocation = "COMMAND_INVOCATION", MetadataUpdate = "METADATA_UPDATE", Webhook = "WEBHOOK", RuleExecution = "RULE_EXECUTION", DataSample = "DATA_SAMPLE", TimeSeries = "TIME_SERIES", AlertActivation = "ALERT_ACTIVATION", AlertResolution = "ALERT_RESOLUTION", SendEmail = "SEND_EMAIL" } export interface RuleAction { id: string; type: AttachedRuleActionType; name: string; } export interface AttachedRuleActionsResponse { positiveActions: RuleAction[]; negativeActions: RuleAction[]; } export interface RuleTrigger { id: string; type: string; name: string; } export interface BaseAction<Metadata = any> { id: string; name: string; description?: string; uiMetadata?: Metadata; statistics?: Statistics; } export interface CommandInvocationAction extends BaseAction<CommandInvocationActionUIMetadata> { commandType: string; endpointIdExpression: string; commandPayloadExpression?: string; } export interface MetadataUpdateAction extends BaseAction<MetadataUpdateActionUIMetadata> { endpointIdExpression: string; metadataKeyExpression: string; metadataValueExpression: string; } export interface WebhookAction extends BaseAction { webhookUrl: string; headersExpression?: string; webhookPayloadExpression?: string; } export interface RuleExecutionAction extends BaseAction { ruleId: string; } export interface DataSampleAction extends BaseAction<DataSampleActionUIMetadata> { endpointIdExpression: string; dataSamplesExpression: string; } export interface TimeSeriesAction extends BaseAction<TimeSeriesActionUIMetadata> { endpointIdExpression: string; timeSeriesNameExpression: string; timeSeriesExpression: string; } export interface AlertActivationUIMetadata { alertTypeSelection?: 'static' | 'script'; alertTypeValue?: string; activateReasonSelection?: string; activateReasonValue?: string; entityIdSelection?: 'current-endpoint' | 'script'; severityLevelSelection?: 'static' | 'script'; severityLevelValue?: AlertSeverityLevel; startedAtSelection?: 'current' | 'script'; lastActiveAtSelection?: 'current' | 'script'; } export interface SendEmailActionUIMetadata { recipientsSelection?: 'static' | 'script'; recipientsValue?: string[]; recipientsExpression?: string; subjectSelection?: 'static' | 'script'; subjectValue?: string; subjectExpression?: string; textSelection?: 'static' | 'script'; textValue?: string; textExpression?: string; } export interface AlertResolutionActionUIMetadata { entityIdSelection?: 'current-endpoint' | 'script'; alertTypeSelection?: 'static' | 'script'; alertTypeValue?: string; resolveReasonSelection?: 'static' | 'script'; resolveReasonValue?: string; } export interface CommandInvocationActionUIMetadata { endpointIdSelection?: 'current-endpoint' | 'script'; } export interface DataSampleActionUIMetadata { endpointIdSelection?: 'current-endpoint' | 'script'; } export interface MetadataUpdateActionUIMetadata { endpointIdSelection?: 'current-endpoint' | 'script'; metadataKeySelection?: 'static' | 'script'; metadataKeyValue?: string; } export interface TimeSeriesActionUIMetadata { endpointIdSelection?: 'current-endpoint' | 'script'; timeSeriesNameSelection?: 'static' | 'script'; timeSeriesNameValue?: string; } export interface AlertActivationAction extends BaseAction<AlertActivationUIMetadata> { alertTypeExpression: string; entityType: string; severityLevelExpression: string; metadataExpression?: string; entityIdExpression: string; activateReasonExpression: string; startedAtExpression?: string; lastActiveAtExpression?: string; } export interface AlertResolutionAction extends BaseAction<AlertResolutionActionUIMetadata> { alertTypeExpression: string; metadataExpression?: string; entityType: string; entityIdExpression: string; resolveReasonExpression: string; } export declare enum SendEmailContentType { Text = "TEXT", HTML = "HTML" } export interface SendEmailAction extends BaseAction { recipientsExpression: string; subjectExpression: string; textExpression: string; contentType?: SendEmailContentType; } export declare type CreateActionPayload<T = Action> = Omit<T, 'id'>; export declare type Action = { updatedAt?: string; createdAt?: string; } & (CommandInvocationAction | MetadataUpdateAction | WebhookAction | RuleExecutionAction | DataSampleAction | TimeSeriesAction | AlertActivationAction | AlertResolutionAction | SendEmailAction); export declare enum ActionType { CommandInvocation = "command-invocation", MetadataUpdate = "metadata-update", Webhook = "webhook", RuleExecution = "rule-execution", DataSample = "data-sample", TimeSeries = "time-series", AlertActivation = "alert-activation", AlertResolution = "alert-resolution", SendEmail = "send-email" } declare type CreateActionKeys<T> = Array<keyof Omit<T, 'id'>>; export interface ActionCreationKeys { [ActionType.CommandInvocation]: CreateActionKeys<CommandInvocationAction & CommandInvocationActionUIMetadata>; [ActionType.MetadataUpdate]: CreateActionKeys<MetadataUpdateAction & MetadataUpdateActionUIMetadata>; [ActionType.RuleExecution]: CreateActionKeys<RuleExecutionAction>; [ActionType.Webhook]: CreateActionKeys<WebhookAction>; [ActionType.DataSample]: CreateActionKeys<DataSampleAction & DataSampleActionUIMetadata>; [ActionType.TimeSeries]: CreateActionKeys<TimeSeriesAction & TimeSeriesActionUIMetadata>; [ActionType.AlertActivation]: CreateActionKeys<AlertActivationAction & AlertActivationUIMetadata>; [ActionType.AlertResolution]: CreateActionKeys<AlertResolutionAction & AlertResolutionActionUIMetadata>; [ActionType.SendEmail]: CreateActionKeys<SendEmailAction & SendEmailActionUIMetadata>; } export declare const actionsCreationKeys: ActionCreationKeys; export declare enum TriggerType { EndpointMetadataUpdated = "endpoint-metadata-updated", EndpointTimeSeriesUpdated = "endpoint-time-series-updated", EndpointDataSamplesReceived = "endpoint-data-samples-received", Cron = "cron", AlertLifecycleEvent = "alert-lifecycle-event", EndpointCommandResultReceivedTrigger = "endpoint-command-result-received", EndpointCommandDispatchedTrigger = "endpoint-command-dispatched" } export declare const TriggerTypeLabels: Record<TriggerType, string>; export declare enum DateSortFields { CreatedAt = "createdAt", UpdatedAt = "updatedAt" } export declare type SortOrder = 'asc' | 'desc'; export declare type QueryParams = FilterParams & PaginationParams; export interface QuerySortParams { sort?: DateSortFields; sortOrder?: SortOrder; } export declare const enum RulesInclude { AttachedToAlertSetting = "ATTACHED_TO_ALERT_SETTING" } export declare type RulesQueryParams = FilterParams & PaginationParams & QuerySortParams & { include?: RulesInclude; actionId?: string; }; export declare type ActionsQueryParams = RulesQueryParams; export declare type TriggersQueryParams = RulesQueryParams; export interface DeleteTracesQueryParams { beforeDate?: string; } export interface DeleteAlertQueryParams { entityId?: string; entityType?: AlertEntityType; } export interface FilterParams { name?: string; description?: string; } export interface PaginationParams { page?: number; size?: number; limit?: number; } export interface EvaluationPayload { expression: string; endpointMetadata?: Record<string, any>; childrenEndpoints?: string[]; } export interface TriggerBody { id: string; name: string; description: string; appName?: string; appVersionName?: string; cron?: string; endpoints?: string[]; createdAt?: string; updatedAt?: string; } interface EndpointTimeseriesUpdatedTriggerBody { appName?: string; appVersionName?: string; endpoints?: string[]; timeSeriesNames?: string[]; } interface BaseTrigger<UIMetadata = any> { name: string; description: string; uiMetadata?: UIMetadata; } export declare type CreateEndpointTimeSeriesUpdatedTriggerPayload = Omit<TriggerBody, 'id' | 'createdAt' | 'updatedAt'> & EndpointTimeseriesUpdatedTriggerBody; export declare type CreateEndpointMetadataUpdatedTriggerPayload = Omit<TriggerBody, 'id' | 'createdAt' | 'updatedAt'>; export interface CronTriggerUIMetadata { cronType?: 'interval' | 'cron'; cronInterval?: number; } export interface AlertLifecycleEventTriggerUIMetadata { alertLifecycleEventTypeValue: string; } export interface CreateAlertLifecycleEventTriggerPayload extends BaseTrigger<AlertLifecycleEventTriggerUIMetadata> { appName?: string; appVersionName?: string; endpointIds?: string[]; metadata: Record<string, string>; } export interface CreateCronTriggerPayload extends BaseTrigger<CronTriggerUIMetadata> { cron: string; appName?: string; appVersionName?: string; endpointIds?: string[]; } export interface CreateEndpointCommandResultReceivedTriggerPayload extends BaseTrigger { commandTypes: string[]; appName?: string; appVersionName?: string; endpointIds?: string[]; metadata?: Record<string, string>; } export declare type CreateEndpointCommandDispatchedTriggerPayload = CreateEndpointCommandResultReceivedTriggerPayload; export declare type CreateTriggerPayload = CreateCronTriggerPayload & CreateEndpointMetadataUpdatedTriggerPayload & CreateEndpointTimeSeriesUpdatedTriggerPayload & CreateAlertLifecycleEventTriggerPayload & CreateEndpointCommandResultReceivedTriggerPayload & CreateEndpointCommandDispatchedTriggerPayload; export interface CreateActionResponse { id: string; } export interface CreateTriggerResponse { id: string; } export interface GetTriggersSearchParams { limit?: number; } export declare type TriggerTypesResponse = ListItemsResponse<TriggerBody[]>; export interface SecretBody { id: string; key: string; value: string; createdAt: string; updatedAt: string; } export declare type SecretsQueryParams = PaginationParams & QuerySortParams & { key?: string; }; export declare type CreateSecretBody = Omit<SecretBody, 'id' | 'createdAt' | 'updatedAt'>; export declare type SecretsResponse = ListItemsResponse<SecretBody[]>; export interface Snippet { id: string; name: string; description?: string; expression: string; createdAt: string; updatedAt: string; } export declare type CreateSnippetBody = Omit<Snippet, 'id' | 'createdAt' | 'updatedAt'>; export declare type SnippetsQueryParams = PaginationParams & QuerySortParams & { name?: string; description?: string; }; export declare type SnippetsResponse = ListItemsResponse<Snippet[]>; export interface AttachActionsPayload { positiveActions: string[]; negativeActions: string[]; } export declare const AttachedToAction: Record<AttachedRuleActionType, ActionType>; export declare enum TraceEntityType { Rule = "RULE", MetadataUpdateAction = "METADATA_UPDATE_ACTION", TimeSeries = "TIME_SERIES_ACTION", AlertActivationAction = "ALERT_ACTIVATION_ACTION", AlertResolutionAction = "ALERT_RESOLUTION_ACTION", CommandInvocationAction = "COMMAND_INVOCATION_ACTION", Webhook = "WEBHOOK_ACTION", SendEmailAction = "SEND_EMAIL_ACTION", DataSample = "DATA_SAMPLE_ACTION", RuleExecution = "RULE_EXECUTION_ACTION" } export declare enum TraceOutcome { Failure = "FAILURE", Success = "SUCCESS" } export declare enum TraceRaisedEntityType { OnDemand = "ON_DEMAND", Endpoint = "ENDPOINT" } export declare const TraceRaisedEntityTypeLabels: { ON_DEMAND: string; ENDPOINT: string; }; export interface TracesRequestOptions { traceId?: string; entityType?: TraceEntityType; entityId?: string; outcome?: TraceOutcome; raisedOnEntityType?: TraceRaisedEntityType; raisedOnEntityId?: string; fromCreatedAt?: string; page?: number; size?: number; include?: 'RELATED'; } export interface StaticTraceItem { traceId: string; entityType: TraceEntityType; entityId: string; outcome: TraceOutcome; createdAt: string; stage?: string; reason?: string; metadata?: Record<string, string>; raisedOnEntityType?: TraceRaisedEntityType; raisedOnEntityId?: string; } export interface AlertHistoryRecord { id: string; alertId: string; eventType: AlertLifecycleEvent; timestamp: string; metadata?: Record<string, string>; systemMetadata?: Record<string, string>; } export declare enum AlertSeverityLevel { Info = "INFO", Low = "LOW", Medium = "MEDIUM", High = "HIGH", Critical = "CRITICAL" } export declare enum AlertState { Active = "ACTIVE", Resolved = "RESOLVED" } export declare enum AlertLifecycleEvent { CREATED = "CREATED", ACTIVE = "ACTIVE", RESOLVED = "RESOLVED", ACKNOWLEDGED = "ACKNOWLEDGED", UNACKNOWLEDGED = "UNACKNOWLEDGED", SEVERITY_LEVEL_INCREASED = "SEVERITY_LEVEL_INCREASED", SEVERITY_LEVEL_DECREASED = "SEVERITY_LEVEL_DECREASED" } export declare enum AlertAcknowledgement { Acknowledged = "ACKNOWLEDGED", Unacknowledged = "UNACKNOWLEDGED" } export declare enum AlertEntityType { Endpoint = "ENDPOINT", Tenant = "TENANT" } export interface Alert { id: string; alertType: string; entityId: string; entityType: AlertEntityType; severityLevel: AlertSeverityLevel; activationMetadata?: string; resolutionMetadata?: string; startedAt: string; state: AlertState; resolveReason: string; activateReason: string; lastActiveAt: string; acknowledgement: AlertAcknowledgement; entityMetadata: string; alertSettingIds: string[]; } export interface UpdateAlertStatusParams { entityId: string; entityType: string; } export interface GetStatusHistoryParams extends UpdateAlertStatusParams { page?: number; size?: number; sortOrder?: SortOrder; sort?: 'timestamp'; eventType?: AlertLifecycleEvent; } export interface UpdateAlertStatusPayload { status: Omit<AlertState, 'UNACKNOWLEDGED'>; transitionReason?: string; } export interface AlertsRequestParams { entityType: AlertEntityType; entityIds?: string; page?: number; size?: number; alertType?: string; state?: AlertState; acknowledgement?: AlertAcknowledgement; severityLevel?: AlertSeverityLevel; sort?: 'lastActiveAt' | 'createdAt'; sortOrder?: SortOrder; entityMetadataPath?: string; entityMetadataValue?: string; } declare type AlertsSearchFilter = { or?: AlertFilterCondition[]; and?: AlertFilterCondition[]; }; export declare enum AlertsFilterOperator { In = "IN", GraterOrEqual = "GT_EQ", LessOrEqual = "LT_EQ" } export declare type AlertFilterCondition = { operator: AlertsFilterOperator; key?: string; values?: string[]; or?: AlertFilterCondition[]; and?: AlertFilterCondition[]; }; export interface AlertsSearchRequestPayload { entityType: AlertEntityType; entityIds?: string[]; sort?: { key: string; direction: SortOrder; }; page?: { page: number; size: number; }; filter?: AlertsSearchFilter; } export declare type AlertsResponse = PaginatedResponse<Alert>; export declare type AlertTypesResponse = string[]; export declare type TraceItem = StaticTraceItem; export declare type TracesResponse = PaginatedResponse<TraceItem>; export declare type AlertHistoryResponse = PaginatedResponse<AlertHistoryRecord>; export declare const isSendEmailAction: (value: any) => value is SendEmailAction; export interface AttachedAlertSettingAction { actionId: string; actionType: AttachedRuleActionType; } export interface AttachedAleertSettingsTrigger { triggerId: string; triggerType: TriggerType; } export declare enum AlertSettingsState { Enabled = "ENABLED", Disabled = "DISABLED" } export interface AlertSettingsItem { id: string; name: string; ruleIds: string[]; actions: AttachedAlertSettingAction[]; triggers: AttachedAleertSettingsTrigger[]; state: AlertSettingsState; createdAt: string; updatedAt: string; description?: string | null; uiMetadata?: string; } export declare type AlertSettingsListResponse = PaginatedResponse<AlertSettingsItem>; export declare type AlertSettingsItemResponse = AlertSettingsItem; export interface AlertSettingsRequestParams { page?: number; size?: number; sort?: 'createdAt' | 'updatedAt'; sortOrder?: SortOrder; name?: string; description?: string; } export declare type CreateAlertSettingsPayload = Omit<AlertSettingsItem, 'id' | 'createdAt' | 'updatedAt'>; export declare type UpdateAlertSettingsPayload = CreateAlertSettingsPayload; export declare const enum AlertMetadataKeyTypes { SystemMetadata = "SYSTEM_METADATA", EntityMetadata = "ENTITY_METADATA", ActivationMetadata = "ACTIVATION_METADATA", ResolutionMetadata = "RESOLUTION_METADATA" } export declare type AlertMetadataKeysResponse = string[]; export {};