@monterosa/sdk-interact-kit 0.19.0-rc.6 → 2.0.0-rc.2

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.
@@ -1,45 +1,8 @@
1
- import { getConnect as getConnect$1, login as login$1, connect, disconnect, subscribe as subscribe$1, unsubscribe as unsubscribe$1, send, ConnState, onConnected } from '@monterosa/sdk-connect-kit';
2
- import { Emitter, memoizePromise, subscribe as subscribe$2, checksum, onTick, now, checkAvailability, calculatePercentage, getItem, setItem, createError } from '@monterosa/sdk-util';
1
+ import { Emitter, memoizePromise, subscribe as subscribe$2, checksum, onTick, now, calculatePercentage, getErrorMessage, createError } from '@monterosa/sdk-util';
2
+ import { getConnect as getConnect$1, connect, disconnect, subscribe as subscribe$1, unsubscribe as unsubscribe$1, send, ConnState, onConnected } from '@monterosa/sdk-connect-kit';
3
3
  import { getSdk, Logger } from '@monterosa/sdk-core';
4
-
5
- /**
6
- * @license
7
- * @monterosa/sdk-interact-kit
8
- *
9
- * Copyright © 2023-2024 Monterosa Productions Limited. All rights reserved.
10
- *
11
- * More details on the license can be found at https://www.monterosa.co/sdk/license
12
- */
13
- /**
14
- * Sign in the user to submit data that requires a verified user.
15
- *
16
- * @example
17
- * ```javascript
18
- * try {
19
- * const sdk = getSdk();
20
- * const userId = "b236e331-ee62-4238-90d0-47588c7facdc";
21
- * const timestamp = 1684934960;
22
- * const signature = "9ABC4892838DC13986A63B736E95A7D99DF95C72";
23
- *
24
- * await login(sdk, userId, timestamp, signature);
25
- *
26
- * console.log('logged in successfully!');
27
- * } catch (err) {
28
- * console.log(err)
29
- * }
30
- * ```
31
- *
32
- * @param sdk - Monterosa SDK instance
33
- * @param userId - The unique user UUID
34
- * @param timestamp - The timecode when the signature was generated
35
- * @param signature - A unique identifier that serves as proof of the user's authenticity.
36
- * The signature must only contain the following characters: 0-9, a-z, A-Z, and must be uppercased
37
- * @returns A Promise that resolves with `void` when the login is successful, otherwise it rejects.
38
- */
39
- async function login(sdk, userId, timestamp, signature) {
40
- const connect = await getConnect$1(sdk.options.host);
41
- return login$1(connect, userId, timestamp, signature);
42
- }
4
+ import { fetchSettings } from '@monterosa/sdk-interact-interop';
5
+ import { storageRead, storageWrite } from '@monterosa/sdk-storage-kit';
43
6
 
44
7
  /**
45
8
  * @license
@@ -219,7 +182,7 @@ var ConnectionHealthState;
219
182
  ConnectionHealthState["Ok"] = "ok";
220
183
  /**
221
184
  * The client is either trying to establish a connection but failing, or
222
- * the client has been explicetily {@link @monterosa/sdk-connect-kit#disconnect() | disconnected}
185
+ * the client has been explicitly {@link @monterosa/sdk-connect-kit#disconnect() | disconnected}
223
186
  */
224
187
  ConnectionHealthState["Error"] = "error";
225
188
  })(ConnectionHealthState || (ConnectionHealthState = {}));
@@ -274,32 +237,24 @@ const getConnectionHealthMemoized = memoizePromise(async (sdk) => {
274
237
  }, (sdk) => sdk.options.host);
275
238
  /**
276
239
  * Returns {@link ConnectionHealth | connection health} instance
240
+ *
241
+ * @param sdk - The SDK instance to monitor
242
+ * @returns The connection health instance.
277
243
  */
278
244
  function getConnectionHealth(sdk = getSdk()) {
279
245
  return getConnectionHealthMemoized(sdk);
280
246
  }
281
247
  /**
282
248
  * Adds an observer for when
283
- * {@link ConnectionHealth.state | connection health state} changed
249
+ * {@link ConnectionHealth | connection health state} changed
250
+ *
251
+ * @param connectionHealth - The instance to observe
252
+ * @param callback - Called with the new state
284
253
  */
285
254
  function onConnectionHealthState(connectionHealth, callback) {
286
255
  return subscribe$2(connectionHealth, 'state', callback);
287
256
  }
288
257
 
289
- /**
290
- * @license
291
- * @monterosa/sdk-interact-kit
292
- *
293
- * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
294
- *
295
- * More details on the license can be found at https://www.monterosa.co/sdk/license
296
- */
297
- async function fetchSettings(host, id) {
298
- const response = await fetch(`https://${host}/projects/${id.substring(0, 2)}/${id}/settings.json`);
299
- const data = await response.json();
300
- return data;
301
- }
302
-
303
258
  /**
304
259
  * @license
305
260
  * @monterosa/sdk-interact-kit
@@ -664,36 +619,25 @@ const getProjectMemoized = memoizePromise(async (sdk) => {
664
619
  return project;
665
620
  }, (sdk) => sdk.options.projectId);
666
621
  /**
667
- * Returns {@link InteractProject | project instance} associated
668
- * with the {@link @monterosa/sdk-core#MonterosaSdk | configured sdk}
622
+ * Returns {@link InteractProject | Project instance} associated
623
+ * with the
624
+ * {@link @monterosa/sdk-core#MonterosaSdk | configured SDK}
625
+ *
626
+ * @param sdk - The SDK instance. Defaults to the default SDK.
627
+ * @returns The Project instance.
669
628
  */
670
629
  function getProject(sdk = getSdk()) {
671
630
  return getProjectMemoized(sdk);
672
631
  }
673
632
  /**
674
- * @internal
675
- */
676
- async function fetchListings(host, projectId) {
677
- const response = await fetch(`https://${host}/projects/${projectId.substring(0, 2)}/${projectId}/listings.json`);
678
- const data = (await response.json());
679
- return data;
680
- }
681
- /**
682
- * Adds an observer for when {@link InteractProject.fields | project fields}
683
- * are updated
633
+ * Adds an observer for when
634
+ * {@link InteractProject | Project fields} are updated
635
+ *
636
+ * @param project - The Project to observe
637
+ * @param callback - Called when Project fields change
684
638
  */
685
639
  function onProjectFieldsUpdated(project, callback) {
686
640
  return subscribe$2(project, 'updated', callback);
687
- }
688
- /**
689
- * Adds an observer that is called when the project listings are updated.
690
- *
691
- * @deprecated Use {@link onEventAdded()}, {@link onEventUpdated()} and
692
- * {@link onEventRemoved()} instead
693
- */
694
- function onProjectListingsUpdated(project, callback) {
695
- console.warn('onProjectListingsUpdated() is deprecated. Please use onEventAdded(), onEventUpdated() and onEventRemoved() instead');
696
- return subscribe$2(project, 'listings', callback);
697
641
  }
698
642
 
699
643
  /******************************************************************************
@@ -762,19 +706,19 @@ async function fetchHistory(host, id) {
762
706
  * More details on the license can be found at https://www.monterosa.co/sdk/license
763
707
  */
764
708
  /**
765
- * Describes the event state.
709
+ * Describes the Event state.
766
710
  */
767
711
  var EventState;
768
712
  (function (EventState) {
769
713
  /**
770
- * The event is in the `upcoming` state when its {@link InteractEvent.startAt | start time}
771
- * less than the {@link now | current time}.
714
+ * The Event is in the `upcoming` state when its {@link InteractEvent | startAt}
715
+ * less than the {@link @monterosa/sdk-util#now | current time}.
772
716
  */
773
717
  EventState["Upcoming"] = "upcoming";
774
718
  /**
775
- * The event is in the `active` state when its {@link InteractEvent.startAt | start time}
776
- * equal or more than the {@link now | current time} and less than the
777
- * {@link InteractEvent.endAt | end time}.
719
+ * The Event is in the `active` state when its {@link InteractEvent | startAt}
720
+ * equal or more than the {@link @monterosa/sdk-util#now | current time} and less than the
721
+ * {@link InteractEvent | endAt}.
778
722
  */
779
723
  EventState["Active"] = "active";
780
724
  /**
@@ -782,8 +726,8 @@ var EventState;
782
726
  */
783
727
  EventState["Prolonged"] = "prolonged";
784
728
  /**
785
- * The event is in the `finished` state when its {@link InteractEvent.endAt | end time}
786
- * equal or more than the {@link now | current time}.
729
+ * The Event is in the `finished` state when its {@link InteractEvent | endAt}
730
+ * equal or more than the {@link @monterosa/sdk-util#now | current time}.
787
731
  */
788
732
  EventState["Finished"] = "finished";
789
733
  })(EventState || (EventState = {}));
@@ -1037,10 +981,10 @@ const getEventsMemoized = memoizePromise(async (project) => {
1037
981
  }
1038
982
  const context = Object.assign(Object.assign({}, project.context), { project });
1039
983
  return (project.events
1040
- // Calling builder function that creates an event instance.
1041
- // Existing event will be returned if it already exists in the cache
984
+ // Calling builder function that creates an Event instance.
985
+ // Existing Event will be returned if it already exists in the cache
1042
986
  .map((data) => buildEvent(data, context))
1043
- // Sort events so the most recent event is first, and the oldest is last
987
+ // Sort Events so the oldest Event is first, and the most recent is last
1044
988
  .sort((a, b) => a.startAt - b.startAt));
1045
989
  },
1046
990
  /**
@@ -1071,12 +1015,13 @@ const getEventsMemoized = memoizePromise(async (project) => {
1071
1015
  return sdk.options.projectId;
1072
1016
  });
1073
1017
  /**
1074
- * Returns all events in a project, including all active events and
1075
- * past/upcoming events, according to Listings settings in Project Setup
1018
+ * Returns all Events in a Project, including all active Events and
1019
+ * past/upcoming Events, according to Listings settings in Project Setup
1076
1020
  * in Studio.
1077
1021
  *
1078
- * @param project - A project instance. If not provided,
1079
- * the one from the default sdk will be fetched.
1022
+ * @param project - A Project instance. If not provided,
1023
+ * the one from the default SDK will be fetched.
1024
+ * @returns A promise that resolves to an array of Events.
1080
1025
  */
1081
1026
  function getEvents(project) {
1082
1027
  return getEventsMemoized(project);
@@ -1112,44 +1057,54 @@ const getEventMemoized = memoizePromise(async (id, project) => {
1112
1057
  }
1113
1058
  }, (id) => id);
1114
1059
  /**
1115
- * Returns an event by its id
1060
+ * Returns an Event by its id
1116
1061
  *
1117
- * @param id - Id of the event
1118
- * @param project - A project instance. If not provided,
1119
- * the one from the default sdk will be fetched.
1062
+ * @param id - Id of the Event
1063
+ * @param project - A Project instance. If not provided,
1064
+ * the one from the default SDK will be fetched.
1120
1065
  *
1121
- * @returns A an event associated with the provided id and project or null if no such
1122
- * event exists in the project.
1066
+ * @returns The Event associated with the provided id,
1067
+ * or null if no such Event exists in the Project.
1123
1068
  */
1124
1069
  function getEvent(id, project) {
1125
1070
  return getEventMemoized(id, project);
1126
1071
  }
1127
1072
  /**
1128
- * Adds an observer for when {@link InteractEvent.state | event state} changed
1073
+ * Adds an observer for when
1074
+ * {@link InteractEvent | Event state} changed
1075
+ *
1076
+ * @param event - The Event to observe
1077
+ * @param callback - Called with the new state
1129
1078
  */
1130
1079
  function onEventState(event, callback) {
1131
1080
  return subscribe$2(event, 'state', callback);
1132
1081
  }
1133
1082
  /**
1134
- * Adds an observer for when event's data changed
1083
+ * Adds an observer for when Event's data changed
1084
+ *
1085
+ * @param event - The Event to observe
1086
+ * @param callback - Called when the Event data changes
1135
1087
  */
1136
1088
  function onEventUpdated(event, callback) {
1137
1089
  return subscribe$2(event, 'updated', callback);
1138
1090
  }
1139
1091
  /**
1140
- * Adds an observer that is called when an event is added to listings.
1092
+ * Adds an observer that is called when an Event is added to listings.
1141
1093
  *
1142
1094
  * @remarks
1143
- * The following actions will result in adding an event to listings:
1095
+ * The following actions will result in adding an Event to listings:
1096
+ *
1097
+ * - The start of the Event in Studio
1144
1098
  *
1145
- * - The start of the event in Studio
1099
+ * - The scheduling of a future Event in Studio, when listings are configured
1100
+ * to include future Events in Project Settings.
1146
1101
  *
1147
- * - The scheduling of a future event in Studio, when listings are configured
1148
- * to include future events in Project Settings.
1102
+ * - When a future Event starts, a new future Event may be added to the list,
1103
+ * depending on the Project configuration, to ensure a minimum number of
1104
+ * upcoming Events are always available.
1149
1105
  *
1150
- * - When a future event starts, a new future event may be added to the list,
1151
- * depending on the project configuration, to ensure a minimum number of
1152
- * upcoming events are always available.
1106
+ * @param project - The Project to observe
1107
+ * @param callback - Called with the added Event
1153
1108
  */
1154
1109
  function onEventAdded(project, callback) {
1155
1110
  return subscribe$2(project, 'listings_events_created', async (data) => {
@@ -1180,28 +1135,22 @@ function onEventAdded(project, callback) {
1180
1135
  });
1181
1136
  }
1182
1137
  /**
1183
- * {@link onEventAdded} alias.
1184
- *
1185
- * @deprecated Use the new {@link onEventAdded} function instead.
1186
- */
1187
- function onEventPublished(project, callback) {
1188
- console.warn('onEventPublished() is deprecated. Please use onEventAdded() instead');
1189
- return onEventAdded(project, callback);
1190
- }
1191
- /**
1192
- * Adds an observer that is called when an event is removed from listings.
1138
+ * Adds an observer that is called when an Event is removed from listings.
1193
1139
  *
1194
1140
  * @remarks
1195
- * The following actions will result in removing an event from listings:
1141
+ * The following actions will result in removing an Event from listings:
1196
1142
  *
1197
- * - The deletion of the event from Studio
1143
+ * - The deletion of the Event from Studio
1198
1144
  *
1199
- * - The change of listings confuguration in Project Settings to exclude future
1200
- * or past events.
1145
+ * - The change of listings configuration in Project Settings to exclude future
1146
+ * or past Events.
1201
1147
  *
1202
- * - The event is removed after a period of time since its completion. This period
1148
+ * - The Event is removed after a period of time since its completion. This period
1203
1149
  * is calculated as 45 seconds plus the Maximum allowed delay (configured in
1204
1150
  * Project Settings in Studio).
1151
+ *
1152
+ * @param project - The Project to observe
1153
+ * @param callback - Called with the removed Event
1205
1154
  */
1206
1155
  function onEventRemoved(project, callback) {
1207
1156
  return subscribe$2(project, 'listings_events_deleted', async (data) => {
@@ -1246,13 +1195,21 @@ function onEventRemoved(project, callback) {
1246
1195
  */
1247
1196
  var AnswerError;
1248
1197
  (function (AnswerError) {
1198
+ /** Selected option index is out of range. */
1249
1199
  AnswerError["OptionIndexOutOfRange"] = "out_of_range";
1200
+ /** Fewer options selected than the minimum required. */
1250
1201
  AnswerError["BelowMinVoteOptions"] = "below_min_vote_options";
1202
+ /** More options selected than the maximum allowed. */
1251
1203
  AnswerError["AboveMaxVoteOptions"] = "above_max_vote_options";
1204
+ /** User has exceeded the maximum votes allowed. */
1252
1205
  AnswerError["AboveMaxVotesPerUser"] = "above_max_per_user";
1206
+ /** A single option received more votes than allowed. */
1253
1207
  AnswerError["AboveMaxVotesPerOption"] = "above_max_per_option";
1208
+ /** Attempted to vote on a non-interactive element. */
1254
1209
  AnswerError["VotedOnNonInteractiveElement"] = "non_interactive_element";
1210
+ /** Attempted to vote on a closed element. */
1255
1211
  AnswerError["VotedOnClosedElement"] = "closed_element";
1212
+ /** No vote value was provided. */
1256
1213
  AnswerError["EmptyVote"] = "empty_vote";
1257
1214
  })(AnswerError || (AnswerError = {}));
1258
1215
  const AnswerErrorMessages = {
@@ -1266,18 +1223,18 @@ const AnswerErrorMessages = {
1266
1223
  [AnswerError.EmptyVote]: (indices) => `Empty value for options indices: ${indices}`,
1267
1224
  };
1268
1225
  /**
1269
- * The ElementState represents the potential states an element is in.
1226
+ * The ElementState represents the potential states an Element is in.
1270
1227
  */
1271
1228
  var ElementState;
1272
1229
  (function (ElementState) {
1273
1230
  /**
1274
1231
  * Element is opened and active. The user can vote if
1275
- * element is `interactive`
1232
+ * the Element is `interactive`
1276
1233
  */
1277
1234
  ElementState["Opened"] = "opened";
1278
1235
  /**
1279
1236
  * Element is closed and the user can no longer vote for
1280
- * `interactive` elements
1237
+ * `interactive` Elements
1281
1238
  */
1282
1239
  ElementState["Closed"] = "closed";
1283
1240
  })(ElementState || (ElementState = {}));
@@ -1366,40 +1323,40 @@ class Answer {
1366
1323
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1367
1324
  */
1368
1325
  /**
1369
- * Describes element types
1326
+ * Describes Element types
1370
1327
  */
1371
1328
  var ElementType;
1372
1329
  (function (ElementType) {
1373
1330
  /**
1374
- * Data element
1331
+ * Data Element
1375
1332
  */
1376
1333
  ElementType["Data"] = "data";
1377
1334
  /**
1378
- * Poll element
1335
+ * Poll Element
1379
1336
  */
1380
1337
  ElementType["Poll"] = "poll";
1381
1338
  /**
1382
- * Regular poll element
1339
+ * Regular poll Element
1383
1340
  */
1384
1341
  ElementType["RegularPoll"] = "rpoll";
1385
1342
  /**
1386
- * Diametric poll element
1343
+ * Diametric poll Element
1387
1344
  */
1388
1345
  ElementType["DiametricPoll"] = "dpoll";
1389
1346
  /**
1390
- * Emoting poll
1347
+ * Emoting poll Element
1391
1348
  */
1392
1349
  ElementType["EmotingPoll"] = "emo";
1393
1350
  /**
1394
- * Powerbar element
1351
+ * Powerbar Element
1395
1352
  */
1396
1353
  ElementType["Powerbar"] = "powerbar";
1397
1354
  /**
1398
- * Prediction element
1355
+ * Prediction Element
1399
1356
  */
1400
1357
  ElementType["Prediction"] = "prediction";
1401
1358
  /**
1402
- * Trivia element
1359
+ * Trivia Element
1403
1360
  */
1404
1361
  ElementType["Trivia"] = "trivia";
1405
1362
  })(ElementType || (ElementType = {}));
@@ -1458,6 +1415,7 @@ class ElementImpl extends Emitter {
1458
1415
  }
1459
1416
  update(data) {
1460
1417
  this._data = data;
1418
+ this.handleState();
1461
1419
  }
1462
1420
  destroy() {
1463
1421
  this.unsubscribeStateHandler();
@@ -1596,13 +1554,12 @@ class ElementImpl extends Emitter {
1596
1554
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1597
1555
  */
1598
1556
  const elements = new Map();
1599
- const storageAvailable = checkAvailability();
1600
- function buildElement(options, context) {
1557
+ async function buildElement(options, context) {
1601
1558
  if (elements.has(options.id)) {
1602
1559
  return elements.get(options.id);
1603
1560
  }
1604
1561
  const element = new ElementImpl(options, context);
1605
- restoreAnswer(element);
1562
+ await restoreAnswer(element);
1606
1563
  elements.set(element.id, element);
1607
1564
  return element;
1608
1565
  }
@@ -1653,14 +1610,21 @@ async function handleCreateMessage(message) {
1653
1610
  }
1654
1611
  if (elements.has(options.id)) {
1655
1612
  const element = elements.get(options.id);
1656
- if (options.updated_at > element.updatedAt) {
1613
+ if (options.updated_at > element.updatedAt ||
1614
+ // This is a workaround to handle a Studio issue when two /create/ messages
1615
+ // are sent upon correct option reveal. The first /create/ message contains
1616
+ // the same duration but a different updated_at timestamp. The second /create/
1617
+ // message contains the same updated_at timestamp but a different duration.
1618
+ // Therefore, we need to check if the duration is different to ensure that
1619
+ // the element is updated correctly.
1620
+ options.duration !== element.duration) {
1657
1621
  element.update(options);
1658
1622
  event.emit('update', element);
1659
1623
  }
1660
1624
  }
1661
1625
  else {
1662
1626
  const context = Object.assign(Object.assign({}, event.context), { event });
1663
- const element = buildElement(options, context);
1627
+ const element = await buildElement(options, context);
1664
1628
  event.emit('publish', element);
1665
1629
  }
1666
1630
  }
@@ -1705,10 +1669,13 @@ function handleRevealMessage(message) {
1705
1669
  if (!element) {
1706
1670
  return;
1707
1671
  }
1708
- element.correctOption = correctOption;
1709
- element.context.event.emit('update', element);
1672
+ if (element.correctOption !== correctOption) {
1673
+ element.correctOption = correctOption;
1674
+ element.context.event.emit('update', element);
1675
+ }
1710
1676
  }
1711
1677
  async function handleEventHistory(history) {
1678
+ var _a, e_1, _b, _c;
1712
1679
  if (history.timeline.length === 0) {
1713
1680
  return;
1714
1681
  }
@@ -1717,10 +1684,27 @@ async function handleEventHistory(history) {
1717
1684
  return;
1718
1685
  }
1719
1686
  const context = Object.assign(Object.assign({}, event.context), { event });
1720
- for (const snapshot of history.timeline) {
1721
- if (!elements.has(snapshot.id)) {
1722
- buildElement(snapshot, context);
1687
+ try {
1688
+ for (var _d = true, _e = __asyncValues(history.timeline), _f; _f = await _e.next(), _a = _f.done, !_a;) {
1689
+ _c = _f.value;
1690
+ _d = false;
1691
+ try {
1692
+ const snapshot = _c;
1693
+ if (!elements.has(snapshot.id)) {
1694
+ await buildElement(snapshot, context);
1695
+ }
1696
+ }
1697
+ finally {
1698
+ _d = true;
1699
+ }
1700
+ }
1701
+ }
1702
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1703
+ finally {
1704
+ try {
1705
+ if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
1723
1706
  }
1707
+ finally { if (e_1) throw e_1.error; }
1724
1708
  }
1725
1709
  }
1726
1710
  async function sendAnswer(element, userAnswer) {
@@ -1732,27 +1716,19 @@ async function sendAnswer(element, userAnswer) {
1732
1716
  .join(':');
1733
1717
  connect.sendVote(event.id, element.pollId, answer);
1734
1718
  }
1735
- function storeAnswer(element, userAnswer) {
1719
+ async function storeAnswer(element, userAnswer) {
1736
1720
  try {
1737
1721
  element.userAnswer = userAnswer;
1738
- if (storageAvailable) {
1739
- // Can throw a "QuotaExceededError" DOMException exception
1740
- // if the quota has been exceeded.
1741
- setItem(`element_${element.id}_vote`, JSON.stringify(userAnswer));
1742
- }
1722
+ await storageWrite(`element_${element.id}_vote`, JSON.stringify(userAnswer));
1743
1723
  }
1744
1724
  catch (err) {
1745
- if (err instanceof Error) {
1746
- console.warn(`Can't store user answer: ${err.message}`);
1747
- }
1725
+ console.warn(`Failed to store user answer: ${getErrorMessage(err)}`);
1748
1726
  }
1749
1727
  }
1750
- function restoreAnswer(element) {
1751
- if (storageAvailable) {
1752
- const userAnswer = getItem(`element_${element.id}_vote`);
1753
- if (userAnswer !== null) {
1754
- element.userAnswer = Answer.fromJSON(userAnswer);
1755
- }
1728
+ async function restoreAnswer(element) {
1729
+ const userAnswer = await storageRead(`element_${element.id}_vote`);
1730
+ if (userAnswer !== null) {
1731
+ element.userAnswer = Answer.fromJSON(userAnswer);
1756
1732
  }
1757
1733
  }
1758
1734
 
@@ -1773,7 +1749,10 @@ const getElementMemoized = memoizePromise(async (event, id) => {
1773
1749
  return element || null;
1774
1750
  }, (event, id) => id);
1775
1751
  /**
1776
- * Returns an element of a specific event by its id
1752
+ * Returns an Element of a specific Event by its id.
1753
+ *
1754
+ * @param event - The Event that owns the Element
1755
+ * @param id - The Element identifier
1777
1756
  */
1778
1757
  function getElement(event, id) {
1779
1758
  return getElementMemoized(event, id);
@@ -1784,15 +1763,18 @@ function getElement(event, id) {
1784
1763
  const getElementsMemoized = memoizePromise(async (event) => {
1785
1764
  await configureEvent(event);
1786
1765
  return (Array.from(elements.values())
1787
- // Get elements which belong only to the provided event
1766
+ // Get Elements which belong only to the provided Event
1788
1767
  .filter((element) => element.eventId === event.id)
1789
- // Sort elements so the most recent event is first, and the oldest is last
1768
+ // Sort Elements so the oldest Element is first, and the most recent is last
1790
1769
  .sort((a, b) => a.publishedAt - b.publishedAt));
1791
1770
  }, (event) => event.id, {
1792
1771
  clearOnResolve: true,
1793
1772
  });
1794
1773
  /**
1795
- * Returns the list of elements published in a specific event
1774
+ * Returns the list of Elements published in a specific Event
1775
+ *
1776
+ * @param event - The Event to fetch Elements for
1777
+ * @returns The published Elements, sorted oldest first.
1796
1778
  */
1797
1779
  function getElements(event) {
1798
1780
  return getElementsMemoized(event);
@@ -1868,29 +1850,41 @@ function isNumbers(value) {
1868
1850
  return value.every((v) => typeof v === 'number');
1869
1851
  }
1870
1852
  /**
1871
- * Adds an observer for when {@link InteractElement.results | element results}
1872
- * are updated
1853
+ * Adds an observer for when
1854
+ * {@link InteractElement | Element results} are updated
1855
+ *
1856
+ * @param element - The Element to observe
1857
+ * @param callback - Called when results are updated
1873
1858
  */
1874
1859
  function onElementResults(element, callback) {
1875
1860
  return subscribe$2(element, 'results', callback);
1876
1861
  }
1877
1862
  /**
1878
- * Adds an observer for when {@link InteractElement.state | element state}
1879
- * changed
1863
+ * Adds an observer for when
1864
+ * {@link InteractElement | Element state} changed
1865
+ *
1866
+ * @param element - The Element to observe
1867
+ * @param callback - Called when the state changes
1880
1868
  */
1881
1869
  function onElementStateChanged(element, callback) {
1882
1870
  return subscribe$2(element, 'state', callback);
1883
1871
  }
1884
1872
  /**
1885
- * Adds an observer for when {@link InteractElement.fields | element's data}
1886
- * is updated
1873
+ * Adds an observer for when
1874
+ * {@link InteractElement | Element fields} are updated
1875
+ *
1876
+ * @param event - The Event containing the Elements
1877
+ * @param callback - Called with the updated Element
1887
1878
  */
1888
1879
  function onElementUpdated(event, callback) {
1889
1880
  configureEvent(event);
1890
1881
  return subscribe$2(event, 'update', callback);
1891
1882
  }
1892
1883
  /**
1893
- * Adds an observer for when a new element is published
1884
+ * Adds an observer for when a new Element is published
1885
+ *
1886
+ * @param event - The Event to observe
1887
+ * @param callback - Called with the published Element
1894
1888
  */
1895
1889
  function onElementPublished(event, callback) {
1896
1890
  configureEvent(event);
@@ -1901,7 +1895,10 @@ function onElementPublished(event, callback) {
1901
1895
  });
1902
1896
  }
1903
1897
  /**
1904
- * Adds an observer for when an element is revoked
1898
+ * Adds an observer for when an Element is revoked
1899
+ *
1900
+ * @param event - The Event to observe
1901
+ * @param callback - Called with the revoked Element
1905
1902
  */
1906
1903
  function onElementRevoked(event, callback) {
1907
1904
  configureEvent(event);
@@ -2058,5 +2055,5 @@ function onPresenceCounterClose(presenceCounter, callback) {
2058
2055
  return () => presenceCounter.off('state', handler);
2059
2056
  }
2060
2057
 
2061
- export { Answer, AnswerError, Channel, ConnectionHealthState, ElementImpl, ElementState, ElementType, EventImpl, EventState, Klass, PresenceCounterState, ProjectImpl, State, answer, fetchListings, getConnect, getConnectionHealth, getElement, getElementMemoized, getElements, getElementsMemoized, getEvent, getEventMemoized, getEvents, getEventsMemoized, getPresenceCounter, getProject, getProjectMemoized, login, onConnectionHealthState, onElementPublished, onElementResults, onElementRevoked, onElementStateChanged, onElementUpdated, onEventAdded, onEventPublished, onEventRemoved, onEventState, onEventUpdated, onPresenceCounterClose, onPresenceCounterOpen, onPresenceCounterUpdate, onProjectFieldsUpdated, onProjectListingsUpdated, validateAnswer };
2062
- //# sourceMappingURL=index.esm.js.map
2058
+ export { Answer, AnswerError, Channel, ConnectionHealthState, ElementImpl, ElementState, ElementType, EventImpl, EventState, Klass, PresenceCounterState, ProjectImpl, State, answer, getConnect, getConnectionHealth, getElement, getElementMemoized, getElements, getElementsMemoized, getEvent, getEventMemoized, getEvents, getEventsMemoized, getPresenceCounter, getProject, getProjectMemoized, onConnectionHealthState, onElementPublished, onElementResults, onElementRevoked, onElementStateChanged, onElementUpdated, onEventAdded, onEventRemoved, onEventState, onEventUpdated, onPresenceCounterClose, onPresenceCounterOpen, onPresenceCounterUpdate, onProjectFieldsUpdated, validateAnswer };
2059
+ //# sourceMappingURL=index.js.map