Comparing version 3.0.0 to 3.0.2
{ | ||
"name": "halfpenny", | ||
"version": "3.0.0", | ||
"description": "Official javascript COINS API client. Not browser compatible!", | ||
"version": "3.0.2", | ||
"description": "Official javascript COINS API client", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"build": "webpack", | ||
"test": "istanbul cover test/", | ||
"posttest": "istanbul check --statements 90 --functions 90 --branches 90", | ||
"posttest": "npm run coverage-check", | ||
"coverage-check": "istanbul check --statements 90 --functions 90 --branches 90", | ||
"commit-build": "git add dist/. && git commit -m 'add build' -n", | ||
"lint": "eslint src/ test/", | ||
@@ -15,2 +18,3 @@ "lintfix": "eslint --fix src/ test/", | ||
"deploy-docs": "gh-pages -d docs && rm -rf docs", | ||
"prepublish": "npm run build && npm run commit-build", | ||
"postpublish": "npm run docs && npm run deploy-docs", | ||
@@ -32,3 +36,6 @@ "publish-patch": "npm run preversion && npm version patch && git push origin master --tags && npm publish", | ||
"devDependencies": { | ||
"babel-core": "^6.7.4", | ||
"babel-loader": "^6.2.4", | ||
"coins-validate": "^2.0.6", | ||
"coveralls": "^2.11.9", | ||
"dom-storage": "2.0.2", | ||
@@ -42,3 +49,4 @@ "eslint": "^2.5.3", | ||
"minami": "^1.1.1", | ||
"tape": "^4.5.1" | ||
"tape": "^4.5.1", | ||
"webpack": "^1.12.14" | ||
}, | ||
@@ -45,0 +53,0 @@ "dependencies": { |
@@ -1,22 +0,40 @@ | ||
# halfpenny // COINS API Javascript client | ||
# halfpenny | ||
What is a [halfpenny](https://en.wikipedia.org/wiki/Halfpenny_(British_pre-decimal_coin)), anyway? Beyond an old-timey coin (AKA a pence), halfpenny is the official javascript API client for the COINS platform. | ||
[ ![Codeship Status for MRN-Code/halfpenny](https://codeship.com/projects/233242e0-d9e4-0133-38b5-0ae147979a90/status?branch=master)](https://codeship.com/projects/143661) | ||
[![Coverage Status](https://coveralls.io/repos/github/MRN-Code/halfpenny/badge.svg?branch=master)](https://coveralls.io/github/MRN-Code/halfpenny?branch=master) | ||
_The official COINS API Javascript client_ | ||
What is a [halfpenny](https://en.wikipedia.org/wiki/Halfpenny_(British_pre-decimal_coin)), anyway? Beyond an old-timey coin (AKA a pence), halfpenny is the official javascript API client for the COINS platform. halfpenny works in the browser and in nodejs. | ||
# usage | ||
```js | ||
const hp = require('halfpenny') | ||
const client = hp.factory({}, (err, client) => { | ||
client.auth.login('username', 'pw') | ||
.then(resp => console.log(resp.data.data[0].user)) | ||
.catch(err => console.error(err)); | ||
}); | ||
/** | ||
{ username: 'drblah', | ||
label: 'blah-blah-blah', | ||
activeFlag: 'Y', | ||
acctExpDate: '2220-01-01T07:00:00.000Z', | ||
passwordExpDate: '2220-01-01T07:00:00.000Z', | ||
siteId: '99', | ||
isSiteAdmin: 'N', | ||
email: 'blahblah@mrn.org', | ||
emailUnsubscribed: false } | ||
*/ | ||
``` | ||
halfpenny is written in nodejs-style commonjs. Therefore, if you are using it in the browser, make sure you are bundling it with browserify/webpack/etc! We do provide a bundled version on your behalf. See `dist/`. | ||
## peer dependencies | ||
### axios | ||
A HTTP request agent is required to retrieve the Client source code and to make | ||
requests. Axios was chosen as that client in order to support both server and | ||
browser environments. | ||
### storage | ||
In order to persist data to disk, a localstorage interface is required. In the | ||
browser, this means supplying `window.localStorage` in the browser, and using | ||
`node-localstorage` or `dom-storage` on the server. | ||
In order to persist data to disk, a `localStorage` interface is required. In the | ||
browser, this will default to `window.localStorage`. If you use nodejs, you must pass in a `localStorage`-like interface, such as `node-localstorage` or `dom-storage`. | ||
## basic configuration | ||
*See examples* | ||
The above configuration parameters are *required*. | ||
**Note that the 'requestFn' must be promisified** | ||
## how it works | ||
@@ -31,36 +49,10 @@ | ||
## examples | ||
```js | ||
const agent = require('axios'); | ||
const DomStorage = require('dom-storage'); | ||
const store = new DomStorage('/path/to/file', {strict: true}); | ||
const apiClientOptions = { | ||
xhrAgent: agent, | ||
baseUrl: 'http://localhost:8800', // hostname:port of nodeapi service | ||
store: store | ||
}; | ||
const clientReady = require('halfpenny')(apiClientOptions) | ||
.catch((err) => { | ||
//whoops | ||
}); | ||
// login | ||
clientReady.then((client) => { | ||
return client.auth.login('username', 'password'); | ||
}); | ||
// get scans | ||
clientReady.then((client) => { | ||
return client.ScansApi.get(null, 'M87100000') | ||
}); | ||
``` | ||
See `nodeapi/test/integration` for more | ||
## todo | ||
* support UMD and browser compatibility. | ||
* Auto-generate documentation from API client | ||
## changelog | ||
- 3.x | ||
- add build, address env incompatibility | ||
- 2.x | ||
@@ -67,0 +59,0 @@ - convert to auto-generated api client, built from server API spec |
@@ -118,3 +118,7 @@ 'use-strict'; | ||
return async.waterfall([ | ||
(cb1) => options.xhrAgent.get(options.clientUrl, cb1), | ||
(cb1) => { | ||
options.xhrAgent.get(options.clientUrl) | ||
.then(r => cb1(null, r)) | ||
.catch(cb1); | ||
}, | ||
(response, cb2) => { // eslint-disable-line | ||
@@ -130,3 +134,2 @@ return Promise.resolve() | ||
}, | ||
}; |
@@ -44,3 +44,3 @@ 'use strict'; | ||
t.plan(3); | ||
axios.get = (url, cb) => cb(null, { data: clientSrcStub }); // manual stubbing! @warning! :) | ||
axios.get = () => Promise.resolve({ data: clientSrcStub }); // manual stubbing! @warning! :) | ||
halfpenny.factory({ store }, (err, client) => { | ||
@@ -47,0 +47,0 @@ if (err) { return t.end(err.message); } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
206208
11
327
1
14
64