@playcademy/sandbox 0.10.1 → 0.10.2-beta.2

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/server.js CHANGED
@@ -280,6 +280,19 @@ var init_platform = __esm(() => {
280
280
  };
281
281
  });
282
282
 
283
+ // ../constants/src/skills.ts
284
+ var SKILL_STATUS_ROUTE = "/__playcademy/skills/status", SKILL_STATUS_TOKEN_AUDIENCE = "playcademy-game-skill-status", SKILL_STATUS_MAX_SKILLS = 50, SKILL_STATUSES, SKILL_MASTERY_SOURCES;
285
+ var init_skills = __esm(() => {
286
+ SKILL_STATUSES = [
287
+ "locked",
288
+ "unlocked",
289
+ "in_progress",
290
+ "mastered",
291
+ "unknown_skill"
292
+ ];
293
+ SKILL_MASTERY_SOURCES = ["assessment", "placement", "test_out", "manual"];
294
+ });
295
+
283
296
  // ../constants/src/system.ts
284
297
  var PLATFORM_TIMEZONE = "America/New_York";
285
298
 
@@ -372,6 +385,7 @@ var init_src = __esm(() => {
372
385
  init_env_vars();
373
386
  init_game();
374
387
  init_platform();
388
+ init_skills();
375
389
  init_timeback2();
376
390
  init_cloudflare();
377
391
  });
@@ -1127,7 +1141,7 @@ var package_default;
1127
1141
  var init_package = __esm(() => {
1128
1142
  package_default = {
1129
1143
  name: "@playcademy/sandbox",
1130
- version: "0.10.1",
1144
+ version: "0.10.2-beta.2",
1131
1145
  description: "Local development server for Playcademy game development",
1132
1146
  type: "module",
1133
1147
  exports: {
@@ -30004,6 +30018,23 @@ function generateDeploymentHash(code) {
30004
30018
  function computeDeployPayloadFingerprint(payload) {
30005
30019
  return sha256Hex(canonicalJson2(payload));
30006
30020
  }
30021
+ function toActiveDeploymentRow(record) {
30022
+ return {
30023
+ gameId: record.gameId,
30024
+ deploymentId: record.deploymentId,
30025
+ provider: "cloudflare",
30026
+ target: record.target,
30027
+ url: record.url,
30028
+ codeHash: record.codeHash,
30029
+ schemaHash: record.schemaHash ?? null,
30030
+ schemaFingerprint: record.schemaFingerprint ?? null,
30031
+ timeTravelBookmark: record.timeTravelBookmark ?? null,
30032
+ bookmarkCapturedAt: record.bookmarkCapturedAt ?? null,
30033
+ resources: record.resources,
30034
+ isActive: true,
30035
+ deployJobId: record.deployJobId ?? null
30036
+ };
30037
+ }
30007
30038
  var GAME_WORKER_KEY_PREFIX = "game-worker-", DASHBOARD_WORKER_KEY_PREFIX = "dash-worker-";
30008
30039
  var init_deployment_util = __esm(() => {
30009
30040
  init_drizzle_orm();
@@ -37027,24 +37058,9 @@ class DeployService {
37027
37058
  }
37028
37059
  }
37029
37060
  async saveDeployment(record) {
37030
- const db2 = this.deps.db;
37031
- await db2.transaction(async (tx) => {
37061
+ await this.deps.db.transaction(async (tx) => {
37032
37062
  await tx.update(gameDeployments).set({ isActive: false }).where(and(eq(gameDeployments.gameId, record.gameId), eq(gameDeployments.target, record.target)));
37033
- await tx.insert(gameDeployments).values({
37034
- gameId: record.gameId,
37035
- deploymentId: record.deploymentId,
37036
- provider: "cloudflare",
37037
- target: record.target,
37038
- url: record.url,
37039
- codeHash: record.codeHash,
37040
- schemaHash: record.schemaHash ?? null,
37041
- schemaFingerprint: record.schemaFingerprint ?? null,
37042
- timeTravelBookmark: record.timeTravelBookmark ?? null,
37043
- bookmarkCapturedAt: record.bookmarkCapturedAt ?? null,
37044
- resources: record.resources,
37045
- isActive: true,
37046
- deployJobId: record.deployJobId ?? null
37047
- });
37063
+ await tx.insert(gameDeployments).values(toActiveDeploymentRow(record));
37048
37064
  });
37049
37065
  }
37050
37066
  async notifyDeploymentFailure(failure) {
@@ -46876,6 +46892,39 @@ function publishableRepositoryUrl(value) {
46876
46892
  return value;
46877
46893
  }
46878
46894
 
46895
+ // ../api-core/src/utils/releases.util.ts
46896
+ function toRelease(row) {
46897
+ return {
46898
+ slug: row.slug,
46899
+ url: row.url,
46900
+ source: normalizeDeploySource(row.source),
46901
+ deployedAt: row.deployedAt.toISOString()
46902
+ };
46903
+ }
46904
+ function toGameReleaseResponse(rows, history) {
46905
+ const releases = rows.map(toRelease);
46906
+ const current = releases[0] ?? null;
46907
+ return history === undefined ? { current } : { current, history: releases };
46908
+ }
46909
+ function normalizeDeploySource(value) {
46910
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
46911
+ return null;
46912
+ }
46913
+ const raw = value;
46914
+ const repository = nullableString(raw.repository);
46915
+ return {
46916
+ repository: repository === null ? null : publishableRepositoryUrl(repository),
46917
+ commit: nullableString(raw.commit),
46918
+ branch: nullableString(raw.branch),
46919
+ dirty: raw.dirty === true,
46920
+ externalBuild: raw.externalBuild === true
46921
+ };
46922
+ }
46923
+ function nullableString(value) {
46924
+ return typeof value === "string" && value.length > 0 ? value : null;
46925
+ }
46926
+ var init_releases_util = () => {};
46927
+
46879
46928
  // ../api-core/src/services/releases.service.ts
46880
46929
  class ReleasesService {
46881
46930
  deps;
@@ -46900,9 +46949,7 @@ class ReleasesService {
46900
46949
  "app.releases.history_requested": history ?? 0,
46901
46950
  "app.releases.history_rows": rows.length
46902
46951
  });
46903
- const releases = rows.map(toRelease);
46904
- const current = releases[0] ?? null;
46905
- return history === undefined ? { current } : { current, history: releases };
46952
+ return toGameReleaseResponse(rows, history);
46906
46953
  }
46907
46954
  }
46908
46955
  function releaseColumns() {
@@ -46919,36 +46966,12 @@ function listedGame() {
46919
46966
  function activeWorkerDeployment() {
46920
46967
  return and(eq(gameDeployments.isActive, true), eq(gameDeployments.target, "game"));
46921
46968
  }
46922
- function toRelease(row) {
46923
- return {
46924
- slug: row.slug,
46925
- url: row.url,
46926
- source: normalizeSource(row.source),
46927
- deployedAt: row.deployedAt.toISOString()
46928
- };
46929
- }
46930
- function normalizeSource(value) {
46931
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
46932
- return null;
46933
- }
46934
- const raw = value;
46935
- const repository = nullableString(raw.repository);
46936
- return {
46937
- repository: repository === null ? null : publishableRepositoryUrl(repository),
46938
- commit: nullableString(raw.commit),
46939
- branch: nullableString(raw.branch),
46940
- dirty: raw.dirty === true,
46941
- externalBuild: raw.externalBuild === true
46942
- };
46943
- }
46944
- function nullableString(value) {
46945
- return typeof value === "string" && value.length > 0 ? value : null;
46946
- }
46947
46969
  var init_releases_service = __esm(() => {
46948
46970
  init_drizzle_orm();
46949
46971
  init_tables_index();
46950
46972
  init_spans();
46951
46973
  init_errors2();
46974
+ init_releases_util();
46952
46975
  });
46953
46976
 
46954
46977
  // ../api-core/src/services/secrets.service.ts
@@ -47404,6 +47427,226 @@ var init_seed_service = __esm(() => {
47404
47427
  init_deployment_util();
47405
47428
  });
47406
47429
 
47430
+ // ../api-core/src/utils/game-worker-call.util.ts
47431
+ function resolveGameWorkerBaseUrl(localGameUrls, slug, deployedUrl) {
47432
+ return (slug ? localGameUrls[slug] : undefined) ?? deployedUrl;
47433
+ }
47434
+ async function callGameWorker(url, token, options) {
47435
+ const controller = new AbortController;
47436
+ const timeout = setTimeout(() => controller.abort(), options.timeoutMs);
47437
+ try {
47438
+ const response = await fetch(url, {
47439
+ method: "GET",
47440
+ headers: {
47441
+ Accept: "application/json",
47442
+ Authorization: `Bearer ${token}`
47443
+ },
47444
+ signal: controller.signal
47445
+ });
47446
+ const body2 = await response.text();
47447
+ return {
47448
+ ok: true,
47449
+ response: new Response(NULL_BODY_STATUSES.has(response.status) ? null : body2, {
47450
+ status: response.status,
47451
+ headers: response.headers
47452
+ })
47453
+ };
47454
+ } catch (error) {
47455
+ if (error instanceof Error && error.name === "AbortError") {
47456
+ return { ok: false, reason: "timeout", details: options.timeoutMessage };
47457
+ }
47458
+ return { ok: false, reason: "fetch_failed", details: errorMessage(error) };
47459
+ } finally {
47460
+ clearTimeout(timeout);
47461
+ }
47462
+ }
47463
+ var NULL_BODY_STATUSES;
47464
+ var init_game_worker_call_util = __esm(() => {
47465
+ NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
47466
+ });
47467
+
47468
+ // ../utils/src/skills.ts
47469
+ function normalizeSkillId(skill) {
47470
+ return skill.trim().toLowerCase();
47471
+ }
47472
+ function normalizeSkillIds(skills2, max) {
47473
+ const normalized = [...new Set(skills2.map(normalizeSkillId).filter((skill) => skill.length > 0))];
47474
+ if (normalized.length === 0) {
47475
+ return { ok: false, error: "At least one skill is required" };
47476
+ }
47477
+ if (normalized.length > max) {
47478
+ return { ok: false, error: `At most ${max} skills can be requested at once` };
47479
+ }
47480
+ return { ok: true, skills: normalized };
47481
+ }
47482
+
47483
+ // ../edge-play/src/game/lib/skills.ts
47484
+ function isValidIsoDate(value) {
47485
+ if (typeof value !== "string" || !ISO_DATE_PATTERN.test(value)) {
47486
+ return false;
47487
+ }
47488
+ const [year, month, day] = value.slice(0, 10).split("-").map(Number);
47489
+ const date3 = new Date(Date.UTC(year, month - 1, day));
47490
+ return !isNaN(Date.parse(value)) && date3.getUTCFullYear() === year && date3.getUTCMonth() === month - 1 && date3.getUTCDate() === day;
47491
+ }
47492
+ function normalizeResult(result) {
47493
+ if (!isRecord(result)) {
47494
+ return null;
47495
+ }
47496
+ if (typeof result.skill !== "string" || !STATUSES.has(result.status)) {
47497
+ return null;
47498
+ }
47499
+ const status = result.status;
47500
+ if (result.source !== undefined) {
47501
+ if (status !== "mastered" || !MASTERY_SOURCES.has(result.source)) {
47502
+ return null;
47503
+ }
47504
+ }
47505
+ if (result.asOf !== undefined && !isValidIsoDate(result.asOf)) {
47506
+ return null;
47507
+ }
47508
+ return {
47509
+ skill: normalizeSkillId(result.skill),
47510
+ status,
47511
+ ...result.source === undefined ? {} : { source: result.source },
47512
+ ...result.asOf === undefined ? {} : { asOf: result.asOf }
47513
+ };
47514
+ }
47515
+ function validateSkillStatusResponse(value, studentId, askedSkills) {
47516
+ if (!isRecord(value)) {
47517
+ return null;
47518
+ }
47519
+ const response = value;
47520
+ if (response.studentId !== studentId || !Array.isArray(response.results)) {
47521
+ return null;
47522
+ }
47523
+ const asked = new Set(askedSkills);
47524
+ const results = new Map;
47525
+ for (const raw of response.results) {
47526
+ const result = normalizeResult(raw);
47527
+ if (!result || !asked.has(result.skill) || results.has(result.skill)) {
47528
+ return null;
47529
+ }
47530
+ results.set(result.skill, result);
47531
+ }
47532
+ return results.size === asked.size ? results : null;
47533
+ }
47534
+ var STATUSES, MASTERY_SOURCES, ISO_DATE_PATTERN;
47535
+ var init_skills2 = __esm(() => {
47536
+ init_src();
47537
+ STATUSES = new Set(SKILL_STATUSES);
47538
+ MASTERY_SOURCES = new Set(SKILL_MASTERY_SOURCES);
47539
+ ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2}))?$/;
47540
+ });
47541
+
47542
+ // ../api-core/src/utils/skill-status.util.ts
47543
+ function normalizeSkillStatusRequest(skills2) {
47544
+ const normalized = normalizeSkillIds(skills2, SKILL_STATUS_MAX_SKILLS);
47545
+ if (!normalized.ok) {
47546
+ throw new ValidationError(normalized.error);
47547
+ }
47548
+ return normalized.skills;
47549
+ }
47550
+ function buildSkillStatusUrl(baseUrl, skills2) {
47551
+ const url = new URL(SKILL_STATUS_ROUTE, baseUrl);
47552
+ for (const skill of skills2) {
47553
+ url.searchParams.append("skill", skill);
47554
+ }
47555
+ return url;
47556
+ }
47557
+ function pickSkillStatusGames(rows, requestingSlug, answeringSlug) {
47558
+ const requestingGame = rows.find((row) => row.slug === requestingSlug);
47559
+ const answeringGame = rows.find((row) => row.slug === answeringSlug);
47560
+ if (!requestingGame) {
47561
+ throw new NotFoundError("Game", requestingSlug);
47562
+ }
47563
+ if (!answeringGame) {
47564
+ throw new NotFoundError("Game", answeringSlug);
47565
+ }
47566
+ return { requestingGame, answeringGame };
47567
+ }
47568
+ async function classifySkillStatusResponse(response, studentId, skills2) {
47569
+ if (response.status === 404) {
47570
+ return { supported: false, reason: "not_implemented" };
47571
+ }
47572
+ if (!response.ok) {
47573
+ return { supported: false, reason: "fetch_failed" };
47574
+ }
47575
+ let json3;
47576
+ try {
47577
+ json3 = JSON.parse(await response.text());
47578
+ } catch {
47579
+ return { supported: false, reason: "not_implemented" };
47580
+ }
47581
+ const answered = validateSkillStatusResponse(json3, studentId, skills2);
47582
+ if (!answered) {
47583
+ return { supported: false, reason: "invalid_response" };
47584
+ }
47585
+ return { supported: true, results: skills2.map((skill) => answered.get(skill)) };
47586
+ }
47587
+ var init_skill_status_util = __esm(() => {
47588
+ init_src();
47589
+ init_skills2();
47590
+ init_errors2();
47591
+ });
47592
+
47593
+ // ../api-core/src/services/skill-status.service.ts
47594
+ class SkillStatusService {
47595
+ deps;
47596
+ constructor(deps) {
47597
+ this.deps = deps;
47598
+ }
47599
+ async getStatus(input) {
47600
+ const skills2 = normalizeSkillStatusRequest(input.skills);
47601
+ setAttributes({
47602
+ "app.skill_status.requesting_game": input.requestingGameSlug,
47603
+ "app.skill_status.answering_game": input.game,
47604
+ "app.skill_status.skill_count": skills2.length
47605
+ });
47606
+ const rows = await this.deps.db.select({ id: games.id, slug: games.slug }).from(games).where(inArray(games.slug, [input.requestingGameSlug, input.game]));
47607
+ const { requestingGame, answeringGame } = pickSkillStatusGames(rows, input.requestingGameSlug, input.game);
47608
+ const deployment = await this.deps.db.query.gameDeployments.findFirst({
47609
+ where: activeDeploymentWhere(answeringGame.id),
47610
+ columns: { url: true }
47611
+ });
47612
+ const baseUrl = resolveGameWorkerBaseUrl(this.deps.localGameUrls, answeringGame.slug, deployment?.url);
47613
+ if (!baseUrl) {
47614
+ return recordResult({ supported: false, reason: "no_active_deployment" });
47615
+ }
47616
+ const token = await this.deps.mintSkillStatusToken({
47617
+ gameId: answeringGame.id,
47618
+ studentId: input.studentId,
47619
+ requestingGame
47620
+ });
47621
+ const call = await callGameWorker(buildSkillStatusUrl(baseUrl, skills2), token, {
47622
+ timeoutMs: SKILL_STATUS_TIMEOUT_MS,
47623
+ timeoutMessage: "Skill status request timed out"
47624
+ });
47625
+ if (!call.ok) {
47626
+ setAttributes({ "app.skill_status.failure_details": call.details });
47627
+ return recordResult({ supported: false, reason: call.reason });
47628
+ }
47629
+ setAttributes({ "app.skill_status.http_status": call.response.status });
47630
+ return recordResult(await classifySkillStatusResponse(call.response, input.studentId, skills2));
47631
+ }
47632
+ }
47633
+ function recordResult(result) {
47634
+ setAttributes(result.supported ? {
47635
+ "app.skill_status.supported": true,
47636
+ "app.skill_status.unknown_skill_count": result.results.filter((entry) => entry.status === "unknown_skill").length
47637
+ } : { "app.skill_status.supported": false, "app.skill_status.reason": result.reason });
47638
+ return result;
47639
+ }
47640
+ var SKILL_STATUS_TIMEOUT_MS = 3000;
47641
+ var init_skill_status_service = __esm(() => {
47642
+ init_drizzle_orm();
47643
+ init_helpers_index();
47644
+ init_tables_index();
47645
+ init_spans();
47646
+ init_game_worker_call_util();
47647
+ init_skill_status_util();
47648
+ });
47649
+
47407
47650
  // ../../node_modules/.bun/drizzle-zod@0.7.1+3ad0422b77d1a05b/node_modules/drizzle-zod/index.mjs
47408
47651
  function isColumnType(column2, columnTypes) {
47409
47652
  return columnTypes.includes(column2.columnType);
@@ -93713,15 +93956,10 @@ class RosterStudents {
93713
93956
  if (isApiError(error88) && error88.statusCode === 401) {
93714
93957
  throw new TimebackAuthenticationError;
93715
93958
  }
93716
- if (error88 instanceof TimebackAuthenticationError || error88 instanceof TimebackError) {
93717
- throw error88;
93959
+ if (!(error88 instanceof TimebackError)) {
93960
+ logTimebackError("student email lookup", error88, { student_email: email5 });
93718
93961
  }
93719
- addEvent("timeback.student_lookup_failed", {
93720
- "app.timeback.student_email": email5,
93721
- "exception.type": errorType(error88),
93722
- "app.error.message": errorMessage(error88)
93723
- });
93724
- throw new StudentNotFoundError(email5, "email");
93962
+ throw error88;
93725
93963
  }
93726
93964
  }
93727
93965
  async resolveById(studentId, providedEmail) {
@@ -98258,12 +98496,6 @@ class TimebackAdminService {
98258
98496
  grade: integration.grade
98259
98497
  };
98260
98498
  }
98261
- resolveGameMetricsBaseUrl(slug2, deployedUrl) {
98262
- if (!slug2) {
98263
- return deployedUrl;
98264
- }
98265
- return this.deps.config.localGameUrls[slug2] ?? deployedUrl;
98266
- }
98267
98499
  static resolveGameMetricsUrl(baseUrl, runIds) {
98268
98500
  try {
98269
98501
  const url4 = new URL("/__playcademy/metrics", baseUrl);
@@ -98297,9 +98529,6 @@ class TimebackAdminService {
98297
98529
  }
98298
98530
  return chunks;
98299
98531
  }
98300
- static isAbortError(error88) {
98301
- return error88 instanceof Error && error88.name === "AbortError";
98302
- }
98303
98532
  static roundXpToTenths(value) {
98304
98533
  const rounded = Math.round(value * TimebackAdminService.XP_PRECISION_FACTOR) / TimebackAdminService.XP_PRECISION_FACTOR;
98305
98534
  return Object.is(rounded, -0) ? 0 : rounded;
@@ -98937,7 +99166,7 @@ class TimebackAdminService {
98937
99166
  if (enrollmentsByCourseId.size === 0) {
98938
99167
  throw new NotFoundError("Student enrollment", `${timebackId}:${gameId}`);
98939
99168
  }
98940
- const metricsBaseUrl = this.resolveGameMetricsBaseUrl(game2?.slug, deployment?.url);
99169
+ const metricsBaseUrl = resolveGameWorkerBaseUrl(this.deps.config.localGameUrls, game2?.slug, deployment?.url);
98941
99170
  if (!metricsBaseUrl) {
98942
99171
  setAttributes({
98943
99172
  "app.timeback.metrics.supported": false,
@@ -98960,40 +99189,18 @@ class TimebackAdminService {
98960
99189
  };
98961
99190
  }
98962
99191
  const token = await this.deps.mintPlatformServiceToken(gameId, targetUser.id);
98963
- const controller = new AbortController;
98964
- const timeout = setTimeout(() => controller.abort(), options?.timeoutMs ?? TimebackAdminService.GAME_METRICS_FETCH_TIMEOUT_MS);
98965
- let response;
98966
- try {
98967
- response = await fetch(metricsUrl, {
98968
- method: "GET",
98969
- headers: {
98970
- Accept: "application/json",
98971
- Authorization: `Bearer ${token}`
98972
- },
98973
- signal: controller.signal
98974
- });
98975
- } catch (error88) {
98976
- const timedOut = TimebackAdminService.isAbortError(error88);
98977
- let details;
98978
- if (timedOut) {
98979
- details = "Game metrics request timed out";
98980
- } else if (error88 instanceof Error) {
98981
- details = error88.message;
98982
- } else {
98983
- details = String(error88);
98984
- }
99192
+ const call = await callGameWorker(metricsUrl, token, {
99193
+ timeoutMs: options?.timeoutMs ?? TimebackAdminService.GAME_METRICS_FETCH_TIMEOUT_MS,
99194
+ timeoutMessage: "Game metrics request timed out"
99195
+ });
99196
+ if (!call.ok) {
98985
99197
  setAttributes({
98986
99198
  "app.timeback.metrics.supported": false,
98987
- "app.timeback.metrics.reason": timedOut ? "timeout" : "fetch_failed"
99199
+ "app.timeback.metrics.reason": call.reason
98988
99200
  });
98989
- return {
98990
- supported: false,
98991
- reason: timedOut ? "timeout" : "fetch_failed",
98992
- details
98993
- };
98994
- } finally {
98995
- clearTimeout(timeout);
99201
+ return { supported: false, reason: call.reason, details: call.details };
98996
99202
  }
99203
+ const { response } = call;
98997
99204
  const result = await classifyGameMetricsResponse(response, { gameId, timebackId });
98998
99205
  setAttributes({
98999
99206
  "app.timeback.metrics.supported": result.supported,
@@ -99991,6 +100198,7 @@ var init_timeback_admin_service = __esm(async () => {
99991
100198
  init_src9();
99992
100199
  init_timeback3();
99993
100200
  init_errors2();
100201
+ init_game_worker_call_util();
99994
100202
  init_timeback_admin_metrics_util();
99995
100203
  init_timeback_admin_util();
99996
100204
  init_timeback_discrepancy_queue_util();
@@ -109902,6 +110110,7 @@ function createPlatformServices(deps) {
109902
110110
  timebackClient,
109903
110111
  alerts,
109904
110112
  mintPlatformServiceToken,
110113
+ mintSkillStatusToken,
109905
110114
  mintAssessmentPreparationReceipt,
109906
110115
  verifyAssessmentPreparationReceipt,
109907
110116
  mintAssessmentToken,
@@ -109985,6 +110194,11 @@ function createPlatformServices(deps) {
109985
110194
  mintAssessmentToken,
109986
110195
  verifyAssessmentToken
109987
110196
  });
110197
+ const skillStatus = new SkillStatusService({
110198
+ db: db2,
110199
+ localGameUrls: config5.localGameUrls,
110200
+ mintSkillStatusToken
110201
+ });
109988
110202
  return {
109989
110203
  assessmentAssets,
109990
110204
  assessmentArtifacts,
@@ -109997,6 +110211,7 @@ function createPlatformServices(deps) {
109997
110211
  deploymentState,
109998
110212
  database,
109999
110213
  seed,
110214
+ skillStatus,
110000
110215
  timeback: timeback2,
110001
110216
  timebackAdmin,
110002
110217
  timebackAssessmentRuntime,
@@ -110015,6 +110230,7 @@ var init_platform2 = __esm(async () => {
110015
110230
  init_releases_service();
110016
110231
  init_secrets_service();
110017
110232
  init_seed_service();
110233
+ init_skill_status_service();
110018
110234
  init_upload_service();
110019
110235
  await __promiseAll([
110020
110236
  init_timeback_admin_service(),
@@ -110733,6 +110949,7 @@ function createServices(ctx) {
110733
110949
  timebackClient: timeback2,
110734
110950
  alerts: infra2.alerts,
110735
110951
  mintPlatformServiceToken: auth2.mintPlatformServiceToken.bind(auth2),
110952
+ mintSkillStatusToken: auth2.mintSkillStatusToken.bind(auth2),
110736
110953
  mintAssessmentPreparationReceipt: auth2.mintAssessmentPreparationReceipt.bind(auth2),
110737
110954
  verifyAssessmentPreparationReceipt: auth2.verifyAssessmentPreparationReceipt.bind(auth2),
110738
110955
  mintAssessmentToken: auth2.mintAssessmentToken.bind(auth2),
@@ -110781,6 +110998,17 @@ function workerKeyGrantsGameRead(key, slug2) {
110781
110998
  function isGameWorkerKey(key) {
110782
110999
  return Boolean(key?.name?.startsWith(GAME_WORKER_KEY_PREFIX));
110783
111000
  }
111001
+ function gameWorkerKeySlug(key) {
111002
+ if (!isGameWorkerKey(key)) {
111003
+ return null;
111004
+ }
111005
+ const writes = (key?.permissions?.games ?? []).filter((scope) => scope.startsWith("write:"));
111006
+ if (writes.length !== 1) {
111007
+ return null;
111008
+ }
111009
+ const slug2 = writes[0].slice("write:".length);
111010
+ return slug2.length > 0 ? slug2 : null;
111011
+ }
110784
111012
  function deniedWorkerKeyRequest(key, method, pathname) {
110785
111013
  if (isDashboardWorkerKey(key) && !isAllowedDashboardWorkerRequest(method, pathname, key.permissions)) {
110786
111014
  return DASHBOARD_WORKER_KEY_RESTRICTED;
@@ -111157,6 +111385,19 @@ var init_clients = __esm(async () => {
111157
111385
  });
111158
111386
 
111159
111387
  // src/infrastructure/api/providers/auth.provider.ts
111388
+ function mintSandboxServiceToken(audience, claims) {
111389
+ const now2 = Math.floor(Date.now() / 1000);
111390
+ const header = btoa(JSON.stringify({ alg: "none", kid: "sandbox", typ: "sandbox" }));
111391
+ const payload = btoa(JSON.stringify({
111392
+ iss: "playcademy-platform",
111393
+ aud: audience,
111394
+ ...claims,
111395
+ iat: now2,
111396
+ exp: now2 + 60,
111397
+ jti: crypto.randomUUID()
111398
+ }));
111399
+ return `${header}.${payload}.sandbox`;
111400
+ }
111160
111401
  function createSandboxAuthProvider() {
111161
111402
  return {
111162
111403
  async createApiKey(params) {
@@ -111228,18 +111469,10 @@ function createSandboxAuthProvider() {
111228
111469
  }
111229
111470
  },
111230
111471
  async mintPlatformServiceToken(gameId, studentId) {
111231
- const now2 = Math.floor(Date.now() / 1000);
111232
- const header = btoa(JSON.stringify({ alg: "none", kid: "sandbox", typ: "sandbox" }));
111233
- const payload = btoa(JSON.stringify({
111234
- iss: "playcademy-platform",
111235
- aud: "playcademy-game-metrics",
111236
- gameId,
111237
- studentId,
111238
- iat: now2,
111239
- exp: now2 + 60,
111240
- jti: crypto.randomUUID()
111241
- }));
111242
- return `${header}.${payload}.sandbox`;
111472
+ return mintSandboxServiceToken("playcademy-game-metrics", { gameId, studentId });
111473
+ },
111474
+ async mintSkillStatusToken(claims) {
111475
+ return mintSandboxServiceToken(SKILL_STATUS_TOKEN_AUDIENCE, { ...claims });
111243
111476
  },
111244
111477
  async mintAssessmentPreparationReceipt(plan) {
111245
111478
  const now2 = Date.now();
@@ -111319,6 +111552,7 @@ function createSandboxAuthProvider() {
111319
111552
  }
111320
111553
  var sandboxApiKeys, sandboxAssessmentPreparationReceipts, ASSESSMENT_PREPARATION_RECEIPT_LIFETIME_MS, MAX_TOKEN_LIFETIME_SECONDS, sandboxAssessmentTokens;
111321
111554
  var init_auth_provider = __esm(async () => {
111555
+ init_src();
111322
111556
  init_src6();
111323
111557
  init_constants();
111324
111558
  await init_dist5();
@@ -167914,6 +168148,36 @@ var init_session_controller = __esm(() => {
167914
168148
  });
167915
168149
  });
167916
168150
 
168151
+ // ../api-core/src/controllers/skills.controller.ts
168152
+ async function getStatus4(ctx) {
168153
+ const requestingGameSlug = gameWorkerKeySlug(ctx.apiKey);
168154
+ if (!requestingGameSlug) {
168155
+ throw ApiError.forbidden("Skill status can only be requested by a deployed game worker");
168156
+ }
168157
+ const body2 = await parseRequestBody(ctx.request, SkillStatusRequestSchema);
168158
+ return ctx.services.skillStatus.getStatus({ ...body2, requestingGameSlug });
168159
+ }
168160
+ async function getStatusLocally(ctx) {
168161
+ await parseRequestBody(ctx.request, SkillStatusRequestSchema);
168162
+ return { supported: false, reason: "no_active_deployment" };
168163
+ }
168164
+ var SkillStatusRequestSchema, skills2;
168165
+ var init_skills_controller = __esm(() => {
168166
+ init_esm();
168167
+ init_src();
168168
+ init_errors2();
168169
+ init_utils7();
168170
+ SkillStatusRequestSchema = exports_external.object({
168171
+ game: exports_external.string().min(1),
168172
+ studentId: exports_external.string().min(1),
168173
+ skills: exports_external.array(exports_external.string()).min(1).max(SKILL_STATUS_MAX_SKILLS * 2)
168174
+ });
168175
+ skills2 = defineControllerNames("skills", {
168176
+ getStatus: requireAuth(getStatus4),
168177
+ getStatusLocally: requireAuth(getStatusLocally)
168178
+ });
168179
+ });
168180
+
167917
168181
  // ../api-core/src/controllers/timeback.controller.ts
167918
168182
  function parseQtiLibraryParams(searchParams) {
167919
168183
  const requestedPage = Number(searchParams.get("page"));
@@ -168951,6 +169215,7 @@ var init_controllers = __esm(() => {
168951
169215
  init_secrets_controller();
168952
169216
  init_seed_controller();
168953
169217
  init_session_controller();
169218
+ init_skills_controller();
168954
169219
  init_timeback_controller();
168955
169220
  init_upload_controller();
168956
169221
  init_user_controller();
@@ -169764,6 +170029,16 @@ var init_leaderboard = __esm(async () => {
169764
170029
  leaderboardRouter.get("/", handle2(leaderboard.getGlobalLeaderboard));
169765
170030
  });
169766
170031
 
170032
+ // src/routes/platform/skills.ts
170033
+ var skillsRouter;
170034
+ var init_skills3 = __esm(async () => {
170035
+ init_dist7();
170036
+ init_controllers();
170037
+ await init_api3();
170038
+ skillsRouter = new Hono2;
170039
+ skillsRouter.post("/status", handle2(skills2.getStatusLocally));
170040
+ });
170041
+
169767
170042
  // src/routes/integrations/timeback.ts
169768
170043
  function hashCode(str) {
169769
170044
  let hash2 = 0;
@@ -170112,6 +170387,7 @@ var exports_routes = {};
170112
170387
  __export(exports_routes, {
170113
170388
  usersRouter: () => usersRouter,
170114
170389
  timebackRouter: () => timebackRouter,
170390
+ skillsRouter: () => skillsRouter,
170115
170391
  manifestRouter: () => manifestRouter,
170116
170392
  ltiRouter: () => ltiRouter,
170117
170393
  leaderboardRouter: () => leaderboardRouter,
@@ -170128,6 +170404,7 @@ var init_routes = __esm(async () => {
170128
170404
  init_users(),
170129
170405
  init_games2(),
170130
170406
  init_leaderboard(),
170407
+ init_skills3(),
170131
170408
  init_timeback8(),
170132
170409
  init_lti()
170133
170410
  ]);
@@ -170143,6 +170420,7 @@ async function registerRoutes(app) {
170143
170420
  leaderboardRouter: leaderboardRouter2,
170144
170421
  ltiRouter: ltiRouter2,
170145
170422
  manifestRouter: manifestRouter2,
170423
+ skillsRouter: skillsRouter2,
170146
170424
  timebackRouter: timebackRouter2,
170147
170425
  usersRouter: usersRouter2
170148
170426
  } = await init_routes().then(() => exports_routes);
@@ -170151,6 +170429,7 @@ async function registerRoutes(app) {
170151
170429
  app.route("/api/users", usersRouter2);
170152
170430
  app.route("/api/games", gamesRouter2);
170153
170431
  app.route("/api/leaderboard", leaderboardRouter2);
170432
+ app.route("/api/skills", skillsRouter2);
170154
170433
  app.route("/api/dev", devRouter2);
170155
170434
  app.route("/api/timeback", timebackRouter2);
170156
170435
  app.route("/api/lti", ltiRouter2);