node-hp-scan-to 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +76 -15
  2. package/dist/Destination.js.map +1 -1
  3. package/dist/DeviceCapabilities.d.ts +4 -0
  4. package/dist/DeviceCapabilities.js.map +1 -1
  5. package/dist/DiscoveryTree.js.map +1 -1
  6. package/dist/Event.js +2 -2
  7. package/dist/Event.js.map +1 -1
  8. package/dist/EventTable.js.map +1 -1
  9. package/dist/HPApi.js.map +1 -1
  10. package/dist/InputSource.d.ts +4 -0
  11. package/dist/InputSource.js +9 -0
  12. package/dist/InputSource.js.map +1 -0
  13. package/dist/Job.d.ts +2 -0
  14. package/dist/Job.js +2 -2
  15. package/dist/Job.js.map +1 -1
  16. package/dist/JpegUtil.js +1 -1
  17. package/dist/JpegUtil.js.map +1 -1
  18. package/dist/PathHelper.d.ts +4 -3
  19. package/dist/PathHelper.js +28 -13
  20. package/dist/PathHelper.js.map +1 -1
  21. package/dist/ScanCaps.d.ts +18 -0
  22. package/dist/ScanCaps.js +14 -0
  23. package/dist/ScanCaps.js.map +1 -1
  24. package/dist/ScanContent.js.map +1 -1
  25. package/dist/ScanJobManifest.js.map +1 -1
  26. package/dist/ScanJobSettings.d.ts +4 -1
  27. package/dist/ScanJobSettings.js +19 -8
  28. package/dist/ScanJobSettings.js.map +1 -1
  29. package/dist/ScanStatus.d.ts +2 -1
  30. package/dist/ScanStatus.js +3 -2
  31. package/dist/ScanStatus.js.map +1 -1
  32. package/dist/WalkupScanDestination.js +2 -2
  33. package/dist/WalkupScanDestination.js.map +1 -1
  34. package/dist/WalkupScanDestinations.js +1 -1
  35. package/dist/WalkupScanDestinations.js.map +1 -1
  36. package/dist/WalkupScanManifest.js.map +1 -1
  37. package/dist/WalkupScanToCompCaps.js.map +1 -1
  38. package/dist/WalkupScanToCompDestination.js +2 -2
  39. package/dist/WalkupScanToCompDestination.js.map +1 -1
  40. package/dist/WalkupScanToCompDestinations.js +1 -1
  41. package/dist/WalkupScanToCompDestinations.js.map +1 -1
  42. package/dist/WalkupScanToCompEvent.js.map +1 -1
  43. package/dist/WalkupScanToCompManifest.js.map +1 -1
  44. package/dist/index.js +28 -7
  45. package/dist/index.js.map +1 -1
  46. package/dist/listening.js.map +1 -1
  47. package/dist/readDeviceCapabilities.js +6 -1
  48. package/dist/readDeviceCapabilities.js.map +1 -1
  49. package/dist/scanProcessing.d.ts +5 -1
  50. package/dist/scanProcessing.js +61 -21
  51. package/dist/scanProcessing.js.map +1 -1
  52. package/package.json +7 -7
  53. package/src/Destination.ts +1 -1
  54. package/src/DeviceCapabilities.ts +4 -0
  55. package/src/DiscoveryTree.ts +1 -1
  56. package/src/Event.ts +4 -4
  57. package/src/EventTable.ts +1 -1
  58. package/src/HPApi.ts +19 -19
  59. package/src/InputSource.ts +4 -0
  60. package/src/Job.ts +19 -7
  61. package/src/JpegUtil.ts +18 -14
  62. package/src/PathHelper.ts +48 -20
  63. package/src/ScanCaps.ts +43 -1
  64. package/src/ScanContent.ts +1 -1
  65. package/src/ScanJobManifest.ts +3 -2
  66. package/src/ScanJobSettings.ts +23 -9
  67. package/src/ScanStatus.ts +6 -3
  68. package/src/WalkupScanDestination.ts +9 -5
  69. package/src/WalkupScanDestinations.ts +9 -4
  70. package/src/WalkupScanManifest.ts +3 -3
  71. package/src/WalkupScanToCompCaps.ts +2 -2
  72. package/src/WalkupScanToCompDestination.ts +15 -5
  73. package/src/WalkupScanToCompDestinations.ts +5 -4
  74. package/src/WalkupScanToCompEvent.ts +1 -1
  75. package/src/WalkupScanToCompManifest.ts +3 -3
  76. package/src/index.ts +92 -35
  77. package/src/listening.ts +14 -15
  78. package/src/readDeviceCapabilities.ts +12 -6
  79. package/src/scanProcessing.ts +129 -52
  80. package/dist/fixJpegSize.d.ts +0 -19
  81. package/dist/fixJpegSize.js +0 -292
  82. package/dist/fixJpegSize.js.map +0 -1
  83. package/dist/scanProcess.d.ts +0 -19
  84. package/dist/scanProcess.js +0 -292
  85. package/dist/scanProcess.js.map +0 -1
  86. package/dist/src/Destination.d.ts +0 -8
  87. package/dist/src/Destination.js +0 -68
  88. package/dist/src/Destination.js.map +0 -1
  89. package/dist/src/DiscoveryTree.d.ts +0 -16
  90. package/dist/src/DiscoveryTree.js +0 -38
  91. package/dist/src/DiscoveryTree.js.map +0 -1
  92. package/dist/src/Event.d.ts +0 -21
  93. package/dist/src/Event.js +0 -32
  94. package/dist/src/Event.js.map +0 -1
  95. package/dist/src/EventTable.d.ts +0 -16
  96. package/dist/src/EventTable.js +0 -33
  97. package/dist/src/EventTable.js.map +0 -1
  98. package/dist/src/HPApi.d.ts +0 -50
  99. package/dist/src/HPApi.js +0 -454
  100. package/dist/src/HPApi.js.map +0 -1
  101. package/dist/src/Job.d.ts +0 -37
  102. package/dist/src/Job.js +0 -78
  103. package/dist/src/Job.js.map +0 -1
  104. package/dist/src/JpegUtil.d.ts +0 -26
  105. package/dist/src/JpegUtil.js +0 -229
  106. package/dist/src/JpegUtil.js.map +0 -1
  107. package/dist/src/KnownShortcut.d.ts +0 -1
  108. package/dist/src/KnownShortcut.js +0 -3
  109. package/dist/src/KnownShortcut.js.map +0 -1
  110. package/dist/src/PathHelper.d.ts +0 -6
  111. package/dist/src/PathHelper.js +0 -52
  112. package/dist/src/PathHelper.js.map +0 -1
  113. package/dist/src/ScanCaps.d.ts +0 -7
  114. package/dist/src/ScanCaps.js +0 -17
  115. package/dist/src/ScanCaps.js.map +0 -1
  116. package/dist/src/ScanJobManifest.d.ts +0 -23
  117. package/dist/src/ScanJobManifest.js +0 -24
  118. package/dist/src/ScanJobManifest.js.map +0 -1
  119. package/dist/src/ScanJobSettings.d.ts +0 -8
  120. package/dist/src/ScanJobSettings.js +0 -56
  121. package/dist/src/ScanJobSettings.js.map +0 -1
  122. package/dist/src/ScanStatus.d.ts +0 -19
  123. package/dist/src/ScanStatus.js +0 -35
  124. package/dist/src/ScanStatus.js.map +0 -1
  125. package/dist/src/WalkupScanDestination.d.ts +0 -22
  126. package/dist/src/WalkupScanDestination.js +0 -38
  127. package/dist/src/WalkupScanDestination.js.map +0 -1
  128. package/dist/src/WalkupScanDestinations.d.ts +0 -12
  129. package/dist/src/WalkupScanDestinations.js +0 -30
  130. package/dist/src/WalkupScanDestinations.js.map +0 -1
  131. package/dist/src/WalkupScanManifest.d.ts +0 -23
  132. package/dist/src/WalkupScanManifest.js +0 -25
  133. package/dist/src/WalkupScanManifest.js.map +0 -1
  134. package/dist/src/WalkupScanToCompCaps.d.ts +0 -12
  135. package/dist/src/WalkupScanToCompCaps.js +0 -20
  136. package/dist/src/WalkupScanToCompCaps.js.map +0 -1
  137. package/dist/src/WalkupScanToCompDestination.d.ts +0 -22
  138. package/dist/src/WalkupScanToCompDestination.js +0 -38
  139. package/dist/src/WalkupScanToCompDestination.js.map +0 -1
  140. package/dist/src/WalkupScanToCompDestinations.d.ts +0 -12
  141. package/dist/src/WalkupScanToCompDestinations.js +0 -30
  142. package/dist/src/WalkupScanToCompDestinations.js.map +0 -1
  143. package/dist/src/WalkupScanToCompEvent.d.ts +0 -11
  144. package/dist/src/WalkupScanToCompEvent.js +0 -20
  145. package/dist/src/WalkupScanToCompEvent.js.map +0 -1
  146. package/dist/src/WalkupScanToCompManifest.d.ts +0 -23
  147. package/dist/src/WalkupScanToCompManifest.js +0 -25
  148. package/dist/src/WalkupScanToCompManifest.js.map +0 -1
  149. package/dist/src/delay.d.ts +0 -1
  150. package/dist/src/delay.js +0 -10
  151. package/dist/src/delay.js.map +0 -1
  152. package/dist/test/DiscoveryTree.test.d.ts +0 -1
  153. package/dist/test/DiscoveryTree.test.js +0 -68
  154. package/dist/test/DiscoveryTree.test.js.map +0 -1
  155. package/dist/test/EtagEventTable.test.d.ts +0 -1
  156. package/dist/test/EtagEventTable.test.js +0 -93
  157. package/dist/test/EtagEventTable.test.js.map +0 -1
  158. package/dist/test/Job.test.d.ts +0 -1
  159. package/dist/test/Job.test.js +0 -104
  160. package/dist/test/Job.test.js.map +0 -1
  161. package/dist/test/JpegUtil.test.d.ts +0 -1
  162. package/dist/test/JpegUtil.test.js +0 -51
  163. package/dist/test/JpegUtil.test.js.map +0 -1
  164. package/dist/test/PathHelper.test.d.ts +0 -1
  165. package/dist/test/PathHelper.test.js +0 -99
  166. package/dist/test/PathHelper.test.js.map +0 -1
  167. package/dist/test/ScanJobManifest.test.d.ts +0 -1
  168. package/dist/test/ScanJobManifest.test.js +0 -56
  169. package/dist/test/ScanJobManifest.test.js.map +0 -1
  170. package/dist/test/ScanJobSettings.test.d.ts +0 -1
  171. package/dist/test/ScanJobSettings.test.js +0 -53
  172. package/dist/test/ScanJobSettings.test.js.map +0 -1
  173. package/dist/test/ScanStatus.test.d.ts +0 -1
  174. package/dist/test/ScanStatus.test.js +0 -75
  175. package/dist/test/ScanStatus.test.js.map +0 -1
  176. package/dist/test/WalkupScanDestination.test.d.ts +0 -1
  177. package/dist/test/WalkupScanDestination.test.js +0 -80
  178. package/dist/test/WalkupScanDestination.test.js.map +0 -1
  179. package/dist/test/WalkupScanDestinations.test.d.ts +0 -1
  180. package/dist/test/WalkupScanDestinations.test.js +0 -68
  181. package/dist/test/WalkupScanDestinations.test.js.map +0 -1
  182. package/dist/test/WalkupScanManifest.test.d.ts +0 -1
  183. package/dist/test/WalkupScanManifest.test.js +0 -46
  184. package/dist/test/WalkupScanManifest.test.js.map +0 -1
  185. package/dist/test/WalkupScanToCompCaps.test.d.ts +0 -1
  186. package/dist/test/WalkupScanToCompCaps.test.js +0 -56
  187. package/dist/test/WalkupScanToCompCaps.test.js.map +0 -1
  188. package/dist/test/WalkupScanToCompDestination.test.d.ts +0 -1
  189. package/dist/test/WalkupScanToCompDestination.test.js +0 -58
  190. package/dist/test/WalkupScanToCompDestination.test.js.map +0 -1
  191. package/dist/test/WalkupScanToCompDestinations.test.d.ts +0 -1
  192. package/dist/test/WalkupScanToCompDestinations.test.js +0 -58
  193. package/dist/test/WalkupScanToCompDestinations.test.js.map +0 -1
  194. package/dist/test/WalkupScanToCompEvent.test.d.ts +0 -1
  195. package/dist/test/WalkupScanToCompEvent.test.js +0 -46
  196. package/dist/test/WalkupScanToCompEvent.test.js.map +0 -1
  197. package/dist/test/WalkupScanToCompManifest.test.d.ts +0 -1
  198. package/dist/test/WalkupScanToCompManifest.test.js +0 -46
  199. package/dist/test/WalkupScanToCompManifest.test.js.map +0 -1
  200. package/dist/test/clean.d.ts +0 -1
  201. package/dist/test/clean.js +0 -21
  202. package/dist/test/clean.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-hp-scan-to",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Scan document to Computer for HP All-in-One Printers",
5
5
  "keywords": [
6
6
  "Officejet",
@@ -32,7 +32,7 @@
32
32
  "README.md"
33
33
  ],
34
34
  "engines": {
35
- "node": ">=12.22.0"
35
+ "node": ">=16.20.0"
36
36
  },
37
37
  "author": {
38
38
  "email": "manuc66@gmail.com",
@@ -54,16 +54,16 @@
54
54
  "@types/config": "^3.3.0",
55
55
  "@types/dateformat": "^5.0.0",
56
56
  "@types/mocha": "^10.0.0",
57
- "@types/node": "^18.11.0",
57
+ "@types/node": "^20.1.7",
58
58
  "@types/xml2js": "^0.4.11",
59
59
  "chai": "^4.3.6",
60
60
  "chai-string": "^1.5.0",
61
61
  "codecov": "^3.8.3",
62
62
  "eslint": "^8.25.0",
63
63
  "mocha": "^10.1.0",
64
- "nodemon": "^2.0.20",
64
+ "nodemon": "^3.0.1",
65
65
  "nyc": "^15.1.0",
66
- "prettier": "^2.7.1",
66
+ "prettier": "^3.0.0",
67
67
  "ts-mockito": "^2.6.1",
68
68
  "ts-node": "^10.9.1",
69
69
  "typescript": "^5.0.2",
@@ -72,10 +72,10 @@
72
72
  "dependencies": {
73
73
  "axios": "^1.1.3",
74
74
  "bonjour": "^3.5.0",
75
- "commander": "^10.0.0",
75
+ "commander": "^11.0.0",
76
76
  "config": "^3.3.8",
77
77
  "dateformat": "^4.6.3",
78
78
  "jspdf": "^2.5.1",
79
- "xml2js": "^0.4.23"
79
+ "xml2js": "^0.6.0"
80
80
  }
81
81
  }
@@ -45,7 +45,7 @@ export default class Destination {
45
45
  "</WalkupScanDestination>";
46
46
 
47
47
  const parsed = await util.promisify<string, WalkupScanDestinationData>(
48
- parser.parseString
48
+ parser.parseString,
49
49
  )(rawDestination);
50
50
 
51
51
  parsed.WalkupScanDestination.Hostname[0]._ = this.hostname;
@@ -1,4 +1,8 @@
1
1
  export interface DeviceCapabilities {
2
2
  supportsMultiItemScanFromPlaten: boolean;
3
3
  useWalkupScanToComp: boolean;
4
+ platenMaxWidth: number | null;
5
+ platenMaxHeight: number | null;
6
+ adfMaxWidth: number | null;
7
+ adfMaxHeight: number | null;
4
8
  }
@@ -28,7 +28,7 @@ export default class DiscoveryTree {
28
28
  const hpLedmWalkupScanToCompManifest = this.data["ledm:DiscoveryTree"][
29
29
  "ledm:SupportedIfc"
30
30
  ].find(
31
- (x) => x["dd:ResourceType"][0] === "ledm:hpLedmWalkupScanToCompManifest"
31
+ (x) => x["dd:ResourceType"][0] === "ledm:hpLedmWalkupScanToCompManifest",
32
32
  );
33
33
  if (hpLedmWalkupScanToCompManifest !== undefined) {
34
34
  return hpLedmWalkupScanToCompManifest["ledm:ManifestURI"][0];
package/src/Event.ts CHANGED
@@ -28,9 +28,9 @@ export default class Event {
28
28
  }
29
29
 
30
30
  get destinationURI(): string | undefined {
31
- if (this.data.hasOwnProperty("ev:Payload")) {
31
+ if (Object.prototype.hasOwnProperty.call(this.data, "ev:Payload")) {
32
32
  const destination = this.data["ev:Payload"].find((v) =>
33
- v["dd:ResourceType"]["0"].includes("Destination")
33
+ v["dd:ResourceType"]["0"].includes("Destination"),
34
34
  );
35
35
 
36
36
  return destination ? destination["dd:ResourceURI"]["0"] : undefined;
@@ -39,9 +39,9 @@ export default class Event {
39
39
  }
40
40
 
41
41
  get compEventURI(): string | undefined {
42
- if (this.data.hasOwnProperty("ev:Payload")) {
42
+ if (Object.prototype.hasOwnProperty.call(this.data, "ev:Payload")) {
43
43
  const compEvent = this.data["ev:Payload"].find((v) =>
44
- v["dd:ResourceType"]["0"].includes("CompEvent")
44
+ v["dd:ResourceType"]["0"].includes("CompEvent"),
45
45
  );
46
46
 
47
47
  return compEvent ? compEvent["dd:ResourceURI"]["0"] : undefined;
package/src/EventTable.ts CHANGED
@@ -25,7 +25,7 @@ export default class EventTable {
25
25
 
26
26
  static async createEtagEventTable(
27
27
  content: string,
28
- etagReceived: string
28
+ etagReceived: string,
29
29
  ): Promise<EtagEventTable> {
30
30
  const parsed = await parseString(content);
31
31
  return {
package/src/HPApi.ts CHANGED
@@ -46,7 +46,7 @@ export default class HPApi {
46
46
  private static logDebug(
47
47
  callId: number,
48
48
  isRequest: boolean,
49
- msg: object | string
49
+ msg: object | string,
50
50
  ): void {
51
51
  if (debug) {
52
52
  const id = String(callId).padStart(4, "0");
@@ -56,7 +56,7 @@ export default class HPApi {
56
56
  }
57
57
 
58
58
  private static async callAxios(
59
- request: AxiosRequestConfig
59
+ request: AxiosRequestConfig,
60
60
  ): Promise<AxiosResponse<string>> {
61
61
  callCount++;
62
62
  if (request.timeout === 0) {
@@ -111,7 +111,7 @@ export default class HPApi {
111
111
  while (!(await HPApi.isAlive())) {
112
112
  if (first) {
113
113
  console.log(
114
- `Device ip: ${printerIP} is down! [${new Date().toISOString()}]`
114
+ `Device ip: ${printerIP} is down! [${new Date().toISOString()}]`,
115
115
  );
116
116
  }
117
117
  first = false;
@@ -119,7 +119,7 @@ export default class HPApi {
119
119
  }
120
120
  if (!first) {
121
121
  console.log(
122
- `Device ip: ${printerIP} is up again! [${new Date().toISOString()}]`
122
+ `Device ip: ${printerIP} is up again! [${new Date().toISOString()}]`,
123
123
  );
124
124
  }
125
125
  }
@@ -140,7 +140,7 @@ export default class HPApi {
140
140
  }
141
141
 
142
142
  static async getWalkupScanDestinations(
143
- uri: string = "/WalkupScan/WalkupScanDestinations"
143
+ uri: string = "/WalkupScan/WalkupScanDestinations",
144
144
  ): Promise<WalkupScanDestinations> {
145
145
  const response = await HPApi.callAxios({
146
146
  baseURL: `http://${printerIP}`,
@@ -168,7 +168,7 @@ export default class HPApi {
168
168
  throw new Error(response.statusText);
169
169
  } else {
170
170
  return WalkupScanToCompDestinations.createWalkupScanToCompDestinations(
171
- response.data
171
+ response.data,
172
172
  );
173
173
  }
174
174
  }
@@ -188,7 +188,7 @@ export default class HPApi {
188
188
  }
189
189
  }
190
190
  static async getWalkupScanToCompManifest(
191
- uri: string
191
+ uri: string,
192
192
  ): Promise<WalkupScanToCompManifest> {
193
193
  const response = await HPApi.callAxios({
194
194
  baseURL: `http://${printerIP}`,
@@ -201,7 +201,7 @@ export default class HPApi {
201
201
  throw new Error(response.statusText);
202
202
  } else {
203
203
  return WalkupScanToCompManifest.createWalkupScanToCompManifest(
204
- response.data
204
+ response.data,
205
205
  );
206
206
  }
207
207
  }
@@ -237,7 +237,7 @@ export default class HPApi {
237
237
  }
238
238
 
239
239
  static async getWalkupScanToCompCaps(
240
- uri: string
240
+ uri: string,
241
241
  ): Promise<WalkupScanToCompCaps> {
242
242
  const response = await HPApi.callAxios({
243
243
  baseURL: `http://${printerIP}`,
@@ -254,7 +254,7 @@ export default class HPApi {
254
254
  }
255
255
 
256
256
  static async getWalkupScanToCompEvent(
257
- compEventURI: string
257
+ compEventURI: string,
258
258
  ): Promise<WalkupScanToCompEvent> {
259
259
  const response = await HPApi.callAxios({
260
260
  baseURL: `http://${printerIP}`,
@@ -271,7 +271,7 @@ export default class HPApi {
271
271
  }
272
272
 
273
273
  static async removeDestination(
274
- walkupScanDestination: WalkupScanDestination | WalkupScanToCompDestination
274
+ walkupScanDestination: WalkupScanDestination | WalkupScanToCompDestination,
275
275
  ): Promise<boolean> {
276
276
  let path: string;
277
277
 
@@ -279,7 +279,7 @@ export default class HPApi {
279
279
  let urlInfo = new URL(walkupScanDestination.resourceURI);
280
280
  if (urlInfo.pathname === null) {
281
281
  throw new Error(
282
- `invalid walkupScanDestination.resourceURI: ${walkupScanDestination.resourceURI}`
282
+ `invalid walkupScanDestination.resourceURI: ${walkupScanDestination.resourceURI}`,
283
283
  );
284
284
  }
285
285
  path = urlInfo.pathname;
@@ -301,7 +301,7 @@ export default class HPApi {
301
301
  }
302
302
 
303
303
  static async registerWalkupScanDestination(
304
- destination: Destination
304
+ destination: Destination,
305
305
  ): Promise<string> {
306
306
  const xml = await destination.toXML();
307
307
  const url = "/WalkupScan/WalkupScanDestinations";
@@ -321,7 +321,7 @@ export default class HPApi {
321
321
  }
322
322
  }
323
323
  static async registerWalkupScanToCompDestination(
324
- destination: Destination
324
+ destination: Destination,
325
325
  ): Promise<string> {
326
326
  const xml = await destination.toXML();
327
327
  const url = "/WalkupScanToComp/WalkupScanToCompDestinations";
@@ -343,7 +343,7 @@ export default class HPApi {
343
343
 
344
344
  static async getEvents(
345
345
  etag = "",
346
- decisecondTimeout = 0
346
+ decisecondTimeout = 0,
347
347
  ): Promise<EtagEventTable> {
348
348
  let url = this.appendTimeout("/EventMgmt/EventTable", decisecondTimeout);
349
349
 
@@ -384,7 +384,7 @@ export default class HPApi {
384
384
 
385
385
  static placeETagHeader(
386
386
  etag: string,
387
- headers: RawAxiosRequestHeaders
387
+ headers: RawAxiosRequestHeaders,
388
388
  ): RawAxiosRequestHeaders {
389
389
  if (etag !== "") {
390
390
  headers["If-None-Match"] = etag;
@@ -403,7 +403,7 @@ export default class HPApi {
403
403
  }
404
404
 
405
405
  static async getDestination(
406
- destinationURL: string
406
+ destinationURL: string,
407
407
  ): Promise<WalkupScanDestination | WalkupScanToCompDestination> {
408
408
  const response = await HPApi.callAxios({
409
409
  baseURL: `http://${printerIP}`,
@@ -418,7 +418,7 @@ export default class HPApi {
418
418
  const content = response.data;
419
419
  if (destinationURL.includes("WalkupScanToComp")) {
420
420
  return WalkupScanToCompDestination.createWalkupScanToCompDestination(
421
- content
421
+ content,
422
422
  );
423
423
  } else {
424
424
  return WalkupScanDestination.createWalkupScanDestination(content);
@@ -488,7 +488,7 @@ export default class HPApi {
488
488
 
489
489
  static async downloadPage(
490
490
  binaryURL: string,
491
- destination: string
491
+ destination: string,
492
492
  ): Promise<string> {
493
493
  const { data }: AxiosResponse<Stream> = await axios.request<Stream>({
494
494
  baseURL: `http://${printerIP}:8080`,
@@ -0,0 +1,4 @@
1
+ export enum InputSource {
2
+ Adf = "Adf",
3
+ Platen = "Platen",
4
+ }
package/src/Job.ts CHANGED
@@ -15,6 +15,8 @@ export interface JobData {
15
15
  ImageWidth: string[];
16
16
  ImageHeight: string[];
17
17
  ScanSettings: {
18
+ InputSource: string[];
19
+ ContentType: string[];
18
20
  XResolution: string[];
19
21
  YResolution: string[];
20
22
  }[];
@@ -52,7 +54,7 @@ export default class Job {
52
54
  if (this.data["j:Job"].ScanJob[0].PostScanPage) {
53
55
  return parseInt(
54
56
  this.data["j:Job"].ScanJob[0].PostScanPage[0].PageNumber[0],
55
- 10
57
+ 10,
56
58
  );
57
59
  }
58
60
  return null;
@@ -84,19 +86,24 @@ export default class Job {
84
86
  }
85
87
 
86
88
  get imageWidth(): number | null {
87
- if (!this.data["j:Job"].ScanJob[0].hasOwnProperty("PreScanPage")) {
89
+ if (
90
+ !Object.prototype.hasOwnProperty.call(
91
+ this.data["j:Job"].ScanJob[0],
92
+ "PreScanPage",
93
+ )
94
+ ) {
88
95
  return null;
89
96
  }
90
97
  return parseInt(
91
98
  this.data["j:Job"].ScanJob[0].PreScanPage?.[0]?.BufferInfo?.[0]
92
- ?.ImageWidth[0] ?? ""
99
+ ?.ImageWidth[0] ?? "",
93
100
  );
94
101
  }
95
102
  get imageHeight(): number | null {
96
103
  if (this.data["j:Job"].ScanJob[0].PreScanPage) {
97
104
  return parseInt(
98
105
  this.data["j:Job"].ScanJob[0].PreScanPage[0].BufferInfo[0]
99
- .ImageHeight[0]
106
+ .ImageHeight[0],
100
107
  );
101
108
  }
102
109
  return null;
@@ -105,16 +112,21 @@ export default class Job {
105
112
  if (this.data["j:Job"].ScanJob[0].PreScanPage) {
106
113
  return parseInt(
107
114
  this.data["j:Job"].ScanJob[0].PreScanPage?.[0]?.BufferInfo?.[0]
108
- ?.ScanSettings?.[0]?.XResolution[0] ?? ""
115
+ ?.ScanSettings?.[0]?.XResolution[0] ?? "",
109
116
  );
110
117
  }
111
118
  return null;
112
119
  }
113
120
  get yResolution(): number | null {
114
- if (this.data["j:Job"].ScanJob[0].hasOwnProperty("PreScanPage")) {
121
+ if (
122
+ Object.prototype.hasOwnProperty.call(
123
+ this.data["j:Job"].ScanJob[0],
124
+ "PreScanPage",
125
+ )
126
+ ) {
115
127
  return parseInt(
116
128
  this.data["j:Job"].ScanJob[0].PreScanPage?.[0]?.BufferInfo?.[0]
117
- ?.ScanSettings?.[0]?.YResolution[0] ?? ""
129
+ ?.ScanSettings?.[0]?.YResolution[0] ?? "",
118
130
  );
119
131
  }
120
132
  return null;
package/src/JpegUtil.ts CHANGED
@@ -39,7 +39,7 @@ export default class JpegUtil {
39
39
 
40
40
  static setJpgSize(
41
41
  buffer: Buffer,
42
- size: { height: number; width: number }
42
+ size: { height: number; width: number },
43
43
  ): boolean {
44
44
  let sizeWritten = false;
45
45
  const parsingSucceed = this.parse(buffer, {
@@ -77,14 +77,14 @@ export default class JpegUtil {
77
77
  let heightWritten = false;
78
78
  const parsingSucceed = this.parse(buffer, {
79
79
  [start_of_Frame_0]: (start: number, length: number) => {
80
- // read the the "Start of frame" marker which contains the file size
80
+ // read the "Start of frame" marker which contains the file size
81
81
 
82
82
  // write the picture size
83
83
  heightWritten = this.writeHeightInStartOfFrame(
84
84
  buffer,
85
85
  start,
86
86
  length,
87
- height
87
+ height,
88
88
  );
89
89
 
90
90
  // stop processing
@@ -122,7 +122,7 @@ export default class JpegUtil {
122
122
 
123
123
  if (startOfStartOfFrame == null || lengthOfStartOfFrame == null) {
124
124
  this.logDebug(
125
- "Start of frame 0 not found, either jpeg parsing is broken either the stream is corrupted"
125
+ "Start of frame 0 not found, either jpeg parsing is broken either the stream is corrupted",
126
126
  );
127
127
  return null;
128
128
  }
@@ -132,7 +132,7 @@ export default class JpegUtil {
132
132
  buffer,
133
133
  startOfStartOfFrame,
134
134
  lengthOfStartOfFrame,
135
- numberOfLine
135
+ numberOfLine,
136
136
  )
137
137
  ) {
138
138
  return numberOfLine;
@@ -144,7 +144,7 @@ export default class JpegUtil {
144
144
  buffer: Buffer,
145
145
  startOfStartOfFrame: number,
146
146
  lengthOfStartOfFrame: number,
147
- numberOfLine: number
147
+ numberOfLine: number,
148
148
  ): boolean {
149
149
  // write the picture height
150
150
  if (6 < lengthOfStartOfFrame) {
@@ -162,7 +162,7 @@ export default class JpegUtil {
162
162
  static readNumberOfLineFromDNL(
163
163
  buffer: Buffer,
164
164
  start: number,
165
- length: number
165
+ length: number,
166
166
  ): number | null {
167
167
  let numberOfLine: number | null = null;
168
168
 
@@ -175,7 +175,9 @@ export default class JpegUtil {
175
175
  }
176
176
  static parse(
177
177
  buffer: Buffer,
178
- markerHandler: { [key: string]: (start: number, length: number) => boolean }
178
+ markerHandler: {
179
+ [key: string]: (start: number, length: number) => boolean;
180
+ },
179
181
  ): boolean {
180
182
  let i: number = 0;
181
183
 
@@ -219,7 +221,7 @@ export default class JpegUtil {
219
221
  private static getBlockLength(
220
222
  buffer: Buffer,
221
223
  i: number,
222
- marker: string
224
+ marker: string,
223
225
  ): number | null {
224
226
  if (
225
227
  marker === "FFDA" ||
@@ -245,7 +247,7 @@ export default class JpegUtil {
245
247
  private static findCurrentBlockSize(
246
248
  buffer: Buffer,
247
249
  i: number,
248
- current_marker: string
250
+ current_marker: string,
249
251
  ): number | null {
250
252
  for (let j = 0; i + j < buffer.length; j++) {
251
253
  if (buffer[i + j] === 0xff) {
@@ -258,7 +260,7 @@ export default class JpegUtil {
258
260
  }
259
261
  } else {
260
262
  this.logDebug(
261
- `Premature end of stream reach while searching for the block size inside marker ${current_marker}`
263
+ `Premature end of stream reach while searching for the block size inside marker ${current_marker}`,
262
264
  );
263
265
  return null;
264
266
  }
@@ -270,7 +272,9 @@ export default class JpegUtil {
270
272
  private static parseMarker(
271
273
  buffer: Buffer,
272
274
  i: number,
273
- markerHandler: { [key: string]: (start: number, length: number) => boolean }
275
+ markerHandler: {
276
+ [key: string]: (start: number, length: number) => boolean;
277
+ },
274
278
  ): boolean {
275
279
  let marker = "";
276
280
 
@@ -283,7 +287,7 @@ export default class JpegUtil {
283
287
  if (buffer[i] != 0xff) {
284
288
  this.logDebug(
285
289
  "We should be at the begining of the next block, but got: " +
286
- buffer[i]
290
+ buffer[i],
287
291
  );
288
292
  return false;
289
293
  }
@@ -303,7 +307,7 @@ export default class JpegUtil {
303
307
  const foundBlockLength = this.getBlockLength(buffer, i, marker);
304
308
  if (foundBlockLength == null) {
305
309
  this.logDebug(
306
- `Was not able to determine block size for marker ${marker}`
310
+ `Was not able to determine block size for marker ${marker}`,
307
311
  );
308
312
  return false;
309
313
  }
package/src/PathHelper.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from "path";
2
2
  import dateformat from "dateformat";
3
- const { promises: Fs } = require("fs");
4
- const fs = require("fs");
5
3
  import os from "os";
4
+ import { promises as Fs } from "fs";
5
+ import fs from "fs";
6
6
 
7
7
  export default class PathHelper {
8
8
  static getFileForPage(
@@ -10,30 +10,60 @@ export default class PathHelper {
10
10
  scanCount: number,
11
11
  currentPageNumber: number,
12
12
  filePattern: string | undefined,
13
- extension: string
13
+ extension: string,
14
+ date: Date,
14
15
  ): string {
15
16
  if (filePattern) {
16
- return path.join(
17
- folder,
18
- `${dateformat(new Date(), filePattern)}.${extension}`
19
- );
17
+ return path.join(folder, `${dateformat(date, filePattern)}.${extension}`);
20
18
  }
21
19
 
22
- return path.join(
23
- folder,
24
- `scan${scanCount}_page${currentPageNumber}.${extension}`
20
+ return this.makeUnique(
21
+ path.join(
22
+ folder,
23
+ `scan${scanCount}_page${currentPageNumber}.${extension}`,
24
+ ),
25
+ date,
26
+ );
27
+ }
28
+
29
+ static async getNextScanNumber(
30
+ folder: string,
31
+ currentScanCount: number,
32
+ filePattern: string | undefined,
33
+ ): Promise<number> {
34
+ if (filePattern) {
35
+ return currentScanCount++;
36
+ }
37
+ const files = await Fs.readdir(folder);
38
+ for (let i = currentScanCount + 1; i < Number.MAX_SAFE_INTEGER; i++) {
39
+ const currentScanCountProbe = `scan${i}`;
40
+ if (
41
+ !(
42
+ files.some((x) => x.startsWith(currentScanCountProbe)) &&
43
+ files.some(
44
+ (x) =>
45
+ x.startsWith(currentScanCountProbe + "_") ||
46
+ files.some((x) => x.startsWith(currentScanCountProbe + ".")),
47
+ )
48
+ )
49
+ ) {
50
+ return i;
51
+ }
52
+ }
53
+ return Promise.reject(
54
+ `Unable to find the valid scan number in folder ${folder}`,
25
55
  );
26
56
  }
27
57
 
28
- static makeUnique(filePath: string): string {
58
+ static makeUnique(filePath: string, date: Date): string {
29
59
  if (!fs.existsSync(filePath)) {
30
60
  return filePath;
31
61
  }
32
62
 
33
63
  let parsed = path.parse(filePath);
34
- let tryName = `${parsed.dir}${path.sep}${parsed.name}${dateformat(
35
- new Date(),
36
- "yyyymmdd"
64
+ let tryName = `${parsed.dir}${path.sep}${parsed.name}_${dateformat(
65
+ date,
66
+ "yyyymmdd",
37
67
  )}${parsed.ext}`;
38
68
  if (!fs.existsSync(tryName)) {
39
69
  return tryName;
@@ -49,7 +79,7 @@ export default class PathHelper {
49
79
  i = String.fromCharCode(i.charCodeAt(0) + 1);
50
80
  }
51
81
  throw new Error(
52
- `Can not create unique file: ${filePath} iterated until: ${tryName}`
82
+ `Can not create unique file: ${filePath} iterated until: ${tryName}`,
53
83
  );
54
84
  }
55
85
 
@@ -57,13 +87,11 @@ export default class PathHelper {
57
87
  folder: string,
58
88
  scanCount: number,
59
89
  filePattern: string | undefined,
60
- extension: string
90
+ extension: string,
91
+ date: Date,
61
92
  ): string {
62
93
  if (filePattern) {
63
- return path.join(
64
- folder,
65
- `${dateformat(new Date(), filePattern)}.${extension}`
66
- );
94
+ return path.join(folder, `${dateformat(date, filePattern)}.${extension}`);
67
95
  }
68
96
 
69
97
  return path.join(folder, `scan${scanCount}.${extension}`);
package/src/ScanCaps.ts CHANGED
@@ -3,7 +3,23 @@ import { Parser } from "xml2js";
3
3
  const parser = new Parser();
4
4
  import { promisify } from "util";
5
5
  const parseString = promisify<string, ScanCapsData>(parser.parseString);
6
- export interface ScanCapsData {}
6
+
7
+ export interface ScanCapsData {
8
+ ScanCaps: {
9
+ Platen: {
10
+ InputSourceCaps: {
11
+ MaxWidth: number;
12
+ MaxHeight: number;
13
+ }[];
14
+ }[];
15
+ Adf: {
16
+ InputSourceCaps: {
17
+ MaxWidth: number;
18
+ MaxHeight: number;
19
+ }[];
20
+ }[];
21
+ };
22
+ }
7
23
 
8
24
  export default class ScanCaps {
9
25
  private readonly data: ScanCapsData;
@@ -16,4 +32,30 @@ export default class ScanCaps {
16
32
  const parsed = await parseString(content);
17
33
  return new ScanCaps(parsed);
18
34
  }
35
+
36
+ get PlatenMaxWidth(): number | null {
37
+ return (
38
+ this.data["ScanCaps"]["Platen"][0]["InputSourceCaps"][0]["MaxWidth"] ||
39
+ null
40
+ );
41
+ }
42
+
43
+ get PlatenMaxHeight(): number | null {
44
+ return (
45
+ this.data["ScanCaps"]["Platen"][0]["InputSourceCaps"][0]["MaxHeight"] ||
46
+ null
47
+ );
48
+ }
49
+
50
+ get AdfMaxWidth(): number | null {
51
+ return (
52
+ this.data["ScanCaps"]["Adf"][0]["InputSourceCaps"][0]["MaxWidth"] || null
53
+ );
54
+ }
55
+
56
+ get AdfMaxHeight(): number | null {
57
+ return (
58
+ this.data["ScanCaps"]["Adf"][0]["InputSourceCaps"][0]["MaxHeight"] || null
59
+ );
60
+ }
19
61
  }
@@ -16,7 +16,7 @@ export interface ScanPage {
16
16
 
17
17
  export async function createPdfFrom(
18
18
  scanContent: ScanContent,
19
- destination: string
19
+ destination: string,
20
20
  ) {
21
21
  let doc: jsPDF | null = null;
22
22
  for (const element of scanContent.elements) {
@@ -29,7 +29,7 @@ export default class ScanJobManifest {
29
29
  this.data = data;
30
30
  }
31
31
  static async createScanJobManifest(
32
- content: string
32
+ content: string,
33
33
  ): Promise<ScanJobManifest> {
34
34
  const parsed = await parseString(content);
35
35
  return new ScanJobManifest(parsed);
@@ -39,7 +39,8 @@ export default class ScanJobManifest {
39
39
  const scanCaps = this.data["man:Manifest"]["map:ResourceMap"]["0"][
40
40
  "map:ResourceNode"
41
41
  ].find(
42
- (x) => x["map:ResourceType"][0]["scan:ScanResourceType"][0] === "ScanCaps"
42
+ (x) =>
43
+ x["map:ResourceType"][0]["scan:ScanResourceType"][0] === "ScanCaps",
43
44
  );
44
45
 
45
46
  if (scanCaps === undefined) {