@playcademy/sdk 0.0.5 → 0.0.7

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.
Files changed (48) hide show
  1. package/dist/index.d.ts +4013 -7
  2. package/dist/index.js +1820 -1785
  3. package/dist/server.d.ts +53 -0
  4. package/dist/server.js +50 -0
  5. package/dist/types.d.ts +4243 -41
  6. package/dist/types.js +1 -748
  7. package/package.json +10 -3
  8. package/dist/core/auth/flows/popup.d.ts +0 -14
  9. package/dist/core/auth/flows/redirect.d.ts +0 -15
  10. package/dist/core/auth/flows/unified.d.ts +0 -11
  11. package/dist/core/auth/login.d.ts +0 -20
  12. package/dist/core/auth/oauth.d.ts +0 -115
  13. package/dist/core/auth/utils.d.ts +0 -23
  14. package/dist/core/cache/cooldown-cache.d.ts +0 -31
  15. package/dist/core/cache/index.d.ts +0 -14
  16. package/dist/core/cache/permanent-cache.d.ts +0 -39
  17. package/dist/core/cache/singleton-cache.d.ts +0 -29
  18. package/dist/core/cache/ttl-cache.d.ts +0 -54
  19. package/dist/core/cache/types.d.ts +0 -23
  20. package/dist/core/client.d.ts +0 -521
  21. package/dist/core/errors.d.ts +0 -11
  22. package/dist/core/namespaces/achievements.d.ts +0 -84
  23. package/dist/core/namespaces/admin.d.ts +0 -385
  24. package/dist/core/namespaces/auth.d.ts +0 -54
  25. package/dist/core/namespaces/character.d.ts +0 -205
  26. package/dist/core/namespaces/credits.d.ts +0 -51
  27. package/dist/core/namespaces/dev.d.ts +0 -323
  28. package/dist/core/namespaces/games.d.ts +0 -173
  29. package/dist/core/namespaces/identity.d.ts +0 -98
  30. package/dist/core/namespaces/index.d.ts +0 -19
  31. package/dist/core/namespaces/leaderboard.d.ts +0 -48
  32. package/dist/core/namespaces/levels.d.ts +0 -90
  33. package/dist/core/namespaces/maps.d.ts +0 -93
  34. package/dist/core/namespaces/realtime.client.d.ts +0 -129
  35. package/dist/core/namespaces/realtime.d.ts +0 -90
  36. package/dist/core/namespaces/runtime.d.ts +0 -222
  37. package/dist/core/namespaces/scores.d.ts +0 -55
  38. package/dist/core/namespaces/shop.d.ts +0 -25
  39. package/dist/core/namespaces/sprites.d.ts +0 -35
  40. package/dist/core/namespaces/telemetry.d.ts +0 -28
  41. package/dist/core/namespaces/timeback.d.ts +0 -111
  42. package/dist/core/namespaces/users.d.ts +0 -172
  43. package/dist/core/request.d.ts +0 -24
  44. package/dist/core/static/identity.d.ts +0 -37
  45. package/dist/core/static/index.d.ts +0 -3
  46. package/dist/core/static/init.d.ts +0 -21
  47. package/dist/core/static/login.d.ts +0 -34
  48. package/dist/messaging.d.ts +0 -544
@@ -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
+ };