Skip to content

Commit 281af90

Browse files
authored
fix: formatting, documentation, add ci, tests (#6)
* Replace eslintrc with xo * Apply xo formatting Apply markdown formatting guidelines * Add configurations semantic-release config circleci config codecov.yml config mocha debug configurations for vscode * Add initial code coverage * Add circleci build badge to readme
1 parent cf16295 commit 281af90

File tree

11 files changed

+529
-315
lines changed

11 files changed

+529
-315
lines changed

.circleci/config.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: 2.1
2+
3+
orbs:
4+
codecov: codecov/[email protected]
5+
6+
references:
7+
attach_workspace: &attach_workspace
8+
attach_workspace:
9+
at: ~/repo
10+
persist_to_workspace: &persist_to_workspace
11+
persist_to_workspace:
12+
root: ~/repo
13+
paths: .
14+
15+
executors:
16+
arwen:
17+
docker:
18+
- image: circleci/node:10.15.1
19+
working_directory: ~/repo
20+
21+
jobs:
22+
build:
23+
executor: arwen
24+
steps:
25+
- *attach_workspace
26+
- checkout
27+
# Download and cache dependencies
28+
- restore_cache:
29+
keys:
30+
- v1-dependencies-{{ checksum "package.json" }}
31+
# fallback to using the latest cache if no exact match is found
32+
- v1-dependencies-
33+
- run: npm install
34+
- save_cache:
35+
paths:
36+
- node_modules
37+
key: v1-dependencies-{{ checksum "package.json" }}
38+
- run: npm test
39+
- codecov/upload:
40+
file: .nyc_output/*.json
41+
- *persist_to_workspace
42+
publish:
43+
executor: arwen
44+
steps:
45+
- *attach_workspace
46+
- checkout
47+
- run: npm run semantic-release
48+
49+
workflows:
50+
build:
51+
jobs:
52+
- build:
53+
filters:
54+
branches:
55+
only: /.*/
56+
- publish:
57+
context: pi
58+
requires:
59+
- build
60+
filters:
61+
branches:
62+
only: master

.eslintrc.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

.vscode/launch.json

Lines changed: 33 additions & 0 deletions
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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Javascript DynamoDB Context Store
1+
# Javascript DynamoDB Context Store
22

3-
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
4-
and retrieves that information for use in asynchronous API calls. The use of a context store
5-
is only needed when SmartApps have to call the SmartThings API in response to external
6-
events. SmartApps that only response to lifecycle events from the SmartThings platform
7-
will automatically have the proper context without the app having to store it.
3+
[![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)
4+
5+
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.
86

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

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

20-
## Installation:
21-
```
18+
## Installation
19+
20+
```bash
2221
npm install @smartthings/dynamodb-context-store
2322
```
2423

2524
## Usage
2625

2726
Create a `DynamoDBContextStore` object and pass it to the SmartApp connector to store the context in a table
2827
named `"smartapp"` in the `us-east-1` AWS region. If the table does not exist it will be created.
28+
2929
```javascript
3030
smartapp.contextStore(new DynamoDBContextStore())
3131
```
3232

3333
The more extensive set of options are shown in this example:
34+
3435
```javascript
3536
smartapp.contextStore(new DynamoDBContextStore(
3637
{
@@ -48,6 +49,7 @@ smartapp.contextStore(new DynamoDBContextStore(
4849
```
4950

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

5860
Other configuration options are:
61+
5962
* **AWSRegion** -- The AWS region containing the table
6063
* **AWSConfigPath** -- The location of the AWS configuration JSON file
6164
* **AWSConfigJSON** -- The AWS credentials and region
@@ -67,6 +70,7 @@ Note that only one of the AWS options should be specified or behavior will be in
6770

6871
By default, the AWS credentials are picked up from the environment. If you prefer you can read the credentials
6972
from a file with this configuration:
73+
7074
```javascript
7175
smartapp.contextStore(new DynamoDBContextStore(
7276
{
@@ -75,8 +79,8 @@ smartapp.contextStore(new DynamoDBContextStore(
7579
))
7680
```
7781

78-
7982
You can also explicitly set the credentials in this way:
83+
8084
```javascript
8185
smartapp.contextStore(new DynamoDBContextStore(
8286
{
@@ -87,11 +91,13 @@ smartapp.contextStore(new DynamoDBContextStore(
8791
}
8892
}
8993
))
90-
````
94+
```
9195

9296
### Sort Key Configuration
97+
9398
In order to support single table schemas, the context store can be configured to use a table with a sort key.
9499
The simplest way to do that is by specifying the sort key name:
100+
95101
```javascript
96102
smartapp.contextStore(new DynamoDBContextStore(
97103
{
@@ -102,10 +108,11 @@ smartapp.contextStore(new DynamoDBContextStore(
102108
}
103109
}
104110
))
105-
106111
```
112+
107113
More control over the sort key can be exercised using this form, which is configured with the default values
108114
used when just the sort key name is specified:
115+
109116
```javascript
110117
smartapp.contextStore(new DynamoDBContextStore(
111118
{
@@ -121,5 +128,4 @@ smartapp.contextStore(new DynamoDBContextStore(
121128
}
122129
}
123130
))
124-
125131
```

config/codecov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ignore:
2+
- "[docs|doc]/**/*" # ignore docs
3+
- "[config|]/**/*" # ignore configs
4+
- "*.md" # ignore markdown
5+
6+
parsers:
7+
javascript:
8+
enable_partials: yes

config/release.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
plugins: [
3+
'@semantic-release/commit-analyzer',
4+
'@semantic-release/release-notes-generator',
5+
['@semantic-release/changelog', {
6+
changelogFile: 'docs/CHANGELOG.md'
7+
}],
8+
'@semantic-release/npm',
9+
['@semantic-release/git', {
10+
assets: ['docs', 'package.json'],
11+
message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
12+
}]
13+
]
14+
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
'use strict';
1+
'use strict'
22

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

0 commit comments

Comments
 (0)