{"bugs":{"url":"https://github.com/streamr-dev/streamr-client/issues"},"dist":{"shasum":"4fcbdd30ec2f9b6bfd7e51ba172193806b9e4be8","tarball":"https://registry.npmjs.org/streamr-client/-/streamr-client-2.0.0-beta.5.tgz","fileCount":62,"integrity":"sha512-m9MwSHqNigg5hCuc9ag+Hgr8cyEAYk8eJJtk/froCcJSKjbSzFTSL7U6DpsfDgFTMHa04+DGSbJXCkDHelCnXQ==","signatures":[{"sig":"MEYCIQDpUt85Otp++yBlZK3ei4HCqmIGOdllUwaCzrWuubu9ngIhALmzojdB7eIpMBJrTJK9GQnUjZquFcDMIDliC7hN6kXG","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4882367,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcrww2CRA9TVsSAnZWagAAfk0P/3lMelOCXMCaqoiXz1Ge\nkCi5AwPGMH1dx8lvpTWxzT9Y6fcmwonEruAZhB6JiW4aXxlI2t2zx7zP10mN\n7W0CQfW7vc0X/OMWxVOEi06IjOGUpbDy3p7esYsXcWM4IJGnNTE9ynzaHwHX\n8zFW68+dIT67YN6Badz2292Ec1spy9RpwE+KWR0aTSVfOTeX/Xcphlt6KDbS\nh/ygrBZ4iNFMW4AV2Yvk1PHLC/GrrXswJCo8r6vefXA7EkRlLHahVSOFK+9d\nHR2IwacU/zDgwOY4rP3JL1Q5k21M2MS16z9HFUpBKK19dTGqpPVc//dB/A6e\ni+j+JYqn/7liOIyc4mQwi4mPN0Z1syEv+hu86HB3FJd88vXwb9DmyZhl02W0\n1nqboba2b4PJAxtjLUzFb7xFItyRLWnOyHe3EkzodfA+uAVb63V/f4EnJtla\npmzN2cT+wafLWFIlCLMy9UbLD/y+2VFO6XAvHBfS2H/4BqwYkOKDoAAO3Y/U\nPHQCr+K45Od3Y2osynfJ0hJo6P1k/u2kmt3Ri50YlYnVk7swgT0YxBPfKhW3\n5Dm1WoobXy4jo3opZTbQYGikcp313NmF3U42O+WkDQqHKZrLaupGh5Guh0k8\nHoAYVyr7f/aDCDRhh3b0G8BSn38d5yf/jucSSUuRk6I1ubZkPrfzZx72t/LF\n/xFs\r\n=Kzkv\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/streamr-client.js","name":"streamr-client","author":{"name":"Streamr"},"readme":"[![Build Status](https://travis-ci.com/streamr-dev/streamr-client-javascript.svg?branch=master)](https://travis-ci.com/streamr-dev/streamr-client-javascript)\n\n## Streamr JavaScript Client\n\nBy using this client, you can easily interact with the [Streamr](http://www.streamr.com) API from JavaScript-based environments, such as browsers and [node.js](https://nodejs.org). You can, for example, subscribe to real-time data in Streams, produce new data to Streams, and create new Streams.\n\nThis library is work-in-progress and doesn't provide wrapper functions for all the endpoints in the Streamr API. Currently it covers producing and subscribing to data as well as manipulating Stream objects.\n\nThe client uses websockets for producing and consuming messages to/from streams. It should work in all modern browsers.\n\n### Installation\n\nThe client is available on [npm](https://www.npmjs.com/package/streamr-client) and can be installed simpy by:\n\n`npm install streamr-client`\n\n### Usage\n\nHere are some quick examples. More detailed examples for the browser and node.js can be found [here](https://github.com/streamr-dev/streamr-client/tree/master/examples).\n\n#### Creating a StreamrClient instance\n\n```javascript\nconst client = new StreamrClient({\n    // See below for more options\n    auth: {\n        apiKey: 'your-api-key'\n    }\n})\n```\n\n#### Subscribing to real-time events in a stream\n\n```javascript\nconst sub = client.subscribe(\n    {\n        stream: 'streamId',\n        apiKey: 'secret',       // Optional. If not given, uses the apiKey given at client creation time.\n        partition: 0,           // Optional, defaults to zero. Use for partitioned streams to select partition.\n        // optional resend options here\n    },\n    (message, metadata) => {\n        // This is the message handler which gets called for every incoming message in the Stream.\n        // Do something with the message here!\n    }\n)\n```\n\n#### Programmatically creating a Stream\n\n```javascript\nclient.getOrCreateStream({\n    name: 'My awesome Stream created via the API',\n})\n    .then((stream) => {\n        console.log(`Stream ${stream.id} has been created!`)\n        // Do something with the Stream, for example call stream.publish(message)\n    })\n```\n\n#### Producing data points to a Stream\n\n```javascript\n// Here's our example data point\nconst msg = {\n    temperature: 25.4,\n    humidity: 10,\n    happy: true\n}\n\n// Publish using the Stream id only\nclient.publish('my-stream-id', msg)\n\n// Or alternatively, via the Stream object (from e.g. getOrCreateStream)\nstream.publish(msg)\n```\n\n### Client options\n\nOption | Default value | Description\n------ | ------------- | -----------\nurl | wss://www.streamr.com/api/v1/ws | Address of the Streamr websocket endpoint to connect to.\nrestUrl | https://www.streamr.com/api/v1 | Base URL of the Streamr REST API.\nauth | {} | Object that can contain different information to authenticate. More details below.\npublishWithSignature | 'auto' | Determines if data points published to streams are signed or not. Possible values are: 'auto', 'always' and 'never'. Signing requires `auth.privateKey` or `auth.provider`.  'auto' will sign only if one of them is set. 'always' will throw an exception if none of them is set.\nverifySignatures | 'auto' | Determines under which conditions signed and unsigned data points are accepted or rejected. 'always' accepts only signed and verified data points. 'never' accepts all data points. 'auto' verifies all signed data points before accepting them and accepts unsigned data points only for streams not supposed to contain signed data.\nautoConnect | true | If set to `true`, the client connects automatically on the first call to `subscribe()`. Otherwise an explicit call to `connect()` is required.\nautoDisconnect | true  | If set to `true`, the client automatically disconnects when the last stream is unsubscribed. Otherwise the connection is left open and can be disconnected explicitly by calling `disconnect()`.\nmaxPublishQueueSize | 10000 | Only in effect when `autoConnect = true`. Controls the maximum number of messages to retain in internal queue when client has disconnected and is reconnecting to Streamr.\n\n### Authentication options\n\nAuthenticating with an API key (you can manage your API keys in the [Streamr web app](https://www.streamr.com)):\n```\nnew StreamrClient({\n    auth: {\n        apiKey: 'your-api-key'\n    }\n})\n```\nAuthenticating with an Ethereum private key by cryptographically signing a challenge (also automatically creates an associated user account):\n```\nnew StreamrClient({\n    auth: {\n        privateKey: 'your-private-key'\n    }\n})\n```\nAuthenticating with an Ethereum private key contained in an Ethereum (web3) provider:\n```\nnew StreamrClient({\n    auth: {\n        provider: web3.currentProvider,\n    }\n})\n```\n(Authenticating with an username and password, for internal use by the Streamr app):\n```\nnew StreamrClient({\n    auth: {\n        username: 'my@email.com',\n        password: 'password'\n    }\n})\n```\n(Authenticating with a pre-existing session token, for internal use by the Streamr app):\n```\nnew StreamrClient({\n    auth: {\n        sessionToken: 'session-token'\n    }\n})\n```\n\n### Message handler callback\n\nThe second argument to `client.subscribe(options, callback)` is the callback function that will be called for each message as they arrive. Its arguments are as follows:\n\nArgument | Description\n-------- | -----------\npayload  | A JS object containing the message payload itself\nstreamMessage | The whole [StreamMessage](https://github.com/streamr-dev/streamr-client-protocol-js/blob/master/src/protocol/message_layer/StreamMessage.js) object containing various metadata, for example `streamMessage.getTimestamp()` etc.\n\n### StreamrClient object\n\n#### Connecting\n\nName | Description\n---- | -----------\nconnect() | Connects to the server, and also subscribes to any streams for which `subscribe()` has been called before calling `connect()`. Returns a Promise. Rejects if already connected or connecting.\ndisconnect() | Disconnects from the server, clearing all subscriptions. Returns a Promise.  Rejects if already disconnected or disconnecting.\npause() | Disconnects from the server without clearing subscriptions.\nensureConnected() | Safely connects if not connected. Returns a promise. Resolves immediately if already connected. Only rejects if an error occurs during connection.\nensureDisconnected() | Safely disconnects if not disconnected. Returns a promise. Resolves immediately if already disconnected. Only rejects if an error occurs during disconnection.\n\n#### Managing subscriptions\n\nName | Description\n---- | -----------\nsubscribe(options, callback) | Subscribes to a stream. Messages in this stream are passed to the `callback` function. See below for subscription options. Returns a `Subscription` object.\nunsubscribe(Subscription) | Unsubscribes the given `Subscription`.\nunsubscribeAll(`streamId`) | Unsubscribes all `Subscriptions` for `streamId`.\ngetSubscriptions(`streamId`) | Returns a list of `Subscriptions` for `streamId`.\n\n#### Stream API\n\nAll the below functions return a Promise which gets resolved with the result. They can also take an `apiKey` as an extra argument. Otherwise the `apiKey` defined in the `StreamrClient` options is used, if any.\n\nName | Description\n---- | -----------\ngetStream(streamId) | Fetches a Stream object from the API.\nlistStreams(query) | Fetches an array of Stream objects from the API. For the query params, consult the API docs.\ngetStreamByName(name) | Fetches a Stream which exactly matches the given name.\ncreateStream(properties) | Creates a Stream with the given properties. For more information on the Stream properties, consult the API docs.\ngetOrCreateStream(properties) | Gets a Stream with the id or name given in `properties`, or creates it if one is not found.\npublish(streamId, message) | Publishes a new message (data point) to the given Stream.\n\n#### Listening to state changes of the client\n\non(eventName, function) | Binds a `function` to an event called `eventName`\nonce(eventName, function) | Binds a `function` to an event called `eventName`. It gets called once and then removed.\nremoveListener(eventName, function) | Unbinds the `function` from events called `eventName`\n\n### Stream object\n\nAll the below functions return a Promise which gets resolved with the result. They can also take an `apiKey` as an extra argument. Otherwise the `apiKey` defined in the `StreamrClient` options is used, if any.\n\nName | Description\n---- | -----------\nupdate() | Updates the properties of this Stream object by sending them to the API.\ndelete() | Deletes this Stream.\ngetPermissions() | Returns the list of permissions for this Stream.\ndetectFields() | Updates the Stream field config (schema) to match the latest data point in the Stream.\npublish(message) | Publishes a new message (data point) to this Stream.\n\n### Subscription options\n\nNote that only one of the resend options can be used for a particular subscription. The default functionality is to resend nothing, only subscribe to messages from the subscription moment onwards.\n\nName | Description\n---- | -----------\nstream    | Stream id to subscribe to\npartition | Partition number to subscribe to. Defaults to the default partition (0).\nresend | Object defining the resend options. Below are examples of its contents.\n\n```javascript\n// Resend N most recent messages\nresend: {\n    last: 10,\n}\n\n// Resend from a specific message reference up to the newest message\nresend: {\n    from: {\n        timestamp: 12345,\n        sequenceNumber: 0, // optional\n    }\n    publisher: 'publisherId', // optional\n    msgChainId: 'msgChainId', // optional\n}\n\n// Resend a limited range of messages\nresend: {\n    from: {\n        timestamp: 12345,\n        sequenceNumber: 0, // optional\n    },\n    to: {\n        timestamp: 54321,\n        sequenceNumber: 0, // optional\n    },\n    publisher: 'publisherId', // optional\n    msgChainId: 'msgChainId', // optional\n}\n```\n\n### Binding to events\n\nThe client and the subscriptions can fire events as detailed below. You can bind to them using `on`:\n\n```javascript\n    // The StreamrClient emits various events\n\tclient.on('connected', () => {\n\t    console.log('Yeah, we are connected now!')\n\t})\n\n    // So does the Subscription object\n\tconst sub = client.subscribe(...)\n\tsub.on('subscribed', () => {\n\t    console.log(`Subscribed to ${sub.streamId}`)\n\t})\n```\n\n### Events on the StreamrClient instance\n\nName | Handler Arguments | Description\n---- | ----------------- | -----------\nconnected |  | Fired when the client has connected (or reconnected).\ndisconnected |  | Fired when the client has disconnected (or paused).\n\n### Events on the Subscription object\n\nName | Handler Arguments | Description\n---- | ----------------- | -----------\nsubscribed | | Fired when a subscription request is acknowledged by the server.\nunsubscribed | | Fired when an unsubscription is acknowledged by the server.\nresending | [ResendResponseResending](https://github.com/streamr-dev/streamr-client-protocol-js/blob/master/src/protocol/control_layer/resend_response_resending/ResendResponseResendingV1.js) | Fired when the subscription starts resending. Followed by the `resent` event to mark completion of the resend after resent messages have been processed by the message handler function.\nresent | [ResendResponseResent](https://github.com/streamr-dev/streamr-client-protocol-js/blob/master/src/protocol/control_layer/resend_response_resent/ResendResponseResentV1.js) | Fired after `resending` when the subscription has finished resending.\nno_resend | [ResendResponseNoResend](https://github.com/streamr-dev/streamr-client-protocol-js/blob/master/src/protocol/control_layer/resend_response_no_resend/ResendResponseNoResendV1.js) | This will occur instead of the `resending` - `resent` sequence in case there were no messages to resend.\nerror | Error object | Reports errors, for example problems with message content\n\n### Logging\n\nThe Streamr JS client library supports [debug](https://github.com/visionmedia/debug) for logging.\n\nIn node.js, start your app like this: `DEBUG=StreamrClient* node your-app.js`\n\nIn the browser, include `debug.js` and set `localStorage.debug = 'StreamrClient'`\n","browser":{"ws":"./src/shim/ws.js","http":"./src/shim/http-https.js","https":"./src/shim/http-https.js","node-fetch":"./src/shim/node-fetch.js"},"engines":{"node":">= 8"},"gitHead":"39db82ddcdf7e0da8917b85768a359c338704965","license":"AGPL-3.0-or-later","scripts":{"dev":"webpack --progress --colors --watch","test":"npm run eslint && jest --detectOpenHandles","build":"NODE_ENV=production webpack","eslint":"eslint src/** test/**","prepack":"npm run build","test-unit":"jest --detectOpenHandles --forceExit test/unit","test-integration":"jest --detectOpenHandles --forceExit --runInBand test/integration"},"_npmUser":{"name":"mthambipillai","email":"melkiorthambipillai@gmail.com"},"homepage":"https://github.com/streamr-dev/streamr-client#readme","repository":{"url":"git://github.com/streamr-dev/streamr-client.git","type":"git"},"_npmVersion":"6.4.1","description":"JavaScript client library for Streamr","directories":{"test":"test"},"maintainers":[{"name":"aapzu","email":"aapzu@iki.fi"},{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"juhah","email":"juha.haavisto@streamr.com"},{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"},{"name":"mirpo","email":"miroslavpokrovskiy@gmail.com"},{"name":"mk_streamr","email":"mikhael.santos@streamr.com"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"mthambipillai","email":"melkiorthambipillai@gmail.com"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"timoxley","email":"secoif@gmail.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"}],"_nodeVersion":"8.12.0","dependencies":{"qs":"^6.6.0","ws":"^6.1.2","once":"^1.4.0","debug":"^3.1.0","ethers":"^4.0.27","websocket":"^1.0.28","node-cache":"^4.2.0","node-fetch":"^2.1.2","querystring":"^0.2.0","randomstring":"^1.1.5","eventemitter3":"^3.0.1","webpack-node-externals":"^1.7.2","streamr-client-protocol":"^2.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"chai":"^4.1.2","jest":"^23.6.0","sinon":"^6.3.5","eslint":"^4.19.1","lodash":"^4.17.10","express":"^4.16.4","webpack":"^3.10.0","babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.2.2","babel-loader":"^7.1.2","babel-runtime":"^6.26.0","eslint-loader":"^1.9.0","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-2017":"0.0.0","eslint-plugin-react":"^7.7.0","babel-preset-stage-2":"^6.24.1","eslint-config-airbnb":"^16.1.0","eslint-plugin-import":"^2.10.0","eslint-config-streamr":"^1.1.7","eslint-plugin-flowtype":"^2.46.1","eslint-plugin-jsx-a11y":"^6.0.3","uglifyjs-webpack-plugin":"^1.2.4","babel-plugin-transform-runtime":"^6.23.0","babel-plugin-add-module-exports":"^0.2.1","babel-plugin-transform-builtin-extend":"^1.1.2"},"_npmOperationalInternal":{"tmp":"tmp/streamr-client_2.0.0-beta.5_1554975797448_0.6783213068437481","host":"s3://npm-registry-packages"},"_id":"streamr-client@2.0.0-beta.5","version":"2.0.0-beta.5"}