Socket
Socket
Sign inDemoInstall

hoodie-plugins-api

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hoodie-plugins-api

Hoodie interface to CouchDB


Version published
Weekly downloads
12
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

Hoodie Plugin API

File and directory structure

/hoodie-plugin-plugin_name
    /pocket
    hoodie.plugin_name.js
    index.js
    package.json
  • /pocket - Extends the Pocket admin interface (contains a HTML fragment with code and styles)
  • hoodie.plugin_name.js - Extends the hoodie.js front-end API
  • index.js - Node.js worker for handling tasks and other events (this is just the default location, you have more options here, see below)
  • package.json - The plugin's metadata and dependencies (since the plugin should function as an npm module)

The server-side component of the plugin can be left in an index.js for simplicity, but Hoodie will prefer the following, if present:

  • Whatever you reference under main in the plugin's package.json
  • Whatever you get when you require() the plugin root directory

Writing workers

// Initializing a worker
module.exports = function (hoodie, callback) {
    // hoodie object is client to hoodie backend, documented below.
    // call callback when setup complete (with optional error if worker failed to initialize).
    // ...
};


// make HTTP requests directly to CouchDB (ideally, you would never need to use this)
hoodie.request(method, path, options, callback)

// get / set plugin configuration
hoodie.config.get(key)
hoodie.config.set(key, value)

// list all databases
hoodie.database.findAll(callback)

// create a new database
hoodie.database.add(name, callback)

// remove a database
hoodie.database.remove(name, callback)

// get a database object to make calls against
hoodie.database(name) => db

// add a document to db
db.add(type, attrs, callback)

// update a document in db
db.update(type, id, changed_attrs, callback)

// get a document from db
db.find(type, id, callback)

// get all documents from db
db.findAll(callback)

// get all documents of a single type in db
db.findAll(type, callback)

// remove a document from db
db.remove(type, id, callback)

// remove all documents of type in db
db.removeAll(type, callback)

// grant read access to everyone on db by updating CouchDB security
db.grantPublicReadAccess(callback)

// grant write access to everyone on db
db.grantPublicReadAccess(callback)

// grant read access to specific user on db by updating CouchDB security
db.grantReadAccess(account_type, account_id, callback)

// grant write access to specific user on db by adding role (checked by design doc in db)
db.grantWriteAccess(account_type, account_id, callback)

// update db security so it's no longer publicly readable
db.revokePublicReadAccess(callback)

// update db security so it's no longer publicly writable
db.revokePublicWriteAccess(callback)

// remove user from couchdb readers for db
db.revokeReadAccess(account_type, account_id, callback)

// remove role from user so they cannot write to db (checked by design doc)
db.revokeWriteAccess(account_type, account_id, callback)


// Index / Query API is not yet implemented, see:
// https://github.com/hoodiehq/hoodie-plugins-api/issues/3

// creates new design doc with CouchDB view on db
db.addIndex(name, {map: .., reduce: ..}, callback)

// removes design doc for couchdb view on db
db.removeIndex(name, callback)

// query a couchdb view on db
db.query(index, options, callback)


//
// hoodie.account API
//
hoodie.account.add(type, attrs, callback)
hoodie.account.update(type, id, changed_attrs, callback)
hoodie.account.find(type, id, callback)
hoodie.account.findAll(callback)
hoodie.account.findAll(type, callback)
hoodie.account.remove(type, id, callback)
hoodie.account.removeAll(type, callback)

// hoodie.account events
hoodie.account.on('change', handler)
hoodie.account.on('change:type', handler)

// use case: 
// handle password resets
hoodie.account.on('change:$passwordReset', function(object) {
  // set new password in user doc & send it via email
})


//
// listen to task document events
//
hoodie.task.on('change', function (db, doc) { ... })
hoodie.task.on('change:type', function (db, doc) { ... })

// add / remove sources (database) to listen for new tasks
hoodie.task.addSource( databaseName )
hoodie.task.removeSource( databaseName )

FAQs

Package last updated on 18 Oct 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc