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/firestore-context-store

v3.0.0

Published

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

Downloads

6

Readme

firestore-context-store-nodejs

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

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
  • authToken: the access token used in calling the API
  • refreshToken: the refresh token used in generating a new access token when one expires
  • clientId: the SmartApp's client ID, used in generating a new access token
  • clientSecret: the SmartApp's client secret, used in generating a new access token
  • config: the current installed app instance configuration, i.e. selected devices, options, etc.v

Installation

npm install @smartthings/firestore-context-store --save

Usage

A note about usage

This package currently targets initializing Cloud Firestore from your own server by using a Service Account. If you are hosted on something like Firebase Cloud Functions or Google Cloud Platform, we don't currently support those methodologies – feel free to contribute!

To use this module to add Firebase Cloud Firestore context storage to your SmartApp, you should:

  1. Generate a service account. We use the Firebase Admin SDK. Go to IAM & admin > Service accounts in the Cloud Platform Console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK in the next step.

  2. require() your Google Services service account JSON file. Be certain that you don't ever commit this file to a public repository.

  3. Create a context store instance with the service account object and the document collection name and pass it to the SmartApp SDK object. For example, the following code:

const SmartApp = require('@smartthings/smartapp');
const FirestoreDBContextStore = require('@smartthings/firestore-context-store');
const serviceAccount = require('./googleservices-YOURAPPNAME-AND-ID.json')

const smartapp = new SmartApp()
  .contextStore(new FirestoreDBContextStore(serviceAccount, 'installedapps'))

This will use a document collection named installedapps to store documents as keyed by the installedAppId value.

Firebase Console

From the Firebase Cloud Firestore console, you will see a new document collection with persisted contexts.

img

More about SmartThings

If you are not familiar with SmartThings, we have extensive on-line documentation.

To create and manage your services and devices on SmartThings, create an account in the developer workspace.

The SmartThings Community is a good place share and ask questions.

There is also a SmartThings reddit community where you can read and share information.

License and Copyright

Licensed under the Apache License, Version 2.0

Copyright 2019 Samsung Electronics Co., LTD.