Skip to content

Build your first plugin

Validate, sign, publish, and install the loyalty discount example plugin.

This tutorial uses the loyalty example in the EdgeCart repository. It is a minimal sandboxed plugin that proposes an order discount based on a merchant-configured percentage.

Before you start

  • Node.js 22+ and a checkout of the EdgeCart repository.
  • The plugin kernel deployed (or running locally) and its endpoint URL.
  • Access to Plugin registry in the EdgeCart admin.
  • The merchant store where you will install the plugin.

Steps

  1. Validate the manifest

    node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
      validate examples/plugins/loyalty/manifest.json

    The command prints the plugin id, version, and trust hash.

  2. Generate a signing key

    node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
      keygen --out loyalty-key.json

    The file contains a base64 Ed25519 public key and private key. Keep the private key local; it is written with 0600 permissions.

  3. Register a publisher

    In Admin → Plugin registry, create a publisher and paste the public key. Create a publisher API key and copy it once; EdgeCart stores only its hash.

    Registry operations require the operator’s email to be in PLATFORM_ADMIN_EMAILS.

  4. Publish the bundle

    node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
      publish \
      examples/plugins/loyalty/manifest.json \
      examples/plugins/loyalty/backend.js \
      --endpoint https://edgecart-plugins.example.com \
      --api-key <publisher-api-key> \
      --private-key "$(jq -r .private_key loyalty-key.json)"

    The CLI signs the bundle and posts it to /v1/releases. The release starts in pending review.

  5. Approve the release

    In Admin → Plugin registry, approve the pending release. Only approved, non-yanked releases can be installed.

  6. Install and configure

    In Admin → Plugins, install Loyalty Discount. Review the trust hash and capabilities (discounts:propose, settings, admin:ui), accept the consent, and set the discount percent in the plugin settings.

  7. Verify

    Add products to a cart. The plugin’s cart:calculate hook proposes an order discount; the host validates it and recalculates the totals. The cart should show the discount without trusting a plugin-supplied total.

What the example does

  • The manifest declares the cart:calculate hook and a percent setting.
  • The bundle exports a default fetch handler. It reads invocation.config and returns { ok: true, value: { adjustments: [...] } }.
  • The host checks the adjustment’s target, currency, and amount bounds, then recomputes the cart totals.
  • A malformed response is rejected and recorded in the invocation log.

Next

Type to search…

↑↓ navigate↵ selectEsc close