@edpire/sdk 0.12.0 → 0.12.2
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/CHANGELOG.md +36 -0
- package/README.md +2 -2
- package/dist/client.d.mts +20 -3
- package/dist/client.mjs +9 -5
- package/dist/core.d.mts +7 -0
- package/dist/core.mjs +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +8 -8
- package/dist/umd/index.global.js +8 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,42 @@ the package follows [semantic versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [0.12.2] - 2026-11-25
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`flattenReview()` on an assessment whose score is hidden.** The review carries no points then,
|
|
19
|
+
so every step came back `unscored` ("not marked") instead of right, partly right or wrong. The
|
|
20
|
+
status now comes from each answer's marking when the score is hidden.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- `ReviewStep.scoreHidden`: true when the teacher keeps the score from students. `score` and
|
|
25
|
+
`maxScore` are then 0: show no points.
|
|
26
|
+
|
|
27
|
+
### Upgrade notes
|
|
28
|
+
|
|
29
|
+
- Nothing to change unless you draw a review one question at a time with `flattenReview()`: then
|
|
30
|
+
hide the points when `scoreHidden` is true. The player and `EdpireAssessment.review()` are
|
|
31
|
+
unchanged.
|
|
32
|
+
|
|
33
|
+
## [0.12.1] - 2026-11-24
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- **Your learners by name, from the Node helpers.** `EdpireClient.mintEmbedToken` takes an optional
|
|
38
|
+
third argument, `{ name, email }`, and `createEdpireTokenHandler`'s `resolveLearner` may return
|
|
39
|
+
`{ ref, name, email }` instead of the ref alone. They are sent as the token call's new optional
|
|
40
|
+
`learner_name` and `learner_email`, so your workspace shows the name instead of the `learner_ref`
|
|
41
|
+
on Edpire's results, statistics and grading screens, papers already submitted included. New types
|
|
42
|
+
`EmbedLearner`, `ResolvedLearner`.
|
|
43
|
+
|
|
44
|
+
### Upgrade notes
|
|
45
|
+
|
|
46
|
+
- Nothing to change: returning a string from `resolveLearner` works as before. The player is the
|
|
47
|
+
same as 0.12.0. The fields reach the server whatever the SDK version, so a backend calling
|
|
48
|
+
`POST /api/v1/embed/token` directly doesn't need this version.
|
|
49
|
+
|
|
14
50
|
## [0.12.0] - 2026-11-24
|
|
15
51
|
|
|
16
52
|
Runtime 3.20.0, schema 5.7.0.
|
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ embed.unmount()
|
|
|
92
92
|
**CDN (no bundler):**
|
|
93
93
|
|
|
94
94
|
```html
|
|
95
|
-
<script src="https://cdn.jsdelivr.net/npm/@edpire/sdk@0.12.
|
|
95
|
+
<script src="https://cdn.jsdelivr.net/npm/@edpire/sdk@0.12.2/dist/umd/index.global.js"></script>
|
|
96
96
|
<script>
|
|
97
97
|
EdpireSDK.EdpireAssessment.mount({ token, container: "#root", onComplete: handleDone })
|
|
98
98
|
</script>
|
|
@@ -330,7 +330,7 @@ The integration uses two parts:
|
|
|
330
330
|
</head>
|
|
331
331
|
<body>
|
|
332
332
|
<div id="root"></div>
|
|
333
|
-
<script src="https://cdn.jsdelivr.net/npm/@edpire/sdk@0.12.
|
|
333
|
+
<script src="https://cdn.jsdelivr.net/npm/@edpire/sdk@0.12.2/dist/umd/index.global.js"></script>
|
|
334
334
|
<script>
|
|
335
335
|
EdpireSDK.EdpireAssessment.mount({
|
|
336
336
|
token: "{{EMBED_TOKEN}}", // replace server-side before loading
|
package/dist/client.d.mts
CHANGED
|
@@ -644,8 +644,22 @@ declare class EdpireClient {
|
|
|
644
644
|
* @returns JWT token and expiration timestamp.
|
|
645
645
|
* @throws {EdpireError} 404 if assessment not found.
|
|
646
646
|
*/
|
|
647
|
-
mintEmbedToken(assessmentId: string, learnerRef: string): Promise<EmbedToken>;
|
|
647
|
+
mintEmbedToken(assessmentId: string, learnerRef: string, learner?: EmbedLearner): Promise<EmbedToken>;
|
|
648
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* Who a learner is, sent with the token so your workspace shows the name instead of the
|
|
651
|
+
* `learner_ref` on Edpire's results, statistics and grading screens (papers already submitted
|
|
652
|
+
* under that ref too). Both optional; a value Edpire can't use is ignored, never refused. The
|
|
653
|
+
* email is shown only on the learner's detail and in the results CSV.
|
|
654
|
+
*/
|
|
655
|
+
interface EmbedLearner {
|
|
656
|
+
name?: string | null;
|
|
657
|
+
email?: string | null;
|
|
658
|
+
}
|
|
659
|
+
/** What `resolveLearner` may return: the learner's ref, or the ref with a name and an email. */
|
|
660
|
+
type ResolvedLearner = string | ({
|
|
661
|
+
ref: string;
|
|
662
|
+
} & EmbedLearner);
|
|
649
663
|
/** Minimal interface covering IncomingMessage + connect/Express-style requests. */
|
|
650
664
|
interface ConnectRequest {
|
|
651
665
|
method?: string;
|
|
@@ -674,6 +688,9 @@ interface EdpireTokenHandlerOptions {
|
|
|
674
688
|
* request body or query string. Return `null` / `undefined` (or throw) to
|
|
675
689
|
* reject unauthenticated requests with a 401.
|
|
676
690
|
*
|
|
691
|
+
* Return `{ ref, name, email }` instead of the ref alone to show the learner by name in
|
|
692
|
+
* Edpire (name and email optional, see {@link EmbedLearner}).
|
|
693
|
+
*
|
|
677
694
|
* @example Next.js App Router + Better Auth
|
|
678
695
|
* ```typescript
|
|
679
696
|
* resolveLearner: async (req) => {
|
|
@@ -682,7 +699,7 @@ interface EdpireTokenHandlerOptions {
|
|
|
682
699
|
* }
|
|
683
700
|
* ```
|
|
684
701
|
*/
|
|
685
|
-
resolveLearner: (req: Request) =>
|
|
702
|
+
resolveLearner: (req: Request) => ResolvedLearner | null | undefined | Promise<ResolvedLearner | null | undefined>;
|
|
686
703
|
/**
|
|
687
704
|
* Optionally validate or remap the assessment ID from the request body.
|
|
688
705
|
*
|
|
@@ -779,4 +796,4 @@ declare function createEdpireTokenHandler(opts: EdpireTokenHandlerOptions): (req
|
|
|
779
796
|
*/
|
|
780
797
|
declare function toNodeHandler(handler: (req: Request) => Promise<Response>): (req: ConnectRequest, res: ConnectResponse) => void;
|
|
781
798
|
|
|
782
|
-
export { type Assessment, type AssessmentExercise, type AssessmentQuestion, type AssessmentSummary, type CheckOptions, type CheckResult, EdpireClient, type EdpireClientOptions, EdpireError, type EdpireTokenHandlerOptions, type EmbedToken, type GradeResult, type PaginatedResponse, type StoredAnswer, type Submission, type SubmissionReview, type SubmitOptions, type Webhook, type WebhookWithSecret, createEdpireTokenHandler, toNodeHandler };
|
|
799
|
+
export { type Assessment, type AssessmentExercise, type AssessmentQuestion, type AssessmentSummary, type CheckOptions, type CheckResult, EdpireClient, type EdpireClientOptions, EdpireError, type EdpireTokenHandlerOptions, type EmbedLearner, type EmbedToken, type GradeResult, type PaginatedResponse, type ResolvedLearner, type StoredAnswer, type Submission, type SubmissionReview, type SubmitOptions, type Webhook, type WebhookWithSecret, createEdpireTokenHandler, toNodeHandler };
|
package/dist/client.mjs
CHANGED
|
@@ -262,22 +262,26 @@ var EdpireClient = class {
|
|
|
262
262
|
* @returns JWT token and expiration timestamp.
|
|
263
263
|
* @throws {EdpireError} 404 if assessment not found.
|
|
264
264
|
*/
|
|
265
|
-
async mintEmbedToken(assessmentId, learnerRef) {
|
|
265
|
+
async mintEmbedToken(assessmentId, learnerRef, learner) {
|
|
266
266
|
return this.request("POST", "/embed/token", {
|
|
267
267
|
assessment_id: assessmentId,
|
|
268
|
-
learner_ref: learnerRef
|
|
268
|
+
learner_ref: learnerRef,
|
|
269
|
+
...learner?.name ? { learner_name: learner.name } : {},
|
|
270
|
+
...learner?.email ? { learner_email: learner.email } : {}
|
|
269
271
|
});
|
|
270
272
|
}
|
|
271
273
|
};
|
|
272
274
|
function createEdpireTokenHandler(opts) {
|
|
273
275
|
const client = new EdpireClient({ apiKey: opts.apiKey, baseUrl: opts.baseUrl });
|
|
274
276
|
return async function edpireTokenHandler(req) {
|
|
275
|
-
let
|
|
277
|
+
let resolved;
|
|
276
278
|
try {
|
|
277
|
-
|
|
279
|
+
resolved = await opts.resolveLearner(req);
|
|
278
280
|
} catch {
|
|
279
281
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
280
282
|
}
|
|
283
|
+
const learnerRef = typeof resolved === "string" ? resolved : resolved?.ref;
|
|
284
|
+
const learner = resolved && typeof resolved === "object" ? { name: resolved.name, email: resolved.email } : void 0;
|
|
281
285
|
if (!learnerRef) {
|
|
282
286
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
283
287
|
}
|
|
@@ -299,7 +303,7 @@ function createEdpireTokenHandler(opts) {
|
|
|
299
303
|
return Response.json({ error: message }, { status: 403 });
|
|
300
304
|
}
|
|
301
305
|
try {
|
|
302
|
-
const result = await client.mintEmbedToken(assessmentId, learnerRef);
|
|
306
|
+
const result = await client.mintEmbedToken(assessmentId, learnerRef, learner);
|
|
303
307
|
return Response.json({ token: result.token });
|
|
304
308
|
} catch (err) {
|
|
305
309
|
if (err instanceof EdpireError) {
|
package/dist/core.d.mts
CHANGED
|
@@ -414,8 +414,15 @@ interface ReviewStep {
|
|
|
414
414
|
* missed and the teacher's comment on an open response.
|
|
415
415
|
*/
|
|
416
416
|
feedback: Record<string, unknown>;
|
|
417
|
+
/** 0 when `scoreHidden`: the review carries no points then. */
|
|
417
418
|
score: number;
|
|
418
419
|
maxScore: number;
|
|
420
|
+
/**
|
|
421
|
+
* True when the teacher chose not to show the score to students (SDK 0.12.2).
|
|
422
|
+
* `score` and `maxScore` are then 0 and mean nothing: show no points. `status`
|
|
423
|
+
* still says right, partly right or wrong.
|
|
424
|
+
*/
|
|
425
|
+
scoreHidden: boolean;
|
|
419
426
|
/**
|
|
420
427
|
* The question as a whole. `awaiting_review` while a teacher has yet to mark
|
|
421
428
|
* any part of it; its score is then provisional. `unscored` when it is worth
|
package/dist/core.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k(t){let n=[],r=0;for(let e of t.exercises)for(let i of e.questions)n.push({exerciseId:e.id,questionId:i.id,content:i.content_ast,points:i.points,sequenceNumber:i.sequence_number,index:r++});return n}function x(t){let n=new Map;for(let r of t){let e=new Map;for(let i of r.questions){let a=new Map;for(let s of i.nodeResults){let o={state:s.status,showFeedback:!0,score:s.score,...s.feedback!==void 0?{message:s.feedback}:{},...s.displayAnswer!==void 0?{displayAnswer:s.displayAnswer}:{},...s.teacherFeedback!==void 0?{teacherFeedback:s.teacherFeedback}:{}};s.detail?.type==="choiceSet"?o.correctChoiceIds=s.detail.correctChoiceIds:s.detail?.type==="matchingSet"&&(o.pairFeedback=s.detail.pairFeedback,o.correctPairings=s.detail.correctPairings),a.set(s.nodeId,o)}e.set(i.questionId,a)}n.set(r.exerciseId,e)}return n}function b(t){return(t??[]).map(n=>({exerciseId:n.exercise_id,questions:n.questions.map(r=>({questionId:r.question_id,...r.explanation?{explanation:r.explanation}:{},nodeResults:r.node_results.map(e=>({nodeId:e.node_id,status:e.status,...e.score!==void 0?{score:e.score}:{},...e.max_score!==void 0?{maxScore:e.max_score}:{},...e.feedback!==void 0?{feedback:e.feedback}:{},...e.display_answer!==void 0?{displayAnswer:e.display_answer}:{},...e.detail!==void 0?{detail:e.detail}:{},...e.teacher_feedback!==void 0?{teacherFeedback:e.teacher_feedback}:{}}))}))}))}function y(t){let n=x(b(t.exercise_feedback)),r=new Map;for(let s of t.answers.exerciseAnswers)for(let o of s.questionAnswers)r.set(o.questionId,o.answers);let e=t.submission.score_hidden===!0,i=[],a=0;for(let s of t.assessment.exercises){let o=n.get(s.id);for(let d of s.questions){let l=o?.get(d.id),f=t.exercise_feedback.find(c=>c.exercise_id===s.id)?.questions.find(c=>c.question_id===d.id),m=f?.node_results??[],u=0,p=0,w=!1;for(let c of m)u+=c.score??0,p+=c.max_score??0,c.status==="awaiting_review"&&(w=!0);i.push({exerciseId:s.id,questionId:d.id,content:d.content,sharedContext:s.sharedContext??null,explanation:f?.explanation??null,answers:r.get(d.id)??[],feedback:l?Object.fromEntries(l):{},score:u,maxScore:p,scoreHidden:e,status:w?"awaiting_review":e?A(m.map(c=>c.status)):p===0?"unscored":u>=p?"correct":u>0?"partial":"incorrect",index:a++})}}return i}function A(t){return t.length===0?"unscored":t.every(n=>n==="correct")?"correct":t.every(n=>n==="incorrect")?"incorrect":"partial"}function I(t){let n=new Map;for(let r of t)n.has(r.exerciseId)||n.set(r.exerciseId,[]),n.get(r.exerciseId).push({questionId:r.questionId,answers:r.answers});return{exerciseAnswers:Array.from(n.entries()).map(([r,e])=>({exerciseId:r,questionAnswers:e}))}}var S=new Set(["choiceSet","inlineChoiceSet","blank","aiAnswerInput","matchingSet","openResponseNode","mathResponse","codingResponse"]),q=new Set(["blankPool","inlinePool"]);function g(t){switch(t.type){case"choiceSet":case"inlineChoiceSet":return t.answer.selectedIds.length>0;case"blank":return t.answer.mode==="choice"?t.answer.choiceId.length>0:t.answer.text.trim().length>0;case"matchingSet":return t.answer.connections.length>0;case"aiAnswer":return t.answer.text.trim().length>0;case"openResponse":{let n=t.answer;return n.recording||n.files&&n.files.length>0?!0:(n.text?.wordCount??0)>0}case"mathResponse":return t.answer.latex.trim().length>0;case"codingResponse":return t.answer.source.trim().length>0;default:{let n=t;return!0}}}function h(t){let n=0,r=e=>{if(Array.isArray(e)){for(let s of e)r(s);return}if(!e||typeof e!="object")return;let{type:i,content:a}=e;if(typeof i=="string"){if(S.has(i)){n+=1;return}if(q.has(i))return}a!==void 0&&r(a)};return r(t),n}function R(t,n){let r=new Map;for(let i of n?.exerciseAnswers??[])for(let a of i.questionAnswers){let s=r.get(a.questionId);s||(s=new Set,r.set(a.questionId,s));for(let o of a.answers)g(o)&&s.add(o.nodeId)}let e=[];return t.exercises.forEach((i,a)=>{i.questions.forEach((s,o)=>{let d=h(s.content);d!==0&&(r.get(s.id)?.size??0)<d&&e.push({questionId:s.id,exerciseIndex:a,...i.title?{exerciseTitle:i.title}:{},questionIndex:o,only:i.questions.length===1})})}),e}function F(t,n,r){let e=new Set(r);return e.size===0?[]:R(t,n).filter(i=>e.has(i.questionId))}export{I as buildSubmitPayload,h as countAnswerableNodes,k as flattenAssessment,y as flattenReview,g as isAnswered,F as missingRequired};
|
package/dist/index.d.mts
CHANGED
|
@@ -673,8 +673,15 @@ interface ReviewStep {
|
|
|
673
673
|
* missed and the teacher's comment on an open response.
|
|
674
674
|
*/
|
|
675
675
|
feedback: Record<string, unknown>;
|
|
676
|
+
/** 0 when `scoreHidden`: the review carries no points then. */
|
|
676
677
|
score: number;
|
|
677
678
|
maxScore: number;
|
|
679
|
+
/**
|
|
680
|
+
* True when the teacher chose not to show the score to students (SDK 0.12.2).
|
|
681
|
+
* `score` and `maxScore` are then 0 and mean nothing: show no points. `status`
|
|
682
|
+
* still says right, partly right or wrong.
|
|
683
|
+
*/
|
|
684
|
+
scoreHidden: boolean;
|
|
678
685
|
/**
|
|
679
686
|
* The question as a whole. `awaiting_review` while a teacher has yet to mark
|
|
680
687
|
* any part of it; its score is then provisional. `unscored` when it is worth
|