@pie-qti/assessment-player 0.1.1 โ 0.1.4
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/core/AssessmentPlayer.d.ts +14 -7
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +33 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +2 -2
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +5 -5
- package/dist/integration/api-contract.d.ts +16 -16
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +100 -80
- package/src/components/AssessmentShell.svelte +8 -8
- package/src/components/ItemRenderer.svelte +8 -8
- package/src/components/NavigationBar.svelte +3 -1
- package/src/components/RubricDisplay.svelte +2 -2
- package/src/core/AssessmentPlayer.ts +51 -44
- package/src/index.ts +1 -1
- package/src/integration/ReferenceBackendAdapter.ts +13 -13
- package/src/integration/api-contract.ts +16 -16
- package/src/integration/index.ts +5 -5
- package/src/types/index.ts +1 -1
- package/.turbo/turbo-build.log +0 -1
- package/BACKEND-INTEGRATION.md +0 -620
- package/CHANGELOG.md +0 -11
- package/EXTENSIBILITY.md +0 -551
- package/svelte.config.js +0 -8
- package/tests/ReferenceBackendAdapter.spec.ts +0 -309
- package/tests/setup.ts +0 -103
- package/tests/smoke.test.ts +0 -7
- package/tsconfig.json +0 -20
- package/tsconfig.svelte.json +0 -10
package/BACKEND-INTEGRATION.md
DELETED
|
@@ -1,620 +0,0 @@
|
|
|
1
|
-
## Backend Integration Guide
|
|
2
|
-
|
|
3
|
-
Complete guide for integrating the QTI 2.2 Assessment Player with secure backend services.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## TL;DR
|
|
8
|
-
|
|
9
|
-
- **By default**: Player runs 100% client-side, no backend required
|
|
10
|
-
- **For production**: Optionally integrate backend for security and persistence
|
|
11
|
-
- **Easy swap**: Provide a `BackendAdapter` implementation to enable backend mode
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Table of Contents
|
|
16
|
-
|
|
17
|
-
1. [Default Behavior (Client-Only)](#default-behavior-client-only)
|
|
18
|
-
2. [Security Model](#security-model)
|
|
19
|
-
3. [API Contract](#api-contract)
|
|
20
|
-
4. [Quick Start](#quick-start)
|
|
21
|
-
5. [Production Implementation](#production-implementation)
|
|
22
|
-
6. [Server-Side Requirements](#server-side-requirements)
|
|
23
|
-
7. [Example Implementations](#example-implementations)
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Default Behavior (Client-Only)
|
|
28
|
-
|
|
29
|
-
### No Backend Required
|
|
30
|
-
|
|
31
|
-
**The QTI 2.2 Assessment Player works completely standalone by default.**
|
|
32
|
-
|
|
33
|
-
Perfect for:
|
|
34
|
-
- ๐จ **Demos and prototypes** - Quick integration without infrastructure
|
|
35
|
-
- ๐งช **Development and testing** - Fast iteration, no server setup
|
|
36
|
-
- ๐ **Educational/training** - Self-contained learning modules
|
|
37
|
-
- ๐ฌ **Research and experimentation** - Offline-capable assessments
|
|
38
|
-
|
|
39
|
-
### How It Works
|
|
40
|
-
|
|
41
|
-
Without a backend adapter, the player:
|
|
42
|
-
1. Stores QTI XML in browser memory
|
|
43
|
-
2. Performs scoring client-side using the QTI engine
|
|
44
|
-
3. Persists state to localStorage (optional)
|
|
45
|
-
4. Runs completely offline
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { AssessmentPlayer } from '@pie-framework/assessment-player';
|
|
49
|
-
|
|
50
|
-
// Client-only mode (default) - works immediately
|
|
51
|
-
const player = new AssessmentPlayer({
|
|
52
|
-
assessment: myQtiAssessment, // QTI structure with itemXml
|
|
53
|
-
role: 'candidate'
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
await player.init();
|
|
57
|
-
// Ready to use - no server needed!
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### โ ๏ธ Client-Only Limitations
|
|
61
|
-
|
|
62
|
-
Be aware:
|
|
63
|
-
- **Security**: Correct answers visible in browser (inspect QTI XML)
|
|
64
|
-
- **Persistence**: Uses localStorage (can be cleared, limited storage)
|
|
65
|
-
- **Integrity**: Scores can be manipulated via browser devtools
|
|
66
|
-
- **Analytics**: No centralized data collection
|
|
67
|
-
|
|
68
|
-
**Use client-only mode for non-critical assessments where security isn't paramount.**
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Security Model
|
|
73
|
-
|
|
74
|
-
### Core Principle: Never Trust the Client
|
|
75
|
-
|
|
76
|
-
The assessment player follows a **zero-trust security model** where:
|
|
77
|
-
|
|
78
|
-
- **Client**: Collects and displays data only
|
|
79
|
-
- **Server**: Stores sensitive data, performs scoring, enforces rules
|
|
80
|
-
|
|
81
|
-
### What Must Stay Server-Side
|
|
82
|
-
|
|
83
|
-
โ
**MUST be server-side**:
|
|
84
|
-
- QTI XML with `<correctResponse>` elements
|
|
85
|
-
- `<responseProcessing>` rules and templates
|
|
86
|
-
- Scoring algorithms and rubrics
|
|
87
|
-
- Answer keys and solution content
|
|
88
|
-
- Assessment-level scoring rules
|
|
89
|
-
|
|
90
|
-
โ **NEVER send to client** (for `candidate` role):
|
|
91
|
-
- Correct answers
|
|
92
|
-
- Scoring formulas
|
|
93
|
-
- Point values
|
|
94
|
-
- Solution explanations
|
|
95
|
-
|
|
96
|
-
### Role-Based Data Filtering
|
|
97
|
-
|
|
98
|
-
The server MUST filter data based on QTI 2.2 roles:
|
|
99
|
-
|
|
100
|
-
| Role | Can See Correct Answers | Can See Scores | Can See Solutions |
|
|
101
|
-
|------|------------------------|----------------|-------------------|
|
|
102
|
-
| `candidate` | โ Never | โ ๏ธ After submission* | โ Never |
|
|
103
|
-
| `scorer` | โ
Yes | โ
Yes | โ
Yes |
|
|
104
|
-
| `author` | โ
Yes | โ
Yes | โ
Yes |
|
|
105
|
-
| `tutor` | โ
Yes | โ
Yes | โ
Yes |
|
|
106
|
-
| `proctor` | โ No | โ ๏ธ Limited | โ No |
|
|
107
|
-
| `testConstructor` | โ
Yes | โ
Yes | โ
Yes |
|
|
108
|
-
|
|
109
|
-
\* Depends on `submissionMode` and assessment configuration
|
|
110
|
-
|
|
111
|
-
### Attack Vectors to Prevent
|
|
112
|
-
|
|
113
|
-
1. **Client-side scoring manipulation**
|
|
114
|
-
- โ BAD: Calculate scores in browser JavaScript
|
|
115
|
-
- โ
GOOD: Send responses to server, return computed scores
|
|
116
|
-
|
|
117
|
-
2. **XML inspection**
|
|
118
|
-
- โ BAD: Send full QTI XML with `<correctResponse>` to candidates
|
|
119
|
-
- โ
GOOD: Strip sensitive elements server-side before sending
|
|
120
|
-
|
|
121
|
-
3. **Session hijacking**
|
|
122
|
-
- โ BAD: Use predictable session IDs
|
|
123
|
-
- โ
GOOD: Use cryptographically random session tokens
|
|
124
|
-
|
|
125
|
-
4. **Replay attacks**
|
|
126
|
-
- โ BAD: Allow unlimited re-submissions with same timestamp
|
|
127
|
-
- โ
GOOD: Validate submission order and enforce attempt limits
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
## API Contract
|
|
132
|
-
|
|
133
|
-
The backend adapter interface is defined in `src/integration/api-contract.ts`.
|
|
134
|
-
|
|
135
|
-
### Core Interface
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
interface BackendAdapter {
|
|
139
|
-
// Initialize new assessment session
|
|
140
|
-
initSession(request: InitSessionRequest): Promise<InitSessionResponse>;
|
|
141
|
-
|
|
142
|
-
// Submit responses for scoring
|
|
143
|
-
submitResponses(request: SubmitResponsesRequest): Promise<SubmitResponsesResponse>;
|
|
144
|
-
|
|
145
|
-
// Save state (auto-save)
|
|
146
|
-
saveState(request: SaveStateRequest): Promise<SaveStateResponse>;
|
|
147
|
-
|
|
148
|
-
// Finalize and get results
|
|
149
|
-
finalizeAssessment(request: FinalizeAssessmentRequest): Promise<FinalizeAssessmentResponse>;
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Key Types
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
// Session initialization
|
|
157
|
-
interface InitSessionRequest {
|
|
158
|
-
assessmentId: string;
|
|
159
|
-
candidateId: string;
|
|
160
|
-
resumeSessionId?: SessionId;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Response submission (client โ server)
|
|
164
|
-
interface SubmitResponsesRequest {
|
|
165
|
-
sessionId: SessionId;
|
|
166
|
-
itemIdentifier: string;
|
|
167
|
-
responses: Record<string, ResponseValue>; // Only responses, no scoring
|
|
168
|
-
submittedAt: number;
|
|
169
|
-
timeSpent?: number;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Scoring result (server โ client)
|
|
173
|
-
interface ScoringResult {
|
|
174
|
-
itemIdentifier: string;
|
|
175
|
-
score: number; // Computed SERVER-SIDE
|
|
176
|
-
maxScore: number;
|
|
177
|
-
completed: boolean;
|
|
178
|
-
outcomeValues: Record<string, any>;
|
|
179
|
-
feedback?: FeedbackItem[];
|
|
180
|
-
correctResponse?: Record<string, ResponseValue>; // Only if role allows
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## Quick Start
|
|
187
|
-
|
|
188
|
-
### 1. Reference Implementation (Development Only)
|
|
189
|
-
|
|
190
|
-
For local development and demos, use the provided reference adapter:
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
import { ReferenceBackendAdapter } from '@pie-framework/assessment-player/integration';
|
|
194
|
-
|
|
195
|
-
// โ ๏ธ WARNING: Insecure for production (client-side scoring)
|
|
196
|
-
const adapter = new ReferenceBackendAdapter();
|
|
197
|
-
|
|
198
|
-
const session = await adapter.initSession({
|
|
199
|
-
assessmentId: 'demo-assessment',
|
|
200
|
-
candidateId: 'student-123'
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
// Submit responses
|
|
204
|
-
await adapter.submitResponses({
|
|
205
|
-
sessionId: session.sessionId,
|
|
206
|
-
itemIdentifier: 'item-1',
|
|
207
|
-
responses: { RESPONSE: 'A' },
|
|
208
|
-
submittedAt: Date.now()
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Finalize
|
|
212
|
-
const results = await adapter.finalizeAssessment({
|
|
213
|
-
sessionId: session.sessionId
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### 2. Use in Assessment Player
|
|
218
|
-
|
|
219
|
-
```typescript
|
|
220
|
-
import { AssessmentPlayer } from '@pie-framework/assessment-player';
|
|
221
|
-
import { ReferenceBackendAdapter } from '@pie-framework/assessment-player/integration';
|
|
222
|
-
|
|
223
|
-
const player = new AssessmentPlayer({
|
|
224
|
-
backend: new ReferenceBackendAdapter(),
|
|
225
|
-
assessmentId: 'test-001',
|
|
226
|
-
candidateId: 'student-123'
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
await player.init();
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
## Production Implementation
|
|
235
|
-
|
|
236
|
-
### Server-Side Architecture
|
|
237
|
-
|
|
238
|
-
```
|
|
239
|
-
โโโโโโโโโโโโโโโ
|
|
240
|
-
โ Client โ
|
|
241
|
-
โ (Browser) โ
|
|
242
|
-
โโโโโโโโฌโโโโโโโ
|
|
243
|
-
โ HTTPS only
|
|
244
|
-
โ
|
|
245
|
-
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
246
|
-
โ API Gateway / Load Balancer โ
|
|
247
|
-
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
248
|
-
โ
|
|
249
|
-
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
250
|
-
โ Application Server (Node/Python/etc) โ
|
|
251
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
252
|
-
โ โ Authentication & Authorization โ โ
|
|
253
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
254
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
255
|
-
โ โ QTI XML Storage & Filtering โ โ
|
|
256
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
257
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
258
|
-
โ โ Response Processing Engine โ โ
|
|
259
|
-
โ โ (Server-side QTI scoring) โ โ
|
|
260
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
261
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
262
|
-
โ โ Session Management โ โ
|
|
263
|
-
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
264
|
-
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
265
|
-
โ
|
|
266
|
-
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
267
|
-
โ Database (PostgreSQL/etc) โ
|
|
268
|
-
โ - QTI XML (full, with correct answers) โ
|
|
269
|
-
โ - Session state โ
|
|
270
|
-
โ - Response history โ
|
|
271
|
-
โ - Scoring results โ
|
|
272
|
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Implement Your Backend Adapter
|
|
276
|
-
|
|
277
|
-
Create a class implementing `BackendAdapter`:
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
// src/adapters/MyBackendAdapter.ts
|
|
281
|
-
import type { BackendAdapter, InitSessionRequest, InitSessionResponse } from '@pie-framework/assessment-player/integration';
|
|
282
|
-
|
|
283
|
-
export class MyBackendAdapter implements BackendAdapter {
|
|
284
|
-
private baseUrl: string;
|
|
285
|
-
private authToken: string;
|
|
286
|
-
|
|
287
|
-
constructor(baseUrl: string, authToken: string) {
|
|
288
|
-
this.baseUrl = baseUrl;
|
|
289
|
-
this.authToken = authToken;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async initSession(request: InitSessionRequest): Promise<InitSessionResponse> {
|
|
293
|
-
const response = await fetch(`${this.baseUrl}/api/qti/sessions/init`, {
|
|
294
|
-
method: 'POST',
|
|
295
|
-
headers: {
|
|
296
|
-
'Content-Type': 'application/json',
|
|
297
|
-
'Authorization': `Bearer ${this.authToken}`
|
|
298
|
-
},
|
|
299
|
-
body: JSON.stringify(request)
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
if (!response.ok) {
|
|
303
|
-
throw new Error(`Init session failed: ${response.statusText}`);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return response.json();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
async submitResponses(request: SubmitResponsesRequest): Promise<SubmitResponsesResponse> {
|
|
310
|
-
const response = await fetch(`${this.baseUrl}/api/qti/responses/submit`, {
|
|
311
|
-
method: 'POST',
|
|
312
|
-
headers: {
|
|
313
|
-
'Content-Type': 'application/json',
|
|
314
|
-
'Authorization': `Bearer ${this.authToken}`
|
|
315
|
-
},
|
|
316
|
-
body: JSON.stringify(request)
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
return response.json();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// ... implement other methods
|
|
323
|
-
}
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
---
|
|
327
|
-
|
|
328
|
-
## Server-Side Requirements
|
|
329
|
-
|
|
330
|
-
### 1. QTI XML Filtering
|
|
331
|
-
|
|
332
|
-
**Before sending to candidate**, strip sensitive elements:
|
|
333
|
-
|
|
334
|
-
```typescript
|
|
335
|
-
// Server-side pseudocode
|
|
336
|
-
function filterQTIForCandidate(itemXml: string): string {
|
|
337
|
-
const dom = parseXML(itemXml);
|
|
338
|
-
|
|
339
|
-
// Remove correct responses
|
|
340
|
-
removeElements(dom, 'correctResponse');
|
|
341
|
-
|
|
342
|
-
// Remove response processing
|
|
343
|
-
removeElements(dom, 'responseProcessing');
|
|
344
|
-
|
|
345
|
-
// Remove solution feedback
|
|
346
|
-
removeElements(dom, 'modalFeedback[showHide="show"][outcomeIdentifier="SCORE"]');
|
|
347
|
-
|
|
348
|
-
return serializeXML(dom);
|
|
349
|
-
}
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### 2. Server-Side Scoring
|
|
353
|
-
|
|
354
|
-
Use the `Player` class on the server (Node.js):
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
// Server-side Node.js
|
|
358
|
-
import { Player } from '@pie-qti/item-player';
|
|
359
|
-
|
|
360
|
-
function scoreItem(itemXml: string, responses: Record<string, any>): ScoringResult {
|
|
361
|
-
// Use FULL QTI XML with responseProcessing
|
|
362
|
-
const player = new Player({
|
|
363
|
-
itemXml,
|
|
364
|
-
role: 'scorer' // Server always uses privileged role
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
// Set candidate responses
|
|
368
|
-
for (const [responseId, value] of Object.entries(responses)) {
|
|
369
|
-
player.setResponse(responseId, value);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Process and score
|
|
373
|
-
const result = player.processResponses();
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
itemIdentifier: player.getIdentifier(),
|
|
377
|
-
score: result.score,
|
|
378
|
-
maxScore: result.maxScore,
|
|
379
|
-
completed: result.completed,
|
|
380
|
-
outcomeValues: result.outcomeValues
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
### 3. Session Management
|
|
386
|
-
|
|
387
|
-
Store session state securely:
|
|
388
|
-
|
|
389
|
-
```sql
|
|
390
|
-
-- Example PostgreSQL schema
|
|
391
|
-
CREATE TABLE qti_sessions (
|
|
392
|
-
session_id UUID PRIMARY KEY,
|
|
393
|
-
assessment_id VARCHAR(255) NOT NULL,
|
|
394
|
-
candidate_id VARCHAR(255) NOT NULL,
|
|
395
|
-
state JSONB NOT NULL,
|
|
396
|
-
created_at TIMESTAMP DEFAULT NOW(),
|
|
397
|
-
finalized_at TIMESTAMP,
|
|
398
|
-
finalized BOOLEAN DEFAULT FALSE
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
CREATE TABLE qti_responses (
|
|
402
|
-
id SERIAL PRIMARY KEY,
|
|
403
|
-
session_id UUID REFERENCES qti_sessions(session_id),
|
|
404
|
-
item_identifier VARCHAR(255) NOT NULL,
|
|
405
|
-
responses JSONB NOT NULL,
|
|
406
|
-
score FLOAT,
|
|
407
|
-
max_score FLOAT,
|
|
408
|
-
submitted_at TIMESTAMP DEFAULT NOW()
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
CREATE INDEX idx_sessions_candidate ON qti_sessions(candidate_id);
|
|
412
|
-
CREATE INDEX idx_responses_session ON qti_responses(session_id);
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
### 4. API Endpoints
|
|
416
|
-
|
|
417
|
-
Example Express.js routes:
|
|
418
|
-
|
|
419
|
-
```typescript
|
|
420
|
-
// POST /api/qti/sessions/init
|
|
421
|
-
app.post('/api/qti/sessions/init', authenticate, async (req, res) => {
|
|
422
|
-
const { assessmentId, candidateId, resumeSessionId } = req.body;
|
|
423
|
-
|
|
424
|
-
// Validate candidate has access to assessment
|
|
425
|
-
await validateAccess(candidateId, assessmentId);
|
|
426
|
-
|
|
427
|
-
// Create or resume session
|
|
428
|
-
const session = resumeSessionId
|
|
429
|
-
? await resumeSession(resumeSessionId)
|
|
430
|
-
: await createSession(assessmentId, candidateId);
|
|
431
|
-
|
|
432
|
-
// Load assessment and filter for candidate role
|
|
433
|
-
const assessment = await loadAssessment(assessmentId);
|
|
434
|
-
const filteredAssessment = filterForRole(assessment, 'candidate');
|
|
435
|
-
|
|
436
|
-
res.json({
|
|
437
|
-
sessionId: session.id,
|
|
438
|
-
assessment: filteredAssessment
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
// POST /api/qti/responses/submit
|
|
443
|
-
app.post('/api/qti/responses/submit', authenticate, async (req, res) => {
|
|
444
|
-
const { sessionId, itemIdentifier, responses } = req.body;
|
|
445
|
-
|
|
446
|
-
// Validate session belongs to authenticated user
|
|
447
|
-
await validateSession(sessionId, req.user.id);
|
|
448
|
-
|
|
449
|
-
// Load FULL item XML (with correct answers)
|
|
450
|
-
const itemXml = await loadItemXml(itemIdentifier);
|
|
451
|
-
|
|
452
|
-
// Score SERVER-SIDE
|
|
453
|
-
const result = scoreItem(itemXml, responses);
|
|
454
|
-
|
|
455
|
-
// Store response and result
|
|
456
|
-
await storeResponse(sessionId, itemIdentifier, responses, result);
|
|
457
|
-
|
|
458
|
-
res.json({
|
|
459
|
-
success: true,
|
|
460
|
-
result
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
---
|
|
466
|
-
|
|
467
|
-
## Example Implementations
|
|
468
|
-
|
|
469
|
-
### Example 1: RESTful Backend
|
|
470
|
-
|
|
471
|
-
```typescript
|
|
472
|
-
export class RestBackendAdapter implements BackendAdapter {
|
|
473
|
-
constructor(
|
|
474
|
-
private apiUrl: string,
|
|
475
|
-
private authToken: string
|
|
476
|
-
) {}
|
|
477
|
-
|
|
478
|
-
async initSession(req: InitSessionRequest): Promise<InitSessionResponse> {
|
|
479
|
-
const res = await fetch(`${this.apiUrl}/sessions`, {
|
|
480
|
-
method: 'POST',
|
|
481
|
-
headers: {
|
|
482
|
-
'Authorization': `Bearer ${this.authToken}`,
|
|
483
|
-
'Content-Type': 'application/json'
|
|
484
|
-
},
|
|
485
|
-
body: JSON.stringify(req)
|
|
486
|
-
});
|
|
487
|
-
return res.json();
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// ... other methods
|
|
491
|
-
}
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
### Example 2: GraphQL Backend
|
|
495
|
-
|
|
496
|
-
```typescript
|
|
497
|
-
export class GraphQLBackendAdapter implements BackendAdapter {
|
|
498
|
-
constructor(private client: ApolloClient) {}
|
|
499
|
-
|
|
500
|
-
async initSession(req: InitSessionRequest): Promise<InitSessionResponse> {
|
|
501
|
-
const result = await this.client.mutate({
|
|
502
|
-
mutation: gql`
|
|
503
|
-
mutation InitSession($input: InitSessionInput!) {
|
|
504
|
-
initSession(input: $input) {
|
|
505
|
-
sessionId
|
|
506
|
-
assessment { ... }
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
`,
|
|
510
|
-
variables: { input: req }
|
|
511
|
-
});
|
|
512
|
-
return result.data.initSession;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// ... other methods
|
|
516
|
-
}
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### Example 3: WebSocket for Real-Time
|
|
520
|
-
|
|
521
|
-
```typescript
|
|
522
|
-
export class WebSocketBackendAdapter implements BackendAdapter {
|
|
523
|
-
constructor(private ws: WebSocket) {}
|
|
524
|
-
|
|
525
|
-
async submitResponses(req: SubmitResponsesRequest): Promise<SubmitResponsesResponse> {
|
|
526
|
-
return new Promise((resolve) => {
|
|
527
|
-
const requestId = crypto.randomUUID();
|
|
528
|
-
|
|
529
|
-
const handler = (event: MessageEvent) => {
|
|
530
|
-
const data = JSON.parse(event.data);
|
|
531
|
-
if (data.requestId === requestId) {
|
|
532
|
-
this.ws.removeEventListener('message', handler);
|
|
533
|
-
resolve(data.response);
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
this.ws.addEventListener('message', handler);
|
|
538
|
-
this.ws.send(JSON.stringify({
|
|
539
|
-
type: 'submitResponses',
|
|
540
|
-
requestId,
|
|
541
|
-
data: req
|
|
542
|
-
}));
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// ... other methods
|
|
547
|
-
}
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
---
|
|
551
|
-
|
|
552
|
-
## Security Checklist
|
|
553
|
-
|
|
554
|
-
Before deploying to production, verify:
|
|
555
|
-
|
|
556
|
-
- [ ] All scoring happens server-side
|
|
557
|
-
- [ ] Correct answers never sent to candidate clients
|
|
558
|
-
- [ ] QTI XML filtered based on role before sending to client
|
|
559
|
-
- [ ] Authentication enforced on all API endpoints
|
|
560
|
-
- [ ] Session IDs are cryptographically random
|
|
561
|
-
- [ ] HTTPS/TLS enforced for all connections
|
|
562
|
-
- [ ] CORS configured properly
|
|
563
|
-
- [ ] Rate limiting on submission endpoints
|
|
564
|
-
- [ ] Input validation on all requests
|
|
565
|
-
- [ ] SQL injection prevention (use parameterized queries)
|
|
566
|
-
- [ ] XSS prevention (sanitize HTML in feedback)
|
|
567
|
-
- [ ] Audit logging for all score changes
|
|
568
|
-
|
|
569
|
-
---
|
|
570
|
-
|
|
571
|
-
## Testing Your Implementation
|
|
572
|
-
|
|
573
|
-
Test your backend adapter:
|
|
574
|
-
|
|
575
|
-
```typescript
|
|
576
|
-
import { describe, it, expect } from 'bun:test';
|
|
577
|
-
import { MyBackendAdapter } from './MyBackendAdapter';
|
|
578
|
-
|
|
579
|
-
describe('MyBackendAdapter', () => {
|
|
580
|
-
it('should initialize session', async () => {
|
|
581
|
-
const adapter = new MyBackendAdapter('https://api.example.com', 'token');
|
|
582
|
-
const response = await adapter.initSession({
|
|
583
|
-
assessmentId: 'test-001',
|
|
584
|
-
candidateId: 'student-123'
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
expect(response.sessionId).toBeDefined();
|
|
588
|
-
expect(response.assessment).toBeDefined();
|
|
589
|
-
|
|
590
|
-
// SECURITY: Verify no correct answers in client response
|
|
591
|
-
const itemXml = response.assessment.testParts[0].sections[0].items[0].itemXml;
|
|
592
|
-
expect(itemXml).not.toContain('<correctResponse>');
|
|
593
|
-
expect(itemXml).not.toContain('<responseProcessing>');
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
it('should score responses server-side', async () => {
|
|
597
|
-
const adapter = new MyBackendAdapter('https://api.example.com', 'token');
|
|
598
|
-
|
|
599
|
-
// Mock incorrect response
|
|
600
|
-
const response = await adapter.submitResponses({
|
|
601
|
-
sessionId: 'test-session',
|
|
602
|
-
itemIdentifier: 'item-1',
|
|
603
|
-
responses: { RESPONSE: 'B' }, // Wrong answer
|
|
604
|
-
submittedAt: Date.now()
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
expect(response.success).toBe(true);
|
|
608
|
-
expect(response.result?.score).toBe(0); // Should be scored server-side
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
---
|
|
614
|
-
|
|
615
|
-
## Support
|
|
616
|
-
|
|
617
|
-
For questions or issues:
|
|
618
|
-
- GitHub Issues: https://github.com/pie-framework/pie-qti/issues
|
|
619
|
-
- API Contract: `src/integration/api-contract.ts`
|
|
620
|
-
- Reference Implementation: `src/integration/ReferenceBackendAdapter.ts`
|
package/CHANGELOG.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# @pie-qti/assessment-player
|
|
2
|
-
|
|
3
|
-
## 0.1.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 2243643: Publish the initial public release of all publishable PIE-QTI packages.
|
|
8
|
-
- Updated dependencies [2243643]
|
|
9
|
-
- @pie-qti/qti-processing@0.1.1
|
|
10
|
-
- @pie-qti/default-components@0.1.1
|
|
11
|
-
- @pie-qti/item-player@0.1.1
|