/** * Copyright Linkurious SAS 2012 - 2019 * * - Created on 2019-10-01 */ import { GenericObject } from '../api/commonTypes'; import { CustomActionParsingError } from '../api/customAction'; import { ErrorHighlight } from '../api/graphQuery'; import { SearchSyntaxError } from '../api/search'; import { FetchConfig } from './types'; export declare enum LkErrorKey { CONNECTION_REFUSED = "connection_refused", FEATURE_DISABLED = "feature_disabled", UNAUTHORIZED = "unauthorized", DATA_SOURCE_UNAVAILABLE = "dataSource_unavailable", GUEST_DISABLED = "guest_disabled", FORBIDDEN = "forbidden", NOT_FOUND = "not_found", BAD_GRAPH_REQUEST = "bad_graph_request", GRAPH_REQUEST_TIMEOUT = "graph_request_timeout", CONSTRAINT_VIOLATION = "constraint_violation", MALFORMED_CUSTOM_ACTION_TEMPLATE = "malformed_custom_action_template", MALFORMED_QUERY_TEMPLATE = "malformed_query_template", MALFORMED_SEARCH_SYNTAX = "malformed_search_syntax", INVALID_LICENSE = "invalid_license", INVALID_ALERT_QUERY = "invalid_alert_query", INVALID_ALERT_TARGET = "invalid_alert_target", ILLEGAL_SOURCE_STATE = "illegal_source_state", FOLDER_DELETION_FAILED = "folder_deletion_failed", ALREADY_EXISTS = "already_exists", STRICT_SCHEMA_REQUIRED = "strict_schema_required", PROPERTY_KEY_ACCESS_RIGHTS_REQUIRED = "property_key_access_rights_required", INVALID_PROPERTY_KEY_ACCESS_LEVEL = "invalid_property_key_access_level", EDIT_CONFLICT = "edit_conflict", READ_ONLY_RIGHT = "readonly_right", VISUALIZATION_LOCKED = "visualization_locked", NOT_SUPPORTED = "not_supported", SOURCE_ACTION_NEEDED = "source_action_needed", MISSING_SEARCH_ENTITIES = "missing_search_entities", SEARCH_DISABLED = "search_disabled", REDUNDANT_ACTION = "redundant_action", INVALID_PARAMETER = "invalid_parameter", CRITICAL = "critical", BUG = "bug", SOCKET_ERROR = "socket_error", PORT_BUSY = "port_busy", PORT_RESTRICTED = "port_restricted", HTTPS_REQUIRED = "https_required", API_NOT_FOUND = "api_not_found", PLUGIN_NOT_READY = "plugin_not_ready", PLUGIN_SERVICE_NOT_READY = "plugin_service_not_ready", INVALID_CONFIGURATION = "invalid_configuration", EMAIL_FORMAT = "email_format", NOT_IMPLEMENTED = "not_implemented", SEND_MAIL_FAILED = "send_mail_failed", CASES_EXTRACT_LIMIT_EXCEEDED = "cases_extract_limit_exceeded", INVALID_CASE_ATTRIBUTES_QUERY = "invalid_case_attributes_query", SPACE_DELETION_FAILED = "space_deletion_failed", INVALID_PARENT_FOLDER = "invalid_parent_folder", ENTITY_RESOLUTION_EXPIRED_LICENSE = "entity_resolution_expired_license", ENTITY_RESOLUTION_QUOTA_EXCEEDED = "entity_resolution_quota_exceeded", LICENSE_SEATS_LIMIT_EXCEEDED = "license_seats_limit_exceeded", LICENSE_ALERTS_LIMIT_EXCEEDED = "license_alerts_limit_exceeded", WORKER_TIMEOUT = "worker_timeout" } /** * Basic error to be extended by custom errors */ export interface LkError { id?: string; key: K; message: string; } export declare class Response { body: B; status: number; header: GenericObject; constructor(options: { body: B; status?: number; header?: GenericObject; }); isSuccess(): this is Exclude>; /** * The result of the narrowed down type in type guards works this way * type TypeGuard = Assertion extends UnionType ? Assertion : (Assertion & UnionType); * type t1 = TypeGuard | Response, Response>; * `t1` equal to `(Response | Response) & Response` * * 1) However, we want `isError()` to narrow down to `never` instead of the `UnionType & Assertion` * * 2) Why `E` does not extends `PossibleErrorKeys` in the generics? * Because having `key : E` in the parameters makes `E` to be equal to `PossibleErrorKeys` * instead of the actual type we pass * * 3) A ternary operator in a parameter works a second checker of the assignment * In `key` parameter, `E extends PossibleErrorKeys ? E : never` makes TS to check `E` * against `PossibleErrorKeys` and throw a TS error if it's false. * `E extends PossibleErrorKeys ? E : PossibleErrorKeys` makes that when it's false, the TS error mentions * `PossibleErrorKeys` */ isError, E extends LkErrorKey>(this: R, key: E extends PossibleErrorKeys ? E : PossibleErrorKeys): this is E extends PossibleErrorKeys ? Response : never; } /** * Input: * ErrorResponses * Output: * Response | Response */ export type ErrorResponses = T extends unknown ? Response : Response; /** * Input: * Response | Response | Response * Output: * LkErrorKey.ALREADY_EXISTS_ERROR | LkErrorKey.EDIT_CONFLICT_ERROR */ export type PossibleErrorKeys = R extends { body: { key: infer ErrorKeys; }; } ? ErrorKeys : never; /** * Every error can carry some payload */ export interface ConnectionRefusedError extends LkError { fetchConfig: FetchConfig; } export interface FeatureDisabledError extends LkError { } export declare enum UnauthorizedErrorReason { LICENSE_MISSING = "license_missing", LICENSE_EXPIRED = "license_expired", SESSION_EXPIRED = "session_expired", SESSION_EVICTED = "session_evicted", SERVER_FULL = "server_full" } export interface UnauthorizedError extends LkError { reason?: UnauthorizedErrorReason; } export interface DataSourceUnavailableError extends LkError { } export interface GuestDisabledError extends LkError { } export interface ForbiddenError extends LkError { } export interface NotFoundError extends LkError { } export interface BadGraphRequestError extends LkError { highlight?: ErrorHighlight; } export interface GraphRequestTimeoutError extends LkError { } export interface ConstraintViolationError extends LkError { } export interface InvalidLicenseError extends LkError { } export interface InvalidAlertQueryError extends LkError { } export interface InvalidAlertTargetError extends LkError { } export interface MalformedCustomActionTemplateError extends LkError { errors: CustomActionParsingError[]; } export interface MalformedSearchSyntaxError extends LkError { details: SearchSyntaxError; } export interface MalformedQueryTemplateError extends LkError { highlight?: ErrorHighlight; } export interface IllegalSourceStateError extends LkError { } export interface FolderDeletionFailedError extends LkError { } export interface AlreadyExistsError extends LkError { } export interface StrictSchemaRequiredError extends LkError { } export interface PropertyKeyAccessRightsRequiredError extends LkError { } export interface InvalidPropertyKeyAccessLevelError extends LkError { } export interface EditConflictError extends LkError { } export interface ReadOnlyRightError extends LkError { } export interface VisualizationLockedError extends LkError { } export interface NotSupportedError extends LkError { } export interface SourceActionNeededError extends LkError { } export interface MissingSearchEntitiesError extends LkError { } export interface InvalidParameterError extends LkError { } export interface CriticalError extends LkError { } export interface Bug extends LkError { } export interface SocketError extends LkError { } export interface PortBusyError extends LkError { } export interface PortRestrictedError extends LkError { } export interface HttpsRequiredError extends LkError { } export interface ApiNotFoundError extends LkError { } export interface PluginNotReadyError extends LkError { } export interface PluginServiceNotReadyError extends LkError { } export interface InvalidConfigurationError extends LkError { } export interface RedundantActionError extends LkError { } export interface SearchDisabledError extends LkError { } export interface EmailFormatError extends LkError { } export interface NotImplementedError extends LkError { } export interface SendMailFailed extends LkError { } export interface CasesExtractLimitExceeded extends LkError { } export interface InvalidCaseAttributesQuery extends LkError { } export interface SpaceDeletionFailed extends LkError { } export interface InvalidParentFolder extends LkError { } export interface EntityResolutionExpiredLicense extends LkError { } export interface EntityResolutionQuotaExceeded extends LkError { } export interface LicenseSeatsLimitExceeded extends LkError { } export interface AlertQueriesLimitExceeded extends LkError { } export interface WorkerTimeoutError extends LkError { } export type LkErrorKeyToInterface = { [LkErrorKey.CONNECTION_REFUSED]: ConnectionRefusedError; [LkErrorKey.FEATURE_DISABLED]: FeatureDisabledError; [LkErrorKey.UNAUTHORIZED]: UnauthorizedError; [LkErrorKey.DATA_SOURCE_UNAVAILABLE]: DataSourceUnavailableError; [LkErrorKey.GUEST_DISABLED]: GuestDisabledError; [LkErrorKey.FORBIDDEN]: ForbiddenError; [LkErrorKey.NOT_FOUND]: NotFoundError; [LkErrorKey.BAD_GRAPH_REQUEST]: BadGraphRequestError; [LkErrorKey.GRAPH_REQUEST_TIMEOUT]: GraphRequestTimeoutError; [LkErrorKey.CONSTRAINT_VIOLATION]: ConstraintViolationError; [LkErrorKey.INVALID_LICENSE]: InvalidLicenseError; [LkErrorKey.INVALID_ALERT_QUERY]: InvalidAlertQueryError; [LkErrorKey.INVALID_ALERT_TARGET]: InvalidAlertTargetError; [LkErrorKey.MALFORMED_CUSTOM_ACTION_TEMPLATE]: MalformedCustomActionTemplateError; [LkErrorKey.MALFORMED_QUERY_TEMPLATE]: MalformedQueryTemplateError; [LkErrorKey.MALFORMED_SEARCH_SYNTAX]: MalformedSearchSyntaxError; [LkErrorKey.ILLEGAL_SOURCE_STATE]: IllegalSourceStateError; [LkErrorKey.FOLDER_DELETION_FAILED]: FolderDeletionFailedError; [LkErrorKey.ALREADY_EXISTS]: AlreadyExistsError; [LkErrorKey.STRICT_SCHEMA_REQUIRED]: StrictSchemaRequiredError; [LkErrorKey.PROPERTY_KEY_ACCESS_RIGHTS_REQUIRED]: PropertyKeyAccessRightsRequiredError; [LkErrorKey.INVALID_PROPERTY_KEY_ACCESS_LEVEL]: InvalidPropertyKeyAccessLevelError; [LkErrorKey.EDIT_CONFLICT]: EditConflictError; [LkErrorKey.READ_ONLY_RIGHT]: ReadOnlyRightError; [LkErrorKey.VISUALIZATION_LOCKED]: VisualizationLockedError; [LkErrorKey.NOT_SUPPORTED]: NotSupportedError; [LkErrorKey.SOURCE_ACTION_NEEDED]: SourceActionNeededError; [LkErrorKey.MISSING_SEARCH_ENTITIES]: MissingSearchEntitiesError; [LkErrorKey.INVALID_PARAMETER]: InvalidParameterError; [LkErrorKey.CRITICAL]: CriticalError; [LkErrorKey.BUG]: Bug; [LkErrorKey.SOCKET_ERROR]: SocketError; [LkErrorKey.PORT_BUSY]: PortBusyError; [LkErrorKey.PORT_RESTRICTED]: PortRestrictedError; [LkErrorKey.HTTPS_REQUIRED]: HttpsRequiredError; [LkErrorKey.API_NOT_FOUND]: ApiNotFoundError; [LkErrorKey.PLUGIN_NOT_READY]: PluginNotReadyError; [LkErrorKey.PLUGIN_SERVICE_NOT_READY]: PluginServiceNotReadyError; [LkErrorKey.INVALID_CONFIGURATION]: InvalidConfigurationError; [LkErrorKey.SEARCH_DISABLED]: SearchDisabledError; [LkErrorKey.REDUNDANT_ACTION]: RedundantActionError; [LkErrorKey.EMAIL_FORMAT]: EmailFormatError; [LkErrorKey.NOT_IMPLEMENTED]: NotImplementedError; [LkErrorKey.SEND_MAIL_FAILED]: SendMailFailed; [LkErrorKey.CASES_EXTRACT_LIMIT_EXCEEDED]: CasesExtractLimitExceeded; [LkErrorKey.INVALID_CASE_ATTRIBUTES_QUERY]: InvalidCaseAttributesQuery; [LkErrorKey.SPACE_DELETION_FAILED]: SpaceDeletionFailed; [LkErrorKey.INVALID_PARENT_FOLDER]: InvalidParentFolder; [LkErrorKey.ENTITY_RESOLUTION_EXPIRED_LICENSE]: EntityResolutionExpiredLicense; [LkErrorKey.ENTITY_RESOLUTION_QUOTA_EXCEEDED]: EntityResolutionQuotaExceeded; [LkErrorKey.LICENSE_SEATS_LIMIT_EXCEEDED]: LicenseSeatsLimitExceeded; [LkErrorKey.LICENSE_ALERTS_LIMIT_EXCEEDED]: AlertQueriesLimitExceeded; [LkErrorKey.WORKER_TIMEOUT]: WorkerTimeoutError; };