@evopos/vite-plugin
v0.1.0
Published
Vite plugin for EvoPOS plugin developers: multi-page build, manifest.json checks, fake kassa at /__evopos/, sandbox dev mode
Readme
@evopos/vite-plugin
Vite plugin for EvoPOS plugin developers. It sets up a multi-page build for your slot pages, checks manifest.json while you type, serves a fake kassa at /__evopos/, and (optionally) registers your dev server in your EvoPOS sandbox so the real sandbox kassa opens your pages from localhost.
Install
npm install -D @evopos/vite-plugin viteRequires Node 20+ and Vite 6 or newer.
Usage
// vite.config.ts
import { defineConfig } from 'vite';
import evopos from '@evopos/vite-plugin';
export default defineConfig({
plugins: [evopos()],
});The plugin returns an array of Vite plugins; evopos() can be placed in plugins as is. A named export evopos is available too.
What it does:
- Sets
base: './'(the plugin is served from a sandboxed iframe, so absolute asset paths would break). - Uses every
*.htmlin the project root and every*.htmlunderpages/as a build input (unless you setbuild.rollupOptions.input/build.rolldownOptions.inputyourself). - Enables dev-server CORS for the sandbox iframe, whose origin is
null, pluslocalhost. It never usesorigin: true. Private Network Access preflights are answered too. - Validates
manifest.jsonagainst the EvoPOS contracts and checks that every slotentryis one of the build inputs. For drivers it checks that theentryfile exists inpublic/.- Dev: errors show in the Vite overlay and in the terminal; the page reloads once the manifest is fixed.
GET /manifest.jsonserves the manifest (HTTP 422 with{ ok: false, errors }while it is invalid). - Build: the build fails with the list of errors; a valid manifest is emitted as
manifest.jsonin the output.
- Dev: errors show in the Vite overlay and in the terminal; the page reloads once the manifest is fixed.
Options
| Option | Type | Default | Description |
|---|---|---|---|
| manifest | string | 'manifest.json' | Path to the manifest, relative to the project root. |
| pagesDir | string | 'pages' | Folder whose *.html files (recursively) are build inputs. |
| devSession | boolean | true | Register the dev server in your sandbox (see below). |
| devUrl | string | EVOPOS_DEV_URL, else http(s)://localhost:<port>/ | URL the sandbox kassa opens in the iframe. |
| fakeKassa | boolean | true | Serve the fake kassa page at /__evopos/. |
| api | string | EVOPOS_API_BASE, else production | Developer API base URL (same as --api in the CLI). |
createClient, now and env exist for tests only.
Fake kassa: /__evopos/
Open http://localhost:5173/__evopos/ while vite is running. The page loads your slot in a sandboxed iframe (sandbox="allow-scripts", so the same origin null as in the real kassa) and plays the host side of the protocol:
- pick a slot, edit the context JSON and the granted permissions;
- emit events, including
receipt.before_closewith a checked response; - see every call the plugin makes (
ui.toast,ui.notify,ui.confirm,ui.open_modal, ...) in a log; - modals opened with
ui.open_modalappear as windows with their own iframe; - manifest errors are shown on the page; drivers get a short note instead of a slot (they have no UI).
The page works fully offline and needs no account. The page is available only in the dev server and is not part of the build. Turn it off with evopos({ fakeKassa: false }).
Dev mode in the sandbox
When you run vite, the plugin can register your dev server in your EvoPOS sandbox, so you can see the plugin inside the real sandbox kassa:
- Log in once:
npx evopos login(or setEVOPOS_TOKEN). - Run
vite. The plugin sends the manifest and your dev URL to the developer API (PUT). The terminal banner shows the sandbox it is connected to. - A dev session lives 15 minutes. The plugin renews it (heartbeat, about every third of the TTL) and re-sends the manifest when you change it.
- On exit (
Ctrl+Corserver.close()) the plugin removes the session (DELETE).
Without a token, dev mode is skipped with a hint to run evopos login; nothing else is affected. A network failure is a warning and the plugin retries; a rejected token (401/403) stops the heartbeat. Turn dev mode off with evopos({ devSession: false }).
Other devices and https
The sandbox kassa opens your devUrl from the browser of whoever uses the kassa. http://localhost works on your own machine. To open it from another device (a phone, a second computer with a kassa) you need an address that device can reach, and over https if the kassa itself runs on https (browsers block mixed content):
# one-time: local CA and a certificate for your LAN name
brew install mkcert # or see https://github.com/FiloSottile/mkcert
mkcert -install
mkcert localhost 192.168.1.20// vite.config.ts
import fs from 'node:fs';
import { defineConfig } from 'vite';
import evopos from '@evopos/vite-plugin';
export default defineConfig({
server: {
host: true,
https: {
key: fs.readFileSync('./localhost+1-key.pem'),
cert: fs.readFileSync('./localhost+1.pem'),
},
},
plugins: [evopos({ devUrl: 'https://192.168.1.20:5173/' })],
});The other device must trust the mkcert root CA (install rootCA.pem there). If you start the server with --host and without https, the plugin prints a warning. Instead of devUrl you can set EVOPOS_DEV_URL.
Environment variables
| Variable | Meaning |
|---|---|
| EVOPOS_TOKEN | Developer token (otherwise the one saved by evopos login). |
| EVOPOS_DEV_URL | URL for the sandbox kassa to open (overridden by the devUrl option). |
| EVOPOS_API_BASE | Developer API base URL (overridden by the api option). |
License
MIT
