{"id":18695328,"url":"https://github.com/smartthingscommunity/file-context-store-nodejs","last_synced_at":"2025-04-12T07:25:21.042Z","repository":{"id":90221938,"uuid":"320300731","full_name":"SmartThingsCommunity/file-context-store-nodejs","owner":"SmartThingsCommunity","description":"File-based context store for SmartApps","archived":false,"fork":false,"pushed_at":"2024-07-19T16:58:30.000Z","size":150,"stargazers_count":1,"open_issues_count":1,"forks_count":4,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-10T03:06:29.332Z","etag":null,"topics":[],"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.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-10T14:42:26.000Z","updated_at":"2024-07-19T16:58:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e3d50b8-746f-428a-a346-870f3b4c87c0","html_url":"https://github.com/SmartThingsCommunity/file-context-store-nodejs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffile-context-store-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffile-context-store-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffile-context-store-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Ffile-context-store-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartThingsCommunity","download_url":"https://codeload.github.com/SmartThingsCommunity/file-context-store-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248532221,"owners_count":21119877,"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":[],"created_at":"2024-11-07T11:14:40.254Z","updated_at":"2025-04-12T07:25:21.016Z","avatar_url":"https://github.com/SmartThingsCommunity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Javascript Local File Context Store\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 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.\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* **locale**: the locale client used to install the app\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* **config**: the current installed app instance configuration, i.e. selected devices, options, etc.\n\n## Installation\n\n```bash\nnpm install @smartthings/file-context-store\n```\n\n## Usage\n\nCreate a `FileContextStore` object and pass it to the SmartApp connector to store the context files in\ndirectory on the local machine.\n\n```javascript\nsmartapp.contextStore(new FileContextStore())\n```\n\nThe default storage is in a directory named `data` in the project location. \nTo locate the directory elsewhere specify the path to the directory to the \nconstructor.\n\n```javascript\nsmartapp.contextStore(new FileContextStore('/opt/data/smartapp'))\n```\n\n## Storage Formats\n\n### Installed App Context\n\nEach installedApp instance context record is stored as a JSON string in a file with the name\n`\u003cinstalledAppId\u003e.json` in the data directory. For example:\n```json\n{\n  \"installedAppId\": \"b643d57e-e2eb-40e4-b2ef-ff43519941cc\",\n  \"locationId\": \"8ea7ab21-932d-4256-80c6-abc53932dd3a\",\n  \"authToken\": \"f4b3b75c-091f-4b31-9833-7b52fe875ffb\",\n  \"refreshToken\": \"e980829a-9763-4105-b986-2d94114b1e80\",\n  \"clientId\": \"12475d16-ec68-490a-a708-6d390c112c7c\",\n  \"clientSecret\": \"2888d8f4-88b6-4741-a98e-54a267e6373b\",\n  \"config\": {\n    \"scenes\": [\n      {\n        \"valueType\": \"STRING\",\n        \"stringConfig\": {\n          \"value\": \"true\"\n        }\n      }\n    ],\n    \"switches\": [\n      {\n        \"valueType\": \"STRING\",\n        \"stringConfig\": {\n          \"value\": \"true\"\n        }\n      }\n    ],\n    \"locks\": [\n      {\n        \"valueType\": \"STRING\",\n        \"stringConfig\": {\n          \"value\": \"true\"\n        }\n      }\n    ]\n  }\n}\n```\n\n### State Storage\n\nState storage is a name-value store for the installed app instance. This is useful for storing information\nbetween invocations of the SmartApp. Each state property is stored in a separate file with the name\n`\u003cinstalledAppId\u003e/\u003cstateName\u003e.json` in the data directory. For example a numeric state property named \n`count` with a value of `5` would be stored in a file named `b643d57e-e2eb-40e4-b2ef-ff43519941cc/count.json`:\n```json\n5\n```\n## Caveats\n\nThis data store is intended for development testing use only, not in a production\nenvironment where scalability and redundancy is of primary concern.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Ffile-context-store-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartthingscommunity%2Ffile-context-store-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Ffile-context-store-nodejs/lists"}