Keyrxng

UbiquityOS Plugin Template

Ubiquity OS · 2024 · Standardized scaffold with dual entry points (Actions + Workers), Supabase adapters, TypeBox validation, and CI for tests and linting.

So what?
public template template adoption
Role
Product Engineer
Year
2024
Stack
TypeScript, Cloudflare Workers, GitHub Actions, Supabase, TypeBox, Jest, ESLint, Knip
Read narrative
public template template adoption

Problem

Plugin authors were cloning assorted repos and hand-assembling scaffolds, leading to inconsistent structures and wasted time. A standard template needed to encode the working patterns used across successful plugins.

Approach

System diagram

flowchart LR
  Dev[Developer] --> Clone[Template Clone]
  Clone --> TS[TypeScript Setup]
  TS --> Ctx[Context Initialization]
  Ctx --> Impl[Plugin Logic Implementation]
  Impl --> Deploy[Dual Deploy]
  Deploy --> Actions[Actions]
  Deploy --> Workers[Workers]
  Workers --> Integrate[UbiquityOS Integration]
  Actions --> Integrate

Outcome

Constraints

Design choices

Proof

Code excerpt — Actions entry with shared context

export async function plugin(inputs: PluginInputs) {
  const {
    eventName,
    eventPayload: payload,
    settings,
    authToken: env.UBIQUIBOT_TOKEN,
  } = inputs;

  const context = {
    eventName: payload.eventName,
    eventPayload: JSON.parse(payload.eventPayload),
    settings,
    authToken: env.UBIQUIBOT_TOKEN,
  };
  return await runPlugin(context);
}

Code excerpt — Worker entry with TypeBox validation

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const webhookPayload = await request.text();
    const parsed = Type.Object({ eventName: Type.String(), eventPayload: Type.String() });
    const validation = Value.Check(parsed, JSON.parse(webhookPayload));
    if (!validation) return new Response("Invalid payload", { status: 400 });
    return await plugin(JSON.parse(webhookPayload));
  },
};

CI evidence — Jest coverage workflow

name: Run Jest testing suite
on:
  workflow_dispatch:
  workflow_run:
    workflows: ["Build"]
    types: [completed]
jobs:
  testing:
    permissions: write-all
    runs-on: ubuntu-latest
    steps:
      - uses: ArtiomTr/jest-coverage-report-action@v2
        with:
          package-manager: yarn

Release evidence — template init merged with CI in place

Merged 12 commits into main (template initialization and CI wiring).

References