@telemetryos/root-sdk 1.0.0 → 1.1.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/bridge.cjs +1 -1
- package/dist/bridge.js +2 -0
- package/dist/client-message-formatter.d.ts +2 -0
- package/dist/client-message-validator.d.ts +6 -0
- package/dist/client.d.ts +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +115 -86
- package/package.json +1 -1
package/dist/bridge.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");const a=e.z.object({telemetrySdkVersion:e.z.string(),applicationName: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 r{bind(){this._windowMessageHandler=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-JDXm3DEz.cjs");const a=e.z.object({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 r{bind(){this._windowMessageHandler=i=>{var s;if(i.source===window)return;const n=a.safeParse(i.data);if(!n.success)return;const t=n.data;(s=this.onMessage)===null||s===void 0||s.call(this,t)},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(i,"*")}}exports.Bridge=r;
|
package/dist/bridge.js
CHANGED
|
@@ -2,6 +2,8 @@ import { z as e } from "./index-B98VDFRY.js";
|
|
|
2
2
|
const t = e.object({
|
|
3
3
|
telemetrySdkVersion: e.string(),
|
|
4
4
|
applicationName: e.string(),
|
|
5
|
+
applicationSpecifier: e.string(),
|
|
6
|
+
applicationInstance: e.string(),
|
|
5
7
|
name: e.string(),
|
|
6
8
|
data: e.any(),
|
|
7
9
|
responseName: e.string().optional(),
|
|
@@ -4,6 +4,8 @@ export type Message = z.infer<typeof clientMessageValidator>;
|
|
|
4
4
|
export declare function formatClientMessage(data: Message): {
|
|
5
5
|
telemetrySdkVersion: string;
|
|
6
6
|
applicationName: string;
|
|
7
|
+
applicationSpecifier: string;
|
|
8
|
+
applicationInstance: string;
|
|
7
9
|
name: string;
|
|
8
10
|
data?: any;
|
|
9
11
|
responseName?: string | undefined;
|
|
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const clientMessageValidator: z.ZodObject<{
|
|
3
3
|
telemetrySdkVersion: z.ZodString;
|
|
4
4
|
applicationName: z.ZodString;
|
|
5
|
+
applicationSpecifier: z.ZodString;
|
|
6
|
+
applicationInstance: z.ZodString;
|
|
5
7
|
name: z.ZodString;
|
|
6
8
|
data: z.ZodAny;
|
|
7
9
|
responseName: z.ZodOptional<z.ZodString>;
|
|
@@ -10,6 +12,8 @@ export declare const clientMessageValidator: z.ZodObject<{
|
|
|
10
12
|
}, "strip", z.ZodTypeAny, {
|
|
11
13
|
telemetrySdkVersion: string;
|
|
12
14
|
applicationName: string;
|
|
15
|
+
applicationSpecifier: string;
|
|
16
|
+
applicationInstance: string;
|
|
13
17
|
name: string;
|
|
14
18
|
data?: any;
|
|
15
19
|
responseName?: string | undefined;
|
|
@@ -18,6 +22,8 @@ export declare const clientMessageValidator: z.ZodObject<{
|
|
|
18
22
|
}, {
|
|
19
23
|
telemetrySdkVersion: string;
|
|
20
24
|
applicationName: string;
|
|
25
|
+
applicationSpecifier: string;
|
|
26
|
+
applicationInstance: string;
|
|
21
27
|
name: string;
|
|
22
28
|
data?: any;
|
|
23
29
|
responseName?: string | undefined;
|
package/dist/client.d.ts
CHANGED
|
@@ -45,7 +45,8 @@ export type SubscriptionResult<D = void> = {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare class Client {
|
|
47
47
|
_applicationName: string;
|
|
48
|
-
|
|
48
|
+
_applicationInstance: string;
|
|
49
|
+
_applicationSpecifier: string;
|
|
49
50
|
_onHandlers: Map<string, MessageHandler<any>[]>;
|
|
50
51
|
_onceHandlers: Map<string, MessageHandler<any>[]>;
|
|
51
52
|
_subscriptionNamesByHandler: Map<MessageHandler<any>, string>;
|
|
@@ -139,6 +140,9 @@ export declare class Client {
|
|
|
139
140
|
* @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
|
|
140
141
|
*/
|
|
141
142
|
get rootSettingsNavigation(): RootSettingsNavigation;
|
|
143
|
+
get applicationName(): string;
|
|
144
|
+
get applicationSpecifier(): string;
|
|
145
|
+
get applicationInstance(): string;
|
|
142
146
|
/**
|
|
143
147
|
* Initializes the client by setting up message listeners and extracting the application ID.
|
|
144
148
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./index-JDXm3DEz.cjs"),k="1.1.0",E={version:k};class I{constructor(e){this._client=e}async getCurrent(){return(await this._client.request("user.getCurrentAccount",{})).account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async getUrl(e,t){return(await this._client.request("applications.getUrl",{name:e,mountPoint:t})).url}}function A(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){A(async()=>{this._client.on("environment.colorSchemeChanged",e),e(await this.getColorScheme())})}unsubscribeColorScheme(e){this._client.off("environment.colorSchemeChanged",e)}}class q{constructor(e){this._client=e}async queryFolders(e){return(await this._client.request("media.queryMediaFolders",{query:e})).folders}async getFoldersByTag(e){return(await this._client.request("media.getMediaFoldersByTag",{tagName:e})).folders}async getFolderById(e){return(await this._client.request("media.getMediaFolderById",{id:e})).folder}async getMediaContentByFolderId(e){return(await this._client.request("media.getMediaContentByFolderId",{folderId:e})).folders}async getMediaContentById(e){return(await this._client.request("media.getMediaContentById",{id:e})).content}}class H{constructor(e){this._client=e}get application(){return new b("application","",this._client)}get instance(){return new b("instance",this._client._applicationId,this._client)}get device(){return new b("device",this._client._applicationId,this._client)}shared(e){return new b("shared",e,this._client)}}class b{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class P{constructor(e){this._client=e}async getCurrent(){return await this._client.request("user.getCurrentUser",{})}}const T=v.z.object({name:v.z.string(),data:v.z.any()});class F{constructor(e){if(e._client._applicationId!=="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"),s=await t.get("navigation"),r=this._store._client._applicationId;s[r]={applicationId:r,entries:e.entries},t.set("navigation",s)}async getRootSettingsNavigation(){const t=await this._store.shared("root-settings-navigation").get("navigation"),s=this._store._client._applicationId;return t[s]}async getAllRootSettingsNavigation(){return this._store.shared("root-settings-navigation").get("navigation")}}const f=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 I(this)}get users(){return new P(this)}get store(){return new H(this)}get applications(){return new M(this)}get media(){return new q(this)}get rootSettingsNavigation(){return new F(this.store)}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),s=t.searchParams;this._applicationInstance=(e=s.get("telemetryApplicationId"))!==null&&e!==void 0?e:"";const r=s.get("applicationSpecifier");if(r)this._applicationSpecifier=r;else{const i=t.hostname.split(".");this._applicationSpecifier=i[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=i=>{if(i.source===window)return;for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(i.data,"*");const l=T.safeParse(i.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 s={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t};window.parent.postMessage(s,"*")}request(e,t){const s=y(),r={telemetrySdkVersion:_,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s};window.parent.postMessage(r,"*");let i=!1,l;const u=new Promise((h,c)=>{const d=new Error(`${e} message request with response name of ${s} timed out after ${f}`);setTimeout(()=>{i=!0,this.off(s,l),c(d)},f)}),a=new Promise(h=>{l=c=>{i||h(c)},this.once(s,h)});return Promise.race([u,a])}async subscribe(e,t,s){let r,i;typeof t=="function"?i=t:(r=t,i=s);const l=y(),u=y();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(l),this._subscriptionNamesByHandler.set(i,l),this.on(l,i);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,g)=>{const m=new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${f}`);setTimeout(()=>{c=!0,this.off(u,d),g(m)},f)}),N=new Promise(w=>{d=g=>{c||w(g)},this.on(u,w)});return Promise.race([S,N])}async unsubscribe(e,t,s){let r,i;typeof t=="function"?i=t:(r=t,i=s);const l=y();let u=[];if(i){const a=this._subscriptionNamesByHandler.get(i);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(i)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,i);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((g,m)=>{const B=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${f}`);setTimeout(()=>{c=!0,this.off(l,d),m(B)},f)}),N=new Promise(g=>{d=m=>{c||g(m)},this.once(l,g)});if(!(await Promise.race([S,N])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const r=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onHandlers.set(e,r),r.push(t)}once(e,t){var s;const r=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];r.length===0&&this._onceHandlers.set(e,r),r.push(t)}off(e,t){const s=this._onHandlers.get(e),r=this._onceHandlers.get(e);if(!(!s&&!r)){if(s){for(let i=0;i<s.length;i+=1)t&&s[i]!==t||(s.splice(i,1),i-=1);s.length===0&&this._onHandlers.delete(e)}if(r){for(let i=0;i<r.length;i+=1)t&&r[i]!==t||(r.splice(i,1),i-=1);r.length===0&&this._onceHandlers.delete(e)}}}}function y(){return Math.random().toString(36).slice(2,9)}const _=E.version;let n=null;function R(){return n}function j(o){n=new C(o),n.bind()}function U(){n==null||n.unbind(),n=null}function z(...o){return p(n),n.on(...o)}function L(...o){return p(n),n.once(...o)}function V(...o){return p(n),n.off(...o)}function x(...o){return p(n),n.send(...o)}function D(...o){return p(n),n.request(...o)}function K(...o){return p(n),n.subscribe(...o)}function G(...o){return p(n),n.unsubscribe(...o)}function J(){return p(n),n.store}function O(){return p(n),n.applications}function Q(){return p(n),n.media}function W(){return p(n),n.accounts}function X(){return p(n),n.users}function Y(){return p(n),n.rootSettingsNavigation}function p(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=I;exports.Applications=M;exports.Client=C;exports.Environment=$;exports.Media=q;exports.Store=H;exports.Users=P;exports.accounts=W;exports.applications=O;exports.configure=j;exports.destroy=U;exports.globalClient=R;exports.media=Q;exports.off=V;exports.on=z;exports.once=L;exports.request=D;exports.rootSettingsNavigation=Y;exports.send=x;exports.store=J;exports.subscribe=K;exports.telemetrySdkVersion=_;exports.unsubscribe=G;exports.users=X;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { z as
|
|
2
|
-
const M = "1.
|
|
1
|
+
import { z as v } from "./index-B98VDFRY.js";
|
|
2
|
+
const M = "1.1.0", H = {
|
|
3
3
|
version: M
|
|
4
4
|
};
|
|
5
|
-
class
|
|
5
|
+
class q {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this._client = e;
|
|
8
8
|
}
|
|
@@ -75,7 +75,7 @@ class P {
|
|
|
75
75
|
})).url;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function B(r, e = console.error) {
|
|
79
79
|
r().catch(e);
|
|
80
80
|
}
|
|
81
81
|
class R {
|
|
@@ -86,7 +86,7 @@ class R {
|
|
|
86
86
|
return (await this._client.request("environment.getColorScheme", {})).colorScheme;
|
|
87
87
|
}
|
|
88
88
|
subscribeColorScheme(e) {
|
|
89
|
-
|
|
89
|
+
B(async () => {
|
|
90
90
|
this._client.on("environment.colorSchemeChanged", e), e(await this.getColorScheme());
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -94,7 +94,7 @@ class R {
|
|
|
94
94
|
this._client.off("environment.colorSchemeChanged", e);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
class
|
|
97
|
+
class C {
|
|
98
98
|
constructor(e) {
|
|
99
99
|
this._client = e;
|
|
100
100
|
}
|
|
@@ -333,9 +333,9 @@ class E {
|
|
|
333
333
|
return await this._client.request("user.getCurrentUser", {});
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
const $ =
|
|
337
|
-
name:
|
|
338
|
-
data:
|
|
336
|
+
const $ = v.object({
|
|
337
|
+
name: v.string(),
|
|
338
|
+
data: v.any()
|
|
339
339
|
});
|
|
340
340
|
class A {
|
|
341
341
|
/**
|
|
@@ -391,7 +391,7 @@ class A {
|
|
|
391
391
|
return this._store.shared("root-settings-navigation").get("navigation");
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
const
|
|
394
|
+
const f = 1e3 * 30;
|
|
395
395
|
class T {
|
|
396
396
|
/**
|
|
397
397
|
* Creates a new Client instance for communicating with the TelemetryOS platform.
|
|
@@ -404,7 +404,7 @@ class T {
|
|
|
404
404
|
* in your application's telemetry.config.json file
|
|
405
405
|
*/
|
|
406
406
|
constructor(e) {
|
|
407
|
-
this._applicationName = e, this.
|
|
407
|
+
this._applicationName = e, this._applicationInstance = "", this._applicationSpecifier = "", this._onHandlers = /* @__PURE__ */ new Map(), this._onceHandlers = /* @__PURE__ */ new Map(), this._subscriptionNamesByHandler = /* @__PURE__ */ new Map(), this._subscriptionNamesBySubjectName = /* @__PURE__ */ new Map();
|
|
408
408
|
}
|
|
409
409
|
/**
|
|
410
410
|
* Provides access to the accounts API for retrieving TelemetryOS account information.
|
|
@@ -418,7 +418,7 @@ class T {
|
|
|
418
418
|
* @returns An Accounts instance bound to this client
|
|
419
419
|
*/
|
|
420
420
|
get accounts() {
|
|
421
|
-
return new
|
|
421
|
+
return new q(this);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* Provides access to the users API for retrieving TelemetryOS user information.
|
|
@@ -475,7 +475,7 @@ class T {
|
|
|
475
475
|
* @returns A Media instance bound to this client
|
|
476
476
|
*/
|
|
477
477
|
get media() {
|
|
478
|
-
return new
|
|
478
|
+
return new C(this);
|
|
479
479
|
}
|
|
480
480
|
/**
|
|
481
481
|
* Provides access to the root settings navigation API for TelemetryOS administration UI integration.
|
|
@@ -495,6 +495,15 @@ class T {
|
|
|
495
495
|
get rootSettingsNavigation() {
|
|
496
496
|
return new A(this.store);
|
|
497
497
|
}
|
|
498
|
+
get applicationName() {
|
|
499
|
+
return this._applicationName;
|
|
500
|
+
}
|
|
501
|
+
get applicationSpecifier() {
|
|
502
|
+
return this._applicationSpecifier;
|
|
503
|
+
}
|
|
504
|
+
get applicationInstance() {
|
|
505
|
+
return this._applicationInstance;
|
|
506
|
+
}
|
|
498
507
|
/**
|
|
499
508
|
* Initializes the client by setting up message listeners and extracting the application ID.
|
|
500
509
|
*
|
|
@@ -512,23 +521,35 @@ class T {
|
|
|
512
521
|
*/
|
|
513
522
|
bind() {
|
|
514
523
|
var e;
|
|
515
|
-
const t = new URL(window.location.href).searchParams;
|
|
516
|
-
this.
|
|
517
|
-
|
|
524
|
+
const t = new URL(window.location.href), s = t.searchParams;
|
|
525
|
+
this._applicationInstance = (e = s.get("telemetryApplicationId")) !== null && e !== void 0 ? e : "";
|
|
526
|
+
const o = s.get("applicationSpecifier");
|
|
527
|
+
if (o)
|
|
528
|
+
this._applicationSpecifier = o;
|
|
529
|
+
else {
|
|
530
|
+
const i = t.hostname.split(".");
|
|
531
|
+
this._applicationSpecifier = i[0] || "";
|
|
532
|
+
}
|
|
533
|
+
if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
|
|
534
|
+
throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
535
|
+
if (!this._applicationInstance)
|
|
536
|
+
throw new Error("Missing telemetryApplicationId query parameter");
|
|
537
|
+
this._windowMessageHandler = (i) => {
|
|
538
|
+
if (i.source === window)
|
|
518
539
|
return;
|
|
519
|
-
for (let
|
|
520
|
-
window.frames[
|
|
521
|
-
const
|
|
522
|
-
if (!
|
|
540
|
+
for (let c = 0; c < window.frames.length; c += 1)
|
|
541
|
+
window.frames[c].postMessage(i.data, "*");
|
|
542
|
+
const l = $.safeParse(i.data);
|
|
543
|
+
if (!l.success)
|
|
523
544
|
return;
|
|
524
|
-
const
|
|
525
|
-
if (
|
|
526
|
-
for (const
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
for (const
|
|
530
|
-
|
|
531
|
-
this._onceHandlers.delete(
|
|
545
|
+
const u = l.data, a = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
|
|
546
|
+
if (a)
|
|
547
|
+
for (const c of a)
|
|
548
|
+
c(u.data);
|
|
549
|
+
if (h) {
|
|
550
|
+
for (const c of h)
|
|
551
|
+
c(u.data);
|
|
552
|
+
this._onceHandlers.delete(u.name);
|
|
532
553
|
}
|
|
533
554
|
}, window.addEventListener("message", this._windowMessageHandler);
|
|
534
555
|
}
|
|
@@ -565,6 +586,8 @@ class T {
|
|
|
565
586
|
const s = {
|
|
566
587
|
telemetrySdkVersion: y,
|
|
567
588
|
applicationName: this._applicationName,
|
|
589
|
+
applicationSpecifier: this._applicationSpecifier,
|
|
590
|
+
applicationInstance: this._applicationInstance,
|
|
568
591
|
name: e,
|
|
569
592
|
data: t
|
|
570
593
|
};
|
|
@@ -591,87 +614,93 @@ class T {
|
|
|
591
614
|
const s = b(), o = {
|
|
592
615
|
telemetrySdkVersion: y,
|
|
593
616
|
applicationName: this._applicationName,
|
|
617
|
+
applicationSpecifier: this._applicationSpecifier,
|
|
618
|
+
applicationInstance: this._applicationInstance,
|
|
594
619
|
name: e,
|
|
595
620
|
data: t,
|
|
596
621
|
responseName: s
|
|
597
622
|
};
|
|
598
623
|
window.parent.postMessage(o, "*");
|
|
599
|
-
let i = !1,
|
|
600
|
-
const
|
|
601
|
-
const
|
|
624
|
+
let i = !1, l;
|
|
625
|
+
const u = new Promise((h, c) => {
|
|
626
|
+
const d = new Error(`${e} message request with response name of ${s} timed out after ${f}`);
|
|
602
627
|
setTimeout(() => {
|
|
603
|
-
i = !0, this.off(s,
|
|
604
|
-
},
|
|
628
|
+
i = !0, this.off(s, l), c(d);
|
|
629
|
+
}, f);
|
|
605
630
|
}), a = new Promise((h) => {
|
|
606
|
-
|
|
607
|
-
i || h(
|
|
631
|
+
l = (c) => {
|
|
632
|
+
i || h(c);
|
|
608
633
|
}, this.once(s, h);
|
|
609
634
|
});
|
|
610
|
-
return Promise.race([
|
|
635
|
+
return Promise.race([u, a]);
|
|
611
636
|
}
|
|
612
637
|
async subscribe(e, t, s) {
|
|
613
638
|
let o, i;
|
|
614
639
|
typeof t == "function" ? i = t : (o = t, i = s);
|
|
615
|
-
const
|
|
640
|
+
const l = b(), u = b();
|
|
616
641
|
let a = this._subscriptionNamesBySubjectName.get(e);
|
|
617
|
-
a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(
|
|
642
|
+
a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(l), this._subscriptionNamesByHandler.set(i, l), this.on(l, i);
|
|
618
643
|
const h = {
|
|
619
644
|
telemetrySdkVersion: y,
|
|
620
645
|
applicationName: this._applicationName,
|
|
646
|
+
applicationSpecifier: this._applicationSpecifier,
|
|
647
|
+
applicationInstance: this._applicationInstance,
|
|
621
648
|
name: e,
|
|
622
649
|
data: o,
|
|
623
|
-
responseName:
|
|
624
|
-
subscriptionName:
|
|
650
|
+
responseName: u,
|
|
651
|
+
subscriptionName: l
|
|
625
652
|
};
|
|
626
653
|
window.parent.postMessage(h, "*");
|
|
627
|
-
let
|
|
628
|
-
const
|
|
629
|
-
const
|
|
654
|
+
let c = !1, d;
|
|
655
|
+
const S = new Promise((_, g) => {
|
|
656
|
+
const m = new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${f}`);
|
|
630
657
|
setTimeout(() => {
|
|
631
|
-
|
|
632
|
-
},
|
|
633
|
-
}),
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}, this.on(
|
|
658
|
+
c = !0, this.off(u, d), g(m);
|
|
659
|
+
}, f);
|
|
660
|
+
}), N = new Promise((_) => {
|
|
661
|
+
d = (g) => {
|
|
662
|
+
c || _(g);
|
|
663
|
+
}, this.on(u, _);
|
|
637
664
|
});
|
|
638
|
-
return Promise.race([
|
|
665
|
+
return Promise.race([S, N]);
|
|
639
666
|
}
|
|
640
667
|
async unsubscribe(e, t, s) {
|
|
641
668
|
let o, i;
|
|
642
669
|
typeof t == "function" ? i = t : (o = t, i = s);
|
|
643
|
-
const
|
|
644
|
-
let
|
|
670
|
+
const l = b();
|
|
671
|
+
let u = [];
|
|
645
672
|
if (i) {
|
|
646
673
|
const a = this._subscriptionNamesByHandler.get(i);
|
|
647
674
|
if (!a)
|
|
648
675
|
return { success: !1 };
|
|
649
|
-
|
|
676
|
+
u = [a], this._subscriptionNamesByHandler.delete(i);
|
|
650
677
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
651
678
|
return { success: !1 };
|
|
652
|
-
for await (const a of
|
|
679
|
+
for await (const a of u) {
|
|
653
680
|
this.off(a, i);
|
|
654
681
|
const h = {
|
|
655
682
|
telemetrySdkVersion: y,
|
|
683
|
+
applicationInstance: this._applicationInstance,
|
|
656
684
|
applicationName: this._applicationName,
|
|
685
|
+
applicationSpecifier: this._applicationSpecifier,
|
|
657
686
|
name: e,
|
|
658
687
|
data: o,
|
|
659
|
-
responseName:
|
|
688
|
+
responseName: l,
|
|
660
689
|
unsubscribeName: a
|
|
661
690
|
};
|
|
662
691
|
window.parent.postMessage(h, "*");
|
|
663
|
-
let
|
|
664
|
-
const
|
|
665
|
-
const
|
|
692
|
+
let c = !1, d;
|
|
693
|
+
const S = new Promise((g, m) => {
|
|
694
|
+
const I = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${f}`);
|
|
666
695
|
setTimeout(() => {
|
|
667
|
-
|
|
668
|
-
},
|
|
669
|
-
}),
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}, this.once(
|
|
696
|
+
c = !0, this.off(l, d), m(I);
|
|
697
|
+
}, f);
|
|
698
|
+
}), N = new Promise((g) => {
|
|
699
|
+
d = (m) => {
|
|
700
|
+
c || g(m);
|
|
701
|
+
}, this.once(l, g);
|
|
673
702
|
});
|
|
674
|
-
if (!(await Promise.race([
|
|
703
|
+
if (!(await Promise.race([S, N])).success)
|
|
675
704
|
return { success: !1 };
|
|
676
705
|
}
|
|
677
706
|
return { success: !0 };
|
|
@@ -751,7 +780,7 @@ class T {
|
|
|
751
780
|
function b() {
|
|
752
781
|
return Math.random().toString(36).slice(2, 9);
|
|
753
782
|
}
|
|
754
|
-
const y =
|
|
783
|
+
const y = H.version;
|
|
755
784
|
let n = null;
|
|
756
785
|
function j() {
|
|
757
786
|
return n;
|
|
@@ -762,55 +791,55 @@ function U(r) {
|
|
|
762
791
|
function L() {
|
|
763
792
|
n == null || n.unbind(), n = null;
|
|
764
793
|
}
|
|
765
|
-
function V(...r) {
|
|
766
|
-
return u(n), n.on(...r);
|
|
767
|
-
}
|
|
768
794
|
function x(...r) {
|
|
769
|
-
return
|
|
795
|
+
return p(n), n.on(...r);
|
|
796
|
+
}
|
|
797
|
+
function V(...r) {
|
|
798
|
+
return p(n), n.once(...r);
|
|
770
799
|
}
|
|
771
800
|
function z(...r) {
|
|
772
|
-
return
|
|
801
|
+
return p(n), n.off(...r);
|
|
773
802
|
}
|
|
774
803
|
function D(...r) {
|
|
775
|
-
return
|
|
804
|
+
return p(n), n.send(...r);
|
|
776
805
|
}
|
|
777
806
|
function K(...r) {
|
|
778
|
-
return
|
|
807
|
+
return p(n), n.request(...r);
|
|
779
808
|
}
|
|
780
809
|
function G(...r) {
|
|
781
|
-
return
|
|
810
|
+
return p(n), n.subscribe(...r);
|
|
782
811
|
}
|
|
783
812
|
function J(...r) {
|
|
784
|
-
return
|
|
813
|
+
return p(n), n.unsubscribe(...r);
|
|
785
814
|
}
|
|
786
815
|
function Q() {
|
|
787
|
-
return
|
|
816
|
+
return p(n), n.store;
|
|
788
817
|
}
|
|
789
818
|
function W() {
|
|
790
|
-
return
|
|
819
|
+
return p(n), n.applications;
|
|
791
820
|
}
|
|
792
821
|
function X() {
|
|
793
|
-
return
|
|
822
|
+
return p(n), n.media;
|
|
794
823
|
}
|
|
795
824
|
function Y() {
|
|
796
|
-
return
|
|
825
|
+
return p(n), n.accounts;
|
|
797
826
|
}
|
|
798
827
|
function Z() {
|
|
799
|
-
return
|
|
828
|
+
return p(n), n.users;
|
|
800
829
|
}
|
|
801
830
|
function O() {
|
|
802
|
-
return
|
|
831
|
+
return p(n), n.rootSettingsNavigation;
|
|
803
832
|
}
|
|
804
|
-
function
|
|
833
|
+
function p(r) {
|
|
805
834
|
if (!r)
|
|
806
835
|
throw new Error("SDK is not configured");
|
|
807
836
|
}
|
|
808
837
|
export {
|
|
809
|
-
|
|
838
|
+
q as Accounts,
|
|
810
839
|
P as Applications,
|
|
811
840
|
T as Client,
|
|
812
841
|
R as Environment,
|
|
813
|
-
|
|
842
|
+
C as Media,
|
|
814
843
|
k as Store,
|
|
815
844
|
E as Users,
|
|
816
845
|
Y as accounts,
|
|
@@ -820,8 +849,8 @@ export {
|
|
|
820
849
|
j as globalClient,
|
|
821
850
|
X as media,
|
|
822
851
|
z as off,
|
|
823
|
-
|
|
824
|
-
|
|
852
|
+
x as on,
|
|
853
|
+
V as once,
|
|
825
854
|
K as request,
|
|
826
855
|
O as rootSettingsNavigation,
|
|
827
856
|
D as send,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|