Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

hoodie-client

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hoodie-client

Hoodie Client Core

latest
Source
npmnpm
Version
3.4.1
Version published
Maintainers
1
Created
Source

hoodie-client

Hoodie’s client for the browser

Build Status Coverage Status Dependency Status devDependency Status

Hoodie’s client glue code that integrates Hoodie’s client core modules: account, store and task

Example

var Hoodie = require('hoodie-client')
var hoodie = new Hoodie(options)

hoodie.account.signUp({
  username: 'pat@Example.com',
  password: 'secret'
}).then(function (accountAttributes) {
  hoodie.log.info('Signed up as %s', accountAttributes.username)
}).catch(function (error) {
  hoodie.log.error(error)
})

API

Constructor

new Hoodie(options)
ArgumentTypeDescriptionRequired
options.urlString Set to hostname where Hoodie server runs, if your app runs on a different host No
options.accountString account options. options.url is always set to hoodie.url + '/account/api' No
options.storeString store options. options.dbName is always set to hoodie.account.id. options.remote is always set to hoodie.url + '/store/api' No
options.taskString task options. options.userId is always set to hoodie.account.id. options.remote is always set to hoodie.url + '/task/api' No
options.connectionStatusString connectionStatus options. options.url is always set to hoodie.url + '/connection-status/api'. options.method is always set to HEAD No

hoodie.url

Read-only

hoodie.url

full url to the hoodie server, e.g. http://example.com/hoodie

hoodie.account

hoodie.account is an instance of hoodie-account-client. See account API

hoodie.store

hoodie.store is an instance of hoodie-store. See store API

hoodie.task

hoodie.task is an instance of hoodie-client-task. See task API

hoodie.connectionStatus

hoodie.connectionStatus is an instance of hoodie-connection-status. See connectionStatus API

hoodie.log

hoodie.log is an instance of hoodie-log. See log API

hoodie.request

Sends an http request

hoodie.request(url)
// or
hoodie.request(options)
ArgumentTypeDescriptionRequired
urlString Relative path or full URL. A path must start with / and sends a GET request to the path, prefixed by hoodie.url. In case a full URL is passed, a GET request to the url is sent. Yes
options.urlString Relative path or full URL. A path must start with / and sends a GET request to the path, prefixed by hoodie.url. In case a full URL is passed, a GET request to the url is sent. Yes
options.methodString Defaults to GET. One of GET, HEAD, POST, PUT, DELETE. No
options.dataObject, Array, String or Number For PUT and POST requests, an optional payload can be sent. It will be stringified before sending the request. No
options.headersObject Map of Headers to be sent with the request. No
options.dataObject, Array, String or Number For PUT and POST requests, an optional payload can be sent. It will be stringified before sending the request. No

Examples

// sends a GET request to hoodie.url + '/foo/api/bar'
hoodie.request('/foo/api/bar')
// sends a GET request to another host
hoodie.request('https://example.com/foo/bar')
// sends a PATCH request to /foo/api/bar
hoodie.request({
  method: 'PATCH',
  url: '/foo/api/bar',
  headers: {
    'x-my-header': 'my value'
  },
  data: {
    foo: 'bar'
  }
})

hoodie.plugin

Initialise hoodie plugin

hoodie.plugin(methods)
hoodie.plugin(plugin)
ArgumentTypeDescriptionRequired
methodsObject Method names as keys, functions as values. Methods get directly set on hoodie, e.g. hoodie.plugin({foo: function () {}}) sets hoodie.foo to function () {} Yes
pluginFunction The passed function gets called with `hoodie` as first argument, and can directly set new methods / properties on it. Yes

Examples

hoodie.plugin({
  sayHi: function () { alert('hi') }
})
hoodie.plugin(function (hoodie) {
  hoodie.sayHi = function () { alert('hi') }
})

hoodie.reset

🐕 TO BE DONE: #12

Reset hoodie client and emit reset event so plugins can reset as well.

hoodie.reset()

Resolves without argument.

hoodie.on

Subscribe to event.

hoodie.on(eventName, handler)

Example

hoodie.on('account:signin', function (accountProperties) {
  alert('Hello there, ' + accountProperties.username)
})

hoodie.one

Call function once at given event.

hoodie.one(eventName, handler)

Example

hoodie.one('mycustomevent', function (options) {
  console.log('foo is %s', options.bar)
})
hoodie.trigger('mycustomevent', { foo: 'bar' })
hoodie.trigger('mycustomevent', { foo: 'baz' })
// logs "foo is bar"
// DOES NOT log "foo is baz"

hoodie.off

Removes event handler that has been added before

hoodie.off(eventName, handler)

Example

hoodie.off('connectionstatus:disconnect', showNotification)

hoodie.trigger

Trigger custom events

hoodie.trigger(eventName[, option1, option2, ...])

Example

hoodie.trigger('mycustomevent', { foo: 'bar' })

Events

resettriggered when hoodie.reset() succeeded
account:*events, see account events
store:*events, see store events
task:*events, see task events
connectionStatus:*events, see connectionStatus events

Testing

Local setup

git clone https://github.com/hoodiehq/hoodie-client.git
cd hoodie-client
npm install

Run all tests

npm test

Run test from one file only

node tests/specs/id

License

Apache 2.0

Keywords

hoodie

FAQs

Package last updated on 15 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts