// Data import { Response, HeaderInit } from 'node-fetch'; import { w3cwebsocket } from 'websocket'; export namespace OGIT { export interface SafeNode { 'ogit/_id': string; 'ogit/_type': string; 'ogit/_modified-on': number; 'ogit/_modified-by': string; 'ogit/_creator': string; 'ogit/_created-on': number; 'ogit/_is-deleted': boolean; 'ogit/_graphtype': string; 'ogit/_xid': string; } export interface Node extends SafeNode { [key: string]: string | number | boolean; } export interface Issue extends SafeNode { 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/subject'?: string; 'ogit/status'?: string; 'ogit/Automation/processingNode'?: string; 'ogit/Automation/originNode'?: string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; } export interface Session extends SafeNode { 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/title'?: string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; '/teaching_issue_subject'?: string; '/teaching_is_handedover'?: string; '/teaching_step_progress'?: string; '/teaching_ki_progress'?: string; '/teaching_ownerId'?: string; '/teaching_conversion_ownerId'?: string; '/teaching_rooms'?: string; '/teaching_rooms_completed'?: string; '/teaching_steps'?: string; '/teaching_steps_deployed'?: string; 'ogit/Knowledge/archived'?: string; } export interface KnowledgeItem extends SafeNode { 'ogit/Automation/knowledgeItemFormalRepresentation': string; 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/description'?: string; 'ogit/isValid'?: string; 'ogit/name'?: string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; 'ogit/_tags'?: string; } export interface Tag extends SafeNode { '/slug': string; 'ogit/name': string; 'ogit/color': string; } export interface KnowledgePool extends SafeNode { 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/name'?: string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; } export interface Account extends SafeNode { 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/name': string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; 'ogit/status'?: string; 'ogit/email': string; 'ogit/Auth/Account/allowCookies'?: boolean; } export interface AccountProfile extends SafeNode { 'ogit/_creator-app'?: string; 'ogit/_modified-by-app'?: string; 'ogit/_owner'?: string; 'ogit/_v'?: number; 'ogit/_v-id'?: string; 'ogit/_organization'?: string; 'ogit/_scope'?: string; 'ogit/Auth/Account/acceptedEmails'?: string; // timestamp 'ogit/Auth/Account/displayName'?: string; 'ogit/firstName'?: string; 'ogit/lastName'?: string; '/jobRole'?: string; '/profileSet'?: string; } export interface Edge extends SafeNode { 'ogit/_edge-id': string; 'ogit/_in-type': string; 'ogit/_out-id': string; 'ogit/_out-type': string; 'ogit/_in-id': string; } export interface Application extends SafeNode { 'ogit/name': string; 'ogit/description': string; 'ogit/Auth/vertexRule': string; 'ogit/Auth/edgeRule': string; } export interface Role extends SafeNode { 'ogit/name': string; 'ogit/description'?: string; 'ogit/Auth/vertexRule': string; 'ogit/Auth/edgeRule': string; } export interface Team extends SafeNode { 'ogit/name': string; 'ogit/description'?: string; } export interface DataScope extends SafeNode { 'ogit/name': string; 'ogit/description'?: string; 'ogit/licenseSubject'?: string; } } export interface AccountWithProfile { account: OGIT.Account; avatar: string; profile: OGIT.AccountProfile; } export interface NodeHistory { action: string; identity: string; data: T; meta: { id: string; nanotime: number; timestamp: number; version: number; vid: string; }; } // HttpTransport interface RequestParams { type: string; headers?: object; body?: object; } interface EmitMessage { name: string; data?: any; } interface Subscriber { next?: (value?: T) => void; error?: (err?: any) => void; complete?: () => void; } interface DefaultFetchOptions { mode: string; method: string; headers: HeaderInit; } interface ReqOptions { waitForIndex?: boolean; headers?: object; token?: string; emit?: (message: EmitMessage) => void; sub?: Subscriber; } type RequestInit = import('node-fetch').RequestInit & { raw?: boolean }; declare class HttpTransport { endpoint: string; constructor(endpoint: string); fetch( token: string, url: string, init?: RequestInit, reqOptions?: ReqOptions, ): Promise; request( token: string, params?: RequestParams, reqOptions?: ReqOptions, ): Promise; defaultFetchOptions(): DefaultFetchOptions; } // WebSocketTransport type EmitHandler = (message: EmitMessage) => void; declare class WebSocketTransport { endpoint: string; useLegacyProtocol: boolean; constructor(endpoint: string); request( token: string, params?: RequestParams, reqOptions?: object, ): Promise; connect(token: string, emit: EmitHandler): Promise; createWebSocket( initialToken: string, emit: EmitHandler, ): Promise; defaultFetchOptions(): { method: 'GET'; headers: { 'Content-Type': 'application/json'; Accept: 'application/json'; }; mode: 'cors'; }; } // EventStream interface EventStreamOptions { groupId?: number; offset?: number; filters?: string[]; scopeId?: string | string[]; } export type ActionType = | 'CREATE' | 'READ' | 'UPDATE' | 'DELETE' | 'WRITETIMESERIES'; export declare interface HiroEvent { id: string; identity: string; type: ActionType; timestamp: number; nanotime: number; body: T; } type EventUnsubscribe = () => void; type EventHandler = (event: HiroEvent) => void; export declare class EventStream { constructor( clientParams: ClientParams, options?: EventStreamOptions & { filters?: string[] }, emit?: (message: EmitMessage) => void, ); subscribe: (handler: EventHandler) => EventUnsubscribe; register: (filter: string) => void; unregister: (filter: string) => void; } // Timeseries export namespace TimeSeries { export interface Value { Entries: Entry[]; Type: 'start' | 'execute' | 'move' | 'finish' | 'consider'; Alternatives?: Alternatives; Changes?: Change[]; ContextHash?: string; Count?: number; Fingerprints?: Fingerprints; IssueVersion?: string; KIID?: string; KIVersion?: string; NodeID?: string; NodeVersion?: string; Stats?: Stats; [index: string]: any; } export interface Alternatives { [index: string]: string; } export interface ChangeValue { created: number; created_on: string; implicit: boolean; key: string; value: any; } export type ChangeVariables = { [key in VariableNames]: ChangeValue; }; export interface ChangeMeta { Action: 'add' | 'delete'; NodeID: string; } export type Change = ChangeMeta & ChangeVariables; export interface Entry { LogLevel: string; Message: string; Command?: string; TimeStamp?: number; } export interface Fingerprints { [index: string]: string; } export interface Stats { backoffs?: number; bind_node?: number; commit_time?: number; ctxs?: number; exec_time?: number; kis?: number; match_time?: number; overall?: number; route_time?: number; routed?: number; } } export interface TimeseriesObject { timestamp: number; value: TimeSeries.Value; } export interface TimeseriesResponse { timestamp: number; value: string; } export interface TimeseriesValue { timestamp: number; value: PlainObject | number | string | Array; } // Servlets interface PlainObject { [key: string]: any; } export type LegacyServletFunction = ( // TODO: fix fetch type fetch: any, options: PlainObject, ...args: any[] ) => any; export interface LegacyServletDefinition { [key: string]: LegacyServletFunction; } export type ServletFactory = () => PlainObject; export type ServletMethods = LegacyServletDefinition | ServletFactory; export interface AppsServlet { getAll(): Promise; getMy(): Promise; install(id: string): Promise; uninstall(id: string): Promise; } interface KiValidateOptions { ki: string; [key: string]: any; } interface KiValidationResponse { valid: boolean; response: | string | { code: number; status: string; error?: string; formatted?: string; variables?: { ISSUE: string[]; NODE: string[]; }; errors?: { line: number; message: string }[]; }; } export interface KiServlet { validate(options: KiValidateOptions): Promise; } export interface KnowledgeServlet { pools(scopeId: string): Promise; kis(scopeId: string): Promise; search(scopeId: string, searchTerms: string[]): Promise; poolsDeployed(scopeId: string): Promise; kisDeployed(scopeId: string): Promise; poolDeployed(scopeId: string, poolId: string): Promise; kiDeployed(scopeId: string, kiId: string): Promise; kiDeployedStatuses(scopeId: string, kiId: string): Promise; deployPool(scopeId: string, poolId: string): Promise; undeployPool(scopeId: string, poolId: string): Promise; newPool(scopeId: string, data: PlainObject): Promise; newKi(scopeId: string, data: PlainObject): Promise; pool(poolId: string): Promise; deletePool(poolId: string): Promise; poolKis(poolId: string): Promise; poolKiDeployed(poolId: string, kiId: string): Promise; deployKi(poolId: string, kiId: string): Promise; undeployKi(poolId: string, kiId: string): Promise; ki(kiId: string): Promise; kiHistory(kiId: string): Promise; kiHistoryVersion(kiId: string, version: string): Promise; updateKi(kiId: string, data: PlainObject): Promise; deleteKi(kiId: string): Promise; kiDeployments(kiId: string): Promise; } interface DefineVariableOptions { name: string; [key: string]: any; } interface SuggestVariableOptions extends PlainObject { name: string; full?: boolean; } export interface VariablesServlet { // TODO: define Variable interface add(data: any): Promise; suggest(data: SuggestVariableOptions): Promise; define(options: DefineVariableOptions): Promise; } export type ActionLogType = | 'SearchKI' | 'SearchTask' | 'SearchTeachingSession' | 'DeployKI' | 'UndeployKI' | 'WriteKI' | 'ForkKI' | 'OpenTeachingSession' | 'OwnTeachingSession' | 'StartTeachingSession' | 'ContinueTeachingSession' | 'StartConversionSession' | 'ContinueConversionSession' | 'AssignKI' | 'ArchiveTeachingSession' | 'RestoreTeachingSession'; export type ActionLogDesktopApp = 'iv' | 'kim' | 'atq' | 'hd' | 'kat'; export interface BaseEvent { action: ActionLogType; instanceId: string; meta: T; } export interface BaseEventMeta { desktopApp: ActionLogDesktopApp; } export interface SearchEventMeta extends BaseEventMeta { searchString: string; } export interface KIEventMeta extends BaseEventMeta { kiId: string; kiName: string; } export interface TeachingSessionEventMeta extends BaseEventMeta { sessionId: string; sessionName: string; taskId: string; desktopRole: string; } export interface DeployKIEventMeta extends KIEventMeta { knowledgePoolId: string; knowledgePoolName: string; } export interface OwnTeachingSessionEventMeta extends TeachingSessionEventMeta { prevOwnerId: string; } export type ActionLogMeta = | SearchEventMeta | KIEventMeta | TeachingSessionEventMeta | DeployKIEventMeta | OwnTeachingSessionEventMeta; export type ActionLogEvent = BaseEvent; export interface BaseQueryOptions { limit?: number; offset?: number; order?: 'asc' | 'desc'; } export interface BaseFilterOptions { appId?: string; ipAddress?: string; instanceId?: string; from?: number; to?: number; limit?: number; order?: 'asc' | 'desc'; } export type OrganizationEventsResponse = { accountId: string; action: ActionLogType; appId: string; instanceId: string; ipAddress: string; orgId: string; } & T; export type OrganizationQueryOptions = BaseQueryOptions & BaseFilterOptions & { accountId?: string; }; export type AccountQueryOptions = BaseQueryOptions & BaseFilterOptions; export interface ActionLogServlet { logEvent( event: ActionLogEvent, ): Promise; getOrganizationEvents( orgId: string, queryOptions?: OrganizationQueryOptions, ): Promise>; } export interface ApiServlet { getMeProfile(): Promise; updateMeProfile(data: PlainObject): Promise; getMeAvatar(): Promise; meAccount(): Promise; mePassword(oldPassword: string, newPassword: string): Promise; meTeams(): Promise; updateMeAvatar(): Promise; } export interface AuthServlet { getAvatar(id: string): Promise; getOrgAvatar(id: string): Promise; getAccount(id: string): Promise; getAccountProfile(id: string): Promise; getAccountProfileByAccountId(accountId: string): Promise; getTeam(id: string): Promise; getTeamMembers(id: string): Promise; getOrganizationMembers(id: string): Promise; organizationTeams(id: string, virtual?: boolean): Promise; accountTeams(id: string): Promise; organizationDomains(id: string): Promise; organizationRoleAssignments(id: string): Promise; getDomainOrganization(id: string): Promise; getDataScope(id: string): Promise; organizationScopes(id: string): Promise; organizationDataSets(id: string): Promise; listAllRoles(): Promise; listRoles(offset: number, limit: number, name: string): Promise; revoke(clientId: string): Promise; } export declare const appsServletFactory: () => AppsServlet; export declare const kiServletFactory: () => KiServlet; export declare const knowledgeServletFactory: () => KnowledgeServlet; export declare const variablesServletFactory: () => VariablesServlet; export declare const actionLogServletFactory: () => ActionLogServlet; // Client export class Token { constructor({ onInvalidate, getMeta, getToken, }: { onInvalidate?: () => void; getMeta?: () => object; getToken: () => Promise; }); get: () => Promise; updateToken: ({ getToken }: { getToken: () => Promise }) => void; } interface ClientParams { endpoint: string; token: string | Token; } interface BaseOptions { offset?: number; limit?: number; } interface Event { name: string; data: any; } type IntrospectFunction = (data: Event) => void; export default class Client { endpoint: string; token: Token; http: HttpTransport; transport: WebSocketTransport | HttpTransport; // added in constructor auth: AuthServlet; api: ApiServlet; variable?: VariablesServlet; ki?: KiServlet; knowledge?: KnowledgeServlet; actionLog?: ActionLogServlet; constructor( params: ClientParams, transportOptions?: object, proxies?: string[], ); private _pubsub: { subscribe: (emit: EmitHandler) => void; }; setToken(token: string | Token): void; eventStream(filters?: string[], options?: EventStreamOptions): EventStream; getToken(): T; me(): Promise; introspect(fn: IntrospectFunction): void; fetch: ( url: string, init?: RequestInit, reqOptions?: ReqOptions, ) => Promise; gremlin: ( root: string, query: string, reqOptions?: ReqOptions, ) => Promise; connect: ( type: string, inId: string, outId: string, reqOptions?: ReqOptions, ) => Promise; disconnect: ( type: string, inId: string, outId: string, reqOptions?: ReqOptions, ) => Promise; lucene: ( query: string, options?: BaseOptions & { order?: string; fields?: string[]; count?: boolean; [index: string]: any; }, reqOptions?: ReqOptions, ) => Promise; streamts: ( timeseriesId: string, options?: { from?: number; to?: number; limit?: number; includeDeleted?: boolean; with?: string[]; order?: 'asc' | 'desc'; }, ) => Promise; history: ( id: string, options?: { offset?: number; limit?: number; from?: number; to?: number; version?: number; type?: string; listMeta?: boolean; includeDeleted?: boolean; vid?: string; }, ) => Promise; // timeseries value type is based on client.js implementation and usage in hiro-desktop-utils writets: ( timeseriesId: string, value: TimeseriesValue | TimeseriesValue[], ) => Promise; addServlet( prefix: string, servletMethods: ServletMethods, proxy?: string, ): Client; getServlet(prefix: string): T; create( type: string, data: any, reqOptions: ReqOptions, ): Promise; update( id: string, data: any, reqOptions: ReqOptions, ): Promise; delete( id: string, reqOptions: ReqOptions, ): Promise; get( id: string, opts?: { listMeta?: boolean; includeDeleted?: boolean }, ): Promise; ids( ids: Array, opts?: { listMeta?: boolean; includeDeleted?: boolean }, ): Promise>; } /** Lucene */ type LuceneOptions = '$not' | '$or' | '$must' | '$and' | '$missing' | T; type LucenseBase = { [K in LuceneOptions]?: string | string[] | LucenseBase; }; interface LuceneSpecial { $search?: { type: 'ngram' | 'prefix'; term: string; field?: string } | string; $range?: { [index: string]: [number, number] }; } interface LucenseAny { [index: string]: string | string[] | LucenseAny; } export type LuceneQuery = LucenseBase & LuceneSpecial & LucenseAny; export const lucene: ( query: LuceneQuery, entity?: any, ) => { querystring: string; placeholders: object; }; /** Gremlin */ export class GremlinQueryBuilder { constructor(initialQuery?: string); toString(): string; raw(query: string): GremlinQueryBuilder; append(query: string): GremlinQueryBuilder; transform( transforms: | Array | { [key: string]: string | GremlinQueryBuilder }, ): GremlinQueryBuilder; union(paths: Array): GremlinQueryBuilder; or(conditions: Array): GremlinQueryBuilder; dedup(prop: string): GremlinQueryBuilder; limit(start: number, finish: number): GremlinQueryBuilder; order(): GremlinQueryBuilder; by(field: string, dir?: string): GremlinQueryBuilder; range(from: number, to: number): GremlinQueryBuilder; values(target: string): GremlinQueryBuilder; filter(condition: string): GremlinQueryBuilder; addTempProp(name: string, value: string): GremlinQueryBuilder; addComputedProp( name: string, query: GremlinQueryBuilder | string, ): GremlinQueryBuilder; groupBy(groupingProp: string, resultProp: string): GremlinQueryBuilder; groupCount(groupingProp: string): GremlinQueryBuilder; inE(...args: Array): GremlinQueryBuilder; outE(...args: Array): GremlinQueryBuilder; bothE(...args: Array): GremlinQueryBuilder; inV(...args: Array): GremlinQueryBuilder; outV(...args: Array): GremlinQueryBuilder; bothV(...args: Array): GremlinQueryBuilder; in(...args: Array): GremlinQueryBuilder; out(...args: Array): GremlinQueryBuilder; both(...args: Array): GremlinQueryBuilder; count(...args: Array): GremlinQueryBuilder; as(...args: Array): GremlinQueryBuilder; select(...args: Array): GremlinQueryBuilder; shuffle(...args: Array): GremlinQueryBuilder; has(...args: Array): GremlinQueryBuilder; hasNot(...args: Array): GremlinQueryBuilder; tree(): GremlinQueryBuilder; property(...args: Array): GremlinQueryBuilder; getProperty(...args: Array): GremlinQueryBuilder; } export function gremlin( initialQuery?: string | GremlinQueryBuilder, ): GremlinQueryBuilder;