Skip to content

fix: formatting, documentation, add ci, tests #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 2.1

orbs:
codecov: codecov/[email protected]

references:
attach_workspace: &attach_workspace
attach_workspace:
at: ~/repo
persist_to_workspace: &persist_to_workspace
persist_to_workspace:
root: ~/repo
paths: .

executors:
arwen:
docker:
- image: circleci/node:10.15.1
working_directory: ~/repo

jobs:
build:
executor: arwen
steps:
- *attach_workspace
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm test
- codecov/upload:
file: .nyc_output/*.json
- *persist_to_workspace
publish:
executor: arwen
steps:
- *attach_workspace
- checkout
- run: npm run semantic-release

workflows:
build:
jobs:
- build:
filters:
branches:
only: /.*/
- publish:
context: pi
requires:
- build
filters:
branches:
only: master
31 changes: 0 additions & 31 deletions .eslintrc.js

This file was deleted.

33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha All",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Mocha Current File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"${file}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Javascript DynamoDB Context Store
# Javascript DynamoDB Context Store

Used by the [SmartApp SDK](https://github.com/SmartThingsCommunity/smartapp-sdk-nodejs) to store IDs and access tokens for an installed instance of a SmartApp
and retrieves that information for use in asynchronous API calls. The use of a context store
is only needed when SmartApps have to call the SmartThings API in response to external
events. SmartApps that only response to lifecycle events from the SmartThings platform
will automatically have the proper context without the app having to store it.
[![CircleCI](https://circleci.com/gh/SmartThingsCommunity/dynamodb-context-store-nodejs/tree/master.svg?style=svg)](https://circleci.com/gh/SmartThingsCommunity/dynamodb-context-store-nodejs/tree/master)

Used by the [SmartApp SDK](https://github.com/SmartThingsCommunity/smartapp-sdk-nodejs) to store IDs and access tokens for an installed instance of a SmartApp and retrieves that information for use in asynchronous API calls. The use of a context store is only needed when SmartApps have to call the SmartThings API in response to external events. SmartApps that only response to lifecycle events from the SmartThings platform will automatically have the proper context without the app having to store it.

The context stored by this module consists of the following data elements:

Expand All @@ -17,20 +15,23 @@ The context stored by this module consists of the following data elements:
_Note: Version 2.X.X is a breaking change to version 1.X.X as far as configuring the context store is
concerned, but either one can be used with any version of the SmartThings SDK._

## Installation:
```
## Installation

```bash
npm install @smartthings/dynamodb-context-store
```

## Usage

Create a `DynamoDBContextStore` object and pass it to the SmartApp connector to store the context in a table
named `"smartapp"` in the `us-east-1` AWS region. If the table does not exist it will be created.

```javascript
smartapp.contextStore(new DynamoDBContextStore())
```

The more extensive set of options are shown in this example:

```javascript
smartapp.contextStore(new DynamoDBContextStore(
{
Expand All @@ -48,6 +49,7 @@ smartapp.contextStore(new DynamoDBContextStore(
```

The **table** configuration options are:

* **name** -- The name of the DynamoDB table storing the context
* **hashKey** -- The name of the partition key of the table
* **prefix** -- A string pre-pended to the installed app ID and used as the partition key for the entry
Expand All @@ -56,6 +58,7 @@ The **table** configuration options are:
* **sortKey** -- Optional sort key definition (see below for more details)

Other configuration options are:

* **AWSRegion** -- The AWS region containing the table
* **AWSConfigPath** -- The location of the AWS configuration JSON file
* **AWSConfigJSON** -- The AWS credentials and region
Expand All @@ -67,6 +70,7 @@ Note that only one of the AWS options should be specified or behavior will be in

By default, the AWS credentials are picked up from the environment. If you prefer you can read the credentials
from a file with this configuration:

```javascript
smartapp.contextStore(new DynamoDBContextStore(
{
Expand All @@ -75,8 +79,8 @@ smartapp.contextStore(new DynamoDBContextStore(
))
```


You can also explicitly set the credentials in this way:

```javascript
smartapp.contextStore(new DynamoDBContextStore(
{
Expand All @@ -87,11 +91,13 @@ smartapp.contextStore(new DynamoDBContextStore(
}
}
))
````
```

### Sort Key Configuration

In order to support single table schemas, the context store can be configured to use a table with a sort key.
The simplest way to do that is by specifying the sort key name:

```javascript
smartapp.contextStore(new DynamoDBContextStore(
{
Expand All @@ -102,10 +108,11 @@ smartapp.contextStore(new DynamoDBContextStore(
}
}
))

```

More control over the sort key can be exercised using this form, which is configured with the default values
used when just the sort key name is specified:

```javascript
smartapp.contextStore(new DynamoDBContextStore(
{
Expand All @@ -121,5 +128,4 @@ smartapp.contextStore(new DynamoDBContextStore(
}
}
))

```
8 changes: 8 additions & 0 deletions config/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ignore:
- "[docs|doc]/**/*" # ignore docs
- "[config|]/**/*" # ignore configs
- "*.md" # ignore markdown

parsers:
javascript:
enable_partials: yes
14 changes: 14 additions & 0 deletions config/release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
['@semantic-release/changelog', {
changelogFile: 'docs/CHANGELOG.md'
}],
'@semantic-release/npm',
['@semantic-release/git', {
assets: ['docs', 'package.json'],
message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
}]
]
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
'use strict'

module.exports = require('./lib/DynamoDBContextStore')
module.exports = require('./lib/dynamodb-context-store')
Loading