@telemetryos/root-sdk 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./index-JDXm3DEz.cjs"),k="1.0.0",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 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;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z as S } from "./index-B98VDFRY.js";
2
- const M = "1.0.0", q = {
2
+ const M = "1.0.1", q = {
3
3
  version: M
4
4
  };
5
5
  class B {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetryos/root-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",