@capturebridge/sdk 0.7.0 → 0.7.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/Camera.js +68 -68
- package/CanonCamera.js +25 -25
- package/CaptureBridge.js +162 -162
- package/CapturePlugin.js +79 -79
- package/Common.js +98 -98
- package/Device.js +451 -451
- package/ICAO.js +70 -70
- package/IFace.js +274 -274
- package/Logs.js +129 -129
- package/MockCamera.js +10 -10
- package/Plugin.js +298 -298
- package/Scanner.js +64 -64
- package/SignatureTablet.js +109 -109
- package/SignatureTabletWidgets.js +153 -153
- package/StreamingCapturePlugin.js +121 -121
- package/TopazSigGem.js +25 -25
- package/package.json +1 -1
package/Logs.js
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import { BASE_URL } from './Common.js'
|
|
2
|
-
|
|
3
|
-
export const TRACE = 10
|
|
4
|
-
export const DEBUG = 20
|
|
5
|
-
export const INFO = 30
|
|
6
|
-
export const WARN = 40
|
|
7
|
-
export const ERROR = 50
|
|
8
|
-
export const FATAL = 60
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @constant
|
|
12
|
-
* @type {Object.<string, number>}
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export const LOG_LEVELS = {
|
|
16
|
-
trace: TRACE,
|
|
17
|
-
debug: DEBUG,
|
|
18
|
-
info: INFO,
|
|
19
|
-
warn: WARN,
|
|
20
|
-
error: ERROR,
|
|
21
|
-
fatal: FATAL
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @classdesc Plugins write
|
|
26
|
-
* {@link https://github.com/trentm/node-bunyan?tab=readme-ov-file#log-record-fields|Bunyan}
|
|
27
|
-
* formated logs to separate log files. This class provides
|
|
28
|
-
* utilities for viewing and following those logs as they're written.
|
|
29
|
-
*/
|
|
30
|
-
export class Logs {
|
|
31
|
-
baseUrl
|
|
32
|
-
#reader
|
|
33
|
-
#controller
|
|
34
|
-
/**
|
|
35
|
-
* Instantiate a Log Object
|
|
36
|
-
* @constructor
|
|
37
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
38
|
-
*/
|
|
39
|
-
constructor (baseUrl = BASE_URL) {
|
|
40
|
-
this.baseUrl = baseUrl
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* End the log stream and stop following logs.
|
|
45
|
-
*/
|
|
46
|
-
end () {
|
|
47
|
-
this.#reader?.cancel()
|
|
48
|
-
this.#controller?.abort()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Add a handler for following logs. Note that each invocation of this method
|
|
53
|
-
* opens a connection to the server and holds it open. Web browsers limit the
|
|
54
|
-
* number of connections to a single domain. Avoid using this method more than
|
|
55
|
-
* once per client.
|
|
56
|
-
* @param {string[]} plugins - Follow logs for the provided Plugin IDs.
|
|
57
|
-
* @param {string|number} level - Log Level.
|
|
58
|
-
* @param {function} callback - Invoked with two arguments. The first argument
|
|
59
|
-
* is an Error object (if an error occurred) or null. The second argument is
|
|
60
|
-
* an log object.
|
|
61
|
-
*/
|
|
62
|
-
follow (plugins, level, callback) {
|
|
63
|
-
let pluginList
|
|
64
|
-
if (typeof plugins === 'object' && plugins.length > 0) {
|
|
65
|
-
pluginList = plugins.join(',')
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error('Invalid value provided for plugins argument')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const logLevel = (typeof level === 'number') ? level : LOG_LEVELS[level]
|
|
71
|
-
|
|
72
|
-
if (!logLevel) {
|
|
73
|
-
throw new Error('Invalid value provided for log level argument')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (typeof callback !== 'function') {
|
|
77
|
-
throw new Error('Invalid value provided for callback argument')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const url = `${this.baseUrl}/plugin/logs/follow?plugins=${pluginList}&level=${logLevel}`
|
|
81
|
-
|
|
82
|
-
this.#controller = new AbortController()
|
|
83
|
-
const signal = this.#controller.signal
|
|
84
|
-
|
|
85
|
-
fetch(url, { signal })
|
|
86
|
-
.then(({ body }) => {
|
|
87
|
-
let buffer = ''
|
|
88
|
-
if (!body) {
|
|
89
|
-
return callback(new Error('No response body'))
|
|
90
|
-
}
|
|
91
|
-
const readData = data => {
|
|
92
|
-
if (!data.done) {
|
|
93
|
-
callback(null, data.value)
|
|
94
|
-
this.#reader.read().then(readData).catch(e => callback(e))
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this.#reader = body
|
|
98
|
-
.pipeThrough(new TextDecoderStream())
|
|
99
|
-
.pipeThrough(new TransformStream({
|
|
100
|
-
transform (chunk, controller) {
|
|
101
|
-
buffer += chunk
|
|
102
|
-
const parts = buffer.split('\n')
|
|
103
|
-
parts.slice(0, -1).forEach(part => controller.enqueue(part))
|
|
104
|
-
buffer = parts[parts.length - 1]
|
|
105
|
-
},
|
|
106
|
-
flush (controller) {
|
|
107
|
-
if (buffer) {
|
|
108
|
-
controller.enqueue(buffer)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}))
|
|
112
|
-
.pipeThrough(new TransformStream({
|
|
113
|
-
transform (chunk, controller) {
|
|
114
|
-
controller.enqueue(JSON.parse(chunk))
|
|
115
|
-
}
|
|
116
|
-
}))
|
|
117
|
-
.getReader()
|
|
118
|
-
this.#reader
|
|
119
|
-
.read()
|
|
120
|
-
.then(readData)
|
|
121
|
-
.catch(e => callback(e))
|
|
122
|
-
}).catch(e => {
|
|
123
|
-
// Don't emit an error when aborting the fetch operation
|
|
124
|
-
if (e.name !== 'AbortError') {
|
|
125
|
-
callback(e)
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
}
|
|
1
|
+
import { BASE_URL } from './Common.js'
|
|
2
|
+
|
|
3
|
+
export const TRACE = 10
|
|
4
|
+
export const DEBUG = 20
|
|
5
|
+
export const INFO = 30
|
|
6
|
+
export const WARN = 40
|
|
7
|
+
export const ERROR = 50
|
|
8
|
+
export const FATAL = 60
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @constant
|
|
12
|
+
* @type {Object.<string, number>}
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export const LOG_LEVELS = {
|
|
16
|
+
trace: TRACE,
|
|
17
|
+
debug: DEBUG,
|
|
18
|
+
info: INFO,
|
|
19
|
+
warn: WARN,
|
|
20
|
+
error: ERROR,
|
|
21
|
+
fatal: FATAL
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @classdesc Plugins write
|
|
26
|
+
* {@link https://github.com/trentm/node-bunyan?tab=readme-ov-file#log-record-fields|Bunyan}
|
|
27
|
+
* formated logs to separate log files. This class provides
|
|
28
|
+
* utilities for viewing and following those logs as they're written.
|
|
29
|
+
*/
|
|
30
|
+
export class Logs {
|
|
31
|
+
baseUrl
|
|
32
|
+
#reader
|
|
33
|
+
#controller
|
|
34
|
+
/**
|
|
35
|
+
* Instantiate a Log Object
|
|
36
|
+
* @constructor
|
|
37
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
38
|
+
*/
|
|
39
|
+
constructor (baseUrl = BASE_URL) {
|
|
40
|
+
this.baseUrl = baseUrl
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* End the log stream and stop following logs.
|
|
45
|
+
*/
|
|
46
|
+
end () {
|
|
47
|
+
this.#reader?.cancel()
|
|
48
|
+
this.#controller?.abort()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Add a handler for following logs. Note that each invocation of this method
|
|
53
|
+
* opens a connection to the server and holds it open. Web browsers limit the
|
|
54
|
+
* number of connections to a single domain. Avoid using this method more than
|
|
55
|
+
* once per client.
|
|
56
|
+
* @param {string[]} plugins - Follow logs for the provided Plugin IDs.
|
|
57
|
+
* @param {string|number} level - Log Level.
|
|
58
|
+
* @param {function} callback - Invoked with two arguments. The first argument
|
|
59
|
+
* is an Error object (if an error occurred) or null. The second argument is
|
|
60
|
+
* an log object.
|
|
61
|
+
*/
|
|
62
|
+
follow (plugins, level, callback) {
|
|
63
|
+
let pluginList
|
|
64
|
+
if (typeof plugins === 'object' && plugins.length > 0) {
|
|
65
|
+
pluginList = plugins.join(',')
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error('Invalid value provided for plugins argument')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const logLevel = (typeof level === 'number') ? level : LOG_LEVELS[level]
|
|
71
|
+
|
|
72
|
+
if (!logLevel) {
|
|
73
|
+
throw new Error('Invalid value provided for log level argument')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof callback !== 'function') {
|
|
77
|
+
throw new Error('Invalid value provided for callback argument')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const url = `${this.baseUrl}/plugin/logs/follow?plugins=${pluginList}&level=${logLevel}`
|
|
81
|
+
|
|
82
|
+
this.#controller = new AbortController()
|
|
83
|
+
const signal = this.#controller.signal
|
|
84
|
+
|
|
85
|
+
fetch(url, { signal })
|
|
86
|
+
.then(({ body }) => {
|
|
87
|
+
let buffer = ''
|
|
88
|
+
if (!body) {
|
|
89
|
+
return callback(new Error('No response body'))
|
|
90
|
+
}
|
|
91
|
+
const readData = data => {
|
|
92
|
+
if (!data.done) {
|
|
93
|
+
callback(null, data.value)
|
|
94
|
+
this.#reader.read().then(readData).catch(e => callback(e))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.#reader = body
|
|
98
|
+
.pipeThrough(new TextDecoderStream())
|
|
99
|
+
.pipeThrough(new TransformStream({
|
|
100
|
+
transform (chunk, controller) {
|
|
101
|
+
buffer += chunk
|
|
102
|
+
const parts = buffer.split('\n')
|
|
103
|
+
parts.slice(0, -1).forEach(part => controller.enqueue(part))
|
|
104
|
+
buffer = parts[parts.length - 1]
|
|
105
|
+
},
|
|
106
|
+
flush (controller) {
|
|
107
|
+
if (buffer) {
|
|
108
|
+
controller.enqueue(buffer)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}))
|
|
112
|
+
.pipeThrough(new TransformStream({
|
|
113
|
+
transform (chunk, controller) {
|
|
114
|
+
controller.enqueue(JSON.parse(chunk))
|
|
115
|
+
}
|
|
116
|
+
}))
|
|
117
|
+
.getReader()
|
|
118
|
+
this.#reader
|
|
119
|
+
.read()
|
|
120
|
+
.then(readData)
|
|
121
|
+
.catch(e => callback(e))
|
|
122
|
+
}).catch(e => {
|
|
123
|
+
// Don't emit an error when aborting the fetch operation
|
|
124
|
+
if (e.name !== 'AbortError') {
|
|
125
|
+
callback(e)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
package/MockCamera.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Camera from './Camera.js'
|
|
2
|
-
import { BASE_URL } from './Common.js'
|
|
3
|
-
|
|
4
|
-
class MockCamera extends Camera {
|
|
5
|
-
constructor (baseUrl = BASE_URL) {
|
|
6
|
-
super('capture_camera_mock', baseUrl)
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default MockCamera
|
|
1
|
+
import Camera from './Camera.js'
|
|
2
|
+
import { BASE_URL } from './Common.js'
|
|
3
|
+
|
|
4
|
+
class MockCamera extends Camera {
|
|
5
|
+
constructor (baseUrl = BASE_URL) {
|
|
6
|
+
super('capture_camera_mock', baseUrl)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default MockCamera
|