@telemetryos/root-sdk 1.6.1 → 1.7.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/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { z as y } from "./index-B98VDFRY.js";
2
- const q = "1.6.1", E = {
3
- version: q
1
+ import { o as P, a as M, s as T, l as C } from "./types-CCzf8sMT.js";
2
+ const B = "1.7.1", A = {
3
+ version: B
4
4
  };
5
- class M {
5
+ class k {
6
6
  constructor(e) {
7
7
  this._client = e;
8
8
  }
@@ -21,7 +21,7 @@ class M {
21
21
  return e.account;
22
22
  }
23
23
  }
24
- class P {
24
+ class F {
25
25
  constructor(e) {
26
26
  this._client = e;
27
27
  }
@@ -118,7 +118,7 @@ class P {
118
118
  this._client._messageInterceptors.set(e, t);
119
119
  }
120
120
  }
121
- class C {
121
+ class $ {
122
122
  constructor(e) {
123
123
  this._client = e;
124
124
  }
@@ -142,26 +142,21 @@ class C {
142
142
  return e.deviceInformation;
143
143
  }
144
144
  }
145
- function A(a, e = console.error) {
146
- a().catch(e);
147
- }
148
- class B {
145
+ class R {
149
146
  constructor(e) {
150
147
  this._client = e;
151
148
  }
152
149
  async getColorScheme() {
153
150
  return (await this._client.request("environment.getColorScheme", {})).colorScheme;
154
151
  }
155
- subscribeColorScheme(e) {
156
- A(async () => {
157
- this._client.on("environment.colorSchemeChanged", e), e(await this.getColorScheme());
158
- });
152
+ async subscribeColorScheme(e) {
153
+ return (await this._client.subscribe("environment.subscribeColorScheme", {}, e)).success;
159
154
  }
160
- unsubscribeColorScheme(e) {
161
- this._client.off("environment.colorSchemeChanged", e);
155
+ async unsubscribeColorScheme(e) {
156
+ return (await this._client.unsubscribe("environment.unsubscribeColorScheme", {}, e)).success;
162
157
  }
163
158
  }
164
- class T {
159
+ class x {
165
160
  constructor(e) {
166
161
  this._client = e;
167
162
  }
@@ -207,7 +202,7 @@ class T {
207
202
  })).content;
208
203
  }
209
204
  }
210
- class F {
205
+ class j {
211
206
  constructor(e) {
212
207
  this._client = e;
213
208
  }
@@ -256,7 +251,7 @@ class F {
256
251
  return new Response(d, c);
257
252
  }
258
253
  }
259
- class k {
254
+ class D {
260
255
  constructor(e) {
261
256
  this._client = e;
262
257
  }
@@ -270,7 +265,7 @@ class k {
270
265
  * @returns A StoreSlice instance for the application scope
271
266
  */
272
267
  get application() {
273
- return new b("application", "", this._client);
268
+ return new v("application", "", this._client);
274
269
  }
275
270
  /**
276
271
  * Provides access to the instance store scope.
@@ -284,7 +279,7 @@ class k {
284
279
  * @returns A StoreSlice instance for the instance scope
285
280
  */
286
281
  get instance() {
287
- return new b("instance", this._client.applicationInstance, this._client);
282
+ return new v("instance", this._client.applicationInstance, this._client);
288
283
  }
289
284
  /**
290
285
  * Provides access to the device store scope.
@@ -299,7 +294,7 @@ class k {
299
294
  * @returns A StoreSlice instance for the device scope
300
295
  */
301
296
  get device() {
302
- return new b("device", this._client.applicationInstance, this._client);
297
+ return new v("device", this._client.applicationInstance, this._client);
303
298
  }
304
299
  /**
305
300
  * Provides access to the shared store scope with a specified namespace.
@@ -315,10 +310,10 @@ class k {
315
310
  * @returns A StoreSlice instance for the specified shared namespace
316
311
  */
317
312
  shared(e) {
318
- return new b("shared", e, this._client);
313
+ return new v("shared", e, this._client);
319
314
  }
320
315
  }
321
- class b {
316
+ class v {
322
317
  constructor(e, t, s) {
323
318
  this._kind = e, this._namespace = t, this._client = s;
324
319
  }
@@ -412,7 +407,7 @@ class b {
412
407
  })).success;
413
408
  }
414
409
  }
415
- class $ {
410
+ class L {
416
411
  constructor(e) {
417
412
  this._client = e;
418
413
  }
@@ -435,7 +430,7 @@ class $ {
435
430
  return e.user;
436
431
  }
437
432
  }
438
- class x {
433
+ class U {
439
434
  constructor(e) {
440
435
  this._client = e;
441
436
  }
@@ -511,15 +506,15 @@ class x {
511
506
  return t.forecast;
512
507
  }
513
508
  }
514
- function v(a) {
509
+ function S(a) {
515
510
  return { ...a, type: "client" };
516
511
  }
517
- const R = y.object({
518
- type: y.literal("bridge"),
519
- name: y.string(),
520
- data: y.any()
512
+ const V = P({
513
+ type: C("bridge"),
514
+ name: T(),
515
+ data: M()
521
516
  });
522
- class j {
517
+ class W {
523
518
  /**
524
519
  * Creates a new RootSettingsNavigation API instance.
525
520
  *
@@ -576,8 +571,11 @@ class j {
576
571
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
577
572
  }
578
573
  }
579
- const m = 1e3 * 30;
580
- class D {
574
+ const _ = 1e3 * 30, q = typeof window > "u" && typeof self < "u", y = q ? self : window;
575
+ function w(a) {
576
+ q ? self.postMessage(a) : y.parent.postMessage(a, "*");
577
+ }
578
+ class G {
581
579
  /**
582
580
  * Creates a new Client instance for communicating with the TelemetryOS platform.
583
581
  *
@@ -603,7 +601,7 @@ class D {
603
601
  * @returns An Accounts instance bound to this client
604
602
  */
605
603
  get accounts() {
606
- return new M(this);
604
+ return new k(this);
607
605
  }
608
606
  /**
609
607
  * Provides access to the users API for retrieving TelemetryOS user information.
@@ -617,7 +615,7 @@ class D {
617
615
  * @returns A Users instance bound to this client
618
616
  */
619
617
  get users() {
620
- return new $(this);
618
+ return new L(this);
621
619
  }
622
620
  /**
623
621
  * Provides access to the store API for data persistence with multiple storage scopes.
@@ -631,7 +629,7 @@ class D {
631
629
  * @returns A Store instance bound to this client
632
630
  */
633
631
  get store() {
634
- return new k(this);
632
+ return new D(this);
635
633
  }
636
634
  /**
637
635
  * Provides access to the applications API for discovering other TelemetryOS applications.
@@ -645,7 +643,7 @@ class D {
645
643
  * @returns An Applications instance bound to this client
646
644
  */
647
645
  get applications() {
648
- return new P(this);
646
+ return new F(this);
649
647
  }
650
648
  /**
651
649
  * Provides access to the media API for working with content hosted on the TelemetryOS platform.
@@ -660,7 +658,7 @@ class D {
660
658
  * @returns A Media instance bound to this client
661
659
  */
662
660
  get media() {
663
- return new T(this);
661
+ return new x(this);
664
662
  }
665
663
  /**
666
664
  * Provides access to the proxy API for fetching third-party content through the TelemetryOS API.
@@ -674,7 +672,7 @@ class D {
674
672
  * @returns A Proxy instance bound to this client
675
673
  */
676
674
  get proxy() {
677
- return new F(this);
675
+ return new j(this);
678
676
  }
679
677
  /**
680
678
  * Provides access to the devices API for interacting with the current device.
@@ -689,7 +687,7 @@ class D {
689
687
  * @returns A Devices instance bound to this client
690
688
  */
691
689
  get devices() {
692
- return new C(this);
690
+ return new $(this);
693
691
  }
694
692
  /**
695
693
  * Provides access to the root settings navigation API for TelemetryOS administration UI integration.
@@ -707,7 +705,7 @@ class D {
707
705
  * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
708
706
  */
709
707
  get rootSettingsNavigation() {
710
- return new j(this.store);
708
+ return new W(this.store);
711
709
  }
712
710
  /**
713
711
  * Provides access to the weather API for retrieving weather data.
@@ -721,7 +719,7 @@ class D {
721
719
  * @returns A Weather instance bound to this client
722
720
  */
723
721
  get weather() {
724
- return new x(this);
722
+ return new U(this);
725
723
  }
726
724
  /**
727
725
  * Provides access to the environment API for accessing environment settings.
@@ -735,7 +733,7 @@ class D {
735
733
  * @returns An Environment instance bound to this client
736
734
  */
737
735
  get environment() {
738
- return new B(this);
736
+ return new R(this);
739
737
  }
740
738
  get applicationName() {
741
739
  return this._applicationName;
@@ -763,7 +761,7 @@ class D {
763
761
  */
764
762
  bind() {
765
763
  var e, t, s;
766
- const o = new URL(window.location.href), r = o.searchParams;
764
+ const o = new URL(y.location.href), r = o.searchParams;
767
765
  if (this._applicationInstance = (e = r.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
768
766
  throw new Error("Missing applicationInstance query parameter");
769
767
  if (this._applicationSpecifier = (t = r.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
@@ -773,19 +771,19 @@ class D {
773
771
  if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
774
772
  throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
775
773
  this._windowMessageHandler = (n) => {
776
- if (n.source === window || !n.data || !("type" in n.data) || n.data.type !== "client" && n.data.type !== "bridge")
774
+ if (n.source === y || !n.data || !("type" in n.data) || n.data.type !== "client" && n.data.type !== "bridge")
777
775
  return;
778
776
  let l;
779
777
  if (n.data.type === "client") {
780
778
  const c = this._messageInterceptors.get(n.data.name);
781
779
  if (!c) {
782
- window.parent.postMessage(n.data, "*");
780
+ w(n.data);
783
781
  return;
784
782
  }
785
783
  l = { ...c(n.data.data), type: "bridge" };
786
784
  }
787
785
  if (!l) {
788
- const c = R.safeParse(n.data);
786
+ const c = V.safeParse(n.data);
789
787
  if (!c.success)
790
788
  return;
791
789
  l = c.data;
@@ -799,9 +797,10 @@ class D {
799
797
  this._onceHandlers.delete(l.name);
800
798
  }
801
799
  }
802
- for (let c = 0; c < window.frames.length; c += 1)
803
- window.frames[c].postMessage(l, "*");
804
- }, window.addEventListener("message", this._windowMessageHandler);
800
+ if (!q)
801
+ for (let c = 0; c < window.frames.length; c += 1)
802
+ window.frames[c].postMessage(l, "*");
803
+ }, y.addEventListener("message", this._windowMessageHandler);
805
804
  }
806
805
  /**
807
806
  * Removes the message event listener and cleans up resources.
@@ -817,7 +816,7 @@ class D {
817
816
  * of managing their own Client instances.
818
817
  */
819
818
  unbind() {
820
- this._windowMessageHandler && window.removeEventListener("message", this._windowMessageHandler);
819
+ this._windowMessageHandler && y.removeEventListener("message", this._windowMessageHandler);
821
820
  }
822
821
  /**
823
822
  * Sends a one-way message to the TelemetryOS platform.
@@ -833,15 +832,15 @@ class D {
833
832
  * @param data The data payload to include with the message
834
833
  */
835
834
  send(e, t) {
836
- const s = v({
837
- telemetrySdkVersion: N,
835
+ const s = S({
836
+ telemetrySdkVersion: I,
838
837
  applicationName: this._applicationName,
839
838
  applicationSpecifier: this._applicationSpecifier,
840
839
  applicationInstance: this._applicationInstance,
841
840
  name: e,
842
841
  data: t
843
842
  });
844
- window.parent.postMessage(s, "*");
843
+ w(s);
845
844
  }
846
845
  /**
847
846
  * Sends a message to the TelemetryOS platform and waits for a response.
@@ -861,8 +860,8 @@ class D {
861
860
  * @throws {Error} If the request times out
862
861
  */
863
862
  request(e, t) {
864
- const s = S(), o = v({
865
- telemetrySdkVersion: N,
863
+ const s = N(), o = S({
864
+ telemetrySdkVersion: I,
866
865
  applicationName: this._applicationName,
867
866
  applicationSpecifier: this._applicationSpecifier,
868
867
  applicationInstance: this._applicationInstance,
@@ -870,13 +869,13 @@ class D {
870
869
  data: t,
871
870
  responseName: s
872
871
  });
873
- window.parent.postMessage(o, "*");
872
+ w(o);
874
873
  let r = !1, n;
875
874
  const l = new Promise((d, u) => {
876
- const p = new Error(`${e} message request with response name of ${s} timed out after ${m}`);
875
+ const p = new Error(`${e} message request with response name of ${s} timed out after ${_}`);
877
876
  setTimeout(() => {
878
877
  r = !0, this.off(s, n), u(p);
879
- }, m);
878
+ }, _);
880
879
  }), c = new Promise((d) => {
881
880
  n = (u) => {
882
881
  r || d(u);
@@ -887,11 +886,11 @@ class D {
887
886
  async subscribe(e, t, s) {
888
887
  let o, r;
889
888
  typeof t == "function" ? r = t : (o = t, r = s);
890
- const n = S(), l = S();
889
+ const n = N(), l = N();
891
890
  let c = this._subscriptionNamesBySubjectName.get(e);
892
891
  c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(n), this._subscriptionNamesByHandler.set(r, n), this.on(n, r);
893
- const d = v({
894
- telemetrySdkVersion: N,
892
+ const d = S({
893
+ telemetrySdkVersion: I,
895
894
  applicationName: this._applicationName,
896
895
  applicationSpecifier: this._applicationSpecifier,
897
896
  applicationInstance: this._applicationInstance,
@@ -900,24 +899,24 @@ class D {
900
899
  responseName: l,
901
900
  subscriptionName: n
902
901
  });
903
- window.parent.postMessage(d, "*");
902
+ w(d);
904
903
  let u = !1, p;
905
- const f = new Promise((w, g) => {
906
- const _ = new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${m}`);
904
+ const f = new Promise((b, g) => {
905
+ const m = new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${_}`);
907
906
  setTimeout(() => {
908
- u = !0, this.off(l, p), g(_);
909
- }, m);
910
- }), I = new Promise((w) => {
907
+ u = !0, this.off(l, p), g(m);
908
+ }, _);
909
+ }), H = new Promise((b) => {
911
910
  p = (g) => {
912
- u || w(g);
913
- }, this.on(l, w);
911
+ u || b(g);
912
+ }, this.on(l, b);
914
913
  });
915
- return Promise.race([f, I]);
914
+ return Promise.race([f, H]);
916
915
  }
917
916
  async unsubscribe(e, t, s) {
918
917
  let o, r;
919
918
  typeof t == "function" ? r = t : (o = t, r = s);
920
- const n = S();
919
+ const n = N();
921
920
  let l = [];
922
921
  if (r) {
923
922
  const c = this._subscriptionNamesByHandler.get(r);
@@ -928,8 +927,8 @@ class D {
928
927
  return { success: !1 };
929
928
  for await (const c of l) {
930
929
  this.off(c, r);
931
- const d = v({
932
- telemetrySdkVersion: N,
930
+ const d = S({
931
+ telemetrySdkVersion: I,
933
932
  applicationInstance: this._applicationInstance,
934
933
  applicationName: this._applicationName,
935
934
  applicationSpecifier: this._applicationSpecifier,
@@ -938,19 +937,19 @@ class D {
938
937
  responseName: n,
939
938
  unsubscribeName: c
940
939
  });
941
- window.parent.postMessage(d, "*");
940
+ w(d);
942
941
  let u = !1, p;
943
- const f = new Promise((g, _) => {
944
- const H = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${m}`);
942
+ const f = new Promise((g, m) => {
943
+ const E = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${_}`);
945
944
  setTimeout(() => {
946
- u = !0, this.off(n, p), _(H);
947
- }, m);
948
- }), I = new Promise((g) => {
949
- p = (_) => {
950
- u || g(_);
945
+ u = !0, this.off(n, p), m(E);
946
+ }, _);
947
+ }), H = new Promise((g) => {
948
+ p = (m) => {
949
+ u || g(m);
951
950
  }, this.once(n, g);
952
951
  });
953
- if (!(await Promise.race([f, I])).success)
952
+ if (!(await Promise.race([f, H])).success)
954
953
  return { success: !1 };
955
954
  }
956
955
  return { success: !0 };
@@ -1027,69 +1026,69 @@ class D {
1027
1026
  }
1028
1027
  }
1029
1028
  }
1030
- function S() {
1029
+ function N() {
1031
1030
  return Math.random().toString(36).slice(2, 9);
1032
1031
  }
1033
- const N = E.version;
1032
+ const I = A.version;
1034
1033
  let i = null;
1035
- function U() {
1034
+ function K() {
1036
1035
  return i;
1037
1036
  }
1038
- function V(a) {
1039
- i = new D(a), i.bind();
1037
+ function O(a) {
1038
+ i = new G(a), i.bind();
1040
1039
  }
1041
1040
  function z() {
1042
1041
  i == null || i.unbind(), i = null;
1043
1042
  }
1044
- function G(...a) {
1043
+ function Q(...a) {
1045
1044
  return h(i), i.on(...a);
1046
1045
  }
1047
- function J(...a) {
1046
+ function X(...a) {
1048
1047
  return h(i), i.once(...a);
1049
1048
  }
1050
- function K(...a) {
1049
+ function Y(...a) {
1051
1050
  return h(i), i.off(...a);
1052
1051
  }
1053
- function O(...a) {
1052
+ function Z(...a) {
1054
1053
  return h(i), i.send(...a);
1055
1054
  }
1056
- function W(...a) {
1055
+ function ee(...a) {
1057
1056
  return h(i), i.request(...a);
1058
1057
  }
1059
- function Q(...a) {
1058
+ function te(...a) {
1060
1059
  return h(i), i.subscribe(...a);
1061
1060
  }
1062
- function X(...a) {
1061
+ function se(...a) {
1063
1062
  return h(i), i.unsubscribe(...a);
1064
1063
  }
1065
- function Y() {
1064
+ function ne() {
1066
1065
  return h(i), i.store;
1067
1066
  }
1068
- function Z() {
1067
+ function ie() {
1069
1068
  return h(i), i.applications;
1070
1069
  }
1071
- function ee() {
1070
+ function re() {
1072
1071
  return h(i), i.media;
1073
1072
  }
1074
- function te() {
1073
+ function oe() {
1075
1074
  return h(i), i.accounts;
1076
1075
  }
1077
- function se() {
1076
+ function ae() {
1078
1077
  return h(i), i.users;
1079
1078
  }
1080
- function ne() {
1079
+ function ce() {
1081
1080
  return h(i), i.devices;
1082
1081
  }
1083
- function ie() {
1082
+ function le() {
1084
1083
  return h(i), i.proxy;
1085
1084
  }
1086
- function re() {
1085
+ function ue() {
1087
1086
  return h(i), i.rootSettingsNavigation;
1088
1087
  }
1089
- function oe() {
1088
+ function pe() {
1090
1089
  return h(i), i.weather;
1091
1090
  }
1092
- function ae() {
1091
+ function he() {
1093
1092
  return h(i), i.environment;
1094
1093
  }
1095
1094
  function h(a) {
@@ -1097,35 +1096,36 @@ function h(a) {
1097
1096
  throw new Error("SDK is not configured");
1098
1097
  }
1099
1098
  export {
1100
- M as Accounts,
1101
- P as Applications,
1102
- D as Client,
1103
- C as Devices,
1104
- B as Environment,
1105
- T as Media,
1106
- F as Proxy,
1107
- k as Store,
1108
- $ as Users,
1109
- x as Weather,
1110
- te as accounts,
1111
- Z as applications,
1112
- V as configure,
1099
+ k as Accounts,
1100
+ F as Applications,
1101
+ G as Client,
1102
+ $ as Devices,
1103
+ R as Environment,
1104
+ x as Media,
1105
+ j as Proxy,
1106
+ D as Store,
1107
+ v as StoreSlice,
1108
+ L as Users,
1109
+ U as Weather,
1110
+ oe as accounts,
1111
+ ie as applications,
1112
+ O as configure,
1113
1113
  z as destroy,
1114
- ne as devices,
1115
- ae as environment,
1116
- U as globalClient,
1117
- ee as media,
1118
- K as off,
1119
- G as on,
1120
- J as once,
1121
- ie as proxy,
1122
- W as request,
1123
- re as rootSettingsNavigation,
1124
- O as send,
1125
- Y as store,
1126
- Q as subscribe,
1127
- N as telemetrySdkVersion,
1128
- X as unsubscribe,
1129
- se as users,
1130
- oe as weather
1114
+ ce as devices,
1115
+ he as environment,
1116
+ K as globalClient,
1117
+ re as media,
1118
+ Y as off,
1119
+ Q as on,
1120
+ X as once,
1121
+ le as proxy,
1122
+ ee as request,
1123
+ ue as rootSettingsNavigation,
1124
+ Z as send,
1125
+ ne as store,
1126
+ te as subscribe,
1127
+ I as telemetrySdkVersion,
1128
+ se as unsubscribe,
1129
+ ae as users,
1130
+ pe as weather
1131
1131
  };
package/dist/store.d.ts CHANGED
@@ -62,7 +62,7 @@ export declare class Store {
62
62
  * This class is not typically instantiated directly by applications. Instead, use the
63
63
  * properties and methods of the Store class to access the appropriate StoreSlice.
64
64
  */
65
- declare class StoreSlice {
65
+ export declare class StoreSlice {
66
66
  _kind: string;
67
67
  _namespace: string;
68
68
  _client: Client;
@@ -126,4 +126,3 @@ declare class StoreSlice {
126
126
  */
127
127
  delete(key: string): Promise<boolean>;
128
128
  }
129
- export {};