@telemetryos/root-sdk 1.4.3 → 1.4.4
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 +6 -0
- package/dist/applications.d.ts +2 -2
- package/dist/bridge-message-formatter.d.ts +1 -4
- package/dist/bridge-message-validator.d.ts +3 -0
- package/dist/bridge.cjs +1 -1
- package/dist/bridge.js +14 -10
- package/dist/client-message-formatter.d.ts +1 -11
- package/dist/client-message-validator.d.ts +3 -0
- package/dist/client.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +129 -118
- package/dist/store.d.ts +5 -5
- package/package.json +1 -1
- /package/dist/{device.d.ts → devices.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
package/dist/applications.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type Application = {
|
|
|
10
10
|
export type GetUrlResult = {
|
|
11
11
|
url: string;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
13
|
+
export type ApplicationsState = {
|
|
14
14
|
ready: string[];
|
|
15
15
|
unavailable: string[];
|
|
16
16
|
};
|
|
@@ -61,5 +61,5 @@ export declare class Applications {
|
|
|
61
61
|
* // result.unavailable: ['app2-hash'] - these failed to load
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
setDependencies(applicationSpecifiers: string[]): Promise<
|
|
64
|
+
setDependencies(applicationSpecifiers: string[]): Promise<ApplicationsState>;
|
|
65
65
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { bridgeMessageValidator } from './bridge-message-validator.js';
|
|
3
3
|
export type Message = z.infer<typeof bridgeMessageValidator>;
|
|
4
|
-
export declare function formatBridgeMessage(data: Message):
|
|
5
|
-
name: string;
|
|
6
|
-
data?: any;
|
|
7
|
-
};
|
|
4
|
+
export declare function formatBridgeMessage(data: Omit<Message, 'type'>): Message;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const bridgeMessageValidator: z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"bridge">;
|
|
3
4
|
name: z.ZodString;
|
|
4
5
|
data: z.ZodAny;
|
|
5
6
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
type: "bridge";
|
|
6
8
|
name: string;
|
|
7
9
|
data?: any;
|
|
8
10
|
}, {
|
|
11
|
+
type: "bridge";
|
|
9
12
|
name: string;
|
|
10
13
|
data?: any;
|
|
11
14
|
}>;
|
package/dist/bridge.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");function r(n){return{...n,type:"bridge"}}const o=e.z.object({type:e.z.literal("client"),telemetrySdkVersion:e.z.string(),applicationName:e.z.string(),applicationSpecifier:e.z.string(),applicationInstance:e.z.string(),name:e.z.string(),data:e.z.any(),responseName:e.z.string().optional(),subscriptionName:e.z.string().optional(),unsubscribeName:e.z.string().optional()});class d{bind(){this._windowMessageHandler=i=>{var s;if(i.source===window)return;const t=o.safeParse(i.data);if(!t.success)return;const a=t.data;(s=this.onMessage)===null||s===void 0||s.call(this,a)},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(i){for(let s=0;s<window.frames.length;s+=1)window.frames[s].postMessage(r(i),"*")}}exports.Bridge=d;
|
package/dist/bridge.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { z as e } from "./index-B98VDFRY.js";
|
|
2
|
-
|
|
2
|
+
function r(n) {
|
|
3
|
+
return { ...n, type: "bridge" };
|
|
4
|
+
}
|
|
5
|
+
const o = e.object({
|
|
6
|
+
type: e.literal("client"),
|
|
3
7
|
telemetrySdkVersion: e.string(),
|
|
4
8
|
applicationName: e.string(),
|
|
5
9
|
applicationSpecifier: e.string(),
|
|
@@ -10,20 +14,20 @@ const t = e.object({
|
|
|
10
14
|
subscriptionName: e.string().optional(),
|
|
11
15
|
unsubscribeName: e.string().optional()
|
|
12
16
|
});
|
|
13
|
-
class
|
|
17
|
+
class l {
|
|
14
18
|
/**
|
|
15
19
|
* Binds the Bridge to the window message event. This will allow the Bridge
|
|
16
20
|
* to listen for messages from the host application.
|
|
17
21
|
*/
|
|
18
22
|
bind() {
|
|
19
|
-
this._windowMessageHandler = (
|
|
23
|
+
this._windowMessageHandler = (i) => {
|
|
20
24
|
var s;
|
|
21
|
-
if (
|
|
25
|
+
if (i.source === window)
|
|
22
26
|
return;
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
27
|
+
const t = o.safeParse(i.data);
|
|
28
|
+
if (!t.success)
|
|
25
29
|
return;
|
|
26
|
-
const a =
|
|
30
|
+
const a = t.data;
|
|
27
31
|
(s = this.onMessage) === null || s === void 0 || s.call(this, a);
|
|
28
32
|
}, window.addEventListener("message", this._windowMessageHandler);
|
|
29
33
|
}
|
|
@@ -38,11 +42,11 @@ class d {
|
|
|
38
42
|
* Sends a message to SDK clients.
|
|
39
43
|
* @param message The message to send.
|
|
40
44
|
*/
|
|
41
|
-
send(
|
|
45
|
+
send(i) {
|
|
42
46
|
for (let s = 0; s < window.frames.length; s += 1)
|
|
43
|
-
window.frames[s].postMessage(
|
|
47
|
+
window.frames[s].postMessage(r(i), "*");
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
export {
|
|
47
|
-
|
|
51
|
+
l as Bridge
|
|
48
52
|
};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { clientMessageValidator } from './client-message-validator.js';
|
|
3
3
|
export type Message = z.infer<typeof clientMessageValidator>;
|
|
4
|
-
export declare function formatClientMessage(data: Message):
|
|
5
|
-
telemetrySdkVersion: string;
|
|
6
|
-
applicationName: string;
|
|
7
|
-
applicationSpecifier: string;
|
|
8
|
-
applicationInstance: string;
|
|
9
|
-
name: string;
|
|
10
|
-
data?: any;
|
|
11
|
-
responseName?: string | undefined;
|
|
12
|
-
subscriptionName?: string | undefined;
|
|
13
|
-
unsubscribeName?: string | undefined;
|
|
14
|
-
};
|
|
4
|
+
export declare function formatClientMessage(data: Omit<Message, 'type'>): Message;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const clientMessageValidator: z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"client">;
|
|
3
4
|
telemetrySdkVersion: z.ZodString;
|
|
4
5
|
applicationName: z.ZodString;
|
|
5
6
|
applicationSpecifier: z.ZodString;
|
|
@@ -10,6 +11,7 @@ export declare const clientMessageValidator: z.ZodObject<{
|
|
|
10
11
|
subscriptionName: z.ZodOptional<z.ZodString>;
|
|
11
12
|
unsubscribeName: z.ZodOptional<z.ZodString>;
|
|
12
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "client";
|
|
13
15
|
telemetrySdkVersion: string;
|
|
14
16
|
applicationName: string;
|
|
15
17
|
applicationSpecifier: string;
|
|
@@ -20,6 +22,7 @@ export declare const clientMessageValidator: z.ZodObject<{
|
|
|
20
22
|
subscriptionName?: string | undefined;
|
|
21
23
|
unsubscribeName?: string | undefined;
|
|
22
24
|
}, {
|
|
25
|
+
type: "client";
|
|
23
26
|
telemetrySdkVersion: string;
|
|
24
27
|
applicationName: string;
|
|
25
28
|
applicationSpecifier: string;
|
package/dist/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { RootSettingsNavigation } from './root-settings-navigation.js';
|
|
|
5
5
|
import { Accounts } from './accounts.js';
|
|
6
6
|
import { Users } from './users.js';
|
|
7
7
|
import { Proxy } from './proxy.js';
|
|
8
|
-
import { Devices } from './
|
|
8
|
+
import { Devices } from './devices.js';
|
|
9
9
|
import { Weather } from './weather.js';
|
|
10
10
|
/**
|
|
11
11
|
* The maximum time in milliseconds to wait for a response to a request call.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./index-JDXm3DEz.cjs"),k="1.4.3",F={version:k};class H{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class q{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e})}}class I{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}function T(o,e=console.error){o().catch(e)}class ${constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}subscribeColorScheme(e){T(async()=>{this._client.on("environment.colorSchemeChanged",e),e(await this.getColorScheme())})}unsubscribeColorScheme(e){this._client.off("environment.colorSchemeChanged",e)}}class P{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class E{constructor(e){this._client=e}get application(){return new y("application","",this._client)}get instance(){return new y("instance",this._client.applicationSpecifier,this._client)}get device(){return new y("device",this._client.applicationSpecifier,this._client)}shared(e){return new y("shared",e,this._client)}}class y{constructor(e,t,n){this._kind=e,this._namespace=t,this._client=n}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class M{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class A{constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}const x=N.z.object({name:N.z.string(),data:N.z.any()});class R{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){const t=this._store.shared("root-settings-navigation"),n=await t.get("navigation"),r=this._store._client._applicationSpecifier;n[r]={applicationSpecifier:r,entries:e.entries},t.set("navigation",n)}async getRootSettingsNavigation(){const t=await this._store.shared("root-settings-navigation").get("navigation"),n=this._store._client._applicationSpecifier;return t[n]}async getAllRootSettingsNavigation(){return this._store.shared("root-settings-navigation").get("navigation")}}class j{constructor(e){this._client=e}async fetch(e,t){let n;typeof e=="string"?n=e:e instanceof URL?n=e.toString():(n=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,c)=>{r[c]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,c])=>{r[h]=c}):r=t.headers);const s=await this._client.request("proxy.fetch",{url:n,method:(t==null?void 0:t.method)||"GET",headers:r,body:(t==null?void 0:t.body)||null});if(!s.success)throw new Error(`Proxy fetch failed: ${s.statusText}`);const l=new Headers(s.headers),u={status:s.status,statusText:s.statusText,headers:l};let a=null;return s.body!==null&&s.body!==void 0&&(typeof s.body=="string"||s.body instanceof ArrayBuffer?a=s.body:typeof s.body=="object"&&(a=JSON.stringify(s.body))),new Response(a,u)}}const g=1e3*30;class B{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new H(this)}get users(){return new M(this)}get store(){return new E(this)}get applications(){return new q(this)}get media(){return new P(this)}get proxy(){return new j(this)}get devices(){return new I(this)}get rootSettingsNavigation(){return new R(this.store)}get weather(){return new A(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e;const t=new URL(window.location.href),n=t.searchParams;this._applicationInstance=(e=n.get("telemetryApplicationId"))!==null&&e!==void 0?e:"";const r=n.get("applicationSpecifier");if(r)this._applicationSpecifier=r;else{const s=t.hostname.split(".");this._applicationSpecifier=s[0]||""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);if(!this._applicationInstance)throw new Error("Missing telemetryApplicationId query parameter");this._windowMessageHandler=s=>{if(s.source===window)return;for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(s.data,"*");const l=x.safeParse(s.data);if(!l.success)return;const u=l.data,a=this._onHandlers.get(u.name),h=this._onceHandlers.get(u.name);if(a)for(const c of a)c(u.data);if(h){for(const c of h)c(u.data);this._onceHandlers.delete(u.name)}},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const n={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t};window.parent.postMessage(n,"*")}request(e,t){const n=b(),r={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n};window.parent.postMessage(r,"*");let s=!1,l;const u=new Promise((h,c)=>{const d=new Error(`${e} message request with response name of ${n} timed out after ${g}`);setTimeout(()=>{s=!0,this.off(n,l),c(d)},g)}),a=new Promise(h=>{l=c=>{s||h(c)},this.once(n,h)});return Promise.race([u,a])}async subscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=b(),u=b();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(l),this._subscriptionNamesByHandler.set(s,l),this.on(l,s);const h={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:r,responseName:u,subscriptionName:l};window.parent.postMessage(h,"*");let c=!1,d;const S=new Promise((w,f)=>{const m=new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(u,d),f(m)},g)}),v=new Promise(w=>{d=f=>{c||w(f)},this.on(u,w)});return Promise.race([S,v])}async unsubscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=b();let u=[];if(s){const a=this._subscriptionNamesByHandler.get(s);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(s)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,s);const h={telemetrySdkVersion:_,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:r,responseName:l,unsubscribeName:a};window.parent.postMessage(h,"*");let c=!1,d;const S=new Promise((f,m)=>{const C=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(l,d),m(C)},g)}),v=new Promise(f=>{d=m=>{c||f(m)},this.once(l,f)});if(!(await Promise.race([S,v])).success)return{success:!1}}return{success:!0}}on(e,t){var n;const r=(n=this._onHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var n;const r=(n=this._onceHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const n=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!n&&!r)){if(n){for(let s=0;s<n.length;s+=1)t&&n[s]!==t||(n.splice(s,1),s-=1);n.length===0&&this._onHandlers.delete(e)}if(r){for(let s=0;s<r.length;s+=1)t&&r[s]!==t||(r.splice(s,1),s-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function b(){return Math.random().toString(36).slice(2,9)}const _=F.version;let i=null;function D(){return i}function L(o){i=new B(o),i.bind()}function U(){i==null||i.unbind(),i=null}function z(...o){return p(i),i.on(...o)}function V(...o){return p(i),i.once(...o)}function O(...o){return p(i),i.off(...o)}function W(...o){return p(i),i.send(...o)}function G(...o){return p(i),i.request(...o)}function J(...o){return p(i),i.subscribe(...o)}function K(...o){return p(i),i.unsubscribe(...o)}function Q(){return p(i),i.store}function X(){return p(i),i.applications}function Y(){return p(i),i.media}function Z(){return p(i),i.accounts}function ee(){return p(i),i.users}function te(){return p(i),i.devices}function se(){return p(i),i.proxy}function ne(){return p(i),i.rootSettingsNavigation}function ie(){return p(i),i.weather}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=H;exports.Applications=q;exports.Client=B;exports.Devices=I;exports.Environment=$;exports.Media=P;exports.Store=E;exports.Users=M;exports.Weather=A;exports.accounts=Z;exports.applications=X;exports.configure=L;exports.destroy=U;exports.devices=te;exports.globalClient=D;exports.media=Y;exports.off=O;exports.on=z;exports.once=V;exports.proxy=se;exports.request=G;exports.rootSettingsNavigation=ne;exports.send=W;exports.store=Q;exports.subscribe=J;exports.telemetrySdkVersion=_;exports.unsubscribe=K;exports.users=ee;exports.weather=ie;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./index-JDXm3DEz.cjs"),F="1.4.4",T={version:F};class q{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 I{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e})}}class P{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}function $(o,e=console.error){o().catch(e)}class x{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}subscribeColorScheme(e){$(async()=>{this._client.on("environment.colorSchemeChanged",e),e(await this.getColorScheme())})}unsubscribeColorScheme(e){this._client.off("environment.colorSchemeChanged",e)}}class E{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class M{constructor(e){this._client=e}get application(){return new b("application","",this._client)}get instance(){return new b("instance",this._client.applicationSpecifier,this._client)}get device(){return new b("device",this._client.applicationSpecifier,this._client)}shared(e){return new b("shared",e,this._client)}}class b{constructor(e,t,n){this._kind=e,this._namespace=t,this._client=n}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class A{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class B{constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}function S(o){return{...o,type:"client"}}const R=y.z.object({type:y.z.literal("bridge"),name:y.z.string(),data:y.z.any()});class j{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 n=this._store.shared("root-settings-navigation"),r=(t=await n.get("navigation"))!==null&&t!==void 0?t:{},s=this._store._client._applicationSpecifier;r[s]={applicationSpecifier:s,entries:e.entries},n.set("navigation",r)}async getRootSettingsNavigation(){var e;const n=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},r=this._store._client._applicationSpecifier;return n[r]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}class D{constructor(e){this._client=e}async fetch(e,t){let n;typeof e=="string"?n=e:e instanceof URL?n=e.toString():(n=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((h,c)=>{r[c]=h}):Array.isArray(t.headers)?t.headers.forEach(([h,c])=>{r[h]=c}):r=t.headers);const s=await this._client.request("proxy.fetch",{url:n,method:(t==null?void 0:t.method)||"GET",headers:r,body:(t==null?void 0:t.body)||null});if(!s.success)throw new Error(`Proxy fetch failed: ${s.statusText}`);const l=new Headers(s.headers),u={status:s.status,statusText:s.statusText,headers:l};let a=null;return s.body!==null&&s.body!==void 0&&(typeof s.body=="string"||s.body instanceof ArrayBuffer?a=s.body:typeof s.body=="object"&&(a=JSON.stringify(s.body))),new Response(a,u)}}const g=1e3*30;class C{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new q(this)}get users(){return new A(this)}get store(){return new M(this)}get applications(){return new I(this)}get media(){return new E(this)}get proxy(){return new D(this)}get devices(){return new P(this)}get rootSettingsNavigation(){return new j(this.store)}get weather(){return new B(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e;const t=new URL(window.location.href),n=t.searchParams;this._applicationInstance=(e=n.get("telemetryApplicationId"))!==null&&e!==void 0?e:"";const r=n.get("applicationSpecifier");if(r)this._applicationSpecifier=r;else{const s=t.hostname.split(".");this._applicationSpecifier=s[0]||""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);if(!this._applicationInstance)throw new Error("Missing telemetryApplicationId query parameter");this._windowMessageHandler=s=>{if(s.source===window||!s.data||!("type"in s.data)||s.data.type!=="client"&&s.data.type!=="bridge")return;if(s.data.type==="client"){window.parent.postMessage(s.data,"*");return}const l=R.safeParse(s.data);if(!l.success)return;const u=l.data,a=this._onHandlers.get(u.name),h=this._onceHandlers.get(u.name);if(a)for(const c of a)c(u.data);if(h){for(const c of h)c(u.data);this._onceHandlers.delete(u.name)}for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(s.data,"*")},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const n=S({telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});window.parent.postMessage(n,"*")}request(e,t){const n=v(),r=S({telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});window.parent.postMessage(r,"*");let s=!1,l;const u=new Promise((h,c)=>{const d=new Error(`${e} message request with response name of ${n} timed out after ${g}`);setTimeout(()=>{s=!0,this.off(n,l),c(d)},g)}),a=new Promise(h=>{l=c=>{s||h(c)},this.once(n,h)});return Promise.race([u,a])}async subscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=v(),u=v();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(l),this._subscriptionNamesByHandler.set(s,l),this.on(l,s);const h=S({telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:r,responseName:u,subscriptionName:l});window.parent.postMessage(h,"*");let c=!1,d;const N=new Promise((w,f)=>{const m=new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(u,d),f(m)},g)}),H=new Promise(w=>{d=f=>{c||w(f)},this.on(u,w)});return Promise.race([N,H])}async unsubscribe(e,t,n){let r,s;typeof t=="function"?s=t:(r=t,s=n);const l=v();let u=[];if(s){const a=this._subscriptionNamesByHandler.get(s);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(s)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,s);const h=S({telemetrySdkVersion:_,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:r,responseName:l,unsubscribeName:a});window.parent.postMessage(h,"*");let c=!1,d;const N=new Promise((f,m)=>{const k=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);setTimeout(()=>{c=!0,this.off(l,d),m(k)},g)}),H=new Promise(f=>{d=m=>{c||f(m)},this.once(l,f)});if(!(await Promise.race([N,H])).success)return{success:!1}}return{success:!0}}on(e,t){var n;const r=(n=this._onHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var n;const r=(n=this._onceHandlers.get(e))!==null&&n!==void 0?n:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const n=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!n&&!r)){if(n){for(let s=0;s<n.length;s+=1)t&&n[s]!==t||(n.splice(s,1),s-=1);n.length===0&&this._onHandlers.delete(e)}if(r){for(let s=0;s<r.length;s+=1)t&&r[s]!==t||(r.splice(s,1),s-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function v(){return Math.random().toString(36).slice(2,9)}const _=T.version;let i=null;function z(){return i}function L(o){i=new C(o),i.bind()}function U(){i==null||i.unbind(),i=null}function V(...o){return p(i),i.on(...o)}function O(...o){return p(i),i.once(...o)}function W(...o){return p(i),i.off(...o)}function G(...o){return p(i),i.send(...o)}function J(...o){return p(i),i.request(...o)}function K(...o){return p(i),i.subscribe(...o)}function Q(...o){return p(i),i.unsubscribe(...o)}function X(){return p(i),i.store}function Y(){return p(i),i.applications}function Z(){return p(i),i.media}function ee(){return p(i),i.accounts}function te(){return p(i),i.users}function se(){return p(i),i.devices}function ne(){return p(i),i.proxy}function ie(){return p(i),i.rootSettingsNavigation}function re(){return p(i),i.weather}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=q;exports.Applications=I;exports.Client=C;exports.Devices=P;exports.Environment=x;exports.Media=E;exports.Store=M;exports.Users=A;exports.Weather=B;exports.accounts=ee;exports.applications=Y;exports.configure=L;exports.destroy=U;exports.devices=se;exports.globalClient=z;exports.media=Z;exports.off=W;exports.on=V;exports.once=O;exports.proxy=ne;exports.request=J;exports.rootSettingsNavigation=ie;exports.send=G;exports.store=X;exports.subscribe=K;exports.telemetrySdkVersion=_;exports.unsubscribe=Q;exports.users=te;exports.weather=re;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Accounts } from './accounts.js';
|
|
2
2
|
export { Applications } from './applications.js';
|
|
3
|
-
export { Devices } from './
|
|
3
|
+
export { Devices } from './devices.js';
|
|
4
4
|
export { Environment } from './environment.js';
|
|
5
5
|
export { Media } from './media.js';
|
|
6
6
|
export { Store } from './store.js';
|
|
@@ -219,7 +219,7 @@ export declare function users(): import("./users.js").Users;
|
|
|
219
219
|
* @returns The Devices API object
|
|
220
220
|
* @throws {Error} If called before configure() or after destroy()
|
|
221
221
|
*/
|
|
222
|
-
export declare function devices(): import("./
|
|
222
|
+
export declare function devices(): import("./devices.js").Devices;
|
|
223
223
|
/**
|
|
224
224
|
* Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
|
|
225
225
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { z as
|
|
2
|
-
const
|
|
3
|
-
version:
|
|
1
|
+
import { z as w } from "./index-B98VDFRY.js";
|
|
2
|
+
const I = "1.4.4", P = {
|
|
3
|
+
version: I
|
|
4
4
|
};
|
|
5
|
-
class
|
|
5
|
+
class E {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this._client = e;
|
|
8
8
|
}
|
|
@@ -21,7 +21,7 @@ class P {
|
|
|
21
21
|
return e.account;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class M {
|
|
25
25
|
constructor(e) {
|
|
26
26
|
this._client = e;
|
|
27
27
|
}
|
|
@@ -83,7 +83,7 @@ class E {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
class
|
|
86
|
+
class A {
|
|
87
87
|
constructor(e) {
|
|
88
88
|
this._client = e;
|
|
89
89
|
}
|
|
@@ -107,10 +107,10 @@ class M {
|
|
|
107
107
|
return e.deviceInformation;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function B(o, e = console.error) {
|
|
111
111
|
o().catch(e);
|
|
112
112
|
}
|
|
113
|
-
class
|
|
113
|
+
class L {
|
|
114
114
|
constructor(e) {
|
|
115
115
|
this._client = e;
|
|
116
116
|
}
|
|
@@ -118,7 +118,7 @@ class D {
|
|
|
118
118
|
return (await this._client.request("environment.getColorScheme", {})).colorScheme;
|
|
119
119
|
}
|
|
120
120
|
subscribeColorScheme(e) {
|
|
121
|
-
|
|
121
|
+
B(async () => {
|
|
122
122
|
this._client.on("environment.colorSchemeChanged", e), e(await this.getColorScheme());
|
|
123
123
|
});
|
|
124
124
|
}
|
|
@@ -126,7 +126,7 @@ class D {
|
|
|
126
126
|
this._client.off("environment.colorSchemeChanged", e);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
class
|
|
129
|
+
class C {
|
|
130
130
|
constructor(e) {
|
|
131
131
|
this._client = e;
|
|
132
132
|
}
|
|
@@ -172,7 +172,7 @@ class B {
|
|
|
172
172
|
})).content;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
class
|
|
175
|
+
class F {
|
|
176
176
|
constructor(e) {
|
|
177
177
|
this._client = e;
|
|
178
178
|
}
|
|
@@ -186,7 +186,7 @@ class C {
|
|
|
186
186
|
* @returns A StoreSlice instance for the application scope
|
|
187
187
|
*/
|
|
188
188
|
get application() {
|
|
189
|
-
return new
|
|
189
|
+
return new y("application", "", this._client);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* Provides access to the instance store scope.
|
|
@@ -200,7 +200,7 @@ class C {
|
|
|
200
200
|
* @returns A StoreSlice instance for the instance scope
|
|
201
201
|
*/
|
|
202
202
|
get instance() {
|
|
203
|
-
return new
|
|
203
|
+
return new y("instance", this._client.applicationSpecifier, this._client);
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* Provides access to the device store scope.
|
|
@@ -215,7 +215,7 @@ class C {
|
|
|
215
215
|
* @returns A StoreSlice instance for the device scope
|
|
216
216
|
*/
|
|
217
217
|
get device() {
|
|
218
|
-
return new
|
|
218
|
+
return new y("device", this._client.applicationSpecifier, this._client);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* Provides access to the shared store scope with a specified namespace.
|
|
@@ -231,10 +231,10 @@ class C {
|
|
|
231
231
|
* @returns A StoreSlice instance for the specified shared namespace
|
|
232
232
|
*/
|
|
233
233
|
shared(e) {
|
|
234
|
-
return new
|
|
234
|
+
return new y("shared", e, this._client);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
class
|
|
237
|
+
class y {
|
|
238
238
|
constructor(e, t, n) {
|
|
239
239
|
this._kind = e, this._namespace = t, this._client = n;
|
|
240
240
|
}
|
|
@@ -302,7 +302,7 @@ class w {
|
|
|
302
302
|
*
|
|
303
303
|
* @param key The key to unsubscribe from
|
|
304
304
|
* @param handler Optional. The specific handler to remove. If not provided, all handlers for this key will be removed.
|
|
305
|
-
* @returns A promise that resolves to true if the
|
|
305
|
+
* @returns A promise that resolves to true if the unsubscribe was successful
|
|
306
306
|
*/
|
|
307
307
|
async unsubscribe(e, t) {
|
|
308
308
|
return (await this._client.unsubscribe("store.unsubscribe", {
|
|
@@ -328,7 +328,7 @@ class w {
|
|
|
328
328
|
})).success;
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
class
|
|
331
|
+
class k {
|
|
332
332
|
constructor(e) {
|
|
333
333
|
this._client = e;
|
|
334
334
|
}
|
|
@@ -351,7 +351,7 @@ class F {
|
|
|
351
351
|
return e.user;
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
|
-
class
|
|
354
|
+
class T {
|
|
355
355
|
constructor(e) {
|
|
356
356
|
this._client = e;
|
|
357
357
|
}
|
|
@@ -427,11 +427,15 @@ class k {
|
|
|
427
427
|
return t.forecast;
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
function b(o) {
|
|
431
|
+
return { ...o, type: "client" };
|
|
432
|
+
}
|
|
433
|
+
const $ = w.object({
|
|
434
|
+
type: w.literal("bridge"),
|
|
435
|
+
name: w.string(),
|
|
436
|
+
data: w.any()
|
|
433
437
|
});
|
|
434
|
-
class
|
|
438
|
+
class x {
|
|
435
439
|
/**
|
|
436
440
|
* Creates a new RootSettingsNavigation API instance.
|
|
437
441
|
*
|
|
@@ -454,11 +458,12 @@ class $ {
|
|
|
454
458
|
* @returns A promise that resolves when the navigation has been registered
|
|
455
459
|
*/
|
|
456
460
|
async setRootSettingsNavigation(e) {
|
|
457
|
-
|
|
458
|
-
n
|
|
459
|
-
|
|
461
|
+
var t;
|
|
462
|
+
const n = this._store.shared("root-settings-navigation"), r = (t = await n.get("navigation")) !== null && t !== void 0 ? t : {}, s = this._store._client._applicationSpecifier;
|
|
463
|
+
r[s] = {
|
|
464
|
+
applicationSpecifier: s,
|
|
460
465
|
entries: e.entries
|
|
461
|
-
},
|
|
466
|
+
}, n.set("navigation", r);
|
|
462
467
|
}
|
|
463
468
|
/**
|
|
464
469
|
* Retrieves the current navigation entries for this root application.
|
|
@@ -469,8 +474,9 @@ class $ {
|
|
|
469
474
|
* @returns A promise that resolves to the navigation state for this application
|
|
470
475
|
*/
|
|
471
476
|
async getRootSettingsNavigation() {
|
|
472
|
-
|
|
473
|
-
|
|
477
|
+
var e;
|
|
478
|
+
const n = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, r = this._store._client._applicationSpecifier;
|
|
479
|
+
return n[r];
|
|
474
480
|
}
|
|
475
481
|
/**
|
|
476
482
|
* Retrieves the navigation entries for all root applications.
|
|
@@ -482,10 +488,11 @@ class $ {
|
|
|
482
488
|
* @returns A promise that resolves to the navigation state for all applications
|
|
483
489
|
*/
|
|
484
490
|
async getAllRootSettingsNavigation() {
|
|
485
|
-
|
|
491
|
+
var e;
|
|
492
|
+
return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
|
|
486
493
|
}
|
|
487
494
|
}
|
|
488
|
-
class
|
|
495
|
+
class R {
|
|
489
496
|
constructor(e) {
|
|
490
497
|
this._client = e;
|
|
491
498
|
}
|
|
@@ -525,7 +532,7 @@ class x {
|
|
|
525
532
|
}
|
|
526
533
|
}
|
|
527
534
|
const g = 1e3 * 30;
|
|
528
|
-
class
|
|
535
|
+
class j {
|
|
529
536
|
/**
|
|
530
537
|
* Creates a new Client instance for communicating with the TelemetryOS platform.
|
|
531
538
|
*
|
|
@@ -551,7 +558,7 @@ class R {
|
|
|
551
558
|
* @returns An Accounts instance bound to this client
|
|
552
559
|
*/
|
|
553
560
|
get accounts() {
|
|
554
|
-
return new
|
|
561
|
+
return new E(this);
|
|
555
562
|
}
|
|
556
563
|
/**
|
|
557
564
|
* Provides access to the users API for retrieving TelemetryOS user information.
|
|
@@ -565,7 +572,7 @@ class R {
|
|
|
565
572
|
* @returns A Users instance bound to this client
|
|
566
573
|
*/
|
|
567
574
|
get users() {
|
|
568
|
-
return new
|
|
575
|
+
return new k(this);
|
|
569
576
|
}
|
|
570
577
|
/**
|
|
571
578
|
* Provides access to the store API for data persistence with multiple storage scopes.
|
|
@@ -579,7 +586,7 @@ class R {
|
|
|
579
586
|
* @returns A Store instance bound to this client
|
|
580
587
|
*/
|
|
581
588
|
get store() {
|
|
582
|
-
return new
|
|
589
|
+
return new F(this);
|
|
583
590
|
}
|
|
584
591
|
/**
|
|
585
592
|
* Provides access to the applications API for discovering other TelemetryOS applications.
|
|
@@ -593,7 +600,7 @@ class R {
|
|
|
593
600
|
* @returns An Applications instance bound to this client
|
|
594
601
|
*/
|
|
595
602
|
get applications() {
|
|
596
|
-
return new
|
|
603
|
+
return new M(this);
|
|
597
604
|
}
|
|
598
605
|
/**
|
|
599
606
|
* Provides access to the media API for working with content hosted on the TelemetryOS platform.
|
|
@@ -608,7 +615,7 @@ class R {
|
|
|
608
615
|
* @returns A Media instance bound to this client
|
|
609
616
|
*/
|
|
610
617
|
get media() {
|
|
611
|
-
return new
|
|
618
|
+
return new C(this);
|
|
612
619
|
}
|
|
613
620
|
/**
|
|
614
621
|
* Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
|
|
@@ -622,7 +629,7 @@ class R {
|
|
|
622
629
|
* @returns A Proxy instance bound to this client
|
|
623
630
|
*/
|
|
624
631
|
get proxy() {
|
|
625
|
-
return new
|
|
632
|
+
return new R(this);
|
|
626
633
|
}
|
|
627
634
|
/**
|
|
628
635
|
* Provides access to the devices API for interacting with the current device.
|
|
@@ -637,7 +644,7 @@ class R {
|
|
|
637
644
|
* @returns A Devices instance bound to this client
|
|
638
645
|
*/
|
|
639
646
|
get devices() {
|
|
640
|
-
return new
|
|
647
|
+
return new A(this);
|
|
641
648
|
}
|
|
642
649
|
/**
|
|
643
650
|
* Provides access to the root settings navigation API for TelemetryOS administration UI integration.
|
|
@@ -655,7 +662,7 @@ class R {
|
|
|
655
662
|
* @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
|
|
656
663
|
*/
|
|
657
664
|
get rootSettingsNavigation() {
|
|
658
|
-
return new
|
|
665
|
+
return new x(this.store);
|
|
659
666
|
}
|
|
660
667
|
/**
|
|
661
668
|
* Provides access to the weather API for retrieving weather data.
|
|
@@ -669,7 +676,7 @@ class R {
|
|
|
669
676
|
* @returns A Weather instance bound to this client
|
|
670
677
|
*/
|
|
671
678
|
get weather() {
|
|
672
|
-
return new
|
|
679
|
+
return new T(this);
|
|
673
680
|
}
|
|
674
681
|
get applicationName() {
|
|
675
682
|
return this._applicationName;
|
|
@@ -711,11 +718,13 @@ class R {
|
|
|
711
718
|
if (!this._applicationInstance)
|
|
712
719
|
throw new Error("Missing telemetryApplicationId query parameter");
|
|
713
720
|
this._windowMessageHandler = (s) => {
|
|
714
|
-
if (s.source === window)
|
|
721
|
+
if (s.source === window || !s.data || !("type" in s.data) || s.data.type !== "client" && s.data.type !== "bridge")
|
|
715
722
|
return;
|
|
716
|
-
|
|
717
|
-
window.
|
|
718
|
-
|
|
723
|
+
if (s.data.type === "client") {
|
|
724
|
+
window.parent.postMessage(s.data, "*");
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const l = $.safeParse(s.data);
|
|
719
728
|
if (!l.success)
|
|
720
729
|
return;
|
|
721
730
|
const u = l.data, a = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
|
|
@@ -727,6 +736,8 @@ class R {
|
|
|
727
736
|
c(u.data);
|
|
728
737
|
this._onceHandlers.delete(u.name);
|
|
729
738
|
}
|
|
739
|
+
for (let c = 0; c < window.frames.length; c += 1)
|
|
740
|
+
window.frames[c].postMessage(s.data, "*");
|
|
730
741
|
}, window.addEventListener("message", this._windowMessageHandler);
|
|
731
742
|
}
|
|
732
743
|
/**
|
|
@@ -759,14 +770,14 @@ class R {
|
|
|
759
770
|
* @param data The data payload to include with the message
|
|
760
771
|
*/
|
|
761
772
|
send(e, t) {
|
|
762
|
-
const n = {
|
|
763
|
-
telemetrySdkVersion:
|
|
773
|
+
const n = b({
|
|
774
|
+
telemetrySdkVersion: v,
|
|
764
775
|
applicationName: this._applicationName,
|
|
765
776
|
applicationSpecifier: this._applicationSpecifier,
|
|
766
777
|
applicationInstance: this._applicationInstance,
|
|
767
778
|
name: e,
|
|
768
779
|
data: t
|
|
769
|
-
};
|
|
780
|
+
});
|
|
770
781
|
window.parent.postMessage(n, "*");
|
|
771
782
|
}
|
|
772
783
|
/**
|
|
@@ -787,15 +798,15 @@ class R {
|
|
|
787
798
|
* @throws {Error} If the request times out
|
|
788
799
|
*/
|
|
789
800
|
request(e, t) {
|
|
790
|
-
const n =
|
|
791
|
-
telemetrySdkVersion:
|
|
801
|
+
const n = S(), r = b({
|
|
802
|
+
telemetrySdkVersion: v,
|
|
792
803
|
applicationName: this._applicationName,
|
|
793
804
|
applicationSpecifier: this._applicationSpecifier,
|
|
794
805
|
applicationInstance: this._applicationInstance,
|
|
795
806
|
name: e,
|
|
796
807
|
data: t,
|
|
797
808
|
responseName: n
|
|
798
|
-
};
|
|
809
|
+
});
|
|
799
810
|
window.parent.postMessage(r, "*");
|
|
800
811
|
let s = !1, l;
|
|
801
812
|
const u = new Promise((h, c) => {
|
|
@@ -813,11 +824,11 @@ class R {
|
|
|
813
824
|
async subscribe(e, t, n) {
|
|
814
825
|
let r, s;
|
|
815
826
|
typeof t == "function" ? s = t : (r = t, s = n);
|
|
816
|
-
const l =
|
|
827
|
+
const l = S(), u = S();
|
|
817
828
|
let a = this._subscriptionNamesBySubjectName.get(e);
|
|
818
829
|
a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(l), this._subscriptionNamesByHandler.set(s, l), this.on(l, s);
|
|
819
|
-
const h = {
|
|
820
|
-
telemetrySdkVersion:
|
|
830
|
+
const h = b({
|
|
831
|
+
telemetrySdkVersion: v,
|
|
821
832
|
applicationName: this._applicationName,
|
|
822
833
|
applicationSpecifier: this._applicationSpecifier,
|
|
823
834
|
applicationInstance: this._applicationInstance,
|
|
@@ -825,25 +836,25 @@ class R {
|
|
|
825
836
|
data: r,
|
|
826
837
|
responseName: u,
|
|
827
838
|
subscriptionName: l
|
|
828
|
-
};
|
|
839
|
+
});
|
|
829
840
|
window.parent.postMessage(h, "*");
|
|
830
841
|
let c = !1, d;
|
|
831
|
-
const
|
|
842
|
+
const N = new Promise((_, f) => {
|
|
832
843
|
const m = new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);
|
|
833
844
|
setTimeout(() => {
|
|
834
845
|
c = !0, this.off(u, d), f(m);
|
|
835
846
|
}, g);
|
|
836
|
-
}),
|
|
847
|
+
}), H = new Promise((_) => {
|
|
837
848
|
d = (f) => {
|
|
838
849
|
c || _(f);
|
|
839
850
|
}, this.on(u, _);
|
|
840
851
|
});
|
|
841
|
-
return Promise.race([
|
|
852
|
+
return Promise.race([N, H]);
|
|
842
853
|
}
|
|
843
854
|
async unsubscribe(e, t, n) {
|
|
844
855
|
let r, s;
|
|
845
856
|
typeof t == "function" ? s = t : (r = t, s = n);
|
|
846
|
-
const l =
|
|
857
|
+
const l = S();
|
|
847
858
|
let u = [];
|
|
848
859
|
if (s) {
|
|
849
860
|
const a = this._subscriptionNamesByHandler.get(s);
|
|
@@ -854,8 +865,8 @@ class R {
|
|
|
854
865
|
return { success: !1 };
|
|
855
866
|
for await (const a of u) {
|
|
856
867
|
this.off(a, s);
|
|
857
|
-
const h = {
|
|
858
|
-
telemetrySdkVersion:
|
|
868
|
+
const h = b({
|
|
869
|
+
telemetrySdkVersion: v,
|
|
859
870
|
applicationInstance: this._applicationInstance,
|
|
860
871
|
applicationName: this._applicationName,
|
|
861
872
|
applicationSpecifier: this._applicationSpecifier,
|
|
@@ -863,20 +874,20 @@ class R {
|
|
|
863
874
|
data: r,
|
|
864
875
|
responseName: l,
|
|
865
876
|
unsubscribeName: a
|
|
866
|
-
};
|
|
877
|
+
});
|
|
867
878
|
window.parent.postMessage(h, "*");
|
|
868
879
|
let c = !1, d;
|
|
869
|
-
const
|
|
870
|
-
const
|
|
880
|
+
const N = new Promise((f, m) => {
|
|
881
|
+
const q = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);
|
|
871
882
|
setTimeout(() => {
|
|
872
|
-
c = !0, this.off(l, d), m(
|
|
883
|
+
c = !0, this.off(l, d), m(q);
|
|
873
884
|
}, g);
|
|
874
|
-
}),
|
|
885
|
+
}), H = new Promise((f) => {
|
|
875
886
|
d = (m) => {
|
|
876
887
|
c || f(m);
|
|
877
888
|
}, this.once(l, f);
|
|
878
889
|
});
|
|
879
|
-
if (!(await Promise.race([
|
|
890
|
+
if (!(await Promise.race([N, H])).success)
|
|
880
891
|
return { success: !1 };
|
|
881
892
|
}
|
|
882
893
|
return { success: !0 };
|
|
@@ -953,66 +964,66 @@ class R {
|
|
|
953
964
|
}
|
|
954
965
|
}
|
|
955
966
|
}
|
|
956
|
-
function
|
|
967
|
+
function S() {
|
|
957
968
|
return Math.random().toString(36).slice(2, 9);
|
|
958
969
|
}
|
|
959
|
-
const
|
|
970
|
+
const v = P.version;
|
|
960
971
|
let i = null;
|
|
961
|
-
function
|
|
972
|
+
function U() {
|
|
962
973
|
return i;
|
|
963
974
|
}
|
|
964
|
-
function
|
|
965
|
-
i = new
|
|
975
|
+
function V(o) {
|
|
976
|
+
i = new j(o), i.bind();
|
|
966
977
|
}
|
|
967
|
-
function
|
|
978
|
+
function z() {
|
|
968
979
|
i == null || i.unbind(), i = null;
|
|
969
980
|
}
|
|
970
|
-
function
|
|
981
|
+
function G(...o) {
|
|
971
982
|
return p(i), i.on(...o);
|
|
972
983
|
}
|
|
973
|
-
function
|
|
984
|
+
function J(...o) {
|
|
974
985
|
return p(i), i.once(...o);
|
|
975
986
|
}
|
|
976
|
-
function
|
|
987
|
+
function K(...o) {
|
|
977
988
|
return p(i), i.off(...o);
|
|
978
989
|
}
|
|
979
|
-
function
|
|
990
|
+
function O(...o) {
|
|
980
991
|
return p(i), i.send(...o);
|
|
981
992
|
}
|
|
982
|
-
function
|
|
993
|
+
function W(...o) {
|
|
983
994
|
return p(i), i.request(...o);
|
|
984
995
|
}
|
|
985
|
-
function
|
|
996
|
+
function Q(...o) {
|
|
986
997
|
return p(i), i.subscribe(...o);
|
|
987
998
|
}
|
|
988
|
-
function
|
|
999
|
+
function X(...o) {
|
|
989
1000
|
return p(i), i.unsubscribe(...o);
|
|
990
1001
|
}
|
|
991
|
-
function
|
|
1002
|
+
function Y() {
|
|
992
1003
|
return p(i), i.store;
|
|
993
1004
|
}
|
|
994
|
-
function
|
|
1005
|
+
function Z() {
|
|
995
1006
|
return p(i), i.applications;
|
|
996
1007
|
}
|
|
997
|
-
function
|
|
1008
|
+
function ee() {
|
|
998
1009
|
return p(i), i.media;
|
|
999
1010
|
}
|
|
1000
|
-
function
|
|
1011
|
+
function te() {
|
|
1001
1012
|
return p(i), i.accounts;
|
|
1002
1013
|
}
|
|
1003
|
-
function
|
|
1014
|
+
function se() {
|
|
1004
1015
|
return p(i), i.users;
|
|
1005
1016
|
}
|
|
1006
|
-
function
|
|
1017
|
+
function ne() {
|
|
1007
1018
|
return p(i), i.devices;
|
|
1008
1019
|
}
|
|
1009
|
-
function
|
|
1020
|
+
function ie() {
|
|
1010
1021
|
return p(i), i.proxy;
|
|
1011
1022
|
}
|
|
1012
|
-
function
|
|
1023
|
+
function re() {
|
|
1013
1024
|
return p(i), i.rootSettingsNavigation;
|
|
1014
1025
|
}
|
|
1015
|
-
function
|
|
1026
|
+
function oe() {
|
|
1016
1027
|
return p(i), i.weather;
|
|
1017
1028
|
}
|
|
1018
1029
|
function p(o) {
|
|
@@ -1020,33 +1031,33 @@ function p(o) {
|
|
|
1020
1031
|
throw new Error("SDK is not configured");
|
|
1021
1032
|
}
|
|
1022
1033
|
export {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1034
|
+
E as Accounts,
|
|
1035
|
+
M as Applications,
|
|
1036
|
+
j as Client,
|
|
1037
|
+
A as Devices,
|
|
1038
|
+
L as Environment,
|
|
1039
|
+
C as Media,
|
|
1040
|
+
F as Store,
|
|
1041
|
+
k as Users,
|
|
1042
|
+
T as Weather,
|
|
1043
|
+
te as accounts,
|
|
1044
|
+
Z as applications,
|
|
1045
|
+
V as configure,
|
|
1046
|
+
z as destroy,
|
|
1047
|
+
ne as devices,
|
|
1048
|
+
U as globalClient,
|
|
1049
|
+
ee as media,
|
|
1050
|
+
K as off,
|
|
1051
|
+
G as on,
|
|
1052
|
+
J as once,
|
|
1053
|
+
ie as proxy,
|
|
1054
|
+
W as request,
|
|
1055
|
+
re as rootSettingsNavigation,
|
|
1056
|
+
O as send,
|
|
1057
|
+
Y as store,
|
|
1058
|
+
Q as subscribe,
|
|
1059
|
+
v as telemetrySdkVersion,
|
|
1060
|
+
X as unsubscribe,
|
|
1061
|
+
se as users,
|
|
1062
|
+
oe as weather
|
|
1052
1063
|
};
|
package/dist/store.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ declare class StoreSlice {
|
|
|
78
78
|
* @param value The value to store - must be JSON serializable
|
|
79
79
|
* @returns A promise that resolves to true if the value was saved successfully
|
|
80
80
|
*/
|
|
81
|
-
set(key: string, value:
|
|
81
|
+
set<T>(key: string, value: T): Promise<boolean>;
|
|
82
82
|
/**
|
|
83
83
|
* Retrieves a value from the store.
|
|
84
84
|
*
|
|
@@ -90,7 +90,7 @@ declare class StoreSlice {
|
|
|
90
90
|
* @param key The key to retrieve the value for
|
|
91
91
|
* @returns A promise that resolves to the stored value, or undefined if the key does not exist
|
|
92
92
|
*/
|
|
93
|
-
get<T>(key: string): Promise<T>;
|
|
93
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
94
94
|
/**
|
|
95
95
|
* Subscribes to changes in the store for a specific key.
|
|
96
96
|
*
|
|
@@ -103,7 +103,7 @@ declare class StoreSlice {
|
|
|
103
103
|
* @param handler The callback function to call when the value changes
|
|
104
104
|
* @returns A promise that resolves to true if the subscription was successful
|
|
105
105
|
*/
|
|
106
|
-
subscribe(key: string, handler: MessageHandler<
|
|
106
|
+
subscribe<T>(key: string, handler: MessageHandler<T | undefined>): Promise<boolean>;
|
|
107
107
|
/**
|
|
108
108
|
* Unsubscribes from changes in the store for a specific key.
|
|
109
109
|
*
|
|
@@ -112,9 +112,9 @@ declare class StoreSlice {
|
|
|
112
112
|
*
|
|
113
113
|
* @param key The key to unsubscribe from
|
|
114
114
|
* @param handler Optional. The specific handler to remove. If not provided, all handlers for this key will be removed.
|
|
115
|
-
* @returns A promise that resolves to true if the
|
|
115
|
+
* @returns A promise that resolves to true if the unsubscribe was successful
|
|
116
116
|
*/
|
|
117
|
-
unsubscribe(key: string, handler?: MessageHandler<
|
|
117
|
+
unsubscribe<T>(key: string, handler?: MessageHandler<T | undefined>): Promise<boolean>;
|
|
118
118
|
/**
|
|
119
119
|
* Deletes a value from the store.
|
|
120
120
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "The official TelemetryOS root application sdk package. Provides types and apis for building root TelemetryOS applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
File without changes
|