@telemetryos/root-sdk 1.7.5 → 1.8.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/CHANGELOG.md +15 -0
- package/dist/client.d.ts +13 -0
- package/dist/currency.d.ts +58 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +194 -128
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @telemetryos/root-sdk
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix uncaught exception that broke SDK bridge messages
|
|
8
|
+
|
|
9
|
+
## 1.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Adds currency API, claude code skills, initializes git repos
|
|
14
|
+
- Adds currency API to root-sdk and sdk
|
|
15
|
+
- Adds Claude Code skills to tos init apps
|
|
16
|
+
- tos init initializes a git repo for your project
|
|
17
|
+
|
|
3
18
|
## 1.7.5
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Users } from './users.js';
|
|
|
7
7
|
import { Proxy } from './proxy.js';
|
|
8
8
|
import { Devices } from './devices.js';
|
|
9
9
|
import { Weather } from './weather.js';
|
|
10
|
+
import { Currency } from './currency.js';
|
|
10
11
|
import { Environment } from './environment.js';
|
|
11
12
|
import { BridgeMessage } from './bridge.js';
|
|
12
13
|
/**
|
|
@@ -207,6 +208,18 @@ export declare class Client {
|
|
|
207
208
|
* @returns A Weather instance bound to this client
|
|
208
209
|
*/
|
|
209
210
|
get weather(): Weather;
|
|
211
|
+
/**
|
|
212
|
+
* Provides access to the currency API for retrieving currency exchange rates.
|
|
213
|
+
*
|
|
214
|
+
* This property returns a new Currency instance that allows applications to fetch
|
|
215
|
+
* currency symbols and exchange rates through the TelemetryOS API.
|
|
216
|
+
*
|
|
217
|
+
* NOTE: Most application developers should use the global currency() function
|
|
218
|
+
* instead of accessing this property directly.
|
|
219
|
+
*
|
|
220
|
+
* @returns A Currency instance bound to this client
|
|
221
|
+
*/
|
|
222
|
+
get currency(): Currency;
|
|
210
223
|
/**
|
|
211
224
|
* Provides access to the environment API for accessing environment settings.
|
|
212
225
|
*
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Client } from './client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Currency symbol information mapping currency codes to their full names
|
|
4
|
+
*/
|
|
5
|
+
export type CurrencySymbols = Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Currency exchange rates mapping currency codes to their exchange rate values
|
|
8
|
+
*/
|
|
9
|
+
export type CurrencyRates = Record<string, number>;
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for getting currency exchange rates
|
|
12
|
+
*/
|
|
13
|
+
export type CurrencyRatesParams = {
|
|
14
|
+
/** Base currency code (e.g., "USD", "EUR") */
|
|
15
|
+
base: string;
|
|
16
|
+
/** Comma-separated list of target currency codes (e.g., "EUR,GBP,JPY") */
|
|
17
|
+
symbols: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Currency API for retrieving currency exchange rates and symbols
|
|
21
|
+
*
|
|
22
|
+
* Provides access to currency exchange data through the TelemetryOS API.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Currency {
|
|
25
|
+
_client: Client;
|
|
26
|
+
constructor(client: Client);
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves all available currency symbols and their full names.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves to a mapping of currency codes to their full names
|
|
31
|
+
* @throws {Error} If the request fails
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const symbols = await currency().getSymbols()
|
|
36
|
+
* // { "USD": "United States Dollar", "EUR": "Euro", ... }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
getSymbols(): Promise<CurrencySymbols>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves current exchange rates for a base currency against target currencies.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Currency rate request parameters including base currency and target symbols
|
|
44
|
+
* @returns A promise that resolves to a mapping of currency codes to their exchange rates
|
|
45
|
+
* @throws {Error} If the request fails or currencies are invalid
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Get exchange rates for USD against EUR, GBP, and JPY
|
|
50
|
+
* const rates = await currency().getRates({
|
|
51
|
+
* base: 'USD',
|
|
52
|
+
* symbols: 'EUR,GBP,JPY'
|
|
53
|
+
* })
|
|
54
|
+
* // { "EUR": 0.92, "GBP": 0.79, "JPY": 149.50 }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
getRates(params: CurrencyRatesParams): Promise<CurrencyRates>;
|
|
58
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),j="1.7.5",D={version:j};class P{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{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})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class T{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class C{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let r={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{r[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{r[u]=p}):r=t.headers);const n=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:r,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!n.success)throw new TypeError(n.errorMessage,{cause:n.errorCause?Error(n.errorCause):void 0});const l=new Headers(n.headers),c={status:n.status,statusText:n.statusText,headers:l};let d=null;if(n.body!==null&&n.body!==void 0)if(n.bodyType==="binary"){const u=atob(n.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);d=p}else n.bodyType==="text"?d=n.body:n.bodyType==="json"&&(d=JSON.stringify(n.body));return new Response(d,c)}}class k{constructor(e){this._client=e}get application(){return new y("application","",this._client)}get instance(){return new y("instance",this._client.applicationInstance,this._client)}get device(){return new y("device",this._client.applicationInstance,this._client)}shared(e){return new y("shared",e,this._client)}}class y{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 F{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}function I(a){return{...a,type:"client"}}const U=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class L{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},r=this._store._client._applicationSpecifier;o[r]={applicationSpecifier:r,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const m=1e3*30,E=typeof window>"u"&&typeof self<"u",b=E?self:window;function w(a){E?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new P(this)}get users(){return new F(this)}get store(){return new k(this)}get applications(){return new M(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new T(this)}get rootSettingsNavigation(){return new L(this.store)}get weather(){return new $(this)}get environment(){return new C(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),r=o.searchParams;if(this._applicationInstance=(e=r.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=r.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const n=o.hostname.split(".");this._applicationSpecifier=(s=n[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=n=>{if(n.source===b||!n.data||!("type"in n.data)||n.data.type!=="client"&&n.data.type!=="bridge")return;let l;if(n.data.type==="client"){const c=this._messageInterceptors.get(n.data.name);if(!c){w(n.data);return}l={...c(n.data.data),type:"bridge"}}if(!l){const c=U.safeParse(n.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const p of d)p(l.data);if(u){for(const p of u)p(l.data);this._onceHandlers.delete(l.name)}}if(!E)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});w(s)}request(e,t){const s=H(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});w(o);let r=!1,n;const l=new Promise((d,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{r=!0,this.off(s,n),u(p)},m)}),c=new Promise(d=>{n=u=>{r||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=H(),l=H();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(n),this._subscriptionNamesByHandler.set(r,n),this.on(n,r);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:n});w(d);let u=!1,p;const f=new Promise((S,g)=>{const _=new Error(`${e} subscribe request with subscription name of ${n} and response name of ${l} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(l,p),g(_)},m)}),q=new Promise(S=>{p=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,q])}async unsubscribe(e,t,s){let o,r;typeof t=="function"?r=t:(o=t,r=s);const n=H();let l=[];if(r){const c=this._subscriptionNamesByHandler.get(r);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(r)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,r);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:n,unsubscribeName:c});w(d);let u=!1,p;const f=new Promise((g,_)=>{const R=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${n} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(n,p),_(R)},m)}),q=new Promise(g=>{p=_=>{u||g(_)},this.once(n,g)});if(!(await Promise.race([f,q])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let r=0;r<s.length;r+=1)t&&s[r]!==t||(s.splice(r,1),r-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let r=0;r<o.length;r+=1)t&&o[r]!==t||(o.splice(r,1),r-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function H(){return Math.random().toString(36).slice(2,9)}const v=D.version;let i=null;function V(){return i}function W(a){i=new x(a),i.bind()}function O(){i==null||i.unbind(),i=null}function G(...a){return h(i),i.on(...a)}function J(...a){return h(i),i.once(...a)}function K(...a){return h(i),i.off(...a)}function z(...a){return h(i),i.send(...a)}function Q(...a){return h(i),i.request(...a)}function X(...a){return h(i),i.subscribe(...a)}function Y(...a){return h(i),i.unsubscribe(...a)}function Z(){return h(i),i.store}function ee(){return h(i),i.applications}function te(){return h(i),i.media}function se(){return h(i),i.accounts}function ne(){return h(i),i.users}function ie(){return h(i),i.devices}function re(){return h(i),i.proxy}function oe(){return h(i),i.rootSettingsNavigation}function ae(){return h(i),i.weather}function ce(){return h(i),i.environment}function h(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=P;exports.Applications=M;exports.Client=x;exports.Devices=T;exports.Environment=C;exports.Media=A;exports.Proxy=B;exports.Store=k;exports.StoreSlice=y;exports.Users=F;exports.Weather=$;exports.accounts=se;exports.applications=ee;exports.configure=W;exports.destroy=O;exports.devices=ie;exports.environment=ce;exports.globalClient=V;exports.media=te;exports.off=K;exports.on=G;exports.once=J;exports.proxy=re;exports.request=Q;exports.rootSettingsNavigation=oe;exports.send=z;exports.store=Z;exports.subscribe=X;exports.telemetrySdkVersion=v;exports.unsubscribe=Y;exports.users=ne;exports.weather=ae;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),D="1.8.1",U={version:D};class P{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{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})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class C{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class T{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,p)=>{n[p]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,p])=>{n[u]=p}):n=t.headers);const i=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!i.success)throw new TypeError(i.errorMessage,{cause:i.errorCause?Error(i.errorCause):void 0});const l=new Headers(i.headers),c={status:i.status,statusText:i.statusText,headers:l};let d=null;if(i.body!==null&&i.body!==void 0)if(i.bodyType==="binary"){const u=atob(i.body),p=new Uint8Array(u.length);for(let f=0;f<u.length;f++)p[f]=u.charCodeAt(f);d=p}else i.bodyType==="text"?d=i.body:i.bodyType==="json"&&(d=JSON.stringify(i.body));return new Response(d,c)}}class F{constructor(e){this._client=e}get application(){return new w("application","",this._client)}get instance(){return new w("instance",this._client.applicationInstance,this._client)}get device(){return new w("device",this._client.applicationInstance,this._client)}shared(e){return new w("shared",e,this._client)}}class w{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 k{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success||!t.conditions)throw new Error(t.error||"Failed to fetch weather conditions");return t.conditions}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch daily forecast");return t.forecast}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success||!t.forecast)throw new Error(t.error||"Failed to fetch hourly forecast");return t.forecast}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,o;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((o=n.error)===null||o===void 0?void 0:o.message)||"Failed to fetch currency rates");return n.rates}}function I(a){return{...a,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;o[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const m=1e3*30,H=typeof window>"u"&&typeof self<"u",b=H?self:window;function y(a){H?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new P(this)}get users(){return new k(this)}get store(){return new F(this)}get applications(){return new M(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new C(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new T(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),n=o.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const i=o.hostname.split(".");this._applicationSpecifier=(s=i[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=i=>{if(i.source===b||!i.data||typeof i.data!="object"||!("type"in i.data)||i.data.type!=="client"&&i.data.type!=="bridge")return;let l;if(i.data.type==="client"){const c=this._messageInterceptors.get(i.data.name);if(!c){y(i.data);return}l={...c(i.data.data),type:"bridge"}}if(!l){const c=L.safeParse(i.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const p of d)p(l.data);if(u){for(const p of u)p(l.data);this._onceHandlers.delete(l.name)}}if(!H)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t){const s=q(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});y(o);let n=!1,i;const l=new Promise((d,u)=>{const p=new Error(`${e} message request with response name of ${s} timed out after ${m}`);setTimeout(()=>{n=!0,this.off(s,i),u(p)},m)}),c=new Promise(d=>{i=u=>{n||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q(),l=q();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(i),this._subscriptionNamesByHandler.set(n,i),this.on(i,n);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:i});y(d);let u=!1,p;const f=new Promise((S,g)=>{const _=new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(l,p),g(_)},m)}),E=new Promise(S=>{p=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,E])}async unsubscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:i,unsubscribeName:c});y(d);let u=!1,p;const f=new Promise((g,_)=>{const j=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${m}`);setTimeout(()=>{u=!0,this.off(i,p),_(j)},m)}),E=new Promise(g=>{p=_=>{u||g(_)},this.once(i,g)});if(!(await Promise.race([f,E])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let n=0;n<o.length;n+=1)t&&o[n]!==t||(o.splice(n,1),n-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function q(){return Math.random().toString(36).slice(2,9)}const v=U.version;let r=null;function W(){return r}function O(a){r=new x(a),r.bind()}function G(){r==null||r.unbind(),r=null}function J(...a){return h(r),r.on(...a)}function K(...a){return h(r),r.once(...a)}function z(...a){return h(r),r.off(...a)}function Q(...a){return h(r),r.send(...a)}function X(...a){return h(r),r.request(...a)}function Y(...a){return h(r),r.subscribe(...a)}function Z(...a){return h(r),r.unsubscribe(...a)}function ee(){return h(r),r.store}function te(){return h(r),r.applications}function se(){return h(r),r.media}function ne(){return h(r),r.accounts}function ie(){return h(r),r.users}function re(){return h(r),r.devices}function oe(){return h(r),r.proxy}function ae(){return h(r),r.rootSettingsNavigation}function ce(){return h(r),r.weather}function le(){return h(r),r.currency}function ue(){return h(r),r.environment}function h(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=P;exports.Applications=M;exports.Client=x;exports.Currency=R;exports.Devices=C;exports.Environment=T;exports.Media=A;exports.Proxy=B;exports.Store=F;exports.StoreSlice=w;exports.Users=k;exports.Weather=$;exports.accounts=ne;exports.applications=te;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=re;exports.environment=ue;exports.globalClient=W;exports.media=se;exports.off=z;exports.on=J;exports.once=K;exports.proxy=oe;exports.request=X;exports.rootSettingsNavigation=ae;exports.send=Q;exports.store=ee;exports.subscribe=Y;exports.telemetrySdkVersion=v;exports.unsubscribe=Z;exports.users=ie;exports.weather=ce;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { Store, StoreSlice } from './store.js';
|
|
|
8
8
|
export { Users } from './users.js';
|
|
9
9
|
export { Weather } from './weather.js';
|
|
10
10
|
export type { WeatherConditions, WeatherForecast, WeatherRequestParams, DailyForecastParams, HourlyForecastParams, } from './weather.js';
|
|
11
|
+
export { Currency } from './currency.js';
|
|
12
|
+
export type { CurrencySymbols, CurrencyRates, CurrencyRatesParams, } from './currency.js';
|
|
11
13
|
import { Client } from './client.js';
|
|
12
14
|
export { Client, type SubscriptionResult, type MessageHandler } from './client.js';
|
|
13
15
|
/**
|
|
@@ -267,6 +269,22 @@ export declare function rootSettingsNavigation(): import("./root-settings-naviga
|
|
|
267
269
|
* const forecast = await weather().getDailyForecast({ city: 'London', units: 'metric', days: 5 });
|
|
268
270
|
*/
|
|
269
271
|
export declare function weather(): import("./weather.js").Weather;
|
|
272
|
+
/**
|
|
273
|
+
* Provides access to the currency API for retrieving currency exchange rates.
|
|
274
|
+
*
|
|
275
|
+
* This API allows applications to fetch currency symbols and exchange rates
|
|
276
|
+
* through the TelemetryOS API.
|
|
277
|
+
*
|
|
278
|
+
* @returns The Currency API object
|
|
279
|
+
* @throws {Error} If called before configure() or after destroy()
|
|
280
|
+
* @example
|
|
281
|
+
* // Get all currency symbols
|
|
282
|
+
* const symbols = await currency().getSymbols();
|
|
283
|
+
*
|
|
284
|
+
* // Get exchange rates
|
|
285
|
+
* const rates = await currency().getRates({ base: 'USD', symbols: 'EUR,GBP,JPY' });
|
|
286
|
+
*/
|
|
287
|
+
export declare function currency(): import("./currency.js").Currency;
|
|
270
288
|
/**
|
|
271
289
|
* Provides access to the environment API for accessing environment settings.
|
|
272
290
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { o as P, a as M, s as T, l as C } from "./types-CCzf8sMT.js";
|
|
2
|
-
const B = "1.
|
|
2
|
+
const B = "1.8.1", A = {
|
|
3
3
|
version: B
|
|
4
4
|
};
|
|
5
|
-
class
|
|
5
|
+
class F {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this._client = e;
|
|
8
8
|
}
|
|
@@ -21,7 +21,7 @@ class k {
|
|
|
21
21
|
return e.account;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class $ {
|
|
25
25
|
constructor(e) {
|
|
26
26
|
this._client = e;
|
|
27
27
|
}
|
|
@@ -118,7 +118,7 @@ class F {
|
|
|
118
118
|
this._client._messageInterceptors.set(e, t);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
class
|
|
121
|
+
class k {
|
|
122
122
|
constructor(e) {
|
|
123
123
|
this._client = e;
|
|
124
124
|
}
|
|
@@ -219,35 +219,35 @@ class j {
|
|
|
219
219
|
referrer: e.referrer,
|
|
220
220
|
integrity: e.integrity
|
|
221
221
|
}));
|
|
222
|
-
let
|
|
222
|
+
let n = {};
|
|
223
223
|
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((u, p) => {
|
|
224
|
-
|
|
224
|
+
n[p] = u;
|
|
225
225
|
}) : Array.isArray(t.headers) ? t.headers.forEach(([u, p]) => {
|
|
226
|
-
|
|
227
|
-
}) :
|
|
228
|
-
const
|
|
226
|
+
n[u] = p;
|
|
227
|
+
}) : n = t.headers);
|
|
228
|
+
const i = await this._client.request("proxy.fetch", {
|
|
229
229
|
url: o,
|
|
230
230
|
method: (t == null ? void 0 : t.method) || "GET",
|
|
231
|
-
headers:
|
|
231
|
+
headers: n,
|
|
232
232
|
body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
|
|
233
233
|
});
|
|
234
|
-
if (!
|
|
235
|
-
throw new TypeError(
|
|
236
|
-
cause:
|
|
234
|
+
if (!i.success)
|
|
235
|
+
throw new TypeError(i.errorMessage, {
|
|
236
|
+
cause: i.errorCause ? Error(i.errorCause) : void 0
|
|
237
237
|
});
|
|
238
|
-
const l = new Headers(
|
|
239
|
-
status:
|
|
240
|
-
statusText:
|
|
238
|
+
const l = new Headers(i.headers), c = {
|
|
239
|
+
status: i.status,
|
|
240
|
+
statusText: i.statusText,
|
|
241
241
|
headers: l
|
|
242
242
|
};
|
|
243
243
|
let d = null;
|
|
244
|
-
if (
|
|
245
|
-
if (
|
|
246
|
-
const u = atob(
|
|
244
|
+
if (i.body !== null && i.body !== void 0)
|
|
245
|
+
if (i.bodyType === "binary") {
|
|
246
|
+
const u = atob(i.body), p = new Uint8Array(u.length);
|
|
247
247
|
for (let f = 0; f < u.length; f++)
|
|
248
248
|
p[f] = u.charCodeAt(f);
|
|
249
249
|
d = p;
|
|
250
|
-
} else
|
|
250
|
+
} else i.bodyType === "text" ? d = i.body : i.bodyType === "json" && (d = JSON.stringify(i.body));
|
|
251
251
|
return new Response(d, c);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
@@ -506,15 +506,62 @@ class U {
|
|
|
506
506
|
return t.forecast;
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
+
class V {
|
|
510
|
+
constructor(e) {
|
|
511
|
+
this._client = e;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Retrieves all available currency symbols and their full names.
|
|
515
|
+
*
|
|
516
|
+
* @returns A promise that resolves to a mapping of currency codes to their full names
|
|
517
|
+
* @throws {Error} If the request fails
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* const symbols = await currency().getSymbols()
|
|
522
|
+
* // { "USD": "United States Dollar", "EUR": "Euro", ... }
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
async getSymbols() {
|
|
526
|
+
const e = await this._client.request("currency.getSymbols", {});
|
|
527
|
+
if (!e.success || !e.symbols)
|
|
528
|
+
throw new Error("Failed to fetch currency symbols");
|
|
529
|
+
return e.symbols;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Retrieves current exchange rates for a base currency against target currencies.
|
|
533
|
+
*
|
|
534
|
+
* @param params - Currency rate request parameters including base currency and target symbols
|
|
535
|
+
* @returns A promise that resolves to a mapping of currency codes to their exchange rates
|
|
536
|
+
* @throws {Error} If the request fails or currencies are invalid
|
|
537
|
+
*
|
|
538
|
+
* @example
|
|
539
|
+
* ```typescript
|
|
540
|
+
* // Get exchange rates for USD against EUR, GBP, and JPY
|
|
541
|
+
* const rates = await currency().getRates({
|
|
542
|
+
* base: 'USD',
|
|
543
|
+
* symbols: 'EUR,GBP,JPY'
|
|
544
|
+
* })
|
|
545
|
+
* // { "EUR": 0.92, "GBP": 0.79, "JPY": 149.50 }
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
async getRates(e) {
|
|
549
|
+
var t, s, o;
|
|
550
|
+
const n = await this._client.request("currency.getRates", e);
|
|
551
|
+
if (!n.success || !n.rates)
|
|
552
|
+
throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((o = n.error) === null || o === void 0 ? void 0 : o.message) || "Failed to fetch currency rates");
|
|
553
|
+
return n.rates;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
509
556
|
function S(a) {
|
|
510
557
|
return { ...a, type: "client" };
|
|
511
558
|
}
|
|
512
|
-
const
|
|
559
|
+
const W = P({
|
|
513
560
|
type: C("bridge"),
|
|
514
561
|
name: T(),
|
|
515
562
|
data: M()
|
|
516
563
|
});
|
|
517
|
-
class
|
|
564
|
+
class G {
|
|
518
565
|
/**
|
|
519
566
|
* Creates a new RootSettingsNavigation API instance.
|
|
520
567
|
*
|
|
@@ -538,9 +585,9 @@ class W {
|
|
|
538
585
|
*/
|
|
539
586
|
async setRootSettingsNavigation(e) {
|
|
540
587
|
var t;
|
|
541
|
-
const s = this._store.shared("root-settings-navigation"), o = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {},
|
|
542
|
-
o[
|
|
543
|
-
applicationSpecifier:
|
|
588
|
+
const s = this._store.shared("root-settings-navigation"), o = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, n = this._store._client._applicationSpecifier;
|
|
589
|
+
o[n] = {
|
|
590
|
+
applicationSpecifier: n,
|
|
544
591
|
entries: e.entries
|
|
545
592
|
}, s.set("navigation", o);
|
|
546
593
|
}
|
|
@@ -571,11 +618,11 @@ class W {
|
|
|
571
618
|
return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
|
|
572
619
|
}
|
|
573
620
|
}
|
|
574
|
-
const _ = 1e3 * 30,
|
|
575
|
-
function
|
|
576
|
-
|
|
621
|
+
const _ = 1e3 * 30, E = typeof window > "u" && typeof self < "u", w = E ? self : window;
|
|
622
|
+
function y(a) {
|
|
623
|
+
E ? self.postMessage(a) : w.parent.postMessage(a, "*");
|
|
577
624
|
}
|
|
578
|
-
class
|
|
625
|
+
class J {
|
|
579
626
|
/**
|
|
580
627
|
* Creates a new Client instance for communicating with the TelemetryOS platform.
|
|
581
628
|
*
|
|
@@ -601,7 +648,7 @@ class G {
|
|
|
601
648
|
* @returns An Accounts instance bound to this client
|
|
602
649
|
*/
|
|
603
650
|
get accounts() {
|
|
604
|
-
return new
|
|
651
|
+
return new F(this);
|
|
605
652
|
}
|
|
606
653
|
/**
|
|
607
654
|
* Provides access to the users API for retrieving TelemetryOS user information.
|
|
@@ -643,7 +690,7 @@ class G {
|
|
|
643
690
|
* @returns An Applications instance bound to this client
|
|
644
691
|
*/
|
|
645
692
|
get applications() {
|
|
646
|
-
return new
|
|
693
|
+
return new $(this);
|
|
647
694
|
}
|
|
648
695
|
/**
|
|
649
696
|
* Provides access to the media API for working with content hosted on the TelemetryOS platform.
|
|
@@ -687,7 +734,7 @@ class G {
|
|
|
687
734
|
* @returns A Devices instance bound to this client
|
|
688
735
|
*/
|
|
689
736
|
get devices() {
|
|
690
|
-
return new
|
|
737
|
+
return new k(this);
|
|
691
738
|
}
|
|
692
739
|
/**
|
|
693
740
|
* Provides access to the root settings navigation API for TelemetryOS administration UI integration.
|
|
@@ -705,7 +752,7 @@ class G {
|
|
|
705
752
|
* @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
|
|
706
753
|
*/
|
|
707
754
|
get rootSettingsNavigation() {
|
|
708
|
-
return new
|
|
755
|
+
return new G(this.store);
|
|
709
756
|
}
|
|
710
757
|
/**
|
|
711
758
|
* Provides access to the weather API for retrieving weather data.
|
|
@@ -721,6 +768,20 @@ class G {
|
|
|
721
768
|
get weather() {
|
|
722
769
|
return new U(this);
|
|
723
770
|
}
|
|
771
|
+
/**
|
|
772
|
+
* Provides access to the currency API for retrieving currency exchange rates.
|
|
773
|
+
*
|
|
774
|
+
* This property returns a new Currency instance that allows applications to fetch
|
|
775
|
+
* currency symbols and exchange rates through the TelemetryOS API.
|
|
776
|
+
*
|
|
777
|
+
* NOTE: Most application developers should use the global currency() function
|
|
778
|
+
* instead of accessing this property directly.
|
|
779
|
+
*
|
|
780
|
+
* @returns A Currency instance bound to this client
|
|
781
|
+
*/
|
|
782
|
+
get currency() {
|
|
783
|
+
return new V(this);
|
|
784
|
+
}
|
|
724
785
|
/**
|
|
725
786
|
* Provides access to the environment API for accessing environment settings.
|
|
726
787
|
*
|
|
@@ -761,29 +822,29 @@ class G {
|
|
|
761
822
|
*/
|
|
762
823
|
bind() {
|
|
763
824
|
var e, t, s;
|
|
764
|
-
const o = new URL(
|
|
765
|
-
if (this._applicationInstance = (e =
|
|
825
|
+
const o = new URL(w.location.href), n = o.searchParams;
|
|
826
|
+
if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
|
|
766
827
|
throw new Error("Missing applicationInstance query parameter");
|
|
767
|
-
if (this._applicationSpecifier = (t =
|
|
768
|
-
const
|
|
769
|
-
this._applicationSpecifier = (s =
|
|
828
|
+
if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
|
|
829
|
+
const i = o.hostname.split(".");
|
|
830
|
+
this._applicationSpecifier = (s = i[0]) !== null && s !== void 0 ? s : "";
|
|
770
831
|
}
|
|
771
832
|
if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
|
|
772
833
|
throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
773
|
-
this._windowMessageHandler = (
|
|
774
|
-
if (
|
|
834
|
+
this._windowMessageHandler = (i) => {
|
|
835
|
+
if (i.source === w || !i.data || typeof i.data != "object" || !("type" in i.data) || i.data.type !== "client" && i.data.type !== "bridge")
|
|
775
836
|
return;
|
|
776
837
|
let l;
|
|
777
|
-
if (
|
|
778
|
-
const c = this._messageInterceptors.get(
|
|
838
|
+
if (i.data.type === "client") {
|
|
839
|
+
const c = this._messageInterceptors.get(i.data.name);
|
|
779
840
|
if (!c) {
|
|
780
|
-
|
|
841
|
+
y(i.data);
|
|
781
842
|
return;
|
|
782
843
|
}
|
|
783
|
-
l = { ...c(
|
|
844
|
+
l = { ...c(i.data.data), type: "bridge" };
|
|
784
845
|
}
|
|
785
846
|
if (!l) {
|
|
786
|
-
const c =
|
|
847
|
+
const c = W.safeParse(i.data);
|
|
787
848
|
if (!c.success)
|
|
788
849
|
return;
|
|
789
850
|
l = c.data;
|
|
@@ -797,10 +858,10 @@ class G {
|
|
|
797
858
|
this._onceHandlers.delete(l.name);
|
|
798
859
|
}
|
|
799
860
|
}
|
|
800
|
-
if (!
|
|
861
|
+
if (!E)
|
|
801
862
|
for (let c = 0; c < window.frames.length; c += 1)
|
|
802
863
|
window.frames[c].postMessage(l, "*");
|
|
803
|
-
},
|
|
864
|
+
}, w.addEventListener("message", this._windowMessageHandler);
|
|
804
865
|
}
|
|
805
866
|
/**
|
|
806
867
|
* Removes the message event listener and cleans up resources.
|
|
@@ -816,7 +877,7 @@ class G {
|
|
|
816
877
|
* of managing their own Client instances.
|
|
817
878
|
*/
|
|
818
879
|
unbind() {
|
|
819
|
-
this._windowMessageHandler &&
|
|
880
|
+
this._windowMessageHandler && w.removeEventListener("message", this._windowMessageHandler);
|
|
820
881
|
}
|
|
821
882
|
/**
|
|
822
883
|
* Sends a one-way message to the TelemetryOS platform.
|
|
@@ -840,7 +901,7 @@ class G {
|
|
|
840
901
|
name: e,
|
|
841
902
|
data: t
|
|
842
903
|
});
|
|
843
|
-
|
|
904
|
+
y(s);
|
|
844
905
|
}
|
|
845
906
|
/**
|
|
846
907
|
* Sends a message to the TelemetryOS platform and waits for a response.
|
|
@@ -869,26 +930,26 @@ class G {
|
|
|
869
930
|
data: t,
|
|
870
931
|
responseName: s
|
|
871
932
|
});
|
|
872
|
-
|
|
873
|
-
let
|
|
933
|
+
y(o);
|
|
934
|
+
let n = !1, i;
|
|
874
935
|
const l = new Promise((d, u) => {
|
|
875
936
|
const p = new Error(`${e} message request with response name of ${s} timed out after ${_}`);
|
|
876
937
|
setTimeout(() => {
|
|
877
|
-
|
|
938
|
+
n = !0, this.off(s, i), u(p);
|
|
878
939
|
}, _);
|
|
879
940
|
}), c = new Promise((d) => {
|
|
880
|
-
|
|
881
|
-
|
|
941
|
+
i = (u) => {
|
|
942
|
+
n || d(u);
|
|
882
943
|
}, this.once(s, d);
|
|
883
944
|
});
|
|
884
945
|
return Promise.race([l, c]);
|
|
885
946
|
}
|
|
886
947
|
async subscribe(e, t, s) {
|
|
887
|
-
let o,
|
|
888
|
-
typeof t == "function" ?
|
|
889
|
-
const
|
|
948
|
+
let o, n;
|
|
949
|
+
typeof t == "function" ? n = t : (o = t, n = s);
|
|
950
|
+
const i = N(), l = N();
|
|
890
951
|
let c = this._subscriptionNamesBySubjectName.get(e);
|
|
891
|
-
c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(
|
|
952
|
+
c || (c = [], this._subscriptionNamesBySubjectName.set(e, c)), c.push(i), this._subscriptionNamesByHandler.set(n, i), this.on(i, n);
|
|
892
953
|
const d = S({
|
|
893
954
|
telemetrySdkVersion: I,
|
|
894
955
|
applicationName: this._applicationName,
|
|
@@ -897,12 +958,12 @@ class G {
|
|
|
897
958
|
name: e,
|
|
898
959
|
data: o,
|
|
899
960
|
responseName: l,
|
|
900
|
-
subscriptionName:
|
|
961
|
+
subscriptionName: i
|
|
901
962
|
});
|
|
902
|
-
|
|
963
|
+
y(d);
|
|
903
964
|
let u = !1, p;
|
|
904
965
|
const f = new Promise((b, g) => {
|
|
905
|
-
const m = new Error(`${e} subscribe request with subscription name of ${
|
|
966
|
+
const m = new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${_}`);
|
|
906
967
|
setTimeout(() => {
|
|
907
968
|
u = !0, this.off(l, p), g(m);
|
|
908
969
|
}, _);
|
|
@@ -914,19 +975,19 @@ class G {
|
|
|
914
975
|
return Promise.race([f, H]);
|
|
915
976
|
}
|
|
916
977
|
async unsubscribe(e, t, s) {
|
|
917
|
-
let o,
|
|
918
|
-
typeof t == "function" ?
|
|
919
|
-
const
|
|
978
|
+
let o, n;
|
|
979
|
+
typeof t == "function" ? n = t : (o = t, n = s);
|
|
980
|
+
const i = N();
|
|
920
981
|
let l = [];
|
|
921
|
-
if (
|
|
922
|
-
const c = this._subscriptionNamesByHandler.get(
|
|
982
|
+
if (n) {
|
|
983
|
+
const c = this._subscriptionNamesByHandler.get(n);
|
|
923
984
|
if (!c)
|
|
924
985
|
return { success: !1 };
|
|
925
|
-
l = [c], this._subscriptionNamesByHandler.delete(
|
|
986
|
+
l = [c], this._subscriptionNamesByHandler.delete(n);
|
|
926
987
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
927
988
|
return { success: !1 };
|
|
928
989
|
for await (const c of l) {
|
|
929
|
-
this.off(c,
|
|
990
|
+
this.off(c, n);
|
|
930
991
|
const d = S({
|
|
931
992
|
telemetrySdkVersion: I,
|
|
932
993
|
applicationInstance: this._applicationInstance,
|
|
@@ -934,20 +995,20 @@ class G {
|
|
|
934
995
|
applicationSpecifier: this._applicationSpecifier,
|
|
935
996
|
name: e,
|
|
936
997
|
data: o,
|
|
937
|
-
responseName:
|
|
998
|
+
responseName: i,
|
|
938
999
|
unsubscribeName: c
|
|
939
1000
|
});
|
|
940
|
-
|
|
1001
|
+
y(d);
|
|
941
1002
|
let u = !1, p;
|
|
942
1003
|
const f = new Promise((g, m) => {
|
|
943
|
-
const
|
|
1004
|
+
const q = new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${_}`);
|
|
944
1005
|
setTimeout(() => {
|
|
945
|
-
u = !0, this.off(
|
|
1006
|
+
u = !0, this.off(i, p), m(q);
|
|
946
1007
|
}, _);
|
|
947
1008
|
}), H = new Promise((g) => {
|
|
948
1009
|
p = (m) => {
|
|
949
1010
|
u || g(m);
|
|
950
|
-
}, this.once(
|
|
1011
|
+
}, this.once(i, g);
|
|
951
1012
|
});
|
|
952
1013
|
if (!(await Promise.race([f, H])).success)
|
|
953
1014
|
return { success: !1 };
|
|
@@ -1014,13 +1075,13 @@ class G {
|
|
|
1014
1075
|
const s = this._onHandlers.get(e), o = this._onceHandlers.get(e);
|
|
1015
1076
|
if (!(!s && !o)) {
|
|
1016
1077
|
if (s) {
|
|
1017
|
-
for (let
|
|
1018
|
-
t && s[
|
|
1078
|
+
for (let n = 0; n < s.length; n += 1)
|
|
1079
|
+
t && s[n] !== t || (s.splice(n, 1), n -= 1);
|
|
1019
1080
|
s.length === 0 && this._onHandlers.delete(e);
|
|
1020
1081
|
}
|
|
1021
1082
|
if (o) {
|
|
1022
|
-
for (let
|
|
1023
|
-
t && o[
|
|
1083
|
+
for (let n = 0; n < o.length; n += 1)
|
|
1084
|
+
t && o[n] !== t || (o.splice(n, 1), n -= 1);
|
|
1024
1085
|
o.length === 0 && this._onceHandlers.delete(e);
|
|
1025
1086
|
}
|
|
1026
1087
|
}
|
|
@@ -1030,76 +1091,80 @@ function N() {
|
|
|
1030
1091
|
return Math.random().toString(36).slice(2, 9);
|
|
1031
1092
|
}
|
|
1032
1093
|
const I = A.version;
|
|
1033
|
-
let
|
|
1034
|
-
function
|
|
1035
|
-
return
|
|
1036
|
-
}
|
|
1037
|
-
function O(a) {
|
|
1038
|
-
i = new G(a), i.bind();
|
|
1094
|
+
let r = null;
|
|
1095
|
+
function O() {
|
|
1096
|
+
return r;
|
|
1039
1097
|
}
|
|
1040
|
-
function z() {
|
|
1041
|
-
|
|
1098
|
+
function z(a) {
|
|
1099
|
+
r = new J(a), r.bind();
|
|
1042
1100
|
}
|
|
1043
|
-
function Q(
|
|
1044
|
-
|
|
1101
|
+
function Q() {
|
|
1102
|
+
r == null || r.unbind(), r = null;
|
|
1045
1103
|
}
|
|
1046
1104
|
function X(...a) {
|
|
1047
|
-
return h(
|
|
1105
|
+
return h(r), r.on(...a);
|
|
1048
1106
|
}
|
|
1049
1107
|
function Y(...a) {
|
|
1050
|
-
return h(
|
|
1108
|
+
return h(r), r.once(...a);
|
|
1051
1109
|
}
|
|
1052
1110
|
function Z(...a) {
|
|
1053
|
-
return h(
|
|
1111
|
+
return h(r), r.off(...a);
|
|
1054
1112
|
}
|
|
1055
1113
|
function ee(...a) {
|
|
1056
|
-
return h(
|
|
1114
|
+
return h(r), r.send(...a);
|
|
1057
1115
|
}
|
|
1058
1116
|
function te(...a) {
|
|
1059
|
-
return h(
|
|
1117
|
+
return h(r), r.request(...a);
|
|
1060
1118
|
}
|
|
1061
1119
|
function se(...a) {
|
|
1062
|
-
return h(
|
|
1120
|
+
return h(r), r.subscribe(...a);
|
|
1063
1121
|
}
|
|
1064
|
-
function ne() {
|
|
1065
|
-
return h(
|
|
1122
|
+
function ne(...a) {
|
|
1123
|
+
return h(r), r.unsubscribe(...a);
|
|
1066
1124
|
}
|
|
1067
1125
|
function ie() {
|
|
1068
|
-
return h(
|
|
1126
|
+
return h(r), r.store;
|
|
1069
1127
|
}
|
|
1070
1128
|
function re() {
|
|
1071
|
-
return h(
|
|
1129
|
+
return h(r), r.applications;
|
|
1072
1130
|
}
|
|
1073
1131
|
function oe() {
|
|
1074
|
-
return h(
|
|
1132
|
+
return h(r), r.media;
|
|
1075
1133
|
}
|
|
1076
1134
|
function ae() {
|
|
1077
|
-
return h(
|
|
1135
|
+
return h(r), r.accounts;
|
|
1078
1136
|
}
|
|
1079
1137
|
function ce() {
|
|
1080
|
-
return h(
|
|
1138
|
+
return h(r), r.users;
|
|
1081
1139
|
}
|
|
1082
1140
|
function le() {
|
|
1083
|
-
return h(
|
|
1141
|
+
return h(r), r.devices;
|
|
1084
1142
|
}
|
|
1085
1143
|
function ue() {
|
|
1086
|
-
return h(
|
|
1144
|
+
return h(r), r.proxy;
|
|
1087
1145
|
}
|
|
1088
1146
|
function pe() {
|
|
1089
|
-
return h(
|
|
1147
|
+
return h(r), r.rootSettingsNavigation;
|
|
1090
1148
|
}
|
|
1091
1149
|
function he() {
|
|
1092
|
-
return h(
|
|
1150
|
+
return h(r), r.weather;
|
|
1151
|
+
}
|
|
1152
|
+
function de() {
|
|
1153
|
+
return h(r), r.currency;
|
|
1154
|
+
}
|
|
1155
|
+
function fe() {
|
|
1156
|
+
return h(r), r.environment;
|
|
1093
1157
|
}
|
|
1094
1158
|
function h(a) {
|
|
1095
1159
|
if (!a)
|
|
1096
1160
|
throw new Error("SDK is not configured");
|
|
1097
1161
|
}
|
|
1098
1162
|
export {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1163
|
+
F as Accounts,
|
|
1164
|
+
$ as Applications,
|
|
1165
|
+
J as Client,
|
|
1166
|
+
V as Currency,
|
|
1167
|
+
k as Devices,
|
|
1103
1168
|
R as Environment,
|
|
1104
1169
|
x as Media,
|
|
1105
1170
|
j as Proxy,
|
|
@@ -1107,25 +1172,26 @@ export {
|
|
|
1107
1172
|
v as StoreSlice,
|
|
1108
1173
|
L as Users,
|
|
1109
1174
|
U as Weather,
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
X as
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1175
|
+
ae as accounts,
|
|
1176
|
+
re as applications,
|
|
1177
|
+
z as configure,
|
|
1178
|
+
de as currency,
|
|
1179
|
+
Q as destroy,
|
|
1180
|
+
le as devices,
|
|
1181
|
+
fe as environment,
|
|
1182
|
+
O as globalClient,
|
|
1183
|
+
oe as media,
|
|
1184
|
+
Z as off,
|
|
1185
|
+
X as on,
|
|
1186
|
+
Y as once,
|
|
1187
|
+
ue as proxy,
|
|
1188
|
+
te as request,
|
|
1189
|
+
pe as rootSettingsNavigation,
|
|
1190
|
+
ee as send,
|
|
1191
|
+
ie as store,
|
|
1192
|
+
se as subscribe,
|
|
1127
1193
|
I as telemetrySdkVersion,
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1194
|
+
ne as unsubscribe,
|
|
1195
|
+
ce as users,
|
|
1196
|
+
he as weather
|
|
1131
1197
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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",
|