Skip to content

Commit 37fdf3b

Browse files
authored
Documentation cleanup (#208)
* adding revised readme + minor ref doc typo cleanups * minor revisions to v2.0 compatibility text * addressing reviewer comments
1 parent f6b6c40 commit 37fdf3b

File tree

4 files changed

+81
-65
lines changed

4 files changed

+81
-65
lines changed

README.md

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SmartThings SmartApp NodeJS SDK
1+
# SmartThings SmartApp Node.js SDK
22

33
<p align="center">
44
<a href="https://www.npmjs.com/package/@smartthings/smartapp"><img src="https://badgen.net/npm/v/@smartthings/smartapp"/></a>
@@ -12,20 +12,47 @@
1212
<a href="https://smartthingsdev.slack.com/messages/CG595N08N"><img src="https://badgen.net/badge//smartthingsdev?icon=slack"/></a>
1313
</p>
1414

15-
#### [Reference Documentation](docs/index.md)
15+
## Reference Documentation
1616

17-
SDK that wraps the SmartThings REST API and reduces the amount of code necessary to write a SmartApp app. It supports
18-
both webhook and AWS Lambda implementations. This is a preview version of the API and will change over time time.
17+
For a detailed look at the API, check out the [reference documentation](docs/index.md).
1918

20-
## Version 2.0 Release
19+
## Getting Started
2120

22-
_ATTENTION! This major release is not completely backwardly compatible with the 1.X version, though for most
23-
SmartApps the changes required should be relatively minor. The major non-backwardly changes are:_
24-
* _Methods that return lists now return arrays rather that an object with the properties `items` and `_links`._
25-
* _Axios is now used rather than request-promise-native for making HTTP calls, resulting in changes to the error
26-
objects thrown when exceptions occur._
21+
>**Version 2.0 Release**
22+
>
23+
>This major release is not fully backwards compatible with version 1.X, though for most SmartApps the changes required should be relatively minor. The major non-backwards compatible changes include:
24+
>* Methods that return lists now return arrays instead of objects with the properties `items` and `_links`.
25+
>* Axios is now used rather than request-promise-native for making HTTP calls, resulting in changes to the error
26+
objects thrown when exceptions occur.
27+
>
28+
>See the [Version 2.0.0 release notes](docs/V2_RELEASE_NOTES.md) for more information.
2729
28-
_See the [Version 2.0.0 release notes](docs/V2_RELEASE_NOTES.md) for more information._
30+
This SDK includes a set of Node.js libraries for building Webhook and AWS Lambda SmartApps, and interacting with the public SmartThings API.
31+
32+
Highlights include:
33+
34+
- ✅ Javascript API hides details of REST calls and authentication.
35+
- ✅ Event handler framework dispatches lifecycle events to named event handlers.
36+
- ✅ Configuration page API simplifies page definition.
37+
- ✅ Integrated [i18n](https://www.npmjs.com/package/i18n) framework provides configuration page localization.
38+
-[Winston](https://www.npmjs.com/package/winston) framework manges log messages.
39+
- ✅ Context Store plugins – easily scale access token management (and more) to support many users.
40+
-[AWS DynamoDB](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs) plugin ([usage](#amazon-aws-dynamodb))
41+
-[Firebase Cloud Firestore](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs) plugin ([usage](#firebase-cloud-firestore))
42+
43+
### What is a SmartApp?
44+
45+
SmartApps are custom applications that execute outside of the SmartThings Platform. All of the SmartApp execution will happen on the server or Lambda that you control. The complexity of execution and the number of expected users will need to be examined to understand the hardware or execution requirements your app needs to handle. Your application will respond to lifecycle events sent from SmartThings to perform actions on behalf of your users and will execute any scheduled tasks that you have created in the SmartApp. Creating a SmartApp allows you to control and get status notifications from SmartThings devices using the SmartThings API.
46+
47+
#### Hosting Your SmartApp
48+
49+
There are two distinct options for hosting your SmartApp: AWS Lambda and Webhook.
50+
51+
- **Webhook** SmartApps are any publicly-accessible web server that will receive a POST request payload.
52+
53+
- **AWS Lambda** SmartApps are hosted in the Amazon Web Services cloud and are invoked by ARN instead of a public-DNS address.
54+
55+
To learn more about SmartApps, including choosing the best hosting solution for your SmartApp, visit the [SmartApp developer documentation](https://developer-preview.smartthings.com/docs/connected-services/smartapp-basics).
2956

3057
## Installation
3158

@@ -35,7 +62,7 @@ npm i @smartthings/smartapp --save
3562

3663
## Importing
3764

38-
`NodeJS`:
65+
`Node.js`:
3966

4067
```javascript
4168
const SmartApp = require('@smartthings/smartapp')
@@ -47,24 +74,15 @@ Or `ES2015`+:
4774
import SmartApp from '@smartthings/smartapp'
4875
```
4976

50-
## Highlights
51-
52-
- [x] Javascript API hides details of REST calls and authentication.
53-
- [x] Event handler framework dispatches lifecycle events to named event handlers.
54-
- [x] Configuration page API simplifies page definition.
55-
- [x] Integrated [i18n](https://www.npmjs.com/package/i18n) framework provides configuration page localization.
56-
- [x] [Winston](https://www.npmjs.com/package/winston) framework manges log messages.
57-
- [x] Context Store plugins – easily scale access token management (and more) to support many users
58-
- [x] [AWS DynamoDB](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs) plugin ([usage](#amazon-aws-dynamodb))
59-
- [x] [Firebase Cloud Firestore](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs) plugin ([usage](#firebase-cloud-firestore))
60-
6177
## Examples
6278

63-
The following example automation is the equivalent of a simple Rule (if contact sensor opens/closes, turn lights on/off) which is easily achieved via our [Rules API](https://smartthings.developer.samsung.com/docs/rules/overview.html). It is given here as a brief showcase of the SDK, and not meant to be a good candidate for a SmartApp. Be sure to check if your automation is possible with the Rules API, as it will benefit from speed, stability, and security through future local execution support.
79+
The example SmartApp below is the equivalent of a simple Rule (if contact sensor opens/closes, turn lights on/off) which is easily achieved via our Rules API. It is given here as a brief showcase of the SDK, and is not meant to be a good candidate for a SmartApp.
6480

65-
### Running it as a web service
81+
>Before hosting your own Automation, be sure to check out [Rules](https://developer-preview.smartthings.com/docs/automations/rules). When all services and Device features involved in a Rule are local, Rules execute locally on a Hub, allowing you to benefit from greater speed, stability, and security than cloud-reliant solutions.
6682
67-
To run the app with an HTTP server, like Express.js:
83+
### Running as a Web Service
84+
85+
To run your SmartApp with an HTTP server, such as Express.js:
6886

6987
```javascript
7088
const SmartApp = require('@smartthings/smartapp');
@@ -111,11 +129,11 @@ server.post('/', function (req, res, next) {
111129
server.listen(PORT, () => console.log(`Server is up and running on port ${PORT}`));
112130
```
113131

114-
### Running as an AWS Lambda function
132+
### Running as an AWS Lambda Function
115133

116-
To run as a Lambda function instead of an HTTP server, ensure that your main entry file exports `smartapp.handleLambdaCallback(...)`.
134+
To run your SmartApp as a Lambda function instead of an HTTP server, ensure that your main entry file exports `smartapp.handleLambdaCallback(...)`.
117135

118-
> **Note:** This snippet is heavily truncated for brevity.
136+
Note that this snippet is heavily truncated for brevity:
119137

120138
```javascript
121139
const SmartApp = require('@smartthings/smartapp');
@@ -130,17 +148,20 @@ exports.handler = (event, context, callback) => {
130148
smartapp.handleLambdaCallback(event, context, callback);
131149
};
132150
```
133-
There are also a few Glitch examples:
151+
152+
### Additional Examples
153+
154+
You can find additional examples in Glitch:
134155

135156
- [Simple SmartThings Automation App using Contact Sensors](https://glitch.com/edit/#!/south-mayonnaise?path=README.md:1:0)
136157
- [Simple SmartThings Automation App using Motion Detectors](https://glitch.com/edit/#!/polite-math?path=README.md:1:0)
137158
- [Simple Switch Cloud-to-Cloud (C2C) App](https://glitch.com/edit/#!/aquamarine-crop?path=README.md:1:0)
138159

139-
More detailed examples to use as a starting point can be found with our [smartthings-smartapp-example](https://github.com/topics/smartthings-smartapp-example) Github Topic.
160+
More detailed examples to use as a starting point can be found in our [smartthings-smartapp-example](https://github.com/topics/smartthings-smartapp-example) Github Topic.
140161

141-
### Localization
162+
## Localization
142163

143-
Configuration page strings are specified in a separate `locales/en.json` file, which can be automatically created the first time you run the app. Here's a completed English localization file for the previous example:
164+
Configuration page strings are specified in a separate `locales/en.json` file, which can be automatically created the first time you run the app. Here's a completed English localization file for the previous simple SmartApp example:
144165

145166
```json
146167
{
@@ -153,25 +174,25 @@ Configuration page strings are specified in a separate `locales/en.json` file, w
153174
}
154175
```
155176

156-
### Unhandled Promise Rejection Handling
177+
## Unhandled Promise Rejection Handling
178+
179+
By default, instantiation of the SmartApp object registers an `unhandledReject` handler that logs unhandled promise rejections. You can disable this behavior by passing an option to the SmartApp instantiation (e.g. `new SmartApp({logUnhandledRejections: false})`).
157180

158-
By default, instantiation of the SmartApp object registers an "unhandledReject" handler
159-
that logs unhandled promise rejections. If you don't want this behavior you can disable
160-
it by passing an option to the SmartApp instantiation, e.g. `new SmartApp({logUnhandledRejections: false})`.
161-
If you want to replace the handler you can do that by calling `unhandledRejectionHandler(promise => {...})`
162-
on the SmartApp object.
181+
If desired, you can replace the handler by calling `unhandledRejectionHandler(promise => {...})` on the SmartApp object.
163182

164-
### Making API calls outside of an EVENT handler
183+
## Making API Calls Outside of an `EVENT` Handler
165184

166-
By default, the SmartApp SDK will facilitate API calls on behalf of a user within the `EVENT` lifecycle. These user tokens are ephemeral and last *5 minutes*. These access tokens are not able to be refreshed and should _not_ be stored. If you're making out-of-band API calls on behalf of a user's installed app, you will need to use the 24-hour access token that are supplied after `INSTALL` and `UPDATE` lifecycles. This token includes a `refresh_token`, and will be automatically refreshed by the SDK when necessary.
185+
By default, the SmartApp SDK will facilitate API calls on behalf of a user within the `EVENT` lifecycle. These user tokens are ephemeral and last *5 minutes*. These access tokens are not able to be refreshed and should _not_ be stored.
167186

168-
> Be aware that **there is no in-memory context store**, you must use a context store plugin. If you'd like to add a custom context store plugin, please [contribute](CONTRIBUTING.md)!
187+
If you are making out-of-band API calls on behalf of a user's installed app, you will need to use the 24-hour access token that is supplied after the `INSTALL` and `UPDATE` lifecycles. This token includes a `refresh_token`, and will automatically be refreshed by the SDK when necessary.
169188

170-
To get started, let's add a compatible `ContextStore` plugin that will persist these tokens (among other things) to a database.
189+
>Note that **there is no in-memory context store**; you must use a context store plugin. If you'd like to add a custom context store plugin, please consider [contributing](CONTRIBUTING.md).
171190
172-
#### Amazon AWS DynamoDB
191+
To get started with our context store example below, we will add a compatible `ContextStore` plugin that will persist these tokens (among other things) to a database.
173192

174-
Available as a node package on [NPM](https://www.npmjs.com/package/@smartthings/dynamodb-context-store) or [fork on GitHub](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs/fork).
193+
### Amazon AWS DynamoDB
194+
195+
>Available as a node package on [NPM](https://www.npmjs.com/package/@smartthings/dynamodb-context-store) or [fork on GitHub](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs/fork).
175196
176197
If you are hosting your SmartApp as an AWS Lambda, this DynamoDB context store makes perfect sense. This assumes you've already configured the [`aws-sdk`](https://www.npmjs.com/package/aws-sdk) package to interact with your Lambda, so extending your context store to DynamoDB is a drop-in solution.
177198

@@ -185,21 +206,22 @@ If you are self-hosted and still want to use DynamoDB, you can do that, too:
185206

186207
For complete directions on usage, please see this project's GitHub repository. ([SmartThingsCommunity/dynamodb-context-store-nodejs](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs))
187208

188-
#### Firebase Cloud Firestore
209+
### Firebase Cloud Firestore
210+
211+
>Available as a node package on [NPM](https://www.npmjs.com/package/@smartthings/firestore-context-store) or [fork on GitHub](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs/fork).
189212
190-
Available as a node package on [NPM](https://www.npmjs.com/package/@smartthings/firestore-context-store) or [fork on GitHub](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs/fork). Usage is generally the same as DynamoDB:
213+
Usage is generally the same as DynamoDB:
191214

192215
1. Generate a Firebase service account. You will receive a JSON file with the credentials.
193216
1. Load your Google Services JSON
194217
1. Create the context store
195218

196-
See the full usage guide on the project's GitHub repository. ([SmartThingsCommunity/firestore-context-store-nodejs](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs#usage))
219+
See the full usage guide on the [project's GitHub repository](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs#usage).
197220

198221
---
199222
## More about SmartThings
200223

201-
If you are not familiar with SmartThings, we have
202-
[extensive on-line documentation](https://smartthings.developer.samsung.com/develop/index.html).
224+
Check out our complete developer documentation [here](https://developer-preview.smartthings.com/docs/getting-started/welcome/).
203225

204226
To create and manage your services and devices on SmartThings, create an account in the
205227
[developer workspace](https://devworkspace.developer.samsung.com/).

docs/classes/_pages_boolean_setting_d_.booleansetting.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# BooleanSetting
44

5-
A boolean setting creates a toggle control that can be turned on an off by the user.
5+
A boolean setting creates a toggle control that can be turned on and off by the user.
66
```
77
section.booleanSetting('turnBackOn')
88
```
@@ -167,4 +167,3 @@ Name | Type |
167167
`value` | string |
168168

169169
**Returns:** *[BooleanSetting](_pages_boolean_setting_d_.booleansetting.md)*
170-

docs/classes/_pages_device_setting_d_.devicesetting.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ section.deviceSetting("motionSensors")
3333

3434
**capabilities**(`items`: string[]): *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
3535

36-
Sets the required capabilities for the devices in the select options.
37-
To appear in the select list devices must have all of these
38-
capabilities.
36+
Sets the required capabilities for the devices in the selection options.
37+
To appear in the selection list, devices must have all of the specified capabilities.
3938

4039
**Parameters:**
4140

@@ -51,7 +50,7 @@ ___
5150

5251
**capability**(`item`: string): *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
5352

54-
Sets the required capability for the devices in the select options.
53+
Sets the required capability for the devices in the selection options.
5554

5655
**Parameters:**
5756

@@ -137,7 +136,7 @@ ___
137136

138137
**excludeCapabilities**(`items`: string[]): *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
139138

140-
Devices with these capabilities will be excluded from the select options
139+
Devices with these capabilities will be excluded from the selection options
141140
even though they match the criteria specified in the `capabilities()` method
142141

143142
**Parameters:**
@@ -154,7 +153,7 @@ ___
154153

155154
**excludeCapability**(`item`: string): *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
156155

157-
Devices with this capability will be excluded from the select options
156+
Devices with this capability will be excluded from the selection options
158157
even though they match the criteria specified in the `capabilities()` method
159158

160159
**Parameters:**
@@ -208,8 +207,8 @@ ___
208207
**permissions**(`value`: string | string[] | [PermissionsEnum](../enums/_pages_device_setting_d_.permissionsenum.md)[]): *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
209208

210209
The required permissions for the selected device(s). This value can be
211-
specified as a string (`rwx`), and array of strings(`['r','w','x']`), or
212-
and array of typescript enum values (`[PermissionsEnum.R, PermissionsEnum.W, PermissionsEnum.X]`)
210+
specified as a string (`rwx`), an array of strings(`['r','w','x']`), or
211+
an array of typescript enum values (`[PermissionsEnum.R, PermissionsEnum.W, PermissionsEnum.X]`)
213212

214213
**Parameters:**
215214

@@ -295,4 +294,3 @@ Name | Type |
295294
`value` | string |
296295

297296
**Returns:** *[DeviceSetting](_pages_device_setting_d_.devicesetting.md)*
298-

docs/index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# SmartApp SDK Reference
22

3-
The [SmartApp](classes/_smart_app_d_.smartapp.md) class handles all SmartApp
4-
[lifecycle events](https://smartthings.developer.samsung.com/docs/smartapps/lifecycles.html)
5-
and callbacks. It is instantiated and configured with handlers for appropriate and invoked
6-
in response to either web-server HTTP requests or AWS Lambda function calls.
3+
The [SmartApp](classes/_smart_app_d_.smartapp.md) class handles all SmartApp [lifecycle events](https://developer-preview.smartthings.com/docs/connected-services/lifecycles) and callbacks. It is instantiated and configured with handlers where appropriate and is invoked in response to either web server HTTP requests, or in response to AWS Lambda function calls.
74

85
## Instantiation and Initialization
96

0 commit comments

Comments
 (0)