dazzle-zpl 0.1.0

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Dazzle: () => Dazzle,
24
+ DazzleError: () => DazzleError
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var Dazzle = class {
28
+ constructor(options) {
29
+ const host = options?.host ?? "localhost";
30
+ const port = options?.port ?? 29100;
31
+ const protocol = options?.protocol ?? "http";
32
+ this.baseUrl = `${protocol}://${host}:${port}`;
33
+ }
34
+ /** Check if the Dazzle server is reachable. */
35
+ async isRunning() {
36
+ try {
37
+ await this.status();
38
+ return true;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ /** Get server status and version. */
44
+ async status() {
45
+ const res = await fetch(`${this.baseUrl}/status`);
46
+ if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);
47
+ return res.json();
48
+ }
49
+ /** List available printers on the host machine. */
50
+ async printers() {
51
+ const res = await fetch(`${this.baseUrl}/printers`);
52
+ if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);
53
+ return res.json();
54
+ }
55
+ /**
56
+ * Send ZPL to be printed.
57
+ *
58
+ * Uses the server's configured default printer unless
59
+ * `options.printer` is specified.
60
+ */
61
+ async print(zpl, options) {
62
+ const url = new URL(`${this.baseUrl}/print`);
63
+ if (options?.printer) {
64
+ url.searchParams.set("printer", options.printer);
65
+ }
66
+ const res = await fetch(url, { method: "POST", body: zpl });
67
+ if (!res.ok) {
68
+ const body = await res.text().catch(() => "");
69
+ throw new DazzleError(body || `Print failed: ${res.status}`, res.status);
70
+ }
71
+ return res.json();
72
+ }
73
+ };
74
+ var DazzleError = class extends Error {
75
+ constructor(message, statusCode) {
76
+ super(message);
77
+ this.statusCode = statusCode;
78
+ this.name = "DazzleError";
79
+ }
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ Dazzle,
84
+ DazzleError
85
+ });
86
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DazzleOptions {\n /** Hostname of the Dazzle server. @default \"localhost\" */\n host?: string;\n /** Port of the Dazzle server. @default 29100 */\n port?: number;\n /** Protocol to use. @default \"http\" */\n protocol?: 'http' | 'https';\n}\n\nexport interface Printer {\n name: string;\n is_default: boolean;\n}\n\nexport interface PrintResult {\n job_id: string;\n}\n\nexport interface ServerStatus {\n status: string;\n version: string;\n}\n\nexport interface PrintOptions {\n /** Override the default printer for this job. */\n printer?: string;\n}\n\nexport class Dazzle {\n private baseUrl: string;\n\n constructor(options?: DazzleOptions) {\n const host = options?.host ?? 'localhost';\n const port = options?.port ?? 29100;\n const protocol = options?.protocol ?? 'http';\n this.baseUrl = `${protocol}://${host}:${port}`;\n }\n\n /** Check if the Dazzle server is reachable. */\n async isRunning(): Promise<boolean> {\n try {\n await this.status();\n return true;\n } catch {\n return false;\n }\n }\n\n /** Get server status and version. */\n async status(): Promise<ServerStatus> {\n const res = await fetch(`${this.baseUrl}/status`);\n if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);\n return res.json();\n }\n\n /** List available printers on the host machine. */\n async printers(): Promise<Printer[]> {\n const res = await fetch(`${this.baseUrl}/printers`);\n if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);\n return res.json();\n }\n\n /**\n * Send ZPL to be printed.\n *\n * Uses the server's configured default printer unless\n * `options.printer` is specified.\n */\n async print(zpl: string, options?: PrintOptions): Promise<PrintResult> {\n const url = new URL(`${this.baseUrl}/print`);\n if (options?.printer) {\n url.searchParams.set('printer', options.printer);\n }\n\n const res = await fetch(url, { method: 'POST', body: zpl });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n throw new DazzleError(body || `Print failed: ${res.status}`, res.status);\n }\n\n return res.json();\n }\n}\n\nexport class DazzleError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n this.name = 'DazzleError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BO,IAAM,SAAN,MAAa;AAAA,EAGlB,YAAY,SAAyB;AACnC,UAAM,OAAO,SAAS,QAAQ;AAC9B,UAAM,OAAO,SAAS,QAAQ;AAC9B,UAAM,WAAW,SAAS,YAAY;AACtC,SAAK,UAAU,GAAG,QAAQ,MAAM,IAAI,IAAI,IAAI;AAAA,EAC9C;AAAA;AAAA,EAGA,MAAM,YAA8B;AAClC,QAAI;AACF,YAAM,KAAK,OAAO;AAClB,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,SAAgC;AACpC,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,SAAS;AAChD,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,YAAY,iBAAiB,IAAI,MAAM,IAAI,IAAI,MAAM;AAC5E,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAAA,EAGA,MAAM,WAA+B;AACnC,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,WAAW;AAClD,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,YAAY,iBAAiB,IAAI,MAAM,IAAI,IAAI,MAAM;AAC5E,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,MAAM,KAAa,SAA8C;AACrE,UAAM,MAAM,IAAI,IAAI,GAAG,KAAK,OAAO,QAAQ;AAC3C,QAAI,SAAS,SAAS;AACpB,UAAI,aAAa,IAAI,WAAW,QAAQ,OAAO;AAAA,IACjD;AAEA,UAAM,MAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,QAAQ,MAAM,IAAI,CAAC;AAE1D,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,EAAE;AAC5C,YAAM,IAAI,YAAY,QAAQ,iBAAiB,IAAI,MAAM,IAAI,IAAI,MAAM;AAAA,IACzE;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AACF;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,46 @@
1
+ interface DazzleOptions {
2
+ /** Hostname of the Dazzle server. @default "localhost" */
3
+ host?: string;
4
+ /** Port of the Dazzle server. @default 29100 */
5
+ port?: number;
6
+ /** Protocol to use. @default "http" */
7
+ protocol?: 'http' | 'https';
8
+ }
9
+ interface Printer {
10
+ name: string;
11
+ is_default: boolean;
12
+ }
13
+ interface PrintResult {
14
+ job_id: string;
15
+ }
16
+ interface ServerStatus {
17
+ status: string;
18
+ version: string;
19
+ }
20
+ interface PrintOptions {
21
+ /** Override the default printer for this job. */
22
+ printer?: string;
23
+ }
24
+ declare class Dazzle {
25
+ private baseUrl;
26
+ constructor(options?: DazzleOptions);
27
+ /** Check if the Dazzle server is reachable. */
28
+ isRunning(): Promise<boolean>;
29
+ /** Get server status and version. */
30
+ status(): Promise<ServerStatus>;
31
+ /** List available printers on the host machine. */
32
+ printers(): Promise<Printer[]>;
33
+ /**
34
+ * Send ZPL to be printed.
35
+ *
36
+ * Uses the server's configured default printer unless
37
+ * `options.printer` is specified.
38
+ */
39
+ print(zpl: string, options?: PrintOptions): Promise<PrintResult>;
40
+ }
41
+ declare class DazzleError extends Error {
42
+ readonly statusCode: number;
43
+ constructor(message: string, statusCode: number);
44
+ }
45
+
46
+ export { Dazzle, DazzleError, type DazzleOptions, type PrintOptions, type PrintResult, type Printer, type ServerStatus };
@@ -0,0 +1,46 @@
1
+ interface DazzleOptions {
2
+ /** Hostname of the Dazzle server. @default "localhost" */
3
+ host?: string;
4
+ /** Port of the Dazzle server. @default 29100 */
5
+ port?: number;
6
+ /** Protocol to use. @default "http" */
7
+ protocol?: 'http' | 'https';
8
+ }
9
+ interface Printer {
10
+ name: string;
11
+ is_default: boolean;
12
+ }
13
+ interface PrintResult {
14
+ job_id: string;
15
+ }
16
+ interface ServerStatus {
17
+ status: string;
18
+ version: string;
19
+ }
20
+ interface PrintOptions {
21
+ /** Override the default printer for this job. */
22
+ printer?: string;
23
+ }
24
+ declare class Dazzle {
25
+ private baseUrl;
26
+ constructor(options?: DazzleOptions);
27
+ /** Check if the Dazzle server is reachable. */
28
+ isRunning(): Promise<boolean>;
29
+ /** Get server status and version. */
30
+ status(): Promise<ServerStatus>;
31
+ /** List available printers on the host machine. */
32
+ printers(): Promise<Printer[]>;
33
+ /**
34
+ * Send ZPL to be printed.
35
+ *
36
+ * Uses the server's configured default printer unless
37
+ * `options.printer` is specified.
38
+ */
39
+ print(zpl: string, options?: PrintOptions): Promise<PrintResult>;
40
+ }
41
+ declare class DazzleError extends Error {
42
+ readonly statusCode: number;
43
+ constructor(message: string, statusCode: number);
44
+ }
45
+
46
+ export { Dazzle, DazzleError, type DazzleOptions, type PrintOptions, type PrintResult, type Printer, type ServerStatus };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ // src/index.ts
2
+ var Dazzle = class {
3
+ constructor(options) {
4
+ const host = options?.host ?? "localhost";
5
+ const port = options?.port ?? 29100;
6
+ const protocol = options?.protocol ?? "http";
7
+ this.baseUrl = `${protocol}://${host}:${port}`;
8
+ }
9
+ /** Check if the Dazzle server is reachable. */
10
+ async isRunning() {
11
+ try {
12
+ await this.status();
13
+ return true;
14
+ } catch {
15
+ return false;
16
+ }
17
+ }
18
+ /** Get server status and version. */
19
+ async status() {
20
+ const res = await fetch(`${this.baseUrl}/status`);
21
+ if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);
22
+ return res.json();
23
+ }
24
+ /** List available printers on the host machine. */
25
+ async printers() {
26
+ const res = await fetch(`${this.baseUrl}/printers`);
27
+ if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);
28
+ return res.json();
29
+ }
30
+ /**
31
+ * Send ZPL to be printed.
32
+ *
33
+ * Uses the server's configured default printer unless
34
+ * `options.printer` is specified.
35
+ */
36
+ async print(zpl, options) {
37
+ const url = new URL(`${this.baseUrl}/print`);
38
+ if (options?.printer) {
39
+ url.searchParams.set("printer", options.printer);
40
+ }
41
+ const res = await fetch(url, { method: "POST", body: zpl });
42
+ if (!res.ok) {
43
+ const body = await res.text().catch(() => "");
44
+ throw new DazzleError(body || `Print failed: ${res.status}`, res.status);
45
+ }
46
+ return res.json();
47
+ }
48
+ };
49
+ var DazzleError = class extends Error {
50
+ constructor(message, statusCode) {
51
+ super(message);
52
+ this.statusCode = statusCode;
53
+ this.name = "DazzleError";
54
+ }
55
+ };
56
+ export {
57
+ Dazzle,
58
+ DazzleError
59
+ };
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DazzleOptions {\n /** Hostname of the Dazzle server. @default \"localhost\" */\n host?: string;\n /** Port of the Dazzle server. @default 29100 */\n port?: number;\n /** Protocol to use. @default \"http\" */\n protocol?: 'http' | 'https';\n}\n\nexport interface Printer {\n name: string;\n is_default: boolean;\n}\n\nexport interface PrintResult {\n job_id: string;\n}\n\nexport interface ServerStatus {\n status: string;\n version: string;\n}\n\nexport interface PrintOptions {\n /** Override the default printer for this job. */\n printer?: string;\n}\n\nexport class Dazzle {\n private baseUrl: string;\n\n constructor(options?: DazzleOptions) {\n const host = options?.host ?? 'localhost';\n const port = options?.port ?? 29100;\n const protocol = options?.protocol ?? 'http';\n this.baseUrl = `${protocol}://${host}:${port}`;\n }\n\n /** Check if the Dazzle server is reachable. */\n async isRunning(): Promise<boolean> {\n try {\n await this.status();\n return true;\n } catch {\n return false;\n }\n }\n\n /** Get server status and version. */\n async status(): Promise<ServerStatus> {\n const res = await fetch(`${this.baseUrl}/status`);\n if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);\n return res.json();\n }\n\n /** List available printers on the host machine. */\n async printers(): Promise<Printer[]> {\n const res = await fetch(`${this.baseUrl}/printers`);\n if (!res.ok) throw new DazzleError(`Server error: ${res.status}`, res.status);\n return res.json();\n }\n\n /**\n * Send ZPL to be printed.\n *\n * Uses the server's configured default printer unless\n * `options.printer` is specified.\n */\n async print(zpl: string, options?: PrintOptions): Promise<PrintResult> {\n const url = new URL(`${this.baseUrl}/print`);\n if (options?.printer) {\n url.searchParams.set('printer', options.printer);\n }\n\n const res = await fetch(url, { method: 'POST', body: zpl });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n throw new DazzleError(body || `Print failed: ${res.status}`, res.status);\n }\n\n return res.json();\n }\n}\n\nexport class DazzleError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n this.name = 'DazzleError';\n }\n}\n"],"mappings":";AA4BO,IAAM,SAAN,MAAa;AAAA,EAGlB,YAAY,SAAyB;AACnC,UAAM,OAAO,SAAS,QAAQ;AAC9B,UAAM,OAAO,SAAS,QAAQ;AAC9B,UA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OAAO;AAAA,EACd;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "dazzle-zpl",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for the Dazzle ZPL print server",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/StirlingMarketingGroup/dazzle",
9
+ "directory": "packages/client"
10
+ },
11
+ "keywords": [
12
+ "zpl",
13
+ "thermal-printer",
14
+ "label-printer",
15
+ "print-server",
16
+ "zebra",
17
+ "dazzle"
18
+ ],
19
+ "type": "module",
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.cts",
31
+ "default": "./dist/index.cjs"
32
+ }
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "devDependencies": {
43
+ "tsup": "^8.0.0",
44
+ "typescript": "^5.6.0"
45
+ }
46
+ }