@cleverence/edge-js-sdk 1.0.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.
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Minimal typed event emitter for browser environments
3
+ */
4
+ type EventHandler<T = unknown> = (data: T) => void;
5
+ declare class EventEmitter<Events extends Record<string, any> = Record<string, unknown>> {
6
+ private handlers;
7
+ /**
8
+ * Subscribe to an event
9
+ */
10
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
11
+ /**
12
+ * Subscribe to an event once (auto-unsubscribes after first call)
13
+ */
14
+ once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
15
+ /**
16
+ * Unsubscribe from an event
17
+ */
18
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
19
+ /**
20
+ * Emit an event to all subscribers
21
+ */
22
+ protected emit<K extends keyof Events>(event: K, data: Events[K]): void;
23
+ /**
24
+ * Remove all listeners for an event, or all listeners if no event specified
25
+ */
26
+ removeAllListeners(event?: keyof Events): this;
27
+ /**
28
+ * Get listener count for an event
29
+ */
30
+ listenerCount(event: keyof Events): number;
31
+ }
32
+
33
+ /**
34
+ * Barcode scan event - simplified API surface for easy consumption
35
+ */
36
+ interface ScanEvent {
37
+ /** Event type discriminator */
38
+ type: 'scan';
39
+ /** Unique event identifier */
40
+ id: string;
41
+ /** When the scan occurred */
42
+ timestamp: Date;
43
+ /** Decoded barcode data string */
44
+ data: string;
45
+ /** Human-readable symbology name: "ean13", "qrcode", "code128", etc. */
46
+ symbology: string;
47
+ /** Scanner source: "integrated-laser", "camera", "bluetooth-ring" */
48
+ source: string;
49
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic" */
50
+ vendor: string;
51
+ /** Extended raw data (optional, for advanced use cases) */
52
+ raw?: {
53
+ /** Raw barcode bytes as hex string */
54
+ bytesHex: string;
55
+ /** Vendor-specific symbology identifier */
56
+ symbologyId: string;
57
+ /** AIM identifier for the symbology */
58
+ aimId: string;
59
+ /** Signal strength if available */
60
+ signalStrength: number | null;
61
+ /** How long the scan took in milliseconds */
62
+ scanDurationMs: number;
63
+ };
64
+ }
65
+ /**
66
+ * RFID read event - simplified API surface for easy consumption
67
+ */
68
+ interface RfidEvent {
69
+ /** Event type discriminator */
70
+ type: 'rfid';
71
+ /** Unique event identifier */
72
+ id: string;
73
+ /** When the read occurred */
74
+ timestamp: Date;
75
+ /** EPC (Electronic Product Code) tag identifier */
76
+ epc: string;
77
+ /** Received Signal Strength Indicator in dBm */
78
+ rssi: number;
79
+ /** Antenna port number that read the tag */
80
+ antenna: number;
81
+ /** Tag Identifier (TID) memory bank data */
82
+ tid?: string | null;
83
+ /** User memory bank data */
84
+ userData?: string | null;
85
+ /** RF phase angle */
86
+ phase?: number;
87
+ /** RF channel frequency */
88
+ channel?: number;
89
+ /** Number of times this tag was read in current inventory */
90
+ readCount?: number;
91
+ /** Protocol Control (PC) bits */
92
+ pc?: string;
93
+ /** CRC checksum */
94
+ crc?: string;
95
+ /** Inventory session identifier */
96
+ inventorySession?: string;
97
+ /** Transmit power used for this read in dBm */
98
+ transmitPowerDbm?: number;
99
+ }
100
+ /**
101
+ * Union type for all events
102
+ */
103
+ type EdgeEvent = ScanEvent | RfidEvent;
104
+
105
+ /**
106
+ * Device capabilities reported by the Edge service on connection
107
+ */
108
+ interface DeviceCapabilities {
109
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic", etc. */
110
+ vendor: string;
111
+ /** Device model name */
112
+ deviceModel: string;
113
+ /** Whether device has barcode scanning capability */
114
+ hasBarcode: boolean;
115
+ /** Whether device has RFID reading capability */
116
+ hasRfid: boolean;
117
+ /** List of supported barcode symbologies */
118
+ supportedSymbologies: string[];
119
+ /** RFID transmit power range in dBm (if RFID capable) */
120
+ rfidPowerRange?: {
121
+ min: number;
122
+ max: number;
123
+ };
124
+ /** Firmware version if available */
125
+ firmwareVersion?: string;
126
+ /** Serial number if available */
127
+ serialNumber?: string;
128
+ }
129
+ /**
130
+ * Edge service status information
131
+ */
132
+ interface EdgeStatus {
133
+ /** Whether the service is connected to hardware */
134
+ connected: boolean;
135
+ /** Unique device identifier */
136
+ deviceId: string;
137
+ /** Edge service version */
138
+ version: string;
139
+ /** Service uptime in seconds */
140
+ uptime: number;
141
+ /** Current battery level (0-100) if available */
142
+ batteryLevel?: number;
143
+ /** Whether device is charging */
144
+ isCharging?: boolean;
145
+ }
146
+ /**
147
+ * Edge service configuration
148
+ */
149
+ interface EdgeConfig {
150
+ /** Enabled barcode symbologies */
151
+ enabledSymbologies: string[];
152
+ /** RFID transmit power in dBm */
153
+ rfidPower?: number;
154
+ /** Whether to deduplicate rapid scans of same barcode */
155
+ deduplicateScans: boolean;
156
+ /** Deduplication window in milliseconds */
157
+ deduplicateWindowMs: number;
158
+ /** Whether sound feedback is enabled */
159
+ soundEnabled: boolean;
160
+ /** Whether vibration feedback is enabled */
161
+ vibrationEnabled: boolean;
162
+ }
163
+ /**
164
+ * RFID inventory options for startRfidInventory()
165
+ */
166
+ interface RfidInventoryOptions {
167
+ /** Transmit power in dBm (uses device default if not specified) */
168
+ power?: number;
169
+ /** Which antenna ports to use (all if not specified) */
170
+ antennas?: number[];
171
+ /** Session (0-3, affects tag persistence behavior) */
172
+ session?: 0 | 1 | 2 | 3;
173
+ /** Target flag (A or B) */
174
+ target?: 'A' | 'B';
175
+ }
176
+ /**
177
+ * RFID tag information from inventory
178
+ */
179
+ interface RfidTag {
180
+ /** EPC tag identifier */
181
+ epc: string;
182
+ /** Last seen RSSI */
183
+ rssi: number;
184
+ /** Antenna that last read the tag */
185
+ antenna: number;
186
+ /** Total read count during inventory */
187
+ readCount: number;
188
+ /** When the tag was first seen */
189
+ firstSeen: Date;
190
+ /** When the tag was last seen */
191
+ lastSeen: Date;
192
+ }
193
+
194
+ /**
195
+ * Connection state for the WebSocket
196
+ */
197
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
198
+ /**
199
+ * Options for creating a CleverenceEdge instance
200
+ */
201
+ interface EdgeOptions {
202
+ /** WebSocket URL. Default: 'ws://localhost:8585' */
203
+ url?: string;
204
+ /** Auto-connect on instantiation. Default: true */
205
+ autoConnect?: boolean;
206
+ /** Initial reconnect delay in ms. Default: 1000 */
207
+ reconnectDelay?: number;
208
+ /** Maximum reconnect delay in ms. Default: 30000 */
209
+ maxReconnectDelay?: number;
210
+ /** Ping interval for keepalive in ms. Default: 30000 */
211
+ pingInterval?: number;
212
+ }
213
+
214
+ /**
215
+ * Events emitted by CleverenceEdge
216
+ */
217
+ interface CleverenceEdgeEvents {
218
+ scan: ScanEvent;
219
+ rfid: RfidEvent;
220
+ connect: void;
221
+ disconnect: void;
222
+ reconnecting: void;
223
+ error: Error;
224
+ capabilities: DeviceCapabilities;
225
+ }
226
+ /**
227
+ * CleverenceEdge SDK - Connect to barcode scanners and RFID readers
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const edge = new CleverenceEdge();
232
+ *
233
+ * edge.on('scan', (event) => {
234
+ * console.log(event.data); // "012345678905"
235
+ * console.log(event.symbology); // "ean13"
236
+ * });
237
+ *
238
+ * edge.on('rfid', (event) => {
239
+ * console.log(event.epc); // "3034257BF400B7800004CB2F"
240
+ * console.log(event.rssi); // -45
241
+ * });
242
+ *
243
+ * await edge.connect();
244
+ * ```
245
+ */
246
+ declare class CleverenceEdge extends EventEmitter<CleverenceEdgeEvents> {
247
+ private ws;
248
+ private options;
249
+ private _capabilities;
250
+ constructor(options?: EdgeOptions);
251
+ /**
252
+ * Current connection state
253
+ */
254
+ get connectionState(): ConnectionState;
255
+ /**
256
+ * Whether currently connected to the Edge service
257
+ */
258
+ get isConnected(): boolean;
259
+ /**
260
+ * Cached device capabilities (available after connect)
261
+ */
262
+ get capabilities(): DeviceCapabilities | null;
263
+ /**
264
+ * Connect to the Edge service
265
+ */
266
+ connect(): Promise<void>;
267
+ /**
268
+ * Disconnect from the Edge service
269
+ */
270
+ disconnect(): void;
271
+ /**
272
+ * Trigger a barcode scan programmatically
273
+ */
274
+ triggerScan(): Promise<void>;
275
+ /**
276
+ * Set enabled barcode symbologies
277
+ */
278
+ setSymbologies(symbologies: string[]): Promise<void>;
279
+ /**
280
+ * Start RFID inventory (continuous reading)
281
+ */
282
+ startRfidInventory(options?: RfidInventoryOptions): Promise<void>;
283
+ /**
284
+ * Stop RFID inventory
285
+ */
286
+ stopRfidInventory(): Promise<void>;
287
+ /**
288
+ * Get current Edge service status
289
+ */
290
+ getStatus(): Promise<EdgeStatus>;
291
+ /**
292
+ * Get device capabilities
293
+ */
294
+ getCapabilities(): Promise<DeviceCapabilities>;
295
+ /**
296
+ * Get current configuration
297
+ */
298
+ getConfig(): Promise<EdgeConfig>;
299
+ /**
300
+ * Get RFID tags from current/last inventory
301
+ */
302
+ getRfidTags(): Promise<RfidTag[]>;
303
+ /**
304
+ * Create a new CleverenceEdge instance
305
+ */
306
+ static create(options?: EdgeOptions): CleverenceEdge;
307
+ private setupWebSocketHandlers;
308
+ private handleServerMessage;
309
+ private handleEvent;
310
+ private ensureConnected;
311
+ }
312
+
313
+ export { CleverenceEdge, type ConnectionState, type DeviceCapabilities, type EdgeConfig, type EdgeEvent, type EdgeOptions, type EdgeStatus, type RfidEvent, type RfidInventoryOptions, type RfidTag, type ScanEvent };
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Minimal typed event emitter for browser environments
3
+ */
4
+ type EventHandler<T = unknown> = (data: T) => void;
5
+ declare class EventEmitter<Events extends Record<string, any> = Record<string, unknown>> {
6
+ private handlers;
7
+ /**
8
+ * Subscribe to an event
9
+ */
10
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
11
+ /**
12
+ * Subscribe to an event once (auto-unsubscribes after first call)
13
+ */
14
+ once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
15
+ /**
16
+ * Unsubscribe from an event
17
+ */
18
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
19
+ /**
20
+ * Emit an event to all subscribers
21
+ */
22
+ protected emit<K extends keyof Events>(event: K, data: Events[K]): void;
23
+ /**
24
+ * Remove all listeners for an event, or all listeners if no event specified
25
+ */
26
+ removeAllListeners(event?: keyof Events): this;
27
+ /**
28
+ * Get listener count for an event
29
+ */
30
+ listenerCount(event: keyof Events): number;
31
+ }
32
+
33
+ /**
34
+ * Barcode scan event - simplified API surface for easy consumption
35
+ */
36
+ interface ScanEvent {
37
+ /** Event type discriminator */
38
+ type: 'scan';
39
+ /** Unique event identifier */
40
+ id: string;
41
+ /** When the scan occurred */
42
+ timestamp: Date;
43
+ /** Decoded barcode data string */
44
+ data: string;
45
+ /** Human-readable symbology name: "ean13", "qrcode", "code128", etc. */
46
+ symbology: string;
47
+ /** Scanner source: "integrated-laser", "camera", "bluetooth-ring" */
48
+ source: string;
49
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic" */
50
+ vendor: string;
51
+ /** Extended raw data (optional, for advanced use cases) */
52
+ raw?: {
53
+ /** Raw barcode bytes as hex string */
54
+ bytesHex: string;
55
+ /** Vendor-specific symbology identifier */
56
+ symbologyId: string;
57
+ /** AIM identifier for the symbology */
58
+ aimId: string;
59
+ /** Signal strength if available */
60
+ signalStrength: number | null;
61
+ /** How long the scan took in milliseconds */
62
+ scanDurationMs: number;
63
+ };
64
+ }
65
+ /**
66
+ * RFID read event - simplified API surface for easy consumption
67
+ */
68
+ interface RfidEvent {
69
+ /** Event type discriminator */
70
+ type: 'rfid';
71
+ /** Unique event identifier */
72
+ id: string;
73
+ /** When the read occurred */
74
+ timestamp: Date;
75
+ /** EPC (Electronic Product Code) tag identifier */
76
+ epc: string;
77
+ /** Received Signal Strength Indicator in dBm */
78
+ rssi: number;
79
+ /** Antenna port number that read the tag */
80
+ antenna: number;
81
+ /** Tag Identifier (TID) memory bank data */
82
+ tid?: string | null;
83
+ /** User memory bank data */
84
+ userData?: string | null;
85
+ /** RF phase angle */
86
+ phase?: number;
87
+ /** RF channel frequency */
88
+ channel?: number;
89
+ /** Number of times this tag was read in current inventory */
90
+ readCount?: number;
91
+ /** Protocol Control (PC) bits */
92
+ pc?: string;
93
+ /** CRC checksum */
94
+ crc?: string;
95
+ /** Inventory session identifier */
96
+ inventorySession?: string;
97
+ /** Transmit power used for this read in dBm */
98
+ transmitPowerDbm?: number;
99
+ }
100
+ /**
101
+ * Union type for all events
102
+ */
103
+ type EdgeEvent = ScanEvent | RfidEvent;
104
+
105
+ /**
106
+ * Device capabilities reported by the Edge service on connection
107
+ */
108
+ interface DeviceCapabilities {
109
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic", etc. */
110
+ vendor: string;
111
+ /** Device model name */
112
+ deviceModel: string;
113
+ /** Whether device has barcode scanning capability */
114
+ hasBarcode: boolean;
115
+ /** Whether device has RFID reading capability */
116
+ hasRfid: boolean;
117
+ /** List of supported barcode symbologies */
118
+ supportedSymbologies: string[];
119
+ /** RFID transmit power range in dBm (if RFID capable) */
120
+ rfidPowerRange?: {
121
+ min: number;
122
+ max: number;
123
+ };
124
+ /** Firmware version if available */
125
+ firmwareVersion?: string;
126
+ /** Serial number if available */
127
+ serialNumber?: string;
128
+ }
129
+ /**
130
+ * Edge service status information
131
+ */
132
+ interface EdgeStatus {
133
+ /** Whether the service is connected to hardware */
134
+ connected: boolean;
135
+ /** Unique device identifier */
136
+ deviceId: string;
137
+ /** Edge service version */
138
+ version: string;
139
+ /** Service uptime in seconds */
140
+ uptime: number;
141
+ /** Current battery level (0-100) if available */
142
+ batteryLevel?: number;
143
+ /** Whether device is charging */
144
+ isCharging?: boolean;
145
+ }
146
+ /**
147
+ * Edge service configuration
148
+ */
149
+ interface EdgeConfig {
150
+ /** Enabled barcode symbologies */
151
+ enabledSymbologies: string[];
152
+ /** RFID transmit power in dBm */
153
+ rfidPower?: number;
154
+ /** Whether to deduplicate rapid scans of same barcode */
155
+ deduplicateScans: boolean;
156
+ /** Deduplication window in milliseconds */
157
+ deduplicateWindowMs: number;
158
+ /** Whether sound feedback is enabled */
159
+ soundEnabled: boolean;
160
+ /** Whether vibration feedback is enabled */
161
+ vibrationEnabled: boolean;
162
+ }
163
+ /**
164
+ * RFID inventory options for startRfidInventory()
165
+ */
166
+ interface RfidInventoryOptions {
167
+ /** Transmit power in dBm (uses device default if not specified) */
168
+ power?: number;
169
+ /** Which antenna ports to use (all if not specified) */
170
+ antennas?: number[];
171
+ /** Session (0-3, affects tag persistence behavior) */
172
+ session?: 0 | 1 | 2 | 3;
173
+ /** Target flag (A or B) */
174
+ target?: 'A' | 'B';
175
+ }
176
+ /**
177
+ * RFID tag information from inventory
178
+ */
179
+ interface RfidTag {
180
+ /** EPC tag identifier */
181
+ epc: string;
182
+ /** Last seen RSSI */
183
+ rssi: number;
184
+ /** Antenna that last read the tag */
185
+ antenna: number;
186
+ /** Total read count during inventory */
187
+ readCount: number;
188
+ /** When the tag was first seen */
189
+ firstSeen: Date;
190
+ /** When the tag was last seen */
191
+ lastSeen: Date;
192
+ }
193
+
194
+ /**
195
+ * Connection state for the WebSocket
196
+ */
197
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
198
+ /**
199
+ * Options for creating a CleverenceEdge instance
200
+ */
201
+ interface EdgeOptions {
202
+ /** WebSocket URL. Default: 'ws://localhost:8585' */
203
+ url?: string;
204
+ /** Auto-connect on instantiation. Default: true */
205
+ autoConnect?: boolean;
206
+ /** Initial reconnect delay in ms. Default: 1000 */
207
+ reconnectDelay?: number;
208
+ /** Maximum reconnect delay in ms. Default: 30000 */
209
+ maxReconnectDelay?: number;
210
+ /** Ping interval for keepalive in ms. Default: 30000 */
211
+ pingInterval?: number;
212
+ }
213
+
214
+ /**
215
+ * Events emitted by CleverenceEdge
216
+ */
217
+ interface CleverenceEdgeEvents {
218
+ scan: ScanEvent;
219
+ rfid: RfidEvent;
220
+ connect: void;
221
+ disconnect: void;
222
+ reconnecting: void;
223
+ error: Error;
224
+ capabilities: DeviceCapabilities;
225
+ }
226
+ /**
227
+ * CleverenceEdge SDK - Connect to barcode scanners and RFID readers
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const edge = new CleverenceEdge();
232
+ *
233
+ * edge.on('scan', (event) => {
234
+ * console.log(event.data); // "012345678905"
235
+ * console.log(event.symbology); // "ean13"
236
+ * });
237
+ *
238
+ * edge.on('rfid', (event) => {
239
+ * console.log(event.epc); // "3034257BF400B7800004CB2F"
240
+ * console.log(event.rssi); // -45
241
+ * });
242
+ *
243
+ * await edge.connect();
244
+ * ```
245
+ */
246
+ declare class CleverenceEdge extends EventEmitter<CleverenceEdgeEvents> {
247
+ private ws;
248
+ private options;
249
+ private _capabilities;
250
+ constructor(options?: EdgeOptions);
251
+ /**
252
+ * Current connection state
253
+ */
254
+ get connectionState(): ConnectionState;
255
+ /**
256
+ * Whether currently connected to the Edge service
257
+ */
258
+ get isConnected(): boolean;
259
+ /**
260
+ * Cached device capabilities (available after connect)
261
+ */
262
+ get capabilities(): DeviceCapabilities | null;
263
+ /**
264
+ * Connect to the Edge service
265
+ */
266
+ connect(): Promise<void>;
267
+ /**
268
+ * Disconnect from the Edge service
269
+ */
270
+ disconnect(): void;
271
+ /**
272
+ * Trigger a barcode scan programmatically
273
+ */
274
+ triggerScan(): Promise<void>;
275
+ /**
276
+ * Set enabled barcode symbologies
277
+ */
278
+ setSymbologies(symbologies: string[]): Promise<void>;
279
+ /**
280
+ * Start RFID inventory (continuous reading)
281
+ */
282
+ startRfidInventory(options?: RfidInventoryOptions): Promise<void>;
283
+ /**
284
+ * Stop RFID inventory
285
+ */
286
+ stopRfidInventory(): Promise<void>;
287
+ /**
288
+ * Get current Edge service status
289
+ */
290
+ getStatus(): Promise<EdgeStatus>;
291
+ /**
292
+ * Get device capabilities
293
+ */
294
+ getCapabilities(): Promise<DeviceCapabilities>;
295
+ /**
296
+ * Get current configuration
297
+ */
298
+ getConfig(): Promise<EdgeConfig>;
299
+ /**
300
+ * Get RFID tags from current/last inventory
301
+ */
302
+ getRfidTags(): Promise<RfidTag[]>;
303
+ /**
304
+ * Create a new CleverenceEdge instance
305
+ */
306
+ static create(options?: EdgeOptions): CleverenceEdge;
307
+ private setupWebSocketHandlers;
308
+ private handleServerMessage;
309
+ private handleEvent;
310
+ private ensureConnected;
311
+ }
312
+
313
+ export { CleverenceEdge, type ConnectionState, type DeviceCapabilities, type EdgeConfig, type EdgeEvent, type EdgeOptions, type EdgeStatus, type RfidEvent, type RfidInventoryOptions, type RfidTag, type ScanEvent };