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
module.exports = function (hoodie, callback) {
};
hoodie.request(method, path, options, callback)
hoodie.config.get(key)
hoodie.config.set(key, value)
hoodie.database.findAll(callback)
hoodie.database.add(name, callback)
hoodie.database.remove(name, callback)
hoodie.database(name) => db
db.add(type, attrs, callback)
db.update(type, id, changed_attrs, callback)
db.find(type, id, callback)
db.findAll(callback)
db.findAll(type, callback)
db.remove(type, id, callback)
db.removeAll(type, callback)
db.grantPublicReadAccess(callback)
db.grantPublicWriteAccess(callback)
db.grantReadAccess(account_type, account_id, callback)
db.grantWriteAccess(account_type, account_id, callback)
db.revokePublicReadAccess(callback)
db.revokePublicWriteAccess(callback)
db.revokeReadAccess(account_type, account_id, callback)
db.revokeWriteAccess(account_type, account_id, callback)
db.addIndex(name, {map: .., reduce: ..}, callback)
db.removeIndex(name, callback)
db.query(index, options, callback)
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.on('change', handler)
hoodie.account.on('type:change', handler)
hoodie.account.on('$passwordReset:change', function(object) {
})
hoodie.task.on('change', function (db, doc) { ... })
hoodie.task.on('type:change', function (db, doc) { ... })
hoodie.task.addSource( databaseName )
hoodie.task.removeSource( databaseName )
hoodie.task.success( databaseName, taskDoc, [callback] )
hoodie.task.error( databaseName, taskDoc, error, [callback] )
hoodie.sendEmail({
from: "Fred Foo ✔ <foo@blurdybloop.com>",
to: "bar@blurdybloop.com, baz@blurdybloop.com",
subject: "Hello ✔",
text: "Hello world ✔",
html: "<b>Hello world ✔</b>"
}, callback)
hoodie.sendEmail({
to: 'test@example.com',
from: 'hoodie@example.com',
subject: 'test',
text: 'blah blah',
attachments: [
{dataURI: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', ...}
]
}, callback);