@playcademy/sdk 0.3.1 → 0.3.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.d.ts CHANGED
@@ -622,13 +622,6 @@ declare class PlaycademyClient {
622
622
  * ```
623
623
  */
624
624
  static init(config: PlaycademyServerClientConfig): Promise<PlaycademyClient>;
625
- /**
626
- * Fetch gameId from API using the API token.
627
- *
628
- * @private
629
- * @throws {Error} Always throws - gameId fetching not yet implemented
630
- * @todo Implement API endpoint to fetch gameId from API token
631
- */
632
625
  private fetchGameId;
633
626
  /**
634
627
  * Makes an authenticated HTTP request to the API.
@@ -659,10 +652,10 @@ declare class PlaycademyClient {
659
652
  timeback: {
660
653
  endActivity: (studentId: string, payload: EndActivityPayload) => Promise<EndActivityResponse>;
661
654
  getStudentXp: (studentId: string, options?: {
662
- grade?: number;
663
- subject?: string;
664
- include?: ("perCourse" | "today")[];
665
- }) => Promise<StudentXpResponse>;
655
+ grade?: number | undefined;
656
+ subject?: string | undefined;
657
+ include?: ("perCourse" | "today")[] | undefined;
658
+ } | undefined) => Promise<StudentXpResponse>;
666
659
  };
667
660
  }
668
661
 
package/dist/server.js CHANGED
@@ -82,14 +82,14 @@ class PlaycademyError extends Error {
82
82
  }
83
83
 
84
84
  class ApiError extends Error {
85
- status;
86
85
  code;
87
86
  details;
88
87
  rawBody;
88
+ status;
89
89
  constructor(status, code, message, details, rawBody) {
90
90
  super(message);
91
- this.status = status;
92
91
  this.name = "ApiError";
92
+ this.status = status;
93
93
  this.code = code;
94
94
  this.details = details;
95
95
  this.rawBody = rawBody;
@@ -120,38 +120,54 @@ class ApiError extends Error {
120
120
  }
121
121
  function statusCodeToErrorCode(status) {
122
122
  switch (status) {
123
- case 400:
123
+ case 400: {
124
124
  return "BAD_REQUEST";
125
- case 401:
125
+ }
126
+ case 401: {
126
127
  return "UNAUTHORIZED";
127
- case 403:
128
+ }
129
+ case 403: {
128
130
  return "FORBIDDEN";
129
- case 404:
131
+ }
132
+ case 404: {
130
133
  return "NOT_FOUND";
131
- case 405:
134
+ }
135
+ case 405: {
132
136
  return "METHOD_NOT_ALLOWED";
133
- case 409:
137
+ }
138
+ case 409: {
134
139
  return "CONFLICT";
135
- case 410:
140
+ }
141
+ case 410: {
136
142
  return "GONE";
137
- case 412:
143
+ }
144
+ case 412: {
138
145
  return "PRECONDITION_FAILED";
139
- case 413:
146
+ }
147
+ case 413: {
140
148
  return "PAYLOAD_TOO_LARGE";
141
- case 422:
149
+ }
150
+ case 422: {
142
151
  return "VALIDATION_FAILED";
143
- case 429:
152
+ }
153
+ case 429: {
144
154
  return "TOO_MANY_REQUESTS";
145
- case 500:
155
+ }
156
+ case 500: {
146
157
  return "INTERNAL_ERROR";
147
- case 501:
158
+ }
159
+ case 501: {
148
160
  return "NOT_IMPLEMENTED";
149
- case 503:
161
+ }
162
+ case 503: {
150
163
  return "SERVICE_UNAVAILABLE";
151
- case 504:
164
+ }
165
+ case 504: {
152
166
  return "TIMEOUT";
153
- default:
167
+ }
168
+ default: {
154
169
  return status >= 500 ? "INTERNAL_ERROR" : "BAD_REQUEST";
170
+ }
155
171
  }
156
172
  }
157
173
  function extractApiErrorInfo(error) {
@@ -268,7 +284,7 @@ async function loadFile(filename, options = {}) {
268
284
  return null;
269
285
  }
270
286
  try {
271
- let content = await readFile(fileResult.path, "utf-8");
287
+ let content = await readFile(fileResult.path, "utf8");
272
288
  if (parseJson) {
273
289
  if (stripComments) {
274
290
  content = stripJsonComments(content);
@@ -277,7 +293,7 @@ async function loadFile(filename, options = {}) {
277
293
  }
278
294
  return content;
279
295
  } catch (error) {
280
- throw new Error(`Failed to load ${fileResult.filename} from ${fileResult.path}: ${error instanceof Error ? error.message : String(error)}`);
296
+ throw new Error(`Failed to load ${fileResult.filename} from ${fileResult.path}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
281
297
  }
282
298
  }
283
299
  async function findFile(filename, options = {}) {
@@ -345,7 +361,7 @@ async function loadConfig(configPath) {
345
361
  validateConfig(config);
346
362
  return config;
347
363
  } catch (error) {
348
- throw new Error(`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`);
364
+ throw new Error(`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
349
365
  }
350
366
  }
351
367
  function validateConfig(config) {
@@ -463,7 +479,9 @@ Please set the PLAYCADEMY_BASE_URL environment variable`);
463
479
  if (error instanceof Error) {
464
480
  throw error;
465
481
  }
466
- throw new Error("[Playcademy SDK] Token verification failed: Network error");
482
+ throw new Error("[Playcademy SDK] Token verification failed: Network error", {
483
+ cause: error
484
+ });
467
485
  }
468
486
  }
469
487
  export {