@telemetryos/root-sdk 1.12.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - - **SDK client refactor:** Removed `applicationName` from the client and `configure()` API (still accepted for backwards compatibility). The SDK now resolves `applicationSpecifier` from URL search params first with subdomain fallback, validates it as a 40-char hex hash, and adds `deviceId` from URL params. Store scoping updated accordingly. Fixed a listener leak when calling `configure()` multiple times.
8
+ - **Template assets moved to `public/`:** SDK template assets (logo, thumbnail) moved from `assets/` to `public/assets/` so Vite includes them in the build output automatically. Dev server updated to resolve from `public/` first.
9
+ - **Documentation updates for v1.13.0:** Added docs for web mount point, Navigation API, `tos claude-code` command, `vite-react-typescript-web` template, `playlist.getDuration()`, `SettingsMediaSelect` component, and custom logo support. Fixed scope availability, store scope guidance for web mount points, and various inconsistencies.
10
+
11
+ ## 1.13.0
12
+
13
+ ### Minor Changes
14
+
15
+ - ### New Features
16
+ - **Web mount point support** — Applications can now define a third UI surface (`/web`) alongside Render and Settings, enabling web-portal-style interfaces with full navigation control via a postMessage bridge.
17
+ - **`playlist.getDuration()`** — New async method returns the playlist-configured page duration in seconds.
18
+ - **Custom logo support** — Projects can specify a `logoPath` in `telemetry.config.json` for branding in the dev host.
19
+ - **`tos claude-code` command** — New CLI command to apply or update Claude Code skills and settings in existing projects.
20
+ - **Web project template** — New `vite-react-typescript-web` template scaffolds a project with all three mount points pre-configured.
21
+
22
+ ### Bug Fixes
23
+ - Fixed SDK client not properly validating bridge message responses.
24
+ - Fixed canvas not resizing when the sidebar toggles or window resizes after a manual drag-resize.
25
+ - Fixed `isLoading` usage and `useEffect` dependency arrays in Claude Code skill examples.
26
+ - Fixed stale active tab when the tabs array changes in the dev host.
27
+
28
+ ### Infrastructure
29
+ - Renamed `generate-application` to `create-project`; extracted shared template utilities.
30
+ - Added unit tests for Navigation, Currency, and Weather classes.
31
+
3
32
  ## 1.12.0
4
33
 
5
34
  ### Minor Changes
package/README.md CHANGED
@@ -301,6 +301,74 @@ const blob = await response.blob();
301
301
  const imageUrl = URL.createObjectURL(blob);
302
302
  ```
303
303
 
304
+ ### Weather API
305
+
306
+ Access weather data including current conditions, forecasts, and alerts. Weather data is sourced from WeatherBit and uses city IDs for location lookup.
307
+
308
+ ```javascript
309
+ import { weather } from '@telemetryos/root-sdk';
310
+
311
+ // Search for cities to get a cityId
312
+ const cities = await weather().getCities({ search: 'New York', countryCode: 'US' });
313
+ const cityId = cities[0].cityId;
314
+
315
+ // Get current weather conditions
316
+ const conditions = await weather().getConditions({ cityId });
317
+ console.log(`${conditions.temperatureC}°C / ${conditions.temperatureF}°F`);
318
+ console.log(`Wind: ${conditions.windSpeedKph} kph`);
319
+ console.log(`Humidity: ${conditions.humidity}%`);
320
+
321
+ // Get daily forecast (up to 16 days)
322
+ const daily = await weather().getDailyForecast({ cityId, days: 7 });
323
+ daily.data.forEach(day => {
324
+ console.log(`${day.forecastDate}: ${day.weatherDescription}`);
325
+ console.log(`High: ${day.maxTemperatureC}°C, Low: ${day.minTemperatureC}°C`);
326
+ });
327
+
328
+ // Get hourly forecast (up to 120 hours)
329
+ const hourly = await weather().getHourlyForecast({ cityId, hours: 24 });
330
+ hourly.data.forEach(hour => {
331
+ console.log(`${hour.forecastTimeLocal}: ${hour.temperatureC}°C`);
332
+ });
333
+
334
+ // Get weather alerts
335
+ const alerts = await weather().getAlerts({ cityId });
336
+ alerts.alerts.forEach(alert => {
337
+ console.log(`${alert.severity}: ${alert.title}`);
338
+ });
339
+ ```
340
+
341
+ All weather responses include dual units (Celsius/Fahrenheit, kph/mph, mb/inHg, km/mi) so you can display data in the user's preferred format. An optional `language` parameter is available on all methods for localized weather descriptions.
342
+
343
+ ### Navigation API
344
+
345
+ The Navigation class provides browser-style navigation control for views embedded in iframes, used primarily by the web mount point. It intercepts `pushState`, `replaceState`, and `popstate` events and relays location changes to the host window via postMessage.
346
+
347
+ ```javascript
348
+ import { Navigation } from '@telemetryos/root-sdk';
349
+ ```
350
+
351
+ Application developers using SPA routing frameworks (React Router, Vue Router, etc.) get navigation support automatically — the SDK intercepts history changes transparently. The host window (dev server or web host) displays an address bar with back/forward controls that communicate with the embedded view. Manual instantiation of `Navigation` is only needed for advanced or custom embedding scenarios.
352
+
353
+ ### Currency API
354
+
355
+ Access currency exchange rates and symbols:
356
+
357
+ ```javascript
358
+ import { currency } from '@telemetryos/root-sdk';
359
+
360
+ // Get all available currency symbols
361
+ const symbols = await currency().getSymbols();
362
+ // { "USD": "United States Dollar", "EUR": "Euro", ... }
363
+
364
+ // Get exchange rates for a base currency
365
+ const rates = await currency().getRates({
366
+ base: 'USD',
367
+ symbols: 'EUR,GBP,JPY'
368
+ });
369
+ // { "EUR": 0.92, "GBP": 0.79, "JPY": 149.50 }
370
+ ```
371
+
304
372
  ## Communication Patterns
305
373
 
306
374
  The SDK uses a request-response pattern for most operations. All requests have a 30-second timeout by default to prevent hanging promises:
package/dist/bridge.cjs CHANGED
@@ -1 +1 @@
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;
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(),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,18 +1,17 @@
1
- import { o, s as e, a as r, l as d } from "./types-CCzf8sMT.js";
1
+ import { o, s, a as r, l as d } from "./types-CCzf8sMT.js";
2
2
  function l(i) {
3
3
  return { ...i, type: "bridge" };
4
4
  }
5
5
  const p = o({
6
6
  type: d("client"),
7
- telemetrySdkVersion: e(),
8
- applicationName: e(),
9
- applicationSpecifier: e(),
10
- applicationInstance: e(),
11
- name: e(),
7
+ telemetrySdkVersion: s(),
8
+ applicationSpecifier: s(),
9
+ applicationInstance: s(),
10
+ name: s(),
12
11
  data: r(),
13
- responseName: e().optional(),
14
- subscriptionName: e().optional(),
15
- unsubscribeName: e().optional()
12
+ responseName: s().optional(),
13
+ subscriptionName: s().optional(),
14
+ unsubscribeName: s().optional()
16
15
  });
17
16
  class w {
18
17
  /**
@@ -21,14 +20,14 @@ class w {
21
20
  */
22
21
  bind() {
23
22
  this._windowMessageHandler = (a) => {
24
- var s;
23
+ var e;
25
24
  if (a.source === window)
26
25
  return;
27
26
  const n = p.safeParse(a.data);
28
27
  if (!n.success)
29
28
  return;
30
29
  const t = n.data;
31
- (s = this.onMessage) === null || s === void 0 || s.call(this, t);
30
+ (e = this.onMessage) === null || e === void 0 || e.call(this, t);
32
31
  }, window.addEventListener("message", this._windowMessageHandler);
33
32
  }
34
33
  /**
@@ -43,8 +42,8 @@ class w {
43
42
  * @param message The message to send.
44
43
  */
45
44
  send(a) {
46
- for (let s = 0; s < window.frames.length; s += 1)
47
- window.frames[s].postMessage(l(a), "*");
45
+ for (let e = 0; e < window.frames.length; e += 1)
46
+ window.frames[e].postMessage(l(a), "*");
48
47
  }
49
48
  }
50
49
  export {
@@ -2,7 +2,6 @@ import { z } from 'zod';
2
2
  export declare const clientMessageValidator: z.ZodObject<{
3
3
  type: z.ZodLiteral<"client">;
4
4
  telemetrySdkVersion: z.ZodString;
5
- applicationName: z.ZodString;
6
5
  applicationSpecifier: z.ZodString;
7
6
  applicationInstance: z.ZodString;
8
7
  name: z.ZodString;
@@ -13,7 +12,6 @@ export declare const clientMessageValidator: z.ZodObject<{
13
12
  }, "strip", z.ZodTypeAny, {
14
13
  type: "client";
15
14
  telemetrySdkVersion: string;
16
- applicationName: string;
17
15
  applicationSpecifier: string;
18
16
  applicationInstance: string;
19
17
  name: string;
@@ -24,7 +22,6 @@ export declare const clientMessageValidator: z.ZodObject<{
24
22
  }, {
25
23
  type: "client";
26
24
  telemetrySdkVersion: string;
27
- applicationName: string;
28
25
  applicationSpecifier: string;
29
26
  applicationInstance: string;
30
27
  name: string;
package/dist/client.d.ts CHANGED
@@ -10,6 +10,7 @@ import { Weather } from './weather.js';
10
10
  import { Currency } from './currency.js';
11
11
  import { Environment } from './environment.js';
12
12
  import { Mqtt } from './mqtt.js';
13
+ import { Navigation } from './navigation.js';
13
14
  import { BridgeMessage } from './bridge.js';
14
15
  /**
15
16
  * The maximum time in milliseconds to wait for a response to a request call.
@@ -75,9 +76,10 @@ export type MessageInterceptor = (data: any) => BridgeMessage;
75
76
  * when an application needs to manage multiple independent communication channels.
76
77
  */
77
78
  export declare class Client {
78
- _applicationName: string;
79
79
  _applicationInstance: string;
80
80
  _applicationSpecifier: string;
81
+ _deviceId: string;
82
+ _navigation: Navigation;
81
83
  _messageInterceptors: Map<string, MessageInterceptor>;
82
84
  _onHandlers: Map<string, MessageHandler<any>[]>;
83
85
  _onceHandlers: Map<string, MessageHandler<any>[]>;
@@ -90,11 +92,8 @@ export declare class Client {
90
92
  * Note that creating a Client instance alone is not sufficient to begin communication.
91
93
  * You must also call the bind() method to initialize event listeners and extract
92
94
  * the application ID from the URL.
93
- *
94
- * @param applicationName The name of your application - must match the 'name' property
95
- * in your application's telemetry.config.json file
96
95
  */
97
- constructor(applicationName: string);
96
+ constructor();
98
97
  /**
99
98
  * Provides access to the accounts API for retrieving TelemetryOS account information.
100
99
  *
@@ -234,9 +233,9 @@ export declare class Client {
234
233
  */
235
234
  get environment(): Environment;
236
235
  get mqtt(): Mqtt;
237
- get applicationName(): string;
238
236
  get applicationSpecifier(): string;
239
237
  get applicationInstance(): string;
238
+ get deviceId(): string;
240
239
  /**
241
240
  * Initializes the client by setting up message listeners and extracting the application ID.
242
241
  *
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),Q="1.12.0",U={version:Q};class T{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e},{timeout:0})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class H{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}async getCapabilities(){const e=await this._client.request("devices.getCapabilities",{});if(!e.success)throw new Error("Failed to get device capabilities");return e.capabilities}}class P{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class F{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}async openPicker(e){return(await this._client.request("media.openPicker",{accept:e==null?void 0:e.accept,currentValue:e==null?void 0:e.currentValue})).selection}}class k{constructor(e){this._client=e}async fetch(e,t){var s;let r;typeof e=="string"?r=e:e instanceof URL?r=e.toString():(r=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,l)=>{n[l]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,l])=>{n[h]=l}):n=t.headers);const o=await this._client.request("proxy.fetch",{url:r,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!o.success)throw new TypeError(o.errorMessage,{cause:o.errorCause?Error(o.errorCause):void 0});const u=new Headers(o.headers),a={status:o.status,statusText:o.statusText,headers:u};let p=null;if(o.body!==null&&o.body!==void 0)if(o.bodyType==="binary"){const h=atob(o.body),l=new Uint8Array(h.length);for(let f=0;f<h.length;f++)l[f]=h.charCodeAt(f);p=l}else o.bodyType==="text"?p=o.body:o.bodyType==="json"&&(p=JSON.stringify(o.body));return new Response(p,a)}}class A{constructor(e){this._client=e}get application(){return new v("application","",this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.applicationInstance,this._client)}shared(e){return new v("shared",e,this._client)}}class v{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class B{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,r;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((r=n.error)===null||r===void 0?void 0:r.message)||"Failed to fetch currency rates");return n.rates}}class x{constructor(e){this._client=e}async discover(){const e=await this._client.request("mqtt.discover",{});if(!e.success)throw new Error("Failed to discover MQTT brokers");return e.brokers}async connect(e,t){const s=await this._client.request("mqtt.connect",{brokerUrl:e,...t});if(!s.success)throw new Error("Failed to connect to MQTT broker");return s.clientId}async disconnect(e){if(!(await this._client.request("mqtt.disconnect",{clientId:e})).success)throw new Error("Failed to disconnect from MQTT broker")}async publish(e,t,s,r){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...r})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,r){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...r},s)).success}async unsubscribe(e,t,s){return(await this._client.unsubscribe("mqtt.unsubscribe",{clientId:e,topic:t},s)).success}async getConnectionStatus(e){const t=await this._client.request("mqtt.getConnectionStatus",{clientId:e});if(!t.success)throw new Error("Failed to get MQTT connection status");return t.status}async subscribeConnectionStatus(e,t){return(await this._client.subscribe("mqtt.subscribeConnectionStatus",{clientId:e},t)).success}async unsubscribeConnectionStatus(e,t){return(await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus",{clientId:e},t)).success}}function E(c){return{...c,type:"client"}}const V=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class L{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),r=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;r[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",r)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},r=this._store._client._applicationSpecifier;return s[r]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const b=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function y(c){C?self.postMessage(c):S.parent.postMessage(c,"*")}class j{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new T(this)}get users(){return new B(this)}get store(){return new A(this)}get applications(){return new M(this)}get media(){return new F(this)}get proxy(){return new k(this)}get devices(){return new H(this)}get rootSettingsNavigation(){return new L(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new P(this)}get mqtt(){return new x(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const r=new URL(S.location.href),n=r.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const o=r.hostname.split(".");this._applicationSpecifier=(s=o[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=o=>{if(o.source===S||!o.data||typeof o.data!="object"||!("type"in o.data)||o.data.type!=="client"&&o.data.type!=="bridge")return;let u;if(o.data.type==="client"){const a=this._messageInterceptors.get(o.data.name);if(!a){y(o.data);return}u={...a(o.data.data),type:"bridge"}}if(!u){const a=V.safeParse(o.data);if(!a.success)return;u=a.data;const p=this._onHandlers.get(u.name),h=this._onceHandlers.get(u.name);if(p)for(const l of p)l(u.data);if(h){for(const l of h)l(u.data);this._onceHandlers.delete(u.name)}}if(!C)for(let a=0;a<window.frames.length;a+=1)window.frames[a].postMessage(u,"*")},S.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&S.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t,s){var r;const n=I(),o=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});y(o);const u=(r=s==null?void 0:s.timeout)!==null&&r!==void 0?r:b;let a=!1,p;const h=new Promise(f=>{p=g=>{a||f(g)},this.once(n,p)});if(u===0)return h;const l=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${u}`);setTimeout(()=>{a=!0,this.off(n,p),g(w)},u)});return Promise.race([l,h])}async subscribe(e,t,s){let r,n;typeof t=="function"?n=t:(r=t,n=s);const o=I(),u=I();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(o),this._subscriptionNamesByHandler.set(n,o),this.on(o,n);const p=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:r,responseName:u,subscriptionName:o});y(p);let h=!1,l;const f=new Promise((w,m)=>{const _=new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);setTimeout(()=>{h=!0,this.off(u,l),m(_)},b)}),g=new Promise(w=>{l=m=>{h||w(m)},this.once(u,l)});return Promise.race([f,g])}async unsubscribe(e,t,s){let r,n;typeof t=="function"?n=t:(r=t,n=s);const o=I();let u=[];if(n){const a=this._subscriptionNamesByHandler.get(n);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,n);const p=E({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:r,responseName:o,unsubscribeName:a});y(p);let h=!1,l;const f=new Promise((m,_)=>{const D=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);setTimeout(()=>{h=!0,this.off(o,l),_(D)},b)}),g=new Promise(m=>{l=_=>{h||m(_)},this.once(o,l)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const r=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var s;const r=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const s=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!s&&!r)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(r){for(let n=0;n<r.length;n+=1)t&&r[n]!==t||(r.splice(n,1),n-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=U.version;let i=null;function W(){return i}function O(c){i=new j(c),i.bind()}function G(){i==null||i.unbind(),i=null}function J(...c){return d(i),i.on(...c)}function K(...c){return d(i),i.once(...c)}function z(...c){return d(i),i.off(...c)}function X(...c){return d(i),i.send(...c)}function Y(...c){return d(i),i.request(...c)}function Z(...c){return d(i),i.subscribe(...c)}function ee(...c){return d(i),i.unsubscribe(...c)}function te(){return d(i),i.store}function se(){return d(i),i.applications}function ne(){return d(i),i.media}function re(){return d(i),i.accounts}function ie(){return d(i),i.users}function oe(){return d(i),i.devices}function ce(){return d(i),i.proxy}function ae(){return d(i),i.rootSettingsNavigation}function ue(){return d(i),i.weather}function le(){return d(i),i.currency}function he(){return d(i),i.environment}function de(){return d(i),i.mqtt}function d(c){if(!c)throw new Error("SDK is not configured")}exports.Accounts=T;exports.Applications=M;exports.Client=j;exports.Currency=R;exports.Devices=H;exports.Environment=P;exports.Media=F;exports.Mqtt=x;exports.Proxy=k;exports.Store=A;exports.StoreSlice=v;exports.Users=B;exports.Weather=$;exports.accounts=re;exports.applications=se;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=oe;exports.environment=he;exports.globalClient=W;exports.media=ne;exports.mqtt=de;exports.off=z;exports.on=J;exports.once=K;exports.proxy=ce;exports.request=Y;exports.rootSettingsNavigation=ae;exports.send=X;exports.store=te;exports.subscribe=Z;exports.telemetrySdkVersion=q;exports.unsubscribe=ee;exports.users=ie;exports.weather=ue;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./types-mYnxD5LM.cjs"),Q="1.13.1",V={version:Q};class E{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 P{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e},{timeout:0})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class 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}async getCapabilities(){const e=await this._client.request("devices.getCapabilities",{});if(!e.success)throw new Error("Failed to get device capabilities");return e.capabilities}}class k{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 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}async openPicker(e){return(await this._client.request("media.openPicker",{accept:e==null?void 0:e.accept,currentValue:e==null?void 0:e.currentValue})).selection}}class F{constructor(e){this._client=e}async fetch(e,t){var s;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 i={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,d)=>{i[d]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,d])=>{i[h]=d}):i=t.headers);const a=await this._client.request("proxy.fetch",{url:n,method:(t==null?void 0:t.method)||"GET",headers:i,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!a.success)throw new TypeError(a.errorMessage,{cause:a.errorCause?Error(a.errorCause):void 0});const c=new Headers(a.headers),l={status:a.status,statusText:a.statusText,headers:c};let u=null;if(a.body!==null&&a.body!==void 0)if(a.bodyType==="binary"){const h=atob(a.body),d=new Uint8Array(h.length);for(let f=0;f<h.length;f++)d[f]=h.charCodeAt(f);u=d}else a.bodyType==="text"?u=a.body:a.bodyType==="json"&&(u=JSON.stringify(a.body));return new Response(u,l)}}class A{constructor(e){this._client=e}get application(){return new v("application",void 0,this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.deviceId,this._client)}shared(e){return new v("shared",e,this._client)}}class v{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class R{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 getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class ${constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,n;const i=await this._client.request("currency.getRates",e);if(!i.success||!i.rates)throw((t=i.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=i.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((n=i.error)===null||n===void 0?void 0:n.message)||"Failed to fetch currency rates");return i.rates}}class L{constructor(e){this._client=e}async discover(){const e=await this._client.request("mqtt.discover",{});if(!e.success)throw new Error("Failed to discover MQTT brokers");return e.brokers}async connect(e,t){const s=await this._client.request("mqtt.connect",{brokerUrl:e,...t});if(!s.success)throw new Error("Failed to connect to MQTT broker");return s.clientId}async disconnect(e){if(!(await this._client.request("mqtt.disconnect",{clientId:e})).success)throw new Error("Failed to disconnect from MQTT broker")}async publish(e,t,s,n){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...n})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,n){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...n},s)).success}async unsubscribe(e,t,s){return(await this._client.unsubscribe("mqtt.unsubscribe",{clientId:e,topic:t},s)).success}async getConnectionStatus(e){const t=await this._client.request("mqtt.getConnectionStatus",{clientId:e});if(!t.success)throw new Error("Failed to get MQTT connection status");return t.status}async subscribeConnectionStatus(e,t){return(await this._client.subscribe("mqtt.subscribeConnectionStatus",{clientId:e},t)).success}async unsubscribeConnectionStatus(e,t){return(await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus",{clientId:e},t)).success}}class x{constructor(e){this._originalPushState=null,this._originalReplaceState=null,this._popstateHandler=null,this._backHandler=null,this._forwardHandler=null,this._client=e}bind(){typeof window>"u"||this._originalPushState||(this._originalPushState=history.pushState.bind(history),history.pushState=(...e)=>{this._originalPushState(...e),this._sendLocationChanged()},this._originalReplaceState=history.replaceState.bind(history),history.replaceState=(...e)=>{this._originalReplaceState(...e),this._sendLocationChanged()},this._popstateHandler=()=>this._sendLocationChanged(),window.addEventListener("popstate",this._popstateHandler),this._backHandler=()=>history.back(),this._forwardHandler=()=>history.forward(),this._client.on("navigation.back",this._backHandler),this._client.on("navigation.forward",this._forwardHandler),this._sendLocationChanged())}unbind(){typeof window>"u"||(this._originalPushState&&(history.pushState=this._originalPushState,this._originalPushState=null),this._originalReplaceState&&(history.replaceState=this._originalReplaceState,this._originalReplaceState=null),this._popstateHandler&&(window.removeEventListener("popstate",this._popstateHandler),this._popstateHandler=null),this._backHandler&&(this._client.off("navigation.back",this._backHandler),this._backHandler=null),this._forwardHandler&&(this._client.off("navigation.forward",this._forwardHandler),this._forwardHandler=null))}_sendLocationChanged(){this._client.send("navigation.locationChanged",{pathname:window.location.pathname})}}function N(o){return{...o,type:"client"}}const O=H.objectType({type:H.literalType("bridge"),name:H.stringType(),data:H.anyType()});class W{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"),n=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},i=this._store._client._applicationSpecifier;n[i]={applicationSpecifier:i,entries:e.entries},s.set("navigation",n)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},n=this._store._client._applicationSpecifier;return s[n]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const y=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function m(o){C?self.postMessage(o):S.parent.postMessage(o,"*")}class j{constructor(){this._applicationInstance="",this._applicationSpecifier="",this._deviceId="",this._navigation=new x(this),this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new E(this)}get users(){return new R(this)}get store(){return new A(this)}get applications(){return new P(this)}get media(){return new M(this)}get proxy(){return new F(this)}get devices(){return new T(this)}get rootSettingsNavigation(){return new W(this.store)}get weather(){return new B(this)}get currency(){return new $(this)}get environment(){return new k(this)}get mqtt(){return new L(this)}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}get deviceId(){return this._deviceId}bind(){var e,t;const s=new URL(S.location.href),n=s.searchParams;this._applicationInstance=n.get("applicationInstance")||"single",this._deviceId=n.get("deviceId")||this._applicationInstance;const i=s.hostname.split("."),a=/^[a-f0-9]{40}$/i;if(this._applicationSpecifier=(e=n.get("applicationSpecifier"))!==null&&e!==void 0?e:"",(!this._applicationSpecifier||!a.test(this._applicationSpecifier))&&(this._applicationSpecifier=(t=i[0])!==null&&t!==void 0?t:""),!this._applicationSpecifier||!a.test(this._applicationSpecifier))throw console.error("TelemetryOS apps require an applicationSpecifier in the URL query parameters or subdomain. Make sure your app is being served correctly through the TelemetryOS platform or development environment."),new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=c=>{if(c.source===S||!c.data||typeof c.data!="object"||!("type"in c.data)||c.data.type!=="client"&&c.data.type!=="bridge")return;let l;if(c.data.type==="client"){const u=this._messageInterceptors.get(c.data.name);if(!u){m(c.data);return}l={...u(c.data.data),type:"bridge",...c.data.responseName?{name:c.data.responseName}:{}}}if(!l){const u=O.safeParse(c.data);if(!u.success)return;l=u.data;const h=this._onHandlers.get(l.name),d=this._onceHandlers.get(l.name);if(h)for(const f of h)f(l.data);if(d){for(const f of d)f(l.data);this._onceHandlers.delete(l.name)}}if(!C)for(let u=0;u<window.frames.length;u+=1)window.frames[u].postMessage(l,"*")},S.addEventListener("message",this._windowMessageHandler),this._navigation.bind()}unbind(){this._windowMessageHandler&&(this._navigation.unbind(),S.removeEventListener("message",this._windowMessageHandler))}send(e,t){const s=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});m(s)}request(e,t,s){var n;const i=I(),a=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:i});m(a);const c=(n=s==null?void 0:s.timeout)!==null&&n!==void 0?n:y;let l=!1,u;const h=new Promise(f=>{u=g=>{l||f(g)},this.once(i,u)});if(c===0)return h;const d=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${i} timed out after ${c}`);setTimeout(()=>{l=!0,this.off(i,u),g(w)},c)});return Promise.race([d,h])}async subscribe(e,t,s){let n,i;typeof t=="function"?i=t:(n=t,i=s);const a=I(),c=I();let l=this._subscriptionNamesBySubjectName.get(e);l||(l=[],this._subscriptionNamesBySubjectName.set(e,l)),l.push(a),this._subscriptionNamesByHandler.set(i,a),this.on(a,i);const u=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:n,responseName:c,subscriptionName:a});m(u);let h=!1,d;const f=new Promise((w,_)=>{const b=new Error(`${e} subscribe request with subscription name of ${a} and response name of ${c} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(c,d),_(b)},y)}),g=new Promise(w=>{d=_=>{h||w(_)},this.once(c,d)});return Promise.race([f,g])}async unsubscribe(e,t,s){let n,i;typeof t=="function"?i=t:(n=t,i=s);const a=I();let c=[];if(i){const l=this._subscriptionNamesByHandler.get(i);if(!l)return{success:!1};c=[l],this._subscriptionNamesByHandler.delete(i)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const l of c){this.off(l,i);const u=N({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationSpecifier:this._applicationSpecifier,name:e,data:n,responseName:a,unsubscribeName:l});m(u);let h=!1,d;const f=new Promise((_,b)=>{const U=new Error(`${e} unsubscribe request with unsubscribe name of ${l} and response name of ${a} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(a,d),b(U)},y)}),g=new Promise(_=>{d=b=>{h||_(b)},this.once(a,d)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const n=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];n.length===0&&this._onHandlers.set(e,n),n.push(t)}once(e,t){var s;const n=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];n.length===0&&this._onceHandlers.set(e,n),n.push(t)}off(e,t){const s=this._onHandlers.get(e),n=this._onceHandlers.get(e);if(!(!s&&!n)){if(s){for(let i=0;i<s.length;i+=1)t&&s[i]!==t||(s.splice(i,1),i-=1);s.length===0&&this._onHandlers.delete(e)}if(n){for(let i=0;i<n.length;i+=1)t&&n[i]!==t||(n.splice(i,1),i-=1);n.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=V.version;let r=null;function G(){return r}function J(o){D(),r=new j,r.bind()}function D(){r==null||r.unbind(),r=null}function K(...o){return p(r),r.on(...o)}function z(...o){return p(r),r.once(...o)}function X(...o){return p(r),r.off(...o)}function Y(...o){return p(r),r.send(...o)}function Z(...o){return p(r),r.request(...o)}function ee(...o){return p(r),r.subscribe(...o)}function te(...o){return p(r),r.unsubscribe(...o)}function se(){return p(r),r.store}function ne(){return p(r),r.applications}function ie(){return p(r),r.media}function re(){return p(r),r.accounts}function oe(){return p(r),r.users}function ae(){return p(r),r.devices}function ce(){return p(r),r.proxy}function le(){return p(r),r.rootSettingsNavigation}function ue(){return p(r),r.weather}function he(){return p(r),r.currency}function de(){return p(r),r.environment}function pe(){return p(r),r.mqtt}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=E;exports.Applications=P;exports.Client=j;exports.Currency=$;exports.Devices=T;exports.Environment=k;exports.Media=M;exports.Mqtt=L;exports.Navigation=x;exports.Proxy=F;exports.Store=A;exports.StoreSlice=v;exports.Users=R;exports.Weather=B;exports.accounts=re;exports.applications=ne;exports.configure=J;exports.currency=he;exports.destroy=D;exports.devices=ae;exports.environment=de;exports.globalClient=G;exports.media=ie;exports.mqtt=pe;exports.off=X;exports.on=K;exports.once=z;exports.proxy=ce;exports.request=Z;exports.rootSettingsNavigation=le;exports.send=Y;exports.store=se;exports.subscribe=ee;exports.telemetrySdkVersion=q;exports.unsubscribe=te;exports.users=oe;exports.weather=ue;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export type { CitiesSearchParams, DailyForecast, DailyForecastData, DailyForecas
12
12
  export { Currency } from './currency.js';
13
13
  export type { CurrencySymbols, CurrencyRates, CurrencyRatesParams } from './currency.js';
14
14
  export { Mqtt } from './mqtt.js';
15
+ export { Navigation } from './navigation.js';
15
16
  export type { MqttBrokerInfo, MqttConnectOptions, MqttPublishOptions, MqttSubscribeOptions, MqttConnectionStatus, MqttMessage, } from './mqtt.js';
16
17
  import { Client } from './client.js';
17
18
  export { Client, type SubscriptionResult, type MessageHandler } from './client.js';
@@ -41,10 +42,8 @@ export declare function globalClient(): Client | null;
41
42
  * This function must be called before using any other exported functions that depend on the global client.
42
43
  * The exported convenience functions (send, request, store, etc.) use this global instance internally,
43
44
  * simplifying integration for applications that don't require multiple client instances.
44
- *
45
- * @param applicationName The name of your application - must match the 'name' property in your application's telemetry.config.json file
46
45
  */
47
- export declare function configure(applicationName: string): void;
46
+ export declare function configure(_applicationName?: string): void;
48
47
  /**
49
48
  * Destroys the SDK by unbinding event listeners and clearing the global client instance.
50
49
  *
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { o as C, a as H, s as M, l as P } from "./types-CCzf8sMT.js";
2
- const F = "1.12.0", k = {
3
- version: F
1
+ import { o as C, a as P, s as T, l as k } from "./types-CCzf8sMT.js";
2
+ const M = "1.13.1", F = {
3
+ version: M
4
4
  };
5
- class A {
5
+ class R {
6
6
  constructor(e) {
7
7
  this._client = e;
8
8
  }
@@ -21,7 +21,7 @@ class A {
21
21
  return e.account;
22
22
  }
23
23
  }
24
- class B {
24
+ class A {
25
25
  constructor(e) {
26
26
  this._client = e;
27
27
  }
@@ -116,7 +116,7 @@ class B {
116
116
  this._client._messageInterceptors.set(e, t);
117
117
  }
118
118
  }
119
- class $ {
119
+ class B {
120
120
  constructor(e) {
121
121
  this._client = e;
122
122
  }
@@ -160,7 +160,7 @@ class $ {
160
160
  return e.capabilities;
161
161
  }
162
162
  }
163
- class R {
163
+ class $ {
164
164
  constructor(e) {
165
165
  this._client = e;
166
166
  }
@@ -174,7 +174,7 @@ class R {
174
174
  return (await this._client.unsubscribe("environment.unsubscribeColorScheme", {}, e)).success;
175
175
  }
176
176
  }
177
- class x {
177
+ class L {
178
178
  constructor(e) {
179
179
  this._client = e;
180
180
  }
@@ -233,14 +233,14 @@ class x {
233
233
  })).selection;
234
234
  }
235
235
  }
236
- class j {
236
+ class x {
237
237
  constructor(e) {
238
238
  this._client = e;
239
239
  }
240
240
  async fetch(e, t) {
241
241
  var s;
242
- let r;
243
- typeof e == "string" ? r = e : e instanceof URL ? r = e.toString() : (r = e.url, t || (t = {
242
+ let n;
243
+ typeof e == "string" ? n = e : e instanceof URL ? n = e.toString() : (n = e.url, t || (t = {
244
244
  method: e.method,
245
245
  headers: e.headers,
246
246
  body: e.body,
@@ -250,39 +250,39 @@ class j {
250
250
  referrer: e.referrer,
251
251
  integrity: e.integrity
252
252
  }));
253
- let n = {};
254
- t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h, l) => {
255
- n[l] = h;
256
- }) : Array.isArray(t.headers) ? t.headers.forEach(([h, l]) => {
257
- n[h] = l;
258
- }) : n = t.headers);
253
+ let i = {};
254
+ t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h, d) => {
255
+ i[d] = h;
256
+ }) : Array.isArray(t.headers) ? t.headers.forEach(([h, d]) => {
257
+ i[h] = d;
258
+ }) : i = t.headers);
259
259
  const o = await this._client.request("proxy.fetch", {
260
- url: r,
260
+ url: n,
261
261
  method: (t == null ? void 0 : t.method) || "GET",
262
- headers: n,
262
+ headers: i,
263
263
  body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
264
264
  });
265
265
  if (!o.success)
266
266
  throw new TypeError(o.errorMessage, {
267
267
  cause: o.errorCause ? Error(o.errorCause) : void 0
268
268
  });
269
- const u = new Headers(o.headers), a = {
269
+ const c = new Headers(o.headers), l = {
270
270
  status: o.status,
271
271
  statusText: o.statusText,
272
- headers: u
272
+ headers: c
273
273
  };
274
- let p = null;
274
+ let u = null;
275
275
  if (o.body !== null && o.body !== void 0)
276
276
  if (o.bodyType === "binary") {
277
- const h = atob(o.body), l = new Uint8Array(h.length);
277
+ const h = atob(o.body), d = new Uint8Array(h.length);
278
278
  for (let f = 0; f < h.length; f++)
279
- l[f] = h.charCodeAt(f);
280
- p = l;
281
- } else o.bodyType === "text" ? p = o.body : o.bodyType === "json" && (p = JSON.stringify(o.body));
282
- return new Response(p, a);
279
+ d[f] = h.charCodeAt(f);
280
+ u = d;
281
+ } else o.bodyType === "text" ? u = o.body : o.bodyType === "json" && (u = JSON.stringify(o.body));
282
+ return new Response(u, l);
283
283
  }
284
284
  }
285
- class D {
285
+ class j {
286
286
  constructor(e) {
287
287
  this._client = e;
288
288
  }
@@ -296,7 +296,7 @@ class D {
296
296
  * @returns A StoreSlice instance for the application scope
297
297
  */
298
298
  get application() {
299
- return new S("application", "", this._client);
299
+ return new S("application", void 0, this._client);
300
300
  }
301
301
  /**
302
302
  * Provides access to the instance store scope.
@@ -305,8 +305,6 @@ class D {
305
305
  * application. This is ideal for instance-specific settings, UI state, temporary data,
306
306
  * or any information that shouldn't be shared with other instances.
307
307
  *
308
- * The namespace for instance data includes both the application name and the instance ID.
309
- *
310
308
  * @returns A StoreSlice instance for the instance scope
311
309
  */
312
310
  get instance() {
@@ -325,7 +323,7 @@ class D {
325
323
  * @returns A StoreSlice instance for the device scope
326
324
  */
327
325
  get device() {
328
- return new S("device", this._client.applicationInstance, this._client);
326
+ return new S("device", this._client.deviceId, this._client);
329
327
  }
330
328
  /**
331
329
  * Provides access to the shared store scope with a specified namespace.
@@ -438,7 +436,7 @@ class S {
438
436
  })).success;
439
437
  }
440
438
  }
441
- class Q {
439
+ class D {
442
440
  constructor(e) {
443
441
  this._client = e;
444
442
  }
@@ -461,7 +459,7 @@ class Q {
461
459
  return e.user;
462
460
  }
463
461
  }
464
- class L {
462
+ class Q {
465
463
  constructor(e) {
466
464
  this._client = e;
467
465
  }
@@ -644,11 +642,11 @@ class U {
644
642
  * ```
645
643
  */
646
644
  async getRates(e) {
647
- var t, s, r;
648
- const n = await this._client.request("currency.getRates", e);
649
- if (!n.success || !n.rates)
650
- throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((r = n.error) === null || r === void 0 ? void 0 : r.message) || "Failed to fetch currency rates");
651
- return n.rates;
645
+ var t, s, n;
646
+ const i = await this._client.request("currency.getRates", e);
647
+ if (!i.success || !i.rates)
648
+ throw ((t = i.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = i.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((n = i.error) === null || n === void 0 ? void 0 : n.message) || "Failed to fetch currency rates");
649
+ return i.rates;
652
650
  }
653
651
  }
654
652
  class V {
@@ -674,20 +672,20 @@ class V {
674
672
  if (!(await this._client.request("mqtt.disconnect", { clientId: e })).success)
675
673
  throw new Error("Failed to disconnect from MQTT broker");
676
674
  }
677
- async publish(e, t, s, r) {
675
+ async publish(e, t, s, n) {
678
676
  if (!(await this._client.request("mqtt.publish", {
679
677
  clientId: e,
680
678
  topic: t,
681
679
  payload: s,
682
- ...r
680
+ ...n
683
681
  })).success)
684
682
  throw new Error("Failed to publish MQTT message");
685
683
  }
686
- async subscribe(e, t, s, r) {
684
+ async subscribe(e, t, s, n) {
687
685
  return (await this._client.subscribe("mqtt.subscribe", {
688
686
  clientId: e,
689
687
  topic: t,
690
- ...r
688
+ ...n
691
689
  }, s)).success;
692
690
  }
693
691
  async unsubscribe(e, t, s) {
@@ -715,13 +713,33 @@ class V {
715
713
  }, t)).success;
716
714
  }
717
715
  }
718
- function q(c) {
719
- return { ...c, type: "client" };
716
+ class O {
717
+ constructor(e) {
718
+ this._originalPushState = null, this._originalReplaceState = null, this._popstateHandler = null, this._backHandler = null, this._forwardHandler = null, this._client = e;
719
+ }
720
+ bind() {
721
+ typeof window > "u" || this._originalPushState || (this._originalPushState = history.pushState.bind(history), history.pushState = (...e) => {
722
+ this._originalPushState(...e), this._sendLocationChanged();
723
+ }, this._originalReplaceState = history.replaceState.bind(history), history.replaceState = (...e) => {
724
+ this._originalReplaceState(...e), this._sendLocationChanged();
725
+ }, this._popstateHandler = () => this._sendLocationChanged(), window.addEventListener("popstate", this._popstateHandler), this._backHandler = () => history.back(), this._forwardHandler = () => history.forward(), this._client.on("navigation.back", this._backHandler), this._client.on("navigation.forward", this._forwardHandler), this._sendLocationChanged());
726
+ }
727
+ unbind() {
728
+ typeof window > "u" || (this._originalPushState && (history.pushState = this._originalPushState, this._originalPushState = null), this._originalReplaceState && (history.replaceState = this._originalReplaceState, this._originalReplaceState = null), this._popstateHandler && (window.removeEventListener("popstate", this._popstateHandler), this._popstateHandler = null), this._backHandler && (this._client.off("navigation.back", this._backHandler), this._backHandler = null), this._forwardHandler && (this._client.off("navigation.forward", this._forwardHandler), this._forwardHandler = null));
729
+ }
730
+ _sendLocationChanged() {
731
+ this._client.send("navigation.locationChanged", {
732
+ pathname: window.location.pathname
733
+ });
734
+ }
735
+ }
736
+ function q(a) {
737
+ return { ...a, type: "client" };
720
738
  }
721
739
  const W = C({
722
- type: P("bridge"),
723
- name: M(),
724
- data: H()
740
+ type: k("bridge"),
741
+ name: T(),
742
+ data: P()
725
743
  });
726
744
  class G {
727
745
  /**
@@ -747,11 +765,11 @@ class G {
747
765
  */
748
766
  async setRootSettingsNavigation(e) {
749
767
  var t;
750
- const s = this._store.shared("root-settings-navigation"), r = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, n = this._store._client._applicationSpecifier;
751
- r[n] = {
752
- applicationSpecifier: n,
768
+ const s = this._store.shared("root-settings-navigation"), n = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, i = this._store._client._applicationSpecifier;
769
+ n[i] = {
770
+ applicationSpecifier: i,
753
771
  entries: e.entries
754
- }, s.set("navigation", r);
772
+ }, s.set("navigation", n);
755
773
  }
756
774
  /**
757
775
  * Retrieves the current navigation entries for this root application.
@@ -763,8 +781,8 @@ class G {
763
781
  */
764
782
  async getRootSettingsNavigation() {
765
783
  var e;
766
- const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, r = this._store._client._applicationSpecifier;
767
- return s[r];
784
+ const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, n = this._store._client._applicationSpecifier;
785
+ return s[n];
768
786
  }
769
787
  /**
770
788
  * Retrieves the navigation entries for all root applications.
@@ -780,9 +798,9 @@ class G {
780
798
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
781
799
  }
782
800
  }
783
- const b = 1e3 * 30, I = typeof window > "u" && typeof self < "u", v = I ? self : window;
784
- function y(c) {
785
- I ? self.postMessage(c) : v.parent.postMessage(c, "*");
801
+ const m = 1e3 * 30, N = typeof window > "u" && typeof self < "u", v = N ? self : window;
802
+ function y(a) {
803
+ N ? self.postMessage(a) : v.parent.postMessage(a, "*");
786
804
  }
787
805
  class J {
788
806
  /**
@@ -791,12 +809,9 @@ class J {
791
809
  * Note that creating a Client instance alone is not sufficient to begin communication.
792
810
  * You must also call the bind() method to initialize event listeners and extract
793
811
  * the application ID from the URL.
794
- *
795
- * @param applicationName The name of your application - must match the 'name' property
796
- * in your application's telemetry.config.json file
797
812
  */
798
- constructor(e) {
799
- 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();
813
+ constructor() {
814
+ this._applicationInstance = "", this._applicationSpecifier = "", this._deviceId = "", this._navigation = new O(this), 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();
800
815
  }
801
816
  /**
802
817
  * Provides access to the accounts API for retrieving TelemetryOS account information.
@@ -810,7 +825,7 @@ class J {
810
825
  * @returns An Accounts instance bound to this client
811
826
  */
812
827
  get accounts() {
813
- return new A(this);
828
+ return new R(this);
814
829
  }
815
830
  /**
816
831
  * Provides access to the users API for retrieving TelemetryOS user information.
@@ -824,7 +839,7 @@ class J {
824
839
  * @returns A Users instance bound to this client
825
840
  */
826
841
  get users() {
827
- return new Q(this);
842
+ return new D(this);
828
843
  }
829
844
  /**
830
845
  * Provides access to the store API for data persistence with multiple storage scopes.
@@ -838,7 +853,7 @@ class J {
838
853
  * @returns A Store instance bound to this client
839
854
  */
840
855
  get store() {
841
- return new D(this);
856
+ return new j(this);
842
857
  }
843
858
  /**
844
859
  * Provides access to the applications API for discovering other TelemetryOS applications.
@@ -852,7 +867,7 @@ class J {
852
867
  * @returns An Applications instance bound to this client
853
868
  */
854
869
  get applications() {
855
- return new B(this);
870
+ return new A(this);
856
871
  }
857
872
  /**
858
873
  * Provides access to the media API for working with content hosted on the TelemetryOS platform.
@@ -867,7 +882,7 @@ class J {
867
882
  * @returns A Media instance bound to this client
868
883
  */
869
884
  get media() {
870
- return new x(this);
885
+ return new L(this);
871
886
  }
872
887
  /**
873
888
  * Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
@@ -881,7 +896,7 @@ class J {
881
896
  * @returns A Proxy instance bound to this client
882
897
  */
883
898
  get proxy() {
884
- return new j(this);
899
+ return new x(this);
885
900
  }
886
901
  /**
887
902
  * Provides access to the devices API for interacting with the current device.
@@ -896,7 +911,7 @@ class J {
896
911
  * @returns A Devices instance bound to this client
897
912
  */
898
913
  get devices() {
899
- return new $(this);
914
+ return new B(this);
900
915
  }
901
916
  /**
902
917
  * Provides access to the root settings navigation API for TelemetryOS administration UI integration.
@@ -928,7 +943,7 @@ class J {
928
943
  * @returns A Weather instance bound to this client
929
944
  */
930
945
  get weather() {
931
- return new L(this);
946
+ return new Q(this);
932
947
  }
933
948
  /**
934
949
  * Provides access to the currency API for retrieving currency exchange rates.
@@ -956,20 +971,20 @@ class J {
956
971
  * @returns An Environment instance bound to this client
957
972
  */
958
973
  get environment() {
959
- return new R(this);
974
+ return new $(this);
960
975
  }
961
976
  get mqtt() {
962
977
  return new V(this);
963
978
  }
964
- get applicationName() {
965
- return this._applicationName;
966
- }
967
979
  get applicationSpecifier() {
968
980
  return this._applicationSpecifier;
969
981
  }
970
982
  get applicationInstance() {
971
983
  return this._applicationInstance;
972
984
  }
985
+ get deviceId() {
986
+ return this._deviceId;
987
+ }
973
988
  /**
974
989
  * Initializes the client by setting up message listeners and extracting the application ID.
975
990
  *
@@ -986,47 +1001,47 @@ class J {
986
1001
  * of creating and binding their own Client instances.
987
1002
  */
988
1003
  bind() {
989
- var e, t, s;
990
- const r = new URL(v.location.href), n = r.searchParams;
991
- if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
992
- throw new Error("Missing applicationInstance query parameter");
993
- if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
994
- const o = r.hostname.split(".");
995
- this._applicationSpecifier = (s = o[0]) !== null && s !== void 0 ? s : "";
996
- }
997
- if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
998
- throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
999
- this._windowMessageHandler = (o) => {
1000
- if (o.source === v || !o.data || typeof o.data != "object" || !("type" in o.data) || o.data.type !== "client" && o.data.type !== "bridge")
1004
+ var e, t;
1005
+ const s = new URL(v.location.href), n = s.searchParams;
1006
+ this._applicationInstance = n.get("applicationInstance") || "single", this._deviceId = n.get("deviceId") || this._applicationInstance;
1007
+ const i = s.hostname.split("."), o = /^[a-f0-9]{40}$/i;
1008
+ if (this._applicationSpecifier = (e = n.get("applicationSpecifier")) !== null && e !== void 0 ? e : "", (!this._applicationSpecifier || !o.test(this._applicationSpecifier)) && (this._applicationSpecifier = (t = i[0]) !== null && t !== void 0 ? t : ""), !this._applicationSpecifier || !o.test(this._applicationSpecifier))
1009
+ throw console.error("TelemetryOS apps require an applicationSpecifier in the URL query parameters or subdomain. Make sure your app is being served correctly through the TelemetryOS platform or development environment."), new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
1010
+ this._windowMessageHandler = (c) => {
1011
+ if (c.source === v || !c.data || typeof c.data != "object" || !("type" in c.data) || c.data.type !== "client" && c.data.type !== "bridge")
1001
1012
  return;
1002
- let u;
1003
- if (o.data.type === "client") {
1004
- const a = this._messageInterceptors.get(o.data.name);
1005
- if (!a) {
1006
- y(o.data);
1013
+ let l;
1014
+ if (c.data.type === "client") {
1015
+ const u = this._messageInterceptors.get(c.data.name);
1016
+ if (!u) {
1017
+ y(c.data);
1007
1018
  return;
1008
1019
  }
1009
- u = { ...a(o.data.data), type: "bridge" };
1020
+ l = {
1021
+ ...u(c.data.data),
1022
+ type: "bridge",
1023
+ ...c.data.responseName ? { name: c.data.responseName } : {}
1024
+ };
1010
1025
  }
1011
- if (!u) {
1012
- const a = W.safeParse(o.data);
1013
- if (!a.success)
1026
+ if (!l) {
1027
+ const u = W.safeParse(c.data);
1028
+ if (!u.success)
1014
1029
  return;
1015
- u = a.data;
1016
- const p = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
1017
- if (p)
1018
- for (const l of p)
1019
- l(u.data);
1020
- if (h) {
1021
- for (const l of h)
1022
- l(u.data);
1023
- this._onceHandlers.delete(u.name);
1030
+ l = u.data;
1031
+ const h = this._onHandlers.get(l.name), d = this._onceHandlers.get(l.name);
1032
+ if (h)
1033
+ for (const f of h)
1034
+ f(l.data);
1035
+ if (d) {
1036
+ for (const f of d)
1037
+ f(l.data);
1038
+ this._onceHandlers.delete(l.name);
1024
1039
  }
1025
1040
  }
1026
- if (!I)
1027
- for (let a = 0; a < window.frames.length; a += 1)
1028
- window.frames[a].postMessage(u, "*");
1029
- }, v.addEventListener("message", this._windowMessageHandler);
1041
+ if (!N)
1042
+ for (let u = 0; u < window.frames.length; u += 1)
1043
+ window.frames[u].postMessage(l, "*");
1044
+ }, v.addEventListener("message", this._windowMessageHandler), this._navigation.bind();
1030
1045
  }
1031
1046
  /**
1032
1047
  * Removes the message event listener and cleans up resources.
@@ -1042,7 +1057,7 @@ class J {
1042
1057
  * of managing their own Client instances.
1043
1058
  */
1044
1059
  unbind() {
1045
- this._windowMessageHandler && v.removeEventListener("message", this._windowMessageHandler);
1060
+ this._windowMessageHandler && (this._navigation.unbind(), v.removeEventListener("message", this._windowMessageHandler));
1046
1061
  }
1047
1062
  /**
1048
1063
  * Sends a one-way message to the TelemetryOS platform.
@@ -1059,8 +1074,7 @@ class J {
1059
1074
  */
1060
1075
  send(e, t) {
1061
1076
  const s = q({
1062
- telemetrySdkVersion: E,
1063
- applicationName: this._applicationName,
1077
+ telemetrySdkVersion: I,
1064
1078
  applicationSpecifier: this._applicationSpecifier,
1065
1079
  applicationInstance: this._applicationInstance,
1066
1080
  name: e,
@@ -1088,99 +1102,96 @@ class J {
1088
1102
  * @throws {Error} If the request times out
1089
1103
  */
1090
1104
  request(e, t, s) {
1091
- var r;
1092
- const n = N(), o = q({
1093
- telemetrySdkVersion: E,
1094
- applicationName: this._applicationName,
1105
+ var n;
1106
+ const i = H(), o = q({
1107
+ telemetrySdkVersion: I,
1095
1108
  applicationSpecifier: this._applicationSpecifier,
1096
1109
  applicationInstance: this._applicationInstance,
1097
1110
  name: e,
1098
1111
  data: t,
1099
- responseName: n
1112
+ responseName: i
1100
1113
  });
1101
1114
  y(o);
1102
- const u = (r = s == null ? void 0 : s.timeout) !== null && r !== void 0 ? r : b;
1103
- let a = !1, p;
1115
+ const c = (n = s == null ? void 0 : s.timeout) !== null && n !== void 0 ? n : m;
1116
+ let l = !1, u;
1104
1117
  const h = new Promise((f) => {
1105
- p = (g) => {
1106
- a || f(g);
1107
- }, this.once(n, p);
1118
+ u = (g) => {
1119
+ l || f(g);
1120
+ }, this.once(i, u);
1108
1121
  });
1109
- if (u === 0)
1122
+ if (c === 0)
1110
1123
  return h;
1111
- const l = new Promise((f, g) => {
1112
- const m = new Error(`${e} message request with response name of ${n} timed out after ${u}`);
1124
+ const d = new Promise((f, g) => {
1125
+ const w = new Error(`${e} message request with response name of ${i} timed out after ${c}`);
1113
1126
  setTimeout(() => {
1114
- a = !0, this.off(n, p), g(m);
1115
- }, u);
1127
+ l = !0, this.off(i, u), g(w);
1128
+ }, c);
1116
1129
  });
1117
- return Promise.race([l, h]);
1130
+ return Promise.race([d, h]);
1118
1131
  }
1119
1132
  async subscribe(e, t, s) {
1120
- let r, n;
1121
- typeof t == "function" ? n = t : (r = t, n = s);
1122
- const o = N(), u = N();
1123
- let a = this._subscriptionNamesBySubjectName.get(e);
1124
- a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(o), this._subscriptionNamesByHandler.set(n, o), this.on(o, n);
1125
- const p = q({
1126
- telemetrySdkVersion: E,
1127
- applicationName: this._applicationName,
1133
+ let n, i;
1134
+ typeof t == "function" ? i = t : (n = t, i = s);
1135
+ const o = H(), c = H();
1136
+ let l = this._subscriptionNamesBySubjectName.get(e);
1137
+ l || (l = [], this._subscriptionNamesBySubjectName.set(e, l)), l.push(o), this._subscriptionNamesByHandler.set(i, o), this.on(o, i);
1138
+ const u = q({
1139
+ telemetrySdkVersion: I,
1128
1140
  applicationSpecifier: this._applicationSpecifier,
1129
1141
  applicationInstance: this._applicationInstance,
1130
1142
  name: e,
1131
- data: r,
1132
- responseName: u,
1143
+ data: n,
1144
+ responseName: c,
1133
1145
  subscriptionName: o
1134
1146
  });
1135
- y(p);
1136
- let h = !1, l;
1137
- const f = new Promise((m, w) => {
1138
- const _ = new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);
1147
+ y(u);
1148
+ let h = !1, d;
1149
+ const f = new Promise((w, _) => {
1150
+ const b = new Error(`${e} subscribe request with subscription name of ${o} and response name of ${c} timed out after ${m}`);
1139
1151
  setTimeout(() => {
1140
- h = !0, this.off(u, l), w(_);
1141
- }, b);
1142
- }), g = new Promise((m) => {
1143
- l = (w) => {
1144
- h || m(w);
1145
- }, this.once(u, l);
1152
+ h = !0, this.off(c, d), _(b);
1153
+ }, m);
1154
+ }), g = new Promise((w) => {
1155
+ d = (_) => {
1156
+ h || w(_);
1157
+ }, this.once(c, d);
1146
1158
  });
1147
1159
  return Promise.race([f, g]);
1148
1160
  }
1149
1161
  async unsubscribe(e, t, s) {
1150
- let r, n;
1151
- typeof t == "function" ? n = t : (r = t, n = s);
1152
- const o = N();
1153
- let u = [];
1154
- if (n) {
1155
- const a = this._subscriptionNamesByHandler.get(n);
1156
- if (!a)
1162
+ let n, i;
1163
+ typeof t == "function" ? i = t : (n = t, i = s);
1164
+ const o = H();
1165
+ let c = [];
1166
+ if (i) {
1167
+ const l = this._subscriptionNamesByHandler.get(i);
1168
+ if (!l)
1157
1169
  return { success: !1 };
1158
- u = [a], this._subscriptionNamesByHandler.delete(n);
1170
+ c = [l], this._subscriptionNamesByHandler.delete(i);
1159
1171
  } else if (!this._subscriptionNamesBySubjectName.get(e))
1160
1172
  return { success: !1 };
1161
- for await (const a of u) {
1162
- this.off(a, n);
1163
- const p = q({
1164
- telemetrySdkVersion: E,
1173
+ for await (const l of c) {
1174
+ this.off(l, i);
1175
+ const u = q({
1176
+ telemetrySdkVersion: I,
1165
1177
  applicationInstance: this._applicationInstance,
1166
- applicationName: this._applicationName,
1167
1178
  applicationSpecifier: this._applicationSpecifier,
1168
1179
  name: e,
1169
- data: r,
1180
+ data: n,
1170
1181
  responseName: o,
1171
- unsubscribeName: a
1182
+ unsubscribeName: l
1172
1183
  });
1173
- y(p);
1174
- let h = !1, l;
1175
- const f = new Promise((w, _) => {
1176
- const T = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);
1184
+ y(u);
1185
+ let h = !1, d;
1186
+ const f = new Promise((_, b) => {
1187
+ const E = new Error(`${e} unsubscribe request with unsubscribe name of ${l} and response name of ${o} timed out after ${m}`);
1177
1188
  setTimeout(() => {
1178
- h = !0, this.off(o, l), _(T);
1179
- }, b);
1180
- }), g = new Promise((w) => {
1181
- l = (_) => {
1182
- h || w(_);
1183
- }, this.once(o, l);
1189
+ h = !0, this.off(o, d), b(E);
1190
+ }, m);
1191
+ }), g = new Promise((_) => {
1192
+ d = (b) => {
1193
+ h || _(b);
1194
+ }, this.once(o, d);
1184
1195
  });
1185
1196
  if (!(await Promise.race([f, g])).success)
1186
1197
  return { success: !1 };
@@ -1206,8 +1217,8 @@ class J {
1206
1217
  */
1207
1218
  on(e, t) {
1208
1219
  var s;
1209
- const r = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
1210
- r.length === 0 && this._onHandlers.set(e, r), r.push(t);
1220
+ const n = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
1221
+ n.length === 0 && this._onHandlers.set(e, n), n.push(t);
1211
1222
  }
1212
1223
  /**
1213
1224
  * Registers a one-time handler for a specific message type.
@@ -1225,8 +1236,8 @@ class J {
1225
1236
  */
1226
1237
  once(e, t) {
1227
1238
  var s;
1228
- const r = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
1229
- r.length === 0 && this._onceHandlers.set(e, r), r.push(t);
1239
+ const n = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
1240
+ n.length === 0 && this._onceHandlers.set(e, n), n.push(t);
1230
1241
  }
1231
1242
  /**
1232
1243
  * Removes previously registered message handlers.
@@ -1244,131 +1255,132 @@ class J {
1244
1255
  * all handlers for this message type will be removed.
1245
1256
  */
1246
1257
  off(e, t) {
1247
- const s = this._onHandlers.get(e), r = this._onceHandlers.get(e);
1248
- if (!(!s && !r)) {
1258
+ const s = this._onHandlers.get(e), n = this._onceHandlers.get(e);
1259
+ if (!(!s && !n)) {
1249
1260
  if (s) {
1250
- for (let n = 0; n < s.length; n += 1)
1251
- t && s[n] !== t || (s.splice(n, 1), n -= 1);
1261
+ for (let i = 0; i < s.length; i += 1)
1262
+ t && s[i] !== t || (s.splice(i, 1), i -= 1);
1252
1263
  s.length === 0 && this._onHandlers.delete(e);
1253
1264
  }
1254
- if (r) {
1255
- for (let n = 0; n < r.length; n += 1)
1256
- t && r[n] !== t || (r.splice(n, 1), n -= 1);
1257
- r.length === 0 && this._onceHandlers.delete(e);
1265
+ if (n) {
1266
+ for (let i = 0; i < n.length; i += 1)
1267
+ t && n[i] !== t || (n.splice(i, 1), i -= 1);
1268
+ n.length === 0 && this._onceHandlers.delete(e);
1258
1269
  }
1259
1270
  }
1260
1271
  }
1261
1272
  }
1262
- function N() {
1273
+ function H() {
1263
1274
  return Math.random().toString(36).slice(2, 9);
1264
1275
  }
1265
- const E = k.version;
1266
- let i = null;
1267
- function O() {
1268
- return i;
1276
+ const I = F.version;
1277
+ let r = null;
1278
+ function X() {
1279
+ return r;
1269
1280
  }
1270
- function z(c) {
1271
- i = new J(c), i.bind();
1281
+ function Y(a) {
1282
+ K(), r = new J(), r.bind();
1272
1283
  }
1273
- function X() {
1274
- i == null || i.unbind(), i = null;
1284
+ function K() {
1285
+ r == null || r.unbind(), r = null;
1275
1286
  }
1276
- function Y(...c) {
1277
- return d(i), i.on(...c);
1287
+ function Z(...a) {
1288
+ return p(r), r.on(...a);
1278
1289
  }
1279
- function Z(...c) {
1280
- return d(i), i.once(...c);
1290
+ function ee(...a) {
1291
+ return p(r), r.once(...a);
1281
1292
  }
1282
- function ee(...c) {
1283
- return d(i), i.off(...c);
1293
+ function te(...a) {
1294
+ return p(r), r.off(...a);
1284
1295
  }
1285
- function te(...c) {
1286
- return d(i), i.send(...c);
1296
+ function se(...a) {
1297
+ return p(r), r.send(...a);
1287
1298
  }
1288
- function se(...c) {
1289
- return d(i), i.request(...c);
1299
+ function ne(...a) {
1300
+ return p(r), r.request(...a);
1290
1301
  }
1291
- function ne(...c) {
1292
- return d(i), i.subscribe(...c);
1302
+ function ie(...a) {
1303
+ return p(r), r.subscribe(...a);
1293
1304
  }
1294
- function re(...c) {
1295
- return d(i), i.unsubscribe(...c);
1305
+ function re(...a) {
1306
+ return p(r), r.unsubscribe(...a);
1296
1307
  }
1297
- function ie() {
1298
- return d(i), i.store;
1308
+ function ae() {
1309
+ return p(r), r.store;
1299
1310
  }
1300
1311
  function oe() {
1301
- return d(i), i.applications;
1312
+ return p(r), r.applications;
1302
1313
  }
1303
1314
  function ce() {
1304
- return d(i), i.media;
1315
+ return p(r), r.media;
1305
1316
  }
1306
- function ae() {
1307
- return d(i), i.accounts;
1317
+ function le() {
1318
+ return p(r), r.accounts;
1308
1319
  }
1309
1320
  function ue() {
1310
- return d(i), i.users;
1311
- }
1312
- function le() {
1313
- return d(i), i.devices;
1321
+ return p(r), r.users;
1314
1322
  }
1315
1323
  function he() {
1316
- return d(i), i.proxy;
1324
+ return p(r), r.devices;
1317
1325
  }
1318
1326
  function de() {
1319
- return d(i), i.rootSettingsNavigation;
1327
+ return p(r), r.proxy;
1320
1328
  }
1321
1329
  function pe() {
1322
- return d(i), i.weather;
1330
+ return p(r), r.rootSettingsNavigation;
1323
1331
  }
1324
1332
  function fe() {
1325
- return d(i), i.currency;
1333
+ return p(r), r.weather;
1326
1334
  }
1327
1335
  function ge() {
1328
- return d(i), i.environment;
1336
+ return p(r), r.currency;
1337
+ }
1338
+ function _e() {
1339
+ return p(r), r.environment;
1329
1340
  }
1330
1341
  function we() {
1331
- return d(i), i.mqtt;
1342
+ return p(r), r.mqtt;
1332
1343
  }
1333
- function d(c) {
1334
- if (!c)
1344
+ function p(a) {
1345
+ if (!a)
1335
1346
  throw new Error("SDK is not configured");
1336
1347
  }
1337
1348
  export {
1338
- A as Accounts,
1339
- B as Applications,
1349
+ R as Accounts,
1350
+ A as Applications,
1340
1351
  J as Client,
1341
1352
  U as Currency,
1342
- $ as Devices,
1343
- R as Environment,
1344
- x as Media,
1353
+ B as Devices,
1354
+ $ as Environment,
1355
+ L as Media,
1345
1356
  V as Mqtt,
1346
- j as Proxy,
1347
- D as Store,
1357
+ O as Navigation,
1358
+ x as Proxy,
1359
+ j as Store,
1348
1360
  S as StoreSlice,
1349
- Q as Users,
1350
- L as Weather,
1351
- ae as accounts,
1361
+ D as Users,
1362
+ Q as Weather,
1363
+ le as accounts,
1352
1364
  oe as applications,
1353
- z as configure,
1354
- fe as currency,
1355
- X as destroy,
1356
- le as devices,
1357
- ge as environment,
1358
- O as globalClient,
1365
+ Y as configure,
1366
+ ge as currency,
1367
+ K as destroy,
1368
+ he as devices,
1369
+ _e as environment,
1370
+ X as globalClient,
1359
1371
  ce as media,
1360
1372
  we as mqtt,
1361
- ee as off,
1362
- Y as on,
1363
- Z as once,
1364
- he as proxy,
1365
- se as request,
1366
- de as rootSettingsNavigation,
1367
- te as send,
1368
- ie as store,
1369
- ne as subscribe,
1370
- E as telemetrySdkVersion,
1373
+ te as off,
1374
+ Z as on,
1375
+ ee as once,
1376
+ de as proxy,
1377
+ ne as request,
1378
+ pe as rootSettingsNavigation,
1379
+ se as send,
1380
+ ae as store,
1381
+ ie as subscribe,
1382
+ I as telemetrySdkVersion,
1371
1383
  re as unsubscribe,
1372
1384
  ue as users,
1373
- pe as weather
1385
+ fe as weather
1374
1386
  };
@@ -0,0 +1,13 @@
1
+ import { Client } from './client.js';
2
+ export declare class Navigation {
3
+ private _client;
4
+ private _originalPushState;
5
+ private _originalReplaceState;
6
+ private _popstateHandler;
7
+ private _backHandler;
8
+ private _forwardHandler;
9
+ constructor(client: Client);
10
+ bind(): void;
11
+ unbind(): void;
12
+ private _sendLocationChanged;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/store.d.ts CHANGED
@@ -19,8 +19,6 @@ export declare class Store {
19
19
  * application. This is ideal for instance-specific settings, UI state, temporary data,
20
20
  * or any information that shouldn't be shared with other instances.
21
21
  *
22
- * The namespace for instance data includes both the application name and the instance ID.
23
- *
24
22
  * @returns A StoreSlice instance for the instance scope
25
23
  */
26
24
  get instance(): StoreSlice;
@@ -64,9 +62,9 @@ export declare class Store {
64
62
  */
65
63
  export declare class StoreSlice {
66
64
  _kind: string;
67
- _namespace: string;
65
+ _namespace: string | undefined;
68
66
  _client: Client;
69
- constructor(kind: string, namespace: string, client: Client);
67
+ constructor(kind: string, namespace: string | undefined, client: Client);
70
68
  /**
71
69
  * Saves a value in the store.
72
70
  *
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.13.1",
4
4
  "description": "The official TelemetryOS root application sdk package. Provides types and apis for building root TelemetryOS applications.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",