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