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.
| Permission | Shown to the owner as | Allows |
|---|---|---|
| orders.read | Read your orders | order.created and order.updated events |
| orders.write | Add notes to your orders | The order.note action |
| products.read | Read your products and stock | product.* and stock.low events |
| shipping.read | Read your shipments and tracking | Reading shipments and their tracking |
| shipping.write | Create shipments, labels and tracking on your orders | The shipment actions |
| customers.address | See your customers' shipping addresses | The shipping address in order events (personal data) |
| observability.read | Receive your alerts and the daily summary | observability.alert.opened, observability.alert.resolved, observability.threshold and observability.daily_summary events |
| observability.events | Receive every event your shoppers' visits record, to send it elsewhere | The observability.event stream |
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
| Event | data | Needs |
|---|---|---|
| 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.low | the variant that ran low | products.read |
| observability.alert.opened | { alert } | observability.read |
| observability.alert.resolved | { alert } | observability.read |
| observability.threshold | { threshold } | observability.read |
| observability.daily_summary | { summary } | observability.read |
| observability.event | { events } | observability.events |
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
| Field | Rule |
|---|---|
| key | a-z, 0-9 and _, starting with a letter, up to 40 characters; unique |
| label | Shown to the owner |
| type | text, secret, number or boolean |
| required | The owner must fill it in |
| default | Used when the owner leaves it empty |
| hint | A 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
| Action | Fields | Needs |
|---|---|---|
| order.note | order_id, text (up to 1000 characters) | orders.write |
| shipment.label | order_id, carrier, label_url (https link to the PDF), tracking_number?, service?. Goes on the order's shipment, created when it has none | shipping.write |
| shipment.tracking | order_id, events [{ at (epoch seconds), message }], status? (in_transit, out_for_delivery, delivered, exception, returned). Events already recorded are skipped | shipping.write |
| order.ship | order_id, carrier, tracking_number, tracking_url?. Marks the order shipped and sends the customer the shipped email | shipping.write |
| return.create | order_id, carrier, label_url, tracking_number?. A return with its label on the order's shipment | shipping.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.
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.