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'spackage.json
- Whatever you get when you
require()
the plugin root directory
Writing workers
// Initializing a workermodule { // 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 // get / set plugin configurationhoodieconfighoodieconfig // list all databaseshoodiedatabase // create a new databasehoodiedatabase // remove a databasehoodiedatabase // get a database object to make calls againsthoodie db // add a document to dbdb // update a document in dbdb // get a document from dbdb // get all documents from dbdb // get all documents of a single type in dbdb // remove a document from dbdb // remove all documents of type in dbdb // grant read access to everyone on db by updating CouchDB securitydb // grant write access to everyone on dbdb // grant read access to specific user on db by updating CouchDB securitydb // grant write access to specific user on db by adding role (checked by design doc in db)db // update db security so it's no longer publicly readabledb // update db security so it's no longer publicly writabledb // remove user from couchdb readers for dbdb // remove role from user so they cannot write to db (checked by design doc)db // Index / Query API // creates new design doc with CouchDB view on dbdb // removes design doc for couchdb view on dbdb // query a couchdb view on dbdb //// hoodie.account API//hoodieaccounthoodieaccounthoodieaccounthoodieaccounthoodieaccounthoodieaccounthoodieaccount // hoodie.account eventshoodieaccounthoodieaccount // use case: // handle password resetshoodieaccount //// listen to task document events//hoodietaskhoodietask // add / remove sources (database) to listen for new taskshoodietaskhoodietask // mark task as completehoodietask // mark task as erroredhoodietask // send emailshoodie // sending emails uses nodemailer API:// https://github.com/andris9/Nodemailer // you can also pass attachments as dataURIs:hoodie; // please note, the 'filePath' property usable on attachments in nodemail// will be stripped in hoodie to prevent accidentally emailing out files// from the server