@telemetryos/root-sdk 1.13.1 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +172 -168
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./types-mYnxD5LM.cjs"),Q="1.13.1",V={version:Q};class E{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},{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 T{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 k{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 M{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 F{constructor(e){this._client=e}async fetch(e,t){var s;let n;typeof e=="string"?n=e:e instanceof URL?n=e.toString():(n=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 i={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,d)=>{i[d]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,d])=>{i[h]=d}):i=t.headers);const a=await this._client.request("proxy.fetch",{url:n,method:(t==null?void 0:t.method)||"GET",headers:i,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!a.success)throw new TypeError(a.errorMessage,{cause:a.errorCause?Error(a.errorCause):void 0});const c=new Headers(a.headers),l={status:a.status,statusText:a.statusText,headers:c};let u=null;if(a.body!==null&&a.body!==void 0)if(a.bodyType==="binary"){const h=atob(a.body),d=new Uint8Array(h.length);for(let f=0;f<h.length;f++)d[f]=h.charCodeAt(f);u=d}else a.bodyType==="text"?u=a.body:a.bodyType==="json"&&(u=JSON.stringify(a.body));return new Response(u,l)}}class A{constructor(e){this._client=e}get application(){return new v("application",void 0,this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.deviceId,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 R{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 B{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 ${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,n;const i=await this._client.request("currency.getRates",e);if(!i.success||!i.rates)throw((t=i.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=i.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((n=i.error)===null||n===void 0?void 0:n.message)||"Failed to fetch currency rates");return i.rates}}class L{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,n){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...n})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,n){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...n},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}}class x{constructor(e){this._originalPushState=null,this._originalReplaceState=null,this._popstateHandler=null,this._backHandler=null,this._forwardHandler=null,this._client=e}bind(){typeof window>"u"||this._originalPushState||(this._originalPushState=history.pushState.bind(history),history.pushState=(...e)=>{this._originalPushState(...e),this._sendLocationChanged()},this._originalReplaceState=history.replaceState.bind(history),history.replaceState=(...e)=>{this._originalReplaceState(...e),this._sendLocationChanged()},this._popstateHandler=()=>this._sendLocationChanged(),window.addEventListener("popstate",this._popstateHandler),this._backHandler=()=>history.back(),this._forwardHandler=()=>history.forward(),this._client.on("navigation.back",this._backHandler),this._client.on("navigation.forward",this._forwardHandler),this._sendLocationChanged())}unbind(){typeof window>"u"||(this._originalPushState&&(history.pushState=this._originalPushState,this._originalPushState=null),this._originalReplaceState&&(history.replaceState=this._originalReplaceState,this._originalReplaceState=null),this._popstateHandler&&(window.removeEventListener("popstate",this._popstateHandler),this._popstateHandler=null),this._backHandler&&(this._client.off("navigation.back",this._backHandler),this._backHandler=null),this._forwardHandler&&(this._client.off("navigation.forward",this._forwardHandler),this._forwardHandler=null))}_sendLocationChanged(){this._client.send("navigation.locationChanged",{pathname:window.location.pathname})}}function N(o){return{...o,type:"client"}}const O=H.objectType({type:H.literalType("bridge"),name:H.stringType(),data:H.anyType()});class W{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"),n=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},i=this._store._client._applicationSpecifier;n[i]={applicationSpecifier:i,entries:e.entries},s.set("navigation",n)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},n=this._store._client._applicationSpecifier;return s[n]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const y=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function m(o){C?self.postMessage(o):S.parent.postMessage(o,"*")}class j{constructor(){this._applicationInstance="",this._applicationSpecifier="",this._deviceId="",this._navigation=new x(this),this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new E(this)}get users(){return new R(this)}get store(){return new A(this)}get applications(){return new P(this)}get media(){return new M(this)}get proxy(){return new F(this)}get devices(){return new T(this)}get rootSettingsNavigation(){return new W(this.store)}get weather(){return new B(this)}get currency(){return new $(this)}get environment(){return new k(this)}get mqtt(){return new L(this)}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}get deviceId(){return this._deviceId}bind(){var e,t;const s=new URL(S.location.href),n=s.searchParams;this._applicationInstance=n.get("applicationInstance")||"single",this._deviceId=n.get("deviceId")||this._applicationInstance;const i=s.hostname.split("."),a=/^[a-f0-9]{40}$/i;if(this._applicationSpecifier=(e=n.get("applicationSpecifier"))!==null&&e!==void 0?e:"",(!this._applicationSpecifier||!a.test(this._applicationSpecifier))&&(this._applicationSpecifier=(t=i[0])!==null&&t!==void 0?t:""),!this._applicationSpecifier||!a.test(this._applicationSpecifier))throw console.error("TelemetryOS apps require an applicationSpecifier in the URL query parameters or subdomain. Make sure your app is being served correctly through the TelemetryOS platform or development environment."),new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=c=>{if(c.source===S||!c.data||typeof c.data!="object"||!("type"in c.data)||c.data.type!=="client"&&c.data.type!=="bridge")return;let l;if(c.data.type==="client"){const u=this._messageInterceptors.get(c.data.name);if(!u){m(c.data);return}l={...u(c.data.data),type:"bridge",...c.data.responseName?{name:c.data.responseName}:{}}}if(!l){const u=O.safeParse(c.data);if(!u.success)return;l=u.data;const h=this._onHandlers.get(l.name),d=this._onceHandlers.get(l.name);if(h)for(const f of h)f(l.data);if(d){for(const f of d)f(l.data);this._onceHandlers.delete(l.name)}}if(!C)for(let u=0;u<window.frames.length;u+=1)window.frames[u].postMessage(l,"*")},S.addEventListener("message",this._windowMessageHandler),this._navigation.bind()}unbind(){this._windowMessageHandler&&(this._navigation.unbind(),S.removeEventListener("message",this._windowMessageHandler))}send(e,t){const s=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});m(s)}request(e,t,s){var n;const i=I(),a=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:i});m(a);const c=(n=s==null?void 0:s.timeout)!==null&&n!==void 0?n:y;let l=!1,u;const h=new Promise(f=>{u=g=>{l||f(g)},this.once(i,u)});if(c===0)return h;const d=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${i} timed out after ${c}`);setTimeout(()=>{l=!0,this.off(i,u),g(w)},c)});return Promise.race([d,h])}async subscribe(e,t,s){let n,i;typeof t=="function"?i=t:(n=t,i=s);const a=I(),c=I();let l=this._subscriptionNamesBySubjectName.get(e);l||(l=[],this._subscriptionNamesBySubjectName.set(e,l)),l.push(a),this._subscriptionNamesByHandler.set(i,a),this.on(a,i);const u=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:n,responseName:c,subscriptionName:a});m(u);let h=!1,d;const f=new Promise((w,_)=>{const b=new Error(`${e} subscribe request with subscription name of ${a} and response name of ${c} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(c,d),_(b)},y)}),g=new Promise(w=>{d=_=>{h||w(_)},this.once(c,d)});return Promise.race([f,g])}async unsubscribe(e,t,s){let n,i;typeof t=="function"?i=t:(n=t,i=s);const a=I();let c=[];if(i){const l=this._subscriptionNamesByHandler.get(i);if(!l)return{success:!1};c=[l],this._subscriptionNamesByHandler.delete(i)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const l of c){this.off(l,i);const u=N({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationSpecifier:this._applicationSpecifier,name:e,data:n,responseName:a,unsubscribeName:l});m(u);let h=!1,d;const f=new Promise((_,b)=>{const U=new Error(`${e} unsubscribe request with unsubscribe name of ${l} and response name of ${a} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(a,d),b(U)},y)}),g=new Promise(_=>{d=b=>{h||_(b)},this.once(a,d)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const n=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];n.length===0&&this._onHandlers.set(e,n),n.push(t)}once(e,t){var s;const n=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];n.length===0&&this._onceHandlers.set(e,n),n.push(t)}off(e,t){const s=this._onHandlers.get(e),n=this._onceHandlers.get(e);if(!(!s&&!n)){if(s){for(let i=0;i<s.length;i+=1)t&&s[i]!==t||(s.splice(i,1),i-=1);s.length===0&&this._onHandlers.delete(e)}if(n){for(let i=0;i<n.length;i+=1)t&&n[i]!==t||(n.splice(i,1),i-=1);n.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=V.version;let r=null;function G(){return r}function J(o){D(),r=new j,r.bind()}function D(){r==null||r.unbind(),r=null}function K(...o){return p(r),r.on(...o)}function z(...o){return p(r),r.once(...o)}function X(...o){return p(r),r.off(...o)}function Y(...o){return p(r),r.send(...o)}function Z(...o){return p(r),r.request(...o)}function ee(...o){return p(r),r.subscribe(...o)}function te(...o){return p(r),r.unsubscribe(...o)}function se(){return p(r),r.store}function ne(){return p(r),r.applications}function ie(){return p(r),r.media}function re(){return p(r),r.accounts}function oe(){return p(r),r.users}function ae(){return p(r),r.devices}function ce(){return p(r),r.proxy}function le(){return p(r),r.rootSettingsNavigation}function ue(){return p(r),r.weather}function he(){return p(r),r.currency}function de(){return p(r),r.environment}function pe(){return p(r),r.mqtt}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=E;exports.Applications=P;exports.Client=j;exports.Currency=$;exports.Devices=T;exports.Environment=k;exports.Media=M;exports.Mqtt=L;exports.Navigation=x;exports.Proxy=F;exports.Store=A;exports.StoreSlice=v;exports.Users=R;exports.Weather=B;exports.accounts=re;exports.applications=ne;exports.configure=J;exports.currency=he;exports.destroy=D;exports.devices=ae;exports.environment=de;exports.globalClient=G;exports.media=ie;exports.mqtt=pe;exports.off=X;exports.on=K;exports.once=z;exports.proxy=ce;exports.request=Z;exports.rootSettingsNavigation=le;exports.send=Y;exports.store=se;exports.subscribe=ee;exports.telemetrySdkVersion=q;exports.unsubscribe=te;exports.users=oe;exports.weather=ue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./types-mYnxD5LM.cjs"),Q="1.13.2",V={version:Q};class E{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},{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 T{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 k{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 M{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 F{constructor(e){this._client=e}async fetch(e,t){var s;let i;typeof e=="string"?i=e:e instanceof URL?i=e.toString():(i=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((h,u)=>{n[u]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,u])=>{n[h]=u}):n=t.headers);const o=await this._client.request("proxy.fetch",{url:i,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 l=new Headers(o.headers),c={status:o.status,statusText:o.statusText,headers:l};let p=null;if(o.body!==null&&o.body!==void 0)if(o.bodyType==="binary"){const h=atob(o.body),u=new Uint8Array(h.length);for(let f=0;f<h.length;f++)u[f]=h.charCodeAt(f);p=u}else o.bodyType==="text"?p=o.body:o.bodyType==="json"&&(p=JSON.stringify(o.body));return new Response(p,c)}}class A{constructor(e){this._client=e}get application(){return new v("application",void 0,this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.deviceId,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 R{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 B{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 ${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,i;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(((i=n.error)===null||i===void 0?void 0:i.message)||"Failed to fetch currency rates");return n.rates}}class L{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,i){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...i})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,i){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...i},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}}class x{constructor(e){this._originalPushState=null,this._originalReplaceState=null,this._popstateHandler=null,this._backHandler=null,this._forwardHandler=null,this._client=e}bind(){typeof window>"u"||this._originalPushState||(this._originalPushState=history.pushState.bind(history),history.pushState=(...e)=>{this._originalPushState(...e),this._sendLocationChanged()},this._originalReplaceState=history.replaceState.bind(history),history.replaceState=(...e)=>{this._originalReplaceState(...e),this._sendLocationChanged()},this._popstateHandler=()=>this._sendLocationChanged(),window.addEventListener("popstate",this._popstateHandler),this._backHandler=()=>history.back(),this._forwardHandler=()=>history.forward(),this._client.on("navigation.back",this._backHandler),this._client.on("navigation.forward",this._forwardHandler),this._sendLocationChanged())}unbind(){typeof window>"u"||(this._originalPushState&&(history.pushState=this._originalPushState,this._originalPushState=null),this._originalReplaceState&&(history.replaceState=this._originalReplaceState,this._originalReplaceState=null),this._popstateHandler&&(window.removeEventListener("popstate",this._popstateHandler),this._popstateHandler=null),this._backHandler&&(this._client.off("navigation.back",this._backHandler),this._backHandler=null),this._forwardHandler&&(this._client.off("navigation.forward",this._forwardHandler),this._forwardHandler=null))}_sendLocationChanged(){this._client.send("navigation.locationChanged",{pathname:window.location.pathname})}}function N(a){return{...a,type:"client"}}const O=H.objectType({type:H.literalType("bridge"),name:H.stringType(),data:H.anyType()});class W{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"),i=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;i[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",i)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},i=this._store._client._applicationSpecifier;return s[i]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const y=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function m(a){C?self.postMessage(a):S.parent.postMessage(a,"*")}class j{constructor(){this._applicationInstance="",this._applicationSpecifier="",this._deviceId="",this._navigation=new x(this),this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new E(this)}get users(){return new R(this)}get store(){return new A(this)}get applications(){return new P(this)}get media(){return new M(this)}get proxy(){return new F(this)}get devices(){return new T(this)}get rootSettingsNavigation(){return new W(this.store)}get weather(){return new B(this)}get currency(){return new $(this)}get environment(){return new k(this)}get mqtt(){return new L(this)}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}get deviceId(){return this._deviceId}bind(){var e,t;const s=new URL(S.location.href),i=s.searchParams;this._applicationInstance=i.get("applicationInstance")||"single",this._deviceId=i.get("deviceId")||this._applicationInstance;const n=/^[a-z0-9-]{40}$/i;if(this._applicationSpecifier=(e=i.get("applicationSpecifier"))!==null&&e!==void 0?e:"",!this._applicationSpecifier||!n.test(this._applicationSpecifier)){const o=s.hostname.split(".");this._applicationSpecifier=(t=o[0])!==null&&t!==void 0?t:""}if(!this._applicationSpecifier||!n.test(this._applicationSpecifier))throw console.error("TelemetryOS apps require an applicationSpecifier in the URL query parameters or subdomain. Make sure your app is being served correctly through the TelemetryOS platform or development environment."),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 l;if(o.data.type==="client"){const c=this._messageInterceptors.get(o.data.name);if(!c){m(o.data);return}l={...c(o.data.data),type:"bridge",...o.data.responseName?{name:o.data.responseName}:{}}}if(!l){const c=O.safeParse(o.data);if(!c.success)return;l=c.data;const p=this._onHandlers.get(l.name),h=this._onceHandlers.get(l.name);if(p)for(const u of p)u(l.data);if(h){for(const u of h)u(l.data);this._onceHandlers.delete(l.name)}}if(!C)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},S.addEventListener("message",this._windowMessageHandler),this._navigation.bind()}unbind(){this._windowMessageHandler&&(this._navigation.unbind(),S.removeEventListener("message",this._windowMessageHandler))}send(e,t){const s=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});m(s)}request(e,t,s){var i;const n=I(),o=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});m(o);const l=(i=s==null?void 0:s.timeout)!==null&&i!==void 0?i:y;let c=!1,p;const h=new Promise(f=>{p=g=>{c||f(g)},this.once(n,p)});if(l===0)return h;const u=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${l}`);setTimeout(()=>{c=!0,this.off(n,p),g(w)},l)});return Promise.race([u,h])}async subscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I(),l=I();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(o),this._subscriptionNamesByHandler.set(n,o),this.on(o,n);const p=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:i,responseName:l,subscriptionName:o});m(p);let h=!1,u;const f=new Promise((w,_)=>{const b=new Error(`${e} subscribe request with subscription name of ${o} and response name of ${l} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(l,u),_(b)},y)}),g=new Promise(w=>{u=_=>{h||w(_)},this.once(l,u)});return Promise.race([f,g])}async unsubscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I();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 p=N({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationSpecifier:this._applicationSpecifier,name:e,data:i,responseName:o,unsubscribeName:c});m(p);let h=!1,u;const f=new Promise((_,b)=>{const U=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${o} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(o,u),b(U)},y)}),g=new Promise(_=>{u=b=>{h||_(b)},this.once(o,u)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const i=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onHandlers.set(e,i),i.push(t)}once(e,t){var s;const i=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onceHandlers.set(e,i),i.push(t)}off(e,t){const s=this._onHandlers.get(e),i=this._onceHandlers.get(e);if(!(!s&&!i)){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(i){for(let n=0;n<i.length;n+=1)t&&i[n]!==t||(i.splice(n,1),n-=1);i.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=V.version;let r=null;function z(){return r}function G(a){D(),r=new j,r.bind()}function D(){r==null||r.unbind(),r=null}function J(...a){return d(r),r.on(...a)}function K(...a){return d(r),r.once(...a)}function X(...a){return d(r),r.off(...a)}function Y(...a){return d(r),r.send(...a)}function Z(...a){return d(r),r.request(...a)}function ee(...a){return d(r),r.subscribe(...a)}function te(...a){return d(r),r.unsubscribe(...a)}function se(){return d(r),r.store}function ne(){return d(r),r.applications}function ie(){return d(r),r.media}function re(){return d(r),r.accounts}function oe(){return d(r),r.users}function ae(){return d(r),r.devices}function ce(){return d(r),r.proxy}function le(){return d(r),r.rootSettingsNavigation}function ue(){return d(r),r.weather}function he(){return d(r),r.currency}function de(){return d(r),r.environment}function pe(){return d(r),r.mqtt}function d(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=E;exports.Applications=P;exports.Client=j;exports.Currency=$;exports.Devices=T;exports.Environment=k;exports.Media=M;exports.Mqtt=L;exports.Navigation=x;exports.Proxy=F;exports.Store=A;exports.StoreSlice=v;exports.Users=R;exports.Weather=B;exports.accounts=re;exports.applications=ne;exports.configure=G;exports.currency=he;exports.destroy=D;exports.devices=ae;exports.environment=de;exports.globalClient=z;exports.media=ie;exports.mqtt=pe;exports.off=X;exports.on=J;exports.once=K;exports.proxy=ce;exports.request=Z;exports.rootSettingsNavigation=le;exports.send=Y;exports.store=se;exports.subscribe=ee;exports.telemetrySdkVersion=q;exports.unsubscribe=te;exports.users=oe;exports.weather=ue;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as C, a as P, s as T, l as k } from "./types-CCzf8sMT.js";
|
|
2
|
-
const M = "1.13.
|
|
2
|
+
const M = "1.13.2", F = {
|
|
3
3
|
version: M
|
|
4
4
|
};
|
|
5
5
|
class R {
|
|
@@ -239,8 +239,8 @@ class x {
|
|
|
239
239
|
}
|
|
240
240
|
async fetch(e, t) {
|
|
241
241
|
var s;
|
|
242
|
-
let
|
|
243
|
-
typeof e == "string" ?
|
|
242
|
+
let i;
|
|
243
|
+
typeof e == "string" ? i = e : e instanceof URL ? i = e.toString() : (i = e.url, t || (t = {
|
|
244
244
|
method: e.method,
|
|
245
245
|
headers: e.headers,
|
|
246
246
|
body: e.body,
|
|
@@ -250,36 +250,36 @@ class x {
|
|
|
250
250
|
referrer: e.referrer,
|
|
251
251
|
integrity: e.integrity
|
|
252
252
|
}));
|
|
253
|
-
let
|
|
254
|
-
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h,
|
|
255
|
-
|
|
256
|
-
}) : Array.isArray(t.headers) ? t.headers.forEach(([h,
|
|
257
|
-
|
|
258
|
-
}) :
|
|
259
|
-
const
|
|
260
|
-
url:
|
|
253
|
+
let n = {};
|
|
254
|
+
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h, u) => {
|
|
255
|
+
n[u] = h;
|
|
256
|
+
}) : Array.isArray(t.headers) ? t.headers.forEach(([h, u]) => {
|
|
257
|
+
n[h] = u;
|
|
258
|
+
}) : n = t.headers);
|
|
259
|
+
const a = await this._client.request("proxy.fetch", {
|
|
260
|
+
url: i,
|
|
261
261
|
method: (t == null ? void 0 : t.method) || "GET",
|
|
262
|
-
headers:
|
|
262
|
+
headers: n,
|
|
263
263
|
body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
|
|
264
264
|
});
|
|
265
|
-
if (!
|
|
266
|
-
throw new TypeError(
|
|
267
|
-
cause:
|
|
265
|
+
if (!a.success)
|
|
266
|
+
throw new TypeError(a.errorMessage, {
|
|
267
|
+
cause: a.errorCause ? Error(a.errorCause) : void 0
|
|
268
268
|
});
|
|
269
|
-
const
|
|
270
|
-
status:
|
|
271
|
-
statusText:
|
|
272
|
-
headers:
|
|
269
|
+
const l = new Headers(a.headers), c = {
|
|
270
|
+
status: a.status,
|
|
271
|
+
statusText: a.statusText,
|
|
272
|
+
headers: l
|
|
273
273
|
};
|
|
274
|
-
let
|
|
275
|
-
if (
|
|
276
|
-
if (
|
|
277
|
-
const h = atob(
|
|
274
|
+
let p = null;
|
|
275
|
+
if (a.body !== null && a.body !== void 0)
|
|
276
|
+
if (a.bodyType === "binary") {
|
|
277
|
+
const h = atob(a.body), u = new Uint8Array(h.length);
|
|
278
278
|
for (let f = 0; f < h.length; f++)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} else
|
|
282
|
-
return new Response(
|
|
279
|
+
u[f] = h.charCodeAt(f);
|
|
280
|
+
p = u;
|
|
281
|
+
} else a.bodyType === "text" ? p = a.body : a.bodyType === "json" && (p = JSON.stringify(a.body));
|
|
282
|
+
return new Response(p, c);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
class j {
|
|
@@ -642,11 +642,11 @@ class U {
|
|
|
642
642
|
* ```
|
|
643
643
|
*/
|
|
644
644
|
async getRates(e) {
|
|
645
|
-
var t, s,
|
|
646
|
-
const
|
|
647
|
-
if (!
|
|
648
|
-
throw ((t =
|
|
649
|
-
return
|
|
645
|
+
var t, s, i;
|
|
646
|
+
const n = await this._client.request("currency.getRates", e);
|
|
647
|
+
if (!n.success || !n.rates)
|
|
648
|
+
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(((i = n.error) === null || i === void 0 ? void 0 : i.message) || "Failed to fetch currency rates");
|
|
649
|
+
return n.rates;
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
class V {
|
|
@@ -672,20 +672,20 @@ class V {
|
|
|
672
672
|
if (!(await this._client.request("mqtt.disconnect", { clientId: e })).success)
|
|
673
673
|
throw new Error("Failed to disconnect from MQTT broker");
|
|
674
674
|
}
|
|
675
|
-
async publish(e, t, s,
|
|
675
|
+
async publish(e, t, s, i) {
|
|
676
676
|
if (!(await this._client.request("mqtt.publish", {
|
|
677
677
|
clientId: e,
|
|
678
678
|
topic: t,
|
|
679
679
|
payload: s,
|
|
680
|
-
...
|
|
680
|
+
...i
|
|
681
681
|
})).success)
|
|
682
682
|
throw new Error("Failed to publish MQTT message");
|
|
683
683
|
}
|
|
684
|
-
async subscribe(e, t, s,
|
|
684
|
+
async subscribe(e, t, s, i) {
|
|
685
685
|
return (await this._client.subscribe("mqtt.subscribe", {
|
|
686
686
|
clientId: e,
|
|
687
687
|
topic: t,
|
|
688
|
-
...
|
|
688
|
+
...i
|
|
689
689
|
}, s)).success;
|
|
690
690
|
}
|
|
691
691
|
async unsubscribe(e, t, s) {
|
|
@@ -733,15 +733,15 @@ class O {
|
|
|
733
733
|
});
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
|
-
function q(
|
|
737
|
-
return { ...
|
|
736
|
+
function q(o) {
|
|
737
|
+
return { ...o, type: "client" };
|
|
738
738
|
}
|
|
739
739
|
const W = C({
|
|
740
740
|
type: k("bridge"),
|
|
741
741
|
name: T(),
|
|
742
742
|
data: P()
|
|
743
743
|
});
|
|
744
|
-
class
|
|
744
|
+
class z {
|
|
745
745
|
/**
|
|
746
746
|
* Creates a new RootSettingsNavigation API instance.
|
|
747
747
|
*
|
|
@@ -765,11 +765,11 @@ class G {
|
|
|
765
765
|
*/
|
|
766
766
|
async setRootSettingsNavigation(e) {
|
|
767
767
|
var t;
|
|
768
|
-
const s = this._store.shared("root-settings-navigation"),
|
|
769
|
-
n
|
|
770
|
-
applicationSpecifier:
|
|
768
|
+
const s = this._store.shared("root-settings-navigation"), i = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, n = this._store._client._applicationSpecifier;
|
|
769
|
+
i[n] = {
|
|
770
|
+
applicationSpecifier: n,
|
|
771
771
|
entries: e.entries
|
|
772
|
-
}, s.set("navigation",
|
|
772
|
+
}, s.set("navigation", i);
|
|
773
773
|
}
|
|
774
774
|
/**
|
|
775
775
|
* Retrieves the current navigation entries for this root application.
|
|
@@ -781,8 +781,8 @@ class G {
|
|
|
781
781
|
*/
|
|
782
782
|
async getRootSettingsNavigation() {
|
|
783
783
|
var e;
|
|
784
|
-
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {},
|
|
785
|
-
return s[
|
|
784
|
+
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, i = this._store._client._applicationSpecifier;
|
|
785
|
+
return s[i];
|
|
786
786
|
}
|
|
787
787
|
/**
|
|
788
788
|
* Retrieves the navigation entries for all root applications.
|
|
@@ -799,10 +799,10 @@ class G {
|
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
const m = 1e3 * 30, N = typeof window > "u" && typeof self < "u", v = N ? self : window;
|
|
802
|
-
function y(
|
|
803
|
-
N ? self.postMessage(
|
|
802
|
+
function y(o) {
|
|
803
|
+
N ? self.postMessage(o) : v.parent.postMessage(o, "*");
|
|
804
804
|
}
|
|
805
|
-
class
|
|
805
|
+
class G {
|
|
806
806
|
/**
|
|
807
807
|
* Creates a new Client instance for communicating with the TelemetryOS platform.
|
|
808
808
|
*
|
|
@@ -929,7 +929,7 @@ class J {
|
|
|
929
929
|
* @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
|
|
930
930
|
*/
|
|
931
931
|
get rootSettingsNavigation() {
|
|
932
|
-
return new
|
|
932
|
+
return new z(this.store);
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
935
935
|
* Provides access to the weather API for retrieving weather data.
|
|
@@ -1002,45 +1002,49 @@ class J {
|
|
|
1002
1002
|
*/
|
|
1003
1003
|
bind() {
|
|
1004
1004
|
var e, t;
|
|
1005
|
-
const s = new URL(v.location.href),
|
|
1006
|
-
this._applicationInstance =
|
|
1007
|
-
const
|
|
1008
|
-
if (this._applicationSpecifier = (e =
|
|
1005
|
+
const s = new URL(v.location.href), i = s.searchParams;
|
|
1006
|
+
this._applicationInstance = i.get("applicationInstance") || "single", this._deviceId = i.get("deviceId") || this._applicationInstance;
|
|
1007
|
+
const n = /^[a-z0-9-]{40}$/i;
|
|
1008
|
+
if (this._applicationSpecifier = (e = i.get("applicationSpecifier")) !== null && e !== void 0 ? e : "", !this._applicationSpecifier || !n.test(this._applicationSpecifier)) {
|
|
1009
|
+
const a = s.hostname.split(".");
|
|
1010
|
+
this._applicationSpecifier = (t = a[0]) !== null && t !== void 0 ? t : "";
|
|
1011
|
+
}
|
|
1012
|
+
if (!this._applicationSpecifier || !n.test(this._applicationSpecifier))
|
|
1009
1013
|
throw console.error("TelemetryOS apps require an applicationSpecifier in the URL query parameters or subdomain. Make sure your app is being served correctly through the TelemetryOS platform or development environment."), new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
1010
|
-
this._windowMessageHandler = (
|
|
1011
|
-
if (
|
|
1014
|
+
this._windowMessageHandler = (a) => {
|
|
1015
|
+
if (a.source === v || !a.data || typeof a.data != "object" || !("type" in a.data) || a.data.type !== "client" && a.data.type !== "bridge")
|
|
1012
1016
|
return;
|
|
1013
1017
|
let l;
|
|
1014
|
-
if (
|
|
1015
|
-
const
|
|
1016
|
-
if (!
|
|
1017
|
-
y(
|
|
1018
|
+
if (a.data.type === "client") {
|
|
1019
|
+
const c = this._messageInterceptors.get(a.data.name);
|
|
1020
|
+
if (!c) {
|
|
1021
|
+
y(a.data);
|
|
1018
1022
|
return;
|
|
1019
1023
|
}
|
|
1020
1024
|
l = {
|
|
1021
|
-
...
|
|
1025
|
+
...c(a.data.data),
|
|
1022
1026
|
type: "bridge",
|
|
1023
|
-
...
|
|
1027
|
+
...a.data.responseName ? { name: a.data.responseName } : {}
|
|
1024
1028
|
};
|
|
1025
1029
|
}
|
|
1026
1030
|
if (!l) {
|
|
1027
|
-
const
|
|
1028
|
-
if (!
|
|
1031
|
+
const c = W.safeParse(a.data);
|
|
1032
|
+
if (!c.success)
|
|
1029
1033
|
return;
|
|
1030
|
-
l =
|
|
1031
|
-
const
|
|
1032
|
-
if (
|
|
1033
|
-
for (const
|
|
1034
|
-
|
|
1035
|
-
if (
|
|
1036
|
-
for (const
|
|
1037
|
-
|
|
1034
|
+
l = c.data;
|
|
1035
|
+
const p = this._onHandlers.get(l.name), h = this._onceHandlers.get(l.name);
|
|
1036
|
+
if (p)
|
|
1037
|
+
for (const u of p)
|
|
1038
|
+
u(l.data);
|
|
1039
|
+
if (h) {
|
|
1040
|
+
for (const u of h)
|
|
1041
|
+
u(l.data);
|
|
1038
1042
|
this._onceHandlers.delete(l.name);
|
|
1039
1043
|
}
|
|
1040
1044
|
}
|
|
1041
1045
|
if (!N)
|
|
1042
|
-
for (let
|
|
1043
|
-
window.frames[
|
|
1046
|
+
for (let c = 0; c < window.frames.length; c += 1)
|
|
1047
|
+
window.frames[c].postMessage(l, "*");
|
|
1044
1048
|
}, v.addEventListener("message", this._windowMessageHandler), this._navigation.bind();
|
|
1045
1049
|
}
|
|
1046
1050
|
/**
|
|
@@ -1102,96 +1106,96 @@ class J {
|
|
|
1102
1106
|
* @throws {Error} If the request times out
|
|
1103
1107
|
*/
|
|
1104
1108
|
request(e, t, s) {
|
|
1105
|
-
var
|
|
1106
|
-
const
|
|
1109
|
+
var i;
|
|
1110
|
+
const n = H(), a = q({
|
|
1107
1111
|
telemetrySdkVersion: I,
|
|
1108
1112
|
applicationSpecifier: this._applicationSpecifier,
|
|
1109
1113
|
applicationInstance: this._applicationInstance,
|
|
1110
1114
|
name: e,
|
|
1111
1115
|
data: t,
|
|
1112
|
-
responseName:
|
|
1116
|
+
responseName: n
|
|
1113
1117
|
});
|
|
1114
|
-
y(
|
|
1115
|
-
const
|
|
1116
|
-
let
|
|
1118
|
+
y(a);
|
|
1119
|
+
const l = (i = s == null ? void 0 : s.timeout) !== null && i !== void 0 ? i : m;
|
|
1120
|
+
let c = !1, p;
|
|
1117
1121
|
const h = new Promise((f) => {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
}, this.once(
|
|
1122
|
+
p = (g) => {
|
|
1123
|
+
c || f(g);
|
|
1124
|
+
}, this.once(n, p);
|
|
1121
1125
|
});
|
|
1122
|
-
if (
|
|
1126
|
+
if (l === 0)
|
|
1123
1127
|
return h;
|
|
1124
|
-
const
|
|
1125
|
-
const w = new Error(`${e} message request with response name of ${
|
|
1128
|
+
const u = new Promise((f, g) => {
|
|
1129
|
+
const w = new Error(`${e} message request with response name of ${n} timed out after ${l}`);
|
|
1126
1130
|
setTimeout(() => {
|
|
1127
|
-
|
|
1128
|
-
},
|
|
1131
|
+
c = !0, this.off(n, p), g(w);
|
|
1132
|
+
}, l);
|
|
1129
1133
|
});
|
|
1130
|
-
return Promise.race([
|
|
1134
|
+
return Promise.race([u, h]);
|
|
1131
1135
|
}
|
|
1132
1136
|
async subscribe(e, t, s) {
|
|
1133
|
-
let
|
|
1134
|
-
typeof t == "function" ?
|
|
1135
|
-
const
|
|
1136
|
-
let
|
|
1137
|
-
|
|
1138
|
-
const
|
|
1137
|
+
let i, n;
|
|
1138
|
+
typeof t == "function" ? n = t : (i = t, n = s);
|
|
1139
|
+
const a = H(), l = H();
|
|
1140
|
+
let c = this._subscriptionNamesBySubjectName.get(e);
|
|
1141
|
+
c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(a), this._subscriptionNamesByHandler.set(n, a), this.on(a, n);
|
|
1142
|
+
const p = q({
|
|
1139
1143
|
telemetrySdkVersion: I,
|
|
1140
1144
|
applicationSpecifier: this._applicationSpecifier,
|
|
1141
1145
|
applicationInstance: this._applicationInstance,
|
|
1142
1146
|
name: e,
|
|
1143
|
-
data:
|
|
1144
|
-
responseName:
|
|
1145
|
-
subscriptionName:
|
|
1147
|
+
data: i,
|
|
1148
|
+
responseName: l,
|
|
1149
|
+
subscriptionName: a
|
|
1146
1150
|
});
|
|
1147
|
-
y(
|
|
1148
|
-
let h = !1,
|
|
1151
|
+
y(p);
|
|
1152
|
+
let h = !1, u;
|
|
1149
1153
|
const f = new Promise((w, _) => {
|
|
1150
|
-
const b = new Error(`${e} subscribe request with subscription name of ${
|
|
1154
|
+
const b = new Error(`${e} subscribe request with subscription name of ${a} and response name of ${l} timed out after ${m}`);
|
|
1151
1155
|
setTimeout(() => {
|
|
1152
|
-
h = !0, this.off(
|
|
1156
|
+
h = !0, this.off(l, u), _(b);
|
|
1153
1157
|
}, m);
|
|
1154
1158
|
}), g = new Promise((w) => {
|
|
1155
|
-
|
|
1159
|
+
u = (_) => {
|
|
1156
1160
|
h || w(_);
|
|
1157
|
-
}, this.once(
|
|
1161
|
+
}, this.once(l, u);
|
|
1158
1162
|
});
|
|
1159
1163
|
return Promise.race([f, g]);
|
|
1160
1164
|
}
|
|
1161
1165
|
async unsubscribe(e, t, s) {
|
|
1162
|
-
let
|
|
1163
|
-
typeof t == "function" ?
|
|
1164
|
-
const
|
|
1165
|
-
let
|
|
1166
|
-
if (
|
|
1167
|
-
const
|
|
1168
|
-
if (!
|
|
1166
|
+
let i, n;
|
|
1167
|
+
typeof t == "function" ? n = t : (i = t, n = s);
|
|
1168
|
+
const a = H();
|
|
1169
|
+
let l = [];
|
|
1170
|
+
if (n) {
|
|
1171
|
+
const c = this._subscriptionNamesByHandler.get(n);
|
|
1172
|
+
if (!c)
|
|
1169
1173
|
return { success: !1 };
|
|
1170
|
-
|
|
1174
|
+
l = [c], this._subscriptionNamesByHandler.delete(n);
|
|
1171
1175
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
1172
1176
|
return { success: !1 };
|
|
1173
|
-
for await (const
|
|
1174
|
-
this.off(
|
|
1175
|
-
const
|
|
1177
|
+
for await (const c of l) {
|
|
1178
|
+
this.off(c, n);
|
|
1179
|
+
const p = q({
|
|
1176
1180
|
telemetrySdkVersion: I,
|
|
1177
1181
|
applicationInstance: this._applicationInstance,
|
|
1178
1182
|
applicationSpecifier: this._applicationSpecifier,
|
|
1179
1183
|
name: e,
|
|
1180
|
-
data:
|
|
1181
|
-
responseName:
|
|
1182
|
-
unsubscribeName:
|
|
1184
|
+
data: i,
|
|
1185
|
+
responseName: a,
|
|
1186
|
+
unsubscribeName: c
|
|
1183
1187
|
});
|
|
1184
|
-
y(
|
|
1185
|
-
let h = !1,
|
|
1188
|
+
y(p);
|
|
1189
|
+
let h = !1, u;
|
|
1186
1190
|
const f = new Promise((_, b) => {
|
|
1187
|
-
const E = new Error(`${e} unsubscribe request with unsubscribe name of ${
|
|
1191
|
+
const E = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${a} timed out after ${m}`);
|
|
1188
1192
|
setTimeout(() => {
|
|
1189
|
-
h = !0, this.off(
|
|
1193
|
+
h = !0, this.off(a, u), b(E);
|
|
1190
1194
|
}, m);
|
|
1191
1195
|
}), g = new Promise((_) => {
|
|
1192
|
-
|
|
1196
|
+
u = (b) => {
|
|
1193
1197
|
h || _(b);
|
|
1194
|
-
}, this.once(
|
|
1198
|
+
}, this.once(a, u);
|
|
1195
1199
|
});
|
|
1196
1200
|
if (!(await Promise.race([f, g])).success)
|
|
1197
1201
|
return { success: !1 };
|
|
@@ -1217,8 +1221,8 @@ class J {
|
|
|
1217
1221
|
*/
|
|
1218
1222
|
on(e, t) {
|
|
1219
1223
|
var s;
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1224
|
+
const i = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1225
|
+
i.length === 0 && this._onHandlers.set(e, i), i.push(t);
|
|
1222
1226
|
}
|
|
1223
1227
|
/**
|
|
1224
1228
|
* Registers a one-time handler for a specific message type.
|
|
@@ -1236,8 +1240,8 @@ class J {
|
|
|
1236
1240
|
*/
|
|
1237
1241
|
once(e, t) {
|
|
1238
1242
|
var s;
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1243
|
+
const i = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1244
|
+
i.length === 0 && this._onceHandlers.set(e, i), i.push(t);
|
|
1241
1245
|
}
|
|
1242
1246
|
/**
|
|
1243
1247
|
* Removes previously registered message handlers.
|
|
@@ -1255,17 +1259,17 @@ class J {
|
|
|
1255
1259
|
* all handlers for this message type will be removed.
|
|
1256
1260
|
*/
|
|
1257
1261
|
off(e, t) {
|
|
1258
|
-
const s = this._onHandlers.get(e),
|
|
1259
|
-
if (!(!s && !
|
|
1262
|
+
const s = this._onHandlers.get(e), i = this._onceHandlers.get(e);
|
|
1263
|
+
if (!(!s && !i)) {
|
|
1260
1264
|
if (s) {
|
|
1261
|
-
for (let
|
|
1262
|
-
t && s[
|
|
1265
|
+
for (let n = 0; n < s.length; n += 1)
|
|
1266
|
+
t && s[n] !== t || (s.splice(n, 1), n -= 1);
|
|
1263
1267
|
s.length === 0 && this._onHandlers.delete(e);
|
|
1264
1268
|
}
|
|
1265
|
-
if (
|
|
1266
|
-
for (let
|
|
1267
|
-
t && n
|
|
1268
|
-
|
|
1269
|
+
if (i) {
|
|
1270
|
+
for (let n = 0; n < i.length; n += 1)
|
|
1271
|
+
t && i[n] !== t || (i.splice(n, 1), n -= 1);
|
|
1272
|
+
i.length === 0 && this._onceHandlers.delete(e);
|
|
1269
1273
|
}
|
|
1270
1274
|
}
|
|
1271
1275
|
}
|
|
@@ -1278,77 +1282,77 @@ let r = null;
|
|
|
1278
1282
|
function X() {
|
|
1279
1283
|
return r;
|
|
1280
1284
|
}
|
|
1281
|
-
function Y(
|
|
1282
|
-
|
|
1285
|
+
function Y(o) {
|
|
1286
|
+
J(), r = new G(), r.bind();
|
|
1283
1287
|
}
|
|
1284
|
-
function
|
|
1288
|
+
function J() {
|
|
1285
1289
|
r == null || r.unbind(), r = null;
|
|
1286
1290
|
}
|
|
1287
|
-
function Z(...
|
|
1288
|
-
return
|
|
1291
|
+
function Z(...o) {
|
|
1292
|
+
return d(r), r.on(...o);
|
|
1289
1293
|
}
|
|
1290
|
-
function ee(...
|
|
1291
|
-
return
|
|
1294
|
+
function ee(...o) {
|
|
1295
|
+
return d(r), r.once(...o);
|
|
1292
1296
|
}
|
|
1293
|
-
function te(...
|
|
1294
|
-
return
|
|
1297
|
+
function te(...o) {
|
|
1298
|
+
return d(r), r.off(...o);
|
|
1295
1299
|
}
|
|
1296
|
-
function se(...
|
|
1297
|
-
return
|
|
1300
|
+
function se(...o) {
|
|
1301
|
+
return d(r), r.send(...o);
|
|
1298
1302
|
}
|
|
1299
|
-
function ne(...
|
|
1300
|
-
return
|
|
1303
|
+
function ne(...o) {
|
|
1304
|
+
return d(r), r.request(...o);
|
|
1301
1305
|
}
|
|
1302
|
-
function ie(...
|
|
1303
|
-
return
|
|
1306
|
+
function ie(...o) {
|
|
1307
|
+
return d(r), r.subscribe(...o);
|
|
1304
1308
|
}
|
|
1305
|
-
function re(...
|
|
1306
|
-
return
|
|
1309
|
+
function re(...o) {
|
|
1310
|
+
return d(r), r.unsubscribe(...o);
|
|
1307
1311
|
}
|
|
1308
1312
|
function ae() {
|
|
1309
|
-
return
|
|
1313
|
+
return d(r), r.store;
|
|
1310
1314
|
}
|
|
1311
1315
|
function oe() {
|
|
1312
|
-
return
|
|
1316
|
+
return d(r), r.applications;
|
|
1313
1317
|
}
|
|
1314
1318
|
function ce() {
|
|
1315
|
-
return
|
|
1319
|
+
return d(r), r.media;
|
|
1316
1320
|
}
|
|
1317
1321
|
function le() {
|
|
1318
|
-
return
|
|
1322
|
+
return d(r), r.accounts;
|
|
1319
1323
|
}
|
|
1320
1324
|
function ue() {
|
|
1321
|
-
return
|
|
1325
|
+
return d(r), r.users;
|
|
1322
1326
|
}
|
|
1323
1327
|
function he() {
|
|
1324
|
-
return
|
|
1328
|
+
return d(r), r.devices;
|
|
1325
1329
|
}
|
|
1326
1330
|
function de() {
|
|
1327
|
-
return
|
|
1331
|
+
return d(r), r.proxy;
|
|
1328
1332
|
}
|
|
1329
1333
|
function pe() {
|
|
1330
|
-
return
|
|
1334
|
+
return d(r), r.rootSettingsNavigation;
|
|
1331
1335
|
}
|
|
1332
1336
|
function fe() {
|
|
1333
|
-
return
|
|
1337
|
+
return d(r), r.weather;
|
|
1334
1338
|
}
|
|
1335
1339
|
function ge() {
|
|
1336
|
-
return
|
|
1340
|
+
return d(r), r.currency;
|
|
1337
1341
|
}
|
|
1338
1342
|
function _e() {
|
|
1339
|
-
return
|
|
1343
|
+
return d(r), r.environment;
|
|
1340
1344
|
}
|
|
1341
1345
|
function we() {
|
|
1342
|
-
return
|
|
1346
|
+
return d(r), r.mqtt;
|
|
1343
1347
|
}
|
|
1344
|
-
function
|
|
1345
|
-
if (!
|
|
1348
|
+
function d(o) {
|
|
1349
|
+
if (!o)
|
|
1346
1350
|
throw new Error("SDK is not configured");
|
|
1347
1351
|
}
|
|
1348
1352
|
export {
|
|
1349
1353
|
R as Accounts,
|
|
1350
1354
|
A as Applications,
|
|
1351
|
-
|
|
1355
|
+
G as Client,
|
|
1352
1356
|
U as Currency,
|
|
1353
1357
|
B as Devices,
|
|
1354
1358
|
$ as Environment,
|
|
@@ -1364,7 +1368,7 @@ export {
|
|
|
1364
1368
|
oe as applications,
|
|
1365
1369
|
Y as configure,
|
|
1366
1370
|
ge as currency,
|
|
1367
|
-
|
|
1371
|
+
J as destroy,
|
|
1368
1372
|
he as devices,
|
|
1369
1373
|
_e as environment,
|
|
1370
1374
|
X as globalClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
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",
|