Plugins
Plugins are a way to package and share code used to bootstrap a Bigsby instance. A plugin is
registered using the registerPlugin
method, which accepts a BigsbyPluginRegistration
object.
A plugin is composed of a name
and an onRegister
method. The onRegister
method
accepts two arguments: the Bigsby instance it's being registered to, as well as any
options that were declared as part of the registration.
const bigsby = new Bigsby();
async function addJwtAuthScheme(
instance: BigsbyInstance,
options: Record<string, unknown>
): Promise<void> {
instance.registerAuthMethod({
name: "jwt",
authenticator: async ({ event }: RequestContext) => {
return verifyJwt(event.headers.authorization, options.secret);
},
});
}
const myPlugin: BigsbyPlugin = {
name: "my-plugin",
onRegister: addJwtAuthScheme,
};
bigsby.registerPlugin({ plugin: myPlugin, options: { secret: "mySecretKey" } });
info
Plugins will execute in the order of their registration when your handler initializes.
Modules
Composition
A Bigsby plugin distributed as an npm package is defined by a default
export from the
module index containing the Bigsby plugin. The example above can be converted to a distributable
package by adding the below to the root index.js
.
export default {
name: "bigsby-plugin-jwt-auth",
onRegister: async (
instance: BigsbyInstance,
options: Record<string, unknown>
): Promise<void> => {
instance.registerAuthMethod({
name: "jwt",
authenticator: async ({ event }: RequestContext) => {
return verifyJwt(event.headers.authorization, options.secret);
},
});
},
} as BigsbyPlugin;
Registration
Bigsby plugins can be consumed directly from the node_modules
folder by supplying the package
name instead of a plugin object when registering on the Bigsby instance.
const bigsby = new Bigsby();
bigsby.registerPlugin({ plugin: "bigsby-plugin-jwt-auth", options: { secret: "mySecretKey" } });