@playcademy/sdk 0.14.0 → 0.14.1-beta.1

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _playcademy_types from '@playcademy/types';
2
+ import { LocalDayContext } from '@playcademy/types';
2
3
  import { TimebackGrade, TimebackSubject, HeartbeatRequest } from '@playcademy/types/timeback';
3
4
  import { TimebackUserRole, UserEnrollment, UserOrganization, UserInfo } from '@playcademy/types/user';
4
5
  import { AUTH_PROVIDER_IDS } from '@playcademy/constants';
@@ -227,6 +228,7 @@ declare abstract class PlaycademyBaseClient {
227
228
  protected initPayload?: InitPayload;
228
229
  protected launchId?: string;
229
230
  protected gameOrigin?: string;
231
+ private browserTimeZone?;
230
232
  constructor(config?: Partial<ClientConfig>);
231
233
  /**
232
234
  * Gets the effective base URL for API requests.
@@ -240,6 +242,10 @@ declare abstract class PlaycademyBaseClient {
240
242
  * Simple ping method for testing connectivity.
241
243
  */
242
244
  ping(): string;
245
+ /**
246
+ * Local day context supplied by the platform during iframe initialization.
247
+ */
248
+ get localDay(): LocalDayContext | undefined;
243
249
  /**
244
250
  * Sets the authentication token for API requests.
245
251
  */
@@ -296,6 +302,7 @@ declare abstract class PlaycademyBaseClient {
296
302
  raw?: boolean;
297
303
  retryPolicy?: RetryPolicy;
298
304
  }): Promise<T>;
305
+ private getBrowserTimeZone;
299
306
  /**
300
307
  * Makes an authenticated HTTP request to the game's backend Worker.
301
308
  */
@@ -1451,6 +1458,8 @@ interface InitPayload {
1451
1458
  gameId: string;
1452
1459
  /** Timeback context (if user has a Timeback account) */
1453
1460
  timeback?: TimebackInitContext;
1461
+ /** Playcademy context for resolving the student's local learning day */
1462
+ localDay?: LocalDayContext;
1454
1463
  /** Runtime mode for the game client */
1455
1464
  mode?: PlaycademyMode;
1456
1465
  /** Launch session correlation ID (UUID, set by platform on game launch) */
package/dist/index.js CHANGED
@@ -1137,6 +1137,8 @@ function isValidGrade(value) {
1137
1137
  function isValidSubject(value) {
1138
1138
  return typeof value === "string" && VALID_SUBJECTS.includes(value);
1139
1139
  }
1140
+ // ../constants/src/platform.ts
1141
+ var PLAYCADEMY_BROWSER_TIME_ZONE_HEADER = "x-playcademy-browser-time-zone";
1140
1142
  // ../constants/src/timeback.ts
1141
1143
  var TIMEBACK_ROUTES = {
1142
1144
  END_ACTIVITY: "/integrations/timeback/end-activity",
@@ -2122,7 +2124,12 @@ function createUsersNamespace(client) {
2122
2124
  return {
2123
2125
  me: async () => {
2124
2126
  assertPlatformMode(client, "users.me()");
2125
- return client["request"]("/users/me", "GET");
2127
+ const user = await client["request"]("/users/me", "GET");
2128
+ const initPayload = client["initPayload"];
2129
+ if (initPayload) {
2130
+ initPayload.localDay = user.localDay;
2131
+ }
2132
+ return user;
2126
2133
  }
2127
2134
  };
2128
2135
  }
@@ -2379,7 +2386,7 @@ async function request({
2379
2386
  return rawText && rawText.length > 0 ? rawText : undefined;
2380
2387
  }
2381
2388
  // src/version.ts
2382
- var SDK_VERSION = "0.14.0";
2389
+ var SDK_VERSION = "0.14.1-beta.1";
2383
2390
 
2384
2391
  // src/clients/base.ts
2385
2392
  class PlaycademyBaseClient {
@@ -2394,6 +2401,7 @@ class PlaycademyBaseClient {
2394
2401
  initPayload;
2395
2402
  launchId;
2396
2403
  gameOrigin;
2404
+ browserTimeZone;
2397
2405
  constructor(config) {
2398
2406
  this.baseUrl = config?.baseUrl?.endsWith("/api") ? config.baseUrl : `${config?.baseUrl}/api`;
2399
2407
  this.gameUrl = config?.gameUrl;
@@ -2422,6 +2430,9 @@ class PlaycademyBaseClient {
2422
2430
  ping() {
2423
2431
  return "pong";
2424
2432
  }
2433
+ get localDay() {
2434
+ return this.initPayload?.localDay;
2435
+ }
2425
2436
  setToken(token, tokenType) {
2426
2437
  this.authStrategy = createAuthStrategy(token, tokenType);
2427
2438
  this.emit("authChange", { token });
@@ -2465,11 +2476,13 @@ class PlaycademyBaseClient {
2465
2476
  });
2466
2477
  }
2467
2478
  async request(path, method, options) {
2479
+ const browserTimeZone = this.getBrowserTimeZone();
2468
2480
  const effectiveHeaders = {
2469
2481
  ...options?.headers,
2470
2482
  ...this.authStrategy.getHeaders(),
2471
2483
  ...this.launchId ? { "x-playcademy-launch-id": this.launchId } : {},
2472
2484
  ...this.gameOrigin ? { "x-playcademy-game-origin": this.gameOrigin } : {},
2485
+ ...browserTimeZone ? { [PLAYCADEMY_BROWSER_TIME_ZONE_HEADER]: browserTimeZone } : {},
2473
2486
  "x-playcademy-sdk-version": SDK_VERSION
2474
2487
  };
2475
2488
  return request({
@@ -2482,6 +2495,22 @@ class PlaycademyBaseClient {
2482
2495
  retryPolicy: options?.retryPolicy
2483
2496
  });
2484
2497
  }
2498
+ getBrowserTimeZone() {
2499
+ if (this.browserTimeZone !== undefined) {
2500
+ return this.browserTimeZone ?? undefined;
2501
+ }
2502
+ if (typeof globalThis.window === "undefined") {
2503
+ this.browserTimeZone = null;
2504
+ return;
2505
+ }
2506
+ try {
2507
+ const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
2508
+ this.browserTimeZone = typeof timeZone === "string" && timeZone ? timeZone : null;
2509
+ } catch {
2510
+ this.browserTimeZone = null;
2511
+ }
2512
+ return this.browserTimeZone ?? undefined;
2513
+ }
2485
2514
  async requestGameBackend(path, method, body, headers, options) {
2486
2515
  const effectiveHeaders = {
2487
2516
  ...headers,