Developer docs / Plug-ins

Your first plug-in, step by step

From an empty folder to a plug-in running on a store: account, Studio, project, code, build, publish, install, test, review and updates.

What you will build

A plug-in that writes a note on every new order, with a text the store owner chooses when installing. It touches every part of a plug-in: a manifest, code, a setting, a permission, an event and an action. Once it works, the same steps carry any plug-in you write.

It takes about 30 minutes. You need nothing set up in advance; every step below says where to click or what to type.

1. Before you start

  • A Commernauts account. Sign up at commernauts.com if you have none; the same account runs stores and publishes plug-ins.
  • Node.js 22.18 or newer and npm. Check with node --version. On a Mac, brew install node gives a current one.
  • A code editor and a terminal.
node --version   # v22.18.0 or newer
npm --version

2. Set up Studio (once)

Open the dashboard at dash.commernauts.com and choose Studio in the sidebar.

  1. Seller details: choose Add seller details and fill in who sells (a person or a company), the address, an email and phone where the marketplace can reach you, and a support contact buyers see. Save seller details. The marketplace takes no submission before this.
  2. Sandbox store: under Sandbox store, enter a name and an address (such as yourname-sandbox) and choose Create a sandbox store. It is free, takes no real orders and search engines skip it. You test your plug-in here.
  3. Payouts: only for paid plug-ins. Choose Set up payouts and follow Stripe. Free plug-ins skip this.

When the terms for creators are published, Seller details also asks you to accept them. A newer version asks again.

3. Create the project

npx --registry=https://npm.commernauts.com @commernauts/plugin new order-thanks
cd order-thanks
npm install

This makes a folder with everything a plug-in needs:

FileWhat it is
commernauts.plugin.tsWhat the plug-in is: its permissions, the events it runs on, and the settings owners fill in. Checked by TypeScript as you type.
src/index.tsThe code: one handler per event.
package.jsonnpm run build (bundle the plug-in) and npm run typecheck.
.npmrcPoints npm at npm.commernauts.com, where @commernauts/plugin comes from. Keep it.
package.jsonOne dependency, @commernauts/plugin: the types, the lists and the build. Nothing else from Commernauts is downloaded.

If npm warns about install scripts for esbuild, the build still works. If npm run build later says esbuild is missing, run npm install-scripts approve esbuild and npm install again.

4. Say what it needs: commernauts.plugin.ts

import { defineManifest, Event, Permission } from '@commernauts/plugin';

export default defineManifest({
  name: 'order-thanks',
  permissions: [Permission.OrdersRead, Permission.OrdersWrite],
  events: [Event.OrderCreated],
  settings: [
    { key: 'text', label: 'Note on each new order', type: 'text', required: true, default: 'Thank you for your order!' },
  ],
});
  • name: lower case, a-z, 0-9 and dashes. It names the built file.
  • permissions: what the store owner grants at install. orders.read lets it receive order events; orders.write lets it add notes. Ask only for what you use; owners see each one.
  • events: when it runs. Each event needs its permission: Event.OrderCreated needs Permission.OrdersRead.
  • settings: the form owners fill in. Types are text, secret (stored encrypted, never shown again), number and boolean.

Every event, permission, capability and action has a name in code: Event, Permission, Capability and Action from @commernauts/plugin. They are the one list the platform, the marketplace and the build all use. Type Event. and your editor lists every event; a missing permission is an error before you build:

permissions: [Permission.ProductsRead],
events: [Event.OrderCreated],
// error: Type '"order.created"' is not assignable to type 'EventsAllowedBy<"products.read">'

Each name comes with a description of what it is:

import { Event, PLUGIN_EVENTS } from '@commernauts/plugin';

PLUGIN_EVENTS[Event.OrderCreated];
// { permission: 'orders.read', description: 'A new order is placed' }

Plug-ins can also quote shipping rates at checkout, take calls from carriers and put buttons on the order page. The Plug-in reference lists every permission, event, capability and action.

5. Write the code: src/index.ts

import { definePlugin, Event, Action } from '@commernauts/plugin';
import manifest from '../commernauts.plugin.ts';

export default definePlugin(manifest, {
  [Event.OrderCreated]: (event, { install }) => [
    { type: Action.OrderNote, order_id: event.data.order.id, text: install.settings.text },
  ],
});

definePlugin takes the manifest, so every event it lists needs a handler, a handler for an event it does not list is an error, and install.settings has the fields of your settings form with their types.

  • Each handler gets the event (here, the new order) and the install: its id, the store id and the settings the owner chose.
  • It answers a list of actions. Commernauts applies each one the owner allowed, through the store's own API, under your plug-in's name. Your code never holds a store password or key.
  • Return nothing, or an empty list, to do nothing.
npm run typecheck   # checks the manifest and the code

6. Build it

npm run build
# dist/order-thanks.plugin.json  1.1 KB  order.created  (orders.read, orders.write)

The build checks the manifest against the same lists the marketplace uses, bundles the code and the manifest into one file, dist/<name>.plugin.json, and stops with what to fix if anything is wrong. That file is what you upload. Build again after every change.

7. Submit it in Studio

  1. In Studio choose Publish a plug-in.
  2. Name it, pick a category, and write a one-line summary and a description.
  3. Price: leave it empty for free. For a paid plug-in, enter euros and choose Billed: Once or Every month.
  4. Version: 1.0.0 for the first one.
  5. Terms of service link and Privacy policy link: https pages you host. Every plug-in needs both, because it works with store data. Buyers accept your terms when they install.
  6. Plugin package (JSON): choose dist/order-thanks.plugin.json, or paste its contents.
  7. Submit for review.

Automatic checks run at once and show on your listing: package size, the worker code, permissions, events, settings and the two links. A red check blocks approval; fix it and submit a new version. A yellow one is for the reviewer, for example a link that did not answer.

8. Install your draft on the sandbox store

You do not wait for review to try it: your own stores can install your draft.

  1. Open Marketplace and your listing (Studio, Your listings, its name).
  2. Under Install on, choose your sandbox store.
  3. Read what it asks for, fill in the settings, and tick I allow this plug-in to do what it asks.
  4. Install.

The plug-in now shows in the sandbox store under Admin, Store version, From the marketplace, with its settings and Recent runs.

9. Test it

  1. In the sandbox store, add a product if it has none (Products, New product).
  2. Open Orders. Under Test order, enter a customer name and email, choose the product and Place test order. A test order runs your plug-in like a real new order, with no payment.
  3. Open the order. Its timeline shows the note, under your plug-in's name.
  4. In Admin, Store version, From the marketplace, open Recent runs on your plug-in: each run shows the event, the actions and whether each was applied or refused.

Changed something? Raise the version in the publish form (1.0.1), upload the new build, then update the install on the sandbox store. Repeat until it does what you want.

A run that throws shows as an error in Recent runs, and the store sends the event again later. An action the owner did not allow shows as refused.

10. Review and going live

  • A marketplace reviewer looks at each version: the checks, your seller details, your terms and privacy links, and what the plug-in asks for.
  • Approved: the listing goes live and every store can install it. Rejected: the note tells you what to change; submit a new version.
  • Store owners now find it in Marketplace, see who sells it and your links, accept your terms, grant its permissions and install it.

11. After it is live

  • New versions: submit them from Studio, Your listings, New version. Each is reviewed; stores see Update and choose when to take it. A version that asks for more permissions asks owners again.
  • How it is doing: Studio shows installs and sales, and your listing shows recent runs across stores (event types and outcomes, never store data).
  • Unlisting or deleting: you can delete a listing nobody has bought or installed. Once anyone has, it stays for them and you can still publish versions.
  • Paid plug-ins: Stripe pays your share to your bank account; Commernauts keeps 30%.

Where to go next

  • Building a plug-in: the parts of a plug-in in more depth.
  • Plug-in reference: every permission, event, action, capability and limit.
  • Managing plug-ins (user docs): what store owners see and do once they install yours.