@playcademy/sdk 0.3.1 → 0.3.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.
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
@@ -81,15 +81,25 @@ class PlaycademyError extends Error {
81
81
  }
82
82
  }
83
83
 
84
+ class ManifestError extends PlaycademyError {
85
+ kind;
86
+ constructor(message, kind) {
87
+ super(message);
88
+ this.name = "ManifestError";
89
+ this.kind = kind;
90
+ Object.setPrototypeOf(this, ManifestError.prototype);
91
+ }
92
+ }
93
+
84
94
  class ApiError extends Error {
85
- status;
86
95
  code;
87
96
  details;
88
97
  rawBody;
98
+ status;
89
99
  constructor(status, code, message, details, rawBody) {
90
100
  super(message);
91
- this.status = status;
92
101
  this.name = "ApiError";
102
+ this.status = status;
93
103
  this.code = code;
94
104
  this.details = details;
95
105
  this.rawBody = rawBody;
@@ -120,38 +130,54 @@ class ApiError extends Error {
120
130
  }
121
131
  function statusCodeToErrorCode(status) {
122
132
  switch (status) {
123
- case 400:
133
+ case 400: {
124
134
  return "BAD_REQUEST";
125
- case 401:
135
+ }
136
+ case 401: {
126
137
  return "UNAUTHORIZED";
127
- case 403:
138
+ }
139
+ case 403: {
128
140
  return "FORBIDDEN";
129
- case 404:
141
+ }
142
+ case 404: {
130
143
  return "NOT_FOUND";
131
- case 405:
144
+ }
145
+ case 405: {
132
146
  return "METHOD_NOT_ALLOWED";
133
- case 409:
147
+ }
148
+ case 409: {
134
149
  return "CONFLICT";
135
- case 410:
150
+ }
151
+ case 410: {
136
152
  return "GONE";
137
- case 412:
153
+ }
154
+ case 412: {
138
155
  return "PRECONDITION_FAILED";
139
- case 413:
156
+ }
157
+ case 413: {
140
158
  return "PAYLOAD_TOO_LARGE";
141
- case 422:
159
+ }
160
+ case 422: {
142
161
  return "VALIDATION_FAILED";
143
- case 429:
162
+ }
163
+ case 429: {
144
164
  return "TOO_MANY_REQUESTS";
145
- case 500:
165
+ }
166
+ case 500: {
146
167
  return "INTERNAL_ERROR";
147
- case 501:
168
+ }
169
+ case 501: {
148
170
  return "NOT_IMPLEMENTED";
149
- case 503:
171
+ }
172
+ case 503: {
150
173
  return "SERVICE_UNAVAILABLE";
151
- case 504:
174
+ }
175
+ case 504: {
152
176
  return "TIMEOUT";
153
- default:
177
+ }
178
+ default: {
154
179
  return status >= 500 ? "INTERNAL_ERROR" : "BAD_REQUEST";
180
+ }
155
181
  }
156
182
  }
157
183
  function extractApiErrorInfo(error) {
@@ -268,7 +294,7 @@ async function loadFile(filename, options = {}) {
268
294
  return null;
269
295
  }
270
296
  try {
271
- let content = await readFile(fileResult.path, "utf-8");
297
+ let content = await readFile(fileResult.path, "utf8");
272
298
  if (parseJson) {
273
299
  if (stripComments) {
274
300
  content = stripJsonComments(content);
@@ -277,7 +303,7 @@ async function loadFile(filename, options = {}) {
277
303
  }
278
304
  return content;
279
305
  } catch (error) {
280
- throw new Error(`Failed to load ${fileResult.filename} from ${fileResult.path}: ${error instanceof Error ? error.message : String(error)}`);
306
+ throw new Error(`Failed to load ${fileResult.filename} from ${fileResult.path}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
281
307
  }
282
308
  }
283
309
  async function findFile(filename, options = {}) {
@@ -345,7 +371,7 @@ async function loadConfig(configPath) {
345
371
  validateConfig(config);
346
372
  return config;
347
373
  } catch (error) {
348
- throw new Error(`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`);
374
+ throw new Error(`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
349
375
  }
350
376
  }
351
377
  function validateConfig(config) {
@@ -463,7 +489,9 @@ Please set the PLAYCADEMY_BASE_URL environment variable`);
463
489
  if (error instanceof Error) {
464
490
  throw error;
465
491
  }
466
- throw new Error("[Playcademy SDK] Token verification failed: Network error");
492
+ throw new Error("[Playcademy SDK] Token verification failed: Network error", {
493
+ cause: error
494
+ });
467
495
  }
468
496
  }
469
497
  export {