Developer docs / Plug-ins

Plug-in reference

Permissions, events, settings, actions, the run protocol and the limits.

Permissions

Every name on this page is in code: Event, Permission, Capability and Action from @commernauts/plugin (Event.OrderCreated is order.created), with PLUGIN_EVENTS, PLUGIN_PERMISSIONS, PLUGIN_CAPABILITIES and PLUGIN_ACTIONS describing each. defineManifest, commernauts-plugin build and the marketplace all check against them.

PermissionShown to the owner asAllows
orders.readRead your ordersorder.created and order.updated events
orders.writeAdd notes to your ordersThe order.note action
products.readRead your products and stockproduct.* and stock.low events
shipping.readRead your shipments and trackingReading shipments and their tracking
shipping.writeCreate shipments, labels and tracking on your ordersThe shipment actions
customers.addressSee your customers' shipping addressesThe shipping address in order events (personal data)

Order events carry the order with the customer's name and email. The shipping address is personal data: it is in the event only when the owner granted customers.address. A team member installing a plug-in needs each permission it asks for; customers.address counts as orders.read.

Events

EventdataNeeds
order.created{ order }orders.read
order.updated{ order }orders.read
product.created{ product }products.read
product.updated{ product }products.read
product.deleted{ product }products.read
stock.lowthe variant that ran lowproducts.read

An order carries id, order_number, status, customer_name, customer_email, total_minor (in cents) and currency; a product carries id, title, status and stock. More fields may be present. Every event has id, type, created_at (unix seconds) and data.

Settings

FieldRule
keya-z, 0-9 and _, starting with a letter, up to 40 characters; unique
labelShown to the owner
typetext, secret, number or boolean
requiredThe owner must fill it in
defaultUsed when the owner leaves it empty
hintA line under the field
  • Up to 20 settings.
  • Text values are at most 2000 characters.
  • A secret is never shown again after it is saved; leaving it empty keeps the stored value.

Actions

ActionFieldsNeeds
order.noteorder_id, text (up to 1000 characters)orders.write
shipment.labelorder_id, carrier, label_url (https link to the PDF), tracking_number?, service?. Goes on the order's shipment, created when it has noneshipping.write
shipment.trackingorder_id, events [{ at (epoch seconds), message }], status? (in_transit, out_for_delivery, delivered, exception, returned). Events already recorded are skippedshipping.write
order.shiporder_id, carrier, tracking_number, tracking_url?. Marks the order shipped and sends the customer the shipped emailshipping.write
return.createorder_id, carrier, label_url, tracking_number?. A return with its label on the order's shipmentshipping.write

An action the owner did not allow is refused, and shows as refused in the store's Recent runs.

Shipping rates at checkout

A plug-in that lists "shipping.rates" under "capabilities" in commernauts.plugin.json quotes shipping at checkout. It needs no events or permissions for this. The store owner chooses whether its rates are offered next to the zone rates or instead of them.

import { definePlugin } from '@commernauts/plugin';
import manifest from '../commernauts.plugin.ts'; // capabilities: [Capability.ShippingRates]

export default definePlugin(manifest, {
  'shipping.rates': (request, { install }) => [
    { id: 'standard', name: 'DHL Paket', amount: 499 + install.settings.markup, days_min: 1, days_max: 3 },
  ],
});
  • The request has the currency, the subtotal, the destination (country, postal code, city) and the cart lines (product, variant, title, quantity, unit price, and weight_grams when the variant has a weight). The customer's name, email and street stay with the store.
  • Each rate has an id (a-z, 0-9, _ and -, up to 40 characters), the name buyers see, the amount in minor units, and optional days_min and days_max.
  • The plug-in has 1.5 seconds to answer. A slow or failing answer gives no rates, and checkout uses the store's zone rates. A store with no zones then asks the buyer to try again, so it never ships for free by accident.
  • Up to 10 rates per answer; rates with a bad id or amount are left out. Each quote shows in Recent runs as shipping.rates.

Calls from carriers and other services

A plug-in that lists "webhooks" under "capabilities" gets its own address for each store that installs it: install.hook_url, sent with every run and shown to the owner next to the install. Give it to the carrier or service that reports to the plug-in, such as tracking updates.

export default definePlugin(manifest, {
  webhook: (call) => {
    const update = JSON.parse(call.body) as { order: string; status: 'delivered' };
    return [{ type: Action.ShipmentTracking, order_id: update.order, events: [{ at: Math.floor(Date.now() / 1000), message: 'Delivered' }], status: update.status }];
  },
});
  • A call is POST or GET to https://platform.commernauts.com/plugins/hooks/<install>/<token>. The token is the secret: an address with a wrong token, or for an install that was removed, answers 404.
  • The plug-in gets the method, the headers (lower case; cookies and authorization left out), the query and the body as text, up to 256 KB. Check the service's own signature header in the handler.
  • It answers actions as for a store event, under the same permissions and limits, and each call shows in Recent runs as webhook.

Buttons in the dashboard

A plug-in can put up to five buttons on the order page, listed under "ui" in commernauts.plugin.json. Each has an id (a-z, 0-9, _ and -), the place ("order") and a label of up to 40 characters.

"ui": [{ "id": "label", "place": "order", "label": "Buy label" }]
export default definePlugin(manifest, {
  button: ({ button, order }) => button === 'label'
    ? [{ type: Action.ShipmentLabel, order_id: order.id, carrier: 'DHL', label_url: 'https://...' }]
    : [],
});

Pressing a button needs the orders.write permission in the store team. The plug-in gets the button id and the order (the shipping address only with customers.address), and its actions apply under the permissions the owner granted. The order page shows the result and the shipments, tracking and notes the actions changed.

The run protocol

definePlugin handles this for you. Underneath, the platform POSTs to the plug-in Worker:

{ "event": { "id": "...", "type": "order.created", "created_at": 1793643614, "data": { "order": { ... } } },
  "install": { "id": "mi_...", "store_id": "st_...", "settings": { "text": "..." } } }

and the Worker answers:

{ "actions": [ { "type": "order.note", "order_id": "ord_...", "text": "..." } ] }

Limits

  • Per run: 50 ms of CPU, 10 outbound requests, and 10 seconds to answer.
  • A shipping plug-in (one that quotes rates, or asks for shipping.write) gets 100 ms of CPU and 30 outbound requests per run, for its calls to carriers.
  • Up to 10 actions per run, and an answer of at most 64 KB.
  • A package of at most 1 MB; a shipping plug-in, at most 3 MB.
  • A handler that throws answers an error, and the store sends the event again later.

The package

npm run build (commernauts-plugin build) writes dist/<name>.plugin.json: the manifest plus the bundled Worker, in the commernauts.plugin/2 format. Publishing checks it: the format, size, a Worker with a default export, known permissions and events, a read permission for every event, and valid settings.

A plug-in can also carry section models (types) that are installed in the store's content when the plug-in is.