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
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
Redirects to login page if user is not logged in already
Parameters
Name |
Description |
options.loginHint string?
|
login_hint to forward email/username in keycloak.
|
▸
changeTenant(tenantId?)
Changes a tenant
In case there is no tenantId provided, it will either redirect to the
tenant selection page or to the oAuth login page.
changeTenant(tenantId:
string?)
Parameters
tenantId (string?)
The tenant id that the user wants to change to
Return current user
Returns
Promise
:
user profile object
Application
Methods for application operations
new Application()
Static Members
▸
getApplications(params)
Get all applications available for the tenant.
Parameters
params (object)
Search parameters
Name |
Description |
params.installed boolean?
|
Filter for only installed applications
|
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of results per page. Default is 10
|
Returns
Promise
:
▸
getApplication(applicationId)
Get detailed information for the available or installed application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
▸
getPermissions(applicationId)
Get permissions required by an application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
▸
installApplication(applicationId, data)
Install an available application
Parameters
applicationId (string)
The application ID
data (object
= {}
)
Application data
Name |
Description |
data.permissions object?
|
Application permissions
|
data.permissions.client Array<{id: string}>?
|
Application client permissions
|
data.permissions.user Array<{id: string}>?
|
Application client permissions
|
Returns
Promise
:
▸
updateInstallation(applicationId, data)
Updates and re-consents an installation
Parameters
applicationId (string)
The application ID
data (object)
Application data
Name |
Description |
data.permissions object?
|
Application permissions
|
data.permissions.client Array<{id: string}>?
|
Application client permissions
|
data.permissions.user Array<{id: string}>?
|
Application client permissions
|
Returns
Promise
:
▸
getInstallationDetails(applicationId)
Get detailed information for an application installation
Parameters
applicationId (string)
The application ID
Returns
Promise
:
▸
uninstallApplication(applicationId)
Uninstall an installed application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
ApplicationDeveloper
Methods for application operations for the owner (developer)
new ApplicationDeveloper()
Static Members
▸
createApplication(application)
Creates an application.
Include the tenant to the allowedTenants to enable the access for the usage. Ownership of the application does not imply ability to use the application.
Parameters
application (object)
The application data
Name |
Description |
application.name string
|
The name of the application
|
application.teaserDescription string?
|
A short description for the application
|
application.url string?
|
A URL with more information on the app. E.g. the app homepage. Protocol is required
|
application.withPublicOauth2Client boolean?
|
Indicator of whether the application should also be accessible as a public OAuth2 client
|
application.redirectUris Array<string>?
|
List of redirect URIs
|
Returns
Promise
:
▸
getApplications(params)
Get all applications, which are owned (developed) by the tenant.
Tenant is implied by the session
Parameters
params (object)
Search parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page. Default is 10
|
Returns
Promise
:
▸
getApplicationDetails(applicationId)
Get details of a specific owned (developed) application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
▸
deleteApplication(applicationId)
Delete an owned (developed) application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
▸
patchApplication(applicationId, application)
Update an owned (developed) application
Parameters
applicationId (string)
The application ID
application (object)
The applications data
Name |
Description |
application.name string?
|
The name of the application
|
application.teaserDescription string?
|
A short description for the application
|
application.url string?
|
A URL with more information on the app. E.g. the app homepage. Protocol is required
|
application.withPublicOauth2Client boolean?
|
Indicator of whether the application should also be accessible as a public OAuth2 client
|
application.status string?
|
Enum: 'active'. 'inactive'. Status of the application. An inactive application cannot be installed, nor can the tenant data be accessed
|
application.redirectUris Array<string>?
|
List of redirect URIs
|
Returns
Promise
:
▸
getAllowedTenants(applicationId, params)
Get the list of the tenants who can install the application
Parameters
applicationId (string)
The application ID
params (object
= {}
)
Search parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page. Default is 10
|
Returns
Promise
:
▸
addAllowedTenant(applicationId, tenantId, data = {})
Add a tenant to the list of those who can install the application
Parameters
applicationId (string)
The application ID
tenantId (string)
The tenant ID
Name |
Description |
data.comment string?
|
A comment about the allowed tenant
|
Returns
Promise
:
▸
removeAllowedTenant(applicationId, tenantId)
Deletes the tenant from the list of the allowed tenants
Parameters
applicationId (string)
The application ID
tenantId (string)
The tenant ID
Returns
Promise
:
▸
regenerateApplicationSecret(applicationId)
Regenerates an application secret for an owned (developed) application
Parameters
applicationId (string)
The application ID
Returns
Promise
:
Certificates
Methods for certificate operations
new Certificates()
Static Members
▸
getDeviceCertificates(deviceId)
Get the certificates assigned to this device
Parameters
Returns
Promise
:
▸
assignCertificates(deviceId, certificate)
Assign a certificate to a device. A certificate can only be assigned to exactly one device.
Parameters
Returns
Promise
:
▸
getDeviceCertificate(deviceId, certificateId)
Get specific certificate object
Parameters
Returns
Promise
:
▸
patchDeviceCertificate(deviceId, certificateId, patch)
Patch specific certificate object
Parameters
Returns
Promise
:
Client
Methods for client operations
new Client()
Static Members
Create a new client for your current tenant.
As stated in the Client model, the client secret will only be
returned upon client creation, and you will never be able to
get it again. Store it safe and secure.
Parameters
Returns
Promise
:
Get the client for the supplied clientId
Parameters
Returns
Promise
:
Delete the client for the supplied clientId
Parameters
Returns
Promise
:
Consumption
Methods for client operations
new Consumption()
Static Members
Get summary of consumption during period.
Parameters
Name |
Description |
params.startTime string?
|
start time for the requested summary
|
params.endTime string?
|
end time for the requested summary
|
params.unit array?
|
the units to return, available values: devices, storageSamples, users
|
Returns
Promise
:
Device
Methods for device operations
new Device()
Static Members
Creates a new device
Parameters
Returns
Promise
:
Get all devices
Parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page. Default is 10
|
params.tags string
(default undefined )
|
Filter the results to contain only devices having all the comma-separated list of tags provided here. Case-insensitive. Surround the tag with * for substring matching. Example: subString-of-a-tag,fullMatching-Tag
|
params.name string
(default undefined )
|
Filter the results to contain only devices having the provided name. Case-insensitive. Surround with
for substring matching. Example: &subString
OR fullMatchingName
|
params.deviceTypeId string
(default undefined )
|
Filter returning devices matching a single device type UUID.
|
params.connectedBy string
(default undefined )
|
Filter the results to contain only devices connected by a given device UUID.
|
Returns
Promise
:
Get a device by its deviceId.
Parameters
Returns
Promise
:
▸
patchDevice(deviceId, patch)
Edit a specific device by id partially. Id is not patchable. You can also only patch a single property from your custom data. To delete submit null.
Parameters
patch (object)
changes to device
Returns
Promise
:
Delete a specific device by id.
Parameters
Returns
Promise
:
▸
createAction(deviceId, action)
Trigger device action
Parameters
Returns
Promise
:
The current state of a a device are the attributes and configurations the device has last sent to the cloud. Newer values for the same attribute and configuration overwrite older on.
Parameters
Returns
Promise
:
▸
getLastDiagnostics(deviceId)
List device diagnostic messages sorted descending by time for a specific device for the last hour to simplify debugging.
Parameters
Returns
Promise
:
▸
pushData(deviceId, data)
Push data to device
Parameters
Returns
Promise
:
▸
getOnlineMonitoringRules(deviceId)
Get the online monitoring configuration for a device
Parameters
Returns
Promise
:
▸
patchOnlineMonitoringRules(deviceId, config)
Edit the online monitoring configuration for a device
Parameters
config (object)
changes to device
Name |
Description |
config.communicationInterval (number | null)
|
The expected communication interval in seconds. Special cases:
0
means monitoring is disabled,
null
means inherit from device type
|
Returns
Promise
:
DeviceType
Methods for device type operations
new DeviceType()
Static Members
▸
createDeviceType(deviceType)
Creates a new device type
Parameters
Returns
Promise
:
Get all device types
Parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page. Default is 10
|
params.name string
(default undefined )
|
Filter the results to contain only devices having the provided name. Case-insensitive. Surround with
for substring matching. Example: &subString
OR fullMatchingName
|
Returns
Promise
:
Returns a list of semantic categories used in your device types.
Returns
Promise
:
▸
getDeviceType(deviceTypeId)
Get a specific device-type by id
Parameters
Returns
Promise
:
▸
patchDeviceType(deviceTypeId, patch)
Edit a specific device-type by id partially. Id is not patchable. You can also only patch a single property from your custom data. To delete submit null.
Parameters
patch (object)
changes to device type
Returns
Promise
:
▸
deleteDeviceType(deviceTypeId)
Delete a specific device-type by id. Note: you can not delete device type if it's attached to at least one device
Parameters
Returns
Promise
:
▸
getOnlineMonitoringRules(deviceTypeId)
Get the online monitoring configuration for a device type
Parameters
Returns
Promise
:
▸
patchOnlineMonitoringRules(deviceTypeId, config)
Edit the online monitoring configuration for a device type
Parameters
config (object)
changes to device
Name |
Description |
config.communicationInterval (number | null)
|
The expected communication interval in seconds. Special cases:
null
and
0
mean monitoring is disabled
|
Returns
Promise
:
Event
Methods for device event operations
new Event()
Static Members
▸
getEvents(deviceId, params, eventTypes)
Retrieve the last days events.
Parameters
eventTypes (string
= undefined
)
A comma separated list of event types used as a filter. So only events with one of this events assigned will be returned.
Returns
Promise
:
▸
createEvent(deviceId, event)
Push a event, to add it to the devices events.
Parameters
Returns
Promise
:
Role
Methods for roles operations
new Role()
Static Members
Get the permissions of the tenant
Returns
Promise
:
Get the roles of the tenant
Parameters
params (object?
= {}
)
Search parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page
|
Returns
Promise
:
Get the role of the tenant
Parameters
roleId (string)
The role's UUID
Returns
Promise
:
Create the role of the tenant
Parameters
Name |
Description |
role.name string
|
The name of the role
|
role.description string?
|
The description of the role
|
role.permissions Array<{id: string, alias: string}>?
|
The permissions of the role. Either id or alias must be provided.
|
Returns
Promise
:
Delete the role of the tenant
Parameters
roleId (string)
The role's UUID
Returns
Promise
:
▸
patchRole(roleId, role)
Patch the role of the tenant
Parameters
roleId (string)
The role's UUID
Name |
Description |
role.name string?
|
The name of the role
|
role.description string?
|
The description of the role
|
role.permissions Array<{id: string, alias: string}>?
|
The permissions of the role. Either id or alias must be provided.
|
Returns
Promise
:
▸
getRoleUsers(roleId, params = {})
Get the users of the role
Parameters
roleId (string)
The role's UUID
params (object?
= {}
)
Search parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page
|
Returns
Promise
:
Tenant
Methods for tenant operations
new Tenant()
Static Members
▸
getUserTenants(userId, params)
Get the tenants of a user for the supplied userId
Parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page
|
Returns
Promise
:
Creates a new tenant and assigns role 'admin' to user.
Parameters
Returns
Promise
:
Gets tenant
Parameters
Returns
Promise
:
▸
getTenantUsers(tenantId, params)
Get the users associated to a tenant by any role
Parameters
Returns
Promise
:
▸
deleteTenantUser(tenantId, userId)
Delete (remove) a user from a tenant
Parameters
Returns
Promise
:
Delete tenant for the supplied tenantId
Parameters
Returns
Promise
:
▸
createInvite(tenantId, invite)
Create invite for tenant
Parameters
invite (Object)
the invite to be created.
Name |
Description |
invite.receiverEmail string
|
email of user to be invited
|
invite.roleNames array<string>
|
Deprecated: array of roles for user to be assigned to. Ex.
['admin']
|
invite.roles array<{id: string}>
|
Array of objects containing the role id for user to be assigned to. Ex.
[{ id: '123e4567-e89b-12d3-a456-426655440000' }]
|
Returns
Promise
:
▸
getInvites(tenantId, params)
Get tenant invites
Parameters
Returns
Promise
:
▸
deleteInvite(tenantId, inviteId)
Delete (revoke) a invite for a user.
- Only open invites can be deleted
Parameters
Returns
Promise
:
▸
getTenantRoles(tenantId)
Gets roles of tenant
Parameters
Returns
Promise
:
▸
putTenantUserRoles(tenantId, userId, put)
Update roles of user for tenant
- roleNames will replace the current roles.
Parameters
Returns
Promise
:
▸
patchTenant(tenantId, patch)
Partially change the data of a specific tenant by its id. The Id itself is not changeable.
Parameters
patch (object)
changes to tenant
Returns
Promise
:
Timeseries
Methods for timeseries operations
new Timeseries()
Static Members
▸
getDeviceLastTimeseries(deviceId, params)
Get data for the last hour reported to the timeseries db by the device with the given uuid in an descending order.
Parameters
Name |
Description |
params.path string
|
Path matching to a path defined in the reporting rules of the device's type. (e.g. $.attributes.brightness).
|
Returns
Promise
:
▸
deleteDeviceTimeseries(deviceId, params)
Delete reported timeseries data of the device belonging to the given uuid.
Parameters
Name |
Description |
params.path string
|
Path matching to a path defined in the reporting rules of the device's type. (e.g. $.attributes.brightness).
|
params.startTime string
|
The start time of the time frame to request. (RFC 3339)
|
params.endTime string
|
The end time of the time frame to request. (RFC 3339)
|
Returns
Promise
:
▸
getDeviceAggregatedTimeseries(deviceId, params)
Get data for the last hour reported to the timeseries db by the device with the given uuid in an descending order.
Parameters
Name |
Description |
params.path string
|
Path matching to a path defined in the reporting rules of the device's type. (e.g. $.attributes.brightness).
|
params.startTime string
|
The start time of the time frame to request. (RFC 3339)
|
params.endTime string
|
The end time of the time frame to request. (RFC 3339)
|
params.limit number
|
The limit of the points returned in one query.
|
params.frameSize string
|
The time frame size in which the values should be aggregated. In case frameSize is set and the number of points in the response will exceed the limit, an error (400) will be returned. Available values : 1m, 5m, 30m, 1h, 1d
|
params.aggregation string
|
How should the values be aggregated. Supported values: min, max, mean, sum, count, diff, first, last. Available values : min, max, mean, sum, count, diff, first, last
|
Returns
Promise
:
User
Methods for user operations
new User()
Static Members
Gets user information
Parameters
Returns
Promise
:
▸
getUserTenant(userId, tenantId)
Gets user tenant information
Parameters
Returns
Promise
:
▸
getUserInvites(userId, params)
Gets user invites
Parameters
Name |
Description |
params.page number
(default 0 )
|
The number of the result page starting with 0
|
params.pageSize number
(default 10 )
|
The number of result per page
|
Returns
Promise
:
▸
acceptUserInvite(userId, inviteId)
Accept a user invite
Parameters
Returns
Promise
:
▸
declineUserInvite(userId, inviteId)
Decline a user invite
Parameters
Returns
Promise
:
▸
getUserPermissions(userId)
Get a user's permissions within the current tenant
Parameters
Returns
Promise
:
UserManager
new UserManager(settings: any)
Extends
OIDC.UserManager
Parameters
Properties
Instance Members
Change the tenant id
Parameters
tenantId (string)
Changes the users's tenant
Returns
Promise<User>
:
UserManager
new UserManager(settings: any)
Extends
OIDC.UserManager
Parameters
Properties
Instance Members
Change the tenant id
Parameters
tenantId (string)
Changes the users's tenant
Returns
Promise<User>
:
UserManager
new UserManager(settings: any)
Extends
OIDC.UserManager
Parameters
Properties
Instance Members
Change the tenant id
Parameters
tenantId (string)
Changes the users's tenant
Returns
Promise<User>
:
allowedContentTypes
allowedContentTypes
isAllowedContentType
Checks if a content type is one of the allowed ones
isAllowedContentType
Parameters
Returns
string
:
XMLHttpRequest
XMLHttpRequest