@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/dist/index.js ADDED
@@ -0,0 +1,833 @@
1
+ import { z as S } from "./index-B98VDFRY.js";
2
+ const M = "1.0.0", q = {
3
+ version: M
4
+ };
5
+ class B {
6
+ constructor(e) {
7
+ this._client = e;
8
+ }
9
+ /**
10
+ * Retrieves information about the account associated with the current session.
11
+ *
12
+ * This method allows an application to get details about the TelemetryOS account
13
+ * in which it is currently running.
14
+ *
15
+ * @returns A promise that resolves to the current account object
16
+ */
17
+ async getCurrent() {
18
+ return (await this._client.request("user.getCurrentAccount", {})).account;
19
+ }
20
+ }
21
+ class P {
22
+ constructor(e) {
23
+ this._client = e;
24
+ }
25
+ /**
26
+ * Retrieves all applications with a specific mount point within the current account.
27
+ *
28
+ * This method allows applications that host other applications to discover compatible
29
+ * applications that can be embedded. For example, a dashboard application might search
30
+ * for all applications that have a 'dashboard-widget' mount point.
31
+ *
32
+ * The results are scoped to the current account, so only applications associated with
33
+ * the same account will be returned.
34
+ *
35
+ * @param mountPoint The mount point identifier to search for
36
+ * @returns A promise that resolves to an array of applications having the specified mount point
37
+ */
38
+ async getAllByMountPoint(e) {
39
+ return (await this._client.request("applications.getByMountPoint", {
40
+ mountPoint: e
41
+ })).applications;
42
+ }
43
+ /**
44
+ * Retrieves an application by its name.
45
+ *
46
+ * This method allows finding a specific application when you know its name. It's useful
47
+ * when you need to check if a particular application is available or get its details
48
+ * before attempting to embed it.
49
+ *
50
+ * @param name The name of the application to query for
51
+ * @returns A promise that resolves to the application object if found, or null if not found
52
+ */
53
+ async getByName(e) {
54
+ return (await this._client.request("applications.getByName", {
55
+ name: e
56
+ })).application;
57
+ }
58
+ /**
59
+ * Generates a URL for embedding an application with the specified name and mount point.
60
+ *
61
+ * This method returns a URL that can be used in an iframe src attribute to embed
62
+ * the application. The URL includes necessary parameters for the application to
63
+ * understand its context and communicate with the platform.
64
+ *
65
+ * Only applications that are associated with the current account can be retrieved.
66
+ *
67
+ * @param name The name of the application to get the URL for
68
+ * @param mountPoint The mount point to use when embedding the application
69
+ * @returns A promise that resolves to the URL string for embedding the application
70
+ */
71
+ async getUrl(e, t) {
72
+ return (await this._client.request("applications.getUrl", {
73
+ name: e,
74
+ mountPoint: t
75
+ })).url;
76
+ }
77
+ }
78
+ function C(r, e = console.error) {
79
+ r().catch(e);
80
+ }
81
+ class R {
82
+ constructor(e) {
83
+ this._client = e;
84
+ }
85
+ async getColorScheme() {
86
+ return (await this._client.request("environment.getColorScheme", {})).colorScheme;
87
+ }
88
+ subscribeColorScheme(e) {
89
+ C(async () => {
90
+ this._client.on("environment.colorSchemeChanged", e), e(await this.getColorScheme());
91
+ });
92
+ }
93
+ unsubscribeColorScheme(e) {
94
+ this._client.off("environment.colorSchemeChanged", e);
95
+ }
96
+ }
97
+ class I {
98
+ constructor(e) {
99
+ this._client = e;
100
+ }
101
+ /**
102
+ * Queries for media folders based on folder properties.
103
+ *
104
+ * This method allows you to search for media folders that match specific criteria,
105
+ * such as name, ID, or other folder properties.
106
+ *
107
+ * @param query An object with partial MediaFolder properties to match against
108
+ * @returns A promise that resolves to an array of matching media folders
109
+ */
110
+ async queryFolders(e) {
111
+ return (await this._client.request("media.queryMediaFolders", {
112
+ query: e
113
+ })).folders;
114
+ }
115
+ /**
116
+ * Retrieves media folders that have been tagged with a specific tag.
117
+ *
118
+ * @param tagName The name of the tag to search for
119
+ * @returns A promise that resolves to an array of media folders with the specified tag
120
+ */
121
+ async getFoldersByTag(e) {
122
+ return (await this._client.request("media.getMediaFoldersByTag", {
123
+ tagName: e
124
+ })).folders;
125
+ }
126
+ /**
127
+ * Retrieves a specific media folder by its ID.
128
+ *
129
+ * @param id The unique identifier of the folder to retrieve
130
+ * @returns A promise that resolves to the media folder with the specified ID
131
+ */
132
+ async getFolderById(e) {
133
+ return (await this._client.request("media.getMediaFolderById", {
134
+ id: e
135
+ })).folder;
136
+ }
137
+ /**
138
+ * Retrieves all media content items within a specific folder.
139
+ *
140
+ * @param folderId The unique identifier of the folder to get content from
141
+ * @returns A promise that resolves to an array of media content items in the folder
142
+ */
143
+ async getMediaContentByFolderId(e) {
144
+ return (await this._client.request("media.getMediaContentByFolderId", {
145
+ folderId: e
146
+ })).folders;
147
+ }
148
+ /**
149
+ * Retrieves a specific media content item by its ID.
150
+ *
151
+ * @param id The unique identifier of the media content to retrieve
152
+ * @returns A promise that resolves to the media content item with the specified ID
153
+ */
154
+ async getMediaContentById(e) {
155
+ return (await this._client.request("media.getMediaContentById", {
156
+ id: e
157
+ })).content;
158
+ }
159
+ }
160
+ class k {
161
+ constructor(e) {
162
+ this._client = e;
163
+ }
164
+ /**
165
+ * Provides access to the application store scope.
166
+ *
167
+ * Data stored in the application scope is shared across all instances of your application
168
+ * within the current account. Use this scope for application-wide settings, shared resources,
169
+ * or any data that should be consistent across all instances.
170
+ *
171
+ * @returns A StoreSlice instance for the application scope
172
+ */
173
+ get application() {
174
+ return new w("application", "", this._client);
175
+ }
176
+ /**
177
+ * Provides access to the instance store scope.
178
+ *
179
+ * Data stored in the instance scope is only available to the current instance of your
180
+ * application. This is ideal for instance-specific settings, UI state, temporary data,
181
+ * or any information that shouldn't be shared with other instances.
182
+ *
183
+ * The namespace for instance data includes both the application name and the instance ID.
184
+ *
185
+ * @returns A StoreSlice instance for the instance scope
186
+ */
187
+ get instance() {
188
+ return new w("instance", this._client._applicationId, this._client);
189
+ }
190
+ /**
191
+ * Provides access to the device store scope.
192
+ *
193
+ * Data stored in the device scope is only available to the application on the
194
+ * current physical device. This is useful for device-specific settings, caching, or
195
+ * any data that should persist across application instances but only on a single device.
196
+ *
197
+ * Note: This scope cannot be used for Settings-related mount points as the User
198
+ * Administration UI does not run on a device.
199
+ *
200
+ * @returns A StoreSlice instance for the device scope
201
+ */
202
+ get device() {
203
+ return new w("device", this._client._applicationId, this._client);
204
+ }
205
+ /**
206
+ * Provides access to the shared store scope with a specified namespace.
207
+ *
208
+ * The shared scope enables data sharing between different applications within the
209
+ * same account. By specifying a common namespace, any two applications can exchange
210
+ * data and communicate with each other.
211
+ *
212
+ * This is particularly useful for application ecosystems where multiple applications
213
+ * need to coordinate or share configuration.
214
+ *
215
+ * @param namespace A string identifier for the shared data space
216
+ * @returns A StoreSlice instance for the specified shared namespace
217
+ */
218
+ shared(e) {
219
+ return new w("shared", e, this._client);
220
+ }
221
+ }
222
+ class w {
223
+ constructor(e, t, s) {
224
+ this._kind = e, this._namespace = t, this._client = s;
225
+ }
226
+ /**
227
+ * Saves a value in the store.
228
+ *
229
+ * This method stores data under the specified key within the current store scope and namespace.
230
+ * The value must be serializable (can be converted to JSON). Complex objects like Date instances
231
+ * will be serialized and deserialize as regular objects, losing their prototype methods.
232
+ *
233
+ * @param key The key to save the value under
234
+ * @param value The value to store - must be JSON serializable
235
+ * @returns A promise that resolves to true if the value was saved successfully
236
+ */
237
+ async set(e, t) {
238
+ return (await this._client.request("store.set", {
239
+ kind: this._kind,
240
+ namespace: this._namespace,
241
+ key: e,
242
+ value: t
243
+ })).success;
244
+ }
245
+ /**
246
+ * Retrieves a value from the store.
247
+ *
248
+ * This method fetches data stored under the specified key within the current store scope
249
+ * and namespace. For real-time applications that need to respond to changes, consider
250
+ * using subscribe() instead.
251
+ *
252
+ * @template T The expected type of the stored value
253
+ * @param key The key to retrieve the value for
254
+ * @returns A promise that resolves to the stored value, or undefined if the key does not exist
255
+ */
256
+ async get(e) {
257
+ return (await this._client.request("store.get", {
258
+ kind: this._kind,
259
+ namespace: this._namespace,
260
+ key: e
261
+ })).value;
262
+ }
263
+ /**
264
+ * Subscribes to changes in the store for a specific key.
265
+ *
266
+ * This method sets up a subscription that will call the provided handler whenever
267
+ * the value associated with the specified key changes. This is the recommended way
268
+ * to access store data in long-running applications that need to stay responsive
269
+ * to data changes.
270
+ *
271
+ * @param key The key to subscribe to
272
+ * @param handler The callback function to call when the value changes
273
+ * @returns A promise that resolves to true if the subscription was successful
274
+ */
275
+ async subscribe(e, t) {
276
+ return (await this._client.subscribe("store.subscribe", {
277
+ kind: this._kind,
278
+ namespace: this._namespace,
279
+ key: e
280
+ }, t)).success;
281
+ }
282
+ /**
283
+ * Unsubscribes from changes in the store for a specific key.
284
+ *
285
+ * This method removes a subscription previously created with subscribe(). It can
286
+ * either remove a specific handler or all handlers for the given key.
287
+ *
288
+ * @param key The key to unsubscribe from
289
+ * @param handler Optional. The specific handler to remove. If not provided, all handlers for this key will be removed.
290
+ * @returns A promise that resolves to true if the unsubscription was successful
291
+ */
292
+ async unsubscribe(e, t) {
293
+ return (await this._client.unsubscribe("store.unsubscribe", {
294
+ kind: this._kind,
295
+ namespace: this._namespace,
296
+ key: e
297
+ }, t)).success;
298
+ }
299
+ /**
300
+ * Deletes a value from the store.
301
+ *
302
+ * This method removes the data stored under the specified key within the
303
+ * current store scope and namespace.
304
+ *
305
+ * @param key The key to delete
306
+ * @returns A promise that resolves to true if the value was deleted successfully
307
+ */
308
+ async delete(e) {
309
+ return (await this._client.request("store.delete", {
310
+ kind: this._kind,
311
+ namespace: this._namespace,
312
+ key: e
313
+ })).success;
314
+ }
315
+ }
316
+ class E {
317
+ constructor(e) {
318
+ this._client = e;
319
+ }
320
+ /**
321
+ * Retrieves information about the user associated with the current session.
322
+ *
323
+ * This method allows an application to get details about the TelemetryOS user
324
+ * who is currently using the application.
325
+ *
326
+ * @returns A promise that resolves to the current user result object
327
+ * @example
328
+ * // Get the current user information
329
+ * const userResult = await users.getCurrent();
330
+ * console.log(`Current user ID: ${userResult.user.id}`);
331
+ */
332
+ async getCurrent() {
333
+ return await this._client.request("user.getCurrentUser", {});
334
+ }
335
+ }
336
+ const $ = S.object({
337
+ name: S.string(),
338
+ data: S.any()
339
+ });
340
+ class A {
341
+ /**
342
+ * Creates a new RootSettingsNavigation API instance.
343
+ *
344
+ * @param store The Store instance to use for persistence
345
+ * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
346
+ */
347
+ constructor(e) {
348
+ if (e._client._applicationId !== "rootSettingsNavigation")
349
+ throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");
350
+ this._store = e;
351
+ }
352
+ /**
353
+ * Registers navigation entries for the root application in the TelemetryOS admin UI.
354
+ *
355
+ * This method allows a root application to define its sidebar navigation structure
356
+ * within the TelemetryOS administration UI. The navigation entries will appear in the
357
+ * sidebar menu, allowing users to navigate to different sections of the application.
358
+ *
359
+ * @param navigation An object containing the navigation entries to register
360
+ * @returns A promise that resolves when the navigation has been registered
361
+ */
362
+ async setRootSettingsNavigation(e) {
363
+ const t = this._store.shared("root-settings-navigation"), s = await t.get("navigation"), o = this._store._client._applicationId;
364
+ s[o] = {
365
+ applicationId: o,
366
+ entries: e.entries
367
+ }, t.set("navigation", s);
368
+ }
369
+ /**
370
+ * Retrieves the current navigation entries for this root application.
371
+ *
372
+ * This method returns the navigation structure that was previously registered
373
+ * for this application using setRootSettingsNavigation().
374
+ *
375
+ * @returns A promise that resolves to the navigation state for this application
376
+ */
377
+ async getRootSettingsNavigation() {
378
+ const t = await this._store.shared("root-settings-navigation").get("navigation"), s = this._store._client._applicationId;
379
+ return t[s];
380
+ }
381
+ /**
382
+ * Retrieves the navigation entries for all root applications.
383
+ *
384
+ * This method returns the navigation structures for all root applications registered
385
+ * in the TelemetryOS administration UI. This can be useful for coordination between
386
+ * different root applications.
387
+ *
388
+ * @returns A promise that resolves to the navigation state for all applications
389
+ */
390
+ async getAllRootSettingsNavigation() {
391
+ return this._store.shared("root-settings-navigation").get("navigation");
392
+ }
393
+ }
394
+ const m = 1e3 * 30;
395
+ class T {
396
+ /**
397
+ * Creates a new Client instance for communicating with the TelemetryOS platform.
398
+ *
399
+ * Note that creating a Client instance alone is not sufficient to begin communication.
400
+ * You must also call the bind() method to initialize event listeners and extract
401
+ * the application ID from the URL.
402
+ *
403
+ * @param applicationName The name of your application - must match the 'name' property
404
+ * in your application's telemetry.config.json file
405
+ */
406
+ constructor(e) {
407
+ this._applicationName = e, this._applicationId = "", this._onHandlers = /* @__PURE__ */ new Map(), this._onceHandlers = /* @__PURE__ */ new Map(), this._subscriptionNamesByHandler = /* @__PURE__ */ new Map(), this._subscriptionNamesBySubjectName = /* @__PURE__ */ new Map();
408
+ }
409
+ /**
410
+ * Provides access to the accounts API for retrieving TelemetryOS account information.
411
+ *
412
+ * This property returns a new Accounts instance that allows querying information
413
+ * about the current TelemetryOS account.
414
+ *
415
+ * NOTE: Most application developers should use the global accounts() function
416
+ * instead of accessing this property directly.
417
+ *
418
+ * @returns An Accounts instance bound to this client
419
+ */
420
+ get accounts() {
421
+ return new B(this);
422
+ }
423
+ /**
424
+ * Provides access to the users API for retrieving TelemetryOS user information.
425
+ *
426
+ * This property returns a new Users instance that allows querying information
427
+ * about the current TelemetryOS user.
428
+ *
429
+ * NOTE: Most application developers should use the global users() function
430
+ * instead of accessing this property directly.
431
+ *
432
+ * @returns A Users instance bound to this client
433
+ */
434
+ get users() {
435
+ return new E(this);
436
+ }
437
+ /**
438
+ * Provides access to the store API for data persistence with multiple storage scopes.
439
+ *
440
+ * This property returns a new Store instance that allows saving, retrieving, and
441
+ * subscribing to data changes across different scopes (global, local, deviceLocal, shared).
442
+ *
443
+ * NOTE: Most application developers should use the global store() function
444
+ * instead of accessing this property directly.
445
+ *
446
+ * @returns A Store instance bound to this client
447
+ */
448
+ get store() {
449
+ return new k(this);
450
+ }
451
+ /**
452
+ * Provides access to the applications API for discovering and embedding other TelemetryOS applications.
453
+ *
454
+ * This property returns a new Applications instance that allows querying for applications
455
+ * by name or mount point, and generating URLs for embedding applications in iframes.
456
+ *
457
+ * NOTE: Most application developers should use the global applications() function
458
+ * instead of accessing this property directly.
459
+ *
460
+ * @returns An Applications instance bound to this client
461
+ */
462
+ get applications() {
463
+ return new P(this);
464
+ }
465
+ /**
466
+ * Provides access to the media API for working with content hosted on the TelemetryOS platform.
467
+ *
468
+ * This property returns a new Media instance that allows applications to browse and access
469
+ * media content uploaded to TelemetryOS. Applications can query folders, retrieve content,
470
+ * and access media files.
471
+ *
472
+ * NOTE: Most application developers should use the global media() function
473
+ * instead of accessing this property directly.
474
+ *
475
+ * @returns A Media instance bound to this client
476
+ */
477
+ get media() {
478
+ return new I(this);
479
+ }
480
+ /**
481
+ * Provides access to the root settings navigation API for TelemetryOS administration UI integration.
482
+ *
483
+ * NOTE: This API is not intended for most application developers. It is specifically designed
484
+ * for root applications that need to integrate with the TelemetryOS administration UI.
485
+ *
486
+ * This property returns a new RootSettingsNavigation instance that allows root applications
487
+ * to register sidebar navigation entries in the TelemetryOS administration UI.
488
+ *
489
+ * Most root application developers should use the global rootSettingsNavigation() function
490
+ * instead of accessing this property directly.
491
+ *
492
+ * @returns A RootSettingsNavigation instance bound to this client
493
+ * @throws {Error} If used by an application not mounted at the 'rootSettingsNavigation' mount point
494
+ */
495
+ get rootSettingsNavigation() {
496
+ return new A(this.store);
497
+ }
498
+ /**
499
+ * Initializes the client by setting up message listeners and extracting the application ID.
500
+ *
501
+ * This method must be called after creating a Client instance and before using any
502
+ * of its communication methods. It performs two important tasks:
503
+ *
504
+ * 1. Sets up an event listener for window 'message' events to receive messages
505
+ * from the TelemetryOS platform
506
+ * 2. Extracts the application ID from the URL's query parameters
507
+ *
508
+ * The application ID is used by several APIs, including the store's local and deviceLocal scopes.
509
+ *
510
+ * NOTE: Most application developers should use the global configure() function instead
511
+ * of creating and binding their own Client instances.
512
+ */
513
+ bind() {
514
+ var e;
515
+ const t = new URL(window.location.href).searchParams;
516
+ this._applicationId = (e = t.get("telemetryApplicationId")) !== null && e !== void 0 ? e : "", this._windowMessageHandler = (s) => {
517
+ if (s.source === window)
518
+ return;
519
+ for (let a = 0; a < window.frames.length; a += 1)
520
+ window.frames[a].postMessage(s.data, "*");
521
+ const o = $.safeParse(s.data);
522
+ if (!o.success)
523
+ return;
524
+ const i = o.data, c = this._onHandlers.get(i.name), l = this._onceHandlers.get(i.name);
525
+ if (c)
526
+ for (const a of c)
527
+ a(i.data);
528
+ if (l) {
529
+ for (const a of l)
530
+ a(i.data);
531
+ this._onceHandlers.delete(i.name);
532
+ }
533
+ }, window.addEventListener("message", this._windowMessageHandler);
534
+ }
535
+ /**
536
+ * Removes the message event listener and cleans up resources.
537
+ *
538
+ * Call this method when you're done with the client to prevent memory leaks
539
+ * and ensure proper cleanup. After calling unbind(), the client will no longer
540
+ * receive messages from the TelemetryOS platform.
541
+ *
542
+ * Note that this does not cancel any active subscriptions or server-side resources.
543
+ * You should explicitly unsubscribe from any subscriptions before unbinding.
544
+ *
545
+ * NOTE: Most application developers should use the global destroy() function instead
546
+ * of managing their own Client instances.
547
+ */
548
+ unbind() {
549
+ this._windowMessageHandler && window.removeEventListener("message", this._windowMessageHandler);
550
+ }
551
+ /**
552
+ * Sends a one-way message to the TelemetryOS platform.
553
+ *
554
+ * Use this method for fire-and-forget messages where no response is expected.
555
+ * The message is sent to the parent window using the postMessage API and includes
556
+ * metadata such as the SDK version and application name.
557
+ *
558
+ * NOTE: Most application developers should use the resource-specific APIs or the global
559
+ * send() function instead of using this method directly.
560
+ *
561
+ * @param name The name of the message type to send
562
+ * @param data The data payload to include with the message
563
+ */
564
+ send(e, t) {
565
+ const s = {
566
+ telemetrySdkVersion: y,
567
+ applicationName: this._applicationName,
568
+ name: e,
569
+ data: t
570
+ };
571
+ window.parent.postMessage(s, "*");
572
+ }
573
+ /**
574
+ * Sends a message to the TelemetryOS platform and waits for a response.
575
+ *
576
+ * This method implements a request-response pattern over the postMessage API.
577
+ * It generates a unique correlation ID and sets up a listener for the response.
578
+ * If no response is received within the timeout period (30 seconds by default),
579
+ * the promise will reject.
580
+ *
581
+ * NOTE: Most application developers should use the resource-specific APIs or the global
582
+ * request() function instead of using this method directly.
583
+ *
584
+ * @template D The expected type of the response data
585
+ * @param name The name of the message type (endpoint) to request
586
+ * @param data The data payload to include with the request
587
+ * @returns A promise that resolves with the response data when received
588
+ * @throws {Error} If the request times out
589
+ */
590
+ request(e, t) {
591
+ const s = b(), o = {
592
+ telemetrySdkVersion: y,
593
+ applicationName: this._applicationName,
594
+ name: e,
595
+ data: t,
596
+ responseName: s
597
+ };
598
+ window.parent.postMessage(o, "*");
599
+ let i = !1, c;
600
+ const l = new Promise((h, d) => {
601
+ const p = new Error(`${e} message request with response name of ${s} timed out after ${m}`);
602
+ setTimeout(() => {
603
+ i = !0, this.off(s, c), d(p);
604
+ }, m);
605
+ }), a = new Promise((h) => {
606
+ c = (d) => {
607
+ i || h(d);
608
+ }, this.once(s, h);
609
+ });
610
+ return Promise.race([l, a]);
611
+ }
612
+ async subscribe(e, t, s) {
613
+ let o, i;
614
+ typeof t == "function" ? i = t : (o = t, i = s);
615
+ const c = b(), l = b();
616
+ let a = this._subscriptionNamesBySubjectName.get(e);
617
+ a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(c), this._subscriptionNamesByHandler.set(i, c), this.on(c, i);
618
+ const h = {
619
+ telemetrySdkVersion: y,
620
+ applicationName: this._applicationName,
621
+ name: e,
622
+ data: o,
623
+ responseName: l,
624
+ subscriptionName: c
625
+ };
626
+ window.parent.postMessage(h, "*");
627
+ let d = !1, p;
628
+ const N = new Promise((_, g) => {
629
+ const f = new Error(`${e} subscribe request with subscription name of ${c} and response name of ${l} timed out after ${m}`);
630
+ setTimeout(() => {
631
+ d = !0, this.off(l, p), g(f);
632
+ }, m);
633
+ }), v = new Promise((_) => {
634
+ p = (g) => {
635
+ d || _(g);
636
+ }, this.on(l, _);
637
+ });
638
+ return Promise.race([N, v]);
639
+ }
640
+ async unsubscribe(e, t, s) {
641
+ let o, i;
642
+ typeof t == "function" ? i = t : (o = t, i = s);
643
+ const c = b();
644
+ let l = [];
645
+ if (i) {
646
+ const a = this._subscriptionNamesByHandler.get(i);
647
+ if (!a)
648
+ return { success: !1 };
649
+ l = [a], this._subscriptionNamesByHandler.delete(i);
650
+ } else if (!this._subscriptionNamesBySubjectName.get(e))
651
+ return { success: !1 };
652
+ for await (const a of l) {
653
+ this.off(a, i);
654
+ const h = {
655
+ telemetrySdkVersion: y,
656
+ applicationName: this._applicationName,
657
+ name: e,
658
+ data: o,
659
+ responseName: c,
660
+ unsubscribeName: a
661
+ };
662
+ window.parent.postMessage(h, "*");
663
+ let d = !1, p;
664
+ const N = new Promise((g, f) => {
665
+ const H = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${c} timed out after ${m}`);
666
+ setTimeout(() => {
667
+ d = !0, this.off(c, p), f(H);
668
+ }, m);
669
+ }), v = new Promise((g) => {
670
+ p = (f) => {
671
+ d || g(f);
672
+ }, this.once(c, g);
673
+ });
674
+ if (!(await Promise.race([N, v])).success)
675
+ return { success: !1 };
676
+ }
677
+ return { success: !0 };
678
+ }
679
+ /**
680
+ * Registers a handler function for a specific message type.
681
+ *
682
+ * The handler will be called each time a message with the specified name is received.
683
+ * You can register multiple handlers for the same message type, and all will be executed
684
+ * when that message is received.
685
+ *
686
+ * Unlike subscribe(), this method only sets up a local event listener and doesn't
687
+ * notify the platform of your interest in a particular message type.
688
+ *
689
+ * NOTE: Most application developers should use the resource-specific APIs or the global
690
+ * on() function instead of using this method directly.
691
+ *
692
+ * @template T The expected type of the message data
693
+ * @param name The name of the message type to listen for
694
+ * @param handler The callback function to execute when messages are received
695
+ */
696
+ on(e, t) {
697
+ var s;
698
+ const o = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
699
+ o.length === 0 && this._onHandlers.set(e, o), o.push(t);
700
+ }
701
+ /**
702
+ * Registers a one-time handler for a specific message type.
703
+ *
704
+ * Similar to the on() method, but the handler will be automatically removed
705
+ * after it is called once. This is useful for initialization events or operations
706
+ * that should only happen once in response to a particular message.
707
+ *
708
+ * NOTE: Most application developers should use the resource-specific APIs or the global
709
+ * once() function instead of using this method directly.
710
+ *
711
+ * @template T The expected type of the message data
712
+ * @param name The name of the message type to listen for
713
+ * @param handler The callback function to execute when the message is received
714
+ */
715
+ once(e, t) {
716
+ var s;
717
+ const o = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
718
+ o.length === 0 && this._onceHandlers.set(e, o), o.push(t);
719
+ }
720
+ /**
721
+ * Removes previously registered message handlers.
722
+ *
723
+ * Use this method to stop receiving messages of a specific type or to remove
724
+ * specific handler functions when they're no longer needed. This applies to
725
+ * handlers registered with both on() and once() methods.
726
+ *
727
+ * NOTE: Most application developers should use the resource-specific APIs or the global
728
+ * off() function instead of using this method directly.
729
+ *
730
+ * @template T The expected type of the message data
731
+ * @param name The name of the message type to stop listening for
732
+ * @param handler Optional. The specific handler function to remove. If omitted,
733
+ * all handlers for this message type will be removed.
734
+ */
735
+ off(e, t) {
736
+ const s = this._onHandlers.get(e), o = this._onceHandlers.get(e);
737
+ if (!(!s && !o)) {
738
+ if (s) {
739
+ for (let i = 0; i < s.length; i += 1)
740
+ t && s[i] !== t || (s.splice(i, 1), i -= 1);
741
+ s.length === 0 && this._onHandlers.delete(e);
742
+ }
743
+ if (o) {
744
+ for (let i = 0; i < o.length; i += 1)
745
+ t && o[i] !== t || (o.splice(i, 1), i -= 1);
746
+ o.length === 0 && this._onceHandlers.delete(e);
747
+ }
748
+ }
749
+ }
750
+ }
751
+ function b() {
752
+ return Math.random().toString(36).slice(2, 9);
753
+ }
754
+ const y = q.version;
755
+ let n = null;
756
+ function j() {
757
+ return n;
758
+ }
759
+ function U(r) {
760
+ n = new T(r), n.bind();
761
+ }
762
+ function L() {
763
+ n == null || n.unbind(), n = null;
764
+ }
765
+ function V(...r) {
766
+ return u(n), n.on(...r);
767
+ }
768
+ function x(...r) {
769
+ return u(n), n.once(...r);
770
+ }
771
+ function z(...r) {
772
+ return u(n), n.off(...r);
773
+ }
774
+ function D(...r) {
775
+ return u(n), n.send(...r);
776
+ }
777
+ function K(...r) {
778
+ return u(n), n.request(...r);
779
+ }
780
+ function G(...r) {
781
+ return u(n), n.subscribe(...r);
782
+ }
783
+ function J(...r) {
784
+ return u(n), n.unsubscribe(...r);
785
+ }
786
+ function Q() {
787
+ return u(n), n.store;
788
+ }
789
+ function W() {
790
+ return u(n), n.applications;
791
+ }
792
+ function X() {
793
+ return u(n), n.media;
794
+ }
795
+ function Y() {
796
+ return u(n), n.accounts;
797
+ }
798
+ function Z() {
799
+ return u(n), n.users;
800
+ }
801
+ function O() {
802
+ return u(n), n.rootSettingsNavigation;
803
+ }
804
+ function u(r) {
805
+ if (!r)
806
+ throw new Error("SDK is not configured");
807
+ }
808
+ export {
809
+ B as Accounts,
810
+ P as Applications,
811
+ T as Client,
812
+ R as Environment,
813
+ I as Media,
814
+ k as Store,
815
+ E as Users,
816
+ Y as accounts,
817
+ W as applications,
818
+ U as configure,
819
+ L as destroy,
820
+ j as globalClient,
821
+ X as media,
822
+ z as off,
823
+ V as on,
824
+ x as once,
825
+ K as request,
826
+ O as rootSettingsNavigation,
827
+ D as send,
828
+ Q as store,
829
+ G as subscribe,
830
+ y as telemetrySdkVersion,
831
+ J as unsubscribe,
832
+ Z as users
833
+ };