@lessonkit/lxpack 0.8.1 → 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/dist/bridge.cjs +68 -13
- package/dist/bridge.d.cts +8 -26
- package/dist/bridge.d.ts +8 -26
- package/dist/bridge.js +45 -12
- package/dist/chunk-PSUSESH3.js +32 -0
- package/dist/index.cjs +177 -203
- package/dist/index.d.cts +9 -20
- package/dist/index.d.ts +9 -20
- package/dist/index.js +151 -202
- package/dist/telemetry-gCxlwc7I.d.cts +9 -0
- package/dist/telemetry-gCxlwc7I.d.ts +9 -0
- package/package.json +7 -4
package/dist/bridge.cjs
CHANGED
|
@@ -20,34 +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
|
-
|
|
36
|
-
return Math.min(1, opts.score / maxScore);
|
|
80
|
+
return (0, import_spa_bridge.normalizeScore)({ score: opts.score, maxScore: opts.maxScore });
|
|
37
81
|
}
|
|
38
82
|
function normalizeAssessmentPassingScore(opts) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
const maxScore = typeof opts?.maxScore === "number" && opts.maxScore > 0 ? opts.maxScore : 1;
|
|
44
|
-
return Math.min(1, passingScore / maxScore);
|
|
83
|
+
return (0, import_spa_bridge.normalizePassingThreshold)({
|
|
84
|
+
passingScore: opts?.passingScore,
|
|
85
|
+
maxScore: opts?.maxScore
|
|
86
|
+
});
|
|
45
87
|
}
|
|
46
|
-
function getBridge() {
|
|
88
|
+
function getBridge(parentWindow) {
|
|
89
|
+
const fromSdk = (0, import_spa_bridge.getLxpackBridge)(parentWindow);
|
|
90
|
+
if (fromSdk) return fromSdk;
|
|
47
91
|
if (typeof window === "undefined") return null;
|
|
48
|
-
const parent = window.parent;
|
|
92
|
+
const parent = parentWindow ?? window.parent;
|
|
49
93
|
if (!parent || parent === window) return null;
|
|
50
|
-
return parent.
|
|
94
|
+
return parent.lxpack ?? null;
|
|
51
95
|
}
|
|
52
96
|
function createLxpackBridge() {
|
|
53
97
|
return getBridge();
|
|
@@ -72,10 +116,21 @@ function notifyLxpackAssessment(payload) {
|
|
|
72
116
|
}
|
|
73
117
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
118
|
0 && (module.exports = {
|
|
119
|
+
DEFAULT_BRIDGE_PASSING_SCORE,
|
|
120
|
+
LESSONKIT_TELEMETRY_EVENTS,
|
|
121
|
+
LXPACK_BRIDGE_VERSIONS,
|
|
75
122
|
createLxpackBridge,
|
|
123
|
+
createLxpackBridgeHost,
|
|
124
|
+
getLxpackBridge,
|
|
125
|
+
mapLessonkitTelemetryToBridgeAction,
|
|
126
|
+
mapLessonkitTelemetryToLxpack,
|
|
76
127
|
normalizeAssessmentPassingScore,
|
|
77
128
|
normalizeAssessmentScore,
|
|
129
|
+
normalizePassingThreshold,
|
|
130
|
+
normalizeScore,
|
|
78
131
|
notifyLxpackAssessment,
|
|
79
132
|
notifyLxpackCourseComplete,
|
|
80
|
-
notifyLxpackLessonComplete
|
|
133
|
+
notifyLxpackLessonComplete,
|
|
134
|
+
supportedBridgeVersions,
|
|
135
|
+
telemetryEventToLessonkit
|
|
81
136
|
});
|
package/dist/bridge.d.cts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import {
|
|
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).
|
|
@@ -30,7 +14,7 @@ declare function normalizeAssessmentScore(opts: {
|
|
|
30
14
|
}): number | null;
|
|
31
15
|
/**
|
|
32
16
|
* Scale a raw passing threshold to 0–1 for the LXPack parent bridge.
|
|
33
|
-
*
|
|
17
|
+
* Delegates to `@lxpack/spa-bridge` (default 0.7 when omitted).
|
|
34
18
|
*/
|
|
35
19
|
declare function normalizeAssessmentPassingScore(opts?: {
|
|
36
20
|
passingScore?: number;
|
|
@@ -43,10 +27,8 @@ declare function notifyLxpackCourseComplete(): boolean;
|
|
|
43
27
|
* Submit assessment results to the parent LXPack bridge.
|
|
44
28
|
* `score` must already be on a 0–1 scale (use `normalizeAssessmentScore` for raw points).
|
|
45
29
|
*/
|
|
46
|
-
declare function notifyLxpackAssessment(payload: {
|
|
30
|
+
declare function notifyLxpackAssessment(payload: LxpackBridgeSubmitAssessmentPayload & {
|
|
47
31
|
id: CheckId;
|
|
48
|
-
score: number;
|
|
49
|
-
passingScore?: number;
|
|
50
32
|
}): boolean;
|
|
51
33
|
|
|
52
|
-
export {
|
|
34
|
+
export { createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import {
|
|
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).
|
|
@@ -30,7 +14,7 @@ declare function normalizeAssessmentScore(opts: {
|
|
|
30
14
|
}): number | null;
|
|
31
15
|
/**
|
|
32
16
|
* Scale a raw passing threshold to 0–1 for the LXPack parent bridge.
|
|
33
|
-
*
|
|
17
|
+
* Delegates to `@lxpack/spa-bridge` (default 0.7 when omitted).
|
|
34
18
|
*/
|
|
35
19
|
declare function normalizeAssessmentPassingScore(opts?: {
|
|
36
20
|
passingScore?: number;
|
|
@@ -43,10 +27,8 @@ declare function notifyLxpackCourseComplete(): boolean;
|
|
|
43
27
|
* Submit assessment results to the parent LXPack bridge.
|
|
44
28
|
* `score` must already be on a 0–1 scale (use `normalizeAssessmentScore` for raw points).
|
|
45
29
|
*/
|
|
46
|
-
declare function notifyLxpackAssessment(payload: {
|
|
30
|
+
declare function notifyLxpackAssessment(payload: LxpackBridgeSubmitAssessmentPayload & {
|
|
47
31
|
id: CheckId;
|
|
48
|
-
score: number;
|
|
49
|
-
passingScore?: number;
|
|
50
32
|
}): boolean;
|
|
51
33
|
|
|
52
|
-
export {
|
|
34
|
+
export { createLxpackBridge, normalizeAssessmentPassingScore, normalizeAssessmentScore, notifyLxpackAssessment, notifyLxpackCourseComplete, notifyLxpackLessonComplete };
|
package/dist/bridge.js
CHANGED
|
@@ -1,24 +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
|
-
|
|
7
|
-
return Math.min(1, opts.score / maxScore);
|
|
29
|
+
return normalizeScore({ score: opts.score, maxScore: opts.maxScore });
|
|
8
30
|
}
|
|
9
31
|
function normalizeAssessmentPassingScore(opts) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const maxScore = typeof opts?.maxScore === "number" && opts.maxScore > 0 ? opts.maxScore : 1;
|
|
15
|
-
return Math.min(1, passingScore / maxScore);
|
|
32
|
+
return normalizePassingThreshold({
|
|
33
|
+
passingScore: opts?.passingScore,
|
|
34
|
+
maxScore: opts?.maxScore
|
|
35
|
+
});
|
|
16
36
|
}
|
|
17
|
-
function getBridge() {
|
|
37
|
+
function getBridge(parentWindow) {
|
|
38
|
+
const fromSdk = getLxpackBridgeFromParent(parentWindow);
|
|
39
|
+
if (fromSdk) return fromSdk;
|
|
18
40
|
if (typeof window === "undefined") return null;
|
|
19
|
-
const parent = window.parent;
|
|
41
|
+
const parent = parentWindow ?? window.parent;
|
|
20
42
|
if (!parent || parent === window) return null;
|
|
21
|
-
return parent.
|
|
43
|
+
return parent.lxpack ?? null;
|
|
22
44
|
}
|
|
23
45
|
function createLxpackBridge() {
|
|
24
46
|
return getBridge();
|
|
@@ -42,10 +64,21 @@ function notifyLxpackAssessment(payload) {
|
|
|
42
64
|
return true;
|
|
43
65
|
}
|
|
44
66
|
export {
|
|
67
|
+
DEFAULT_BRIDGE_PASSING_SCORE,
|
|
68
|
+
LESSONKIT_TELEMETRY_EVENTS,
|
|
69
|
+
LXPACK_BRIDGE_VERSIONS,
|
|
45
70
|
createLxpackBridge,
|
|
71
|
+
createLxpackBridgeHost2 as createLxpackBridgeHost,
|
|
72
|
+
getLxpackBridge,
|
|
73
|
+
mapLessonkitTelemetryToBridgeAction,
|
|
74
|
+
mapLessonkitTelemetryToLxpack,
|
|
46
75
|
normalizeAssessmentPassingScore,
|
|
47
76
|
normalizeAssessmentScore,
|
|
77
|
+
normalizePassingThreshold2 as normalizePassingThreshold,
|
|
78
|
+
normalizeScore2 as normalizeScore,
|
|
48
79
|
notifyLxpackAssessment,
|
|
49
80
|
notifyLxpackCourseComplete,
|
|
50
|
-
notifyLxpackLessonComplete
|
|
81
|
+
notifyLxpackLessonComplete,
|
|
82
|
+
supportedBridgeVersions,
|
|
83
|
+
telemetryEventToLessonkit
|
|
51
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
|
+
};
|