@telemetryos/root-sdk 1.5.1 → 1.7.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Introduce workers, and a vite plugin to build them. Introduce React components and hooks for app developers. Add a weather control panel to the dev host.
8
+
9
+ ## 1.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Add scripts for release process
14
+
15
+ Adds a few scripts to help make the release process for these packages
16
+ smoother. Fixes a few issues with undeployed changes from the last release.
17
+
18
+ ## 1.6.0
19
+
20
+ ### Minor Changes
21
+
22
+ - Fixes the init command, improvements
23
+ - Fixes an issue where the init command would fail
24
+ - Changes the location of the config file when you store an API token
25
+ - Improves CLAUDE.md for Claude Code integration
26
+ - Exports the environment API for the SDK
27
+
3
28
  ## 1.5.1
4
29
 
5
30
  ### Patch Changes
package/README.md CHANGED
@@ -336,11 +336,9 @@ Worker scripts run in the background continuously for root applications. On devi
336
336
  {
337
337
  "name": "my-application",
338
338
  "version": "1.0.0",
339
- "workers": [
340
- {
341
- "script": "./workers/background-sync.js"
342
- }
343
- ]
339
+ "backgroundWorkers": {
340
+ "background": "workers/background-sync.js"
341
+ }
344
342
  }
345
343
  ```
346
344
 
@@ -391,22 +389,18 @@ Your application must include a `telemetry.config.json` file at the root level:
391
389
  "name": "my-application",
392
390
  "version": "1.0.0",
393
391
  "displayName": "My Application",
394
- "description": "A TelemetryOS application that does amazing things",
392
+ "description": "A TelemetryOS root application",
395
393
  "mountPoints": {
396
- "render": {
397
- "path": "/render"
398
- },
399
- "settings": {
400
- "path": "/settings"
401
- }
394
+ "rootRender": "/root-render",
395
+ "rootSettings": "/root-settings"
402
396
  },
403
- "workers": [
404
- {
405
- "name": "background",
406
- "script": "./workers/background.js"
407
- }
408
- ],
409
- "containers": []
397
+ "backgroundWorkers": {
398
+ "background": "workers/background.js"
399
+ },
400
+ "devServer": {
401
+ "runCommand": "vite --port 3000",
402
+ "url": "http://localhost:3000"
403
+ }
410
404
  }
411
405
  ```
412
406
 
@@ -61,7 +61,7 @@ export declare class Applications {
61
61
  * // result.unavailable: ['app2-hash'] - these failed to load
62
62
  * ```
63
63
  */
64
- setDependencies(applicationSpecifiers: string[]): Promise<ApplicationsState>;
64
+ setDependencies(applicationSpecifiers: Record<string, string[]>): Promise<ApplicationsState>;
65
65
  /**
66
66
  * Registers a message interceptor for client messages from sub-applications.
67
67
  *
package/dist/bridge.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");function r(n){return{...n,type:"bridge"}}const o=e.z.object({type:e.z.literal("client"),telemetrySdkVersion:e.z.string(),applicationName:e.z.string(),applicationSpecifier:e.z.string(),applicationInstance:e.z.string(),name:e.z.string(),data:e.z.any(),responseName:e.z.string().optional(),subscriptionName:e.z.string().optional(),unsubscribeName:e.z.string().optional()});class d{bind(){this._windowMessageHandler=i=>{var s;if(i.source===window)return;const t=o.safeParse(i.data);if(!t.success)return;const a=t.data;(s=this.onMessage)===null||s===void 0||s.call(this,a)},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(i){for(let s=0;s<window.frames.length;s+=1)window.frames[s].postMessage(r(i),"*")}}exports.Bridge=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./types-mYnxD5LM.cjs");function r(n){return{...n,type:"bridge"}}const o=e.objectType({type:e.literalType("client"),telemetrySdkVersion:e.stringType(),applicationName:e.stringType(),applicationSpecifier:e.stringType(),applicationInstance:e.stringType(),name:e.stringType(),data:e.anyType(),responseName:e.stringType().optional(),subscriptionName:e.stringType().optional(),unsubscribeName:e.stringType().optional()});class d{bind(){this._windowMessageHandler=i=>{var s;if(i.source===window)return;const t=o.safeParse(i.data);if(!t.success)return;const a=t.data;(s=this.onMessage)===null||s===void 0||s.call(this,a)},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(i){for(let s=0;s<window.frames.length;s+=1)window.frames[s].postMessage(r(i),"*")}}exports.Bridge=d;
package/dist/bridge.js CHANGED
@@ -1,34 +1,34 @@
1
- import { z as e } from "./index-B98VDFRY.js";
2
- function r(n) {
3
- return { ...n, type: "bridge" };
1
+ import { o, s as e, a as r, l as d } from "./types-CCzf8sMT.js";
2
+ function l(i) {
3
+ return { ...i, type: "bridge" };
4
4
  }
5
- const o = e.object({
6
- type: e.literal("client"),
7
- telemetrySdkVersion: e.string(),
8
- applicationName: e.string(),
9
- applicationSpecifier: e.string(),
10
- applicationInstance: e.string(),
11
- name: e.string(),
12
- data: e.any(),
13
- responseName: e.string().optional(),
14
- subscriptionName: e.string().optional(),
15
- unsubscribeName: e.string().optional()
5
+ const p = o({
6
+ type: d("client"),
7
+ telemetrySdkVersion: e(),
8
+ applicationName: e(),
9
+ applicationSpecifier: e(),
10
+ applicationInstance: e(),
11
+ name: e(),
12
+ data: r(),
13
+ responseName: e().optional(),
14
+ subscriptionName: e().optional(),
15
+ unsubscribeName: e().optional()
16
16
  });
17
- class l {
17
+ class w {
18
18
  /**
19
19
  * Binds the Bridge to the window message event. This will allow the Bridge
20
20
  * to listen for messages from the host application.
21
21
  */
22
22
  bind() {
23
- this._windowMessageHandler = (i) => {
23
+ this._windowMessageHandler = (a) => {
24
24
  var s;
25
- if (i.source === window)
25
+ if (a.source === window)
26
26
  return;
27
- const t = o.safeParse(i.data);
28
- if (!t.success)
27
+ const n = p.safeParse(a.data);
28
+ if (!n.success)
29
29
  return;
30
- const a = t.data;
31
- (s = this.onMessage) === null || s === void 0 || s.call(this, a);
30
+ const t = n.data;
31
+ (s = this.onMessage) === null || s === void 0 || s.call(this, t);
32
32
  }, window.addEventListener("message", this._windowMessageHandler);
33
33
  }
34
34
  /**
@@ -42,11 +42,11 @@ class l {
42
42
  * Sends a message to SDK clients.
43
43
  * @param message The message to send.
44
44
  */
45
- send(i) {
45
+ send(a) {
46
46
  for (let s = 0; s < window.frames.length; s += 1)
47
- window.frames[s].postMessage(r(i), "*");
47
+ window.frames[s].postMessage(l(a), "*");
48
48
  }
49
49
  }
50
50
  export {
51
- l as Bridge
51
+ w as Bridge
52
52
  };
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,10 +1,9 @@
1
- import { Client } from './index.js';
2
- type ColorScheme = 'light' | 'dark' | 'system';
1
+ import { Client, MessageHandler } from './client.js';
2
+ export type ColorScheme = 'light' | 'dark' | 'system';
3
3
  export declare class Environment {
4
4
  _client: Client;
5
5
  constructor(client: Client);
6
6
  getColorScheme(): Promise<ColorScheme>;
7
- subscribeColorScheme(handler: (colorScheme: ColorScheme) => void): void;
8
- unsubscribeColorScheme(handler: (colorScheme: ColorScheme) => void): void;
7
+ subscribeColorScheme(handler: MessageHandler<ColorScheme>): Promise<boolean>;
8
+ unsubscribeColorScheme(handler?: MessageHandler<ColorScheme>): Promise<boolean>;
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 N=require("./types-mYnxD5LM.cjs"),j="1.7.0",D={version:j};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 T{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class C{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 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 k{constructor(e){this._client=e}get application(){return new y("application","",this._client)}get instance(){return new y("instance",this._client.applicationInstance,this._client)}get device(){return new y("device",this._client.applicationInstance,this._client)}shared(e){return new y("shared",e,this._client)}}class y{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 F{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}}function I(a){return{...a,type:"client"}}const U=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"),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,E=typeof window>"u"&&typeof self<"u",b=E?self:window;function w(a){E?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 F(this)}get store(){return new k(this)}get applications(){return new M(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new T(this)}get rootSettingsNavigation(){return new L(this.store)}get weather(){return new $(this)}get environment(){return new C(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),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===b||!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){w(n.data);return}l={...c(n.data.data),type:"bridge"}}if(!l){const c=U.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)}}if(!E)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});w(s)}request(e,t){const s=H(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});w(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=H(),l=H();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=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:n});w(d);let u=!1,p;const f=new Promise((S,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)}),q=new Promise(S=>{p=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,q])}async unsubscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=H();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=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:n,unsubscribeName:c});w(d);let u=!1,p;const f=new Promise((g,_)=>{const R=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),_(R)},m)}),q=new Promise(g=>{p=_=>{u||g(_)},this.once(n,g)});if(!(await Promise.race([f,q])).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 H(){return Math.random().toString(36).slice(2,9)}const v=D.version;let i=null;function V(){return i}function W(a){i=new x(a),i.bind()}function O(){i==null||i.unbind(),i=null}function G(...a){return h(i),i.on(...a)}function J(...a){return h(i),i.once(...a)}function K(...a){return h(i),i.off(...a)}function z(...a){return h(i),i.send(...a)}function Q(...a){return h(i),i.request(...a)}function X(...a){return h(i),i.subscribe(...a)}function Y(...a){return h(i),i.unsubscribe(...a)}function Z(){return h(i),i.store}function ee(){return h(i),i.applications}function te(){return h(i),i.media}function se(){return h(i),i.accounts}function ne(){return h(i),i.users}function ie(){return h(i),i.devices}function re(){return h(i),i.proxy}function oe(){return h(i),i.rootSettingsNavigation}function ae(){return h(i),i.weather}function ce(){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.Devices=T;exports.Environment=C;exports.Media=A;exports.Proxy=B;exports.Store=k;exports.StoreSlice=y;exports.Users=F;exports.Weather=$;exports.accounts=se;exports.applications=ee;exports.configure=W;exports.destroy=O;exports.devices=ie;exports.environment=ce;exports.globalClient=V;exports.media=te;exports.off=K;exports.on=G;exports.once=J;exports.proxy=re;exports.request=Q;exports.rootSettingsNavigation=oe;exports.send=z;exports.store=Z;exports.subscribe=X;exports.telemetrySdkVersion=v;exports.unsubscribe=Y;exports.users=ne;exports.weather=ae;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
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
- export { Store } from './store.js';
7
+ export { Store, StoreSlice } from './store.js';
8
8
  export { Users } from './users.js';
9
9
  export { Weather } from './weather.js';
10
10
  export type { WeatherConditions, WeatherForecast, WeatherRequestParams, DailyForecastParams, HourlyForecastParams, } from './weather.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;