@busy-app/busy-lib 0.0.1 → 0.0.2

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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var u=(e,t,r)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var s=(e,t,r)=>u(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("openapi-fetch");function l(e){const t=e.split(".");if(t.length!==4)return!1;for(const r of t){if(r.length===0||r.length>1&&r[0]==="0"||!/^\d+$/.test(r))return!1;const i=Number(r);if(i<0||i>255)return!1}return!0}const p=(e,t)=>{if(typeof FormData<"u"&&e instanceof FormData||typeof Buffer<"u"&&typeof Buffer.isBuffer=="function"&&Buffer.isBuffer(e)||typeof File<"u"&&e instanceof File||typeof Blob<"u"&&e instanceof Blob||typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer||typeof ArrayBuffer<"u"&&ArrayBuffer.isView&&ArrayBuffer.isView(e))return e;let r;return t&&(t instanceof Headers?r=t.get("Content-Type")??t.get("content-type")??void 0:typeof t=="object"&&(r=t["Content-Type"]??t["content-type"]),r==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};let n=null;function w(e){n=c({baseUrl:e,bodySerializer:p})}async function d(e){const{appId:t,fileName:r,file:i}=e;if(!n)throw new Error("API client is not initialized");const{data:a,error:o}=await n.POST("/v0/assets/upload",{params:{query:{app_id:t,file:r}},headers:{"Content-Type":"application/octet-stream"},body:i});if(o)throw o;return a}async function y(e){const{appId:t}=e;if(!n)throw new Error("API client is not initialized");const{data:r,error:i}=await n.DELETE("/v0/assets/upload",{params:{query:{app_id:t}}});if(i)throw i;return r}const h={timeout:5,x:0,y:0,display:"front"};function m(e){return{...h,...e}}async function E(e){const{appId:t,elements:r}=e;if(!n)throw new Error("API client is not initialized");const i=r.map(m),{data:a,error:o}=await n.POST("/v0/display/draw",{body:{app_id:t,elements:i}});if(o)throw o;return a}async function A(){if(!n)throw new Error("API client is not initialized");const{data:e,error:t}=await n.DELETE("/v0/display/draw");if(t)throw t;return e}async function B(e){const{appId:t,path:r}=e;if(!n)throw new Error("API client is not initialized");const{data:i,error:a}=await n.POST("/v0/audio/play",{params:{query:{app_id:t,path:r}}});if(a)throw a;return i}async function P(){if(!n)throw new Error("API client is not initialized");const{data:e,error:t}=await n.DELETE("/v0/audio/play");if(t)throw t;return e}class S{constructor(t="10.0.4.20"){s(this,"ip");if(!l(t))throw new Error(`Incorrect IPv4: ${t}`);this.ip=t,console.log(this.ip),w(`http://${this.ip}/api/`)}async uploadAsset(t){return await d(t)}async deleteAssets(t){return await y(t)}async drawDisplay(t){return await E(t)}async clearDisplay(){return await A()}async playSound(t){return await B(t)}async stopSound(){return await P()}}exports.BusyBar=S;
@@ -0,0 +1,805 @@
1
+ declare interface AudioParams {
2
+ appId: paths["/v0/audio/play"]["post"]["parameters"]["query"]["app_id"];
3
+ path: paths["/v0/audio/play"]["post"]["parameters"]["query"]["path"];
4
+ }
5
+
6
+ /**
7
+ * Main library class for interacting with the Busy Bar API.
8
+ *
9
+ * @class
10
+ */
11
+ export declare class BusyBar {
12
+ /**
13
+ * Device IPv4 address.
14
+ * @type {IPv4}
15
+ * @readonly
16
+ */
17
+ readonly ip: IPv4;
18
+ /**
19
+ * Creates an instance of BUSY Bar.
20
+ * Initializes the API client with the provided IPv4 address.
21
+ *
22
+ * @param {IPv4} [ip="10.0.4.20"] - The IPv4 address of the device.
23
+ * @throws {Error} If the provided IP is not a valid IPv4 address.
24
+ */
25
+ constructor(ip?: IPv4);
26
+ /**
27
+ * Uploads an asset to the device.
28
+ *
29
+ * @param {UploadParams} params - Parameters for the upload.
30
+ * @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
31
+ * @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
32
+ * @param {UploadParams['file']} params.file - File data to upload.
33
+ * @returns {Promise<{ result: string }>} Result of the upload operation.
34
+ */
35
+ uploadAsset(params: UploadParams): Promise<{
36
+ result: string;
37
+ }>;
38
+ /**
39
+ * Deletes all assets for a specific application from the device.
40
+ *
41
+ * @param {DeleteParams} params - Parameters for the delete.
42
+ * @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
43
+ * @returns {Promise<{ result: string }>} Result of the delete operation.
44
+ */
45
+ deleteAssets(params: DeleteParams): Promise<{
46
+ result: string;
47
+ }>;
48
+ /**
49
+ * Draws elements on the device display.
50
+ *
51
+ * @param {DrawParams} params - Parameters for the draw operation.
52
+ * @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
53
+ * @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
54
+ * @returns {Promise<{ result: string }>} Result of the draw operation.
55
+ */
56
+ drawDisplay(params: DrawParams): Promise<{
57
+ result: string;
58
+ }>;
59
+ /**
60
+ * Clears the device display and stops the Canvas application if running.
61
+ *
62
+ * @returns {Promise<{ result: string }>} Result of the clear operation.
63
+ */
64
+ clearDisplay(): Promise<{
65
+ result: string;
66
+ }>;
67
+ /**
68
+ * Plays an audio file from the assets directory.
69
+ *
70
+ * @param {AudioParams} params - Parameters for the audio playback.
71
+ * @param {AudioParams['appId']} params.appId - Application ID for organizing assets.
72
+ * @param {AudioParams['path']} params.path - Path to the audio file within the app's assets directory.
73
+ * @returns {Promise<{ result: string }>} Result of the play operation.
74
+ */
75
+ playSound(params: AudioParams): Promise<{
76
+ result: string;
77
+ }>;
78
+ /**
79
+ * Stops any currently playing audio on the device.
80
+ *
81
+ * @returns {Promise<{ result: string }>} Result of the stop operation.
82
+ */
83
+ stopSound(): Promise<{
84
+ result: string;
85
+ }>;
86
+ }
87
+
88
+ declare interface components {
89
+ schemas: {
90
+ /** @example {
91
+ * "state": 1
92
+ * } */
93
+ LedState: {
94
+ /**
95
+ * @description Current LED state (0 for off, 1 for on)
96
+ * @enum {integer}
97
+ */
98
+ state: 0 | 1;
99
+ };
100
+ /** @example {
101
+ * "state": 1
102
+ * } */
103
+ LedStateRequest: {
104
+ /**
105
+ * @description LED state (0 for off, 1 for on)
106
+ * @enum {integer}
107
+ */
108
+ state: 0 | 1;
109
+ };
110
+ SuccessResponse: {
111
+ /**
112
+ * @description Success status message
113
+ * @example OK
114
+ */
115
+ result: string;
116
+ };
117
+ LedStateResponse: components["schemas"]["SuccessResponse"] & {
118
+ /**
119
+ * @description Current LED state (0 for off, 1 for on)
120
+ * @enum {integer}
121
+ */
122
+ state: 0 | 1;
123
+ };
124
+ /** @example {
125
+ * "branch": "main",
126
+ * "version": "1.0.0",
127
+ * "build_date": "2024-01-01",
128
+ * "commit_hash": "abc123def456"
129
+ * } */
130
+ VersionInfo: {
131
+ /**
132
+ * @description Git branch name
133
+ * @example main
134
+ */
135
+ branch: string;
136
+ /**
137
+ * @description Firmware version
138
+ * @example 1.0.0
139
+ */
140
+ version: string;
141
+ /**
142
+ * @description Build date
143
+ * @example 2024-01-01
144
+ */
145
+ build_date: string;
146
+ /**
147
+ * @description Git commit hash (may include -dirty suffix)
148
+ * @example abc123def456-dirty
149
+ */
150
+ commit_hash: string;
151
+ };
152
+ /**
153
+ * Format: binary
154
+ * @description Binary data upload
155
+ */
156
+ BinaryUpload: string;
157
+ FileUpload: {
158
+ /**
159
+ * Format: binary
160
+ * @description File to upload
161
+ */
162
+ file: string;
163
+ };
164
+ /** @example {
165
+ * "error": "Invalid parameter",
166
+ * "code": 400
167
+ * } */
168
+ Error: {
169
+ /** @description Error message */
170
+ error: string;
171
+ /** @description Error code */
172
+ code?: number;
173
+ };
174
+ /** @example {
175
+ * "app_id": "my_app",
176
+ * "elements": [
177
+ * {
178
+ * "id": "0",
179
+ * "timeout": 5,
180
+ * "type": "text",
181
+ * "text": "Hello, world!",
182
+ * "x": 0,
183
+ * "y": 0,
184
+ * "display": "front"
185
+ * },
186
+ * {
187
+ * "id": "1",
188
+ * "timeout": 6,
189
+ * "type": "image",
190
+ * "path": "data.png",
191
+ * "x": 0,
192
+ * "y": 0,
193
+ * "display": "back"
194
+ * }
195
+ * ]
196
+ * } */
197
+ DisplayElements: {
198
+ /**
199
+ * @description Application ID for organizing assets
200
+ * @example my_app
201
+ */
202
+ app_id: string;
203
+ /** @description Array of elements to display */
204
+ elements: components["schemas"]["DisplayElement"][];
205
+ };
206
+ DisplayElement: {
207
+ /** @description Unique identifier for the element */
208
+ id: string;
209
+ /** @description Time in seconds the element should be displayed (0 for no timeout) */
210
+ timeout?: number;
211
+ /**
212
+ * @description Type of display element
213
+ * @enum {string}
214
+ */
215
+ type: "text" | "image";
216
+ /** @description X coordinate for placement on display */
217
+ x: number;
218
+ /** @description Y coordinate for placement on display */
219
+ y: number;
220
+ /**
221
+ * @description Which display to show the element on (for dual-display devices)
222
+ * @default front
223
+ * @enum {string}
224
+ */
225
+ display: "front" | "back";
226
+ };
227
+ TextElement: Omit<components["schemas"]["DisplayElement"], "type"> & {
228
+ /** @description Text content to display */
229
+ text: string;
230
+ } & {
231
+ /**
232
+ * @description discriminator enum property added by openapi-typescript
233
+ * @enum {string}
234
+ */
235
+ type: "text";
236
+ };
237
+ ImageElement: Omit<components["schemas"]["DisplayElement"], "type"> & {
238
+ /** @description Path to the image file in the app's assets */
239
+ path: string;
240
+ } & {
241
+ /**
242
+ * @description discriminator enum property added by openapi-typescript
243
+ * @enum {string}
244
+ */
245
+ type: "image";
246
+ };
247
+ };
248
+ responses: never;
249
+ parameters: never;
250
+ requestBodies: never;
251
+ headers: never;
252
+ pathItems: never;
253
+ }
254
+
255
+ declare type CustomElement = CustomTextElement | CustomImageElement;
256
+
257
+ declare type CustomImageElement = MakeOptional<components["schemas"]["ImageElement"], OptionalFields>;
258
+
259
+ declare type CustomTextElement = MakeOptional<components["schemas"]["TextElement"], OptionalFields>;
260
+
261
+ declare interface DeleteParams {
262
+ appId: paths["/v0/assets/upload"]["delete"]["parameters"]["query"]["app_id"];
263
+ }
264
+
265
+ declare interface DrawParams {
266
+ appId: paths["/v0/display/draw"]["post"]["requestBody"]["content"]["application/json"]["app_id"];
267
+ elements: CustomElement[];
268
+ }
269
+
270
+ declare type IPv4 = string;
271
+
272
+ declare type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
273
+
274
+ declare interface operations {
275
+ getLedState: {
276
+ parameters: {
277
+ query?: {
278
+ /** @description LED state (0 for off, 1 for on) - alternative to JSON body */
279
+ state?: 0 | 1;
280
+ };
281
+ header?: never;
282
+ path?: never;
283
+ cookie?: never;
284
+ };
285
+ requestBody?: never;
286
+ responses: {
287
+ /** @description LED state retrieved successfully */
288
+ 200: {
289
+ headers: {
290
+ [name: string]: unknown;
291
+ };
292
+ content: {
293
+ "application/json": components["schemas"]["LedStateResponse"];
294
+ };
295
+ };
296
+ /** @description Internal server error */
297
+ 500: {
298
+ headers: {
299
+ [name: string]: unknown;
300
+ };
301
+ content: {
302
+ "application/json": components["schemas"]["Error"];
303
+ };
304
+ };
305
+ };
306
+ };
307
+ setLedState: {
308
+ parameters: {
309
+ query?: {
310
+ /** @description LED state (0 for off, 1 for on) - alternative to JSON body */
311
+ state?: 0 | 1;
312
+ };
313
+ header?: never;
314
+ path?: never;
315
+ cookie?: never;
316
+ };
317
+ /** @description LED state as JSON (alternative to query parameter) */
318
+ requestBody?: {
319
+ content: {
320
+ "application/json": components["schemas"]["LedStateRequest"];
321
+ };
322
+ };
323
+ responses: {
324
+ /** @description LED state set successfully */
325
+ 200: {
326
+ headers: {
327
+ [name: string]: unknown;
328
+ };
329
+ content: {
330
+ "application/json": components["schemas"]["LedStateResponse"];
331
+ };
332
+ };
333
+ /** @description Invalid state parameter */
334
+ 400: {
335
+ headers: {
336
+ [name: string]: unknown;
337
+ };
338
+ content: {
339
+ "application/json": components["schemas"]["Error"];
340
+ };
341
+ };
342
+ };
343
+ };
344
+ getVersion: {
345
+ parameters: {
346
+ query?: never;
347
+ header?: never;
348
+ path?: never;
349
+ cookie?: never;
350
+ };
351
+ requestBody?: never;
352
+ responses: {
353
+ /** @description Version information retrieved successfully */
354
+ 200: {
355
+ headers: {
356
+ [name: string]: unknown;
357
+ };
358
+ content: {
359
+ "application/json": components["schemas"]["VersionInfo"];
360
+ };
361
+ };
362
+ /** @description Internal server error */
363
+ 500: {
364
+ headers: {
365
+ [name: string]: unknown;
366
+ };
367
+ content: {
368
+ "application/json": components["schemas"]["Error"];
369
+ };
370
+ };
371
+ };
372
+ };
373
+ uploadAssetWithAppId: {
374
+ parameters: {
375
+ query: {
376
+ /**
377
+ * @description Application ID for organizing assets
378
+ * @example my_app
379
+ */
380
+ app_id: string;
381
+ /**
382
+ * @description Filename for the uploaded asset
383
+ * @example data.png
384
+ */
385
+ file: string;
386
+ };
387
+ header?: never;
388
+ path?: never;
389
+ cookie?: never;
390
+ };
391
+ requestBody: {
392
+ content: {
393
+ "application/octet-stream": string;
394
+ };
395
+ };
396
+ responses: {
397
+ /** @description File uploaded successfully */
398
+ 200: {
399
+ headers: {
400
+ [name: string]: unknown;
401
+ };
402
+ content: {
403
+ "application/json": components["schemas"]["SuccessResponse"];
404
+ };
405
+ };
406
+ /** @description Invalid parameters or upload failed */
407
+ 400: {
408
+ headers: {
409
+ [name: string]: unknown;
410
+ };
411
+ content: {
412
+ "application/json": components["schemas"]["Error"];
413
+ };
414
+ };
415
+ /** @description File too large */
416
+ 413: {
417
+ headers: {
418
+ [name: string]: unknown;
419
+ };
420
+ content: {
421
+ "application/json": components["schemas"]["Error"];
422
+ };
423
+ };
424
+ };
425
+ };
426
+ deleteAppAssets: {
427
+ parameters: {
428
+ query: {
429
+ /**
430
+ * @description Application ID whose assets should be deleted
431
+ * @example my_app
432
+ */
433
+ app_id: string;
434
+ };
435
+ header?: never;
436
+ path?: never;
437
+ cookie?: never;
438
+ };
439
+ requestBody?: never;
440
+ responses: {
441
+ /** @description Assets deleted successfully */
442
+ 200: {
443
+ headers: {
444
+ [name: string]: unknown;
445
+ };
446
+ content: {
447
+ "application/json": components["schemas"]["SuccessResponse"];
448
+ };
449
+ };
450
+ /** @description Invalid app_id or deletion failed */
451
+ 400: {
452
+ headers: {
453
+ [name: string]: unknown;
454
+ };
455
+ content: {
456
+ "application/json": components["schemas"]["Error"];
457
+ };
458
+ };
459
+ };
460
+ };
461
+ drawOnDisplay: {
462
+ parameters: {
463
+ query?: never;
464
+ header?: never;
465
+ path?: never;
466
+ cookie?: never;
467
+ };
468
+ requestBody: {
469
+ content: {
470
+ "application/json": components["schemas"]["DisplayElements"];
471
+ };
472
+ };
473
+ responses: {
474
+ /** @description Drawing command executed successfully */
475
+ 200: {
476
+ headers: {
477
+ [name: string]: unknown;
478
+ };
479
+ content: {
480
+ "application/json": components["schemas"]["SuccessResponse"];
481
+ };
482
+ };
483
+ /** @description Invalid drawing data */
484
+ 400: {
485
+ headers: {
486
+ [name: string]: unknown;
487
+ };
488
+ content: {
489
+ "application/json": components["schemas"]["Error"];
490
+ };
491
+ };
492
+ /** @description Display error */
493
+ 500: {
494
+ headers: {
495
+ [name: string]: unknown;
496
+ };
497
+ content: {
498
+ "application/json": components["schemas"]["Error"];
499
+ };
500
+ };
501
+ };
502
+ };
503
+ clearDisplay: {
504
+ parameters: {
505
+ query?: never;
506
+ header?: never;
507
+ path?: never;
508
+ cookie?: never;
509
+ };
510
+ requestBody?: never;
511
+ responses: {
512
+ /** @description Display cleared successfully */
513
+ 200: {
514
+ headers: {
515
+ [name: string]: unknown;
516
+ };
517
+ content: {
518
+ "application/json": components["schemas"]["SuccessResponse"];
519
+ };
520
+ };
521
+ /** @description Display error */
522
+ 500: {
523
+ headers: {
524
+ [name: string]: unknown;
525
+ };
526
+ content: {
527
+ "application/json": components["schemas"]["Error"];
528
+ };
529
+ };
530
+ };
531
+ };
532
+ playAudio: {
533
+ parameters: {
534
+ query: {
535
+ /**
536
+ * @description Application ID for organizing assets
537
+ * @example my_app
538
+ */
539
+ app_id: string;
540
+ /**
541
+ * @description Path to audio file within app's assets directory
542
+ * @example data.snd
543
+ */
544
+ path: string;
545
+ };
546
+ header?: never;
547
+ path?: never;
548
+ cookie?: never;
549
+ };
550
+ requestBody?: never;
551
+ responses: {
552
+ /** @description Audio playback started successfully */
553
+ 200: {
554
+ headers: {
555
+ [name: string]: unknown;
556
+ };
557
+ content: {
558
+ "application/json": components["schemas"]["SuccessResponse"];
559
+ };
560
+ };
561
+ /** @description Invalid file path or file not found */
562
+ 400: {
563
+ headers: {
564
+ [name: string]: unknown;
565
+ };
566
+ content: {
567
+ "application/json": components["schemas"]["Error"];
568
+ };
569
+ };
570
+ /** @description Audio system error */
571
+ 500: {
572
+ headers: {
573
+ [name: string]: unknown;
574
+ };
575
+ content: {
576
+ "application/json": components["schemas"]["Error"];
577
+ };
578
+ };
579
+ };
580
+ };
581
+ stopAudio: {
582
+ parameters: {
583
+ query?: never;
584
+ header?: never;
585
+ path?: never;
586
+ cookie?: never;
587
+ };
588
+ requestBody?: never;
589
+ responses: {
590
+ /** @description Audio playback stopped successfully */
591
+ 200: {
592
+ headers: {
593
+ [name: string]: unknown;
594
+ };
595
+ content: {
596
+ "application/json": components["schemas"]["SuccessResponse"];
597
+ };
598
+ };
599
+ /** @description Audio system error */
600
+ 500: {
601
+ headers: {
602
+ [name: string]: unknown;
603
+ };
604
+ content: {
605
+ "application/json": components["schemas"]["Error"];
606
+ };
607
+ };
608
+ };
609
+ };
610
+ connectWebSocket: {
611
+ parameters: {
612
+ query?: never;
613
+ header?: never;
614
+ path?: never;
615
+ cookie?: never;
616
+ };
617
+ requestBody?: never;
618
+ responses: {
619
+ /** @description WebSocket connection established */
620
+ 101: {
621
+ headers: {
622
+ [name: string]: unknown;
623
+ };
624
+ content?: never;
625
+ };
626
+ /** @description WebSocket upgrade failed */
627
+ 400: {
628
+ headers: {
629
+ [name: string]: unknown;
630
+ };
631
+ content: {
632
+ "application/json": components["schemas"]["Error"];
633
+ };
634
+ };
635
+ /** @description Upgrade required */
636
+ 426: {
637
+ headers: {
638
+ [name: string]: unknown;
639
+ };
640
+ content: {
641
+ "application/json": components["schemas"]["Error"];
642
+ };
643
+ };
644
+ };
645
+ };
646
+ }
647
+
648
+ declare type OptionalFields = "timeout" | "x" | "y" | "display";
649
+
650
+ /**
651
+ * This file was auto-generated by openapi-typescript.
652
+ * Do not make direct changes to the file.
653
+ */
654
+ declare interface paths {
655
+ "/v0/led": {
656
+ parameters: {
657
+ query?: never;
658
+ header?: never;
659
+ path?: never;
660
+ cookie?: never;
661
+ };
662
+ /**
663
+ * Get LED state
664
+ * @description Retrieves the current LED state
665
+ */
666
+ get: operations["getLedState"];
667
+ put?: never;
668
+ /**
669
+ * Set LED state
670
+ * @description Sets the LED state via query parameter or JSON body
671
+ */
672
+ post: operations["setLedState"];
673
+ delete?: never;
674
+ options?: never;
675
+ head?: never;
676
+ patch?: never;
677
+ trace?: never;
678
+ };
679
+ "/v0/version": {
680
+ parameters: {
681
+ query?: never;
682
+ header?: never;
683
+ path?: never;
684
+ cookie?: never;
685
+ };
686
+ /**
687
+ * Get firmware version information
688
+ * @description Retrieves firmware version, branch, build date, and commit information
689
+ */
690
+ get: operations["getVersion"];
691
+ put?: never;
692
+ post?: never;
693
+ delete?: never;
694
+ options?: never;
695
+ head?: never;
696
+ patch?: never;
697
+ trace?: never;
698
+ };
699
+ "/v0/assets/upload": {
700
+ parameters: {
701
+ query?: never;
702
+ header?: never;
703
+ path?: never;
704
+ cookie?: never;
705
+ };
706
+ get?: never;
707
+ put?: never;
708
+ /**
709
+ * Upload asset file with app ID
710
+ * @description Uploads a file to a specific app's assets directory
711
+ */
712
+ post: operations["uploadAssetWithAppId"];
713
+ /**
714
+ * Delete app assets
715
+ * @description Deletes all assets for a specific app ID
716
+ */
717
+ delete: operations["deleteAppAssets"];
718
+ options?: never;
719
+ head?: never;
720
+ patch?: never;
721
+ trace?: never;
722
+ };
723
+ "/v0/display/draw": {
724
+ parameters: {
725
+ query?: never;
726
+ header?: never;
727
+ path?: never;
728
+ cookie?: never;
729
+ };
730
+ get?: never;
731
+ put?: never;
732
+ /**
733
+ * Draw on display
734
+ * @description Sends drawing data to the display.
735
+ * Supports JSON-defined display elements.
736
+ *
737
+ */
738
+ post: operations["drawOnDisplay"];
739
+ /**
740
+ * Clear display
741
+ * @description Clears the display and stops the Canvas application if running
742
+ */
743
+ delete: operations["clearDisplay"];
744
+ options?: never;
745
+ head?: never;
746
+ patch?: never;
747
+ trace?: never;
748
+ };
749
+ "/v0/audio/play": {
750
+ parameters: {
751
+ query?: never;
752
+ header?: never;
753
+ path?: never;
754
+ cookie?: never;
755
+ };
756
+ get?: never;
757
+ put?: never;
758
+ /**
759
+ * Play audio file
760
+ * @description Plays an audio file from the assets directory.
761
+ * Supported formats include .snd files.
762
+ *
763
+ */
764
+ post: operations["playAudio"];
765
+ /**
766
+ * Stop audio playback
767
+ * @description Stops any currently playing audio
768
+ */
769
+ delete: operations["stopAudio"];
770
+ options?: never;
771
+ head?: never;
772
+ patch?: never;
773
+ trace?: never;
774
+ };
775
+ "/ws_test": {
776
+ parameters: {
777
+ query?: never;
778
+ header?: never;
779
+ path?: never;
780
+ cookie?: never;
781
+ };
782
+ /**
783
+ * WebSocket test endpoint
784
+ * @description WebSocket connection for real-time communication and testing.
785
+ * Upgrade from HTTP to WebSocket protocol is required.
786
+ *
787
+ */
788
+ get: operations["connectWebSocket"];
789
+ put?: never;
790
+ post?: never;
791
+ delete?: never;
792
+ options?: never;
793
+ head?: never;
794
+ patch?: never;
795
+ trace?: never;
796
+ };
797
+ }
798
+
799
+ declare interface UploadParams {
800
+ appId: paths["/v0/assets/upload"]["post"]["parameters"]["query"]["app_id"];
801
+ fileName: paths["/v0/assets/upload"]["post"]["parameters"]["query"]["file"];
802
+ file: Buffer | Blob | File | ArrayBuffer;
803
+ }
804
+
805
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,198 @@
1
+ var s = Object.defineProperty;
2
+ var u = (r, t, e) => t in r ? s(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var f = (r, t, e) => u(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import c from "openapi-fetch";
5
+ function p(r) {
6
+ const t = r.split(".");
7
+ if (t.length !== 4)
8
+ return !1;
9
+ for (const e of t) {
10
+ if (e.length === 0 || e.length > 1 && e[0] === "0" || !/^\d+$/.test(e))
11
+ return !1;
12
+ const i = Number(e);
13
+ if (i < 0 || i > 255)
14
+ return !1;
15
+ }
16
+ return !0;
17
+ }
18
+ const l = (r, t) => {
19
+ if (typeof FormData < "u" && r instanceof FormData || typeof Buffer < "u" && typeof Buffer.isBuffer == "function" && Buffer.isBuffer(r) || typeof File < "u" && r instanceof File || typeof Blob < "u" && r instanceof Blob || typeof ArrayBuffer < "u" && r instanceof ArrayBuffer || typeof ArrayBuffer < "u" && ArrayBuffer.isView && ArrayBuffer.isView(r))
20
+ return r;
21
+ let e;
22
+ return t && (t instanceof Headers ? e = t.get("Content-Type") ?? t.get("content-type") ?? void 0 : typeof t == "object" && (e = t["Content-Type"] ?? t["content-type"]), e === "application/x-www-form-urlencoded") ? r && typeof r == "object" && !(r instanceof URLSearchParams) ? new URLSearchParams(r).toString() : String(r) : JSON.stringify(r);
23
+ };
24
+ let n = null;
25
+ function w(r) {
26
+ n = c({
27
+ baseUrl: r,
28
+ bodySerializer: l
29
+ });
30
+ }
31
+ async function d(r) {
32
+ const { appId: t, fileName: e, file: i } = r;
33
+ if (!n)
34
+ throw new Error("API client is not initialized");
35
+ const { data: a, error: o } = await n.POST("/v0/assets/upload", {
36
+ params: {
37
+ query: {
38
+ app_id: t,
39
+ file: e
40
+ }
41
+ },
42
+ headers: {
43
+ "Content-Type": "application/octet-stream"
44
+ },
45
+ body: i
46
+ });
47
+ if (o)
48
+ throw o;
49
+ return a;
50
+ }
51
+ async function y(r) {
52
+ const { appId: t } = r;
53
+ if (!n)
54
+ throw new Error("API client is not initialized");
55
+ const { data: e, error: i } = await n.DELETE("/v0/assets/upload", {
56
+ params: {
57
+ query: {
58
+ app_id: t
59
+ }
60
+ }
61
+ });
62
+ if (i)
63
+ throw i;
64
+ return e;
65
+ }
66
+ const m = { timeout: 5, x: 0, y: 0, display: "front" };
67
+ function h(r) {
68
+ return { ...m, ...r };
69
+ }
70
+ async function E(r) {
71
+ const { appId: t, elements: e } = r;
72
+ if (!n)
73
+ throw new Error("API client is not initialized");
74
+ const i = e.map(h), { data: a, error: o } = await n.POST("/v0/display/draw", {
75
+ body: {
76
+ app_id: t,
77
+ elements: i
78
+ }
79
+ });
80
+ if (o)
81
+ throw o;
82
+ return a;
83
+ }
84
+ async function A() {
85
+ if (!n)
86
+ throw new Error("API client is not initialized");
87
+ const { data: r, error: t } = await n.DELETE("/v0/display/draw");
88
+ if (t)
89
+ throw t;
90
+ return r;
91
+ }
92
+ async function B(r) {
93
+ const { appId: t, path: e } = r;
94
+ if (!n)
95
+ throw new Error("API client is not initialized");
96
+ const { data: i, error: a } = await n.POST("/v0/audio/play", {
97
+ params: {
98
+ query: {
99
+ app_id: t,
100
+ path: e
101
+ }
102
+ }
103
+ });
104
+ if (a)
105
+ throw a;
106
+ return i;
107
+ }
108
+ async function I() {
109
+ if (!n)
110
+ throw new Error("API client is not initialized");
111
+ const { data: r, error: t } = await n.DELETE("/v0/audio/play");
112
+ if (t)
113
+ throw t;
114
+ return r;
115
+ }
116
+ class T {
117
+ /**
118
+ * Creates an instance of BUSY Bar.
119
+ * Initializes the API client with the provided IPv4 address.
120
+ *
121
+ * @param {IPv4} [ip="10.0.4.20"] - The IPv4 address of the device.
122
+ * @throws {Error} If the provided IP is not a valid IPv4 address.
123
+ */
124
+ constructor(t = "10.0.4.20") {
125
+ /**
126
+ * Device IPv4 address.
127
+ * @type {IPv4}
128
+ * @readonly
129
+ */
130
+ f(this, "ip");
131
+ if (!p(t))
132
+ throw new Error(`Incorrect IPv4: ${t}`);
133
+ this.ip = t, console.log(this.ip), w(`http://${this.ip}/api/`);
134
+ }
135
+ /**
136
+ * Uploads an asset to the device.
137
+ *
138
+ * @param {UploadParams} params - Parameters for the upload.
139
+ * @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
140
+ * @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
141
+ * @param {UploadParams['file']} params.file - File data to upload.
142
+ * @returns {Promise<{ result: string }>} Result of the upload operation.
143
+ */
144
+ async uploadAsset(t) {
145
+ return await d(t);
146
+ }
147
+ /**
148
+ * Deletes all assets for a specific application from the device.
149
+ *
150
+ * @param {DeleteParams} params - Parameters for the delete.
151
+ * @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
152
+ * @returns {Promise<{ result: string }>} Result of the delete operation.
153
+ */
154
+ async deleteAssets(t) {
155
+ return await y(t);
156
+ }
157
+ /**
158
+ * Draws elements on the device display.
159
+ *
160
+ * @param {DrawParams} params - Parameters for the draw operation.
161
+ * @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
162
+ * @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
163
+ * @returns {Promise<{ result: string }>} Result of the draw operation.
164
+ */
165
+ async drawDisplay(t) {
166
+ return await E(t);
167
+ }
168
+ /**
169
+ * Clears the device display and stops the Canvas application if running.
170
+ *
171
+ * @returns {Promise<{ result: string }>} Result of the clear operation.
172
+ */
173
+ async clearDisplay() {
174
+ return await A();
175
+ }
176
+ /**
177
+ * Plays an audio file from the assets directory.
178
+ *
179
+ * @param {AudioParams} params - Parameters for the audio playback.
180
+ * @param {AudioParams['appId']} params.appId - Application ID for organizing assets.
181
+ * @param {AudioParams['path']} params.path - Path to the audio file within the app's assets directory.
182
+ * @returns {Promise<{ result: string }>} Result of the play operation.
183
+ */
184
+ async playSound(t) {
185
+ return await B(t);
186
+ }
187
+ /**
188
+ * Stops any currently playing audio on the device.
189
+ *
190
+ * @returns {Promise<{ result: string }>} Result of the stop operation.
191
+ */
192
+ async stopSound() {
193
+ return await I();
194
+ }
195
+ }
196
+ export {
197
+ T as BusyBar
198
+ };
package/package.json CHANGED
@@ -2,7 +2,10 @@
2
2
  "name": "@busy-app/busy-lib",
3
3
  "private": false,
4
4
  "description": "A library for interacting with the BUSY Bar API",
5
- "version": "0.0.1",
5
+ "version": "0.0.2",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
6
9
  "type": "module",
7
10
  "main": "dist/index.cjs",
8
11
  "module": "dist/index.js",
@@ -17,10 +20,6 @@
17
20
  "files": [
18
21
  "dist"
19
22
  ],
20
- "scripts": {
21
- "build": "vite build",
22
- "docs:generate": "typedoc"
23
- },
24
23
  "dependencies": {
25
24
  "openapi-fetch": "^0.14.0"
26
25
  },
@@ -34,7 +33,10 @@
34
33
  "vite-tsconfig-paths": "^5.1.4"
35
34
  },
36
35
  "engines": {
37
- "node": "22.15.1"
36
+ "node": ">=18"
38
37
  },
39
- "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
40
- }
38
+ "scripts": {
39
+ "build": "vite build",
40
+ "docs:generate": "typedoc"
41
+ }
42
+ }