{"bugs":{"url":"https://github.com/streamr-dev/streamr-client/issues"},"dist":{"shasum":"1b7cdc00adcd4cf1e93d2f02b3da398a3db634c6","tarball":"https://registry.npmjs.org/streamr-client/-/streamr-client-2.0.0-beta.4.tgz","fileCount":59,"integrity":"sha512-JEHg5fVMcXH/NrhhQlrkctveM/fTPi3v3n2TwhefzRm0UNHax2wcz8FgqbVphJKUhc9wMniHq/tou7V/zKZrMw==","signatures":[{"sig":"MEUCIQDUV1dNhpI1nycSB2B+fLPUJ3zY7JpJS1GIISTYK2oRjQIgYq/s3Jkx/WpEC/01ZUxmtYdMT4n44xCZfpOKNJETqMI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4481550,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcnfieCRA9TVsSAnZWagAAqfwP/2UjhegrlZyf8WHabyBX\nydaTIEVKOXLcJda9EgS0KHAaN3NXo7vswB2DUYfSANutheelNTLC9PfFT53Q\nMf2yfJBDcJCngPh8x7E9U6gDa4LA2bLbgxf3pm0Z+i8uZfC4wgmu3AKaWaXm\nnd1/TnMKATCyP6985oX3F2H2nh8cjD1GA5mVtPu+nFoZv7/M7OVsGLeKsihi\nospRBetqWAEmFYhQPF1Vnh44GCbUjSsBkxCnvrBS/Ol8Xpu/zBVYGZAlxe9F\nP7lFkkxfQkDWJ16CRwdSn8jijbeX8nHttQ1sGjNrVpEe16CFemVXtiGoj+AF\nwY8zlL9p6kCJKEs6GZXQa648t4UfiVYLojpHAFe7OZObPdRWwNr131aTqEXp\ncIT6WwEew2OCd6QqK3PfUxfPFiaOgmYskS9Otuxaxf0Kq/0yVlLH1fqBTLud\nhFVFVQdgSjZrsGdD1F3Hd9NL5/Bd7wQMSEGhwZwGXk0zr62CJGvzQB+5VqTr\nmC7kvJdH48DlpEGHotJIjGjKCx1r3uSJc1uk9ZsCGrMC2691sLf80iCGBu3b\nmOwW4HwofNv9yK013WPjPPmgXeMb0ZnyHAeXETfQNcOn5tVTdvUQgHma7OR4\ncKKPLZ1qbjZYzWrE8FD2kvtPcVJe3/P773bd/qGM8SwHx5F53bGUZP89jrF5\napdz\r\n=QDIY\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()`.\n\n### Authentication options\n\nOption | Default value | Description\n------ | ------------- | -----------\nauth.apiKey | null | Default API key to use to authenticate.\nauth.privateKey | null | Ethereum private key to use to authenticate.\nauth.provider | null | Ethereum provider used to connect to an account to use to authenticate.\nauth.username | null | Username to use to authenticate. Needs `auth.password` as well.\nauth.password | null | Password to use to authenticate. Needs `auth.username` as well.\nauth.sessionToken | null | Session token to authenticate directly without fetching a token with credentials. If the token expires, a new token cannot be retrieved.\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-------- | -----------\nmessage  | A javascript object containing the message itself\nmetadata | Metadata for the message, for example `metadata.timestamp` 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()`.\ndisconnect() | Disconnects from the server, clearing all subscriptions.\npause() | Disconnects from the server without clearing subscriptions.\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\napiKey   | User key or stream key that authorizes the subscription. If defined, overrides the client's `apiKey`.\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 | `{ from: number }` | Fired when a subscription request is acknowledged by the server.\nunsubscribed |  | Fired when an unsubscription is acknowledged by the server.\nresending |  | Fired when the subscription starts resending.\nresent |  | Fired after `resending` when the subscription has finished resending.\nno_resend |  | Fired after `resending` in case there was nothing 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":"069dba201625316c6e419111445b4d34c63440f4","license":"AGPL-3.0-or-later","scripts":{"dev":"webpack --progress --colors --watch","test":"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","debug":"^3.1.0","ethers":"^4.0.27","websocket":"^1.0.28","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.4_1553856670109_0.12406886251020355","host":"s3://npm-registry-packages"},"_id":"streamr-client@2.0.0-beta.4","version":"2.0.0-beta.4"}