Developer documentation

Plugin Bus

The plugin bus is the shared lane for plugin-to-plugin values, events, and request interpolation.

Bus API

Method/actionUse
ctx.bus.input(name, fallback)Read a public variable.
ctx.bus.read(channel, fallback)Read latest published channel data.
ctx.bus.output(name, value)Return an action that stores an output variable.
ctx.bus.setVariable(name, value)Return an action that stores a variable.
ctx.bus.publish(channel, data)Return an action that publishes event data.
pluginBus.outputAction equivalent of ctx.bus.output.
pluginBus.setVariableAction equivalent of ctx.bus.setVariable.
pluginBus.publishAction equivalent of ctx.bus.publish.
pluginBus.clearTraceClear bus trace history.

Publish a value for another plugin

commands: {
  "auth.publish": function(ctx) {
    var token = ctx.dollar("#authTokenInput").val();
    return {
      __action: "multi",
      actions: [
        { __action: "pluginBus.output", name: "auth.token", value: token },
        { __action: "pluginBus.publish", channel: "auth.token.changed", data: { source: "auth" } }
      ]
    };
  },

  "auth.apply": function(ctx) {
    var token = ctx.bus.input("auth.token", "");
    return { __action: "setFields", fields: { "activeRequest.headers": { "Authorization": "Bearer " + token } } };
  }
}

Public bus variables can be used in requests with interpolation such as {{auth.token}}. Private names start with _ or contain .private., :private:, or /private/.