@telemetryos/root-sdk 1.0.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/README.md +598 -0
- package/dist/accounts.d.ts +18 -0
- package/dist/applications.d.ts +55 -0
- package/dist/bridge-message-formatter.d.ts +7 -0
- package/dist/bridge-message-validator.d.ts +11 -0
- package/dist/bridge.cjs +1 -0
- package/dist/bridge.d.ts +45 -0
- package/dist/bridge.js +46 -0
- package/dist/client-message-formatter.d.ts +12 -0
- package/dist/client-message-validator.d.ts +26 -0
- package/dist/client.d.ts +293 -0
- package/dist/client.spec.d.ts +1 -0
- package/dist/do-async.d.ts +1 -0
- package/dist/environment.d.ts +10 -0
- package/dist/index-B98VDFRY.js +2974 -0
- package/dist/index-JDXm3DEz.cjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +833 -0
- package/dist/index.spec.d.ts +1 -0
- package/dist/media.d.ts +71 -0
- package/dist/root-settings-navigation.d.ts +59 -0
- package/dist/store.d.ts +129 -0
- package/dist/test-setup.d.ts +1 -0
- package/dist/users.d.ts +25 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
# TelemetryOS Root Applications SDK
|
|
2
|
+
|
|
3
|
+
Welcome to the TelemetryOS Root Applications SDK! This document will guide you through building root applications for TelemetryOS.
|
|
4
|
+
|
|
5
|
+
## What is TelemetryOS?
|
|
6
|
+
|
|
7
|
+
TelemetryOS is a platform for running web applications on devices connected to displays, such as TVs and touch screen kiosks. It can manage thousands of devices per account, enabling organizations to create, manage, and deploy dynamic content and interactive applications across their physical locations.
|
|
8
|
+
|
|
9
|
+
Key features of the platform include:
|
|
10
|
+
|
|
11
|
+
- Run single-page applications on display devices.
|
|
12
|
+
- Support containers that run alongside applications.
|
|
13
|
+
- Run worker scripts that operate continuously in the background.
|
|
14
|
+
- Compose content with our Freeform Editor for visual layouts.
|
|
15
|
+
- Support content playlists and scheduling.
|
|
16
|
+
- Manage devices at scale.
|
|
17
|
+
|
|
18
|
+
## Root Applications in TelemetryOS
|
|
19
|
+
|
|
20
|
+
Root applications are advanced web applications that replace TelemetryOS's default Freeform Editor entirely. When you build a root application, you're creating a complete custom interface that runs directly on devices.
|
|
21
|
+
|
|
22
|
+
**Important:** Most developers should use the standard SDK (`@telemetryos/sdk`) instead. Root applications are for specialized use cases that require complete control over the device experience.
|
|
23
|
+
|
|
24
|
+
### Example Use Cases
|
|
25
|
+
|
|
26
|
+
Root applications could be used for scenarios like:
|
|
27
|
+
|
|
28
|
+
- **IPTV Set-Top Box Interface** - Custom UI for channel navigation, program guides, and proprietary video decoding with specialized hardware integration
|
|
29
|
+
- **Industrial Control Dashboards** - Real-time monitoring and control interfaces for manufacturing equipment or building systems
|
|
30
|
+
- **Interactive Kiosk Systems** - Completely custom navigation flows for specific business processes (beyond standard digital signage)
|
|
31
|
+
- **Point-of-Sale Terminals** - Custom checkout interfaces with payment processing and inventory integration
|
|
32
|
+
- **Educational Interactive Displays** - Specialized learning interfaces with custom interaction patterns
|
|
33
|
+
|
|
34
|
+
### How Root Applications Work
|
|
35
|
+
|
|
36
|
+
Your root application runs as an iframe directly within TelemetryOS's infrastructure, completely replacing the Freeform Editor. You're responsible for building:
|
|
37
|
+
|
|
38
|
+
- **Complete Device Interface** - The entire user experience that displays on physical devices
|
|
39
|
+
- **Custom Administration Interface** - Configuration tools integrated into TelemetryOS's administration UI
|
|
40
|
+
- **Administration Navigation** - Custom sidebar navigation items in the TelemetryOS administration UI for managing your specialized resources
|
|
41
|
+
|
|
42
|
+
### Mount Points
|
|
43
|
+
|
|
44
|
+
Root applications define specialized mount points in their `telemetry.config.json` file:
|
|
45
|
+
|
|
46
|
+
- `rootRender` - The main interface that displays on physical devices. This replaces the Freeform Editor entirely.
|
|
47
|
+
- `rootSettings` - The main configuration interface in TelemetryOS's [administration UI][admin-ui] where customers configure your root application.
|
|
48
|
+
|
|
49
|
+
And specialized worker scripts:
|
|
50
|
+
|
|
51
|
+
- `rootSettingsNavigation` - Registers custom navigation items in TelemetryOS's administration UI sidebar, allowing you to add specialized management interfaces (e.g., "Channel Management", "Hardware Settings", "Custom Reports").
|
|
52
|
+
- `rootSettingsDeviceContentAssignment` - Configures custom options when customers assign your root application to devices.
|
|
53
|
+
|
|
54
|
+
### Administration UI Integration
|
|
55
|
+
|
|
56
|
+
Root applications can integrate deeply with TelemetryOS's administration interface by registering custom navigation items:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
// Register custom sidebar navigation for your root application
|
|
60
|
+
import { rootSettingsNavigation } from '@telemetryos/root-sdk';
|
|
61
|
+
|
|
62
|
+
await rootSettingsNavigation().register([
|
|
63
|
+
{ label: 'Channel Management', path: '/admin/channels' },
|
|
64
|
+
{ label: 'Hardware Configuration', path: '/admin/hardware' },
|
|
65
|
+
{ label: 'Viewing Analytics', path: '/admin/analytics' }
|
|
66
|
+
]);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
This allows customers to manage your specialized resources alongside their standard TelemetryOS configuration.
|
|
70
|
+
|
|
71
|
+
### Embedding Other Applications (Optional)
|
|
72
|
+
|
|
73
|
+
Root applications can also discover and embed other TelemetryOS applications if needed:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// Discover applications by mount point
|
|
77
|
+
const widgets = await applications().getAllByMountPoint('status-widget');
|
|
78
|
+
|
|
79
|
+
// Create custom composition interface
|
|
80
|
+
const iframe = document.createElement('iframe');
|
|
81
|
+
iframe.src = await applications().getUrl('system-monitor', 'render');
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Getting Started
|
|
85
|
+
|
|
86
|
+
To get started, add the SDK to your project:
|
|
87
|
+
|
|
88
|
+
### Installation
|
|
89
|
+
|
|
90
|
+
With npm:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install @telemetryos/root-sdk
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or include it directly in your HTML:
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<script src="https://cdn.jsdelivr.net/npm/@telemetryos/root-sdk"></script>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Basic Configuration
|
|
103
|
+
|
|
104
|
+
Import and configure the SDK with your application name:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import { configure } from '@telemetryos/root-sdk';
|
|
108
|
+
|
|
109
|
+
// Initialize the SDK - call this early in your application lifecycle
|
|
110
|
+
// The application name must match the name in your telemetry.config.json
|
|
111
|
+
configure('myAppName')
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Or using the global object if you included the script directly:
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
telemetry.configure('myAppName')
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The SDK automatically extracts the application ID from URL parameters, which is essential for proper functioning of the store's local and deviceLocal scopes.
|
|
121
|
+
|
|
122
|
+
## Core SDK Features
|
|
123
|
+
|
|
124
|
+
### Storage API
|
|
125
|
+
|
|
126
|
+
The SDK provides a powerful storage system with multiple scopes:
|
|
127
|
+
|
|
128
|
+
- **Global** - Shared across all instances of your application within an account. Use for app-wide settings like branding or global configuration.
|
|
129
|
+
- **Local** - Specific to this application instance (uses applicationId). Perfect for settings ↔ render communication since both mount points share the same instance.
|
|
130
|
+
- **DeviceLocal** - Stored only on the current device, never synced across devices. Survives device restarts. Ideal for device-specific calibration or state.
|
|
131
|
+
- **Shared** - Inter-application communication using namespace strings. Applications can coordinate by agreeing on namespace and key conventions.
|
|
132
|
+
|
|
133
|
+
The `applicationId` is automatically provided when your application is embedded, ensuring that multiple instances of your app maintain separate configurations.
|
|
134
|
+
|
|
135
|
+
Example usage:
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
import { store } from '@telemetryos/root-sdk';
|
|
139
|
+
|
|
140
|
+
// Global scope - shared across all instances of your app
|
|
141
|
+
await store().global.set('systemConfig', { theme: 'dark', language: 'en' });
|
|
142
|
+
|
|
143
|
+
// Local scope - specific to this app instance
|
|
144
|
+
await store().local.set('currentChannel', 'HBO');
|
|
145
|
+
|
|
146
|
+
// DeviceLocal scope - stays on this device only
|
|
147
|
+
await store().deviceLocal.set('hardwareConfig', { audioLevel: 0.8 });
|
|
148
|
+
|
|
149
|
+
// Shared scope - communicate with other applications
|
|
150
|
+
await store().shared.set('system-status', 'currentMode', 'interactive');
|
|
151
|
+
|
|
152
|
+
// Subscribe to changes for real-time updates
|
|
153
|
+
const channelHandler = (newChannel) => {
|
|
154
|
+
console.log(`Channel updated to: ${newChannel}`);
|
|
155
|
+
switchToChannel(newChannel);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
store().local.subscribe('currentChannel', channelHandler);
|
|
159
|
+
|
|
160
|
+
// Clean up subscriptions when no longer needed
|
|
161
|
+
store().local.unsubscribe('currentChannel', channelHandler);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Store subscriptions are essential for real-time applications. When a setting is changed (e.g., in the settings mount point), the render mount point will receive immediate updates through store subscriptions.
|
|
165
|
+
|
|
166
|
+
### Application Discovery
|
|
167
|
+
|
|
168
|
+
Applications can discover and embed other applications:
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import { applications } from '@telemetryos/root-sdk';
|
|
172
|
+
|
|
173
|
+
// Find all applications with a specific mount point
|
|
174
|
+
const widgets = await applications().getAllByMountPoint('dashboard-widget');
|
|
175
|
+
|
|
176
|
+
// Get URL for embedding an application
|
|
177
|
+
const url = await applications().getUrl('weather-app', 'render');
|
|
178
|
+
|
|
179
|
+
// Use this URL in an iframe to embed the application
|
|
180
|
+
const iframe = document.createElement('iframe');
|
|
181
|
+
iframe.src = url;
|
|
182
|
+
document.body.appendChild(iframe);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Media Access
|
|
186
|
+
|
|
187
|
+
Access media content uploaded to TelemetryOS:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
import { media } from '@telemetryos/root-sdk';
|
|
191
|
+
|
|
192
|
+
// Get media folders by tag
|
|
193
|
+
const folders = await media().getFoldersByTag('marketing');
|
|
194
|
+
|
|
195
|
+
// Get content from a folder
|
|
196
|
+
const content = await media().getMediaContentByFolderId(folderId);
|
|
197
|
+
|
|
198
|
+
// Access the media file URLs
|
|
199
|
+
const mediaItem = await media().getMediaContentById(mediaId);
|
|
200
|
+
|
|
201
|
+
// Use this URL to display/play the media
|
|
202
|
+
const publicUrl = mediaItem.publicUrls[0];
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Account and User Information
|
|
206
|
+
|
|
207
|
+
Access information about the current account and user:
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
import { accounts, users } from '@telemetryos/root-sdk';
|
|
211
|
+
|
|
212
|
+
// Get current account
|
|
213
|
+
const account = await accounts().getCurrent();
|
|
214
|
+
|
|
215
|
+
// Get current user
|
|
216
|
+
const userResult = await users().getCurrent();
|
|
217
|
+
const userId = userResult.user.id;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Communication Patterns
|
|
221
|
+
|
|
222
|
+
The SDK uses a request-response pattern for most operations. All requests have a 30-second timeout by default to prevent hanging promises:
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
try {
|
|
226
|
+
const result = await someAsyncSdkOperation();
|
|
227
|
+
// Handle successful result
|
|
228
|
+
} catch (error) {
|
|
229
|
+
// Handle timeout or other errors
|
|
230
|
+
console.error('Operation failed:', error.message);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Offline Support
|
|
235
|
+
|
|
236
|
+
Your applications automatically work offline without any additional code. TelemetryOS handles caching for you:
|
|
237
|
+
|
|
238
|
+
- **Applications are cached locally** on devices for offline operation
|
|
239
|
+
- **Store system works offline** - all data reads and writes continue normally, syncing when back online
|
|
240
|
+
- **External API calls are cached** - HTTP requests to external services work offline using cached responses
|
|
241
|
+
- **No configuration needed** - offline support is completely automatic
|
|
242
|
+
|
|
243
|
+
This means users can interact with your application even when devices lose internet connectivity.
|
|
244
|
+
|
|
245
|
+
## Advanced Features
|
|
246
|
+
|
|
247
|
+
### Worker Scripts
|
|
248
|
+
|
|
249
|
+
Worker scripts run in the background continuously for root applications. On devices, they start when your root application is assigned and run until it's replaced. In the administration UI, they start when the page loads for any enabled root applications. Define them in your `telemetry.config.json`:
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"name": "my-application",
|
|
254
|
+
"version": "1.0.0",
|
|
255
|
+
"workers": [
|
|
256
|
+
{
|
|
257
|
+
"script": "./workers/background-sync.js"
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Worker scripts can access the SDK by importing and configuring it just like the main application. They're ideal for:
|
|
264
|
+
|
|
265
|
+
- Periodic data synchronization.
|
|
266
|
+
- Processing background tasks.
|
|
267
|
+
- Maintaining real-time connections.
|
|
268
|
+
- Updating shared state even when the main app is not in view.
|
|
269
|
+
|
|
270
|
+
### Containers
|
|
271
|
+
|
|
272
|
+
Containers allow you to run more complex backend services alongside your application. They run in a local Docker instance, with traffic to specific hostnames automatically tunneled to the appropriate container.
|
|
273
|
+
|
|
274
|
+
Define containers in your `telemetry.config.json`:
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"name": "my-application",
|
|
279
|
+
"version": "1.0.0",
|
|
280
|
+
"containers": [
|
|
281
|
+
{
|
|
282
|
+
"name": "my-backend",
|
|
283
|
+
"image": "mybackend:latest",
|
|
284
|
+
"port": 3000
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Access the container from your application (containers only run on devices):
|
|
291
|
+
|
|
292
|
+
```javascript
|
|
293
|
+
// Container name becomes hostname - requests to my-backend are routed to your container
|
|
294
|
+
fetch('https://my-backend/api/data')
|
|
295
|
+
.then(response => response.json())
|
|
296
|
+
.then(data => console.log(data));
|
|
297
|
+
|
|
298
|
+
// Your app should handle cases where containers aren't available (e.g., in administration UI)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## `telemetry.config.json` Configuration
|
|
302
|
+
|
|
303
|
+
Your application must include a `telemetry.config.json` file at the root level:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"name": "my-application",
|
|
308
|
+
"version": "1.0.0",
|
|
309
|
+
"displayName": "My Application",
|
|
310
|
+
"description": "A TelemetryOS application that does amazing things",
|
|
311
|
+
"mountPoints": {
|
|
312
|
+
"render": {
|
|
313
|
+
"path": "/render"
|
|
314
|
+
},
|
|
315
|
+
"settings": {
|
|
316
|
+
"path": "/settings"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
"workers": [
|
|
320
|
+
{
|
|
321
|
+
"name": "background",
|
|
322
|
+
"script": "./workers/background.js"
|
|
323
|
+
}
|
|
324
|
+
],
|
|
325
|
+
"containers": []
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
This configuration:
|
|
330
|
+
|
|
331
|
+
1. Defines your application name and metadata
|
|
332
|
+
2. Specifies mount points for different application contexts
|
|
333
|
+
3. Configures background workers
|
|
334
|
+
4. Sets up containers if needed
|
|
335
|
+
|
|
336
|
+
## Best Practices
|
|
337
|
+
|
|
338
|
+
1. **Store Usage**
|
|
339
|
+
- Use the appropriate store scope for your data
|
|
340
|
+
- Always subscribe to changes for real-time updates rather than polling
|
|
341
|
+
- Consider data persistence requirements when choosing a scope
|
|
342
|
+
|
|
343
|
+
2. **Application Structure**
|
|
344
|
+
- Clearly separate your settings UI from your render UI using mount points
|
|
345
|
+
- Handle settings changes gracefully in the render view
|
|
346
|
+
- Consider using a state management library with the SDK for complex applications
|
|
347
|
+
|
|
348
|
+
3. **Performance**
|
|
349
|
+
- Optimize your application for performance on TelemetryOS
|
|
350
|
+
- Use worker scripts for background tasks and to maintain state during playlist transitions
|
|
351
|
+
- Implement efficient rendering patterns to minimize resource usage
|
|
352
|
+
|
|
353
|
+
4. **Error Handling**
|
|
354
|
+
- Implement robust error handling for all SDK operations
|
|
355
|
+
- Account for timeout scenarios (30-second default)
|
|
356
|
+
- Provide fallback content when network operations fail
|
|
357
|
+
|
|
358
|
+
5. **Responsive Design**
|
|
359
|
+
- Design your application to adapt to different screen sizes and orientations
|
|
360
|
+
- Test your application on different device types
|
|
361
|
+
- Consider touch interaction for kiosk deployments
|
|
362
|
+
|
|
363
|
+
## Development Workflow
|
|
364
|
+
|
|
365
|
+
1. Develop and test your application locally
|
|
366
|
+
2. Package your application with its config file
|
|
367
|
+
3. Upload to TelemetryOS
|
|
368
|
+
4. Enable your root application in account settings
|
|
369
|
+
5. Assign your root application to specific devices in the devices list view
|
|
370
|
+
|
|
371
|
+
## Implementation Patterns and Examples
|
|
372
|
+
|
|
373
|
+
This section provides structured examples of common implementation patterns to help you build effective TelemetryOS applications.
|
|
374
|
+
|
|
375
|
+
### SDK Architecture Overview
|
|
376
|
+
|
|
377
|
+
- **Core Communication**: The SDK uses the `postMessage` API for communication with TelemetryOS.
|
|
378
|
+
- **Message Flow**: Messages flow between applications and TelemetryOS via the parent window.
|
|
379
|
+
- **Resource APIs**: Domain-specific APIs (store, media, applications, etc.) are built on top of the core messaging APIs.
|
|
380
|
+
- **Configuration Flow**: Applications must call `configure()` before using any SDK features.
|
|
381
|
+
|
|
382
|
+
### Common Implementation Patterns
|
|
383
|
+
|
|
384
|
+
#### 1. Fetching and Displaying Media
|
|
385
|
+
|
|
386
|
+
```javascript
|
|
387
|
+
import { media } from '@telemetryos/root-sdk';
|
|
388
|
+
|
|
389
|
+
async function displayMedia(mediaId) {
|
|
390
|
+
const mediaItem = await media().getMediaContentById(mediaId);
|
|
391
|
+
const mediaElement = document.createElement('img');
|
|
392
|
+
mediaElement.src = mediaItem.publicUrls[0];
|
|
393
|
+
document.body.appendChild(mediaElement);
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
#### 2. Settings Communication Between Mount Points
|
|
398
|
+
|
|
399
|
+
```javascript
|
|
400
|
+
import { store } from '@telemetryos/root-sdk';
|
|
401
|
+
|
|
402
|
+
// In settings mount point
|
|
403
|
+
async function saveSettings(city) {
|
|
404
|
+
await store().local.set('city', city);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// In render mount point
|
|
408
|
+
function setupSettingsListener() {
|
|
409
|
+
store().local.subscribe('city', (city) => {
|
|
410
|
+
updateWeatherDisplay(city);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Initial load
|
|
414
|
+
store().local.get('city').then(city => {
|
|
415
|
+
if (city) updateWeatherDisplay(city);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
#### 3. Embedding Another Application
|
|
421
|
+
|
|
422
|
+
```javascript
|
|
423
|
+
import { applications } from '@telemetryos/root-sdk';
|
|
424
|
+
|
|
425
|
+
async function embedWeatherWidget(containerId) {
|
|
426
|
+
const url = await applications().getUrl('weather-app', 'render');
|
|
427
|
+
const container = document.getElementById(containerId);
|
|
428
|
+
|
|
429
|
+
const iframe = document.createElement('iframe');
|
|
430
|
+
iframe.src = url;
|
|
431
|
+
iframe.style.border = 'none';
|
|
432
|
+
iframe.style.width = '100%';
|
|
433
|
+
iframe.style.height = '100%';
|
|
434
|
+
|
|
435
|
+
container.appendChild(iframe);
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
#### 4. Implementing a Background Worker
|
|
440
|
+
|
|
441
|
+
```javascript
|
|
442
|
+
// In worker.js - defined in telemetry.config.json
|
|
443
|
+
import { configure, store } from '@telemetryos/root-sdk';
|
|
444
|
+
|
|
445
|
+
configure('myApp');
|
|
446
|
+
|
|
447
|
+
// Run periodic synchronization
|
|
448
|
+
async function syncData() {
|
|
449
|
+
try {
|
|
450
|
+
const data = await fetchExternalData();
|
|
451
|
+
await store().global.set('latestData', data);
|
|
452
|
+
} catch (error) {
|
|
453
|
+
console.error('Sync failed:', error);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Schedule next sync
|
|
457
|
+
setTimeout(syncData, 60000);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Start sync process
|
|
461
|
+
syncData();
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
#### 5. Robust Error Handling
|
|
465
|
+
|
|
466
|
+
Always implement proper error handling for SDK operations:
|
|
467
|
+
|
|
468
|
+
```javascript
|
|
469
|
+
try {
|
|
470
|
+
const result = await media().getFoldersByTag('marketing');
|
|
471
|
+
displayFolders(result);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
// Check for timeout errors
|
|
474
|
+
if (error.message.includes('timed out')) {
|
|
475
|
+
showTimeoutMessage();
|
|
476
|
+
} else {
|
|
477
|
+
showGenericError();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Provide fallback content or retry strategy
|
|
481
|
+
displayCachedContent();
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Complete Application Examples
|
|
486
|
+
|
|
487
|
+
#### Weather Application
|
|
488
|
+
|
|
489
|
+
```javascript
|
|
490
|
+
// In settings.js (settings mount point)
|
|
491
|
+
import { configure, store } from '@telemetryos/root-sdk';
|
|
492
|
+
|
|
493
|
+
configure('weather-app');
|
|
494
|
+
|
|
495
|
+
document.getElementById('cityForm').addEventListener('submit', async (e) => {
|
|
496
|
+
e.preventDefault();
|
|
497
|
+
const city = document.getElementById('cityInput').value;
|
|
498
|
+
await store().local.set('city', city);
|
|
499
|
+
showSuccessMessage('City saved successfully');
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// Initial load of current value
|
|
503
|
+
store().local.get('city').then(city => {
|
|
504
|
+
if (city) {
|
|
505
|
+
document.getElementById('cityInput').value = city;
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
```javascript
|
|
511
|
+
// In render.js (render mount point)
|
|
512
|
+
import { configure, store } from '@telemetryos/root-sdk';
|
|
513
|
+
|
|
514
|
+
configure('weather-app');
|
|
515
|
+
|
|
516
|
+
// Subscribe to city changes
|
|
517
|
+
store().local.subscribe('city', (city) => {
|
|
518
|
+
if (city) {
|
|
519
|
+
fetchAndDisplayWeather(city);
|
|
520
|
+
} else {
|
|
521
|
+
showConfigurationMessage();
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// Initial load
|
|
526
|
+
store().local.get('city').then(city => {
|
|
527
|
+
if (city) {
|
|
528
|
+
fetchAndDisplayWeather(city);
|
|
529
|
+
} else {
|
|
530
|
+
showConfigurationMessage();
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
async function fetchAndDisplayWeather(city) {
|
|
535
|
+
try {
|
|
536
|
+
const weather = await fetchWeatherData(city);
|
|
537
|
+
renderWeatherUI(weather);
|
|
538
|
+
} catch (error) {
|
|
539
|
+
showErrorMessage('Could not load weather data');
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### Dashboard Container Application
|
|
545
|
+
|
|
546
|
+
```javascript
|
|
547
|
+
import { configure, applications } from '@telemetryos/root-sdk';
|
|
548
|
+
|
|
549
|
+
configure('dashboard-app');
|
|
550
|
+
|
|
551
|
+
async function initializeDashboard() {
|
|
552
|
+
try {
|
|
553
|
+
// Discover all dashboard widget applications
|
|
554
|
+
const widgets = await applications().getAllByMountPoint('dashboard-widget');
|
|
555
|
+
|
|
556
|
+
if (widgets.length === 0) {
|
|
557
|
+
showNoWidgetsMessage();
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const container = document.getElementById('widgetsContainer');
|
|
562
|
+
|
|
563
|
+
// Create a grid layout for widgets
|
|
564
|
+
for (const widget of widgets) {
|
|
565
|
+
const widgetElement = document.createElement('div');
|
|
566
|
+
widgetElement.className = 'widget-container';
|
|
567
|
+
|
|
568
|
+
// Get embeddable URL for this widget
|
|
569
|
+
const url = await applications().getUrl(widget.name, 'dashboard-widget');
|
|
570
|
+
|
|
571
|
+
// Create and configure iframe
|
|
572
|
+
const iframe = document.createElement('iframe');
|
|
573
|
+
iframe.src = url;
|
|
574
|
+
iframe.title = widget.name;
|
|
575
|
+
iframe.frameBorder = '0';
|
|
576
|
+
iframe.style.width = '100%';
|
|
577
|
+
iframe.style.height = '100%';
|
|
578
|
+
|
|
579
|
+
widgetElement.appendChild(iframe);
|
|
580
|
+
container.appendChild(widgetElement);
|
|
581
|
+
}
|
|
582
|
+
} catch (error) {
|
|
583
|
+
console.error('Failed to initialize dashboard:', error);
|
|
584
|
+
showErrorMessage();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Initialize dashboard when DOM is ready
|
|
589
|
+
document.addEventListener('DOMContentLoaded', initializeDashboard);
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
## Support and Resources
|
|
593
|
+
|
|
594
|
+
For more information or support, please visit our documentation or contact our support team.
|
|
595
|
+
|
|
596
|
+
Happy building!
|
|
597
|
+
|
|
598
|
+
[admin-ui]: https://app.telemetryos.ai
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Client } from './index.js';
|
|
2
|
+
type CurrentAccount = {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class Accounts {
|
|
6
|
+
_client: Client;
|
|
7
|
+
constructor(client: Client);
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves information about the account associated with the current session.
|
|
10
|
+
*
|
|
11
|
+
* This method allows an application to get details about the TelemetryOS account
|
|
12
|
+
* in which it is currently running.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise that resolves to the current account object
|
|
15
|
+
*/
|
|
16
|
+
getCurrent(): Promise<CurrentAccount>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Client } from './client.js';
|
|
2
|
+
export type MountPoint = {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
export type Application = {
|
|
7
|
+
name: string;
|
|
8
|
+
mountPoints: Record<string, MountPoint>;
|
|
9
|
+
};
|
|
10
|
+
export type GetUrlResult = {
|
|
11
|
+
url: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class Applications {
|
|
14
|
+
_client: Client;
|
|
15
|
+
constructor(client: Client);
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves all applications with a specific mount point within the current account.
|
|
18
|
+
*
|
|
19
|
+
* This method allows applications that host other applications to discover compatible
|
|
20
|
+
* applications that can be embedded. For example, a dashboard application might search
|
|
21
|
+
* for all applications that have a 'dashboard-widget' mount point.
|
|
22
|
+
*
|
|
23
|
+
* The results are scoped to the current account, so only applications associated with
|
|
24
|
+
* the same account will be returned.
|
|
25
|
+
*
|
|
26
|
+
* @param mountPoint The mount point identifier to search for
|
|
27
|
+
* @returns A promise that resolves to an array of applications having the specified mount point
|
|
28
|
+
*/
|
|
29
|
+
getAllByMountPoint(mountPoint: string): Promise<Application[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves an application by its name.
|
|
32
|
+
*
|
|
33
|
+
* This method allows finding a specific application when you know its name. It's useful
|
|
34
|
+
* when you need to check if a particular application is available or get its details
|
|
35
|
+
* before attempting to embed it.
|
|
36
|
+
*
|
|
37
|
+
* @param name The name of the application to query for
|
|
38
|
+
* @returns A promise that resolves to the application object if found, or null if not found
|
|
39
|
+
*/
|
|
40
|
+
getByName(name: string): Promise<Application | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Generates a URL for embedding an application with the specified name and mount point.
|
|
43
|
+
*
|
|
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.
|
|
47
|
+
*
|
|
48
|
+
* Only applications that are associated with the current account can be retrieved.
|
|
49
|
+
*
|
|
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
|
|
53
|
+
*/
|
|
54
|
+
getUrl(name: string, mountPoint: string): Promise<string>;
|
|
55
|
+
}
|
package/dist/bridge.cjs
ADDED
|
@@ -0,0 +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;
|