npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@smartthings/file-context-store

v1.1.1

Published

Stores SmartApp configuration and auth tokens for use in app-initiated calls

Downloads

596

Readme

Javascript Local File Context Store

Used by the SmartApp SDK 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:

  • installedAppId: the UUID of the installed app instance. This is the primary key of the table.
  • locationId: the UUID of the location in which the app is installed
  • locale: the locale client used to install the app
  • authToken: the access token used in calling the API
  • refreshToken: the refresh token used in generating a new access token when one expires
  • config: the current installed app instance configuration, i.e. selected devices, options, etc.

Installation

npm install @smartthings/file-context-store

Usage

Create a FileContextStore object and pass it to the SmartApp connector to store the context files in directory on the local machine.

smartapp.contextStore(new FileContextStore())

The default storage is in a directory named data in the project location. To locate the directory elsewhere specify the path to the directory to the constructor.

smartapp.contextStore(new FileContextStore('/opt/data/smartapp'))

Storage Formats

Installed App Context

Each installedApp instance context record is stored as a JSON string in a file with the name <installedAppId>.json in the data directory. For example:

{
  "installedAppId": "b643d57e-e2eb-40e4-b2ef-ff43519941cc",
  "locationId": "8ea7ab21-932d-4256-80c6-abc53932dd3a",
  "authToken": "f4b3b75c-091f-4b31-9833-7b52fe875ffb",
  "refreshToken": "e980829a-9763-4105-b986-2d94114b1e80",
  "clientId": "12475d16-ec68-490a-a708-6d390c112c7c",
  "clientSecret": "2888d8f4-88b6-4741-a98e-54a267e6373b",
  "config": {
    "scenes": [
      {
        "valueType": "STRING",
        "stringConfig": {
          "value": "true"
        }
      }
    ],
    "switches": [
      {
        "valueType": "STRING",
        "stringConfig": {
          "value": "true"
        }
      }
    ],
    "locks": [
      {
        "valueType": "STRING",
        "stringConfig": {
          "value": "true"
        }
      }
    ]
  }
}

State Storage

State storage is a name-value store for the installed app instance. This is useful for storing information between invocations of the SmartApp. Each state property is stored in a separate file with the name <installedAppId>/<stateName>.json in the data directory. For example a numeric state property named count with a value of 5 would be stored in a file named b643d57e-e2eb-40e4-b2ef-ff43519941cc/count.json:

5

Caveats

This data store is intended for development testing use only, not in a production environment where scalability and redundancy is of primary concern.