Docs menu

Build a Varde plugin with signed requests and pages

This tutorial builds one small Node service: a Server notes page with a list and an Add note action. Notes live in memory per group, so a restart clears them.

  • Node.js 20 or later
  • A self-hosted control plane
  • A plugin secret

The short version

The control plane reads a JSON manifest, signs each HTTP request with HS256, and draws the declared settings and pages using Varde’s native interface. Your service handles the data and actions.

Catalog plugins get one-click install in a Varde release that has not shipped yet. In the manifest, label, help, and placeholder set what the setup form shows.

Plugin build checklist

0 of 4

Step by step

  1. Define the manifest

    The JSON manifest tells the control plane what service to load and which settings and pages to draw. Save this as server-notes.json.

    json

    {
      "id": "server-notes",
      "name": "Server notes",
      "version": "1.0.0",
      "base_url": "http://127.0.0.1:7300",
      "secret_env": "SERVER_NOTES_SECRET",
      "service_token": "server-notes",
      "settings": [
        { "name": "service_state", "type": "string", "hidden": true }
      ],
      "pages": [
        {
          "id": "notes",
          "title": "Server notes",
          "list": { "endpoint": "/varde/notes" },
          "actions": [
            {
              "id": "add-note",
              "title": "Add note",
              "endpoint": "/varde/notes",
              "fields": [
                {
                  "name": "note",
                  "type": "string",
                  "help": "Write a note for your group."
                }
              ]
            }
          ]
        }
      ]
    }
  2. Write the HTTP service

    Use Node.js 20 or later and install jose in the project folder. Set SERVER_NOTES_SECRET to the same value the control plane reads from the manifest’s secret_env. Save the service as server-notes.mjs, then start it with node server-notes.mjs after setting the environment variable. This is the complete example service:

    shell

    npm install jose

    JavaScript

    import { createServer } from "node:http";
    import { jwtVerify } from "jose";
    
    const pluginId = "server-notes";
    const secret = new TextEncoder().encode(process.env.SERVER_NOTES_SECRET ?? "");
    const port = Number(process.env.PORT ?? "7300");
    const notesByGroup = new Map();
    const seenTokenIds = new Map();
    const maxRequestBytes = 1024 * 1024;
    
    if (secret.byteLength < 32) {
      throw new Error("SERVER_NOTES_SECRET must be at least 32 bytes");
    }
    
    function sendJson(response, status, value) {
      const body = JSON.stringify(value);
      response.writeHead(status, {
        "content-type": "application/json",
        "content-length": Buffer.byteLength(body),
      });
      response.end(body);
    }
    
    async function readJson(request) {
      const chunks = [];
      let size = 0;
    
      for await (const chunk of request) {
        size += chunk.length;
        if (size > maxRequestBytes) {
          throw new Error("Request body is too large");
        }
        chunks.push(chunk);
      }
    
      return JSON.parse(Buffer.concat(chunks).toString("utf8"));
    }
    
    function isRequestEnvelope(value) {
      return (
        value !== null &&
        typeof value === "object" &&
        !Array.isArray(value) &&
        typeof value.group_id === "string" &&
        value.user !== null &&
        typeof value.user === "object" &&
        !Array.isArray(value.user) &&
        typeof value.user.id === "string" &&
        typeof value.user.display_name === "string" &&
        typeof value.user.role === "string" &&
        value.settings !== null &&
        typeof value.settings === "object" &&
        !Array.isArray(value.settings)
      );
    }
    
    async function verifyRequest(request, envelope) {
      const now = Date.now();
      for (const [tokenId, expiresAt] of seenTokenIds) {
        if (expiresAt <= now) {
          seenTokenIds.delete(tokenId);
        }
      }
    
      const authorization = request.headers.authorization ?? "";
      if (!authorization.startsWith("Bearer ")) {
        return false;
      }
    
      try {
        const { payload } = await jwtVerify(
          authorization.slice(7),
          secret,
          {
            algorithms: ["HS256"],
            issuer: "varde-control-plane",
            audience: pluginId,
          },
        );
    
        const validClaims =
          typeof payload.sub === "string" &&
          typeof payload.grp === "string" &&
          typeof payload.role === "string" &&
          typeof payload.iat === "number" &&
          typeof payload.exp === "number" &&
          typeof payload.jti === "string" &&
          payload.jti.length > 0 &&
          payload.exp - payload.iat <= 60 &&
          payload.sub === envelope.user.id &&
          payload.grp === envelope.group_id &&
          payload.role === envelope.user.role;
    
        if (!validClaims || seenTokenIds.has(payload.jti)) {
          return false;
        }
    
        seenTokenIds.set(payload.jti, payload.exp * 1000);
        return true;
      } catch {
        return false;
      }
    }
    
    createServer(async (request, response) => {
      if (request.method !== "POST") {
        return sendJson(response, 405, { error: "Use POST" });
      }
    
      let envelope;
      try {
        envelope = await readJson(request);
      } catch {
        return sendJson(response, 400, { error: "Malformed request body" });
      }
    
      if (!isRequestEnvelope(envelope)) {
        return sendJson(response, 400, { error: "Malformed request body" });
      }
    
      if (!(await verifyRequest(request, envelope))) {
        return sendJson(response, 401, { error: "Unauthorized" });
      }
    
      const url = new URL(request.url ?? "/", "http://127.0.0.1");
      const operation = request.headers["x-varde-op"];
    
      if (url.pathname === "/varde/v1/settings" && operation === "settings") {
        return sendJson(response, 200, {
          store: { service_state: "ready" },
        });
      }
    
      if (url.pathname === "/varde/v1/disable" && operation === "disable") {
        notesByGroup.delete(envelope.group_id);
        return sendJson(response, 200, { message: "Plugin disabled" });
      }
    
      if (url.pathname === "/varde/notes" && operation === "list") {
        const notes = notesByGroup.get(envelope.group_id) ?? [];
        const items = notes.map((note) => ({
          title: note.text,
          subtitle: "Added by " + note.displayName,
          status: "Saved",
        }));
        return sendJson(response, 200, { items });
      }
    
      if (
        url.pathname === "/varde/notes" &&
        operation === "action:add-note"
      ) {
        const value = envelope.values?.note;
        if (typeof value !== "string" || value.trim() === "") {
          return sendJson(response, 422, {
            error: "Write a note before saving.",
          });
        }
    
        const notes = notesByGroup.get(envelope.group_id) ?? [];
        notes.push({
          text: value.trim(),
          displayName: envelope.user.display_name,
        });
        notesByGroup.set(envelope.group_id, notes);
        return sendJson(response, 200, {
          message: "Note added",
          notes: ["Visible to this group"],
        });
      }
    
      return sendJson(response, 404, { error: "Unknown plugin route" });
    }).listen(port, "127.0.0.1");
    Run the service with the same secret value the control plane uses:

    shell

    SERVER_NOTES_SECRET="<shared 32-byte secret>" PORT=7300 node server-notes.mjs
    Replace the placeholder with a secret of at least 32 bytes, and set the same value in the control plane environment.
  3. Verify each signed request

    The control plane sends a POST with a JSON envelope and the X-Varde-Op header. The envelope contains group_id, user with its ID, display name, and role, plus settings. Action calls also include values. The authorization token is an HS256 JWT with issuer varde-control-plane, audience equal to your plugin ID, subject equal to the user ID, group claim grp, role, issue time iat, expiry exp no more than 60 seconds later, and a random jti. The example checks the signing algorithm, issuer, audience, expiry, and the identity, group, role, issue time, and token ID claims against the request. The example rejects a reused jti until it expires; with several plugin replicas, share that record, for example in Redis.

    json

    {
      "group_id": "group-id",
      "user": {
        "id": "user-id",
        "display_name": "Member",
        "role": "member"
      },
      "settings": {
        "service_state": "ready"
      }
    }
    X-Varde-Op is list, action:add-note, settings, or disable. The plugin secret is used to verify the signature and is not included in the envelope.
  4. Return the page and action replies

    A list reply is {"items":[{"title":"Ready for Friday","subtitle":"Added by Sam","status":"Saved"}]}. Each item can include title, subtitle, status, and an optional HTTP or HTTPS href. The example maps each group’s in-memory notes into these items. An action reply is {"message":"Note added","notes":["Visible to this group"]}, with optional HTTP or HTTPS href. A successful reply must be JSON.
  5. Load and enable the plugin

    Run the service on the base URL in the manifest, then start the control plane with --plugin /path/server-notes.json and the same SERVER_NOTES_SECRET environment variable. In the group’s Settings, find the Server notes plugin in the Plugins card and select Enable plugin. The page appears in the dashboard navigation.

Manifest reference

  • Plugin fields
    • id, name, version, and base_url are required. The ID is lowercase ASCII, starts with a letter, and has 2 to 32 letters, numbers, or hyphens. Names and versions must be non-empty.
    • base_url uses HTTP or HTTPS without credentials, a query, or a fragment. Trailing slashes are removed.
    • Set exactly one of secret_env and secret_file. The secret must be at least 32 bytes. Relative secret file paths resolve beside the manifest, and trailing line endings are ignored.
    • service_token, settings, and pages are optional. Unknown fields and duplicate plugin IDs prevent the control plane from starting.
  • Pages and actions
    • A page needs a unique ID and non-empty title. It may have a list endpoint and actions. An action needs a unique ID within its page, a non-empty title, and an endpoint; fields are optional.
    • Page and action IDs start with a lowercase letter and use up to 32 lowercase letters, numbers, or hyphens. Endpoints are relative paths starting with /, with no scheme, host, or ...
  • Fields and field types
    • Field names are unique, start with a lowercase letter, and use lowercase letters, numbers, and underscores up to 64 characters. Fields may set required, help, and a type-checked default. Required fields cannot be omitted, and secret fields cannot have a default.
    • Types are string, int, bool, select, secret, multiselect, and member_multiselect. Both select types need string options, and submitted values must match them.
    • hidden is only for settings. The {"secret":true} flag is only valid on string fields; the secret type is already a secret string. A member_multiselect accepts group user IDs and can declare {"requires":"steam_id"}. The control plane expands selected members into objects with user_id, display_name, and steam_id, not IDs.

Settings and disable hooks

The control plane calls /varde/v1/settings with operation settings after enabling or updating plugin settings. The response {"store":{"service_state":"ready"}} is merged only into declared hidden settings. A hidden setting is controlled by the service, not submitted by a group member. The example returns service_state this way. When an owner disables the plugin, the control plane calls /varde/v1/disable with operation disable. That call is best-effort.

Handle errors and limits

Return 400 for a malformed request body and 401 for an invalid signed request. For a user-fixable action problem, return another 4xx status with {"error":"message"}. Varde shows that message and truncates it to 300 characters. A 5xx response, timeout, invalid JSON, invalid reply, or response over 1 MiB becomes plugin_unavailable. Calls time out after 10 seconds, and redirects are not followed. Keep successful responses small and JSON encoded.

Call Varde with a service token

If the plugin needs Varde data, use a service token whose name matches the manifest’s service_token. Give it only the required scopes and bind it to the group that enabled the plugin. For example, a token with the members scope can list that group’s members:

JavaScript

const response = await fetch(
  process.env.VARDE_CONTROL_PLANE_URL +
    "/v1/groups/" + encodeURIComponent(groupId) + "/members",
  {
    headers: {
      authorization: "Bearer " + process.env.VARDE_SERVICE_TOKEN,
    },
  },
);
if (!response.ok) {
  throw new Error("Varde API request failed");
}
const { members } = await response.json();

Server addons

Plugins can also manage typed server addons with HTTPS archives, a lowercase SHA-256 digest, a driver target, and small relative files. Addon writes need the matching group-bound service token with the server_addons scope. Varde applies addon changes at the next server start and does not restart a running server. The full plugin reference covers the remaining limits and fields.

For a plugin codebase in active use, see the Auto Tournament plugin.

What’s next

See how operators install plugins in Varde plugins. For the broader control plane and setup, follow the host guide.