Skip to content

Commit 5895d6b

Browse files
authored
fix: autocompletions with jsdocs (#63)
fix: dep vulns chore: add start and debug scripts docs: add typedefs to api docs: add typedef to endpoint-context api docs: add util/events.js for typedefs docs: add jsdocs to signature.js feat: add ColorSetting, MessageGroupSetting w/ jsdocs docs: add jsdocs to all *settings docs: add jsdocs to smart-app.js Remove index.js chore: remove comments from events.js docs: add mode, device, and timer event docs split string by regex properly use correct return result remove events.js set this.api = {} for rules Add .vscode launch.json to debug mocha tests easily Use proper jsdoc type over typedef docs: update readme chore: add boolean-setting-spec docs: add SmartAppOptions object fix usage of typedef vs type in api.js
1 parent f8bdaeb commit 5895d6b

36 files changed

+2179
-353
lines changed

.vscode/launch.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Mocha All",
8+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
9+
"args": [
10+
"--timeout",
11+
"999999",
12+
"--colors",
13+
"${workspaceFolder}/test"
14+
],
15+
"console": "integratedTerminal",
16+
"internalConsoleOptions": "neverOpen"
17+
},
18+
{
19+
"type": "node",
20+
"request": "launch",
21+
"name": "Mocha Current File",
22+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
23+
"args": [
24+
"--timeout",
25+
"999999",
26+
"--colors",
27+
"${file}"
28+
],
29+
"console": "integratedTerminal",
30+
"internalConsoleOptions": "neverOpen"
31+
}
32+
]
33+
}

README.md

+23-13
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ npm i @smartthings/smartapp --save
2727
`NodeJS`:
2828

2929
```javascript
30-
const smartapp = require('@smartthings/smartapp')
30+
const SmartApp = require('@smartthings/smartapp')
3131
```
3232

33-
Or, if you're transpiling to `ES6`/`ES2015`+:
33+
Or `ES2015`+:
3434

3535
```javascript
36-
import smartapp from '@smartthings/smartapp'
36+
import SmartApp from '@smartthings/smartapp'
3737
```
3838

3939
## Highlights
@@ -43,6 +43,9 @@ import smartapp from '@smartthings/smartapp'
4343
- [x] Configuration page API simplifies page definition.
4444
- [x] Integrated [i18n](https://www.npmjs.com/package/i18n) framework provides configuration page localization.
4545
- [x] [Winston](https://www.npmjs.com/package/winston) framework manges log messages.
46+
- [x] Context Store plugins – easily scale access token management (and more) to support many users
47+
- [x] [AWS DynamoDB](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs) plugin
48+
- [x] [Firebase Cloud Firestore](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs) plugin
4649

4750
## Roadmap
4851

@@ -58,29 +61,36 @@ To run the app with an HTTP server, like Express.js:
5861

5962
```javascript
6063
const express = require('express');
61-
const smartapp = require('@smartthings/smartapp');
64+
const SmartApp = require('@smartthings/smartapp');
6265
const server = module.exports = express();
6366
const PORT = 8080;
6467

6568
server.use(express.json());
6669

6770
/* Define the SmartApp */
68-
smartapp
71+
const smartapp = new SmartApp()
6972
// @smartthings_rsa.pub is your on-disk public key
7073
// If you do not have it yet, omit publicKey()
7174
.publicKey('@smartthings_rsa.pub') // optional until app verified
7275
.app.enableEventLogging(2) // logs all lifecycle event requests and responses as pretty-printed JSON. Omit in production
7376
.configureI18n()
7477
.page('mainPage', (context, page, configData) => {
7578
page.section('sensors', section => {
76-
section.deviceSetting('contactSensor').capabilities(['contactSensor']).required(false);
79+
section
80+
.deviceSetting('contactSensor')
81+
.capabilities(['contactSensor'])
82+
.required(false);
7783
});
7884
page.section('lights', section => {
79-
section.deviceSetting('lights').capabilities(['switch']).multiple(true).permissions('rx');
85+
section
86+
.deviceSetting('lights')
87+
.capabilities(['switch'])
88+
.multiple(true)
89+
.permissions('rx');
8090
});
8191
})
8292
.updated(async (context, updateData) => {
83-
// Called for both INSTALLED and UPDATED lifecycle events if there is no separate installed() handler
93+
// Called for both INSTALLED and UPDATED lifecycle events if there is no separate installed() handler
8494
await context.api.subscriptions.unsubscribeAll()
8595
return context.api.subscriptions.subscribeToDevices(context.config.contactSensor, 'contactSensor', 'contact', 'myDeviceEventHandler');
8696
})
@@ -104,15 +114,15 @@ To run as a Lambda function instead of an HTTP server, ensure that your main ent
104114

105115
> **Note:** This snippet is heavily truncated for brevity – see the web service example above a more detailed example of how to define a `smartapp`.
106116
107-
```
108-
const smartapp = require('@smartthings/smartapp')
109-
smartapp
110-
.app.enableEventLogging() // logs all lifecycle event requests and responses. Omit in production
117+
```javascript
118+
const SmartApp = require('@smartthings/smartapp')
119+
const smartapp = new SmartApp()
120+
.enableEventLogging() // logs all lifecycle event requests and responses. Omit in production
111121
.page( ... )
112122
.updated(() => { ... })
113123
.subscribedEventHandler( ... );
114124

115-
exports.handle = (event, context, callback) => {
125+
exports.handler = (event, context, callback) => {
116126
smartapp.handleLambdaCallback(event, context, callback);
117127
};
118128
```

index.js

-9
This file was deleted.

lib/api.js

+24
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,41 @@ const Subscriptions = require('./platform/subscriptions')
1313

1414
module.exports = class SmartThingsApi {
1515
constructor(options) {
16+
// TODO – expand these JSdocs
17+
/** @type { import('./platform/client') } */
1618
this.client = new Client(options)
19+
20+
/** @type { import('./platform/apps') } */
1721
this.apps = new Apps(this)
22+
23+
/** @type { import('./platform/deviceprofiles') } */
1824
this.deviceProfiles = new DeviceProfiles(this)
25+
26+
/** @type { import('./platform/devices') } */
1927
this.devices = new Devices(this)
28+
29+
/** @type { import('./platform/installedapps') } */
2030
this.installedApps = new InstalledApps(this)
31+
32+
/** @type { import('./platform/locations') } */
2133
this.locations = new Locations(this)
34+
35+
/** @type { import('./platform/modes') } */
2236
this.modes = new Modes(this)
37+
38+
/** @type { import('./platform/scenes') } */
2339
this.scenes = new Scenes(this)
40+
41+
/** @type { import('./platform/schedules') } */
2442
this.schedules = new Schedules(this)
43+
44+
/** @type { import('./platform/subscriptions') } */
2545
this.subscriptions = new Subscriptions(this)
46+
47+
/** @type {String} */
2648
this.installedAppId = options.installedAppId
49+
50+
/** @type {String} */
2751
this.locationId = options.locationId
2852
}
2953
}

lib/pages/boolean-setting.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ module.exports = class BooleanSetting extends SectionSetting {
88
this._type = 'BOOLEAN'
99
}
1010

11-
image(value) {
12-
this._image = value
11+
/**
12+
* Set an image icon
13+
*
14+
* @param {String} source HTTPS url or Base64-encoded data URI. Max length 2048 characters.
15+
* @returns {BooleanSetting} Boolean Setting instance
16+
*/
17+
image(source) {
18+
this._image = source
1319
return this
1420
}
1521

22+
/**
23+
* Indicates if this input should refresh configs after a change in value.
24+
*
25+
* @param {String} value
26+
* @default false
27+
* @returns {BooleanSetting} Boolean Setting instance
28+
*/
1629
submitOnChange(value) {
1730
this._submitOnChange = value
1831
return this

lib/pages/color-setting.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict'
2+
3+
const SectionSetting = require('./section-setting.js')
4+
5+
module.exports = class ColorSetting extends SectionSetting {
6+
constructor(section, id) {
7+
super(section, id)
8+
this._type = 'COLOR'
9+
}
10+
11+
/**
12+
* Configure your image source
13+
*
14+
* @param {String} source HTTPS url or Base64-encoded data URI. Max length 2048 characters.
15+
* @returns {ColorSetting} Color Setting instance
16+
*/
17+
image(source) {
18+
this._image = source
19+
return this
20+
}
21+
22+
toJson() {
23+
const result = super.toJson()
24+
if (this._image) {
25+
result.image = this._image
26+
}
27+
28+
return result
29+
}
30+
}

lib/pages/decimal-setting.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,45 @@ module.exports = class DecimalSetting extends SectionSetting {
99
this._description = 'Tap to set'
1010
}
1111

12+
/**
13+
* The maximum inclusive value the decimal can be set to.
14+
*
15+
* @param {number} value Maximum value
16+
* @returns {DecimalSetting} Decimal Setting instance
17+
*/
1218
max(value) {
1319
this._max = value
1420
return this
1521
}
1622

23+
/**
24+
* The minimum inclusive value the decimal can be set to.
25+
*
26+
* @param {number} value Minimum value
27+
* @returns {DecimalSetting} Decimal Setting instance
28+
*/
1729
min(value) {
1830
this._min = value
1931
return this
2032
}
2133

22-
image(value) {
23-
this._image = value
34+
/**
35+
* Set an image icon
36+
*
37+
* @param {String} source HTTPS url or Base64-encoded data URI. Max length 2048 characters.
38+
* @returns {DecimalSetting} Decimal Setting instance
39+
*/
40+
image(source) {
41+
this._image = source
2442
return this
2543
}
2644

45+
/**
46+
* A string to be shown after the text input field.
47+
*
48+
* @param {String} value Max length 10 characters
49+
* @returns {DecimalSetting} Decimal Setting instance
50+
*/
2751
postMessage(value) {
2852
this._postMessage = value
2953
return this

0 commit comments

Comments
 (0)