@lessonkit/lxpack 0.8.0 → 0.9.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/README.md CHANGED
@@ -45,4 +45,4 @@ import { notifyLxpackLessonComplete } from "@lessonkit/lxpack/bridge";
45
45
 
46
46
  `@lessonkit/react` forwards `lesson_completed`, `course_completed`, and `quiz_completed` automatically when `window.parent.lxpackBridge.v1` is present (`config.lxpack.bridge: "off"` to disable).
47
47
 
48
- For interoperability notes, see [LXPack upgrades](https://lessonkit.readthedocs.io/en/latest/reference/lxpack-upgrades.html).
48
+ For interoperability notes, see [LXPack upgrades](https://lessonkit.readthedocs.io/en/latest/reference/lxpack-upgrades.html). LXPack maintainers: [upgrade plan for maintainers](https://github.com/eddiethedean/lessonkit/blob/main/docs/LXPACK_UPGRADE_PLAN_FOR_MAINTAINERS.md).
package/dist/bridge.cjs CHANGED
@@ -20,29 +20,78 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/bridge.ts
21
21
  var bridge_exports = {};
22
22
  __export(bridge_exports, {
23
+ DEFAULT_BRIDGE_PASSING_SCORE: () => import_spa_bridge2.DEFAULT_BRIDGE_PASSING_SCORE,
24
+ LESSONKIT_TELEMETRY_EVENTS: () => import_tracking_schema2.LESSONKIT_TELEMETRY_EVENTS,
25
+ LXPACK_BRIDGE_VERSIONS: () => import_spa_bridge2.LXPACK_BRIDGE_VERSIONS,
23
26
  createLxpackBridge: () => createLxpackBridge,
27
+ createLxpackBridgeHost: () => import_spa_bridge2.createLxpackBridgeHost,
28
+ getLxpackBridge: () => import_spa_bridge2.getLxpackBridge,
29
+ mapLessonkitTelemetryToBridgeAction: () => import_tracking_schema2.mapLessonkitTelemetryToBridgeAction,
30
+ mapLessonkitTelemetryToLxpack: () => import_tracking_schema2.mapLessonkitTelemetryToLxpack,
24
31
  normalizeAssessmentPassingScore: () => normalizeAssessmentPassingScore,
25
32
  normalizeAssessmentScore: () => normalizeAssessmentScore,
33
+ normalizePassingThreshold: () => import_spa_bridge2.normalizePassingThreshold,
34
+ normalizeScore: () => import_spa_bridge2.normalizeScore,
26
35
  notifyLxpackAssessment: () => notifyLxpackAssessment,
27
36
  notifyLxpackCourseComplete: () => notifyLxpackCourseComplete,
28
- notifyLxpackLessonComplete: () => notifyLxpackLessonComplete
37
+ notifyLxpackLessonComplete: () => notifyLxpackLessonComplete,
38
+ supportedBridgeVersions: () => import_spa_bridge2.supportedBridgeVersions,
39
+ telemetryEventToLessonkit: () => telemetryEventToLessonkit
29
40
  });
30
41
  module.exports = __toCommonJS(bridge_exports);
42
+ var import_spa_bridge = require("@lxpack/spa-bridge");
43
+ var import_spa_bridge2 = require("@lxpack/spa-bridge");
44
+ var import_tracking_schema2 = require("@lxpack/tracking-schema");
45
+
46
+ // src/telemetry.ts
47
+ var import_tracking_schema = require("@lxpack/tracking-schema");
48
+ var SUPPORTED = new Set(import_tracking_schema.LESSONKIT_TELEMETRY_EVENTS);
49
+ function telemetryEventToLessonkit(event) {
50
+ if (!SUPPORTED.has(event.name)) {
51
+ return null;
52
+ }
53
+ const name = event.name;
54
+ const mapped = {
55
+ name,
56
+ lessonId: event.lessonId
57
+ };
58
+ if (name === "quiz_completed" || name === "quiz_answered") {
59
+ const data = event.data;
60
+ mapped.assessmentId = data?.checkId;
61
+ if (data && "score" in data) {
62
+ mapped.score = data.score;
63
+ mapped.maxScore = data.maxScore;
64
+ mapped.passingScore = data.passingScore;
65
+ }
66
+ if (data) {
67
+ mapped.data = data;
68
+ }
69
+ } else if (name === "interaction" && event.data) {
70
+ mapped.data = event.data;
71
+ }
72
+ return mapped;
73
+ }
74
+
75
+ // src/bridge.ts
31
76
  function normalizeAssessmentScore(opts) {
32
77
  if (typeof opts.score !== "number" || !Number.isFinite(opts.score)) {
33
78
  return null;
34
79
  }
35
- const maxScore = typeof opts.maxScore === "number" && opts.maxScore > 0 ? opts.maxScore : 1;
36
- return opts.score / maxScore;
80
+ return (0, import_spa_bridge.normalizeScore)({ score: opts.score, maxScore: opts.maxScore });
37
81
  }
38
- function normalizeAssessmentPassingScore(passingScore) {
39
- return typeof passingScore === "number" && passingScore > 0 ? passingScore : 1;
82
+ function normalizeAssessmentPassingScore(opts) {
83
+ return (0, import_spa_bridge.normalizePassingThreshold)({
84
+ passingScore: opts?.passingScore,
85
+ maxScore: opts?.maxScore
86
+ });
40
87
  }
41
- function getBridge() {
88
+ function getBridge(parentWindow) {
89
+ const fromSdk = (0, import_spa_bridge.getLxpackBridge)(parentWindow);
90
+ if (fromSdk) return fromSdk;
42
91
  if (typeof window === "undefined") return null;
43
- const parent = window.parent;
92
+ const parent = parentWindow ?? window.parent;
44
93
  if (!parent || parent === window) return null;
45
- return parent.lxpackBridge?.v1 ?? parent.lxpack ?? null;
94
+ return parent.lxpack ?? null;
46
95
  }
47
96
  function createLxpackBridge() {
48
97
  return getBridge();
@@ -67,10 +116,21 @@ function notifyLxpackAssessment(payload) {
67
116
  }
68
117
  // Annotate the CommonJS export names for ESM import in node:
69
118
  0 && (module.exports = {
119
+ DEFAULT_BRIDGE_PASSING_SCORE,
120
+ LESSONKIT_TELEMETRY_EVENTS,
121
+ LXPACK_BRIDGE_VERSIONS,
70
122
  createLxpackBridge,
123
+ createLxpackBridgeHost,
124
+ getLxpackBridge,
125
+ mapLessonkitTelemetryToBridgeAction,
126
+ mapLessonkitTelemetryToLxpack,
71
127
  normalizeAssessmentPassingScore,
72
128
  normalizeAssessmentScore,
129
+ normalizePassingThreshold,
130
+ normalizeScore,
73
131
  notifyLxpackAssessment,
74
132
  notifyLxpackCourseComplete,
75
- notifyLxpackLessonComplete
133
+ notifyLxpackLessonComplete,
134
+ supportedBridgeVersions,
135
+ telemetryEventToLessonkit
76
136
  });
package/dist/bridge.d.cts CHANGED
@@ -1,25 +1,9 @@
1
- import { LessonId, CheckId } from '@lessonkit/core';
1
+ import { CheckId, LessonId } from '@lessonkit/core';
2
+ import { LxpackBridgeV1, LxpackBridgeSubmitAssessmentPayload } from '@lxpack/spa-bridge';
3
+ export { DEFAULT_BRIDGE_PASSING_SCORE, LXPACK_BRIDGE_VERSIONS, LxpackBridgeSubmitAssessmentPayload, LxpackBridgeV1, createLxpackBridgeHost, getLxpackBridge, normalizePassingThreshold, normalizeScore, supportedBridgeVersions } from '@lxpack/spa-bridge';
4
+ export { LESSONKIT_TELEMETRY_EVENTS, LessonkitBridgeAction, LessonkitTelemetryEvent, LessonkitTelemetryEventName, TrackingSchemaEvent, mapLessonkitTelemetryToBridgeAction, mapLessonkitTelemetryToLxpack } from '@lxpack/tracking-schema';
5
+ export { t as telemetryEventToLessonkit } from './telemetry-gCxlwc7I.cjs';
2
6
 
3
- type LxpackBridgeV1 = {
4
- completeLesson?: (lessonId: LessonId) => void;
5
- completeCourse?: () => void;
6
- submitAssessment?: (payload: {
7
- id: string;
8
- score: number;
9
- passingScore?: number;
10
- }) => void;
11
- track?: (payload: {
12
- type: string;
13
- id: string;
14
- data?: Record<string, unknown>;
15
- }) => void;
16
- };
17
- type LxpackBridgeHost = {
18
- lxpackBridge?: {
19
- v1?: LxpackBridgeV1;
20
- };
21
- lxpack?: LxpackBridgeV1;
22
- };
23
7
  /**
24
8
  * Scale a raw quiz score to 0–1 for the LXPack parent bridge.
25
9
  * Returns null when `score` is missing or not finite (caller should skip submit).
@@ -28,8 +12,14 @@ declare function normalizeAssessmentScore(opts: {
28
12
  score?: number;
29
13
  maxScore?: number;
30
14
  }): number | null;
31
- /** Bridge passing threshold (0–1 scale). Defaults to 1 when omitted or invalid. */
32
- declare function normalizeAssessmentPassingScore(passingScore?: number): number;
15
+ /**
16
+ * Scale a raw passing threshold to 0–1 for the LXPack parent bridge.
17
+ * Delegates to `@lxpack/spa-bridge` (default 0.7 when omitted).
18
+ */
19
+ declare function normalizeAssessmentPassingScore(opts?: {
20
+ passingScore?: number;
21
+ maxScore?: number;
22
+ }): number;
33
23
  declare function createLxpackBridge(): LxpackBridgeV1 | null;
34
24
  declare function notifyLxpackLessonComplete(lessonId: LessonId): boolean;
35
25
  declare function notifyLxpackCourseComplete(): boolean;
@@ -37,10 +27,8 @@ declare function notifyLxpackCourseComplete(): boolean;
37
27
  * Submit assessment results to the parent LXPack bridge.
38
28
  * `score` must already be on a 0–1 scale (use `normalizeAssessmentScore` for raw points).
39
29
  */
40
- declare function notifyLxpackAssessment(payload: {
30
+ declare function notifyLxpackAssessment(payload: LxpackBridgeSubmitAssessmentPayload & {
41
31
  id: CheckId;
42
- score: number;
43
- passingScore?: number;
44
32
  }): boolean;
45
33
 
46
- export { type LxpackBridgeHost, type LxpackBridgeV1, createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
34
+ export { createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
package/dist/bridge.d.ts CHANGED
@@ -1,25 +1,9 @@
1
- import { LessonId, CheckId } from '@lessonkit/core';
1
+ import { CheckId, LessonId } from '@lessonkit/core';
2
+ import { LxpackBridgeV1, LxpackBridgeSubmitAssessmentPayload } from '@lxpack/spa-bridge';
3
+ export { DEFAULT_BRIDGE_PASSING_SCORE, LXPACK_BRIDGE_VERSIONS, LxpackBridgeSubmitAssessmentPayload, LxpackBridgeV1, createLxpackBridgeHost, getLxpackBridge, normalizePassingThreshold, normalizeScore, supportedBridgeVersions } from '@lxpack/spa-bridge';
4
+ export { LESSONKIT_TELEMETRY_EVENTS, LessonkitBridgeAction, LessonkitTelemetryEvent, LessonkitTelemetryEventName, TrackingSchemaEvent, mapLessonkitTelemetryToBridgeAction, mapLessonkitTelemetryToLxpack } from '@lxpack/tracking-schema';
5
+ export { t as telemetryEventToLessonkit } from './telemetry-gCxlwc7I.js';
2
6
 
3
- type LxpackBridgeV1 = {
4
- completeLesson?: (lessonId: LessonId) => void;
5
- completeCourse?: () => void;
6
- submitAssessment?: (payload: {
7
- id: string;
8
- score: number;
9
- passingScore?: number;
10
- }) => void;
11
- track?: (payload: {
12
- type: string;
13
- id: string;
14
- data?: Record<string, unknown>;
15
- }) => void;
16
- };
17
- type LxpackBridgeHost = {
18
- lxpackBridge?: {
19
- v1?: LxpackBridgeV1;
20
- };
21
- lxpack?: LxpackBridgeV1;
22
- };
23
7
  /**
24
8
  * Scale a raw quiz score to 0–1 for the LXPack parent bridge.
25
9
  * Returns null when `score` is missing or not finite (caller should skip submit).
@@ -28,8 +12,14 @@ declare function normalizeAssessmentScore(opts: {
28
12
  score?: number;
29
13
  maxScore?: number;
30
14
  }): number | null;
31
- /** Bridge passing threshold (0–1 scale). Defaults to 1 when omitted or invalid. */
32
- declare function normalizeAssessmentPassingScore(passingScore?: number): number;
15
+ /**
16
+ * Scale a raw passing threshold to 0–1 for the LXPack parent bridge.
17
+ * Delegates to `@lxpack/spa-bridge` (default 0.7 when omitted).
18
+ */
19
+ declare function normalizeAssessmentPassingScore(opts?: {
20
+ passingScore?: number;
21
+ maxScore?: number;
22
+ }): number;
33
23
  declare function createLxpackBridge(): LxpackBridgeV1 | null;
34
24
  declare function notifyLxpackLessonComplete(lessonId: LessonId): boolean;
35
25
  declare function notifyLxpackCourseComplete(): boolean;
@@ -37,10 +27,8 @@ declare function notifyLxpackCourseComplete(): boolean;
37
27
  * Submit assessment results to the parent LXPack bridge.
38
28
  * `score` must already be on a 0–1 scale (use `normalizeAssessmentScore` for raw points).
39
29
  */
40
- declare function notifyLxpackAssessment(payload: {
30
+ declare function notifyLxpackAssessment(payload: LxpackBridgeSubmitAssessmentPayload & {
41
31
  id: CheckId;
42
- score: number;
43
- passingScore?: number;
44
32
  }): boolean;
45
33
 
46
- export { type LxpackBridgeHost, type LxpackBridgeV1, createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
34
+ export { createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
package/dist/bridge.js CHANGED
@@ -1,19 +1,46 @@
1
+ import {
2
+ telemetryEventToLessonkit
3
+ } from "./chunk-PSUSESH3.js";
4
+
1
5
  // src/bridge.ts
6
+ import {
7
+ getLxpackBridge as getLxpackBridgeFromParent,
8
+ normalizePassingThreshold,
9
+ normalizeScore
10
+ } from "@lxpack/spa-bridge";
11
+ import {
12
+ createLxpackBridgeHost as createLxpackBridgeHost2,
13
+ DEFAULT_BRIDGE_PASSING_SCORE,
14
+ getLxpackBridge,
15
+ LXPACK_BRIDGE_VERSIONS,
16
+ normalizePassingThreshold as normalizePassingThreshold2,
17
+ normalizeScore as normalizeScore2,
18
+ supportedBridgeVersions
19
+ } from "@lxpack/spa-bridge";
20
+ import {
21
+ LESSONKIT_TELEMETRY_EVENTS,
22
+ mapLessonkitTelemetryToBridgeAction,
23
+ mapLessonkitTelemetryToLxpack
24
+ } from "@lxpack/tracking-schema";
2
25
  function normalizeAssessmentScore(opts) {
3
26
  if (typeof opts.score !== "number" || !Number.isFinite(opts.score)) {
4
27
  return null;
5
28
  }
6
- const maxScore = typeof opts.maxScore === "number" && opts.maxScore > 0 ? opts.maxScore : 1;
7
- return opts.score / maxScore;
29
+ return normalizeScore({ score: opts.score, maxScore: opts.maxScore });
8
30
  }
9
- function normalizeAssessmentPassingScore(passingScore) {
10
- return typeof passingScore === "number" && passingScore > 0 ? passingScore : 1;
31
+ function normalizeAssessmentPassingScore(opts) {
32
+ return normalizePassingThreshold({
33
+ passingScore: opts?.passingScore,
34
+ maxScore: opts?.maxScore
35
+ });
11
36
  }
12
- function getBridge() {
37
+ function getBridge(parentWindow) {
38
+ const fromSdk = getLxpackBridgeFromParent(parentWindow);
39
+ if (fromSdk) return fromSdk;
13
40
  if (typeof window === "undefined") return null;
14
- const parent = window.parent;
41
+ const parent = parentWindow ?? window.parent;
15
42
  if (!parent || parent === window) return null;
16
- return parent.lxpackBridge?.v1 ?? parent.lxpack ?? null;
43
+ return parent.lxpack ?? null;
17
44
  }
18
45
  function createLxpackBridge() {
19
46
  return getBridge();
@@ -37,10 +64,21 @@ function notifyLxpackAssessment(payload) {
37
64
  return true;
38
65
  }
39
66
  export {
67
+ DEFAULT_BRIDGE_PASSING_SCORE,
68
+ LESSONKIT_TELEMETRY_EVENTS,
69
+ LXPACK_BRIDGE_VERSIONS,
40
70
  createLxpackBridge,
71
+ createLxpackBridgeHost2 as createLxpackBridgeHost,
72
+ getLxpackBridge,
73
+ mapLessonkitTelemetryToBridgeAction,
74
+ mapLessonkitTelemetryToLxpack,
41
75
  normalizeAssessmentPassingScore,
42
76
  normalizeAssessmentScore,
77
+ normalizePassingThreshold2 as normalizePassingThreshold,
78
+ normalizeScore2 as normalizeScore,
43
79
  notifyLxpackAssessment,
44
80
  notifyLxpackCourseComplete,
45
- notifyLxpackLessonComplete
81
+ notifyLxpackLessonComplete,
82
+ supportedBridgeVersions,
83
+ telemetryEventToLessonkit
46
84
  };
@@ -0,0 +1,32 @@
1
+ // src/telemetry.ts
2
+ import { LESSONKIT_TELEMETRY_EVENTS } from "@lxpack/tracking-schema";
3
+ var SUPPORTED = new Set(LESSONKIT_TELEMETRY_EVENTS);
4
+ function telemetryEventToLessonkit(event) {
5
+ if (!SUPPORTED.has(event.name)) {
6
+ return null;
7
+ }
8
+ const name = event.name;
9
+ const mapped = {
10
+ name,
11
+ lessonId: event.lessonId
12
+ };
13
+ if (name === "quiz_completed" || name === "quiz_answered") {
14
+ const data = event.data;
15
+ mapped.assessmentId = data?.checkId;
16
+ if (data && "score" in data) {
17
+ mapped.score = data.score;
18
+ mapped.maxScore = data.maxScore;
19
+ mapped.passingScore = data.passingScore;
20
+ }
21
+ if (data) {
22
+ mapped.data = data;
23
+ }
24
+ } else if (name === "interaction" && event.data) {
25
+ mapped.data = event.data;
26
+ }
27
+ return mapped;
28
+ }
29
+
30
+ export {
31
+ telemetryEventToLessonkit
32
+ };