Skip to content

Commit 12af9fe

Browse files
authored
docs: context stores (#66)
* docs: update readme for context stores * docs: fix erroneous "app" in example * Add firestore-context-store links
1 parent a2d168f commit 12af9fe

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import SmartApp from '@smartthings/smartapp'
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.
4646
- [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
47+
- [x] [AWS DynamoDB](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs) plugin ([usage](#amazon-aws-dynamodb))
48+
- [x] [Firebase Cloud Firestore](https://github.com/SmartThingsCommunity/firestore-context-store-nodejs) plugin ([usage](#firebase-cloud-firestore))
4949

5050
## Roadmap
5151

@@ -72,7 +72,7 @@ const smartapp = new SmartApp()
7272
// @smartthings_rsa.pub is your on-disk public key
7373
// If you do not have it yet, omit publicKey()
7474
.publicKey('@smartthings_rsa.pub') // optional until app verified
75-
.app.enableEventLogging(2) // logs all lifecycle event requests and responses as pretty-printed JSON. Omit in production
75+
.enableEventLogging(2) // logs all lifecycle event requests and responses as pretty-printed JSON. Omit in production
7676
.configureI18n()
7777
.page('mainPage', (context, page, configData) => {
7878
page.section('sensors', section => {
@@ -142,6 +142,40 @@ Configuration page strings are specified in a separate `locales/en.json` file, w
142142
}
143143
```
144144

145+
### Making API calls outside of an EVENT handler
146+
147+
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.
148+
149+
> 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)!
150+
151+
To get started, let's add a compatible `ContextStore` plugin that will persist these tokens (among other things) to a database.
152+
153+
#### Amazon AWS DynamoDB
154+
155+
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).
156+
157+
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.
158+
159+
If you are self-hosted and still want to use DynamoDB, you can do that, too:
160+
161+
1. Import the package to your project: `npm i --save @smartthings/dynamodb-context-store`
162+
- *Note:* when adding this package, you also have `aws-sdk` available at the global scope, so you can configure the AWS SDK: `AWS.config.loadFromPath(creds)`
163+
1. Get an [AWS Access Key and Secret](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html)
164+
1. Set your credentials for your app, [any of the following ways are fine](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html).
165+
1. Register your Context Store plugin as described on [the project repository's readme.](https://github.com/SmartThingsCommunity/dynamodb-context-store-nodejs#usage)
166+
167+
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))
168+
169+
#### Firebase Cloud Firestore
170+
171+
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:
172+
173+
1. Generate a Firebase service account. You will receive a JSON file with the credentials.
174+
1. Load your Google Services JSON
175+
1. Create the context store
176+
177+
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))
178+
145179
---
146180

147181
## More about SmartThings

0 commit comments

Comments
 (0)