@telemetryos/root-sdk 1.5.1 → 1.6.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,25 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Add scripts for release process
8
+
9
+ Adds a few scripts to help make the release process for these packages
10
+ smoother. Fixes a few issues with undeployed changes from the last release.
11
+
12
+ ## 1.6.0
13
+
14
+ ### Minor Changes
15
+
16
+ - Fixes the init command, improvements
17
+
18
+ - Fixes an issue where the init command would fail
19
+ - Changes the location of the config file when you store an API token
20
+ - Improves CLAUDE.md for Claude Code integration
21
+ - Exports the environment API for the SDK
22
+
3
23
  ## 1.5.1
4
24
 
5
25
  ### Patch Changes
package/dist/client.d.ts CHANGED
@@ -7,6 +7,7 @@ import { Users } from './users.js';
7
7
  import { Proxy } from './proxy.js';
8
8
  import { Devices } from './devices.js';
9
9
  import { Weather } from './weather.js';
10
+ import { Environment } from './environment.js';
10
11
  import { BridgeMessage } from './bridge.js';
11
12
  /**
12
13
  * The maximum time in milliseconds to wait for a response to a request call.
@@ -206,6 +207,18 @@ export declare class Client {
206
207
  * @returns A Weather instance bound to this client
207
208
  */
208
209
  get weather(): Weather;
210
+ /**
211
+ * Provides access to the environment API for accessing environment settings.
212
+ *
213
+ * This property returns a new Environment instance that allows applications to get
214
+ * and subscribe to environment settings such as the current color scheme.
215
+ *
216
+ * NOTE: Most application developers should use the global environment() function
217
+ * instead of accessing this property directly.
218
+ *
219
+ * @returns An Environment instance bound to this client
220
+ */
221
+ get environment(): Environment;
209
222
  get applicationName(): string;
210
223
  get applicationSpecifier(): string;
211
224
  get applicationInstance(): string;
@@ -1,5 +1,5 @@
1
1
  import { Client } from './index.js';
2
- type ColorScheme = 'light' | 'dark' | 'system';
2
+ export type ColorScheme = 'light' | 'dark' | 'system';
3
3
  export declare class Environment {
4
4
  _client: Client;
5
5
  constructor(client: Client);
@@ -7,4 +7,3 @@ export declare class Environment {
7
7
  subscribeColorScheme(handler: (colorScheme: ColorScheme) => void): void;
8
8
  unsubscribeColorScheme(handler: (colorScheme: ColorScheme) => void): void;
9
9
  }
10
- export {};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./index-JDXm3DEz.cjs"),F="1.5.1",$={version:F};class H{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 q{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 E{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}}function x(a,e=console.error){a().catch(e)}class R{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}subscribeColorScheme(e){x(async()=>{this._client.on("environment.colorSchemeChanged",e),e(await this.getColorScheme())})}unsubscribeColorScheme(e){this._client.off("environment.colorSchemeChanged",e)}}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}}class P{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 r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{r[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{r[u]=p}):r=t.headers);const n=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:r,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!n.success)throw new TypeError(n.errorMessage,{cause:n.errorCause?Error(n.errorCause):void 0});const l=new Headers(n.headers),c={status:n.status,statusText:n.statusText,headers:l};let h=null;if(n.body!==null&&n.body!==void 0)if(n.bodyType==="binary"){const u=atob(n.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);h=p}else n.bodyType==="text"?h=n.body:n.bodyType==="json"&&(h=JSON.stringify(n.body));return new Response(h,c)}}class C{constructor(e){this._client=e}get application(){return new S("application","",this._client)}get instance(){return new S("instance",this._client.applicationInstance,this._client)}get device(){return new S("device",this._client.applicationInstance,this._client)}shared(e){return new S("shared",e,this._client)}}class S{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 A{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 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}}function v(a){return{...a,type:"client"}}const j=b.z.object({type:b.z.literal("bridge"),name:b.z.string(),data:b.z.any()});class D{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:{},r=this._store._client._applicationSpecifier;o[r]={applicationSpecifier:r,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const _=1e3*30;class T{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 H(this)}get users(){return new A(this)}get store(){return new C(this)}get applications(){return new q(this)}get media(){return new M(this)}get proxy(){return new P(this)}get devices(){return new E(this)}get rootSettingsNavigation(){return new D(this.store)}get weather(){return new B(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(window.location.href),r=o.searchParams;if(this._applicationInstance=(e=r.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=r.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const n=o.hostname.split(".");this._applicationSpecifier=(s=n[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=n=>{if(n.source===window||!n.data||!("type"in n.data)||n.data.type!=="client"&&n.data.type!=="bridge")return;let l;if(n.data.type==="client"){const c=this._messageInterceptors.get(n.data.name);if(!c){window.parent.postMessage(n.data,"*");return}l={...c(n.data.data),type:"bridge"}}if(!l){const c=j.safeParse(n.data);if(!c.success)return;l=c.data;const h=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(h)for(const p of h)p(l.data);if(u){for(const p of u)p(l.data);this._onceHandlers.delete(l.name)}}for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=v({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});window.parent.postMessage(s,"*")}request(e,t){const s=N(),o=v({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});window.parent.postMessage(o,"*");let r=!1,n;const l=new Promise((h,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${_}`);setTimeout(()=>{r=!0,this.off(s,n),u(p)},_)}),c=new Promise(h=>{n=u=>{r||h(u)},this.once(s,h)});return Promise.race([l,c])}async subscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=N(),l=N();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(n),this._subscriptionNamesByHandler.set(r,n),this.on(n,r);const h=v({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:n});window.parent.postMessage(h,"*");let u=!1,p;const f=new Promise((y,g)=>{const m=new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(l,p),g(m)},_)}),I=new Promise(y=>{p=g=>{u||y(g)},this.on(l,y)});return Promise.race([f,I])}async unsubscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=N();let l=[];if(r){const c=this._subscriptionNamesByHandler.get(r);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(r)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,r);const h=v({telemetrySdkVersion:w,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:n,unsubscribeName:c});window.parent.postMessage(h,"*");let u=!1,p;const f=new Promise((g,m)=>{const k=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(n,p),m(k)},_)}),I=new Promise(g=>{p=m=>{u||g(m)},this.once(n,g)});if(!(await Promise.race([f,I])).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 r=0;r<s.length;r+=1)t&&s[r]!==t||(s.splice(r,1),r-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let r=0;r<o.length;r+=1)t&&o[r]!==t||(o.splice(r,1),r-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function N(){return Math.random().toString(36).slice(2,9)}const w=$.version;let i=null;function U(){return i}function z(a){i=new T(a),i.bind()}function L(){i==null||i.unbind(),i=null}function V(...a){return d(i),i.on(...a)}function O(...a){return d(i),i.once(...a)}function W(...a){return d(i),i.off(...a)}function G(...a){return d(i),i.send(...a)}function J(...a){return d(i),i.request(...a)}function K(...a){return d(i),i.subscribe(...a)}function Q(...a){return d(i),i.unsubscribe(...a)}function X(){return d(i),i.store}function Y(){return d(i),i.applications}function Z(){return d(i),i.media}function ee(){return d(i),i.accounts}function te(){return d(i),i.users}function se(){return d(i),i.devices}function ne(){return d(i),i.proxy}function ie(){return d(i),i.rootSettingsNavigation}function re(){return d(i),i.weather}function d(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=H;exports.Applications=q;exports.Client=T;exports.Devices=E;exports.Environment=R;exports.Media=M;exports.Proxy=P;exports.Store=C;exports.Users=A;exports.Weather=B;exports.accounts=ee;exports.applications=Y;exports.configure=z;exports.destroy=L;exports.devices=se;exports.globalClient=U;exports.media=Z;exports.off=W;exports.on=V;exports.once=O;exports.proxy=ne;exports.request=J;exports.rootSettingsNavigation=ie;exports.send=G;exports.store=X;exports.subscribe=K;exports.telemetrySdkVersion=w;exports.unsubscribe=Q;exports.users=te;exports.weather=re;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./index-JDXm3DEz.cjs"),$="1.6.1",x={version:$};class H{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 q{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 E{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}}function R(a,e=console.error){a().catch(e)}class M{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}subscribeColorScheme(e){R(async()=>{this._client.on("environment.colorSchemeChanged",e),e(await this.getColorScheme())})}unsubscribeColorScheme(e){this._client.off("environment.colorSchemeChanged",e)}}class P{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 C{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 r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{r[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{r[u]=p}):r=t.headers);const n=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:r,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!n.success)throw new TypeError(n.errorMessage,{cause:n.errorCause?Error(n.errorCause):void 0});const l=new Headers(n.headers),c={status:n.status,statusText:n.statusText,headers:l};let d=null;if(n.body!==null&&n.body!==void 0)if(n.bodyType==="binary"){const u=atob(n.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);d=p}else n.bodyType==="text"?d=n.body:n.bodyType==="json"&&(d=JSON.stringify(n.body));return new Response(d,c)}}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 T{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}}function S(a){return{...a,type:"client"}}const j=b.z.object({type:b.z.literal("bridge"),name:b.z.string(),data:b.z.any()});class D{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:{},r=this._store._client._applicationSpecifier;o[r]={applicationSpecifier:r,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;class k{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 H(this)}get users(){return new B(this)}get store(){return new A(this)}get applications(){return new q(this)}get media(){return new P(this)}get proxy(){return new C(this)}get devices(){return new E(this)}get rootSettingsNavigation(){return new D(this.store)}get weather(){return new T(this)}get environment(){return new M(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(window.location.href),r=o.searchParams;if(this._applicationInstance=(e=r.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=r.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const n=o.hostname.split(".");this._applicationSpecifier=(s=n[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=n=>{if(n.source===window||!n.data||!("type"in n.data)||n.data.type!=="client"&&n.data.type!=="bridge")return;let l;if(n.data.type==="client"){const c=this._messageInterceptors.get(n.data.name);if(!c){window.parent.postMessage(n.data,"*");return}l={...c(n.data.data),type:"bridge"}}if(!l){const c=j.safeParse(n.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)}}for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=S({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});window.parent.postMessage(s,"*")}request(e,t){const s=N(),o=S({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});window.parent.postMessage(o,"*");let r=!1,n;const l=new Promise((d,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{r=!0,this.off(s,n),u(p)},m)}),c=new Promise(d=>{n=u=>{r||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=N(),l=N();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(n),this._subscriptionNamesByHandler.set(r,n),this.on(n,r);const d=S({telemetrySdkVersion:w,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:n});window.parent.postMessage(d,"*");let u=!1,p;const f=new Promise((y,g)=>{const _=new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(l,p),g(_)},m)}),I=new Promise(y=>{p=g=>{u||y(g)},this.on(l,y)});return Promise.race([f,I])}async unsubscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=N();let l=[];if(r){const c=this._subscriptionNamesByHandler.get(r);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(r)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,r);const d=S({telemetrySdkVersion:w,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:n,unsubscribeName:c});window.parent.postMessage(d,"*");let u=!1,p;const f=new Promise((g,_)=>{const F=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(n,p),_(F)},m)}),I=new Promise(g=>{p=_=>{u||g(_)},this.once(n,g)});if(!(await Promise.race([f,I])).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 r=0;r<s.length;r+=1)t&&s[r]!==t||(s.splice(r,1),r-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let r=0;r<o.length;r+=1)t&&o[r]!==t||(o.splice(r,1),r-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function N(){return Math.random().toString(36).slice(2,9)}const w=x.version;let i=null;function U(){return i}function z(a){i=new k(a),i.bind()}function L(){i==null||i.unbind(),i=null}function V(...a){return h(i),i.on(...a)}function O(...a){return h(i),i.once(...a)}function W(...a){return h(i),i.off(...a)}function G(...a){return h(i),i.send(...a)}function J(...a){return h(i),i.request(...a)}function K(...a){return h(i),i.subscribe(...a)}function Q(...a){return h(i),i.unsubscribe(...a)}function X(){return h(i),i.store}function Y(){return h(i),i.applications}function Z(){return h(i),i.media}function ee(){return h(i),i.accounts}function te(){return h(i),i.users}function se(){return h(i),i.devices}function ne(){return h(i),i.proxy}function ie(){return h(i),i.rootSettingsNavigation}function re(){return h(i),i.weather}function oe(){return h(i),i.environment}function h(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=H;exports.Applications=q;exports.Client=k;exports.Devices=E;exports.Environment=M;exports.Media=P;exports.Proxy=C;exports.Store=A;exports.Users=B;exports.Weather=T;exports.accounts=ee;exports.applications=Y;exports.configure=z;exports.destroy=L;exports.devices=se;exports.environment=oe;exports.globalClient=U;exports.media=Z;exports.off=W;exports.on=V;exports.once=O;exports.proxy=ne;exports.request=J;exports.rootSettingsNavigation=ie;exports.send=G;exports.store=X;exports.subscribe=K;exports.telemetrySdkVersion=w;exports.unsubscribe=Q;exports.users=te;exports.weather=re;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Accounts } from './accounts.js';
2
2
  export { Applications } from './applications.js';
3
3
  export { Devices } from './devices.js';
4
- export { Environment } from './environment.js';
4
+ export { Environment, type ColorScheme } from './environment.js';
5
5
  export { Media } from './media.js';
6
6
  export { Proxy } from './proxy.js';
7
7
  export { Store } from './store.js';
@@ -267,3 +267,21 @@ export declare function rootSettingsNavigation(): import("./root-settings-naviga
267
267
  * const forecast = await weather().getDailyForecast({ city: 'London', units: 'metric', days: 5 });
268
268
  */
269
269
  export declare function weather(): import("./weather.js").Weather;
270
+ /**
271
+ * Provides access to the environment API for accessing environment settings.
272
+ *
273
+ * This API allows applications to get and subscribe to environment settings
274
+ * such as the current color scheme (light/dark/system).
275
+ *
276
+ * @returns The Environment API object
277
+ * @throws {Error} If called before configure() or after destroy()
278
+ * @example
279
+ * // Get current color scheme
280
+ * const scheme = await environment().getColorScheme();
281
+ *
282
+ * // Subscribe to color scheme changes
283
+ * environment().subscribeColorScheme((newScheme) => {
284
+ * applyTheme(newScheme);
285
+ * });
286
+ */
287
+ export declare function environment(): import("./environment.js").Environment;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z as y } from "./index-B98VDFRY.js";
2
- const q = "1.5.1", E = {
2
+ const q = "1.6.1", E = {
3
3
  version: q
4
4
  };
5
5
  class M {
@@ -145,7 +145,7 @@ class C {
145
145
  function A(a, e = console.error) {
146
146
  a().catch(e);
147
147
  }
148
- class L {
148
+ class B {
149
149
  constructor(e) {
150
150
  this._client = e;
151
151
  }
@@ -161,7 +161,7 @@ class L {
161
161
  this._client.off("environment.colorSchemeChanged", e);
162
162
  }
163
163
  }
164
- class B {
164
+ class T {
165
165
  constructor(e) {
166
166
  this._client = e;
167
167
  }
@@ -207,7 +207,7 @@ class B {
207
207
  })).content;
208
208
  }
209
209
  }
210
- class T {
210
+ class F {
211
211
  constructor(e) {
212
212
  this._client = e;
213
213
  }
@@ -245,18 +245,18 @@ class T {
245
245
  statusText: n.statusText,
246
246
  headers: l
247
247
  };
248
- let h = null;
248
+ let d = null;
249
249
  if (n.body !== null && n.body !== void 0)
250
250
  if (n.bodyType === "binary") {
251
251
  const u = atob(n.body), p = new Uint8Array(u.length);
252
252
  for (let f = 0; f < u.length; f++)
253
253
  p[f] = u.charCodeAt(f);
254
- h = p;
255
- } else n.bodyType === "text" ? h = n.body : n.bodyType === "json" && (h = JSON.stringify(n.body));
256
- return new Response(h, c);
254
+ d = p;
255
+ } else n.bodyType === "text" ? d = n.body : n.bodyType === "json" && (d = JSON.stringify(n.body));
256
+ return new Response(d, c);
257
257
  }
258
258
  }
259
- class F {
259
+ class k {
260
260
  constructor(e) {
261
261
  this._client = e;
262
262
  }
@@ -412,7 +412,7 @@ class b {
412
412
  })).success;
413
413
  }
414
414
  }
415
- class k {
415
+ class $ {
416
416
  constructor(e) {
417
417
  this._client = e;
418
418
  }
@@ -435,7 +435,7 @@ class k {
435
435
  return e.user;
436
436
  }
437
437
  }
438
- class $ {
438
+ class x {
439
439
  constructor(e) {
440
440
  this._client = e;
441
441
  }
@@ -511,15 +511,15 @@ class $ {
511
511
  return t.forecast;
512
512
  }
513
513
  }
514
- function S(a) {
514
+ function v(a) {
515
515
  return { ...a, type: "client" };
516
516
  }
517
- const x = y.object({
517
+ const R = y.object({
518
518
  type: y.literal("bridge"),
519
519
  name: y.string(),
520
520
  data: y.any()
521
521
  });
522
- class R {
522
+ class j {
523
523
  /**
524
524
  * Creates a new RootSettingsNavigation API instance.
525
525
  *
@@ -576,8 +576,8 @@ class R {
576
576
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
577
577
  }
578
578
  }
579
- const _ = 1e3 * 30;
580
- class j {
579
+ const m = 1e3 * 30;
580
+ class D {
581
581
  /**
582
582
  * Creates a new Client instance for communicating with the TelemetryOS platform.
583
583
  *
@@ -617,7 +617,7 @@ class j {
617
617
  * @returns A Users instance bound to this client
618
618
  */
619
619
  get users() {
620
- return new k(this);
620
+ return new $(this);
621
621
  }
622
622
  /**
623
623
  * Provides access to the store API for data persistence with multiple storage scopes.
@@ -631,7 +631,7 @@ class j {
631
631
  * @returns A Store instance bound to this client
632
632
  */
633
633
  get store() {
634
- return new F(this);
634
+ return new k(this);
635
635
  }
636
636
  /**
637
637
  * Provides access to the applications API for discovering other TelemetryOS applications.
@@ -660,7 +660,7 @@ class j {
660
660
  * @returns A Media instance bound to this client
661
661
  */
662
662
  get media() {
663
- return new B(this);
663
+ return new T(this);
664
664
  }
665
665
  /**
666
666
  * Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
@@ -674,7 +674,7 @@ class j {
674
674
  * @returns A Proxy instance bound to this client
675
675
  */
676
676
  get proxy() {
677
- return new T(this);
677
+ return new F(this);
678
678
  }
679
679
  /**
680
680
  * Provides access to the devices API for interacting with the current device.
@@ -707,7 +707,7 @@ class j {
707
707
  * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
708
708
  */
709
709
  get rootSettingsNavigation() {
710
- return new R(this.store);
710
+ return new j(this.store);
711
711
  }
712
712
  /**
713
713
  * Provides access to the weather API for retrieving weather data.
@@ -721,7 +721,21 @@ class j {
721
721
  * @returns A Weather instance bound to this client
722
722
  */
723
723
  get weather() {
724
- return new $(this);
724
+ return new x(this);
725
+ }
726
+ /**
727
+ * Provides access to the environment API for accessing environment settings.
728
+ *
729
+ * This property returns a new Environment instance that allows applications to get
730
+ * and subscribe to environment settings such as the current color scheme.
731
+ *
732
+ * NOTE: Most application developers should use the global environment() function
733
+ * instead of accessing this property directly.
734
+ *
735
+ * @returns An Environment instance bound to this client
736
+ */
737
+ get environment() {
738
+ return new B(this);
725
739
  }
726
740
  get applicationName() {
727
741
  return this._applicationName;
@@ -771,13 +785,13 @@ class j {
771
785
  l = { ...c(n.data.data), type: "bridge" };
772
786
  }
773
787
  if (!l) {
774
- const c = x.safeParse(n.data);
788
+ const c = R.safeParse(n.data);
775
789
  if (!c.success)
776
790
  return;
777
791
  l = c.data;
778
- const h = this._onHandlers.get(l.name), u = this._onceHandlers.get(l.name);
779
- if (h)
780
- for (const p of h)
792
+ const d = this._onHandlers.get(l.name), u = this._onceHandlers.get(l.name);
793
+ if (d)
794
+ for (const p of d)
781
795
  p(l.data);
782
796
  if (u) {
783
797
  for (const p of u)
@@ -819,7 +833,7 @@ class j {
819
833
  * @param data The data payload to include with the message
820
834
  */
821
835
  send(e, t) {
822
- const s = S({
836
+ const s = v({
823
837
  telemetrySdkVersion: N,
824
838
  applicationName: this._applicationName,
825
839
  applicationSpecifier: this._applicationSpecifier,
@@ -847,7 +861,7 @@ class j {
847
861
  * @throws {Error} If the request times out
848
862
  */
849
863
  request(e, t) {
850
- const s = v(), o = S({
864
+ const s = S(), o = v({
851
865
  telemetrySdkVersion: N,
852
866
  applicationName: this._applicationName,
853
867
  applicationSpecifier: this._applicationSpecifier,
@@ -858,25 +872,25 @@ class j {
858
872
  });
859
873
  window.parent.postMessage(o, "*");
860
874
  let r = !1, n;
861
- const l = new Promise((h, u) => {
862
- const p = new Error(`${e} message request with response name of ${s} timed out after ${_}`);
875
+ const l = new Promise((d, u) => {
876
+ const p = new Error(`${e} message request with response name of ${s} timed out after ${m}`);
863
877
  setTimeout(() => {
864
878
  r = !0, this.off(s, n), u(p);
865
- }, _);
866
- }), c = new Promise((h) => {
879
+ }, m);
880
+ }), c = new Promise((d) => {
867
881
  n = (u) => {
868
- r || h(u);
869
- }, this.once(s, h);
882
+ r || d(u);
883
+ }, this.once(s, d);
870
884
  });
871
885
  return Promise.race([l, c]);
872
886
  }
873
887
  async subscribe(e, t, s) {
874
888
  let o, r;
875
889
  typeof t == "function" ? r = t : (o = t, r = s);
876
- const n = v(), l = v();
890
+ const n = S(), l = S();
877
891
  let c = this._subscriptionNamesBySubjectName.get(e);
878
892
  c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(n), this._subscriptionNamesByHandler.set(r, n), this.on(n, r);
879
- const h = S({
893
+ const d = v({
880
894
  telemetrySdkVersion: N,
881
895
  applicationName: this._applicationName,
882
896
  applicationSpecifier: this._applicationSpecifier,
@@ -886,13 +900,13 @@ class j {
886
900
  responseName: l,
887
901
  subscriptionName: n
888
902
  });
889
- window.parent.postMessage(h, "*");
903
+ window.parent.postMessage(d, "*");
890
904
  let u = !1, p;
891
905
  const f = new Promise((w, g) => {
892
- const m = new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${_}`);
906
+ const _ = new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${m}`);
893
907
  setTimeout(() => {
894
- u = !0, this.off(l, p), g(m);
895
- }, _);
908
+ u = !0, this.off(l, p), g(_);
909
+ }, m);
896
910
  }), I = new Promise((w) => {
897
911
  p = (g) => {
898
912
  u || w(g);
@@ -903,7 +917,7 @@ class j {
903
917
  async unsubscribe(e, t, s) {
904
918
  let o, r;
905
919
  typeof t == "function" ? r = t : (o = t, r = s);
906
- const n = v();
920
+ const n = S();
907
921
  let l = [];
908
922
  if (r) {
909
923
  const c = this._subscriptionNamesByHandler.get(r);
@@ -914,7 +928,7 @@ class j {
914
928
  return { success: !1 };
915
929
  for await (const c of l) {
916
930
  this.off(c, r);
917
- const h = S({
931
+ const d = v({
918
932
  telemetrySdkVersion: N,
919
933
  applicationInstance: this._applicationInstance,
920
934
  applicationName: this._applicationName,
@@ -924,16 +938,16 @@ class j {
924
938
  responseName: n,
925
939
  unsubscribeName: c
926
940
  });
927
- window.parent.postMessage(h, "*");
941
+ window.parent.postMessage(d, "*");
928
942
  let u = !1, p;
929
- const f = new Promise((g, m) => {
930
- const H = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${_}`);
943
+ const f = new Promise((g, _) => {
944
+ const H = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${m}`);
931
945
  setTimeout(() => {
932
- u = !0, this.off(n, p), m(H);
933
- }, _);
946
+ u = !0, this.off(n, p), _(H);
947
+ }, m);
934
948
  }), I = new Promise((g) => {
935
- p = (m) => {
936
- u || g(m);
949
+ p = (_) => {
950
+ u || g(_);
937
951
  }, this.once(n, g);
938
952
  });
939
953
  if (!(await Promise.race([f, I])).success)
@@ -1013,7 +1027,7 @@ class j {
1013
1027
  }
1014
1028
  }
1015
1029
  }
1016
- function v() {
1030
+ function S() {
1017
1031
  return Math.random().toString(36).slice(2, 9);
1018
1032
  }
1019
1033
  const N = E.version;
@@ -1022,79 +1036,83 @@ function U() {
1022
1036
  return i;
1023
1037
  }
1024
1038
  function V(a) {
1025
- i = new j(a), i.bind();
1039
+ i = new D(a), i.bind();
1026
1040
  }
1027
1041
  function z() {
1028
1042
  i == null || i.unbind(), i = null;
1029
1043
  }
1030
1044
  function G(...a) {
1031
- return d(i), i.on(...a);
1045
+ return h(i), i.on(...a);
1032
1046
  }
1033
1047
  function J(...a) {
1034
- return d(i), i.once(...a);
1048
+ return h(i), i.once(...a);
1035
1049
  }
1036
1050
  function K(...a) {
1037
- return d(i), i.off(...a);
1051
+ return h(i), i.off(...a);
1038
1052
  }
1039
1053
  function O(...a) {
1040
- return d(i), i.send(...a);
1054
+ return h(i), i.send(...a);
1041
1055
  }
1042
1056
  function W(...a) {
1043
- return d(i), i.request(...a);
1057
+ return h(i), i.request(...a);
1044
1058
  }
1045
1059
  function Q(...a) {
1046
- return d(i), i.subscribe(...a);
1060
+ return h(i), i.subscribe(...a);
1047
1061
  }
1048
1062
  function X(...a) {
1049
- return d(i), i.unsubscribe(...a);
1063
+ return h(i), i.unsubscribe(...a);
1050
1064
  }
1051
1065
  function Y() {
1052
- return d(i), i.store;
1066
+ return h(i), i.store;
1053
1067
  }
1054
1068
  function Z() {
1055
- return d(i), i.applications;
1069
+ return h(i), i.applications;
1056
1070
  }
1057
1071
  function ee() {
1058
- return d(i), i.media;
1072
+ return h(i), i.media;
1059
1073
  }
1060
1074
  function te() {
1061
- return d(i), i.accounts;
1075
+ return h(i), i.accounts;
1062
1076
  }
1063
1077
  function se() {
1064
- return d(i), i.users;
1078
+ return h(i), i.users;
1065
1079
  }
1066
1080
  function ne() {
1067
- return d(i), i.devices;
1081
+ return h(i), i.devices;
1068
1082
  }
1069
1083
  function ie() {
1070
- return d(i), i.proxy;
1084
+ return h(i), i.proxy;
1071
1085
  }
1072
1086
  function re() {
1073
- return d(i), i.rootSettingsNavigation;
1087
+ return h(i), i.rootSettingsNavigation;
1074
1088
  }
1075
1089
  function oe() {
1076
- return d(i), i.weather;
1090
+ return h(i), i.weather;
1091
+ }
1092
+ function ae() {
1093
+ return h(i), i.environment;
1077
1094
  }
1078
- function d(a) {
1095
+ function h(a) {
1079
1096
  if (!a)
1080
1097
  throw new Error("SDK is not configured");
1081
1098
  }
1082
1099
  export {
1083
1100
  M as Accounts,
1084
1101
  P as Applications,
1085
- j as Client,
1102
+ D as Client,
1086
1103
  C as Devices,
1087
- L as Environment,
1088
- B as Media,
1089
- T as Proxy,
1090
- F as Store,
1091
- k as Users,
1092
- $ as Weather,
1104
+ B as Environment,
1105
+ T as Media,
1106
+ F as Proxy,
1107
+ k as Store,
1108
+ $ as Users,
1109
+ x as Weather,
1093
1110
  te as accounts,
1094
1111
  Z as applications,
1095
1112
  V as configure,
1096
1113
  z as destroy,
1097
1114
  ne as devices,
1115
+ ae as environment,
1098
1116
  U as globalClient,
1099
1117
  ee as media,
1100
1118
  K as off,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.5.1",
3
+ "version": "1.6.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",