@telemetryos/root-sdk 1.11.0 → 1.12.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 +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +49 -49
- 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 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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),Q="1.12.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((h,l)=>{n[l]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,l])=>{n[h]=l}):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 h=atob(o.body),l=new Uint8Array(h.length);for(let f=0;f<h.length;f++)l[f]=h.charCodeAt(f);p=l}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),h=this._onceHandlers.get(u.name);if(p)for(const l of p)l(u.data);if(h){for(const l of h)l(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 h=new Promise(f=>{p=g=>{a||f(g)},this.once(n,p)});if(u===0)return h;const l=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([l,h])}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 h=!1,l;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(()=>{h=!0,this.off(u,l),m(_)},b)}),g=new Promise(w=>{l=m=>{h||w(m)},this.once(u,l)});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 h=!1,l;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(()=>{h=!0,this.off(o,l),_(D)},b)}),g=new Promise(m=>{l=_=>{h||m(_)},this.once(o,l)});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 d(i),i.on(...c)}function K(...c){return d(i),i.once(...c)}function z(...c){return d(i),i.off(...c)}function X(...c){return d(i),i.send(...c)}function Y(...c){return d(i),i.request(...c)}function Z(...c){return d(i),i.subscribe(...c)}function ee(...c){return d(i),i.unsubscribe(...c)}function te(){return d(i),i.store}function se(){return d(i),i.applications}function ne(){return d(i),i.media}function re(){return d(i),i.accounts}function ie(){return d(i),i.users}function oe(){return d(i),i.devices}function ce(){return d(i),i.proxy}function ae(){return d(i),i.rootSettingsNavigation}function ue(){return d(i),i.weather}function le(){return d(i),i.currency}function he(){return d(i),i.environment}function de(){return d(i),i.mqtt}function d(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
|
@@ -3,7 +3,7 @@ export { Applications } from './applications.js';
|
|
|
3
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
|
|
6
|
+
export type { MediaContent, MediaFolder, MediaSelection, MediaPickerOptions } from './media.js';
|
|
7
7
|
export { Proxy } from './proxy.js';
|
|
8
8
|
export { Store, StoreSlice } from './store.js';
|
|
9
9
|
export { Users } from './users.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as C, a as H, s as M, l as P } from "./types-CCzf8sMT.js";
|
|
2
|
-
const F = "1.
|
|
2
|
+
const F = "1.12.0", k = {
|
|
3
3
|
version: F
|
|
4
4
|
};
|
|
5
5
|
class A {
|
|
@@ -251,10 +251,10 @@ class j {
|
|
|
251
251
|
integrity: e.integrity
|
|
252
252
|
}));
|
|
253
253
|
let n = {};
|
|
254
|
-
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((
|
|
255
|
-
n[
|
|
256
|
-
}) : Array.isArray(t.headers) ? t.headers.forEach(([
|
|
257
|
-
n[
|
|
254
|
+
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h, l) => {
|
|
255
|
+
n[l] = h;
|
|
256
|
+
}) : Array.isArray(t.headers) ? t.headers.forEach(([h, l]) => {
|
|
257
|
+
n[h] = l;
|
|
258
258
|
}) : n = t.headers);
|
|
259
259
|
const o = await this._client.request("proxy.fetch", {
|
|
260
260
|
url: r,
|
|
@@ -274,10 +274,10 @@ class j {
|
|
|
274
274
|
let p = null;
|
|
275
275
|
if (o.body !== null && o.body !== void 0)
|
|
276
276
|
if (o.bodyType === "binary") {
|
|
277
|
-
const
|
|
278
|
-
for (let f = 0; f <
|
|
279
|
-
|
|
280
|
-
p =
|
|
277
|
+
const h = atob(o.body), l = new Uint8Array(h.length);
|
|
278
|
+
for (let f = 0; f < h.length; f++)
|
|
279
|
+
l[f] = h.charCodeAt(f);
|
|
280
|
+
p = l;
|
|
281
281
|
} else o.bodyType === "text" ? p = o.body : o.bodyType === "json" && (p = JSON.stringify(o.body));
|
|
282
282
|
return new Response(p, a);
|
|
283
283
|
}
|
|
@@ -1013,13 +1013,13 @@ class J {
|
|
|
1013
1013
|
if (!a.success)
|
|
1014
1014
|
return;
|
|
1015
1015
|
u = a.data;
|
|
1016
|
-
const p = this._onHandlers.get(u.name),
|
|
1016
|
+
const p = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
|
|
1017
1017
|
if (p)
|
|
1018
|
-
for (const
|
|
1019
|
-
|
|
1020
|
-
if (
|
|
1021
|
-
for (const
|
|
1022
|
-
|
|
1018
|
+
for (const l of p)
|
|
1019
|
+
l(u.data);
|
|
1020
|
+
if (h) {
|
|
1021
|
+
for (const l of h)
|
|
1022
|
+
l(u.data);
|
|
1023
1023
|
this._onceHandlers.delete(u.name);
|
|
1024
1024
|
}
|
|
1025
1025
|
}
|
|
@@ -1101,20 +1101,20 @@ class J {
|
|
|
1101
1101
|
y(o);
|
|
1102
1102
|
const u = (r = s == null ? void 0 : s.timeout) !== null && r !== void 0 ? r : b;
|
|
1103
1103
|
let a = !1, p;
|
|
1104
|
-
const
|
|
1104
|
+
const h = new Promise((f) => {
|
|
1105
1105
|
p = (g) => {
|
|
1106
1106
|
a || f(g);
|
|
1107
1107
|
}, this.once(n, p);
|
|
1108
1108
|
});
|
|
1109
1109
|
if (u === 0)
|
|
1110
|
-
return
|
|
1111
|
-
const
|
|
1110
|
+
return h;
|
|
1111
|
+
const l = new Promise((f, g) => {
|
|
1112
1112
|
const m = new Error(`${e} message request with response name of ${n} timed out after ${u}`);
|
|
1113
1113
|
setTimeout(() => {
|
|
1114
1114
|
a = !0, this.off(n, p), g(m);
|
|
1115
1115
|
}, u);
|
|
1116
1116
|
});
|
|
1117
|
-
return Promise.race([
|
|
1117
|
+
return Promise.race([l, h]);
|
|
1118
1118
|
}
|
|
1119
1119
|
async subscribe(e, t, s) {
|
|
1120
1120
|
let r, n;
|
|
@@ -1133,16 +1133,16 @@ class J {
|
|
|
1133
1133
|
subscriptionName: o
|
|
1134
1134
|
});
|
|
1135
1135
|
y(p);
|
|
1136
|
-
let
|
|
1136
|
+
let h = !1, l;
|
|
1137
1137
|
const f = new Promise((m, w) => {
|
|
1138
1138
|
const _ = new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);
|
|
1139
1139
|
setTimeout(() => {
|
|
1140
|
-
|
|
1140
|
+
h = !0, this.off(u, l), w(_);
|
|
1141
1141
|
}, b);
|
|
1142
1142
|
}), g = new Promise((m) => {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
}, this.
|
|
1143
|
+
l = (w) => {
|
|
1144
|
+
h || m(w);
|
|
1145
|
+
}, this.once(u, l);
|
|
1146
1146
|
});
|
|
1147
1147
|
return Promise.race([f, g]);
|
|
1148
1148
|
}
|
|
@@ -1171,16 +1171,16 @@ class J {
|
|
|
1171
1171
|
unsubscribeName: a
|
|
1172
1172
|
});
|
|
1173
1173
|
y(p);
|
|
1174
|
-
let
|
|
1174
|
+
let h = !1, l;
|
|
1175
1175
|
const f = new Promise((w, _) => {
|
|
1176
1176
|
const T = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);
|
|
1177
1177
|
setTimeout(() => {
|
|
1178
|
-
|
|
1178
|
+
h = !0, this.off(o, l), _(T);
|
|
1179
1179
|
}, b);
|
|
1180
1180
|
}), g = new Promise((w) => {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
}, this.once(o,
|
|
1181
|
+
l = (_) => {
|
|
1182
|
+
h || w(_);
|
|
1183
|
+
}, this.once(o, l);
|
|
1184
1184
|
});
|
|
1185
1185
|
if (!(await Promise.race([f, g])).success)
|
|
1186
1186
|
return { success: !1 };
|
|
@@ -1274,63 +1274,63 @@ function X() {
|
|
|
1274
1274
|
i == null || i.unbind(), i = null;
|
|
1275
1275
|
}
|
|
1276
1276
|
function Y(...c) {
|
|
1277
|
-
return
|
|
1277
|
+
return d(i), i.on(...c);
|
|
1278
1278
|
}
|
|
1279
1279
|
function Z(...c) {
|
|
1280
|
-
return
|
|
1280
|
+
return d(i), i.once(...c);
|
|
1281
1281
|
}
|
|
1282
1282
|
function ee(...c) {
|
|
1283
|
-
return
|
|
1283
|
+
return d(i), i.off(...c);
|
|
1284
1284
|
}
|
|
1285
1285
|
function te(...c) {
|
|
1286
|
-
return
|
|
1286
|
+
return d(i), i.send(...c);
|
|
1287
1287
|
}
|
|
1288
1288
|
function se(...c) {
|
|
1289
|
-
return
|
|
1289
|
+
return d(i), i.request(...c);
|
|
1290
1290
|
}
|
|
1291
1291
|
function ne(...c) {
|
|
1292
|
-
return
|
|
1292
|
+
return d(i), i.subscribe(...c);
|
|
1293
1293
|
}
|
|
1294
1294
|
function re(...c) {
|
|
1295
|
-
return
|
|
1295
|
+
return d(i), i.unsubscribe(...c);
|
|
1296
1296
|
}
|
|
1297
1297
|
function ie() {
|
|
1298
|
-
return
|
|
1298
|
+
return d(i), i.store;
|
|
1299
1299
|
}
|
|
1300
1300
|
function oe() {
|
|
1301
|
-
return
|
|
1301
|
+
return d(i), i.applications;
|
|
1302
1302
|
}
|
|
1303
1303
|
function ce() {
|
|
1304
|
-
return
|
|
1304
|
+
return d(i), i.media;
|
|
1305
1305
|
}
|
|
1306
1306
|
function ae() {
|
|
1307
|
-
return
|
|
1307
|
+
return d(i), i.accounts;
|
|
1308
1308
|
}
|
|
1309
1309
|
function ue() {
|
|
1310
|
-
return
|
|
1310
|
+
return d(i), i.users;
|
|
1311
1311
|
}
|
|
1312
1312
|
function le() {
|
|
1313
|
-
return
|
|
1313
|
+
return d(i), i.devices;
|
|
1314
1314
|
}
|
|
1315
1315
|
function he() {
|
|
1316
|
-
return
|
|
1316
|
+
return d(i), i.proxy;
|
|
1317
1317
|
}
|
|
1318
1318
|
function de() {
|
|
1319
|
-
return
|
|
1319
|
+
return d(i), i.rootSettingsNavigation;
|
|
1320
1320
|
}
|
|
1321
1321
|
function pe() {
|
|
1322
|
-
return
|
|
1322
|
+
return d(i), i.weather;
|
|
1323
1323
|
}
|
|
1324
1324
|
function fe() {
|
|
1325
|
-
return
|
|
1325
|
+
return d(i), i.currency;
|
|
1326
1326
|
}
|
|
1327
1327
|
function ge() {
|
|
1328
|
-
return
|
|
1328
|
+
return d(i), i.environment;
|
|
1329
1329
|
}
|
|
1330
1330
|
function we() {
|
|
1331
|
-
return
|
|
1331
|
+
return d(i), i.mqtt;
|
|
1332
1332
|
}
|
|
1333
|
-
function
|
|
1333
|
+
function d(c) {
|
|
1334
1334
|
if (!c)
|
|
1335
1335
|
throw new Error("SDK is not configured");
|
|
1336
1336
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.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",
|