@playcademy/vite-plugin 0.2.9 → 0.2.11

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.
Files changed (2) hide show
  1. package/dist/index.js +106 -48
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -41490,9 +41490,15 @@ var init_overworld = __esm(() => {
41490
41490
  };
41491
41491
  });
41492
41492
  var PLATFORM_TIMEZONE = "America/New_York";
41493
+ var TIMEBACK_ROUTES;
41493
41494
  var TIMEBACK_ORG_SOURCED_ID = "PLAYCADEMY";
41494
- var init_timeback2 = () => {};
41495
+ var init_timeback2 = __esm(() => {
41496
+ TIMEBACK_ROUTES = {
41497
+ END_ACTIVITY: "/integrations/timeback/end-activity"
41498
+ };
41499
+ });
41495
41500
  var WORKER_NAMING;
41501
+ var SECRETS_PREFIX = "secrets_";
41496
41502
  var init_workers = __esm(() => {
41497
41503
  WORKER_NAMING = {
41498
41504
  STAGING_PREFIX: "staging-",
@@ -42380,7 +42386,7 @@ var package_default;
42380
42386
  var init_package = __esm(() => {
42381
42387
  package_default = {
42382
42388
  name: "@playcademy/sandbox",
42383
- version: "0.3.11",
42389
+ version: "0.3.13",
42384
42390
  description: "Local development server for Playcademy game development",
42385
42391
  type: "module",
42386
42392
  exports: {
@@ -42850,7 +42856,7 @@ function createHandle(buildContext) {
42850
42856
  try {
42851
42857
  const ctx = await buildContext(c);
42852
42858
  const result = await controller(ctx);
42853
- if (options?.status === 204 || result === undefined || result === null) {
42859
+ if (options?.status === 204 || result === undefined) {
42854
42860
  return new Response(null, { status: options?.status ?? 204 });
42855
42861
  }
42856
42862
  return new Response(JSON.stringify(result), {
@@ -55076,6 +55082,20 @@ class GameService {
55076
55082
  orderBy: [desc(games.createdAt)]
55077
55083
  });
55078
55084
  }
55085
+ async getSubjects() {
55086
+ const db2 = this.ctx.db;
55087
+ const integrations = await db2.query.gameTimebackIntegrations.findMany({
55088
+ columns: { gameId: true, subject: true },
55089
+ orderBy: [asc(gameTimebackIntegrations.createdAt)]
55090
+ });
55091
+ const subjectMap = {};
55092
+ for (const integration of integrations) {
55093
+ if (!(integration.gameId in subjectMap)) {
55094
+ subjectMap[integration.gameId] = integration.subject;
55095
+ }
55096
+ }
55097
+ return subjectMap;
55098
+ }
55079
55099
  async getById(gameId) {
55080
55100
  const db2 = this.ctx.db;
55081
55101
  const game = await db2.query.games.findFirst({
@@ -56063,13 +56083,13 @@ class LevelService {
56063
56083
  throw new BadRequestError("Level must be at least 1");
56064
56084
  }
56065
56085
  if (levelConfigCache?.has(level)) {
56066
- return levelConfigCache.get(level) || null;
56086
+ return levelConfigCache.get(level) ?? null;
56067
56087
  }
56068
56088
  const [config2] = await this.ctx.db.select().from(levelConfigs).where(eq(levelConfigs.level, level)).limit(1);
56069
56089
  if (levelConfigCache && config2) {
56070
56090
  levelConfigCache.set(level, config2);
56071
56091
  }
56072
- return config2 || null;
56092
+ return config2 ?? null;
56073
56093
  }
56074
56094
  async listConfigs() {
56075
56095
  return this.ctx.db.select().from(levelConfigs).orderBy(levelConfigs.level);
@@ -56949,9 +56969,9 @@ class SecretsService {
56949
56969
  }
56950
56970
  }
56951
56971
  var logger21;
56952
- var SECRETS_PREFIX = "secrets_";
56953
56972
  var INTERNAL_SECRET_KEYS;
56954
56973
  var init_secrets_service = __esm(() => {
56974
+ init_src();
56955
56975
  init_src2();
56956
56976
  init_config2();
56957
56977
  init_errors();
@@ -56959,6 +56979,28 @@ var init_secrets_service = __esm(() => {
56959
56979
  logger21 = log.scope("SecretsService");
56960
56980
  INTERNAL_SECRET_KEYS = ["PLAYCADEMY_API_KEY", "GAME_ID", "PLAYCADEMY_BASE_URL"];
56961
56981
  });
56982
+ var ROUTES;
56983
+ var init_constants2 = __esm(() => {
56984
+ init_src();
56985
+ ROUTES = {
56986
+ INDEX: "/api",
56987
+ HEALTH: "/api/health",
56988
+ TIMEBACK: {
56989
+ END_ACTIVITY: `/api${TIMEBACK_ROUTES.END_ACTIVITY}`
56990
+ }
56991
+ };
56992
+ });
56993
+ function prefixSecrets(secrets) {
56994
+ const prefixed = {};
56995
+ for (const [key, value] of Object.entries(secrets)) {
56996
+ prefixed[SECRETS_PREFIX + key] = value;
56997
+ }
56998
+ return prefixed;
56999
+ }
57000
+ var init_setup = __esm(() => {
57001
+ init_src();
57002
+ init_constants2();
57003
+ });
56962
57004
 
56963
57005
  class SeedService {
56964
57006
  ctx;
@@ -56973,7 +57015,7 @@ class SeedService {
56973
57015
  }
56974
57016
  return cf;
56975
57017
  }
56976
- async seed(slug2, code, user) {
57018
+ async seed(slug2, code, user, secrets) {
56977
57019
  const cf = this.getCloudflare();
56978
57020
  const game = await this.ctx.services.game.validateDeveloperAccessBySlug(user, slug2);
56979
57021
  const isProd = isProduction2(this.ctx.config);
@@ -56985,10 +57027,11 @@ class SeedService {
56985
57027
  gameId: game.id,
56986
57028
  slug: slug2,
56987
57029
  deploymentId,
56988
- codeLength: code.length
57030
+ codeLength: code.length,
57031
+ secretCount: secrets ? Object.keys(secrets).length : 0
56989
57032
  });
56990
57033
  try {
56991
- const workerResponse = await this.deployAndExecuteSeedWorker(cf, seedDeploymentId, game.id, deploymentId, code);
57034
+ const workerResponse = await this.deployAndExecuteSeedWorker(cf, seedDeploymentId, game.id, deploymentId, code, secrets);
56992
57035
  logger22.info("Seed completed", {
56993
57036
  gameId: game.id,
56994
57037
  slug: slug2,
@@ -57060,7 +57103,7 @@ class SeedService {
57060
57103
  });
57061
57104
  }
57062
57105
  }
57063
- async deployAndExecuteSeedWorker(cf, seedDeploymentId, gameId, deploymentId, workerCode) {
57106
+ async deployAndExecuteSeedWorker(cf, seedDeploymentId, gameId, deploymentId, workerCode, secrets) {
57064
57107
  try {
57065
57108
  const result = await cf.deploy(seedDeploymentId, workerCode, {
57066
57109
  GAME_ID: gameId,
@@ -57070,6 +57113,13 @@ class SeedService {
57070
57113
  keepAssets: false
57071
57114
  });
57072
57115
  logger22.info("Worker deployed", { seedDeploymentId, url: result.url });
57116
+ if (secrets && Object.keys(secrets).length > 0) {
57117
+ await cf.setSecrets(seedDeploymentId, prefixSecrets(secrets));
57118
+ logger22.info("Secrets bound to worker", {
57119
+ seedDeploymentId,
57120
+ count: Object.keys(secrets).length
57121
+ });
57122
+ }
57073
57123
  return await this.executeSeedWorker(result.url, seedDeploymentId);
57074
57124
  } finally {
57075
57125
  await this.cleanupSeedWorker(cf, seedDeploymentId);
@@ -57185,6 +57235,7 @@ class SeedService {
57185
57235
  }
57186
57236
  var logger22;
57187
57237
  var init_seed_service = __esm(() => {
57238
+ init_setup();
57188
57239
  init_src2();
57189
57240
  init_config2();
57190
57241
  init_errors();
@@ -57699,7 +57750,7 @@ var PLAYCADEMY_DEFAULTS;
57699
57750
  var RESOURCE_DEFAULTS;
57700
57751
  var HTTP_STATUS;
57701
57752
  var ERROR_NAMES;
57702
- var init_constants2;
57753
+ var init_constants3;
57703
57754
  var isObject = (value) => typeof value === "object" && value !== null;
57704
57755
  var SUBJECT_VALUES;
57705
57756
  var GRADE_VALUES;
@@ -57879,7 +57930,7 @@ var init_types7 = __esm(() => {
57879
57930
  init_timeback3();
57880
57931
  init_workers2();
57881
57932
  });
57882
- init_constants2 = __esm2(() => {
57933
+ init_constants3 = __esm2(() => {
57883
57934
  init_src5();
57884
57935
  TIMEBACK_API_URLS = {
57885
57936
  production: "https://api.alpha-1edtech.ai",
@@ -58054,7 +58105,7 @@ var init_types7 = __esm(() => {
58054
58105
  timebackSdk: "TimebackSDKError"
58055
58106
  };
58056
58107
  });
58057
- init_constants2();
58108
+ init_constants3();
58058
58109
  SUBJECT_VALUES = TIMEBACK_SUBJECTS;
58059
58110
  GRADE_VALUES = TIMEBACK_GRADE_LEVELS;
58060
58111
  });
@@ -61398,7 +61449,7 @@ var PLAYCADEMY_DEFAULTS2;
61398
61449
  var RESOURCE_DEFAULTS2;
61399
61450
  var HTTP_STATUS2;
61400
61451
  var ERROR_NAMES2;
61401
- var init_constants3;
61452
+ var init_constants4;
61402
61453
  var exports_verify;
61403
61454
  var init_verify;
61404
61455
  var TimebackError;
@@ -62092,7 +62143,7 @@ var init_dist3 = __esm(() => {
62092
62143
  init_timeback4();
62093
62144
  init_workers3();
62094
62145
  });
62095
- init_constants3 = __esm3(() => {
62146
+ init_constants4 = __esm3(() => {
62096
62147
  init_src6();
62097
62148
  TIMEBACK_API_URLS2 = {
62098
62149
  production: "https://api.alpha-1edtech.ai",
@@ -62273,9 +62324,9 @@ var init_dist3 = __esm(() => {
62273
62324
  fetchTimebackConfig: () => fetchTimebackConfig
62274
62325
  });
62275
62326
  init_verify = __esm3(() => {
62276
- init_constants3();
62327
+ init_constants4();
62277
62328
  });
62278
- init_constants3();
62329
+ init_constants4();
62279
62330
  TimebackError = class TimebackError2 extends Error {
62280
62331
  constructor(message) {
62281
62332
  super(message);
@@ -62332,7 +62383,7 @@ var init_dist3 = __esm(() => {
62332
62383
  Object.setPrototypeOf(this, ResourceNotFoundError2.prototype);
62333
62384
  }
62334
62385
  };
62335
- init_constants3();
62386
+ init_constants4();
62336
62387
  SUBJECT_VALUES2 = TIMEBACK_SUBJECTS2;
62337
62388
  GRADE_VALUES2 = TIMEBACK_GRADE_LEVELS2;
62338
62389
  colors3 = {
@@ -62353,8 +62404,8 @@ var init_dist3 = __esm(() => {
62353
62404
  };
62354
62405
  log3 = createLogger2();
62355
62406
  init_verify();
62356
- init_constants3();
62357
- init_constants3();
62407
+ init_constants4();
62408
+ init_constants4();
62358
62409
  if (process.env.DEBUG === "true") {
62359
62410
  process.env.TERM = "dumb";
62360
62411
  }
@@ -62366,13 +62417,13 @@ var init_dist3 = __esm(() => {
62366
62417
  this.name = ERROR_NAMES2.timebackAuth;
62367
62418
  }
62368
62419
  };
62369
- init_constants3();
62370
- init_constants3();
62371
- init_constants3();
62372
- init_constants3();
62373
- init_constants3();
62374
- init_constants3();
62375
- init_constants3();
62420
+ init_constants4();
62421
+ init_constants4();
62422
+ init_constants4();
62423
+ init_constants4();
62424
+ init_constants4();
62425
+ init_constants4();
62426
+ init_constants4();
62376
62427
  exports_external2 = {};
62377
62428
  __export2(exports_external2, {
62378
62429
  void: () => voidType2,
@@ -65912,7 +65963,7 @@ var compose = (middleware, onError, onNotFound) => {
65912
65963
  var init_compose = () => {};
65913
65964
  var init_http_exception = () => {};
65914
65965
  var GET_MATCH_RESULT;
65915
- var init_constants4 = __esm(() => {
65966
+ var init_constants5 = __esm(() => {
65916
65967
  GET_MATCH_RESULT = Symbol();
65917
65968
  });
65918
65969
  async function parseFormData(request2, options) {
@@ -66189,7 +66240,7 @@ var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
66189
66240
  var HonoRequest;
66190
66241
  var init_request = __esm(() => {
66191
66242
  init_http_exception();
66192
- init_constants4();
66243
+ init_constants5();
66193
66244
  init_body();
66194
66245
  init_url();
66195
66246
  HonoRequest = class {
@@ -66519,7 +66570,7 @@ var init_router = __esm(() => {
66519
66570
  };
66520
66571
  });
66521
66572
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
66522
- var init_constants5 = () => {};
66573
+ var init_constants6 = () => {};
66523
66574
  var notFoundHandler = (c) => {
66524
66575
  return c.text("404 Not Found", 404);
66525
66576
  };
@@ -66741,7 +66792,7 @@ var init_hono_base = __esm(() => {
66741
66792
  init_compose();
66742
66793
  init_context2();
66743
66794
  init_router();
66744
- init_constants5();
66795
+ init_constants6();
66745
66796
  init_url();
66746
66797
  });
66747
66798
  function match(method, path2) {
@@ -126714,7 +126765,8 @@ var init_schemas3 = __esm(() => {
126714
126765
  });
126715
126766
  SetSecretsRequestSchema = exports_external.record(exports_external.string().min(1), exports_external.string());
126716
126767
  SeedRequestSchema = exports_external.object({
126717
- code: exports_external.string().min(1, "Seed code is required")
126768
+ code: exports_external.string().min(1, "Seed code is required"),
126769
+ secrets: exports_external.record(exports_external.string(), exports_external.string()).optional()
126718
126770
  });
126719
126771
  SchemaInfoSchema = exports_external.object({
126720
126772
  sql: exports_external.string(),
@@ -136759,6 +136811,7 @@ var init_domain_controller = __esm(() => {
136759
136811
  });
136760
136812
  var logger43;
136761
136813
  var list3;
136814
+ var getSubjects;
136762
136815
  var getById2;
136763
136816
  var getBySlug;
136764
136817
  var upsertBySlug;
@@ -136776,6 +136829,10 @@ var init_game_controller = __esm(() => {
136776
136829
  logger43.debug("Listing games", { userId: ctx.user.id });
136777
136830
  return ctx.services.game.list();
136778
136831
  });
136832
+ getSubjects = requireAuth(async (ctx) => {
136833
+ logger43.debug("Getting game subjects", { userId: ctx.user.id });
136834
+ return ctx.services.game.getSubjects();
136835
+ });
136779
136836
  getById2 = requireAuth(async (ctx) => {
136780
136837
  const gameId = ctx.params.gameId;
136781
136838
  if (!gameId) {
@@ -136828,6 +136885,7 @@ var init_game_controller = __esm(() => {
136828
136885
  });
136829
136886
  games2 = {
136830
136887
  list: list3,
136888
+ getSubjects,
136831
136889
  getById: getById2,
136832
136890
  getBySlug,
136833
136891
  upsertBySlug,
@@ -137233,7 +137291,6 @@ var init_leaderboard_controller = __esm(() => {
137233
137291
  init_esm();
137234
137292
  init_schemas_index();
137235
137293
  init_src2();
137236
- init_src4();
137237
137294
  init_errors();
137238
137295
  init_utils11();
137239
137296
  logger47 = log.scope("LeaderboardController");
@@ -137322,9 +137379,6 @@ var init_leaderboard_controller = __esm(() => {
137322
137379
  if (!gameId || !userId) {
137323
137380
  throw ApiError.badRequest("Game ID and User ID are required");
137324
137381
  }
137325
- if (!isValidUUID(userId)) {
137326
- throw ApiError.unprocessableEntity("userId must be a valid UUID format");
137327
- }
137328
137382
  logger47.debug("Getting user rank", {
137329
137383
  requesterId: ctx.user.id,
137330
137384
  gameId,
@@ -137337,9 +137391,6 @@ var init_leaderboard_controller = __esm(() => {
137337
137391
  if (!userId) {
137338
137392
  throw ApiError.badRequest("User ID is required");
137339
137393
  }
137340
- if (!isValidUUID(userId)) {
137341
- throw ApiError.unprocessableEntity("userId must be a valid UUID format");
137342
- }
137343
137394
  const url = ctx.url;
137344
137395
  const limit = Math.min(Number(url.searchParams.get("limit") || "50"), 100);
137345
137396
  const gameId = url.searchParams.get("gameId") || undefined;
@@ -137356,9 +137407,6 @@ var init_leaderboard_controller = __esm(() => {
137356
137407
  if (!gameId || !userId) {
137357
137408
  throw ApiError.badRequest("Game ID and User ID are required");
137358
137409
  }
137359
- if (!isValidUUID(userId)) {
137360
- throw ApiError.unprocessableEntity("userId must be a valid UUID format");
137361
- }
137362
137410
  const url = ctx.url;
137363
137411
  const limit = Math.min(Number(url.searchParams.get("limit") || "10"), 100);
137364
137412
  logger47.debug("Getting user scores", {
@@ -137794,8 +137842,13 @@ var init_seed_controller = __esm(() => {
137794
137842
  }
137795
137843
  throw ApiError.badRequest("Invalid JSON body");
137796
137844
  }
137797
- logger55.debug("Seeding database", { userId: ctx.user.id, slug: slug2, codeLength: body2.code.length });
137798
- return ctx.services.seed.seed(slug2, body2.code, ctx.user);
137845
+ logger55.debug("Seeding database", {
137846
+ userId: ctx.user.id,
137847
+ slug: slug2,
137848
+ codeLength: body2.code.length,
137849
+ secretCount: body2.secrets ? Object.keys(body2.secrets).length : 0
137850
+ });
137851
+ return ctx.services.seed.seed(slug2, body2.code, ctx.user, body2.secrets);
137799
137852
  });
137800
137853
  });
137801
137854
  var logger56;
@@ -140156,7 +140209,12 @@ var init_overworld4 = __esm5(() => {
140156
140209
  PLAYGROUND: "00000000-0000-0000-0000-000000000001"
140157
140210
  };
140158
140211
  });
140159
- var init_timeback9 = () => {};
140212
+ var TIMEBACK_ROUTES2;
140213
+ var init_timeback9 = __esm5(() => {
140214
+ TIMEBACK_ROUTES2 = {
140215
+ END_ACTIVITY: "/integrations/timeback/end-activity"
140216
+ };
140217
+ });
140160
140218
  var WORKER_NAMING2;
140161
140219
  var init_workers4 = __esm5(() => {
140162
140220
  WORKER_NAMING2 = {
@@ -140386,13 +140444,13 @@ var init_demo_items2 = __esm5(() => {
140386
140444
  }
140387
140445
  ];
140388
140446
  });
140389
- var init_constants6 = __esm5(() => {
140447
+ var init_constants7 = __esm5(() => {
140390
140448
  init_src7();
140391
140449
  init_demo_users2();
140392
140450
  init_demo_tokens2();
140393
140451
  init_demo_items2();
140394
140452
  });
140395
- init_constants6();
140453
+ init_constants7();
140396
140454
 
140397
140455
  // src/lib/sandbox/token.ts
140398
140456
  var ROLE_TO_USER_ID = {
@@ -140758,7 +140816,7 @@ var import_picocolors12 = __toESM(require_picocolors(), 1);
140758
140816
  // package.json
140759
140817
  var package_default2 = {
140760
140818
  name: "@playcademy/vite-plugin",
140761
- version: "0.2.9",
140819
+ version: "0.2.11",
140762
140820
  type: "module",
140763
140821
  exports: {
140764
140822
  ".": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/vite-plugin",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -22,11 +22,11 @@
22
22
  "dependencies": {
23
23
  "archiver": "^7.0.1",
24
24
  "picocolors": "^1.1.1",
25
- "playcademy": "0.16.2"
25
+ "playcademy": "0.16.4"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@inquirer/prompts": "^7.8.6",
29
- "@playcademy/sandbox": "0.3.11",
29
+ "@playcademy/sandbox": "0.3.13",
30
30
  "@playcademy/utils": "0.0.1",
31
31
  "@types/archiver": "^6.0.3",
32
32
  "@types/bun": "latest"