@telemetryos/root-sdk 1.13.0 → 1.13.2

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,19 @@
1
1
  # @telemetryos/root-sdk
2
2
 
3
+ ## 1.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Widen applicationSpecifier pattern to accept dev specifiers
8
+
9
+ ## 1.13.1
10
+
11
+ ### Patch Changes
12
+
13
+ - - **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.
14
+ - **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.
15
+ - **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.
16
+
3
17
  ## 1.13.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -340,6 +340,16 @@ alerts.alerts.forEach(alert => {
340
340
 
341
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
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
+
343
353
  ### Currency API
344
354
 
345
355
  Access currency exchange rates and symbols:
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
@@ -76,9 +76,9 @@ export type MessageInterceptor = (data: any) => BridgeMessage;
76
76
  * when an application needs to manage multiple independent communication channels.
77
77
  */
78
78
  export declare class Client {
79
- _applicationName: string;
80
79
  _applicationInstance: string;
81
80
  _applicationSpecifier: string;
81
+ _deviceId: string;
82
82
  _navigation: Navigation;
83
83
  _messageInterceptors: Map<string, MessageInterceptor>;
84
84
  _onHandlers: Map<string, MessageHandler<any>[]>;
@@ -92,11 +92,8 @@ export declare class Client {
92
92
  * Note that creating a Client instance alone is not sufficient to begin communication.
93
93
  * You must also call the bind() method to initialize event listeners and extract
94
94
  * the application ID from the URL.
95
- *
96
- * @param applicationName The name of your application - must match the 'name' property
97
- * in your application's telemetry.config.json file
98
95
  */
99
- constructor(applicationName: string);
96
+ constructor();
100
97
  /**
101
98
  * Provides access to the accounts API for retrieving TelemetryOS account information.
102
99
  *
@@ -236,9 +233,9 @@ export declare class Client {
236
233
  */
237
234
  get environment(): Environment;
238
235
  get mqtt(): Mqtt;
239
- get applicationName(): string;
240
236
  get applicationSpecifier(): string;
241
237
  get applicationInstance(): string;
238
+ get deviceId(): string;
242
239
  /**
243
240
  * Initializes the client by setting up message listeners and extracting the application ID.
244
241
  *
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.13.0",U={version:Q};class I{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 M{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 k{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 i;typeof e=="string"?i=e:e instanceof URL?i=e.toString():(i=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,u)=>{n[u]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,u])=>{n[h]=u}):n=t.headers);const a=await this._client.request("proxy.fetch",{url:i,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(!a.success)throw new TypeError(a.errorMessage,{cause:a.errorCause?Error(a.errorCause):void 0});const l=new Headers(a.headers),c={status:a.status,statusText:a.statusText,headers:l};let p=null;if(a.body!==null&&a.body!==void 0)if(a.bodyType==="binary"){const h=atob(a.body),u=new Uint8Array(h.length);for(let f=0;f<h.length;f++)u[f]=h.charCodeAt(f);p=u}else a.bodyType==="text"?p=a.body:a.bodyType==="json"&&(p=JSON.stringify(a.body));return new Response(p,c)}}class A{constructor(e){this._client=e}get application(){return new v("application","",this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.applicationInstance,this._client)}shared(e){return new v("shared",e,this._client)}}class v{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class 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,i;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(((i=n.error)===null||i===void 0?void 0:i.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,i){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...i})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,i){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...i},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 L{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 H(o){return{...o,type:"client"}}const V=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.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"),i=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;i[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",i)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},i=this._store._client._applicationSpecifier;return s[i]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const m=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function y(o){C?self.postMessage(o):S.parent.postMessage(o,"*")}class j{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._navigation=new L(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 I(this)}get users(){return new R(this)}get store(){return new A(this)}get applications(){return new P(this)}get media(){return new k(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 M(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 i=new URL(S.location.href),n=i.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 a=i.hostname.split(".");this._applicationSpecifier=(s=a[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=a=>{if(a.source===S||!a.data||typeof a.data!="object"||!("type"in a.data)||a.data.type!=="client"&&a.data.type!=="bridge")return;let l;if(a.data.type==="client"){const c=this._messageInterceptors.get(a.data.name);if(!c){y(a.data);return}l={...c(a.data.data),type:"bridge",...a.data.responseName?{name:a.data.responseName}:{}}}if(!l){const c=V.safeParse(a.data);if(!c.success)return;l=c.data;const p=this._onHandlers.get(l.name),h=this._onceHandlers.get(l.name);if(p)for(const u of p)u(l.data);if(h){for(const u of h)u(l.data);this._onceHandlers.delete(l.name)}}if(!C)for(let c=0;c<window.frames.length;c+=1)window.frames[c].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=H({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t,s){var i;const n=E(),a=H({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});y(a);const l=(i=s==null?void 0:s.timeout)!==null&&i!==void 0?i:m;let c=!1,p;const h=new Promise(f=>{p=g=>{c||f(g)},this.once(n,p)});if(l===0)return h;const u=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${l}`);setTimeout(()=>{c=!0,this.off(n,p),g(w)},l)});return Promise.race([u,h])}async subscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const a=E(),l=E();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(a),this._subscriptionNamesByHandler.set(n,a),this.on(a,n);const p=H({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:i,responseName:l,subscriptionName:a});y(p);let h=!1,u;const f=new Promise((w,_)=>{const b=new Error(`${e} subscribe request with subscription name of ${a} and response name of ${l} timed out after ${m}`);setTimeout(()=>{h=!0,this.off(l,u),_(b)},m)}),g=new Promise(w=>{u=_=>{h||w(_)},this.once(l,u)});return Promise.race([f,g])}async unsubscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const a=E();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const p=H({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:i,responseName:a,unsubscribeName:c});y(p);let h=!1,u;const f=new Promise((_,b)=>{const D=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${a} timed out after ${m}`);setTimeout(()=>{h=!0,this.off(a,u),b(D)},m)}),g=new Promise(_=>{u=b=>{h||_(b)},this.once(a,u)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const i=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onHandlers.set(e,i),i.push(t)}once(e,t){var s;const i=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onceHandlers.set(e,i),i.push(t)}off(e,t){const s=this._onHandlers.get(e),i=this._onceHandlers.get(e);if(!(!s&&!i)){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(i){for(let n=0;n<i.length;n+=1)t&&i[n]!==t||(i.splice(n,1),n-=1);i.length===0&&this._onceHandlers.delete(e)}}}}function E(){return Math.random().toString(36).slice(2,9)}const q=U.version;let r=null;function O(){return r}function G(o){r=new j(o),r.bind()}function J(){r==null||r.unbind(),r=null}function K(...o){return d(r),r.on(...o)}function z(...o){return d(r),r.once(...o)}function X(...o){return d(r),r.off(...o)}function Y(...o){return d(r),r.send(...o)}function Z(...o){return d(r),r.request(...o)}function ee(...o){return d(r),r.subscribe(...o)}function te(...o){return d(r),r.unsubscribe(...o)}function se(){return d(r),r.store}function ne(){return d(r),r.applications}function ie(){return d(r),r.media}function re(){return d(r),r.accounts}function ae(){return d(r),r.users}function oe(){return d(r),r.devices}function ce(){return d(r),r.proxy}function le(){return d(r),r.rootSettingsNavigation}function ue(){return d(r),r.weather}function he(){return d(r),r.currency}function de(){return d(r),r.environment}function pe(){return d(r),r.mqtt}function d(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=I;exports.Applications=P;exports.Client=j;exports.Currency=$;exports.Devices=T;exports.Environment=M;exports.Media=k;exports.Mqtt=x;exports.Navigation=L;exports.Proxy=F;exports.Store=A;exports.StoreSlice=v;exports.Users=R;exports.Weather=B;exports.accounts=re;exports.applications=ne;exports.configure=G;exports.currency=he;exports.destroy=J;exports.devices=oe;exports.environment=de;exports.globalClient=O;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=ae;exports.weather=ue;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./types-mYnxD5LM.cjs"),Q="1.13.2",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 i;typeof e=="string"?i=e:e instanceof URL?i=e.toString():(i=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,u)=>{n[u]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,u])=>{n[h]=u}):n=t.headers);const o=await this._client.request("proxy.fetch",{url:i,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 l=new Headers(o.headers),c={status:o.status,statusText:o.statusText,headers:l};let p=null;if(o.body!==null&&o.body!==void 0)if(o.bodyType==="binary"){const h=atob(o.body),u=new Uint8Array(h.length);for(let f=0;f<h.length;f++)u[f]=h.charCodeAt(f);p=u}else o.bodyType==="text"?p=o.body:o.bodyType==="json"&&(p=JSON.stringify(o.body));return new Response(p,c)}}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,i;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(((i=n.error)===null||i===void 0?void 0:i.message)||"Failed to fetch currency rates");return n.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,i){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...i})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,i){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...i},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(a){return{...a,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"),i=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;i[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",i)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},i=this._store._client._applicationSpecifier;return s[i]}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(a){C?self.postMessage(a):S.parent.postMessage(a,"*")}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),i=s.searchParams;this._applicationInstance=i.get("applicationInstance")||"single",this._deviceId=i.get("deviceId")||this._applicationInstance;const n=/^[a-z0-9-]{40}$/i;if(this._applicationSpecifier=(e=i.get("applicationSpecifier"))!==null&&e!==void 0?e:"",!this._applicationSpecifier||!n.test(this._applicationSpecifier)){const o=s.hostname.split(".");this._applicationSpecifier=(t=o[0])!==null&&t!==void 0?t:""}if(!this._applicationSpecifier||!n.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=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 l;if(o.data.type==="client"){const c=this._messageInterceptors.get(o.data.name);if(!c){m(o.data);return}l={...c(o.data.data),type:"bridge",...o.data.responseName?{name:o.data.responseName}:{}}}if(!l){const c=O.safeParse(o.data);if(!c.success)return;l=c.data;const p=this._onHandlers.get(l.name),h=this._onceHandlers.get(l.name);if(p)for(const u of p)u(l.data);if(h){for(const u of h)u(l.data);this._onceHandlers.delete(l.name)}}if(!C)for(let c=0;c<window.frames.length;c+=1)window.frames[c].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 i;const n=I(),o=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});m(o);const l=(i=s==null?void 0:s.timeout)!==null&&i!==void 0?i:y;let c=!1,p;const h=new Promise(f=>{p=g=>{c||f(g)},this.once(n,p)});if(l===0)return h;const u=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${l}`);setTimeout(()=>{c=!0,this.off(n,p),g(w)},l)});return Promise.race([u,h])}async subscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I(),l=I();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(o),this._subscriptionNamesByHandler.set(n,o),this.on(o,n);const p=N({telemetrySdkVersion:q,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:i,responseName:l,subscriptionName:o});m(p);let h=!1,u;const f=new Promise((w,_)=>{const b=new Error(`${e} subscribe request with subscription name of ${o} and response name of ${l} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(l,u),_(b)},y)}),g=new Promise(w=>{u=_=>{h||w(_)},this.once(l,u)});return Promise.race([f,g])}async unsubscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const p=N({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationSpecifier:this._applicationSpecifier,name:e,data:i,responseName:o,unsubscribeName:c});m(p);let h=!1,u;const f=new Promise((_,b)=>{const U=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${o} timed out after ${y}`);setTimeout(()=>{h=!0,this.off(o,u),b(U)},y)}),g=new Promise(_=>{u=b=>{h||_(b)},this.once(o,u)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const i=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onHandlers.set(e,i),i.push(t)}once(e,t){var s;const i=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onceHandlers.set(e,i),i.push(t)}off(e,t){const s=this._onHandlers.get(e),i=this._onceHandlers.get(e);if(!(!s&&!i)){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(i){for(let n=0;n<i.length;n+=1)t&&i[n]!==t||(i.splice(n,1),n-=1);i.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=V.version;let r=null;function z(){return r}function G(a){D(),r=new j,r.bind()}function D(){r==null||r.unbind(),r=null}function J(...a){return d(r),r.on(...a)}function K(...a){return d(r),r.once(...a)}function X(...a){return d(r),r.off(...a)}function Y(...a){return d(r),r.send(...a)}function Z(...a){return d(r),r.request(...a)}function ee(...a){return d(r),r.subscribe(...a)}function te(...a){return d(r),r.unsubscribe(...a)}function se(){return d(r),r.store}function ne(){return d(r),r.applications}function ie(){return d(r),r.media}function re(){return d(r),r.accounts}function oe(){return d(r),r.users}function ae(){return d(r),r.devices}function ce(){return d(r),r.proxy}function le(){return d(r),r.rootSettingsNavigation}function ue(){return d(r),r.weather}function he(){return d(r),r.currency}function de(){return d(r),r.environment}function pe(){return d(r),r.mqtt}function d(a){if(!a)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=G;exports.currency=he;exports.destroy=D;exports.devices=ae;exports.environment=de;exports.globalClient=z;exports.media=ie;exports.mqtt=pe;exports.off=X;exports.on=J;exports.once=K;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
@@ -42,10 +42,8 @@ export declare function globalClient(): Client | null;
42
42
  * This function must be called before using any other exported functions that depend on the global client.
43
43
  * The exported convenience functions (send, request, store, etc.) use this global instance internally,
44
44
  * simplifying integration for applications that don't require multiple client instances.
45
- *
46
- * @param applicationName The name of your application - must match the 'name' property in your application's telemetry.config.json file
47
45
  */
48
- export declare function configure(applicationName: string): void;
46
+ export declare function configure(_applicationName?: string): void;
49
47
  /**
50
48
  * Destroys the SDK by unbinding event listeners and clearing the global client instance.
51
49
  *
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { o as C, a as P, s as T, l as k } from "./types-CCzf8sMT.js";
2
- const M = "1.13.0", F = {
2
+ const M = "1.13.2", F = {
3
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 R {
24
+ class A {
25
25
  constructor(e) {
26
26
  this._client = e;
27
27
  }
@@ -296,7 +296,7 @@ class j {
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 j {
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 j {
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.
@@ -715,7 +713,7 @@ class V {
715
713
  }, t)).success;
716
714
  }
717
715
  }
718
- class W {
716
+ class O {
719
717
  constructor(e) {
720
718
  this._originalPushState = null, this._originalReplaceState = null, this._popstateHandler = null, this._backHandler = null, this._forwardHandler = null, this._client = e;
721
719
  }
@@ -738,12 +736,12 @@ class W {
738
736
  function q(o) {
739
737
  return { ...o, type: "client" };
740
738
  }
741
- const G = C({
739
+ const W = C({
742
740
  type: k("bridge"),
743
741
  name: T(),
744
742
  data: P()
745
743
  });
746
- class J {
744
+ class z {
747
745
  /**
748
746
  * Creates a new RootSettingsNavigation API instance.
749
747
  *
@@ -800,23 +798,20 @@ class J {
800
798
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
801
799
  }
802
800
  }
803
- const b = 1e3 * 30, E = typeof window > "u" && typeof self < "u", v = E ? self : window;
801
+ const m = 1e3 * 30, N = typeof window > "u" && typeof self < "u", v = N ? self : window;
804
802
  function y(o) {
805
- E ? self.postMessage(o) : v.parent.postMessage(o, "*");
803
+ N ? self.postMessage(o) : v.parent.postMessage(o, "*");
806
804
  }
807
- class K {
805
+ class G {
808
806
  /**
809
807
  * Creates a new Client instance for communicating with the TelemetryOS platform.
810
808
  *
811
809
  * Note that creating a Client instance alone is not sufficient to begin communication.
812
810
  * You must also call the bind() method to initialize event listeners and extract
813
811
  * the application ID from the URL.
814
- *
815
- * @param applicationName The name of your application - must match the 'name' property
816
- * in your application's telemetry.config.json file
817
812
  */
818
- constructor(e) {
819
- this._applicationName = e, this._applicationInstance = "", this._applicationSpecifier = "", this._navigation = new W(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();
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();
820
815
  }
821
816
  /**
822
817
  * Provides access to the accounts API for retrieving TelemetryOS account information.
@@ -830,7 +825,7 @@ class K {
830
825
  * @returns An Accounts instance bound to this client
831
826
  */
832
827
  get accounts() {
833
- return new A(this);
828
+ return new R(this);
834
829
  }
835
830
  /**
836
831
  * Provides access to the users API for retrieving TelemetryOS user information.
@@ -872,7 +867,7 @@ class K {
872
867
  * @returns An Applications instance bound to this client
873
868
  */
874
869
  get applications() {
875
- return new R(this);
870
+ return new A(this);
876
871
  }
877
872
  /**
878
873
  * Provides access to the media API for working with content hosted on the TelemetryOS platform.
@@ -934,7 +929,7 @@ class K {
934
929
  * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
935
930
  */
936
931
  get rootSettingsNavigation() {
937
- return new J(this.store);
932
+ return new z(this.store);
938
933
  }
939
934
  /**
940
935
  * Provides access to the weather API for retrieving weather data.
@@ -981,15 +976,15 @@ class K {
981
976
  get mqtt() {
982
977
  return new V(this);
983
978
  }
984
- get applicationName() {
985
- return this._applicationName;
986
- }
987
979
  get applicationSpecifier() {
988
980
  return this._applicationSpecifier;
989
981
  }
990
982
  get applicationInstance() {
991
983
  return this._applicationInstance;
992
984
  }
985
+ get deviceId() {
986
+ return this._deviceId;
987
+ }
993
988
  /**
994
989
  * Initializes the client by setting up message listeners and extracting the application ID.
995
990
  *
@@ -1006,16 +1001,16 @@ class K {
1006
1001
  * of creating and binding their own Client instances.
1007
1002
  */
1008
1003
  bind() {
1009
- var e, t, s;
1010
- const i = new URL(v.location.href), n = i.searchParams;
1011
- if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
1012
- throw new Error("Missing applicationInstance query parameter");
1013
- if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
1014
- const a = i.hostname.split(".");
1015
- this._applicationSpecifier = (s = a[0]) !== null && s !== void 0 ? s : "";
1004
+ var e, t;
1005
+ const s = new URL(v.location.href), i = s.searchParams;
1006
+ this._applicationInstance = i.get("applicationInstance") || "single", this._deviceId = i.get("deviceId") || this._applicationInstance;
1007
+ const n = /^[a-z0-9-]{40}$/i;
1008
+ if (this._applicationSpecifier = (e = i.get("applicationSpecifier")) !== null && e !== void 0 ? e : "", !this._applicationSpecifier || !n.test(this._applicationSpecifier)) {
1009
+ const a = s.hostname.split(".");
1010
+ this._applicationSpecifier = (t = a[0]) !== null && t !== void 0 ? t : "";
1016
1011
  }
1017
- if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
1018
- throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
1012
+ if (!this._applicationSpecifier || !n.test(this._applicationSpecifier))
1013
+ 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}"`);
1019
1014
  this._windowMessageHandler = (a) => {
1020
1015
  if (a.source === v || !a.data || typeof a.data != "object" || !("type" in a.data) || a.data.type !== "client" && a.data.type !== "bridge")
1021
1016
  return;
@@ -1033,7 +1028,7 @@ class K {
1033
1028
  };
1034
1029
  }
1035
1030
  if (!l) {
1036
- const c = G.safeParse(a.data);
1031
+ const c = W.safeParse(a.data);
1037
1032
  if (!c.success)
1038
1033
  return;
1039
1034
  l = c.data;
@@ -1047,7 +1042,7 @@ class K {
1047
1042
  this._onceHandlers.delete(l.name);
1048
1043
  }
1049
1044
  }
1050
- if (!E)
1045
+ if (!N)
1051
1046
  for (let c = 0; c < window.frames.length; c += 1)
1052
1047
  window.frames[c].postMessage(l, "*");
1053
1048
  }, v.addEventListener("message", this._windowMessageHandler), this._navigation.bind();
@@ -1083,8 +1078,7 @@ class K {
1083
1078
  */
1084
1079
  send(e, t) {
1085
1080
  const s = q({
1086
- telemetrySdkVersion: H,
1087
- applicationName: this._applicationName,
1081
+ telemetrySdkVersion: I,
1088
1082
  applicationSpecifier: this._applicationSpecifier,
1089
1083
  applicationInstance: this._applicationInstance,
1090
1084
  name: e,
@@ -1113,9 +1107,8 @@ class K {
1113
1107
  */
1114
1108
  request(e, t, s) {
1115
1109
  var i;
1116
- const n = N(), a = q({
1117
- telemetrySdkVersion: H,
1118
- applicationName: this._applicationName,
1110
+ const n = H(), a = q({
1111
+ telemetrySdkVersion: I,
1119
1112
  applicationSpecifier: this._applicationSpecifier,
1120
1113
  applicationInstance: this._applicationInstance,
1121
1114
  name: e,
@@ -1123,19 +1116,19 @@ class K {
1123
1116
  responseName: n
1124
1117
  });
1125
1118
  y(a);
1126
- const l = (i = s == null ? void 0 : s.timeout) !== null && i !== void 0 ? i : b;
1119
+ const l = (i = s == null ? void 0 : s.timeout) !== null && i !== void 0 ? i : m;
1127
1120
  let c = !1, p;
1128
1121
  const h = new Promise((f) => {
1129
- p = (_) => {
1130
- c || f(_);
1122
+ p = (g) => {
1123
+ c || f(g);
1131
1124
  }, this.once(n, p);
1132
1125
  });
1133
1126
  if (l === 0)
1134
1127
  return h;
1135
- const u = new Promise((f, _) => {
1128
+ const u = new Promise((f, g) => {
1136
1129
  const w = new Error(`${e} message request with response name of ${n} timed out after ${l}`);
1137
1130
  setTimeout(() => {
1138
- c = !0, this.off(n, p), _(w);
1131
+ c = !0, this.off(n, p), g(w);
1139
1132
  }, l);
1140
1133
  });
1141
1134
  return Promise.race([u, h]);
@@ -1143,12 +1136,11 @@ class K {
1143
1136
  async subscribe(e, t, s) {
1144
1137
  let i, n;
1145
1138
  typeof t == "function" ? n = t : (i = t, n = s);
1146
- const a = N(), l = N();
1139
+ const a = H(), l = H();
1147
1140
  let c = this._subscriptionNamesBySubjectName.get(e);
1148
1141
  c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(a), this._subscriptionNamesByHandler.set(n, a), this.on(a, n);
1149
1142
  const p = q({
1150
- telemetrySdkVersion: H,
1151
- applicationName: this._applicationName,
1143
+ telemetrySdkVersion: I,
1152
1144
  applicationSpecifier: this._applicationSpecifier,
1153
1145
  applicationInstance: this._applicationInstance,
1154
1146
  name: e,
@@ -1158,22 +1150,22 @@ class K {
1158
1150
  });
1159
1151
  y(p);
1160
1152
  let h = !1, u;
1161
- const f = new Promise((w, g) => {
1162
- const m = new Error(`${e} subscribe request with subscription name of ${a} and response name of ${l} timed out after ${b}`);
1153
+ const f = new Promise((w, _) => {
1154
+ const b = new Error(`${e} subscribe request with subscription name of ${a} and response name of ${l} timed out after ${m}`);
1163
1155
  setTimeout(() => {
1164
- h = !0, this.off(l, u), g(m);
1165
- }, b);
1166
- }), _ = new Promise((w) => {
1167
- u = (g) => {
1168
- h || w(g);
1156
+ h = !0, this.off(l, u), _(b);
1157
+ }, m);
1158
+ }), g = new Promise((w) => {
1159
+ u = (_) => {
1160
+ h || w(_);
1169
1161
  }, this.once(l, u);
1170
1162
  });
1171
- return Promise.race([f, _]);
1163
+ return Promise.race([f, g]);
1172
1164
  }
1173
1165
  async unsubscribe(e, t, s) {
1174
1166
  let i, n;
1175
1167
  typeof t == "function" ? n = t : (i = t, n = s);
1176
- const a = N();
1168
+ const a = H();
1177
1169
  let l = [];
1178
1170
  if (n) {
1179
1171
  const c = this._subscriptionNamesByHandler.get(n);
@@ -1185,9 +1177,8 @@ class K {
1185
1177
  for await (const c of l) {
1186
1178
  this.off(c, n);
1187
1179
  const p = q({
1188
- telemetrySdkVersion: H,
1180
+ telemetrySdkVersion: I,
1189
1181
  applicationInstance: this._applicationInstance,
1190
- applicationName: this._applicationName,
1191
1182
  applicationSpecifier: this._applicationSpecifier,
1192
1183
  name: e,
1193
1184
  data: i,
@@ -1196,17 +1187,17 @@ class K {
1196
1187
  });
1197
1188
  y(p);
1198
1189
  let h = !1, u;
1199
- const f = new Promise((g, m) => {
1200
- const I = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${a} timed out after ${b}`);
1190
+ const f = new Promise((_, b) => {
1191
+ const E = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${a} timed out after ${m}`);
1201
1192
  setTimeout(() => {
1202
- h = !0, this.off(a, u), m(I);
1203
- }, b);
1204
- }), _ = new Promise((g) => {
1205
- u = (m) => {
1206
- h || g(m);
1193
+ h = !0, this.off(a, u), b(E);
1194
+ }, m);
1195
+ }), g = new Promise((_) => {
1196
+ u = (b) => {
1197
+ h || _(b);
1207
1198
  }, this.once(a, u);
1208
1199
  });
1209
- if (!(await Promise.race([f, _])).success)
1200
+ if (!(await Promise.race([f, g])).success)
1210
1201
  return { success: !1 };
1211
1202
  }
1212
1203
  return { success: !0 };
@@ -1283,18 +1274,18 @@ class K {
1283
1274
  }
1284
1275
  }
1285
1276
  }
1286
- function N() {
1277
+ function H() {
1287
1278
  return Math.random().toString(36).slice(2, 9);
1288
1279
  }
1289
- const H = F.version;
1280
+ const I = F.version;
1290
1281
  let r = null;
1291
- function z() {
1282
+ function X() {
1292
1283
  return r;
1293
1284
  }
1294
- function X(o) {
1295
- r = new K(o), r.bind();
1285
+ function Y(o) {
1286
+ J(), r = new G(), r.bind();
1296
1287
  }
1297
- function Y() {
1288
+ function J() {
1298
1289
  r == null || r.unbind(), r = null;
1299
1290
  }
1300
1291
  function Z(...o) {
@@ -1345,10 +1336,10 @@ function pe() {
1345
1336
  function fe() {
1346
1337
  return d(r), r.weather;
1347
1338
  }
1348
- function _e() {
1339
+ function ge() {
1349
1340
  return d(r), r.currency;
1350
1341
  }
1351
- function ge() {
1342
+ function _e() {
1352
1343
  return d(r), r.environment;
1353
1344
  }
1354
1345
  function we() {
@@ -1359,15 +1350,15 @@ function d(o) {
1359
1350
  throw new Error("SDK is not configured");
1360
1351
  }
1361
1352
  export {
1362
- A as Accounts,
1363
- R as Applications,
1364
- K as Client,
1353
+ R as Accounts,
1354
+ A as Applications,
1355
+ G as Client,
1365
1356
  U as Currency,
1366
1357
  B as Devices,
1367
1358
  $ as Environment,
1368
1359
  L as Media,
1369
1360
  V as Mqtt,
1370
- W as Navigation,
1361
+ O as Navigation,
1371
1362
  x as Proxy,
1372
1363
  j as Store,
1373
1364
  S as StoreSlice,
@@ -1375,12 +1366,12 @@ export {
1375
1366
  Q as Weather,
1376
1367
  le as accounts,
1377
1368
  oe as applications,
1378
- X as configure,
1379
- _e as currency,
1380
- Y as destroy,
1369
+ Y as configure,
1370
+ ge as currency,
1371
+ J as destroy,
1381
1372
  he as devices,
1382
- ge as environment,
1383
- z as globalClient,
1373
+ _e as environment,
1374
+ X as globalClient,
1384
1375
  ce as media,
1385
1376
  we as mqtt,
1386
1377
  te as off,
@@ -1392,7 +1383,7 @@ export {
1392
1383
  se as send,
1393
1384
  ae as store,
1394
1385
  ie as subscribe,
1395
- H as telemetrySdkVersion,
1386
+ I as telemetrySdkVersion,
1396
1387
  re as unsubscribe,
1397
1388
  ue as users,
1398
1389
  fe as weather
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
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.13.0",
3
+ "version": "1.13.2",
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",