node-hp-scan-to 1.0.1 → 1.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.
Files changed (68) hide show
  1. package/README.md +92 -11
  2. package/dist/Destination.d.ts +8 -7
  3. package/dist/Destination.js +115 -84
  4. package/dist/Destination.js.map +1 -1
  5. package/dist/Event.d.ts +21 -17
  6. package/dist/Event.js +46 -30
  7. package/dist/Event.js.map +1 -1
  8. package/dist/EventTable.d.ts +11 -11
  9. package/dist/EventTable.js +26 -26
  10. package/dist/EventTable.js.map +1 -1
  11. package/dist/HPApi.d.ts +42 -29
  12. package/dist/HPApi.js +528 -333
  13. package/dist/HPApi.js.map +1 -1
  14. package/dist/Job.d.ts +36 -24
  15. package/dist/Job.js +94 -62
  16. package/dist/Job.js.map +1 -1
  17. package/dist/JpegUtil.d.ts +26 -0
  18. package/dist/JpegUtil.js +238 -0
  19. package/dist/JpegUtil.js.map +1 -0
  20. package/dist/PathHelper.d.ts +5 -0
  21. package/dist/PathHelper.js +79 -0
  22. package/dist/PathHelper.js.map +1 -0
  23. package/dist/ScanContent.d.ts +12 -0
  24. package/dist/ScanContent.js +82 -0
  25. package/dist/ScanContent.js.map +1 -0
  26. package/dist/ScanJobSettings.d.ts +6 -6
  27. package/dist/ScanJobSettings.js +95 -94
  28. package/dist/ScanJobSettings.js.map +1 -1
  29. package/dist/ScanStatus.d.ts +18 -18
  30. package/dist/ScanStatus.js +35 -29
  31. package/dist/ScanStatus.js.map +1 -1
  32. package/dist/WalkupScanDestination.d.ts +24 -24
  33. package/dist/WalkupScanDestination.js +40 -40
  34. package/dist/WalkupScanDestination.js.map +1 -1
  35. package/dist/WalkupScanDestinations.d.ts +11 -11
  36. package/dist/WalkupScanDestinations.js +26 -26
  37. package/dist/WalkupScanDestinations.js.map +1 -1
  38. package/dist/WalkupScanToCompDestination.d.ts +26 -0
  39. package/dist/WalkupScanToCompDestination.js +44 -0
  40. package/dist/WalkupScanToCompDestination.js.map +1 -0
  41. package/dist/WalkupScanToCompDestinations.d.ts +11 -0
  42. package/dist/WalkupScanToCompDestinations.js +27 -0
  43. package/dist/WalkupScanToCompDestinations.js.map +1 -0
  44. package/dist/WalkupScanToCompEvent.d.ts +10 -0
  45. package/dist/WalkupScanToCompEvent.js +17 -0
  46. package/dist/WalkupScanToCompEvent.js.map +1 -0
  47. package/dist/index.d.ts +2 -2
  48. package/dist/index.js +630 -292
  49. package/dist/index.js.map +1 -1
  50. package/nodemon.json +5 -5
  51. package/package.json +72 -57
  52. package/src/Destination.ts +63 -45
  53. package/src/Event.ts +45 -31
  54. package/src/EventTable.ts +25 -25
  55. package/src/HPApi.ts +365 -222
  56. package/src/Job.ts +100 -62
  57. package/src/JpegUtil.ts +319 -0
  58. package/src/PathHelper.ts +44 -0
  59. package/src/ScanContent.ts +34 -0
  60. package/src/ScanJobSettings.ts +55 -55
  61. package/src/ScanStatus.ts +36 -31
  62. package/src/WalkupScanDestination.ts +46 -44
  63. package/src/WalkupScanDestinations.ts +29 -27
  64. package/src/WalkupScanToCompDestination.ts +55 -0
  65. package/src/WalkupScanToCompDestinations.ts +34 -0
  66. package/src/WalkupScanToCompEvent.ts +18 -0
  67. package/src/index.ts +555 -205
  68. package/tsconfig.json +34 -0
package/dist/HPApi.js CHANGED
@@ -1,334 +1,529 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __importDefault = (this && this.__importDefault) || function (mod) {
38
- return (mod && mod.__esModule) ? mod : { "default": mod };
39
- };
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- var WalkupScanDestination_1 = __importDefault(require("./WalkupScanDestination"));
42
- var util_1 = __importDefault(require("util"));
43
- var fs_1 = __importDefault(require("fs"));
44
- var axios_1 = __importDefault(require("axios"));
45
- var url_1 = __importDefault(require("url"));
46
- var xml2js_1 = __importDefault(require("xml2js"));
47
- var EventTable_1 = __importDefault(require("./EventTable"));
48
- var Job_1 = __importDefault(require("./Job"));
49
- var ScanStatus_1 = __importDefault(require("./ScanStatus"));
50
- var WalkupScanDestinations_1 = __importDefault(require("./WalkupScanDestinations"));
51
- var parser = new xml2js_1.default.Parser();
52
- var parseString = util_1.default.promisify(parser.parseString);
53
- var printerIP = "192.168.1.11";
54
- var HPApi = /** @class */ (function () {
55
- function HPApi() {
56
- }
57
- HPApi.setPrinterIP = function (ip) {
58
- printerIP = ip;
59
- };
60
- HPApi.getWalkupScanDestinations = function () {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var response, parsed;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, axios_1.default({
66
- baseURL: "http://" + printerIP,
67
- url: "/WalkupScan/WalkupScanDestinations",
68
- method: "GET",
69
- responseType: "text"
70
- })];
71
- case 1:
72
- response = _a.sent();
73
- if (!(response.status !== 200)) return [3 /*break*/, 2];
74
- throw new Error(response.statusText);
75
- case 2: return [4 /*yield*/, parseString(response.data)];
76
- case 3:
77
- parsed = _a.sent();
78
- return [2 /*return*/, new WalkupScanDestinations_1.default(parsed)];
79
- }
80
- });
81
- });
82
- };
83
- HPApi.removeDestination = function (walkupScanDestination) {
84
- return __awaiter(this, void 0, void 0, function () {
85
- var urlInfo, response;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- urlInfo = url_1.default.parse(walkupScanDestination.resourceURI);
90
- return [4 /*yield*/, axios_1.default({
91
- baseURL: "http://" + printerIP,
92
- url: urlInfo.pathname,
93
- method: "DELETE",
94
- responseType: "text"
95
- })];
96
- case 1:
97
- response = _a.sent();
98
- if (response.status === 204) {
99
- return [2 /*return*/, true];
100
- }
101
- else {
102
- throw response;
103
- }
104
- return [2 /*return*/];
105
- }
106
- });
107
- });
108
- };
109
- HPApi.registerDestination = function (destination) {
110
- return __awaiter(this, void 0, void 0, function () {
111
- var xml, response;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0: return [4 /*yield*/, destination.toXML()];
115
- case 1:
116
- xml = _a.sent();
117
- return [4 /*yield*/, axios_1.default({
118
- baseURL: "http://" + printerIP,
119
- url: "/WalkupScan/WalkupScanDestinations",
120
- method: "POST",
121
- headers: { "Content-Type": "text/xml" },
122
- data: xml,
123
- responseType: "text"
124
- })];
125
- case 2:
126
- response = _a.sent();
127
- if (response.status === 201) {
128
- return [2 /*return*/, response.headers.location];
129
- }
130
- else {
131
- throw response;
132
- }
133
- return [2 /*return*/];
134
- }
135
- });
136
- });
137
- };
138
- HPApi.getEvents = function (etag, timeout) {
139
- if (etag === void 0) { etag = ""; }
140
- if (timeout === void 0) { timeout = 0; }
141
- return __awaiter(this, void 0, void 0, function () {
142
- var url, headers, response, error_1, parsed;
143
- return __generator(this, function (_a) {
144
- switch (_a.label) {
145
- case 0:
146
- url = this.appendTimeout(timeout, "/EventMgmt/EventTable");
147
- headers = this.placeETagHeader(etag, {});
148
- _a.label = 1;
149
- case 1:
150
- _a.trys.push([1, 3, , 4]);
151
- return [4 /*yield*/, axios_1.default({
152
- baseURL: "http://" + printerIP,
153
- url: url,
154
- method: "GET",
155
- responseType: "text",
156
- headers: headers
157
- })];
158
- case 2:
159
- response = _a.sent();
160
- return [3 /*break*/, 4];
161
- case 3:
162
- error_1 = _a.sent();
163
- response = error_1.response;
164
- if (response.status === 304) {
165
- return [2 /*return*/, {
166
- etag: etag,
167
- eventTable: new EventTable_1.default({})
168
- }];
169
- }
170
- throw error_1;
171
- case 4: return [4 /*yield*/, parseString(response.data)];
172
- case 5:
173
- parsed = _a.sent();
174
- return [2 /*return*/, {
175
- etag: response.headers["etag"],
176
- eventTable: new EventTable_1.default(parsed)
177
- }];
178
- }
179
- });
180
- });
181
- };
182
- HPApi.placeETagHeader = function (etag, headers) {
183
- if (etag !== "") {
184
- headers = {
185
- "If-None-Match": etag
186
- };
187
- }
188
- return headers;
189
- };
190
- HPApi.appendTimeout = function (timeout, url) {
191
- if (timeout === void 0) { timeout = null; }
192
- if (timeout == null) {
193
- timeout = 1200;
194
- }
195
- if (timeout > 0) {
196
- url += "?timeout=" + timeout;
197
- }
198
- return url;
199
- };
200
- HPApi.getDestination = function (destinationURL) {
201
- return __awaiter(this, void 0, void 0, function () {
202
- var response, parsed;
203
- return __generator(this, function (_a) {
204
- switch (_a.label) {
205
- case 0: return [4 /*yield*/, axios_1.default({
206
- url: destinationURL,
207
- method: "GET",
208
- responseType: "text"
209
- })];
210
- case 1:
211
- response = _a.sent();
212
- if (!(response.status !== 200)) return [3 /*break*/, 2];
213
- throw response;
214
- case 2: return [4 /*yield*/, parseString(response.data)];
215
- case 3:
216
- parsed = _a.sent();
217
- return [2 /*return*/, new WalkupScanDestination_1.default(parsed)];
218
- }
219
- });
220
- });
221
- };
222
- HPApi.getScanStatus = function () {
223
- return __awaiter(this, void 0, void 0, function () {
224
- var response, parsed;
225
- return __generator(this, function (_a) {
226
- switch (_a.label) {
227
- case 0: return [4 /*yield*/, axios_1.default({
228
- baseURL: "http://" + printerIP,
229
- url: "/Scan/Status",
230
- method: "GET",
231
- responseType: "text"
232
- })];
233
- case 1:
234
- response = _a.sent();
235
- if (!(response.status !== 200)) return [3 /*break*/, 2];
236
- throw response;
237
- case 2: return [4 /*yield*/, parseString(response.data)];
238
- case 3:
239
- parsed = _a.sent();
240
- return [2 /*return*/, new ScanStatus_1.default(parsed)];
241
- }
242
- });
243
- });
244
- };
245
- HPApi.delay = function (t) {
246
- return new Promise(function (resolve) {
247
- setTimeout(resolve, t);
248
- });
249
- };
250
- HPApi.postJob = function (job) {
251
- return __awaiter(this, void 0, void 0, function () {
252
- var xml, response;
253
- return __generator(this, function (_a) {
254
- switch (_a.label) {
255
- case 0: return [4 /*yield*/, HPApi.delay(500)];
256
- case 1:
257
- _a.sent();
258
- return [4 /*yield*/, job.toXML()];
259
- case 2:
260
- xml = _a.sent();
261
- return [4 /*yield*/, axios_1.default({
262
- baseURL: "http://" + printerIP + ":8080",
263
- url: "/Scan/Jobs",
264
- method: "POST",
265
- headers: { "Content-Type": "text/xml" },
266
- data: xml,
267
- responseType: "text"
268
- })];
269
- case 3:
270
- response = _a.sent();
271
- if (response.status === 201) {
272
- return [2 /*return*/, response.headers.location];
273
- }
274
- else {
275
- throw response;
276
- }
277
- return [2 /*return*/];
278
- }
279
- });
280
- });
281
- };
282
- /**
283
- * @param jobURL
284
- * @return {Promise<Job|*>}
285
- */
286
- HPApi.getJob = function (jobURL) {
287
- return __awaiter(this, void 0, void 0, function () {
288
- var response, parsed;
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, axios_1.default({
292
- url: jobURL,
293
- method: "GET",
294
- responseType: "text"
295
- })];
296
- case 1:
297
- response = _a.sent();
298
- if (!(response.status !== 200)) return [3 /*break*/, 2];
299
- throw response;
300
- case 2: return [4 /*yield*/, parseString(response.data)];
301
- case 3:
302
- parsed = _a.sent();
303
- return [2 /*return*/, new Job_1.default(parsed)];
304
- }
305
- });
306
- });
307
- };
308
- HPApi.downloadPage = function (binaryURL, destination) {
309
- return __awaiter(this, void 0, void 0, function () {
310
- var response;
311
- return __generator(this, function (_a) {
312
- switch (_a.label) {
313
- case 0: return [4 /*yield*/, axios_1.default({
314
- baseURL: "http://" + printerIP + ":8080",
315
- url: binaryURL,
316
- method: "GET",
317
- responseType: "stream"
318
- })];
319
- case 1:
320
- response = _a.sent();
321
- response.data.pipe(fs_1.default.createWriteStream(destination));
322
- return [2 /*return*/, new Promise(function (resolve, reject) {
323
- response.data
324
- .on("end", function () { return resolve(destination); })
325
- .on("error", function (error) { return reject(error); });
326
- })];
327
- }
328
- });
329
- });
330
- };
331
- return HPApi;
332
- }());
333
- exports.default = HPApi;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ var WalkupScanDestination_1 = __importDefault(require("./WalkupScanDestination"));
66
+ var WalkupScanToCompDestination_1 = __importDefault(require("./WalkupScanToCompDestination"));
67
+ var util_1 = require("util");
68
+ var fs_1 = __importDefault(require("fs"));
69
+ var axios_1 = __importDefault(require("axios"));
70
+ var url_1 = require("url");
71
+ var xml2js_1 = require("xml2js");
72
+ var stream = __importStar(require("stream/promises"));
73
+ var EventTable_1 = __importDefault(require("./EventTable"));
74
+ var Job_1 = __importDefault(require("./Job"));
75
+ var ScanStatus_1 = __importDefault(require("./ScanStatus"));
76
+ var WalkupScanDestinations_1 = __importDefault(require("./WalkupScanDestinations"));
77
+ var WalkupScanToCompDestinations_1 = __importDefault(require("./WalkupScanToCompDestinations"));
78
+ var WalkupScanToCompEvent_1 = __importDefault(require("./WalkupScanToCompEvent"));
79
+ var parser = new xml2js_1.Parser();
80
+ var parseString = (0, util_1.promisify)(parser.parseString);
81
+ var printerIP = "192.168.1.11";
82
+ var debug = false;
83
+ var callCount = 0;
84
+ var HPApi = /** @class */ (function () {
85
+ function HPApi() {
86
+ }
87
+ HPApi.setPrinterIP = function (ip) {
88
+ printerIP = ip;
89
+ };
90
+ HPApi.setDebug = function (dbg) {
91
+ debug = dbg;
92
+ };
93
+ HPApi.logDebug = function (callId, isRequest, msg) {
94
+ if (debug) {
95
+ var id = String(callId).padStart(4, "0");
96
+ var content = typeof msg === "string" ? msg : JSON.stringify(msg);
97
+ console.log(id + (isRequest ? " -> " : " <- ") + content);
98
+ }
99
+ };
100
+ HPApi.callAxios = function (request) {
101
+ var _a, _b, _c, _d;
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var response, error_1, axiosError;
104
+ return __generator(this, function (_e) {
105
+ switch (_e.label) {
106
+ case 0:
107
+ callCount++;
108
+ HPApi.logDebug(callCount, true, request);
109
+ _e.label = 1;
110
+ case 1:
111
+ _e.trys.push([1, 3, , 4]);
112
+ return [4 /*yield*/, (0, axios_1.default)(request)];
113
+ case 2:
114
+ response = (_e.sent());
115
+ HPApi.logDebug(callCount, false, {
116
+ status: response.status,
117
+ data: response.data,
118
+ headers: response.headers,
119
+ statusText: response.statusText,
120
+ });
121
+ return [2 /*return*/, response];
122
+ case 3:
123
+ error_1 = _e.sent();
124
+ axiosError = error_1;
125
+ if (axiosError.isAxiosError) {
126
+ HPApi.logDebug(callCount, false, {
127
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status,
128
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data,
129
+ headers: (_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.headers,
130
+ statusText: (_d = axiosError.response) === null || _d === void 0 ? void 0 : _d.statusText,
131
+ });
132
+ }
133
+ throw error_1;
134
+ case 4: return [2 /*return*/];
135
+ }
136
+ });
137
+ });
138
+ };
139
+ HPApi.getWalkupScanDestinations = function () {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ var response, parsed;
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0: return [4 /*yield*/, HPApi.callAxios({
145
+ baseURL: "http://".concat(printerIP),
146
+ url: "/WalkupScan/WalkupScanDestinations",
147
+ method: "GET",
148
+ responseType: "text",
149
+ })];
150
+ case 1:
151
+ response = _a.sent();
152
+ if (!(response.status !== 200)) return [3 /*break*/, 2];
153
+ throw new Error(response.statusText);
154
+ case 2: return [4 /*yield*/, parseString(response.data)];
155
+ case 3:
156
+ parsed = (_a.sent());
157
+ return [2 /*return*/, new WalkupScanDestinations_1.default(parsed)];
158
+ }
159
+ });
160
+ });
161
+ };
162
+ HPApi.getWalkupScanToCompDestinations = function () {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var response, parsed;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0: return [4 /*yield*/, HPApi.callAxios({
168
+ baseURL: "http://".concat(printerIP),
169
+ url: "/WalkupScanToComp/WalkupScanToCompDestinations",
170
+ method: "GET",
171
+ responseType: "text",
172
+ })];
173
+ case 1:
174
+ response = _a.sent();
175
+ if (!(response.status !== 200)) return [3 /*break*/, 2];
176
+ throw new Error(response.statusText);
177
+ case 2: return [4 /*yield*/, parseString(response.data)];
178
+ case 3:
179
+ parsed = (_a.sent());
180
+ return [2 /*return*/, new WalkupScanToCompDestinations_1.default(parsed)];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ HPApi.getWalkupScanToCompCaps = function () {
186
+ return __awaiter(this, void 0, void 0, function () {
187
+ return __generator(this, function (_a) {
188
+ return [2 /*return*/, HPApi.callAxios({
189
+ baseURL: "http://".concat(printerIP),
190
+ url: "/WalkupScanToComp/WalkupScanToCompCaps",
191
+ method: "GET",
192
+ responseType: "text",
193
+ }).then(function (response) { return response.status == 200; }, function () { return false; })];
194
+ });
195
+ });
196
+ };
197
+ HPApi.getWalkupScanToCompEvent = function (compEventURI) {
198
+ return __awaiter(this, void 0, void 0, function () {
199
+ var response;
200
+ return __generator(this, function (_a) {
201
+ switch (_a.label) {
202
+ case 0: return [4 /*yield*/, HPApi.callAxios({
203
+ baseURL: "http://".concat(printerIP),
204
+ url: compEventURI,
205
+ method: "GET",
206
+ responseType: "text",
207
+ })];
208
+ case 1:
209
+ response = _a.sent();
210
+ if (response.status !== 200) {
211
+ throw response;
212
+ }
213
+ else {
214
+ return [2 /*return*/, HPApi.createWalkupScanToCompEvent(response.data)];
215
+ }
216
+ return [2 /*return*/];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ HPApi.removeDestination = function (walkupScanDestination) {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var urlInfo, response;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0:
227
+ urlInfo = new url_1.URL(walkupScanDestination.resourceURI);
228
+ if (urlInfo.pathname === null) {
229
+ throw new Error("invalid walkupScanDestination.resourceURI: ".concat(walkupScanDestination.resourceURI));
230
+ }
231
+ return [4 /*yield*/, HPApi.callAxios({
232
+ baseURL: "http://".concat(printerIP),
233
+ url: urlInfo.pathname,
234
+ method: "DELETE",
235
+ responseType: "text",
236
+ })];
237
+ case 1:
238
+ response = _a.sent();
239
+ if (response.status === 204) {
240
+ return [2 /*return*/, true];
241
+ }
242
+ else {
243
+ throw response;
244
+ }
245
+ return [2 /*return*/];
246
+ }
247
+ });
248
+ });
249
+ };
250
+ HPApi.registerDestination = function (destination, toComp) {
251
+ return __awaiter(this, void 0, void 0, function () {
252
+ var xml, url, response;
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0: return [4 /*yield*/, destination.toXML()];
256
+ case 1:
257
+ xml = _a.sent();
258
+ url = "/WalkupScan/WalkupScanDestinations";
259
+ if (toComp) {
260
+ url = "/WalkupScanToComp/WalkupScanToCompDestinations";
261
+ }
262
+ return [4 /*yield*/, HPApi.callAxios({
263
+ baseURL: "http://".concat(printerIP),
264
+ url: url,
265
+ method: "POST",
266
+ headers: { "Content-Type": "text/xml" },
267
+ data: xml,
268
+ responseType: "text",
269
+ })];
270
+ case 2:
271
+ response = _a.sent();
272
+ if (response.status === 201) {
273
+ return [2 /*return*/, new url_1.URL(response.headers.location).pathname];
274
+ }
275
+ else {
276
+ throw response;
277
+ }
278
+ return [2 /*return*/];
279
+ }
280
+ });
281
+ });
282
+ };
283
+ HPApi.getEvents = function (etag, timeout) {
284
+ var _a;
285
+ if (etag === void 0) { etag = ""; }
286
+ if (timeout === void 0) { timeout = 0; }
287
+ return __awaiter(this, void 0, void 0, function () {
288
+ var url, headers, response, error_2, axiosError, parsed;
289
+ return __generator(this, function (_b) {
290
+ switch (_b.label) {
291
+ case 0:
292
+ url = this.appendTimeout("/EventMgmt/EventTable", timeout);
293
+ headers = this.placeETagHeader(etag, {});
294
+ _b.label = 1;
295
+ case 1:
296
+ _b.trys.push([1, 3, , 4]);
297
+ return [4 /*yield*/, HPApi.callAxios({
298
+ baseURL: "http://".concat(printerIP),
299
+ url: url,
300
+ method: "GET",
301
+ responseType: "text",
302
+ headers: headers,
303
+ })];
304
+ case 2:
305
+ response = _b.sent();
306
+ return [3 /*break*/, 4];
307
+ case 3:
308
+ error_2 = _b.sent();
309
+ axiosError = error_2;
310
+ if (!axiosError.isAxiosError)
311
+ throw error_2;
312
+ if (((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) === 304) {
313
+ return [2 /*return*/, {
314
+ etag: etag,
315
+ eventTable: new EventTable_1.default({}),
316
+ }];
317
+ }
318
+ throw error_2;
319
+ case 4: return [4 /*yield*/, parseString(response.data)];
320
+ case 5:
321
+ parsed = _b.sent();
322
+ return [2 /*return*/, {
323
+ etag: response.headers["etag"],
324
+ eventTable: new EventTable_1.default(parsed),
325
+ }];
326
+ }
327
+ });
328
+ });
329
+ };
330
+ HPApi.placeETagHeader = function (etag, headers) {
331
+ if (etag !== "") {
332
+ headers = {
333
+ "If-None-Match": etag,
334
+ };
335
+ }
336
+ return headers;
337
+ };
338
+ HPApi.appendTimeout = function (url, timeout) {
339
+ if (timeout === void 0) { timeout = null; }
340
+ if (timeout == null) {
341
+ timeout = 1200;
342
+ }
343
+ if (timeout > 0) {
344
+ url += "?timeout=" + timeout;
345
+ }
346
+ return url;
347
+ };
348
+ HPApi.getDestination = function (destinationURL) {
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var response, content;
351
+ return __generator(this, function (_a) {
352
+ switch (_a.label) {
353
+ case 0: return [4 /*yield*/, HPApi.callAxios({
354
+ baseURL: "http://".concat(printerIP),
355
+ url: destinationURL,
356
+ method: "GET",
357
+ responseType: "text",
358
+ })];
359
+ case 1:
360
+ response = _a.sent();
361
+ if (response.status !== 200) {
362
+ throw response;
363
+ }
364
+ else {
365
+ content = response.data;
366
+ if (destinationURL.includes("WalkupScanToComp")) {
367
+ return [2 /*return*/, this.createWalkupScanToCompDestination(content)];
368
+ }
369
+ else {
370
+ return [2 /*return*/, this.createWalkupScanDestination(content)];
371
+ }
372
+ }
373
+ return [2 /*return*/];
374
+ }
375
+ });
376
+ });
377
+ };
378
+ HPApi.createWalkupScanDestination = function (content) {
379
+ return __awaiter(this, void 0, void 0, function () {
380
+ var parsed;
381
+ return __generator(this, function (_a) {
382
+ switch (_a.label) {
383
+ case 0: return [4 /*yield*/, parseString(content)];
384
+ case 1:
385
+ parsed = (_a.sent());
386
+ return [2 /*return*/, new WalkupScanDestination_1.default(parsed)];
387
+ }
388
+ });
389
+ });
390
+ };
391
+ HPApi.createWalkupScanToCompDestination = function (content) {
392
+ return __awaiter(this, void 0, void 0, function () {
393
+ var parsed;
394
+ return __generator(this, function (_a) {
395
+ switch (_a.label) {
396
+ case 0: return [4 /*yield*/, parseString(content)];
397
+ case 1:
398
+ parsed = (_a.sent());
399
+ return [2 /*return*/, new WalkupScanToCompDestination_1.default(parsed)];
400
+ }
401
+ });
402
+ });
403
+ };
404
+ HPApi.createWalkupScanToCompEvent = function (content) {
405
+ return __awaiter(this, void 0, void 0, function () {
406
+ var parsed;
407
+ return __generator(this, function (_a) {
408
+ switch (_a.label) {
409
+ case 0: return [4 /*yield*/, parseString(content)];
410
+ case 1:
411
+ parsed = (_a.sent());
412
+ return [2 /*return*/, new WalkupScanToCompEvent_1.default(parsed)];
413
+ }
414
+ });
415
+ });
416
+ };
417
+ HPApi.getScanStatus = function () {
418
+ return __awaiter(this, void 0, void 0, function () {
419
+ var response, parsed;
420
+ return __generator(this, function (_a) {
421
+ switch (_a.label) {
422
+ case 0: return [4 /*yield*/, HPApi.callAxios({
423
+ baseURL: "http://".concat(printerIP),
424
+ url: "/Scan/Status",
425
+ method: "GET",
426
+ responseType: "text",
427
+ })];
428
+ case 1:
429
+ response = _a.sent();
430
+ if (!(response.status !== 200)) return [3 /*break*/, 2];
431
+ throw response;
432
+ case 2: return [4 /*yield*/, parseString(response.data)];
433
+ case 3:
434
+ parsed = (_a.sent());
435
+ return [2 /*return*/, new ScanStatus_1.default(parsed)];
436
+ }
437
+ });
438
+ });
439
+ };
440
+ HPApi.delay = function (t) {
441
+ return new Promise(function (resolve) {
442
+ setTimeout(resolve, t);
443
+ });
444
+ };
445
+ HPApi.postJob = function (job) {
446
+ return __awaiter(this, void 0, void 0, function () {
447
+ var xml, response;
448
+ return __generator(this, function (_a) {
449
+ switch (_a.label) {
450
+ case 0: return [4 /*yield*/, HPApi.delay(500)];
451
+ case 1:
452
+ _a.sent();
453
+ return [4 /*yield*/, job.toXML()];
454
+ case 2:
455
+ xml = _a.sent();
456
+ return [4 /*yield*/, HPApi.callAxios({
457
+ baseURL: "http://".concat(printerIP, ":8080"),
458
+ url: "/Scan/Jobs",
459
+ method: "POST",
460
+ headers: { "Content-Type": "text/xml" },
461
+ data: xml,
462
+ responseType: "text",
463
+ })];
464
+ case 3:
465
+ response = _a.sent();
466
+ if (response.status === 201) {
467
+ return [2 /*return*/, response.headers.location];
468
+ }
469
+ else {
470
+ throw response;
471
+ }
472
+ return [2 /*return*/];
473
+ }
474
+ });
475
+ });
476
+ };
477
+ /**
478
+ * @param jobURL
479
+ * @return {Promise<Job|*>}
480
+ */
481
+ HPApi.getJob = function (jobURL) {
482
+ return __awaiter(this, void 0, void 0, function () {
483
+ var response, parsed;
484
+ return __generator(this, function (_a) {
485
+ switch (_a.label) {
486
+ case 0: return [4 /*yield*/, HPApi.callAxios({
487
+ url: jobURL,
488
+ method: "GET",
489
+ responseType: "text",
490
+ })];
491
+ case 1:
492
+ response = _a.sent();
493
+ if (!(response.status !== 200)) return [3 /*break*/, 2];
494
+ throw response;
495
+ case 2: return [4 /*yield*/, parseString(response.data)];
496
+ case 3:
497
+ parsed = (_a.sent());
498
+ return [2 /*return*/, new Job_1.default(parsed)];
499
+ }
500
+ });
501
+ });
502
+ };
503
+ HPApi.downloadPage = function (binaryURL, destination) {
504
+ return __awaiter(this, void 0, void 0, function () {
505
+ var data, destinationFileStream;
506
+ return __generator(this, function (_a) {
507
+ switch (_a.label) {
508
+ case 0: return [4 /*yield*/, axios_1.default.request({
509
+ baseURL: "http://".concat(printerIP, ":8080"),
510
+ url: binaryURL,
511
+ method: "GET",
512
+ responseType: "stream",
513
+ })];
514
+ case 1:
515
+ data = (_a.sent()).data;
516
+ destinationFileStream = fs_1.default.createWriteStream(destination);
517
+ data.pipe(destinationFileStream);
518
+ return [4 /*yield*/, stream.finished(destinationFileStream)];
519
+ case 2:
520
+ _a.sent();
521
+ return [2 /*return*/, destination];
522
+ }
523
+ });
524
+ });
525
+ };
526
+ return HPApi;
527
+ }());
528
+ exports.default = HPApi;
334
529
  //# sourceMappingURL=HPApi.js.map