@playcademy/sdk 0.0.6 → 0.0.8
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 +64 -49
- package/dist/index.js +57 -38
- package/dist/server.d.ts +53 -0
- package/dist/server.js +50 -0
- package/dist/types.d.ts +50 -36
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,24 +3,6 @@ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
|
3
3
|
import * as drizzle_zod from 'drizzle-zod';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* SDK Constants
|
|
8
|
-
* These are re-exported from @playcademy/data but defined here
|
|
9
|
-
* to avoid bundling issues with API Extractor
|
|
10
|
-
*/
|
|
11
|
-
declare const CURRENCIES: {
|
|
12
|
-
readonly PRIMARY: "PLAYCADEMY_CREDITS";
|
|
13
|
-
readonly XP: "PLAYCADEMY_XP";
|
|
14
|
-
};
|
|
15
|
-
declare const BADGES: {
|
|
16
|
-
readonly FOUNDING_MEMBER: "FOUNDING_MEMBER_BADGE";
|
|
17
|
-
readonly EARLY_ADOPTER: "EARLY_ADOPTER_BADGE";
|
|
18
|
-
readonly FIRST_GAME: "FIRST_GAME_BADGE";
|
|
19
|
-
};
|
|
20
|
-
declare const AuthProvider: {
|
|
21
|
-
readonly TIMEBACK: "TIMEBACK";
|
|
22
|
-
};
|
|
23
|
-
|
|
24
6
|
declare const users: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
25
7
|
name: "user";
|
|
26
8
|
schema: undefined;
|
|
@@ -2343,6 +2325,25 @@ type AuthenticatedUser = User & {
|
|
|
2343
2325
|
* Types that combine data from multiple domains
|
|
2344
2326
|
*/
|
|
2345
2327
|
type ManifestV1 = z.infer<typeof ManifestV1Schema>;
|
|
2328
|
+
/**
|
|
2329
|
+
* Basic user information in the shape of the claims from identity providers
|
|
2330
|
+
*/
|
|
2331
|
+
interface UserInfo {
|
|
2332
|
+
/** Unique user identifier (sub claim from JWT) */
|
|
2333
|
+
sub: string;
|
|
2334
|
+
/** User's email address */
|
|
2335
|
+
email: string;
|
|
2336
|
+
/** User's display name */
|
|
2337
|
+
name: string;
|
|
2338
|
+
/** Whether the email has been verified */
|
|
2339
|
+
email_verified: boolean;
|
|
2340
|
+
/** Optional given name (first name) */
|
|
2341
|
+
given_name?: string;
|
|
2342
|
+
/** Optional family name (last name) */
|
|
2343
|
+
family_name?: string;
|
|
2344
|
+
/** Additional user attributes from the identity provider */
|
|
2345
|
+
[key: string]: unknown;
|
|
2346
|
+
}
|
|
2346
2347
|
/**
|
|
2347
2348
|
* Character-related Composite Types
|
|
2348
2349
|
* Types that combine character component data with sprite sheet information
|
|
@@ -2583,6 +2584,24 @@ interface AchievementProgressResponse {
|
|
|
2583
2584
|
createdAt: string;
|
|
2584
2585
|
}
|
|
2585
2586
|
|
|
2587
|
+
/**
|
|
2588
|
+
* SDK Constants
|
|
2589
|
+
* These are re-exported from @playcademy/data but defined here
|
|
2590
|
+
* to avoid bundling issues with API Extractor
|
|
2591
|
+
*/
|
|
2592
|
+
declare const CURRENCIES: {
|
|
2593
|
+
readonly PRIMARY: "PLAYCADEMY_CREDITS";
|
|
2594
|
+
readonly XP: "PLAYCADEMY_XP";
|
|
2595
|
+
};
|
|
2596
|
+
declare const BADGES: {
|
|
2597
|
+
readonly FOUNDING_MEMBER: "FOUNDING_MEMBER_BADGE";
|
|
2598
|
+
readonly EARLY_ADOPTER: "EARLY_ADOPTER_BADGE";
|
|
2599
|
+
readonly FIRST_GAME: "FIRST_GAME_BADGE";
|
|
2600
|
+
};
|
|
2601
|
+
declare const AuthProvider: {
|
|
2602
|
+
readonly TIMEBACK: "TIMEBACK";
|
|
2603
|
+
};
|
|
2604
|
+
|
|
2586
2605
|
interface ClientConfig {
|
|
2587
2606
|
baseUrl: string;
|
|
2588
2607
|
token?: string;
|
|
@@ -2629,26 +2648,6 @@ interface AuthResult {
|
|
|
2629
2648
|
/** Error if authentication failed */
|
|
2630
2649
|
error?: Error;
|
|
2631
2650
|
}
|
|
2632
|
-
/**
|
|
2633
|
-
* Standard OAuth/OIDC user claims returned from identity providers
|
|
2634
|
-
* This is what external identity providers (like Timeback) return
|
|
2635
|
-
*/
|
|
2636
|
-
interface UserInfo {
|
|
2637
|
-
/** Unique user identifier (sub claim from JWT) */
|
|
2638
|
-
sub: string;
|
|
2639
|
-
/** User's email address */
|
|
2640
|
-
email: string;
|
|
2641
|
-
/** User's display name */
|
|
2642
|
-
name: string;
|
|
2643
|
-
/** Whether the email has been verified */
|
|
2644
|
-
email_verified: boolean;
|
|
2645
|
-
/** Optional given name (first name) */
|
|
2646
|
-
given_name?: string;
|
|
2647
|
-
/** Optional family name (last name) */
|
|
2648
|
-
family_name?: string;
|
|
2649
|
-
/** Additional user attributes from the identity provider */
|
|
2650
|
-
[key: string]: unknown;
|
|
2651
|
-
}
|
|
2652
2651
|
/**
|
|
2653
2652
|
* Authentication state change event payload.
|
|
2654
2653
|
* Used when authentication state changes in the application.
|
|
@@ -2874,16 +2873,24 @@ interface UserScore {
|
|
|
2874
2873
|
* - Sets up event listeners for token refresh
|
|
2875
2874
|
* - Exposes the client for debugging in development mode
|
|
2876
2875
|
*
|
|
2876
|
+
* @param options - Optional configuration overrides
|
|
2877
|
+
* @param options.baseUrl - Override the base URL for API requests
|
|
2877
2878
|
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
2878
2879
|
* @throws Error if not running in a browser context
|
|
2879
2880
|
*
|
|
2880
2881
|
* @example
|
|
2881
2882
|
* ```typescript
|
|
2883
|
+
* // Default initialization
|
|
2882
2884
|
* const client = await PlaycademyClient.init()
|
|
2883
|
-
*
|
|
2885
|
+
*
|
|
2886
|
+
* // With custom base URL
|
|
2887
|
+
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
2884
2888
|
* ```
|
|
2885
2889
|
*/
|
|
2886
|
-
declare function init(
|
|
2890
|
+
declare function init(options?: {
|
|
2891
|
+
baseUrl?: string;
|
|
2892
|
+
allowedParentOrigins?: string[];
|
|
2893
|
+
}): Promise<PlaycademyClient>;
|
|
2887
2894
|
|
|
2888
2895
|
/**
|
|
2889
2896
|
* Authenticates a user with email and password.
|
|
@@ -2965,6 +2972,22 @@ declare class PlaycademyClient {
|
|
|
2965
2972
|
* @param token - The authentication token, or null to clear
|
|
2966
2973
|
*/
|
|
2967
2974
|
setToken(token: string | null): void;
|
|
2975
|
+
/**
|
|
2976
|
+
* Gets the current authentication token.
|
|
2977
|
+
*
|
|
2978
|
+
* @returns The current token or null if not authenticated
|
|
2979
|
+
*
|
|
2980
|
+
* @example
|
|
2981
|
+
* ```typescript
|
|
2982
|
+
* // Send token to your backend for verification
|
|
2983
|
+
* const token = client.getToken()
|
|
2984
|
+
* const response = await fetch('/api/auth/playcademy', {
|
|
2985
|
+
* method: 'POST',
|
|
2986
|
+
* body: JSON.stringify({ gameToken: token })
|
|
2987
|
+
* })
|
|
2988
|
+
* ```
|
|
2989
|
+
*/
|
|
2990
|
+
getToken(): string | null;
|
|
2968
2991
|
/**
|
|
2969
2992
|
* Checks if the client has a valid API token for making Playcademy API requests.
|
|
2970
2993
|
*
|
|
@@ -3059,14 +3082,6 @@ declare class PlaycademyClient {
|
|
|
3059
3082
|
};
|
|
3060
3083
|
/** Identity provider connection methods (connect external accounts) */
|
|
3061
3084
|
identity: {
|
|
3062
|
-
readonly user: {
|
|
3063
|
-
sub: string;
|
|
3064
|
-
email: string;
|
|
3065
|
-
name: string;
|
|
3066
|
-
email_verified: true;
|
|
3067
|
-
given_name: undefined;
|
|
3068
|
-
family_name: undefined;
|
|
3069
|
-
} | null;
|
|
3070
3085
|
connect: (options: AuthOptions) => Promise<AuthResult>;
|
|
3071
3086
|
_getContext: () => {
|
|
3072
3087
|
isInIframe: boolean;
|
|
@@ -3114,7 +3129,7 @@ declare class PlaycademyClient {
|
|
|
3114
3129
|
};
|
|
3115
3130
|
leaderboard: {
|
|
3116
3131
|
get: (gameId: string, options?: {
|
|
3117
|
-
limit
|
|
3132
|
+
limit? /** Runtime methods (getGameToken, exit) */: number;
|
|
3118
3133
|
offset?: number;
|
|
3119
3134
|
}) => Promise<LeaderboardEntry[]>;
|
|
3120
3135
|
};
|
package/dist/index.js
CHANGED
|
@@ -398,18 +398,13 @@ async function login(client, options) {
|
|
|
398
398
|
try {
|
|
399
399
|
let stateData = options.stateData;
|
|
400
400
|
if (!stateData) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
try {
|
|
406
|
-
const currentUser2 = await client.users.me();
|
|
407
|
-
if (currentUser2?.id) {
|
|
408
|
-
stateData = { playcademy_user_id: currentUser2.id };
|
|
409
|
-
}
|
|
410
|
-
} catch {
|
|
411
|
-
log.debug("[Playcademy SDK] No current user available for state data");
|
|
401
|
+
try {
|
|
402
|
+
const currentUser = await client.users.me();
|
|
403
|
+
if (currentUser?.id) {
|
|
404
|
+
stateData = { playcademy_user_id: currentUser.id };
|
|
412
405
|
}
|
|
406
|
+
} catch {
|
|
407
|
+
log.debug("[Playcademy SDK] No current user available for state data");
|
|
413
408
|
}
|
|
414
409
|
}
|
|
415
410
|
log.debug("[Playcademy SDK] Starting OAuth login", {
|
|
@@ -446,20 +441,6 @@ var init_login = __esm(() => {
|
|
|
446
441
|
// src/core/namespaces/identity.ts
|
|
447
442
|
function createIdentityNamespace(client) {
|
|
448
443
|
return {
|
|
449
|
-
get user() {
|
|
450
|
-
const gameUser = client["initPayload"]?.user;
|
|
451
|
-
if (!gameUser)
|
|
452
|
-
return null;
|
|
453
|
-
const name = gameUser.name || gameUser.username || "";
|
|
454
|
-
return {
|
|
455
|
-
sub: gameUser.id,
|
|
456
|
-
email: gameUser.email || "",
|
|
457
|
-
name,
|
|
458
|
-
email_verified: true,
|
|
459
|
-
given_name: undefined,
|
|
460
|
-
family_name: undefined
|
|
461
|
-
};
|
|
462
|
-
},
|
|
463
444
|
connect: (options) => login(client, options),
|
|
464
445
|
_getContext: () => ({
|
|
465
446
|
isInIframe: client["authContext"]?.isInIframe ?? false
|
|
@@ -2594,29 +2575,61 @@ var init_namespaces = __esm(() => {
|
|
|
2594
2575
|
});
|
|
2595
2576
|
|
|
2596
2577
|
// src/core/static/init.ts
|
|
2597
|
-
async function getPlaycademyConfig() {
|
|
2578
|
+
async function getPlaycademyConfig(allowedParentOrigins) {
|
|
2598
2579
|
const preloaded = window.PLAYCADEMY;
|
|
2599
2580
|
if (preloaded?.token) {
|
|
2600
2581
|
return preloaded;
|
|
2601
2582
|
}
|
|
2602
2583
|
if (window.self !== window.top) {
|
|
2603
|
-
return await waitForPlaycademyInit();
|
|
2584
|
+
return await waitForPlaycademyInit(allowedParentOrigins);
|
|
2604
2585
|
} else {
|
|
2605
2586
|
return createStandaloneConfig();
|
|
2606
2587
|
}
|
|
2607
2588
|
}
|
|
2608
|
-
|
|
2589
|
+
function getReferrerOrigin() {
|
|
2590
|
+
try {
|
|
2591
|
+
return document.referrer ? new URL(document.referrer).origin : null;
|
|
2592
|
+
} catch {
|
|
2593
|
+
return null;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function buildAllowedOrigins(explicit) {
|
|
2597
|
+
if (Array.isArray(explicit) && explicit.length > 0)
|
|
2598
|
+
return explicit;
|
|
2599
|
+
const ref = getReferrerOrigin();
|
|
2600
|
+
return ref ? [ref] : [];
|
|
2601
|
+
}
|
|
2602
|
+
function isOriginAllowed(origin, allowlist) {
|
|
2603
|
+
if (!allowlist || allowlist.length === 0) {
|
|
2604
|
+
console.error("[Playcademy SDK] No allowed origins configured. Consider passing allowedParentOrigins explicitly to init().");
|
|
2605
|
+
return false;
|
|
2606
|
+
}
|
|
2607
|
+
return allowlist.includes(origin);
|
|
2608
|
+
}
|
|
2609
|
+
async function waitForPlaycademyInit(allowedParentOrigins) {
|
|
2609
2610
|
return new Promise((resolve, reject) => {
|
|
2610
2611
|
let contextReceived = false;
|
|
2611
2612
|
const timeoutDuration = 5000;
|
|
2613
|
+
const allowlist = buildAllowedOrigins(allowedParentOrigins);
|
|
2614
|
+
let hasWarnedAboutUntrustedOrigin = false;
|
|
2615
|
+
function warnAboutUntrustedOrigin(origin) {
|
|
2616
|
+
if (hasWarnedAboutUntrustedOrigin)
|
|
2617
|
+
return;
|
|
2618
|
+
hasWarnedAboutUntrustedOrigin = true;
|
|
2619
|
+
console.warn("[Playcademy SDK] Ignoring INIT from untrusted origin:", origin);
|
|
2620
|
+
}
|
|
2612
2621
|
const handleMessage = (event) => {
|
|
2613
|
-
if (event.data?.type
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
resolve(event.data.payload);
|
|
2622
|
+
if (event.data?.type !== "PLAYCADEMY_INIT" /* INIT */)
|
|
2623
|
+
return;
|
|
2624
|
+
if (!isOriginAllowed(event.origin, allowlist)) {
|
|
2625
|
+
warnAboutUntrustedOrigin(event.origin);
|
|
2626
|
+
return;
|
|
2619
2627
|
}
|
|
2628
|
+
contextReceived = true;
|
|
2629
|
+
window.removeEventListener("message", handleMessage);
|
|
2630
|
+
clearTimeout(timeoutId);
|
|
2631
|
+
window.PLAYCADEMY = event.data.payload;
|
|
2632
|
+
resolve(event.data.payload);
|
|
2620
2633
|
};
|
|
2621
2634
|
window.addEventListener("message", handleMessage);
|
|
2622
2635
|
const timeoutId = setTimeout(() => {
|
|
@@ -2628,22 +2641,25 @@ async function waitForPlaycademyInit() {
|
|
|
2628
2641
|
});
|
|
2629
2642
|
}
|
|
2630
2643
|
function createStandaloneConfig() {
|
|
2644
|
+
console.warn("[Playcademy SDK] Standalone mode detected, creating mock context for local development");
|
|
2631
2645
|
const mockConfig = {
|
|
2632
2646
|
baseUrl: "/api",
|
|
2633
2647
|
token: "mock-game-token-for-local-dev",
|
|
2634
2648
|
gameId: "mock-game-id-from-template",
|
|
2635
|
-
realtimeUrl: undefined
|
|
2636
|
-
user: undefined
|
|
2649
|
+
realtimeUrl: undefined
|
|
2637
2650
|
};
|
|
2638
2651
|
window.PLAYCADEMY = mockConfig;
|
|
2639
2652
|
return mockConfig;
|
|
2640
2653
|
}
|
|
2641
|
-
async function init() {
|
|
2654
|
+
async function init(options) {
|
|
2642
2655
|
const { PlaycademyClient } = await Promise.resolve().then(() => (init_client(), exports_client));
|
|
2643
2656
|
if (typeof window === "undefined") {
|
|
2644
2657
|
throw new Error("Playcademy SDK must run in a browser context");
|
|
2645
2658
|
}
|
|
2646
|
-
const config = await getPlaycademyConfig();
|
|
2659
|
+
const config = await getPlaycademyConfig(options?.allowedParentOrigins);
|
|
2660
|
+
if (options?.baseUrl) {
|
|
2661
|
+
config.baseUrl = options.baseUrl;
|
|
2662
|
+
}
|
|
2647
2663
|
const client = new PlaycademyClient({
|
|
2648
2664
|
baseUrl: config.baseUrl,
|
|
2649
2665
|
token: config.token,
|
|
@@ -2756,6 +2772,9 @@ var init_client = __esm(() => {
|
|
|
2756
2772
|
this.token = token ?? undefined;
|
|
2757
2773
|
this.emit("authChange", { token: this.token ?? null });
|
|
2758
2774
|
}
|
|
2775
|
+
getToken() {
|
|
2776
|
+
return this.token ?? null;
|
|
2777
|
+
}
|
|
2759
2778
|
isAuthenticated() {
|
|
2760
2779
|
return !!this.token;
|
|
2761
2780
|
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic user information in the shape of the claims from identity providers
|
|
3
|
+
*/
|
|
4
|
+
interface UserInfo {
|
|
5
|
+
/** Unique user identifier (sub claim from JWT) */
|
|
6
|
+
sub: string;
|
|
7
|
+
/** User's email address */
|
|
8
|
+
email: string;
|
|
9
|
+
/** User's display name */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Whether the email has been verified */
|
|
12
|
+
email_verified: boolean;
|
|
13
|
+
/** Optional given name (first name) */
|
|
14
|
+
given_name?: string;
|
|
15
|
+
/** Optional family name (last name) */
|
|
16
|
+
family_name?: string;
|
|
17
|
+
/** Additional user attributes from the identity provider */
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Server-only utilities for Playcademy.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: This module is intended for backend/server runtimes. It should not be
|
|
25
|
+
* bundled into browser code. The API intentionally avoids requiring a
|
|
26
|
+
* PlaycademyClient instance, offering stateless helpers for auth flows.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Verifies a short-lived Playcademy Game Token and returns verified identity claims.
|
|
31
|
+
*
|
|
32
|
+
* This calls the Playcademy API to cryptographically verify the token and
|
|
33
|
+
* returns the verified user information and claims.
|
|
34
|
+
*
|
|
35
|
+
* @param gameToken - The game JWT token to verify
|
|
36
|
+
* @param options - Optional configuration (reserved for future use)
|
|
37
|
+
* @returns Promise containing verified claims, gameId, and user information
|
|
38
|
+
* @throws Error if token is invalid or verification fails
|
|
39
|
+
*/
|
|
40
|
+
declare function verifyGameToken(gameToken: string, options?: {
|
|
41
|
+
baseUrl?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
claims: Record<string, unknown>;
|
|
44
|
+
gameId: string;
|
|
45
|
+
user: UserInfo;
|
|
46
|
+
}>;
|
|
47
|
+
declare const PlaycademyServer: {
|
|
48
|
+
auth: {
|
|
49
|
+
verifyGameToken: typeof verifyGameToken;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { PlaycademyServer, verifyGameToken };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
12
|
+
|
|
13
|
+
// src/server.ts
|
|
14
|
+
async function verifyGameToken(gameToken, options) {
|
|
15
|
+
if (!gameToken || typeof gameToken !== "string") {
|
|
16
|
+
throw new Error("[Playcademy SDK] gameToken must be a non-empty string");
|
|
17
|
+
}
|
|
18
|
+
const baseUrl = options?.baseUrl || process.env.PLAYCADEMY_BASE_URL || process.env.PUBLIC_PLAYCADEMY_BASE_URL || process.env.NEXT_PUBLIC_PLAYCADEMY_BASE_URL;
|
|
19
|
+
if (!baseUrl) {
|
|
20
|
+
throw new Error(`[Playcademy SDK] PLAYCADEMY_BASE_URL is not set
|
|
21
|
+
Please set the PLAYCADEMY_BASE_URL environment variable`);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(`${baseUrl}/api/games/verify`, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
"Content-Type": "application/json"
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({ token: gameToken })
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
33
|
+
throw new Error(`[Playcademy SDK] Token verification failed: ${response.status} ${errorText}`);
|
|
34
|
+
}
|
|
35
|
+
const result = await response.json();
|
|
36
|
+
return result;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof Error) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("[Playcademy SDK] Token verification failed: Network error");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var PlaycademyServer = {
|
|
45
|
+
auth: { verifyGameToken }
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
verifyGameToken,
|
|
49
|
+
PlaycademyServer
|
|
50
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -3,10 +3,6 @@ import * as drizzle_zod from 'drizzle-zod';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as _playcademy_realtime_server_types from '@playcademy/realtime/server/types';
|
|
5
5
|
|
|
6
|
-
declare const AuthProvider: {
|
|
7
|
-
readonly TIMEBACK: "TIMEBACK";
|
|
8
|
-
};
|
|
9
|
-
|
|
10
6
|
declare const userRoleEnum: drizzle_orm_pg_core.PgEnum<["admin", "player", "developer"]>;
|
|
11
7
|
declare const users: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
12
8
|
name: "user";
|
|
@@ -3095,6 +3091,25 @@ type AuthenticatedUser = User & {
|
|
|
3095
3091
|
* Types that combine data from multiple domains
|
|
3096
3092
|
*/
|
|
3097
3093
|
type ManifestV1 = z.infer<typeof ManifestV1Schema>;
|
|
3094
|
+
/**
|
|
3095
|
+
* Basic user information in the shape of the claims from identity providers
|
|
3096
|
+
*/
|
|
3097
|
+
interface UserInfo {
|
|
3098
|
+
/** Unique user identifier (sub claim from JWT) */
|
|
3099
|
+
sub: string;
|
|
3100
|
+
/** User's email address */
|
|
3101
|
+
email: string;
|
|
3102
|
+
/** User's display name */
|
|
3103
|
+
name: string;
|
|
3104
|
+
/** Whether the email has been verified */
|
|
3105
|
+
email_verified: boolean;
|
|
3106
|
+
/** Optional given name (first name) */
|
|
3107
|
+
given_name?: string;
|
|
3108
|
+
/** Optional family name (last name) */
|
|
3109
|
+
family_name?: string;
|
|
3110
|
+
/** Additional user attributes from the identity provider */
|
|
3111
|
+
[key: string]: unknown;
|
|
3112
|
+
}
|
|
3098
3113
|
/**
|
|
3099
3114
|
* Character-related Composite Types
|
|
3100
3115
|
* Types that combine character component data with sprite sheet information
|
|
@@ -3350,6 +3365,10 @@ interface AchievementProgressResponse {
|
|
|
3350
3365
|
createdAt: string;
|
|
3351
3366
|
}
|
|
3352
3367
|
|
|
3368
|
+
declare const AuthProvider: {
|
|
3369
|
+
readonly TIMEBACK: "TIMEBACK";
|
|
3370
|
+
};
|
|
3371
|
+
|
|
3353
3372
|
/**
|
|
3354
3373
|
* OAuth 2.0 implementation for the Playcademy SDK
|
|
3355
3374
|
*/
|
|
@@ -3585,16 +3604,24 @@ declare enum MessageEvents {
|
|
|
3585
3604
|
* - Sets up event listeners for token refresh
|
|
3586
3605
|
* - Exposes the client for debugging in development mode
|
|
3587
3606
|
*
|
|
3607
|
+
* @param options - Optional configuration overrides
|
|
3608
|
+
* @param options.baseUrl - Override the base URL for API requests
|
|
3588
3609
|
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
3589
3610
|
* @throws Error if not running in a browser context
|
|
3590
3611
|
*
|
|
3591
3612
|
* @example
|
|
3592
3613
|
* ```typescript
|
|
3614
|
+
* // Default initialization
|
|
3593
3615
|
* const client = await PlaycademyClient.init()
|
|
3594
|
-
*
|
|
3616
|
+
*
|
|
3617
|
+
* // With custom base URL
|
|
3618
|
+
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
3595
3619
|
* ```
|
|
3596
3620
|
*/
|
|
3597
|
-
declare function init(
|
|
3621
|
+
declare function init(options?: {
|
|
3622
|
+
baseUrl?: string;
|
|
3623
|
+
allowedParentOrigins?: string[];
|
|
3624
|
+
}): Promise<PlaycademyClient>;
|
|
3598
3625
|
|
|
3599
3626
|
/**
|
|
3600
3627
|
* Authenticates a user with email and password.
|
|
@@ -3676,6 +3703,22 @@ declare class PlaycademyClient {
|
|
|
3676
3703
|
* @param token - The authentication token, or null to clear
|
|
3677
3704
|
*/
|
|
3678
3705
|
setToken(token: string | null): void;
|
|
3706
|
+
/**
|
|
3707
|
+
* Gets the current authentication token.
|
|
3708
|
+
*
|
|
3709
|
+
* @returns The current token or null if not authenticated
|
|
3710
|
+
*
|
|
3711
|
+
* @example
|
|
3712
|
+
* ```typescript
|
|
3713
|
+
* // Send token to your backend for verification
|
|
3714
|
+
* const token = client.getToken()
|
|
3715
|
+
* const response = await fetch('/api/auth/playcademy', {
|
|
3716
|
+
* method: 'POST',
|
|
3717
|
+
* body: JSON.stringify({ gameToken: token })
|
|
3718
|
+
* })
|
|
3719
|
+
* ```
|
|
3720
|
+
*/
|
|
3721
|
+
getToken(): string | null;
|
|
3679
3722
|
/**
|
|
3680
3723
|
* Checks if the client has a valid API token for making Playcademy API requests.
|
|
3681
3724
|
*
|
|
@@ -3770,14 +3813,6 @@ declare class PlaycademyClient {
|
|
|
3770
3813
|
};
|
|
3771
3814
|
/** Identity provider connection methods (connect external accounts) */
|
|
3772
3815
|
identity: {
|
|
3773
|
-
readonly user: {
|
|
3774
|
-
sub: string;
|
|
3775
|
-
email: string;
|
|
3776
|
-
name: string;
|
|
3777
|
-
email_verified: true;
|
|
3778
|
-
given_name: undefined;
|
|
3779
|
-
family_name: undefined;
|
|
3780
|
-
} | null;
|
|
3781
3816
|
connect: (options: AuthOptions) => Promise<AuthResult>;
|
|
3782
3817
|
_getContext: () => {
|
|
3783
3818
|
isInIframe: boolean;
|
|
@@ -3825,7 +3860,7 @@ declare class PlaycademyClient {
|
|
|
3825
3860
|
};
|
|
3826
3861
|
leaderboard: {
|
|
3827
3862
|
get: (gameId: string, options?: {
|
|
3828
|
-
limit
|
|
3863
|
+
limit? /** Runtime methods (getGameToken, exit) */: number;
|
|
3829
3864
|
offset?: number;
|
|
3830
3865
|
}) => Promise<LeaderboardEntry[]>;
|
|
3831
3866
|
};
|
|
@@ -4175,7 +4210,6 @@ interface InitPayload {
|
|
|
4175
4210
|
token: string;
|
|
4176
4211
|
gameId: string;
|
|
4177
4212
|
realtimeUrl?: string;
|
|
4178
|
-
user?: GameUser;
|
|
4179
4213
|
}
|
|
4180
4214
|
type AuthProviderType = (typeof AuthProvider)[keyof typeof AuthProvider];
|
|
4181
4215
|
interface AuthOptions {
|
|
@@ -4217,26 +4251,6 @@ interface AuthResult {
|
|
|
4217
4251
|
/** Error if authentication failed */
|
|
4218
4252
|
error?: Error;
|
|
4219
4253
|
}
|
|
4220
|
-
/**
|
|
4221
|
-
* Standard OAuth/OIDC user claims returned from identity providers
|
|
4222
|
-
* This is what external identity providers (like Timeback) return
|
|
4223
|
-
*/
|
|
4224
|
-
interface UserInfo {
|
|
4225
|
-
/** Unique user identifier (sub claim from JWT) */
|
|
4226
|
-
sub: string;
|
|
4227
|
-
/** User's email address */
|
|
4228
|
-
email: string;
|
|
4229
|
-
/** User's display name */
|
|
4230
|
-
name: string;
|
|
4231
|
-
/** Whether the email has been verified */
|
|
4232
|
-
email_verified: boolean;
|
|
4233
|
-
/** Optional given name (first name) */
|
|
4234
|
-
given_name?: string;
|
|
4235
|
-
/** Optional family name (last name) */
|
|
4236
|
-
family_name?: string;
|
|
4237
|
-
/** Additional user attributes from the identity provider */
|
|
4238
|
-
[key: string]: unknown;
|
|
4239
|
-
}
|
|
4240
4254
|
/**
|
|
4241
4255
|
* Simplified user data passed to games via InitPayload
|
|
4242
4256
|
* This is a subset of AuthenticatedUser suitable for external game consumption
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcademy/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
"require": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts"
|
|
10
10
|
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"import": "./dist/server.js",
|
|
13
|
+
"require": "./dist/server.js",
|
|
14
|
+
"types": "./dist/server.d.ts"
|
|
15
|
+
},
|
|
11
16
|
"./types": {
|
|
12
17
|
"import": "./dist/types.js",
|
|
13
18
|
"require": "./dist/types.js",
|