File: examples/plugins/event-webhooks/plugin.js (71 lines)
// event-webhooks: settings for an events-only device.json.
//
// The events themselves are sent by the reader (no browser needed). This page
// stores {server, secret} in config.json and can send a test request that
// looks exactly like a real "reader.exit" delivery, so you can check your
// receiver before reading a single page.
CrossPoint.registerPlugin(async (container, api) => {
const $ = (s) => container.querySelector(s);
const b64 = (t) => { let s = ''; for (const c of new TextEncoder().encode(t)) s += String.fromCharCode(c); return btoa(s); };
const read = async (name) => {
try { const r = await fetch(api.pluginFile(name)); return r.ok ? await r.json() : {}; } catch (e) { return {}; }
};