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.

Terminal
npm install @p2lrn/toolkit@0.5.0-alpha.11

Public 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.

TypeScript
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 / load

P2LRNAuthoringWorkspace and the aliases createAuthoringWorkspace(), openAuthoringWorkspace(), loadAuthoringWorkspace() manage the editable project.

addUnit

Add a unit within the course or another unit.

addFile / addUrl / addWebContent

Incorporate local resources, URLs or web content.

addQuestionnaire / addComponent / addComposite

Create assessment and native content.

setCourseMetadata / setEntityText / setChildren

Update metadata/text and explicit order.

setCourseRights

Save author, createdAt, license and copyrightHolder in the portable rights extension.

setProgression

Compulsory, blocking, completion, minimum grade and prerequisites apply.

build

Build 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.

DOCUMENT→reader()→structure→authorship decision→P2LRN content
DOCX / PPTX

Extract structure and internal content.

PDF

Reads text when available; needs pdfjs-dist as an optional dependency.

ODT / EPUB

Read the contents of the container.

TXT / Markdown / HTML / RTF / TEX / XML / YAML

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

Multipart

Divide large resources into verified parts. See guide.

Cambios incrementales (Delta)

Create and apply differences between packages when you need to transport changes.

Signing and trust

Generate keys, sign and verify packets using separate signatures.

Inspect / Reader

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.