npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iobroker/plugin-base

v2.0.1

Published

Base module for plugins for js-controller and adapters

Downloads

63,733

Readme

plugins-base

Base Package for Plugins

This package allows to extend ioBroker with a plugin system. Plugins can add specialized functionality and can run inside an adapter or also inside the js-controller. Plugins are no adapters and so have - by definition - a limited featureset and a mainly static configuration.

Implementation

  • Plugins are always published as "@iobroker/plugin-MySuperPlugin" as name with "MySuperPlugin" being the plugin name.
  • Plugins use this package as core dependency and then extend the "PluginBase" object.
  • The main script of the plugin package experts the plugin class directly.
  • The plugin needs to implement the following methods:
    • constructor to pass the settings to the parent object, required
    • "init" method is called to initialize the plugin, required
    • "destroy" method is called before adapter/js-controller is stopped and should cleanup all needed resources, optional. If plugin is not able to be deactivated on the fly it needs to return false.
  • The plugin always have an "enabled" flag where the user defines if the plugin should be executed or not. This flag is respected.
  • Plugins can also interact with objects and states but very limited. The following Methods are available:
    • getState
    • setState
    • getObject
    • setObject
    • extendObject

Example code:

const {PluginBase} = require('@iobroker/plugin-base');

class MySuperPlugin extends PluginBase {

    constructor(settings) {
        super(settings);
    }

    /**
     * Register and initialize Plugin
     *
     * @param pluginConfig {object} plugin configuration from config files
     * @param callback {function} callback when done, signature "(err, initSuccessful)". On err or initSuccessful===false the plugin instance will be discarded
     */
    init(pluginConfig, callback) {
        if (!pluginConfig.enabled) {
            this.log.info('Sentry Plugin disabled by user');
            return void callback(null, false);
        }

        // initialize your code here

        callback(null, true);
    }

    /**
     * Method which is called on a clean end of the process to pot. clean up used resources
     */
    destroy() {
        // Implement in your Plugin instance if needed
    }
}

module.exports = MySuperPlugin;

The object offers the following "public" variables and methods to be used in your implementation:

  • this.log as ioBroker style Log class with methods for silly, debug, info, warn and error and will log automatically with a prepended String identifying the adapter and plugin
  • this.pluginScope contains the scope the plugin runs in. this.SCOPES.ADAPTER and this.SCOPES.CONTROLLER can be used if a plugin provides different functionality.
  • this.pluginNamespace is the State/Object namespace of the plugin instance, e.g. "system.adapter.name.instance.plugins.MySuperPlugin" or "system.host.name.plugins.MySuperPlugin". Please try to stay inside this namescape if nwe objects are created
  • this.iobrokerConfig contains the full ioBroker config object (basically iobroker-data/iobroker.json)
  • this.parentPackage contains the package.json of the adapter/controller the plugin runs in
  • this.parentIoPackage contains the io-package.json when running in js-controller or the instance configuration when running in an adapter

Configuration

Plugins are configured inside io-package.json in common area or in iobroker-data/iobroker.json on main level in a plugins key:

"plugins": {
    "MySuperPlugin": {
        "enabled": true,
        "key": "value"
        ...
    }
}

The configuration here is enhanced by an "enabled" key and passed to the "init" method. The configuration can also contain "enabled" as boolean field directly which then acts as default value. If "enabled" is not included the plugin will be activated by default!

Examples

One example is the Sentry plugin available at https://github.com/ioBroker/plugin-sentry

Changelog

2.0.1 (2024-05-27)

Breaking Changes:

  • (foxriver76) Methods no longer work with callback, please check the methods according to the types.
  • (foxriver76) All methods with async postfix are now working renamed to methods without the postfix while the callback methods have been removed
  • (foxriver76) Renamed instanciatePlugin to instantiatePlugin
  • (foxriver76) renamed isPluginInstanciated to isPluginInstantiated

1.2.1 (2021-01-24)

  • (Apollon77) Add error handling in some places when setting active Status

1.2.0 (2020-05-09)

  • (Apollon77) Add async methods for Objects and States
  • (Apollon77) rework enable detection for plugins

1.1.1 (2020-05-01)

  • (Apollon77) fix for host lookup to work for all plugins

1.1.0 (2020-05-01)

  • (Apollon77) Check host sentry plugin status when no adapter flag exists to allow users to turn it of more easy

1.0.0 (2020-04-26)

  • (Apollon77) Declare as 1.0.0 for release of js-controller 3.0

0.1.1 (2020-03-29)

  • (AlCalzone) add type support and optimizations

0.1.0 (2020-03-28)

  • (Apollon77) initial release to npm