@busy-app/busy-lib 0.6.0 → 0.8.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.
package/dist/index.js CHANGED
@@ -1,1062 +1,1563 @@
1
- var T = Object.defineProperty;
2
- var P = (e, t, i) => t in e ? T(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var o = (e, t, i) => P(e, typeof t != "symbol" ? t + "" : t, i);
4
- import v from "openapi-fetch";
5
- const b = (e, t) => {
1
+ var D = Object.defineProperty;
2
+ var O = (e, t, n) => t in e ? D(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var u = (e, t, n) => O(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import b from "openapi-fetch";
5
+ const U = (e, t) => {
6
6
  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))
7
7
  return e;
8
- let i;
9
- return t && (t instanceof Headers ? i = t.get("Content-Type") ?? t.get("content-type") ?? void 0 : typeof t == "object" && (i = t["Content-Type"] ?? t["content-type"]), i === "application/x-www-form-urlencoded") ? e && typeof e == "object" && !(e instanceof URLSearchParams) ? new URLSearchParams(e).toString() : String(e) : JSON.stringify(e);
8
+ let n;
9
+ return t && (t instanceof Headers ? n = t.get("Content-Type") ?? t.get("content-type") ?? void 0 : typeof t == "object" && (n = t["Content-Type"] ?? t["content-type"]), n === "application/x-www-form-urlencoded") ? e && typeof e == "object" && !(e instanceof URLSearchParams) ? new URLSearchParams(e).toString() : String(e) : JSON.stringify(e);
10
10
  };
11
- let y, w, h = null;
12
- async function A() {
13
- if (!w) {
14
- if (!y)
11
+ let m, h, y = null;
12
+ async function G() {
13
+ if (!h) {
14
+ if (!m)
15
15
  throw new Error("getApiVersionFn is not set");
16
- h || (h = (async () => {
17
- const e = await y();
16
+ y || (y = (async () => {
17
+ const e = await m();
18
18
  if (!e.api_semver)
19
19
  throw new Error("Empty API version");
20
- w = e.api_semver;
20
+ h = e.api_semver;
21
21
  })().finally(() => {
22
- h = null;
23
- })), await h;
22
+ y = null;
23
+ })), await y;
24
24
  }
25
25
  }
26
26
  async function p(e) {
27
- const n = (e.headers.get("content-type") || "").includes("application/json") ? await e.clone().json() : await e.clone().text(), s = typeof n == "object" && n !== null ? n.error || n.message : typeof n == "string" ? n : void 0;
27
+ const i = (e.headers.get("content-type") || "").includes("application/json") ? await e.clone().json() : await e.clone().text(), r = typeof i == "object" && i !== null ? i.error || i.message : typeof i == "string" ? i : void 0;
28
28
  return Object.assign(
29
- new Error(s || `HTTP ${e.status} ${e.statusText}`),
29
+ new Error(r || `HTTP ${e.status} ${e.statusText}`),
30
30
  {
31
31
  status: e.status,
32
32
  statusText: e.statusText,
33
- body: n
33
+ body: i
34
34
  }
35
35
  );
36
36
  }
37
- let m;
38
- function I(e) {
39
- m = e;
40
- }
41
- let d;
37
+ let l;
42
38
  const B = {
43
39
  async onRequest({ request: e, schemaPath: t }) {
44
- return d && e.headers.set("Authorization", `Bearer ${d}`), t !== "/version" && (await A(), w && e.headers.set("X-API-Sem-Ver", w), m && e.headers.set("X-API-Token", m)), e;
40
+ return l && e.headers.set("Authorization", `Bearer ${l}`), t !== "/version" && (await G(), h && e.headers.set("X-API-Sem-Ver", h)), e;
45
41
  },
46
- async onResponse({ request: e, response: t, options: i, schemaPath: n }) {
42
+ async onResponse({ request: e, response: t, options: n, schemaPath: i }) {
47
43
  if (t.ok)
48
44
  return t;
49
- if (n === "/version")
45
+ if (i === "/version")
50
46
  throw await p(t);
51
47
  if (t.status !== 405)
52
48
  throw await p(t);
53
- w = void 0, await A(), w && e.headers.set("X-API-Sem-Ver", w), d && e.headers.set("Authorization", `Bearer ${d}`);
54
- const s = await (i.fetch ?? fetch)(e);
55
- if (s.ok)
56
- return s;
57
- throw await p(s);
49
+ h = void 0, await G(), h && e.headers.set("X-API-Sem-Ver", h), l && e.headers.set("Authorization", `Bearer ${l}`);
50
+ const r = await (n.fetch ?? fetch)(e);
51
+ if (r.ok)
52
+ return r;
53
+ throw await p(r);
58
54
  }
59
55
  };
60
- let r = null;
61
- function z(e, t, i) {
62
- y = t, d = i ?? void 0, r = v({
56
+ let S = null;
57
+ function C(e, t, n) {
58
+ m = t, l = n ?? void 0, S = b({
63
59
  baseUrl: e,
64
- bodySerializer: b
65
- }), r.use(B);
66
- }
67
- async function L() {
68
- if (!r)
69
- throw new Error("API client is not initialized");
70
- const { data: e, error: t } = await r.GET("/account");
71
- if (t)
72
- throw t;
73
- return e;
60
+ bodySerializer: U
61
+ }), S.use(B);
74
62
  }
75
- async function D() {
76
- if (!r)
63
+ function o() {
64
+ if (!S)
77
65
  throw new Error("API client is not initialized");
78
- const { data: e, error: t } = await r.DELETE("/account");
79
- if (t)
80
- throw t;
81
- return e;
66
+ return S;
82
67
  }
83
- async function O() {
84
- if (!r)
85
- throw new Error("API client is not initialized");
86
- const { data: e, error: t } = await r.POST("/account/link");
87
- if (t)
88
- throw t;
89
- return e;
68
+ async function s(e, t = 3e3) {
69
+ if (t <= 0)
70
+ return await e();
71
+ const n = new AbortController(), i = setTimeout(() => n.abort(), t);
72
+ try {
73
+ return await e(n.signal);
74
+ } catch (r) {
75
+ throw r instanceof DOMException && r.name === "AbortError" ? new Error(`Request timed out after ${t}ms`) : r;
76
+ } finally {
77
+ clearTimeout(i);
78
+ }
90
79
  }
91
- async function W(e) {
92
- const { appId: t, fileName: i, file: n } = e;
93
- if (!r)
94
- throw new Error("API client is not initialized");
95
- const { data: s, error: a } = await r.POST("/assets/upload", {
96
- params: {
97
- query: {
98
- app_id: t,
99
- file: i
100
- }
101
- },
102
- headers: {
103
- "Content-Type": "application/octet-stream"
104
- },
105
- body: n
106
- });
107
- if (a)
108
- throw a;
109
- return s;
80
+ async function I(e) {
81
+ const t = o(), { data: n, error: i } = await s(
82
+ (r) => t.GET("/version", { signal: r }),
83
+ e == null ? void 0 : e.timeout
84
+ );
85
+ if (i)
86
+ throw i;
87
+ return n;
110
88
  }
111
- async function C(e) {
112
- const { appId: t } = e;
113
- if (!r)
114
- throw new Error("API client is not initialized");
115
- const { data: i, error: n } = await r.DELETE("/assets/upload", {
116
- params: {
117
- query: {
118
- app_id: t
119
- }
120
- }
121
- });
122
- if (n)
123
- throw n;
124
- return i;
89
+ async function $(e) {
90
+ const t = o(), { data: n, error: i } = await s(
91
+ (r) => t.GET("/status", { signal: r }),
92
+ e == null ? void 0 : e.timeout
93
+ );
94
+ if (i)
95
+ throw i;
96
+ return n;
125
97
  }
126
98
  async function R(e) {
127
- if (!r)
128
- throw new Error("API client is not initialized");
129
- const { appId: t, elements: i } = e, { data: n, error: s } = await r.POST("/display/draw", {
130
- body: {
131
- app_id: t,
132
- elements: i
133
- }
134
- });
135
- if (s)
136
- throw s;
99
+ const t = o(), { data: n, error: i } = await s(
100
+ (r) => t.GET("/status/system", { signal: r }),
101
+ e == null ? void 0 : e.timeout
102
+ );
103
+ if (i)
104
+ throw i;
137
105
  return n;
138
106
  }
139
- async function U() {
140
- if (!r)
141
- throw new Error("API client is not initialized");
142
- const { data: e, error: t } = await r.DELETE("/display/draw");
143
- if (t)
144
- throw t;
145
- return e;
146
- }
147
- async function K(e) {
148
- const { appId: t, path: i } = e;
149
- if (!r)
150
- throw new Error("API client is not initialized");
151
- const { data: n, error: s } = await r.POST("/audio/play", {
152
- params: {
153
- query: {
154
- app_id: t,
155
- path: i
156
- }
157
- }
158
- });
159
- if (s)
160
- throw s;
107
+ async function W(e) {
108
+ const t = o(), { data: n, error: i } = await s(
109
+ (r) => t.GET("/status/power", { signal: r }),
110
+ e == null ? void 0 : e.timeout
111
+ );
112
+ if (i)
113
+ throw i;
161
114
  return n;
162
115
  }
163
- async function $() {
164
- if (!r)
165
- throw new Error("API client is not initialized");
166
- const { data: e, error: t } = await r.DELETE("/audio/play");
167
- if (t)
168
- throw t;
169
- return e;
170
- }
171
- async function _() {
172
- if (!r)
173
- throw new Error("API client is not initialized");
174
- const { data: e, error: t } = await r.GET("/wifi/status");
175
- if (t)
176
- throw t;
177
- return e;
116
+ class N {
117
+ /**
118
+ * Get API version information.
119
+ *
120
+ * @param {TimeoutOptions} [params] - Optional parameters.
121
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
122
+ * @returns {Promise<VersionInfo>} A promise that resolves to an object containing the `api_semver` string.
123
+ */
124
+ async SystemVersionGet(t) {
125
+ const n = await I(t);
126
+ return this.apiSemver = n.api_semver, n;
127
+ }
128
+ /**
129
+ * @deprecated Use `SystemVersionGet` instead. will be removed in the next release.
130
+ */
131
+ async SystemVersion(t) {
132
+ return this.SystemVersionGet(t);
133
+ }
134
+ /**
135
+ * Get device status.
136
+ *
137
+ * @param {TimeoutOptions} [params] - Optional parameters.
138
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
139
+ * @returns {Promise<Status>} Current status of the device.
140
+ */
141
+ async SystemStatusGet(t) {
142
+ return await $(t);
143
+ }
144
+ /**
145
+ * @deprecated Use `SystemStatusGet` instead. will be removed in the next release.
146
+ */
147
+ async SystemStatus(t) {
148
+ return this.SystemStatusGet(t);
149
+ }
150
+ /**
151
+ * Get system status.
152
+ *
153
+ * @param {TimeoutOptions} [params] - Optional parameters.
154
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
155
+ * @returns {Promise<StatusSystem>} Current system status.
156
+ */
157
+ async SystemInfoGet(t) {
158
+ return await R(t);
159
+ }
160
+ /**
161
+ * @deprecated Use `SystemInfoGet` instead. will be removed in the next release.
162
+ */
163
+ async SystemInfo(t) {
164
+ return this.SystemInfoGet(t);
165
+ }
166
+ /**
167
+ * Get power status.
168
+ *
169
+ * @param {TimeoutOptions} [params] - Optional parameters.
170
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
171
+ * @returns {Promise<StatusPower>} Current power status.
172
+ */
173
+ async SystemStatusPowerGet(t) {
174
+ return await W(t);
175
+ }
176
+ /**
177
+ * @deprecated Use `SystemStatusPowerGet` instead. will be removed in the next release.
178
+ */
179
+ async SystemStatusPower(t) {
180
+ return this.SystemStatusPowerGet(t);
181
+ }
178
182
  }
179
- async function F(e) {
180
- if (!r)
181
- throw new Error("API client is not initialized");
182
- const { data: t, error: i } = await r.POST("/wifi/connect", {
183
- body: {
184
- ssid: e.ssid,
185
- password: e.password,
186
- security: e.security,
187
- ip_config: {
188
- ip_method: e.ipConfig.ipMethod,
189
- address: e.ipConfig.address,
190
- mask: e.ipConfig.mask,
191
- gateway: e.ipConfig.gateway
192
- }
193
- }
194
- });
183
+ async function M(e) {
184
+ const t = o(), { data: n, error: i } = await s(
185
+ (r) => t.POST("/update/check", { signal: r }),
186
+ e == null ? void 0 : e.timeout
187
+ );
195
188
  if (i)
196
189
  throw i;
197
- return t;
198
- }
199
- async function G() {
200
- if (!r)
201
- throw new Error("API client is not initialized");
202
- const { data: e, error: t } = await r.POST("/wifi/disconnect");
203
- if (t)
204
- throw t;
205
- return e;
206
- }
207
- async function N() {
208
- if (!r)
209
- throw new Error("API client is not initialized");
210
- const { data: e, error: t } = await r.GET("/wifi/networks");
211
- if (t)
212
- throw t;
213
- return e;
214
- }
215
- async function V(e) {
216
- if (!r)
217
- throw new Error("API client is not initialized");
218
- const { path: t, file: i } = e, { data: n, error: s } = await r.POST("/storage/write", {
219
- params: {
220
- query: {
221
- path: t
222
- }
223
- },
224
- headers: {
225
- "Content-Type": "application/octet-stream"
226
- },
227
- body: i
228
- });
229
- if (s)
230
- throw s;
231
190
  return n;
232
191
  }
233
- async function q(e) {
234
- if (!r)
235
- throw new Error("API client is not initialized");
236
- const { path: t, asArrayBuffer: i } = e, { data: n, error: s } = await r.GET("/storage/read", {
237
- params: {
238
- query: {
239
- path: t
240
- }
241
- },
242
- parseAs: i ? "arrayBuffer" : "blob"
243
- });
244
- if (s)
245
- throw s;
192
+ async function V(e) {
193
+ const t = o(), { data: n, error: i } = await s(
194
+ (r) => t.GET("/update/status", { signal: r }),
195
+ e == null ? void 0 : e.timeout
196
+ );
197
+ if (i)
198
+ throw i;
246
199
  return n;
247
200
  }
248
- async function x(e) {
249
- if (!r)
250
- throw new Error("API client is not initialized");
251
- const { path: t } = e, { data: i, error: n } = await r.GET("/storage/list", {
252
- params: {
253
- query: {
254
- path: t
255
- }
256
- }
257
- });
258
- if (n)
259
- throw n;
260
- return i;
261
- }
262
- async function j(e) {
263
- if (!r)
264
- throw new Error("API client is not initialized");
265
- const { path: t } = e, { data: i, error: n } = await r.DELETE("/storage/remove", {
266
- params: {
267
- query: {
268
- path: t
269
- }
270
- }
271
- });
272
- if (n)
273
- throw n;
201
+ async function K(e) {
202
+ const t = o(), { version: n } = e, { data: i, error: r } = await s(
203
+ (c) => t.GET("/update/changelog", {
204
+ params: {
205
+ query: {
206
+ version: n
207
+ }
208
+ },
209
+ signal: c
210
+ }),
211
+ e.timeout
212
+ );
213
+ if (r)
214
+ throw r;
274
215
  return i;
275
216
  }
276
- async function H(e) {
277
- if (!r)
278
- throw new Error("API client is not initialized");
279
- const { path: t } = e, { data: i, error: n } = await r.POST("/storage/mkdir", {
280
- params: {
281
- query: {
282
- path: t
283
- }
284
- }
285
- });
286
- if (n)
287
- throw n;
217
+ async function x(e) {
218
+ const t = o(), { version: n } = e, { data: i, error: r } = await s(
219
+ (c) => t.POST("/update/install", {
220
+ params: {
221
+ query: {
222
+ version: n
223
+ }
224
+ },
225
+ signal: c
226
+ }),
227
+ e.timeout
228
+ );
229
+ if (r)
230
+ throw r;
288
231
  return i;
289
232
  }
290
- async function J() {
291
- if (!r)
292
- throw new Error("API client is not initialized");
293
- const { data: e, error: t } = await r.GET("/storage/status");
294
- if (t)
295
- throw t;
296
- return e;
233
+ async function _(e) {
234
+ const t = o(), { data: n, error: i } = await s(
235
+ (r) => t.POST("/update/abort_download", { signal: r }),
236
+ e == null ? void 0 : e.timeout
237
+ );
238
+ if (i)
239
+ throw i;
240
+ return n;
297
241
  }
298
- async function X() {
299
- if (!r)
300
- throw new Error("API client is not initialized");
301
- const { data: e, error: t } = await r.GET("/version");
302
- if (t)
303
- throw t;
304
- return e;
242
+ class F {
243
+ /**
244
+ * Start firmware update check.
245
+ *
246
+ * @param {TimeoutOptions} [params] - Optional parameters.
247
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
248
+ * @returns {Promise<SuccessResponse>} A promise that resolves to the update check result.
249
+ */
250
+ async UpdateCheck(t) {
251
+ return await M(t);
252
+ }
253
+ /**
254
+ * @deprecated Use `UpdateCheck` instead. will be removed in the next release.
255
+ */
256
+ async SystemUpdateCheck(t) {
257
+ return this.UpdateCheck(t);
258
+ }
259
+ /**
260
+ * Get firmware update status.
261
+ *
262
+ * @param {TimeoutOptions} [params] - Optional parameters.
263
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
264
+ * @returns {Promise<UpdateStatus>} A promise that resolves to the update status.
265
+ */
266
+ async UpdateStatusGet(t) {
267
+ return await V(t);
268
+ }
269
+ /**
270
+ * @deprecated Use `UpdateStatusGet` instead. will be removed in the next release.
271
+ */
272
+ async SystemUpdateStatus(t) {
273
+ return this.UpdateStatusGet(t);
274
+ }
275
+ /**
276
+ * Get firmware update changelog.
277
+ *
278
+ * @param {ChangelogParams} params - Parameters for the changelog request.
279
+ * @param {string} params.version - Version string to get the changelog for.
280
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
281
+ * @returns {Promise<UpdateChangelog>} A promise that resolves to the changelog content.
282
+ */
283
+ async UpdateChangelogGet(t) {
284
+ return await K(t);
285
+ }
286
+ /**
287
+ * @deprecated Use `UpdateChangelogGet` instead. will be removed in the next release.
288
+ */
289
+ async SystemUpdateChangelog(t) {
290
+ return this.UpdateChangelogGet(t);
291
+ }
292
+ /**
293
+ * Start firmware update installation.
294
+ *
295
+ * @param {InstallParams} params - Parameters for the installation.
296
+ * @param {string} params.version - Version string to install.
297
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
298
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful initiation.
299
+ */
300
+ async UpdateInstall(t) {
301
+ return await x(t);
302
+ }
303
+ /**
304
+ * Abort firmware update download.
305
+ *
306
+ * @param {TimeoutOptions} [params] - Optional parameters.
307
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
308
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful abort.
309
+ */
310
+ async UpdateAbort(t) {
311
+ return await _(t);
312
+ }
305
313
  }
306
- async function M(e) {
307
- if (!r)
308
- throw new Error("API client is not initialized");
309
- const { name: t, file: i } = e, { data: n, error: s } = await r.POST("/update", {
310
- params: {
311
- query: {
312
- name: t
313
- }
314
- },
315
- headers: {
316
- "Content-Type": "application/octet-stream"
317
- },
318
- body: i
319
- });
320
- if (s)
321
- throw s;
314
+ async function q(e) {
315
+ const t = o(), { data: n, error: i } = await s(
316
+ (r) => t.GET("/time", { signal: r }),
317
+ e == null ? void 0 : e.timeout
318
+ );
319
+ if (i)
320
+ throw i;
322
321
  return n;
323
322
  }
324
- async function Q() {
325
- if (!r)
326
- throw new Error("API client is not initialized");
327
- const { data: e, error: t } = await r.GET("/status");
328
- if (t)
329
- throw t;
330
- return e;
323
+ async function j(e) {
324
+ const t = o(), { data: n, error: i } = await s(
325
+ (r) => t.POST("/time/timestamp", {
326
+ params: {
327
+ query: { ...e, timeout: void 0 }
328
+ },
329
+ signal: r
330
+ }),
331
+ e.timeout
332
+ );
333
+ if (i)
334
+ throw i;
335
+ return n;
331
336
  }
332
- async function Y() {
333
- if (!r)
334
- throw new Error("API client is not initialized");
335
- const { data: e, error: t } = await r.GET("/status/system");
336
- if (t)
337
- throw t;
338
- return e;
337
+ async function z(e) {
338
+ const t = o(), { data: n, error: i } = await s(
339
+ (r) => t.POST("/time/timezone", {
340
+ params: {
341
+ query: { ...e, timeout: void 0 }
342
+ },
343
+ signal: r
344
+ }),
345
+ e.timeout
346
+ );
347
+ if (i)
348
+ throw i;
349
+ return n;
339
350
  }
340
- async function Z() {
341
- if (!r)
342
- throw new Error("API client is not initialized");
343
- const { data: e, error: t } = await r.GET("/status/power");
344
- if (t)
345
- throw t;
346
- return e;
351
+ async function H(e) {
352
+ const t = o(), { data: n, error: i } = await s(
353
+ (r) => t.GET("/time/tzlist", { signal: r }),
354
+ e == null ? void 0 : e.timeout
355
+ );
356
+ if (i)
357
+ throw i;
358
+ return n;
347
359
  }
348
- async function tt() {
349
- if (!r)
350
- throw new Error("API client is not initialized");
351
- const { data: e, error: t } = await r.GET("/time");
352
- if (t)
353
- throw t;
354
- return e;
360
+ class J {
361
+ /**
362
+ * Get current timestamp info.
363
+ *
364
+ * @param {TimeoutOptions} [params] - Optional parameters.
365
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
366
+ * @returns {Promise<TimestampInfo>} A promise that resolves to the timestamp information.
367
+ */
368
+ async TimeGet(t) {
369
+ return await q(t);
370
+ }
371
+ /**
372
+ * @deprecated Use `TimeGet` instead. will be removed in the next release.
373
+ */
374
+ async SystemTime(t) {
375
+ return await this.TimeGet(t);
376
+ }
377
+ /**
378
+ * Set system timestamp.
379
+ *
380
+ * @param {SetTimestampParams} params - Parameters for setting the timestamp.
381
+ * @param {number} params.timestamp - Unix timestamp to set.
382
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
383
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
384
+ */
385
+ async TimeTimestampSet(t) {
386
+ return await j(t);
387
+ }
388
+ /**
389
+ * @deprecated Use `TimeTimestampSet` instead. will be removed in the next release.
390
+ */
391
+ async SystemTimeTimestamp(t) {
392
+ return await this.TimeTimestampSet(t);
393
+ }
394
+ /**
395
+ * Set system timezone.
396
+ *
397
+ * @param {SetTimezoneParams} params - Parameters for setting the timezone.
398
+ * @param {string} params.timezone - Timezone string to set (e.g., "Europe/Moscow").
399
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
400
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
401
+ */
402
+ async TimeTimezoneSet(t) {
403
+ return await z(t);
404
+ }
405
+ /**
406
+ * @deprecated Use `TimeTimezoneSet` instead. will be removed in the next release.
407
+ */
408
+ async SystemTimeTimezone(t) {
409
+ return await this.TimeTimezoneSet(t);
410
+ }
411
+ /**
412
+ * Get list of supported timezones.
413
+ *
414
+ * @param {TimeoutOptions} [params] - Optional parameters.
415
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
416
+ * @returns {Promise<TimezoneList>} A promise that resolves to a list of timezone items.
417
+ */
418
+ async TimeTzListGet(t) {
419
+ return await H(t);
420
+ }
421
+ /**
422
+ * @deprecated Use `TimeTzListGet` instead. will be removed in the next release.
423
+ */
424
+ async SystemTimeTzList(t) {
425
+ return await this.TimeTzListGet(t);
426
+ }
355
427
  }
356
- async function et(e) {
357
- if (!r)
358
- throw new Error("API client is not initialized");
359
- const { data: t, error: i } = await r.POST("/time/timestamp", {
360
- params: {
361
- query: e
362
- }
363
- });
428
+ async function X(e) {
429
+ const t = o(), { data: n, error: i } = await s(
430
+ (r) => t.GET("/account/status", { signal: r }),
431
+ e == null ? void 0 : e.timeout
432
+ );
364
433
  if (i)
365
434
  throw i;
366
- return t;
435
+ return n;
367
436
  }
368
- async function it(e) {
369
- if (!r)
370
- throw new Error("API client is not initialized");
371
- const { data: t, error: i } = await r.POST("/time/timezone", {
372
- params: {
373
- query: e
374
- }
375
- });
437
+ async function Q(e) {
438
+ const t = o(), { data: n, error: i } = await s(
439
+ (r) => t.GET("/account/info", { signal: r }),
440
+ e == null ? void 0 : e.timeout
441
+ );
376
442
  if (i)
377
443
  throw i;
378
- return t;
379
- }
380
- async function rt() {
381
- if (!r)
382
- throw new Error("API client is not initialized");
383
- const { data: e, error: t } = await r.GET("/display/brightness");
384
- if (t)
385
- throw t;
386
- return e;
387
- }
388
- async function nt(e) {
389
- if (!r)
390
- throw new Error("API client is not initialized");
391
- const { front: t, back: i } = e, n = (u) => {
392
- if (typeof u == "number") {
393
- if (u < 0 || u > 100)
394
- throw new Error("Brightness value must be between 0 and 100 or 'auto'");
395
- return String(u);
396
- }
397
- if (u === "auto")
398
- return "auto";
399
- }, s = n(t), a = n(i), { data: c, error: f } = await r.POST("/display/brightness", {
400
- params: {
401
- query: {
402
- front: s,
403
- back: a
404
- }
405
- }
406
- });
407
- if (f)
408
- throw f;
409
- return c;
444
+ return n;
410
445
  }
411
- async function st() {
412
- if (!r)
413
- throw new Error("API client is not initialized");
414
- const { data: e, error: t } = await r.GET("/audio/volume");
415
- if (t)
416
- throw t;
417
- return e;
446
+ async function Y(e) {
447
+ const t = o(), { data: n, error: i } = await s(
448
+ (r) => t.GET("/account/profile", { signal: r }),
449
+ e == null ? void 0 : e.timeout
450
+ );
451
+ if (i)
452
+ throw i;
453
+ return n;
418
454
  }
419
- async function ot(e) {
420
- if (!r)
421
- throw new Error("API client is not initialized");
422
- const { volume: t } = e;
423
- if (typeof t != "number" || t < 0 || t > 100)
424
- throw new Error("Volume must be a number between 0 and 100");
425
- const { data: i, error: n } = await r.POST("/audio/volume", {
426
- params: {
427
- query: {
428
- volume: t
429
- }
430
- }
431
- });
432
- if (n)
433
- throw n;
455
+ async function Z(e) {
456
+ const t = o(), { profile: n } = e, { data: i, error: r } = await s(
457
+ (c) => t.POST("/account/profile", {
458
+ params: {
459
+ query: {
460
+ profile: n
461
+ }
462
+ },
463
+ signal: c
464
+ }),
465
+ e.timeout
466
+ );
467
+ if (r)
468
+ throw r;
434
469
  return i;
435
470
  }
436
- async function at() {
437
- if (!r)
438
- throw new Error("API client is not initialized");
439
- const { data: e, error: t } = await r.GET("/access");
440
- if (t)
441
- throw t;
442
- return e;
443
- }
444
- async function ct(e) {
445
- if (!r)
446
- throw new Error("API client is not initialized");
447
- const { mode: t, key: i } = e;
448
- if (!/^\d{4,10}$/.test(String(i)))
449
- throw new Error("Key must be a string of 4 to 10 digits");
450
- const { data: n, error: s } = await r.POST("/access", {
451
- params: {
452
- query: {
453
- mode: t,
454
- key: i
455
- }
456
- }
457
- });
458
- if (s)
459
- throw s;
471
+ async function tt(e) {
472
+ const t = o(), { data: n, error: i } = await s(
473
+ (r) => t.DELETE("/account", { signal: r }),
474
+ e == null ? void 0 : e.timeout
475
+ );
476
+ if (i)
477
+ throw i;
460
478
  return n;
461
479
  }
462
- async function ft() {
463
- if (!r)
464
- throw new Error("API client is not initialized");
465
- const { data: e, error: t } = await r.GET("/name");
466
- if (t)
467
- throw t;
468
- return e;
469
- }
470
- async function ut(e) {
471
- if (!r)
472
- throw new Error("API client is not initialized");
473
- const { data: t, error: i } = await r.POST("/name", {
474
- body: e
475
- });
480
+ async function et(e) {
481
+ const t = o(), { data: n, error: i } = await s(
482
+ (r) => t.POST("/account/link", { signal: r }),
483
+ e == null ? void 0 : e.timeout
484
+ );
476
485
  if (i)
477
486
  throw i;
478
- return t;
479
- }
480
- async function wt() {
481
- if (!r)
482
- throw new Error("API client is not initialized");
483
- const { data: e, error: t } = await r.POST("/ble/enable");
484
- if (t)
485
- throw t;
486
- return e;
487
- }
488
- async function dt() {
489
- if (!r)
490
- throw new Error("API client is not initialized");
491
- const { data: e, error: t } = await r.POST("/ble/disable");
492
- if (t)
493
- throw t;
494
- return e;
495
- }
496
- async function ht() {
497
- if (!r)
498
- throw new Error("API client is not initialized");
499
- const { data: e, error: t } = await r.DELETE("/ble/pairing");
500
- if (t)
501
- throw t;
502
- return e;
503
- }
504
- async function lt() {
505
- if (!r)
506
- throw new Error("API client is not initialized");
507
- const { data: e, error: t } = await r.GET("/ble/status");
508
- if (t)
509
- throw t;
510
- return e;
511
- }
512
- async function pt(e) {
513
- if (!r)
514
- throw new Error("API client is not initialized");
515
- const { keyName: t } = e, { data: i, error: n } = await r.POST("/input", {
516
- params: {
517
- query: {
518
- key: t
519
- }
520
- }
521
- });
522
- if (n)
523
- throw n;
524
- return i;
487
+ return n;
525
488
  }
526
- const yt = "http://10.0.4.20", mt = "https://proxy.busy.app", Et = /^https?:\/\/proxy(?:\.(?:dev|test|stage))?\.busy\.app$/i;
527
- class Tt {
489
+ class nt {
528
490
  /**
529
- * Creates an instance of BUSY Bar.
530
- * Initializes the API client with the provided host address.
491
+ * Get account info.
531
492
  *
532
- * @param {BusyBarConfig} config - BUSY Bar connection configuration
533
- * @param {BusyBarConfig['addr']} config.addr -
534
- * The device address or proxy endpoint.
493
+ * @param {TimeoutOptions} [params] - Optional parameters.
494
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
495
+ * @returns {Promise<AccountInfo>} A promise that resolves to the account information.
496
+ */
497
+ async AccountInfoGet(t) {
498
+ return await Q(t);
499
+ }
500
+ /**
501
+ * @deprecated Use `AccountInfoGet` instead. will be removed in the next release.
502
+ */
503
+ async Account(t) {
504
+ return this.AccountInfoGet(t);
505
+ }
506
+ /**
507
+ * Get account state.
535
508
  *
536
- * Can be:
537
- * - An IP address (e.g. `192.168.0.10`)
538
- * - An mDNS hostname (e.g. `busybar.local`)
539
- * - A domain name
540
- * - A full URL (`http://` or `https://`)
509
+ * @param {TimeoutOptions} [params] - Optional parameters.
510
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
511
+ * @returns {Promise<AccountState>} A promise that resolves to the account state.
512
+ */
513
+ async AccountStateGet(t) {
514
+ return await X(t);
515
+ }
516
+ /**
517
+ * Get account profile.
541
518
  *
542
- * If no protocol is specified, `http://` will be automatically added.
519
+ * @param {TimeoutOptions} [params] - Optional parameters.
520
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
521
+ * @returns {Promise<AccountProfile>} A promise that resolves to the account profile.
522
+ */
523
+ async AccountProfileGet(t) {
524
+ return await Y(t);
525
+ }
526
+ /**
527
+ * Set account profile.
543
528
  *
544
- * @param {BusyBarConfig['token']} config.token -
545
- * Optional authentication token.
529
+ * @param {SetAccountProfileParams} params - Parameters for setting the account profile.
530
+ * @param {string} params.profile - Profile data string.
531
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
532
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
533
+ */
534
+ async AccountProfileSet(t) {
535
+ return await Z(t);
536
+ }
537
+ /**
538
+ * Unlink device from account. Removes association with the current account.
546
539
  *
547
- * Must be provided when `addr` points to a secured proxy endpoint
548
- * such as `https://proxy.busy.app`.
540
+ * @param {TimeoutOptions} [params] - Optional parameters.
541
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
542
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful unlinking.
549
543
  */
550
- constructor(t) {
551
- /**
552
- * Device host address (IP or mDNS).
553
- * @type {BusyBarConfig['host']}
554
- * @readonly
555
- */
556
- o(this, "addr");
557
- /**
558
- * Current API semantic version.
559
- * @type {ApiSemver}
560
- */
561
- o(this, "apiSemver");
562
- if (!t || !t.addr && !t.token)
563
- this.addr = yt;
564
- else if (!t.addr)
565
- this.addr = mt;
566
- else {
567
- let i = t.addr.trim();
568
- if (/^https?:\/\//i.test(i) || (i = `http://${i}`), Et.test(i) && !t.token)
569
- throw new Error("Token is required. Please provide it.");
570
- this.addr = i;
544
+ async AccountUnlink(t) {
545
+ return await tt(t);
546
+ }
547
+ /**
548
+ * Link device to account. Requests account link PIN. Works only if device is connected to MQTT and is not linked to account.
549
+ *
550
+ * @param {TimeoutOptions} [params] - Optional parameters.
551
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
552
+ * @returns {Promise<AccountLink>} A promise that resolves to the link information (e.g., PIN).
553
+ */
554
+ async AccountLink(t) {
555
+ return await et(t);
556
+ }
557
+ }
558
+ async function it(e) {
559
+ const t = o(), { appId: n, elements: i } = e, { data: r, error: c } = await s(
560
+ (a) => t.POST("/display/draw", {
561
+ body: {
562
+ app_id: n,
563
+ elements: i
564
+ },
565
+ signal: a
566
+ }),
567
+ e.timeout
568
+ );
569
+ if (c)
570
+ throw c;
571
+ return r;
572
+ }
573
+ async function rt(e) {
574
+ const t = o(), { data: n, error: i } = await s(
575
+ (r) => t.DELETE("/display/draw", { signal: r }),
576
+ e == null ? void 0 : e.timeout
577
+ );
578
+ if (i)
579
+ throw i;
580
+ return n;
581
+ }
582
+ async function ot(e) {
583
+ const t = o(), { display: n } = e, { data: i, error: r } = await s(
584
+ (c) => t.GET("/screen", {
585
+ params: {
586
+ query: {
587
+ display: n
588
+ }
589
+ },
590
+ parseAs: "blob",
591
+ signal: c
592
+ }),
593
+ e.timeout
594
+ );
595
+ if (r)
596
+ throw r;
597
+ return i;
598
+ }
599
+ async function st(e) {
600
+ const t = o(), { data: n, error: i } = await s(
601
+ (r) => t.GET("/display/brightness", { signal: r }),
602
+ e == null ? void 0 : e.timeout
603
+ );
604
+ if (i)
605
+ throw i;
606
+ return n;
607
+ }
608
+ async function ct(e) {
609
+ const t = o(), { front: n, back: i } = e, r = (d) => {
610
+ if (typeof d == "number") {
611
+ if (d < 0 || d > 100)
612
+ throw new Error("Brightness value must be between 0 and 100 or 'auto'");
613
+ return String(d);
571
614
  }
572
- this.apiSemver = "", z(
573
- `${this.addr}/api/`,
574
- this.getApiVersion.bind(this),
575
- t == null ? void 0 : t.token
576
- );
577
- }
615
+ if (d === "auto")
616
+ return "auto";
617
+ }, c = r(n), a = r(i), { data: f, error: w } = await s(
618
+ (d) => t.POST("/display/brightness", {
619
+ params: {
620
+ query: {
621
+ front: c,
622
+ back: a
623
+ }
624
+ },
625
+ signal: d
626
+ }),
627
+ e.timeout
628
+ );
629
+ if (w)
630
+ throw w;
631
+ return f;
632
+ }
633
+ class at {
578
634
  /**
579
- * Retrieves the API semantic version.
635
+ * Draw on display. Starts the Canvas application if not running.
580
636
  *
581
- * @returns {Promise<VersionInfo>} A promise that resolves to an object containing the `api_semver` string.
637
+ * @param {DrawParams} params - Parameters for the draw operation.
638
+ * @param {string} params.appId - Application ID.
639
+ * @param {any} params.elements - Display elements to draw.
640
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
641
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful draw command.
582
642
  */
583
- async getApiVersion() {
584
- const t = await X();
585
- return this.apiSemver = t.api_semver, t;
643
+ async DisplayDraw(t) {
644
+ return await it(t);
586
645
  }
587
646
  /**
588
- * Updates the firmware.
647
+ * Clear display. Clears the display and stops the Canvas application if running.
589
648
  *
590
- * @param {UpdateParams} params - Parameters for the firmware update.
591
- * @param {UpdateParams['name']} params.name - Name for the update package.
592
- * @param {UpdateParams['file']} params.file - File data to upload.
593
- * @returns {Promise<SuccessResponse>} Result of the update operation.
649
+ * @param {TimeoutOptions} [params] - Optional parameters.
650
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
651
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful clear command.
594
652
  */
595
- async updateFirmware(t) {
596
- return await M(t);
653
+ async DisplayClear(t) {
654
+ return await rt(t);
597
655
  }
598
656
  /**
599
- * Gets the current status of the device, including system and power information.
657
+ * Get single frame for requested screen.
600
658
  *
601
- * @returns {Promise<Status>} Current status of the device.
659
+ * @param {GetScreenFrameParams} params - Parameters for the frame request.
660
+ * @param {string} params.display - Display identifier.
661
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
662
+ * @returns {Promise<Blob>} A promise that resolves to the screen frame as a Blob.
602
663
  */
603
- async deviceStatus() {
604
- return await Q();
664
+ async DisplayScreenFrameGet(t) {
665
+ return await ot(t);
605
666
  }
606
667
  /**
607
- * Gets the current system status.
668
+ * Get display brightness.
608
669
  *
609
- * @returns {Promise<StatusSystem>} Current system status.
670
+ * @param {TimeoutOptions} [params] - Optional parameters.
671
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
672
+ * @returns {Promise<DisplayBrightnessInfo>} A promise that resolves to the brightness information.
610
673
  */
611
- async systemStatus() {
612
- return await Y();
674
+ async DisplayBrightnessGet(t) {
675
+ return await st(t);
613
676
  }
614
677
  /**
615
- * Gets the current power status.
616
- *
617
- * @returns {Promise<StatusPower>} Current power status.
678
+ * @deprecated Use `DisplayBrightnessGet` instead. will be removed in the next release.
618
679
  */
619
- async powerStatus() {
620
- return await Z();
680
+ async DisplayBrightness(t) {
681
+ return this.DisplayBrightnessGet(t);
621
682
  }
622
683
  /**
623
- * Gets current device timestamp with timezone.
684
+ * Set display brightness.
624
685
  *
625
- * @returns {Promise<TimestampInfo>} Current device timestamp as an ISO 8601 string.
686
+ * @param {BrightnessParams} params - Brightness parameters:
687
+ * @param {number|"auto"} [params.front] - Front brightness (0-100 or "auto").
688
+ * @param {number|"auto"} [params.back] - Back brightness (0-100 or "auto").
689
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
690
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
626
691
  */
627
- async getTime() {
628
- return await tt();
692
+ async DisplayBrightnessSet(t) {
693
+ return await ct(t);
629
694
  }
695
+ }
696
+ async function ut(e) {
697
+ const t = o(), { appId: n, path: i } = e, { data: r, error: c } = await s(
698
+ (a) => t.POST("/audio/play", {
699
+ params: {
700
+ query: {
701
+ app_id: n,
702
+ path: i
703
+ }
704
+ },
705
+ signal: a
706
+ }),
707
+ e.timeout
708
+ );
709
+ if (c)
710
+ throw c;
711
+ return r;
712
+ }
713
+ async function dt(e) {
714
+ const t = o(), { data: n, error: i } = await s(
715
+ (r) => t.DELETE("/audio/play", { signal: r }),
716
+ e == null ? void 0 : e.timeout
717
+ );
718
+ if (i)
719
+ throw i;
720
+ return n;
721
+ }
722
+ async function ft(e) {
723
+ const t = o(), { data: n, error: i } = await s(
724
+ (r) => t.GET("/audio/volume", { signal: r }),
725
+ e == null ? void 0 : e.timeout
726
+ );
727
+ if (i)
728
+ throw i;
729
+ return n;
730
+ }
731
+ async function ht(e) {
732
+ const t = o(), { volume: n } = e;
733
+ if (typeof n != "number" || n < 0 || n > 100)
734
+ throw new Error("Volume must be a number between 0 and 100");
735
+ const { data: i, error: r } = await s(
736
+ (c) => t.POST("/audio/volume", {
737
+ params: {
738
+ query: {
739
+ volume: n
740
+ }
741
+ },
742
+ signal: c
743
+ }),
744
+ e.timeout
745
+ );
746
+ if (r)
747
+ throw r;
748
+ return i;
749
+ }
750
+ class wt {
630
751
  /**
631
- * Sets the current device timestamp.
752
+ * Play audio file. Plays a file from internal storage.
632
753
  *
633
- * @param {SetTimestampParams} params - The parameters for setting the timestamp.
634
- * @param {SetTimestampParams['timestamp']} params.timestamp - The new timestamp (ISO 8601 string).
635
- * @returns {Promise<SuccessResponse>} A success response if the timestamp was set.
754
+ * @param {AudioPlayParams} params - Parameters for audio playback.
755
+ * @param {string} params.appId - Application ID.
756
+ * @param {string} params.path - Path to the audio file.
757
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
758
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful play command.
636
759
  */
637
- async setTimestamp(t) {
638
- return await et(t);
760
+ async AudioPlay(t) {
761
+ return await ut(t);
639
762
  }
640
763
  /**
641
- * Sets the device timezone.
642
- *
643
- * @param {SetTimezoneParams} params - The parameters for setting the timezone.
644
- * @param {SetTimezoneParams['timezone']} params.timezone - The new timezone identifier (IANA TZ string).
645
- * @returns {Promise<SuccessResponse>} A success response if the timezone was set.
764
+ * @deprecated Use `AudioPlay` instead. will be removed in the next release.
646
765
  */
647
- async setTimezone(t) {
648
- return await it(t);
766
+ async Audio(t) {
767
+ return this.AudioPlay(t);
649
768
  }
650
769
  /**
651
- * Gets the status of the MQTT account linked to the device.
770
+ * Stop audio playback. Stops any currently playing audio.
652
771
  *
653
- * @returns {Promise<AccountInfo>} Information about the current MQTT account status.
772
+ * @param {TimeoutOptions} [params] - Optional parameters.
773
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
774
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful stop command.
654
775
  */
655
- async getMqttStatus() {
656
- return await L();
776
+ async AudioStop(t) {
777
+ return await dt(t);
657
778
  }
658
779
  /**
659
- * Unlinks the current account from the device.
780
+ * Get audio volume.
660
781
  *
661
- * @returns {Promise<SuccessResponse>} Result of the account unlink operation.
782
+ * @param {TimeoutOptions} [params] - Optional parameters.
783
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
784
+ * @returns {Promise<AudioVolumeInfo>} A promise that resolves to the audio volume information.
662
785
  */
663
- async unlinkAccount() {
664
- return await D();
786
+ async AudioVolumeGet(t) {
787
+ return await ft(t);
665
788
  }
666
789
  /**
667
- * Links an account to the device.
668
- *
669
- * @returns {Promise<AccountLink>} Information about the account link operation.
790
+ * @deprecated Use `AudioVolumeGet` instead. will be removed in the next release.
670
791
  */
671
- async linkAccount() {
672
- return await O();
792
+ async AudioVolume(t) {
793
+ return this.AudioVolumeGet(t);
673
794
  }
674
795
  /**
675
- * Uploads an asset to the device.
796
+ * Set audio volume.
676
797
  *
677
- * @param {UploadParams} params - Parameters for the upload.
678
- * @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
679
- * @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
680
- * @param {UploadParams['file']} params.file - File data to upload.
681
- * @returns {Promise<SuccessResponse>} Result of the upload operation.
798
+ * @param {AudioVolumeParams} params - Volume parameters:
799
+ * @param {number} params.volume - Volume level (0-100).
800
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
801
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
682
802
  */
683
- async uploadAsset(t) {
684
- return await W(t);
803
+ async AudioVolumeSet(t) {
804
+ return await ht(t);
685
805
  }
806
+ }
807
+ async function lt(e) {
808
+ const t = o(), { data: n, error: i } = await s(
809
+ (r) => t.GET("/wifi/status", { signal: r }),
810
+ e == null ? void 0 : e.timeout
811
+ );
812
+ if (i)
813
+ throw i;
814
+ return n;
815
+ }
816
+ async function yt(e) {
817
+ const t = o(), { data: n, error: i } = await s(
818
+ (r) => t.POST("/wifi/connect", {
819
+ body: {
820
+ ssid: e.ssid,
821
+ password: e.password,
822
+ security: e.security,
823
+ ip_config: {
824
+ ip_method: e.ipConfig.ipMethod,
825
+ address: e.ipConfig.address,
826
+ mask: e.ipConfig.mask,
827
+ gateway: e.ipConfig.gateway
828
+ }
829
+ },
830
+ signal: r
831
+ }),
832
+ e.timeout
833
+ );
834
+ if (i)
835
+ throw i;
836
+ return n;
837
+ }
838
+ async function St(e) {
839
+ const t = o(), { data: n, error: i } = await s(
840
+ (r) => t.POST("/wifi/disconnect", { signal: r }),
841
+ e == null ? void 0 : e.timeout
842
+ );
843
+ if (i)
844
+ throw i;
845
+ return n;
846
+ }
847
+ async function pt(e) {
848
+ const t = o(), { data: n, error: i } = await s(
849
+ (r) => t.GET("/wifi/networks", { signal: r }),
850
+ e == null ? void 0 : e.timeout
851
+ );
852
+ if (i)
853
+ throw i;
854
+ return n;
855
+ }
856
+ class mt {
686
857
  /**
687
- * Deletes all assets for a specific application from the device.
858
+ * Returns current Wi-Fi status.
688
859
  *
689
- * @param {DeleteParams} params - Parameters for the delete.
690
- * @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
691
- * @returns {Promise<SuccessResponse>} Result of the delete operation.
860
+ * @param {TimeoutOptions} [params] - Optional parameters.
861
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
862
+ * @returns {Promise<WifiStatusResponse>} A promise that resolves to the Wi-Fi status.
692
863
  */
693
- async deleteAssets(t) {
694
- return await C(t);
864
+ async WifiStatusGet(t) {
865
+ return await lt(t);
695
866
  }
696
867
  /**
697
- * Draws elements on the device display.
698
- *
699
- * @param {DrawParams} params - Parameters for the draw operation.
700
- * @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
701
- * @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
702
- * @returns {Promise<SuccessResponse>} Result of the draw operation.
868
+ * @deprecated Use `WifiStatusGet` instead. will be removed in the next release.
703
869
  */
704
- async drawDisplay(t) {
705
- return await R(t);
870
+ async WifiStatus(t) {
871
+ return this.WifiStatusGet(t);
706
872
  }
707
873
  /**
708
- * Clears the device display and stops the Canvas application if running.
874
+ * Connects to Wi-Fi network.
709
875
  *
710
- * @returns {Promise<SuccessResponse>} Result of the clear operation.
876
+ * @param {ConnectParams} params - Connection parameters:
877
+ * @param {string} params.ssid - Network SSID.
878
+ * @param {string} params.password - Network password.
879
+ * @param {WifiSecurityMethod} params.security - Security method.
880
+ * @param {object} params.ipConfig - IP configuration.
881
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
882
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful connection initiation.
711
883
  */
712
- async clearDisplay() {
713
- return await U();
884
+ async WifiConnect(t) {
885
+ return await yt(t);
714
886
  }
715
887
  /**
716
- * Plays an audio file from the assets directory.
888
+ * Disconnects from Wi-Fi.
717
889
  *
718
- * @param {AudioPlayParams} params - Parameters for the audio playback.
719
- * @param {AudioPlayParams['appId']} params.appId - Application ID for organizing assets.
720
- * @param {AudioPlayParams['path']} params.path - Path to the audio file within the app's assets directory.
721
- * @returns {Promise<SuccessResponse>} Result of the play operation.
890
+ * @param {TimeoutOptions} [params] - Optional parameters.
891
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
892
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful disconnection.
722
893
  */
723
- async playSound(t) {
724
- return await K(t);
894
+ async WifiDisconnect(t) {
895
+ return await St(t);
725
896
  }
726
897
  /**
727
- * Stops any currently playing audio on the device.
898
+ * Scans environment for available Wi-Fi networks.
728
899
  *
729
- * @returns {Promise<SuccessResponse>} Result of the stop operation.
900
+ * @param {TimeoutOptions} [params] - Optional parameters.
901
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
902
+ * @returns {Promise<WifiNetworkResponse>} A promise that resolves to a list of available networks.
730
903
  */
731
- async stopSound() {
732
- return await $();
904
+ async WifiNetworksGet(t) {
905
+ return await pt(t);
733
906
  }
734
907
  /**
735
- * @deprecated since 0.5.0 will be removed in 0.7.0.
736
- *
737
- * This method is no longer supported and does nothing.
738
- *
739
- * Works only with BusyLib v0.5.0 and device firmware v0.3.0.
740
- *
741
- * Always throws an error.
908
+ * @deprecated Use `WifiNetworksGet` instead. will be removed in the next release.
742
909
  */
743
- async enableWifi() {
744
- throw new Error(
745
- "[DEPRECATED] BusyBar.enableWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
746
- );
910
+ async WifiNetworks(t) {
911
+ return this.WifiNetworksGet(t);
747
912
  }
913
+ }
914
+ async function Tt(e) {
915
+ const t = o(), { path: n, file: i } = e, { data: r, error: c } = await s(
916
+ (a) => t.POST("/storage/write", {
917
+ params: {
918
+ query: {
919
+ path: n
920
+ }
921
+ },
922
+ headers: {
923
+ "Content-Type": "application/octet-stream"
924
+ },
925
+ body: i,
926
+ signal: a
927
+ }),
928
+ e.timeout
929
+ );
930
+ if (c)
931
+ throw c;
932
+ return r;
933
+ }
934
+ async function Et(e) {
935
+ const t = o(), { path: n, asArrayBuffer: i } = e, { data: r, error: c } = await s(
936
+ (a) => t.GET("/storage/read", {
937
+ params: {
938
+ query: {
939
+ path: n
940
+ }
941
+ },
942
+ parseAs: i ? "arrayBuffer" : "blob",
943
+ signal: a
944
+ }),
945
+ e.timeout
946
+ );
947
+ if (c)
948
+ throw c;
949
+ return r;
950
+ }
951
+ async function gt(e) {
952
+ const t = o(), { path: n } = e, { data: i, error: r } = await s(
953
+ (c) => t.GET("/storage/list", {
954
+ params: {
955
+ query: {
956
+ path: n
957
+ }
958
+ },
959
+ signal: c
960
+ }),
961
+ e.timeout
962
+ );
963
+ if (r)
964
+ throw r;
965
+ return i;
966
+ }
967
+ async function kt(e) {
968
+ const t = o(), { path: n } = e, { data: i, error: r } = await s(
969
+ (c) => t.DELETE("/storage/remove", {
970
+ params: {
971
+ query: {
972
+ path: n
973
+ }
974
+ },
975
+ signal: c
976
+ }),
977
+ e.timeout
978
+ );
979
+ if (r)
980
+ throw r;
981
+ return i;
982
+ }
983
+ async function Gt(e) {
984
+ const t = o(), { path: n } = e, { data: i, error: r } = await s(
985
+ (c) => t.POST("/storage/mkdir", {
986
+ params: {
987
+ query: {
988
+ path: n
989
+ }
990
+ },
991
+ signal: c
992
+ }),
993
+ e.timeout
994
+ );
995
+ if (r)
996
+ throw r;
997
+ return i;
998
+ }
999
+ async function bt(e) {
1000
+ const t = o(), { data: n, error: i } = await s(
1001
+ (r) => t.GET("/storage/status", { signal: r }),
1002
+ e == null ? void 0 : e.timeout
1003
+ );
1004
+ if (i)
1005
+ throw i;
1006
+ return n;
1007
+ }
1008
+ class At {
748
1009
  /**
749
- * @deprecated since 0.5.0 will be removed in 0.7.0.
750
- *
751
- * This method is no longer supported and does nothing.
1010
+ * Upload file to internal storage. Uploads a file to a specified path.
752
1011
  *
753
- * Works only with BusyLib v0.5.0 and device firmware v0.3.0.
754
- *
755
- * Always throws an error.
1012
+ * @param {UploadFileParams} params - Upload parameters:
1013
+ * @param {string} params.path - Destination path.
1014
+ * @param {BusyFile} params.file - File content.
1015
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1016
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful upload.
756
1017
  */
757
- async disableWifi() {
758
- throw new Error(
759
- "[DEPRECATED] BusyBar.disableWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
760
- );
1018
+ async StorageWrite(t) {
1019
+ return await Tt(t);
761
1020
  }
762
1021
  /**
763
- * Gets the current status of the Wi-Fi module.
1022
+ * Download file from internal storage. Downloads a file from a specified path.
764
1023
  *
765
- * @returns {Promise<WifiStatusResponse>} Current Wi-Fi status.
1024
+ * @param {DownloadFileParams} params - Download parameters:
1025
+ * @param {string} params.path - Path to the file.
1026
+ * @param {boolean} [params.asArrayBuffer] - Whether to return ArrayBuffer instead of Blob.
1027
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1028
+ * @returns {Promise<StorageReadResponse>} A promise that resolves to the file content (Blob or ArrayBuffer).
766
1029
  */
767
- async statusWifi() {
768
- return await _();
1030
+ async StorageRead(t) {
1031
+ return await Et(t);
769
1032
  }
770
1033
  /**
771
- * Connects the device to a Wi-Fi network with the specified parameters.
772
- *
773
- * @param {ConnectParams} params - Connection parameters:
774
- * @param {ConnectParams['ssid']} params.ssid - SSID (network name) to connect to.
775
- * @param {ConnectParams['password']} [params.password] - Password for the Wi-Fi network (if required).
776
- * @param {ConnectParams['security']} params.security - Security type (e.g., "open", "wpa2", etc.).
777
- * @param {ConnectParams['ipConfig']} params.ipConfig - IP configuration object:
778
- * @param {ConnectParams['ipConfig']['ipMethod']} params.ipConfig.ipMethod - IP assignment method ("dhcp" or "static").
779
- * @param {ConnectParams['ipConfig']['ipType']} params.ipConfig.ipType - IP type ("ipv4" or "ipv6").
780
- * @param {ConnectParams['ipConfig']['address']} [params.ipConfig.address] - Static IP address (if using "static" method).
781
- * @param {ConnectParams['ipConfig']['mask']} [params.ipConfig.mask] - Subnet mask (if using "static" method).
782
- * @param {ConnectParams['ipConfig']['gateway']} [params.ipConfig.gateway] - Gateway address (if using "static" method).
783
- * @returns {Promise<SuccessResponse>} Result of the connect operation.
784
- */
785
- async connectWifi(t) {
786
- return await F(t);
787
- }
788
- /**
789
- * Disconnects the device from the current Wi-Fi network.
1034
+ * List files on internal storage.
790
1035
  *
791
- * @returns {Promise<SuccessResponse>} Result of the disconnect operation.
1036
+ * @param {ReadDirectoryParams} params - List parameters:
1037
+ * @param {string} params.path - Path to the directory.
1038
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1039
+ * @returns {Promise<StorageList>} A promise that resolves to a list of files and directories.
792
1040
  */
793
- async disconnectWifi() {
794
- return await G();
1041
+ async StorageListGet(t) {
1042
+ return await gt(t);
795
1043
  }
796
1044
  /**
797
- * Scans for available Wi-Fi networks near your device.
798
- *
799
- * @returns {Promise<WifiNetworkResponse>} List of discovered networks.
1045
+ * @deprecated Use `StorageListGet` instead. will be removed in the next release.
800
1046
  */
801
- async networksWifi() {
802
- return await N();
1047
+ async StorageList(t) {
1048
+ return this.StorageListGet(t);
803
1049
  }
804
1050
  /**
805
- * @deprecated since 0.5.0 will be removed in 0.7.0.
806
- *
807
- * This method is no longer supported and does nothing.
1051
+ * Remove a file on internal storage. Removes a file with a specified path.
808
1052
  *
809
- * Works only with BusyLib v0.5.0 and device firmware v0.3.0.
810
- *
811
- * Always throws an error.
1053
+ * @param {RemoveParams} params - Remove parameters:
1054
+ * @param {string} params.path - Path to the file to remove.
1055
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1056
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful removal.
812
1057
  */
813
- async forgetWifi() {
814
- throw new Error(
815
- "[DEPRECATED] BusyBar.forgetWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
816
- );
1058
+ async StorageRemove(t) {
1059
+ return await kt(t);
817
1060
  }
818
1061
  /**
819
- * Uploads a file to the device's internal storage.
1062
+ * Create a directory on internal storage. Creates a new directory with a specified path.
820
1063
  *
821
- * @param {UploadFileParams} params - Upload parameters:
822
- * @param {UploadFileParams['path']} params.path - Path where the file will be saved (e.g., "/ext/test.png").
823
- * @param {UploadFileParams['file']} params.file - File data to upload.
824
- * @returns {Promise<SuccessResponse>} Result of the upload operation.
1064
+ * @param {CreateDirectoryParams} params - Directory creation parameters:
1065
+ * @param {string} params.path - Path to the new directory.
1066
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1067
+ * @returns {Promise<SuccessResponse>} A promise that resolves on successful creation.
825
1068
  */
826
- async uploadFile(t) {
827
- return await V(t);
1069
+ async StorageMkdir(t) {
1070
+ return await Gt(t);
828
1071
  }
829
1072
  /**
830
- * Downloads a file from the device's internal storage.
1073
+ * Show storage usage.
831
1074
  *
832
- * @param {DownloadFileParams} params - Download parameters:
833
- * @param {DownloadFileParams['path']} params.path - Path to the file to download (e.g., "/ext/test.png").
834
- * @param {DownloadFileParams['asArrayBuffer']} [params.asArrayBuffer] - If true, returns data as ArrayBuffer; otherwise, as Blob.
835
- * @returns {Promise<StorageReadResponse>} The file data.
1075
+ * @param {TimeoutOptions} [params] - Optional parameters.
1076
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1077
+ * @returns {Promise<StorageStatus>} A promise that resolves to the storage status.
836
1078
  */
837
- async downloadFile(t) {
838
- return await q(t);
1079
+ async StorageStatusGet(t) {
1080
+ return await bt(t);
839
1081
  }
840
1082
  /**
841
- * Reads the contents of a directory (files and subdirectories) at the specified path.
842
- *
843
- * @param {ReadDirectoryParams} params - List parameters:
844
- * @param {ReadDirectoryParams['path']} params.path - Path to the directory to list (e.g., "/ext").
845
- * @returns {Promise<StorageList>} List of files and directories.
1083
+ * @deprecated Use `StorageStatusGet` instead. will be removed in the next release.
846
1084
  */
847
- async readDirectory(t) {
848
- return await x(t);
1085
+ async StorageStatus(t) {
1086
+ return this.StorageStatusGet(t);
849
1087
  }
1088
+ }
1089
+ async function vt(e) {
1090
+ const t = o(), { data: n, error: i } = await s(
1091
+ (r) => t.GET("/access", { signal: r }),
1092
+ e == null ? void 0 : e.timeout
1093
+ );
1094
+ if (i)
1095
+ throw i;
1096
+ return n;
1097
+ }
1098
+ async function Pt(e) {
1099
+ const t = o();
1100
+ let { mode: n, key: i } = e;
1101
+ if (i = i ?? "", String(i).trim() && !/^\d{4,10}$/.test(String(i)))
1102
+ throw new Error("Key must be a string of 4 to 10 digits");
1103
+ const { data: r, error: c } = await s(
1104
+ (a) => t.POST("/access", {
1105
+ params: {
1106
+ query: {
1107
+ mode: n,
1108
+ key: i
1109
+ }
1110
+ },
1111
+ signal: a
1112
+ }),
1113
+ e.timeout
1114
+ );
1115
+ if (c)
1116
+ throw c;
1117
+ return r;
1118
+ }
1119
+ async function Lt(e) {
1120
+ const t = o(), { data: n, error: i } = await s(
1121
+ (r) => t.GET("/name", { signal: r }),
1122
+ e == null ? void 0 : e.timeout
1123
+ );
1124
+ if (i)
1125
+ throw i;
1126
+ return n;
1127
+ }
1128
+ async function Dt(e) {
1129
+ const t = o(), { data: n, error: i } = await s(
1130
+ (r) => t.POST("/name", {
1131
+ body: e,
1132
+ signal: r
1133
+ }),
1134
+ e.timeout
1135
+ );
1136
+ if (i)
1137
+ throw i;
1138
+ return n;
1139
+ }
1140
+ class Ot {
850
1141
  /**
851
- * Removes a file or a directory from the device's internal storage.
1142
+ * Get HTTP API access over Wi-Fi configuration.
852
1143
  *
853
- * @param {RemoveParams} params - Remove parameters:
854
- * @param {RemoveParams['path']} params.path - Path of the file to remove (e.g., "/ext/test.png").
855
- * @returns {Promise<SuccessResponse>} Result of the remove operation.
1144
+ * @param {TimeoutOptions} [params] - Optional parameters.
1145
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1146
+ * @returns {Promise<HttpAccessInfo>} A promise that resolves to the access configuration.
856
1147
  */
857
- async removeResource(t) {
858
- return await j(t);
1148
+ async SettingsAccessGet(t) {
1149
+ return await vt(t);
859
1150
  }
860
1151
  /**
861
- * Creates a new directory in the device's internal storage.
862
- *
863
- * @param {CreateDirectoryParams} params - Directory creation parameters:
864
- * @param {CreateDirectoryParams['path']} params.path - Path to the new directory (e.g., "/ext/newdir").
865
- * @returns {Promise<SuccessResponse>} Result of the create operation.
1152
+ * @deprecated Use `SettingsAccessGet` instead. will be removed in the next release.
866
1153
  */
867
- async createDirectory(t) {
868
- return await H(t);
1154
+ async SettingsAccess(t) {
1155
+ return this.SettingsAccessGet(t);
869
1156
  }
870
1157
  /**
871
- * Gets the current status of the device's internal storage.
1158
+ * Set HTTP API access over Wi-Fi configuration.
872
1159
  *
873
- * @returns {Promise<StorageStatus>} Current storage status information.
1160
+ * @param {HttpAccessParams} params - Access parameters:
1161
+ * @param {boolean} params.mode - Enable/disable access.
1162
+ * @param {string} params.key - Access key (4-10 digits).
1163
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1164
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
874
1165
  */
875
- async statusStorage() {
876
- return await J();
1166
+ async SettingsAccessSet(t) {
1167
+ return await Pt(t);
877
1168
  }
878
1169
  /**
879
- * Gets the current display brightness settings for the device.
1170
+ * Get current device name.
880
1171
  *
881
- * @returns {Promise<DisplayBrightnessInfo>} Current brightness information for front and back panels.
1172
+ * @param {TimeoutOptions} [params] - Optional parameters.
1173
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1174
+ * @returns {Promise<NameInfo>} A promise that resolves to the device name.
882
1175
  */
883
- async getDisplayBrightness() {
884
- return await rt();
1176
+ async SettingsNameGet(t) {
1177
+ return await Lt(t);
885
1178
  }
886
1179
  /**
887
- * Sets the display brightness for the device.
888
- *
889
- * @param {BrightnessParams} params - Brightness parameters:
890
- * @param {BrightnessParams['front']} [params.front] - Brightness for the front panel (0-100 or "auto").
891
- * @param {BrightnessParams['back']} [params.back] - Brightness for the back panel (0-100 or "auto").
892
- * @returns {Promise<SuccessResponse>} Result of the brightness update operation.
893
- * @throws {Error} If brightness value is outside the range 0-100 or not "auto".
1180
+ * @deprecated Use `SettingsNameGet` instead. will be removed in the next release.
894
1181
  */
895
- async setDisplayBrightness(t) {
896
- return await nt(t);
1182
+ async SettingsName(t) {
1183
+ return this.SettingsNameGet(t);
897
1184
  }
898
1185
  /**
899
- * Gets the current audio volume value.
1186
+ * Set device name.
900
1187
  *
901
- * @returns {Promise<AudioVolumeInfo>} Current audio volume (0-100).
1188
+ * @param {NameParams} params - Name parameters:
1189
+ * @param {string} params.name - New device name (max 64 chars).
1190
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1191
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
902
1192
  */
903
- async getAudioVolume() {
904
- return await st();
1193
+ async SettingsNameSet(t) {
1194
+ return await Dt(t);
905
1195
  }
1196
+ }
1197
+ async function Ut(e) {
1198
+ const t = o(), { data: n, error: i } = await s(
1199
+ (r) => t.POST("/ble/enable", { signal: r }),
1200
+ e == null ? void 0 : e.timeout
1201
+ );
1202
+ if (i)
1203
+ throw i;
1204
+ return n;
1205
+ }
1206
+ async function Bt(e) {
1207
+ const t = o(), { data: n, error: i } = await s(
1208
+ (r) => t.POST("/ble/disable", { signal: r }),
1209
+ e == null ? void 0 : e.timeout
1210
+ );
1211
+ if (i)
1212
+ throw i;
1213
+ return n;
1214
+ }
1215
+ async function Ct(e) {
1216
+ const t = o(), { data: n, error: i } = await s(
1217
+ (r) => t.DELETE("/ble/pairing", { signal: r }),
1218
+ e == null ? void 0 : e.timeout
1219
+ );
1220
+ if (i)
1221
+ throw i;
1222
+ return n;
1223
+ }
1224
+ async function It(e) {
1225
+ const t = o(), { data: n, error: i } = await s(
1226
+ (r) => t.GET("/ble/status", { signal: r }),
1227
+ e == null ? void 0 : e.timeout
1228
+ );
1229
+ if (i)
1230
+ throw i;
1231
+ return n;
1232
+ }
1233
+ class $t {
906
1234
  /**
907
- * Sets the audio volume value.
1235
+ * Enable BLE. Starts advertising.
908
1236
  *
909
- * @param {AudioVolumeParams} params - Audio volume parameters:
910
- * @param {AudioVolumeParams['volume']} params.volume - Audio volume (number from 0 to 100).
911
- * @returns {Promise<SuccessResponse>} Result of the volume update operation.
912
- * @throws {Error} If volume is outside the range 0-100 or request fails.
1237
+ * @param {TimeoutOptions} [params] - Optional parameters.
1238
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1239
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
913
1240
  */
914
- async setAudioVolume(t) {
915
- return await ot(t);
1241
+ async BleEnable(t) {
1242
+ return await Ut(t);
916
1243
  }
917
1244
  /**
918
- * Gets the current HTTP API access configuration.
1245
+ * Disable BLE. Stops advertising.
919
1246
  *
920
- * @returns {Promise<HttpAccessInfo>} Current HTTP access info.
1247
+ * @param {TimeoutOptions} [params] - Optional parameters.
1248
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1249
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
921
1250
  */
922
- async getHttpAccess() {
923
- return await at();
1251
+ async BleDisable(t) {
1252
+ return await Bt(t);
924
1253
  }
925
1254
  /**
926
- * Sets the HTTP API access configuration.
1255
+ * Remove pairing. Remove pairing with previous device.
927
1256
  *
928
- * @param {HttpAccessParams} params - Access parameters:
929
- * @param {HttpAccessParams['mode']} params.mode - Access mode ("disabled", "enabled", "key").
930
- * @param {HttpAccessParams['key']} params.key - Access key (4-10 digits).
931
- * @returns {Promise<SuccessResponse>} Result of the set operation.
1257
+ * @param {TimeoutOptions} [params] - Optional parameters.
1258
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1259
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
932
1260
  */
933
- async setHttpAccess(t) {
934
- const i = await ct(t);
935
- return t.mode === "key" && t.key && this.setApiKey(t.key), i;
1261
+ async BleUnpair(t) {
1262
+ return await Ct(t);
936
1263
  }
937
1264
  /**
938
- * Gets the current device name.
1265
+ * Returns current BLE status.
939
1266
  *
940
- * @returns {Promise<NameInfo>} The current device name information.
1267
+ * @param {TimeoutOptions} [params] - Optional parameters.
1268
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1269
+ * @returns {Promise<BleStatusResponse>} A promise that resolves to the BLE status.
941
1270
  */
942
- async getName() {
943
- return await ft();
1271
+ async BleStatusGet(t) {
1272
+ return await It(t);
944
1273
  }
1274
+ }
1275
+ async function Rt(e) {
1276
+ const t = o(), { keyName: n } = e, { data: i, error: r } = await s(
1277
+ (c) => t.POST("/input", {
1278
+ params: {
1279
+ query: {
1280
+ key: n
1281
+ }
1282
+ },
1283
+ signal: c
1284
+ }),
1285
+ e.timeout
1286
+ );
1287
+ if (r)
1288
+ throw r;
1289
+ return i;
1290
+ }
1291
+ class Wt {
945
1292
  /**
946
- * Sets the device name.
1293
+ * Send input event. Send single key press event.
947
1294
  *
948
- * @param {NameParams} params - The parameters for setting the device name.
949
- * @param {NameParams['name']} params.name - The new device name.
950
- * @returns {Promise<SuccessResponse>} Result of setting the device name.
951
- */
952
- async setName(t) {
953
- return await ut(t);
954
- }
955
- /**
956
- * Sets API key for all subsequent requests.
957
- * @param {string} key - API key to use in "X-API-Token" header.
1295
+ * @param {InputKeyParams} params - Button press parameters:
1296
+ * @param {KeyName} params.keyName - Name of the key to press.
1297
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1298
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
958
1299
  */
959
- setApiKey(t) {
960
- I(t);
1300
+ async InputSend(t) {
1301
+ return await Rt(t);
961
1302
  }
1303
+ }
1304
+ async function Nt(e) {
1305
+ const t = o(), { data: n, error: i } = await s(
1306
+ (r) => t.GET("/matter/commissioning", { signal: r }),
1307
+ e == null ? void 0 : e.timeout
1308
+ );
1309
+ if (i)
1310
+ throw i;
1311
+ return n;
1312
+ }
1313
+ async function Mt(e) {
1314
+ const t = o(), { data: n, error: i } = await s(
1315
+ (r) => t.POST("/matter/commissioning", { signal: r }),
1316
+ e == null ? void 0 : e.timeout
1317
+ );
1318
+ if (i)
1319
+ throw i;
1320
+ return n;
1321
+ }
1322
+ async function Vt(e) {
1323
+ const t = o(), { data: n, error: i } = await s(
1324
+ (r) => t.DELETE("/matter/commissioning", { signal: r }),
1325
+ e == null ? void 0 : e.timeout
1326
+ );
1327
+ if (i)
1328
+ throw i;
1329
+ return n;
1330
+ }
1331
+ class Kt {
962
1332
  /**
963
- * Enables BLE module.
964
- * @returns {Promise<SuccessResponse>} Result of the enable operation.
1333
+ * Get Matter status.
1334
+ *
1335
+ * @param {TimeoutOptions} [params] - Optional parameters.
1336
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1337
+ * @returns {Promise<MatterStatus>} A promise that resolves to the Matter status.
965
1338
  */
966
- async enableBle() {
967
- return await wt();
1339
+ async MatterStatusGet(t) {
1340
+ return await Nt(t);
968
1341
  }
969
1342
  /**
970
- * Disables BLE module.
971
- * @returns {Promise<SuccessResponse>} Result of the disable operation.
1343
+ * Pair Matter device.
1344
+ *
1345
+ * @param {TimeoutOptions} [params] - Optional parameters.
1346
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1347
+ * @returns {Promise<MatterPairingInfo>} A promise that resolves on success.
972
1348
  */
973
- async disableBle() {
974
- return await dt();
1349
+ async MatterPair(t) {
1350
+ return await Mt(t);
975
1351
  }
976
1352
  /**
977
- * Removes all BLE pairings from the device.
1353
+ * Erase Matter devices.
978
1354
  *
979
- * @returns {Promise<SuccessResponse>} Result of the BLE pairing removal operation.
1355
+ * @param {TimeoutOptions} [params] - Optional parameters.
1356
+ * @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
1357
+ * @returns {Promise<SuccessResponse>} A promise that resolves on success.
980
1358
  */
981
- async pairingBle() {
982
- return await ht();
1359
+ async MatterErase(t) {
1360
+ return await Vt(t);
983
1361
  }
1362
+ }
1363
+ const E = "http://10.0.4.20", xt = "https://proxy.busy.app", _t = /^https?:\/\/proxy(?:\.(?:dev|test|stage))?\.busy\.app$/i;
1364
+ function g(e) {
1365
+ const t = e.split(".");
1366
+ if (t.length !== 4)
1367
+ return !1;
1368
+ for (const n of t) {
1369
+ if (n.length === 0 || n.length > 1 && n[0] === "0" || !/^\d+$/.test(n))
1370
+ return !1;
1371
+ const i = Number(n);
1372
+ if (i < 0 || i > 255)
1373
+ return !1;
1374
+ }
1375
+ return !0;
1376
+ }
1377
+ function k(e) {
1378
+ return /\.local$/i.test(e);
1379
+ }
1380
+ class Ft {
984
1381
  /**
985
- * Gets the current BLE module status.
1382
+ * Creates an instance of BUSY Bar.
1383
+ * Initializes the API client with the provided host address.
1384
+ *
1385
+ * @param {BusyBarConfig} config - BUSY Bar connection configuration
1386
+ * @param {BusyBarConfig['addr']} config.addr -
1387
+ * The device address or proxy endpoint.
1388
+ *
1389
+ * Can be:
1390
+ * - An IP address (e.g. `192.168.0.10`)
1391
+ * - An mDNS hostname (e.g. `busybar.local`)
1392
+ * - A domain name
1393
+ * - A full URL (`http://` or `https://`)
1394
+ *
1395
+ * If no protocol is specified, `http://` will be automatically added.
1396
+ *
1397
+ * @param {BusyBarConfig['token']} config.token -
1398
+ * Optional authentication token.
986
1399
  *
987
- * @returns {Promise<BleStatusResponse>} Current BLE status information.
1400
+ * Must be provided when `addr` points to a secured proxy endpoint
1401
+ * such as `https://proxy.busy.app`.
988
1402
  */
989
- async statusBle() {
990
- return await lt();
1403
+ constructor(t) {
1404
+ /**
1405
+ * Device host address (IP or mDNS).
1406
+ * @type {BusyBarConfig['host']}
1407
+ * @readonly
1408
+ */
1409
+ u(this, "addr");
1410
+ /**
1411
+ * Current API semantic version.
1412
+ * @type {ApiSemver}
1413
+ */
1414
+ u(this, "apiSemver");
1415
+ /**
1416
+ * Detected connection type based on auth requirements.
1417
+ * - "wifi": Device requires authentication (returned 401/403).
1418
+ * - "usb": Device allows access without token (returned 200).
1419
+ * - "unknown": Detection failed or not yet completed.
1420
+ */
1421
+ u(this, "connectionType", "unknown");
1422
+ if (!t || !t.addr && !t.token)
1423
+ this.addr = E;
1424
+ else if (!t.addr)
1425
+ this.addr = xt;
1426
+ else {
1427
+ let n = t.addr.trim();
1428
+ if (/^https?:\/\//i.test(n) || (n = `http://${n}`), _t.test(n) && !t.token)
1429
+ throw new Error("Token is required. Please provide it.");
1430
+ this.addr = n;
1431
+ }
1432
+ this.apiSemver = "", C(
1433
+ `${this.addr}/api/`,
1434
+ this.SystemVersionGet.bind(this),
1435
+ t == null ? void 0 : t.token
1436
+ ), this.detectConnectionType();
991
1437
  }
992
1438
  /**
993
- * Sends a button press.
994
- *
995
- * @param params - Button press parameters:
996
- * @param {InputKeyParams['keyName']} params.keyName - Button key.
997
- * @example
998
- * {
999
- * keyName: "ok"
1000
- * }
1001
- * @returns {Promise<SuccessResponse>} Result of pressing the button.
1002
- */
1003
- async pressButton(t) {
1004
- return await pt(t);
1439
+ * Probes the device to determine connection type.
1440
+ * Sends a request without authentication credentials.
1441
+ */
1442
+ async detectConnectionType() {
1443
+ const t = new URL(this.addr).hostname;
1444
+ if (!g(t) && !k(t)) {
1445
+ this.connectionType = "wifi";
1446
+ return;
1447
+ }
1448
+ const n = b({
1449
+ baseUrl: `${this.addr}/api/`
1450
+ });
1451
+ try {
1452
+ const { response: i } = await n.GET("/name");
1453
+ if (i.status === 401 || i.status === 403)
1454
+ this.connectionType = "wifi";
1455
+ else if (i.ok)
1456
+ this.connectionType = "usb";
1457
+ else
1458
+ throw new Error(
1459
+ `Failed to detect connection type. Status: ${i.status}`
1460
+ );
1461
+ } catch (i) {
1462
+ throw i;
1463
+ }
1005
1464
  }
1006
1465
  }
1007
- var E = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(E || {});
1008
- const g = 3e3, k = /* @__PURE__ */ new Set([1001, 1006, 1012, 1013, 1014, 3008]);
1009
- function S(e, t) {
1466
+ function qt(e, t) {
1467
+ t.forEach((n) => {
1468
+ Object.getOwnPropertyNames(n.prototype).forEach((i) => {
1469
+ Object.defineProperty(
1470
+ e.prototype,
1471
+ i,
1472
+ Object.getOwnPropertyDescriptor(n.prototype, i) || /* @__PURE__ */ Object.create(null)
1473
+ );
1474
+ });
1475
+ });
1476
+ }
1477
+ qt(Ft, [
1478
+ N,
1479
+ F,
1480
+ J,
1481
+ nt,
1482
+ at,
1483
+ wt,
1484
+ mt,
1485
+ At,
1486
+ Ot,
1487
+ $t,
1488
+ Wt,
1489
+ Kt
1490
+ ]);
1491
+ var T = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(T || {});
1492
+ const A = 3e3, v = /* @__PURE__ */ new Set([1001, 1006, 1012, 1013, 1014, 3008]);
1493
+ function P(e, t) {
1010
1494
  if (t < 0 || t >= e.length)
1011
1495
  throw new Error(`Index ${t} is out of bounds (0…${e.length - 1})`);
1012
- const i = e[t];
1013
- if (i === void 0)
1496
+ const n = e[t];
1497
+ if (n === void 0)
1014
1498
  throw new Error(`Unexpected undefined at index ${t}`);
1015
- return i;
1499
+ return n;
1016
1500
  }
1017
- function At(e, t) {
1018
- let i = 0;
1019
- const n = e.length, s = [];
1020
- for (; i < n; ) {
1021
- const a = S(e, i);
1022
- if (i += 1, (a & 128) !== 0) {
1023
- const c = a & 127;
1024
- for (let f = 0; f < c * t; f++)
1025
- s.push(e[i + f]);
1026
- i += c * t;
1501
+ function jt(e, t) {
1502
+ let n = 0;
1503
+ const i = e.length, r = [];
1504
+ for (; n < i; ) {
1505
+ const c = P(e, n);
1506
+ if (n += 1, (c & 128) !== 0) {
1507
+ const a = c & 127;
1508
+ for (let f = 0; f < a * t; f++)
1509
+ r.push(e[n + f]);
1510
+ n += a * t;
1027
1511
  } else {
1028
- const c = a, f = e.slice(i, i + t);
1029
- for (let u = 0; u < c; u++)
1030
- for (let l = 0; l < t; l++)
1031
- s.push(f[l]);
1032
- i += t;
1512
+ const a = c, f = e.slice(n, n + t);
1513
+ for (let w = 0; w < a; w++)
1514
+ for (let d = 0; d < t; d++)
1515
+ r.push(f[d]);
1516
+ n += t;
1033
1517
  }
1034
1518
  }
1035
- return new Uint8Array(s);
1519
+ return new Uint8Array(r);
1036
1520
  }
1037
- function gt(e) {
1521
+ function zt(e) {
1038
1522
  const t = new Uint8Array(e.length * 2);
1039
- let i = 0, n = 0;
1040
- for (; i < e.length; ) {
1041
- const s = S(e, i), a = s & 15, c = s >> 4 & 15;
1042
- t[n] = a, t[n + 1] = c, i += 1, n += 2;
1523
+ let n = 0, i = 0;
1524
+ for (; n < e.length; ) {
1525
+ const r = P(e, n), c = r & 15, a = r >> 4 & 15;
1526
+ t[i] = c, t[i + 1] = a, n += 1, i += 2;
1043
1527
  }
1044
1528
  return t;
1045
1529
  }
1046
- class Pt {
1530
+ const L = () => typeof window < "u" && typeof window.document < "u";
1531
+ class Xt {
1047
1532
  constructor(t) {
1048
- o(this, "connected", !1);
1533
+ u(this, "addr");
1534
+ u(this, "connected", !1);
1049
1535
  // @ts-ignore
1050
- o(this, "apiKey");
1536
+ u(this, "apiKey");
1051
1537
  // @ts-ignore
1052
- o(this, "apiSemver");
1053
- o(this, "dataListeners", []);
1054
- o(this, "stopListeners", []);
1055
- o(this, "errorListeners", []);
1056
- o(this, "socket", null);
1057
- if (this.config = t, !(() => typeof window < "u" && typeof window.document < "u"))
1538
+ u(this, "apiSemver");
1539
+ u(this, "dataListeners", []);
1540
+ u(this, "stopListeners", []);
1541
+ u(this, "errorListeners", []);
1542
+ u(this, "socket", null);
1543
+ if (this.config = t, !L())
1058
1544
  throw new Error("not browser");
1059
- t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver);
1545
+ if (t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver), !t || !t.addr)
1546
+ this.addr = E;
1547
+ else {
1548
+ let n = t.addr.trim();
1549
+ /^https?:\/\//i.test(n) || (n = `http://${n}`);
1550
+ try {
1551
+ const r = new URL(n).hostname;
1552
+ if (!g(r) && !k(r))
1553
+ throw new Error(
1554
+ `Invalid address: "${t.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`
1555
+ );
1556
+ } catch (i) {
1557
+ throw i instanceof Error && i.message.startsWith("Invalid address") ? i : new Error(`Invalid URL format: "${t.addr}"`);
1558
+ }
1559
+ this.addr = n;
1560
+ }
1060
1561
  }
1061
1562
  onData(t) {
1062
1563
  this.dataListeners.push(t);
@@ -1068,62 +1569,53 @@ class Pt {
1068
1569
  this.errorListeners.push(t);
1069
1570
  }
1070
1571
  emitData(t) {
1071
- for (const i of this.dataListeners)
1072
- i(t);
1572
+ for (const n of this.dataListeners)
1573
+ n(t);
1073
1574
  }
1074
1575
  emitStop() {
1075
1576
  for (const t of this.stopListeners)
1076
1577
  t();
1077
1578
  }
1078
1579
  emitError(t) {
1079
- for (const i of this.errorListeners)
1080
- i(t);
1580
+ for (const n of this.errorListeners)
1581
+ n(t);
1081
1582
  }
1082
1583
  async openWebsocket() {
1083
1584
  this.socket && await this.closeWebsocket();
1084
- let t;
1085
- if (this.config.mode === "cloud" ? t = new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`) : this.config.mode === "local" && (t = new URL(`${this.config.barUrl}/api/screen/ws`), this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver)), !t)
1585
+ const t = new URL(`${this.addr}/api/screen/ws`);
1586
+ if (this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver), !t)
1086
1587
  throw new Error("The WebSocket URL is not specified");
1087
1588
  this.socket = new WebSocket(t), this.socket.onopen = () => {
1088
- this.socket && (this.config.mode === "cloud" ? this.socket.send(
1089
- JSON.stringify({
1090
- token: this.config.token,
1091
- display: this.config.deviceScreen
1092
- })
1093
- ) : this.config.mode === "local" && this.socket.send(JSON.stringify({ display: this.config.deviceScreen })), this.connected = !0);
1094
- }, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (i) => {
1589
+ this.socket && (this.socket.send(JSON.stringify({ display: this.config.deviceScreen })), this.connected = !0);
1590
+ }, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (n) => {
1095
1591
  try {
1096
- if (typeof i.data == "string")
1592
+ if (typeof n.data == "string")
1097
1593
  return;
1098
- const n = new Uint8Array(i.data);
1099
- if (this.config.mode === "cloud")
1100
- this.emitData(n);
1101
- else if (this.config.mode === "local") {
1102
- let s;
1103
- const a = this.config.deviceScreen === E.FRONT ? 3 : 2;
1104
- try {
1105
- const c = At(n, a);
1106
- this.config.deviceScreen === E.BACK ? s = gt(c) : s = c, this.emitData(s);
1107
- } catch {
1108
- this.emitData(n);
1109
- }
1594
+ const i = new Uint8Array(n.data);
1595
+ let r;
1596
+ const c = this.config.deviceScreen === T.FRONT ? 3 : 2;
1597
+ try {
1598
+ const a = jt(i, c);
1599
+ this.config.deviceScreen === T.BACK ? r = zt(a) : r = a, this.emitData(r);
1600
+ } catch {
1601
+ this.emitData(i);
1110
1602
  }
1111
1603
  } catch {
1112
1604
  this.connected = !1, this.emitStop();
1113
1605
  }
1114
- }, this.socket.onerror = (i) => {
1606
+ }, this.socket.onerror = (n) => {
1115
1607
  this.connected = !1, this.emitError({
1116
1608
  code: 1006,
1117
1609
  // Standard «abnormal closure» code per RFC-6455
1118
1610
  message: "WebSocket error occurred",
1119
- raw: i
1611
+ raw: n
1120
1612
  }), this.emitStop();
1121
- }, this.socket.onclose = async (i) => {
1122
- if (this.socket = null, this.connected = !1, i.code === g || k.has(i.code)) {
1613
+ }, this.socket.onclose = async (n) => {
1614
+ if (this.socket = null, this.connected = !1, n.code === A || v.has(n.code)) {
1123
1615
  this.emitError({
1124
- code: i.code,
1125
- message: i.reason,
1126
- raw: i
1616
+ code: n.code,
1617
+ message: n.reason,
1618
+ raw: n
1127
1619
  });
1128
1620
  return;
1129
1621
  }
@@ -1138,21 +1630,38 @@ class Pt {
1138
1630
  });
1139
1631
  }
1140
1632
  }
1141
- class vt {
1633
+ class Qt {
1142
1634
  constructor(t) {
1143
- o(this, "connected", !1);
1635
+ u(this, "addr");
1636
+ u(this, "connected", !1);
1144
1637
  // @ts-ignore
1145
- o(this, "apiKey");
1638
+ u(this, "apiKey");
1146
1639
  // @ts-ignore
1147
- o(this, "apiSemver");
1148
- o(this, "inputEvent");
1149
- o(this, "dataListeners", []);
1150
- o(this, "stopListeners", []);
1151
- o(this, "errorListeners", []);
1152
- o(this, "socket", null);
1153
- if (this.config = t, !(() => typeof window < "u" && typeof window.document < "u"))
1640
+ u(this, "apiSemver");
1641
+ u(this, "inputEvent");
1642
+ u(this, "dataListeners", []);
1643
+ u(this, "stopListeners", []);
1644
+ u(this, "errorListeners", []);
1645
+ u(this, "socket", null);
1646
+ if (!L())
1154
1647
  throw new Error("not browser");
1155
- t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver), this.inputEvent = {};
1648
+ if (t != null && t.apiKey && (this.apiKey = t.apiKey), t != null && t.apiSemver && (this.apiSemver = t.apiSemver), !t || !t.addr)
1649
+ this.addr = E;
1650
+ else {
1651
+ let n = t.addr.trim();
1652
+ /^https?:\/\//i.test(n) || (n = `http://${n}`);
1653
+ try {
1654
+ const r = new URL(n).hostname;
1655
+ if (!g(r) && !k(r))
1656
+ throw new Error(
1657
+ `Invalid address: "${t.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`
1658
+ );
1659
+ } catch (i) {
1660
+ throw i instanceof Error && i.message.startsWith("Invalid address") ? i : new Error(`Invalid URL format: "${t.addr}"`);
1661
+ }
1662
+ this.addr = n;
1663
+ }
1664
+ this.inputEvent = {};
1156
1665
  }
1157
1666
  onData(t) {
1158
1667
  this.dataListeners.push(t);
@@ -1164,56 +1673,56 @@ class vt {
1164
1673
  this.errorListeners.push(t);
1165
1674
  }
1166
1675
  emitData(t) {
1167
- for (const i of this.dataListeners)
1168
- i(t);
1676
+ for (const n of this.dataListeners)
1677
+ n(t);
1169
1678
  }
1170
1679
  emitStop() {
1171
1680
  for (const t of this.stopListeners)
1172
1681
  t();
1173
1682
  }
1174
1683
  emitError(t) {
1175
- for (const i of this.errorListeners)
1176
- i(t);
1684
+ for (const n of this.errorListeners)
1685
+ n(t);
1177
1686
  }
1178
1687
  async openWebsocket() {
1179
1688
  this.socket && await this.closeWebsocket();
1180
- let t;
1181
- if (this.config.mode === "cloud" ? t = new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`) : this.config.mode === "local" && (t = new URL(`${this.config.barUrl}/api/input`), this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver)), !t)
1689
+ const t = new URL(`${this.addr}/api/input`);
1690
+ if (this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver), !t)
1182
1691
  throw new Error("The WebSocket URL is not specified");
1183
1692
  this.socket = new WebSocket(t), this.socket.onopen = () => {
1184
1693
  this.socket && (this.connected = !0);
1185
- }, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (i) => {
1694
+ }, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (n) => {
1186
1695
  try {
1187
- if (typeof i.data == "string")
1696
+ if (typeof n.data == "string")
1188
1697
  return;
1189
- const n = new Uint8Array(i.data);
1190
- this.emitData(n);
1698
+ const i = new Uint8Array(n.data);
1699
+ this.emitData(i);
1191
1700
  } catch {
1192
1701
  this.connected = !1, this.emitStop();
1193
1702
  }
1194
- }, this.socket.onerror = (i) => {
1703
+ }, this.socket.onerror = (n) => {
1195
1704
  this.connected = !1, this.emitError({
1196
1705
  code: 1006,
1197
1706
  // Standard «abnormal closure» code per RFC-6455
1198
1707
  message: "WebSocket error occurred",
1199
- raw: i
1708
+ raw: n
1200
1709
  }), this.emitStop();
1201
- }, this.socket.onclose = async (i) => {
1202
- if (this.socket = null, this.connected = !1, i.code === g || k.has(i.code)) {
1710
+ }, this.socket.onclose = async (n) => {
1711
+ if (this.socket = null, this.connected = !1, n.code === A || v.has(n.code)) {
1203
1712
  this.emitError({
1204
- code: i.code,
1205
- message: i.reason,
1206
- raw: i
1713
+ code: n.code,
1714
+ message: n.reason,
1715
+ raw: n
1207
1716
  });
1208
1717
  return;
1209
1718
  }
1210
1719
  this.emitStop();
1211
1720
  };
1212
1721
  }
1213
- sendInput({ keyName: t, value: i }) {
1722
+ sendInput({ keyName: t, value: n }) {
1214
1723
  if (!this.socket || !this.connected)
1215
1724
  throw new Error("WebSocket: Not connected");
1216
- this.inputEvent[t] = i, this.socket.send(JSON.stringify(this.inputEvent)), i === 0 && delete this.inputEvent[t];
1725
+ this.inputEvent[t] = n, this.socket.send(JSON.stringify(this.inputEvent)), n === 0 && delete this.inputEvent[t];
1217
1726
  }
1218
1727
  closeWebsocket() {
1219
1728
  return this.connected = !1, new Promise((t) => {
@@ -1224,8 +1733,8 @@ class vt {
1224
1733
  }
1225
1734
  }
1226
1735
  export {
1227
- Tt as BusyBar,
1228
- E as DeviceScreen,
1229
- vt as Input,
1230
- Pt as ScreenStream
1736
+ Ft as BusyBar,
1737
+ T as DeviceScreen,
1738
+ Qt as Input,
1739
+ Xt as ScreenStream
1231
1740
  };