@telemetryos/root-sdk 1.9.0 → 1.11.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/CHANGELOG.md +15 -0
- package/dist/client.d.ts +7 -1
- package/dist/devices.d.ts +16 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +338 -228
- package/dist/media.d.ts +29 -2
- package/dist/mqtt.d.ts +43 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @telemetryos/root-sdk
|
|
2
2
|
|
|
3
|
+
## 1.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added media select component, improved tos init tos publish and tos auth commands, add new store hook
|
|
8
|
+
|
|
9
|
+
## 1.10.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Added MQTT, publish command, and other improvements
|
|
14
|
+
- Added MQTT support to the SDK
|
|
15
|
+
- Added a command `tos publish` that sends the project to be built on the platform (requires user token, so wont work right away)
|
|
16
|
+
- Added mock data for the currency service
|
|
17
|
+
|
|
3
18
|
## 1.9.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Devices } from './devices.js';
|
|
|
9
9
|
import { Weather } from './weather.js';
|
|
10
10
|
import { Currency } from './currency.js';
|
|
11
11
|
import { Environment } from './environment.js';
|
|
12
|
+
import { Mqtt } from './mqtt.js';
|
|
12
13
|
import { BridgeMessage } from './bridge.js';
|
|
13
14
|
/**
|
|
14
15
|
* The maximum time in milliseconds to wait for a response to a request call.
|
|
@@ -232,6 +233,7 @@ export declare class Client {
|
|
|
232
233
|
* @returns An Environment instance bound to this client
|
|
233
234
|
*/
|
|
234
235
|
get environment(): Environment;
|
|
236
|
+
get mqtt(): Mqtt;
|
|
235
237
|
get applicationName(): string;
|
|
236
238
|
get applicationSpecifier(): string;
|
|
237
239
|
get applicationInstance(): string;
|
|
@@ -293,10 +295,14 @@ export declare class Client {
|
|
|
293
295
|
* @template D The expected type of the response data
|
|
294
296
|
* @param name The name of the message type (endpoint) to request
|
|
295
297
|
* @param data The data payload to include with the request
|
|
298
|
+
* @param options Optional configuration for this request
|
|
299
|
+
* @param options.timeout Override the default timeout in milliseconds. Set to 0 to disable timeout.
|
|
296
300
|
* @returns A promise that resolves with the response data when received
|
|
297
301
|
* @throws {Error} If the request times out
|
|
298
302
|
*/
|
|
299
|
-
request<D>(name: string, data: any
|
|
303
|
+
request<D>(name: string, data: any, options?: {
|
|
304
|
+
timeout?: number;
|
|
305
|
+
}): Promise<D>;
|
|
300
306
|
/**
|
|
301
307
|
* Sets up a persistent subscription to messages from the TelemetryOS platform.
|
|
302
308
|
*
|
package/dist/devices.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type DeviceInformation = {
|
|
|
5
5
|
deviceManufacturer: string;
|
|
6
6
|
devicePlatform: string;
|
|
7
7
|
};
|
|
8
|
+
export type DeviceCapability = 'configurableDisplays' | 'configurableAudio' | 'applicationContainers' | 'applicationManagement' | 'resourceCaching' | 'bluetooth' | 'wiFi' | 'ethernet' | 'usbProvisioning' | 'videoStreaming' | 'screenCaptureStreaming' | 'mqtt';
|
|
8
9
|
export declare class Devices {
|
|
9
10
|
_client: Client;
|
|
10
11
|
constructor(client: Client);
|
|
@@ -22,5 +23,20 @@ export declare class Devices {
|
|
|
22
23
|
* console.log(`Device: ${info.deviceManufacturer} ${info.deviceModel}`);
|
|
23
24
|
*/
|
|
24
25
|
getInformation(): Promise<DeviceInformation>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the capabilities of the current device.
|
|
28
|
+
*
|
|
29
|
+
* Capabilities indicate what hardware and software features are available on
|
|
30
|
+
* the device running the application. This can be used to conditionally enable
|
|
31
|
+
* features based on what the device supports (e.g., MQTT, Bluetooth, WiFi).
|
|
32
|
+
*
|
|
33
|
+
* @returns A promise that resolves to an array of device capability strings
|
|
34
|
+
* @example
|
|
35
|
+
* const capabilities = await devices.getCapabilities();
|
|
36
|
+
* if (capabilities.includes('mqtt')) {
|
|
37
|
+
* // Enable MQTT features
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
getCapabilities(): Promise<DeviceCapability[]>;
|
|
25
41
|
}
|
|
26
42
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),D="1.9.0",U={version:D};class C{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class P{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class M{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class T{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,h)=>{n[h]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,h])=>{n[u]=h}):n=t.headers);const i=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!i.success)throw new TypeError(i.errorMessage,{cause:i.errorCause?Error(i.errorCause):void 0});const l=new Headers(i.headers),c={status:i.status,statusText:i.statusText,headers:l};let d=null;if(i.body!==null&&i.body!==void 0)if(i.bodyType==="binary"){const u=atob(i.body),h=new Uint8Array(u.length);for(let f=0;f<u.length;f++)h[f]=u.charCodeAt(f);d=h}else i.bodyType==="text"?d=i.body:i.bodyType==="json"&&(d=JSON.stringify(i.body));return new Response(d,c)}}class F{constructor(e){this._client=e}get application(){return new w("application","",this._client)}get instance(){return new w("instance",this._client.applicationInstance,this._client)}get device(){return new w("device",this._client.applicationInstance,this._client)}shared(e){return new w("shared",e,this._client)}}class w{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class k{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,o;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((o=n.error)===null||o===void 0?void 0:o.message)||"Failed to fetch currency rates");return n.rates}}function I(a){return{...a,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;o[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const _=1e3*30,H=typeof window>"u"&&typeof self<"u",b=H?self:window;function y(a){H?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new C(this)}get users(){return new k(this)}get store(){return new F(this)}get applications(){return new P(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new M(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new T(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),n=o.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const i=o.hostname.split(".");this._applicationSpecifier=(s=i[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=i=>{if(i.source===b||!i.data||typeof i.data!="object"||!("type"in i.data)||i.data.type!=="client"&&i.data.type!=="bridge")return;let l;if(i.data.type==="client"){const c=this._messageInterceptors.get(i.data.name);if(!c){y(i.data);return}l={...c(i.data.data),type:"bridge"}}if(!l){const c=L.safeParse(i.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const h of d)h(l.data);if(u){for(const h of u)h(l.data);this._onceHandlers.delete(l.name)}}if(!H)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t){const s=q(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});y(o);let n=!1,i;const l=new Promise((d,u)=>{const h=new Error(`${e} message request with response name of ${s} timed out after ${_}`);setTimeout(()=>{n=!0,this.off(s,i),u(h)},_)}),c=new Promise(d=>{i=u=>{n||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q(),l=q();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(i),this._subscriptionNamesByHandler.set(n,i),this.on(i,n);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:i});y(d);let u=!1,h;const f=new Promise((S,g)=>{const m=new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(l,h),g(m)},_)}),E=new Promise(S=>{h=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,E])}async unsubscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:i,unsubscribeName:c});y(d);let u=!1,h;const f=new Promise((g,m)=>{const j=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(i,h),m(j)},_)}),E=new Promise(g=>{h=m=>{u||g(m)},this.once(i,g)});if(!(await Promise.race([f,E])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let n=0;n<o.length;n+=1)t&&o[n]!==t||(o.splice(n,1),n-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function q(){return Math.random().toString(36).slice(2,9)}const v=U.version;let r=null;function W(){return r}function O(a){r=new x(a),r.bind()}function G(){r==null||r.unbind(),r=null}function J(...a){return p(r),r.on(...a)}function K(...a){return p(r),r.once(...a)}function z(...a){return p(r),r.off(...a)}function Q(...a){return p(r),r.send(...a)}function X(...a){return p(r),r.request(...a)}function Y(...a){return p(r),r.subscribe(...a)}function Z(...a){return p(r),r.unsubscribe(...a)}function ee(){return p(r),r.store}function te(){return p(r),r.applications}function se(){return p(r),r.media}function ne(){return p(r),r.accounts}function ie(){return p(r),r.users}function re(){return p(r),r.devices}function oe(){return p(r),r.proxy}function ae(){return p(r),r.rootSettingsNavigation}function ce(){return p(r),r.weather}function le(){return p(r),r.currency}function ue(){return p(r),r.environment}function p(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=C;exports.Applications=P;exports.Client=x;exports.Currency=R;exports.Devices=M;exports.Environment=T;exports.Media=A;exports.Proxy=B;exports.Store=F;exports.StoreSlice=w;exports.Users=k;exports.Weather=$;exports.accounts=ne;exports.applications=te;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=re;exports.environment=ue;exports.globalClient=W;exports.media=se;exports.off=z;exports.on=J;exports.once=K;exports.proxy=oe;exports.request=X;exports.rootSettingsNavigation=ae;exports.send=Q;exports.store=ee;exports.subscribe=Y;exports.telemetrySdkVersion=v;exports.unsubscribe=Z;exports.users=ie;exports.weather=ce;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),Q="1.11.0",U={version:Q};class T{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e},{timeout:0})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class H{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}async getCapabilities(){const e=await this._client.request("devices.getCapabilities",{});if(!e.success)throw new Error("Failed to get device capabilities");return e.capabilities}}class P{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class F{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}async openPicker(e){return(await this._client.request("media.openPicker",{accept:e==null?void 0:e.accept,currentValue:e==null?void 0:e.currentValue})).selection}}class k{constructor(e){this._client=e}async fetch(e,t){var s;let r;typeof e=="string"?r=e:e instanceof URL?r=e.toString():(r=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((l,d)=>{n[d]=l}):Array.isArray(t.headers)?t.headers.forEach(([l,d])=>{n[l]=d}):n=t.headers);const o=await this._client.request("proxy.fetch",{url:r,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!o.success)throw new TypeError(o.errorMessage,{cause:o.errorCause?Error(o.errorCause):void 0});const u=new Headers(o.headers),a={status:o.status,statusText:o.statusText,headers:u};let p=null;if(o.body!==null&&o.body!==void 0)if(o.bodyType==="binary"){const l=atob(o.body),d=new Uint8Array(l.length);for(let f=0;f<l.length;f++)d[f]=l.charCodeAt(f);p=d}else o.bodyType==="text"?p=o.body:o.bodyType==="json"&&(p=JSON.stringify(o.body));return new Response(p,a)}}class A{constructor(e){this._client=e}get application(){return new v("application","",this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.applicationInstance,this._client)}shared(e){return new v("shared",e,this._client)}}class v{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class B{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,r;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((r=n.error)===null||r===void 0?void 0:r.message)||"Failed to fetch currency rates");return n.rates}}class x{constructor(e){this._client=e}async discover(){const e=await this._client.request("mqtt.discover",{});if(!e.success)throw new Error("Failed to discover MQTT brokers");return e.brokers}async connect(e,t){const s=await this._client.request("mqtt.connect",{brokerUrl:e,...t});if(!s.success)throw new Error("Failed to connect to MQTT broker");return s.clientId}async disconnect(e){if(!(await this._client.request("mqtt.disconnect",{clientId:e})).success)throw new Error("Failed to disconnect from MQTT broker")}async publish(e,t,s,r){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...r})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,r){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...r},s)).success}async unsubscribe(e,t,s){return(await this._client.unsubscribe("mqtt.unsubscribe",{clientId:e,topic:t},s)).success}async getConnectionStatus(e){const t=await this._client.request("mqtt.getConnectionStatus",{clientId:e});if(!t.success)throw new Error("Failed to get MQTT connection status");return t.status}async subscribeConnectionStatus(e,t){return(await this._client.subscribe("mqtt.subscribeConnectionStatus",{clientId:e},t)).success}async unsubscribeConnectionStatus(e,t){return(await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus",{clientId:e},t)).success}}function E(c){return{...c,type:"client"}}const V=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class L{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),r=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;r[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",r)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},r=this._store._client._applicationSpecifier;return s[r]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const b=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function y(c){C?self.postMessage(c):S.parent.postMessage(c,"*")}class j{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new T(this)}get users(){return new B(this)}get store(){return new A(this)}get applications(){return new M(this)}get media(){return new F(this)}get proxy(){return new k(this)}get devices(){return new H(this)}get rootSettingsNavigation(){return new L(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new P(this)}get mqtt(){return new x(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const r=new URL(S.location.href),n=r.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const o=r.hostname.split(".");this._applicationSpecifier=(s=o[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=o=>{if(o.source===S||!o.data||typeof o.data!="object"||!("type"in o.data)||o.data.type!=="client"&&o.data.type!=="bridge")return;let u;if(o.data.type==="client"){const a=this._messageInterceptors.get(o.data.name);if(!a){y(o.data);return}u={...a(o.data.data),type:"bridge"}}if(!u){const a=V.safeParse(o.data);if(!a.success)return;u=a.data;const p=this._onHandlers.get(u.name),l=this._onceHandlers.get(u.name);if(p)for(const d of p)d(u.data);if(l){for(const d of l)d(u.data);this._onceHandlers.delete(u.name)}}if(!C)for(let a=0;a<window.frames.length;a+=1)window.frames[a].postMessage(u,"*")},S.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&S.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t,s){var r;const n=I(),o=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});y(o);const u=(r=s==null?void 0:s.timeout)!==null&&r!==void 0?r:b;let a=!1,p;const l=new Promise(f=>{p=g=>{a||f(g)},this.once(n,p)});if(u===0)return l;const d=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${u}`);setTimeout(()=>{a=!0,this.off(n,p),g(w)},u)});return Promise.race([d,l])}async subscribe(e,t,s){let r,n;typeof t=="function"?n=t:(r=t,n=s);const o=I(),u=I();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(o),this._subscriptionNamesByHandler.set(n,o),this.on(o,n);const p=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:r,responseName:u,subscriptionName:o});y(p);let l=!1,d;const f=new Promise((w,m)=>{const _=new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);setTimeout(()=>{l=!0,this.off(u,d),m(_)},b)}),g=new Promise(w=>{d=m=>{l||w(m)},this.on(u,w)});return Promise.race([f,g])}async unsubscribe(e,t,s){let r,n;typeof t=="function"?n=t:(r=t,n=s);const o=I();let u=[];if(n){const a=this._subscriptionNamesByHandler.get(n);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,n);const p=E({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:r,responseName:o,unsubscribeName:a});y(p);let l=!1,d;const f=new Promise((m,_)=>{const D=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);setTimeout(()=>{l=!0,this.off(o,d),_(D)},b)}),g=new Promise(m=>{d=_=>{l||m(_)},this.once(o,m)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const r=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var s;const r=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const s=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!s&&!r)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(r){for(let n=0;n<r.length;n+=1)t&&r[n]!==t||(r.splice(n,1),n-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=U.version;let i=null;function W(){return i}function O(c){i=new j(c),i.bind()}function G(){i==null||i.unbind(),i=null}function J(...c){return h(i),i.on(...c)}function K(...c){return h(i),i.once(...c)}function z(...c){return h(i),i.off(...c)}function X(...c){return h(i),i.send(...c)}function Y(...c){return h(i),i.request(...c)}function Z(...c){return h(i),i.subscribe(...c)}function ee(...c){return h(i),i.unsubscribe(...c)}function te(){return h(i),i.store}function se(){return h(i),i.applications}function ne(){return h(i),i.media}function re(){return h(i),i.accounts}function ie(){return h(i),i.users}function oe(){return h(i),i.devices}function ce(){return h(i),i.proxy}function ae(){return h(i),i.rootSettingsNavigation}function ue(){return h(i),i.weather}function le(){return h(i),i.currency}function he(){return h(i),i.environment}function de(){return h(i),i.mqtt}function h(c){if(!c)throw new Error("SDK is not configured")}exports.Accounts=T;exports.Applications=M;exports.Client=j;exports.Currency=R;exports.Devices=H;exports.Environment=P;exports.Media=F;exports.Mqtt=x;exports.Proxy=k;exports.Store=A;exports.StoreSlice=v;exports.Users=B;exports.Weather=$;exports.accounts=re;exports.applications=se;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=oe;exports.environment=he;exports.globalClient=W;exports.media=ne;exports.mqtt=de;exports.off=z;exports.on=J;exports.once=K;exports.proxy=ce;exports.request=Y;exports.rootSettingsNavigation=ae;exports.send=X;exports.store=te;exports.subscribe=Z;exports.telemetrySdkVersion=q;exports.unsubscribe=ee;exports.users=ie;exports.weather=ue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { Accounts } from './accounts.js';
|
|
2
2
|
export { Applications } from './applications.js';
|
|
3
|
-
export { Devices } from './devices.js';
|
|
3
|
+
export { Devices, type DeviceCapability } from './devices.js';
|
|
4
4
|
export { Environment, type ColorScheme } from './environment.js';
|
|
5
5
|
export { Media } from './media.js';
|
|
6
|
+
export type { MediaContent, MediaFolder, MediaSelection, MediaPickerOptions, } from './media.js';
|
|
6
7
|
export { Proxy } from './proxy.js';
|
|
7
8
|
export { Store, StoreSlice } from './store.js';
|
|
8
9
|
export { Users } from './users.js';
|
|
@@ -10,6 +11,8 @@ export { Weather } from './weather.js';
|
|
|
10
11
|
export type { CitiesSearchParams, DailyForecast, DailyForecastData, DailyForecastParams, HourlyForecast, HourlyForecastData, HourlyForecastParams, WeatherAlert, WeatherAlerts, WeatherAlertSeverity, WeatherAlertsParams, WeatherCity, WeatherConditions, WeatherConditionsParams, WeatherPartOfDay, } from './weather.js';
|
|
11
12
|
export { Currency } from './currency.js';
|
|
12
13
|
export type { CurrencySymbols, CurrencyRates, CurrencyRatesParams } from './currency.js';
|
|
14
|
+
export { Mqtt } from './mqtt.js';
|
|
15
|
+
export type { MqttBrokerInfo, MqttConnectOptions, MqttPublishOptions, MqttSubscribeOptions, MqttConnectionStatus, MqttMessage, } from './mqtt.js';
|
|
13
16
|
import { Client } from './client.js';
|
|
14
17
|
export { Client, type SubscriptionResult, type MessageHandler } from './client.js';
|
|
15
18
|
/**
|
|
@@ -303,3 +306,14 @@ export declare function currency(): import("./currency.js").Currency;
|
|
|
303
306
|
* });
|
|
304
307
|
*/
|
|
305
308
|
export declare function environment(): import("./environment.js").Environment;
|
|
309
|
+
/**
|
|
310
|
+
* Provides access to the MQTT API for connecting to MQTT brokers.
|
|
311
|
+
*
|
|
312
|
+
* This API allows applications to discover, connect to, publish/subscribe on,
|
|
313
|
+
* and disconnect from MQTT brokers. MQTT is only available on dedicated player
|
|
314
|
+
* devices.
|
|
315
|
+
*
|
|
316
|
+
* @returns The Mqtt API object
|
|
317
|
+
* @throws {Error} If called before configure() or after destroy()
|
|
318
|
+
*/
|
|
319
|
+
export declare function mqtt(): import("./mqtt.js").Mqtt;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
const
|
|
3
|
-
version:
|
|
1
|
+
import { o as C, a as H, s as M, l as P } from "./types-CCzf8sMT.js";
|
|
2
|
+
const F = "1.11.0", k = {
|
|
3
|
+
version: F
|
|
4
4
|
};
|
|
5
|
-
class
|
|
5
|
+
class A {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this._client = e;
|
|
8
8
|
}
|
|
@@ -21,7 +21,7 @@ class F {
|
|
|
21
21
|
return e.account;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class B {
|
|
25
25
|
constructor(e) {
|
|
26
26
|
this._client = e;
|
|
27
27
|
}
|
|
@@ -78,9 +78,7 @@ class $ {
|
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
async setDependencies(e) {
|
|
81
|
-
return await this._client.request("applications.setDependencies", {
|
|
82
|
-
applicationSpecifiers: e
|
|
83
|
-
});
|
|
81
|
+
return await this._client.request("applications.setDependencies", { applicationSpecifiers: e }, { timeout: 0 });
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* Registers a message interceptor for client messages from sub-applications.
|
|
@@ -118,7 +116,7 @@ class $ {
|
|
|
118
116
|
this._client._messageInterceptors.set(e, t);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
class
|
|
119
|
+
class $ {
|
|
122
120
|
constructor(e) {
|
|
123
121
|
this._client = e;
|
|
124
122
|
}
|
|
@@ -141,6 +139,26 @@ class k {
|
|
|
141
139
|
throw new Error("Failed to get device information");
|
|
142
140
|
return e.deviceInformation;
|
|
143
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves the capabilities of the current device.
|
|
144
|
+
*
|
|
145
|
+
* Capabilities indicate what hardware and software features are available on
|
|
146
|
+
* the device running the application. This can be used to conditionally enable
|
|
147
|
+
* features based on what the device supports (e.g., MQTT, Bluetooth, WiFi).
|
|
148
|
+
*
|
|
149
|
+
* @returns A promise that resolves to an array of device capability strings
|
|
150
|
+
* @example
|
|
151
|
+
* const capabilities = await devices.getCapabilities();
|
|
152
|
+
* if (capabilities.includes('mqtt')) {
|
|
153
|
+
* // Enable MQTT features
|
|
154
|
+
* }
|
|
155
|
+
*/
|
|
156
|
+
async getCapabilities() {
|
|
157
|
+
const e = await this._client.request("devices.getCapabilities", {});
|
|
158
|
+
if (!e.success)
|
|
159
|
+
throw new Error("Failed to get device capabilities");
|
|
160
|
+
return e.capabilities;
|
|
161
|
+
}
|
|
144
162
|
}
|
|
145
163
|
class R {
|
|
146
164
|
constructor(e) {
|
|
@@ -201,6 +219,19 @@ class x {
|
|
|
201
219
|
id: e
|
|
202
220
|
})).content;
|
|
203
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Opens a full-screen media picker dialog in the host window.
|
|
224
|
+
* This allows users to browse folders, view media, and select an item.
|
|
225
|
+
*
|
|
226
|
+
* @param options Optional picker options including content type filter and current value
|
|
227
|
+
* @returns A promise that resolves to the selected media, or null if cancelled
|
|
228
|
+
*/
|
|
229
|
+
async openPicker(e) {
|
|
230
|
+
return (await this._client.request("media.openPicker", {
|
|
231
|
+
accept: e == null ? void 0 : e.accept,
|
|
232
|
+
currentValue: e == null ? void 0 : e.currentValue
|
|
233
|
+
})).selection;
|
|
234
|
+
}
|
|
204
235
|
}
|
|
205
236
|
class j {
|
|
206
237
|
constructor(e) {
|
|
@@ -208,8 +239,8 @@ class j {
|
|
|
208
239
|
}
|
|
209
240
|
async fetch(e, t) {
|
|
210
241
|
var s;
|
|
211
|
-
let
|
|
212
|
-
typeof e == "string" ?
|
|
242
|
+
let r;
|
|
243
|
+
typeof e == "string" ? r = e : e instanceof URL ? r = e.toString() : (r = e.url, t || (t = {
|
|
213
244
|
method: e.method,
|
|
214
245
|
headers: e.headers,
|
|
215
246
|
body: e.body,
|
|
@@ -220,35 +251,35 @@ class j {
|
|
|
220
251
|
integrity: e.integrity
|
|
221
252
|
}));
|
|
222
253
|
let n = {};
|
|
223
|
-
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((
|
|
224
|
-
n[
|
|
225
|
-
}) : Array.isArray(t.headers) ? t.headers.forEach(([
|
|
226
|
-
n[
|
|
254
|
+
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((l, d) => {
|
|
255
|
+
n[d] = l;
|
|
256
|
+
}) : Array.isArray(t.headers) ? t.headers.forEach(([l, d]) => {
|
|
257
|
+
n[l] = d;
|
|
227
258
|
}) : n = t.headers);
|
|
228
|
-
const
|
|
229
|
-
url:
|
|
259
|
+
const o = await this._client.request("proxy.fetch", {
|
|
260
|
+
url: r,
|
|
230
261
|
method: (t == null ? void 0 : t.method) || "GET",
|
|
231
262
|
headers: n,
|
|
232
263
|
body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
|
|
233
264
|
});
|
|
234
|
-
if (!
|
|
235
|
-
throw new TypeError(
|
|
236
|
-
cause:
|
|
265
|
+
if (!o.success)
|
|
266
|
+
throw new TypeError(o.errorMessage, {
|
|
267
|
+
cause: o.errorCause ? Error(o.errorCause) : void 0
|
|
237
268
|
});
|
|
238
|
-
const
|
|
239
|
-
status:
|
|
240
|
-
statusText:
|
|
241
|
-
headers:
|
|
269
|
+
const u = new Headers(o.headers), a = {
|
|
270
|
+
status: o.status,
|
|
271
|
+
statusText: o.statusText,
|
|
272
|
+
headers: u
|
|
242
273
|
};
|
|
243
|
-
let
|
|
244
|
-
if (
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
for (let f = 0; f <
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
} else
|
|
251
|
-
return new Response(
|
|
274
|
+
let p = null;
|
|
275
|
+
if (o.body !== null && o.body !== void 0)
|
|
276
|
+
if (o.bodyType === "binary") {
|
|
277
|
+
const l = atob(o.body), d = new Uint8Array(l.length);
|
|
278
|
+
for (let f = 0; f < l.length; f++)
|
|
279
|
+
d[f] = l.charCodeAt(f);
|
|
280
|
+
p = d;
|
|
281
|
+
} else o.bodyType === "text" ? p = o.body : o.bodyType === "json" && (p = JSON.stringify(o.body));
|
|
282
|
+
return new Response(p, a);
|
|
252
283
|
}
|
|
253
284
|
}
|
|
254
285
|
class D {
|
|
@@ -265,7 +296,7 @@ class D {
|
|
|
265
296
|
* @returns A StoreSlice instance for the application scope
|
|
266
297
|
*/
|
|
267
298
|
get application() {
|
|
268
|
-
return new
|
|
299
|
+
return new S("application", "", this._client);
|
|
269
300
|
}
|
|
270
301
|
/**
|
|
271
302
|
* Provides access to the instance store scope.
|
|
@@ -279,7 +310,7 @@ class D {
|
|
|
279
310
|
* @returns A StoreSlice instance for the instance scope
|
|
280
311
|
*/
|
|
281
312
|
get instance() {
|
|
282
|
-
return new
|
|
313
|
+
return new S("instance", this._client.applicationInstance, this._client);
|
|
283
314
|
}
|
|
284
315
|
/**
|
|
285
316
|
* Provides access to the device store scope.
|
|
@@ -294,7 +325,7 @@ class D {
|
|
|
294
325
|
* @returns A StoreSlice instance for the device scope
|
|
295
326
|
*/
|
|
296
327
|
get device() {
|
|
297
|
-
return new
|
|
328
|
+
return new S("device", this._client.applicationInstance, this._client);
|
|
298
329
|
}
|
|
299
330
|
/**
|
|
300
331
|
* Provides access to the shared store scope with a specified namespace.
|
|
@@ -310,10 +341,10 @@ class D {
|
|
|
310
341
|
* @returns A StoreSlice instance for the specified shared namespace
|
|
311
342
|
*/
|
|
312
343
|
shared(e) {
|
|
313
|
-
return new
|
|
344
|
+
return new S("shared", e, this._client);
|
|
314
345
|
}
|
|
315
346
|
}
|
|
316
|
-
class
|
|
347
|
+
class S {
|
|
317
348
|
constructor(e, t, s) {
|
|
318
349
|
this._kind = e, this._namespace = t, this._client = s;
|
|
319
350
|
}
|
|
@@ -407,7 +438,7 @@ class v {
|
|
|
407
438
|
})).success;
|
|
408
439
|
}
|
|
409
440
|
}
|
|
410
|
-
class
|
|
441
|
+
class Q {
|
|
411
442
|
constructor(e) {
|
|
412
443
|
this._client = e;
|
|
413
444
|
}
|
|
@@ -430,7 +461,7 @@ class L {
|
|
|
430
461
|
return e.user;
|
|
431
462
|
}
|
|
432
463
|
}
|
|
433
|
-
class
|
|
464
|
+
class L {
|
|
434
465
|
constructor(e) {
|
|
435
466
|
this._client = e;
|
|
436
467
|
}
|
|
@@ -573,7 +604,7 @@ class U {
|
|
|
573
604
|
return t;
|
|
574
605
|
}
|
|
575
606
|
}
|
|
576
|
-
class
|
|
607
|
+
class U {
|
|
577
608
|
constructor(e) {
|
|
578
609
|
this._client = e;
|
|
579
610
|
}
|
|
@@ -613,20 +644,84 @@ class V {
|
|
|
613
644
|
* ```
|
|
614
645
|
*/
|
|
615
646
|
async getRates(e) {
|
|
616
|
-
var t, s,
|
|
647
|
+
var t, s, r;
|
|
617
648
|
const n = await this._client.request("currency.getRates", e);
|
|
618
649
|
if (!n.success || !n.rates)
|
|
619
|
-
throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((
|
|
650
|
+
throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((r = n.error) === null || r === void 0 ? void 0 : r.message) || "Failed to fetch currency rates");
|
|
620
651
|
return n.rates;
|
|
621
652
|
}
|
|
622
653
|
}
|
|
623
|
-
|
|
624
|
-
|
|
654
|
+
class V {
|
|
655
|
+
constructor(e) {
|
|
656
|
+
this._client = e;
|
|
657
|
+
}
|
|
658
|
+
async discover() {
|
|
659
|
+
const e = await this._client.request("mqtt.discover", {});
|
|
660
|
+
if (!e.success)
|
|
661
|
+
throw new Error("Failed to discover MQTT brokers");
|
|
662
|
+
return e.brokers;
|
|
663
|
+
}
|
|
664
|
+
async connect(e, t) {
|
|
665
|
+
const s = await this._client.request("mqtt.connect", {
|
|
666
|
+
brokerUrl: e,
|
|
667
|
+
...t
|
|
668
|
+
});
|
|
669
|
+
if (!s.success)
|
|
670
|
+
throw new Error("Failed to connect to MQTT broker");
|
|
671
|
+
return s.clientId;
|
|
672
|
+
}
|
|
673
|
+
async disconnect(e) {
|
|
674
|
+
if (!(await this._client.request("mqtt.disconnect", { clientId: e })).success)
|
|
675
|
+
throw new Error("Failed to disconnect from MQTT broker");
|
|
676
|
+
}
|
|
677
|
+
async publish(e, t, s, r) {
|
|
678
|
+
if (!(await this._client.request("mqtt.publish", {
|
|
679
|
+
clientId: e,
|
|
680
|
+
topic: t,
|
|
681
|
+
payload: s,
|
|
682
|
+
...r
|
|
683
|
+
})).success)
|
|
684
|
+
throw new Error("Failed to publish MQTT message");
|
|
685
|
+
}
|
|
686
|
+
async subscribe(e, t, s, r) {
|
|
687
|
+
return (await this._client.subscribe("mqtt.subscribe", {
|
|
688
|
+
clientId: e,
|
|
689
|
+
topic: t,
|
|
690
|
+
...r
|
|
691
|
+
}, s)).success;
|
|
692
|
+
}
|
|
693
|
+
async unsubscribe(e, t, s) {
|
|
694
|
+
return (await this._client.unsubscribe("mqtt.unsubscribe", {
|
|
695
|
+
clientId: e,
|
|
696
|
+
topic: t
|
|
697
|
+
}, s)).success;
|
|
698
|
+
}
|
|
699
|
+
async getConnectionStatus(e) {
|
|
700
|
+
const t = await this._client.request("mqtt.getConnectionStatus", {
|
|
701
|
+
clientId: e
|
|
702
|
+
});
|
|
703
|
+
if (!t.success)
|
|
704
|
+
throw new Error("Failed to get MQTT connection status");
|
|
705
|
+
return t.status;
|
|
706
|
+
}
|
|
707
|
+
async subscribeConnectionStatus(e, t) {
|
|
708
|
+
return (await this._client.subscribe("mqtt.subscribeConnectionStatus", {
|
|
709
|
+
clientId: e
|
|
710
|
+
}, t)).success;
|
|
711
|
+
}
|
|
712
|
+
async unsubscribeConnectionStatus(e, t) {
|
|
713
|
+
return (await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus", {
|
|
714
|
+
clientId: e
|
|
715
|
+
}, t)).success;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function q(c) {
|
|
719
|
+
return { ...c, type: "client" };
|
|
625
720
|
}
|
|
626
|
-
const W =
|
|
627
|
-
type:
|
|
721
|
+
const W = C({
|
|
722
|
+
type: P("bridge"),
|
|
628
723
|
name: M(),
|
|
629
|
-
data:
|
|
724
|
+
data: H()
|
|
630
725
|
});
|
|
631
726
|
class G {
|
|
632
727
|
/**
|
|
@@ -652,11 +747,11 @@ class G {
|
|
|
652
747
|
*/
|
|
653
748
|
async setRootSettingsNavigation(e) {
|
|
654
749
|
var t;
|
|
655
|
-
const s = this._store.shared("root-settings-navigation"),
|
|
656
|
-
|
|
750
|
+
const s = this._store.shared("root-settings-navigation"), r = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, n = this._store._client._applicationSpecifier;
|
|
751
|
+
r[n] = {
|
|
657
752
|
applicationSpecifier: n,
|
|
658
753
|
entries: e.entries
|
|
659
|
-
}, s.set("navigation",
|
|
754
|
+
}, s.set("navigation", r);
|
|
660
755
|
}
|
|
661
756
|
/**
|
|
662
757
|
* Retrieves the current navigation entries for this root application.
|
|
@@ -668,8 +763,8 @@ class G {
|
|
|
668
763
|
*/
|
|
669
764
|
async getRootSettingsNavigation() {
|
|
670
765
|
var e;
|
|
671
|
-
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {},
|
|
672
|
-
return s[
|
|
766
|
+
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, r = this._store._client._applicationSpecifier;
|
|
767
|
+
return s[r];
|
|
673
768
|
}
|
|
674
769
|
/**
|
|
675
770
|
* Retrieves the navigation entries for all root applications.
|
|
@@ -685,9 +780,9 @@ class G {
|
|
|
685
780
|
return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
|
|
686
781
|
}
|
|
687
782
|
}
|
|
688
|
-
const
|
|
689
|
-
function
|
|
690
|
-
|
|
783
|
+
const b = 1e3 * 30, I = typeof window > "u" && typeof self < "u", v = I ? self : window;
|
|
784
|
+
function y(c) {
|
|
785
|
+
I ? self.postMessage(c) : v.parent.postMessage(c, "*");
|
|
691
786
|
}
|
|
692
787
|
class J {
|
|
693
788
|
/**
|
|
@@ -715,7 +810,7 @@ class J {
|
|
|
715
810
|
* @returns An Accounts instance bound to this client
|
|
716
811
|
*/
|
|
717
812
|
get accounts() {
|
|
718
|
-
return new
|
|
813
|
+
return new A(this);
|
|
719
814
|
}
|
|
720
815
|
/**
|
|
721
816
|
* Provides access to the users API for retrieving TelemetryOS user information.
|
|
@@ -729,7 +824,7 @@ class J {
|
|
|
729
824
|
* @returns A Users instance bound to this client
|
|
730
825
|
*/
|
|
731
826
|
get users() {
|
|
732
|
-
return new
|
|
827
|
+
return new Q(this);
|
|
733
828
|
}
|
|
734
829
|
/**
|
|
735
830
|
* Provides access to the store API for data persistence with multiple storage scopes.
|
|
@@ -757,7 +852,7 @@ class J {
|
|
|
757
852
|
* @returns An Applications instance bound to this client
|
|
758
853
|
*/
|
|
759
854
|
get applications() {
|
|
760
|
-
return new
|
|
855
|
+
return new B(this);
|
|
761
856
|
}
|
|
762
857
|
/**
|
|
763
858
|
* Provides access to the media API for working with content hosted on the TelemetryOS platform.
|
|
@@ -801,7 +896,7 @@ class J {
|
|
|
801
896
|
* @returns A Devices instance bound to this client
|
|
802
897
|
*/
|
|
803
898
|
get devices() {
|
|
804
|
-
return new
|
|
899
|
+
return new $(this);
|
|
805
900
|
}
|
|
806
901
|
/**
|
|
807
902
|
* Provides access to the root settings navigation API for TelemetryOS administration UI integration.
|
|
@@ -833,7 +928,7 @@ class J {
|
|
|
833
928
|
* @returns A Weather instance bound to this client
|
|
834
929
|
*/
|
|
835
930
|
get weather() {
|
|
836
|
-
return new
|
|
931
|
+
return new L(this);
|
|
837
932
|
}
|
|
838
933
|
/**
|
|
839
934
|
* Provides access to the currency API for retrieving currency exchange rates.
|
|
@@ -847,7 +942,7 @@ class J {
|
|
|
847
942
|
* @returns A Currency instance bound to this client
|
|
848
943
|
*/
|
|
849
944
|
get currency() {
|
|
850
|
-
return new
|
|
945
|
+
return new U(this);
|
|
851
946
|
}
|
|
852
947
|
/**
|
|
853
948
|
* Provides access to the environment API for accessing environment settings.
|
|
@@ -863,6 +958,9 @@ class J {
|
|
|
863
958
|
get environment() {
|
|
864
959
|
return new R(this);
|
|
865
960
|
}
|
|
961
|
+
get mqtt() {
|
|
962
|
+
return new V(this);
|
|
963
|
+
}
|
|
866
964
|
get applicationName() {
|
|
867
965
|
return this._applicationName;
|
|
868
966
|
}
|
|
@@ -889,46 +987,46 @@ class J {
|
|
|
889
987
|
*/
|
|
890
988
|
bind() {
|
|
891
989
|
var e, t, s;
|
|
892
|
-
const
|
|
990
|
+
const r = new URL(v.location.href), n = r.searchParams;
|
|
893
991
|
if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
|
|
894
992
|
throw new Error("Missing applicationInstance query parameter");
|
|
895
993
|
if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
|
|
896
|
-
const
|
|
897
|
-
this._applicationSpecifier = (s =
|
|
994
|
+
const o = r.hostname.split(".");
|
|
995
|
+
this._applicationSpecifier = (s = o[0]) !== null && s !== void 0 ? s : "";
|
|
898
996
|
}
|
|
899
997
|
if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
|
|
900
998
|
throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
901
|
-
this._windowMessageHandler = (
|
|
902
|
-
if (
|
|
999
|
+
this._windowMessageHandler = (o) => {
|
|
1000
|
+
if (o.source === v || !o.data || typeof o.data != "object" || !("type" in o.data) || o.data.type !== "client" && o.data.type !== "bridge")
|
|
903
1001
|
return;
|
|
904
|
-
let
|
|
905
|
-
if (
|
|
906
|
-
const
|
|
907
|
-
if (!
|
|
908
|
-
|
|
1002
|
+
let u;
|
|
1003
|
+
if (o.data.type === "client") {
|
|
1004
|
+
const a = this._messageInterceptors.get(o.data.name);
|
|
1005
|
+
if (!a) {
|
|
1006
|
+
y(o.data);
|
|
909
1007
|
return;
|
|
910
1008
|
}
|
|
911
|
-
|
|
1009
|
+
u = { ...a(o.data.data), type: "bridge" };
|
|
912
1010
|
}
|
|
913
|
-
if (!
|
|
914
|
-
const
|
|
915
|
-
if (!
|
|
1011
|
+
if (!u) {
|
|
1012
|
+
const a = W.safeParse(o.data);
|
|
1013
|
+
if (!a.success)
|
|
916
1014
|
return;
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
if (
|
|
920
|
-
for (const
|
|
921
|
-
|
|
922
|
-
if (
|
|
923
|
-
for (const
|
|
924
|
-
|
|
925
|
-
this._onceHandlers.delete(
|
|
1015
|
+
u = a.data;
|
|
1016
|
+
const p = this._onHandlers.get(u.name), l = this._onceHandlers.get(u.name);
|
|
1017
|
+
if (p)
|
|
1018
|
+
for (const d of p)
|
|
1019
|
+
d(u.data);
|
|
1020
|
+
if (l) {
|
|
1021
|
+
for (const d of l)
|
|
1022
|
+
d(u.data);
|
|
1023
|
+
this._onceHandlers.delete(u.name);
|
|
926
1024
|
}
|
|
927
1025
|
}
|
|
928
|
-
if (!
|
|
929
|
-
for (let
|
|
930
|
-
window.frames[
|
|
931
|
-
},
|
|
1026
|
+
if (!I)
|
|
1027
|
+
for (let a = 0; a < window.frames.length; a += 1)
|
|
1028
|
+
window.frames[a].postMessage(u, "*");
|
|
1029
|
+
}, v.addEventListener("message", this._windowMessageHandler);
|
|
932
1030
|
}
|
|
933
1031
|
/**
|
|
934
1032
|
* Removes the message event listener and cleans up resources.
|
|
@@ -944,7 +1042,7 @@ class J {
|
|
|
944
1042
|
* of managing their own Client instances.
|
|
945
1043
|
*/
|
|
946
1044
|
unbind() {
|
|
947
|
-
this._windowMessageHandler &&
|
|
1045
|
+
this._windowMessageHandler && v.removeEventListener("message", this._windowMessageHandler);
|
|
948
1046
|
}
|
|
949
1047
|
/**
|
|
950
1048
|
* Sends a one-way message to the TelemetryOS platform.
|
|
@@ -960,15 +1058,15 @@ class J {
|
|
|
960
1058
|
* @param data The data payload to include with the message
|
|
961
1059
|
*/
|
|
962
1060
|
send(e, t) {
|
|
963
|
-
const s =
|
|
964
|
-
telemetrySdkVersion:
|
|
1061
|
+
const s = q({
|
|
1062
|
+
telemetrySdkVersion: E,
|
|
965
1063
|
applicationName: this._applicationName,
|
|
966
1064
|
applicationSpecifier: this._applicationSpecifier,
|
|
967
1065
|
applicationInstance: this._applicationInstance,
|
|
968
1066
|
name: e,
|
|
969
1067
|
data: t
|
|
970
1068
|
});
|
|
971
|
-
|
|
1069
|
+
y(s);
|
|
972
1070
|
}
|
|
973
1071
|
/**
|
|
974
1072
|
* Sends a message to the TelemetryOS platform and waits for a response.
|
|
@@ -984,100 +1082,107 @@ class J {
|
|
|
984
1082
|
* @template D The expected type of the response data
|
|
985
1083
|
* @param name The name of the message type (endpoint) to request
|
|
986
1084
|
* @param data The data payload to include with the request
|
|
1085
|
+
* @param options Optional configuration for this request
|
|
1086
|
+
* @param options.timeout Override the default timeout in milliseconds. Set to 0 to disable timeout.
|
|
987
1087
|
* @returns A promise that resolves with the response data when received
|
|
988
1088
|
* @throws {Error} If the request times out
|
|
989
1089
|
*/
|
|
990
|
-
request(e, t) {
|
|
991
|
-
|
|
992
|
-
|
|
1090
|
+
request(e, t, s) {
|
|
1091
|
+
var r;
|
|
1092
|
+
const n = N(), o = q({
|
|
1093
|
+
telemetrySdkVersion: E,
|
|
993
1094
|
applicationName: this._applicationName,
|
|
994
1095
|
applicationSpecifier: this._applicationSpecifier,
|
|
995
1096
|
applicationInstance: this._applicationInstance,
|
|
996
1097
|
name: e,
|
|
997
1098
|
data: t,
|
|
998
|
-
responseName:
|
|
1099
|
+
responseName: n
|
|
1100
|
+
});
|
|
1101
|
+
y(o);
|
|
1102
|
+
const u = (r = s == null ? void 0 : s.timeout) !== null && r !== void 0 ? r : b;
|
|
1103
|
+
let a = !1, p;
|
|
1104
|
+
const l = new Promise((f) => {
|
|
1105
|
+
p = (g) => {
|
|
1106
|
+
a || f(g);
|
|
1107
|
+
}, this.once(n, p);
|
|
999
1108
|
});
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
const
|
|
1003
|
-
const
|
|
1109
|
+
if (u === 0)
|
|
1110
|
+
return l;
|
|
1111
|
+
const d = new Promise((f, g) => {
|
|
1112
|
+
const m = new Error(`${e} message request with response name of ${n} timed out after ${u}`);
|
|
1004
1113
|
setTimeout(() => {
|
|
1005
|
-
|
|
1006
|
-
},
|
|
1007
|
-
}), c = new Promise((d) => {
|
|
1008
|
-
i = (u) => {
|
|
1009
|
-
n || d(u);
|
|
1010
|
-
}, this.once(s, d);
|
|
1114
|
+
a = !0, this.off(n, p), g(m);
|
|
1115
|
+
}, u);
|
|
1011
1116
|
});
|
|
1012
|
-
return Promise.race([
|
|
1117
|
+
return Promise.race([d, l]);
|
|
1013
1118
|
}
|
|
1014
1119
|
async subscribe(e, t, s) {
|
|
1015
|
-
let
|
|
1016
|
-
typeof t == "function" ? n = t : (
|
|
1017
|
-
const
|
|
1018
|
-
let
|
|
1019
|
-
|
|
1020
|
-
const
|
|
1021
|
-
telemetrySdkVersion:
|
|
1120
|
+
let r, n;
|
|
1121
|
+
typeof t == "function" ? n = t : (r = t, n = s);
|
|
1122
|
+
const o = N(), u = N();
|
|
1123
|
+
let a = this._subscriptionNamesBySubjectName.get(e);
|
|
1124
|
+
a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(o), this._subscriptionNamesByHandler.set(n, o), this.on(o, n);
|
|
1125
|
+
const p = q({
|
|
1126
|
+
telemetrySdkVersion: E,
|
|
1022
1127
|
applicationName: this._applicationName,
|
|
1023
1128
|
applicationSpecifier: this._applicationSpecifier,
|
|
1024
1129
|
applicationInstance: this._applicationInstance,
|
|
1025
1130
|
name: e,
|
|
1026
|
-
data:
|
|
1027
|
-
responseName:
|
|
1028
|
-
subscriptionName:
|
|
1131
|
+
data: r,
|
|
1132
|
+
responseName: u,
|
|
1133
|
+
subscriptionName: o
|
|
1029
1134
|
});
|
|
1030
|
-
|
|
1031
|
-
let
|
|
1032
|
-
const f = new Promise((
|
|
1033
|
-
const
|
|
1135
|
+
y(p);
|
|
1136
|
+
let l = !1, d;
|
|
1137
|
+
const f = new Promise((m, w) => {
|
|
1138
|
+
const _ = new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);
|
|
1034
1139
|
setTimeout(() => {
|
|
1035
|
-
|
|
1036
|
-
},
|
|
1037
|
-
}),
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}, this.on(
|
|
1140
|
+
l = !0, this.off(u, d), w(_);
|
|
1141
|
+
}, b);
|
|
1142
|
+
}), g = new Promise((m) => {
|
|
1143
|
+
d = (w) => {
|
|
1144
|
+
l || m(w);
|
|
1145
|
+
}, this.on(u, m);
|
|
1041
1146
|
});
|
|
1042
|
-
return Promise.race([f,
|
|
1147
|
+
return Promise.race([f, g]);
|
|
1043
1148
|
}
|
|
1044
1149
|
async unsubscribe(e, t, s) {
|
|
1045
|
-
let
|
|
1046
|
-
typeof t == "function" ? n = t : (
|
|
1047
|
-
const
|
|
1048
|
-
let
|
|
1150
|
+
let r, n;
|
|
1151
|
+
typeof t == "function" ? n = t : (r = t, n = s);
|
|
1152
|
+
const o = N();
|
|
1153
|
+
let u = [];
|
|
1049
1154
|
if (n) {
|
|
1050
|
-
const
|
|
1051
|
-
if (!
|
|
1155
|
+
const a = this._subscriptionNamesByHandler.get(n);
|
|
1156
|
+
if (!a)
|
|
1052
1157
|
return { success: !1 };
|
|
1053
|
-
|
|
1158
|
+
u = [a], this._subscriptionNamesByHandler.delete(n);
|
|
1054
1159
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
1055
1160
|
return { success: !1 };
|
|
1056
|
-
for await (const
|
|
1057
|
-
this.off(
|
|
1058
|
-
const
|
|
1059
|
-
telemetrySdkVersion:
|
|
1161
|
+
for await (const a of u) {
|
|
1162
|
+
this.off(a, n);
|
|
1163
|
+
const p = q({
|
|
1164
|
+
telemetrySdkVersion: E,
|
|
1060
1165
|
applicationInstance: this._applicationInstance,
|
|
1061
1166
|
applicationName: this._applicationName,
|
|
1062
1167
|
applicationSpecifier: this._applicationSpecifier,
|
|
1063
1168
|
name: e,
|
|
1064
|
-
data:
|
|
1065
|
-
responseName:
|
|
1066
|
-
unsubscribeName:
|
|
1169
|
+
data: r,
|
|
1170
|
+
responseName: o,
|
|
1171
|
+
unsubscribeName: a
|
|
1067
1172
|
});
|
|
1068
|
-
|
|
1069
|
-
let
|
|
1070
|
-
const f = new Promise((
|
|
1071
|
-
const
|
|
1173
|
+
y(p);
|
|
1174
|
+
let l = !1, d;
|
|
1175
|
+
const f = new Promise((w, _) => {
|
|
1176
|
+
const T = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);
|
|
1072
1177
|
setTimeout(() => {
|
|
1073
|
-
|
|
1074
|
-
},
|
|
1075
|
-
}),
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}, this.once(
|
|
1178
|
+
l = !0, this.off(o, d), _(T);
|
|
1179
|
+
}, b);
|
|
1180
|
+
}), g = new Promise((w) => {
|
|
1181
|
+
d = (_) => {
|
|
1182
|
+
l || w(_);
|
|
1183
|
+
}, this.once(o, w);
|
|
1079
1184
|
});
|
|
1080
|
-
if (!(await Promise.race([f,
|
|
1185
|
+
if (!(await Promise.race([f, g])).success)
|
|
1081
1186
|
return { success: !1 };
|
|
1082
1187
|
}
|
|
1083
1188
|
return { success: !0 };
|
|
@@ -1101,8 +1206,8 @@ class J {
|
|
|
1101
1206
|
*/
|
|
1102
1207
|
on(e, t) {
|
|
1103
1208
|
var s;
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1209
|
+
const r = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1210
|
+
r.length === 0 && this._onHandlers.set(e, r), r.push(t);
|
|
1106
1211
|
}
|
|
1107
1212
|
/**
|
|
1108
1213
|
* Registers a one-time handler for a specific message type.
|
|
@@ -1120,8 +1225,8 @@ class J {
|
|
|
1120
1225
|
*/
|
|
1121
1226
|
once(e, t) {
|
|
1122
1227
|
var s;
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1228
|
+
const r = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1229
|
+
r.length === 0 && this._onceHandlers.set(e, r), r.push(t);
|
|
1125
1230
|
}
|
|
1126
1231
|
/**
|
|
1127
1232
|
* Removes previously registered message handlers.
|
|
@@ -1139,17 +1244,17 @@ class J {
|
|
|
1139
1244
|
* all handlers for this message type will be removed.
|
|
1140
1245
|
*/
|
|
1141
1246
|
off(e, t) {
|
|
1142
|
-
const s = this._onHandlers.get(e),
|
|
1143
|
-
if (!(!s && !
|
|
1247
|
+
const s = this._onHandlers.get(e), r = this._onceHandlers.get(e);
|
|
1248
|
+
if (!(!s && !r)) {
|
|
1144
1249
|
if (s) {
|
|
1145
1250
|
for (let n = 0; n < s.length; n += 1)
|
|
1146
1251
|
t && s[n] !== t || (s.splice(n, 1), n -= 1);
|
|
1147
1252
|
s.length === 0 && this._onHandlers.delete(e);
|
|
1148
1253
|
}
|
|
1149
|
-
if (
|
|
1150
|
-
for (let n = 0; n <
|
|
1151
|
-
t &&
|
|
1152
|
-
|
|
1254
|
+
if (r) {
|
|
1255
|
+
for (let n = 0; n < r.length; n += 1)
|
|
1256
|
+
t && r[n] !== t || (r.splice(n, 1), n -= 1);
|
|
1257
|
+
r.length === 0 && this._onceHandlers.delete(e);
|
|
1153
1258
|
}
|
|
1154
1259
|
}
|
|
1155
1260
|
}
|
|
@@ -1157,108 +1262,113 @@ class J {
|
|
|
1157
1262
|
function N() {
|
|
1158
1263
|
return Math.random().toString(36).slice(2, 9);
|
|
1159
1264
|
}
|
|
1160
|
-
const
|
|
1161
|
-
let
|
|
1265
|
+
const E = k.version;
|
|
1266
|
+
let i = null;
|
|
1162
1267
|
function O() {
|
|
1163
|
-
return
|
|
1268
|
+
return i;
|
|
1164
1269
|
}
|
|
1165
|
-
function z(
|
|
1166
|
-
|
|
1270
|
+
function z(c) {
|
|
1271
|
+
i = new J(c), i.bind();
|
|
1167
1272
|
}
|
|
1168
|
-
function
|
|
1169
|
-
|
|
1273
|
+
function X() {
|
|
1274
|
+
i == null || i.unbind(), i = null;
|
|
1170
1275
|
}
|
|
1171
|
-
function
|
|
1172
|
-
return
|
|
1276
|
+
function Y(...c) {
|
|
1277
|
+
return h(i), i.on(...c);
|
|
1173
1278
|
}
|
|
1174
|
-
function
|
|
1175
|
-
return
|
|
1279
|
+
function Z(...c) {
|
|
1280
|
+
return h(i), i.once(...c);
|
|
1176
1281
|
}
|
|
1177
|
-
function
|
|
1178
|
-
return
|
|
1282
|
+
function ee(...c) {
|
|
1283
|
+
return h(i), i.off(...c);
|
|
1179
1284
|
}
|
|
1180
|
-
function
|
|
1181
|
-
return
|
|
1285
|
+
function te(...c) {
|
|
1286
|
+
return h(i), i.send(...c);
|
|
1182
1287
|
}
|
|
1183
|
-
function
|
|
1184
|
-
return
|
|
1288
|
+
function se(...c) {
|
|
1289
|
+
return h(i), i.request(...c);
|
|
1185
1290
|
}
|
|
1186
|
-
function
|
|
1187
|
-
return
|
|
1291
|
+
function ne(...c) {
|
|
1292
|
+
return h(i), i.subscribe(...c);
|
|
1188
1293
|
}
|
|
1189
|
-
function
|
|
1190
|
-
return
|
|
1294
|
+
function re(...c) {
|
|
1295
|
+
return h(i), i.unsubscribe(...c);
|
|
1191
1296
|
}
|
|
1192
1297
|
function ie() {
|
|
1193
|
-
return
|
|
1194
|
-
}
|
|
1195
|
-
function re() {
|
|
1196
|
-
return p(r), r.applications;
|
|
1298
|
+
return h(i), i.store;
|
|
1197
1299
|
}
|
|
1198
1300
|
function oe() {
|
|
1199
|
-
return
|
|
1200
|
-
}
|
|
1201
|
-
function ae() {
|
|
1202
|
-
return p(r), r.accounts;
|
|
1301
|
+
return h(i), i.applications;
|
|
1203
1302
|
}
|
|
1204
1303
|
function ce() {
|
|
1205
|
-
return
|
|
1304
|
+
return h(i), i.media;
|
|
1206
1305
|
}
|
|
1207
|
-
function
|
|
1208
|
-
return
|
|
1306
|
+
function ae() {
|
|
1307
|
+
return h(i), i.accounts;
|
|
1209
1308
|
}
|
|
1210
1309
|
function ue() {
|
|
1211
|
-
return
|
|
1310
|
+
return h(i), i.users;
|
|
1212
1311
|
}
|
|
1213
|
-
function
|
|
1214
|
-
return
|
|
1312
|
+
function le() {
|
|
1313
|
+
return h(i), i.devices;
|
|
1215
1314
|
}
|
|
1216
|
-
function
|
|
1217
|
-
return
|
|
1315
|
+
function he() {
|
|
1316
|
+
return h(i), i.proxy;
|
|
1218
1317
|
}
|
|
1219
1318
|
function de() {
|
|
1220
|
-
return
|
|
1319
|
+
return h(i), i.rootSettingsNavigation;
|
|
1320
|
+
}
|
|
1321
|
+
function pe() {
|
|
1322
|
+
return h(i), i.weather;
|
|
1221
1323
|
}
|
|
1222
1324
|
function fe() {
|
|
1223
|
-
return
|
|
1325
|
+
return h(i), i.currency;
|
|
1326
|
+
}
|
|
1327
|
+
function ge() {
|
|
1328
|
+
return h(i), i.environment;
|
|
1329
|
+
}
|
|
1330
|
+
function we() {
|
|
1331
|
+
return h(i), i.mqtt;
|
|
1224
1332
|
}
|
|
1225
|
-
function
|
|
1226
|
-
if (!
|
|
1333
|
+
function h(c) {
|
|
1334
|
+
if (!c)
|
|
1227
1335
|
throw new Error("SDK is not configured");
|
|
1228
1336
|
}
|
|
1229
1337
|
export {
|
|
1230
|
-
|
|
1231
|
-
|
|
1338
|
+
A as Accounts,
|
|
1339
|
+
B as Applications,
|
|
1232
1340
|
J as Client,
|
|
1233
|
-
|
|
1234
|
-
|
|
1341
|
+
U as Currency,
|
|
1342
|
+
$ as Devices,
|
|
1235
1343
|
R as Environment,
|
|
1236
1344
|
x as Media,
|
|
1345
|
+
V as Mqtt,
|
|
1237
1346
|
j as Proxy,
|
|
1238
1347
|
D as Store,
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1348
|
+
S as StoreSlice,
|
|
1349
|
+
Q as Users,
|
|
1350
|
+
L as Weather,
|
|
1242
1351
|
ae as accounts,
|
|
1243
|
-
|
|
1352
|
+
oe as applications,
|
|
1244
1353
|
z as configure,
|
|
1245
|
-
|
|
1246
|
-
|
|
1354
|
+
fe as currency,
|
|
1355
|
+
X as destroy,
|
|
1247
1356
|
le as devices,
|
|
1248
|
-
|
|
1357
|
+
ge as environment,
|
|
1249
1358
|
O as globalClient,
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
Y as
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1359
|
+
ce as media,
|
|
1360
|
+
we as mqtt,
|
|
1361
|
+
ee as off,
|
|
1362
|
+
Y as on,
|
|
1363
|
+
Z as once,
|
|
1364
|
+
he as proxy,
|
|
1365
|
+
se as request,
|
|
1366
|
+
de as rootSettingsNavigation,
|
|
1367
|
+
te as send,
|
|
1258
1368
|
ie as store,
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1369
|
+
ne as subscribe,
|
|
1370
|
+
E as telemetrySdkVersion,
|
|
1371
|
+
re as unsubscribe,
|
|
1372
|
+
ue as users,
|
|
1263
1373
|
pe as weather
|
|
1264
1374
|
};
|
package/dist/media.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from './client.js';
|
|
2
2
|
type MediaContentUser = {};
|
|
3
|
-
type MediaContent = {
|
|
3
|
+
export type MediaContent = {
|
|
4
4
|
id: string;
|
|
5
5
|
contentFolderId: string;
|
|
6
6
|
contentType: string;
|
|
@@ -17,7 +17,7 @@ type MediaContent = {
|
|
|
17
17
|
createdAt: Date;
|
|
18
18
|
updatedAt: Date;
|
|
19
19
|
};
|
|
20
|
-
type MediaFolder = {
|
|
20
|
+
export type MediaFolder = {
|
|
21
21
|
id: string;
|
|
22
22
|
parentId: string;
|
|
23
23
|
name: string;
|
|
@@ -26,6 +26,25 @@ type MediaFolder = {
|
|
|
26
26
|
updatedAt: Date;
|
|
27
27
|
createdAt: Date;
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Represents a selected media item with essential display properties.
|
|
31
|
+
*/
|
|
32
|
+
export type MediaSelection = {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
thumbnailUrl: string;
|
|
36
|
+
url: string;
|
|
37
|
+
contentType: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Options for the media picker dialog.
|
|
41
|
+
*/
|
|
42
|
+
export type MediaPickerOptions = {
|
|
43
|
+
/** Filter by content type patterns: ['image/*', 'video/*'] */
|
|
44
|
+
accept?: string[];
|
|
45
|
+
/** Pre-select the current value in the picker */
|
|
46
|
+
currentValue?: MediaSelection;
|
|
47
|
+
};
|
|
29
48
|
export declare class Media {
|
|
30
49
|
_client: Client;
|
|
31
50
|
constructor(client: Client);
|
|
@@ -56,5 +75,13 @@ export declare class Media {
|
|
|
56
75
|
* @returns A promise that resolves to the media content with the specified ID
|
|
57
76
|
*/
|
|
58
77
|
getById(id: string): Promise<MediaContent>;
|
|
78
|
+
/**
|
|
79
|
+
* Opens a full-screen media picker dialog in the host window.
|
|
80
|
+
* This allows users to browse folders, view media, and select an item.
|
|
81
|
+
*
|
|
82
|
+
* @param options Optional picker options including content type filter and current value
|
|
83
|
+
* @returns A promise that resolves to the selected media, or null if cancelled
|
|
84
|
+
*/
|
|
85
|
+
openPicker(options?: MediaPickerOptions): Promise<MediaSelection | null>;
|
|
59
86
|
}
|
|
60
87
|
export {};
|
package/dist/mqtt.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Client, type MessageHandler } from './client.js';
|
|
2
|
+
export type MqttBrokerInfo = {
|
|
3
|
+
name: string;
|
|
4
|
+
address: string;
|
|
5
|
+
port: number;
|
|
6
|
+
protocol: 'mqtt' | 'mqtts' | 'ws' | 'wss';
|
|
7
|
+
};
|
|
8
|
+
export type MqttConnectOptions = {
|
|
9
|
+
username?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
clientId?: string;
|
|
12
|
+
keepalive?: number;
|
|
13
|
+
clean?: boolean;
|
|
14
|
+
reconnectPeriod?: number;
|
|
15
|
+
connectTimeout?: number;
|
|
16
|
+
};
|
|
17
|
+
export type MqttPublishOptions = {
|
|
18
|
+
qos?: 0 | 1 | 2;
|
|
19
|
+
retain?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type MqttSubscribeOptions = {
|
|
22
|
+
qos?: 0 | 1 | 2;
|
|
23
|
+
};
|
|
24
|
+
export type MqttConnectionStatus = 'connected' | 'disconnected' | 'connecting' | 'reconnecting' | 'error';
|
|
25
|
+
export type MqttMessage = {
|
|
26
|
+
topic: string;
|
|
27
|
+
payload: string;
|
|
28
|
+
qos: 0 | 1 | 2;
|
|
29
|
+
retain: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare class Mqtt {
|
|
32
|
+
_client: Client;
|
|
33
|
+
constructor(client: Client);
|
|
34
|
+
discover(): Promise<MqttBrokerInfo[]>;
|
|
35
|
+
connect(brokerUrl: string, options?: MqttConnectOptions): Promise<string>;
|
|
36
|
+
disconnect(clientId: string): Promise<void>;
|
|
37
|
+
publish(clientId: string, topic: string, payload: string, options?: MqttPublishOptions): Promise<void>;
|
|
38
|
+
subscribe(clientId: string, topic: string, handler: MessageHandler<MqttMessage>, options?: MqttSubscribeOptions): Promise<boolean>;
|
|
39
|
+
unsubscribe(clientId: string, topic: string, handler?: MessageHandler<MqttMessage>): Promise<boolean>;
|
|
40
|
+
getConnectionStatus(clientId: string): Promise<MqttConnectionStatus>;
|
|
41
|
+
subscribeConnectionStatus(clientId: string, handler: MessageHandler<MqttConnectionStatus>): Promise<boolean>;
|
|
42
|
+
unsubscribeConnectionStatus(clientId: string, handler?: MessageHandler<MqttConnectionStatus>): Promise<boolean>;
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "The official TelemetryOS root application sdk package. Provides types and apis for building root TelemetryOS applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|