@telemetryos/root-sdk 1.8.0 → 1.8.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix uncaught exception that broke SDK bridge messages
8
+
3
9
  ## 1.8.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),D="1.8.0",U={version:D};class P{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})}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 C{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class T{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{n[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{n[u]=p}):n=t.headers);const r=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!r.success)throw new TypeError(r.errorMessage,{cause:r.errorCause?Error(r.errorCause):void 0});const l=new Headers(r.headers),c={status:r.status,statusText:r.statusText,headers:l};let d=null;if(r.body!==null&&r.body!==void 0)if(r.bodyType==="binary"){const u=atob(r.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);d=p}else r.bodyType==="text"?d=r.body:r.bodyType==="json"&&(d=JSON.stringify(r.body));return new Response(d,c)}}class F{constructor(e){this._client=e}get application(){return new w("application","",this._client)}get instance(){return new w("instance",this._client.applicationInstance,this._client)}get device(){return new w("device",this._client.applicationInstance,this._client)}shared(e){return new w("shared",e,this._client)}}class w{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class k{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,o;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((o=n.error)===null||o===void 0?void 0:o.message)||"Failed to fetch currency rates");return n.rates}}function I(a){return{...a,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;o[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const m=1e3*30,H=typeof window>"u"&&typeof self<"u",b=H?self:window;function y(a){H?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new P(this)}get users(){return new k(this)}get store(){return new F(this)}get applications(){return new M(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new C(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new T(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),n=o.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const r=o.hostname.split(".");this._applicationSpecifier=(s=r[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=r=>{if(r.source===b||!r.data||!("type"in r.data)||r.data.type!=="client"&&r.data.type!=="bridge")return;let l;if(r.data.type==="client"){const c=this._messageInterceptors.get(r.data.name);if(!c){y(r.data);return}l={...c(r.data.data),type:"bridge"}}if(!l){const c=L.safeParse(r.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const p of d)p(l.data);if(u){for(const p of u)p(l.data);this._onceHandlers.delete(l.name)}}if(!H)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t){const s=q(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});y(o);let n=!1,r;const l=new Promise((d,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{n=!0,this.off(s,r),u(p)},m)}),c=new Promise(d=>{r=u=>{n||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const r=q(),l=q();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(r),this._subscriptionNamesByHandler.set(n,r),this.on(r,n);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:r});y(d);let u=!1,p;const f=new Promise((S,g)=>{const _=new Error(`${e} subscribe request with subscription name of ${r} and response name of ${l} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(l,p),g(_)},m)}),E=new Promise(S=>{p=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,E])}async unsubscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const r=q();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:r,unsubscribeName:c});y(d);let u=!1,p;const f=new Promise((g,_)=>{const j=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${r} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(r,p),_(j)},m)}),E=new Promise(g=>{p=_=>{u||g(_)},this.once(r,g)});if(!(await Promise.race([f,E])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let n=0;n<o.length;n+=1)t&&o[n]!==t||(o.splice(n,1),n-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function q(){return Math.random().toString(36).slice(2,9)}const v=U.version;let i=null;function W(){return i}function O(a){i=new x(a),i.bind()}function G(){i==null||i.unbind(),i=null}function J(...a){return h(i),i.on(...a)}function K(...a){return h(i),i.once(...a)}function z(...a){return h(i),i.off(...a)}function Q(...a){return h(i),i.send(...a)}function X(...a){return h(i),i.request(...a)}function Y(...a){return h(i),i.subscribe(...a)}function Z(...a){return h(i),i.unsubscribe(...a)}function ee(){return h(i),i.store}function te(){return h(i),i.applications}function se(){return h(i),i.media}function ne(){return h(i),i.accounts}function ie(){return h(i),i.users}function re(){return h(i),i.devices}function oe(){return h(i),i.proxy}function ae(){return h(i),i.rootSettingsNavigation}function ce(){return h(i),i.weather}function le(){return h(i),i.currency}function ue(){return h(i),i.environment}function h(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=P;exports.Applications=M;exports.Client=x;exports.Currency=R;exports.Devices=C;exports.Environment=T;exports.Media=A;exports.Proxy=B;exports.Store=F;exports.StoreSlice=w;exports.Users=k;exports.Weather=$;exports.accounts=ne;exports.applications=te;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=re;exports.environment=ue;exports.globalClient=W;exports.media=se;exports.off=z;exports.on=J;exports.once=K;exports.proxy=oe;exports.request=X;exports.rootSettingsNavigation=ae;exports.send=Q;exports.store=ee;exports.subscribe=Y;exports.telemetrySdkVersion=v;exports.unsubscribe=Z;exports.users=ie;exports.weather=ce;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),D="1.8.1",U={version:D};class P{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})}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 C{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class T{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{n[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{n[u]=p}):n=t.headers);const i=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!i.success)throw new TypeError(i.errorMessage,{cause:i.errorCause?Error(i.errorCause):void 0});const l=new Headers(i.headers),c={status:i.status,statusText:i.statusText,headers:l};let d=null;if(i.body!==null&&i.body!==void 0)if(i.bodyType==="binary"){const u=atob(i.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);d=p}else i.bodyType==="text"?d=i.body:i.bodyType==="json"&&(d=JSON.stringify(i.body));return new Response(d,c)}}class F{constructor(e){this._client=e}get application(){return new w("application","",this._client)}get instance(){return new w("instance",this._client.applicationInstance,this._client)}get device(){return new w("device",this._client.applicationInstance,this._client)}shared(e){return new w("shared",e,this._client)}}class w{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class k{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,o;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((o=n.error)===null||o===void 0?void 0:o.message)||"Failed to fetch currency rates");return n.rates}}function I(a){return{...a,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;o[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const m=1e3*30,H=typeof window>"u"&&typeof self<"u",b=H?self:window;function y(a){H?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new P(this)}get users(){return new k(this)}get store(){return new F(this)}get applications(){return new M(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new C(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new T(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),n=o.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const i=o.hostname.split(".");this._applicationSpecifier=(s=i[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=i=>{if(i.source===b||!i.data||typeof i.data!="object"||!("type"in i.data)||i.data.type!=="client"&&i.data.type!=="bridge")return;let l;if(i.data.type==="client"){const c=this._messageInterceptors.get(i.data.name);if(!c){y(i.data);return}l={...c(i.data.data),type:"bridge"}}if(!l){const c=L.safeParse(i.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const p of d)p(l.data);if(u){for(const p of u)p(l.data);this._onceHandlers.delete(l.name)}}if(!H)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t){const s=q(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});y(o);let n=!1,i;const l=new Promise((d,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{n=!0,this.off(s,i),u(p)},m)}),c=new Promise(d=>{i=u=>{n||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q(),l=q();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(i),this._subscriptionNamesByHandler.set(n,i),this.on(i,n);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:i});y(d);let u=!1,p;const f=new Promise((S,g)=>{const _=new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(l,p),g(_)},m)}),E=new Promise(S=>{p=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,E])}async unsubscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:i,unsubscribeName:c});y(d);let u=!1,p;const f=new Promise((g,_)=>{const j=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(i,p),_(j)},m)}),E=new Promise(g=>{p=_=>{u||g(_)},this.once(i,g)});if(!(await Promise.race([f,E])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let n=0;n<o.length;n+=1)t&&o[n]!==t||(o.splice(n,1),n-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function q(){return Math.random().toString(36).slice(2,9)}const v=U.version;let r=null;function W(){return r}function O(a){r=new x(a),r.bind()}function G(){r==null||r.unbind(),r=null}function J(...a){return h(r),r.on(...a)}function K(...a){return h(r),r.once(...a)}function z(...a){return h(r),r.off(...a)}function Q(...a){return h(r),r.send(...a)}function X(...a){return h(r),r.request(...a)}function Y(...a){return h(r),r.subscribe(...a)}function Z(...a){return h(r),r.unsubscribe(...a)}function ee(){return h(r),r.store}function te(){return h(r),r.applications}function se(){return h(r),r.media}function ne(){return h(r),r.accounts}function ie(){return h(r),r.users}function re(){return h(r),r.devices}function oe(){return h(r),r.proxy}function ae(){return h(r),r.rootSettingsNavigation}function ce(){return h(r),r.weather}function le(){return h(r),r.currency}function ue(){return h(r),r.environment}function h(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=P;exports.Applications=M;exports.Client=x;exports.Currency=R;exports.Devices=C;exports.Environment=T;exports.Media=A;exports.Proxy=B;exports.Store=F;exports.StoreSlice=w;exports.Users=k;exports.Weather=$;exports.accounts=ne;exports.applications=te;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=re;exports.environment=ue;exports.globalClient=W;exports.media=se;exports.off=z;exports.on=J;exports.once=K;exports.proxy=oe;exports.request=X;exports.rootSettingsNavigation=ae;exports.send=Q;exports.store=ee;exports.subscribe=Y;exports.telemetrySdkVersion=v;exports.unsubscribe=Z;exports.users=ie;exports.weather=ce;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { o as P, a as M, s as T, l as C } from "./types-CCzf8sMT.js";
2
- const B = "1.8.0", A = {
2
+ const B = "1.8.1", A = {
3
3
  version: B
4
4
  };
5
5
  class F {
@@ -225,29 +225,29 @@ class j {
225
225
  }) : Array.isArray(t.headers) ? t.headers.forEach(([u, p]) => {
226
226
  n[u] = p;
227
227
  }) : n = t.headers);
228
- const r = await this._client.request("proxy.fetch", {
228
+ const i = await this._client.request("proxy.fetch", {
229
229
  url: o,
230
230
  method: (t == null ? void 0 : t.method) || "GET",
231
231
  headers: n,
232
232
  body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
233
233
  });
234
- if (!r.success)
235
- throw new TypeError(r.errorMessage, {
236
- cause: r.errorCause ? Error(r.errorCause) : void 0
234
+ if (!i.success)
235
+ throw new TypeError(i.errorMessage, {
236
+ cause: i.errorCause ? Error(i.errorCause) : void 0
237
237
  });
238
- const l = new Headers(r.headers), c = {
239
- status: r.status,
240
- statusText: r.statusText,
238
+ const l = new Headers(i.headers), c = {
239
+ status: i.status,
240
+ statusText: i.statusText,
241
241
  headers: l
242
242
  };
243
243
  let d = null;
244
- if (r.body !== null && r.body !== void 0)
245
- if (r.bodyType === "binary") {
246
- const u = atob(r.body), p = new Uint8Array(u.length);
244
+ if (i.body !== null && i.body !== void 0)
245
+ if (i.bodyType === "binary") {
246
+ const u = atob(i.body), p = new Uint8Array(u.length);
247
247
  for (let f = 0; f < u.length; f++)
248
248
  p[f] = u.charCodeAt(f);
249
249
  d = p;
250
- } else r.bodyType === "text" ? d = r.body : r.bodyType === "json" && (d = JSON.stringify(r.body));
250
+ } else i.bodyType === "text" ? d = i.body : i.bodyType === "json" && (d = JSON.stringify(i.body));
251
251
  return new Response(d, c);
252
252
  }
253
253
  }
@@ -618,9 +618,9 @@ class G {
618
618
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
619
619
  }
620
620
  }
621
- const _ = 1e3 * 30, E = typeof window > "u" && typeof self < "u", y = E ? self : window;
622
- function w(a) {
623
- E ? self.postMessage(a) : y.parent.postMessage(a, "*");
621
+ const _ = 1e3 * 30, E = typeof window > "u" && typeof self < "u", w = E ? self : window;
622
+ function y(a) {
623
+ E ? self.postMessage(a) : w.parent.postMessage(a, "*");
624
624
  }
625
625
  class J {
626
626
  /**
@@ -822,29 +822,29 @@ class J {
822
822
  */
823
823
  bind() {
824
824
  var e, t, s;
825
- const o = new URL(y.location.href), n = o.searchParams;
825
+ const o = new URL(w.location.href), n = o.searchParams;
826
826
  if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
827
827
  throw new Error("Missing applicationInstance query parameter");
828
828
  if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
829
- const r = o.hostname.split(".");
830
- this._applicationSpecifier = (s = r[0]) !== null && s !== void 0 ? s : "";
829
+ const i = o.hostname.split(".");
830
+ this._applicationSpecifier = (s = i[0]) !== null && s !== void 0 ? s : "";
831
831
  }
832
832
  if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
833
833
  throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
834
- this._windowMessageHandler = (r) => {
835
- if (r.source === y || !r.data || !("type" in r.data) || r.data.type !== "client" && r.data.type !== "bridge")
834
+ this._windowMessageHandler = (i) => {
835
+ if (i.source === w || !i.data || typeof i.data != "object" || !("type" in i.data) || i.data.type !== "client" && i.data.type !== "bridge")
836
836
  return;
837
837
  let l;
838
- if (r.data.type === "client") {
839
- const c = this._messageInterceptors.get(r.data.name);
838
+ if (i.data.type === "client") {
839
+ const c = this._messageInterceptors.get(i.data.name);
840
840
  if (!c) {
841
- w(r.data);
841
+ y(i.data);
842
842
  return;
843
843
  }
844
- l = { ...c(r.data.data), type: "bridge" };
844
+ l = { ...c(i.data.data), type: "bridge" };
845
845
  }
846
846
  if (!l) {
847
- const c = W.safeParse(r.data);
847
+ const c = W.safeParse(i.data);
848
848
  if (!c.success)
849
849
  return;
850
850
  l = c.data;
@@ -861,7 +861,7 @@ class J {
861
861
  if (!E)
862
862
  for (let c = 0; c < window.frames.length; c += 1)
863
863
  window.frames[c].postMessage(l, "*");
864
- }, y.addEventListener("message", this._windowMessageHandler);
864
+ }, w.addEventListener("message", this._windowMessageHandler);
865
865
  }
866
866
  /**
867
867
  * Removes the message event listener and cleans up resources.
@@ -877,7 +877,7 @@ class J {
877
877
  * of managing their own Client instances.
878
878
  */
879
879
  unbind() {
880
- this._windowMessageHandler && y.removeEventListener("message", this._windowMessageHandler);
880
+ this._windowMessageHandler && w.removeEventListener("message", this._windowMessageHandler);
881
881
  }
882
882
  /**
883
883
  * Sends a one-way message to the TelemetryOS platform.
@@ -901,7 +901,7 @@ class J {
901
901
  name: e,
902
902
  data: t
903
903
  });
904
- w(s);
904
+ y(s);
905
905
  }
906
906
  /**
907
907
  * Sends a message to the TelemetryOS platform and waits for a response.
@@ -930,15 +930,15 @@ class J {
930
930
  data: t,
931
931
  responseName: s
932
932
  });
933
- w(o);
934
- let n = !1, r;
933
+ y(o);
934
+ let n = !1, i;
935
935
  const l = new Promise((d, u) => {
936
936
  const p = new Error(`${e} message request with response name of ${s} timed out after ${_}`);
937
937
  setTimeout(() => {
938
- n = !0, this.off(s, r), u(p);
938
+ n = !0, this.off(s, i), u(p);
939
939
  }, _);
940
940
  }), c = new Promise((d) => {
941
- r = (u) => {
941
+ i = (u) => {
942
942
  n || d(u);
943
943
  }, this.once(s, d);
944
944
  });
@@ -947,9 +947,9 @@ class J {
947
947
  async subscribe(e, t, s) {
948
948
  let o, n;
949
949
  typeof t == "function" ? n = t : (o = t, n = s);
950
- const r = N(), l = N();
950
+ const i = N(), l = N();
951
951
  let c = this._subscriptionNamesBySubjectName.get(e);
952
- c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(r), this._subscriptionNamesByHandler.set(n, r), this.on(r, n);
952
+ c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(i), this._subscriptionNamesByHandler.set(n, i), this.on(i, n);
953
953
  const d = S({
954
954
  telemetrySdkVersion: I,
955
955
  applicationName: this._applicationName,
@@ -958,12 +958,12 @@ class J {
958
958
  name: e,
959
959
  data: o,
960
960
  responseName: l,
961
- subscriptionName: r
961
+ subscriptionName: i
962
962
  });
963
- w(d);
963
+ y(d);
964
964
  let u = !1, p;
965
965
  const f = new Promise((b, g) => {
966
- const m = new Error(`${e} subscribe request with subscription name of ${r} and response name of ${l} timed out after ${_}`);
966
+ const m = new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${_}`);
967
967
  setTimeout(() => {
968
968
  u = !0, this.off(l, p), g(m);
969
969
  }, _);
@@ -977,7 +977,7 @@ class J {
977
977
  async unsubscribe(e, t, s) {
978
978
  let o, n;
979
979
  typeof t == "function" ? n = t : (o = t, n = s);
980
- const r = N();
980
+ const i = N();
981
981
  let l = [];
982
982
  if (n) {
983
983
  const c = this._subscriptionNamesByHandler.get(n);
@@ -995,20 +995,20 @@ class J {
995
995
  applicationSpecifier: this._applicationSpecifier,
996
996
  name: e,
997
997
  data: o,
998
- responseName: r,
998
+ responseName: i,
999
999
  unsubscribeName: c
1000
1000
  });
1001
- w(d);
1001
+ y(d);
1002
1002
  let u = !1, p;
1003
1003
  const f = new Promise((g, m) => {
1004
- const q = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${r} timed out after ${_}`);
1004
+ const q = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${_}`);
1005
1005
  setTimeout(() => {
1006
- u = !0, this.off(r, p), m(q);
1006
+ u = !0, this.off(i, p), m(q);
1007
1007
  }, _);
1008
1008
  }), H = new Promise((g) => {
1009
1009
  p = (m) => {
1010
1010
  u || g(m);
1011
- }, this.once(r, g);
1011
+ }, this.once(i, g);
1012
1012
  });
1013
1013
  if (!(await Promise.race([f, H])).success)
1014
1014
  return { success: !1 };
@@ -1091,69 +1091,69 @@ function N() {
1091
1091
  return Math.random().toString(36).slice(2, 9);
1092
1092
  }
1093
1093
  const I = A.version;
1094
- let i = null;
1094
+ let r = null;
1095
1095
  function O() {
1096
- return i;
1096
+ return r;
1097
1097
  }
1098
1098
  function z(a) {
1099
- i = new J(a), i.bind();
1099
+ r = new J(a), r.bind();
1100
1100
  }
1101
1101
  function Q() {
1102
- i == null || i.unbind(), i = null;
1102
+ r == null || r.unbind(), r = null;
1103
1103
  }
1104
1104
  function X(...a) {
1105
- return h(i), i.on(...a);
1105
+ return h(r), r.on(...a);
1106
1106
  }
1107
1107
  function Y(...a) {
1108
- return h(i), i.once(...a);
1108
+ return h(r), r.once(...a);
1109
1109
  }
1110
1110
  function Z(...a) {
1111
- return h(i), i.off(...a);
1111
+ return h(r), r.off(...a);
1112
1112
  }
1113
1113
  function ee(...a) {
1114
- return h(i), i.send(...a);
1114
+ return h(r), r.send(...a);
1115
1115
  }
1116
1116
  function te(...a) {
1117
- return h(i), i.request(...a);
1117
+ return h(r), r.request(...a);
1118
1118
  }
1119
1119
  function se(...a) {
1120
- return h(i), i.subscribe(...a);
1120
+ return h(r), r.subscribe(...a);
1121
1121
  }
1122
1122
  function ne(...a) {
1123
- return h(i), i.unsubscribe(...a);
1123
+ return h(r), r.unsubscribe(...a);
1124
1124
  }
1125
1125
  function ie() {
1126
- return h(i), i.store;
1126
+ return h(r), r.store;
1127
1127
  }
1128
1128
  function re() {
1129
- return h(i), i.applications;
1129
+ return h(r), r.applications;
1130
1130
  }
1131
1131
  function oe() {
1132
- return h(i), i.media;
1132
+ return h(r), r.media;
1133
1133
  }
1134
1134
  function ae() {
1135
- return h(i), i.accounts;
1135
+ return h(r), r.accounts;
1136
1136
  }
1137
1137
  function ce() {
1138
- return h(i), i.users;
1138
+ return h(r), r.users;
1139
1139
  }
1140
1140
  function le() {
1141
- return h(i), i.devices;
1141
+ return h(r), r.devices;
1142
1142
  }
1143
1143
  function ue() {
1144
- return h(i), i.proxy;
1144
+ return h(r), r.proxy;
1145
1145
  }
1146
1146
  function pe() {
1147
- return h(i), i.rootSettingsNavigation;
1147
+ return h(r), r.rootSettingsNavigation;
1148
1148
  }
1149
1149
  function he() {
1150
- return h(i), i.weather;
1150
+ return h(r), r.weather;
1151
1151
  }
1152
1152
  function de() {
1153
- return h(i), i.currency;
1153
+ return h(r), r.currency;
1154
1154
  }
1155
1155
  function fe() {
1156
- return h(i), i.environment;
1156
+ return h(r), r.environment;
1157
1157
  }
1158
1158
  function h(a) {
1159
1159
  if (!a)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
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",