@playcademy/sdk 0.2.0 → 0.2.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/README.md +20 -17
- package/dist/index.d.ts +245 -561
- package/dist/index.js +1275 -1435
- package/dist/internal.d.ts +2558 -2318
- package/dist/internal.js +2454 -2565
- package/dist/server.d.ts +6 -5
- package/dist/server.js +14 -1
- package/dist/types.d.ts +448 -549
- package/package.json +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _playcademy_realtime_server_types from '@playcademy/realtime/server/types';
|
|
2
1
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
3
2
|
import { z } from 'zod';
|
|
4
3
|
import * as _playcademy_timeback_types from '@playcademy/timeback/types';
|
|
@@ -2121,166 +2120,6 @@ declare const playerCharacterAccessories: drizzle_orm_pg_core.PgTableWithColumns
|
|
|
2121
2120
|
};
|
|
2122
2121
|
dialect: "pg";
|
|
2123
2122
|
}>;
|
|
2124
|
-
declare const gameTimebackIntegrations: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
2125
|
-
name: "game_timeback_integrations";
|
|
2126
|
-
schema: undefined;
|
|
2127
|
-
columns: {
|
|
2128
|
-
id: drizzle_orm_pg_core.PgColumn<{
|
|
2129
|
-
name: "id";
|
|
2130
|
-
tableName: "game_timeback_integrations";
|
|
2131
|
-
dataType: "string";
|
|
2132
|
-
columnType: "PgUUID";
|
|
2133
|
-
data: string;
|
|
2134
|
-
driverParam: string;
|
|
2135
|
-
notNull: true;
|
|
2136
|
-
hasDefault: true;
|
|
2137
|
-
isPrimaryKey: true;
|
|
2138
|
-
isAutoincrement: false;
|
|
2139
|
-
hasRuntimeDefault: false;
|
|
2140
|
-
enumValues: undefined;
|
|
2141
|
-
baseColumn: never;
|
|
2142
|
-
identity: undefined;
|
|
2143
|
-
generated: undefined;
|
|
2144
|
-
}, {}, {}>;
|
|
2145
|
-
gameId: drizzle_orm_pg_core.PgColumn<{
|
|
2146
|
-
name: "game_id";
|
|
2147
|
-
tableName: "game_timeback_integrations";
|
|
2148
|
-
dataType: "string";
|
|
2149
|
-
columnType: "PgUUID";
|
|
2150
|
-
data: string;
|
|
2151
|
-
driverParam: string;
|
|
2152
|
-
notNull: true;
|
|
2153
|
-
hasDefault: false;
|
|
2154
|
-
isPrimaryKey: false;
|
|
2155
|
-
isAutoincrement: false;
|
|
2156
|
-
hasRuntimeDefault: false;
|
|
2157
|
-
enumValues: undefined;
|
|
2158
|
-
baseColumn: never;
|
|
2159
|
-
identity: undefined;
|
|
2160
|
-
generated: undefined;
|
|
2161
|
-
}, {}, {}>;
|
|
2162
|
-
courseId: drizzle_orm_pg_core.PgColumn<{
|
|
2163
|
-
name: "course_id";
|
|
2164
|
-
tableName: "game_timeback_integrations";
|
|
2165
|
-
dataType: "string";
|
|
2166
|
-
columnType: "PgText";
|
|
2167
|
-
data: string;
|
|
2168
|
-
driverParam: string;
|
|
2169
|
-
notNull: true;
|
|
2170
|
-
hasDefault: false;
|
|
2171
|
-
isPrimaryKey: false;
|
|
2172
|
-
isAutoincrement: false;
|
|
2173
|
-
hasRuntimeDefault: false;
|
|
2174
|
-
enumValues: [string, ...string[]];
|
|
2175
|
-
baseColumn: never;
|
|
2176
|
-
identity: undefined;
|
|
2177
|
-
generated: undefined;
|
|
2178
|
-
}, {}, {}>;
|
|
2179
|
-
grade: drizzle_orm_pg_core.PgColumn<{
|
|
2180
|
-
name: "grade";
|
|
2181
|
-
tableName: "game_timeback_integrations";
|
|
2182
|
-
dataType: "number";
|
|
2183
|
-
columnType: "PgInteger";
|
|
2184
|
-
data: number;
|
|
2185
|
-
driverParam: string | number;
|
|
2186
|
-
notNull: true;
|
|
2187
|
-
hasDefault: false;
|
|
2188
|
-
isPrimaryKey: false;
|
|
2189
|
-
isAutoincrement: false;
|
|
2190
|
-
hasRuntimeDefault: false;
|
|
2191
|
-
enumValues: undefined;
|
|
2192
|
-
baseColumn: never;
|
|
2193
|
-
identity: undefined;
|
|
2194
|
-
generated: undefined;
|
|
2195
|
-
}, {}, {}>;
|
|
2196
|
-
subject: drizzle_orm_pg_core.PgColumn<{
|
|
2197
|
-
name: "subject";
|
|
2198
|
-
tableName: "game_timeback_integrations";
|
|
2199
|
-
dataType: "string";
|
|
2200
|
-
columnType: "PgText";
|
|
2201
|
-
data: string;
|
|
2202
|
-
driverParam: string;
|
|
2203
|
-
notNull: true;
|
|
2204
|
-
hasDefault: false;
|
|
2205
|
-
isPrimaryKey: false;
|
|
2206
|
-
isAutoincrement: false;
|
|
2207
|
-
hasRuntimeDefault: false;
|
|
2208
|
-
enumValues: [string, ...string[]];
|
|
2209
|
-
baseColumn: never;
|
|
2210
|
-
identity: undefined;
|
|
2211
|
-
generated: undefined;
|
|
2212
|
-
}, {}, {}>;
|
|
2213
|
-
totalXp: drizzle_orm_pg_core.PgColumn<{
|
|
2214
|
-
name: "total_xp";
|
|
2215
|
-
tableName: "game_timeback_integrations";
|
|
2216
|
-
dataType: "number";
|
|
2217
|
-
columnType: "PgInteger";
|
|
2218
|
-
data: number;
|
|
2219
|
-
driverParam: string | number;
|
|
2220
|
-
notNull: false;
|
|
2221
|
-
hasDefault: false;
|
|
2222
|
-
isPrimaryKey: false;
|
|
2223
|
-
isAutoincrement: false;
|
|
2224
|
-
hasRuntimeDefault: false;
|
|
2225
|
-
enumValues: undefined;
|
|
2226
|
-
baseColumn: never;
|
|
2227
|
-
identity: undefined;
|
|
2228
|
-
generated: undefined;
|
|
2229
|
-
}, {}, {}>;
|
|
2230
|
-
lastVerifiedAt: drizzle_orm_pg_core.PgColumn<{
|
|
2231
|
-
name: "last_verified_at";
|
|
2232
|
-
tableName: "game_timeback_integrations";
|
|
2233
|
-
dataType: "date";
|
|
2234
|
-
columnType: "PgTimestamp";
|
|
2235
|
-
data: Date;
|
|
2236
|
-
driverParam: string;
|
|
2237
|
-
notNull: false;
|
|
2238
|
-
hasDefault: false;
|
|
2239
|
-
isPrimaryKey: false;
|
|
2240
|
-
isAutoincrement: false;
|
|
2241
|
-
hasRuntimeDefault: false;
|
|
2242
|
-
enumValues: undefined;
|
|
2243
|
-
baseColumn: never;
|
|
2244
|
-
identity: undefined;
|
|
2245
|
-
generated: undefined;
|
|
2246
|
-
}, {}, {}>;
|
|
2247
|
-
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
2248
|
-
name: "created_at";
|
|
2249
|
-
tableName: "game_timeback_integrations";
|
|
2250
|
-
dataType: "date";
|
|
2251
|
-
columnType: "PgTimestamp";
|
|
2252
|
-
data: Date;
|
|
2253
|
-
driverParam: string;
|
|
2254
|
-
notNull: true;
|
|
2255
|
-
hasDefault: true;
|
|
2256
|
-
isPrimaryKey: false;
|
|
2257
|
-
isAutoincrement: false;
|
|
2258
|
-
hasRuntimeDefault: false;
|
|
2259
|
-
enumValues: undefined;
|
|
2260
|
-
baseColumn: never;
|
|
2261
|
-
identity: undefined;
|
|
2262
|
-
generated: undefined;
|
|
2263
|
-
}, {}, {}>;
|
|
2264
|
-
updatedAt: drizzle_orm_pg_core.PgColumn<{
|
|
2265
|
-
name: "updated_at";
|
|
2266
|
-
tableName: "game_timeback_integrations";
|
|
2267
|
-
dataType: "date";
|
|
2268
|
-
columnType: "PgTimestamp";
|
|
2269
|
-
data: Date;
|
|
2270
|
-
driverParam: string;
|
|
2271
|
-
notNull: true;
|
|
2272
|
-
hasDefault: true;
|
|
2273
|
-
isPrimaryKey: false;
|
|
2274
|
-
isAutoincrement: false;
|
|
2275
|
-
hasRuntimeDefault: false;
|
|
2276
|
-
enumValues: undefined;
|
|
2277
|
-
baseColumn: never;
|
|
2278
|
-
identity: undefined;
|
|
2279
|
-
generated: undefined;
|
|
2280
|
-
}, {}, {}>;
|
|
2281
|
-
};
|
|
2282
|
-
dialect: "pg";
|
|
2283
|
-
}>;
|
|
2284
2123
|
|
|
2285
2124
|
declare const achievementScopeEnum: drizzle_orm_pg_core.PgEnum<["daily", "weekly", "monthly", "yearly", "game", "global", "map", "level", "event"]>;
|
|
2286
2125
|
declare const achievements: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
@@ -2613,13 +2452,66 @@ type MapObject = typeof mapObjects.$inferSelect;
|
|
|
2613
2452
|
type User = typeof users.$inferSelect;
|
|
2614
2453
|
type UserRoleEnumType = (typeof userRoleEnum.enumValues)[number];
|
|
2615
2454
|
type DeveloperStatusResponse = z.infer<typeof DeveloperStatusResponseSchema>;
|
|
2455
|
+
/**
|
|
2456
|
+
* TimeBack enrollment information for a game.
|
|
2457
|
+
*/
|
|
2458
|
+
type UserEnrollment = {
|
|
2459
|
+
gameId?: string;
|
|
2460
|
+
courseId: string;
|
|
2461
|
+
grade: number;
|
|
2462
|
+
subject: string;
|
|
2463
|
+
orgId?: string;
|
|
2464
|
+
};
|
|
2465
|
+
/**
|
|
2466
|
+
* TimeBack user role (matches OneRoster spec).
|
|
2467
|
+
*/
|
|
2468
|
+
type TimebackUserRole = 'administrator' | 'aide' | 'guardian' | 'parent' | 'proctor' | 'relative' | 'student' | 'teacher';
|
|
2469
|
+
/**
|
|
2470
|
+
* Organization type (matches OneRoster spec).
|
|
2471
|
+
*/
|
|
2472
|
+
type TimebackOrgType = 'department' | 'school' | 'district' | 'local' | 'state' | 'national';
|
|
2473
|
+
/**
|
|
2474
|
+
* TimeBack organization data for a user.
|
|
2475
|
+
* Represents schools, districts, or other educational organizations.
|
|
2476
|
+
*/
|
|
2477
|
+
type UserOrganization = {
|
|
2478
|
+
/** Organization ID (OneRoster sourcedId) */
|
|
2479
|
+
id: string;
|
|
2480
|
+
/** Organization name */
|
|
2481
|
+
name: string | null;
|
|
2482
|
+
/** Organization type (school, district, etc.) */
|
|
2483
|
+
type: TimebackOrgType | string;
|
|
2484
|
+
/** Whether this is the user's primary organization */
|
|
2485
|
+
isPrimary: boolean;
|
|
2486
|
+
};
|
|
2487
|
+
/**
|
|
2488
|
+
* TimeBack student profile (role + organizations).
|
|
2489
|
+
* Subset of UserTimebackData returned by OneRoster API.
|
|
2490
|
+
*/
|
|
2491
|
+
type TimebackStudentProfile = {
|
|
2492
|
+
/** User's primary role in TimeBack (student, parent, teacher, etc.) */
|
|
2493
|
+
role: TimebackUserRole;
|
|
2494
|
+
/** User's organizations (schools/districts) */
|
|
2495
|
+
organizations: UserOrganization[];
|
|
2496
|
+
};
|
|
2497
|
+
/**
|
|
2498
|
+
* TimeBack-related data for a user.
|
|
2499
|
+
*/
|
|
2500
|
+
type UserTimebackData = TimebackStudentProfile & {
|
|
2501
|
+
/** User's TimeBack ID (sourcedId) */
|
|
2502
|
+
id: string;
|
|
2503
|
+
/** Course enrollments */
|
|
2504
|
+
enrollments: UserEnrollment[];
|
|
2505
|
+
};
|
|
2616
2506
|
/**
|
|
2617
2507
|
* User data with authentication provider information.
|
|
2618
2508
|
* Returned by the /users/me endpoint with additional auth context.
|
|
2619
2509
|
*/
|
|
2620
|
-
type AuthenticatedUser = User & {
|
|
2510
|
+
type AuthenticatedUser = Omit<User, 'timebackId'> & {
|
|
2621
2511
|
/** Whether the user authenticated via Timeback SSO */
|
|
2622
2512
|
hasTimebackAccount: boolean;
|
|
2513
|
+
/** TimeBack data (id, role, enrollments, organizations) - only present if user has a timeback account */
|
|
2514
|
+
timeback?: UserTimebackData;
|
|
2623
2515
|
};
|
|
2624
2516
|
|
|
2625
2517
|
/**
|
|
@@ -2830,7 +2722,6 @@ interface SpriteTemplateData {
|
|
|
2830
2722
|
};
|
|
2831
2723
|
};
|
|
2832
2724
|
}
|
|
2833
|
-
type GameTimebackIntegration = typeof gameTimebackIntegrations.$inferSelect;
|
|
2834
2725
|
type TodayXpResponse = {
|
|
2835
2726
|
xp: number;
|
|
2836
2727
|
date: string;
|
|
@@ -2844,56 +2735,6 @@ type XpHistoryResponse = {
|
|
|
2844
2735
|
xp: number;
|
|
2845
2736
|
}>;
|
|
2846
2737
|
};
|
|
2847
|
-
type TimebackSetupRequest = {
|
|
2848
|
-
gameId: string;
|
|
2849
|
-
config: {
|
|
2850
|
-
organization: {
|
|
2851
|
-
name: string;
|
|
2852
|
-
type: string;
|
|
2853
|
-
identifier: string;
|
|
2854
|
-
};
|
|
2855
|
-
course: {
|
|
2856
|
-
title: string;
|
|
2857
|
-
subjects: string[];
|
|
2858
|
-
grades: number[];
|
|
2859
|
-
courseCode: string;
|
|
2860
|
-
level: string;
|
|
2861
|
-
gradingScheme: string;
|
|
2862
|
-
metadata?: Record<string, unknown>;
|
|
2863
|
-
};
|
|
2864
|
-
component: {
|
|
2865
|
-
title: string;
|
|
2866
|
-
sortOrder: number;
|
|
2867
|
-
prerequisites: string[];
|
|
2868
|
-
prerequisiteCriteria: string;
|
|
2869
|
-
};
|
|
2870
|
-
resource: {
|
|
2871
|
-
title: string;
|
|
2872
|
-
vendorResourceId: string;
|
|
2873
|
-
vendorId: string;
|
|
2874
|
-
applicationId: string;
|
|
2875
|
-
roles: string[];
|
|
2876
|
-
importance: string;
|
|
2877
|
-
metadata: {
|
|
2878
|
-
type?: string;
|
|
2879
|
-
launchUrl?: string;
|
|
2880
|
-
toolProvider?: string;
|
|
2881
|
-
instructionalMethod?: string;
|
|
2882
|
-
subject?: string;
|
|
2883
|
-
grades?: number[];
|
|
2884
|
-
language?: string;
|
|
2885
|
-
xp?: number;
|
|
2886
|
-
[key: string]: unknown;
|
|
2887
|
-
};
|
|
2888
|
-
};
|
|
2889
|
-
componentResource: {
|
|
2890
|
-
title: string;
|
|
2891
|
-
sortOrder: number;
|
|
2892
|
-
lessonType: string | null;
|
|
2893
|
-
};
|
|
2894
|
-
};
|
|
2895
|
-
verbose?: boolean;
|
|
2896
|
-
};
|
|
2897
2738
|
/**
|
|
2898
2739
|
* Minimal course configuration for TimeBack integration (used in user-facing config).
|
|
2899
2740
|
*
|
|
@@ -2907,100 +2748,6 @@ type TimebackCourseConfig = {
|
|
|
2907
2748
|
subject: string;
|
|
2908
2749
|
grade: number;
|
|
2909
2750
|
};
|
|
2910
|
-
/**
|
|
2911
|
-
* Derived course configuration after merging base + per-course overrides + templating.
|
|
2912
|
-
* This is what the CLI sends to the Platform API in PlatformTimebackSetupRequest.
|
|
2913
|
-
*/
|
|
2914
|
-
type DerivedPlatformCourseConfig = TimebackCourseConfig & {
|
|
2915
|
-
title: string;
|
|
2916
|
-
courseCode: string;
|
|
2917
|
-
level: string;
|
|
2918
|
-
metadata?: Record<string, unknown>;
|
|
2919
|
-
totalXp?: number | null;
|
|
2920
|
-
masterableUnits?: number | null;
|
|
2921
|
-
};
|
|
2922
|
-
type PlatformTimebackSetupRequest = {
|
|
2923
|
-
gameId: string;
|
|
2924
|
-
courses: DerivedPlatformCourseConfig[];
|
|
2925
|
-
baseConfig: {
|
|
2926
|
-
organization: {
|
|
2927
|
-
name: string;
|
|
2928
|
-
type: string;
|
|
2929
|
-
identifier: string;
|
|
2930
|
-
};
|
|
2931
|
-
component: {
|
|
2932
|
-
title: string;
|
|
2933
|
-
titleSuffix?: string;
|
|
2934
|
-
sortOrder: number;
|
|
2935
|
-
prerequisites: string[];
|
|
2936
|
-
prerequisiteCriteria: string;
|
|
2937
|
-
};
|
|
2938
|
-
resource: {
|
|
2939
|
-
title: string;
|
|
2940
|
-
titleSuffix?: string;
|
|
2941
|
-
vendorResourceId: string;
|
|
2942
|
-
vendorId: string;
|
|
2943
|
-
applicationId: string;
|
|
2944
|
-
roles: string[];
|
|
2945
|
-
importance: string;
|
|
2946
|
-
metadata: {
|
|
2947
|
-
type?: string;
|
|
2948
|
-
launchUrl?: string;
|
|
2949
|
-
toolProvider?: string;
|
|
2950
|
-
instructionalMethod?: string;
|
|
2951
|
-
language?: string;
|
|
2952
|
-
[key: string]: unknown;
|
|
2953
|
-
};
|
|
2954
|
-
};
|
|
2955
|
-
componentResource: {
|
|
2956
|
-
title: string;
|
|
2957
|
-
titleSuffix?: string;
|
|
2958
|
-
sortOrder: number;
|
|
2959
|
-
lessonType: string | null;
|
|
2960
|
-
};
|
|
2961
|
-
};
|
|
2962
|
-
verbose?: boolean;
|
|
2963
|
-
};
|
|
2964
|
-
type PlatformTimebackSetupResponse = {
|
|
2965
|
-
integrations: GameTimebackIntegration[];
|
|
2966
|
-
verbose?: Array<{
|
|
2967
|
-
integration: GameTimebackIntegration;
|
|
2968
|
-
config: {
|
|
2969
|
-
course: unknown;
|
|
2970
|
-
component: unknown;
|
|
2971
|
-
resource: unknown;
|
|
2972
|
-
componentResource: unknown;
|
|
2973
|
-
};
|
|
2974
|
-
}>;
|
|
2975
|
-
};
|
|
2976
|
-
type TimebackVerificationResources = {
|
|
2977
|
-
course: {
|
|
2978
|
-
found: boolean;
|
|
2979
|
-
data?: unknown;
|
|
2980
|
-
};
|
|
2981
|
-
component: {
|
|
2982
|
-
found: boolean;
|
|
2983
|
-
data?: unknown;
|
|
2984
|
-
};
|
|
2985
|
-
resource: {
|
|
2986
|
-
found: boolean;
|
|
2987
|
-
data?: unknown;
|
|
2988
|
-
};
|
|
2989
|
-
componentResource: {
|
|
2990
|
-
found: boolean;
|
|
2991
|
-
data?: unknown;
|
|
2992
|
-
};
|
|
2993
|
-
};
|
|
2994
|
-
type TimebackVerifyCourseResult = {
|
|
2995
|
-
integration: GameTimebackIntegration;
|
|
2996
|
-
resources: TimebackVerificationResources;
|
|
2997
|
-
status: 'success' | 'error';
|
|
2998
|
-
errors?: string[];
|
|
2999
|
-
};
|
|
3000
|
-
type TimebackVerifyAllResponse = {
|
|
3001
|
-
status: 'success' | 'error';
|
|
3002
|
-
results: TimebackVerifyCourseResult[];
|
|
3003
|
-
};
|
|
3004
2751
|
type EndActivityResponse = {
|
|
3005
2752
|
status: 'ok';
|
|
3006
2753
|
courseId: string;
|
|
@@ -3011,13 +2758,8 @@ type EndActivityResponse = {
|
|
|
3011
2758
|
inProgress?: string;
|
|
3012
2759
|
};
|
|
3013
2760
|
|
|
3014
|
-
/**
|
|
3015
|
-
|
|
3016
|
-
*/
|
|
3017
|
-
type XpSummaryResponse$1 = {
|
|
3018
|
-
today: TodayXpResponse;
|
|
3019
|
-
total: TotalXpResponse;
|
|
3020
|
-
};
|
|
2761
|
+
/** Permitted HTTP verbs */
|
|
2762
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
3021
2763
|
|
|
3022
2764
|
/**
|
|
3023
2765
|
* Connection monitoring types
|
|
@@ -3033,6 +2775,180 @@ type XpSummaryResponse$1 = {
|
|
|
3033
2775
|
*/
|
|
3034
2776
|
type ConnectionState = 'online' | 'offline' | 'degraded';
|
|
3035
2777
|
|
|
2778
|
+
/**
|
|
2779
|
+
* Connection Manager
|
|
2780
|
+
*
|
|
2781
|
+
* Manages connection monitoring and integrates it with the Playcademy client.
|
|
2782
|
+
* Handles event wiring, state management, and disconnect callbacks.
|
|
2783
|
+
*
|
|
2784
|
+
* In iframe mode, disables local monitoring and listens to platform connection
|
|
2785
|
+
* state broadcasts instead (avoids duplicate heartbeats).
|
|
2786
|
+
*/
|
|
2787
|
+
|
|
2788
|
+
/**
|
|
2789
|
+
* Configuration for the ConnectionManager.
|
|
2790
|
+
*/
|
|
2791
|
+
interface ConnectionManagerConfig {
|
|
2792
|
+
/** Base URL for API requests (used for heartbeat pings) */
|
|
2793
|
+
baseUrl: string;
|
|
2794
|
+
/** Authentication context (iframe vs standalone) for alert routing */
|
|
2795
|
+
authContext?: {
|
|
2796
|
+
isInIframe: boolean;
|
|
2797
|
+
};
|
|
2798
|
+
/** Handler to call when connection issues are detected */
|
|
2799
|
+
onDisconnect?: DisconnectHandler;
|
|
2800
|
+
/** Callback to emit connection change events to the client */
|
|
2801
|
+
onConnectionChange?: (state: ConnectionState, reason: string) => void;
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* Manages connection monitoring for the Playcademy client.
|
|
2805
|
+
*
|
|
2806
|
+
* The ConnectionManager serves as an integration layer between the low-level
|
|
2807
|
+
* ConnectionMonitor and the PlaycademyClient. It handles:
|
|
2808
|
+
* - Event wiring and coordination
|
|
2809
|
+
* - Disconnect callbacks with context
|
|
2810
|
+
* - Platform-level alert integration
|
|
2811
|
+
* - Request success/failure tracking
|
|
2812
|
+
*
|
|
2813
|
+
* This class is used internally by PlaycademyClient and typically not
|
|
2814
|
+
* instantiated directly by game developers.
|
|
2815
|
+
*
|
|
2816
|
+
* @see {@link ConnectionMonitor} for the underlying monitoring implementation
|
|
2817
|
+
* @see {@link PlaycademyClient.onDisconnect} for the public API
|
|
2818
|
+
*/
|
|
2819
|
+
declare class ConnectionManager {
|
|
2820
|
+
private monitor?;
|
|
2821
|
+
private authContext?;
|
|
2822
|
+
private disconnectHandler?;
|
|
2823
|
+
private connectionChangeCallback?;
|
|
2824
|
+
private currentState;
|
|
2825
|
+
private additionalDisconnectHandlers;
|
|
2826
|
+
/**
|
|
2827
|
+
* Creates a new ConnectionManager instance.
|
|
2828
|
+
*
|
|
2829
|
+
* @param config - Configuration options for the manager
|
|
2830
|
+
*
|
|
2831
|
+
* @example
|
|
2832
|
+
* ```typescript
|
|
2833
|
+
* const manager = new ConnectionManager({
|
|
2834
|
+
* baseUrl: 'https://api.playcademy.com',
|
|
2835
|
+
* authContext: { isInIframe: false },
|
|
2836
|
+
* onDisconnect: (context) => {
|
|
2837
|
+
* console.log(`Disconnected: ${context.state}`)
|
|
2838
|
+
* },
|
|
2839
|
+
* onConnectionChange: (state, reason) => {
|
|
2840
|
+
* console.log(`Connection changed: ${state}`)
|
|
2841
|
+
* }
|
|
2842
|
+
* })
|
|
2843
|
+
* ```
|
|
2844
|
+
*/
|
|
2845
|
+
constructor(config: ConnectionManagerConfig);
|
|
2846
|
+
/**
|
|
2847
|
+
* Gets the current connection state.
|
|
2848
|
+
*
|
|
2849
|
+
* @returns The current connection state ('online', 'offline', or 'degraded')
|
|
2850
|
+
*
|
|
2851
|
+
* @example
|
|
2852
|
+
* ```typescript
|
|
2853
|
+
* const state = manager.getState()
|
|
2854
|
+
* if (state === 'offline') {
|
|
2855
|
+
* console.log('No connection')
|
|
2856
|
+
* }
|
|
2857
|
+
* ```
|
|
2858
|
+
*/
|
|
2859
|
+
getState(): ConnectionState;
|
|
2860
|
+
/**
|
|
2861
|
+
* Manually triggers a connection check immediately.
|
|
2862
|
+
*
|
|
2863
|
+
* Forces a heartbeat ping to verify the current connection status.
|
|
2864
|
+
* Useful when you need to check connectivity before a critical operation.
|
|
2865
|
+
*
|
|
2866
|
+
* In iframe mode, this returns the last known state from platform.
|
|
2867
|
+
*
|
|
2868
|
+
* @returns Promise resolving to the current connection state
|
|
2869
|
+
*
|
|
2870
|
+
* @example
|
|
2871
|
+
* ```typescript
|
|
2872
|
+
* const state = await manager.checkNow()
|
|
2873
|
+
* if (state === 'online') {
|
|
2874
|
+
* await performCriticalOperation()
|
|
2875
|
+
* }
|
|
2876
|
+
* ```
|
|
2877
|
+
*/
|
|
2878
|
+
checkNow(): Promise<ConnectionState>;
|
|
2879
|
+
/**
|
|
2880
|
+
* Reports a successful API request to the connection monitor.
|
|
2881
|
+
*
|
|
2882
|
+
* This resets the consecutive failure counter and transitions from
|
|
2883
|
+
* 'degraded' to 'online' state if applicable.
|
|
2884
|
+
*
|
|
2885
|
+
* Typically called automatically by the SDK's request wrapper.
|
|
2886
|
+
* No-op in iframe mode (platform handles monitoring).
|
|
2887
|
+
*/
|
|
2888
|
+
reportRequestSuccess(): void;
|
|
2889
|
+
/**
|
|
2890
|
+
* Reports a failed API request to the connection monitor.
|
|
2891
|
+
*
|
|
2892
|
+
* Only network errors are tracked (not 4xx/5xx HTTP responses).
|
|
2893
|
+
* After consecutive failures exceed the threshold, the state transitions
|
|
2894
|
+
* to 'degraded' or 'offline'.
|
|
2895
|
+
*
|
|
2896
|
+
* Typically called automatically by the SDK's request wrapper.
|
|
2897
|
+
* No-op in iframe mode (platform handles monitoring).
|
|
2898
|
+
*
|
|
2899
|
+
* @param error - The error from the failed request
|
|
2900
|
+
*/
|
|
2901
|
+
reportRequestFailure(error: unknown): void;
|
|
2902
|
+
/**
|
|
2903
|
+
* Registers a callback to be called when connection issues are detected.
|
|
2904
|
+
*
|
|
2905
|
+
* The callback only fires for 'offline' and 'degraded' states, not when
|
|
2906
|
+
* recovering to 'online'. This provides a clean API for games to handle
|
|
2907
|
+
* disconnect scenarios without being notified of every state change.
|
|
2908
|
+
*
|
|
2909
|
+
* Works in both iframe and standalone modes transparently.
|
|
2910
|
+
*
|
|
2911
|
+
* @param callback - Function to call when connection degrades
|
|
2912
|
+
* @returns Cleanup function to unregister the callback
|
|
2913
|
+
*
|
|
2914
|
+
* @example
|
|
2915
|
+
* ```typescript
|
|
2916
|
+
* const cleanup = manager.onDisconnect(({ state, reason, displayAlert }) => {
|
|
2917
|
+
* if (state === 'offline') {
|
|
2918
|
+
* displayAlert?.('Connection lost. Saving your progress...', { type: 'error' })
|
|
2919
|
+
* saveGameState()
|
|
2920
|
+
* }
|
|
2921
|
+
* })
|
|
2922
|
+
*
|
|
2923
|
+
* // Later: cleanup() to unregister
|
|
2924
|
+
* ```
|
|
2925
|
+
*/
|
|
2926
|
+
onDisconnect(callback: DisconnectHandler): () => void;
|
|
2927
|
+
/**
|
|
2928
|
+
* Stops connection monitoring and performs cleanup.
|
|
2929
|
+
*
|
|
2930
|
+
* Removes event listeners and clears heartbeat intervals.
|
|
2931
|
+
* Should be called when the client is being destroyed.
|
|
2932
|
+
*/
|
|
2933
|
+
stop(): void;
|
|
2934
|
+
/**
|
|
2935
|
+
* Sets up listener for platform connection state broadcasts (iframe mode only).
|
|
2936
|
+
*/
|
|
2937
|
+
private _setupPlatformListener;
|
|
2938
|
+
/**
|
|
2939
|
+
* Handles connection state changes from the monitor or platform.
|
|
2940
|
+
*
|
|
2941
|
+
* Coordinates between:
|
|
2942
|
+
* 1. Emitting events to the client (for client.on('connectionChange'))
|
|
2943
|
+
* 2. Calling the disconnect handler if configured
|
|
2944
|
+
* 3. Calling any additional handlers registered via onDisconnect()
|
|
2945
|
+
*
|
|
2946
|
+
* @param state - The new connection state
|
|
2947
|
+
* @param reason - Human-readable reason for the state change
|
|
2948
|
+
*/
|
|
2949
|
+
private _handleConnectionChange;
|
|
2950
|
+
}
|
|
2951
|
+
|
|
3036
2952
|
/**
|
|
3037
2953
|
* @fileoverview Playcademy Messaging System
|
|
3038
2954
|
*
|
|
@@ -3244,208 +3160,103 @@ declare function init<T extends PlaycademyClient = PlaycademyClient>(this: new (
|
|
|
3244
3160
|
*/
|
|
3245
3161
|
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
3246
3162
|
|
|
3247
|
-
/**
|
|
3248
|
-
|
|
3163
|
+
/**
|
|
3164
|
+
* @fileoverview Authentication Strategy Pattern
|
|
3165
|
+
*
|
|
3166
|
+
* Provides different authentication strategies for the Playcademy SDK.
|
|
3167
|
+
* Each strategy knows how to add its authentication headers to requests.
|
|
3168
|
+
*/
|
|
3249
3169
|
|
|
3250
3170
|
/**
|
|
3251
|
-
*
|
|
3252
|
-
* Provides namespaced access to all platform features including games, users, inventory, and more.
|
|
3171
|
+
* Base interface for authentication strategies
|
|
3253
3172
|
*/
|
|
3254
|
-
|
|
3173
|
+
interface AuthStrategy {
|
|
3174
|
+
/** Get the token value */
|
|
3175
|
+
getToken(): string | null;
|
|
3176
|
+
/** Get the token type */
|
|
3177
|
+
getType(): TokenType;
|
|
3178
|
+
/** Get authentication headers for a request */
|
|
3179
|
+
getHeaders(): Record<string, string>;
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
/**
|
|
3183
|
+
* Base Playcademy SDK client with shared infrastructure.
|
|
3184
|
+
* Provides authentication, HTTP requests, events, connection monitoring,
|
|
3185
|
+
* and fundamental namespaces used by all clients.
|
|
3186
|
+
*
|
|
3187
|
+
* Extended by PlaycademyClient (game SDK) and PlaycademyInternalClient (platform SDK).
|
|
3188
|
+
*/
|
|
3189
|
+
declare abstract class PlaycademyBaseClient {
|
|
3255
3190
|
baseUrl: string;
|
|
3256
3191
|
gameUrl?: string;
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3192
|
+
protected authStrategy: AuthStrategy;
|
|
3193
|
+
protected gameId?: string;
|
|
3194
|
+
protected config: Partial<ClientConfig>;
|
|
3195
|
+
protected listeners: EventListeners;
|
|
3196
|
+
protected internalClientSessionId?: string;
|
|
3197
|
+
protected authContext?: {
|
|
3198
|
+
isInIframe: boolean;
|
|
3199
|
+
};
|
|
3200
|
+
protected initPayload?: InitPayload;
|
|
3201
|
+
protected connectionManager?: ConnectionManager;
|
|
3265
3202
|
/**
|
|
3266
3203
|
* Internal session manager for automatic session lifecycle.
|
|
3267
|
-
*
|
|
3268
|
-
* This manager handles starting and ending game sessions automatically.
|
|
3269
|
-
* Game developers don't need to call these methods directly - they're managed
|
|
3270
|
-
* by the SDK during initialization and cleanup.
|
|
3271
|
-
*
|
|
3272
3204
|
* @private
|
|
3273
3205
|
* @internal
|
|
3274
3206
|
*/
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
* @param config.token - Authentication token
|
|
3282
|
-
* @param config.tokenType - Optional token type (auto-detected if not provided)
|
|
3283
|
-
* @param config.gameId - Game ID for automatic session management
|
|
3284
|
-
* @param config.autoStartSession - Automatically start a game session?
|
|
3285
|
-
*/
|
|
3207
|
+
protected _sessionManager: {
|
|
3208
|
+
startSession: (gameId: string) => Promise<{
|
|
3209
|
+
sessionId: string;
|
|
3210
|
+
}>;
|
|
3211
|
+
endSession: (sessionId: string, gameId: string) => Promise<void>;
|
|
3212
|
+
};
|
|
3286
3213
|
constructor(config?: Partial<ClientConfig>);
|
|
3287
3214
|
/**
|
|
3288
3215
|
* Gets the effective base URL for API requests.
|
|
3289
|
-
* Converts relative URLs to absolute URLs in browser environments.
|
|
3290
|
-
* Note: baseUrl already includes /api suffix from constructor.
|
|
3291
|
-
*
|
|
3292
|
-
* @returns The complete base URL for API requests (with /api suffix)
|
|
3293
3216
|
*/
|
|
3294
3217
|
getBaseUrl(): string;
|
|
3295
3218
|
/**
|
|
3296
3219
|
* Gets the effective game backend URL for integration requests.
|
|
3297
|
-
* Throws if gameUrl is not configured.
|
|
3298
|
-
*
|
|
3299
|
-
* @returns The complete game backend URL for API requests (with /api suffix)
|
|
3300
|
-
* @throws PlaycademyError if gameUrl is not set
|
|
3301
3220
|
*/
|
|
3302
|
-
|
|
3221
|
+
protected getGameBackendUrl(): string;
|
|
3303
3222
|
/**
|
|
3304
3223
|
* Simple ping method for testing connectivity.
|
|
3305
|
-
*
|
|
3306
|
-
* @returns 'pong' string response
|
|
3307
3224
|
*/
|
|
3308
3225
|
ping(): string;
|
|
3309
3226
|
/**
|
|
3310
3227
|
* Sets the authentication token for API requests.
|
|
3311
|
-
* Emits an 'authChange' event when the token changes.
|
|
3312
|
-
*
|
|
3313
|
-
* @param token - The authentication token, or null to clear
|
|
3314
|
-
* @param tokenType - Optional token type (auto-detected if not provided)
|
|
3315
3228
|
*/
|
|
3316
3229
|
setToken(token: string | null, tokenType?: TokenType): void;
|
|
3317
3230
|
/**
|
|
3318
3231
|
* Gets the current token type.
|
|
3319
|
-
*
|
|
3320
|
-
* @returns The token type
|
|
3321
3232
|
*/
|
|
3322
3233
|
getTokenType(): TokenType;
|
|
3323
3234
|
/**
|
|
3324
3235
|
* Gets the current authentication token.
|
|
3325
|
-
*
|
|
3326
|
-
* @returns The current token or null if not authenticated
|
|
3327
|
-
*
|
|
3328
|
-
* @example
|
|
3329
|
-
* ```typescript
|
|
3330
|
-
* // Send token to your backend for verification
|
|
3331
|
-
* const token = client.getToken()
|
|
3332
|
-
* const response = await fetch('/api/auth/playcademy', {
|
|
3333
|
-
* method: 'POST',
|
|
3334
|
-
* body: JSON.stringify({ gameToken: token })
|
|
3335
|
-
* })
|
|
3336
|
-
* ```
|
|
3337
3236
|
*/
|
|
3338
3237
|
getToken(): string | null;
|
|
3339
3238
|
/**
|
|
3340
|
-
* Checks if the client has a valid API token
|
|
3341
|
-
*
|
|
3342
|
-
* For games (iframe context): Checks if we have a valid token from the parent.
|
|
3343
|
-
* For Cademy (standalone): Checks if we have a token from better-auth.
|
|
3344
|
-
*
|
|
3345
|
-
* Note: This checks for API authentication, not whether a user has linked
|
|
3346
|
-
* their identity via OAuth.
|
|
3347
|
-
*
|
|
3348
|
-
* @returns true if API token exists, false otherwise
|
|
3349
|
-
*
|
|
3350
|
-
* @example
|
|
3351
|
-
* ```typescript
|
|
3352
|
-
* if (client.isAuthenticated()) {
|
|
3353
|
-
* // Can make API calls
|
|
3354
|
-
* const games = await client.games.list()
|
|
3355
|
-
* } else {
|
|
3356
|
-
* console.error('No API token available')
|
|
3357
|
-
* }
|
|
3358
|
-
* ```
|
|
3239
|
+
* Checks if the client has a valid API token.
|
|
3359
3240
|
*/
|
|
3360
3241
|
isAuthenticated(): boolean;
|
|
3361
3242
|
/**
|
|
3362
3243
|
* Registers a callback to be called when authentication state changes.
|
|
3363
|
-
*
|
|
3364
|
-
* @param callback - Function to call when auth state changes
|
|
3365
3244
|
*/
|
|
3366
3245
|
onAuthChange(callback: (token: string | null) => void): void;
|
|
3367
3246
|
/**
|
|
3368
3247
|
* Registers a callback to be called when connection issues are detected.
|
|
3369
|
-
*
|
|
3370
|
-
* This is a convenience method that filters connection change events to only
|
|
3371
|
-
* fire when the connection degrades (offline or degraded states). Use this
|
|
3372
|
-
* when you want to handle disconnects without being notified of recoveries.
|
|
3373
|
-
*
|
|
3374
|
-
* For all connection state changes, use `client.on('connectionChange', ...)` instead.
|
|
3375
|
-
*
|
|
3376
|
-
* @param callback - Function to call when connection state changes to offline or degraded
|
|
3377
|
-
* @returns Cleanup function to unregister the callback
|
|
3378
|
-
*
|
|
3379
|
-
* @example
|
|
3380
|
-
* ```typescript
|
|
3381
|
-
* const cleanup = client.onDisconnect(({ state, reason, displayAlert }) => {
|
|
3382
|
-
* console.log(`Connection ${state}: ${reason}`)
|
|
3383
|
-
*
|
|
3384
|
-
* if (state === 'offline') {
|
|
3385
|
-
* // Save state and return to game lobby
|
|
3386
|
-
* displayAlert?.('Connection lost. Your progress has been saved.', { type: 'error' })
|
|
3387
|
-
* saveGameState()
|
|
3388
|
-
* returnToLobby()
|
|
3389
|
-
* } else if (state === 'degraded') {
|
|
3390
|
-
* displayAlert?.('Slow connection detected.', { type: 'warning' })
|
|
3391
|
-
* }
|
|
3392
|
-
* })
|
|
3393
|
-
*
|
|
3394
|
-
* // Later: cleanup() to unregister
|
|
3395
|
-
* ```
|
|
3396
|
-
*
|
|
3397
|
-
* @see Connection monitoring documentation in SDK Browser docs for detailed usage examples
|
|
3398
|
-
* @see {@link ConnectionManager.onDisconnect} for the underlying implementation
|
|
3399
3248
|
*/
|
|
3400
3249
|
onDisconnect(callback: (context: DisconnectContext) => void | Promise<void>): () => void;
|
|
3401
3250
|
/**
|
|
3402
3251
|
* Gets the current connection state.
|
|
3403
|
-
*
|
|
3404
|
-
* Returns the last known connection state without triggering a new check.
|
|
3405
|
-
* Use `checkConnection()` to force an immediate verification.
|
|
3406
|
-
*
|
|
3407
|
-
* @returns Current connection state ('online', 'offline', 'degraded') or 'unknown' if monitoring is disabled
|
|
3408
|
-
*
|
|
3409
|
-
* @example
|
|
3410
|
-
* ```typescript
|
|
3411
|
-
* const state = client.getConnectionState()
|
|
3412
|
-
* if (state === 'offline') {
|
|
3413
|
-
* console.log('No connection available')
|
|
3414
|
-
* }
|
|
3415
|
-
* ```
|
|
3416
|
-
*
|
|
3417
|
-
* @see {@link checkConnection} to trigger an immediate connection check
|
|
3418
|
-
* @see {@link ConnectionManager.getState} for the underlying implementation
|
|
3419
3252
|
*/
|
|
3420
3253
|
getConnectionState(): ConnectionState | 'unknown';
|
|
3421
3254
|
/**
|
|
3422
3255
|
* Manually triggers a connection check immediately.
|
|
3423
|
-
*
|
|
3424
|
-
* Forces a heartbeat ping to verify connectivity right now, bypassing the normal
|
|
3425
|
-
* interval. Useful when you need to verify connection status before a critical
|
|
3426
|
-
* operation (e.g., saving important game state).
|
|
3427
|
-
*
|
|
3428
|
-
* @returns Promise resolving to the current connection state after verification
|
|
3429
|
-
*
|
|
3430
|
-
* @example
|
|
3431
|
-
* ```typescript
|
|
3432
|
-
* // Check before critical operation
|
|
3433
|
-
* const state = await client.checkConnection()
|
|
3434
|
-
* if (state !== 'online') {
|
|
3435
|
-
* alert('Please check your internet connection before saving')
|
|
3436
|
-
* return
|
|
3437
|
-
* }
|
|
3438
|
-
*
|
|
3439
|
-
* await client.games.saveState(importantData)
|
|
3440
|
-
* ```
|
|
3441
|
-
*
|
|
3442
|
-
* @see {@link getConnectionState} to get the last known state without checking
|
|
3443
|
-
* @see {@link ConnectionManager.checkNow} for the underlying implementation
|
|
3444
3256
|
*/
|
|
3445
3257
|
checkConnection(): Promise<ConnectionState | 'unknown'>;
|
|
3446
3258
|
/**
|
|
3447
3259
|
* Sets the authentication context for the client.
|
|
3448
|
-
* This is called during initialization to store environment info.
|
|
3449
3260
|
* @internal
|
|
3450
3261
|
*/
|
|
3451
3262
|
_setAuthContext(context: {
|
|
@@ -3453,28 +3264,14 @@ declare class PlaycademyClient {
|
|
|
3453
3264
|
}): void;
|
|
3454
3265
|
/**
|
|
3455
3266
|
* Registers an event listener for client events.
|
|
3456
|
-
*
|
|
3457
|
-
* @param event - The event type to listen for
|
|
3458
|
-
* @param callback - Function to call when the event is emitted
|
|
3459
3267
|
*/
|
|
3460
3268
|
on<E extends keyof ClientEvents>(event: E, callback: (payload: ClientEvents[E]) => void): void;
|
|
3461
3269
|
/**
|
|
3462
3270
|
* Emits an event to all registered listeners.
|
|
3463
|
-
*
|
|
3464
|
-
* @param event - The event type to emit
|
|
3465
|
-
* @param payload - The event payload
|
|
3466
3271
|
*/
|
|
3467
|
-
|
|
3272
|
+
protected emit<E extends keyof ClientEvents>(event: E, payload: ClientEvents[E]): void;
|
|
3468
3273
|
/**
|
|
3469
3274
|
* Makes an authenticated HTTP request to the platform API.
|
|
3470
|
-
*
|
|
3471
|
-
* @param path - API endpoint path
|
|
3472
|
-
* @param method - HTTP method
|
|
3473
|
-
* @param options - Optional request configuration
|
|
3474
|
-
* @param options.body - Request body
|
|
3475
|
-
* @param options.headers - Additional headers
|
|
3476
|
-
* @param options.raw - If true, returns raw Response instead of parsing
|
|
3477
|
-
* @returns Promise resolving to the response data or raw Response
|
|
3478
3275
|
*/
|
|
3479
3276
|
protected request<T>(path: string, method: Method, options?: {
|
|
3480
3277
|
body?: unknown;
|
|
@@ -3483,49 +3280,64 @@ declare class PlaycademyClient {
|
|
|
3483
3280
|
}): Promise<T>;
|
|
3484
3281
|
/**
|
|
3485
3282
|
* Makes an authenticated HTTP request to the game's backend Worker.
|
|
3486
|
-
* Uses gameUrl if set, otherwise falls back to platform API.
|
|
3487
|
-
*
|
|
3488
|
-
* @param path - API endpoint path
|
|
3489
|
-
* @param method - HTTP method
|
|
3490
|
-
* @param body - Request body (optional)
|
|
3491
|
-
* @param headers - Additional headers (optional)
|
|
3492
|
-
* @param raw - If true, returns raw Response instead of parsing (optional)
|
|
3493
|
-
* @returns Promise resolving to the response data or raw Response
|
|
3494
3283
|
*/
|
|
3495
3284
|
protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>, raw?: boolean): Promise<T>;
|
|
3496
3285
|
/**
|
|
3497
3286
|
* Ensures a gameId is available, throwing an error if not.
|
|
3498
|
-
*
|
|
3499
|
-
* @returns The gameId
|
|
3500
|
-
* @throws PlaycademyError if no gameId is configured
|
|
3501
3287
|
*/
|
|
3502
|
-
|
|
3288
|
+
protected _ensureGameId(): string;
|
|
3503
3289
|
/**
|
|
3504
3290
|
* Detects and sets the authentication context (iframe vs standalone).
|
|
3505
|
-
* Safe to call in any environment - isInIframe handles browser detection.
|
|
3506
3291
|
*/
|
|
3507
3292
|
private _detectAuthContext;
|
|
3508
3293
|
/**
|
|
3509
3294
|
* Initializes connection monitoring if enabled.
|
|
3510
|
-
* Safe to call in any environment - only runs in browser.
|
|
3511
3295
|
*/
|
|
3512
3296
|
private _initializeConnectionMonitor;
|
|
3513
3297
|
/**
|
|
3514
3298
|
* Initializes an internal game session for automatic session management.
|
|
3515
|
-
* Only starts a session if:
|
|
3516
|
-
* 1. A gameId is configured
|
|
3517
|
-
* 2. No session already exists
|
|
3518
|
-
* 3. autoStartSession is enabled (defaults to false)
|
|
3519
3299
|
*/
|
|
3520
3300
|
private _initializeInternalSession;
|
|
3521
|
-
/**
|
|
3301
|
+
/**
|
|
3302
|
+
* Current user data and inventory management.
|
|
3303
|
+
* - `me()` - Get authenticated user profile
|
|
3304
|
+
* - `inventory.get()` - List user's items
|
|
3305
|
+
* - `inventory.add(slug, qty)` - Award items to user
|
|
3306
|
+
*/
|
|
3307
|
+
users: {
|
|
3308
|
+
me: () => Promise<AuthenticatedUser>;
|
|
3309
|
+
inventory: {
|
|
3310
|
+
get: () => Promise<InventoryItemWithItem[]>;
|
|
3311
|
+
add: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
3312
|
+
remove: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
3313
|
+
quantity: (identifier: string) => Promise<number>;
|
|
3314
|
+
has: (identifier: string, minQuantity?: number) => Promise<boolean>;
|
|
3315
|
+
};
|
|
3316
|
+
};
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
/**
|
|
3320
|
+
* Playcademy SDK client for game developers.
|
|
3321
|
+
* Provides namespaced access to platform features for games running inside Cademy.
|
|
3322
|
+
*/
|
|
3323
|
+
declare class PlaycademyClient extends PlaycademyBaseClient {
|
|
3324
|
+
/**
|
|
3325
|
+
* Connect external identity providers to the user's Playcademy account.
|
|
3326
|
+
* - `connect(provider)` - Link Discord, Google, etc. via OAuth popup
|
|
3327
|
+
*/
|
|
3522
3328
|
identity: {
|
|
3523
3329
|
connect: (options: AuthOptions) => Promise<AuthResult>;
|
|
3524
3330
|
_getContext: () => {
|
|
3525
3331
|
isInIframe: boolean;
|
|
3526
3332
|
};
|
|
3527
3333
|
};
|
|
3528
|
-
/**
|
|
3334
|
+
/**
|
|
3335
|
+
* Game runtime lifecycle and asset loading.
|
|
3336
|
+
* - `exit()` - Return to Cademy hub
|
|
3337
|
+
* - `getGameToken()` - Get short-lived auth token
|
|
3338
|
+
* - `assets.url()`, `assets.json()`, `assets.fetch()` - Load game assets
|
|
3339
|
+
* - `on('pause')`, `on('resume')` - Handle visibility changes
|
|
3340
|
+
*/
|
|
3529
3341
|
runtime: {
|
|
3530
3342
|
getGameToken: (gameId: string, options?: {
|
|
3531
3343
|
apply?: boolean;
|
|
@@ -3560,64 +3372,58 @@ declare class PlaycademyClient {
|
|
|
3560
3372
|
arrayBuffer: (path: string) => Promise<ArrayBuffer>;
|
|
3561
3373
|
};
|
|
3562
3374
|
};
|
|
3563
|
-
/**
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3375
|
+
/**
|
|
3376
|
+
* TimeBack integration for activity tracking and user context.
|
|
3377
|
+
*
|
|
3378
|
+
* User context (cached from init, refreshable):
|
|
3379
|
+
* - `user.role` - User's role (student, parent, teacher, etc.)
|
|
3380
|
+
* - `user.enrollments` - Courses the player is enrolled in for this game
|
|
3381
|
+
* - `user.organizations` - Schools/districts the player belongs to
|
|
3382
|
+
* - `user.fetch()` - Refresh user context from server
|
|
3383
|
+
*
|
|
3384
|
+
* Activity tracking:
|
|
3385
|
+
* - `startActivity(metadata)` - Begin tracking an activity
|
|
3386
|
+
* - `pauseActivity()` / `resumeActivity()` - Pause/resume timer
|
|
3387
|
+
* - `endActivity(scoreData)` - Submit activity results to TimeBack
|
|
3388
|
+
*/
|
|
3575
3389
|
timeback: {
|
|
3390
|
+
readonly user: TimebackUser;
|
|
3576
3391
|
startActivity: (metadata: _playcademy_timeback_types.ActivityData) => void;
|
|
3577
3392
|
pauseActivity: () => void;
|
|
3578
3393
|
resumeActivity: () => void;
|
|
3579
3394
|
endActivity: (data: _playcademy_timeback_types.EndActivityScoreData) => Promise<EndActivityResponse>;
|
|
3580
|
-
management: {
|
|
3581
|
-
setup: (request: PlatformTimebackSetupRequest) => Promise<PlatformTimebackSetupResponse>;
|
|
3582
|
-
verify: (gameId: string) => Promise<TimebackVerifyAllResponse>;
|
|
3583
|
-
cleanup: (gameId: string) => Promise<void>;
|
|
3584
|
-
get: (gameId: string) => Promise<GameTimebackIntegration[]>;
|
|
3585
|
-
getConfig: (gameId: string) => Promise<TimebackSetupRequest["config"]>;
|
|
3586
|
-
};
|
|
3587
|
-
xp: {
|
|
3588
|
-
today: (options?: {
|
|
3589
|
-
date?: string;
|
|
3590
|
-
timezone?: string;
|
|
3591
|
-
}) => Promise<TodayXpResponse>;
|
|
3592
|
-
total: () => Promise<TotalXpResponse>;
|
|
3593
|
-
history: (options?: {
|
|
3594
|
-
startDate?: string;
|
|
3595
|
-
endDate?: string;
|
|
3596
|
-
}) => Promise<XpHistoryResponse>;
|
|
3597
|
-
summary: (options?: {
|
|
3598
|
-
date?: string;
|
|
3599
|
-
timezone?: string;
|
|
3600
|
-
}) => Promise<XpSummaryResponse$1>;
|
|
3601
|
-
};
|
|
3602
3395
|
};
|
|
3603
|
-
/**
|
|
3396
|
+
/**
|
|
3397
|
+
* Playcademy Credits (platform currency) management.
|
|
3398
|
+
* - `get()` - Get user's credit balance
|
|
3399
|
+
* - `add(amount)` - Award credits to user
|
|
3400
|
+
*/
|
|
3604
3401
|
credits: {
|
|
3605
3402
|
balance: () => Promise<number>;
|
|
3606
3403
|
add: (amount: number) => Promise<number>;
|
|
3607
3404
|
spend: (amount: number) => Promise<number>;
|
|
3608
3405
|
};
|
|
3609
|
-
/**
|
|
3406
|
+
/**
|
|
3407
|
+
* Game score submission and leaderboards.
|
|
3408
|
+
* - `submit(gameId, score, metadata?)` - Record a game score
|
|
3409
|
+
*/
|
|
3610
3410
|
scores: {
|
|
3611
3411
|
submit: (gameId: string, score: number, metadata?: Record<string, unknown>) => Promise<ScoreSubmission>;
|
|
3612
3412
|
};
|
|
3613
|
-
/**
|
|
3413
|
+
/**
|
|
3414
|
+
* Realtime multiplayer authentication.
|
|
3415
|
+
* - `getToken()` - Get token for WebSocket/realtime connections
|
|
3416
|
+
*/
|
|
3614
3417
|
realtime: {
|
|
3615
3418
|
token: {
|
|
3616
3419
|
get: () => Promise<RealtimeTokenResponse>;
|
|
3617
3420
|
};
|
|
3618
|
-
open(channel?: string, url?: string): Promise<_playcademy_realtime_server_types.RealtimeChannel>;
|
|
3619
3421
|
};
|
|
3620
|
-
/**
|
|
3422
|
+
/**
|
|
3423
|
+
* Make requests to your game's custom backend API routes.
|
|
3424
|
+
* - `get(path)`, `post(path, body)`, `put()`, `delete()` - HTTP methods
|
|
3425
|
+
* - Routes are relative to your game's deployment (e.g., '/hello' → your-game.playcademy.gg/api/hello)
|
|
3426
|
+
*/
|
|
3621
3427
|
backend: {
|
|
3622
3428
|
get<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
|
|
3623
3429
|
post<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
@@ -3638,9 +3444,70 @@ declare class PlaycademyClient {
|
|
|
3638
3444
|
};
|
|
3639
3445
|
}
|
|
3640
3446
|
|
|
3447
|
+
/**
|
|
3448
|
+
* Type definitions for the game timeback namespace.
|
|
3449
|
+
*
|
|
3450
|
+
* Re-exports core types from @playcademy/data for SDK consumers,
|
|
3451
|
+
* plus SDK-specific types like TimebackInitContext.
|
|
3452
|
+
*/
|
|
3453
|
+
|
|
3454
|
+
/**
|
|
3455
|
+
* A TimeBack enrollment for the current game session.
|
|
3456
|
+
* Alias for UserEnrollment without the optional gameId.
|
|
3457
|
+
*/
|
|
3458
|
+
type TimebackEnrollment = Omit<UserEnrollment, 'gameId'>;
|
|
3459
|
+
/**
|
|
3460
|
+
* A TimeBack organization (school/district) for the current user.
|
|
3461
|
+
* Alias for UserOrganization.
|
|
3462
|
+
*/
|
|
3463
|
+
type TimebackOrganization = UserOrganization;
|
|
3464
|
+
/**
|
|
3465
|
+
* TimeBack context passed during game initialization.
|
|
3466
|
+
* This is sent from the platform (cademy) to the game iframe via postMessage.
|
|
3467
|
+
*/
|
|
3468
|
+
interface TimebackInitContext {
|
|
3469
|
+
/** User's TimeBack ID */
|
|
3470
|
+
id: string;
|
|
3471
|
+
/** User's role in TimeBack (student, parent, teacher, etc.) */
|
|
3472
|
+
role: TimebackUserRole;
|
|
3473
|
+
/** User's enrollments for this game (one per grade/subject combo) */
|
|
3474
|
+
enrollments: TimebackEnrollment[];
|
|
3475
|
+
/** User's organizations (schools/districts) */
|
|
3476
|
+
organizations: TimebackOrganization[];
|
|
3477
|
+
}
|
|
3478
|
+
/**
|
|
3479
|
+
* TimeBack user context with current data (may be stale from init).
|
|
3480
|
+
* Use `fetch()` to get fresh data from the server.
|
|
3481
|
+
*/
|
|
3482
|
+
interface TimebackUserContext {
|
|
3483
|
+
/** User's TimeBack ID */
|
|
3484
|
+
id: string | undefined;
|
|
3485
|
+
/** User's role in TimeBack (student, parent, teacher, etc.) */
|
|
3486
|
+
role: TimebackUserRole | undefined;
|
|
3487
|
+
/** User's enrollments for this game */
|
|
3488
|
+
enrollments: TimebackEnrollment[];
|
|
3489
|
+
/** User's organizations (schools/districts) */
|
|
3490
|
+
organizations: TimebackOrganization[];
|
|
3491
|
+
}
|
|
3492
|
+
/**
|
|
3493
|
+
* TimeBack user object with both cached getters and fetch method.
|
|
3494
|
+
*/
|
|
3495
|
+
interface TimebackUser extends TimebackUserContext {
|
|
3496
|
+
/**
|
|
3497
|
+
* Fetch TimeBack data from the server (cached for 5 min).
|
|
3498
|
+
* Updates the cached values so subsequent property access returns fresh data.
|
|
3499
|
+
* @param options - Cache options (pass { force: true } to bypass cache)
|
|
3500
|
+
* @returns Promise resolving to fresh user context
|
|
3501
|
+
*/
|
|
3502
|
+
fetch(options?: {
|
|
3503
|
+
force?: boolean;
|
|
3504
|
+
}): Promise<TimebackUserContext>;
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3641
3507
|
/**
|
|
3642
3508
|
* Core client configuration and lifecycle types
|
|
3643
3509
|
*/
|
|
3510
|
+
|
|
3644
3511
|
type TokenType = 'session' | 'apiKey' | 'gameJwt';
|
|
3645
3512
|
interface ClientConfig {
|
|
3646
3513
|
baseUrl: string;
|
|
@@ -3684,6 +3551,8 @@ interface InitPayload {
|
|
|
3684
3551
|
gameId: string;
|
|
3685
3552
|
/** Realtime WebSocket URL */
|
|
3686
3553
|
realtimeUrl?: string;
|
|
3554
|
+
/** Timeback context (if user has a Timeback account) */
|
|
3555
|
+
timeback?: TimebackInitContext;
|
|
3687
3556
|
}
|
|
3688
3557
|
/**
|
|
3689
3558
|
* Simplified user data passed to games via InitPayload
|
|
@@ -3868,19 +3737,6 @@ interface ScoreSubmission {
|
|
|
3868
3737
|
achievedAt: Date;
|
|
3869
3738
|
}
|
|
3870
3739
|
|
|
3871
|
-
/**
|
|
3872
|
-
* TimeBack namespace types
|
|
3873
|
-
*/
|
|
3874
|
-
|
|
3875
|
-
/**
|
|
3876
|
-
* Combined response type for summary method
|
|
3877
|
-
*/
|
|
3878
|
-
type XpSummaryResponse = {
|
|
3879
|
-
today: TodayXpResponse;
|
|
3880
|
-
total: TotalXpResponse;
|
|
3881
|
-
history: XpHistoryResponse;
|
|
3882
|
-
};
|
|
3883
|
-
|
|
3884
3740
|
/**
|
|
3885
3741
|
* Users namespace types
|
|
3886
3742
|
*/
|
|
@@ -4040,6 +3896,49 @@ type DevUploadHooks = {
|
|
|
4040
3896
|
onClose?: () => void;
|
|
4041
3897
|
};
|
|
4042
3898
|
|
|
3899
|
+
/**
|
|
3900
|
+
* Platform TimeBack Types
|
|
3901
|
+
*
|
|
3902
|
+
* Types for TimeBack data on the platform side.
|
|
3903
|
+
* Unlike game types, these include gameId for cross-game enrollment views.
|
|
3904
|
+
*/
|
|
3905
|
+
|
|
3906
|
+
/**
|
|
3907
|
+
* Platform TimeBack user context.
|
|
3908
|
+
* Unlike game context, enrollments include gameId for cross-game views.
|
|
3909
|
+
*/
|
|
3910
|
+
interface PlatformTimebackUserContext {
|
|
3911
|
+
/** User's TimeBack ID */
|
|
3912
|
+
id: string | undefined;
|
|
3913
|
+
/** User's role in TimeBack (student, parent, teacher, etc.) */
|
|
3914
|
+
role: TimebackUserRole | undefined;
|
|
3915
|
+
/** User's enrollments across ALL games (includes gameId) */
|
|
3916
|
+
enrollments: UserEnrollment[];
|
|
3917
|
+
/** User's organizations (schools/districts) */
|
|
3918
|
+
organizations: UserOrganization[];
|
|
3919
|
+
}
|
|
3920
|
+
/**
|
|
3921
|
+
* Platform TimeBack user object with both cached getters and fetch method.
|
|
3922
|
+
*/
|
|
3923
|
+
interface PlatformTimebackUser extends PlatformTimebackUserContext {
|
|
3924
|
+
/**
|
|
3925
|
+
* Fetch TimeBack data from the server (cached for 5 min).
|
|
3926
|
+
* Updates the cached values so subsequent property access returns fresh data.
|
|
3927
|
+
* @param options - Cache options (pass { force: true } to bypass cache)
|
|
3928
|
+
* @returns Promise resolving to user context with full enrollment data
|
|
3929
|
+
*/
|
|
3930
|
+
fetch(options?: {
|
|
3931
|
+
force?: boolean;
|
|
3932
|
+
}): Promise<PlatformTimebackUserContext>;
|
|
3933
|
+
}
|
|
3934
|
+
/**
|
|
3935
|
+
* Combined response type for xp.summary() method
|
|
3936
|
+
*/
|
|
3937
|
+
interface XpSummaryResponse {
|
|
3938
|
+
today: TodayXpResponse;
|
|
3939
|
+
total: TotalXpResponse;
|
|
3940
|
+
}
|
|
3941
|
+
|
|
4043
3942
|
/**
|
|
4044
3943
|
* @fileoverview Server SDK Type Definitions
|
|
4045
3944
|
*
|
|
@@ -4219,4 +4118,4 @@ interface PlaycademyServerClientState {
|
|
|
4219
4118
|
}
|
|
4220
4119
|
|
|
4221
4120
|
export { PlaycademyClient };
|
|
4222
|
-
export type { Achievement, AchievementCurrent, AchievementProgressResponse, AuthCallbackPayload, AuthOptions, AuthProviderType, AuthResult, AuthServerMessage, AuthStateChangePayload, AuthStateUpdate, AuthenticatedUser, BetterAuthApiKey, BetterAuthApiKeyResponse, BetterAuthSignInResponse, BucketFile, CharacterComponent, CharacterComponentWithSpriteUrl, CharacterComponentsOptions, ClientConfig, ClientEvents, ConnectionStatePayload, CreateCharacterData, Currency, DevUploadEvent, DevUploadHooks, DeveloperStatusResponse, DisconnectContext, DisconnectHandler, DisplayAlertPayload, EventListeners, ExternalGame, FetchedGame, Game, GameContextPayload, GameLeaderboardEntry, GameSession, GameStateData, GameTokenResponse, GameUser, HostedGame, InitPayload, InventoryItem, InventoryItemWithItem, InventoryMutationResponse, Item, KeyEventPayload, LeaderboardEntry, LevelConfig, LoginResponse, ManifestV1, Map, MapElement, MapElementWithGame, MapObject, MapObjectWithItem, PlaycademyServerClientConfig, PlaycademyServerClientState, PlayerCharacter, RealtimeTokenResponse, ScoreSubmission, ShopCurrency, ShopDisplayItem, ShopViewResponse, SpriteTemplate, SpriteTemplateData, StartSessionResponse, TelemetryPayload, TodayXpResponse, TokenRefreshPayload, TokenType, TotalXpResponse, UpdateCharacterData, User, UserInfo, UserLevel, UserLevelWithConfig, UserRank, UserRankResponse, UserRoleEnumType, UserScore, XpHistoryResponse, XpSummaryResponse };
|
|
4121
|
+
export type { Achievement, AchievementCurrent, AchievementProgressResponse, AuthCallbackPayload, AuthOptions, AuthProviderType, AuthResult, AuthServerMessage, AuthStateChangePayload, AuthStateUpdate, AuthenticatedUser, BetterAuthApiKey, BetterAuthApiKeyResponse, BetterAuthSignInResponse, BucketFile, CharacterComponent, CharacterComponentWithSpriteUrl, CharacterComponentsOptions, ClientConfig, ClientEvents, ConnectionStatePayload, CreateCharacterData, Currency, DevUploadEvent, DevUploadHooks, DeveloperStatusResponse, DisconnectContext, DisconnectHandler, DisplayAlertPayload, EventListeners, ExternalGame, FetchedGame, Game, GameContextPayload, GameLeaderboardEntry, GameSession, GameStateData, GameTokenResponse, GameUser, HostedGame, InitPayload, InventoryItem, InventoryItemWithItem, InventoryMutationResponse, Item, KeyEventPayload, LeaderboardEntry, LevelConfig, LoginResponse, ManifestV1, Map, MapElement, MapElementWithGame, MapObject, MapObjectWithItem, PlatformTimebackUser, PlatformTimebackUserContext, PlaycademyServerClientConfig, PlaycademyServerClientState, PlayerCharacter, RealtimeTokenResponse, ScoreSubmission, ShopCurrency, ShopDisplayItem, ShopViewResponse, SpriteTemplate, SpriteTemplateData, StartSessionResponse, TelemetryPayload, TimebackEnrollment, TimebackInitContext, TimebackOrganization, TimebackUser, TimebackUserContext, TimebackUserRole, TodayXpResponse, TokenRefreshPayload, TokenType, TotalXpResponse, UpdateCharacterData, User, UserEnrollment, UserInfo, UserLevel, UserLevelWithConfig, UserOrganization, UserRank, UserRankResponse, UserRoleEnumType, UserScore, UserTimebackData, XpHistoryResponse, XpSummaryResponse };
|