coursecode 0.1.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/LICENSE +21 -0
- package/README.md +322 -0
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/bin/cli.js +331 -0
- package/framework/assets/logo-coursecode-black.svg +14 -0
- package/framework/assets/logo-coursecode-white.svg +14 -0
- package/framework/assets/logo-coursecode.svg +14 -0
- package/framework/css/01-base.css +160 -0
- package/framework/css/02-layout.css +499 -0
- package/framework/css/accessibility.css +834 -0
- package/framework/css/components/accordions.css +710 -0
- package/framework/css/components/assessments.css +520 -0
- package/framework/css/components/audio-player.css +570 -0
- package/framework/css/components/badges.css +80 -0
- package/framework/css/components/breadcrumbs.css +87 -0
- package/framework/css/components/buttons.css +707 -0
- package/framework/css/components/callouts.css +1280 -0
- package/framework/css/components/cards.css +475 -0
- package/framework/css/components/carousel.css +193 -0
- package/framework/css/components/checkbox-group.css +123 -0
- package/framework/css/components/checklist.css +203 -0
- package/framework/css/components/collapse.css +96 -0
- package/framework/css/components/comparison.css +33 -0
- package/framework/css/components/content-image.css +36 -0
- package/framework/css/components/document-gallery.css +425 -0
- package/framework/css/components/dropdown.css +115 -0
- package/framework/css/components/embed-frame.css +142 -0
- package/framework/css/components/engagement.css +412 -0
- package/framework/css/components/features.css +35 -0
- package/framework/css/components/flip-cards.css +253 -0
- package/framework/css/components/footer.css +353 -0
- package/framework/css/components/forms.css +294 -0
- package/framework/css/components/hero.css +216 -0
- package/framework/css/components/images.css +528 -0
- package/framework/css/components/interactive-timeline.css +274 -0
- package/framework/css/components/intro-cards.css +30 -0
- package/framework/css/components/lightbox.css +666 -0
- package/framework/css/components/loading.css +65 -0
- package/framework/css/components/modals.css +235 -0
- package/framework/css/components/notifications.css +107 -0
- package/framework/css/components/quote.css +150 -0
- package/framework/css/components/sidebar.css +684 -0
- package/framework/css/components/slide-header.css +52 -0
- package/framework/css/components/spinner.css +62 -0
- package/framework/css/components/stats.css +44 -0
- package/framework/css/components/steps.css +232 -0
- package/framework/css/components/tables.css +90 -0
- package/framework/css/components/tabs.css +347 -0
- package/framework/css/components/timeline.css +154 -0
- package/framework/css/components/toggle.css +95 -0
- package/framework/css/components/tooltip.css +226 -0
- package/framework/css/components/video-player.css +438 -0
- package/framework/css/design-tokens.css +707 -0
- package/framework/css/framework.css +86 -0
- package/framework/css/interactions/accessibility.css +75 -0
- package/framework/css/interactions/base.css +92 -0
- package/framework/css/interactions/drag-drop.css +295 -0
- package/framework/css/interactions/fill-in-the-blank.css +236 -0
- package/framework/css/interactions/hotspots.css +69 -0
- package/framework/css/interactions/index.css +45 -0
- package/framework/css/interactions/interactive-image.css +359 -0
- package/framework/css/interactions/likert.css +126 -0
- package/framework/css/interactions/matching.css +354 -0
- package/framework/css/interactions/numeric-input.css +78 -0
- package/framework/css/interactions/sequencing.css +378 -0
- package/framework/css/interactions/true-false.css +177 -0
- package/framework/css/layouts/article.css +258 -0
- package/framework/css/layouts/base.css +30 -0
- package/framework/css/layouts/canvas.css +38 -0
- package/framework/css/layouts/focused.css +236 -0
- package/framework/css/layouts/index.css +29 -0
- package/framework/css/layouts/presentation.css +191 -0
- package/framework/css/layouts/traditional.css +52 -0
- package/framework/css/responsive.css +439 -0
- package/framework/css/utilities/accessibility-utils.css +59 -0
- package/framework/css/utilities/animations.css +419 -0
- package/framework/css/utilities/borders.css +72 -0
- package/framework/css/utilities/colors.css +76 -0
- package/framework/css/utilities/container.css +46 -0
- package/framework/css/utilities/decorative.css +442 -0
- package/framework/css/utilities/display.css +257 -0
- package/framework/css/utilities/flexbox.css +80 -0
- package/framework/css/utilities/grid.css +69 -0
- package/framework/css/utilities/icons.css +534 -0
- package/framework/css/utilities/lists.css +190 -0
- package/framework/css/utilities/spacing.css +167 -0
- package/framework/css/utilities/tables.css +81 -0
- package/framework/css/utilities/typography.css +159 -0
- package/framework/css/utilities/visibility.css +117 -0
- package/framework/docs/COURSE_AUTHORING_GUIDE.md +1773 -0
- package/framework/docs/COURSE_OUTLINE_GUIDE.md +725 -0
- package/framework/docs/COURSE_OUTLINE_TEMPLATE.md +161 -0
- package/framework/docs/DATA_MODEL.md +409 -0
- package/framework/docs/FRAMEWORK_GUIDE.md +1088 -0
- package/framework/docs/USER_GUIDE.md +583 -0
- package/framework/docs/examples/cloudflare-channel-relay.js +169 -0
- package/framework/docs/examples/cloudflare-data-worker.js +102 -0
- package/framework/docs/examples/cloudflare-error-worker.js +228 -0
- package/framework/index.html +175 -0
- package/framework/js/app/AppActions.js +410 -0
- package/framework/js/app/AppState.js +225 -0
- package/framework/js/app/AppUI.js +616 -0
- package/framework/js/assessment/AssessmentActions.js +615 -0
- package/framework/js/assessment/AssessmentFactory.js +471 -0
- package/framework/js/assessment/AssessmentState.js +322 -0
- package/framework/js/assessment/AssessmentUI.js +451 -0
- package/framework/js/automation/api-engagement.js +196 -0
- package/framework/js/automation/api-interactions.js +167 -0
- package/framework/js/automation/api.js +242 -0
- package/framework/js/automation/index.js +41 -0
- package/framework/js/components/interactions/drag-drop.js +884 -0
- package/framework/js/components/interactions/fill-in.js +535 -0
- package/framework/js/components/interactions/hotspot.js +702 -0
- package/framework/js/components/interactions/interaction-base.js +511 -0
- package/framework/js/components/interactions/likert.js +301 -0
- package/framework/js/components/interactions/matching.js +699 -0
- package/framework/js/components/interactions/multiple-choice.js +377 -0
- package/framework/js/components/interactions/numeric.js +271 -0
- package/framework/js/components/interactions/sequencing.js +423 -0
- package/framework/js/components/interactions/true-false.js +241 -0
- package/framework/js/components/ui-components/accordion.js +442 -0
- package/framework/js/components/ui-components/alert.js +88 -0
- package/framework/js/components/ui-components/audio-player.js +1193 -0
- package/framework/js/components/ui-components/callout.js +121 -0
- package/framework/js/components/ui-components/carousel.js +145 -0
- package/framework/js/components/ui-components/checkbox-group.js +87 -0
- package/framework/js/components/ui-components/checklist.js +40 -0
- package/framework/js/components/ui-components/collapse.js +114 -0
- package/framework/js/components/ui-components/comparison.js +30 -0
- package/framework/js/components/ui-components/conditional-display.js +150 -0
- package/framework/js/components/ui-components/content-image.js +41 -0
- package/framework/js/components/ui-components/dropdown.js +262 -0
- package/framework/js/components/ui-components/embed-frame.js +274 -0
- package/framework/js/components/ui-components/features.js +33 -0
- package/framework/js/components/ui-components/flip-card.js +230 -0
- package/framework/js/components/ui-components/form-validator.js +76 -0
- package/framework/js/components/ui-components/hero.js +49 -0
- package/framework/js/components/ui-components/index.js +12 -0
- package/framework/js/components/ui-components/interactive-image.js +235 -0
- package/framework/js/components/ui-components/interactive-timeline.js +285 -0
- package/framework/js/components/ui-components/intro-cards.js +35 -0
- package/framework/js/components/ui-components/lightbox.js +652 -0
- package/framework/js/components/ui-components/modal.js +386 -0
- package/framework/js/components/ui-components/notifications.js +145 -0
- package/framework/js/components/ui-components/progress.js +88 -0
- package/framework/js/components/ui-components/quote.js +41 -0
- package/framework/js/components/ui-components/stats.js +33 -0
- package/framework/js/components/ui-components/steps.js +41 -0
- package/framework/js/components/ui-components/tabs.js +255 -0
- package/framework/js/components/ui-components/timeline.js +42 -0
- package/framework/js/components/ui-components/toggle-group.js +73 -0
- package/framework/js/components/ui-components/tooltip.js +458 -0
- package/framework/js/components/ui-components/value-display.js +133 -0
- package/framework/js/components/ui-components/video-player.js +686 -0
- package/framework/js/core/component-catalog.js +121 -0
- package/framework/js/core/event-bus.js +178 -0
- package/framework/js/core/interaction-catalog.js +149 -0
- package/framework/js/dev/runtime-linter.js +1725 -0
- package/framework/js/drivers/cmi5-driver.js +768 -0
- package/framework/js/drivers/driver-factory.js +77 -0
- package/framework/js/drivers/driver-interface.js +110 -0
- package/framework/js/drivers/http-driver-base.js +241 -0
- package/framework/js/drivers/lti-driver.js +508 -0
- package/framework/js/drivers/proxy-driver.js +444 -0
- package/framework/js/drivers/scorm-12-driver.js +560 -0
- package/framework/js/drivers/scorm-2004-driver.js +775 -0
- package/framework/js/drivers/scorm-driver-base.js +112 -0
- package/framework/js/engagement/engagement-manager.js +404 -0
- package/framework/js/engagement/engagement-progress.js +191 -0
- package/framework/js/engagement/engagement-trackers.js +215 -0
- package/framework/js/engagement/requirement-strategies.js +268 -0
- package/framework/js/main.js +727 -0
- package/framework/js/managers/accessibility-manager.js +499 -0
- package/framework/js/managers/assessment-manager.js +230 -0
- package/framework/js/managers/audio-manager.js +944 -0
- package/framework/js/managers/comment-manager.js +88 -0
- package/framework/js/managers/flag-manager.js +86 -0
- package/framework/js/managers/interaction-manager.js +254 -0
- package/framework/js/managers/interaction-registry.js +96 -0
- package/framework/js/managers/objective-manager.js +423 -0
- package/framework/js/managers/score-manager.js +441 -0
- package/framework/js/managers/video-manager.js +536 -0
- package/framework/js/navigation/Breadcrumbs.js +234 -0
- package/framework/js/navigation/NavigationActions.js +1132 -0
- package/framework/js/navigation/NavigationState.js +276 -0
- package/framework/js/navigation/NavigationUI.js +574 -0
- package/framework/js/navigation/document-gallery.js +357 -0
- package/framework/js/navigation/navigation-helpers.js +175 -0
- package/framework/js/navigation/navigation-validators.js +174 -0
- package/framework/js/state/index.js +8 -0
- package/framework/js/state/lms-connection.js +482 -0
- package/framework/js/state/lms-error-utils.js +58 -0
- package/framework/js/state/state-commits.js +200 -0
- package/framework/js/state/state-domains.js +86 -0
- package/framework/js/state/state-manager.js +502 -0
- package/framework/js/state/state-validation.js +311 -0
- package/framework/js/state/transaction-log.js +41 -0
- package/framework/js/state/xapi-statement-service.js +325 -0
- package/framework/js/utilities/access-control.js +99 -0
- package/framework/js/utilities/breakpoint-manager.js +315 -0
- package/framework/js/utilities/canvas-slide.js +35 -0
- package/framework/js/utilities/conditional-display.js +388 -0
- package/framework/js/utilities/course-channel.js +214 -0
- package/framework/js/utilities/course-helpers.js +420 -0
- package/framework/js/utilities/data-reporter.js +273 -0
- package/framework/js/utilities/error-reporter.js +313 -0
- package/framework/js/utilities/hotspot-helper.js +341 -0
- package/framework/js/utilities/icons.js +348 -0
- package/framework/js/utilities/logger.js +92 -0
- package/framework/js/utilities/markdown-renderer.js +45 -0
- package/framework/js/utilities/scroll-tracker.js +68 -0
- package/framework/js/utilities/ui-initializer.js +146 -0
- package/framework/js/utilities/utilities.js +293 -0
- package/framework/js/utilities/view-manager.js +227 -0
- package/framework/js/validation/html-validators.js +422 -0
- package/framework/js/validation/scorm-validators.js +438 -0
- package/framework/js/vendor/pipwerks.js +931 -0
- package/framework/scripts/generate-narration.js +629 -0
- package/framework/scripts/tts-providers/azure-provider.js +178 -0
- package/framework/scripts/tts-providers/base-provider.js +81 -0
- package/framework/scripts/tts-providers/deepgram-provider.js +135 -0
- package/framework/scripts/tts-providers/elevenlabs-provider.js +148 -0
- package/framework/scripts/tts-providers/google-provider.js +272 -0
- package/framework/scripts/tts-providers/index.js +158 -0
- package/framework/scripts/tts-providers/openai-provider.js +143 -0
- package/framework/version.json +63 -0
- package/lib/authoring-api.js +919 -0
- package/lib/build-linter.js +450 -0
- package/lib/build-packaging.js +186 -0
- package/lib/build.js +88 -0
- package/lib/cloud.js +691 -0
- package/lib/convert.js +341 -0
- package/lib/course-parser.js +936 -0
- package/lib/course-writer.js +258 -0
- package/lib/create.js +248 -0
- package/lib/css-index.js +237 -0
- package/lib/dev.js +51 -0
- package/lib/export-content.js +1246 -0
- package/lib/headless-browser.js +413 -0
- package/lib/import.js +377 -0
- package/lib/index.js +80 -0
- package/lib/info.js +79 -0
- package/lib/interaction-formatters.js +568 -0
- package/lib/manifest/cmi5-manifest.js +63 -0
- package/lib/manifest/lti-tool-config.js +53 -0
- package/lib/manifest/manifest-factory.js +99 -0
- package/lib/manifest/scorm-12-manifest.js +61 -0
- package/lib/manifest/scorm-2004-manifest.js +94 -0
- package/lib/manifest/scorm-proxy-manifest.js +104 -0
- package/lib/manifest-parser.js +96 -0
- package/lib/mcp-prompts.js +753 -0
- package/lib/mcp-server.js +316 -0
- package/lib/narration.js +53 -0
- package/lib/pdf-structure.js +142 -0
- package/lib/preview-export.js +231 -0
- package/lib/preview-routes-api.js +662 -0
- package/lib/preview-routes-editing.js +159 -0
- package/lib/preview-routes-lms.js +230 -0
- package/lib/preview-server.js +564 -0
- package/lib/project-utils.js +269 -0
- package/lib/proxy-templates/proxy.html +68 -0
- package/lib/proxy-templates/scorm-bridge.js +112 -0
- package/lib/scaffold.js +193 -0
- package/lib/schema-extractor.js +361 -0
- package/lib/slide-source-editor.js +586 -0
- package/lib/stub-player/app-viewer.js +195 -0
- package/lib/stub-player/app.js +370 -0
- package/lib/stub-player/catalog-panel.js +312 -0
- package/lib/stub-player/config-panel.js +1303 -0
- package/lib/stub-player/content-generator.js +586 -0
- package/lib/stub-player/content-viewer.js +173 -0
- package/lib/stub-player/debug-panel.js +420 -0
- package/lib/stub-player/edit-mode.js +922 -0
- package/lib/stub-player/edit-utils.js +400 -0
- package/lib/stub-player/header-bar.js +354 -0
- package/lib/stub-player/interaction-editor.js +210 -0
- package/lib/stub-player/interactions-panel.js +565 -0
- package/lib/stub-player/lms-api.js +1094 -0
- package/lib/stub-player/login-screen.js +74 -0
- package/lib/stub-player/outline-mode.js +689 -0
- package/lib/stub-player/styles/_assessments-panel.css +245 -0
- package/lib/stub-player/styles/_base.css +89 -0
- package/lib/stub-player/styles/_catalog-icons.css +96 -0
- package/lib/stub-player/styles/_catalog-panel.css +291 -0
- package/lib/stub-player/styles/_config-panel.css +636 -0
- package/lib/stub-player/styles/_content-viewer.css +834 -0
- package/lib/stub-player/styles/_debug-panel.css +576 -0
- package/lib/stub-player/styles/_edit-mode.css +128 -0
- package/lib/stub-player/styles/_header-bar.css +343 -0
- package/lib/stub-player/styles/_interaction-editor.css +140 -0
- package/lib/stub-player/styles/_interactions-panel.css +1038 -0
- package/lib/stub-player/styles/_login-screen.css +102 -0
- package/lib/stub-player/styles/_outline-mode.css +752 -0
- package/lib/stub-player/styles.css +15 -0
- package/lib/stub-player.js +160 -0
- package/lib/test-data-reporting.js +176 -0
- package/lib/test-error-reporting.js +146 -0
- package/lib/token.js +86 -0
- package/lib/upgrade.js +257 -0
- package/lib/validation-rules.js +517 -0
- package/lib/vite-plugin-content-discovery.js +296 -0
- package/package.json +108 -0
- package/schemas/XMLSchema.dtd +402 -0
- package/schemas/adlcp_v1p3.xsd +111 -0
- package/schemas/adlnav_v1p3.xsd +61 -0
- package/schemas/adlseq_v1p3.xsd +93 -0
- package/schemas/common/anyElement.xsd +27 -0
- package/schemas/common/dataTypes.xsd +138 -0
- package/schemas/common/elementNames.xsd +767 -0
- package/schemas/common/elementTypes.xsd +786 -0
- package/schemas/common/rootElement.xsd +31 -0
- package/schemas/common/vocabTypes.xsd +345 -0
- package/schemas/common/vocabValues.xsd +257 -0
- package/schemas/datatypes.dtd +203 -0
- package/schemas/ims_xml.xsd +35 -0
- package/schemas/imscp_v1p1.xsd +368 -0
- package/schemas/imsss_v1p0.xsd +67 -0
- package/schemas/imsss_v1p0auxresource.xsd +19 -0
- package/schemas/imsss_v1p0control.xsd +20 -0
- package/schemas/imsss_v1p0delivery.xsd +17 -0
- package/schemas/imsss_v1p0limit.xsd +47 -0
- package/schemas/imsss_v1p0objective.xsd +67 -0
- package/schemas/imsss_v1p0random.xsd +16 -0
- package/schemas/imsss_v1p0rollup.xsd +46 -0
- package/schemas/imsss_v1p0seqrule.xsd +108 -0
- package/schemas/imsss_v1p0util.xsd +94 -0
- package/schemas/license.txt +17 -0
- package/schemas/lom.xsd +102 -0
- package/schemas/lomCustom.xsd +62 -0
- package/schemas/lomLoose.xsd +62 -0
- package/schemas/lomStrict.xsd +62 -0
- package/schemas/xml.xsd +81 -0
- package/template/.env.example +92 -0
- package/template/course/assets/audio/example-intro.mp3 +0 -0
- package/template/course/assets/audio/example-ui-demo--compact-player.mp3 +0 -0
- package/template/course/assets/audio/example-ui-demo--demo-modal.mp3 +0 -0
- package/template/course/assets/audio/example-ui-demo--full-player.mp3 +0 -0
- package/template/course/assets/docs/example_md_1.md +39 -0
- package/template/course/assets/docs/example_md_2.md +41 -0
- package/template/course/assets/docs/example_pdf_1_thumbnail.png +0 -0
- package/template/course/assets/docs/example_pdf_2.pdf +0 -0
- package/template/course/assets/images/course-architecture.svg +36 -0
- package/template/course/assets/images/logo.svg +14 -0
- package/template/course/assets/widgets/counter-demo.html +190 -0
- package/template/course/assets/widgets/gravity-painter.html +384 -0
- package/template/course/course-config.js +539 -0
- package/template/course/icons.js +19 -0
- package/template/course/interactions/PLUGIN_GUIDE.md +97 -0
- package/template/course/slides/example-course-structure.js +138 -0
- package/template/course/slides/example-final-exam.js +144 -0
- package/template/course/slides/example-finishing.js +127 -0
- package/template/course/slides/example-interactions-showcase.js +615 -0
- package/template/course/slides/example-preview-tour.js +129 -0
- package/template/course/slides/example-remedial.js +143 -0
- package/template/course/slides/example-summary.js +103 -0
- package/template/course/slides/example-ui-showcase.js +1805 -0
- package/template/course/slides/example-welcome.js +123 -0
- package/template/course/slides/example-workflow.js +140 -0
- package/template/course/theme.css +165 -0
- package/template/eslint.config.js +47 -0
- package/template/package.json +28 -0
- package/template/vite.config.js +339 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lti-driver.js
|
|
3
|
+
* @description LTI 1.3 driver implementation.
|
|
4
|
+
* Extends HttpDriverBase for shared mock state, suspend data, and semantic interface.
|
|
5
|
+
*
|
|
6
|
+
* LTI 1.3 launch flow:
|
|
7
|
+
* 1. Platform redirects to tool with id_token (JWT) via OIDC
|
|
8
|
+
* 2. Driver validates JWT using platform's JWKS endpoint
|
|
9
|
+
* 3. State persistence via host-provided state endpoint
|
|
10
|
+
* 4. Score reporting via AGS (Assignment and Grade Services)
|
|
11
|
+
*
|
|
12
|
+
* This driver adds:
|
|
13
|
+
* - JWT validation and claims extraction
|
|
14
|
+
* - AGS score passback on terminate
|
|
15
|
+
* - State persistence via host endpoint
|
|
16
|
+
* - Emergency save via sendBeacon
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { HttpDriverBase } from './http-driver-base.js';
|
|
20
|
+
import { logger } from '../utilities/logger.js';
|
|
21
|
+
|
|
22
|
+
// jose is dynamically imported in initialize() to avoid bundling for non-LTI builds
|
|
23
|
+
|
|
24
|
+
// =============================================================================
|
|
25
|
+
// LTI Driver Class
|
|
26
|
+
// =============================================================================
|
|
27
|
+
|
|
28
|
+
export class LtiDriver extends HttpDriverBase {
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
|
|
32
|
+
// JWT claims extracted at launch
|
|
33
|
+
this._claims = null;
|
|
34
|
+
|
|
35
|
+
// AGS endpoint (from JWT claims)
|
|
36
|
+
this._agsEndpoint = null;
|
|
37
|
+
this._agsLineItemUrl = null;
|
|
38
|
+
this._accessToken = null;
|
|
39
|
+
|
|
40
|
+
// Host state endpoint for suspend_data persistence
|
|
41
|
+
this._stateEndpoint = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// =========================================================================
|
|
45
|
+
// Interface Implementation
|
|
46
|
+
// =========================================================================
|
|
47
|
+
|
|
48
|
+
getFormat() {
|
|
49
|
+
return 'lti';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getCapabilities() {
|
|
53
|
+
return {
|
|
54
|
+
supportsObjectives: true, // via suspend_data
|
|
55
|
+
supportsInteractions: true, // via suspend_data
|
|
56
|
+
supportsComments: true, // via suspend_data
|
|
57
|
+
supportsEmergencySave: true,
|
|
58
|
+
maxSuspendDataBytes: 0, // unlimited (host-dependent)
|
|
59
|
+
asyncCommit: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Initializes the LTI 1.3 connection.
|
|
65
|
+
*/
|
|
66
|
+
async initialize() {
|
|
67
|
+
if (this._isConnected) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check for LTI dev API (stub player)
|
|
72
|
+
// Search current window and parent frame (stub player injects on parent)
|
|
73
|
+
const devApi = typeof window !== 'undefined' && (window.lti || (window.parent !== window && window.parent.lti));
|
|
74
|
+
if (devApi) {
|
|
75
|
+
logger.info('[LtiDriver] Using LTI development API');
|
|
76
|
+
this._mock = true;
|
|
77
|
+
this._devApi = devApi;
|
|
78
|
+
this._devApi.initialize();
|
|
79
|
+
this._loadMockState();
|
|
80
|
+
this._isConnected = true;
|
|
81
|
+
this._logMockStatement('initialized', { verb: 'initialized' });
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Check for LTI launch parameters
|
|
86
|
+
if (!this._hasLaunchParameters()) {
|
|
87
|
+
logger.info('[LtiDriver] No LTI launch parameters. Using localStorage mock.');
|
|
88
|
+
this._mock = true;
|
|
89
|
+
this._loadMockState();
|
|
90
|
+
this._isConnected = true;
|
|
91
|
+
this._logMockStatement('initialized', { verb: 'initialized' });
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Production mode: validate JWT and extract claims
|
|
96
|
+
try {
|
|
97
|
+
await this._processLaunch();
|
|
98
|
+
await this._prefetchState();
|
|
99
|
+
|
|
100
|
+
this._isConnected = true;
|
|
101
|
+
logger.debug('[LtiDriver] Initialized via LTI 1.3');
|
|
102
|
+
return true;
|
|
103
|
+
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (import.meta.env.DEV) {
|
|
106
|
+
logger.warn('[LtiDriver] LTI launch failed, using mock mode:', error.message);
|
|
107
|
+
this._mock = true;
|
|
108
|
+
this._loadMockState();
|
|
109
|
+
this._isConnected = true;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw new Error(`[LtiDriver] Initialization failed: ${error.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Terminates the LTI session.
|
|
119
|
+
*/
|
|
120
|
+
async terminate() {
|
|
121
|
+
if (!this._isConnected || this._isTerminated) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (this._mock) {
|
|
126
|
+
return this._terminateMock();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
await this._persistState();
|
|
131
|
+
await this._postScore();
|
|
132
|
+
|
|
133
|
+
this._isTerminated = true;
|
|
134
|
+
logger.debug('[LtiDriver] Session terminated');
|
|
135
|
+
return true;
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
logger.error('[LtiDriver] Terminate failed:', error);
|
|
139
|
+
this._isTerminated = true;
|
|
140
|
+
throw new Error(`[LtiDriver] Termination failed: ${error.message}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Emergency save using sendBeacon for page unload scenarios.
|
|
146
|
+
*/
|
|
147
|
+
emergencySave() {
|
|
148
|
+
if (this._mock || this._isTerminated) {
|
|
149
|
+
if (this._mock) {
|
|
150
|
+
this._saveMockState();
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!this._stateEndpoint) {
|
|
156
|
+
logger.warn('[LtiDriver] emergencySave: No state endpoint configured');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const stateKey = this._getStateKey();
|
|
161
|
+
if (!stateKey) return;
|
|
162
|
+
|
|
163
|
+
if (this._suspendDataDirty && this._suspendDataCache !== null) {
|
|
164
|
+
const payload = {
|
|
165
|
+
key: stateKey,
|
|
166
|
+
type: 'suspend_data',
|
|
167
|
+
data: this._suspendDataCache
|
|
168
|
+
};
|
|
169
|
+
const blob = new Blob([JSON.stringify(payload)], { type: 'application/json' });
|
|
170
|
+
const sent = navigator.sendBeacon(this._stateEndpoint, blob);
|
|
171
|
+
if (sent) {
|
|
172
|
+
logger.debug('[LtiDriver] Emergency save: suspend_data sent via sendBeacon');
|
|
173
|
+
} else {
|
|
174
|
+
logger.warn('[LtiDriver] Emergency save: sendBeacon failed for suspend_data');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this._bookmarkDirty) {
|
|
179
|
+
const payload = {
|
|
180
|
+
key: stateKey,
|
|
181
|
+
type: 'bookmark',
|
|
182
|
+
data: {
|
|
183
|
+
location: this._bookmarkCache,
|
|
184
|
+
completionStatus: this._completionStatus,
|
|
185
|
+
successStatus: this._successStatus,
|
|
186
|
+
score: this._score
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const blob = new Blob([JSON.stringify(payload)], { type: 'application/json' });
|
|
190
|
+
const sent = navigator.sendBeacon(this._stateEndpoint, blob);
|
|
191
|
+
if (sent) {
|
|
192
|
+
logger.debug('[LtiDriver] Emergency save: bookmark sent via sendBeacon');
|
|
193
|
+
} else {
|
|
194
|
+
logger.warn('[LtiDriver] Emergency save: sendBeacon failed for bookmark');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// =========================================================================
|
|
200
|
+
// Semantic Reads (override)
|
|
201
|
+
// =========================================================================
|
|
202
|
+
|
|
203
|
+
getLearnerInfo() {
|
|
204
|
+
return {
|
|
205
|
+
id: this._claims?.sub || 'dev-learner',
|
|
206
|
+
name: this._claims?.name || this._claims?.given_name || 'Development User'
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// =========================================================================
|
|
211
|
+
// LTI-specific Methods
|
|
212
|
+
// =========================================================================
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Gets LTI launch data.
|
|
216
|
+
*/
|
|
217
|
+
getLaunchData() {
|
|
218
|
+
if (this._mock) {
|
|
219
|
+
if (this._devApi && typeof this._devApi.getLaunchData === 'function') {
|
|
220
|
+
return this._devApi.getLaunchData();
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
userId: 'preview_user',
|
|
224
|
+
name: 'Preview User',
|
|
225
|
+
roles: ['Learner'],
|
|
226
|
+
resourceLinkId: 'preview-resource',
|
|
227
|
+
contextId: 'preview-context'
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!this._claims) return null;
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
userId: this._claims.sub,
|
|
235
|
+
name: this._claims.name || this._claims.given_name,
|
|
236
|
+
roles: this._claims['https://purl.imsglobal.org/spec/lti/claim/roles'] || [],
|
|
237
|
+
resourceLinkId: this._claims['https://purl.imsglobal.org/spec/lti/claim/resource_link']?.id,
|
|
238
|
+
contextId: this._claims['https://purl.imsglobal.org/spec/lti/claim/context']?.id,
|
|
239
|
+
contextTitle: this._claims['https://purl.imsglobal.org/spec/lti/claim/context']?.title,
|
|
240
|
+
returnUrl: this._claims['https://purl.imsglobal.org/spec/lti/claim/launch_presentation']?.return_url
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// =========================================================================
|
|
245
|
+
// Private: LTI 1.3 Launch Processing
|
|
246
|
+
// =========================================================================
|
|
247
|
+
|
|
248
|
+
_hasLaunchParameters() {
|
|
249
|
+
if (typeof window === 'undefined') return false;
|
|
250
|
+
|
|
251
|
+
const params = new URLSearchParams(window.location.search);
|
|
252
|
+
return Boolean(
|
|
253
|
+
params.get('id_token') ||
|
|
254
|
+
params.get('state') ||
|
|
255
|
+
window.location.hash.includes('id_token')
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async _processLaunch() {
|
|
260
|
+
const { jwtVerify, createRemoteJWKSet } = await import('jose');
|
|
261
|
+
|
|
262
|
+
const params = new URLSearchParams(window.location.search);
|
|
263
|
+
const idToken = params.get('id_token');
|
|
264
|
+
|
|
265
|
+
if (!idToken) {
|
|
266
|
+
throw new Error('No id_token found in launch parameters');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const [headerB64] = idToken.split('.');
|
|
270
|
+
const header = JSON.parse(atob(headerB64));
|
|
271
|
+
|
|
272
|
+
const jwksUrl = this._getJwksUrl(header);
|
|
273
|
+
const JWKS = createRemoteJWKSet(new URL(jwksUrl));
|
|
274
|
+
|
|
275
|
+
const { payload } = await jwtVerify(idToken, JWKS, {
|
|
276
|
+
algorithms: ['RS256', 'ES256']
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
this._validateLtiClaims(payload);
|
|
280
|
+
this._claims = payload;
|
|
281
|
+
|
|
282
|
+
const agsEndpoint = payload['https://purl.imsglobal.org/spec/lti-ags/claim/endpoint'];
|
|
283
|
+
if (agsEndpoint) {
|
|
284
|
+
this._agsEndpoint = agsEndpoint.lineitems;
|
|
285
|
+
this._agsLineItemUrl = agsEndpoint.lineitem;
|
|
286
|
+
logger.debug('[LtiDriver] AGS endpoint configured:', this._agsEndpoint);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this._stateEndpoint = this._resolveStateEndpoint();
|
|
290
|
+
logger.debug('[LtiDriver] Launch processed. User:', payload.sub);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
_validateLtiClaims(claims) {
|
|
294
|
+
const messageType = claims['https://purl.imsglobal.org/spec/lti/claim/message_type'];
|
|
295
|
+
if (messageType !== 'LtiResourceLinkRequest') {
|
|
296
|
+
throw new Error(`Unsupported LTI message type: ${messageType}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const version = claims['https://purl.imsglobal.org/spec/lti/claim/version'];
|
|
300
|
+
if (version !== '1.3.0') {
|
|
301
|
+
throw new Error(`Unsupported LTI version: ${version}`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (!claims['https://purl.imsglobal.org/spec/lti/claim/deployment_id']) {
|
|
305
|
+
throw new Error('Missing required claim: deployment_id');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (!claims['https://purl.imsglobal.org/spec/lti/claim/resource_link']?.id) {
|
|
309
|
+
throw new Error('Missing required claim: resource_link.id');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!claims.sub) {
|
|
313
|
+
throw new Error('Missing required claim: sub');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
_getJwksUrl(_header) {
|
|
318
|
+
const meta = document.querySelector('meta[name="lti-jwks-url"]');
|
|
319
|
+
if (meta) return meta.content;
|
|
320
|
+
|
|
321
|
+
if (window.__LTI_CONFIG__?.jwksUrl) return window.__LTI_CONFIG__.jwksUrl;
|
|
322
|
+
|
|
323
|
+
throw new Error('JWKS URL not configured. Set via meta tag or window.__LTI_CONFIG__.');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
_resolveStateEndpoint() {
|
|
327
|
+
const meta = document.querySelector('meta[name="lti-state-endpoint"]');
|
|
328
|
+
if (meta) return meta.content;
|
|
329
|
+
|
|
330
|
+
if (window.__LTI_CONFIG__?.stateEndpoint) return window.__LTI_CONFIG__.stateEndpoint;
|
|
331
|
+
|
|
332
|
+
return '/api/lti/state';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
_getStateKey() {
|
|
336
|
+
if (this._claims) {
|
|
337
|
+
const resourceLink = this._claims['https://purl.imsglobal.org/spec/lti/claim/resource_link']?.id;
|
|
338
|
+
return `${resourceLink}:${this._claims.sub}`;
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// =========================================================================
|
|
344
|
+
// Private: State Persistence via Host Endpoint
|
|
345
|
+
// =========================================================================
|
|
346
|
+
|
|
347
|
+
async _prefetchState() {
|
|
348
|
+
if (!this._stateEndpoint) return;
|
|
349
|
+
|
|
350
|
+
const stateKey = this._getStateKey();
|
|
351
|
+
if (!stateKey) return;
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
const response = await fetch(`${this._stateEndpoint}?key=${encodeURIComponent(stateKey)}`, {
|
|
355
|
+
headers: this._getAuthHeaders()
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (response.ok) {
|
|
359
|
+
const state = await response.json();
|
|
360
|
+
this._suspendDataCache = state.suspendData || null;
|
|
361
|
+
this._bookmarkCache = state.bookmark || null;
|
|
362
|
+
this._completionStatus = state.completionStatus || 'unknown';
|
|
363
|
+
this._successStatus = state.successStatus || 'unknown';
|
|
364
|
+
this._score = state.score ?? null;
|
|
365
|
+
logger.debug('[LtiDriver] State pre-fetched');
|
|
366
|
+
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
logger.warn('[LtiDriver] Failed to prefetch state:', error.message);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async _persistState() {
|
|
373
|
+
if (!this._stateEndpoint) return;
|
|
374
|
+
|
|
375
|
+
const stateKey = this._getStateKey();
|
|
376
|
+
if (!stateKey) return;
|
|
377
|
+
|
|
378
|
+
const dirty = this._suspendDataDirty || this._bookmarkDirty;
|
|
379
|
+
if (!dirty) return;
|
|
380
|
+
|
|
381
|
+
const payload = {
|
|
382
|
+
key: stateKey,
|
|
383
|
+
suspendData: this._suspendDataDirty ? this._suspendDataCache : undefined,
|
|
384
|
+
bookmark: this._bookmarkCache,
|
|
385
|
+
completionStatus: this._completionStatus,
|
|
386
|
+
successStatus: this._successStatus,
|
|
387
|
+
score: this._score
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const response = await fetch(this._stateEndpoint, {
|
|
391
|
+
method: 'POST',
|
|
392
|
+
headers: {
|
|
393
|
+
'Content-Type': 'application/json',
|
|
394
|
+
...this._getAuthHeaders()
|
|
395
|
+
},
|
|
396
|
+
body: JSON.stringify(payload)
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
if (!response.ok) {
|
|
400
|
+
throw new Error(`State persistence failed: ${response.status} ${response.statusText}`);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
this._suspendDataDirty = false;
|
|
404
|
+
this._bookmarkDirty = false;
|
|
405
|
+
logger.debug('[LtiDriver] State persisted');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
_getAuthHeaders() {
|
|
409
|
+
if (this._accessToken) {
|
|
410
|
+
return { 'Authorization': `Bearer ${this._accessToken}` };
|
|
411
|
+
}
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// =========================================================================
|
|
416
|
+
// Private: AGS Score Passback
|
|
417
|
+
// =========================================================================
|
|
418
|
+
|
|
419
|
+
async _postScore() {
|
|
420
|
+
if (!this._agsLineItemUrl || this._score === null) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
try {
|
|
425
|
+
const scorePayload = {
|
|
426
|
+
userId: this._claims.sub,
|
|
427
|
+
scoreGiven: this._score * 100,
|
|
428
|
+
scoreMaximum: 100,
|
|
429
|
+
comment: '',
|
|
430
|
+
timestamp: new Date().toISOString(),
|
|
431
|
+
activityProgress: this._completionStatus === 'completed' ? 'Completed' : 'InProgress',
|
|
432
|
+
gradingProgress: this._successStatus !== 'unknown' ? 'FullyGraded' : 'NotReady'
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const scoreUrl = `${this._agsLineItemUrl}/scores`;
|
|
436
|
+
await fetch(scoreUrl, {
|
|
437
|
+
method: 'POST',
|
|
438
|
+
headers: {
|
|
439
|
+
'Content-Type': 'application/vnd.ims.lis.v1.score+json',
|
|
440
|
+
...this._getAuthHeaders()
|
|
441
|
+
},
|
|
442
|
+
body: JSON.stringify(scorePayload)
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
logger.debug('[LtiDriver] Score posted to AGS:', this._score);
|
|
446
|
+
|
|
447
|
+
} catch (error) {
|
|
448
|
+
logger.error('[LtiDriver] Failed to post score to AGS:', error.message);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// =========================================================================
|
|
453
|
+
// Private: Development Mode (no LTI platform)
|
|
454
|
+
// =========================================================================
|
|
455
|
+
|
|
456
|
+
_loadMockState() {
|
|
457
|
+
try {
|
|
458
|
+
if (this._devApi) {
|
|
459
|
+
const state = this._devApi.getState('lti_state');
|
|
460
|
+
if (state) {
|
|
461
|
+
this._mockState = state;
|
|
462
|
+
this._bookmarkCache = state.bookmark || null;
|
|
463
|
+
this._completionStatus = state.completionStatus || 'unknown';
|
|
464
|
+
this._successStatus = state.successStatus || 'unknown';
|
|
465
|
+
this._score = state.score ?? null;
|
|
466
|
+
}
|
|
467
|
+
this._mockState.suspendData = this._devApi.getState('suspend_data') || null;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const stored = localStorage.getItem('lti_dev_state');
|
|
472
|
+
if (stored) {
|
|
473
|
+
const parsed = JSON.parse(stored);
|
|
474
|
+
this._mockState = parsed;
|
|
475
|
+
this._bookmarkCache = parsed.bookmark || null;
|
|
476
|
+
this._completionStatus = parsed.completionStatus || 'unknown';
|
|
477
|
+
this._successStatus = parsed.successStatus || 'unknown';
|
|
478
|
+
this._score = parsed.score ?? null;
|
|
479
|
+
}
|
|
480
|
+
} catch (_e) {
|
|
481
|
+
this._mockState = {};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
_saveMockState() {
|
|
486
|
+
try {
|
|
487
|
+
const state = {
|
|
488
|
+
...this._mockState,
|
|
489
|
+
bookmark: this._bookmarkCache,
|
|
490
|
+
completionStatus: this._completionStatus,
|
|
491
|
+
successStatus: this._successStatus,
|
|
492
|
+
score: this._score
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
if (this._devApi) {
|
|
496
|
+
this._devApi.setState('lti_state', state);
|
|
497
|
+
if (this._mockState.suspendData) {
|
|
498
|
+
this._devApi.setState('suspend_data', this._mockState.suspendData);
|
|
499
|
+
}
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
localStorage.setItem('lti_dev_state', JSON.stringify(state));
|
|
504
|
+
} catch (e) {
|
|
505
|
+
logger.warn('[LtiDriver] Failed to save mock state:', e);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|