@telemetryos/root-sdk 1.4.3 → 1.5.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,21 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add message interceptors for root applications.
8
+
9
+ This allows root applications to listen for messages from their descendant
10
+ applications, and implement custom functionality those applications
11
+ can use, or allow for interop.
12
+
13
+ ## 1.4.4
14
+
15
+ ### Patch Changes
16
+
17
+ - Correctly pass on messages from deeply nested applications up to the parent page and in the reverse
18
+
3
19
  ## 1.4.3
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -182,6 +182,35 @@ iframe.src = url;
182
182
  document.body.appendChild(iframe);
183
183
  ```
184
184
 
185
+ ### Message Interceptors
186
+
187
+ Root applications can intercept messages from embedded sub-applications using message interceptors. This allows you to handle client messages before they bubble up to the parent window, enabling custom communication patterns:
188
+
189
+ ```javascript
190
+ import { applications } from '@telemetryos/root-sdk';
191
+
192
+ // Register an interceptor to provide color scheme to sub-applications
193
+ applications().bind('theme.getColorScheme', (data) => {
194
+ // Get the current color scheme from settings or state
195
+ const colors = getCurrentColorScheme();
196
+
197
+ // Return a bridge message that will be sent to handlers and child frames
198
+ return {
199
+ name: 'theme.colorScheme',
200
+ data: { primary: colors.primary, secondary: colors.secondary }
201
+ };
202
+ });
203
+
204
+ // The interceptor transforms client messages into bridge messages
205
+ // that are handled locally and forwarded to child applications
206
+ ```
207
+
208
+ Interceptors are useful for:
209
+ - **Theme Coordination** - Provide consistent color schemes and styling across embedded applications
210
+ - **State Synchronization** - Coordinate state changes across multiple embedded applications
211
+ - **Custom Routing** - Implement application-specific message routing logic
212
+ - **Data Transformation** - Normalize or transform message data before distribution
213
+
185
214
  ### Media Access
186
215
 
187
216
  Access media content uploaded to TelemetryOS:
@@ -1,4 +1,4 @@
1
- import { Client } from './client.js';
1
+ import { Client, MessageInterceptor } from './client.js';
2
2
  export type MountPoint = {
3
3
  [key: string]: any;
4
4
  path: string;
@@ -10,7 +10,7 @@ export type Application = {
10
10
  export type GetUrlResult = {
11
11
  url: string;
12
12
  };
13
- export type SetDependenciesResult = {
13
+ export type ApplicationsState = {
14
14
  ready: string[];
15
15
  unavailable: string[];
16
16
  };
@@ -61,5 +61,36 @@ export declare class Applications {
61
61
  * // result.unavailable: ['app2-hash'] - these failed to load
62
62
  * ```
63
63
  */
64
- setDependencies(applicationSpecifiers: string[]): Promise<SetDependenciesResult>;
64
+ setDependencies(applicationSpecifiers: string[]): Promise<ApplicationsState>;
65
+ /**
66
+ * Registers a message interceptor for client messages from sub-applications.
67
+ *
68
+ * Interceptors allow a root application to handle messages from embedded child applications
69
+ * before they bubble up to the parent window. When an interceptor is registered, client messages
70
+ * with the specified name will be transformed into bridge messages that are handled locally
71
+ * and forwarded to child frames.
72
+ *
73
+ * This is useful for implementing custom communication patterns between root applications
74
+ * and their embedded sub-applications, such as coordinating theme changes, state
75
+ * synchronization, or custom routing logic.
76
+ *
77
+ * @param name The message name to intercept
78
+ * @param interceptor A function that receives the message data and returns a BridgeMessage
79
+ * @throws Error if an interceptor is already bound for the specified message name
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * import { applications } from '@telemetryos/root-sdk'
84
+ *
85
+ * // Intercept color scheme requests from sub-applications
86
+ * applications().bind('theme.getColorScheme', (data) => {
87
+ * const colors = getCurrentColorScheme()
88
+ * return {
89
+ * name: 'theme.colorScheme',
90
+ * data: { primary: colors.primary, secondary: colors.secondary }
91
+ * }
92
+ * })
93
+ * ```
94
+ */
95
+ bind(name: string, interceptor: MessageInterceptor): void;
65
96
  }
@@ -1,7 +1,5 @@
1
1
  import { z } from 'zod';
2
2
  import { bridgeMessageValidator } from './bridge-message-validator.js';
3
- export type Message = z.infer<typeof bridgeMessageValidator>;
4
- export declare function formatBridgeMessage(data: Message): {
5
- name: string;
6
- data?: any;
7
- };
3
+ type Message = z.infer<typeof bridgeMessageValidator>;
4
+ export declare function formatBridgeMessage(data: Omit<Message, 'type'>): Message;
5
+ export {};
@@ -1,11 +1,14 @@
1
1
  import { z } from 'zod';
2
2
  export declare const bridgeMessageValidator: z.ZodObject<{
3
+ type: z.ZodLiteral<"bridge">;
3
4
  name: z.ZodString;
4
5
  data: z.ZodAny;
5
6
  }, "strip", z.ZodTypeAny, {
7
+ type: "bridge";
6
8
  name: string;
7
9
  data?: any;
8
10
  }, {
11
+ type: "bridge";
9
12
  name: string;
10
13
  data?: any;
11
14
  }>;
package/dist/bridge.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");const a=e.z.object({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 r{bind(){this._windowMessageHandler=i=>{var s;if(i.source===window)return;const n=a.safeParse(i.data);if(!n.success)return;const t=n.data;(s=this.onMessage)===null||s===void 0||s.call(this,t)},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(i,"*")}}exports.Bridge=r;
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;
package/dist/bridge.d.ts CHANGED
@@ -5,12 +5,12 @@ import { bridgeMessageValidator } from './bridge-message-validator.js';
5
5
  * Defines the structure of a client message as defined in the
6
6
  * clientMessageValidator.
7
7
  */
8
- export type ClientMessage = z.infer<typeof clientMessageValidator>;
8
+ export type ClientMessage = Omit<z.infer<typeof clientMessageValidator>, 'type'>;
9
9
  /**
10
10
  * Defines the structure of a bridge message as defined in the
11
11
  * bridgeMessageValidator.
12
12
  */
13
- export type BridgeMessage = z.infer<typeof bridgeMessageValidator>;
13
+ export type BridgeMessage = Omit<z.infer<typeof bridgeMessageValidator>, 'type'>;
14
14
  /**
15
15
  * The Bridge class is provides a way for host applications to communicate with
16
16
  * TelemetryOS applications. It listens for window message events and sends
package/dist/bridge.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { z as e } from "./index-B98VDFRY.js";
2
- const t = e.object({
2
+ function r(n) {
3
+ return { ...n, type: "bridge" };
4
+ }
5
+ const o = e.object({
6
+ type: e.literal("client"),
3
7
  telemetrySdkVersion: e.string(),
4
8
  applicationName: e.string(),
5
9
  applicationSpecifier: e.string(),
@@ -10,20 +14,20 @@ const t = e.object({
10
14
  subscriptionName: e.string().optional(),
11
15
  unsubscribeName: e.string().optional()
12
16
  });
13
- class d {
17
+ class l {
14
18
  /**
15
19
  * Binds the Bridge to the window message event. This will allow the Bridge
16
20
  * to listen for messages from the host application.
17
21
  */
18
22
  bind() {
19
- this._windowMessageHandler = (n) => {
23
+ this._windowMessageHandler = (i) => {
20
24
  var s;
21
- if (n.source === window)
25
+ if (i.source === window)
22
26
  return;
23
- const i = t.safeParse(n.data);
24
- if (!i.success)
27
+ const t = o.safeParse(i.data);
28
+ if (!t.success)
25
29
  return;
26
- const a = i.data;
30
+ const a = t.data;
27
31
  (s = this.onMessage) === null || s === void 0 || s.call(this, a);
28
32
  }, window.addEventListener("message", this._windowMessageHandler);
29
33
  }
@@ -38,11 +42,11 @@ class d {
38
42
  * Sends a message to SDK clients.
39
43
  * @param message The message to send.
40
44
  */
41
- send(n) {
45
+ send(i) {
42
46
  for (let s = 0; s < window.frames.length; s += 1)
43
- window.frames[s].postMessage(n, "*");
47
+ window.frames[s].postMessage(r(i), "*");
44
48
  }
45
49
  }
46
50
  export {
47
- d as Bridge
51
+ l as Bridge
48
52
  };
@@ -1,14 +1,5 @@
1
1
  import { z } from 'zod';
2
2
  import { clientMessageValidator } from './client-message-validator.js';
3
- export type Message = z.infer<typeof clientMessageValidator>;
4
- export declare function formatClientMessage(data: Message): {
5
- telemetrySdkVersion: string;
6
- applicationName: string;
7
- applicationSpecifier: string;
8
- applicationInstance: string;
9
- name: string;
10
- data?: any;
11
- responseName?: string | undefined;
12
- subscriptionName?: string | undefined;
13
- unsubscribeName?: string | undefined;
14
- };
3
+ type Message = z.infer<typeof clientMessageValidator>;
4
+ export declare function formatClientMessage(data: Omit<Message, 'type'>): Message;
5
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const clientMessageValidator: z.ZodObject<{
3
+ type: z.ZodLiteral<"client">;
3
4
  telemetrySdkVersion: z.ZodString;
4
5
  applicationName: z.ZodString;
5
6
  applicationSpecifier: z.ZodString;
@@ -10,6 +11,7 @@ export declare const clientMessageValidator: z.ZodObject<{
10
11
  subscriptionName: z.ZodOptional<z.ZodString>;
11
12
  unsubscribeName: z.ZodOptional<z.ZodString>;
12
13
  }, "strip", z.ZodTypeAny, {
14
+ type: "client";
13
15
  telemetrySdkVersion: string;
14
16
  applicationName: string;
15
17
  applicationSpecifier: string;
@@ -20,6 +22,7 @@ export declare const clientMessageValidator: z.ZodObject<{
20
22
  subscriptionName?: string | undefined;
21
23
  unsubscribeName?: string | undefined;
22
24
  }, {
25
+ type: "client";
23
26
  telemetrySdkVersion: string;
24
27
  applicationName: string;
25
28
  applicationSpecifier: string;
package/dist/client.d.ts CHANGED
@@ -5,8 +5,9 @@ import { RootSettingsNavigation } from './root-settings-navigation.js';
5
5
  import { Accounts } from './accounts.js';
6
6
  import { Users } from './users.js';
7
7
  import { Proxy } from './proxy.js';
8
- import { Devices } from './device.js';
8
+ import { Devices } from './devices.js';
9
9
  import { Weather } from './weather.js';
10
+ import { BridgeMessage } from './bridge.js';
10
11
  /**
11
12
  * The maximum time in milliseconds to wait for a response to a request call.
12
13
  *
@@ -33,6 +34,30 @@ export type SubscriptionResult<D = void> = {
33
34
  success: boolean;
34
35
  data: D;
35
36
  };
37
+ /**
38
+ * A function that intercepts client messages from sub-applications and transforms them
39
+ * into bridge messages.
40
+ *
41
+ * Message interceptors are registered using applications().bind() and allow root applications
42
+ * to handle messages from embedded child applications before they bubble up to the parent window.
43
+ * The interceptor receives the message data payload and must return a BridgeMessage object
44
+ * containing a name and data that will be forwarded to message handlers and child frames.
45
+ *
46
+ * @param data The data payload from the intercepted client message
47
+ * @returns A BridgeMessage object with name and data properties
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const interceptor: MessageInterceptor = (data) => {
52
+ * const colors = getCurrentColorScheme()
53
+ * return {
54
+ * name: 'theme.colorScheme',
55
+ * data: { primary: colors.primary, secondary: colors.secondary }
56
+ * }
57
+ * }
58
+ * ```
59
+ */
60
+ export type MessageInterceptor = (data: any) => BridgeMessage;
36
61
  /**
37
62
  * Client is the core class that powers communication with the TelemetryOS platform.
38
63
  *
@@ -50,6 +75,7 @@ export declare class Client {
50
75
  _applicationName: string;
51
76
  _applicationInstance: string;
52
77
  _applicationSpecifier: string;
78
+ _messageInterceptors: Map<string, MessageInterceptor>;
53
79
  _onHandlers: Map<string, MessageHandler<any>[]>;
54
80
  _onceHandlers: Map<string, MessageHandler<any>[]>;
55
81
  _subscriptionNamesByHandler: Map<MessageHandler<any>, string>;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./index-JDXm3DEz.cjs"),k="1.4.3",F={version:k};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})}}class I{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 T(o,e=console.error){o().catch(e)}class ${constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}subscribeColorScheme(e){T(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 E{constructor(e){this._client=e}get application(){return new y("application","",this._client)}get instance(){return new y("instance",this._client.applicationSpecifier,this._client)}get device(){return new y("device",this._client.applicationSpecifier,this._client)}shared(e){return new y("shared",e,this._client)}}class y{constructor(e,t,n){this._kind=e,this._namespace=t,this._client=n}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 M{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 A{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}}const x=N.z.object({name:N.z.string(),data:N.z.any()});class R{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){const t=this._store.shared("root-settings-navigation"),n=await t.get("navigation"),r=this._store._client._applicationSpecifier;n[r]={applicationSpecifier:r,entries:e.entries},t.set("navigation",n)}async getRootSettingsNavigation(){const t=await this._store.shared("root-settings-navigation").get("navigation"),n=this._store._client._applicationSpecifier;return t[n]}async getAllRootSettingsNavigation(){return this._store.shared("root-settings-navigation").get("navigation")}}class j{constructor(e){this._client=e}async fetch(e,t){let n;typeof e=="string"?n=e:e instanceof URL?n=e.toString():(n=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,c)=>{r[c]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,c])=>{r[h]=c}):r=t.headers);const s=await this._client.request("proxy.fetch",{url:n,method:(t==null?void 0:t.method)||"GET",headers:r,body:(t==null?void 0:t.body)||null});if(!s.success)throw new Error(`Proxy fetch failed: ${s.statusText}`);const l=new Headers(s.headers),u={status:s.status,statusText:s.statusText,headers:l};let a=null;return s.body!==null&&s.body!==void 0&&(typeof s.body=="string"||s.body instanceof ArrayBuffer?a=s.body:typeof s.body=="object"&&(a=JSON.stringify(s.body))),new Response(a,u)}}const g=1e3*30;class B{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",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 M(this)}get store(){return new E(this)}get applications(){return new q(this)}get media(){return new P(this)}get proxy(){return new j(this)}get devices(){return new I(this)}get rootSettingsNavigation(){return new R(this.store)}get weather(){return new A(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e;const t=new URL(window.location.href),n=t.searchParams;this._applicationInstance=(e=n.get("telemetryApplicationId"))!==null&&e!==void 0?e:"";const r=n.get("applicationSpecifier");if(r)this._applicationSpecifier=r;else{const s=t.hostname.split(".");this._applicationSpecifier=s[0]||""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);if(!this._applicationInstance)throw new Error("Missing telemetryApplicationId query parameter");this._windowMessageHandler=s=>{if(s.source===window)return;for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(s.data,"*");const l=x.safeParse(s.data);if(!l.success)return;const u=l.data,a=this._onHandlers.get(u.name),h=this._onceHandlers.get(u.name);if(a)for(const c of a)c(u.data);if(h){for(const c of h)c(u.data);this._onceHandlers.delete(u.name)}},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const n={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t};window.parent.postMessage(n,"*")}request(e,t){const n=b(),r={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n};window.parent.postMessage(r,"*");let s=!1,l;const u=new Promise((h,c)=>{const d=new Error(`${e} message request with response name of ${n} timed out after ${g}`);setTimeout(()=>{s=!0,this.off(n,l),c(d)},g)}),a=new Promise(h=>{l=c=>{s||h(c)},this.once(n,h)});return Promise.race([u,a])}async subscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=b(),u=b();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(l),this._subscriptionNamesByHandler.set(s,l),this.on(l,s);const h={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:r,responseName:u,subscriptionName:l};window.parent.postMessage(h,"*");let c=!1,d;const S=new Promise((w,f)=>{const m=new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(u,d),f(m)},g)}),v=new Promise(w=>{d=f=>{c||w(f)},this.on(u,w)});return Promise.race([S,v])}async unsubscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=b();let u=[];if(s){const a=this._subscriptionNamesByHandler.get(s);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(s)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,s);const h={telemetrySdkVersion:_,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:r,responseName:l,unsubscribeName:a};window.parent.postMessage(h,"*");let c=!1,d;const S=new Promise((f,m)=>{const C=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(l,d),m(C)},g)}),v=new Promise(f=>{d=m=>{c||f(m)},this.once(l,f)});if(!(await Promise.race([S,v])).success)return{success:!1}}return{success:!0}}on(e,t){var n;const r=(n=this._onHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var n;const r=(n=this._onceHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const n=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!n&&!r)){if(n){for(let s=0;s<n.length;s+=1)t&&n[s]!==t||(n.splice(s,1),s-=1);n.length===0&&this._onHandlers.delete(e)}if(r){for(let s=0;s<r.length;s+=1)t&&r[s]!==t||(r.splice(s,1),s-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function b(){return Math.random().toString(36).slice(2,9)}const _=F.version;let i=null;function D(){return i}function L(o){i=new B(o),i.bind()}function U(){i==null||i.unbind(),i=null}function z(...o){return p(i),i.on(...o)}function V(...o){return p(i),i.once(...o)}function O(...o){return p(i),i.off(...o)}function W(...o){return p(i),i.send(...o)}function G(...o){return p(i),i.request(...o)}function J(...o){return p(i),i.subscribe(...o)}function K(...o){return p(i),i.unsubscribe(...o)}function Q(){return p(i),i.store}function X(){return p(i),i.applications}function Y(){return p(i),i.media}function Z(){return p(i),i.accounts}function ee(){return p(i),i.users}function te(){return p(i),i.devices}function se(){return p(i),i.proxy}function ne(){return p(i),i.rootSettingsNavigation}function ie(){return p(i),i.weather}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=H;exports.Applications=q;exports.Client=B;exports.Devices=I;exports.Environment=$;exports.Media=P;exports.Store=E;exports.Users=M;exports.Weather=A;exports.accounts=Z;exports.applications=X;exports.configure=L;exports.destroy=U;exports.devices=te;exports.globalClient=D;exports.media=Y;exports.off=O;exports.on=z;exports.once=V;exports.proxy=se;exports.request=G;exports.rootSettingsNavigation=ne;exports.send=W;exports.store=Q;exports.subscribe=J;exports.telemetrySdkVersion=_;exports.unsubscribe=K;exports.users=ee;exports.weather=ie;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./index-JDXm3DEz.cjs"),F="1.5.0",$={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;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export { Accounts } from './accounts.js';
2
2
  export { Applications } from './applications.js';
3
- export { Devices } from './device.js';
3
+ export { Devices } from './devices.js';
4
4
  export { Environment } from './environment.js';
5
5
  export { Media } from './media.js';
6
+ export { Proxy } from './proxy.js';
6
7
  export { Store } from './store.js';
7
8
  export { Users } from './users.js';
8
9
  export { Weather } from './weather.js';
@@ -219,7 +220,7 @@ export declare function users(): import("./users.js").Users;
219
220
  * @returns The Devices API object
220
221
  * @throws {Error} If called before configure() or after destroy()
221
222
  */
222
- export declare function devices(): import("./device.js").Devices;
223
+ export declare function devices(): import("./devices.js").Devices;
223
224
  /**
224
225
  * Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
225
226
  *
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { z as N } from "./index-B98VDFRY.js";
2
- const q = "1.4.3", I = {
1
+ import { z as y } from "./index-B98VDFRY.js";
2
+ const q = "1.5.0", E = {
3
3
  version: q
4
4
  };
5
- class P {
5
+ class M {
6
6
  constructor(e) {
7
7
  this._client = e;
8
8
  }
@@ -21,7 +21,7 @@ class P {
21
21
  return e.account;
22
22
  }
23
23
  }
24
- class E {
24
+ class P {
25
25
  constructor(e) {
26
26
  this._client = e;
27
27
  }
@@ -82,8 +82,43 @@ class E {
82
82
  applicationSpecifiers: e
83
83
  });
84
84
  }
85
+ /**
86
+ * Registers a message interceptor for client messages from sub-applications.
87
+ *
88
+ * Interceptors allow a root application to handle messages from embedded child applications
89
+ * before they bubble up to the parent window. When an interceptor is registered, client messages
90
+ * with the specified name will be transformed into bridge messages that are handled locally
91
+ * and forwarded to child frames.
92
+ *
93
+ * This is useful for implementing custom communication patterns between root applications
94
+ * and their embedded sub-applications, such as coordinating theme changes, state
95
+ * synchronization, or custom routing logic.
96
+ *
97
+ * @param name The message name to intercept
98
+ * @param interceptor A function that receives the message data and returns a BridgeMessage
99
+ * @throws Error if an interceptor is already bound for the specified message name
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import { applications } from '@telemetryos/root-sdk'
104
+ *
105
+ * // Intercept color scheme requests from sub-applications
106
+ * applications().bind('theme.getColorScheme', (data) => {
107
+ * const colors = getCurrentColorScheme()
108
+ * return {
109
+ * name: 'theme.colorScheme',
110
+ * data: { primary: colors.primary, secondary: colors.secondary }
111
+ * }
112
+ * })
113
+ * ```
114
+ */
115
+ bind(e, t) {
116
+ if (this._client._messageInterceptors.has(e))
117
+ throw new Error(`Interceptor already bound for message ${e}`);
118
+ this._client._messageInterceptors.set(e, t);
119
+ }
85
120
  }
86
- class M {
121
+ class C {
87
122
  constructor(e) {
88
123
  this._client = e;
89
124
  }
@@ -107,10 +142,10 @@ class M {
107
142
  return e.deviceInformation;
108
143
  }
109
144
  }
110
- function A(o, e = console.error) {
111
- o().catch(e);
145
+ function A(a, e = console.error) {
146
+ a().catch(e);
112
147
  }
113
- class D {
148
+ class L {
114
149
  constructor(e) {
115
150
  this._client = e;
116
151
  }
@@ -172,7 +207,56 @@ class B {
172
207
  })).content;
173
208
  }
174
209
  }
175
- class C {
210
+ class T {
211
+ constructor(e) {
212
+ this._client = e;
213
+ }
214
+ async fetch(e, t) {
215
+ var s;
216
+ let o;
217
+ typeof e == "string" ? o = e : e instanceof URL ? o = e.toString() : (o = e.url, t || (t = {
218
+ method: e.method,
219
+ headers: e.headers,
220
+ body: e.body,
221
+ credentials: e.credentials,
222
+ cache: e.cache,
223
+ redirect: e.redirect,
224
+ referrer: e.referrer,
225
+ integrity: e.integrity
226
+ }));
227
+ let r = {};
228
+ t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((u, p) => {
229
+ r[p] = u;
230
+ }) : Array.isArray(t.headers) ? t.headers.forEach(([u, p]) => {
231
+ r[u] = p;
232
+ }) : r = t.headers);
233
+ const n = await this._client.request("proxy.fetch", {
234
+ url: o,
235
+ method: (t == null ? void 0 : t.method) || "GET",
236
+ headers: r,
237
+ body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
238
+ });
239
+ if (!n.success)
240
+ throw new TypeError(n.errorMessage, {
241
+ cause: n.errorCause ? Error(n.errorCause) : void 0
242
+ });
243
+ const l = new Headers(n.headers), c = {
244
+ status: n.status,
245
+ statusText: n.statusText,
246
+ headers: l
247
+ };
248
+ let h = null;
249
+ if (n.body !== null && n.body !== void 0)
250
+ if (n.bodyType === "binary") {
251
+ const u = atob(n.body), p = new Uint8Array(u.length);
252
+ for (let f = 0; f < u.length; f++)
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);
257
+ }
258
+ }
259
+ class F {
176
260
  constructor(e) {
177
261
  this._client = e;
178
262
  }
@@ -186,7 +270,7 @@ class C {
186
270
  * @returns A StoreSlice instance for the application scope
187
271
  */
188
272
  get application() {
189
- return new w("application", "", this._client);
273
+ return new b("application", "", this._client);
190
274
  }
191
275
  /**
192
276
  * Provides access to the instance store scope.
@@ -200,7 +284,7 @@ class C {
200
284
  * @returns A StoreSlice instance for the instance scope
201
285
  */
202
286
  get instance() {
203
- return new w("instance", this._client.applicationSpecifier, this._client);
287
+ return new b("instance", this._client.applicationInstance, this._client);
204
288
  }
205
289
  /**
206
290
  * Provides access to the device store scope.
@@ -215,7 +299,7 @@ class C {
215
299
  * @returns A StoreSlice instance for the device scope
216
300
  */
217
301
  get device() {
218
- return new w("device", this._client.applicationSpecifier, this._client);
302
+ return new b("device", this._client.applicationInstance, this._client);
219
303
  }
220
304
  /**
221
305
  * Provides access to the shared store scope with a specified namespace.
@@ -231,12 +315,12 @@ class C {
231
315
  * @returns A StoreSlice instance for the specified shared namespace
232
316
  */
233
317
  shared(e) {
234
- return new w("shared", e, this._client);
318
+ return new b("shared", e, this._client);
235
319
  }
236
320
  }
237
- class w {
238
- constructor(e, t, n) {
239
- this._kind = e, this._namespace = t, this._client = n;
321
+ class b {
322
+ constructor(e, t, s) {
323
+ this._kind = e, this._namespace = t, this._client = s;
240
324
  }
241
325
  /**
242
326
  * Saves a value in the store.
@@ -302,7 +386,7 @@ class w {
302
386
  *
303
387
  * @param key The key to unsubscribe from
304
388
  * @param handler Optional. The specific handler to remove. If not provided, all handlers for this key will be removed.
305
- * @returns A promise that resolves to true if the unsubscription was successful
389
+ * @returns A promise that resolves to true if the unsubscribe was successful
306
390
  */
307
391
  async unsubscribe(e, t) {
308
392
  return (await this._client.unsubscribe("store.unsubscribe", {
@@ -328,7 +412,7 @@ class w {
328
412
  })).success;
329
413
  }
330
414
  }
331
- class F {
415
+ class k {
332
416
  constructor(e) {
333
417
  this._client = e;
334
418
  }
@@ -351,7 +435,7 @@ class F {
351
435
  return e.user;
352
436
  }
353
437
  }
354
- class k {
438
+ class $ {
355
439
  constructor(e) {
356
440
  this._client = e;
357
441
  }
@@ -427,11 +511,15 @@ class k {
427
511
  return t.forecast;
428
512
  }
429
513
  }
430
- const T = N.object({
431
- name: N.string(),
432
- data: N.any()
514
+ function S(a) {
515
+ return { ...a, type: "client" };
516
+ }
517
+ const x = y.object({
518
+ type: y.literal("bridge"),
519
+ name: y.string(),
520
+ data: y.any()
433
521
  });
434
- class $ {
522
+ class R {
435
523
  /**
436
524
  * Creates a new RootSettingsNavigation API instance.
437
525
  *
@@ -454,11 +542,12 @@ class $ {
454
542
  * @returns A promise that resolves when the navigation has been registered
455
543
  */
456
544
  async setRootSettingsNavigation(e) {
457
- const t = this._store.shared("root-settings-navigation"), n = await t.get("navigation"), r = this._store._client._applicationSpecifier;
458
- n[r] = {
545
+ var t;
546
+ const s = this._store.shared("root-settings-navigation"), o = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, r = this._store._client._applicationSpecifier;
547
+ o[r] = {
459
548
  applicationSpecifier: r,
460
549
  entries: e.entries
461
- }, t.set("navigation", n);
550
+ }, s.set("navigation", o);
462
551
  }
463
552
  /**
464
553
  * Retrieves the current navigation entries for this root application.
@@ -469,8 +558,9 @@ class $ {
469
558
  * @returns A promise that resolves to the navigation state for this application
470
559
  */
471
560
  async getRootSettingsNavigation() {
472
- const t = await this._store.shared("root-settings-navigation").get("navigation"), n = this._store._client._applicationSpecifier;
473
- return t[n];
561
+ var e;
562
+ const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, o = this._store._client._applicationSpecifier;
563
+ return s[o];
474
564
  }
475
565
  /**
476
566
  * Retrieves the navigation entries for all root applications.
@@ -482,50 +572,12 @@ class $ {
482
572
  * @returns A promise that resolves to the navigation state for all applications
483
573
  */
484
574
  async getAllRootSettingsNavigation() {
485
- return this._store.shared("root-settings-navigation").get("navigation");
486
- }
487
- }
488
- class x {
489
- constructor(e) {
490
- this._client = e;
491
- }
492
- async fetch(e, t) {
493
- let n;
494
- typeof e == "string" ? n = e : e instanceof URL ? n = e.toString() : (n = e.url, t || (t = {
495
- method: e.method,
496
- headers: e.headers,
497
- body: e.body,
498
- credentials: e.credentials,
499
- cache: e.cache,
500
- redirect: e.redirect,
501
- referrer: e.referrer,
502
- integrity: e.integrity
503
- }));
504
- let r = {};
505
- t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h, c) => {
506
- r[c] = h;
507
- }) : Array.isArray(t.headers) ? t.headers.forEach(([h, c]) => {
508
- r[h] = c;
509
- }) : r = t.headers);
510
- const s = await this._client.request("proxy.fetch", {
511
- url: n,
512
- method: (t == null ? void 0 : t.method) || "GET",
513
- headers: r,
514
- body: (t == null ? void 0 : t.body) || null
515
- });
516
- if (!s.success)
517
- throw new Error(`Proxy fetch failed: ${s.statusText}`);
518
- const l = new Headers(s.headers), u = {
519
- status: s.status,
520
- statusText: s.statusText,
521
- headers: l
522
- };
523
- let a = null;
524
- return s.body !== null && s.body !== void 0 && (typeof s.body == "string" || s.body instanceof ArrayBuffer ? a = s.body : typeof s.body == "object" && (a = JSON.stringify(s.body))), new Response(a, u);
575
+ var e;
576
+ return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
525
577
  }
526
578
  }
527
- const g = 1e3 * 30;
528
- class R {
579
+ const _ = 1e3 * 30;
580
+ class j {
529
581
  /**
530
582
  * Creates a new Client instance for communicating with the TelemetryOS platform.
531
583
  *
@@ -537,7 +589,7 @@ class R {
537
589
  * in your application's telemetry.config.json file
538
590
  */
539
591
  constructor(e) {
540
- this._applicationName = e, this._applicationInstance = "", this._applicationSpecifier = "", this._onHandlers = /* @__PURE__ */ new Map(), this._onceHandlers = /* @__PURE__ */ new Map(), this._subscriptionNamesByHandler = /* @__PURE__ */ new Map(), this._subscriptionNamesBySubjectName = /* @__PURE__ */ new Map();
592
+ this._applicationName = e, this._applicationInstance = "", this._applicationSpecifier = "", this._messageInterceptors = /* @__PURE__ */ new Map(), this._onHandlers = /* @__PURE__ */ new Map(), this._onceHandlers = /* @__PURE__ */ new Map(), this._subscriptionNamesByHandler = /* @__PURE__ */ new Map(), this._subscriptionNamesBySubjectName = /* @__PURE__ */ new Map();
541
593
  }
542
594
  /**
543
595
  * Provides access to the accounts API for retrieving TelemetryOS account information.
@@ -551,7 +603,7 @@ class R {
551
603
  * @returns An Accounts instance bound to this client
552
604
  */
553
605
  get accounts() {
554
- return new P(this);
606
+ return new M(this);
555
607
  }
556
608
  /**
557
609
  * Provides access to the users API for retrieving TelemetryOS user information.
@@ -565,7 +617,7 @@ class R {
565
617
  * @returns A Users instance bound to this client
566
618
  */
567
619
  get users() {
568
- return new F(this);
620
+ return new k(this);
569
621
  }
570
622
  /**
571
623
  * Provides access to the store API for data persistence with multiple storage scopes.
@@ -579,7 +631,7 @@ class R {
579
631
  * @returns A Store instance bound to this client
580
632
  */
581
633
  get store() {
582
- return new C(this);
634
+ return new F(this);
583
635
  }
584
636
  /**
585
637
  * Provides access to the applications API for discovering other TelemetryOS applications.
@@ -593,7 +645,7 @@ class R {
593
645
  * @returns An Applications instance bound to this client
594
646
  */
595
647
  get applications() {
596
- return new E(this);
648
+ return new P(this);
597
649
  }
598
650
  /**
599
651
  * Provides access to the media API for working with content hosted on the TelemetryOS platform.
@@ -622,7 +674,7 @@ class R {
622
674
  * @returns A Proxy instance bound to this client
623
675
  */
624
676
  get proxy() {
625
- return new x(this);
677
+ return new T(this);
626
678
  }
627
679
  /**
628
680
  * Provides access to the devices API for interacting with the current device.
@@ -637,7 +689,7 @@ class R {
637
689
  * @returns A Devices instance bound to this client
638
690
  */
639
691
  get devices() {
640
- return new M(this);
692
+ return new C(this);
641
693
  }
642
694
  /**
643
695
  * Provides access to the root settings navigation API for TelemetryOS administration UI integration.
@@ -655,7 +707,7 @@ class R {
655
707
  * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
656
708
  */
657
709
  get rootSettingsNavigation() {
658
- return new $(this.store);
710
+ return new R(this.store);
659
711
  }
660
712
  /**
661
713
  * Provides access to the weather API for retrieving weather data.
@@ -669,7 +721,7 @@ class R {
669
721
  * @returns A Weather instance bound to this client
670
722
  */
671
723
  get weather() {
672
- return new k(this);
724
+ return new $(this);
673
725
  }
674
726
  get applicationName() {
675
727
  return this._applicationName;
@@ -696,37 +748,45 @@ class R {
696
748
  * of creating and binding their own Client instances.
697
749
  */
698
750
  bind() {
699
- var e;
700
- const t = new URL(window.location.href), n = t.searchParams;
701
- this._applicationInstance = (e = n.get("telemetryApplicationId")) !== null && e !== void 0 ? e : "";
702
- const r = n.get("applicationSpecifier");
703
- if (r)
704
- this._applicationSpecifier = r;
705
- else {
706
- const s = t.hostname.split(".");
707
- this._applicationSpecifier = s[0] || "";
751
+ var e, t, s;
752
+ const o = new URL(window.location.href), r = o.searchParams;
753
+ if (this._applicationInstance = (e = r.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
754
+ throw new Error("Missing applicationInstance query parameter");
755
+ if (this._applicationSpecifier = (t = r.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
756
+ const n = o.hostname.split(".");
757
+ this._applicationSpecifier = (s = n[0]) !== null && s !== void 0 ? s : "";
708
758
  }
709
759
  if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
710
760
  throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
711
- if (!this._applicationInstance)
712
- throw new Error("Missing telemetryApplicationId query parameter");
713
- this._windowMessageHandler = (s) => {
714
- if (s.source === window)
715
- return;
716
- for (let c = 0; c < window.frames.length; c += 1)
717
- window.frames[c].postMessage(s.data, "*");
718
- const l = T.safeParse(s.data);
719
- if (!l.success)
761
+ this._windowMessageHandler = (n) => {
762
+ if (n.source === window || !n.data || !("type" in n.data) || n.data.type !== "client" && n.data.type !== "bridge")
720
763
  return;
721
- const u = l.data, a = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
722
- if (a)
723
- for (const c of a)
724
- c(u.data);
725
- if (h) {
726
- for (const c of h)
727
- c(u.data);
728
- this._onceHandlers.delete(u.name);
764
+ let l;
765
+ if (n.data.type === "client") {
766
+ const c = this._messageInterceptors.get(n.data.name);
767
+ if (!c) {
768
+ window.parent.postMessage(n.data, "*");
769
+ return;
770
+ }
771
+ l = { ...c(n.data.data), type: "bridge" };
772
+ }
773
+ if (!l) {
774
+ const c = x.safeParse(n.data);
775
+ if (!c.success)
776
+ return;
777
+ 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)
781
+ p(l.data);
782
+ if (u) {
783
+ for (const p of u)
784
+ p(l.data);
785
+ this._onceHandlers.delete(l.name);
786
+ }
729
787
  }
788
+ for (let c = 0; c < window.frames.length; c += 1)
789
+ window.frames[c].postMessage(l, "*");
730
790
  }, window.addEventListener("message", this._windowMessageHandler);
731
791
  }
732
792
  /**
@@ -759,15 +819,15 @@ class R {
759
819
  * @param data The data payload to include with the message
760
820
  */
761
821
  send(e, t) {
762
- const n = {
763
- telemetrySdkVersion: b,
822
+ const s = S({
823
+ telemetrySdkVersion: N,
764
824
  applicationName: this._applicationName,
765
825
  applicationSpecifier: this._applicationSpecifier,
766
826
  applicationInstance: this._applicationInstance,
767
827
  name: e,
768
828
  data: t
769
- };
770
- window.parent.postMessage(n, "*");
829
+ });
830
+ window.parent.postMessage(s, "*");
771
831
  }
772
832
  /**
773
833
  * Sends a message to the TelemetryOS platform and waits for a response.
@@ -787,96 +847,96 @@ class R {
787
847
  * @throws {Error} If the request times out
788
848
  */
789
849
  request(e, t) {
790
- const n = y(), r = {
791
- telemetrySdkVersion: b,
850
+ const s = v(), o = S({
851
+ telemetrySdkVersion: N,
792
852
  applicationName: this._applicationName,
793
853
  applicationSpecifier: this._applicationSpecifier,
794
854
  applicationInstance: this._applicationInstance,
795
855
  name: e,
796
856
  data: t,
797
- responseName: n
798
- };
799
- window.parent.postMessage(r, "*");
800
- let s = !1, l;
801
- const u = new Promise((h, c) => {
802
- const d = new Error(`${e} message request with response name of ${n} timed out after ${g}`);
857
+ responseName: s
858
+ });
859
+ window.parent.postMessage(o, "*");
860
+ 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 ${_}`);
803
863
  setTimeout(() => {
804
- s = !0, this.off(n, l), c(d);
805
- }, g);
806
- }), a = new Promise((h) => {
807
- l = (c) => {
808
- s || h(c);
809
- }, this.once(n, h);
864
+ r = !0, this.off(s, n), u(p);
865
+ }, _);
866
+ }), c = new Promise((h) => {
867
+ n = (u) => {
868
+ r || h(u);
869
+ }, this.once(s, h);
810
870
  });
811
- return Promise.race([u, a]);
871
+ return Promise.race([l, c]);
812
872
  }
813
- async subscribe(e, t, n) {
814
- let r, s;
815
- typeof t == "function" ? s = t : (r = t, s = n);
816
- const l = y(), u = y();
817
- let a = this._subscriptionNamesBySubjectName.get(e);
818
- a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(l), this._subscriptionNamesByHandler.set(s, l), this.on(l, s);
819
- const h = {
820
- telemetrySdkVersion: b,
873
+ async subscribe(e, t, s) {
874
+ let o, r;
875
+ typeof t == "function" ? r = t : (o = t, r = s);
876
+ const n = v(), l = v();
877
+ let c = this._subscriptionNamesBySubjectName.get(e);
878
+ c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(n), this._subscriptionNamesByHandler.set(r, n), this.on(n, r);
879
+ const h = S({
880
+ telemetrySdkVersion: N,
821
881
  applicationName: this._applicationName,
822
882
  applicationSpecifier: this._applicationSpecifier,
823
883
  applicationInstance: this._applicationInstance,
824
884
  name: e,
825
- data: r,
826
- responseName: u,
827
- subscriptionName: l
828
- };
885
+ data: o,
886
+ responseName: l,
887
+ subscriptionName: n
888
+ });
829
889
  window.parent.postMessage(h, "*");
830
- let c = !1, d;
831
- const S = new Promise((_, f) => {
832
- const m = new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);
890
+ let u = !1, p;
891
+ 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 ${_}`);
833
893
  setTimeout(() => {
834
- c = !0, this.off(u, d), f(m);
835
- }, g);
836
- }), v = new Promise((_) => {
837
- d = (f) => {
838
- c || _(f);
839
- }, this.on(u, _);
894
+ u = !0, this.off(l, p), g(m);
895
+ }, _);
896
+ }), I = new Promise((w) => {
897
+ p = (g) => {
898
+ u || w(g);
899
+ }, this.on(l, w);
840
900
  });
841
- return Promise.race([S, v]);
901
+ return Promise.race([f, I]);
842
902
  }
843
- async unsubscribe(e, t, n) {
844
- let r, s;
845
- typeof t == "function" ? s = t : (r = t, s = n);
846
- const l = y();
847
- let u = [];
848
- if (s) {
849
- const a = this._subscriptionNamesByHandler.get(s);
850
- if (!a)
903
+ async unsubscribe(e, t, s) {
904
+ let o, r;
905
+ typeof t == "function" ? r = t : (o = t, r = s);
906
+ const n = v();
907
+ let l = [];
908
+ if (r) {
909
+ const c = this._subscriptionNamesByHandler.get(r);
910
+ if (!c)
851
911
  return { success: !1 };
852
- u = [a], this._subscriptionNamesByHandler.delete(s);
912
+ l = [c], this._subscriptionNamesByHandler.delete(r);
853
913
  } else if (!this._subscriptionNamesBySubjectName.get(e))
854
914
  return { success: !1 };
855
- for await (const a of u) {
856
- this.off(a, s);
857
- const h = {
858
- telemetrySdkVersion: b,
915
+ for await (const c of l) {
916
+ this.off(c, r);
917
+ const h = S({
918
+ telemetrySdkVersion: N,
859
919
  applicationInstance: this._applicationInstance,
860
920
  applicationName: this._applicationName,
861
921
  applicationSpecifier: this._applicationSpecifier,
862
922
  name: e,
863
- data: r,
864
- responseName: l,
865
- unsubscribeName: a
866
- };
923
+ data: o,
924
+ responseName: n,
925
+ unsubscribeName: c
926
+ });
867
927
  window.parent.postMessage(h, "*");
868
- let c = !1, d;
869
- const S = new Promise((f, m) => {
870
- const H = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);
928
+ 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 ${_}`);
871
931
  setTimeout(() => {
872
- c = !0, this.off(l, d), m(H);
873
- }, g);
874
- }), v = new Promise((f) => {
875
- d = (m) => {
876
- c || f(m);
877
- }, this.once(l, f);
932
+ u = !0, this.off(n, p), m(H);
933
+ }, _);
934
+ }), I = new Promise((g) => {
935
+ p = (m) => {
936
+ u || g(m);
937
+ }, this.once(n, g);
878
938
  });
879
- if (!(await Promise.race([S, v])).success)
939
+ if (!(await Promise.race([f, I])).success)
880
940
  return { success: !1 };
881
941
  }
882
942
  return { success: !0 };
@@ -899,9 +959,9 @@ class R {
899
959
  * @param handler The callback function to execute when messages are received
900
960
  */
901
961
  on(e, t) {
902
- var n;
903
- const r = (n = this._onHandlers.get(e)) !== null && n !== void 0 ? n : [];
904
- r.length === 0 && this._onHandlers.set(e, r), r.push(t);
962
+ var s;
963
+ const o = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
964
+ o.length === 0 && this._onHandlers.set(e, o), o.push(t);
905
965
  }
906
966
  /**
907
967
  * Registers a one-time handler for a specific message type.
@@ -918,9 +978,9 @@ class R {
918
978
  * @param handler The callback function to execute when the message is received
919
979
  */
920
980
  once(e, t) {
921
- var n;
922
- const r = (n = this._onceHandlers.get(e)) !== null && n !== void 0 ? n : [];
923
- r.length === 0 && this._onceHandlers.set(e, r), r.push(t);
981
+ var s;
982
+ const o = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
983
+ o.length === 0 && this._onceHandlers.set(e, o), o.push(t);
924
984
  }
925
985
  /**
926
986
  * Removes previously registered message handlers.
@@ -938,115 +998,116 @@ class R {
938
998
  * all handlers for this message type will be removed.
939
999
  */
940
1000
  off(e, t) {
941
- const n = this._onHandlers.get(e), r = this._onceHandlers.get(e);
942
- if (!(!n && !r)) {
943
- if (n) {
944
- for (let s = 0; s < n.length; s += 1)
945
- t && n[s] !== t || (n.splice(s, 1), s -= 1);
946
- n.length === 0 && this._onHandlers.delete(e);
1001
+ const s = this._onHandlers.get(e), o = this._onceHandlers.get(e);
1002
+ if (!(!s && !o)) {
1003
+ if (s) {
1004
+ for (let r = 0; r < s.length; r += 1)
1005
+ t && s[r] !== t || (s.splice(r, 1), r -= 1);
1006
+ s.length === 0 && this._onHandlers.delete(e);
947
1007
  }
948
- if (r) {
949
- for (let s = 0; s < r.length; s += 1)
950
- t && r[s] !== t || (r.splice(s, 1), s -= 1);
951
- r.length === 0 && this._onceHandlers.delete(e);
1008
+ if (o) {
1009
+ for (let r = 0; r < o.length; r += 1)
1010
+ t && o[r] !== t || (o.splice(r, 1), r -= 1);
1011
+ o.length === 0 && this._onceHandlers.delete(e);
952
1012
  }
953
1013
  }
954
1014
  }
955
1015
  }
956
- function y() {
1016
+ function v() {
957
1017
  return Math.random().toString(36).slice(2, 9);
958
1018
  }
959
- const b = I.version;
1019
+ const N = E.version;
960
1020
  let i = null;
961
- function L() {
1021
+ function U() {
962
1022
  return i;
963
1023
  }
964
- function U(o) {
965
- i = new R(o), i.bind();
1024
+ function V(a) {
1025
+ i = new j(a), i.bind();
966
1026
  }
967
- function V() {
1027
+ function z() {
968
1028
  i == null || i.unbind(), i = null;
969
1029
  }
970
- function z(...o) {
971
- return p(i), i.on(...o);
972
- }
973
- function G(...o) {
974
- return p(i), i.once(...o);
1030
+ function G(...a) {
1031
+ return d(i), i.on(...a);
975
1032
  }
976
- function J(...o) {
977
- return p(i), i.off(...o);
1033
+ function J(...a) {
1034
+ return d(i), i.once(...a);
978
1035
  }
979
- function K(...o) {
980
- return p(i), i.send(...o);
1036
+ function K(...a) {
1037
+ return d(i), i.off(...a);
981
1038
  }
982
- function O(...o) {
983
- return p(i), i.request(...o);
1039
+ function O(...a) {
1040
+ return d(i), i.send(...a);
984
1041
  }
985
- function W(...o) {
986
- return p(i), i.subscribe(...o);
1042
+ function W(...a) {
1043
+ return d(i), i.request(...a);
987
1044
  }
988
- function Q(...o) {
989
- return p(i), i.unsubscribe(...o);
1045
+ function Q(...a) {
1046
+ return d(i), i.subscribe(...a);
990
1047
  }
991
- function X() {
992
- return p(i), i.store;
1048
+ function X(...a) {
1049
+ return d(i), i.unsubscribe(...a);
993
1050
  }
994
1051
  function Y() {
995
- return p(i), i.applications;
1052
+ return d(i), i.store;
996
1053
  }
997
1054
  function Z() {
998
- return p(i), i.media;
1055
+ return d(i), i.applications;
999
1056
  }
1000
1057
  function ee() {
1001
- return p(i), i.accounts;
1058
+ return d(i), i.media;
1002
1059
  }
1003
1060
  function te() {
1004
- return p(i), i.users;
1061
+ return d(i), i.accounts;
1005
1062
  }
1006
1063
  function se() {
1007
- return p(i), i.devices;
1064
+ return d(i), i.users;
1008
1065
  }
1009
1066
  function ne() {
1010
- return p(i), i.proxy;
1067
+ return d(i), i.devices;
1011
1068
  }
1012
1069
  function ie() {
1013
- return p(i), i.rootSettingsNavigation;
1070
+ return d(i), i.proxy;
1014
1071
  }
1015
1072
  function re() {
1016
- return p(i), i.weather;
1073
+ return d(i), i.rootSettingsNavigation;
1074
+ }
1075
+ function oe() {
1076
+ return d(i), i.weather;
1017
1077
  }
1018
- function p(o) {
1019
- if (!o)
1078
+ function d(a) {
1079
+ if (!a)
1020
1080
  throw new Error("SDK is not configured");
1021
1081
  }
1022
1082
  export {
1023
- P as Accounts,
1024
- E as Applications,
1025
- R as Client,
1026
- M as Devices,
1027
- D as Environment,
1083
+ M as Accounts,
1084
+ P as Applications,
1085
+ j as Client,
1086
+ C as Devices,
1087
+ L as Environment,
1028
1088
  B as Media,
1029
- C as Store,
1030
- F as Users,
1031
- k as Weather,
1032
- ee as accounts,
1033
- Y as applications,
1034
- U as configure,
1035
- V as destroy,
1036
- se as devices,
1037
- L as globalClient,
1038
- Z as media,
1039
- J as off,
1040
- z as on,
1041
- G as once,
1042
- ne as proxy,
1043
- O as request,
1044
- ie as rootSettingsNavigation,
1045
- K as send,
1046
- X as store,
1047
- W as subscribe,
1048
- b as telemetrySdkVersion,
1049
- Q as unsubscribe,
1050
- te as users,
1051
- re as weather
1089
+ T as Proxy,
1090
+ F as Store,
1091
+ k as Users,
1092
+ $ as Weather,
1093
+ te as accounts,
1094
+ Z as applications,
1095
+ V as configure,
1096
+ z as destroy,
1097
+ ne as devices,
1098
+ U as globalClient,
1099
+ ee as media,
1100
+ K as off,
1101
+ G as on,
1102
+ J as once,
1103
+ ie as proxy,
1104
+ W as request,
1105
+ re as rootSettingsNavigation,
1106
+ O as send,
1107
+ Y as store,
1108
+ Q as subscribe,
1109
+ N as telemetrySdkVersion,
1110
+ X as unsubscribe,
1111
+ se as users,
1112
+ oe as weather
1052
1113
  };
package/dist/proxy.d.ts CHANGED
@@ -12,15 +12,12 @@ export declare class Proxy {
12
12
  /**
13
13
  * Fetches content from an external URL through the TelemetryOS API.
14
14
  *
15
- * This method has the same interface as the native `fetch()` API but routes the request through
16
- * the platform. This is useful for:
17
- * - Accessing external APIs that have CORS restrictions
18
- * - Fetching content with platform authentication
19
- * - Benefiting from platform caching and bandwidth management
20
- * - Proxying content from external sources
15
+ * This method is a subset of the native `fetch()` API that routes requests through
16
+ * the platform. Only `method`, `headers`, and `body` options are supported.
17
+ * AbortSignal and other fetch options are not supported.
21
18
  *
22
- * @param input The URL to fetch from (as a string or URL object)
23
- * @param init Optional fetch options (method, headers, body, signal, etc.)
19
+ * @param input The URL to fetch from (as a string, URL, or Request object)
20
+ * @param init Optional fetch options (method, headers, body)
24
21
  * @returns A promise that resolves to a standard Response object
25
22
  *
26
23
  * @example
package/dist/store.d.ts CHANGED
@@ -78,7 +78,7 @@ declare class StoreSlice {
78
78
  * @param value The value to store - must be JSON serializable
79
79
  * @returns A promise that resolves to true if the value was saved successfully
80
80
  */
81
- set(key: string, value: any): Promise<boolean>;
81
+ set<T>(key: string, value: T): Promise<boolean>;
82
82
  /**
83
83
  * Retrieves a value from the store.
84
84
  *
@@ -90,7 +90,7 @@ declare class StoreSlice {
90
90
  * @param key The key to retrieve the value for
91
91
  * @returns A promise that resolves to the stored value, or undefined if the key does not exist
92
92
  */
93
- get<T>(key: string): Promise<T>;
93
+ get<T>(key: string): Promise<T | undefined>;
94
94
  /**
95
95
  * Subscribes to changes in the store for a specific key.
96
96
  *
@@ -103,7 +103,7 @@ declare class StoreSlice {
103
103
  * @param handler The callback function to call when the value changes
104
104
  * @returns A promise that resolves to true if the subscription was successful
105
105
  */
106
- subscribe(key: string, handler: MessageHandler<any>): Promise<boolean>;
106
+ subscribe<T>(key: string, handler: MessageHandler<T | undefined>): Promise<boolean>;
107
107
  /**
108
108
  * Unsubscribes from changes in the store for a specific key.
109
109
  *
@@ -112,9 +112,9 @@ declare class StoreSlice {
112
112
  *
113
113
  * @param key The key to unsubscribe from
114
114
  * @param handler Optional. The specific handler to remove. If not provided, all handlers for this key will be removed.
115
- * @returns A promise that resolves to true if the unsubscription was successful
115
+ * @returns A promise that resolves to true if the unsubscribe was successful
116
116
  */
117
- unsubscribe(key: string, handler?: MessageHandler<any>): Promise<boolean>;
117
+ unsubscribe<T>(key: string, handler?: MessageHandler<T | undefined>): Promise<boolean>;
118
118
  /**
119
119
  * Deletes a value from the store.
120
120
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "The official TelemetryOS root application sdk package. Provides types and apis for building root TelemetryOS applications.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
File without changes