@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/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
4
4
  import * as drizzle_zod from 'drizzle-zod';
5
5
  import { z } from 'zod';
6
6
  import { OrganizationConfig, CourseConfig, ComponentConfig, ResourceConfig, ComponentResourceConfig } from '@playcademy/timeback/types';
7
+ import { AUTH_PROVIDER_IDS } from '@playcademy/constants';
7
8
 
8
9
  declare const users: drizzle_orm_pg_core.PgTableWithColumns<{
9
10
  name: "user";
@@ -552,7 +553,7 @@ declare const items: drizzle_orm_pg_core.PgTableWithColumns<{
552
553
  tableName: "items";
553
554
  dataType: "string";
554
555
  columnType: "PgEnumColumn";
555
- data: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
556
+ data: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
556
557
  driverParam: string;
557
558
  notNull: true;
558
559
  hasDefault: true;
@@ -1439,7 +1440,7 @@ declare const characterComponents: drizzle_orm_pg_core.PgTableWithColumns<{
1439
1440
  tableName: "character_components";
1440
1441
  dataType: "string";
1441
1442
  columnType: "PgEnumColumn";
1442
- data: "accessory" | "body" | "outfit" | "hairstyle" | "eyes";
1443
+ data: "body" | "outfit" | "hairstyle" | "eyes" | "accessory";
1443
1444
  driverParam: string;
1444
1445
  notNull: true;
1445
1446
  hasDefault: false;
@@ -2441,7 +2442,7 @@ declare const InsertItemSchema: drizzle_zod.BuildSchema<"insert", {
2441
2442
  tableName: "items";
2442
2443
  dataType: "string";
2443
2444
  columnType: "PgEnumColumn";
2444
- data: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
2445
+ data: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
2445
2446
  driverParam: string;
2446
2447
  notNull: true;
2447
2448
  hasDefault: true;
@@ -2542,7 +2543,7 @@ declare const UpdateItemSchema: z.ZodObject<Omit<{
2542
2543
  slug?: string | undefined;
2543
2544
  metadata?: Record<string, unknown> | undefined;
2544
2545
  gameId?: string | null | undefined;
2545
- type?: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other" | undefined;
2546
+ type?: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other" | undefined;
2546
2547
  isPlaceable?: boolean | undefined;
2547
2548
  imageUrl?: string | null | undefined;
2548
2549
  }, {
@@ -2551,7 +2552,7 @@ declare const UpdateItemSchema: z.ZodObject<Omit<{
2551
2552
  slug?: string | undefined;
2552
2553
  metadata?: Record<string, unknown> | undefined;
2553
2554
  gameId?: string | null | undefined;
2554
- type?: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other" | undefined;
2555
+ type?: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other" | undefined;
2555
2556
  isPlaceable?: boolean | undefined;
2556
2557
  imageUrl?: string | null | undefined;
2557
2558
  }>;
@@ -3021,6 +3022,7 @@ type XpHistoryResponse = {
3021
3022
  xp: number;
3022
3023
  }>;
3023
3024
  };
3025
+ type TimebackSubject = 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3024
3026
  type TimebackSetupRequest = {
3025
3027
  gameId: string;
3026
3028
  config: {
@@ -3108,6 +3110,9 @@ type RecordProgressRequest = {
3108
3110
  gameId: string;
3109
3111
  studentId: string;
3110
3112
  progressData: {
3113
+ sensorUrl?: string;
3114
+ subject?: TimebackSubject;
3115
+ appName?: string;
3111
3116
  score?: number;
3112
3117
  totalQuestions?: number;
3113
3118
  correctQuestions?: number;
@@ -3120,9 +3125,6 @@ type RecordProgressRequest = {
3120
3125
  classId?: string;
3121
3126
  courseName?: string;
3122
3127
  studentEmail?: string;
3123
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3124
- appName?: string;
3125
- sensorUrl?: string;
3126
3128
  };
3127
3129
  };
3128
3130
  type RecordProgressResponse = {
@@ -3133,6 +3135,9 @@ type RecordSessionEndRequest = {
3133
3135
  gameId: string;
3134
3136
  studentId: string;
3135
3137
  sessionData: {
3138
+ sensorUrl?: string;
3139
+ subject?: TimebackSubject;
3140
+ appName?: string;
3136
3141
  activeTimeSeconds: number;
3137
3142
  inactiveTimeSeconds?: number;
3138
3143
  wasteTimeSeconds?: number;
@@ -3141,9 +3146,6 @@ type RecordSessionEndRequest = {
3141
3146
  courseId?: string;
3142
3147
  courseName?: string;
3143
3148
  studentEmail?: string;
3144
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3145
- appName?: string;
3146
- sensorUrl?: string;
3147
3149
  };
3148
3150
  };
3149
3151
  type RecordSessionEndResponse = {
@@ -3155,6 +3157,9 @@ type AwardXpRequest = {
3155
3157
  studentId: string;
3156
3158
  xpAmount: number;
3157
3159
  metadata: {
3160
+ sensorUrl: string;
3161
+ subject: TimebackSubject;
3162
+ appName: string;
3158
3163
  reason: string;
3159
3164
  activityId?: string;
3160
3165
  activityName?: string;
@@ -3162,9 +3167,6 @@ type AwardXpRequest = {
3162
3167
  courseName?: string;
3163
3168
  studentEmail?: string;
3164
3169
  bonusType?: string;
3165
- subject?: 'Reading' | 'Language' | 'Vocabulary' | 'Social Studies' | 'Writing' | 'Science' | 'FastMath' | 'Math' | 'None';
3166
- appName?: string;
3167
- sensorUrl?: string;
3168
3170
  };
3169
3171
  };
3170
3172
  type AwardXpResponse = {
@@ -3173,24 +3175,6 @@ type AwardXpResponse = {
3173
3175
  xpAwarded: number;
3174
3176
  };
3175
3177
 
3176
- /**
3177
- * SDK Constants
3178
- * These are re-exported from @playcademy/data but defined here
3179
- * to avoid bundling issues with API Extractor
3180
- */
3181
- declare const CURRENCIES: {
3182
- readonly PRIMARY: "PLAYCADEMY_CREDITS";
3183
- readonly XP: "PLAYCADEMY_XP";
3184
- };
3185
- declare const BADGES: {
3186
- readonly FOUNDING_MEMBER: "FOUNDING_MEMBER_BADGE";
3187
- readonly EARLY_ADOPTER: "EARLY_ADOPTER_BADGE";
3188
- readonly FIRST_GAME: "FIRST_GAME_BADGE";
3189
- };
3190
- declare const AuthProvider: {
3191
- readonly TIMEBACK: "TIMEBACK";
3192
- };
3193
-
3194
3178
  /**
3195
3179
  * @fileoverview Server SDK Type Definitions
3196
3180
  *
@@ -3263,12 +3247,13 @@ interface BackendDeploymentBundle {
3263
3247
  type TokenType = 'session' | 'apiKey' | 'gameJwt';
3264
3248
  interface ClientConfig {
3265
3249
  baseUrl: string;
3250
+ gameUrl?: string;
3266
3251
  token?: string;
3267
3252
  tokenType?: TokenType;
3268
3253
  gameId?: string;
3269
3254
  autoStartSession?: boolean;
3270
3255
  }
3271
- type AuthProviderType = (typeof AuthProvider)[keyof typeof AuthProvider];
3256
+ type AuthProviderType = (typeof AUTH_PROVIDER_IDS)[keyof typeof AUTH_PROVIDER_IDS];
3272
3257
  interface AuthOptions {
3273
3258
  /** The identity provider to use for authentication */
3274
3259
  provider: AuthProviderType;
@@ -3620,7 +3605,8 @@ type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
3620
3605
  * Provides namespaced access to all platform features including games, users, inventory, and more.
3621
3606
  */
3622
3607
  declare class PlaycademyClient {
3623
- private baseUrl;
3608
+ baseUrl: string;
3609
+ gameUrl?: string;
3624
3610
  private authStrategy;
3625
3611
  private gameId?;
3626
3612
  private config;
@@ -3632,7 +3618,7 @@ declare class PlaycademyClient {
3632
3618
  * Creates a new PlaycademyClient instance.
3633
3619
  *
3634
3620
  * @param config - Optional configuration object
3635
- * @param config.baseUrl - Base URL for API requests (defaults to '/api')
3621
+ * @param config.baseUrl - Base URL (e.g., 'https://hub.playcademy.net' or '/'). SDK automatically appends /api
3636
3622
  * @param config.token - Authentication token
3637
3623
  * @param config.tokenType - Optional token type (auto-detected if not provided)
3638
3624
  * @param config.gameId - Game ID for automatic session management
@@ -3642,10 +3628,19 @@ declare class PlaycademyClient {
3642
3628
  /**
3643
3629
  * Gets the effective base URL for API requests.
3644
3630
  * Converts relative URLs to absolute URLs in browser environments.
3631
+ * Note: baseUrl already includes /api suffix from constructor.
3645
3632
  *
3646
- * @returns The complete base URL for API requests
3633
+ * @returns The complete base URL for API requests (with /api suffix)
3647
3634
  */
3648
3635
  getBaseUrl(): string;
3636
+ /**
3637
+ * Gets the effective game backend URL for integration requests.
3638
+ * Throws if gameUrl is not configured.
3639
+ *
3640
+ * @returns The complete game backend URL for API requests (with /api suffix)
3641
+ * @throws PlaycademyError if gameUrl is not set
3642
+ */
3643
+ private getGameBackendUrl;
3649
3644
  /**
3650
3645
  * Simple ping method for testing connectivity.
3651
3646
  *
@@ -3733,7 +3728,7 @@ declare class PlaycademyClient {
3733
3728
  */
3734
3729
  private emit;
3735
3730
  /**
3736
- * Makes an authenticated HTTP request to the API.
3731
+ * Makes an authenticated HTTP request to the platform API.
3737
3732
  *
3738
3733
  * @param path - API endpoint path
3739
3734
  * @param method - HTTP method
@@ -3742,6 +3737,17 @@ declare class PlaycademyClient {
3742
3737
  * @returns Promise resolving to the response data
3743
3738
  */
3744
3739
  protected request<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
3740
+ /**
3741
+ * Makes an authenticated HTTP request to the game's backend Worker.
3742
+ * Uses gameUrl if set, otherwise falls back to platform API.
3743
+ *
3744
+ * @param path - API endpoint path
3745
+ * @param method - HTTP method
3746
+ * @param body - Request body (optional)
3747
+ * @param headers - Additional headers (optional)
3748
+ * @returns Promise resolving to the response data
3749
+ */
3750
+ protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
3745
3751
  /**
3746
3752
  * Ensures a gameId is available, throwing an error if not.
3747
3753
  *
@@ -3913,7 +3919,7 @@ declare class PlaycademyClient {
3913
3919
  create: (props: InsertItemInput) => Promise<{
3914
3920
  id: string;
3915
3921
  createdAt: Date;
3916
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
3922
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
3917
3923
  gameId: string | null;
3918
3924
  slug: string;
3919
3925
  displayName: string;
@@ -3925,7 +3931,7 @@ declare class PlaycademyClient {
3925
3931
  get: (itemId: string) => Promise<{
3926
3932
  id: string;
3927
3933
  createdAt: Date;
3928
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
3934
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
3929
3935
  gameId: string | null;
3930
3936
  slug: string;
3931
3937
  displayName: string;
@@ -3937,7 +3943,7 @@ declare class PlaycademyClient {
3937
3943
  list: () => Promise<{
3938
3944
  id: string;
3939
3945
  createdAt: Date;
3940
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
3946
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
3941
3947
  gameId: string | null;
3942
3948
  slug: string;
3943
3949
  displayName: string;
@@ -3949,7 +3955,7 @@ declare class PlaycademyClient {
3949
3955
  update: (itemId: string, props: UpdateItemInput) => Promise<{
3950
3956
  id: string;
3951
3957
  createdAt: Date;
3952
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
3958
+ type: "accessory" | "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
3953
3959
  gameId: string | null;
3954
3960
  slug: string;
3955
3961
  displayName: string;
@@ -4088,7 +4094,7 @@ declare class PlaycademyClient {
4088
4094
  }) => Promise<TodayXpResponse>;
4089
4095
  total: () => Promise<TotalXpResponse>;
4090
4096
  history: (options?: {
4091
- startDate? /** TimeBack XP methods (today, total, history) */: string;
4097
+ startDate?: string;
4092
4098
  endDate?: string;
4093
4099
  }) => Promise<XpHistoryResponse>;
4094
4100
  summary: (options?: {
@@ -4180,6 +4186,15 @@ declare class PlaycademyClient {
4180
4186
  }, cacheOptions?: TTLCacheConfig) => Promise<NotificationStats>;
4181
4187
  };
4182
4188
  };
4189
+ /** Backend methods for calling custom game API routes */
4190
+ backend: {
4191
+ get<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4192
+ post<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4193
+ put<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4194
+ patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4195
+ delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4196
+ request<T = unknown>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4197
+ };
4183
4198
  /** Auto-initializes a PlaycademyClient with context from the environment */
4184
4199
  static init: typeof init;
4185
4200
  /** Authenticates a user with email and password */
@@ -4734,5 +4749,5 @@ declare class PlaycademyMessaging {
4734
4749
  */
4735
4750
  declare const messaging: PlaycademyMessaging;
4736
4751
 
4737
- export { AuthProvider, BADGES, CURRENCIES, MessageEvents, PlaycademyClient, messaging };
4752
+ export { MessageEvents, PlaycademyClient, messaging };
4738
4753
  export type { DevUploadEvent, DevUploadHooks };