@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,456 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * Minimal typed event emitter for browser environments
6
+ */
7
+ type EventHandler<T = unknown> = (data: T) => void;
8
+ declare class EventEmitter<Events extends Record<string, any> = Record<string, unknown>> {
9
+ private handlers;
10
+ /**
11
+ * Subscribe to an event
12
+ */
13
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
14
+ /**
15
+ * Subscribe to an event once (auto-unsubscribes after first call)
16
+ */
17
+ once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
18
+ /**
19
+ * Unsubscribe from an event
20
+ */
21
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
22
+ /**
23
+ * Emit an event to all subscribers
24
+ */
25
+ protected emit<K extends keyof Events>(event: K, data: Events[K]): void;
26
+ /**
27
+ * Remove all listeners for an event, or all listeners if no event specified
28
+ */
29
+ removeAllListeners(event?: keyof Events): this;
30
+ /**
31
+ * Get listener count for an event
32
+ */
33
+ listenerCount(event: keyof Events): number;
34
+ }
35
+
36
+ /**
37
+ * Barcode scan event - simplified API surface for easy consumption
38
+ */
39
+ interface ScanEvent {
40
+ /** Event type discriminator */
41
+ type: 'scan';
42
+ /** Unique event identifier */
43
+ id: string;
44
+ /** When the scan occurred */
45
+ timestamp: Date;
46
+ /** Decoded barcode data string */
47
+ data: string;
48
+ /** Human-readable symbology name: "ean13", "qrcode", "code128", etc. */
49
+ symbology: string;
50
+ /** Scanner source: "integrated-laser", "camera", "bluetooth-ring" */
51
+ source: string;
52
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic" */
53
+ vendor: string;
54
+ /** Extended raw data (optional, for advanced use cases) */
55
+ raw?: {
56
+ /** Raw barcode bytes as hex string */
57
+ bytesHex: string;
58
+ /** Vendor-specific symbology identifier */
59
+ symbologyId: string;
60
+ /** AIM identifier for the symbology */
61
+ aimId: string;
62
+ /** Signal strength if available */
63
+ signalStrength: number | null;
64
+ /** How long the scan took in milliseconds */
65
+ scanDurationMs: number;
66
+ };
67
+ }
68
+ /**
69
+ * RFID read event - simplified API surface for easy consumption
70
+ */
71
+ interface RfidEvent {
72
+ /** Event type discriminator */
73
+ type: 'rfid';
74
+ /** Unique event identifier */
75
+ id: string;
76
+ /** When the read occurred */
77
+ timestamp: Date;
78
+ /** EPC (Electronic Product Code) tag identifier */
79
+ epc: string;
80
+ /** Received Signal Strength Indicator in dBm */
81
+ rssi: number;
82
+ /** Antenna port number that read the tag */
83
+ antenna: number;
84
+ /** Tag Identifier (TID) memory bank data */
85
+ tid?: string | null;
86
+ /** User memory bank data */
87
+ userData?: string | null;
88
+ /** RF phase angle */
89
+ phase?: number;
90
+ /** RF channel frequency */
91
+ channel?: number;
92
+ /** Number of times this tag was read in current inventory */
93
+ readCount?: number;
94
+ /** Protocol Control (PC) bits */
95
+ pc?: string;
96
+ /** CRC checksum */
97
+ crc?: string;
98
+ /** Inventory session identifier */
99
+ inventorySession?: string;
100
+ /** Transmit power used for this read in dBm */
101
+ transmitPowerDbm?: number;
102
+ }
103
+
104
+ /**
105
+ * Device capabilities reported by the Edge service on connection
106
+ */
107
+ interface DeviceCapabilities {
108
+ /** Device vendor: "zebra", "honeywell", "urovo", "datalogic", etc. */
109
+ vendor: string;
110
+ /** Device model name */
111
+ deviceModel: string;
112
+ /** Whether device has barcode scanning capability */
113
+ hasBarcode: boolean;
114
+ /** Whether device has RFID reading capability */
115
+ hasRfid: boolean;
116
+ /** List of supported barcode symbologies */
117
+ supportedSymbologies: string[];
118
+ /** RFID transmit power range in dBm (if RFID capable) */
119
+ rfidPowerRange?: {
120
+ min: number;
121
+ max: number;
122
+ };
123
+ /** Firmware version if available */
124
+ firmwareVersion?: string;
125
+ /** Serial number if available */
126
+ serialNumber?: string;
127
+ }
128
+ /**
129
+ * Edge service status information
130
+ */
131
+ interface EdgeStatus {
132
+ /** Whether the service is connected to hardware */
133
+ connected: boolean;
134
+ /** Unique device identifier */
135
+ deviceId: string;
136
+ /** Edge service version */
137
+ version: string;
138
+ /** Service uptime in seconds */
139
+ uptime: number;
140
+ /** Current battery level (0-100) if available */
141
+ batteryLevel?: number;
142
+ /** Whether device is charging */
143
+ isCharging?: boolean;
144
+ }
145
+ /**
146
+ * Edge service configuration
147
+ */
148
+ interface EdgeConfig {
149
+ /** Enabled barcode symbologies */
150
+ enabledSymbologies: string[];
151
+ /** RFID transmit power in dBm */
152
+ rfidPower?: number;
153
+ /** Whether to deduplicate rapid scans of same barcode */
154
+ deduplicateScans: boolean;
155
+ /** Deduplication window in milliseconds */
156
+ deduplicateWindowMs: number;
157
+ /** Whether sound feedback is enabled */
158
+ soundEnabled: boolean;
159
+ /** Whether vibration feedback is enabled */
160
+ vibrationEnabled: boolean;
161
+ }
162
+ /**
163
+ * RFID inventory options for startRfidInventory()
164
+ */
165
+ interface RfidInventoryOptions {
166
+ /** Transmit power in dBm (uses device default if not specified) */
167
+ power?: number;
168
+ /** Which antenna ports to use (all if not specified) */
169
+ antennas?: number[];
170
+ /** Session (0-3, affects tag persistence behavior) */
171
+ session?: 0 | 1 | 2 | 3;
172
+ /** Target flag (A or B) */
173
+ target?: 'A' | 'B';
174
+ }
175
+ /**
176
+ * RFID tag information from inventory
177
+ */
178
+ interface RfidTag {
179
+ /** EPC tag identifier */
180
+ epc: string;
181
+ /** Last seen RSSI */
182
+ rssi: number;
183
+ /** Antenna that last read the tag */
184
+ antenna: number;
185
+ /** Total read count during inventory */
186
+ readCount: number;
187
+ /** When the tag was first seen */
188
+ firstSeen: Date;
189
+ /** When the tag was last seen */
190
+ lastSeen: Date;
191
+ }
192
+
193
+ /**
194
+ * Connection state for the WebSocket
195
+ */
196
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
197
+ /**
198
+ * Options for creating a CleverenceEdge instance
199
+ */
200
+ interface EdgeOptions {
201
+ /** WebSocket URL. Default: 'ws://localhost:8585' */
202
+ url?: string;
203
+ /** Auto-connect on instantiation. Default: true */
204
+ autoConnect?: boolean;
205
+ /** Initial reconnect delay in ms. Default: 1000 */
206
+ reconnectDelay?: number;
207
+ /** Maximum reconnect delay in ms. Default: 30000 */
208
+ maxReconnectDelay?: number;
209
+ /** Ping interval for keepalive in ms. Default: 30000 */
210
+ pingInterval?: number;
211
+ }
212
+
213
+ /**
214
+ * Events emitted by CleverenceEdge
215
+ */
216
+ interface CleverenceEdgeEvents {
217
+ scan: ScanEvent;
218
+ rfid: RfidEvent;
219
+ connect: void;
220
+ disconnect: void;
221
+ reconnecting: void;
222
+ error: Error;
223
+ capabilities: DeviceCapabilities;
224
+ }
225
+ /**
226
+ * CleverenceEdge SDK - Connect to barcode scanners and RFID readers
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * const edge = new CleverenceEdge();
231
+ *
232
+ * edge.on('scan', (event) => {
233
+ * console.log(event.data); // "012345678905"
234
+ * console.log(event.symbology); // "ean13"
235
+ * });
236
+ *
237
+ * edge.on('rfid', (event) => {
238
+ * console.log(event.epc); // "3034257BF400B7800004CB2F"
239
+ * console.log(event.rssi); // -45
240
+ * });
241
+ *
242
+ * await edge.connect();
243
+ * ```
244
+ */
245
+ declare class CleverenceEdge extends EventEmitter<CleverenceEdgeEvents> {
246
+ private ws;
247
+ private options;
248
+ private _capabilities;
249
+ constructor(options?: EdgeOptions);
250
+ /**
251
+ * Current connection state
252
+ */
253
+ get connectionState(): ConnectionState;
254
+ /**
255
+ * Whether currently connected to the Edge service
256
+ */
257
+ get isConnected(): boolean;
258
+ /**
259
+ * Cached device capabilities (available after connect)
260
+ */
261
+ get capabilities(): DeviceCapabilities | null;
262
+ /**
263
+ * Connect to the Edge service
264
+ */
265
+ connect(): Promise<void>;
266
+ /**
267
+ * Disconnect from the Edge service
268
+ */
269
+ disconnect(): void;
270
+ /**
271
+ * Trigger a barcode scan programmatically
272
+ */
273
+ triggerScan(): Promise<void>;
274
+ /**
275
+ * Set enabled barcode symbologies
276
+ */
277
+ setSymbologies(symbologies: string[]): Promise<void>;
278
+ /**
279
+ * Start RFID inventory (continuous reading)
280
+ */
281
+ startRfidInventory(options?: RfidInventoryOptions): Promise<void>;
282
+ /**
283
+ * Stop RFID inventory
284
+ */
285
+ stopRfidInventory(): Promise<void>;
286
+ /**
287
+ * Get current Edge service status
288
+ */
289
+ getStatus(): Promise<EdgeStatus>;
290
+ /**
291
+ * Get device capabilities
292
+ */
293
+ getCapabilities(): Promise<DeviceCapabilities>;
294
+ /**
295
+ * Get current configuration
296
+ */
297
+ getConfig(): Promise<EdgeConfig>;
298
+ /**
299
+ * Get RFID tags from current/last inventory
300
+ */
301
+ getRfidTags(): Promise<RfidTag[]>;
302
+ /**
303
+ * Create a new CleverenceEdge instance
304
+ */
305
+ static create(options?: EdgeOptions): CleverenceEdge;
306
+ private setupWebSocketHandlers;
307
+ private handleServerMessage;
308
+ private handleEvent;
309
+ private ensureConnected;
310
+ }
311
+
312
+ interface EdgeProviderProps {
313
+ children: ReactNode;
314
+ /** Edge connection options */
315
+ options?: EdgeOptions;
316
+ /** Custom CleverenceEdge instance (if you want to manage it yourself) */
317
+ instance?: CleverenceEdge;
318
+ }
319
+ /**
320
+ * React context provider for CleverenceEdge
321
+ *
322
+ * @example
323
+ * ```tsx
324
+ * function App() {
325
+ * return (
326
+ * <EdgeProvider>
327
+ * <Scanner />
328
+ * </EdgeProvider>
329
+ * );
330
+ * }
331
+ * ```
332
+ */
333
+ declare function EdgeProvider({ children, options, instance }: EdgeProviderProps): react_jsx_runtime.JSX.Element;
334
+
335
+ interface UseEdgeReturn {
336
+ /** The CleverenceEdge instance */
337
+ edge: CleverenceEdge | null;
338
+ /** Whether connected to the Edge service */
339
+ isConnected: boolean;
340
+ /** Current connection state */
341
+ connectionState: ConnectionState;
342
+ /** Device capabilities (available after connect) */
343
+ capabilities: DeviceCapabilities | null;
344
+ /** Last error that occurred */
345
+ error: Error | null;
346
+ }
347
+ /**
348
+ * Hook to access the CleverenceEdge instance and connection state
349
+ *
350
+ * @example
351
+ * ```tsx
352
+ * function StatusBar() {
353
+ * const { isConnected, capabilities, error } = useEdge();
354
+ *
355
+ * if (error) return <div>Error: {error.message}</div>;
356
+ * if (!isConnected) return <div>Connecting...</div>;
357
+ *
358
+ * return (
359
+ * <div>
360
+ * Connected to {capabilities?.vendor} {capabilities?.deviceModel}
361
+ * </div>
362
+ * );
363
+ * }
364
+ * ```
365
+ */
366
+ declare function useEdge(): UseEdgeReturn;
367
+
368
+ interface UseBarcodeOptions {
369
+ /** Maximum number of scans to keep in history. Default: 50 */
370
+ maxHistory?: number;
371
+ /** Called when a new scan is received */
372
+ onScan?: (event: ScanEvent) => void;
373
+ }
374
+ interface UseBarcodeReturn {
375
+ /** Most recent scan event */
376
+ lastScan: ScanEvent | null;
377
+ /** History of scan events (newest first) */
378
+ scanHistory: ScanEvent[];
379
+ /** Clear the scan history */
380
+ clearHistory: () => void;
381
+ /** Trigger a scan programmatically */
382
+ triggerScan: () => Promise<void>;
383
+ }
384
+ /**
385
+ * Hook for barcode scanning
386
+ *
387
+ * @example
388
+ * ```tsx
389
+ * function Scanner() {
390
+ * const { lastScan, scanHistory, clearHistory } = useBarcode({
391
+ * onScan: (scan) => console.log('Scanned:', scan.data),
392
+ * });
393
+ *
394
+ * return (
395
+ * <div>
396
+ * <h1>Last: {lastScan?.data}</h1>
397
+ * <button onClick={clearHistory}>Clear</button>
398
+ * <ul>
399
+ * {scanHistory.map(scan => (
400
+ * <li key={scan.id}>{scan.data} ({scan.symbology})</li>
401
+ * ))}
402
+ * </ul>
403
+ * </div>
404
+ * );
405
+ * }
406
+ * ```
407
+ */
408
+ declare function useBarcode(options?: UseBarcodeOptions): UseBarcodeReturn;
409
+
410
+ interface UseRfidOptions {
411
+ /** Called when a new RFID tag is read */
412
+ onRead?: (event: RfidEvent) => void;
413
+ }
414
+ interface UseRfidReturn {
415
+ /** Most recent RFID read event */
416
+ lastRead: RfidEvent | null;
417
+ /** Aggregated list of unique tags (by EPC) */
418
+ tags: Map<string, RfidTag>;
419
+ /** Whether an inventory is currently active */
420
+ isInventoryActive: boolean;
421
+ /** Start RFID inventory */
422
+ startInventory: (options?: RfidInventoryOptions) => Promise<void>;
423
+ /** Stop RFID inventory */
424
+ stopInventory: () => Promise<void>;
425
+ /** Clear the tags list */
426
+ clearTags: () => void;
427
+ }
428
+ /**
429
+ * Hook for RFID reading
430
+ *
431
+ * @example
432
+ * ```tsx
433
+ * function RfidReader() {
434
+ * const { tags, isInventoryActive, startInventory, stopInventory } = useRfid();
435
+ *
436
+ * return (
437
+ * <div>
438
+ * <button onClick={() => isInventoryActive ? stopInventory() : startInventory()}>
439
+ * {isInventoryActive ? 'Stop' : 'Start'} Inventory
440
+ * </button>
441
+ * <p>{tags.size} unique tags found</p>
442
+ * <ul>
443
+ * {Array.from(tags.values()).map(tag => (
444
+ * <li key={tag.epc}>
445
+ * {tag.epc} (RSSI: {tag.rssi}, Count: {tag.readCount})
446
+ * </li>
447
+ * ))}
448
+ * </ul>
449
+ * </div>
450
+ * );
451
+ * }
452
+ * ```
453
+ */
454
+ declare function useRfid(options?: UseRfidOptions): UseRfidReturn;
455
+
456
+ export { type ConnectionState, type DeviceCapabilities, type EdgeConfig, type EdgeOptions, EdgeProvider, type EdgeProviderProps, type EdgeStatus, type RfidEvent, type RfidInventoryOptions, type RfidTag, type ScanEvent, type UseBarcodeOptions, type UseBarcodeReturn, type UseEdgeReturn, type UseRfidOptions, type UseRfidReturn, useBarcode, useEdge, useRfid };