@speakableio/core 0.1.21 → 0.1.22

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.mjs CHANGED
@@ -1,5 +1,37 @@
1
1
  // src/providers/SpeakableProvider.tsx
2
2
  import { createContext, useContext, useEffect, useState } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var FsCtx = createContext(null);
5
+ function SpeakableProvider({
6
+ user,
7
+ children,
8
+ queryClient,
9
+ permissions,
10
+ fsClient
11
+ }) {
12
+ const [speakableApi, setSpeakableApi] = useState(null);
13
+ useEffect(() => {
14
+ setSpeakableApi(fsClient);
15
+ }, [fsClient]);
16
+ if (!speakableApi) return null;
17
+ return /* @__PURE__ */ jsx(
18
+ FsCtx.Provider,
19
+ {
20
+ value: {
21
+ speakableApi,
22
+ queryClient,
23
+ user,
24
+ permissions
25
+ },
26
+ children
27
+ }
28
+ );
29
+ }
30
+ function useSpeakableApi() {
31
+ const ctx = useContext(FsCtx);
32
+ if (!ctx) throw new Error("useSpeakableApi must be used within a SpeakableProvider");
33
+ return ctx;
34
+ }
3
35
 
4
36
  // src/utils/error-handler.ts
5
37
  var ServiceError = class extends Error {
@@ -55,10 +87,12 @@ var FirebaseAPI = class _FirebaseAPI {
55
87
  return this.config.helpers;
56
88
  }
57
89
  httpsCallable(functionName) {
58
- return this.config?.httpsCallable(functionName);
90
+ var _a;
91
+ return (_a = this.config) == null ? void 0 : _a.httpsCallable(functionName);
59
92
  }
60
93
  logEvent(name, data) {
61
- this.config?.logEvent(name, data);
94
+ var _a;
95
+ (_a = this.config) == null ? void 0 : _a.logEvent(name, data);
62
96
  }
63
97
  accessQueryConstraints() {
64
98
  const { query, orderBy, limit, startAt, startAfter, endAt, endBefore } = this.helpers;
@@ -233,12 +267,13 @@ var _attachScoresAssignment = async ({
233
267
  return acc;
234
268
  }, {});
235
269
  const assignmentsWithScores = assignments.map((a) => {
270
+ var _a;
236
271
  return {
237
272
  ...a,
238
273
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/ban-ts-comment
239
274
  // @ts-ignore
240
275
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
241
- scores: scoresObject[a.id] ?? null
276
+ scores: (_a = scoresObject[a.id]) != null ? _a : null
242
277
  };
243
278
  });
244
279
  return assignmentsWithScores;
@@ -267,6 +302,7 @@ var checkAssignmentAvailability = (scheduledTime) => {
267
302
 
268
303
  // src/domains/assignment/services/get-assignment.service.ts
269
304
  async function _getAssignment(params) {
305
+ var _a;
270
306
  const path = refsAssignmentFiresotre.assignment({ id: params.assignmentId });
271
307
  const response = await api.getDoc(path);
272
308
  if (!response.data) return null;
@@ -276,7 +312,7 @@ async function _getAssignment(params) {
276
312
  ...assignment,
277
313
  isAvailable,
278
314
  id: params.assignmentId,
279
- scheduledTime: assignment.scheduledTime ?? null
315
+ scheduledTime: (_a = assignment.scheduledTime) != null ? _a : null
280
316
  };
281
317
  if (params.analyticType) {
282
318
  const assignmentsWithScores = await attachScoresAssignment({
@@ -498,7 +534,7 @@ var purify = (word) => {
498
534
  return word.normalize("NFD").replace(/\/([^" "]*)/g, "").replace(/\([^()]*\)/g, "").replace(/([^()]*)/g, "").replace(/[\u0300-\u036f]/g, "").replace(/[-]/g, " ").replace(/[.,/#!¡¿?؟。,.?$%^&*;:{}=\-_`~()’'…\s]/g, "").replace(/\s\s+/g, " ").toLowerCase().trim();
499
535
  };
500
536
  var cleanString = (words) => {
501
- const splitWords = words?.split("+");
537
+ const splitWords = words == null ? void 0 : words.split("+");
502
538
  if (splitWords && splitWords.length === 1) {
503
539
  const newWord = purify(words);
504
540
  return newWord;
@@ -519,7 +555,7 @@ var getWordHash = (word, language) => {
519
555
  // src/domains/cards/services/get-card-verification-status.service.ts
520
556
  var charactarLanguages = ["zh", "ja", "ko"];
521
557
  var getVerificationStatus = async (target_text, language) => {
522
- if (target_text?.length < 3 && !charactarLanguages.includes(language)) {
558
+ if ((target_text == null ? void 0 : target_text.length) < 3 && !charactarLanguages.includes(language)) {
523
559
  return "NOT_RECOMMENDED" /* NOT_RECOMMENDED */;
524
560
  }
525
561
  const hash = getWordHash(target_text, language);
@@ -758,11 +794,12 @@ var SpeakableFirebaseFunctions = {
758
794
 
759
795
  // src/domains/notification/services/send-notification.service.ts
760
796
  var _sendNotification = async (sendTo, notification) => {
761
- const results = await SpeakableFirebaseFunctions.createNotification?.({
797
+ var _a, _b;
798
+ const results = await ((_b = (_a = SpeakableFirebaseFunctions).createNotification) == null ? void 0 : _b.call(_a, {
762
799
  sendTo,
763
800
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
764
801
  notification
765
- });
802
+ }));
766
803
  return results;
767
804
  };
768
805
  var sendNotification = withErrorHandler(_sendNotification, "sendNotification");
@@ -828,6 +865,7 @@ var createNewAssignmentNotification = async ({
828
865
  data,
829
866
  profile
830
867
  }) => {
868
+ var _a;
831
869
  const { assignment, sendTo } = data;
832
870
  const teacherName = profile.displayName || "Your teacher";
833
871
  const dueDate = assignment.dueDateTimestamp ? dayjs2(assignment.dueDateTimestamp.toDate()).format("MMM Do") : null;
@@ -838,7 +876,7 @@ var createNewAssignmentNotification = async ({
838
876
  link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
839
877
  messagePreview: `A new assignment "${assignment.name}" is now available. ${dueDate ? `Due ${dueDate}` : ""}`,
840
878
  title: "New Assignment Available!",
841
- imageUrl: profile.image?.url
879
+ imageUrl: (_a = profile.image) == null ? void 0 : _a.url
842
880
  });
843
881
  return results;
844
882
  };
@@ -847,6 +885,7 @@ var createAssessmentSubmissionNotification = async ({
847
885
  profile,
848
886
  userId
849
887
  }) => {
888
+ var _a;
850
889
  const studentName = profile.displayName || "Your student";
851
890
  const results = await sendNotification(assignment.owners, {
852
891
  courseId: assignment.courseId,
@@ -855,7 +894,7 @@ var createAssessmentSubmissionNotification = async ({
855
894
  title: `Assessment Submitted!`,
856
895
  senderName: studentName,
857
896
  messagePreview: `${studentName} has submitted the assessment "${assignment.name}"`,
858
- imageUrl: profile.image?.url
897
+ imageUrl: (_a = profile.image) == null ? void 0 : _a.url
859
898
  });
860
899
  return results;
861
900
  };
@@ -863,6 +902,7 @@ var createAssessmentScoredNotification = async ({
863
902
  data,
864
903
  profile
865
904
  }) => {
905
+ var _a, _b, _c, _d;
866
906
  const { assignment, sendTo } = data;
867
907
  const teacherName = profile.displayName || "Your teacher";
868
908
  const title = `${assignment.isAssessment ? "Assessment" : "Assignment"} Reviewed!`;
@@ -873,16 +913,16 @@ var createAssessmentScoredNotification = async ({
873
913
  link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
874
914
  title,
875
915
  messagePreview,
876
- imageUrl: profile.image?.url,
916
+ imageUrl: (_a = profile.image) == null ? void 0 : _a.url,
877
917
  senderName: teacherName
878
918
  });
879
- await SpeakableFirebaseFunctions.sendAssessmentScoredEmail?.({
919
+ await ((_d = (_c = SpeakableFirebaseFunctions).sendAssessmentScoredEmail) == null ? void 0 : _d.call(_c, {
880
920
  assessmentTitle: assignment.name,
881
921
  link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
882
- senderImage: profile.image?.url || "",
922
+ senderImage: ((_b = profile.image) == null ? void 0 : _b.url) || "",
883
923
  studentId: sendTo[0],
884
924
  teacherName: profile.displayName
885
- });
925
+ }));
886
926
  return results;
887
927
  };
888
928
 
@@ -894,14 +934,15 @@ var notificationQueryKeys = {
894
934
  var useCreateNotification = () => {
895
935
  const { user, queryClient } = useSpeakableApi();
896
936
  const handleCreateNotifications = async (type, data) => {
937
+ var _a, _b;
897
938
  const result = await createNotification({
898
939
  type,
899
940
  userId: user.auth.uid,
900
- profile: user?.profile ?? {},
941
+ profile: (_a = user == null ? void 0 : user.profile) != null ? _a : {},
901
942
  data
902
943
  });
903
944
  queryClient.invalidateQueries({
904
- queryKey: notificationQueryKeys.byId(user?.auth.uid ?? "")
945
+ queryKey: notificationQueryKeys.byId((_b = user == null ? void 0 : user.auth.uid) != null ? _b : "")
905
946
  });
906
947
  return result;
907
948
  };
@@ -911,14 +952,13 @@ var useCreateNotification = () => {
911
952
  };
912
953
 
913
954
  // src/lib/create-firebase-client.ts
914
- async function createFsClient({
955
+ function createFsClientBase({
915
956
  db,
916
- platform,
957
+ helpers,
917
958
  httpsCallable,
918
959
  logEvent
919
960
  }) {
920
961
  const dbAsFirestore = db;
921
- const helpers = platform === "web" ? await import("firebase/firestore") : await import("@react-native-firebase/firestore");
922
962
  api.initialize({
923
963
  db: dbAsFirestore,
924
964
  helpers,
@@ -931,50 +971,6 @@ async function createFsClient({
931
971
  };
932
972
  }
933
973
 
934
- // src/providers/SpeakableProvider.tsx
935
- import { jsx } from "react/jsx-runtime";
936
- var FsCtx = createContext(null);
937
- function SpeakableProvider({
938
- db,
939
- platform,
940
- children,
941
- queryClient,
942
- user,
943
- permissions,
944
- httpsCallable,
945
- logEvent
946
- }) {
947
- const [speakableApi, setSpeakableApi] = useState(null);
948
- useEffect(() => {
949
- createFsClient({
950
- db,
951
- httpsCallable,
952
- platform,
953
- logEvent
954
- }).then((repos) => {
955
- setSpeakableApi(repos);
956
- });
957
- }, [db, platform, httpsCallable]);
958
- if (!speakableApi) return null;
959
- return /* @__PURE__ */ jsx(
960
- FsCtx.Provider,
961
- {
962
- value: {
963
- speakableApi,
964
- queryClient,
965
- user,
966
- permissions
967
- },
968
- children
969
- }
970
- );
971
- }
972
- function useSpeakableApi() {
973
- const ctx = useContext(FsCtx);
974
- if (!ctx) throw new Error("useSpeakableApi must be used within a SpeakableProvider");
975
- return ctx;
976
- }
977
-
978
974
  // src/domains/assignment/hooks/score-hooks.ts
979
975
  import { useMutation as useMutation2, useQuery as useQuery3 } from "@tanstack/react-query";
980
976
 
@@ -1173,7 +1169,10 @@ var SpeakablePlanHierarchy = [
1173
1169
  // src/hooks/usePermissions.ts
1174
1170
  var usePermissions = () => {
1175
1171
  const { permissions } = useSpeakableApi();
1176
- const has = (permission) => permissions.permissions?.includes(permission);
1172
+ const has = (permission) => {
1173
+ var _a;
1174
+ return (_a = permissions.permissions) == null ? void 0 : _a.includes(permission);
1175
+ };
1177
1176
  return {
1178
1177
  plan: permissions.plan,
1179
1178
  permissionsLoaded: permissions.loaded,
@@ -1203,6 +1202,7 @@ var useGoogleClassroom = () => {
1203
1202
  googleUserId = null
1204
1203
  // optional to override the user's googleUserId
1205
1204
  }) => {
1205
+ var _a, _b;
1206
1206
  try {
1207
1207
  const { googleClassroomUserId = null } = scores;
1208
1208
  const googleId = googleUserId || googleClassroomUserId;
@@ -1212,14 +1212,14 @@ var useGoogleClassroom = () => {
1212
1212
  message: "No Google Classroom ID found"
1213
1213
  };
1214
1214
  const { courseWorkId, maxPoints, owners, courseId } = assignment;
1215
- const draftGrade = scores?.score ? scores?.score / 100 * maxPoints : 0;
1216
- const result = await SpeakableFirebaseFunctions.submitAssignmentToGoogleClassroomV2?.({
1215
+ const draftGrade = (scores == null ? void 0 : scores.score) ? (scores == null ? void 0 : scores.score) / 100 * maxPoints : 0;
1216
+ const result = await ((_b = (_a = SpeakableFirebaseFunctions).submitAssignmentToGoogleClassroomV2) == null ? void 0 : _b.call(_a, {
1217
1217
  teacherId: owners[0],
1218
1218
  courseId,
1219
1219
  courseWorkId,
1220
1220
  userId: googleId,
1221
1221
  draftGrade
1222
- });
1222
+ }));
1223
1223
  return result;
1224
1224
  } catch (error) {
1225
1225
  return { error: true, message: error.message };
@@ -1232,8 +1232,9 @@ var useGoogleClassroom = () => {
1232
1232
 
1233
1233
  // src/lib/firebase/firebase-analytics/grading-standard.ts
1234
1234
  var logGradingStandardLog = (data) => {
1235
+ var _a, _b;
1235
1236
  if (data.courseId && data.type && data.level) {
1236
- SpeakableFirebaseFunctions.updateCourseAnalytics?.({
1237
+ (_b = (_a = SpeakableFirebaseFunctions).updateCourseAnalytics) == null ? void 0 : _b.call(_a, {
1237
1238
  eventType: data.type || "custom",
1238
1239
  level: data.level,
1239
1240
  courseId: data.courseId
@@ -1269,15 +1270,17 @@ var logOpenActivityPreview = (data = {}) => {
1269
1270
  api.logEvent("open_activity_preview", data);
1270
1271
  };
1271
1272
  var logSubmitAssignment = (data = {}) => {
1272
- SpeakableFirebaseFunctions.updateCourseAnalytics?.({
1273
+ var _a, _b;
1274
+ (_b = (_a = SpeakableFirebaseFunctions).updateCourseAnalytics) == null ? void 0 : _b.call(_a, {
1273
1275
  eventType: ANALYTICS_EVENT_TYPES.SUBMISSION,
1274
1276
  ...data
1275
1277
  });
1276
1278
  api.logEvent(ANALYTICS_EVENT_TYPES.SUBMISSION, data);
1277
1279
  };
1278
1280
  var logStartAssignment = (data = {}) => {
1281
+ var _a, _b;
1279
1282
  if (data.courseId) {
1280
- SpeakableFirebaseFunctions.updateCourseAnalytics?.({
1283
+ (_b = (_a = SpeakableFirebaseFunctions).updateCourseAnalytics) == null ? void 0 : _b.call(_a, {
1281
1284
  eventType: ANALYTICS_EVENT_TYPES.ASSIGNMENT_STARTED,
1282
1285
  ...data
1283
1286
  });
@@ -1318,17 +1321,18 @@ var refsScoresPractice = {
1318
1321
 
1319
1322
  // src/domains/assignment/services/create-score.service.ts
1320
1323
  async function _createScore(params) {
1324
+ var _a, _b;
1321
1325
  if (params.isAssignment) {
1322
1326
  const ref = refsAssignmentFiresotre.assignmentScores({
1323
1327
  id: params.activityId,
1324
1328
  userId: params.userId
1325
1329
  });
1326
- await SpeakableFirebaseFunctions.updateAssignmentGradebookStatus?.({
1330
+ await ((_b = (_a = SpeakableFirebaseFunctions).updateAssignmentGradebookStatus) == null ? void 0 : _b.call(_a, {
1327
1331
  assignmentId: params.activityId,
1328
1332
  userId: params.userId,
1329
1333
  status: "IN_PROGRESS",
1330
1334
  score: null
1331
- });
1335
+ }));
1332
1336
  await api.setDoc(ref, params.scoreData, { merge: true });
1333
1337
  return {
1334
1338
  id: params.userId
@@ -1429,15 +1433,16 @@ var getScore = withErrorHandler(_getScore, "getScore");
1429
1433
  // src/domains/assignment/utils/calculateScoreAndProgress.ts
1430
1434
  var calculateScoreAndProgress = (scores, cardsList, weights) => {
1431
1435
  const totalSetPoints = cardsList.reduce((acc, cardId) => {
1432
- acc += weights?.[cardId] || 1;
1436
+ acc += (weights == null ? void 0 : weights[cardId]) || 1;
1433
1437
  return acc;
1434
1438
  }, 0);
1435
- const totalPointsAwarded = Object.keys(scores?.cards || {}).reduce((acc, cardId) => {
1436
- const cardScores = scores?.cards?.[cardId];
1437
- if (cardScores?.completed || cardScores?.score || cardScores?.score === 0) {
1438
- const score2 = cardScores?.score || cardScores?.score === 0 ? Number(cardScores?.score ?? 0) : null;
1439
- const weight = weights?.[cardId] || 1;
1440
- const fraction = (score2 ?? 0) / 100;
1439
+ const totalPointsAwarded = Object.keys((scores == null ? void 0 : scores.cards) || {}).reduce((acc, cardId) => {
1440
+ var _a, _b;
1441
+ const cardScores = (_a = scores == null ? void 0 : scores.cards) == null ? void 0 : _a[cardId];
1442
+ if ((cardScores == null ? void 0 : cardScores.completed) || (cardScores == null ? void 0 : cardScores.score) || (cardScores == null ? void 0 : cardScores.score) === 0) {
1443
+ const score2 = (cardScores == null ? void 0 : cardScores.score) || (cardScores == null ? void 0 : cardScores.score) === 0 ? Number((_b = cardScores == null ? void 0 : cardScores.score) != null ? _b : 0) : null;
1444
+ const weight = (weights == null ? void 0 : weights[cardId]) || 1;
1445
+ const fraction = (score2 != null ? score2 : 0) / 100;
1441
1446
  if (score2 || score2 === 0) {
1442
1447
  acc += weight * fraction;
1443
1448
  } else {
@@ -1446,9 +1451,10 @@ var calculateScoreAndProgress = (scores, cardsList, weights) => {
1446
1451
  }
1447
1452
  return acc;
1448
1453
  }, 0);
1449
- const totalCompletedCards = Object.keys(scores?.cards || {}).reduce((acc, cardId) => {
1450
- const cardScores = scores?.cards?.[cardId];
1451
- if (cardScores?.completed || cardScores?.score || cardScores?.score === 0) {
1454
+ const totalCompletedCards = Object.keys((scores == null ? void 0 : scores.cards) || {}).reduce((acc, cardId) => {
1455
+ var _a;
1456
+ const cardScores = (_a = scores == null ? void 0 : scores.cards) == null ? void 0 : _a[cardId];
1457
+ if ((cardScores == null ? void 0 : cardScores.completed) || (cardScores == null ? void 0 : cardScores.score) || (cardScores == null ? void 0 : cardScores.score) === 0) {
1452
1458
  acc += 1;
1453
1459
  }
1454
1460
  return acc;
@@ -1504,21 +1510,22 @@ var updateCardScore = withErrorHandler(_updateCardScore, "updateCardScore");
1504
1510
  // src/domains/assignment/services/clear-score.service.ts
1505
1511
  import dayjs3 from "dayjs";
1506
1512
  async function clearScore(params) {
1513
+ var _a, _b, _c, _d, _e;
1507
1514
  const update = {
1508
1515
  [`cards.${params.cardId}`]: {
1509
- attempts: params.cardScores.attempts ?? 1,
1510
- correct: params.cardScores.correct ?? 0,
1516
+ attempts: (_a = params.cardScores.attempts) != null ? _a : 1,
1517
+ correct: (_b = params.cardScores.correct) != null ? _b : 0,
1511
1518
  // save old score history
1512
1519
  history: [
1513
1520
  {
1514
1521
  ...params.cardScores,
1515
- attempts: params.cardScores.attempts ?? 1,
1516
- correct: params.cardScores.correct ?? 0,
1522
+ attempts: (_c = params.cardScores.attempts) != null ? _c : 1,
1523
+ correct: (_d = params.cardScores.correct) != null ? _d : 0,
1517
1524
  retryTime: dayjs3().format("YYYY-MM-DD HH:mm:ss"),
1518
1525
  history: null
1519
1526
  },
1520
1527
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1521
- ...params.cardScores.history ?? []
1528
+ ...(_e = params.cardScores.history) != null ? _e : []
1522
1529
  ]
1523
1530
  }
1524
1531
  };
@@ -1575,6 +1582,7 @@ var submitAssignmentScore = withErrorHandler(
1575
1582
  "submitAssignmentScore"
1576
1583
  );
1577
1584
  async function handleAssessment(assignment, userId, cardIds, setWeights, fieldsUpdated, studentName) {
1585
+ var _a, _b;
1578
1586
  const path = refsAssignmentFiresotre.assignmentScores({ id: assignment.id, userId });
1579
1587
  const response = await api.getDoc(path);
1580
1588
  if (!response.data) {
@@ -1582,21 +1590,22 @@ async function handleAssessment(assignment, userId, cardIds, setWeights, fieldsU
1582
1590
  }
1583
1591
  const { score: scoreCalculated } = calculateScoreAndProgress_default(response.data, cardIds, setWeights);
1584
1592
  await api.updateDoc(path, { score: scoreCalculated, status: "PENDING_REVIEW" });
1585
- await SpeakableFirebaseFunctions.submitAssessment?.({
1593
+ await ((_b = (_a = SpeakableFirebaseFunctions).submitAssessment) == null ? void 0 : _b.call(_a, {
1586
1594
  assignmentId: assignment.id,
1587
1595
  assignmentTitle: assignment.name,
1588
1596
  userId,
1589
1597
  teacherId: assignment.owners[0],
1590
1598
  studentName
1591
- });
1599
+ }));
1592
1600
  fieldsUpdated.status = "PENDING_REVIEW";
1593
1601
  return { success: true, fieldsUpdated };
1594
1602
  }
1595
1603
  async function handleCourseAssignment(assignment, userId) {
1596
- await SpeakableFirebaseFunctions?.submitAssignmentV2?.({
1604
+ var _a, _b;
1605
+ await ((_b = (_a = SpeakableFirebaseFunctions) == null ? void 0 : _a.submitAssignmentV2) == null ? void 0 : _b.call(_a, {
1597
1606
  assignmentId: assignment.id,
1598
1607
  userId
1599
- });
1608
+ }));
1600
1609
  }
1601
1610
  async function submitPracticeScore({
1602
1611
  setId,
@@ -1658,7 +1667,7 @@ function useUpdateScore() {
1658
1667
  });
1659
1668
  },
1660
1669
  onError: (_, variables, context) => {
1661
- if (context?.previousData)
1670
+ if (context == null ? void 0 : context.previousData)
1662
1671
  queryClient.setQueryData(scoreQueryKeys.byId(variables.activityId), context.previousData);
1663
1672
  },
1664
1673
  onSettled: (_, err, variables) => {
@@ -1683,7 +1692,7 @@ function useUpdateCardScore({
1683
1692
  mutationFn: async ({ cardId, cardScore }) => {
1684
1693
  const previousScores = queryClient.getQueryData(queryKey);
1685
1694
  const { progress, score, newScoreUpdated, updatedCardScore } = getScoreUpdated({
1686
- previousScores: previousScores ?? {},
1695
+ previousScores: previousScores != null ? previousScores : {},
1687
1696
  cardId,
1688
1697
  set,
1689
1698
  cardScore
@@ -1734,22 +1743,23 @@ var getScoreUpdated = ({
1734
1743
  previousScores,
1735
1744
  set
1736
1745
  }) => {
1737
- const previousCard = previousScores.cards?.[cardId];
1746
+ var _a, _b, _c, _d;
1747
+ const previousCard = (_a = previousScores.cards) == null ? void 0 : _a[cardId];
1738
1748
  const newCardScore = {
1739
- ...previousCard ?? {},
1749
+ ...previousCard != null ? previousCard : {},
1740
1750
  ...cardScore
1741
1751
  };
1742
1752
  const newScores = {
1743
1753
  ...previousScores,
1744
1754
  cards: {
1745
- ...previousScores.cards ?? {},
1755
+ ...(_b = previousScores.cards) != null ? _b : {},
1746
1756
  [cardId]: newCardScore
1747
1757
  }
1748
1758
  };
1749
1759
  const { score, progress } = calculateScoreAndProgress_default(
1750
1760
  newScores,
1751
- set?.content ?? [],
1752
- set?.weights ?? {}
1761
+ (_c = set == null ? void 0 : set.content) != null ? _c : [],
1762
+ (_d = set == null ? void 0 : set.weights) != null ? _d : {}
1753
1763
  );
1754
1764
  return {
1755
1765
  newScoreUpdated: newScores,
@@ -1764,7 +1774,8 @@ var handleOptimisticScore = ({
1764
1774
  cardScore,
1765
1775
  set
1766
1776
  }) => {
1767
- let cards = { ...score?.cards ?? {} };
1777
+ var _a, _b, _c;
1778
+ let cards = { ...(_a = score == null ? void 0 : score.cards) != null ? _a : {} };
1768
1779
  cards = {
1769
1780
  ...cards,
1770
1781
  [cardId]: {
@@ -1775,11 +1786,11 @@ var handleOptimisticScore = ({
1775
1786
  const { score: scoreValue, progress } = calculateScoreAndProgress_default(
1776
1787
  // @ts-ignore
1777
1788
  {
1778
- ...score ?? {},
1789
+ ...score != null ? score : {},
1779
1790
  cards
1780
1791
  },
1781
- set?.content ?? [],
1782
- set?.weights ?? {}
1792
+ (_b = set == null ? void 0 : set.content) != null ? _b : [],
1793
+ (_c = set == null ? void 0 : set.weights) != null ? _c : {}
1783
1794
  );
1784
1795
  return { cards, score: scoreValue, progress };
1785
1796
  };
@@ -1788,8 +1799,9 @@ function useClearScore() {
1788
1799
  const mutation = useMutation2({
1789
1800
  mutationFn: clearScore,
1790
1801
  onSettled: (result) => {
1802
+ var _a;
1791
1803
  queryClient.invalidateQueries({
1792
- queryKey: scoreQueryKeys.byId(result?.activityId ?? "")
1804
+ queryKey: scoreQueryKeys.byId((_a = result == null ? void 0 : result.activityId) != null ? _a : "")
1793
1805
  });
1794
1806
  }
1795
1807
  });
@@ -1832,9 +1844,9 @@ function useSubmitAssignmentScore({
1832
1844
  if (assignment.isAssessment) {
1833
1845
  createNotification2(SpeakableNotificationTypes.ASSESSMENT_SUBMITTED, assignment);
1834
1846
  }
1835
- if (assignment?.id) {
1847
+ if (assignment == null ? void 0 : assignment.id) {
1836
1848
  logSubmitAssignment({
1837
- courseId: assignment?.courseId
1849
+ courseId: assignment == null ? void 0 : assignment.courseId
1838
1850
  });
1839
1851
  }
1840
1852
  onAssignmentSubmitted(assignment.id);
@@ -1938,6 +1950,7 @@ function useActivity({
1938
1950
  onAssignmentSubmitted,
1939
1951
  ltiData
1940
1952
  }) {
1953
+ var _a, _b, _c, _d;
1941
1954
  const { queryClient, user } = useSpeakableApi();
1942
1955
  const userId = user.auth.uid;
1943
1956
  const assignmentQuery = useAssignment({
@@ -1946,12 +1959,12 @@ function useActivity({
1946
1959
  enabled: isAssignment
1947
1960
  });
1948
1961
  const activeAssignment = assignmentQuery.data;
1949
- const setId = isAssignment ? activeAssignment?.setId ?? "" : id;
1962
+ const setId = isAssignment ? (_a = activeAssignment == null ? void 0 : activeAssignment.setId) != null ? _a : "" : id;
1950
1963
  const querySet = useSet({ setId });
1951
1964
  const setData = querySet.data;
1952
- const activityId = isAssignment ? activeAssignment?.id ?? "" : setId;
1965
+ const activityId = isAssignment ? (_b = activeAssignment == null ? void 0 : activeAssignment.id) != null ? _b : "" : setId;
1953
1966
  const { cardsObject, cardsQueries, cards } = useCards({
1954
- cardIds: setData?.content ?? [],
1967
+ cardIds: (_c = setData == null ? void 0 : setData.content) != null ? _c : [],
1955
1968
  enabled: querySet.isSuccess,
1956
1969
  asObject: true
1957
1970
  });
@@ -1959,7 +1972,7 @@ function useActivity({
1959
1972
  isAssignment,
1960
1973
  activityId: id,
1961
1974
  userId,
1962
- courseId: activeAssignment?.courseId,
1975
+ courseId: activeAssignment == null ? void 0 : activeAssignment.courseId,
1963
1976
  googleClassroomUserId: user.profile.googleClassroomUserId,
1964
1977
  enabled: isAssignment ? assignmentQuery.isSuccess : querySet.isSuccess
1965
1978
  });
@@ -1968,7 +1981,7 @@ function useActivity({
1968
1981
  activityId,
1969
1982
  isAssignment,
1970
1983
  userId,
1971
- set: querySet.data ?? void 0
1984
+ set: (_d = querySet.data) != null ? _d : void 0
1972
1985
  });
1973
1986
  const { mutationClearScore } = useClearScore();
1974
1987
  const { submitAssignmentScore: submitAssignmentScore2 } = useSubmitAssignmentScore({
@@ -1991,12 +2004,13 @@ function useActivity({
1991
2004
  cardId,
1992
2005
  wasCompleted = true
1993
2006
  }) => {
1994
- const currentCard = cardsObject?.[cardId];
1995
- if (currentCard?.type === "MULTIPLE_CHOICE" /* MULTIPLE_CHOICE */ || currentCard?.type === "READ_REPEAT" /* READ_REPEAT */) {
2007
+ var _a2, _b2;
2008
+ const currentCard = cardsObject == null ? void 0 : cardsObject[cardId];
2009
+ if ((currentCard == null ? void 0 : currentCard.type) === "MULTIPLE_CHOICE" /* MULTIPLE_CHOICE */ || (currentCard == null ? void 0 : currentCard.type) === "READ_REPEAT" /* READ_REPEAT */) {
1996
2010
  return;
1997
2011
  }
1998
2012
  const queryKeys = scoreQueryKeys.byId(activityId);
1999
- const activeCardScores = queryClient.getQueryData(queryKeys)?.cards?.[cardId];
2013
+ const activeCardScores = (_b2 = (_a2 = queryClient.getQueryData(queryKeys)) == null ? void 0 : _a2.cards) == null ? void 0 : _b2[cardId];
2000
2014
  if (activeCardScores === void 0) return;
2001
2015
  mutationClearScore.mutate({
2002
2016
  isAssignment,
@@ -2007,33 +2021,34 @@ function useActivity({
2007
2021
  });
2008
2022
  };
2009
2023
  const onSubmitScore = async () => {
2024
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l;
2010
2025
  try {
2011
2026
  let results;
2012
2027
  if (isAssignment) {
2013
- const cardScores = scoreQuery.data?.cards || {};
2028
+ const cardScores = ((_a2 = scoreQuery.data) == null ? void 0 : _a2.cards) || {};
2014
2029
  const hasPendingReview = Object.values(cardScores).some(
2015
2030
  (cardScore) => cardScore.status === "pending_review"
2016
2031
  );
2017
2032
  results = await submitAssignmentScore2({
2018
2033
  assignment: assignmentQuery.data,
2019
2034
  userId,
2020
- cardIds: setData?.content ?? [],
2035
+ cardIds: (_b2 = setData == null ? void 0 : setData.content) != null ? _b2 : [],
2021
2036
  scores: scoreQuery.data,
2022
- setWeights: setData?.weights ?? {},
2037
+ setWeights: (_c2 = setData == null ? void 0 : setData.weights) != null ? _c2 : {},
2023
2038
  status: hasPendingReview ? "PENDING_REVIEW" : "FINALIZED"
2024
2039
  });
2025
- if (assignmentQuery.data?.ltiDeeplink) {
2040
+ if ((_d2 = assignmentQuery.data) == null ? void 0 : _d2.ltiDeeplink) {
2026
2041
  submitLTIScore({
2027
- maxPoints: assignmentQuery.data?.maxPoints,
2028
- score: scoreQuery.data?.score ?? 0,
2029
- SERVICE_KEY: ltiData?.serviceKey ?? "",
2030
- lineItemId: ltiData?.lineItemId ?? "",
2031
- lti_id: ltiData?.lti_id ?? ""
2042
+ maxPoints: (_e = assignmentQuery.data) == null ? void 0 : _e.maxPoints,
2043
+ score: (_g = (_f = scoreQuery.data) == null ? void 0 : _f.score) != null ? _g : 0,
2044
+ SERVICE_KEY: (_h = ltiData == null ? void 0 : ltiData.serviceKey) != null ? _h : "",
2045
+ lineItemId: (_i = ltiData == null ? void 0 : ltiData.lineItemId) != null ? _i : "",
2046
+ lti_id: (_j = ltiData == null ? void 0 : ltiData.lti_id) != null ? _j : ""
2032
2047
  });
2033
2048
  }
2034
2049
  } else {
2035
2050
  results = await submitPracticeScore2({
2036
- setId: querySet.data?.id ?? "",
2051
+ setId: (_l = (_k = querySet.data) == null ? void 0 : _k.id) != null ? _l : "",
2037
2052
  userId,
2038
2053
  scores: scoreQuery.data
2039
2054
  });
@@ -2051,23 +2066,24 @@ function useActivity({
2051
2066
  gradingStandard,
2052
2067
  type
2053
2068
  }) => {
2054
- const card = cardsObject?.[cardId];
2069
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
2070
+ const card = cardsObject == null ? void 0 : cardsObject[cardId];
2055
2071
  const scoresObject = queryClient.getQueryData(scoreQueryKeys.byId(activityId));
2056
- const cardScore = scoresObject?.cards?.[cardId];
2072
+ const cardScore = (_a2 = scoresObject == null ? void 0 : scoresObject.cards) == null ? void 0 : _a2[cardId];
2057
2073
  const serverTimestamp = api.helpers.serverTimestamp;
2058
2074
  addGradingStandardLog(
2059
2075
  {
2060
- assignmentId: activeAssignment?.id ?? "",
2061
- courseId: activeAssignment?.courseId ?? "",
2062
- teacherId: activeAssignment?.owners[0] ?? "",
2063
- setId: setData?.id ?? "",
2076
+ assignmentId: (_b2 = activeAssignment == null ? void 0 : activeAssignment.id) != null ? _b2 : "",
2077
+ courseId: (_c2 = activeAssignment == null ? void 0 : activeAssignment.courseId) != null ? _c2 : "",
2078
+ teacherId: (_d2 = activeAssignment == null ? void 0 : activeAssignment.owners[0]) != null ? _d2 : "",
2079
+ setId: (_e = setData == null ? void 0 : setData.id) != null ? _e : "",
2064
2080
  cardId,
2065
2081
  level: gradingStandard.level,
2066
2082
  justification: gradingStandard.justification,
2067
- transcript: cardScore?.transcript ?? "",
2068
- audioUrl: cardScore?.audio ?? "",
2069
- prompt: card?.prompt ?? "",
2070
- responseType: card?.type === "RESPOND_WRITE" /* RESPOND_WRITE */ ? "written" : "spoken",
2083
+ transcript: (_f = cardScore == null ? void 0 : cardScore.transcript) != null ? _f : "",
2084
+ audioUrl: (_g = cardScore == null ? void 0 : cardScore.audio) != null ? _g : "",
2085
+ prompt: (_h = card == null ? void 0 : card.prompt) != null ? _h : "",
2086
+ responseType: (card == null ? void 0 : card.type) === "RESPOND_WRITE" /* RESPOND_WRITE */ ? "written" : "spoken",
2071
2087
  type,
2072
2088
  dateMade: serverTimestamp()
2073
2089
  },
@@ -2082,8 +2098,8 @@ function useActivity({
2082
2098
  }
2083
2099
  }, []);
2084
2100
  useInitActivity({
2085
- assignment: activeAssignment ?? void 0,
2086
- set: setData ?? void 0,
2101
+ assignment: activeAssignment != null ? activeAssignment : void 0,
2102
+ set: setData != null ? setData : void 0,
2087
2103
  enabled: !!setData,
2088
2104
  userId
2089
2105
  });
@@ -2122,31 +2138,32 @@ var useInitActivity = ({
2122
2138
  }) => {
2123
2139
  const { trackActivity } = useActivityTracker({ userId });
2124
2140
  const init = () => {
2141
+ var _a, _b, _c, _d, _e;
2125
2142
  if (!enabled) return;
2126
2143
  if (!assignment) {
2127
2144
  trackActivity({
2128
- activityName: set?.name ?? "",
2145
+ activityName: (_a = set == null ? void 0 : set.name) != null ? _a : "",
2129
2146
  activityType: "set",
2130
- id: set?.id,
2131
- language: set?.language
2147
+ id: set == null ? void 0 : set.id,
2148
+ language: set == null ? void 0 : set.language
2132
2149
  });
2133
2150
  } else if (assignment.name) {
2134
2151
  trackActivity({
2135
2152
  activityName: assignment.name,
2136
2153
  activityType: assignment.isAssessment ? "assessment" : "assignment",
2137
2154
  id: assignment.id,
2138
- language: set?.language
2155
+ language: set == null ? void 0 : set.language
2139
2156
  });
2140
2157
  }
2141
- if (set?.public) {
2142
- SpeakableFirebaseFunctions?.onSetOpened?.({
2158
+ if (set == null ? void 0 : set.public) {
2159
+ (_c = (_b = SpeakableFirebaseFunctions) == null ? void 0 : _b.onSetOpened) == null ? void 0 : _c.call(_b, {
2143
2160
  setId: set.id,
2144
2161
  language: set.language
2145
2162
  });
2146
2163
  }
2147
- SpeakableFirebaseFunctions?.updateAlgoliaIndex?.({
2164
+ (_e = (_d = SpeakableFirebaseFunctions) == null ? void 0 : _d.updateAlgoliaIndex) == null ? void 0 : _e.call(_d, {
2148
2165
  updatePlays: true,
2149
- objectID: set?.id
2166
+ objectID: set == null ? void 0 : set.id
2150
2167
  });
2151
2168
  };
2152
2169
  useEffect2(() => {
@@ -2160,12 +2177,13 @@ var submitLTIScore = async ({
2160
2177
  lineItemId,
2161
2178
  lti_id
2162
2179
  }) => {
2180
+ var _a, _b;
2163
2181
  try {
2164
2182
  if (!SERVICE_KEY || !lineItemId || !lti_id) {
2165
2183
  throw new Error("Missing required LTI credentials");
2166
2184
  }
2167
2185
  const earnedPoints = score ? score / 100 * maxPoints : 0;
2168
- const { data } = await SpeakableFirebaseFunctions?.submitLTIAssignmentScore?.({
2186
+ const { data } = await ((_b = (_a = SpeakableFirebaseFunctions) == null ? void 0 : _a.submitLTIAssignmentScore) == null ? void 0 : _b.call(_a, {
2169
2187
  SERVICE_KEY,
2170
2188
  scoreData: {
2171
2189
  lineItemId,
@@ -2173,7 +2191,7 @@ var submitLTIScore = async ({
2173
2191
  maxPoints,
2174
2192
  earnedPoints
2175
2193
  }
2176
- });
2194
+ }));
2177
2195
  return { success: true, data };
2178
2196
  } catch (error) {
2179
2197
  console.error("Failed to submit LTI score:", error);
@@ -2207,7 +2225,7 @@ export {
2207
2225
  cardsQueryKeys,
2208
2226
  createAssignmentRepo,
2209
2227
  createCardRepo,
2210
- createFsClient,
2228
+ createFsClientBase,
2211
2229
  createSetRepo,
2212
2230
  getCardFromCache,
2213
2231
  getSetFromCache,
@@ -2225,3 +2243,4 @@ export {
2225
2243
  useSet,
2226
2244
  useSpeakableApi
2227
2245
  };
2246
+ //# sourceMappingURL=index.mjs.map