- Print
Capabilities-0.10.0
- Print
Capabilities Module 0.10.0
Usage
To use the Capabilities module, you can import it into your project from the Firebolt SDK:
import { Capabilities } from '@firebolt-js/sdk'
Methods
available
Returns whether a capability is available now.
function available(capability: Capability): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
capability | Capability | true |
Promise resolution:
Type | Description |
---|---|
boolean | Whether or not capability is available now. |
Examples
Device Token.
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.available("xrn:firebolt:capability:token:device")
.then(available => {
console.log(available)
})
Value of available
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.available",
"params": {
"capability": "xrn:firebolt:capability:token:device"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
More examples...
Unavailable Platform token.JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.available("xrn:firebolt:capability:token:platform")
.then(available => {
console.log(available)
})
Value of available
:
false
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.available",
"params": {
"capability": "xrn:firebolt:capability:token:platform"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": false
}
granted
Returns whether the current App has a user grant for passed capability and role.
function granted(capability: Capability, options?: CapabilityOption): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
capability | Capability | true | |
options | CapabilityOption | false | Capability options |
Promise resolution:
Type | Description |
---|---|
boolean | Whether or not app is granted to use the given capability and the role |
Examples
Default capabilities without grants.
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.granted("xrn:firebolt:capability:keyboard", null)
.then(granted => {
console.log(granted)
})
Value of granted
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.granted",
"params": {
"capability": "xrn:firebolt:capability:keyboard"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
More examples...
Get Postal code without grants.JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.granted("xrn:firebolt:capability:localization:postalCode", null)
.then(granted => {
console.log(granted)
})
Value of granted
:
false
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.granted",
"params": {
"capability": "xrn:firebolt:capability:localization:postalCode"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": false
}
Get Postal code with grants.
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.granted("xrn:firebolt:capability:localization:postalCode", null)
.then(granted => {
console.log(granted)
})
Value of granted
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.granted",
"params": {
"capability": "xrn:firebolt:capability:localization:postalCode"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
info
Returns an array of CapabilityInfo objects for the passed in capabilities.
function info(capabilities: Capability[]): Promise<CapabilityInfo[]>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
capabilities | [Capability ] | true |
Promise resolution:
Type | Description |
---|---|
[CapabilityInfo ] | Returns an array of CapabilityInfo objects for the passed in capabilities. |
Examples
Default result
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.info([
"xrn:firebolt:capability:device:model",
"xrn:firebolt:capability:keyboard",
"xrn:firebolt:capability:protocol:bluetoothle",
"xrn:firebolt:capability:token:device",
"xrn:firebolt:capability:token:platform",
"xrn:firebolt:capability:protocol:moca",
"xrn:firebolt:capability:wifi:scan",
"xrn:firebolt:capability:localization:postalCode",
"xrn:firebolt:capability:localization:locality"
])
.then(info => {
console.log(info)
})
Value of info
:
[
{
"capability": "xrn:firebolt:capability:device:model",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:keyboard",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:protocol:bluetoothle",
"supported": false,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unsupported"
]
},
{
"capability": "xrn:firebolt:capability:token:device",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unavailable"
]
},
{
"capability": "xrn:firebolt:capability:protocol:moca",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"disabled",
"unavailable"
]
},
{
"capability": "xrn:firebolt:capability:wifi:scan",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unpermitted"
]
},
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"ungranted"
]
},
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"ungranted"
]
},
{
"capability": "xrn:firebolt:capability:localization:locality",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"grantDenied",
"ungranted"
]
}
]
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.info",
"params": {
"capabilities": [
"xrn:firebolt:capability:device:model",
"xrn:firebolt:capability:keyboard",
"xrn:firebolt:capability:protocol:bluetoothle",
"xrn:firebolt:capability:token:device",
"xrn:firebolt:capability:token:platform",
"xrn:firebolt:capability:protocol:moca",
"xrn:firebolt:capability:wifi:scan",
"xrn:firebolt:capability:localization:postalCode",
"xrn:firebolt:capability:localization:locality"
]
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"capability": "xrn:firebolt:capability:device:model",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:keyboard",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:protocol:bluetoothle",
"supported": false,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unsupported"
]
},
{
"capability": "xrn:firebolt:capability:token:device",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
},
{
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unavailable"
]
},
{
"capability": "xrn:firebolt:capability:protocol:moca",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"disabled",
"unavailable"
]
},
{
"capability": "xrn:firebolt:capability:wifi:scan",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unpermitted"
]
},
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"ungranted"
]
},
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"ungranted"
]
},
{
"capability": "xrn:firebolt:capability:localization:locality",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"grantDenied",
"ungranted"
]
}
]
}
listen
Listen for events from this module.
To listen to a specific event pass the event name as the first parameter:
Capabilities.listen(event: string, (data: any) => void): Promise<number>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
event | string | Yes | The event to listen for, see Events. |
callback | function | Yes | A function that will be invoked when the event occurs. |
Promise resolution:
Type | Description |
---|---|
number | Listener ID to clear the callback method and stop receiving the event, e.g. Capabilities.clear(id) |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
data | any | Yes | The event data, which depends on which event is firing, see Events. |
To listen to all events from this module pass only a callback, without specifying an event name:
Capabilities.listen((event: string, data: any) => void): Promise<number>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
callback | function | Yes | A function that will be invoked when the event occurs. The event data depends on which event is firing, see Events. |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
event | string | Yes | The event that has occured listen for, see Events. |
data | any | Yes | The event data, which depends on which event is firing, see Events. |
Promise resolution:
Type | Description |
---|---|
number | Listener ID to clear the callback method and stop receiving the event, e.g. Capabilities.clear(id) |
See Listening for events for more information and examples.
once
Listen for only one occurance of an event from this module. The callback will be cleared after one event.
To listen to a specific event pass the event name as the first parameter:
Capabilities.once(event: string, (data: any) => void): Promise<number>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
event | string | Yes | The event to listen for, see Events. |
callback | function | Yes | A function that will be invoked when the event occurs. |
Promise resolution:
Type | Description |
---|---|
number | Listener ID to clear the callback method and stop receiving the event, e.g. Capabilities.clear(id) |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
data | any | Yes | The event data, which depends on which event is firing, see Events. |
To listen to all events from this module pass only a callback, without specifying an event name:
Capabilities.once((event: string, data: any) => void): Promise<number>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
callback | function | Yes | A function that will be invoked when the event occurs. The event data depends on which event is firing, see Events. |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
event | string | Yes | The event that has occured listen for, see Events. |
data | any | Yes | The event data, which depends on which event is firing, see Events. |
Promise resolution:
Type | Description |
---|---|
number | Listener ID to clear the callback method and stop receiving the event, e.g. Capabilities.clear(id) |
See Listening for events for more information and examples.
permitted
Returns whether the current App has permission to the passed capability and role.
function permitted(capability: Capability, options?: CapabilityOption): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
capability | Capability | true | |
options | CapabilityOption | false | Capability options |
Promise resolution:
Type | Description |
---|---|
boolean | Whether or not app is permitted for the given capability and the role |
Examples
Keyboard
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.permitted("xrn:firebolt:capability:keyboard", null)
.then(permitted => {
console.log(permitted)
})
Value of permitted
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.permitted",
"params": {
"capability": "xrn:firebolt:capability:keyboard"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
More examples...
Keyboard incorrect manage role capabilityJavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.permitted("xrn:firebolt:capability:keyboard", {"role":"manage"})
.then(permitted => {
console.log(permitted)
})
Value of permitted
:
false
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.permitted",
"params": {
"capability": "xrn:firebolt:capability:keyboard",
"options": {
"role": "manage"
}
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": false
}
Wifi scan not permitted capability
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.permitted("xrn:firebolt:capability:wifi:scan", null)
.then(permitted => {
console.log(permitted)
})
Value of permitted
:
false
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.permitted",
"params": {
"capability": "xrn:firebolt:capability:wifi:scan"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": false
}
request
Requests grants for all capability/role combinations in the roles array.
function request(grants: Permission[]): Promise<CapabilityInfo[]>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
grants | [Permission ] | true |
Promise resolution:
Type | Description |
---|---|
[CapabilityInfo ] | Returns an array of CapabilityInfo objects for the passed in capabilities. |
Examples
Default result
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.request([{"role":"use","capability":"xrn:firebolt:capability:commerce:purchase"}])
.then(Default Result => {
console.log(Default Result)
})
Value of Default Result
:
[
{
"capability": "xrn:firebolt:capability:commerce:purchase",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
}
]
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.request",
"params": {
"grants": [
{
"role": "use",
"capability": "xrn:firebolt:capability:commerce:purchase"
}
]
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"capability": "xrn:firebolt:capability:commerce:purchase",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
}
]
}
supported
Returns whether the platform supports the passed capability.
function supported(capability: Capability): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
capability | Capability | true |
Promise resolution:
Type | Description |
---|---|
boolean | Whether or not capability is supported in device. |
Examples
Wifi scan supported capability
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.supported("xrn:firebolt:capability:wifi:scan")
.then(supported => {
console.log(supported)
})
Value of supported
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.supported",
"params": {
"capability": "xrn:firebolt:capability:wifi:scan"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
More examples...
BLE protocol unsupported capabilityJavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.supported("xrn:firebolt:capability:protocol:bluetoothle")
.then(supported => {
console.log(supported)
})
Value of supported
:
false
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.supported",
"params": {
"capability": "xrn:firebolt:capability:protocol:bluetoothle"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": false
}
Events
available
Listens for all App permitted capabilities to become available.
See also: listen(), once(), clear().
Event value:
Type | Description |
---|---|
CapabilityInfo | Provides the capability info. |
Examples
Platform token is available:
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.listen('available', value => {
console.log(value)
})
Value of value
{
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unpermitted"
]
}
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.onAvailable",
"params": {
"capability": "xrn:firebolt:capability:token:platform",
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unpermitted"
]
}
}
granted
Listens for all App permitted capabilities to become granted.
See also: listen(), once(), clear().
Event value:
Type | Description |
---|---|
CapabilityInfo | Provides the capability info. |
Examples
Postal code granted:
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.listen('granted', value => {
console.log(value)
})
Value of value
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
}
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.onGranted",
"params": {
"role": "use",
"capability": "xrn:firebolt:capability:localization:postalCode",
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
}
}
}
revoked
Listens for all App permitted capabilities to become revoked.
See also: listen(), once(), clear().
Event value:
Type | Description |
---|---|
CapabilityInfo | Provides the capability info. |
Examples
Postal code revoked:
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.listen('revoked', value => {
console.log(value)
})
Value of value
{
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"grantDenied"
]
}
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.onRevoked",
"params": {
"role": "use",
"capability": "xrn:firebolt:capability:localization:postalCode",
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capability": "xrn:firebolt:capability:localization:postalCode",
"supported": true,
"available": true,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"grantDenied"
]
}
}
unavailable
Listens for all App permitted capabilities to become unavailable.
See also: listen(), once(), clear().
Event value:
Type | Description |
---|---|
CapabilityInfo | Provides the capability info. |
Examples
Platform token is unavailable.:
JavaScript:
import { Capabilities } from '@firebolt-js/sdk'
Capabilities.listen('unavailable', value => {
console.log(value)
})
Value of value
{
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unavailable"
]
}
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "capabilities.onUnavailable",
"params": {
"capability": "xrn:firebolt:capability:token:platform",
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capability": "xrn:firebolt:capability:token:platform",
"supported": true,
"available": false,
"use": {
"permitted": true,
"granted": true
},
"manage": {
"permitted": true,
"granted": true
},
"provide": {
"permitted": true,
"granted": true
},
"details": [
"unavailable"
]
}
}
Schemas
CapabilityOption
type CapabilityOption = {
role?: Role // Role provides access level for the app for a given capability.
}
See also: