@lessonkit/xapi 1.0.2 → 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 +38 -1
- package/dist/index.js +38 -1
- package/package.json +2 -2
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;
|
|
@@ -237,7 +273,8 @@ function createXAPIClient(opts) {
|
|
|
237
273
|
};
|
|
238
274
|
const emit = (event) => {
|
|
239
275
|
const statement = telemetryEventToXAPIStatement(event);
|
|
240
|
-
if (statement)
|
|
276
|
+
if (!statement) return;
|
|
277
|
+
sendOrQueue(statement);
|
|
241
278
|
};
|
|
242
279
|
return {
|
|
243
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;
|
|
@@ -209,7 +245,8 @@ function createXAPIClient(opts) {
|
|
|
209
245
|
};
|
|
210
246
|
const emit = (event) => {
|
|
211
247
|
const statement = telemetryEventToXAPIStatement(event);
|
|
212
|
-
if (statement)
|
|
248
|
+
if (!statement) return;
|
|
249
|
+
sendOrQueue(statement);
|
|
213
250
|
};
|
|
214
251
|
return {
|
|
215
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,7 +48,7 @@
|
|
|
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",
|