@playcademy/better-auth 0.0.2 → 0.0.3

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/server.js +25 -29
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -20157,35 +20157,20 @@ import { existsSync, readdirSync, statSync } from "fs";
20157
20157
  import { readFile } from "fs/promises";
20158
20158
  import { dirname, parse as parse9, resolve } from "path";
20159
20159
  function createTimebackNamespace(client) {
20160
- let courseId;
20161
- async function ensureCourseId() {
20162
- if (courseId)
20163
- return courseId;
20164
- try {
20165
- const integration = await client["request"](`/api/timeback/integrations/${client.gameId}`, "GET");
20166
- if (!integration || !integration.courseId) {
20167
- throw new Error("No TimeBack integration found for this game. Please run TimeBack setup first.");
20168
- }
20169
- courseId = integration.courseId;
20170
- return courseId;
20171
- } catch (error4) {
20172
- throw new Error(`Failed to fetch courseId: ${error4 instanceof Error ? error4.message : String(error4)}`);
20173
- }
20174
- }
20175
20160
  function enrichActivityData(data) {
20176
20161
  return {
20177
20162
  ...data,
20178
- subject: data.subject || client.config.integrations?.timeback?.course.subjects?.[0],
20179
- appName: data.appName || client.config.name,
20180
- courseName: data.courseName || client.config.integrations?.timeback?.course.title
20163
+ appName: data.appName || client.config.name
20181
20164
  };
20182
20165
  }
20183
20166
  return {
20184
- get courseId() {
20185
- return courseId;
20186
- },
20187
20167
  endActivity: async (studentId, payload) => {
20188
- await ensureCourseId();
20168
+ if (!payload.activityData.grade) {
20169
+ throw new Error("activityData.grade is required for TimeBack integration");
20170
+ }
20171
+ if (!payload.activityData.subject) {
20172
+ throw new Error("activityData.subject is required for TimeBack integration");
20173
+ }
20189
20174
  const enrichedActivityData = enrichActivityData(payload.activityData);
20190
20175
  return client["request"]("/api/timeback/end-activity", "POST", {
20191
20176
  gameId: client.gameId,
@@ -20193,7 +20178,8 @@ function createTimebackNamespace(client) {
20193
20178
  activityData: enrichedActivityData,
20194
20179
  scoreData: payload.scoreData,
20195
20180
  timingData: payload.timingData,
20196
- xpEarned: payload.xpEarned
20181
+ xpEarned: payload.xpEarned,
20182
+ masteredUnits: payload.masteredUnits
20197
20183
  });
20198
20184
  }
20199
20185
  };
@@ -20454,7 +20440,20 @@ Please set the PLAYCADEMY_BASE_URL environment variable`);
20454
20440
  let errorMessage = "Unknown error";
20455
20441
  try {
20456
20442
  const data = await response.json();
20457
- errorMessage = data.error || data.message || "Unknown error";
20443
+ const errorField = data.error || data.message;
20444
+ if (typeof errorField === "string") {
20445
+ errorMessage = errorField;
20446
+ } else if (errorField && typeof errorField === "object") {
20447
+ const errorObj = errorField;
20448
+ if ("message" in errorObj && typeof errorObj.message === "string") {
20449
+ errorMessage = errorObj.message;
20450
+ if ("code" in errorObj && typeof errorObj.code === "string") {
20451
+ errorMessage = `[${errorObj.code}] ${errorMessage}`;
20452
+ }
20453
+ } else {
20454
+ errorMessage = JSON.stringify(errorField);
20455
+ }
20456
+ }
20458
20457
  } catch {
20459
20458
  errorMessage = response.statusText || "Unknown error";
20460
20459
  }
@@ -20606,13 +20605,10 @@ var playcademy = () => {
20606
20605
  try {
20607
20606
  verified = await verifyGameToken(gameToken, { baseUrl: authApiUrl });
20608
20607
  } catch (error4) {
20609
- const errorMessage = error4 instanceof Error ? error4.message : String(error4);
20610
20608
  const platformMode = ctx.request?.headers.get("x-playcademy-mode");
20611
20609
  if (platformMode === "platform") {
20612
- console.error("[Playcademy Auth] Token verification failed:", {
20613
- error: errorMessage,
20614
- hasAuthApiOverride: !!authApiUrl
20615
- });
20610
+ const errorMessage = error4 instanceof Error ? error4.message : String(error4);
20611
+ console.error("[Playcademy Auth] Token verification failed:", errorMessage);
20616
20612
  }
20617
20613
  return new Response(JSON.stringify({ ok: false, code: "invalid_token" }), {
20618
20614
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/better-auth",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@inquirer/prompts": "^7.9.0",
31
- "@playcademy/sdk": "0.1.18",
31
+ "@playcademy/sdk": "0.2.2",
32
32
  "@playcademy/utils": "0.0.1",
33
33
  "@types/bun": "latest",
34
34
  "typescript": "^5.7.2"