/** * Types for `window.Emda`: the API that Emda kiosks give to the pages they show. * Docs: https://emda.io/docs/page-api ยท For AI agents: https://emda.io/llms-full.txt * * `window.Emda` is undefined outside Emda, and each part only exists when it's turned on in the * kiosk's Settings: page integration (version, device info, print, navigation), the receipt * printer (`receipt`) and the scale (`scale`). Always feature-detect. */ export {}; declare global { interface Window { Emda?: Emda.Api; } interface WindowEventMap { /** Fired once when `window.Emda` is ready (if it exists at all on this kiosk). */ 'emda:ready': Event; } namespace Emda { type Result = { ok: true } | { ok: false; error: E }; interface DeviceInfo { /** Stable per install; Settings โ†’ Diagnostics shows a short form. */ deviceId: string; appVersion: string; platform: string; } type PrintError = 'unavailable' | 'printing-disabled' | 'not-licensed' | 'blocked' | 'print-failed'; type ReceiptError = | 'receipt-disabled' | 'not-licensed' | 'blocked' | 'printer-unreachable' | 'printer-failed' | 'render-failed'; interface ReceiptOptions { /** Override the kiosk's "cut after printing" setting. */ cut?: boolean; /** Override the kiosk's "open the cash drawer" setting. */ openDrawer?: boolean; } interface Receipt { /** * Prints HTML on the ESC/POS receipt printer. It's drawn at paper width (58 mm = 384 CSS px, * 80 mm = 576 CSS px), black on white. Scripts inside it don't run. */ print(html: string, options?: ReceiptOptions): Promise>; /** Loads a page at paper width (with the kiosk's cookies) and prints it. */ printUrl(url: string, options?: ReceiptOptions): Promise>; /** Opens the cash drawer on the receipt printer's drawer port. */ openDrawer(): Promise>; } type ScaleStatus = 'stable' | 'repeated' | 'unstable' | 'zero' | 'negative' | 'overweight' | 'unknown'; interface ScaleReading { status: ScaleStatus; statusRaw?: string; /** Kilograms. */ weight: number; hasWeight: boolean; stable: boolean; overweight: boolean; underweight: boolean; /** The scale's raw reply, for logging. */ raw: string; } type ScaleErrorCode = | 'not_connected' | 'not_licensed' | 'timeout' | 'bad_response' | 'bad_request' | 'not_supported' | 'cancelled'; /** Scale methods reject with this. */ interface ScaleError { code: ScaleErrorCode; /** HTTP-like status: 503, 402, 504, 502, 400, 501, or 0 for cancelled. */ status: number; message: string; } interface WaitForStableOptions { /** Default 30000. */ timeoutMs?: number; /** Default 400. */ intervalMs?: number; /** Called on every poll with the reading, or null and an error code. */ onReading?: (reading: ScaleReading | null, errorCode: ScaleErrorCode | null) => void; } interface Scale { getWeight(): Promise; /** stable && hasWeight && in range && weight > 0 */ isUsableReading(reading: ScaleReading | null | undefined): boolean; /** Polls until a usable reading or the timeout. */ waitForStable(options?: WaitForStableOptions): { promise: Promise; cancel(): void }; zero(): Promise; /** Kilograms. */ setTare(kg: number): Promise; clearTare(): Promise; /** SHEKEL only. */ setUnitPrice(unitPrice: number): Promise; /** SHEKEL only. */ getTotal(): Promise<{ success: boolean; totalPrice: number; raw: string }>; getFirmware(): Promise<{ firmwareId: string }>; } interface Api { /** Always true once the object exists. */ ready: true; /** Page integration only (Settings โ†’ Remote API โ†’ Allow page integration). */ version?: string; getDeviceInfo?(): Promise; /** Same as window.print(): follows the kiosk's printing settings (silent or dialog). */ print?(): void; /** Renders another page and prints it on the normal printer. */ printUrl?(url: string): Promise>; home?(): void; reload?(): void; back?(): void; forward?(): void; /** Only when the receipt printer is on. */ receipt?: Receipt; /** Only when the scale is on. */ scale?: Scale; } } }