Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions for-developers/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Configured callbacks use replacements for specific URL to receive and send data.
| `%_input.url%` | The URL pointing to an HTTP endpoint sending out the input data for the plugin. This can be mapped to STDIN or read directly by the plugin. |
| `%_output.url%` | The URL to write the data back to. This can be mapped to STDOUT or written directly by the plugin. |
| `%info.json%` | A map containing context information about the current callback. This includes the URL requested, its query in a parsed form, as well as the HTTP Headers of the request. In addition it includes the plugin's base config as returned by `/api/config`. Since version 6.17, the info also includes the languages as configured in the base config. Individual callbacks may add additional information. |
| `%_exec.pluginDir%` | The absolute filesystem path to the plugin's directory. Use this to reference scripts and other plugin resources by their absolute path — e.g. `value: "%_exec.pluginDir%/src/handler.js"`. Without this prefix the path is resolved relative to the per-job working directory (a transient subdirectory under fylr's `tempDir`), where your script does not exist; the process exits with the runtime's "module not found" error. |

When a plugin wants to return an error, it needs to exit with a non zero exit code. If called as an extension plugin, FYLR sets the `X-Execserver-Error` header, unless more than 4K of data have already been produce and sent out to the response body.

Expand Down Expand Up @@ -64,12 +65,12 @@ callbacks:
commands:
- prog: "node"
stdin:
url: "%_input.url%"
type: "body"
stdout:
url: "%_output.url%"
type: "body"
args:
- type: "value"
value: "set_comment.js"
value: "%_exec.pluginDir%/set_comment.js"

db_pre_save:
steps:
Expand All @@ -86,12 +87,12 @@ callbacks:
commands:
- prog: "node"
stdin:
url: "%_input.url%"
type: "body"
stdout:
url: "%_output.url%"
type: "body"
args:
- type: "value"
value: "set_comment.js"
value: "%_exec.pluginDir%/set_comment.js"
- type: "value"
value: "%info.json%"

Expand Down Expand Up @@ -152,6 +153,10 @@ In case of an error, fylr tries to parse errors using the api error format. If a

Callbacks are predefined hooks in the API of FYLR. Each hook is different and might use its own format for in and output of the data.

{% hint style="warning" %}
**Stdin/stdout transport differs between extensions and callbacks.** Extensions use the URL-replacement form (`stdin.url: "%_input.url%"` / `stdout.url: "%_output.url%"`) because fylr exposes the input/output as on-the-fly HTTP endpoints. Callbacks (e.g. `db_pre_save`, `transition_db_pre_save`) connect the plugin's process stdin/stdout directly via `type: "body"`. Using the URL form inside a callback definition fails at job dispatch with `Could not prepare stdin "%_input.url%": parse "%_input.url%": invalid URL escape "%_i"` because the placeholder is not substituted in that path.
{% endhint %}

Errors can be generated using the api error JSON format which looks like this:

```json
Expand Down