@telemetryos/root-sdk 1.0.1 → 1.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @telemetryos/root-sdk
2
+
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added setDependencies to applications api
@@ -10,6 +10,10 @@ export type Application = {
10
10
  export type GetUrlResult = {
11
11
  url: string;
12
12
  };
13
+ export type SetDependenciesResult = {
14
+ ready: string[];
15
+ unavailable: string[];
16
+ };
13
17
  export declare class Applications {
14
18
  _client: Client;
15
19
  constructor(client: Client);
@@ -39,17 +43,23 @@ export declare class Applications {
39
43
  */
40
44
  getByName(name: string): Promise<Application | null>;
41
45
  /**
42
- * Generates a URL for embedding an application with the specified name and mount point.
46
+ * Sets the dependencies for the current application.
47
+ *
48
+ * This method allows an application to declare which other applications it depends on.
49
+ * The player will download and prepare these dependencies before they can be loaded.
43
50
  *
44
- * This method returns a URL that can be used in an iframe src attribute to embed
45
- * the application. The URL includes necessary parameters for the application to
46
- * understand its context and communicate with the platform.
51
+ * IMPORTANT: This method must be called and awaited before loading any sub-applications
52
+ * in iframes. Only applications that return as 'ready' should be loaded.
47
53
  *
48
- * Only applications that are associated with the current account can be retrieved.
54
+ * @param applicationSpecifiers An array of application specifiers that this application depends on
55
+ * @returns A promise that resolves with arrays of ready and unavailable application specifiers
49
56
  *
50
- * @param name The name of the application to get the URL for
51
- * @param mountPoint The mount point to use when embedding the application
52
- * @returns A promise that resolves to the URL string for embedding the application
57
+ * @example
58
+ * ```typescript
59
+ * const result = await client.applications.setDependencies(['app1-hash', 'app2-hash'])
60
+ * // result.ready: ['app1-hash'] - these can be loaded in iframes
61
+ * // result.unavailable: ['app2-hash'] - these failed to load
62
+ * ```
53
63
  */
54
- getUrl(name: string, mountPoint: string): Promise<string>;
64
+ setDependencies(applicationSpecifiers: string[]): Promise<SetDependenciesResult>;
55
65
  }
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=n=>{var s;if(n.source===window)return;const i=a.safeParse(n.data);if(!i.success)return;const t=i.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(n){for(let s=0;s<window.frames.length;s+=1)window.frames[s].postMessage(n,"*")}}exports.Bridge=r;
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
- _applicationId: string;
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 S=require("./index-JDXm3DEz.cjs"),k="1.0.1",E={version:k};class M{constructor(e){this._client=e}async getCurrent(){return(await this._client.request("user.getCurrentAccount",{})).account}}class H{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 C{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=S.z.object({name:S.z.string(),data:S.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 m=1e3*30;class B{constructor(e){this._applicationName=e,this._applicationId="",this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new M(this)}get users(){return new P(this)}get store(){return new C(this)}get applications(){return new H(this)}get media(){return new q(this)}get rootSettingsNavigation(){return new F(this.store)}bind(){var e;const t=new URL(window.location.href).searchParams;this._applicationId=(e=t.get("telemetryApplicationId"))!==null&&e!==void 0?e:"",this._windowMessageHandler=s=>{if(s.source===window)return;for(let a=0;a<window.frames.length;a+=1)window.frames[a].postMessage(s.data,"*");const r=T.safeParse(s.data);if(!r.success)return;const i=r.data,c=this._onHandlers.get(i.name),l=this._onceHandlers.get(i.name);if(c)for(const a of c)a(i.data);if(l){for(const a of l)a(i.data);this._onceHandlers.delete(i.name)}},window.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&window.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s={telemetrySdkVersion:_,applicationName:this._applicationName,name:e,data:t};window.parent.postMessage(s,"*")}request(e,t){const s=y(),r={telemetrySdkVersion:_,applicationName:this._applicationName,name:e,data:t,responseName:s};window.parent.postMessage(r,"*");let i=!1,c;const l=new Promise((h,d)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{i=!0,this.off(s,c),d(p)},m)}),a=new Promise(h=>{c=d=>{i||h(d)},this.once(s,h)});return Promise.race([l,a])}async subscribe(e,t,s){let r,i;typeof t=="function"?i=t:(r=t,i=s);const c=y(),l=y();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(c),this._subscriptionNamesByHandler.set(i,c),this.on(c,i);const h={telemetrySdkVersion:_,applicationName:this._applicationName,name:e,data:r,responseName:l,subscriptionName:c};window.parent.postMessage(h,"*");let d=!1,p;const N=new Promise((w,g)=>{const f=new Error(`${e} subscribe request with subscription name of ${c} and response name of ${l} timed out after ${m}`);setTimeout(()=>{d=!0,this.off(l,p),g(f)},m)}),v=new Promise(w=>{p=g=>{d||w(g)},this.on(l,w)});return Promise.race([N,v])}async unsubscribe(e,t,s){let r,i;typeof t=="function"?i=t:(r=t,i=s);const c=y();let l=[];if(i){const a=this._subscriptionNamesByHandler.get(i);if(!a)return{success:!1};l=[a],this._subscriptionNamesByHandler.delete(i)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of l){this.off(a,i);const h={telemetrySdkVersion:_,applicationName:this._applicationName,name:e,data:r,responseName:c,unsubscribeName:a};window.parent.postMessage(h,"*");let d=!1,p;const N=new Promise((g,f)=>{const I=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${c} timed out after ${m}`);setTimeout(()=>{d=!0,this.off(c,p),f(I)},m)}),v=new Promise(g=>{p=f=>{d||g(f)},this.once(c,g)});if(!(await Promise.race([N,v])).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 B(o),n.bind()}function U(){n==null||n.unbind(),n=null}function z(...o){return u(n),n.on(...o)}function L(...o){return u(n),n.once(...o)}function V(...o){return u(n),n.off(...o)}function x(...o){return u(n),n.send(...o)}function D(...o){return u(n),n.request(...o)}function K(...o){return u(n),n.subscribe(...o)}function G(...o){return u(n),n.unsubscribe(...o)}function J(){return u(n),n.store}function O(){return u(n),n.applications}function Q(){return u(n),n.media}function W(){return u(n),n.accounts}function X(){return u(n),n.users}function Y(){return u(n),n.rootSettingsNavigation}function u(o){if(!o)throw new Error("SDK is not configured")}exports.Accounts=M;exports.Applications=H;exports.Client=B;exports.Environment=$;exports.Media=q;exports.Store=C;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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./index-JDXm3DEz.cjs"),k="1.2.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 setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e})}}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 D(...o){return p(n),n.once(...o)}function L(...o){return p(n),n.off(...o)}function V(...o){return p(n),n.send(...o)}function x(...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=L;exports.on=z;exports.once=D;exports.request=x;exports.rootSettingsNavigation=Y;exports.send=V;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 S } from "./index-B98VDFRY.js";
2
- const M = "1.0.1", q = {
1
+ import { z as v } from "./index-B98VDFRY.js";
2
+ const M = "1.2.0", H = {
3
3
  version: M
4
4
  };
5
- class B {
5
+ class q {
6
6
  constructor(e) {
7
7
  this._client = e;
8
8
  }
@@ -56,27 +56,32 @@ class P {
56
56
  })).application;
57
57
  }
58
58
  /**
59
- * Generates a URL for embedding an application with the specified name and mount point.
59
+ * Sets the dependencies for the current application.
60
60
  *
61
- * This method returns a URL that can be used in an iframe src attribute to embed
62
- * the application. The URL includes necessary parameters for the application to
63
- * understand its context and communicate with the platform.
61
+ * This method allows an application to declare which other applications it depends on.
62
+ * The player will download and prepare these dependencies before they can be loaded.
64
63
  *
65
- * Only applications that are associated with the current account can be retrieved.
64
+ * IMPORTANT: This method must be called and awaited before loading any sub-applications
65
+ * in iframes. Only applications that return as 'ready' should be loaded.
66
66
  *
67
- * @param name The name of the application to get the URL for
68
- * @param mountPoint The mount point to use when embedding the application
69
- * @returns A promise that resolves to the URL string for embedding the application
70
- */
71
- async getUrl(e, t) {
72
- return (await this._client.request("applications.getUrl", {
73
- name: e,
74
- mountPoint: t
75
- })).url;
67
+ * @param applicationSpecifiers An array of application specifiers that this application depends on
68
+ * @returns A promise that resolves with arrays of ready and unavailable application specifiers
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const result = await client.applications.setDependencies(['app1-hash', 'app2-hash'])
73
+ * // result.ready: ['app1-hash'] - these can be loaded in iframes
74
+ * // result.unavailable: ['app2-hash'] - these failed to load
75
+ * ```
76
+ */
77
+ async setDependencies(e) {
78
+ return await this._client.request("applications.setDependencies", {
79
+ applicationSpecifiers: e
80
+ });
76
81
  }
77
82
  }
78
- function C(r, e = console.error) {
79
- r().catch(e);
83
+ function B(o, e = console.error) {
84
+ o().catch(e);
80
85
  }
81
86
  class R {
82
87
  constructor(e) {
@@ -86,7 +91,7 @@ class R {
86
91
  return (await this._client.request("environment.getColorScheme", {})).colorScheme;
87
92
  }
88
93
  subscribeColorScheme(e) {
89
- C(async () => {
94
+ B(async () => {
90
95
  this._client.on("environment.colorSchemeChanged", e), e(await this.getColorScheme());
91
96
  });
92
97
  }
@@ -94,7 +99,7 @@ class R {
94
99
  this._client.off("environment.colorSchemeChanged", e);
95
100
  }
96
101
  }
97
- class I {
102
+ class C {
98
103
  constructor(e) {
99
104
  this._client = e;
100
105
  }
@@ -333,9 +338,9 @@ class E {
333
338
  return await this._client.request("user.getCurrentUser", {});
334
339
  }
335
340
  }
336
- const $ = S.object({
337
- name: S.string(),
338
- data: S.any()
341
+ const $ = v.object({
342
+ name: v.string(),
343
+ data: v.any()
339
344
  });
340
345
  class A {
341
346
  /**
@@ -360,9 +365,9 @@ class A {
360
365
  * @returns A promise that resolves when the navigation has been registered
361
366
  */
362
367
  async setRootSettingsNavigation(e) {
363
- const t = this._store.shared("root-settings-navigation"), s = await t.get("navigation"), o = this._store._client._applicationId;
364
- s[o] = {
365
- applicationId: o,
368
+ const t = this._store.shared("root-settings-navigation"), s = await t.get("navigation"), r = this._store._client._applicationId;
369
+ s[r] = {
370
+ applicationId: r,
366
371
  entries: e.entries
367
372
  }, t.set("navigation", s);
368
373
  }
@@ -391,7 +396,7 @@ class A {
391
396
  return this._store.shared("root-settings-navigation").get("navigation");
392
397
  }
393
398
  }
394
- const m = 1e3 * 30;
399
+ const g = 1e3 * 30;
395
400
  class T {
396
401
  /**
397
402
  * Creates a new Client instance for communicating with the TelemetryOS platform.
@@ -404,7 +409,7 @@ class T {
404
409
  * in your application's telemetry.config.json file
405
410
  */
406
411
  constructor(e) {
407
- this._applicationName = e, this._applicationId = "", this._onHandlers = /* @__PURE__ */ new Map(), this._onceHandlers = /* @__PURE__ */ new Map(), this._subscriptionNamesByHandler = /* @__PURE__ */ new Map(), this._subscriptionNamesBySubjectName = /* @__PURE__ */ new Map();
412
+ 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
413
  }
409
414
  /**
410
415
  * Provides access to the accounts API for retrieving TelemetryOS account information.
@@ -418,7 +423,7 @@ class T {
418
423
  * @returns An Accounts instance bound to this client
419
424
  */
420
425
  get accounts() {
421
- return new B(this);
426
+ return new q(this);
422
427
  }
423
428
  /**
424
429
  * Provides access to the users API for retrieving TelemetryOS user information.
@@ -475,7 +480,7 @@ class T {
475
480
  * @returns A Media instance bound to this client
476
481
  */
477
482
  get media() {
478
- return new I(this);
483
+ return new C(this);
479
484
  }
480
485
  /**
481
486
  * Provides access to the root settings navigation API for TelemetryOS administration UI integration.
@@ -495,6 +500,15 @@ class T {
495
500
  get rootSettingsNavigation() {
496
501
  return new A(this.store);
497
502
  }
503
+ get applicationName() {
504
+ return this._applicationName;
505
+ }
506
+ get applicationSpecifier() {
507
+ return this._applicationSpecifier;
508
+ }
509
+ get applicationInstance() {
510
+ return this._applicationInstance;
511
+ }
498
512
  /**
499
513
  * Initializes the client by setting up message listeners and extracting the application ID.
500
514
  *
@@ -512,23 +526,35 @@ class T {
512
526
  */
513
527
  bind() {
514
528
  var e;
515
- const t = new URL(window.location.href).searchParams;
516
- this._applicationId = (e = t.get("telemetryApplicationId")) !== null && e !== void 0 ? e : "", this._windowMessageHandler = (s) => {
517
- if (s.source === window)
529
+ const t = new URL(window.location.href), s = t.searchParams;
530
+ this._applicationInstance = (e = s.get("telemetryApplicationId")) !== null && e !== void 0 ? e : "";
531
+ const r = s.get("applicationSpecifier");
532
+ if (r)
533
+ this._applicationSpecifier = r;
534
+ else {
535
+ const i = t.hostname.split(".");
536
+ this._applicationSpecifier = i[0] || "";
537
+ }
538
+ if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
539
+ throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
540
+ if (!this._applicationInstance)
541
+ throw new Error("Missing telemetryApplicationId query parameter");
542
+ this._windowMessageHandler = (i) => {
543
+ if (i.source === window)
518
544
  return;
519
- for (let a = 0; a < window.frames.length; a += 1)
520
- window.frames[a].postMessage(s.data, "*");
521
- const o = $.safeParse(s.data);
522
- if (!o.success)
545
+ for (let c = 0; c < window.frames.length; c += 1)
546
+ window.frames[c].postMessage(i.data, "*");
547
+ const l = $.safeParse(i.data);
548
+ if (!l.success)
523
549
  return;
524
- const i = o.data, c = this._onHandlers.get(i.name), l = this._onceHandlers.get(i.name);
525
- if (c)
526
- for (const a of c)
527
- a(i.data);
528
- if (l) {
529
- for (const a of l)
530
- a(i.data);
531
- this._onceHandlers.delete(i.name);
550
+ const u = l.data, a = this._onHandlers.get(u.name), h = this._onceHandlers.get(u.name);
551
+ if (a)
552
+ for (const c of a)
553
+ c(u.data);
554
+ if (h) {
555
+ for (const c of h)
556
+ c(u.data);
557
+ this._onceHandlers.delete(u.name);
532
558
  }
533
559
  }, window.addEventListener("message", this._windowMessageHandler);
534
560
  }
@@ -565,6 +591,8 @@ class T {
565
591
  const s = {
566
592
  telemetrySdkVersion: y,
567
593
  applicationName: this._applicationName,
594
+ applicationSpecifier: this._applicationSpecifier,
595
+ applicationInstance: this._applicationInstance,
568
596
  name: e,
569
597
  data: t
570
598
  };
@@ -588,90 +616,96 @@ class T {
588
616
  * @throws {Error} If the request times out
589
617
  */
590
618
  request(e, t) {
591
- const s = b(), o = {
619
+ const s = b(), r = {
592
620
  telemetrySdkVersion: y,
593
621
  applicationName: this._applicationName,
622
+ applicationSpecifier: this._applicationSpecifier,
623
+ applicationInstance: this._applicationInstance,
594
624
  name: e,
595
625
  data: t,
596
626
  responseName: s
597
627
  };
598
- window.parent.postMessage(o, "*");
599
- let i = !1, c;
600
- const l = new Promise((h, d) => {
601
- const p = new Error(`${e} message request with response name of ${s} timed out after ${m}`);
628
+ window.parent.postMessage(r, "*");
629
+ let i = !1, l;
630
+ const u = new Promise((h, c) => {
631
+ const d = new Error(`${e} message request with response name of ${s} timed out after ${g}`);
602
632
  setTimeout(() => {
603
- i = !0, this.off(s, c), d(p);
604
- }, m);
633
+ i = !0, this.off(s, l), c(d);
634
+ }, g);
605
635
  }), a = new Promise((h) => {
606
- c = (d) => {
607
- i || h(d);
636
+ l = (c) => {
637
+ i || h(c);
608
638
  }, this.once(s, h);
609
639
  });
610
- return Promise.race([l, a]);
640
+ return Promise.race([u, a]);
611
641
  }
612
642
  async subscribe(e, t, s) {
613
- let o, i;
614
- typeof t == "function" ? i = t : (o = t, i = s);
615
- const c = b(), l = b();
643
+ let r, i;
644
+ typeof t == "function" ? i = t : (r = t, i = s);
645
+ const l = b(), u = b();
616
646
  let a = this._subscriptionNamesBySubjectName.get(e);
617
- a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(c), this._subscriptionNamesByHandler.set(i, c), this.on(c, i);
647
+ a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(l), this._subscriptionNamesByHandler.set(i, l), this.on(l, i);
618
648
  const h = {
619
649
  telemetrySdkVersion: y,
620
650
  applicationName: this._applicationName,
651
+ applicationSpecifier: this._applicationSpecifier,
652
+ applicationInstance: this._applicationInstance,
621
653
  name: e,
622
- data: o,
623
- responseName: l,
624
- subscriptionName: c
654
+ data: r,
655
+ responseName: u,
656
+ subscriptionName: l
625
657
  };
626
658
  window.parent.postMessage(h, "*");
627
- let d = !1, p;
628
- const N = new Promise((_, g) => {
629
- const f = new Error(`${e} subscribe request with subscription name of ${c} and response name of ${l} timed out after ${m}`);
659
+ let c = !1, d;
660
+ const S = new Promise((_, f) => {
661
+ const m = new Error(`${e} subscribe request with subscription name of ${l} and response name of ${u} timed out after ${g}`);
630
662
  setTimeout(() => {
631
- d = !0, this.off(l, p), g(f);
632
- }, m);
633
- }), v = new Promise((_) => {
634
- p = (g) => {
635
- d || _(g);
636
- }, this.on(l, _);
663
+ c = !0, this.off(u, d), f(m);
664
+ }, g);
665
+ }), N = new Promise((_) => {
666
+ d = (f) => {
667
+ c || _(f);
668
+ }, this.on(u, _);
637
669
  });
638
- return Promise.race([N, v]);
670
+ return Promise.race([S, N]);
639
671
  }
640
672
  async unsubscribe(e, t, s) {
641
- let o, i;
642
- typeof t == "function" ? i = t : (o = t, i = s);
643
- const c = b();
644
- let l = [];
673
+ let r, i;
674
+ typeof t == "function" ? i = t : (r = t, i = s);
675
+ const l = b();
676
+ let u = [];
645
677
  if (i) {
646
678
  const a = this._subscriptionNamesByHandler.get(i);
647
679
  if (!a)
648
680
  return { success: !1 };
649
- l = [a], this._subscriptionNamesByHandler.delete(i);
681
+ u = [a], this._subscriptionNamesByHandler.delete(i);
650
682
  } else if (!this._subscriptionNamesBySubjectName.get(e))
651
683
  return { success: !1 };
652
- for await (const a of l) {
684
+ for await (const a of u) {
653
685
  this.off(a, i);
654
686
  const h = {
655
687
  telemetrySdkVersion: y,
688
+ applicationInstance: this._applicationInstance,
656
689
  applicationName: this._applicationName,
690
+ applicationSpecifier: this._applicationSpecifier,
657
691
  name: e,
658
- data: o,
659
- responseName: c,
692
+ data: r,
693
+ responseName: l,
660
694
  unsubscribeName: a
661
695
  };
662
696
  window.parent.postMessage(h, "*");
663
- let d = !1, p;
664
- const N = new Promise((g, f) => {
665
- const H = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${c} timed out after ${m}`);
697
+ let c = !1, d;
698
+ const S = new Promise((f, m) => {
699
+ const I = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${l} timed out after ${g}`);
666
700
  setTimeout(() => {
667
- d = !0, this.off(c, p), f(H);
668
- }, m);
669
- }), v = new Promise((g) => {
670
- p = (f) => {
671
- d || g(f);
672
- }, this.once(c, g);
701
+ c = !0, this.off(l, d), m(I);
702
+ }, g);
703
+ }), N = new Promise((f) => {
704
+ d = (m) => {
705
+ c || f(m);
706
+ }, this.once(l, f);
673
707
  });
674
- if (!(await Promise.race([N, v])).success)
708
+ if (!(await Promise.race([S, N])).success)
675
709
  return { success: !1 };
676
710
  }
677
711
  return { success: !0 };
@@ -695,8 +729,8 @@ class T {
695
729
  */
696
730
  on(e, t) {
697
731
  var s;
698
- const o = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
699
- o.length === 0 && this._onHandlers.set(e, o), o.push(t);
732
+ const r = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
733
+ r.length === 0 && this._onHandlers.set(e, r), r.push(t);
700
734
  }
701
735
  /**
702
736
  * Registers a one-time handler for a specific message type.
@@ -714,8 +748,8 @@ class T {
714
748
  */
715
749
  once(e, t) {
716
750
  var s;
717
- const o = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
718
- o.length === 0 && this._onceHandlers.set(e, o), o.push(t);
751
+ const r = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
752
+ r.length === 0 && this._onceHandlers.set(e, r), r.push(t);
719
753
  }
720
754
  /**
721
755
  * Removes previously registered message handlers.
@@ -733,17 +767,17 @@ class T {
733
767
  * all handlers for this message type will be removed.
734
768
  */
735
769
  off(e, t) {
736
- const s = this._onHandlers.get(e), o = this._onceHandlers.get(e);
737
- if (!(!s && !o)) {
770
+ const s = this._onHandlers.get(e), r = this._onceHandlers.get(e);
771
+ if (!(!s && !r)) {
738
772
  if (s) {
739
773
  for (let i = 0; i < s.length; i += 1)
740
774
  t && s[i] !== t || (s.splice(i, 1), i -= 1);
741
775
  s.length === 0 && this._onHandlers.delete(e);
742
776
  }
743
- if (o) {
744
- for (let i = 0; i < o.length; i += 1)
745
- t && o[i] !== t || (o.splice(i, 1), i -= 1);
746
- o.length === 0 && this._onceHandlers.delete(e);
777
+ if (r) {
778
+ for (let i = 0; i < r.length; i += 1)
779
+ t && r[i] !== t || (r.splice(i, 1), i -= 1);
780
+ r.length === 0 && this._onceHandlers.delete(e);
747
781
  }
748
782
  }
749
783
  }
@@ -751,80 +785,80 @@ class T {
751
785
  function b() {
752
786
  return Math.random().toString(36).slice(2, 9);
753
787
  }
754
- const y = q.version;
788
+ const y = H.version;
755
789
  let n = null;
756
790
  function j() {
757
791
  return n;
758
792
  }
759
- function U(r) {
760
- n = new T(r), n.bind();
793
+ function D(o) {
794
+ n = new T(o), n.bind();
761
795
  }
762
796
  function L() {
763
797
  n == null || n.unbind(), n = null;
764
798
  }
765
- function V(...r) {
766
- return u(n), n.on(...r);
799
+ function U(...o) {
800
+ return p(n), n.on(...o);
767
801
  }
768
- function x(...r) {
769
- return u(n), n.once(...r);
802
+ function x(...o) {
803
+ return p(n), n.once(...o);
770
804
  }
771
- function z(...r) {
772
- return u(n), n.off(...r);
805
+ function V(...o) {
806
+ return p(n), n.off(...o);
773
807
  }
774
- function D(...r) {
775
- return u(n), n.send(...r);
808
+ function z(...o) {
809
+ return p(n), n.send(...o);
776
810
  }
777
- function K(...r) {
778
- return u(n), n.request(...r);
811
+ function K(...o) {
812
+ return p(n), n.request(...o);
779
813
  }
780
- function G(...r) {
781
- return u(n), n.subscribe(...r);
814
+ function G(...o) {
815
+ return p(n), n.subscribe(...o);
782
816
  }
783
- function J(...r) {
784
- return u(n), n.unsubscribe(...r);
817
+ function J(...o) {
818
+ return p(n), n.unsubscribe(...o);
785
819
  }
786
820
  function Q() {
787
- return u(n), n.store;
821
+ return p(n), n.store;
788
822
  }
789
823
  function W() {
790
- return u(n), n.applications;
824
+ return p(n), n.applications;
791
825
  }
792
826
  function X() {
793
- return u(n), n.media;
827
+ return p(n), n.media;
794
828
  }
795
829
  function Y() {
796
- return u(n), n.accounts;
830
+ return p(n), n.accounts;
797
831
  }
798
832
  function Z() {
799
- return u(n), n.users;
833
+ return p(n), n.users;
800
834
  }
801
835
  function O() {
802
- return u(n), n.rootSettingsNavigation;
836
+ return p(n), n.rootSettingsNavigation;
803
837
  }
804
- function u(r) {
805
- if (!r)
838
+ function p(o) {
839
+ if (!o)
806
840
  throw new Error("SDK is not configured");
807
841
  }
808
842
  export {
809
- B as Accounts,
843
+ q as Accounts,
810
844
  P as Applications,
811
845
  T as Client,
812
846
  R as Environment,
813
- I as Media,
847
+ C as Media,
814
848
  k as Store,
815
849
  E as Users,
816
850
  Y as accounts,
817
851
  W as applications,
818
- U as configure,
852
+ D as configure,
819
853
  L as destroy,
820
854
  j as globalClient,
821
855
  X as media,
822
- z as off,
823
- V as on,
856
+ V as off,
857
+ U as on,
824
858
  x as once,
825
859
  K as request,
826
860
  O as rootSettingsNavigation,
827
- D as send,
861
+ z as send,
828
862
  Q as store,
829
863
  G as subscribe,
830
864
  y as telemetrySdkVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.2.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",