UNPKG

@danidoble/webserial-vending-commands

Version:
121 lines (120 loc) 3.45 kB
var u = Object.defineProperty; var d = (r, t, i) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[t] = i; var o = (r, t, i) => d(r, typeof t != "symbol" ? t + "" : t, i); import { p as l } from "./parser-DRICA5j-.js"; const n = class n { build(t) { return l(t + n.append); } static connection() { const t = JSON.stringify({ action: "CONNECT" }); return n.instance.build(t); } static connect() { return n.connection(); } static custom(t) { if (typeof t != "string") throw new Error("Invalid string"); return n.instance.build(t); } static readQR({ type: t = "production" } = { type: "production" }) { const i = JSON.stringify({ action: "READQR", server: t === "production" ? "PROD" : "QA" }); return n.instance.build(i); } static forceHide() { const t = JSON.stringify({ action: "FORCEHIDE" }); return n.instance.build(t); } static forceShow() { const t = JSON.stringify({ action: "FORCESHOW" }); return n.instance.build(t); } static makeSale({ amount: t = 0, reference: i = null } = {}) { if (t <= 0) throw new Error("Invalid amount"); if (typeof t != "number" && (t = parseFloat(t)), isNaN(t)) throw new Error("Invalid amount"); if (i && !/^[A-Z-a-z0-9_\s]+$/g.test(i)) throw new Error( "Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null" ); const a = t.toFixed(2), e = JSON.stringify({ action: "PAYMENT", amount: a, reference: i }); return n.instance.build(e); } static getVoucher({ folio: t = null } = {}) { if (!t) throw new Error("Folio must be a number"); const i = JSON.stringify({ action: "GETVOUCHER", folio: t }); return n.instance.build(i); } static info() { const t = JSON.stringify({ action: "DEVICEINFO" }); return n.instance.build(t); } static keepAlive() { const t = JSON.stringify({ action: "KEEPALIVE" }); return n.instance.build(t); } static restartApp() { const t = JSON.stringify({ action: "RESETAPP" }); return n.instance.build(t); } static getConfig() { const t = JSON.stringify({ action: "GETCONFIG" }); return n.instance.build(t); } static hideButtons() { const t = JSON.stringify({ action: "HIDEBUTTONS" }); return n.instance.build(t); } static showButtons() { const t = JSON.stringify({ action: "SHOWBUTTONS" }); return n.instance.build(t); } static demo() { const t = JSON.stringify({ action: "DEMO" }); return n.instance.build(t); } static refund({ amount: t = 0, folio: i = null, auth: a = null } = {}) { if (t <= 0) throw new Error("Invalid amount"); if (typeof t != "number" && (t = parseFloat(t)), isNaN(t)) throw new Error("Invalid amount"); if (!i) throw new Error("Folio must be a number"); if (!a) throw new Error("Auth must be a number"); const e = t.toFixed(2), c = JSON.stringify({ action: "REFUND", amount: e, folio: i, auth: a }); return n.instance.build(c); } static exit() { const t = JSON.stringify({ action: "EXIT" }); return n.instance.build(t); } static init() { const t = JSON.stringify({ action: "INIT" }); return n.instance.build(t); } }; o(n, "append", `\r `), o(n, "instance"); let s = n; s.instance = new s(); export { s as PinPax };