@playcademy/sandbox 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -176,7 +176,134 @@ Once running, the sandbox provides several key endpoints:
176
176
  - **API Base URL**: `/api`
177
177
  - **Real-time URL**: `ws://localhost:{realtimePort}`
178
178
 
179
- All production Playcademy APIs are available under the `/api` prefix, including `/users`, `/games`, `/inventory`, and more. Note that `/timeback` endpoints are available but return noop responses due to external API dependencies.
179
+ All production Playcademy APIs are available under the `/api` prefix, including `/users`, `/games`, `/inventory`, and more.
180
+
181
+ ## TimeBack Integration Testing
182
+
183
+ The sandbox supports three TimeBack modes for flexible development and testing.
184
+
185
+ ### Mode 1: Local TimeBack (Recommended for Development)
186
+
187
+ **Use local TimeBack Docker instance for offline development:**
188
+
189
+ ```bash
190
+ # Enable local mode
191
+ TIMEBACK_LOCAL=true
192
+
193
+ # Set local TimeBack URLs (different ports)
194
+ TIMEBACK_ONEROSTER_API_URL=http://localhost:9000
195
+ TIMEBACK_CALIPER_API_URL=http://localhost:9001
196
+
197
+ # Optional: pre-seed with course/student IDs
198
+ SANDBOX_TIMEBACK_COURSE_ID=local-dev-course
199
+ SANDBOX_TIMEBACK_STUDENT_ID=local-dev-student
200
+ ```
201
+
202
+ **Benefits:**
203
+
204
+ - ✅ No external API dependencies
205
+ - ✅ Works offline
206
+ - ✅ Fast iteration
207
+ - ✅ No real credentials needed
208
+
209
+ **Requirements:**
210
+
211
+ - Install and run `@superbuilders/timeback-local` Docker container
212
+
213
+ ### Mode 2: Remote TimeBack (Staging/Production)
214
+
215
+ **Connect to real TimeBack for end-to-end testing:**
216
+
217
+ ```bash
218
+ # Required: TimeBack API credentials
219
+ TIMEBACK_ONEROSTER_API_URL=https://api.timeback.org/ims/oneroster
220
+ TIMEBACK_API_CLIENT_ID=your-client-id
221
+ TIMEBACK_API_CLIENT_SECRET=your-client-secret
222
+ TIMEBACK_API_AUTH_URL=https://auth.timeback.org
223
+
224
+ # Optional: pre-seed with existing course/student
225
+ SANDBOX_TIMEBACK_COURSE_ID=your-existing-course-id
226
+ SANDBOX_TIMEBACK_STUDENT_ID=your-student-sourcedId
227
+ ```
228
+
229
+ **Benefits:**
230
+
231
+ - ✅ Tests against real TimeBack
232
+ - ✅ See actual events in TimeBack dashboard
233
+ - ✅ Full production simulation
234
+
235
+ **Pre-Seeding (Required for Local Testing):**
236
+
237
+ ```bash
238
+ SANDBOX_TIMEBACK_COURSE_ID=your-existing-course-id
239
+ SANDBOX_TIMEBACK_STUDENT_ID=your-existing-student-sourcedId
240
+ ```
241
+
242
+ These are **required** (not optional) for local TimeBack testing because the sandbox uses mock authentication. CLI commands like `playcademy timeback setup` won't work against the sandbox - you must use existing TimeBack resources.
243
+
244
+ **How to get these IDs:**
245
+
246
+ 1. Run `playcademy timeback setup` against the **platform** once (not sandbox)
247
+ 2. Get `courseId` from the output or your TimeBack dashboard
248
+ 3. Get `studentId` (sourcedId) from your TimeBack student roster
249
+ 4. Set them in `.env` for future local development
250
+
251
+ What they do:
252
+
253
+ - `SANDBOX_TIMEBACK_COURSE_ID` - Links your game to an existing TimeBack course
254
+ - `SANDBOX_TIMEBACK_STUDENT_ID` - Links the sandbox demo user to a real TimeBack student
255
+
256
+ ### Mode 3: Disabled (Default)
257
+
258
+ No TimeBack integration. TimeBack routes return errors. This is the default when no TimeBack environment variables are set.
259
+
260
+ ### Runtime Testing Workflow
261
+
262
+ Once you have TimeBack credentials and IDs configured:
263
+
264
+ ```bash
265
+ # 1. Start dev server
266
+ bun dev
267
+
268
+ # 2. Test in your game - TimeBack just works!
269
+ client.timeback.endActivity({
270
+ activityData: { activityId: 'test-1' },
271
+ scoreData: { correctQuestions: 8, totalQuestions: 10 },
272
+ timingData: { durationSeconds: 300 }
273
+ })
274
+
275
+ # 3. Check your TimeBack dashboard - events appear in real-time!
276
+ ```
277
+
278
+ **Note on CLI Commands:**
279
+ The sandbox provides TimeBack management endpoints, but CLI commands (`playcademy timeback setup`, `verify`) require Better Auth authentication and won't work against the sandbox. These commands should be run against the platform. Once you have a course/student ID from the platform, set them in your `.env` for local testing.
280
+
281
+ ### Available TimeBack Endpoints
282
+
283
+ The sandbox provides these TimeBack endpoints (matching production platform):
284
+
285
+ **Management:**
286
+
287
+ - `GET /api/timeback/integrations/:gameId` - Get integration details
288
+ - `POST /api/timeback/setup` - Create TimeBack integration
289
+ - `DELETE /api/timeback/integrations/:gameId` - Delete integration
290
+ - `GET /api/timeback/verify/:gameId` - Verify OneRoster resources
291
+ - `GET /api/timeback/config/:gameId` - Get TimeBack configuration
292
+
293
+ **Runtime:**
294
+
295
+ - `POST /api/timeback/end-activity` - Submit activity results
296
+
297
+ **XP Queries:**
298
+
299
+ - `GET /api/timeback/xp/today` - Get today's XP
300
+ - `PUT /api/timeback/xp/today` - Update today's XP
301
+ - `GET /api/timeback/xp/total` - Get total XP
302
+ - `GET /api/timeback/xp/history` - Get XP history
303
+
304
+ These use the same api-core handlers as the production platform, ensuring consistency.
305
+
306
+ When properly configured, your game can call `client.timeback.endActivity()` during local development and see real events appear in your TimeBack dashboard.
180
307
 
181
308
  ## Debugging
182
309