@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 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.0/dist/umd/index.global.js"></script>
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.0/dist/umd/index.global.js"></script>
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) => string | null | undefined | Promise<string | null | undefined>;
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 learnerRef;
277
+ let resolved;
276
278
  try {
277
- learnerRef = await opts.resolveLearner(req);
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 h(t){let i=[],n=0;for(let e of t.exercises)for(let r of e.questions)i.push({exerciseId:e.id,questionId:r.id,content:r.content_ast,points:r.points,sequenceNumber:r.sequence_number,index:n++});return i}function m(t){let i=new Map;for(let n of t){let e=new Map;for(let r of n.questions){let o=new Map;for(let s of r.nodeResults){let a={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"?a.correctChoiceIds=s.detail.correctChoiceIds:s.detail?.type==="matchingSet"&&(a.pairFeedback=s.detail.pairFeedback,a.correctPairings=s.detail.correctPairings),o.set(s.nodeId,a)}e.set(r.questionId,o)}i.set(n.exerciseId,e)}return i}function w(t){return(t??[]).map(i=>({exerciseId:i.exercise_id,questions:i.questions.map(n=>({questionId:n.question_id,...n.explanation?{explanation:n.explanation}:{},nodeResults:n.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 k(t){let i=m(w(t.exercise_feedback)),n=new Map;for(let o of t.answers.exerciseAnswers)for(let s of o.questionAnswers)n.set(s.questionId,s.answers);let e=[],r=0;for(let o of t.assessment.exercises){let s=i.get(o.id);for(let a of o.questions){let d=s?.get(a.id),l=t.exercise_feedback.find(c=>c.exercise_id===o.id)?.questions.find(c=>c.question_id===a.id),g=l?.node_results??[],u=0,p=0,f=!1;for(let c of g)u+=c.score??0,p+=c.max_score??0,c.status==="awaiting_review"&&(f=!0);e.push({exerciseId:o.id,questionId:a.id,content:a.content,sharedContext:o.sharedContext??null,explanation:l?.explanation??null,answers:n.get(a.id)??[],feedback:d?Object.fromEntries(d):{},score:u,maxScore:p,status:f?"awaiting_review":p===0?"unscored":u>=p?"correct":u>0?"partial":"incorrect",index:r++})}}return e}function A(t){let i=new Map;for(let n of t)i.has(n.exerciseId)||i.set(n.exerciseId,[]),i.get(n.exerciseId).push({questionId:n.questionId,answers:n.answers});return{exerciseAnswers:Array.from(i.entries()).map(([n,e])=>({exerciseId:n,questionAnswers:e}))}}var y=new Set(["choiceSet","inlineChoiceSet","blank","aiAnswerInput","matchingSet","openResponseNode","mathResponse","codingResponse"]),I=new Set(["blankPool","inlinePool"]);function x(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 i=t.answer;return i.recording||i.files&&i.files.length>0?!0:(i.text?.wordCount??0)>0}case"mathResponse":return t.answer.latex.trim().length>0;case"codingResponse":return t.answer.source.trim().length>0;default:{let i=t;return!0}}}function b(t){let i=0,n=e=>{if(Array.isArray(e)){for(let s of e)n(s);return}if(!e||typeof e!="object")return;let{type:r,content:o}=e;if(typeof r=="string"){if(y.has(r)){i+=1;return}if(I.has(r))return}o!==void 0&&n(o)};return n(t),i}function S(t,i){let n=new Map;for(let r of i?.exerciseAnswers??[])for(let o of r.questionAnswers){let s=n.get(o.questionId);s||(s=new Set,n.set(o.questionId,s));for(let a of o.answers)x(a)&&s.add(a.nodeId)}let e=[];return t.exercises.forEach((r,o)=>{r.questions.forEach((s,a)=>{let d=b(s.content);d!==0&&(n.get(s.id)?.size??0)<d&&e.push({questionId:s.id,exerciseIndex:o,...r.title?{exerciseTitle:r.title}:{},questionIndex:a,only:r.questions.length===1})})}),e}function q(t,i,n){let e=new Set(n);return e.size===0?[]:S(t,i).filter(r=>e.has(r.questionId))}export{A as buildSubmitPayload,b as countAnswerableNodes,h as flattenAssessment,k as flattenReview,x as isAnswered,q as missingRequired};
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