@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.cjs CHANGED
@@ -21,11 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AIBotService: () => AIBotService,
24
+ ApiErrors: () => ApiErrors,
24
25
  CookieConsentLog: () => CookieConsentLog,
25
26
  HighlightResultType: () => HighlightResultType,
26
27
  HighlightService: () => HighlightService,
27
28
  PdfGeneratorService: () => PdfGeneratorService,
28
29
  PollyService: () => PollyService,
30
+ QuizService: () => QuizService,
29
31
  SSMLSpeechSpeeds: () => SSMLSpeechSpeeds,
30
32
  SolrProxyService: () => SolrProxyService,
31
33
  TaggingService: () => TaggingService,
@@ -1062,6 +1064,279 @@ var AIBotService = class extends base_service_default {
1062
1064
  }
1063
1065
  };
1064
1066
 
1067
+ // src/services/quiz_service.ts
1068
+ var ApiErrors = /* @__PURE__ */ ((ApiErrors2) => {
1069
+ ApiErrors2["OVERVIEW_NOT_FOUND"] = "Quiz overview not found";
1070
+ ApiErrors2["NOT_FOUND"] = "Quiz not found";
1071
+ ApiErrors2["ARCHIVED"] = "This shared quiz session is archived";
1072
+ ApiErrors2["GALE_USER_DATA_CLIENT_ERROR"] = "Failed to fetch Gale user data: Client error";
1073
+ return ApiErrors2;
1074
+ })(ApiErrors || {});
1075
+ var QuizService = class extends base_service_default {
1076
+ discoverUrlPrefix() {
1077
+ switch (this.environment) {
1078
+ case "production":
1079
+ return "https://api.iquiz.dk/api";
1080
+ case "development":
1081
+ case "local":
1082
+ case "testing":
1083
+ return "https://galecms.test.tibalo.dk/api";
1084
+ case "test":
1085
+ return `https://localhost:3010/galeapi/api`;
1086
+ default:
1087
+ throw new Error(`Unknown environment: ${this.environment}`);
1088
+ }
1089
+ }
1090
+ makeHeaders(extra) {
1091
+ const headers = new Headers();
1092
+ headers.append("Content-Type", "application/json");
1093
+ if (extra) {
1094
+ for (const [key, val] of Object.entries(extra)) {
1095
+ headers.append(key, val);
1096
+ }
1097
+ }
1098
+ return headers;
1099
+ }
1100
+ // ─────────────────────────────────────────────────────────────
1101
+ // Legacy Gale quizzes
1102
+ // ─────────────────────────────────────────────────────────────
1103
+ async checkActiveSession({
1104
+ isbn,
1105
+ quizNumber,
1106
+ extraHeaders,
1107
+ timeout = 3e3
1108
+ }) {
1109
+ const url = `${this.getUrlPrefix()}/isbn/${isbn}/quiz/${quizNumber}`;
1110
+ const headers = this.makeHeaders(extraHeaders);
1111
+ const res = await this.getAsync({ url, headers, timeout });
1112
+ return await res.json();
1113
+ }
1114
+ async startQuiz({
1115
+ isbn,
1116
+ quiz,
1117
+ shared,
1118
+ extraHeaders,
1119
+ timeout = 3e3
1120
+ }) {
1121
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quiz}` : `${this.getUrlPrefix()}/isbn/${isbn}/quiz/${quiz}`;
1122
+ const headers = this.makeHeaders(extraHeaders);
1123
+ const res = await this.postAsync({ url, headers, body: "{}", timeout });
1124
+ return await res.json();
1125
+ }
1126
+ async getProblems({
1127
+ isbn,
1128
+ quizUnitId,
1129
+ shared,
1130
+ extraHeaders,
1131
+ timeout = 3e3
1132
+ }) {
1133
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1134
+ const headers = this.makeHeaders(extraHeaders);
1135
+ const res = await this.getAsync({ url, headers, timeout });
1136
+ return await res.json();
1137
+ }
1138
+ async resetAnswer({
1139
+ isbn,
1140
+ quizUnitId,
1141
+ questionID,
1142
+ extraHeaders,
1143
+ timeout = 3e3
1144
+ }) {
1145
+ const url = `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}/question/${questionID}`;
1146
+ const headers = this.makeHeaders(extraHeaders);
1147
+ const res = await this.putAsync({
1148
+ url,
1149
+ headers,
1150
+ body: JSON.stringify({}),
1151
+ timeout
1152
+ });
1153
+ return await res.json();
1154
+ }
1155
+ async saveAnswer({
1156
+ isbn,
1157
+ quizUnitId,
1158
+ answer,
1159
+ shared,
1160
+ extraHeaders,
1161
+ timeout = 3e3
1162
+ }) {
1163
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1164
+ const headers = this.makeHeaders(extraHeaders);
1165
+ const res = await this.putAsync({
1166
+ url,
1167
+ headers,
1168
+ body: JSON.stringify(answer),
1169
+ timeout
1170
+ });
1171
+ return await res.json();
1172
+ }
1173
+ async finishQuiz({
1174
+ isbn,
1175
+ quizUnitId,
1176
+ shared,
1177
+ extraHeaders,
1178
+ timeout = 3e3
1179
+ }) {
1180
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}/finish` : `${this.getUrlPrefix()}/isbn/${isbn}/student/${quizUnitId}`;
1181
+ const headers = this.makeHeaders(extraHeaders);
1182
+ const res = await this.postAsync({
1183
+ url,
1184
+ headers,
1185
+ body: JSON.stringify({}),
1186
+ timeout
1187
+ });
1188
+ return await res.json();
1189
+ }
1190
+ async getResults({
1191
+ isbn,
1192
+ quizUnitId,
1193
+ shared,
1194
+ extraHeaders,
1195
+ timeout = 3e3
1196
+ }) {
1197
+ const url = shared ? `${this.getUrlPrefix()}/shared/student/${quizUnitId}/result` : `${this.getUrlPrefix()}/isbn/${isbn}/student/overview/${quizUnitId}`;
1198
+ const headers = this.makeHeaders(extraHeaders);
1199
+ const res = await this.getAsync({ url, headers, timeout });
1200
+ return await res.json();
1201
+ }
1202
+ // ─────────────────────────────────────────────────────────────
1203
+ // Shared quizzes
1204
+ // ─────────────────────────────────────────────────────────────
1205
+ async createSharedQuiz({
1206
+ quizData,
1207
+ extraHeaders,
1208
+ timeout = 3e3
1209
+ }) {
1210
+ const url = `${this.getUrlPrefix()}/shared/quiz`;
1211
+ const headers = this.makeHeaders(extraHeaders);
1212
+ const res = await this.postAsync({
1213
+ url,
1214
+ headers,
1215
+ body: JSON.stringify(quizData),
1216
+ timeout
1217
+ });
1218
+ return await res.json();
1219
+ }
1220
+ async copyEditSharedQuiz({
1221
+ quizSessionId,
1222
+ quizData,
1223
+ action,
1224
+ extraHeaders,
1225
+ timeout = 3e3
1226
+ }) {
1227
+ const url = `${this.getUrlPrefix()}/shared/quiz/${quizSessionId}`;
1228
+ const method = action === "edit" ? "PUT" : "POST";
1229
+ const headers = this.makeHeaders(extraHeaders);
1230
+ const res = method === "PUT" ? await this.putAsync({
1231
+ url,
1232
+ headers,
1233
+ body: JSON.stringify(quizData),
1234
+ timeout
1235
+ }) : await this.postAsync({
1236
+ url,
1237
+ headers,
1238
+ body: JSON.stringify(quizData),
1239
+ timeout
1240
+ });
1241
+ return await res.json();
1242
+ }
1243
+ async getTeachersQuizProblems({
1244
+ quizSessionId,
1245
+ extraHeaders,
1246
+ timeout = 3e3
1247
+ }) {
1248
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/problems`;
1249
+ const headers = this.makeHeaders(extraHeaders);
1250
+ const res = await this.getAsync({ url, headers, timeout });
1251
+ return await res.json();
1252
+ }
1253
+ async getTeachersUnitOverview({
1254
+ quizSessionId,
1255
+ quizUnitId,
1256
+ extraHeaders,
1257
+ timeout = 3e3
1258
+ }) {
1259
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/units/${quizUnitId}`;
1260
+ const headers = this.makeHeaders(extraHeaders);
1261
+ const res = await this.getAsync({ url, headers, timeout });
1262
+ return await res.json();
1263
+ }
1264
+ async activateDeactivateQuestion({
1265
+ quizSessionId,
1266
+ questionId,
1267
+ activate,
1268
+ extraHeaders,
1269
+ timeout = 3e3
1270
+ }) {
1271
+ const url = `${this.getUrlPrefix()}/shared/teacher/quiz/${quizSessionId}/question/${questionId}`;
1272
+ const method = activate ? "PATCH" : "DELETE";
1273
+ const headers = this.makeHeaders(extraHeaders);
1274
+ const res = method === "PATCH" ? await this.postAsync({
1275
+ url,
1276
+ headers,
1277
+ body: null,
1278
+ timeout
1279
+ }) : await this.deleteAsync({ url, headers, timeout });
1280
+ return await res.json();
1281
+ }
1282
+ async getTeachersQuizzes({
1283
+ extraHeaders,
1284
+ timeout = 3e3
1285
+ }) {
1286
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes`;
1287
+ const headers = this.makeHeaders(extraHeaders);
1288
+ const res = await this.getAsync({ url, headers, timeout });
1289
+ return await res.json();
1290
+ }
1291
+ async getStudentsQuizzes({
1292
+ extraHeaders,
1293
+ timeout = 3e3
1294
+ }) {
1295
+ const url = `${this.getUrlPrefix()}/shared/student/quizzes`;
1296
+ const headers = this.makeHeaders(extraHeaders);
1297
+ const res = await this.getAsync({ url, headers, timeout });
1298
+ return await res.json();
1299
+ }
1300
+ async getTeachersQuiz({
1301
+ quizSessionId,
1302
+ extraHeaders,
1303
+ timeout = 3e3
1304
+ }) {
1305
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}`;
1306
+ const headers = this.makeHeaders(extraHeaders);
1307
+ const res = await this.getAsync({ url, headers, timeout });
1308
+ return await res.json();
1309
+ }
1310
+ async toggleArchiveQuiz({
1311
+ quizSessionId,
1312
+ archive,
1313
+ extraHeaders,
1314
+ timeout = 3e3
1315
+ }) {
1316
+ const url = `${this.getUrlPrefix()}/shared/quiz/${quizSessionId}`;
1317
+ const method = archive ? "DELETE" : "PATCH";
1318
+ const headers = this.makeHeaders(extraHeaders);
1319
+ const res = method === "DELETE" ? await this.deleteAsync({ url, headers, timeout }) : await this.postAsync({
1320
+ url,
1321
+ headers,
1322
+ body: null,
1323
+ timeout
1324
+ });
1325
+ return await res.json();
1326
+ }
1327
+ async deleteSharedQuizUnit({
1328
+ quizSessionId,
1329
+ quizUnitId,
1330
+ extraHeaders,
1331
+ timeout = 3e3
1332
+ }) {
1333
+ const url = `${this.getUrlPrefix()}/shared/teacher/quizzes/${quizSessionId}/units/${quizUnitId}`;
1334
+ const headers = this.makeHeaders(extraHeaders);
1335
+ const res = await this.deleteAsync({ url, headers, timeout });
1336
+ return await res.json();
1337
+ }
1338
+ };
1339
+
1065
1340
  // src/services/writing_task_service.ts
1066
1341
  var WritingTaskService = class extends base_service_default {
1067
1342
  discoverUrlPrefix() {
@@ -1100,11 +1375,13 @@ var SolrProxyService = class extends base_service_default {
1100
1375
  // Annotate the CommonJS export names for ESM import in node:
1101
1376
  0 && (module.exports = {
1102
1377
  AIBotService,
1378
+ ApiErrors,
1103
1379
  CookieConsentLog,
1104
1380
  HighlightResultType,
1105
1381
  HighlightService,
1106
1382
  PdfGeneratorService,
1107
1383
  PollyService,
1384
+ QuizService,
1108
1385
  SSMLSpeechSpeeds,
1109
1386
  SolrProxyService,
1110
1387
  TaggingService,