{"_id":"@bynorth/focals-client-js","_rev":"2-1a607eb223b004fb5730998b962a5a9c","name":"@bynorth/focals-client-js","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"@bynorth/focals-client-js","version":"0.1.1","description":"Client library used to integrate with the Focals Developer APIs","main":"index.js","scripts":{"lint":"eslint index.js lib test","lint:junit":"eslint --format junit -o coverage/lint-results.xml index.js lib test","lint:fix":"eslint --fix index.js lib test","lint:todo":"! grep -Eir --exclude-dir node_modules --include '*.js' '(TODO|FIXME|HACK)' .","test":"mocha --color --recursive test","test:junit":"mocha --color --recursive --reporter mocha-junit-reporter --reporter-options mochaFile=coverage/test-results.xml test","test:cover":"nyc npm run test","package:lint":"depcheck --ignores='depcheck,nyc,eslint,mocha,mocha-junit-reporter' --specials=mocha","package:outdated":"npm outdated"},"nyc":{"reporter":["lcov","text-summary","cobertura"],"include":["lib/**/*.js","index.js"],"cache":false,"check-coverage":true,"per-file":true,"lines":80,"statements":80,"functions":75,"branches":80,"temp-directory":"coverage/nyc_output"},"keywords":["north","focals"],"devDependencies":{"chai":"^4.2.0","chai-as-promised":"^7.1.1","depcheck":"^0.7.1","eslint":"^5.12.1","faker":"^4.1.0","mocha":"^5.2.0","mocha-junit-reporter":"^1.18.0","nyc":"^13.2.0","proxyquire":"^2.1.3","sinon":"^7.2.3"},"author":{"name":"North Inc."},"license":"ISC","dependencies":{"json-refs":"^3.0.13","jsonpointer":"^4.0.1","node-jose":"^1.1.3","node-rsa":"^1.0.5","request":"^2.88.0","request-promise-native":"^1.0.7"},"gitHead":"e7da297301204df83dd3c18090ecea85ffc58cd1","_id":"@bynorth/focals-client-js@0.1.1","_nodeVersion":"12.6.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-2J/pCATXYVPyKMv/K5ntUDPXHVVdFu1xF0qhMH5lBfP5lDFeQpp5oQkdV32BNgtFc2aXY3qvTopXujUIFXqYEg==","shasum":"c0fe76ac8df47987bfd3f731d2abb72649fa1064","tarball":"https://registry.npmjs.org/@bynorth/focals-client-js/-/focals-client-js-0.1.1.tgz","fileCount":22,"unpackedSize":50502,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdk6+5CRA9TVsSAnZWagAA+xsP+gLX4X+KGXbdkDk9DVBx\nC8IeolXDZkhXopUmdlEVfDtwDcfUrhEv4ZOcuFPYQ/410zPjrbTMOoaIYLaQ\nyLy1S0wzIeWISylpWJ9+UJCjX6yUWtcFmrLC13yEowjObu7X+qEVKKhdeEIh\nGnXFfSE19er7DmcjGkKZvDdB/Ji7xvDHZIopD/nylYvnnXtIHGosjKBqJiVR\naFAJJYhDc5JlAJIeYGWpISBRDMKUKGBOvsly7Ucodiqcj86vam9o/LIM/pAX\nH6LKHogutcg1GpmHqXJnowC4bS8/2+zT2bWwJFVjGBhi/Gi7w6xnMX85VfPP\nVsc95oRsPgf2Ca+pHjFbAxFY7DvwgezWVyiIzN1/PS+vV1h6wDG1UyPLf3h1\nSHtuSOUe00QnrLaeq6biSzCc/iz6CAW7OE+Gk31ZIrneN73qRWevlEFYh/AB\nOhaTozPVH12XpFL4u1d005GtCJlPfbqH7P/ZGe4U2m6ifc4KlfvDX47QdT7z\nHpvcDD3xlXCy5xus8gHOg7ST3XfTwu0uUhSc1Z9lq2gyVrKg+dS9DpCGFjOF\ngbVy+loiR/qKPB3uS/SLi7sueXEzaZIgEa48RBKbLC6IeYTBopBmyq6zzpih\nYE9MpkvFlpA/rcXGLdDLF0pyl0sPsQd2uxWujKIDe3OEkn3WT+cHGpKGAqVQ\nNQF1\r\n=YuLv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA74Rzhev1zyyYN4KdEG9kgnzEK/RUNeobqN9HF6hTLJAiEAo23zKc6auD2aDQur6cXg7QPNu6T269BhpVQzNvpK+0E="}]},"maintainers":[{"name":"nickbynorth","email":"nick.goral@bynorth.com"},{"name":"agrant","email":"aaron.grant@thalmic.com"}],"_npmUser":{"name":"nickbynorth","email":"nick.goral@bynorth.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/focals-client-js_0.1.1_1569959864146_0.38387948280851303"},"_hasShrinkwrap":false},"0.1.2":{"name":"@bynorth/focals-client-js","version":"0.1.2","description":"Client library used to integrate with the Focals Developer APIs","main":"index.js","scripts":{"lint":"eslint index.js lib test","lint:junit":"eslint --format junit -o coverage/lint-results.xml index.js lib test","lint:fix":"eslint --fix index.js lib test","lint:todo":"! grep -Eir --exclude-dir node_modules --include '*.js' '(TODO|FIXME|HACK)' .","test":"mocha --color --recursive test","test:junit":"mocha --color --recursive --reporter mocha-junit-reporter --reporter-options mochaFile=coverage/test-results.xml test","test:cover":"nyc npm run test","package:lint":"depcheck --ignores='depcheck,nyc,eslint,mocha,mocha-junit-reporter' --specials=mocha","package:outdated":"npm outdated"},"nyc":{"reporter":["lcov","text-summary","cobertura"],"include":["lib/**/*.js","index.js"],"cache":false,"check-coverage":true,"per-file":true,"lines":80,"statements":80,"functions":75,"branches":80,"temp-directory":"coverage/nyc_output"},"keywords":["north","focals"],"devDependencies":{"chai":"^4.2.0","chai-as-promised":"^7.1.1","depcheck":"^0.7.1","eslint":"^5.12.1","faker":"^4.1.0","mocha":"^5.2.0","mocha-junit-reporter":"^1.18.0","nyc":"^13.2.0","proxyquire":"^2.1.3","sinon":"^7.2.3"},"author":{"name":"North Inc."},"license":"ISC","dependencies":{"egads":"^1.0.2","json-refs":"^3.0.13","jsonpointer":"^4.0.1","node-jose":"^1.1.3","node-rsa":"^1.0.5","request":"^2.88.0","request-promise-native":"^1.0.7"},"gitHead":"33f3252d38d8f43a9aa0a1ec61aba8e4c7633af9","_id":"@bynorth/focals-client-js@0.1.2","_nodeVersion":"12.6.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-doyLiGo2UOWxwya6XTm2c9tO3993tA1JnJAG1RJixwNcWO56rbngQaTUsXtFszThq+P27McY/SpqUavmMSXANQ==","shasum":"b57a08cc2b799e934a679b26cc2cf978519b395d","tarball":"https://registry.npmjs.org/@bynorth/focals-client-js/-/focals-client-js-0.1.2.tgz","fileCount":22,"unpackedSize":50605,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdlNvDCRA9TVsSAnZWagAAAmAP/RWGezFpkMah2FZAt2Ar\nUpHqbiAiIoaPftJtwgd6r2MK4QkVV/9qFDmoop6qxxpu+zfb3LNjo+HaqzyR\nHk1NsNIfxoFpXyvLBNYI/+dNqYVaixa1c4ZOYb+rjoL4Ix+aZKcOVLwLSVVb\nmKwLymnKH8jnjEw6GdxsSUrLuiP6LnhTwUVerNZqw6Tn3QCyXtaHZoRxRDBk\nmu/GGSNovZK0ms4eNrz3p2sCze7aXKUs2QEvg/9Jm0iSxZ9lCs5XbLid/VTo\nEDhSrdE9FwF4QisKkLauaVBzaruIlHji4WBPBG0wEdUEkCf5DIHe5QgvdJmx\nBjyfniehIZULEBKi9+asiU94q9h6OW7ABt6jZDrkBEZUL2MujniAwRfVhLwZ\ncf7QwsjZO9YC7YIW4Ao27PQsseF1kok4dIgr/nAD5o1zrpSqZm500VKzuhvQ\n1wGNT0BI+AyKyzs+tpL+MDLtRKYkA3d9SoKfJONXOLtNERM2VNfpJdoO3bHX\nexc3oCFzAt6EDz8WZZ1R+FHjWiWaKqMtHZr4tsWvG6SiHIyqyt3RvOUD67lm\nRxTDxXb4PI9CZjFW7hBU6OWCv7qEDcjvPuJ//xrkc9p82UL0Jfgs5MJr4tgT\nbRmHj1XllKtSkMmLElLMKoo2y29DtXQV2pyfRL9OQO/CjIkCWzGb7kn3TkdY\nu4+O\r\n=KCVj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDS+nHj0/s8kjztBOdxzMFSIJcQgyqh4l53/6NZpccMJgIgE1TfzcmYxRa25ljd4u0gh95of4UuqblgbqsueVVPWtE="}]},"maintainers":[{"name":"agrant","email":"aaron.grant@thalmic.com"},{"name":"nickbynorth","email":"nick.goral@bynorth.com"}],"_npmUser":{"name":"agrant","email":"aaron.grant@thalmic.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/focals-client-js_0.1.2_1570036674491_0.19945227344412042"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-01T19:57:43.916Z","0.1.1":"2019-10-01T19:57:44.954Z","modified":"2022-04-04T21:19:55.256Z","0.1.2":"2019-10-02T17:17:54.670Z"},"maintainers":[{"name":"agrant","email":"aaron.grant@thalmic.com"},{"name":"nickbynorth","email":"nick.goral@bynorth.com"}],"description":"Client library used to integrate with the Focals Developer APIs","keywords":["north","focals"],"author":{"name":"North Inc."},"license":"ISC","readme":"**THIS IS AN ALPHA RELEASE**\n\n# Focals Developer API Client Library\n\nThis library is designed to help make the process of creating Abilities for Focals easier by making it simpler to encrypt and decrypt content, retrieve public keys for users, and URL generation for interacting with the Focals Developer API.\n\nThe Focals Developer API, Developer Portal, and Client Library are in alpha and are liable to change significantly.\n\n## Usage\nInstall the library using:  \n`npm i @bynorth/focals-client-js`\n\n### Init\nBefore using the library, call the `init` function during your startup code. To make full use of the library, you need to provide your API Key and Secret, your ability's Integration ID, as well as your Shared Secret and your Private Key:  \n```\nconst configInit = require('@bynorth/focals-client-js').init;\nconfigInit({\n                apiSecret: '<YOUR API SECRET>',\n                apiKey: '<YOUR API KEY>',\n                sharedSecret: '<YOUR SHARED SECRET>',\n                privateKey: '<YOUR PRIVATE KEY>',\n                integrationId: '<YOUR INTEGRATION ID>',\n            });\n```\nThis is done to to store the values in an object in the library, to reduce the number of parameters passed to each function.  \nThe values you need can be found on the ability page on the [Developer Portal](https://developer.bynorth.com)\n\n#### Optional Values\n**baseUrl**   \nThis is reserved in the event that test environments are opened up to external developers in the future, and as such isn't needed yet.  \n**signingVersion**  \nThis option will be used when future signing versions are introduced, however there is only one option available at present, so the value doesn't need to be set\n\n### Device Keys\nIn order to perform encryption you need to have the public key for the intended recipient. In order to simplify this process, you can use the provided `DeviceKeysService`.  \nSimply pass the `userId` of the user (received as part of the enable flow), and the service will make the web request and return an array of retrieved public keys:  \n```\nconst deviceKeysService = require('@bynorth/focals-client-js').DeviceKeysService;\n\nconst publicKeys = deviceKeysService.getPublicKeys('userId');\n```\n\n### Encryption/Decryption\nThis library includes functionality to ease the implementation of end-to-end encryption when developing against the Focals Developer API by providing functions to encrypt a provided package, that only the recipient will be able to decrypt, and a function to decrypt a package intended for your ability.\n\n#### Encryption\nTo encrypt a packet you call the `encryptPacket` function, passing in as parameters:\n- The packet object\n- An array of JSON pointers on the packet to encrypt, following [RFC-6901](https://tools.ietf.org/html/rfc6901)\n- An array of public keys to use for encryption (retrieved using the above `DeviceKeysService` in this library)\n```\nconst encryptionService = require('@bynorth/focals-client-js').EncryptionService;\n\nconst encryptedPacket = encryptionService.encryptPacket(input, pathsToEncrypt, publicKeys);\n```\n\nFurther information on how end-to-end encryption works can be found here: [https://github.com/focalsbynorth/abilities-library/docs/encryption.md](https://github.com/focalsbynorth/abilities-library/docs/encryption.md)\n\n#### Decryption\nTo decrypt a packet you call the `decryptPacket` function, passing in as a parameter the encrypted packet object. This function will use the private key that was set during `init`.  \nIf no private key is detected, an exception will be raised.\n```\nconst encryptionService = require('@bynorth/focals-client-js').EncryptionService;\n\nconst decryptedPacket = encryptionService.decryptPacket(input);\n```\n\n### Signature Verification\nThe `SignatureService` provides a way to easily verify signatures received. To use this functionality you need to have configured your shared secret during `init`.  \nCall the `verifySignature` function, passing in as parameters:\n- The received `state`\n- The received `timestamp`\n- The received `signature`\n```\nconst signatureService = require('@bynorth/focals-client-js').SignatureService;\n\nconst isValid = signatureService.verifySignature('<RECEIVED STATE>', '<RECEIVED TIMESTAMP>', '<RECEIVED SIGNATURE>');\n```\nThe function will generate the HMAC signature using the timestamp and state, and your configured shared secret, and verify the received signature against that. The function will return a boolean value to indicate whether or not the signature is valid.\n\n### URLs\nThe `UrlService` is used to make generating URLs to interact with the Focals Developer API easier.  \nThis currently consists of a builder to generate the `enable` URL to allow a user to enable your ability. To indicate a success, simply call the function passing in the previously received `state` as a parameter. If there was an error, you can pass through both the `state` and the encountered error:  \n```\nconst urlService = require('@bynorth/focals-client-js').UrlService;\n\nconst enableUrl = urlService.buildEnableUrl('<STATE>');\n// Or if there was an error:\nconst enableUrl = urlService.buildEnableUrl('<STATE>', '<ERROR>');\n```\n\n### Publishing Packets to Users\nThe `PublishService` is used to handle publishing packets to users through the Focals Developer API possible with minimal effort.\nThere are two ways to publish packets to users:\n- Standard\n    - This is used when there is no personally identifiable information in your packets\n- Encrypted\n    - Use this to send sensitive data that has previously been encrypted using the `EncryptionService`\nBoth approaches require you to pass in the targets `userId`, as well as the `packet` to publish - the packet is the object that should change depending on which approach you follow:\n```\nconst publishService = require('@bynorth/focals-client-js').PublishService;\n\nconst response = publishService.publishToUser('userId', '<YOUR PACKET>');\nconst encryptedResponse = publishService.encryptedPublishToUser('userId', '<YOUR ENCRYPTED PACKET>');\n```\n","readmeFilename":"README.md"}