@lessonkit/xapi 1.0.1 → 1.1.0
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 +50 -4
- package/dist/index.js +50 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -162,6 +162,42 @@ function telemetryEventToXAPIStatement(event) {
|
|
|
162
162
|
{ result: Object.keys(result).length ? result : void 0 }
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
|
+
case "assessment_answered": {
|
|
166
|
+
const lessonId = event.lessonId;
|
|
167
|
+
const checkId = event.data.checkId;
|
|
168
|
+
const result = {};
|
|
169
|
+
if (typeof event.data.correct === "boolean") {
|
|
170
|
+
result.success = event.data.correct;
|
|
171
|
+
}
|
|
172
|
+
return statementFor(
|
|
173
|
+
(0, import_core2.buildLessonkitUrn)({ courseId, lessonId, checkId }),
|
|
174
|
+
XAPIVerbs.answered,
|
|
175
|
+
event.timestamp,
|
|
176
|
+
{ result: Object.keys(result).length ? result : void 0 }
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
case "assessment_completed": {
|
|
180
|
+
const lessonId = event.lessonId;
|
|
181
|
+
const checkId = event.data.checkId;
|
|
182
|
+
const { score, maxScore } = event.data;
|
|
183
|
+
const result = {};
|
|
184
|
+
if (typeof score === "number" || typeof maxScore === "number") {
|
|
185
|
+
const max = typeof maxScore === "number" ? maxScore : void 0;
|
|
186
|
+
const raw = typeof score === "number" ? score : void 0;
|
|
187
|
+
result.score = {
|
|
188
|
+
raw,
|
|
189
|
+
max,
|
|
190
|
+
min: 0,
|
|
191
|
+
scaled: typeof raw === "number" && typeof max === "number" && max > 0 ? raw / max : void 0
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return statementFor(
|
|
195
|
+
(0, import_core2.buildLessonkitUrn)({ courseId, lessonId, checkId }),
|
|
196
|
+
XAPIVerbs.completed,
|
|
197
|
+
event.timestamp,
|
|
198
|
+
{ result: Object.keys(result).length ? result : void 0 }
|
|
199
|
+
);
|
|
200
|
+
}
|
|
165
201
|
case "interaction": {
|
|
166
202
|
const lessonId = event.lessonId;
|
|
167
203
|
const blockId = event.data?.blockId;
|
|
@@ -211,8 +247,17 @@ function createXAPIClient(opts) {
|
|
|
211
247
|
return;
|
|
212
248
|
}
|
|
213
249
|
const existing = inflightById.get(statement.id);
|
|
214
|
-
if (existing)
|
|
215
|
-
|
|
250
|
+
if (existing) {
|
|
251
|
+
void existing.then(
|
|
252
|
+
() => void 0,
|
|
253
|
+
() => {
|
|
254
|
+
sendOrQueue(statement);
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const transportFlight = Promise.resolve().then(() => transport(statement));
|
|
260
|
+
const flight = transportFlight.catch(() => {
|
|
216
261
|
queue.enqueue(statement);
|
|
217
262
|
if (isDevEnvironment() && !warnedTransportFailure) {
|
|
218
263
|
warnedTransportFailure = true;
|
|
@@ -223,12 +268,13 @@ function createXAPIClient(opts) {
|
|
|
223
268
|
}).finally(() => {
|
|
224
269
|
inflightById.delete(statement.id);
|
|
225
270
|
});
|
|
226
|
-
inflightById.set(statement.id,
|
|
271
|
+
inflightById.set(statement.id, transportFlight);
|
|
227
272
|
void flight;
|
|
228
273
|
};
|
|
229
274
|
const emit = (event) => {
|
|
230
275
|
const statement = telemetryEventToXAPIStatement(event);
|
|
231
|
-
if (statement)
|
|
276
|
+
if (!statement) return;
|
|
277
|
+
sendOrQueue(statement);
|
|
232
278
|
};
|
|
233
279
|
return {
|
|
234
280
|
send: (statement) => {
|
package/dist/index.js
CHANGED
|
@@ -134,6 +134,42 @@ function telemetryEventToXAPIStatement(event) {
|
|
|
134
134
|
{ result: Object.keys(result).length ? result : void 0 }
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
|
+
case "assessment_answered": {
|
|
138
|
+
const lessonId = event.lessonId;
|
|
139
|
+
const checkId = event.data.checkId;
|
|
140
|
+
const result = {};
|
|
141
|
+
if (typeof event.data.correct === "boolean") {
|
|
142
|
+
result.success = event.data.correct;
|
|
143
|
+
}
|
|
144
|
+
return statementFor(
|
|
145
|
+
buildLessonkitUrn({ courseId, lessonId, checkId }),
|
|
146
|
+
XAPIVerbs.answered,
|
|
147
|
+
event.timestamp,
|
|
148
|
+
{ result: Object.keys(result).length ? result : void 0 }
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
case "assessment_completed": {
|
|
152
|
+
const lessonId = event.lessonId;
|
|
153
|
+
const checkId = event.data.checkId;
|
|
154
|
+
const { score, maxScore } = event.data;
|
|
155
|
+
const result = {};
|
|
156
|
+
if (typeof score === "number" || typeof maxScore === "number") {
|
|
157
|
+
const max = typeof maxScore === "number" ? maxScore : void 0;
|
|
158
|
+
const raw = typeof score === "number" ? score : void 0;
|
|
159
|
+
result.score = {
|
|
160
|
+
raw,
|
|
161
|
+
max,
|
|
162
|
+
min: 0,
|
|
163
|
+
scaled: typeof raw === "number" && typeof max === "number" && max > 0 ? raw / max : void 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return statementFor(
|
|
167
|
+
buildLessonkitUrn({ courseId, lessonId, checkId }),
|
|
168
|
+
XAPIVerbs.completed,
|
|
169
|
+
event.timestamp,
|
|
170
|
+
{ result: Object.keys(result).length ? result : void 0 }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
137
173
|
case "interaction": {
|
|
138
174
|
const lessonId = event.lessonId;
|
|
139
175
|
const blockId = event.data?.blockId;
|
|
@@ -183,8 +219,17 @@ function createXAPIClient(opts) {
|
|
|
183
219
|
return;
|
|
184
220
|
}
|
|
185
221
|
const existing = inflightById.get(statement.id);
|
|
186
|
-
if (existing)
|
|
187
|
-
|
|
222
|
+
if (existing) {
|
|
223
|
+
void existing.then(
|
|
224
|
+
() => void 0,
|
|
225
|
+
() => {
|
|
226
|
+
sendOrQueue(statement);
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const transportFlight = Promise.resolve().then(() => transport(statement));
|
|
232
|
+
const flight = transportFlight.catch(() => {
|
|
188
233
|
queue.enqueue(statement);
|
|
189
234
|
if (isDevEnvironment() && !warnedTransportFailure) {
|
|
190
235
|
warnedTransportFailure = true;
|
|
@@ -195,12 +240,13 @@ function createXAPIClient(opts) {
|
|
|
195
240
|
}).finally(() => {
|
|
196
241
|
inflightById.delete(statement.id);
|
|
197
242
|
});
|
|
198
|
-
inflightById.set(statement.id,
|
|
243
|
+
inflightById.set(statement.id, transportFlight);
|
|
199
244
|
void flight;
|
|
200
245
|
};
|
|
201
246
|
const emit = (event) => {
|
|
202
247
|
const statement = telemetryEventToXAPIStatement(event);
|
|
203
|
-
if (statement)
|
|
248
|
+
if (!statement) return;
|
|
249
|
+
sendOrQueue(statement);
|
|
204
250
|
};
|
|
205
251
|
return {
|
|
206
252
|
send: (statement) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lessonkit/xapi",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "xAPI statement generation primitives for LessonKit.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"lint": "echo \"(no lint configured yet)\""
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@lessonkit/core": "1.0
|
|
51
|
+
"@lessonkit/core": "1.1.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsup": "^8.5.0",
|
|
55
55
|
"typescript": "^5.8.3",
|
|
56
|
-
"vitest": "^
|
|
56
|
+
"vitest": "^4.1.8"
|
|
57
57
|
}
|
|
58
58
|
}
|