{"id":17549948,"url":"https://github.com/g-ray/masq-client","last_synced_at":"2025-10-06T18:13:27.962Z","repository":{"id":68799555,"uuid":"135162198","full_name":"G-Ray/masq-client","owner":"G-Ray","description":"Promise-based client library that allows applications to connect to Masq App to store and retrieve application data.","archived":false,"fork":false,"pushed_at":"2018-05-28T13:55:30.000Z","size":394,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T02:25:59.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/G-Ray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-05-28T13:06:51.000Z","updated_at":"2020-04-29T17:19:14.000Z","dependencies_parsed_at":"2023-02-22T03:45:26.020Z","dependency_job_id":null,"html_url":"https://github.com/G-Ray/masq-client","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/G-Ray%2Fmasq-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/G-Ray%2Fmasq-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/G-Ray%2Fmasq-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/G-Ray%2Fmasq-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/G-Ray","download_url":"https://codeload.github.com/G-Ray/masq-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999866,"owners_count":21031046,"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-10-21T03:57:07.614Z","updated_at":"2025-10-06T18:13:22.919Z","avatar_url":"https://github.com/G-Ray.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Masq Client\n\n[![](https://img.shields.io/badge/project-Masq-7C4DFF.svg?style=flat-square)](https://github.com/QwantResearch/masq-client)\n[![](https://api.travis-ci.org/QwantResearch/masq-client.svg)](https://travis-ci.org/QwantResearch/masq-client)\n\n![Masq Logo](https://i.imgur.com/qZ3dq0Q.png)\n\nPromise-based client library for Qwant Masq. It allows applications to connect to the [Masq App](https://github.com/QwantResearch/masq-app) (central data manager) to store and retrieve application data.\n\n# Install\n\n## Developer\n\n```\ngit clone https://github.com/QwantResearch/masq-client.git\ncd client\nnpm install\n```\n\n# Example usage\nInstall the package using npm:\n\n```bash\nnpm install --save git+https://github.com/QwantResearch/masq-client.git\n```\n\n\nUsing the client library in your app:\n\n```JavaScript\nimport MasqClient from 'masq-client'\n\n// Define the Masq App socket URL (where the data will be persisted)\nvar settings = {\n  socketUrl: 'ws://localhost:8080'\n}\n\n// Initialize the store\nvar masqStore = new MasqClient.Client(settings)\n```\n\n**NOTE:** You can find a fully working example in the [search demo app](https://github.com/QwantResearch/masq-demos).\n\n# API\n\n## Initialize the client\n\n```JavaScript\nvar settings = {}\n// first check if we have previously stored an authz token (more info below in the app registration)\nvar token = window.localStorage.getItem('token')\nif (token) {\n  settings['authToken'] = token\n}\n\nvar client = new Client(settings)\n\n// create a callback function that is called when an update is received from the server (typically following a sync event)\nvar pushCallback = function(msg) {\n  // update your local app data\n}\n\n// finally init the WebSocket client that connects to the store\nclient.initWS(pushCallback).then(function () {\n  // you can start using the client\n})\n```\n\n## Register an App\n\nBefore being able to use Masq to store application data, an application has to register itself with the Masq App in order to receive an *authorization* token.\n\nList of parameters:\n\n  * `url`: URL of the app to be registered\n  * `name`: name of the app\n  * `desc`: description of the app\n  * `icon`: URL of an icon for the app\n  \n```JavaScript\nvar regParams = {\n  url: 'http://example.org',\n  name: 'Example app',\n  desc: 'A generic app that uses Masq for storage',\n  icon: 'http://example.org/icon.png'\n}\n\ndocument.getElementById('registerButton').addEventListener('click', function () {\n  client.addApp(regParams).then(function (token) {\n    // store the authorization token for future use\n    window.localStorage.setItem('token', token)\n    // init your app logic\n  })\n})\n```\n\n## Store app data remotely\n\n```JavaScript\nvar key = 'hello'\nvar appData = {}\nappData.date = Date.now() // 1510847132596\nappData.text = 'Hello World!'\n\nclient.setItem(key, appData).then(function () {\n  // success\n}).catch(function (err) {\n  console.log(err)\n})\n```\n\n\n## Get the remote data for a given key\n\n```JavaScript\nvar key = 'hello'\n\nclient.getItem(key).then(function (data) {\n  console.log(data) // prints { date: 1510847132596, text: \"Hello World!\" }\n}).catch(function (err) {\n  console.log(err)\n})\n```\n\n\n## List all key for this app\n\n```JavaScript\nclient.listKeys().then(function (keys) {\n  console.log(keys) // prints ['hello']\n})\n```\n\n\n## Delete a specific key\n\n```JavaScript\nvar key = 'hello'\n\nclient.removeItem(key).then(function () {\n  // success, we have deleted the key \"hello\"\n})\n```\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg-ray%2Fmasq-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg-ray%2Fmasq-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg-ray%2Fmasq-client/lists"}