@monterosa/sdk-interact-kit 2.0.0-rc.1 → 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,48 +1,9 @@
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
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
4
  import { fetchSettings } from '@monterosa/sdk-interact-interop';
5
5
  import { storageRead, storageWrite } from '@monterosa/sdk-storage-kit';
6
6
 
7
- /**
8
- * @license
9
- * @monterosa/sdk-interact-kit
10
- *
11
- * Copyright © 2023-2024 Monterosa Productions Limited. All rights reserved.
12
- *
13
- * More details on the license can be found at https://www.monterosa.co/sdk/license
14
- */
15
- /**
16
- * Sign in the user to submit data that requires a verified user.
17
- *
18
- * @example
19
- * ```javascript
20
- * try {
21
- * const sdk = getSdk();
22
- * const userId = "b236e331-ee62-4238-90d0-47588c7facdc";
23
- * const timestamp = 1684934960;
24
- * const signature = "9ABC4892838DC13986A63B736E95A7D99DF95C72";
25
- *
26
- * await login(sdk, userId, timestamp, signature);
27
- *
28
- * console.log('logged in successfully!');
29
- * } catch (err) {
30
- * console.log(err)
31
- * }
32
- * ```
33
- *
34
- * @param sdk - Monterosa SDK instance
35
- * @param userId - The unique user UUID
36
- * @param timestamp - The timecode when the signature was generated
37
- * @param signature - A unique identifier that serves as proof of the user's authenticity.
38
- * The signature must only contain the following characters: 0-9, a-z, A-Z, and must be uppercased
39
- * @returns A Promise that resolves with `void` when the login is successful, otherwise it rejects.
40
- */
41
- async function login(sdk, userId, timestamp, signature) {
42
- const connect = await getConnect$1(sdk.options.host);
43
- return login$1(connect, userId, timestamp, signature);
44
- }
45
-
46
7
  /**
47
8
  * @license
48
9
  * @monterosa/sdk-interact-kit
@@ -221,7 +182,7 @@ var ConnectionHealthState;
221
182
  ConnectionHealthState["Ok"] = "ok";
222
183
  /**
223
184
  * The client is either trying to establish a connection but failing, or
224
- * 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}
225
186
  */
226
187
  ConnectionHealthState["Error"] = "error";
227
188
  })(ConnectionHealthState || (ConnectionHealthState = {}));
@@ -276,13 +237,19 @@ const getConnectionHealthMemoized = memoizePromise(async (sdk) => {
276
237
  }, (sdk) => sdk.options.host);
277
238
  /**
278
239
  * Returns {@link ConnectionHealth | connection health} instance
240
+ *
241
+ * @param sdk - The SDK instance to monitor
242
+ * @returns The connection health instance.
279
243
  */
280
244
  function getConnectionHealth(sdk = getSdk()) {
281
245
  return getConnectionHealthMemoized(sdk);
282
246
  }
283
247
  /**
284
248
  * Adds an observer for when
285
- * {@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
286
253
  */
287
254
  function onConnectionHealthState(connectionHealth, callback) {
288
255
  return subscribe$2(connectionHealth, 'state', callback);
@@ -652,28 +619,25 @@ const getProjectMemoized = memoizePromise(async (sdk) => {
652
619
  return project;
653
620
  }, (sdk) => sdk.options.projectId);
654
621
  /**
655
- * Returns {@link InteractProject | project instance} associated
656
- * 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.
657
628
  */
658
629
  function getProject(sdk = getSdk()) {
659
630
  return getProjectMemoized(sdk);
660
631
  }
661
632
  /**
662
- * Adds an observer for when {@link InteractProject.fields | project fields}
663
- * 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
664
638
  */
665
639
  function onProjectFieldsUpdated(project, callback) {
666
640
  return subscribe$2(project, 'updated', callback);
667
- }
668
- /**
669
- * Adds an observer that is called when the project listings are updated.
670
- *
671
- * @deprecated Use {@link onEventAdded()}, {@link onEventUpdated()} and
672
- * {@link onEventRemoved()} instead
673
- */
674
- function onProjectListingsUpdated(project, callback) {
675
- console.warn('onProjectListingsUpdated() is deprecated. Please use onEventAdded(), onEventUpdated() and onEventRemoved() instead');
676
- return subscribe$2(project, 'listings', callback);
677
641
  }
678
642
 
679
643
  /******************************************************************************
@@ -742,19 +706,19 @@ async function fetchHistory(host, id) {
742
706
  * More details on the license can be found at https://www.monterosa.co/sdk/license
743
707
  */
744
708
  /**
745
- * Describes the event state.
709
+ * Describes the Event state.
746
710
  */
747
711
  var EventState;
748
712
  (function (EventState) {
749
713
  /**
750
- * The event is in the `upcoming` state when its {@link InteractEvent.startAt | start time}
751
- * 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}.
752
716
  */
753
717
  EventState["Upcoming"] = "upcoming";
754
718
  /**
755
- * The event is in the `active` state when its {@link InteractEvent.startAt | start time}
756
- * equal or more than the {@link now | current time} and less than the
757
- * {@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}.
758
722
  */
759
723
  EventState["Active"] = "active";
760
724
  /**
@@ -762,8 +726,8 @@ var EventState;
762
726
  */
763
727
  EventState["Prolonged"] = "prolonged";
764
728
  /**
765
- * The event is in the `finished` state when its {@link InteractEvent.endAt | end time}
766
- * 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}.
767
731
  */
768
732
  EventState["Finished"] = "finished";
769
733
  })(EventState || (EventState = {}));
@@ -1017,10 +981,10 @@ const getEventsMemoized = memoizePromise(async (project) => {
1017
981
  }
1018
982
  const context = Object.assign(Object.assign({}, project.context), { project });
1019
983
  return (project.events
1020
- // Calling builder function that creates an event instance.
1021
- // 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
1022
986
  .map((data) => buildEvent(data, context))
1023
- // 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
1024
988
  .sort((a, b) => a.startAt - b.startAt));
1025
989
  },
1026
990
  /**
@@ -1051,12 +1015,13 @@ const getEventsMemoized = memoizePromise(async (project) => {
1051
1015
  return sdk.options.projectId;
1052
1016
  });
1053
1017
  /**
1054
- * Returns all events in a project, including all active events and
1055
- * 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
1056
1020
  * in Studio.
1057
1021
  *
1058
- * @param project - A project instance. If not provided,
1059
- * 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.
1060
1025
  */
1061
1026
  function getEvents(project) {
1062
1027
  return getEventsMemoized(project);
@@ -1092,44 +1057,54 @@ const getEventMemoized = memoizePromise(async (id, project) => {
1092
1057
  }
1093
1058
  }, (id) => id);
1094
1059
  /**
1095
- * Returns an event by its id
1060
+ * Returns an Event by its id
1096
1061
  *
1097
- * @param id - Id of the event
1098
- * @param project - A project instance. If not provided,
1099
- * 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.
1100
1065
  *
1101
- * @returns A an event associated with the provided id and project or null if no such
1102
- * 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.
1103
1068
  */
1104
1069
  function getEvent(id, project) {
1105
1070
  return getEventMemoized(id, project);
1106
1071
  }
1107
1072
  /**
1108
- * 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
1109
1078
  */
1110
1079
  function onEventState(event, callback) {
1111
1080
  return subscribe$2(event, 'state', callback);
1112
1081
  }
1113
1082
  /**
1114
- * 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
1115
1087
  */
1116
1088
  function onEventUpdated(event, callback) {
1117
1089
  return subscribe$2(event, 'updated', callback);
1118
1090
  }
1119
1091
  /**
1120
- * 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.
1121
1093
  *
1122
1094
  * @remarks
1123
- * The following actions will result in adding an event to listings:
1095
+ * The following actions will result in adding an Event to listings:
1124
1096
  *
1125
- * - The start of the event in Studio
1097
+ * - The start of the Event in Studio
1126
1098
  *
1127
- * - The scheduling of a future event in Studio, when listings are configured
1128
- * to include future events in Project Settings.
1099
+ * - The scheduling of a future Event in Studio, when listings are configured
1100
+ * to include future Events in Project Settings.
1129
1101
  *
1130
- * - When a future event starts, a new future event may be added to the list,
1131
- * depending on the project configuration, to ensure a minimum number of
1132
- * upcoming events are always available.
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.
1105
+ *
1106
+ * @param project - The Project to observe
1107
+ * @param callback - Called with the added Event
1133
1108
  */
1134
1109
  function onEventAdded(project, callback) {
1135
1110
  return subscribe$2(project, 'listings_events_created', async (data) => {
@@ -1160,28 +1135,22 @@ function onEventAdded(project, callback) {
1160
1135
  });
1161
1136
  }
1162
1137
  /**
1163
- * {@link onEventAdded} alias.
1164
- *
1165
- * @deprecated Use the new {@link onEventAdded} function instead.
1166
- */
1167
- function onEventPublished(project, callback) {
1168
- console.warn('onEventPublished() is deprecated. Please use onEventAdded() instead');
1169
- return onEventAdded(project, callback);
1170
- }
1171
- /**
1172
- * 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.
1173
1139
  *
1174
1140
  * @remarks
1175
- * The following actions will result in removing an event from listings:
1141
+ * The following actions will result in removing an Event from listings:
1176
1142
  *
1177
- * - The deletion of the event from Studio
1143
+ * - The deletion of the Event from Studio
1178
1144
  *
1179
- * - The change of listings confuguration in Project Settings to exclude future
1180
- * or past events.
1145
+ * - The change of listings configuration in Project Settings to exclude future
1146
+ * or past Events.
1181
1147
  *
1182
- * - 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
1183
1149
  * is calculated as 45 seconds plus the Maximum allowed delay (configured in
1184
1150
  * Project Settings in Studio).
1151
+ *
1152
+ * @param project - The Project to observe
1153
+ * @param callback - Called with the removed Event
1185
1154
  */
1186
1155
  function onEventRemoved(project, callback) {
1187
1156
  return subscribe$2(project, 'listings_events_deleted', async (data) => {
@@ -1226,13 +1195,21 @@ function onEventRemoved(project, callback) {
1226
1195
  */
1227
1196
  var AnswerError;
1228
1197
  (function (AnswerError) {
1198
+ /** Selected option index is out of range. */
1229
1199
  AnswerError["OptionIndexOutOfRange"] = "out_of_range";
1200
+ /** Fewer options selected than the minimum required. */
1230
1201
  AnswerError["BelowMinVoteOptions"] = "below_min_vote_options";
1202
+ /** More options selected than the maximum allowed. */
1231
1203
  AnswerError["AboveMaxVoteOptions"] = "above_max_vote_options";
1204
+ /** User has exceeded the maximum votes allowed. */
1232
1205
  AnswerError["AboveMaxVotesPerUser"] = "above_max_per_user";
1206
+ /** A single option received more votes than allowed. */
1233
1207
  AnswerError["AboveMaxVotesPerOption"] = "above_max_per_option";
1208
+ /** Attempted to vote on a non-interactive element. */
1234
1209
  AnswerError["VotedOnNonInteractiveElement"] = "non_interactive_element";
1210
+ /** Attempted to vote on a closed element. */
1235
1211
  AnswerError["VotedOnClosedElement"] = "closed_element";
1212
+ /** No vote value was provided. */
1236
1213
  AnswerError["EmptyVote"] = "empty_vote";
1237
1214
  })(AnswerError || (AnswerError = {}));
1238
1215
  const AnswerErrorMessages = {
@@ -1246,18 +1223,18 @@ const AnswerErrorMessages = {
1246
1223
  [AnswerError.EmptyVote]: (indices) => `Empty value for options indices: ${indices}`,
1247
1224
  };
1248
1225
  /**
1249
- * The ElementState represents the potential states an element is in.
1226
+ * The ElementState represents the potential states an Element is in.
1250
1227
  */
1251
1228
  var ElementState;
1252
1229
  (function (ElementState) {
1253
1230
  /**
1254
1231
  * Element is opened and active. The user can vote if
1255
- * element is `interactive`
1232
+ * the Element is `interactive`
1256
1233
  */
1257
1234
  ElementState["Opened"] = "opened";
1258
1235
  /**
1259
1236
  * Element is closed and the user can no longer vote for
1260
- * `interactive` elements
1237
+ * `interactive` Elements
1261
1238
  */
1262
1239
  ElementState["Closed"] = "closed";
1263
1240
  })(ElementState || (ElementState = {}));
@@ -1346,40 +1323,40 @@ class Answer {
1346
1323
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1347
1324
  */
1348
1325
  /**
1349
- * Describes element types
1326
+ * Describes Element types
1350
1327
  */
1351
1328
  var ElementType;
1352
1329
  (function (ElementType) {
1353
1330
  /**
1354
- * Data element
1331
+ * Data Element
1355
1332
  */
1356
1333
  ElementType["Data"] = "data";
1357
1334
  /**
1358
- * Poll element
1335
+ * Poll Element
1359
1336
  */
1360
1337
  ElementType["Poll"] = "poll";
1361
1338
  /**
1362
- * Regular poll element
1339
+ * Regular poll Element
1363
1340
  */
1364
1341
  ElementType["RegularPoll"] = "rpoll";
1365
1342
  /**
1366
- * Diametric poll element
1343
+ * Diametric poll Element
1367
1344
  */
1368
1345
  ElementType["DiametricPoll"] = "dpoll";
1369
1346
  /**
1370
- * Emoting poll
1347
+ * Emoting poll Element
1371
1348
  */
1372
1349
  ElementType["EmotingPoll"] = "emo";
1373
1350
  /**
1374
- * Powerbar element
1351
+ * Powerbar Element
1375
1352
  */
1376
1353
  ElementType["Powerbar"] = "powerbar";
1377
1354
  /**
1378
- * Prediction element
1355
+ * Prediction Element
1379
1356
  */
1380
1357
  ElementType["Prediction"] = "prediction";
1381
1358
  /**
1382
- * Trivia element
1359
+ * Trivia Element
1383
1360
  */
1384
1361
  ElementType["Trivia"] = "trivia";
1385
1362
  })(ElementType || (ElementType = {}));
@@ -1772,7 +1749,10 @@ const getElementMemoized = memoizePromise(async (event, id) => {
1772
1749
  return element || null;
1773
1750
  }, (event, id) => id);
1774
1751
  /**
1775
- * 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
1776
1756
  */
1777
1757
  function getElement(event, id) {
1778
1758
  return getElementMemoized(event, id);
@@ -1783,15 +1763,18 @@ function getElement(event, id) {
1783
1763
  const getElementsMemoized = memoizePromise(async (event) => {
1784
1764
  await configureEvent(event);
1785
1765
  return (Array.from(elements.values())
1786
- // Get elements which belong only to the provided event
1766
+ // Get Elements which belong only to the provided Event
1787
1767
  .filter((element) => element.eventId === event.id)
1788
- // 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
1789
1769
  .sort((a, b) => a.publishedAt - b.publishedAt));
1790
1770
  }, (event) => event.id, {
1791
1771
  clearOnResolve: true,
1792
1772
  });
1793
1773
  /**
1794
- * 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.
1795
1778
  */
1796
1779
  function getElements(event) {
1797
1780
  return getElementsMemoized(event);
@@ -1867,29 +1850,41 @@ function isNumbers(value) {
1867
1850
  return value.every((v) => typeof v === 'number');
1868
1851
  }
1869
1852
  /**
1870
- * Adds an observer for when {@link InteractElement.results | element results}
1871
- * 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
1872
1858
  */
1873
1859
  function onElementResults(element, callback) {
1874
1860
  return subscribe$2(element, 'results', callback);
1875
1861
  }
1876
1862
  /**
1877
- * Adds an observer for when {@link InteractElement.state | element state}
1878
- * 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
1879
1868
  */
1880
1869
  function onElementStateChanged(element, callback) {
1881
1870
  return subscribe$2(element, 'state', callback);
1882
1871
  }
1883
1872
  /**
1884
- * Adds an observer for when {@link InteractElement.fields | element's data}
1885
- * 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
1886
1878
  */
1887
1879
  function onElementUpdated(event, callback) {
1888
1880
  configureEvent(event);
1889
1881
  return subscribe$2(event, 'update', callback);
1890
1882
  }
1891
1883
  /**
1892
- * 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
1893
1888
  */
1894
1889
  function onElementPublished(event, callback) {
1895
1890
  configureEvent(event);
@@ -1900,7 +1895,10 @@ function onElementPublished(event, callback) {
1900
1895
  });
1901
1896
  }
1902
1897
  /**
1903
- * 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
1904
1902
  */
1905
1903
  function onElementRevoked(event, callback) {
1906
1904
  configureEvent(event);
@@ -2057,5 +2055,5 @@ function onPresenceCounterClose(presenceCounter, callback) {
2057
2055
  return () => presenceCounter.off('state', handler);
2058
2056
  }
2059
2057
 
2060
- 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, login, onConnectionHealthState, onElementPublished, onElementResults, onElementRevoked, onElementStateChanged, onElementUpdated, onEventAdded, onEventPublished, onEventRemoved, onEventState, onEventUpdated, onPresenceCounterClose, onPresenceCounterOpen, onPresenceCounterUpdate, onProjectFieldsUpdated, onProjectListingsUpdated, validateAnswer };
2061
- //# 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