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
Validate the manifest
node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \ validate examples/plugins/loyalty/manifest.jsonThe command prints the plugin id, version, and trust hash.
Generate a signing key
node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \ keygen --out loyalty-key.jsonThe file contains a base64 Ed25519 public key and private key. Keep the private key local; it is written with
0600permissions.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.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 inpendingreview.Approve the release
In Admin → Plugin registry, approve the pending release. Only approved, non-yanked releases can be installed.
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.Verify
Add products to a cart. The plugin’s
cart:calculatehook 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:calculatehook and apercentsetting. - The bundle exports a default
fetchhandler. It readsinvocation.configand 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.