@telemetryos/root-sdk 1.13.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 +8 -0
- package/README.md +10 -0
- package/dist/bridge.cjs +1 -1
- package/dist/bridge.js +12 -13
- package/dist/client-message-validator.d.ts +0 -3
- package/dist/client.d.ts +3 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +212 -225
- package/dist/store.d.ts +2 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 1.13.0
|
|
4
12
|
|
|
5
13
|
### 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(),
|
|
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
|
|
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:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
name: e(),
|
|
7
|
+
telemetrySdkVersion: s(),
|
|
8
|
+
applicationSpecifier: s(),
|
|
9
|
+
applicationInstance: s(),
|
|
10
|
+
name: s(),
|
|
12
11
|
data: r(),
|
|
13
|
-
responseName:
|
|
14
|
-
subscriptionName:
|
|
15
|
-
unsubscribeName:
|
|
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
|
|
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
|
-
(
|
|
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
|
|
47
|
-
window.frames[
|
|
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(
|
|
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.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
|
@@ -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(
|
|
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.
|
|
2
|
+
const M = "1.13.1", F = {
|
|
3
3
|
version: M
|
|
4
4
|
};
|
|
5
|
-
class
|
|
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
|
|
24
|
+
class A {
|
|
25
25
|
constructor(e) {
|
|
26
26
|
this._client = e;
|
|
27
27
|
}
|
|
@@ -239,8 +239,8 @@ class x {
|
|
|
239
239
|
}
|
|
240
240
|
async fetch(e, t) {
|
|
241
241
|
var s;
|
|
242
|
-
let
|
|
243
|
-
typeof e == "string" ?
|
|
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,36 +250,36 @@ class x {
|
|
|
250
250
|
referrer: e.referrer,
|
|
251
251
|
integrity: e.integrity
|
|
252
252
|
}));
|
|
253
|
-
let
|
|
254
|
-
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((h,
|
|
255
|
-
|
|
256
|
-
}) : Array.isArray(t.headers) ? t.headers.forEach(([h,
|
|
257
|
-
|
|
258
|
-
}) :
|
|
259
|
-
const
|
|
260
|
-
url:
|
|
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
|
+
const o = await this._client.request("proxy.fetch", {
|
|
260
|
+
url: n,
|
|
261
261
|
method: (t == null ? void 0 : t.method) || "GET",
|
|
262
|
-
headers:
|
|
262
|
+
headers: i,
|
|
263
263
|
body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
|
|
264
264
|
});
|
|
265
|
-
if (!
|
|
266
|
-
throw new TypeError(
|
|
267
|
-
cause:
|
|
265
|
+
if (!o.success)
|
|
266
|
+
throw new TypeError(o.errorMessage, {
|
|
267
|
+
cause: o.errorCause ? Error(o.errorCause) : void 0
|
|
268
268
|
});
|
|
269
|
-
const
|
|
270
|
-
status:
|
|
271
|
-
statusText:
|
|
272
|
-
headers:
|
|
269
|
+
const c = new Headers(o.headers), l = {
|
|
270
|
+
status: o.status,
|
|
271
|
+
statusText: o.statusText,
|
|
272
|
+
headers: c
|
|
273
273
|
};
|
|
274
|
-
let
|
|
275
|
-
if (
|
|
276
|
-
if (
|
|
277
|
-
const h = atob(
|
|
274
|
+
let u = null;
|
|
275
|
+
if (o.body !== null && o.body !== void 0)
|
|
276
|
+
if (o.bodyType === "binary") {
|
|
277
|
+
const h = atob(o.body), d = new Uint8Array(h.length);
|
|
278
278
|
for (let f = 0; f < h.length; f++)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} else
|
|
282
|
-
return new Response(
|
|
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
285
|
class j {
|
|
@@ -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",
|
|
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.
|
|
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.
|
|
@@ -644,11 +642,11 @@ class U {
|
|
|
644
642
|
* ```
|
|
645
643
|
*/
|
|
646
644
|
async getRates(e) {
|
|
647
|
-
var t, s,
|
|
648
|
-
const
|
|
649
|
-
if (!
|
|
650
|
-
throw ((t =
|
|
651
|
-
return
|
|
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,
|
|
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
|
-
...
|
|
680
|
+
...n
|
|
683
681
|
})).success)
|
|
684
682
|
throw new Error("Failed to publish MQTT message");
|
|
685
683
|
}
|
|
686
|
-
async subscribe(e, t, s,
|
|
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
|
-
...
|
|
688
|
+
...n
|
|
691
689
|
}, s)).success;
|
|
692
690
|
}
|
|
693
691
|
async unsubscribe(e, t, s) {
|
|
@@ -715,7 +713,7 @@ class V {
|
|
|
715
713
|
}, t)).success;
|
|
716
714
|
}
|
|
717
715
|
}
|
|
718
|
-
class
|
|
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
|
}
|
|
@@ -735,15 +733,15 @@ class W {
|
|
|
735
733
|
});
|
|
736
734
|
}
|
|
737
735
|
}
|
|
738
|
-
function q(
|
|
739
|
-
return { ...
|
|
736
|
+
function q(a) {
|
|
737
|
+
return { ...a, type: "client" };
|
|
740
738
|
}
|
|
741
|
-
const
|
|
739
|
+
const W = C({
|
|
742
740
|
type: k("bridge"),
|
|
743
741
|
name: T(),
|
|
744
742
|
data: P()
|
|
745
743
|
});
|
|
746
|
-
class
|
|
744
|
+
class G {
|
|
747
745
|
/**
|
|
748
746
|
* Creates a new RootSettingsNavigation API instance.
|
|
749
747
|
*
|
|
@@ -767,11 +765,11 @@ class J {
|
|
|
767
765
|
*/
|
|
768
766
|
async setRootSettingsNavigation(e) {
|
|
769
767
|
var t;
|
|
770
|
-
const s = this._store.shared("root-settings-navigation"),
|
|
771
|
-
i
|
|
772
|
-
applicationSpecifier:
|
|
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,
|
|
773
771
|
entries: e.entries
|
|
774
|
-
}, s.set("navigation",
|
|
772
|
+
}, s.set("navigation", n);
|
|
775
773
|
}
|
|
776
774
|
/**
|
|
777
775
|
* Retrieves the current navigation entries for this root application.
|
|
@@ -783,8 +781,8 @@ class J {
|
|
|
783
781
|
*/
|
|
784
782
|
async getRootSettingsNavigation() {
|
|
785
783
|
var e;
|
|
786
|
-
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {},
|
|
787
|
-
return s[
|
|
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];
|
|
788
786
|
}
|
|
789
787
|
/**
|
|
790
788
|
* Retrieves the navigation entries for all root applications.
|
|
@@ -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
|
|
804
|
-
function y(
|
|
805
|
-
|
|
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, "*");
|
|
806
804
|
}
|
|
807
|
-
class
|
|
805
|
+
class J {
|
|
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(
|
|
819
|
-
this.
|
|
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
|
|
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
|
|
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
|
|
932
|
+
return new G(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,50 +1001,46 @@ class K {
|
|
|
1006
1001
|
* of creating and binding their own Client instances.
|
|
1007
1002
|
*/
|
|
1008
1003
|
bind() {
|
|
1009
|
-
var e, t
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
if (this._applicationSpecifier = (
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
|
|
1018
|
-
throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
1019
|
-
this._windowMessageHandler = (a) => {
|
|
1020
|
-
if (a.source === v || !a.data || typeof a.data != "object" || !("type" in a.data) || a.data.type !== "client" && a.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")
|
|
1021
1012
|
return;
|
|
1022
1013
|
let l;
|
|
1023
|
-
if (
|
|
1024
|
-
const
|
|
1025
|
-
if (!
|
|
1026
|
-
y(
|
|
1014
|
+
if (c.data.type === "client") {
|
|
1015
|
+
const u = this._messageInterceptors.get(c.data.name);
|
|
1016
|
+
if (!u) {
|
|
1017
|
+
y(c.data);
|
|
1027
1018
|
return;
|
|
1028
1019
|
}
|
|
1029
1020
|
l = {
|
|
1030
|
-
...c
|
|
1021
|
+
...u(c.data.data),
|
|
1031
1022
|
type: "bridge",
|
|
1032
|
-
...
|
|
1023
|
+
...c.data.responseName ? { name: c.data.responseName } : {}
|
|
1033
1024
|
};
|
|
1034
1025
|
}
|
|
1035
1026
|
if (!l) {
|
|
1036
|
-
const
|
|
1037
|
-
if (!
|
|
1027
|
+
const u = W.safeParse(c.data);
|
|
1028
|
+
if (!u.success)
|
|
1038
1029
|
return;
|
|
1039
|
-
l =
|
|
1040
|
-
const
|
|
1041
|
-
if (
|
|
1042
|
-
for (const
|
|
1043
|
-
|
|
1044
|
-
if (
|
|
1045
|
-
for (const
|
|
1046
|
-
|
|
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);
|
|
1047
1038
|
this._onceHandlers.delete(l.name);
|
|
1048
1039
|
}
|
|
1049
1040
|
}
|
|
1050
|
-
if (!
|
|
1051
|
-
for (let
|
|
1052
|
-
window.frames[
|
|
1041
|
+
if (!N)
|
|
1042
|
+
for (let u = 0; u < window.frames.length; u += 1)
|
|
1043
|
+
window.frames[u].postMessage(l, "*");
|
|
1053
1044
|
}, v.addEventListener("message", this._windowMessageHandler), this._navigation.bind();
|
|
1054
1045
|
}
|
|
1055
1046
|
/**
|
|
@@ -1083,8 +1074,7 @@ class K {
|
|
|
1083
1074
|
*/
|
|
1084
1075
|
send(e, t) {
|
|
1085
1076
|
const s = q({
|
|
1086
|
-
telemetrySdkVersion:
|
|
1087
|
-
applicationName: this._applicationName,
|
|
1077
|
+
telemetrySdkVersion: I,
|
|
1088
1078
|
applicationSpecifier: this._applicationSpecifier,
|
|
1089
1079
|
applicationInstance: this._applicationInstance,
|
|
1090
1080
|
name: e,
|
|
@@ -1112,101 +1102,98 @@ class K {
|
|
|
1112
1102
|
* @throws {Error} If the request times out
|
|
1113
1103
|
*/
|
|
1114
1104
|
request(e, t, s) {
|
|
1115
|
-
var
|
|
1116
|
-
const
|
|
1117
|
-
telemetrySdkVersion:
|
|
1118
|
-
applicationName: this._applicationName,
|
|
1105
|
+
var n;
|
|
1106
|
+
const i = H(), o = q({
|
|
1107
|
+
telemetrySdkVersion: I,
|
|
1119
1108
|
applicationSpecifier: this._applicationSpecifier,
|
|
1120
1109
|
applicationInstance: this._applicationInstance,
|
|
1121
1110
|
name: e,
|
|
1122
1111
|
data: t,
|
|
1123
|
-
responseName:
|
|
1112
|
+
responseName: i
|
|
1124
1113
|
});
|
|
1125
|
-
y(
|
|
1126
|
-
const
|
|
1127
|
-
let
|
|
1114
|
+
y(o);
|
|
1115
|
+
const c = (n = s == null ? void 0 : s.timeout) !== null && n !== void 0 ? n : m;
|
|
1116
|
+
let l = !1, u;
|
|
1128
1117
|
const h = new Promise((f) => {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
}, this.once(
|
|
1118
|
+
u = (g) => {
|
|
1119
|
+
l || f(g);
|
|
1120
|
+
}, this.once(i, u);
|
|
1132
1121
|
});
|
|
1133
|
-
if (
|
|
1122
|
+
if (c === 0)
|
|
1134
1123
|
return h;
|
|
1135
|
-
const
|
|
1136
|
-
const w = new Error(`${e} message request with response name of ${
|
|
1124
|
+
const d = new Promise((f, g) => {
|
|
1125
|
+
const w = new Error(`${e} message request with response name of ${i} timed out after ${c}`);
|
|
1137
1126
|
setTimeout(() => {
|
|
1138
|
-
|
|
1139
|
-
},
|
|
1127
|
+
l = !0, this.off(i, u), g(w);
|
|
1128
|
+
}, c);
|
|
1140
1129
|
});
|
|
1141
|
-
return Promise.race([
|
|
1130
|
+
return Promise.race([d, h]);
|
|
1142
1131
|
}
|
|
1143
1132
|
async subscribe(e, t, s) {
|
|
1144
|
-
let
|
|
1145
|
-
typeof t == "function" ?
|
|
1146
|
-
const
|
|
1147
|
-
let
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1150
|
-
telemetrySdkVersion:
|
|
1151
|
-
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,
|
|
1152
1140
|
applicationSpecifier: this._applicationSpecifier,
|
|
1153
1141
|
applicationInstance: this._applicationInstance,
|
|
1154
1142
|
name: e,
|
|
1155
|
-
data:
|
|
1156
|
-
responseName:
|
|
1157
|
-
subscriptionName:
|
|
1143
|
+
data: n,
|
|
1144
|
+
responseName: c,
|
|
1145
|
+
subscriptionName: o
|
|
1158
1146
|
});
|
|
1159
|
-
y(
|
|
1160
|
-
let h = !1,
|
|
1161
|
-
const f = new Promise((w,
|
|
1162
|
-
const
|
|
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}`);
|
|
1163
1151
|
setTimeout(() => {
|
|
1164
|
-
h = !0, this.off(
|
|
1165
|
-
},
|
|
1166
|
-
}),
|
|
1167
|
-
|
|
1168
|
-
h || w(
|
|
1169
|
-
}, this.once(
|
|
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);
|
|
1170
1158
|
});
|
|
1171
|
-
return Promise.race([f,
|
|
1159
|
+
return Promise.race([f, g]);
|
|
1172
1160
|
}
|
|
1173
1161
|
async unsubscribe(e, t, s) {
|
|
1174
|
-
let
|
|
1175
|
-
typeof t == "function" ?
|
|
1176
|
-
const
|
|
1177
|
-
let
|
|
1178
|
-
if (
|
|
1179
|
-
const
|
|
1180
|
-
if (!
|
|
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)
|
|
1181
1169
|
return { success: !1 };
|
|
1182
|
-
|
|
1170
|
+
c = [l], this._subscriptionNamesByHandler.delete(i);
|
|
1183
1171
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
1184
1172
|
return { success: !1 };
|
|
1185
|
-
for await (const
|
|
1186
|
-
this.off(
|
|
1187
|
-
const
|
|
1188
|
-
telemetrySdkVersion:
|
|
1173
|
+
for await (const l of c) {
|
|
1174
|
+
this.off(l, i);
|
|
1175
|
+
const u = q({
|
|
1176
|
+
telemetrySdkVersion: I,
|
|
1189
1177
|
applicationInstance: this._applicationInstance,
|
|
1190
|
-
applicationName: this._applicationName,
|
|
1191
1178
|
applicationSpecifier: this._applicationSpecifier,
|
|
1192
1179
|
name: e,
|
|
1193
|
-
data:
|
|
1194
|
-
responseName:
|
|
1195
|
-
unsubscribeName:
|
|
1180
|
+
data: n,
|
|
1181
|
+
responseName: o,
|
|
1182
|
+
unsubscribeName: l
|
|
1196
1183
|
});
|
|
1197
|
-
y(
|
|
1198
|
-
let h = !1,
|
|
1199
|
-
const f = new Promise((
|
|
1200
|
-
const
|
|
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}`);
|
|
1201
1188
|
setTimeout(() => {
|
|
1202
|
-
h = !0, this.off(
|
|
1203
|
-
},
|
|
1204
|
-
}),
|
|
1205
|
-
|
|
1206
|
-
h ||
|
|
1207
|
-
}, this.once(
|
|
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);
|
|
1208
1195
|
});
|
|
1209
|
-
if (!(await Promise.race([f,
|
|
1196
|
+
if (!(await Promise.race([f, g])).success)
|
|
1210
1197
|
return { success: !1 };
|
|
1211
1198
|
}
|
|
1212
1199
|
return { success: !0 };
|
|
@@ -1230,8 +1217,8 @@ class K {
|
|
|
1230
1217
|
*/
|
|
1231
1218
|
on(e, t) {
|
|
1232
1219
|
var s;
|
|
1233
|
-
const
|
|
1234
|
-
|
|
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);
|
|
1235
1222
|
}
|
|
1236
1223
|
/**
|
|
1237
1224
|
* Registers a one-time handler for a specific message type.
|
|
@@ -1249,8 +1236,8 @@ class K {
|
|
|
1249
1236
|
*/
|
|
1250
1237
|
once(e, t) {
|
|
1251
1238
|
var s;
|
|
1252
|
-
const
|
|
1253
|
-
|
|
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);
|
|
1254
1241
|
}
|
|
1255
1242
|
/**
|
|
1256
1243
|
* Removes previously registered message handlers.
|
|
@@ -1268,106 +1255,106 @@ class K {
|
|
|
1268
1255
|
* all handlers for this message type will be removed.
|
|
1269
1256
|
*/
|
|
1270
1257
|
off(e, t) {
|
|
1271
|
-
const s = this._onHandlers.get(e),
|
|
1272
|
-
if (!(!s && !
|
|
1258
|
+
const s = this._onHandlers.get(e), n = this._onceHandlers.get(e);
|
|
1259
|
+
if (!(!s && !n)) {
|
|
1273
1260
|
if (s) {
|
|
1274
|
-
for (let
|
|
1275
|
-
t && s[
|
|
1261
|
+
for (let i = 0; i < s.length; i += 1)
|
|
1262
|
+
t && s[i] !== t || (s.splice(i, 1), i -= 1);
|
|
1276
1263
|
s.length === 0 && this._onHandlers.delete(e);
|
|
1277
1264
|
}
|
|
1278
|
-
if (
|
|
1279
|
-
for (let
|
|
1280
|
-
t && i
|
|
1281
|
-
|
|
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);
|
|
1282
1269
|
}
|
|
1283
1270
|
}
|
|
1284
1271
|
}
|
|
1285
1272
|
}
|
|
1286
|
-
function
|
|
1273
|
+
function H() {
|
|
1287
1274
|
return Math.random().toString(36).slice(2, 9);
|
|
1288
1275
|
}
|
|
1289
|
-
const
|
|
1276
|
+
const I = F.version;
|
|
1290
1277
|
let r = null;
|
|
1291
|
-
function
|
|
1278
|
+
function X() {
|
|
1292
1279
|
return r;
|
|
1293
1280
|
}
|
|
1294
|
-
function
|
|
1295
|
-
r = new
|
|
1281
|
+
function Y(a) {
|
|
1282
|
+
K(), r = new J(), r.bind();
|
|
1296
1283
|
}
|
|
1297
|
-
function
|
|
1284
|
+
function K() {
|
|
1298
1285
|
r == null || r.unbind(), r = null;
|
|
1299
1286
|
}
|
|
1300
|
-
function Z(...
|
|
1301
|
-
return
|
|
1287
|
+
function Z(...a) {
|
|
1288
|
+
return p(r), r.on(...a);
|
|
1302
1289
|
}
|
|
1303
|
-
function ee(...
|
|
1304
|
-
return
|
|
1290
|
+
function ee(...a) {
|
|
1291
|
+
return p(r), r.once(...a);
|
|
1305
1292
|
}
|
|
1306
|
-
function te(...
|
|
1307
|
-
return
|
|
1293
|
+
function te(...a) {
|
|
1294
|
+
return p(r), r.off(...a);
|
|
1308
1295
|
}
|
|
1309
|
-
function se(...
|
|
1310
|
-
return
|
|
1296
|
+
function se(...a) {
|
|
1297
|
+
return p(r), r.send(...a);
|
|
1311
1298
|
}
|
|
1312
|
-
function ne(...
|
|
1313
|
-
return
|
|
1299
|
+
function ne(...a) {
|
|
1300
|
+
return p(r), r.request(...a);
|
|
1314
1301
|
}
|
|
1315
|
-
function ie(...
|
|
1316
|
-
return
|
|
1302
|
+
function ie(...a) {
|
|
1303
|
+
return p(r), r.subscribe(...a);
|
|
1317
1304
|
}
|
|
1318
|
-
function re(...
|
|
1319
|
-
return
|
|
1305
|
+
function re(...a) {
|
|
1306
|
+
return p(r), r.unsubscribe(...a);
|
|
1320
1307
|
}
|
|
1321
1308
|
function ae() {
|
|
1322
|
-
return
|
|
1309
|
+
return p(r), r.store;
|
|
1323
1310
|
}
|
|
1324
1311
|
function oe() {
|
|
1325
|
-
return
|
|
1312
|
+
return p(r), r.applications;
|
|
1326
1313
|
}
|
|
1327
1314
|
function ce() {
|
|
1328
|
-
return
|
|
1315
|
+
return p(r), r.media;
|
|
1329
1316
|
}
|
|
1330
1317
|
function le() {
|
|
1331
|
-
return
|
|
1318
|
+
return p(r), r.accounts;
|
|
1332
1319
|
}
|
|
1333
1320
|
function ue() {
|
|
1334
|
-
return
|
|
1321
|
+
return p(r), r.users;
|
|
1335
1322
|
}
|
|
1336
1323
|
function he() {
|
|
1337
|
-
return
|
|
1324
|
+
return p(r), r.devices;
|
|
1338
1325
|
}
|
|
1339
1326
|
function de() {
|
|
1340
|
-
return
|
|
1327
|
+
return p(r), r.proxy;
|
|
1341
1328
|
}
|
|
1342
1329
|
function pe() {
|
|
1343
|
-
return
|
|
1330
|
+
return p(r), r.rootSettingsNavigation;
|
|
1344
1331
|
}
|
|
1345
1332
|
function fe() {
|
|
1346
|
-
return
|
|
1347
|
-
}
|
|
1348
|
-
function _e() {
|
|
1349
|
-
return d(r), r.currency;
|
|
1333
|
+
return p(r), r.weather;
|
|
1350
1334
|
}
|
|
1351
1335
|
function ge() {
|
|
1352
|
-
return
|
|
1336
|
+
return p(r), r.currency;
|
|
1337
|
+
}
|
|
1338
|
+
function _e() {
|
|
1339
|
+
return p(r), r.environment;
|
|
1353
1340
|
}
|
|
1354
1341
|
function we() {
|
|
1355
|
-
return
|
|
1342
|
+
return p(r), r.mqtt;
|
|
1356
1343
|
}
|
|
1357
|
-
function
|
|
1358
|
-
if (!
|
|
1344
|
+
function p(a) {
|
|
1345
|
+
if (!a)
|
|
1359
1346
|
throw new Error("SDK is not configured");
|
|
1360
1347
|
}
|
|
1361
1348
|
export {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1349
|
+
R as Accounts,
|
|
1350
|
+
A as Applications,
|
|
1351
|
+
J as Client,
|
|
1365
1352
|
U as Currency,
|
|
1366
1353
|
B as Devices,
|
|
1367
1354
|
$ as Environment,
|
|
1368
1355
|
L as Media,
|
|
1369
1356
|
V as Mqtt,
|
|
1370
|
-
|
|
1357
|
+
O as Navigation,
|
|
1371
1358
|
x as Proxy,
|
|
1372
1359
|
j as Store,
|
|
1373
1360
|
S as StoreSlice,
|
|
@@ -1375,12 +1362,12 @@ export {
|
|
|
1375
1362
|
Q as Weather,
|
|
1376
1363
|
le as accounts,
|
|
1377
1364
|
oe as applications,
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1365
|
+
Y as configure,
|
|
1366
|
+
ge as currency,
|
|
1367
|
+
K as destroy,
|
|
1381
1368
|
he as devices,
|
|
1382
|
-
|
|
1383
|
-
|
|
1369
|
+
_e as environment,
|
|
1370
|
+
X as globalClient,
|
|
1384
1371
|
ce as media,
|
|
1385
1372
|
we as mqtt,
|
|
1386
1373
|
te as off,
|
|
@@ -1392,7 +1379,7 @@ export {
|
|
|
1392
1379
|
se as send,
|
|
1393
1380
|
ae as store,
|
|
1394
1381
|
ie as subscribe,
|
|
1395
|
-
|
|
1382
|
+
I as telemetrySdkVersion,
|
|
1396
1383
|
re as unsubscribe,
|
|
1397
1384
|
ue as users,
|
|
1398
1385
|
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.
|
|
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",
|