@telemetryos/root-sdk 1.5.1 → 1.7.0

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.5.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.0", 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 L {
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 B {
159
+ class x {
165
160
  constructor(e) {
166
161
  this._client = e;
167
162
  }
@@ -207,7 +202,7 @@ class B {
207
202
  })).content;
208
203
  }
209
204
  }
210
- class T {
205
+ class j {
211
206
  constructor(e) {
212
207
  this._client = e;
213
208
  }
@@ -245,18 +240,18 @@ class T {
245
240
  statusText: n.statusText,
246
241
  headers: l
247
242
  };
248
- let h = null;
243
+ let d = null;
249
244
  if (n.body !== null && n.body !== void 0)
250
245
  if (n.bodyType === "binary") {
251
246
  const u = atob(n.body), p = new Uint8Array(u.length);
252
247
  for (let f = 0; f < u.length; f++)
253
248
  p[f] = u.charCodeAt(f);
254
- h = p;
255
- } else n.bodyType === "text" ? h = n.body : n.bodyType === "json" && (h = JSON.stringify(n.body));
256
- return new Response(h, c);
249
+ d = p;
250
+ } else n.bodyType === "text" ? d = n.body : n.bodyType === "json" && (d = JSON.stringify(n.body));
251
+ return new Response(d, c);
257
252
  }
258
253
  }
259
- class F {
254
+ class D {
260
255
  constructor(e) {
261
256
  this._client = e;
262
257
  }
@@ -270,7 +265,7 @@ class F {
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 F {
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 F {
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 F {
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 k {
410
+ class L {
416
411
  constructor(e) {
417
412
  this._client = e;
418
413
  }
@@ -435,7 +430,7 @@ class k {
435
430
  return e.user;
436
431
  }
437
432
  }
438
- class $ {
433
+ class U {
439
434
  constructor(e) {
440
435
  this._client = e;
441
436
  }
@@ -514,12 +509,12 @@ class $ {
514
509
  function S(a) {
515
510
  return { ...a, type: "client" };
516
511
  }
517
- const x = 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 R {
517
+ class W {
523
518
  /**
524
519
  * Creates a new RootSettingsNavigation API instance.
525
520
  *
@@ -576,8 +571,11 @@ class R {
576
571
  return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
577
572
  }
578
573
  }
579
- const _ = 1e3 * 30;
580
- class j {
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 j {
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 j {
617
615
  * @returns A Users instance bound to this client
618
616
  */
619
617
  get users() {
620
- return new k(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 j {
631
629
  * @returns A Store instance bound to this client
632
630
  */
633
631
  get store() {
634
- return new F(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 j {
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 j {
660
658
  * @returns A Media instance bound to this client
661
659
  */
662
660
  get media() {
663
- return new B(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 j {
674
672
  * @returns A Proxy instance bound to this client
675
673
  */
676
674
  get proxy() {
677
- return new T(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 j {
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 j {
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 R(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,21 @@ class j {
721
719
  * @returns A Weather instance bound to this client
722
720
  */
723
721
  get weather() {
724
- return new $(this);
722
+ return new U(this);
723
+ }
724
+ /**
725
+ * Provides access to the environment API for accessing environment settings.
726
+ *
727
+ * This property returns a new Environment instance that allows applications to get
728
+ * and subscribe to environment settings such as the current color scheme.
729
+ *
730
+ * NOTE: Most application developers should use the global environment() function
731
+ * instead of accessing this property directly.
732
+ *
733
+ * @returns An Environment instance bound to this client
734
+ */
735
+ get environment() {
736
+ return new R(this);
725
737
  }
726
738
  get applicationName() {
727
739
  return this._applicationName;
@@ -749,7 +761,7 @@ class j {
749
761
  */
750
762
  bind() {
751
763
  var e, t, s;
752
- const o = new URL(window.location.href), r = o.searchParams;
764
+ const o = new URL(y.location.href), r = o.searchParams;
753
765
  if (this._applicationInstance = (e = r.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
754
766
  throw new Error("Missing applicationInstance query parameter");
755
767
  if (this._applicationSpecifier = (t = r.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
@@ -759,25 +771,25 @@ class j {
759
771
  if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
760
772
  throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
761
773
  this._windowMessageHandler = (n) => {
762
- 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")
763
775
  return;
764
776
  let l;
765
777
  if (n.data.type === "client") {
766
778
  const c = this._messageInterceptors.get(n.data.name);
767
779
  if (!c) {
768
- window.parent.postMessage(n.data, "*");
780
+ w(n.data);
769
781
  return;
770
782
  }
771
783
  l = { ...c(n.data.data), type: "bridge" };
772
784
  }
773
785
  if (!l) {
774
- const c = x.safeParse(n.data);
786
+ const c = V.safeParse(n.data);
775
787
  if (!c.success)
776
788
  return;
777
789
  l = c.data;
778
- const h = this._onHandlers.get(l.name), u = this._onceHandlers.get(l.name);
779
- if (h)
780
- for (const p of h)
790
+ const d = this._onHandlers.get(l.name), u = this._onceHandlers.get(l.name);
791
+ if (d)
792
+ for (const p of d)
781
793
  p(l.data);
782
794
  if (u) {
783
795
  for (const p of u)
@@ -785,9 +797,10 @@ class j {
785
797
  this._onceHandlers.delete(l.name);
786
798
  }
787
799
  }
788
- for (let c = 0; c < window.frames.length; c += 1)
789
- window.frames[c].postMessage(l, "*");
790
- }, 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);
791
804
  }
792
805
  /**
793
806
  * Removes the message event listener and cleans up resources.
@@ -803,7 +816,7 @@ class j {
803
816
  * of managing their own Client instances.
804
817
  */
805
818
  unbind() {
806
- this._windowMessageHandler && window.removeEventListener("message", this._windowMessageHandler);
819
+ this._windowMessageHandler && y.removeEventListener("message", this._windowMessageHandler);
807
820
  }
808
821
  /**
809
822
  * Sends a one-way message to the TelemetryOS platform.
@@ -820,14 +833,14 @@ class j {
820
833
  */
821
834
  send(e, t) {
822
835
  const s = S({
823
- telemetrySdkVersion: N,
836
+ telemetrySdkVersion: I,
824
837
  applicationName: this._applicationName,
825
838
  applicationSpecifier: this._applicationSpecifier,
826
839
  applicationInstance: this._applicationInstance,
827
840
  name: e,
828
841
  data: t
829
842
  });
830
- window.parent.postMessage(s, "*");
843
+ w(s);
831
844
  }
832
845
  /**
833
846
  * Sends a message to the TelemetryOS platform and waits for a response.
@@ -847,8 +860,8 @@ class j {
847
860
  * @throws {Error} If the request times out
848
861
  */
849
862
  request(e, t) {
850
- const s = v(), o = S({
851
- telemetrySdkVersion: N,
863
+ const s = N(), o = S({
864
+ telemetrySdkVersion: I,
852
865
  applicationName: this._applicationName,
853
866
  applicationSpecifier: this._applicationSpecifier,
854
867
  applicationInstance: this._applicationInstance,
@@ -856,28 +869,28 @@ class j {
856
869
  data: t,
857
870
  responseName: s
858
871
  });
859
- window.parent.postMessage(o, "*");
872
+ w(o);
860
873
  let r = !1, n;
861
- const l = new Promise((h, u) => {
874
+ const l = new Promise((d, u) => {
862
875
  const p = new Error(`${e} message request with response name of ${s} timed out after ${_}`);
863
876
  setTimeout(() => {
864
877
  r = !0, this.off(s, n), u(p);
865
878
  }, _);
866
- }), c = new Promise((h) => {
879
+ }), c = new Promise((d) => {
867
880
  n = (u) => {
868
- r || h(u);
869
- }, this.once(s, h);
881
+ r || d(u);
882
+ }, this.once(s, d);
870
883
  });
871
884
  return Promise.race([l, c]);
872
885
  }
873
886
  async subscribe(e, t, s) {
874
887
  let o, r;
875
888
  typeof t == "function" ? r = t : (o = t, r = s);
876
- const n = v(), l = v();
889
+ const n = N(), l = N();
877
890
  let c = this._subscriptionNamesBySubjectName.get(e);
878
891
  c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(n), this._subscriptionNamesByHandler.set(r, n), this.on(n, r);
879
- const h = S({
880
- telemetrySdkVersion: N,
892
+ const d = S({
893
+ telemetrySdkVersion: I,
881
894
  applicationName: this._applicationName,
882
895
  applicationSpecifier: this._applicationSpecifier,
883
896
  applicationInstance: this._applicationInstance,
@@ -886,24 +899,24 @@ class j {
886
899
  responseName: l,
887
900
  subscriptionName: n
888
901
  });
889
- window.parent.postMessage(h, "*");
902
+ w(d);
890
903
  let u = !1, p;
891
- const f = new Promise((w, g) => {
904
+ const f = new Promise((b, g) => {
892
905
  const m = new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${_}`);
893
906
  setTimeout(() => {
894
907
  u = !0, this.off(l, p), g(m);
895
908
  }, _);
896
- }), I = new Promise((w) => {
909
+ }), H = new Promise((b) => {
897
910
  p = (g) => {
898
- u || w(g);
899
- }, this.on(l, w);
911
+ u || b(g);
912
+ }, this.on(l, b);
900
913
  });
901
- return Promise.race([f, I]);
914
+ return Promise.race([f, H]);
902
915
  }
903
916
  async unsubscribe(e, t, s) {
904
917
  let o, r;
905
918
  typeof t == "function" ? r = t : (o = t, r = s);
906
- const n = v();
919
+ const n = N();
907
920
  let l = [];
908
921
  if (r) {
909
922
  const c = this._subscriptionNamesByHandler.get(r);
@@ -914,8 +927,8 @@ class j {
914
927
  return { success: !1 };
915
928
  for await (const c of l) {
916
929
  this.off(c, r);
917
- const h = S({
918
- telemetrySdkVersion: N,
930
+ const d = S({
931
+ telemetrySdkVersion: I,
919
932
  applicationInstance: this._applicationInstance,
920
933
  applicationName: this._applicationName,
921
934
  applicationSpecifier: this._applicationSpecifier,
@@ -924,19 +937,19 @@ class j {
924
937
  responseName: n,
925
938
  unsubscribeName: c
926
939
  });
927
- window.parent.postMessage(h, "*");
940
+ w(d);
928
941
  let u = !1, p;
929
942
  const f = new Promise((g, m) => {
930
- const H = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${_}`);
943
+ const E = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${_}`);
931
944
  setTimeout(() => {
932
- u = !0, this.off(n, p), m(H);
945
+ u = !0, this.off(n, p), m(E);
933
946
  }, _);
934
- }), I = new Promise((g) => {
947
+ }), H = new Promise((g) => {
935
948
  p = (m) => {
936
949
  u || g(m);
937
950
  }, this.once(n, g);
938
951
  });
939
- if (!(await Promise.race([f, I])).success)
952
+ if (!(await Promise.race([f, H])).success)
940
953
  return { success: !1 };
941
954
  }
942
955
  return { success: !0 };
@@ -1013,101 +1026,106 @@ class j {
1013
1026
  }
1014
1027
  }
1015
1028
  }
1016
- function v() {
1029
+ function N() {
1017
1030
  return Math.random().toString(36).slice(2, 9);
1018
1031
  }
1019
- const N = E.version;
1032
+ const I = A.version;
1020
1033
  let i = null;
1021
- function U() {
1034
+ function K() {
1022
1035
  return i;
1023
1036
  }
1024
- function V(a) {
1025
- i = new j(a), i.bind();
1037
+ function O(a) {
1038
+ i = new G(a), i.bind();
1026
1039
  }
1027
1040
  function z() {
1028
1041
  i == null || i.unbind(), i = null;
1029
1042
  }
1030
- function G(...a) {
1031
- return d(i), i.on(...a);
1032
- }
1033
- function J(...a) {
1034
- return d(i), i.once(...a);
1035
- }
1036
- function K(...a) {
1037
- return d(i), i.off(...a);
1038
- }
1039
- function O(...a) {
1040
- return d(i), i.send(...a);
1041
- }
1042
- function W(...a) {
1043
- return d(i), i.request(...a);
1044
- }
1045
1043
  function Q(...a) {
1046
- return d(i), i.subscribe(...a);
1044
+ return h(i), i.on(...a);
1047
1045
  }
1048
1046
  function X(...a) {
1049
- return d(i), i.unsubscribe(...a);
1047
+ return h(i), i.once(...a);
1050
1048
  }
1051
- function Y() {
1052
- return d(i), i.store;
1049
+ function Y(...a) {
1050
+ return h(i), i.off(...a);
1053
1051
  }
1054
- function Z() {
1055
- return d(i), i.applications;
1052
+ function Z(...a) {
1053
+ return h(i), i.send(...a);
1056
1054
  }
1057
- function ee() {
1058
- return d(i), i.media;
1055
+ function ee(...a) {
1056
+ return h(i), i.request(...a);
1059
1057
  }
1060
- function te() {
1061
- return d(i), i.accounts;
1058
+ function te(...a) {
1059
+ return h(i), i.subscribe(...a);
1062
1060
  }
1063
- function se() {
1064
- return d(i), i.users;
1061
+ function se(...a) {
1062
+ return h(i), i.unsubscribe(...a);
1065
1063
  }
1066
1064
  function ne() {
1067
- return d(i), i.devices;
1065
+ return h(i), i.store;
1068
1066
  }
1069
1067
  function ie() {
1070
- return d(i), i.proxy;
1068
+ return h(i), i.applications;
1071
1069
  }
1072
1070
  function re() {
1073
- return d(i), i.rootSettingsNavigation;
1071
+ return h(i), i.media;
1074
1072
  }
1075
1073
  function oe() {
1076
- return d(i), i.weather;
1074
+ return h(i), i.accounts;
1075
+ }
1076
+ function ae() {
1077
+ return h(i), i.users;
1078
+ }
1079
+ function ce() {
1080
+ return h(i), i.devices;
1081
+ }
1082
+ function le() {
1083
+ return h(i), i.proxy;
1084
+ }
1085
+ function ue() {
1086
+ return h(i), i.rootSettingsNavigation;
1087
+ }
1088
+ function pe() {
1089
+ return h(i), i.weather;
1090
+ }
1091
+ function he() {
1092
+ return h(i), i.environment;
1077
1093
  }
1078
- function d(a) {
1094
+ function h(a) {
1079
1095
  if (!a)
1080
1096
  throw new Error("SDK is not configured");
1081
1097
  }
1082
1098
  export {
1083
- M as Accounts,
1084
- P as Applications,
1085
- j as Client,
1086
- C as Devices,
1087
- L as Environment,
1088
- B as Media,
1089
- T as Proxy,
1090
- F as Store,
1091
- k as Users,
1092
- $ as Weather,
1093
- te as accounts,
1094
- Z as applications,
1095
- 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,
1096
1113
  z as destroy,
1097
- ne as devices,
1098
- U as globalClient,
1099
- ee as media,
1100
- K as off,
1101
- G as on,
1102
- J as once,
1103
- ie as proxy,
1104
- W as request,
1105
- re as rootSettingsNavigation,
1106
- O as send,
1107
- Y as store,
1108
- Q as subscribe,
1109
- N as telemetrySdkVersion,
1110
- X as unsubscribe,
1111
- se as users,
1112
- 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
1113
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 {};