JavaScript SDK (browser)
@jodaprint/sdk
Classes
JodaPrint
Prints through the JodaPrint agent on this computer (local mode, A6).
const jp = new JodaPrint({ orgId, signer }); await jp.connect(); await jp.print({ type: "receipt", data: jp.receipt().text("Hello").cut() });
Constructors
Constructor
new JodaPrint(
options?):JodaPrint
Parameters
options?
JodaPrintOptions = {}
Returns
JodaPrint
Properties
drawer
readonlydrawer:object
open
open: (
printer?,pin?) =>Promise<{ok:true; }>
Parameters
printer?
PrinterRef
pin?
2 | 5
Returns
Promise<{ ok: true; }>
jobs
readonlyjobs:object
cancel
cancel: (
jobId) =>Promise<PrintResult>
Parameters
jobId
string
Returns
Promise<PrintResult>
get
get: (
jobId) =>Promise<Job>
Parameters
jobId
string
Returns
Promise<Job>
printers
readonlyprinters:object
list
list: () =>
Promise<Printer[]>
Returns
Promise<Printer[]>
status
status: (
printerId) =>Promise<PrinterStatus>
Parameters
printerId
string
Returns
Promise<PrinterStatus>
Accessors
agent
Get Signature
get agent():
AgentInfo|null
The connected agent (version, capabilities...), or null.
Returns
AgentInfo | null
Methods
call()
call<
T>(method,params?):Promise<T>
Sends any agent method (the typed helpers above cover all of A6).
Type Parameters
T
T
Parameters
method
string
params?
Record<string, unknown> = {}
Returns
Promise<T>
connect()
connect():
Promise<AgentInfo>
Finds the agent: tries each port in order and resolves with agent.info.
Returns
Promise<AgentInfo>
disconnect()
disconnect():
void
Closes the connection and stops reconnecting.
Returns
void
isConnected()
isConnected():
boolean
Returns
boolean
on()
on<
E>(event,listener): () =>void
Type Parameters
E
E extends keyof JodaPrintEvents
Parameters
event
E
listener
Listener<E>
Returns
() => void
print()
print(
job):Promise<PrintResult>
Queues a job. Resolves once the agent stored it ({ jobId, state }).
Parameters
job
PrintJob
Returns
Promise<PrintResult>
printAndWait()
printAndWait(
job,options?):Promise<Job>
Prints and resolves when the job is printed; rejects with the job's error otherwise.
Parameters
job
PrintJob
options?
timeoutMs?
number
Returns
Promise<Job>
receipt()
receipt(
options?):ReceiptBuilder
Starts an A8 receipt document.
Parameters
options?
ReceiptOptions
Returns
ReceiptBuilder
JodaPrintError
Every error the SDK throws: agent errors (A9) and SDK-only ones.
Extends
Error
Constructors
Constructor
new JodaPrintError(
code,message,extra?):JodaPrintError
Parameters
code
AnyErrorCode
message
string
extra?
details?
Record<string, unknown>
helpUrl?
string
retryable?
boolean
Returns
JodaPrintError
Overrides
Error.constructor
Properties
code
readonlycode:AnyErrorCode
details
readonlydetails:Record<string,unknown> |undefined
helpUrl
readonlyhelpUrl:string|undefined
Where to download the agent (AGENT_NOT_FOUND) or how to trust it (AGENT_CERT_UNTRUSTED).
name
readonlyname:"JodaPrintError"="JodaPrintError"
Overrides
Error.name
retryable
readonlyretryable:boolean
ReceiptBuilder
Builds an A8 receipt document:
receipt({ width: "80mm" }) .text("Boutique Bèl Fanm").bold().center().size(2) .line("dashed") .pair("TOTAL", "2 400,00 HTG").bold() .qr("https://example.com/r/10492").center() .feed(3).cut() .build()
Style methods (bold, center, size, ...) change the block added just before them.
Constructors
Constructor
new ReceiptBuilder(
options?):ReceiptBuilder
Parameters
options?
ReceiptOptions
Returns
ReceiptBuilder
Methods
align()
align(
align):this
Parameters
align
Align
Returns
this
barcode()
barcode(
value,format?,options?):this
Parameters
value
string
format?
"CODE128" | "EAN13" | "EAN8" | "UPC-A" | "CODE39" | "ITF"
options?
BarcodeOptions
Returns
this
bold()
bold(
on?):this
Parameters
on?
boolean
Returns
this
build()
build():
ReceiptDocument
The finished document (a copy: the builder can keep going).
Returns
ReceiptDocument
center()
center():
this
Returns
this
cut()
cut(
mode?):this
Parameters
mode?
"full" | "partial"
Returns
this
drawer()
drawer(
pin?):this
Parameters
pin?
2 | 5
Returns
this
feed()
feed(
lines?):this
Parameters
lines?
number
Returns
this
font()
font(
font):this
Parameters
font
"a" | "b"
Returns
this
image()
image(
src,options?):this
An https URL or base64 PNG/JPEG; width in printer dots.
Parameters
src
string
options?
ImageOptions
Returns
this
invert()
invert(
on?):this
Parameters
on?
boolean
Returns
this
left()
left():
this
Returns
this
line()
line(
style?):this
Parameters
style?
"solid" | "dashed" | "double"
Returns
this
pair()
pair(
left,right,options?):this
Left and right text on one line, for totals.
Parameters
left
string
right
string
options?
PairOptions
Returns
this
qr()
qr(
value,options?):this
Parameters
value
string
options?
QrOptions
Returns
this
raw()
raw(
base64):this
Printer bytes (base64): an escape hatch for commands the format does not cover.
Parameters
base64
string
Returns
this
right()
right():
this
Returns
this
size()
size(
size):this
Character magnification, 1 to 8.
Parameters
size
number
Returns
this
table()
table(
columns,rows,options?):this
Columns with width fractions that add up to at most 1; numbers are shorthand for left-aligned columns of that width.
Parameters
columns
(number | TableColumn)[]
rows
string[][]
options?
TableOptions
Returns
this
text()
text(
value,options?):this
Parameters
value
string
options?
TextOptions
Returns
this
toJSON()
toJSON():
ReceiptDocument
Returns
ReceiptDocument
underline()
underline(
on?):this
Parameters
on?
boolean
Returns
this
Interfaces
AgentInfo
Result of agent.info (A6).
Properties
activated
activated:
boolean
True once the agent is activated.
arch
arch:
"amd64"|"arm64"|"arm"|"386"
capabilities
capabilities:
AgentCapability[]
deviceId
deviceId:
string
Device ID, generated once per installation.
orgId
orgId:
string|null
Organization ID, null before activation.
os
os:
"windows"|"darwin"|"linux"|"android"
version
version:
string
Agent version (semver).
Job
A job as stored by the agent or cloud (A7).
Properties
attempt
attempt:
number
Print attempts made so far.
createdAt
createdAt:
string
When the job was created.
deviceId?
optionaldeviceId?:string
errorCode?
optionalerrorCode?:ErrorCode
errorMessage?
optionalerrorMessage?:string
Last error message.
id
id:
string
Job ID.
idempotencyKey?
optionalidempotencyKey?:string
Idempotency key from the request.
metadata?
optionalmetadata?:object
Free key/value pairs stored with the job and searchable.
Index Signature
[k: string]: string
printedAt?
optionalprintedAt?:string
When the job printed.
printerId
printerId:
string
source
source:
"local"|"cloud"
state
state:
JobState
type
type:
JobType
updatedAt
updatedAt:
string
When the job last changed state.
JodaPrintBridge
The Android agent's WebView shell injects this object (Prompt 7.2, ADR 0039). It carries the same request, response and event envelopes as the WebSocket: one JSON text per message. Android's WebView delivers messages as events ({ data }); a plain string is accepted too.
Properties
onmessage
onmessage: ((
message) =>void) |null
Methods
postMessage()
postMessage(
message):void
Parameters
message
string
Returns
void
JodaPrintEvents
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
Properties
connected
connected:
AgentInfo
disconnected
disconnected:
object
code
code:
number
reason
reason:
string
job.updated
job.updated:
Job
printer.status
printer.status:
PrinterStatus
JodaPrintOptions
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
Properties
bridge?
optionalbridge?:boolean|JodaPrintBridge
Use window.JodaPrintBridge when the page runs in the Android agent's WebView shell (default true). Signatures and origin rules apply as over the WebSocket.
connectTimeoutMs?
optionalconnectTimeoutMs?:number
Time to open the connection on one port. Default 3 s.
downloadUrl?
optionaldownloadUrl?:string
Shown in AGENT_NOT_FOUND and AGENT_CERT_UNTRUSTED errors.
fetch?
optionalfetch?: {(input,init?):Promise<Response>; (input,init?):Promise<Response>; }
Replaces the global fetch used to diagnose connection failures.
Call Signature
(
input,init?):Promise<Response>
Parameters
input
RequestInfo | URL
init?
RequestInit
Returns
Promise<Response>
Call Signature
(
input,init?):Promise<Response>
Parameters
input
string | Request | URL
init?
RequestInit
Returns
Promise<Response>
host?
optionalhost?:string
Agent host. Default "localhost".
locale?
optionallocale?:string
Language of the SDK's own error messages: en, fr or ht (default: the browser's).
orgId?
optionalorgId?:string
The organization's ID; required with a signer.
ports?
optionalports?:number[]
reconnect?
optionalreconnect?:boolean
Reconnect after the agent restarts. Default true.
secure?
optionalsecure?:boolean
Use wss (default). ws only for agents started without TLS in development.
signer?
optionalsigner?:Signer
Signs each request on your backend. Without it requests are unsigned (unsigned mode, A10.3).
timeoutMs?
optionaltimeoutMs?:number
Per-request timeout, and how long calls wait while reconnecting. Default 30 s.
webSocket?
optionalwebSocket?: (url) =>WebSocketLike
Replaces new WebSocket(url) (tests, Node).
Parameters
url
string
Returns
WebSocketLike
Printer
A printer the agent can reach (A7). IDs are stable hashes of connection + address or OS name.
Properties
address?
optionaladdress?:string
Connection address: host:port, serial port, OS queue name or vendor ID.
alias?
optionalalias?:string
Alias from config.
capabilities
capabilities: (
"drawer"|"status.realtime"|"cut"|"color"|"duplex"|"copies"|"beep")[]
connection
connection:
"usb"|"network"|"serial"|"bluetooth"|"spooler"|"vendor"|"virtual"
id
id:
string
Stable printer ID.
isDefault
isDefault:
boolean
True for the default printer.
kind
kind:
"thermal"|"label"|"document"
name
name:
string
Display name.
paper?
optionalpaper?:Paper
PrinterStatus
Current state of one printer.
Properties
coverOpen?
optionalcoverOpen?:boolean
Cover open.
cutterError?
optionalcutterError?:boolean
Auto-cutter error.
errorCode?
optionalerrorCode?:ErrorCode
message?
optionalmessage?:string
Details for humans.
paperNearEnd?
optionalpaperNearEnd?:boolean
Paper near end sensor.
paperOut?
optionalpaperOut?:boolean
Paper end sensor.
printerId
printerId:
string
state
state:
"online"|"offline"|"error"|"unknown"
unrecoverableError?
optionalunrecoverableError?:boolean
Unrecoverable printer error.
updatedAt
updatedAt:
string
When this status was observed.
PrintResult
Result of print.
Properties
jobId
jobId:
string
state
state:
JobState
ReceiptDocument
A receipt described as blocks (A8). The agent renders it to ESC/POS for the target printer.
Properties
blocks
blocks: [
ReceiptBlock,...ReceiptBlock[]]
Min Items
1
Max Items
2000
codepage?
optionalcodepage?:Codepage
width?
optionalwidth?:"58mm"|"80mm"
ReceiptOptions
Properties
codepage?
optionalcodepage?:Codepage
width?
optionalwidth?:"58mm"|"80mm"
Signature
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
Properties
keyId
keyId:
string
nonce
nonce:
string
sig
sig:
string
ts
ts:
number
Unix seconds.
SignPayload
What the developer's backend signs (A10.1); it answers with the signature.
Properties
method
method:
string
orgId
orgId:
string
params
params:
unknown
WebSocketLike
The subset of the browser WebSocket the SDK uses (tests and Node pass their own).
Properties
onclose
onclose: ((
ev) =>void) |null
onerror
onerror: ((
ev) =>void) |null
onmessage
onmessage: ((
ev) =>void) |null
onopen
onopen: ((
ev) =>void) |null
readyState
readonlyreadyState:number
Methods
close()
close(
code?,reason?):void
Parameters
code?
number
reason?
string
Returns
void
send()
send(
data):void
Parameters
data
string
Returns
void
Type Aliases
Align
Align =
"left"|"center"|"right"
AnyErrorCode
AnyErrorCode =
ErrorCode|SdkErrorCode
Any error code a developer can receive from JodaPrint.
BarcodeOptions
BarcodeOptions =
Omit<BarcodeBlock,"type"|"value"|"format">
ContentPrintJob
ContentPrintJob =
Omit<ContentJobRequest,"encoding"|"data"> &object
A job as the SDK accepts it: encoding is optional and a receipt builder can be the data.
Type Declaration
data
data:
string|ReceiptDocument|ReceiptBuilder
encoding?
optionalencoding?:ContentJobRequest["encoding"]
ImageOptions
ImageOptions =
Omit<ImageBlock,"type"|"src">
JobRequest
JobRequest =
object
A print job submitted by a client (A7). With encoding json, data is a receipt document. With encoding url, data is an https URL the agent downloads. With templateId (Prompt 8.1), data holds the template's variables and the template sets the type and content.
Properties
data
data:
string|ReceiptDocument| { }
Job content, or template variables with templateId.
encoding?
optionalencoding?:"json"|"base64"|"utf8"|"url"
idempotencyKey?
optionalidempotencyKey?:string
Same key within 24 h returns the first job and prints nothing.
metadata?
optionalmetadata?:object
Free key/value pairs stored with the job and searchable.
Index Signature
[k: string]: string
options?
optionaloptions?:JobOptions
printer?
optionalprinter?:PrinterRef
templateId?
optionaltemplateId?:string
Print a stored template (ZPL, EPL or receipt) filled with data. The job then has no type or encoding.
type?
optionaltype?:JobType
JobState
JobState =
"queued"|"sending"|"printed"|"failed"|"cancelled"
PairOptions
PairOptions =
Omit<PairBlock,"type"|"left"|"right">
PrinterRef
PrinterRef =
PrinterRefById|PrinterRefByAlias|PrinterRefByName
Selects a printer by id, alias or name (A7). Omit the whole reference to use the default printer.
PrintJob
PrintJob =
ContentPrintJob|TemplatePrintJob
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
QrOptions
QrOptions =
Omit<QrBlock,"type"|"value">
ReceiptBlock
ReceiptBlock =
TextBlock|LineBlock|PairBlock|TableBlock|QrBlock|BarcodeBlock|ImageBlock|FeedBlock|CutBlock|DrawerBlock|RawBlock
Signer
Signer = (
payload) =>Promise<Signature>
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
Parameters
payload
SignPayload
Returns
Promise<Signature>
TableOptions
TableOptions =
Omit<TableBlock,"type"|"columns"|"rows">
TemplatePrintJob
TemplatePrintJob =
TemplateJobRequest
A template stored in the dashboard, filled with variables (Prompt 8.1): { templateId, data }.
TextOptions
TextOptions =
Omit<TextBlock,"type"|"value">
Variables
DEFAULT_DOWNLOAD_URL
constDEFAULT_DOWNLOAD_URL:"https://dashboard-production-b942.up.railway.app/"="https://dashboard-production-b942.up.railway.app/"
@jodaprint/sdk: print from the browser through the JodaPrint agent on this computer (local mode, A6). Zero runtime dependencies.
DEFAULT_PORTS
constDEFAULT_PORTS:number[]
Ports the agent tries, in order (A6).
Functions
httpSigner()
httpSigner(
url,init?):Signer
A signer that POSTs { method, orgId, params } to your backend (see @jodaprint/node signRequestHandler) and returns its { keyId, sig, ts, nonce }.
Parameters
url
string
init?
RequestInit = {}
Returns
Signer
receipt()
receipt(
options?):ReceiptBuilder
Starts a receipt document.
Parameters
options?
ReceiptOptions
Returns
ReceiptBuilder