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.
- package/README.md +92 -11
- package/dist/Destination.d.ts +8 -7
- package/dist/Destination.js +115 -84
- package/dist/Destination.js.map +1 -1
- package/dist/Event.d.ts +21 -17
- package/dist/Event.js +46 -30
- package/dist/Event.js.map +1 -1
- package/dist/EventTable.d.ts +11 -11
- package/dist/EventTable.js +26 -26
- package/dist/EventTable.js.map +1 -1
- package/dist/HPApi.d.ts +42 -29
- package/dist/HPApi.js +528 -333
- package/dist/HPApi.js.map +1 -1
- package/dist/Job.d.ts +36 -24
- package/dist/Job.js +94 -62
- package/dist/Job.js.map +1 -1
- package/dist/JpegUtil.d.ts +26 -0
- package/dist/JpegUtil.js +238 -0
- package/dist/JpegUtil.js.map +1 -0
- package/dist/PathHelper.d.ts +5 -0
- package/dist/PathHelper.js +79 -0
- package/dist/PathHelper.js.map +1 -0
- package/dist/ScanContent.d.ts +12 -0
- package/dist/ScanContent.js +82 -0
- package/dist/ScanContent.js.map +1 -0
- package/dist/ScanJobSettings.d.ts +6 -6
- package/dist/ScanJobSettings.js +95 -94
- package/dist/ScanJobSettings.js.map +1 -1
- package/dist/ScanStatus.d.ts +18 -18
- package/dist/ScanStatus.js +35 -29
- package/dist/ScanStatus.js.map +1 -1
- package/dist/WalkupScanDestination.d.ts +24 -24
- package/dist/WalkupScanDestination.js +40 -40
- package/dist/WalkupScanDestination.js.map +1 -1
- package/dist/WalkupScanDestinations.d.ts +11 -11
- package/dist/WalkupScanDestinations.js +26 -26
- package/dist/WalkupScanDestinations.js.map +1 -1
- package/dist/WalkupScanToCompDestination.d.ts +26 -0
- package/dist/WalkupScanToCompDestination.js +44 -0
- package/dist/WalkupScanToCompDestination.js.map +1 -0
- package/dist/WalkupScanToCompDestinations.d.ts +11 -0
- package/dist/WalkupScanToCompDestinations.js +27 -0
- package/dist/WalkupScanToCompDestinations.js.map +1 -0
- package/dist/WalkupScanToCompEvent.d.ts +10 -0
- package/dist/WalkupScanToCompEvent.js +17 -0
- package/dist/WalkupScanToCompEvent.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +630 -292
- package/dist/index.js.map +1 -1
- package/nodemon.json +5 -5
- package/package.json +72 -57
- package/src/Destination.ts +63 -45
- package/src/Event.ts +45 -31
- package/src/EventTable.ts +25 -25
- package/src/HPApi.ts +365 -222
- package/src/Job.ts +100 -62
- package/src/JpegUtil.ts +319 -0
- package/src/PathHelper.ts +44 -0
- package/src/ScanContent.ts +34 -0
- package/src/ScanJobSettings.ts +55 -55
- package/src/ScanStatus.ts +36 -31
- package/src/WalkupScanDestination.ts +46 -44
- package/src/WalkupScanDestinations.ts +29 -27
- package/src/WalkupScanToCompDestination.ts +55 -0
- package/src/WalkupScanToCompDestinations.ts +34 -0
- package/src/WalkupScanToCompEvent.ts +18 -0
- package/src/index.ts +555 -205
- package/tsconfig.json +34 -0
package/dist/HPApi.js
CHANGED
|
@@ -1,334 +1,529 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
case
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
});
|
|
249
|
-
};
|
|
250
|
-
HPApi.
|
|
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*/,
|
|
256
|
-
case 1:
|
|
257
|
-
_a.sent();
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
var response, parsed;
|
|
289
|
-
return __generator(this, function (
|
|
290
|
-
switch (
|
|
291
|
-
case 0:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
case
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return [2 /*return*/,
|
|
323
|
-
response.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|