@playcademy/sdk 0.0.9 → 0.1.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/server.d.ts CHANGED
@@ -96,7 +96,7 @@ interface PlaycademyServerClientConfig {
96
96
  config?: PlaycademyConfig;
97
97
  /**
98
98
  * Optional base URL for Playcademy API.
99
- * Defaults to environment variables or 'https://hub.playcademy.com'.
99
+ * Defaults to environment variables or 'https://hub.playcademy.net'.
100
100
  *
101
101
  * @example 'http://localhost:3000' for local development
102
102
  */
package/dist/server.js CHANGED
@@ -301,7 +301,7 @@ class PlaycademyClient {
301
301
  if (!apiKey || typeof apiKey !== "string") {
302
302
  throw new Error("[Playcademy SDK] apiKey is required");
303
303
  }
304
- const finalBaseUrl = baseUrl || process.env.PLAYCADEMY_BASE_URL || "https://hub.playcademy.com";
304
+ const finalBaseUrl = baseUrl || process.env.PLAYCADEMY_BASE_URL || "https://hub.playcademy.net";
305
305
  const loadedConfig = config.config || await loadConfig(configPath);
306
306
  const state = {
307
307
  apiKey,
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AUTH_PROVIDER_IDS } from '@playcademy/constants';
1
2
  import { InferSelectModel } from 'drizzle-orm';
2
3
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
3
4
  import * as drizzle_zod from 'drizzle-zod';
@@ -645,7 +646,7 @@ declare const items: drizzle_orm_pg_core.PgTableWithColumns<{
645
646
  tableName: "items";
646
647
  dataType: "string";
647
648
  columnType: "PgEnumColumn";
648
- data: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
649
+ data: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
649
650
  driverParam: string;
650
651
  notNull: true;
651
652
  hasDefault: true;
@@ -1889,7 +1890,7 @@ declare const characterComponents: drizzle_orm_pg_core.PgTableWithColumns<{
1889
1890
  tableName: "character_components";
1890
1891
  dataType: "string";
1891
1892
  columnType: "PgEnumColumn";
1892
- data: "accessory" | "body" | "outfit" | "hairstyle" | "eyes";
1893
+ data: "body" | "outfit" | "hairstyle" | "eyes" | "accessory";
1893
1894
  driverParam: string;
1894
1895
  notNull: true;
1895
1896
  hasDefault: false;
@@ -3108,7 +3109,7 @@ declare const InsertItemSchema: drizzle_zod.BuildSchema<"insert", {
3108
3109
  tableName: "items";
3109
3110
  dataType: "string";
3110
3111
  columnType: "PgEnumColumn";
3111
- data: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
3112
+ data: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
3112
3113
  driverParam: string;
3113
3114
  notNull: true;
3114
3115
  hasDefault: true;
@@ -3209,7 +3210,7 @@ declare const UpdateItemSchema: z.ZodObject<Omit<{
3209
3210
  slug?: string | undefined;
3210
3211
  metadata?: Record<string, unknown> | undefined;
3211
3212
  gameId?: string | null | undefined;
3212
- type?: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other" | undefined;
3213
+ type?: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other" | undefined;
3213
3214
  isPlaceable?: boolean | undefined;
3214
3215
  imageUrl?: string | null | undefined;
3215
3216
  }, {
@@ -3218,7 +3219,7 @@ declare const UpdateItemSchema: z.ZodObject<Omit<{
3218
3219
  slug?: string | undefined;
3219
3220
  metadata?: Record<string, unknown> | undefined;
3220
3221
  gameId?: string | null | undefined;
3221
- type?: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other" | undefined;
3222
+ type?: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other" | undefined;
3222
3223
  isPlaceable?: boolean | undefined;
3223
3224
  imageUrl?: string | null | undefined;
3224
3225
  }>;
@@ -3705,6 +3706,7 @@ type XpHistoryResponse = {
3705
3706
  xp: number;
3706
3707
  }>;
3707
3708
  };
3709
+ type TimebackSubject = 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3708
3710
  type TimebackSetupRequest = {
3709
3711
  gameId: string;
3710
3712
  config: {
@@ -3792,6 +3794,9 @@ type RecordProgressRequest = {
3792
3794
  gameId: string;
3793
3795
  studentId: string;
3794
3796
  progressData: {
3797
+ sensorUrl?: string;
3798
+ subject?: TimebackSubject;
3799
+ appName?: string;
3795
3800
  score?: number;
3796
3801
  totalQuestions?: number;
3797
3802
  correctQuestions?: number;
@@ -3804,9 +3809,6 @@ type RecordProgressRequest = {
3804
3809
  classId?: string;
3805
3810
  courseName?: string;
3806
3811
  studentEmail?: string;
3807
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3808
- appName?: string;
3809
- sensorUrl?: string;
3810
3812
  };
3811
3813
  };
3812
3814
  type RecordProgressResponse = {
@@ -3817,6 +3819,9 @@ type RecordSessionEndRequest = {
3817
3819
  gameId: string;
3818
3820
  studentId: string;
3819
3821
  sessionData: {
3822
+ sensorUrl?: string;
3823
+ subject?: TimebackSubject;
3824
+ appName?: string;
3820
3825
  activeTimeSeconds: number;
3821
3826
  inactiveTimeSeconds?: number;
3822
3827
  wasteTimeSeconds?: number;
@@ -3825,9 +3830,6 @@ type RecordSessionEndRequest = {
3825
3830
  courseId?: string;
3826
3831
  courseName?: string;
3827
3832
  studentEmail?: string;
3828
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3829
- appName?: string;
3830
- sensorUrl?: string;
3831
3833
  };
3832
3834
  };
3833
3835
  type RecordSessionEndResponse = {
@@ -3839,6 +3841,9 @@ type AwardXpRequest = {
3839
3841
  studentId: string;
3840
3842
  xpAmount: number;
3841
3843
  metadata: {
3844
+ sensorUrl: string;
3845
+ subject: TimebackSubject;
3846
+ appName: string;
3842
3847
  reason: string;
3843
3848
  activityId?: string;
3844
3849
  activityName?: string;
@@ -3846,9 +3851,6 @@ type AwardXpRequest = {
3846
3851
  courseName?: string;
3847
3852
  studentEmail?: string;
3848
3853
  bonusType?: string;
3849
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3850
- appName?: string;
3851
- sensorUrl?: string;
3852
3854
  };
3853
3855
  };
3854
3856
  type AwardXpResponse = {
@@ -3857,10 +3859,6 @@ type AwardXpResponse = {
3857
3859
  xpAwarded: number;
3858
3860
  };
3859
3861
 
3860
- declare const AuthProvider: {
3861
- readonly TIMEBACK: "TIMEBACK";
3862
- };
3863
-
3864
3862
  /**
3865
3863
  * OAuth 2.0 implementation for the Playcademy SDK
3866
3864
  */
@@ -4040,7 +4038,7 @@ interface PlaycademyServerClientConfig {
4040
4038
  config?: PlaycademyConfig;
4041
4039
  /**
4042
4040
  * Optional base URL for Playcademy API.
4043
- * Defaults to environment variables or 'https://hub.playcademy.com'.
4041
+ * Defaults to environment variables or 'https://hub.playcademy.net'.
4044
4042
  *
4045
4043
  * @example 'http://localhost:3000' for local development
4046
4044
  */
@@ -4295,7 +4293,8 @@ type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4295
4293
  * Provides namespaced access to all platform features including games, users, inventory, and more.
4296
4294
  */
4297
4295
  declare class PlaycademyClient {
4298
- private baseUrl;
4296
+ baseUrl: string;
4297
+ gameUrl?: string;
4299
4298
  private authStrategy;
4300
4299
  private gameId?;
4301
4300
  private config;
@@ -4307,7 +4306,7 @@ declare class PlaycademyClient {
4307
4306
  * Creates a new PlaycademyClient instance.
4308
4307
  *
4309
4308
  * @param config - Optional configuration object
4310
- * @param config.baseUrl - Base URL for API requests (defaults to '/api')
4309
+ * @param config.baseUrl - Base URL (e.g., 'https://hub.playcademy.net' or '/'). SDK automatically appends /api
4311
4310
  * @param config.token - Authentication token
4312
4311
  * @param config.tokenType - Optional token type (auto-detected if not provided)
4313
4312
  * @param config.gameId - Game ID for automatic session management
@@ -4317,10 +4316,19 @@ declare class PlaycademyClient {
4317
4316
  /**
4318
4317
  * Gets the effective base URL for API requests.
4319
4318
  * Converts relative URLs to absolute URLs in browser environments.
4319
+ * Note: baseUrl already includes /api suffix from constructor.
4320
4320
  *
4321
- * @returns The complete base URL for API requests
4321
+ * @returns The complete base URL for API requests (with /api suffix)
4322
4322
  */
4323
4323
  getBaseUrl(): string;
4324
+ /**
4325
+ * Gets the effective game backend URL for integration requests.
4326
+ * Throws if gameUrl is not configured.
4327
+ *
4328
+ * @returns The complete game backend URL for API requests (with /api suffix)
4329
+ * @throws PlaycademyError if gameUrl is not set
4330
+ */
4331
+ private getGameBackendUrl;
4324
4332
  /**
4325
4333
  * Simple ping method for testing connectivity.
4326
4334
  *
@@ -4408,7 +4416,7 @@ declare class PlaycademyClient {
4408
4416
  */
4409
4417
  private emit;
4410
4418
  /**
4411
- * Makes an authenticated HTTP request to the API.
4419
+ * Makes an authenticated HTTP request to the platform API.
4412
4420
  *
4413
4421
  * @param path - API endpoint path
4414
4422
  * @param method - HTTP method
@@ -4417,6 +4425,17 @@ declare class PlaycademyClient {
4417
4425
  * @returns Promise resolving to the response data
4418
4426
  */
4419
4427
  protected request<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4428
+ /**
4429
+ * Makes an authenticated HTTP request to the game's backend Worker.
4430
+ * Uses gameUrl if set, otherwise falls back to platform API.
4431
+ *
4432
+ * @param path - API endpoint path
4433
+ * @param method - HTTP method
4434
+ * @param body - Request body (optional)
4435
+ * @param headers - Additional headers (optional)
4436
+ * @returns Promise resolving to the response data
4437
+ */
4438
+ protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4420
4439
  /**
4421
4440
  * Ensures a gameId is available, throwing an error if not.
4422
4441
  *
@@ -4588,7 +4607,7 @@ declare class PlaycademyClient {
4588
4607
  create: (props: InsertItemInput) => Promise<{
4589
4608
  id: string;
4590
4609
  createdAt: Date;
4591
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
4610
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
4592
4611
  gameId: string | null;
4593
4612
  slug: string;
4594
4613
  displayName: string;
@@ -4600,7 +4619,7 @@ declare class PlaycademyClient {
4600
4619
  get: (itemId: string) => Promise<{
4601
4620
  id: string;
4602
4621
  createdAt: Date;
4603
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
4622
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
4604
4623
  gameId: string | null;
4605
4624
  slug: string;
4606
4625
  displayName: string;
@@ -4612,7 +4631,7 @@ declare class PlaycademyClient {
4612
4631
  list: () => Promise<{
4613
4632
  id: string;
4614
4633
  createdAt: Date;
4615
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
4634
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
4616
4635
  gameId: string | null;
4617
4636
  slug: string;
4618
4637
  displayName: string;
@@ -4624,7 +4643,7 @@ declare class PlaycademyClient {
4624
4643
  update: (itemId: string, props: UpdateItemInput) => Promise<{
4625
4644
  id: string;
4626
4645
  createdAt: Date;
4627
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
4646
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
4628
4647
  gameId: string | null;
4629
4648
  slug: string;
4630
4649
  displayName: string;
@@ -4763,7 +4782,7 @@ declare class PlaycademyClient {
4763
4782
  }) => Promise<TodayXpResponse>;
4764
4783
  total: () => Promise<TotalXpResponse>;
4765
4784
  history: (options?: {
4766
- startDate? /** TimeBack XP methods (today, total, history) */: string;
4785
+ startDate?: string;
4767
4786
  endDate?: string;
4768
4787
  }) => Promise<XpHistoryResponse>;
4769
4788
  summary: (options?: {
@@ -4855,6 +4874,15 @@ declare class PlaycademyClient {
4855
4874
  }, cacheOptions?: TTLCacheConfig) => Promise<NotificationStats>;
4856
4875
  };
4857
4876
  };
4877
+ /** Backend methods for calling custom game API routes */
4878
+ backend: {
4879
+ get<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4880
+ post<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4881
+ put<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4882
+ patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4883
+ delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4884
+ request<T = unknown>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4885
+ };
4858
4886
  /** Auto-initializes a PlaycademyClient with context from the environment */
4859
4887
  static init: typeof init;
4860
4888
  /** Authenticates a user with email and password */
@@ -4868,6 +4896,7 @@ declare class PlaycademyClient {
4868
4896
  type TokenType = 'session' | 'apiKey' | 'gameJwt';
4869
4897
  interface ClientConfig {
4870
4898
  baseUrl: string;
4899
+ gameUrl?: string;
4871
4900
  token?: string;
4872
4901
  tokenType?: TokenType;
4873
4902
  gameId?: string;
@@ -4875,11 +4904,12 @@ interface ClientConfig {
4875
4904
  }
4876
4905
  interface InitPayload {
4877
4906
  baseUrl: string;
4907
+ gameUrl?: string;
4878
4908
  token: string;
4879
4909
  gameId: string;
4880
4910
  realtimeUrl?: string;
4881
4911
  }
4882
- type AuthProviderType = (typeof AuthProvider)[keyof typeof AuthProvider];
4912
+ type AuthProviderType = (typeof AUTH_PROVIDER_IDS)[keyof typeof AUTH_PROVIDER_IDS];
4883
4913
  interface AuthOptions {
4884
4914
  /** The identity provider to use for authentication */
4885
4915
  provider: AuthProviderType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -27,21 +27,22 @@
27
27
  "scripts": {
28
28
  "build": "bun build.js",
29
29
  "lint": "bunx eslint . --fix --ignore-pattern dist",
30
- "bump": "SKIP_TESTS=1 bunx bumpp --no-tag --no-push -c \"chore(@playcademy/sdk): release v%s\"",
31
- "pub": "bun run build && bun run bump && bun publish --access public",
30
+ "pub": "bun publish.ts",
32
31
  "test": "bun test",
33
32
  "test:watch": "bun test --watch",
34
33
  "docs": "typedoc"
35
34
  },
36
35
  "devDependencies": {
37
- "playcademy": "0.4.0",
38
- "@playcademy/timeback": "0.0.1",
39
- "@playcademy/utils": "0.0.1",
36
+ "@inquirer/prompts": "^7.8.6",
37
+ "@playcademy/constants": "0.0.1",
40
38
  "@playcademy/data": "0.0.1",
41
39
  "@playcademy/logger": "0.0.1",
42
- "@playcademy/sandbox": "0.1.0-beta.20",
40
+ "@playcademy/sandbox": "0.1.0",
43
41
  "@playcademy/test": "0.0.1",
42
+ "@playcademy/timeback": "0.0.1",
43
+ "@playcademy/utils": "0.0.1",
44
44
  "@types/bun": "latest",
45
+ "playcademy": "0.11.2",
45
46
  "rollup": "^4.50.2",
46
47
  "rollup-plugin-dts": "^6.2.3",
47
48
  "typescript": "^5.7.2",