@gyldendalas/gyldendal-divine-api 0.2.3 → 0.2.6

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 CHANGED
@@ -1022,6 +1022,279 @@ var AIBotService = class extends base_service_default {
1022
1022
  }
1023
1023
  };
1024
1024
 
1025
+ // src/services/quiz_service.ts
1026
+ var ApiErrors = /* @__PURE__ */ ((ApiErrors2) => {
1027
+ ApiErrors2["OVERVIEW_NOT_FOUND"] = "Quiz overview not found";
1028
+ ApiErrors2["NOT_FOUND"] = "Quiz not found";
1029
+ ApiErrors2["ARCHIVED"] = "This shared quiz session is archived";
1030
+ ApiErrors2["GALE_USER_DATA_CLIENT_ERROR"] = "Failed to fetch Gale user data: Client error";
1031
+ return ApiErrors2;
1032
+ })(ApiErrors || {});
1033
+ var QuizService = class extends base_service_default {
1034
+ discoverUrlPrefix() {
1035
+ switch (this.environment) {
1036
+ case "production":
1037
+ return "https://api.iquiz.dk/api";
1038
+ case "development":
1039
+ case "local":
1040
+ case "testing":
1041
+ return "https://galecms.test.tibalo.dk/api";
1042
+ case "test":
1043
+ return `https://localhost:3010/galeapi/api`;
1044
+ default:
1045
+ throw new Error(`Unknown environment: ${this.environment}`);
1046
+ }
1047
+ }
1048
+ makeHeaders(extra) {
1049
+ const headers = new Headers();
1050
+ headers.append("Content-Type", "application/json");
1051
+ if (extra) {
1052
+ for (const [key, val] of Object.entries(extra)) {
1053
+ headers.append(key, val);
1054
+ }
1055
+ }
1056
+ return headers;
1057
+ }
1058
+ // ─────────────────────────────────────────────────────────────
1059
+ // Legacy Gale quizzes
1060
+ // ─────────────────────────────────────────────────────────────
1061
+ async checkActiveSession({
1062
+ isbn,
1063
+ quizNumber,
1064
+ extraHeaders,
1065
+ timeout = 3e3
1066
+ }) {
1067
+ const url = `${this.getUrlPrefix()}/isbn/${isbn}/quiz/${quizNumber}`;
1068
+ const headers = this.makeHeaders(extraHeaders);
1069
+ const res = await this.getAsync({ url, headers, timeout });
1070
+ return await res.json();
1071
+ }
1072
+ async startQuiz({
1073
+ isbn,
1074
+ quiz,
1075
+ shared,
1076
+ extraHeaders,
1077
+ timeout = 3e3
1078
+ }) {
1079
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quiz}` : `${this.getUrlPrefix()}/isbn/${isbn}/quiz/${quiz}`;
1080
+ const headers = this.makeHeaders(extraHeaders);
1081
+ const res = await this.postAsync({ url, headers, body: "{}", timeout });
1082
+ return await res.json();
1083
+ }
1084
+ async getProblems({
1085
+ isbn,
1086
+ quizUnitId,
1087
+ shared,
1088
+ extraHeaders,
1089
+ timeout = 3e3
1090
+ }) {
1091
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1092
+ const headers = this.makeHeaders(extraHeaders);
1093
+ const res = await this.getAsync({ url, headers, timeout });
1094
+ return await res.json();
1095
+ }
1096
+ async resetAnswer({
1097
+ isbn,
1098
+ quizUnitId,
1099
+ questionID,
1100
+ extraHeaders,
1101
+ timeout = 3e3
1102
+ }) {
1103
+ const url = `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}/question/${questionID}`;
1104
+ const headers = this.makeHeaders(extraHeaders);
1105
+ const res = await this.putAsync({
1106
+ url,
1107
+ headers,
1108
+ body: JSON.stringify({}),
1109
+ timeout
1110
+ });
1111
+ return await res.json();
1112
+ }
1113
+ async saveAnswer({
1114
+ isbn,
1115
+ quizUnitId,
1116
+ answer,
1117
+ shared,
1118
+ extraHeaders,
1119
+ timeout = 3e3
1120
+ }) {
1121
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1122
+ const headers = this.makeHeaders(extraHeaders);
1123
+ const res = await this.putAsync({
1124
+ url,
1125
+ headers,
1126
+ body: JSON.stringify(answer),
1127
+ timeout
1128
+ });
1129
+ return await res.json();
1130
+ }
1131
+ async finishQuiz({
1132
+ isbn,
1133
+ quizUnitId,
1134
+ shared,
1135
+ extraHeaders,
1136
+ timeout = 3e3
1137
+ }) {
1138
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}/finish` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1139
+ const headers = this.makeHeaders(extraHeaders);
1140
+ const res = await this.postAsync({
1141
+ url,
1142
+ headers,
1143
+ body: JSON.stringify({}),
1144
+ timeout
1145
+ });
1146
+ return await res.json();
1147
+ }
1148
+ async getResults({
1149
+ isbn,
1150
+ quizUnitId,
1151
+ shared,
1152
+ extraHeaders,
1153
+ timeout = 3e3
1154
+ }) {
1155
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}/result` : `${this.getUrlPrefix()}/isbn/${isbn}/student/overview/${quizUnitId}`;
1156
+ const headers = this.makeHeaders(extraHeaders);
1157
+ const res = await this.getAsync({ url, headers, timeout });
1158
+ return await res.json();
1159
+ }
1160
+ // ─────────────────────────────────────────────────────────────
1161
+ // Shared quizzes
1162
+ // ─────────────────────────────────────────────────────────────
1163
+ async createSharedQuiz({
1164
+ quizData,
1165
+ extraHeaders,
1166
+ timeout = 3e3
1167
+ }) {
1168
+ const url = `${this.getUrlPrefix()}/shared/quiz`;
1169
+ const headers = this.makeHeaders(extraHeaders);
1170
+ const res = await this.postAsync({
1171
+ url,
1172
+ headers,
1173
+ body: JSON.stringify(quizData),
1174
+ timeout
1175
+ });
1176
+ return await res.json();
1177
+ }
1178
+ async copyEditSharedQuiz({
1179
+ quizSessionId,
1180
+ quizData,
1181
+ action,
1182
+ extraHeaders,
1183
+ timeout = 3e3
1184
+ }) {
1185
+ const url = `${this.getUrlPrefix()}/shared/quiz/${quizSessionId}`;
1186
+ const method = action === "edit" ? "PUT" : "POST";
1187
+ const headers = this.makeHeaders(extraHeaders);
1188
+ const res = method === "PUT" ? await this.putAsync({
1189
+ url,
1190
+ headers,
1191
+ body: JSON.stringify(quizData),
1192
+ timeout
1193
+ }) : await this.postAsync({
1194
+ url,
1195
+ headers,
1196
+ body: JSON.stringify(quizData),
1197
+ timeout
1198
+ });
1199
+ return await res.json();
1200
+ }
1201
+ async getTeachersQuizProblems({
1202
+ quizSessionId,
1203
+ extraHeaders,
1204
+ timeout = 3e3
1205
+ }) {
1206
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/problems`;
1207
+ const headers = this.makeHeaders(extraHeaders);
1208
+ const res = await this.getAsync({ url, headers, timeout });
1209
+ return await res.json();
1210
+ }
1211
+ async getTeachersUnitOverview({
1212
+ quizSessionId,
1213
+ quizUnitId,
1214
+ extraHeaders,
1215
+ timeout = 3e3
1216
+ }) {
1217
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/units/${quizUnitId}`;
1218
+ const headers = this.makeHeaders(extraHeaders);
1219
+ const res = await this.getAsync({ url, headers, timeout });
1220
+ return await res.json();
1221
+ }
1222
+ async activateDeactivateQuestion({
1223
+ quizSessionId,
1224
+ questionId,
1225
+ activate,
1226
+ extraHeaders,
1227
+ timeout = 3e3
1228
+ }) {
1229
+ const url = `${this.getUrlPrefix()}/shared/teacher/quiz/${quizSessionId}/question/${questionId}`;
1230
+ const method = activate ? "PATCH" : "DELETE";
1231
+ const headers = this.makeHeaders(extraHeaders);
1232
+ const res = method === "PATCH" ? await this.postAsync({
1233
+ url,
1234
+ headers,
1235
+ body: null,
1236
+ timeout
1237
+ }) : await this.deleteAsync({ url, headers, timeout });
1238
+ return await res.json();
1239
+ }
1240
+ async getTeachersQuizzes({
1241
+ extraHeaders,
1242
+ timeout = 3e3
1243
+ }) {
1244
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes`;
1245
+ const headers = this.makeHeaders(extraHeaders);
1246
+ const res = await this.getAsync({ url, headers, timeout });
1247
+ return await res.json();
1248
+ }
1249
+ async getStudentsQuizzes({
1250
+ extraHeaders,
1251
+ timeout = 3e3
1252
+ }) {
1253
+ const url = `${this.getUrlPrefix()}/shared/student/quizzes`;
1254
+ const headers = this.makeHeaders(extraHeaders);
1255
+ const res = await this.getAsync({ url, headers, timeout });
1256
+ return await res.json();
1257
+ }
1258
+ async getTeachersQuiz({
1259
+ quizSessionId,
1260
+ extraHeaders,
1261
+ timeout = 3e3
1262
+ }) {
1263
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}`;
1264
+ const headers = this.makeHeaders(extraHeaders);
1265
+ const res = await this.getAsync({ url, headers, timeout });
1266
+ return await res.json();
1267
+ }
1268
+ async toggleArchiveQuiz({
1269
+ quizSessionId,
1270
+ archive,
1271
+ extraHeaders,
1272
+ timeout = 3e3
1273
+ }) {
1274
+ const url = `${this.getUrlPrefix()}/shared/quiz/${quizSessionId}`;
1275
+ const method = archive ? "DELETE" : "PATCH";
1276
+ const headers = this.makeHeaders(extraHeaders);
1277
+ const res = method === "DELETE" ? await this.deleteAsync({ url, headers, timeout }) : await this.postAsync({
1278
+ url,
1279
+ headers,
1280
+ body: null,
1281
+ timeout
1282
+ });
1283
+ return await res.json();
1284
+ }
1285
+ async deleteSharedQuizUnit({
1286
+ quizSessionId,
1287
+ quizUnitId,
1288
+ extraHeaders,
1289
+ timeout = 3e3
1290
+ }) {
1291
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/units/${quizUnitId}`;
1292
+ const headers = this.makeHeaders(extraHeaders);
1293
+ const res = await this.deleteAsync({ url, headers, timeout });
1294
+ return await res.json();
1295
+ }
1296
+ };
1297
+
1025
1298
  // src/services/writing_task_service.ts
1026
1299
  var WritingTaskService = class extends base_service_default {
1027
1300
  discoverUrlPrefix() {
@@ -1059,11 +1332,13 @@ var SolrProxyService = class extends base_service_default {
1059
1332
  };
1060
1333
  export {
1061
1334
  AIBotService,
1335
+ ApiErrors,
1062
1336
  CookieConsentLog,
1063
1337
  HighlightResultType,
1064
1338
  HighlightService,
1065
1339
  PdfGeneratorService,
1066
1340
  PollyService,
1341
+ QuizService,
1067
1342
  SSMLSpeechSpeeds,
1068
1343
  SolrProxyService,
1069
1344
  TaggingService,