Extending
Actinium is easy to extend and much of its bootstrapping is hook-able.
Actinium SDK
// Extend Actinium SDK
Actinium.MyPlugin = require('./sdk');const COLLECTION = 'SomeCollection';
const MyPluginSDK = {};
MyPluginSDK.create = async (req, options) => {
// Get params from request object
let { params } = req;
// Run a hook so other plugins can do some thangs to the params
await Actinium.Hook.run('some-collection-before-create', params, req, options);
// Create the new object
const obj = new Actinium.Object(COLLECTION);
// Save the object
let savedObj = await obj.save(params, options);
if (!savedObj) {
return new Error('Unable to save SomeCollection object');
}
// Convert the Actinium.Object into a JavaScript Object.
savedObj = saveObj.toJSON();
// Run a hook so other plugins can do some thangs
await Actinium.Hook.run('some-collection-created', savedObj, req, options);
return savedObj;
};
module.exports = MyPluginSDK;const SDK = require('./sdk');
const PLUGIN = {
ID: 'MyPlugin',
name: 'My Awesome Plugin',
description: 'The name says it all bro',
version: {
actinium: '>=3.0.5',
plugin: '0.0.1',
},
};
Actinium.Plugin.register(PLUGIN);
Actinium.Hook.register('plugin-load', async ({ ID }) => {
if (ID !== PLUGIN.ID) return;
if (!Actinium.Plugin.isActive(ID)) return;
Actinium.MyPlugin = SDK;
});Cloud Functions
Express Middleware
Last updated