From 02ea4bf1c99566a7a5ecf51eb49ab6df19ee94d6 Mon Sep 17 00:00:00 2001
From: william-davis-dev <84206899+william-davis-dev@users.noreply.github.com>
Date: Mon, 5 Aug 2024 20:02:55 -0400
Subject: [PATCH 1/4] add ZPL converter function
---
src/core/config/Categories.json | 3 +-
src/core/operations/ZPLConvert.mjs | 103 +++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 1 deletion(-)
create mode 100644 src/core/operations/ZPLConvert.mjs
diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json
index bebdd6a5e2..643fa1d548 100644
--- a/src/core/config/Categories.json
+++ b/src/core/config/Categories.json
@@ -537,7 +537,8 @@
"HTML To Text",
"Generate Lorem Ipsum",
"Numberwang",
- "XKCD Random Number"
+ "XKCD Random Number",
+ "ZPL Converter"
]
},
{
diff --git a/src/core/operations/ZPLConvert.mjs b/src/core/operations/ZPLConvert.mjs
new file mode 100644
index 0000000000..e79585ca78
--- /dev/null
+++ b/src/core/operations/ZPLConvert.mjs
@@ -0,0 +1,103 @@
+/**
+ * @author william-davis-dev
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+import Operation from "../Operation.mjs";
+import OperationError from "../errors/OperationError.mjs";
+
+/**
+ * Convert Label ZPL Into Usable Formats
+ */
+class ZPLConvert extends Operation {
+
+ /**
+ * ZPLConvert constructor
+ */
+ constructor() {
+ super();
+
+ this.name = "ZPL Converter";
+ this.module = "Default";
+ this.description = [
+ "Takes ZPL (Zebra Printer Language)-encoded text data and converts renders it to readable images.",
+ "
",
+ "Uses the Labelary API for full support of all ZPL instructions.",
+ "
",
+ "Use the 'Render Image' operation to see the final label output."
+ ].join("\n");
+ this.infoURL = "https://en.wikipedia.org/wiki/Zebra_Programming_Language";
+ this.inputType = "string";
+ this.outputType = "ArrayBuffer";
+ this.manualBake = true;
+ this.args = [
+ {
+ name: "Width",
+ type: "number",
+ value: 4
+ },
+ {
+ name: "Height",
+ type: "number",
+ value: 6
+ },
+ {
+ name: "Label Index",
+ type: "number",
+ value: 0
+ },
+ {
+ name: "Label Resolution",
+ type: "option",
+ value: [
+ "6 dpmm (152 dpi)",
+ "8 dpmm (203 dpi)",
+ "12 dpmm (300 dpi)",
+ "24 dpmm (600 dpi)"
+ ],
+ defaultIndex: 1
+ },
+ {
+ name: "Labelary Endpoint",
+ type: "text",
+ value: "https://api.labelary.com"
+ }
+ ];
+ }
+
+ /**
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {ArrayBuffer}
+ */
+ run(input, args) {
+ const [widthArg, heightArg, index, labelResolutionArg, labelaryApi] = args;
+ // The first segment of the resolution arg is the numeric indicator of the resolution
+ const labelResolution = labelResolutionArg.toString().split(" ")[0];
+
+ const labelaryUrl = `${labelaryApi}/v1/printers/${labelResolution}dpmm/labels/${widthArg}x${heightArg}/${index}`
+
+ return fetch(labelaryUrl, {
+ method: 'POST',
+ headers: {"accept": "image/png", "Content-Type": "application/x-www-form-urlencoded"},
+ body: input,
+ }).then(response => {
+ if (!response.ok) {
+ return response.text()
+ .then(text => {
+ throw new OperationError(text);
+ });
+ }
+ return response.blob();
+ }).then(blob => {
+ return blob.arrayBuffer()
+ }).then(data => {
+ return data;
+ }).catch(e => {
+ throw new OperationError(`Error making request to ${labelaryUrl} with message: ${e.toString()}`);
+ });
+
+ }
+}
+
+export default ZPLConvert;
From adf73aa251a62779fbed67d28fe37e6a836a1697 Mon Sep 17 00:00:00 2001
From: william-davis-dev <84206899+william-davis-dev@users.noreply.github.com>
Date: Tue, 6 Aug 2024 21:55:29 -0400
Subject: [PATCH 2/4] resolve linting issues in the zpl converter operation
---
src/core/operations/ZPLConvert.mjs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/core/operations/ZPLConvert.mjs b/src/core/operations/ZPLConvert.mjs
index e79585ca78..4e6e4f330e 100644
--- a/src/core/operations/ZPLConvert.mjs
+++ b/src/core/operations/ZPLConvert.mjs
@@ -75,10 +75,10 @@ class ZPLConvert extends Operation {
// The first segment of the resolution arg is the numeric indicator of the resolution
const labelResolution = labelResolutionArg.toString().split(" ")[0];
- const labelaryUrl = `${labelaryApi}/v1/printers/${labelResolution}dpmm/labels/${widthArg}x${heightArg}/${index}`
+ const labelaryUrl = `${labelaryApi}/v1/printers/${labelResolution}dpmm/labels/${widthArg}x${heightArg}/${index}`;
return fetch(labelaryUrl, {
- method: 'POST',
+ method: "POST",
headers: {"accept": "image/png", "Content-Type": "application/x-www-form-urlencoded"},
body: input,
}).then(response => {
@@ -90,7 +90,7 @@ class ZPLConvert extends Operation {
}
return response.blob();
}).then(blob => {
- return blob.arrayBuffer()
+ return blob.arrayBuffer();
}).then(data => {
return data;
}).catch(e => {
From 4a9dccaad9badad072255695bae2b4412c76c9ad Mon Sep 17 00:00:00 2001
From: william-davis-dev <84206899+william-davis-dev@users.noreply.github.com>
Date: Tue, 6 Aug 2024 22:13:42 -0400
Subject: [PATCH 3/4] upgrade chrome driver dependency
the CI/CD pipeline appears to be using chrome 127
---
package-lock.json | 8 ++++----
package.json | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index a006a85367..4a2fbd7c4a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -115,7 +115,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
- "chromedriver": "^125.0.3",
+ "chromedriver": "^127.0.1",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^12.0.2",
@@ -5093,9 +5093,9 @@
}
},
"node_modules/chromedriver": {
- "version": "125.0.3",
- "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-125.0.3.tgz",
- "integrity": "sha512-Qzuk5Wian2o3EVGjtbz6V/jv+pT/AV9246HbG6kUljZXXjsKZLZxqJC+kHR3qEh/wdv4EJD0YwAOWV72v9hogw==",
+ "version": "127.0.1",
+ "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-127.0.1.tgz",
+ "integrity": "sha512-j57OWXsxdhwK+faTWA2pi+8hf052qVjZjP0wXnjqY/QglHtlOXWhRj4s7/+ybJRNgs1zQ5csfOyV6sQQdH+Fnw==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
diff --git a/package.json b/package.json
index 710a42e0ba..eaeb5aba92 100644
--- a/package.json
+++ b/package.json
@@ -55,7 +55,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
- "chromedriver": "^125.0.3",
+ "chromedriver": "^127.0.1",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^12.0.2",
From 4d905a4bb7f7d295968bf2901aa0b9987c6a6d33 Mon Sep 17 00:00:00 2001
From: william-davis-dev <84206899+william-davis-dev@users.noreply.github.com>
Date: Thu, 8 Aug 2024 19:25:14 -0400
Subject: [PATCH 4/4] update description for clarity
---
src/core/operations/ZPLConvert.mjs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/core/operations/ZPLConvert.mjs b/src/core/operations/ZPLConvert.mjs
index 4e6e4f330e..a7e34cfc05 100644
--- a/src/core/operations/ZPLConvert.mjs
+++ b/src/core/operations/ZPLConvert.mjs
@@ -20,7 +20,7 @@ class ZPLConvert extends Operation {
this.name = "ZPL Converter";
this.module = "Default";
this.description = [
- "Takes ZPL (Zebra Printer Language)-encoded text data and converts renders it to readable images.",
+ "Takes a ZPL (Zebra Printer Language) string and renders it into a png.",
"
",
"Uses the Labelary API for full support of all ZPL instructions.",
"
",