Storeware Docs

The SDK

createStorewareApp handles webhooks, installs, admin sessions and API clients in one place.

Early access

The CLI and the SDK are not on npm yet, so the commands below do not run for everyone. If you would like to build an app now, tell us.
npm install @storeware/plugin-sdk

One object

import { createStorewareApp, kvInstallationStore } from '@storeware/plugin-sdk';

const storeware = createStorewareApp({
  clientId: env.STOREWARE_CLIENT_ID,
  clientSecret: env.STOREWARE_CLIENT_SECRET,
  installations: kvInstallationStore(env.INSTALLATIONS),
});

storeware.webhooks.on('order.paid.v1', async (event) => {
  const client = await storeware.clientFor(event.storeId);
  // ...
});
  • webhooks.handle(request) verifies each delivery with the secret of the shop it names, finishes installs from their grant, and dispatches.
  • authenticateAdmin(request) proves the person looking at your home or panel, from its session token, and trades the first one for the install.
  • verifyRequest(request, kind) does the same for tool, knowledge and block calls.
  • clientFor(storeId) is an API client whose tokens rotate into your store by themselves.

Anywhere

Every handler takes a fetch Request and returns a Response, and signing uses WebCrypto, so the SDK runs on Workers, Next route handlers, Hono, Bun, Deno and Node. For Express or node:http:

import { toNodeListener } from '@storeware/plugin-sdk/node';

app.post('/webhooks', toNodeListener((request) => storeware.webhooks.handle(request)));

Mount it before any body parser.

Hosted by Storeware

For an app Storeware hosts, createHostedApp(env) returns the same object, built on what Storeware hands your code instead of a client secret and a store:

import { createHostedApp } from '@storeware/plugin-sdk';

const storeware = createHostedApp(env);

Swap it for createStorewareApp to move the app to a server of your own, and back.

Testing

@storeware/plugin-sdk/testing signs requests and mints sessions exactly as Storeware does, so a handler that passes your tests verifies real traffic.

import { signedDelivery } from '@storeware/plugin-sdk/testing';

const request = await signedDelivery({ secret, event: 'order.paid.v1', storeId });

Reference

Every export, module by module, read from the SDK's own source.

On this page