Infohub JS API
Loading...
Searching...
No Matches
Context Class Reference

Description

Maintains the shared connection and selection state for COLNEO infohub services.

A context stores the authenticated user and access token, the service endpoints, and the currently selected scope, project, and optional coordination model. Pass the same context instance to service classes so that they use consistent authentication and project state.

Context extends EventTarget and dispatches a CustomEvent named contextChanged whenever one of its setters changes the stored state. The event's detail object contains only the values changed by that operation. Use the context getters when a complete view of the current state is required.

const context = new Context();
function handleContextChanged(event) {
// event.detail contains the values changed by the latest operation.
if (event.detail.scope !== undefined) {
console.log('Scope changed to:', event.detail.scope);
}
// Read the complete current selection from the context.
console.log({
scope: context.getScope(),
projectShortId: context.getProjectShortId(),
coordinationModelShortId: context.getCoordinationModelShortId()
});
}
context.addEventListener('contextChanged', handleContextChanged);
context.setScopeAndProjectShortId('project', 'project-123');
// Remove the listener when it is no longer needed.
context.removeEventListener('contextChanged', handleContextChanged);
Maintains the shared connection and selection state for COLNEO infohub services.
Definition Context.js:52
Examples
C:/xampp/htdocs/InfohubJsApi/src/adapter/IModelViewer.js.
Inheritance diagram for Context:

Public Member Functions

 constructor ()
 dump ()
async getCoordinationModel (query={ members:['info'] })
 getCoordinationModelShortId ()
async getProject (query={ members:['info'] })
 getProjectShortId ()
 getScope ()
 getServiceUrl (servicename)
 getToken ()
 getUserId ()
 resetLocalStorage (cb)
 resetProjectAndScope ()
 restoreFromLocalStorage (cb)
 saveToLocalStorage (cb)
 setCoordinationModelShortId (sid)
 setProjectShortId (sid)
 setScope (scope)
 setScopeAndProjectShortId (scope, project_sid, coordmodel_sid=null)
 setServiceUrls (cfg)
 setServiceUrlsDefault ()
 setUserAndToken (userid, token)

Static Public Member Functions

static getServiceNames ()

Static Public Attributes

static SERVICE

Function Documentation

◆ constructor()

constructor ( )

Create an COLNEO infohub context with service endpoints set to null and empty user state.

Example

// create context
const ctx = new Context();
ctx.setServiceUrls({
hub : "https://app.colneo.services/hub",
admin : "https://app.colneo.services/admin",
usr : "https://app.colneo.services/usr",
idp : "https://idp.colneo.services/service"
});
ctx.setUserAndToken( "user@example.com" , "... jwt_token ...");
ctx.setScopeAndProject( "cn_c00", "proj_123" );
ctx.getScope(); // => "project"
ctx.getProjectShortId(); // => "proj_123"
ctx.getUser(); // => "user@example.com"
ctx.getToken(); // => "jwt_token"
console.log(cntx.getUser()); // => "user@example.com"
Since
08.2025, jh

◆ dump()

dump ( )

Print current context to the console (for debugging).

Returns
{void}

◆ getCoordinationModel()

async getCoordinationModel ( query = { members: ['info'] })

Get Coordination Model as Object
API call to get coordmodel data from infohub by short id.

Returns
{Promise<object|null>} Returns a Project object or null

◆ getCoordinationModelShortId()

getCoordinationModelShortId ( )
Returns
Project ShortId
Since
1.0, 09.2025, jh

◆ getProject()

async getProject ( query = { members: ['info'] })

Get Project as Object from infohub
A project shortid must be set.


API call to get project data from infohub by short id

Returns
{Promise<object|null>} Returns a Project object or null

◆ getProjectShortId()

getProjectShortId ( )
Returns
Project ShortId
Since
1.0, 09.2025, jh

◆ getScope()

getScope ( )

Get current scope ID.

Returns
{string}

◆ getServiceNames()

getServiceNames ( )
static

Get list of names of supported web services.

Example:

let names = Infohub.getServiceNames()
Returns
{string[]} Array of names as string
Since
08.2025, jh

◆ getServiceUrl()

getServiceUrl ( servicename)

Get URL of supported webservice.

Parameters
{string}servicename
Returns
{string | null} Url of service, null if not found
Since
08.2025, jh

◆ getToken()

getToken ( )

Get current access token.

Returns
{string}

◆ getUserId()

getUserId ( )

Get current user id.

Returns
{string} User ID (Email)

◆ resetLocalStorage()

resetLocalStorage ( cb)

◆ resetProjectAndScope()

resetProjectAndScope ( )

Reset scope, project and coordinationmodel to null.

Returns
{void}

◆ restoreFromLocalStorage()

restoreFromLocalStorage ( cb)
Parameters
{Function}cb

◆ saveToLocalStorage()

saveToLocalStorage ( cb)
Parameters
{Function}cb

◆ setCoordinationModelShortId()

setCoordinationModelShortId ( sid)

Set current project short id.

Parameters
{string}sid
Returns
{void}

◆ setProjectShortId()

setProjectShortId ( sid)

Set current project short id.

Parameters
{string}sid
Returns
{void}

◆ setScope()

setScope ( scope)

Set current scope ID.

Parameters
{string}scope
Returns
{void}

◆ setScopeAndProjectShortId()

setScopeAndProjectShortId ( scope,
project_sid,
coordmodel_sid = null )

Set scope, project short id and coordmodel shortid.

Parameters
{string}scope
{string}project_sid
{string|null}coordmodel_sid
Returns
{void}

◆ setServiceUrls()

setServiceUrls ( cfg)

Set multiple service URLs at once.

Example:

const ctx = new cnContext();
ctx.setServiceUrls({
hub : "https://app.colneo.services/hub",
admin : "https://app.colneo.services/admin",
usr : "https://app.colneo.services/usr"
});
console.log(ctx.getServiceUrl("hub")); // https://app.colneo.services/hub
console.log(ctx.getServiceUrl("config")); // null (not set yet)
Parameters
{Record<string,string>}cfg - Object mapping service names to URLs
Exceptions
{TypeError}If cfg is not a non-null object

◆ setServiceUrlsDefault()

setServiceUrlsDefault ( )

Set default values for services urls.

◆ setUserAndToken()

setUserAndToken ( userid,
token )

Set current user id and authentication token.

Parameters
{string|null}userid
{string|null}token
Returns
{void}

Member Data Documentation

◆ SERVICE

SERVICE
static
Initial value:
= {
HUB: "hub",
CONFIG: "config",
ADMIN: "admin",
USR: "usr",
IDP: "idp",
IAM: "iam",
RENDER: "render",
RPC: "rpc",
TYPES: "types",
BCF: "bcf",
CM: "cm",
CONNECTORSHAREPOINT: "connectorsharepoint"
}

Supported web services of COLNEO infohub.

HUB | CONFIG | USR | IDP | IAM | RENDER | RPC | TYPES | CM

Example:

...
const url = `${ctx.getServiceUrl(cnContext.SERVICE.IDP)}/users/${userid}`;
...
Since
1.0, 2025