@busy-app/busy-lib 0.2.1 → 0.3.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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var P=(e,t,i)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var o=(e,t,i)=>P(e,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("openapi-fetch");function b(e){const t=e.split(".");if(t.length!==4)return!1;for(const i of t){if(i.length===0||i.length>1&&i[0]==="0"||!/^\d+$/.test(i))return!1;const n=Number(i);if(n<0||n>255)return!1}return!0}const I=(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 i;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)};let y,w,l=null;async function E(){if(!w){if(!y)throw new Error("getApiVersionFn is not set");l||(l=(async()=>{const e=await y();if(!e.api_semver)throw new Error("Empty API version");w=e.api_semver})().finally(()=>{l=null})),await l}}async function p(e){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;return Object.assign(new Error(s||`HTTP ${e.status} ${e.statusText}`),{status:e.status,statusText:e.statusText,body:n})}let m;function v(e){m=e}const B={async onRequest({request:e,schemaPath:t}){if(t!=="/version"){if(await E(),w)return e.headers.set("X-API-Sem-Ver",w);m&&e.headers.set("X-API-Token",m)}return e},async onResponse({request:e,response:t,options:i,schemaPath:n}){if(t.ok)return t;if(n==="/version")throw await p(t);if(t.status!==405)throw await p(t);w=void 0,await E(),w&&e.headers.set("X-API-Sem-Ver",w);const s=await(i.fetch??fetch)(e);if(s.ok)return s;throw await p(s)}};let r=null;function L(e,t){y=t,r=T({baseUrl:e,bodySerializer:I}),r.use(B)}async function z(e){const{appId:t,fileName:i,file:n}=e;if(!r)throw new Error("API client is not initialized");const{data:s,error:a}=await r.POST("/assets/upload",{params:{query:{app_id:t,file:i}},headers:{"Content-Type":"application/octet-stream"},body:n});if(a)throw a;return s}async function D(e){const{appId:t}=e;if(!r)throw new Error("API client is not initialized");const{data:i,error:n}=await r.DELETE("/assets/upload",{params:{query:{app_id:t}}});if(n)throw n;return i}const O={timeout:5,x:0,y:0,display:"front"};function K(e){return{...O,...e}}async function U(e){const{appId:t,elements:i}=e;if(!r)throw new Error("API client is not initialized");const n=i.map(K),{data:s,error:a}=await r.POST("/display/draw",{body:{app_id:t,elements:n}});if(a)throw a;return s}async function C(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/display/draw");if(t)throw t;return e}async function W(e){const{appId:t,path:i}=e;if(!r)throw new Error("API client is not initialized");const{data:n,error:s}=await r.POST("/audio/play",{params:{query:{app_id:t,path:i}}});if(s)throw s;return n}async function $(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/audio/play");if(t)throw t;return e}async function F(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/enable");if(t)throw t;return e}async function R(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disable");if(t)throw t;return e}async function V(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/status");if(t)throw t;return e}async function _(e){if(!r)throw new Error("API client is not initialized");const{data:t,error:i}=await r.POST("/wifi/connect",{body:{ssid:e.ssid,password:e.password,security:e.security,ip_config:{ip_method:e.ipConfig.ipMethod,ip_type:e.ipConfig.ipType,address:e.ipConfig.address,mask:e.ipConfig.mask,gateway:e.ipConfig.gateway}}});if(i)throw i;return t}async function q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disconnect");if(t)throw t;return e}async function x(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/networks");if(t)throw t;return e}async function N(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/forget");if(t)throw t;return e}async function G(e){if(!r)throw new Error("API client is not initialized");const{path:t,file:i}=e,{data:n,error:s}=await r.POST("/storage/write",{params:{query:{path:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function j(e){if(!r)throw new Error("API client is not initialized");const{path:t,asArrayBuffer:i}=e,{data:n,error:s}=await r.GET("/storage/read",{params:{query:{path:t}},parseAs:i?"arrayBuffer":"blob"});if(s)throw s;return n}async function H(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.GET("/storage/list",{params:{query:{path:t}}});if(n)throw n;return i}async function J(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.DELETE("/storage/remove",{params:{query:{path:t}}});if(n)throw n;return i}async function X(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.POST("/storage/mkdir",{params:{query:{path:t}}});if(n)throw n;return i}async function M(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/version");if(t)throw t;return e}async function Q(e){if(!r)throw new Error("API client is not initialized");const{name:t,file:i}=e,{data:n,error:s}=await r.POST("/update",{params:{query:{name:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function Y(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status");if(t)throw t;return e}async function Z(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/system");if(t)throw t;return e}async function tt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/power");if(t)throw t;return e}async function et(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/display/brightness");if(t)throw t;return e}async function it(e){if(!r)throw new Error("API client is not initialized");const{front:t,back:i}=e,n=u=>{if(typeof u=="number"){if(u<0||u>100)throw new Error("Brightness value must be between 0 and 100 or 'auto'");return String(u)}if(u==="auto")return"auto"},s=n(t),a=n(i),{data:c,error:f}=await r.POST("/display/brightness",{params:{query:{front:s,back:a}}});if(f)throw f;return c}async function rt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/audio/volume");if(t)throw t;return e}async function nt(e){if(!r)throw new Error("API client is not initialized");const{volume:t}=e;if(typeof t!="number"||t<0||t>100)throw new Error("Volume must be a number between 0 and 100");const{data:i,error:n}=await r.POST("/audio/volume",{params:{query:{volume:t}}});if(n)throw n;return i}async function st(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/access");if(t)throw t;return e}async function ot(e){if(!r)throw new Error("API client is not initialized");const{mode:t,key:i}=e;if(!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:n,error:s}=await r.POST("/access",{params:{query:{mode:t,key:i}}});if(s)throw s;return n}async function at(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/enable");if(t)throw t;return e}async function ct(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/disable");if(t)throw t;return e}async function ft(e){if(!r)throw new Error("API client is not initialized");const{keyName:t}=e,{data:i,error:n}=await r.POST("/input",{params:{query:{key:t}}});if(n)throw n;return i}class ut{constructor(t="10.0.4.20"){o(this,"ip");o(this,"apiSemver");if(!b(t))throw new Error(`Incorrect IPv4: ${t}`);this.ip=t,this.apiSemver="",L(`http://${this.ip}/api/`,this.getApiVersion.bind(this))}async getApiVersion(){const t=await M();return this.apiSemver=t.api_semver,t}async updateFirmware(t){return await Q(t)}async deviceStatus(){return await Y()}async systemStatus(){return await Z()}async powerStatus(){return await tt()}async uploadAsset(t){return await z(t)}async deleteAssets(t){return await D(t)}async drawDisplay(t){return await U(t)}async clearDisplay(){return await C()}async playSound(t){return await W(t)}async stopSound(){return await $()}async enableWifi(){return await F()}async disableWifi(){return await R()}async statusWifi(){return await V()}async connectWifi(t){return await _(t)}async disconnectWifi(){return await q()}async networksWifi(){return await x()}async forgetWifi(){return await N()}async uploadFile(t){return await G(t)}async downloadFile(t){return await j(t)}async readDirectory(t){return await H(t)}async removeResource(t){return await J(t)}async createDirectory(t){return await X(t)}async getDisplayBrightness(){return await et()}async setDisplayBrightness(t){return await it(t)}async getAudioVolume(){return await rt()}async setAudioVolume(t){return await nt(t)}async getHttpAccess(){return await st()}async setHttpAccess(t){const i=await ot(t);return t.mode==="key"&&t.key&&this.setApiKey(t.key),i}setApiKey(t){v(t)}async enableBle(){return await at()}async disableBle(){return await ct()}async pressButton(t){return await ft(t)}}var h=(e=>(e[e.FRONT=0]="FRONT",e[e.BACK=1]="BACK",e))(h||{});const g=3e3,S=new Set([1001,1006,1012,1013,1014,3008]);function A(e,t){if(t<0||t>=e.length)throw new Error(`Index ${t} is out of bounds (0…${e.length-1})`);const i=e[t];if(i===void 0)throw new Error(`Unexpected undefined at index ${t}`);return i}function wt(e,t){let i=0;const n=e.length,s=[];for(;i<n;){const a=A(e,i);if(i+=1,(a&128)!==0){const c=a&127;for(let f=0;f<c*t;f++)s.push(e[i+f]);i+=c*t}else{const c=a,f=e.slice(i,i+t);for(let u=0;u<c;u++)for(let d=0;d<t;d++)s.push(f[d]);i+=t}}return new Uint8Array(s)}function lt(e){const t=new Uint8Array(e.length*2);let i=0,n=0;for(;i<e.length;){const s=A(e,i),a=s&15,c=s>>4&15;t[n]=a,t[n+1]=c,i+=1,n+=2}return t}class ht{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver)}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;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)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.config.mode==="cloud"?this.socket.send(JSON.stringify({token:this.config.token,display:this.config.deviceScreen})):this.config.mode==="local"&&this.socket.send(JSON.stringify({display:this.config.deviceScreen})),this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);if(this.config.mode==="cloud")this.emitData(n);else if(this.config.mode==="local"){let s;const a=this.config.deviceScreen===h.FRONT?3:2;try{const c=wt(n,a);this.config.deviceScreen===h.BACK?s=lt(c):s=c,this.emitData(s)}catch{this.emitData(n)}}}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}class dt{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"inputEvent");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver),this.inputEvent={}}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;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)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);this.emitData(n)}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}sendInput({keyName:t,value:i}){if(!this.socket||!this.connected)throw new Error("WebSocket: Not connected");this.inputEvent[t]=i,this.socket.send(JSON.stringify(this.inputEvent)),i===0&&delete this.inputEvent[t]}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}exports.BusyBar=ut;exports.DeviceScreen=h;exports.Input=dt;exports.ScreenStream=ht;
1
+ "use strict";var k=Object.defineProperty;var P=(e,t,i)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var o=(e,t,i)=>P(e,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("openapi-fetch"),b=(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 i;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)};let y,w,h=null;async function E(){if(!w){if(!y)throw new Error("getApiVersionFn is not set");h||(h=(async()=>{const e=await y();if(!e.api_semver)throw new Error("Empty API version");w=e.api_semver})().finally(()=>{h=null})),await h}}async function p(e){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;return Object.assign(new Error(s||`HTTP ${e.status} ${e.statusText}`),{status:e.status,statusText:e.statusText,body:n})}let m;function I(e){m=e}const v={async onRequest({request:e,schemaPath:t}){if(t!=="/version"){if(await E(),w)return e.headers.set("X-API-Sem-Ver",w);m&&e.headers.set("X-API-Token",m)}return e},async onResponse({request:e,response:t,options:i,schemaPath:n}){if(t.ok)return t;if(n==="/version")throw await p(t);if(t.status!==405)throw await p(t);w=void 0,await E(),w&&e.headers.set("X-API-Sem-Ver",w);const s=await(i.fetch??fetch)(e);if(s.ok)return s;throw await p(s)}};let r=null;function B(e,t){y=t,r=T({baseUrl:e,bodySerializer:b}),r.use(v)}async function L(e){const{appId:t,fileName:i,file:n}=e;if(!r)throw new Error("API client is not initialized");const{data:s,error:a}=await r.POST("/assets/upload",{params:{query:{app_id:t,file:i}},headers:{"Content-Type":"application/octet-stream"},body:n});if(a)throw a;return s}async function z(e){const{appId:t}=e;if(!r)throw new Error("API client is not initialized");const{data:i,error:n}=await r.DELETE("/assets/upload",{params:{query:{app_id:t}}});if(n)throw n;return i}const D={timeout:5,x:0,y:0,display:"front"};function O(e){return{...D,...e}}async function K(e){const{appId:t,elements:i}=e;if(!r)throw new Error("API client is not initialized");const n=i.map(O),{data:s,error:a}=await r.POST("/display/draw",{body:{app_id:t,elements:n}});if(a)throw a;return s}async function U(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/display/draw");if(t)throw t;return e}async function C(e){const{appId:t,path:i}=e;if(!r)throw new Error("API client is not initialized");const{data:n,error:s}=await r.POST("/audio/play",{params:{query:{app_id:t,path:i}}});if(s)throw s;return n}async function W(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/audio/play");if(t)throw t;return e}async function $(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/enable");if(t)throw t;return e}async function F(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disable");if(t)throw t;return e}async function R(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/status");if(t)throw t;return e}async function V(e){if(!r)throw new Error("API client is not initialized");const{data:t,error:i}=await r.POST("/wifi/connect",{body:{ssid:e.ssid,password:e.password,security:e.security,ip_config:{ip_method:e.ipConfig.ipMethod,ip_type:e.ipConfig.ipType,address:e.ipConfig.address,mask:e.ipConfig.mask,gateway:e.ipConfig.gateway}}});if(i)throw i;return t}async function _(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disconnect");if(t)throw t;return e}async function q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/networks");if(t)throw t;return e}async function x(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/forget");if(t)throw t;return e}async function G(e){if(!r)throw new Error("API client is not initialized");const{path:t,file:i}=e,{data:n,error:s}=await r.POST("/storage/write",{params:{query:{path:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function N(e){if(!r)throw new Error("API client is not initialized");const{path:t,asArrayBuffer:i}=e,{data:n,error:s}=await r.GET("/storage/read",{params:{query:{path:t}},parseAs:i?"arrayBuffer":"blob"});if(s)throw s;return n}async function j(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.GET("/storage/list",{params:{query:{path:t}}});if(n)throw n;return i}async function H(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.DELETE("/storage/remove",{params:{query:{path:t}}});if(n)throw n;return i}async function J(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.POST("/storage/mkdir",{params:{query:{path:t}}});if(n)throw n;return i}async function X(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/version");if(t)throw t;return e}async function M(e){if(!r)throw new Error("API client is not initialized");const{name:t,file:i}=e,{data:n,error:s}=await r.POST("/update",{params:{query:{name:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function Q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status");if(t)throw t;return e}async function Y(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/system");if(t)throw t;return e}async function Z(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/power");if(t)throw t;return e}async function tt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/display/brightness");if(t)throw t;return e}async function et(e){if(!r)throw new Error("API client is not initialized");const{front:t,back:i}=e,n=u=>{if(typeof u=="number"){if(u<0||u>100)throw new Error("Brightness value must be between 0 and 100 or 'auto'");return String(u)}if(u==="auto")return"auto"},s=n(t),a=n(i),{data:c,error:f}=await r.POST("/display/brightness",{params:{query:{front:s,back:a}}});if(f)throw f;return c}async function it(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/audio/volume");if(t)throw t;return e}async function rt(e){if(!r)throw new Error("API client is not initialized");const{volume:t}=e;if(typeof t!="number"||t<0||t>100)throw new Error("Volume must be a number between 0 and 100");const{data:i,error:n}=await r.POST("/audio/volume",{params:{query:{volume:t}}});if(n)throw n;return i}async function nt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/access");if(t)throw t;return e}async function st(e){if(!r)throw new Error("API client is not initialized");const{mode:t,key:i}=e;if(!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:n,error:s}=await r.POST("/access",{params:{query:{mode:t,key:i}}});if(s)throw s;return n}async function ot(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/enable");if(t)throw t;return e}async function at(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/disable");if(t)throw t;return e}async function ct(e){if(!r)throw new Error("API client is not initialized");const{keyName:t}=e,{data:i,error:n}=await r.POST("/input",{params:{query:{key:t}}});if(n)throw n;return i}class ft{constructor(t){o(this,"host");o(this,"apiSemver");this.host=t.host,this.apiSemver="",B(`http://${this.host}/api/`,this.getApiVersion.bind(this))}async getApiVersion(){const t=await X();return this.apiSemver=t.api_semver,t}async updateFirmware(t){return await M(t)}async deviceStatus(){return await Q()}async systemStatus(){return await Y()}async powerStatus(){return await Z()}async uploadAsset(t){return await L(t)}async deleteAssets(t){return await z(t)}async drawDisplay(t){return await K(t)}async clearDisplay(){return await U()}async playSound(t){return await C(t)}async stopSound(){return await W()}async enableWifi(){return await $()}async disableWifi(){return await F()}async statusWifi(){return await R()}async connectWifi(t){return await V(t)}async disconnectWifi(){return await _()}async networksWifi(){return await q()}async forgetWifi(){return await x()}async uploadFile(t){return await G(t)}async downloadFile(t){return await N(t)}async readDirectory(t){return await j(t)}async removeResource(t){return await H(t)}async createDirectory(t){return await J(t)}async getDisplayBrightness(){return await tt()}async setDisplayBrightness(t){return await et(t)}async getAudioVolume(){return await it()}async setAudioVolume(t){return await rt(t)}async getHttpAccess(){return await nt()}async setHttpAccess(t){const i=await st(t);return t.mode==="key"&&t.key&&this.setApiKey(t.key),i}setApiKey(t){I(t)}async enableBle(){return await ot()}async disableBle(){return await at()}async pressButton(t){return await ct(t)}}var l=(e=>(e[e.FRONT=0]="FRONT",e[e.BACK=1]="BACK",e))(l||{});const g=3e3,S=new Set([1001,1006,1012,1013,1014,3008]);function A(e,t){if(t<0||t>=e.length)throw new Error(`Index ${t} is out of bounds (0…${e.length-1})`);const i=e[t];if(i===void 0)throw new Error(`Unexpected undefined at index ${t}`);return i}function ut(e,t){let i=0;const n=e.length,s=[];for(;i<n;){const a=A(e,i);if(i+=1,(a&128)!==0){const c=a&127;for(let f=0;f<c*t;f++)s.push(e[i+f]);i+=c*t}else{const c=a,f=e.slice(i,i+t);for(let u=0;u<c;u++)for(let d=0;d<t;d++)s.push(f[d]);i+=t}}return new Uint8Array(s)}function wt(e){const t=new Uint8Array(e.length*2);let i=0,n=0;for(;i<e.length;){const s=A(e,i),a=s&15,c=s>>4&15;t[n]=a,t[n+1]=c,i+=1,n+=2}return t}class ht{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver)}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;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)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.config.mode==="cloud"?this.socket.send(JSON.stringify({token:this.config.token,display:this.config.deviceScreen})):this.config.mode==="local"&&this.socket.send(JSON.stringify({display:this.config.deviceScreen})),this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);if(this.config.mode==="cloud")this.emitData(n);else if(this.config.mode==="local"){let s;const a=this.config.deviceScreen===l.FRONT?3:2;try{const c=ut(n,a);this.config.deviceScreen===l.BACK?s=wt(c):s=c,this.emitData(s)}catch{this.emitData(n)}}}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}class lt{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"inputEvent");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver),this.inputEvent={}}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;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)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);this.emitData(n)}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}sendInput({keyName:t,value:i}){if(!this.socket||!this.connected)throw new Error("WebSocket: Not connected");this.inputEvent[t]=i,this.socket.send(JSON.stringify(this.inputEvent)),i===0&&delete this.inputEvent[t]}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}exports.BusyBar=ft;exports.DeviceScreen=l;exports.Input=lt;exports.ScreenStream=ht;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ declare interface AudioParams {
7
7
  path: paths["/audio/play"]["post"]["parameters"]["query"]["path"];
8
8
  }
9
9
 
10
+ export declare type AudioVolumeInfo = components["schemas"]["AudioVolumeInfo"];
11
+
10
12
  declare interface AudioVolumeParams {
11
13
  volume: operations["setAudioVolume"]["parameters"]["query"]["volume"];
12
14
  }
@@ -36,58 +38,56 @@ declare interface BrightnessParams {
36
38
  */
37
39
  export declare class BusyBar {
38
40
  /**
39
- * Device IPv4 address.
40
- * @type {IPv4}
41
+ * Device host address (IP or mDNS).
42
+ * @type {BusyBarConfig['host']}
41
43
  * @readonly
42
44
  */
43
- readonly ip: IPv4;
44
- private apiSemver;
45
+ readonly host: BusyBarConfig["host"];
46
+ /**
47
+ * Current API semantic version.
48
+ * @type {ApiSemver}
49
+ */
50
+ apiSemver: ApiSemver;
45
51
  /**
46
52
  * Creates an instance of BUSY Bar.
47
- * Initializes the API client with the provided IPv4 address.
53
+ * Initializes the API client with the provided host address.
48
54
  *
49
- * @param {IPv4} [ip="10.0.4.20"] - The IPv4 address of the device.
50
- * @throws {Error} If the provided IP is not a valid IPv4 address.
55
+ * @param {BusyBarConfig} config - The host address of the device (IP or mDNS).
51
56
  */
52
- constructor(ip?: IPv4);
57
+ constructor(config: BusyBarConfig);
53
58
  /**
54
59
  * Retrieves the API semantic version.
55
60
  *
56
- * @returns A promise that resolves to an object containing the `api_semver` string.
61
+ * @returns {Promise<VersionInfo>} A promise that resolves to an object containing the `api_semver` string.
57
62
  */
58
- private getApiVersion;
63
+ getApiVersion(): Promise<VersionInfo>;
59
64
  /**
60
65
  * Updates the firmware.
61
66
  *
62
67
  * @param {UpdateParams} params - Parameters for the firmware update.
63
68
  * @param {UpdateParams['name']} params.name - Name for the update package.
64
69
  * @param {UpdateParams['file']} params.file - File data to upload.
65
- * @returns Result of the update operation.
70
+ * @returns {Promise<SuccessResponse>} Result of the update operation.
66
71
  */
67
- updateFirmware(params: UpdateParams): Promise<{
68
- result: string;
69
- }>;
72
+ updateFirmware(params: UpdateParams): Promise<SuccessResponse>;
70
73
  /**
71
74
  * Gets the current status of the device, including system and power information.
72
75
  *
73
- * @returns Current status of the device.
76
+ * @returns {Promise<Status>} Current status of the device.
74
77
  */
75
- deviceStatus(): Promise<{
76
- system?: components["schemas"]["StatusSystem"];
77
- power?: components["schemas"]["StatusPower"];
78
- }>;
78
+ deviceStatus(): Promise<Status>;
79
79
  /**
80
80
  * Gets the current system status.
81
81
  *
82
- * @returns Current system status.
82
+ * @returns {Promise<StatusSystem>} Current system status.
83
83
  */
84
- systemStatus(): Promise<components["schemas"]["StatusSystem"]>;
84
+ systemStatus(): Promise<StatusSystem>;
85
85
  /**
86
86
  * Gets the current power status.
87
87
  *
88
- * @returns Current power status.
88
+ * @returns {Promise<StatusPower>} Current power status.
89
89
  */
90
- powerStatus(): Promise<components["schemas"]["StatusPower"]>;
90
+ powerStatus(): Promise<StatusPower>;
91
91
  /**
92
92
  * Uploads an asset to the device.
93
93
  *
@@ -95,77 +95,65 @@ export declare class BusyBar {
95
95
  * @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
96
96
  * @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
97
97
  * @param {UploadParams['file']} params.file - File data to upload.
98
- * @returns {Promise<{ result: string }>} Result of the upload operation.
98
+ * @returns {Promise<SuccessResponse>} Result of the upload operation.
99
99
  */
100
- uploadAsset(params: UploadParams): Promise<{
101
- result: string;
102
- }>;
100
+ uploadAsset(params: UploadParams): Promise<SuccessResponse>;
103
101
  /**
104
102
  * Deletes all assets for a specific application from the device.
105
103
  *
106
104
  * @param {DeleteParams} params - Parameters for the delete.
107
105
  * @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
108
- * @returns {Promise<{ result: string }>} Result of the delete operation.
106
+ * @returns {Promise<SuccessResponse>} Result of the delete operation.
109
107
  */
110
- deleteAssets(params: DeleteParams): Promise<{
111
- result: string;
112
- }>;
108
+ deleteAssets(params: DeleteParams): Promise<SuccessResponse>;
113
109
  /**
114
110
  * Draws elements on the device display.
115
111
  *
116
112
  * @param {DrawParams} params - Parameters for the draw operation.
117
113
  * @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
118
114
  * @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
119
- * @returns {Promise<{ result: string }>} Result of the draw operation.
115
+ * @returns {Promise<SuccessResponse>} Result of the draw operation.
120
116
  */
121
- drawDisplay(params: DrawParams): Promise<{
122
- result: string;
123
- }>;
117
+ drawDisplay(params: DrawParams): Promise<SuccessResponse>;
124
118
  /**
125
119
  * Clears the device display and stops the Canvas application if running.
126
120
  *
127
- * @returns {Promise<{ result: string }>} Result of the clear operation.
121
+ * @returns {Promise<SuccessResponse>} Result of the clear operation.
128
122
  */
129
- clearDisplay(): Promise<{
130
- result: string;
131
- }>;
123
+ clearDisplay(): Promise<SuccessResponse>;
132
124
  /**
133
125
  * Plays an audio file from the assets directory.
134
126
  *
135
127
  * @param {AudioParams} params - Parameters for the audio playback.
136
128
  * @param {AudioParams['appId']} params.appId - Application ID for organizing assets.
137
129
  * @param {AudioParams['path']} params.path - Path to the audio file within the app's assets directory.
138
- * @returns {Promise<{ result: string }>} Result of the play operation.
130
+ * @returns {Promise<SuccessResponse>} Result of the play operation.
139
131
  */
140
- playSound(params: AudioParams): Promise<{
141
- result: string;
142
- }>;
132
+ playSound(params: AudioParams): Promise<SuccessResponse>;
143
133
  /**
144
134
  * Stops any currently playing audio on the device.
145
135
  *
146
- * @returns {Promise<{ result: string }>} Result of the stop operation.
136
+ * @returns {Promise<SuccessResponse>} Result of the stop operation.
147
137
  */
148
- stopSound(): Promise<{
149
- result: string;
150
- }>;
138
+ stopSound(): Promise<SuccessResponse>;
151
139
  /**
152
140
  * Enables the device's Wi-Fi module.
153
141
  *
154
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the enable operation.
142
+ * @returns {Promise<SuccessResponse>} Result of the enable operation.
155
143
  */
156
- enableWifi(): Promise<components["schemas"]["SuccessResponse"]>;
144
+ enableWifi(): Promise<SuccessResponse>;
157
145
  /**
158
146
  * Disables the device's Wi-Fi module.
159
147
  *
160
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disable operation.
148
+ * @returns {Promise<SuccessResponse>} Result of the disable operation.
161
149
  */
162
- disableWifi(): Promise<components["schemas"]["SuccessResponse"]>;
150
+ disableWifi(): Promise<SuccessResponse>;
163
151
  /**
164
152
  * Gets the current status of the Wi-Fi module.
165
153
  *
166
- * @returns {Promise<components['schemas']['StatusResponse']>} Current Wi-Fi status.
154
+ * @returns {Promise<WifiStatusResponse>} Current Wi-Fi status.
167
155
  */
168
- statusWifi(): Promise<components["schemas"]["StatusResponse"]>;
156
+ statusWifi(): Promise<WifiStatusResponse>;
169
157
  /**
170
158
  * Connects the device to a Wi-Fi network with the specified parameters.
171
159
  *
@@ -179,21 +167,21 @@ export declare class BusyBar {
179
167
  * @param {ConnectParams['ipConfig']['address']} [params.ipConfig.address] - Static IP address (if using "static" method).
180
168
  * @param {ConnectParams['ipConfig']['mask']} [params.ipConfig.mask] - Subnet mask (if using "static" method).
181
169
  * @param {ConnectParams['ipConfig']['gateway']} [params.ipConfig.gateway] - Gateway address (if using "static" method).
182
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the connect operation.
170
+ * @returns {Promise<SuccessResponse>} Result of the connect operation.
183
171
  */
184
- connectWifi(params: ConnectParams): Promise<components["schemas"]["SuccessResponse"]>;
172
+ connectWifi(params: ConnectParams): Promise<SuccessResponse>;
185
173
  /**
186
174
  * Disconnects the device from the current Wi-Fi network.
187
175
  *
188
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disconnect operation.
176
+ * @returns {Promise<SuccessResponse>} Result of the disconnect operation.
189
177
  */
190
- disconnectWifi(): Promise<components["schemas"]["SuccessResponse"]>;
178
+ disconnectWifi(): Promise<SuccessResponse>;
191
179
  /**
192
180
  * Scans for available Wi-Fi networks near your device.
193
181
  *
194
- * @returns {Promise<components['schemas']['NetworkResponse']>} List of discovered networks.
182
+ * @returns {Promise<WifiNetworkResponse>} List of discovered networks.
195
183
  */
196
- networksWifi(): Promise<components["schemas"]["NetworkResponse"]>;
184
+ networksWifi(): Promise<WifiNetworkResponse>;
197
185
  /**
198
186
  * Removes the saved Wi-Fi configuration (forgets the network).
199
187
  *
@@ -206,88 +194,88 @@ export declare class BusyBar {
206
194
  * @param {UploadFileParams} params - Upload parameters:
207
195
  * @param {UploadFileParams['path']} params.path - Path where the file will be saved (e.g., "/ext/test.png").
208
196
  * @param {UploadFileParams['file']} params.file - File data to upload.
209
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the upload operation.
197
+ * @returns {Promise<SuccessResponse>} Result of the upload operation.
210
198
  */
211
- uploadFile(params: UploadFileParams): Promise<components["schemas"]["SuccessResponse"]>;
199
+ uploadFile(params: UploadFileParams): Promise<SuccessResponse>;
212
200
  /**
213
201
  * Downloads a file from the device's internal storage.
214
202
  *
215
203
  * @param {DownloadFileParams} params - Download parameters:
216
204
  * @param {DownloadFileParams['path']} params.path - Path to the file to download (e.g., "/ext/test.png").
217
205
  * @param {DownloadFileParams['asArrayBuffer']} [params.asArrayBuffer] - If true, returns data as ArrayBuffer; otherwise, as Blob.
218
- * @returns {Promise<ArrayBuffer | Blob>} The file data.
206
+ * @returns {Promise<StorageReadResponse>} The file data.
219
207
  */
220
- downloadFile(params: DownloadFileParams): Promise<ArrayBuffer | Blob>;
208
+ downloadFile(params: DownloadFileParams): Promise<StorageReadResponse>;
221
209
  /**
222
210
  * Reads the contents of a directory (files and subdirectories) at the specified path.
223
211
  *
224
212
  * @param {ReadDirectoryParams} params - List parameters:
225
213
  * @param {ReadDirectoryParams['path']} params.path - Path to the directory to list (e.g., "/ext").
226
- * @returns {Promise<components["schemas"]["StorageList"]>} List of files and directories.
214
+ * @returns {Promise<StorageList>} List of files and directories.
227
215
  */
228
- readDirectory(params: ReadDirectoryParams): Promise<components["schemas"]["StorageList"]>;
216
+ readDirectory(params: ReadDirectoryParams): Promise<StorageList>;
229
217
  /**
230
218
  * Removes a file or a directory from the device's internal storage.
231
219
  *
232
220
  * @param {RemoveParams} params - Remove parameters:
233
221
  * @param {RemoveParams['path']} params.path - Path of the file to remove (e.g., "/ext/test.png").
234
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the remove operation.
222
+ * @returns {Promise<SuccessResponse>} Result of the remove operation.
235
223
  */
236
- removeResource(params: RemoveParams): Promise<components["schemas"]["SuccessResponse"]>;
224
+ removeResource(params: RemoveParams): Promise<SuccessResponse>;
237
225
  /**
238
226
  * Creates a new directory in the device's internal storage.
239
227
  *
240
228
  * @param {CreateDirectoryParams} params - Directory creation parameters:
241
229
  * @param {CreateDirectoryParams['path']} params.path - Path to the new directory (e.g., "/ext/newdir").
242
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the create operation.
230
+ * @returns {Promise<SuccessResponse>} Result of the create operation.
243
231
  */
244
- createDirectory(params: CreateDirectoryParams): Promise<components["schemas"]["SuccessResponse"]>;
232
+ createDirectory(params: CreateDirectoryParams): Promise<SuccessResponse>;
245
233
  /**
246
234
  * Gets the current display brightness settings for the device.
247
235
  *
248
- * @returns {Promise<components["schemas"]["DisplayBrightnessInfo"]>} Current brightness information for front and back panels.
236
+ * @returns {Promise<DisplayBrightnessInfo>} Current brightness information for front and back panels.
249
237
  */
250
- getDisplayBrightness(): Promise<components["schemas"]["DisplayBrightnessInfo"]>;
238
+ getDisplayBrightness(): Promise<DisplayBrightnessInfo>;
251
239
  /**
252
240
  * Sets the display brightness for the device.
253
241
  *
254
242
  * @param {BrightnessParams} params - Brightness parameters:
255
243
  * @param {BrightnessParams['front']} [params.front] - Brightness for the front panel (0-100 or "auto").
256
244
  * @param {BrightnessParams['back']} [params.back] - Brightness for the back panel (0-100 or "auto").
257
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the brightness update operation.
245
+ * @returns {Promise<SuccessResponse>} Result of the brightness update operation.
258
246
  * @throws {Error} If brightness value is outside the range 0-100 or not "auto".
259
247
  */
260
- setDisplayBrightness(params: BrightnessParams): Promise<components["schemas"]["SuccessResponse"]>;
248
+ setDisplayBrightness(params: BrightnessParams): Promise<SuccessResponse>;
261
249
  /**
262
250
  * Gets the current audio volume value.
263
251
  *
264
- * @returns {Promise<components["schemas"]["AudioVolumeInfo"]>} Current audio volume (0-100).
252
+ * @returns {Promise<AudioVolumeInfo>} Current audio volume (0-100).
265
253
  */
266
- getAudioVolume(): Promise<components["schemas"]["AudioVolumeInfo"]>;
254
+ getAudioVolume(): Promise<AudioVolumeInfo>;
267
255
  /**
268
256
  * Sets the audio volume value.
269
257
  *
270
258
  * @param {AudioVolumeParams} params - Audio volume parameters:
271
259
  * @param {AudioVolumeParams['volume']} params.volume - Audio volume (number from 0 to 100).
272
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the volume update operation.
260
+ * @returns {Promise<SuccessResponse>} Result of the volume update operation.
273
261
  * @throws {Error} If volume is outside the range 0-100 or request fails.
274
262
  */
275
- setAudioVolume(params: AudioVolumeParams): Promise<components["schemas"]["SuccessResponse"]>;
263
+ setAudioVolume(params: AudioVolumeParams): Promise<SuccessResponse>;
276
264
  /**
277
265
  * Gets the current HTTP API access configuration.
278
266
  *
279
- * @returns {Promise<components["schemas"]["HttpAccessInfo"]>} Current HTTP access info.
267
+ * @returns {Promise<HttpAccessInfo>} Current HTTP access info.
280
268
  */
281
- getHttpAccess(): Promise<components["schemas"]["HttpAccessInfo"]>;
269
+ getHttpAccess(): Promise<HttpAccessInfo>;
282
270
  /**
283
271
  * Sets the HTTP API access configuration.
284
272
  *
285
- * @param {HttpAccess} params - Access parameters:
286
- * @param {HttpAccess['mode']} params.mode - Access mode ("disabled", "enabled", "key").
287
- * @param {HttpAccess['key']} params.key - Access key (4-10 digits).
288
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the set operation.
273
+ * @param {HttpAccessParams} params - Access parameters:
274
+ * @param {HttpAccessParams['mode']} params.mode - Access mode ("disabled", "enabled", "key").
275
+ * @param {HttpAccessParams['key']} params.key - Access key (4-10 digits).
276
+ * @returns {Promise<SuccessResponse>} Result of the set operation.
289
277
  */
290
- setHttpAccess(params: HttpAccess): Promise<components["schemas"]["SuccessResponse"]>;
278
+ setHttpAccess(params: HttpAccessParams): Promise<SuccessResponse>;
291
279
  /**
292
280
  * Sets API key for all subsequent requests.
293
281
  * @param {string} key - API key to use in "X-API-Token" header.
@@ -295,14 +283,14 @@ export declare class BusyBar {
295
283
  setApiKey(key: string): void;
296
284
  /**
297
285
  * Enables BLE module.
298
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the enable operation.
286
+ * @returns {Promise<SuccessResponse>} Result of the enable operation.
299
287
  */
300
- enableBle(): Promise<components["schemas"]["SuccessResponse"]>;
288
+ enableBle(): Promise<SuccessResponse>;
301
289
  /**
302
290
  * Disables BLE module.
303
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the disable operation.
291
+ * @returns {Promise<SuccessResponse>} Result of the disable operation.
304
292
  */
305
- disableBle(): Promise<components["schemas"]["SuccessResponse"]>;
293
+ disableBle(): Promise<SuccessResponse>;
306
294
  /**
307
295
  * Sends a button press.
308
296
  *
@@ -312,9 +300,13 @@ export declare class BusyBar {
312
300
  * {
313
301
  * keyName: "ok"
314
302
  * }
315
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of pressing the button.
303
+ * @returns {Promise<SuccessResponse>} Result of pressing the button.
316
304
  */
317
- pressButton(params: InputKey): Promise<components["schemas"]["SuccessResponse"]>;
305
+ pressButton(params: InputKey): Promise<SuccessResponse>;
306
+ }
307
+
308
+ declare interface BusyBarConfig {
309
+ host: string;
318
310
  }
319
311
 
320
312
  declare type BusyFile = Buffer | Blob | File | ArrayBuffer;
@@ -675,6 +667,8 @@ export declare enum DeviceScreen {
675
667
  BACK = 1
676
668
  }
677
669
 
670
+ export declare type DisplayBrightnessInfo = components["schemas"]["DisplayBrightnessInfo"];
671
+
678
672
  export declare interface DownloadFileParams {
679
673
  path: operations["readStorageFile"]["parameters"]["query"]["path"];
680
674
  asArrayBuffer?: boolean;
@@ -685,15 +679,20 @@ declare interface DrawParams {
685
679
  elements: CustomElement[];
686
680
  }
687
681
 
682
+ declare type Error_2 = components["schemas"]["Error"];
683
+ export { Error_2 as Error }
684
+
688
685
  declare type ErrorListener = (payload: ErrorPayload) => void;
689
686
 
690
687
  declare interface ErrorPayload {
691
688
  code: number;
692
689
  message: string;
693
- raw: Error | CloseEvent | Event;
690
+ raw: Error_2 | CloseEvent | Event;
694
691
  }
695
692
 
696
- declare interface HttpAccess {
693
+ export declare type HttpAccessInfo = components["schemas"]["HttpAccessInfo"];
694
+
695
+ declare interface HttpAccessParams {
697
696
  mode: operations["setHttpAccess"]["parameters"]["query"]["mode"];
698
697
  key: operations["setHttpAccess"]["parameters"]["query"]["key"];
699
698
  }
@@ -727,8 +726,6 @@ declare interface InputKey {
727
726
  keyName: KeyName;
728
727
  }
729
728
 
730
- declare type IPv4 = string;
731
-
732
729
  export declare type KeyName = operations["setInputKey"]["parameters"]["query"]["key"];
733
730
 
734
731
  export declare type KeyValue = 1 | 0;
@@ -745,8 +742,6 @@ declare interface LocalConfig_2 extends BaseConfig_2 {
745
742
 
746
743
  declare type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
747
744
 
748
- export declare type Network = components["schemas"]["Network"];
749
-
750
745
  declare interface operations {
751
746
  getVersion: {
752
747
  parameters: {
@@ -2521,10 +2516,26 @@ declare interface SiteConfig_2 extends BaseConfig_2 {
2521
2516
 
2522
2517
  declare type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S;
2523
2518
 
2519
+ export declare type Status = components["schemas"]["Status"];
2520
+
2521
+ export declare type StatusPower = components["schemas"]["StatusPower"];
2522
+
2523
+ export declare type StatusSystem = components["schemas"]["StatusSystem"];
2524
+
2524
2525
  declare type StopListener = () => void;
2525
2526
 
2527
+ export declare type StorageDirElement = components["schemas"]["StorageDirElement"];
2528
+
2529
+ export declare type StorageFileElement = components["schemas"]["StorageFileElement"];
2530
+
2531
+ export declare type StorageList = components["schemas"]["StorageList"];
2532
+
2526
2533
  export declare type StorageListElement = components["schemas"]["StorageListElement"];
2527
2534
 
2535
+ export declare type StorageReadResponse = ArrayBuffer | Blob;
2536
+
2537
+ export declare type SuccessResponse = components["schemas"]["SuccessResponse"];
2538
+
2528
2539
  declare interface UpdateParams {
2529
2540
  name?: string;
2530
2541
  file: BusyFile;
@@ -2541,4 +2552,20 @@ declare interface UploadParams {
2541
2552
  file: BusyFile;
2542
2553
  }
2543
2554
 
2555
+ export declare type VersionInfo = components["schemas"]["VersionInfo"];
2556
+
2557
+ export declare type WifiConnectRequestConfig = components["schemas"]["ConnectRequestConfig"];
2558
+
2559
+ export declare type WifiIpMethod = components["schemas"]["WifiIpMethod"];
2560
+
2561
+ export declare type WifiIpType = components["schemas"]["WifiIpType"];
2562
+
2563
+ export declare type WifiNetwork = components["schemas"]["Network"];
2564
+
2565
+ export declare type WifiNetworkResponse = components["schemas"]["NetworkResponse"];
2566
+
2567
+ export declare type WifiSecurityMethod = components["schemas"]["WifiSecurityMethod"];
2568
+
2569
+ export declare type WifiStatusResponse = components["schemas"]["StatusResponse"];
2570
+
2544
2571
  export { }
package/dist/index.js CHANGED
@@ -2,38 +2,25 @@ var k = Object.defineProperty;
2
2
  var P = (e, t, i) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
3
  var o = (e, t, i) => P(e, typeof t != "symbol" ? t + "" : t, i);
4
4
  import T from "openapi-fetch";
5
- function b(e) {
6
- const t = e.split(".");
7
- if (t.length !== 4)
8
- return !1;
9
- for (const i of t) {
10
- if (i.length === 0 || i.length > 1 && i[0] === "0" || !/^\d+$/.test(i))
11
- return !1;
12
- const n = Number(i);
13
- if (n < 0 || n > 255)
14
- return !1;
15
- }
16
- return !0;
17
- }
18
- const I = (e, t) => {
5
+ const b = (e, t) => {
19
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))
20
7
  return e;
21
8
  let i;
22
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);
23
10
  };
24
- let p, w, l = null;
11
+ let p, w, h = null;
25
12
  async function E() {
26
13
  if (!w) {
27
14
  if (!p)
28
15
  throw new Error("getApiVersionFn is not set");
29
- l || (l = (async () => {
16
+ h || (h = (async () => {
30
17
  const e = await p();
31
18
  if (!e.api_semver)
32
19
  throw new Error("Empty API version");
33
20
  w = e.api_semver;
34
21
  })().finally(() => {
35
- l = null;
36
- })), await l;
22
+ h = null;
23
+ })), await h;
37
24
  }
38
25
  }
39
26
  async function d(e) {
@@ -48,10 +35,10 @@ async function d(e) {
48
35
  );
49
36
  }
50
37
  let y;
51
- function v(e) {
38
+ function I(e) {
52
39
  y = e;
53
40
  }
54
- const B = {
41
+ const v = {
55
42
  async onRequest({ request: e, schemaPath: t }) {
56
43
  if (t !== "/version") {
57
44
  if (await E(), w)
@@ -75,13 +62,13 @@ const B = {
75
62
  }
76
63
  };
77
64
  let r = null;
78
- function L(e, t) {
65
+ function B(e, t) {
79
66
  p = t, r = T({
80
67
  baseUrl: e,
81
- bodySerializer: I
82
- }), r.use(B);
68
+ bodySerializer: b
69
+ }), r.use(v);
83
70
  }
84
- async function z(e) {
71
+ async function L(e) {
85
72
  const { appId: t, fileName: i, file: n } = e;
86
73
  if (!r)
87
74
  throw new Error("API client is not initialized");
@@ -101,7 +88,7 @@ async function z(e) {
101
88
  throw a;
102
89
  return s;
103
90
  }
104
- async function D(e) {
91
+ async function z(e) {
105
92
  const { appId: t } = e;
106
93
  if (!r)
107
94
  throw new Error("API client is not initialized");
@@ -116,15 +103,15 @@ async function D(e) {
116
103
  throw n;
117
104
  return i;
118
105
  }
119
- const O = { timeout: 5, x: 0, y: 0, display: "front" };
120
- function K(e) {
121
- return { ...O, ...e };
106
+ const D = { timeout: 5, x: 0, y: 0, display: "front" };
107
+ function O(e) {
108
+ return { ...D, ...e };
122
109
  }
123
- async function U(e) {
110
+ async function K(e) {
124
111
  const { appId: t, elements: i } = e;
125
112
  if (!r)
126
113
  throw new Error("API client is not initialized");
127
- const n = i.map(K), { data: s, error: a } = await r.POST("/display/draw", {
114
+ const n = i.map(O), { data: s, error: a } = await r.POST("/display/draw", {
128
115
  body: {
129
116
  app_id: t,
130
117
  elements: n
@@ -134,7 +121,7 @@ async function U(e) {
134
121
  throw a;
135
122
  return s;
136
123
  }
137
- async function C() {
124
+ async function U() {
138
125
  if (!r)
139
126
  throw new Error("API client is not initialized");
140
127
  const { data: e, error: t } = await r.DELETE("/display/draw");
@@ -142,7 +129,7 @@ async function C() {
142
129
  throw t;
143
130
  return e;
144
131
  }
145
- async function W(e) {
132
+ async function C(e) {
146
133
  const { appId: t, path: i } = e;
147
134
  if (!r)
148
135
  throw new Error("API client is not initialized");
@@ -158,7 +145,7 @@ async function W(e) {
158
145
  throw s;
159
146
  return n;
160
147
  }
161
- async function $() {
148
+ async function W() {
162
149
  if (!r)
163
150
  throw new Error("API client is not initialized");
164
151
  const { data: e, error: t } = await r.DELETE("/audio/play");
@@ -166,7 +153,7 @@ async function $() {
166
153
  throw t;
167
154
  return e;
168
155
  }
169
- async function F() {
156
+ async function $() {
170
157
  if (!r)
171
158
  throw new Error("API client is not initialized");
172
159
  const { data: e, error: t } = await r.POST("/wifi/enable");
@@ -174,7 +161,7 @@ async function F() {
174
161
  throw t;
175
162
  return e;
176
163
  }
177
- async function R() {
164
+ async function F() {
178
165
  if (!r)
179
166
  throw new Error("API client is not initialized");
180
167
  const { data: e, error: t } = await r.POST("/wifi/disable");
@@ -182,7 +169,7 @@ async function R() {
182
169
  throw t;
183
170
  return e;
184
171
  }
185
- async function V() {
172
+ async function R() {
186
173
  if (!r)
187
174
  throw new Error("API client is not initialized");
188
175
  const { data: e, error: t } = await r.GET("/wifi/status");
@@ -190,7 +177,7 @@ async function V() {
190
177
  throw t;
191
178
  return e;
192
179
  }
193
- async function x(e) {
180
+ async function V(e) {
194
181
  if (!r)
195
182
  throw new Error("API client is not initialized");
196
183
  const { data: t, error: i } = await r.POST("/wifi/connect", {
@@ -211,7 +198,7 @@ async function x(e) {
211
198
  throw i;
212
199
  return t;
213
200
  }
214
- async function _() {
201
+ async function x() {
215
202
  if (!r)
216
203
  throw new Error("API client is not initialized");
217
204
  const { data: e, error: t } = await r.POST("/wifi/disconnect");
@@ -219,7 +206,7 @@ async function _() {
219
206
  throw t;
220
207
  return e;
221
208
  }
222
- async function N() {
209
+ async function _() {
223
210
  if (!r)
224
211
  throw new Error("API client is not initialized");
225
212
  const { data: e, error: t } = await r.GET("/wifi/networks");
@@ -253,7 +240,7 @@ async function G(e) {
253
240
  throw s;
254
241
  return n;
255
242
  }
256
- async function j(e) {
243
+ async function N(e) {
257
244
  if (!r)
258
245
  throw new Error("API client is not initialized");
259
246
  const { path: t, asArrayBuffer: i } = e, { data: n, error: s } = await r.GET("/storage/read", {
@@ -268,7 +255,7 @@ async function j(e) {
268
255
  throw s;
269
256
  return n;
270
257
  }
271
- async function H(e) {
258
+ async function j(e) {
272
259
  if (!r)
273
260
  throw new Error("API client is not initialized");
274
261
  const { path: t } = e, { data: i, error: n } = await r.GET("/storage/list", {
@@ -282,7 +269,7 @@ async function H(e) {
282
269
  throw n;
283
270
  return i;
284
271
  }
285
- async function J(e) {
272
+ async function H(e) {
286
273
  if (!r)
287
274
  throw new Error("API client is not initialized");
288
275
  const { path: t } = e, { data: i, error: n } = await r.DELETE("/storage/remove", {
@@ -296,7 +283,7 @@ async function J(e) {
296
283
  throw n;
297
284
  return i;
298
285
  }
299
- async function X(e) {
286
+ async function J(e) {
300
287
  if (!r)
301
288
  throw new Error("API client is not initialized");
302
289
  const { path: t } = e, { data: i, error: n } = await r.POST("/storage/mkdir", {
@@ -310,7 +297,7 @@ async function X(e) {
310
297
  throw n;
311
298
  return i;
312
299
  }
313
- async function Q() {
300
+ async function X() {
314
301
  if (!r)
315
302
  throw new Error("API client is not initialized");
316
303
  const { data: e, error: t } = await r.GET("/version");
@@ -318,7 +305,7 @@ async function Q() {
318
305
  throw t;
319
306
  return e;
320
307
  }
321
- async function M(e) {
308
+ async function Q(e) {
322
309
  if (!r)
323
310
  throw new Error("API client is not initialized");
324
311
  const { name: t, file: i } = e, { data: n, error: s } = await r.POST("/update", {
@@ -336,7 +323,7 @@ async function M(e) {
336
323
  throw s;
337
324
  return n;
338
325
  }
339
- async function Y() {
326
+ async function M() {
340
327
  if (!r)
341
328
  throw new Error("API client is not initialized");
342
329
  const { data: e, error: t } = await r.GET("/status");
@@ -344,7 +331,7 @@ async function Y() {
344
331
  throw t;
345
332
  return e;
346
333
  }
347
- async function Z() {
334
+ async function Y() {
348
335
  if (!r)
349
336
  throw new Error("API client is not initialized");
350
337
  const { data: e, error: t } = await r.GET("/status/system");
@@ -352,7 +339,7 @@ async function Z() {
352
339
  throw t;
353
340
  return e;
354
341
  }
355
- async function tt() {
342
+ async function Z() {
356
343
  if (!r)
357
344
  throw new Error("API client is not initialized");
358
345
  const { data: e, error: t } = await r.GET("/status/power");
@@ -360,7 +347,7 @@ async function tt() {
360
347
  throw t;
361
348
  return e;
362
349
  }
363
- async function et() {
350
+ async function tt() {
364
351
  if (!r)
365
352
  throw new Error("API client is not initialized");
366
353
  const { data: e, error: t } = await r.GET("/display/brightness");
@@ -368,7 +355,7 @@ async function et() {
368
355
  throw t;
369
356
  return e;
370
357
  }
371
- async function it(e) {
358
+ async function et(e) {
372
359
  if (!r)
373
360
  throw new Error("API client is not initialized");
374
361
  const { front: t, back: i } = e, n = (u) => {
@@ -391,7 +378,7 @@ async function it(e) {
391
378
  throw f;
392
379
  return c;
393
380
  }
394
- async function rt() {
381
+ async function it() {
395
382
  if (!r)
396
383
  throw new Error("API client is not initialized");
397
384
  const { data: e, error: t } = await r.GET("/audio/volume");
@@ -399,7 +386,7 @@ async function rt() {
399
386
  throw t;
400
387
  return e;
401
388
  }
402
- async function nt(e) {
389
+ async function rt(e) {
403
390
  if (!r)
404
391
  throw new Error("API client is not initialized");
405
392
  const { volume: t } = e;
@@ -416,7 +403,7 @@ async function nt(e) {
416
403
  throw n;
417
404
  return i;
418
405
  }
419
- async function st() {
406
+ async function nt() {
420
407
  if (!r)
421
408
  throw new Error("API client is not initialized");
422
409
  const { data: e, error: t } = await r.GET("/access");
@@ -424,7 +411,7 @@ async function st() {
424
411
  throw t;
425
412
  return e;
426
413
  }
427
- async function ot(e) {
414
+ async function st(e) {
428
415
  if (!r)
429
416
  throw new Error("API client is not initialized");
430
417
  const { mode: t, key: i } = e;
@@ -442,7 +429,7 @@ async function ot(e) {
442
429
  throw s;
443
430
  return n;
444
431
  }
445
- async function at() {
432
+ async function ot() {
446
433
  if (!r)
447
434
  throw new Error("API client is not initialized");
448
435
  const { data: e, error: t } = await r.POST("/ble/enable");
@@ -450,7 +437,7 @@ async function at() {
450
437
  throw t;
451
438
  return e;
452
439
  }
453
- async function ct() {
440
+ async function at() {
454
441
  if (!r)
455
442
  throw new Error("API client is not initialized");
456
443
  const { data: e, error: t } = await r.POST("/ble/disable");
@@ -458,7 +445,7 @@ async function ct() {
458
445
  throw t;
459
446
  return e;
460
447
  }
461
- async function ft(e) {
448
+ async function ct(e) {
462
449
  if (!r)
463
450
  throw new Error("API client is not initialized");
464
451
  const { keyName: t } = e, { data: i, error: n } = await r.POST("/input", {
@@ -472,34 +459,34 @@ async function ft(e) {
472
459
  throw n;
473
460
  return i;
474
461
  }
475
- class dt {
462
+ class lt {
476
463
  /**
477
464
  * Creates an instance of BUSY Bar.
478
- * Initializes the API client with the provided IPv4 address.
465
+ * Initializes the API client with the provided host address.
479
466
  *
480
- * @param {IPv4} [ip="10.0.4.20"] - The IPv4 address of the device.
481
- * @throws {Error} If the provided IP is not a valid IPv4 address.
467
+ * @param {BusyBarConfig} config - The host address of the device (IP or mDNS).
482
468
  */
483
- constructor(t = "10.0.4.20") {
469
+ constructor(t) {
484
470
  /**
485
- * Device IPv4 address.
486
- * @type {IPv4}
471
+ * Device host address (IP or mDNS).
472
+ * @type {BusyBarConfig['host']}
487
473
  * @readonly
488
474
  */
489
- o(this, "ip");
490
- // @ts-ignore
475
+ o(this, "host");
476
+ /**
477
+ * Current API semantic version.
478
+ * @type {ApiSemver}
479
+ */
491
480
  o(this, "apiSemver");
492
- if (!b(t))
493
- throw new Error(`Incorrect IPv4: ${t}`);
494
- this.ip = t, this.apiSemver = "", L(`http://${this.ip}/api/`, this.getApiVersion.bind(this));
481
+ this.host = t.host, this.apiSemver = "", B(`http://${this.host}/api/`, this.getApiVersion.bind(this));
495
482
  }
496
483
  /**
497
484
  * Retrieves the API semantic version.
498
485
  *
499
- * @returns A promise that resolves to an object containing the `api_semver` string.
486
+ * @returns {Promise<VersionInfo>} A promise that resolves to an object containing the `api_semver` string.
500
487
  */
501
488
  async getApiVersion() {
502
- const t = await Q();
489
+ const t = await X();
503
490
  return this.apiSemver = t.api_semver, t;
504
491
  }
505
492
  /**
@@ -508,34 +495,34 @@ class dt {
508
495
  * @param {UpdateParams} params - Parameters for the firmware update.
509
496
  * @param {UpdateParams['name']} params.name - Name for the update package.
510
497
  * @param {UpdateParams['file']} params.file - File data to upload.
511
- * @returns Result of the update operation.
498
+ * @returns {Promise<SuccessResponse>} Result of the update operation.
512
499
  */
513
500
  async updateFirmware(t) {
514
- return await M(t);
501
+ return await Q(t);
515
502
  }
516
503
  /**
517
504
  * Gets the current status of the device, including system and power information.
518
505
  *
519
- * @returns Current status of the device.
506
+ * @returns {Promise<Status>} Current status of the device.
520
507
  */
521
508
  async deviceStatus() {
522
- return await Y();
509
+ return await M();
523
510
  }
524
511
  /**
525
512
  * Gets the current system status.
526
513
  *
527
- * @returns Current system status.
514
+ * @returns {Promise<StatusSystem>} Current system status.
528
515
  */
529
516
  async systemStatus() {
530
- return await Z();
517
+ return await Y();
531
518
  }
532
519
  /**
533
520
  * Gets the current power status.
534
521
  *
535
- * @returns Current power status.
522
+ * @returns {Promise<StatusPower>} Current power status.
536
523
  */
537
524
  async powerStatus() {
538
- return await tt();
525
+ return await Z();
539
526
  }
540
527
  /**
541
528
  * Uploads an asset to the device.
@@ -544,20 +531,20 @@ class dt {
544
531
  * @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
545
532
  * @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
546
533
  * @param {UploadParams['file']} params.file - File data to upload.
547
- * @returns {Promise<{ result: string }>} Result of the upload operation.
534
+ * @returns {Promise<SuccessResponse>} Result of the upload operation.
548
535
  */
549
536
  async uploadAsset(t) {
550
- return await z(t);
537
+ return await L(t);
551
538
  }
552
539
  /**
553
540
  * Deletes all assets for a specific application from the device.
554
541
  *
555
542
  * @param {DeleteParams} params - Parameters for the delete.
556
543
  * @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
557
- * @returns {Promise<{ result: string }>} Result of the delete operation.
544
+ * @returns {Promise<SuccessResponse>} Result of the delete operation.
558
545
  */
559
546
  async deleteAssets(t) {
560
- return await D(t);
547
+ return await z(t);
561
548
  }
562
549
  /**
563
550
  * Draws elements on the device display.
@@ -565,18 +552,18 @@ class dt {
565
552
  * @param {DrawParams} params - Parameters for the draw operation.
566
553
  * @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
567
554
  * @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
568
- * @returns {Promise<{ result: string }>} Result of the draw operation.
555
+ * @returns {Promise<SuccessResponse>} Result of the draw operation.
569
556
  */
570
557
  async drawDisplay(t) {
571
- return await U(t);
558
+ return await K(t);
572
559
  }
573
560
  /**
574
561
  * Clears the device display and stops the Canvas application if running.
575
562
  *
576
- * @returns {Promise<{ result: string }>} Result of the clear operation.
563
+ * @returns {Promise<SuccessResponse>} Result of the clear operation.
577
564
  */
578
565
  async clearDisplay() {
579
- return await C();
566
+ return await U();
580
567
  }
581
568
  /**
582
569
  * Plays an audio file from the assets directory.
@@ -584,42 +571,42 @@ class dt {
584
571
  * @param {AudioParams} params - Parameters for the audio playback.
585
572
  * @param {AudioParams['appId']} params.appId - Application ID for organizing assets.
586
573
  * @param {AudioParams['path']} params.path - Path to the audio file within the app's assets directory.
587
- * @returns {Promise<{ result: string }>} Result of the play operation.
574
+ * @returns {Promise<SuccessResponse>} Result of the play operation.
588
575
  */
589
576
  async playSound(t) {
590
- return await W(t);
577
+ return await C(t);
591
578
  }
592
579
  /**
593
580
  * Stops any currently playing audio on the device.
594
581
  *
595
- * @returns {Promise<{ result: string }>} Result of the stop operation.
582
+ * @returns {Promise<SuccessResponse>} Result of the stop operation.
596
583
  */
597
584
  async stopSound() {
598
- return await $();
585
+ return await W();
599
586
  }
600
587
  /**
601
588
  * Enables the device's Wi-Fi module.
602
589
  *
603
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the enable operation.
590
+ * @returns {Promise<SuccessResponse>} Result of the enable operation.
604
591
  */
605
592
  async enableWifi() {
606
- return await F();
593
+ return await $();
607
594
  }
608
595
  /**
609
596
  * Disables the device's Wi-Fi module.
610
597
  *
611
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disable operation.
598
+ * @returns {Promise<SuccessResponse>} Result of the disable operation.
612
599
  */
613
600
  async disableWifi() {
614
- return await R();
601
+ return await F();
615
602
  }
616
603
  /**
617
604
  * Gets the current status of the Wi-Fi module.
618
605
  *
619
- * @returns {Promise<components['schemas']['StatusResponse']>} Current Wi-Fi status.
606
+ * @returns {Promise<WifiStatusResponse>} Current Wi-Fi status.
620
607
  */
621
608
  async statusWifi() {
622
- return await V();
609
+ return await R();
623
610
  }
624
611
  /**
625
612
  * Connects the device to a Wi-Fi network with the specified parameters.
@@ -634,26 +621,26 @@ class dt {
634
621
  * @param {ConnectParams['ipConfig']['address']} [params.ipConfig.address] - Static IP address (if using "static" method).
635
622
  * @param {ConnectParams['ipConfig']['mask']} [params.ipConfig.mask] - Subnet mask (if using "static" method).
636
623
  * @param {ConnectParams['ipConfig']['gateway']} [params.ipConfig.gateway] - Gateway address (if using "static" method).
637
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the connect operation.
624
+ * @returns {Promise<SuccessResponse>} Result of the connect operation.
638
625
  */
639
626
  async connectWifi(t) {
640
- return await x(t);
627
+ return await V(t);
641
628
  }
642
629
  /**
643
630
  * Disconnects the device from the current Wi-Fi network.
644
631
  *
645
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disconnect operation.
632
+ * @returns {Promise<SuccessResponse>} Result of the disconnect operation.
646
633
  */
647
634
  async disconnectWifi() {
648
- return await _();
635
+ return await x();
649
636
  }
650
637
  /**
651
638
  * Scans for available Wi-Fi networks near your device.
652
639
  *
653
- * @returns {Promise<components['schemas']['NetworkResponse']>} List of discovered networks.
640
+ * @returns {Promise<WifiNetworkResponse>} List of discovered networks.
654
641
  */
655
642
  async networksWifi() {
656
- return await N();
643
+ return await _();
657
644
  }
658
645
  /**
659
646
  * Removes the saved Wi-Fi configuration (forgets the network).
@@ -669,7 +656,7 @@ class dt {
669
656
  * @param {UploadFileParams} params - Upload parameters:
670
657
  * @param {UploadFileParams['path']} params.path - Path where the file will be saved (e.g., "/ext/test.png").
671
658
  * @param {UploadFileParams['file']} params.file - File data to upload.
672
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the upload operation.
659
+ * @returns {Promise<SuccessResponse>} Result of the upload operation.
673
660
  */
674
661
  async uploadFile(t) {
675
662
  return await G(t);
@@ -680,48 +667,48 @@ class dt {
680
667
  * @param {DownloadFileParams} params - Download parameters:
681
668
  * @param {DownloadFileParams['path']} params.path - Path to the file to download (e.g., "/ext/test.png").
682
669
  * @param {DownloadFileParams['asArrayBuffer']} [params.asArrayBuffer] - If true, returns data as ArrayBuffer; otherwise, as Blob.
683
- * @returns {Promise<ArrayBuffer | Blob>} The file data.
670
+ * @returns {Promise<StorageReadResponse>} The file data.
684
671
  */
685
672
  async downloadFile(t) {
686
- return await j(t);
673
+ return await N(t);
687
674
  }
688
675
  /**
689
676
  * Reads the contents of a directory (files and subdirectories) at the specified path.
690
677
  *
691
678
  * @param {ReadDirectoryParams} params - List parameters:
692
679
  * @param {ReadDirectoryParams['path']} params.path - Path to the directory to list (e.g., "/ext").
693
- * @returns {Promise<components["schemas"]["StorageList"]>} List of files and directories.
680
+ * @returns {Promise<StorageList>} List of files and directories.
694
681
  */
695
682
  async readDirectory(t) {
696
- return await H(t);
683
+ return await j(t);
697
684
  }
698
685
  /**
699
686
  * Removes a file or a directory from the device's internal storage.
700
687
  *
701
688
  * @param {RemoveParams} params - Remove parameters:
702
689
  * @param {RemoveParams['path']} params.path - Path of the file to remove (e.g., "/ext/test.png").
703
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the remove operation.
690
+ * @returns {Promise<SuccessResponse>} Result of the remove operation.
704
691
  */
705
692
  async removeResource(t) {
706
- return await J(t);
693
+ return await H(t);
707
694
  }
708
695
  /**
709
696
  * Creates a new directory in the device's internal storage.
710
697
  *
711
698
  * @param {CreateDirectoryParams} params - Directory creation parameters:
712
699
  * @param {CreateDirectoryParams['path']} params.path - Path to the new directory (e.g., "/ext/newdir").
713
- * @returns {Promise<components['schemas']['SuccessResponse']>} Result of the create operation.
700
+ * @returns {Promise<SuccessResponse>} Result of the create operation.
714
701
  */
715
702
  async createDirectory(t) {
716
- return await X(t);
703
+ return await J(t);
717
704
  }
718
705
  /**
719
706
  * Gets the current display brightness settings for the device.
720
707
  *
721
- * @returns {Promise<components["schemas"]["DisplayBrightnessInfo"]>} Current brightness information for front and back panels.
708
+ * @returns {Promise<DisplayBrightnessInfo>} Current brightness information for front and back panels.
722
709
  */
723
710
  async getDisplayBrightness() {
724
- return await et();
711
+ return await tt();
725
712
  }
726
713
  /**
727
714
  * Sets the display brightness for the device.
@@ -729,49 +716,49 @@ class dt {
729
716
  * @param {BrightnessParams} params - Brightness parameters:
730
717
  * @param {BrightnessParams['front']} [params.front] - Brightness for the front panel (0-100 or "auto").
731
718
  * @param {BrightnessParams['back']} [params.back] - Brightness for the back panel (0-100 or "auto").
732
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the brightness update operation.
719
+ * @returns {Promise<SuccessResponse>} Result of the brightness update operation.
733
720
  * @throws {Error} If brightness value is outside the range 0-100 or not "auto".
734
721
  */
735
722
  async setDisplayBrightness(t) {
736
- return await it(t);
723
+ return await et(t);
737
724
  }
738
725
  /**
739
726
  * Gets the current audio volume value.
740
727
  *
741
- * @returns {Promise<components["schemas"]["AudioVolumeInfo"]>} Current audio volume (0-100).
728
+ * @returns {Promise<AudioVolumeInfo>} Current audio volume (0-100).
742
729
  */
743
730
  async getAudioVolume() {
744
- return await rt();
731
+ return await it();
745
732
  }
746
733
  /**
747
734
  * Sets the audio volume value.
748
735
  *
749
736
  * @param {AudioVolumeParams} params - Audio volume parameters:
750
737
  * @param {AudioVolumeParams['volume']} params.volume - Audio volume (number from 0 to 100).
751
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the volume update operation.
738
+ * @returns {Promise<SuccessResponse>} Result of the volume update operation.
752
739
  * @throws {Error} If volume is outside the range 0-100 or request fails.
753
740
  */
754
741
  async setAudioVolume(t) {
755
- return await nt(t);
742
+ return await rt(t);
756
743
  }
757
744
  /**
758
745
  * Gets the current HTTP API access configuration.
759
746
  *
760
- * @returns {Promise<components["schemas"]["HttpAccessInfo"]>} Current HTTP access info.
747
+ * @returns {Promise<HttpAccessInfo>} Current HTTP access info.
761
748
  */
762
749
  async getHttpAccess() {
763
- return await st();
750
+ return await nt();
764
751
  }
765
752
  /**
766
753
  * Sets the HTTP API access configuration.
767
754
  *
768
- * @param {HttpAccess} params - Access parameters:
769
- * @param {HttpAccess['mode']} params.mode - Access mode ("disabled", "enabled", "key").
770
- * @param {HttpAccess['key']} params.key - Access key (4-10 digits).
771
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the set operation.
755
+ * @param {HttpAccessParams} params - Access parameters:
756
+ * @param {HttpAccessParams['mode']} params.mode - Access mode ("disabled", "enabled", "key").
757
+ * @param {HttpAccessParams['key']} params.key - Access key (4-10 digits).
758
+ * @returns {Promise<SuccessResponse>} Result of the set operation.
772
759
  */
773
760
  async setHttpAccess(t) {
774
- const i = await ot(t);
761
+ const i = await st(t);
775
762
  return t.mode === "key" && t.key && this.setApiKey(t.key), i;
776
763
  }
777
764
  /**
@@ -779,21 +766,21 @@ class dt {
779
766
  * @param {string} key - API key to use in "X-API-Token" header.
780
767
  */
781
768
  setApiKey(t) {
782
- v(t);
769
+ I(t);
783
770
  }
784
771
  /**
785
772
  * Enables BLE module.
786
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the enable operation.
773
+ * @returns {Promise<SuccessResponse>} Result of the enable operation.
787
774
  */
788
775
  async enableBle() {
789
- return await at();
776
+ return await ot();
790
777
  }
791
778
  /**
792
779
  * Disables BLE module.
793
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the disable operation.
780
+ * @returns {Promise<SuccessResponse>} Result of the disable operation.
794
781
  */
795
782
  async disableBle() {
796
- return await ct();
783
+ return await at();
797
784
  }
798
785
  /**
799
786
  * Sends a button press.
@@ -804,10 +791,10 @@ class dt {
804
791
  * {
805
792
  * keyName: "ok"
806
793
  * }
807
- * @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of pressing the button.
794
+ * @returns {Promise<SuccessResponse>} Result of pressing the button.
808
795
  */
809
796
  async pressButton(t) {
810
- return await ft(t);
797
+ return await ct(t);
811
798
  }
812
799
  }
813
800
  var m = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(m || {});
@@ -820,7 +807,7 @@ function A(e, t) {
820
807
  throw new Error(`Unexpected undefined at index ${t}`);
821
808
  return i;
822
809
  }
823
- function ut(e, t) {
810
+ function ft(e, t) {
824
811
  let i = 0;
825
812
  const n = e.length, s = [];
826
813
  for (; i < n; ) {
@@ -833,14 +820,14 @@ function ut(e, t) {
833
820
  } else {
834
821
  const c = a, f = e.slice(i, i + t);
835
822
  for (let u = 0; u < c; u++)
836
- for (let h = 0; h < t; h++)
837
- s.push(f[h]);
823
+ for (let l = 0; l < t; l++)
824
+ s.push(f[l]);
838
825
  i += t;
839
826
  }
840
827
  }
841
828
  return new Uint8Array(s);
842
829
  }
843
- function wt(e) {
830
+ function ut(e) {
844
831
  const t = new Uint8Array(e.length * 2);
845
832
  let i = 0, n = 0;
846
833
  for (; i < e.length; ) {
@@ -849,7 +836,7 @@ function wt(e) {
849
836
  }
850
837
  return t;
851
838
  }
852
- class pt {
839
+ class dt {
853
840
  constructor(t) {
854
841
  o(this, "connected", !1);
855
842
  // @ts-ignore
@@ -908,8 +895,8 @@ class pt {
908
895
  let s;
909
896
  const a = this.config.deviceScreen === m.FRONT ? 3 : 2;
910
897
  try {
911
- const c = ut(n, a);
912
- this.config.deviceScreen === m.BACK ? s = wt(c) : s = c, this.emitData(s);
898
+ const c = ft(n, a);
899
+ this.config.deviceScreen === m.BACK ? s = ut(c) : s = c, this.emitData(s);
913
900
  } catch {
914
901
  this.emitData(n);
915
902
  }
@@ -944,7 +931,7 @@ class pt {
944
931
  });
945
932
  }
946
933
  }
947
- class yt {
934
+ class pt {
948
935
  constructor(t) {
949
936
  o(this, "connected", !1);
950
937
  // @ts-ignore
@@ -1030,8 +1017,8 @@ class yt {
1030
1017
  }
1031
1018
  }
1032
1019
  export {
1033
- dt as BusyBar,
1020
+ lt as BusyBar,
1034
1021
  m as DeviceScreen,
1035
- yt as Input,
1036
- pt as ScreenStream
1022
+ pt as Input,
1023
+ dt as ScreenStream
1037
1024
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
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.2.1",
5
+ "version": "0.3.0",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },