@edpire/sdk 0.12.0 → 0.12.1

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,23 @@ the package follows [semantic versioning](https://semver.org/spec/v2.0.0.html).
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [0.12.1] - 2026-11-24
15
+
16
+ ### Added
17
+
18
+ - **Your learners by name, from the Node helpers.** `EdpireClient.mintEmbedToken` takes an optional
19
+ third argument, `{ name, email }`, and `createEdpireTokenHandler`'s `resolveLearner` may return
20
+ `{ ref, name, email }` instead of the ref alone. They are sent as the token call's new optional
21
+ `learner_name` and `learner_email`, so your workspace shows the name instead of the `learner_ref`
22
+ on Edpire's results, statistics and grading screens, papers already submitted included. New types
23
+ `EmbedLearner`, `ResolvedLearner`.
24
+
25
+ ### Upgrade notes
26
+
27
+ - Nothing to change: returning a string from `resolveLearner` works as before. The player is the
28
+ same as 0.12.0. The fields reach the server whatever the SDK version, so a backend calling
29
+ `POST /api/v1/embed/token` directly doesn't need this version.
30
+
14
31
  ## [0.12.0] - 2026-11-24
15
32
 
16
33
  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.1/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.1/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edpire/sdk",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Embeddable JS SDK for Edpire assessments",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://docs.edpire.com/developer/sdk/overview",