CREATE / TOOLKIT
Toolkit for programmatic authoring
Toolkit is the authoring option when the course is generated from code, a server integration, or an automated process. If you're creating manually, Studio is usually the most direct route.
1. Before you start
Toolkit is installed using NPM and requires Node.js 22 or later. The current public prerelease is 0.5.0-alpha.11 under the dist-tag next.
npm install @p2lrn/toolkit@0.5.0-alpha.11Public subpaths: @p2lrn/toolkit/core, /reader, /creator, /authoring, /host and /document-reader.
2. Typical workflow
The code build flow has four steps: create a workspace, add structure and resources, apply optional rules, and build the final package.
import { P2LRNAuthoringWorkspace } from '@p2lrn/toolkit/authoring';
const workspace = P2LRNAuthoringWorkspace.create('./workspace', {
title: 'Basic digital safety course',
language: 'en',
});
workspace.addUnit({
key: 'unit-1',
title: 'Fundamentals',
});
workspace.addFile({
source: './material/intro.html',
key: 'intro',
title: 'Introduction',
parent: 'unit-1',
mediaType: 'text/html',
});
workspace.build('./course.p2lrn', {
strictProfiles: true,
});The workspace is the editable project; curso.p2lrn It is the portable file that you will deliver to the Player.
3. Authoring operations
create / open / loadP2LRNAuthoringWorkspace and the aliases createAuthoringWorkspace(), openAuthoringWorkspace(), loadAuthoringWorkspace() manage the editable project.
addUnitAdd a unit within the course or another unit.
addFile / addUrl / addWebContentIncorporate local resources, URLs or web content.
addQuestionnaire / addComponent / addCompositeCreate assessment and native content.
setCourseMetadata / setEntityText / setChildrenUpdate metadata/text and explicit order.
setCourseRightsSave author, createdAt, license and copyrightHolder in the portable rights extension.
setProgressionCompulsory, blocking, completion, minimum grade and prerequisites apply.
buildBuild and validate the final package.
4. Read documents before turning them into a course
Reader extracts structure; it doesn't decide for you which part of the document should become a lesson, activity, or resource. That decision remains in Studio, in your code or in the logic of your application.
Extract structure and internal content.
Reads text when available; needs pdfjs-dist as an optional dependency.
Read the contents of the container.
Realiza lectura estructural ligera.
5. Progression and quizzes
Navigation rules are added to the same workspace. Consultation Progress for required, gateFollowing, minimum grade and prerequisites. For evaluations and games consult Quizzes and games; Those guides include valid examples and exact technical identifiers.
6. When to use the CLI instead of the API
The API fits best within a TypeScript application. The CLI is useful in scripts, terminals, integration processes, or manual checks. Both work on the same format.
7. Advanced tools
Divide large resources into verified parts. See guide.
Create and apply differences between packages when you need to transport changes.
Generate keys, sign and verify packets using separate signatures.
They allow you to review structure, plans and content before or after the build.
8. Authoritative reference host
The subpath @p2lrn/toolkit/host incorporates a server-side implementation to test and build the host's authoritative boundary.
createReferenceAuthoritativeHost()Exposes a Host Adapter v1 with server-defined partitioning, state, events, resources, and authoritative qualification.
createMemoryAuthoritativeHostStore()Reference store for ephemeral tests/processes.
createJsonFileAuthoritativeHostStore(path)Reference atomic JSON persistence for a single process.
reportScore() demands a grade() from the server that returns authoritative:true; It does not automatically raise a note from the browser.