@lightelligence/browser-sdk
current

Getting started

To start using browser sdk you will need to install it via npm:

npm install @lightelligence/browser-sdk

and import it in your source code:

import BrowserSDK from '@lightelligence/browser-sdk';

Then you will need to create an instance of sdk:

const browserSDK = new BrowserSDK({
  environment: 'preview',
// you can change it to 'dev', 'int' or 'preview'   clientId: 'olt_sensor_dashboard',
  scope: ['openid','profile','email','offline_access']
});

Use login method will redirect user to login page redirects back upon successfull authorization:

browserSDK.login();

Now you can retrieve your logged in user by calling:

browserSDK.getCurrentUser().then(user => console.log(user));

From here you can start exploring other modules. Let's start with Device module.

Import Device module

import BrowserSDK, {Device} from '@lightelligence/browser-sdk';

Use getDevices method to get all devices

Device.getDevices().then(devices => console.log(devices));

Now you are ready to build your application. Explore available methods below.

NOTE: Ensure that your app is redirect all request to index.html file. The authorization would not work without it

BrowserSDK

Main browser sdk module TODO: add getting started block here

new BrowserSDK(options: Object)
Parameters
options (Object)
Name Description
options.environment string? lightelligence environment. avalaible options: 'dev', 'int', 'preview', 'prod'
options.clientId string registered app client id
options.scope array (default ['openid','profile','email']) openid scope
options.authCallback string (default '/auth-callback') configurable authCallback path, the signin redirect after this path is called is automatically handled by this sdk
Instance Members
login(options = {})
changeTenant(tenantId?)
logout()
getCurrentUser()

Application

Methods for application operations

new Application()
Static Members
getApplications(params)
getApplication(applicationId)
getPermissions(applicationId)
installApplication(applicationId, data)
updateInstallation(applicationId, data)
getInstallationDetails(applicationId)
uninstallApplication(applicationId)

ApplicationDeveloper

Methods for application operations for the owner (developer)

new ApplicationDeveloper()
Static Members
createApplication(application)
getApplications(params)
getApplicationDetails(applicationId)
deleteApplication(applicationId)
patchApplication(applicationId, application)
getAllowedTenants(applicationId, params)
addAllowedTenant(applicationId, tenantId, data = {})
removeAllowedTenant(applicationId, tenantId)
regenerateApplicationSecret(applicationId)

Certificates

Methods for certificate operations

new Certificates()
Static Members
getDeviceCertificates(deviceId)
assignCertificates(deviceId, certificate)
getDeviceCertificate(deviceId, certificateId)
patchDeviceCertificate(deviceId, certificateId, patch)

Client

Methods for client operations

new Client()
Static Members
createClient(client)
getClient(clientId)
deleteClient(clientId)

Consumption

Methods for client operations

new Consumption()
Static Members
getSummary(params)

Device

Methods for device operations

new Device()
Static Members
createDevice(device)
getDevices(params)
getDeviceTags()
getDevice(deviceId)
patchDevice(deviceId, patch)
deleteDevice(deviceId)
createAction(deviceId, action)
getState(deviceId)
getLastDiagnostics(deviceId)
pushData(deviceId, data)
getOnlineMonitoringRules(deviceId)
patchOnlineMonitoringRules(deviceId, config)

DeviceType

Methods for device type operations

new DeviceType()
Static Members
createDeviceType(deviceType)
getDeviceTypes(params)
getUsedCategories()
getDeviceType(deviceTypeId)
patchDeviceType(deviceTypeId, patch)
deleteDeviceType(deviceTypeId)
getOnlineMonitoringRules(deviceTypeId)
patchOnlineMonitoringRules(deviceTypeId, config)

Event

Methods for device event operations

new Event()
Static Members
getEvents(deviceId, params, eventTypes)
createEvent(deviceId, event)

Role

Methods for roles operations

new Role()
Static Members
getPermissions()
getRoles(params = {})
getRole(roleId)
createRole(role)
deleteRole(roleId)
patchRole(roleId, role)
getRoleUsers(roleId, params = {})

Tenant

Methods for tenant operations

new Tenant()
Static Members
getUserTenants(userId, params)
createTenant(tenant)
getTenant(tenantId)
getTenantUsers(tenantId, params)
deleteTenantUser(tenantId, userId)
deleteTenant(tenantId)
createInvite(tenantId, invite)
getInvites(tenantId, params)
deleteInvite(tenantId, inviteId)
getTenantRoles(tenantId)
putTenantUserRoles(tenantId, userId, put)
patchTenant(tenantId, patch)

Timeseries

Methods for timeseries operations

new Timeseries()
Static Members
getDeviceLastTimeseries(deviceId, params)
deleteDeviceTimeseries(deviceId, params)
getDeviceAggregatedTimeseries(deviceId, params)

User

Methods for user operations

new User()
Static Members
getUser(userId)
getUserTenant(userId, tenantId)
getUserInvites(userId, params)
acceptUserInvite(userId, inviteId)
declineUserInvite(userId, inviteId)
getUserPermissions(userId)

UserManager

new UserManager(settings: any)

Extends OIDC.UserManager

Parameters
settings (any)
Properties
postForm (Function)
_XMLHttpRequest (XMLHttpRequest)
_contentTypes (Array<string>)
Instance Members
changeTenant(tenantId)

UserManager

new UserManager(settings: any)

Extends OIDC.UserManager

Parameters
settings (any)
Properties
headers (Object<string>)
Instance Members
changeTenant(tenantId)

UserManager

new UserManager(settings: any)

Extends OIDC.UserManager

Parameters
settings (any)
Properties
_jsonService (jsonService)
exchangeRefreshToken (Function)
Instance Members
changeTenant(tenantId)

UserManager

User Manager

Just a wrapper around OIDC.UserManager https://github.com/IdentityModel/oidc-client-js/blob/dev/src/UserManager.js

new UserManager(settings: any)

Extends OIDC.UserManager

Parameters
settings (any)
Instance Members
changeTenant(tenantId)

tokenClient

We access the tokenClient which is part of the UserManager

https://github.com/IdentityModel/oidc-client-js/blob/dev/src/UserManager.js#L45

tokenClient

tokenClient

tokenClient

Type: tokenClient

jsonService

We need to access the JSONService instance in order to modify the XMLHTTPRequest to accept headers.

https://github.com/IdentityModel/oidc-client-js/blob/dev/src/JsonService.js#L99

jsonService
Static Members
postForm(url, payload)

allowedContentTypes

allowedContentTypes

isAllowedContentType

Checks if a content type is one of the allowed ones

isAllowedContentType
Parameters
contentType (any)
Returns
string:

XMLHttpRequest

XMLHttpRequest