@zpl-toolchain/print 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ /** Configuration for connecting to a ZPL printer over TCP/IP. */
2
+ export interface PrinterConfig {
3
+ /** Printer IP address or hostname. */
4
+ host: string;
5
+ /** TCP port (default: 9100 — the standard ZPL raw printing port). */
6
+ port?: number;
7
+ /** Connection timeout in milliseconds (default: 5000). */
8
+ timeout?: number;
9
+ /** Maximum number of retry attempts on transient errors (default: 2). */
10
+ maxRetries?: number;
11
+ /** Base delay between retries in milliseconds; grows with exponential backoff (default: 500). */
12
+ retryDelay?: number;
13
+ }
14
+ /** Outcome of a print operation. */
15
+ export interface PrintResult {
16
+ /** Whether the ZPL was successfully sent to the printer. */
17
+ success: boolean;
18
+ /** Number of bytes written to the printer socket. */
19
+ bytesWritten: number;
20
+ /** Wall-clock duration of the operation in milliseconds. */
21
+ duration: number;
22
+ }
23
+ /** Parsed representation of the Zebra ~HS (Host Status) response.
24
+ *
25
+ * Contains all 24 fields from the three response lines,
26
+ * matching the Rust `HostStatus` struct for full parity.
27
+ */
28
+ export interface PrinterStatus {
29
+ /** Printer is ready to accept data (not paused, head closed, media loaded). */
30
+ ready: boolean;
31
+ /** Communication settings (field 0). */
32
+ communicationFlag: number;
33
+ /** Media (label stock) is depleted or not detected (field 1). */
34
+ paperOut: boolean;
35
+ /** Printer is in a paused state (field 2). */
36
+ paused: boolean;
37
+ /** Label length in dots (field 3). */
38
+ labelLengthDots: number;
39
+ /** Number of formats waiting in the receive buffer (field 4). */
40
+ formatsInBuffer: number;
41
+ /** Receive-buffer full (field 5). */
42
+ bufferFull: boolean;
43
+ /** Communications diagnostic mode active (field 6). */
44
+ commDiagMode: boolean;
45
+ /** Partial format in progress (field 7). */
46
+ partialFormat: boolean;
47
+ /** Reserved/unused field (field 8). */
48
+ reserved1: number;
49
+ /** Corrupt RAM detected (field 9). */
50
+ corruptRam: boolean;
51
+ /** Under-temperature condition (field 10). */
52
+ underTemperature: boolean;
53
+ /** Over-temperature condition (field 11). */
54
+ overTemperature: boolean;
55
+ /** Function settings bitmask (field 0). */
56
+ functionSettings: number;
57
+ /** Print head is open / not latched (field 1). */
58
+ headOpen: boolean;
59
+ /** Ribbon cartridge is depleted or missing (field 2). */
60
+ ribbonOut: boolean;
61
+ /** Thermal transfer mode active (field 3). */
62
+ thermalTransferMode: boolean;
63
+ /** Print mode code (field 4): 0=tear-off, 1=peel-off, 2=rewind, etc. */
64
+ printMode: number;
65
+ /** Print width mode (field 5). */
66
+ printWidthMode: number;
67
+ /** Label waiting to be taken (field 6). */
68
+ labelWaiting: boolean;
69
+ /** Number of labels remaining in the current batch (field 7). */
70
+ labelsRemaining: number;
71
+ /** Format-while-printing flag/mask (field 8). */
72
+ formatWhilePrinting: number;
73
+ /** Number of graphics stored in memory (field 9). */
74
+ graphicsStoredInMemory: number;
75
+ /** Password value (field 0). */
76
+ password: number;
77
+ /** Static RAM installed flag (field 1). */
78
+ staticRamInstalled: boolean;
79
+ /** The raw ~HS response string for advanced inspection. */
80
+ raw: string;
81
+ }
82
+ /** A printer device as reported by the Zebra Browser Print agent. */
83
+ export interface PrinterDevice {
84
+ /** Human-readable device name (e.g. "ZD421"). */
85
+ name: string;
86
+ /** Unique device identifier. */
87
+ uid: string;
88
+ /** Connection type reported by the agent (e.g. "network", "usb", "driver"). */
89
+ connection: string;
90
+ /** Device type string. */
91
+ deviceType: string;
92
+ /** Provider identifier. */
93
+ provider: string;
94
+ /** Manufacturer string. */
95
+ manufacturer: string;
96
+ }
97
+ /** Configuration for the HTTP print proxy server. */
98
+ export interface ProxyConfig {
99
+ /** Port the proxy listens on (default: 3001). */
100
+ port?: number;
101
+ /** Hostname to bind to (default: "127.0.0.1"). */
102
+ hostname?: string;
103
+ /**
104
+ * List of allowed printer IPs / hostnames.
105
+ * Required — the proxy rejects all requests when this is empty or undefined (SSRF protection).
106
+ * Supports simple glob patterns with `*` (e.g., `"192.168.1.*"`).
107
+ */
108
+ allowedPrinters?: string[];
109
+ /**
110
+ * List of allowed destination ports.
111
+ * Defaults to `[9100]`. Restricts which ports the proxy can connect to,
112
+ * preventing port-scanning attacks on allowed hosts.
113
+ */
114
+ allowedPorts?: number[];
115
+ /**
116
+ * Maximum number of concurrent WebSocket connections.
117
+ * Defaults to 50. New connections are rejected when the limit is reached.
118
+ */
119
+ maxConnections?: number;
120
+ /** Maximum request body size in bytes (default: 1 MiB). */
121
+ maxPayloadSize?: number;
122
+ /**
123
+ * CORS allowed origins.
124
+ * `"*"` allows any origin; an array restricts to specific origins.
125
+ * Default: `"*"`.
126
+ */
127
+ cors?: string | string[];
128
+ }
129
+ /** Options for pre-print validation via `printValidated()`. */
130
+ export interface ValidateOptions {
131
+ /**
132
+ * Printer profile JSON string for profile-aware validation.
133
+ * Enables DPI-specific, media-specific, and hardware-gated checks.
134
+ *
135
+ * Pass the raw JSON string of a printer profile (e.g., `fs.readFileSync("ZD421.json", "utf-8")`).
136
+ */
137
+ profileJson?: string;
138
+ /**
139
+ * Whether to treat warnings as errors (abort printing if any warnings are found).
140
+ * Default: `false`.
141
+ */
142
+ strict?: boolean;
143
+ }
144
+ /** Options for batch printing with status polling. */
145
+ export interface BatchOptions {
146
+ /**
147
+ * Poll printer status (`~HS`) every N labels.
148
+ * When undefined or 0, no status polling is performed.
149
+ */
150
+ statusInterval?: number;
151
+ }
152
+ /** Progress update emitted after each label in a batch. */
153
+ export interface BatchProgress {
154
+ /** Number of labels sent so far. */
155
+ sent: number;
156
+ /** Total number of labels in the batch. */
157
+ total: number;
158
+ /** Latest printer status (only present when `statusInterval` is set). */
159
+ status?: PrinterStatus;
160
+ }
161
+ /** Final result of a batch print operation. */
162
+ export interface BatchResult {
163
+ /** Number of labels successfully sent. */
164
+ sent: number;
165
+ /** Total number of labels in the batch. */
166
+ total: number;
167
+ }
168
+ /** Well-known error codes surfaced by the print client. */
169
+ export type PrintErrorCode = "CONNECTION_REFUSED" | "TIMEOUT" | "HOST_NOT_FOUND" | "BROKEN_PIPE" | "CONNECTION_RESET" | "VALIDATION_FAILED" | "UNKNOWN";
170
+ /** An error thrown by the print client with a classified code. */
171
+ export declare class PrintError extends Error {
172
+ readonly code: PrintErrorCode;
173
+ constructor(message: string, code: PrintErrorCode, cause?: unknown);
174
+ }
175
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IAEb,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,4DAA4D;IAC5D,OAAO,EAAE,OAAO,CAAC;IAEjB,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IAErB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAE5B,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAC;IAGf,wCAAwC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,sCAAsC;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,uDAAuD;IACvD,YAAY,EAAE,OAAO,CAAC;IACtB,4CAA4C;IAC5C,aAA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,0 +1,14 @@
1
+ // ─── Printer connection configuration ────────────────────────────────────────
2
+ /** An error thrown by the print client with a classified code. */
3
+ export class PrintError extends Error {
4
+ code;
5
+ constructor(message, code, cause) {
6
+ super(message);
7
+ this.name = "PrintError";
8
+ this.code = code;
9
+ if (cause) {
10
+ this.cause = cause;
11
+ }
12
+ }
13
+ }
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAuOhF,kEAAkE;AAClE,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnB,IAAI,CAAiB;IAErC,YAAY,OAAe,EAAE,IAAoB,EAAE,KAAe;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@zpl-toolchain/print",
3
+ "version": "0.1.2",
4
+ "description": "Print client for sending ZPL to Zebra and ZPL-compatible printers",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "sideEffects": false,
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "node": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./proxy": {
19
+ "types": "./dist/proxy.d.ts",
20
+ "node": "./dist/proxy.js"
21
+ },
22
+ "./browser": {
23
+ "types": "./dist/browser.d.ts",
24
+ "default": "./dist/browser.js"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test": "node --test dist/test/*.js",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "keywords": [
33
+ "zpl",
34
+ "zebra",
35
+ "label",
36
+ "printer",
37
+ "print",
38
+ "tcp",
39
+ "raw"
40
+ ],
41
+ "license": "MIT OR Apache-2.0",
42
+ "author": "zpl-toolchain contributors",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/trevordcampbell/zpl-toolchain.git",
46
+ "directory": "packages/ts/print"
47
+ },
48
+ "homepage": "https://github.com/trevordcampbell/zpl-toolchain",
49
+ "bugs": {
50
+ "url": "https://github.com/trevordcampbell/zpl-toolchain/issues"
51
+ },
52
+ "files": [
53
+ "dist/**/*.js",
54
+ "dist/**/*.d.ts",
55
+ "dist/**/*.d.ts.map",
56
+ "dist/**/*.js.map",
57
+ "!dist/test",
58
+ "README.md"
59
+ ],
60
+ "publishConfig": {
61
+ "access": "public"
62
+ },
63
+ "devDependencies": {
64
+ "@types/node": "^25.2.2",
65
+ "@types/ws": "^8.18.1",
66
+ "typescript": "^5.0.0"
67
+ },
68
+ "peerDependencies": {
69
+ "@zpl-toolchain/core": ">=0.1.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@zpl-toolchain/core": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "dependencies": {
77
+ "ws": "^8.19.0"
78
+ }
79
+ }