{"id":18695336,"url":"https://github.com/smartthingscommunity/firestore-context-store-nodejs","last_synced_at":"2025-04-12T07:25:21.708Z","repository":{"id":34840868,"uuid":"175466854","full_name":"SmartThingsCommunity/firestore-context-store-nodejs","owner":"SmartThingsCommunity","description":"Stores SmartApp configuration and auth tokens for use in app-initiated calls","archived":false,"fork":false,"pushed_at":"2024-02-06T22:12:32.000Z","size":530,"stargazers_count":2,"open_issues_count":15,"forks_count":9,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-11T10:42:47.134Z","etag":null,"topics":["firestore-database","nodejs","smartapp-sdk-nodejs","smartthings-smartapp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SmartThingsCommunity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-03-13T17:19:28.000Z","updated_at":"2024-05-30T11:41:31.000Z","dependencies_parsed_at":"2024-02-06T00:25:44.740Z","dependency_job_id":"cc42576d-6595-4e7a-9689-359bcfc2a6da","html_url":"https://github.com/SmartThingsCommunity/firestore-context-store-nodejs","commit_stats":{"total_commits":22,"total_committers":4,"mean_commits":5.5,"dds":"0.18181818181818177","last_synced_commit":"42316c2535b1cf9d928a8a5990b584a0786f2fdf"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffirestore-context-store-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffirestore-context-store-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffirestore-context-store-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffirestore-context-store-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartThingsCommunity","download_url":"https://codeload.github.com/SmartThingsCommunity/firestore-context-store-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248532223,"owners_count":21119878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firestore-database","nodejs","smartapp-sdk-nodejs","smartthings-smartapp"],"created_at":"2024-11-07T11:14:40.449Z","updated_at":"2025-04-12T07:25:21.679Z","avatar_url":"https://github.com/SmartThingsCommunity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# firestore-context-store-nodejs\n\n\u003e Stores SmartApp configuration and auth tokens for use in app-initiated calls\n\nUsed by the [SmartApp SDK](https://github.com/SmartThingsCommunity/smartapp-sdk-nodejs) to store IDs and access tokens for an installed instance of a SmartApp\nand retrieves that information for use in asynchronous API calls. The use of a context store\nis only needed when SmartApps have to call the SmartThings API in response to external\nevents. SmartApps that only response to lifecycle events from the SmartThings platform\nwill automatically have the proper context without the app having to store it.\n\nThe context stored by this module consists of the following data elements:\n\n- **installedAppId**: the UUID of the installed app instance. This is the primary key of the table.\n- **locationId**: the UUID of the location in which the app is installed\n- **authToken**: the access token used in calling the API\n- **refreshToken**: the refresh token used in generating a new access token when one expires\n- **clientId**: the SmartApp's client ID, used in generating a new access token\n- **clientSecret**: the SmartApp's client secret, used in generating a new access token\n- **config**: the current installed app instance configuration, i.e. selected devices, options, etc.v\n\n## Installation\n\n```shell\nnpm install @smartthings/firestore-context-store --save\n```\n\n## Usage\n\n### A note about usage\n\nThis 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](https://firebase.google.com/docs/functions/) or [Google Cloud Platform](https://cloud.google.com/), we don't currently support those methodologies – feel free to contribute!\n\nTo use this module to add Firebase Cloud Firestore context storage to your SmartApp, you should:\n\n1. **Generate a service account**. We use the Firebase Admin SDK. Go to IAM \u0026 admin \u003e 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.\n\n1. **`require()` your Google Services service account JSON file.** Be certain that you don't ever commit this file to a public repository.\n\n1. **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:\n\n```javascript\nconst SmartApp = require('@smartthings/smartapp');\nconst FirestoreDBContextStore = require('@smartthings/firestore-context-store');\nconst serviceAccount = require('./googleservices-YOURAPPNAME-AND-ID.json')\n\nconst smartapp = new SmartApp()\n  .contextStore(new FirestoreDBContextStore(serviceAccount, 'installedapps'))\n```\n\nThis will use a document collection named `installedapps` to store documents as keyed by the `installedAppId` value.\n\n### Firebase Console\n\nFrom the Firebase Cloud Firestore console, you will see a new document collection with persisted contexts.\n\n![img](docs/example_console.png)\n\n## More about SmartThings\n\nIf you are not familiar with SmartThings, we have\n[extensive on-line documentation](https://smartthings.developer.samsung.com/develop/index.html).\n\nTo create and manage your services and devices on SmartThings, create an account in the\n[developer workspace](https://devworkspace.developer.samsung.com/).\n\nThe [SmartThings Community](https://community.smartthings.com/c/developers/) is a good place share and\nask questions.\n\nThere is also a [SmartThings reddit community](https://www.reddit.com/r/SmartThings/) where you\ncan read and share information.\n\n## License and Copyright\n\nLicensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n\nCopyright 2019 Samsung Electronics Co., LTD.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Ffirestore-context-store-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartthingscommunity%2Ffirestore-context-store-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Ffirestore-context-store-nodejs/lists"}