@labelzoom/mcp 0.2.0 → 0.2.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 LabelZoom
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LabelZoom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,157 +1,159 @@
1
- # LabelZoom MCP server
2
-
3
- An [MCP](https://modelcontextprotocol.io) server for [LabelZoom](https://www.labelzoom.com). It lets
4
- Claude and other MCP clients convert barcode labels between formats, render a label to an image and
5
- look at it, and print labels with LabelZoom Cloud Print. It's published to npm as `@labelzoom/mcp`.
6
-
7
- Rendering is the part that changes how label work goes: the assistant can check that ZPL produces the
8
- label you meant, instead of reasoning about the code blind.
9
-
10
- ## Install
11
-
12
- You need Node.js 20 or later.
13
-
14
- Add the server to Claude Code:
15
-
16
- ```sh
17
- claude mcp add labelzoom -- npx -y @labelzoom/mcp
18
- ```
19
-
20
- To convert without a watermark, or to print, give it a LabelZoom API key:
21
-
22
- ```sh
23
- claude mcp add labelzoom --env LABELZOOM_API_KEY=YOUR_API_KEY -- npx -y @labelzoom/mcp
24
- ```
25
-
26
- For Claude Desktop and other clients, add this to the client's MCP configuration:
27
-
28
- ```json
29
- {
30
- "mcpServers": {
31
- "labelzoom": {
32
- "command": "npx",
33
- "args": ["-y", "@labelzoom/mcp"],
34
- "env": { "LABELZOOM_API_KEY": "YOUR_API_KEY" }
35
- }
36
- }
37
- }
38
- ```
39
-
40
- ### Configuration
41
-
42
- | Variable | Default | Description |
43
- | --- | --- | --- |
44
- | `LABELZOOM_API_KEY` | None | An API key from the **API Access** section of your [LabelZoom dashboard](https://www.labelzoom.com/dashboard). Printing needs a key with the `print` scope. |
45
- | `LABELZOOM_API_BASE_URL` | `https://api.labelzoom.com` | The API to call. Change it only if you were given a dedicated endpoint. |
46
-
47
- Without a key, conversions run on the free tier: output is watermarked and holds only the first label,
48
- and some conversions, such as JSON output and image to image, need a paid plan. See
49
- [rate limits and plans](https://docs.labelzoom.com/reference/rate-limits-and-plans/).
50
-
51
- `LABELZOOM_TOKEN`, the variable name before version 0.2.0, still works when `LABELZOOM_API_KEY` isn't
52
- set.
53
-
54
- ## Tools
55
-
56
- | Tool | What it does |
57
- | --- | --- |
58
- | `render_label_preview` | Renders a label to a PNG and returns it as an image, so the assistant can see it |
59
- | `convert_label` | Converts a label between any source and target format |
60
- | `list_conversion_formats` | Lists the formats, which sources take `sourceDpi`, and whether a key is set |
61
- | `print_label` | Sends a document to a Cloud Print printer, converting it to the printer's language on the way |
62
- | `print_template` | Fills a published Print Template with data and prints it, one label per record |
63
- | `get_print_job` | Looks up a print job to see whether it printed |
64
- | `get_print_quota` | Shows your plan's printer and daily job limits, and when the daily count resets |
65
-
66
- ### Documents
67
-
68
- The tools that take a document read it from `content` or from a file at `input_path`:
69
-
70
- - **Text formats:** pass label code in `content` as is. This covers the printer languages, LabelZoom XML
71
- and JSON, and DYMO files.
72
- - **Binary formats:** pass a PDF, an image, or a NiceLabel or BarTender file in `content` as base64, or
73
- point `input_path` at the file.
74
- - **The `url` source:** put the URL in `content`, and LabelZoom fetches the document. You can convert a
75
- URL, but you can't print one.
76
-
77
- `convert_label` returns text output inline. It writes binary output to `output_path` when you give one,
78
- and returns it as base64 otherwise. EPL, IPL, TSPL, DPL and SBPL output can contain raw bytes, such as an
79
- inline bitmap. That output comes back inline only when it has none, and as base64 when it does.
80
-
81
- ### Formats
82
-
83
- | Kind | Sources | Targets |
84
- | --- | --- | --- |
85
- | Printer languages | `zpl` `epl` `ipl` `tspl` `dpl` `sbpl` `cpcl` `esclabel` `fingerprint` `ezpl` `tpcl` | `zpl` `epl` `ipl` `tspl` `dpl` `sbpl` `cpcl` |
86
- | Label design files | `nlbl` `lbl` (NiceLabel), `btw` (BarTender), `dymo` (DYMO) | None |
87
- | Documents and images | `pdf` `png` `bmp` `gif` `jpeg` `jpg` | `pdf` `png` `bmp` `gif` `jpeg` |
88
- | LabelZoom | `xml` `json` | `xml` `json` |
89
- | Other | `url` | None |
90
-
91
- ### Options
92
-
93
- Options use the API's own names.
94
-
95
- | Option | Applies to | What it does |
96
- | --- | --- | --- |
97
- | `sourceDpi` | Printer-language and image sources | The resolution the document was made for. The output follows it unless `targetDpi` is set |
98
- | `targetDpi` | Every target except PDF | The resolution of the output. Match the printer |
99
- | `labelWidth`, `labelHeight` | Every source | The label size in inches. Leave them unset to use the size the label code declares |
100
- | `labelIndex` | Multi-label documents | Converts only this label, counting from 0 |
101
- | `data` | Labels with variable fields | Values for the fields. An array produces one label per entry |
102
- | `rotation` | Every conversion and print | Rotates the output by a multiple of 90 degrees |
103
- | `pdfPageNumber`, `pdfConversionMode` | PDF sources | The page, counting from 0, and `IMAGE` or `NATIVE` conversion |
104
- | `split` | PDF and image sources | Cuts each page into a grid of labels. Lengths are in inches |
105
- | `scaling`, `darkness`, `colorMode` | PDF and image sources | How the page is scaled and reduced to black and white |
106
- | `zplCommandsToIgnore` | ZPL and ESC/Label sources | Commands to skip, such as `["^PQ"]` |
107
- | `zplImageCompression`, `zplCollapseCopies`, `layout` | ZPL targets | Image encoding, collapsing identical labels into a `^PQ` count, and labels side by side on a multi-across roll |
108
- | `watermark`, `dialect` | Every target | Forces a watermark, or picks an output dialect on a paid plan |
109
-
110
- A print takes the document options and `rotation`. The printer decides the output format.
111
-
112
- ### Printing
113
-
114
- Printing needs a printer connected through [LabelZoom Cloud Print](https://www.labelzoom.com/cloud-print)
115
- and an API key with the `print` scope. Copy the printer's ID from the dashboard.
116
-
117
- - **Accepted is not printed.** A job starts out `dispatched` or `queued`. Only `completed` means the label
118
- came out of the printer, so use `get_print_job` to follow it.
119
- - **Retries are safe.** Every print carries an idempotency key. Pass `idempotency_key`, such as an order
120
- number, and repeating the print returns the original job instead of printing again. Without one,
121
- the server generates a key for each call and reuses it if that call is retried.
122
- - **Copies multiply.** `copies` sends the job 1 to 9999 times. A quantity in the label itself, such as
123
- `^PQ3`, multiplies with it.
124
- - **The daily job limit isn't retried.** It resets at midnight UTC, and `get_print_quota` shows when.
125
-
126
- ## Try it
127
-
128
- > Render this ZPL and tell me if the barcode fits on a 4x6 label.
129
- >
130
- > ```
131
- > ^XA
132
- > ^FO50,50^A0N,60,60^FDHello LabelZoom^FS
133
- > ^FO50,150^BY3^BCN,100,Y,N,N^FD12345678^FS
134
- > ^XZ
135
- > ```
136
-
137
- ## Contributing
138
-
139
- The server is built on the [LabelZoom Node.js SDK](https://www.npmjs.com/package/@labelzoom/sdk), which
140
- handles the API's wire rules and runs the shared LabelZoom conformance suite. The tests here check that
141
- each tool drives the SDK correctly. They run offline.
142
-
143
- ```sh
144
- npm install
145
- npm test # builds, then runs the tool tests
146
- npm run typecheck
147
- ```
148
-
149
- `src/tools.ts` registers the tools, `src/client.ts` builds the SDK client from the environment,
150
- `src/formats.ts` decides how documents travel in a tool call, and `src/index.ts` is the stdio entry point.
151
-
152
- To release, publish a GitHub Release tagged `vX.Y.Z` that matches `package.json`. The publish workflow
153
- tests the build and publishes it to npm with provenance.
154
-
155
- ## License
156
-
157
- MIT
1
+ # LabelZoom MCP server
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server for [LabelZoom](https://www.labelzoom.com). It lets
4
+ Claude and other MCP clients convert barcode labels between formats, render a label to an image and
5
+ look at it, and print labels with LabelZoom Cloud Print. It's published to npm as `@labelzoom/mcp`.
6
+
7
+ Rendering is the part that changes how label work goes: the assistant can check that ZPL produces the
8
+ label you meant, instead of reasoning about the code blind.
9
+
10
+ ## Install
11
+
12
+ You need Node.js 20 or later.
13
+
14
+ Add the server to Claude Code:
15
+
16
+ ```sh
17
+ claude mcp add labelzoom -- npx -y @labelzoom/mcp
18
+ ```
19
+
20
+ To convert without a watermark, or to print, give it a LabelZoom API key:
21
+
22
+ ```sh
23
+ claude mcp add labelzoom --env LABELZOOM_API_KEY=YOUR_API_KEY -- npx -y @labelzoom/mcp
24
+ ```
25
+
26
+ For Claude Desktop and other clients, add this to the client's MCP configuration:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "labelzoom": {
32
+ "command": "npx",
33
+ "args": ["-y", "@labelzoom/mcp"],
34
+ "env": { "LABELZOOM_API_KEY": "YOUR_API_KEY" }
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ### Configuration
41
+
42
+ | Variable | Default | Description |
43
+ | --- | --- | --- |
44
+ | `LABELZOOM_API_KEY` | None | An API key from the **API Access** section of your [LabelZoom dashboard](https://www.labelzoom.com/dashboard). Printing needs a key with the `print` scope. |
45
+ | `LABELZOOM_API_BASE_URL` | `https://api.labelzoom.com` | The API to call. Change it only if you were given a dedicated endpoint. |
46
+
47
+ Without a key, conversions run on the free tier: output is watermarked, only the first label of each
48
+ request converts (set `labelIndex` to convert any other one), and some conversions, such as JSON
49
+ output and image to image, need a paid plan. See
50
+ [rate limits and plans](https://docs.labelzoom.com/reference/rate-limits-and-plans/).
51
+
52
+ `LABELZOOM_TOKEN`, the variable name before version 0.2.0, still works when `LABELZOOM_API_KEY` isn't
53
+ set.
54
+
55
+ ## Tools
56
+
57
+ | Tool | What it does |
58
+ | --- | --- |
59
+ | `render_label_preview` | Renders a label to a PNG and returns it as an image, so the assistant can see it |
60
+ | `convert_label` | Converts a label between any source and target format |
61
+ | `list_conversion_formats` | Lists the formats, which sources take `sourceDpi`, and whether a key is set |
62
+ | `print_label` | Sends a document to a Cloud Print printer, converting it to the printer's language on the way |
63
+ | `print_template` | Fills a published Print Template with data and prints it, one label per record |
64
+ | `get_print_job` | Looks up a print job to see whether it printed |
65
+ | `get_print_quota` | Shows your plan's printer and daily job limits, and when the daily count resets |
66
+
67
+ ### Documents
68
+
69
+ The tools that take a document read it from `content` or from a file at `input_path`:
70
+
71
+ - **Text formats:** pass label code in `content` as is. This covers the printer languages, LabelZoom XML
72
+ and JSON, and DYMO files.
73
+ - **Binary formats:** pass a PDF, an image, or a NiceLabel or BarTender file in `content` as base64, or
74
+ point `input_path` at the file.
75
+ - **The `url` source:** put the URL in `content`, and LabelZoom fetches the document. You can convert a
76
+ URL, but you can't print one.
77
+
78
+ `convert_label` returns text output inline. It writes binary output to `output_path` when you give one,
79
+ and returns it as base64 otherwise. EPL, IPL, TSPL, DPL and SBPL output can contain raw bytes, such as an
80
+ inline bitmap. That output comes back inline only when it has none, and as base64 when it does.
81
+
82
+ ### Formats
83
+
84
+ | Kind | Sources | Targets |
85
+ | --- | --- | --- |
86
+ | Printer languages | `zpl` `epl` `ipl` `tspl` `dpl` `sbpl` `cpcl` `esclabel` `fingerprint` `ezpl` `tpcl` | `zpl` `epl` `ipl` `tspl` `dpl` `sbpl` `cpcl` |
87
+ | Label design files | `nlbl` `lbl` (NiceLabel), `btw` (BarTender), `dymo` (DYMO) | None |
88
+ | Documents and images | `pdf` `png` `bmp` `gif` `jpeg` `jpg` | `pdf` `png` `bmp` `gif` `jpeg` |
89
+ | LabelZoom | `xml` `json` | `xml` `json` |
90
+ | Other | `url` | None |
91
+
92
+ ### Options
93
+
94
+ Options use the API's own names.
95
+
96
+ | Option | Applies to | What it does |
97
+ | --- | --- | --- |
98
+ | `sourceDpi` | Printer-language and image sources | The resolution the document was made for. The output follows it unless `targetDpi` is set |
99
+ | `targetDpi` | Every target except PDF | The resolution of the output. Match the printer |
100
+ | `labelWidth`, `labelHeight` | Every source | The label size in inches. Leave them unset to use the size the label code declares |
101
+ | `labelIndex` | Multi-label documents | Converts only this label, counting from 0 |
102
+ | `data` | Labels with variable fields | Values for the fields. An array produces one label per entry |
103
+ | `rotation` | Every conversion and print | Rotates the output by a multiple of 90 degrees |
104
+ | `pdfPageNumber`, `pdfConversionMode` | PDF sources | The page, counting from 0, and `IMAGE` or `NATIVE` conversion |
105
+ | `split` | PDF and image sources | Cuts each page into a grid of labels. Lengths are in inches |
106
+ | `scaling`, `darkness`, `colorMode` | PDF and image sources | How the page is scaled and reduced to black and white |
107
+ | `zplCommandsToIgnore` | ZPL and ESC/Label sources | Commands to skip, such as `["^PQ"]` |
108
+ | `zplImageCompression`, `zplCollapseCopies` | ZPL targets | Image encoding, and collapsing identical labels into a `^PQ` count |
109
+ | `layout` | Printer-language targets from a PDF or image | Labels side by side on a multi-across roll |
110
+ | `watermark`, `dialect` | Every target | Forces a watermark, or picks an output dialect on a paid plan |
111
+
112
+ A print takes the document options and `rotation`. The printer decides the output format.
113
+
114
+ ### Printing
115
+
116
+ Printing needs a printer connected through [LabelZoom Cloud Print](https://www.labelzoom.com/cloud-print)
117
+ and an API key with the `print` scope. Copy the printer's ID from the dashboard.
118
+
119
+ - **Accepted is not printed.** A job starts out `dispatched` or `queued`. Only `completed` means the label
120
+ came out of the printer, so use `get_print_job` to follow it.
121
+ - **Retries are safe.** Every print carries an idempotency key. Pass `idempotency_key`, such as an order
122
+ number, and repeating the print returns the original job instead of printing again. Without one,
123
+ the server generates a key for each call and reuses it if that call is retried.
124
+ - **Copies multiply.** `copies` sends the job 1 to 9999 times. A quantity in the label itself, such as
125
+ `^PQ3`, multiplies with it.
126
+ - **The daily job limit isn't retried.** It resets at midnight UTC, and `get_print_quota` shows when.
127
+
128
+ ## Try it
129
+
130
+ > Render this ZPL and tell me if the barcode fits on a 4x6 label.
131
+ >
132
+ > ```
133
+ > ^XA
134
+ > ^FO50,50^A0N,60,60^FDHello LabelZoom^FS
135
+ > ^FO50,150^BY3^BCN,100,Y,N,N^FD12345678^FS
136
+ > ^XZ
137
+ > ```
138
+
139
+ ## Contributing
140
+
141
+ The server is built on the [LabelZoom Node.js SDK](https://www.npmjs.com/package/@labelzoom/sdk), which
142
+ handles the API's wire rules and runs the shared LabelZoom conformance suite. The tests here check that
143
+ each tool drives the SDK correctly. They run offline.
144
+
145
+ ```sh
146
+ npm install
147
+ npm test # builds, then runs the tool tests
148
+ npm run typecheck
149
+ ```
150
+
151
+ `src/tools.ts` registers the tools, `src/client.ts` builds the SDK client from the environment,
152
+ `src/formats.ts` decides how documents travel in a tool call, and `src/index.ts` is the stdio entry point.
153
+
154
+ To release, publish a GitHub Release tagged `vX.Y.Z` that matches `package.json`. The publish workflow
155
+ tests the build and publishes it to npm with provenance.
156
+
157
+ ## License
158
+
159
+ MIT
package/package.json CHANGED
@@ -1,59 +1,60 @@
1
- {
2
- "name": "@labelzoom/mcp",
3
- "version": "0.2.0",
4
- "description": "MCP server for LabelZoom: convert, preview and print barcode labels (ZPL, EPL, CPCL and other printer languages, BarTender, NiceLabel and DYMO files, PDF and images) from Claude and other MCP clients",
5
- "keywords": [
6
- "mcp",
7
- "model-context-protocol",
8
- "labelzoom",
9
- "zpl",
10
- "epl",
11
- "cpcl",
12
- "barcode",
13
- "label",
14
- "thermal-printer",
15
- "bartender",
16
- "nicelabel"
17
- ],
18
- "license": "MIT",
19
- "author": {
20
- "name": "RJF Technology Solutions LLC",
21
- "email": "support@labelzoom.com"
22
- },
23
- "homepage": "https://github.com/labelzoom/labelzoom-mcp#readme",
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/labelzoom/labelzoom-mcp.git"
27
- },
28
- "bugs": {
29
- "url": "https://github.com/labelzoom/labelzoom-mcp/issues"
30
- },
31
- "type": "module",
32
- "bin": {
33
- "labelzoom-mcp": "dist/index.js"
34
- },
35
- "files": [
36
- "dist",
37
- "!dist/**/*.test.*",
38
- "README.md"
39
- ],
40
- "engines": {
41
- "node": ">=20"
42
- },
43
- "scripts": {
44
- "build": "tsc",
45
- "dev": "tsc --watch",
46
- "prepack": "npm run build",
47
- "test": "tsc && node --test dist/*.test.js",
48
- "typecheck": "tsc --noEmit"
49
- },
50
- "dependencies": {
51
- "@labelzoom/sdk": "^2.0.0",
52
- "@modelcontextprotocol/sdk": "^1.32.2",
53
- "zod": "^4.6.7"
54
- },
55
- "devDependencies": {
56
- "@types/node": "^24.19.2",
57
- "typescript": "^5.9.3"
58
- }
59
- }
1
+ {
2
+ "name": "@labelzoom/mcp",
3
+ "version": "0.2.1",
4
+ "description": "MCP server for LabelZoom: convert, preview and print barcode labels (ZPL, EPL, CPCL and other printer languages, BarTender, NiceLabel and DYMO files, PDF and images) from Claude and other MCP clients",
5
+ "keywords": [
6
+ "mcp",
7
+ "model-context-protocol",
8
+ "labelzoom",
9
+ "zpl",
10
+ "epl",
11
+ "cpcl",
12
+ "barcode",
13
+ "label",
14
+ "thermal-printer",
15
+ "bartender",
16
+ "nicelabel"
17
+ ],
18
+ "license": "MIT",
19
+ "author": {
20
+ "name": "RJF Technology Solutions LLC",
21
+ "email": "support@labelzoom.com"
22
+ },
23
+ "homepage": "https://github.com/labelzoom/labelzoom-mcp#readme",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/labelzoom/labelzoom-mcp.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/labelzoom/labelzoom-mcp/issues"
30
+ },
31
+ "type": "module",
32
+ "bin": {
33
+ "labelzoom-mcp": "dist/index.js"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "!dist/**/*.test.*",
38
+ "README.md"
39
+ ],
40
+ "engines": {
41
+ "node": ">=20"
42
+ },
43
+ "scripts": {
44
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
45
+ "build": "npm run clean && tsc",
46
+ "dev": "tsc --watch",
47
+ "prepack": "npm run build",
48
+ "test": "tsc && node --test dist/*.test.js",
49
+ "typecheck": "tsc --noEmit"
50
+ },
51
+ "dependencies": {
52
+ "@labelzoom/sdk": "^2.0.0",
53
+ "@modelcontextprotocol/sdk": "^1.32.2",
54
+ "zod": "^4.6.7"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^24.19.2",
58
+ "typescript": "^5.9.3"
59
+ }
60
+ }
package/dist/api.d.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * Thin client over the LabelZoom conversion API.
3
- *
4
- * Endpoint: POST {base}/api/v2/convert/{sourceFormat}/to/{targetFormat}?params={json}
5
- * The Content-Type must agree with sourceFormat, and Accept must admit the
6
- * media type implied by targetFormat, or the server rejects the request before
7
- * any conversion happens.
8
- */
9
- export declare const SOURCE_FORMATS: readonly ["zpl", "xml", "json", "pdf", "png", "bmp", "gif", "jpeg", "jpg"];
10
- export declare const TARGET_FORMATS: readonly ["zpl", "xml", "json", "pdf", "png", "bmp", "gif", "jpeg"];
11
- export type SourceFormat = (typeof SOURCE_FORMATS)[number];
12
- export type TargetFormat = (typeof TARGET_FORMATS)[number];
13
- export declare const isTextFormat: (format: string) => boolean;
14
- export declare const mediaTypeFor: (format: string) => string;
15
- export interface ConversionParams {
16
- dpi?: number;
17
- rotation?: number;
18
- scaling?: number;
19
- darkness?: number;
20
- colorMode?: 'BW' | 'GRAYSCALE' | 'COLOR';
21
- watermark?: boolean;
22
- dialect?: string;
23
- data?: unknown;
24
- label?: {
25
- width?: number;
26
- height?: number;
27
- };
28
- pdf?: {
29
- conversionMode?: 'IMAGE' | 'NATIVE';
30
- pageNumber?: number;
31
- };
32
- zpl?: {
33
- commandsToIgnore?: string[];
34
- imageCompression?: 'Z64' | 'COMPRESSED_HEX';
35
- };
36
- }
37
- export interface ConversionResult {
38
- bytes: Uint8Array;
39
- contentType: string;
40
- }
41
- export declare class LabelZoomError extends Error {
42
- readonly status: number;
43
- readonly detail: string;
44
- constructor(status: number, detail: string);
45
- }
46
- export interface ClientOptions {
47
- baseUrl?: string;
48
- token?: string;
49
- fetchImpl?: typeof fetch;
50
- }
51
- export declare class LabelZoomClient {
52
- private readonly baseUrl;
53
- private readonly token?;
54
- private readonly fetchImpl;
55
- constructor(options?: ClientOptions);
56
- get isAuthenticated(): boolean;
57
- convert(sourceFormat: SourceFormat, targetFormat: TargetFormat, body: Uint8Array, params?: ConversionParams): Promise<ConversionResult>;
58
- }
package/dist/api.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Thin client over the LabelZoom conversion API.
3
- *
4
- * Endpoint: POST {base}/api/v2/convert/{sourceFormat}/to/{targetFormat}?params={json}
5
- * The Content-Type must agree with sourceFormat, and Accept must admit the
6
- * media type implied by targetFormat, or the server rejects the request before
7
- * any conversion happens.
8
- */
9
- export const SOURCE_FORMATS = ['zpl', 'xml', 'json', 'pdf', 'png', 'bmp', 'gif', 'jpeg', 'jpg'];
10
- export const TARGET_FORMATS = ['zpl', 'xml', 'json', 'pdf', 'png', 'bmp', 'gif', 'jpeg'];
11
- const MEDIA_TYPES = {
12
- xml: 'application/xml',
13
- json: 'application/json',
14
- zpl: 'text/plain',
15
- png: 'image/png',
16
- bmp: 'image/bmp',
17
- gif: 'image/gif',
18
- jpeg: 'image/jpeg',
19
- jpg: 'image/jpeg',
20
- pdf: 'application/pdf',
21
- };
22
- /** Formats whose payload is human-readable text rather than opaque bytes. */
23
- const TEXT_FORMATS = new Set(['zpl', 'xml', 'json']);
24
- export const isTextFormat = (format) => TEXT_FORMATS.has(format.toLowerCase());
25
- export const mediaTypeFor = (format) => MEDIA_TYPES[format.toLowerCase()] ?? 'application/octet-stream';
26
- export class LabelZoomError extends Error {
27
- status;
28
- detail;
29
- constructor(status, detail) {
30
- super(`LabelZoom API returned ${status}: ${detail}`);
31
- this.status = status;
32
- this.detail = detail;
33
- this.name = 'LabelZoomError';
34
- }
35
- }
36
- export class LabelZoomClient {
37
- baseUrl;
38
- token;
39
- fetchImpl;
40
- constructor(options = {}) {
41
- this.baseUrl = (options.baseUrl ?? 'https://api.labelzoom.net').replace(/\/+$/, '');
42
- this.token = options.token;
43
- this.fetchImpl = options.fetchImpl ?? fetch;
44
- }
45
- get isAuthenticated() {
46
- return Boolean(this.token);
47
- }
48
- async convert(sourceFormat, targetFormat, body, params = {}) {
49
- if (body.byteLength === 0) {
50
- throw new Error('Refusing to send an empty body; the API rejects zero-length requests.');
51
- }
52
- const url = new URL(`${this.baseUrl}/api/v2/convert/${sourceFormat}/to/${targetFormat}`);
53
- if (Object.keys(params).length > 0) {
54
- url.searchParams.set('params', JSON.stringify(params));
55
- }
56
- const headers = {
57
- 'Content-Type': mediaTypeFor(sourceFormat),
58
- Accept: mediaTypeFor(targetFormat),
59
- };
60
- if (this.token) {
61
- headers.Authorization = `Bearer ${this.token}`;
62
- }
63
- const response = await this.fetchImpl(url, {
64
- method: 'POST',
65
- headers,
66
- // Copy into a fresh ArrayBuffer so a pooled Buffer's offset can't leak extra bytes.
67
- body: body.slice().buffer,
68
- });
69
- if (!response.ok) {
70
- throw new LabelZoomError(response.status, (await response.text()).trim() || response.statusText);
71
- }
72
- return {
73
- bytes: new Uint8Array(await response.arrayBuffer()),
74
- contentType: response.headers.get('content-type') ?? mediaTypeFor(targetFormat),
75
- };
76
- }
77
- }
78
- //# sourceMappingURL=api.js.map
package/dist/api.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AACzG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAU,CAAC;AAKlG,MAAM,WAAW,GAA2B;IAC1C,GAAG,EAAE,iBAAiB;IACtB,IAAI,EAAE,kBAAkB;IACxB,GAAG,EAAE,YAAY;IACjB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,YAAY;IACjB,GAAG,EAAE,iBAAiB;CACvB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAErD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