@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
@@ -1,90 +0,0 @@
1
- import type { LevelConfig, UserLevel } from '@playcademy/data/types';
2
- import type { PlaycademyClient } from '../../types';
3
- import type { CooldownCacheConfig } from '../cache/types';
4
- /**
5
- * Creates the levels namespace for the PlaycademyClient.
6
- * Provides methods for retrieving user levels and progress.
7
- *
8
- * @param client - The PlaycademyClient instance
9
- * @returns Levels namespace with level query methods
10
- */
11
- export declare function createLevelsNamespace(client: PlaycademyClient): {
12
- /**
13
- * Retrieves the current user's level information.
14
- *
15
- * @returns Promise resolving to user level data
16
- *
17
- * @example
18
- * ```typescript
19
- * const userLevel = await client.levels.get()
20
- * console.log('Current level:', userLevel.currentLevel)
21
- * console.log('Current XP:', userLevel.currentXp)
22
- * console.log('Total XP earned:', userLevel.totalXP)
23
- * ```
24
- */
25
- get: () => Promise<UserLevel>;
26
- /**
27
- * Retrieves the current user's level progress information.
28
- * Uses a 5 second cooldown by default to prevent rapid API calls.
29
- *
30
- * @param options - Optional cache configuration
31
- * @param options.cooldown - Custom cooldown in milliseconds (0 to disable)
32
- * @param options.force - Force refresh, bypassing cooldown
33
- * @returns Promise resolving to level progress data
34
- *
35
- * @example
36
- * ```typescript
37
- * // Use default 5 second cooldown
38
- * const progress = await client.levels.progress()
39
- *
40
- * // Custom 10 second cooldown for background sync
41
- * const bgProgress = await client.levels.progress({ cooldown: 10_000 })
42
- *
43
- * // Force refresh on level up
44
- * const freshProgress = await client.levels.progress({ force: true })
45
- *
46
- * // Disable cooldown for real-time display
47
- * const realtimeProgress = await client.levels.progress({ cooldown: 0 })
48
- * ```
49
- */
50
- progress: (options?: CooldownCacheConfig) => Promise<{
51
- level: number;
52
- currentXp: number;
53
- xpToNextLevel: number;
54
- totalXP: number;
55
- }>;
56
- /**
57
- * Configuration methods for level system.
58
- */
59
- config: {
60
- /**
61
- * Retrieves all level configurations (full XP curve).
62
- *
63
- * @returns Promise resolving to array of level configurations
64
- *
65
- * @example
66
- * ```typescript
67
- * const configs = await client.levels.config.list()
68
- * configs.forEach(config => {
69
- * console.log(`Level ${config.level}: ${config.xpRequired} XP, ${config.creditsReward} credits`)
70
- * })
71
- * ```
72
- */
73
- list: () => Promise<LevelConfig[]>;
74
- /**
75
- * Retrieves configuration for a specific level.
76
- *
77
- * @param level - The level number to get configuration for
78
- * @returns Promise resolving to level configuration or null if not found
79
- *
80
- * @example
81
- * ```typescript
82
- * const config = await client.levels.config.get(10)
83
- * if (config) {
84
- * console.log(`Level 10 requires ${config.xpRequired} XP`)
85
- * }
86
- * ```
87
- */
88
- get: (level: number) => Promise<LevelConfig | null>;
89
- };
90
- };
@@ -1,93 +0,0 @@
1
- import type { CreateMapObjectData, MapData, MapElementWithGame, MapObjectWithItem } from '@playcademy/data/types';
2
- import type { PlaycademyClient } from '../../types';
3
- /**
4
- * Creates the maps namespace for the PlaycademyClient.
5
- * Provides methods for retrieving map data and elements.
6
- *
7
- * @param client - The PlaycademyClient instance
8
- * @returns Maps namespace with element retrieval methods
9
- */
10
- export declare function createMapsNamespace(client: PlaycademyClient): {
11
- /**
12
- * Gets details for a specific map by its string identifier.
13
- *
14
- * @param identifier - The string identifier of the map
15
- * @returns Promise resolving to map data
16
- *
17
- * @example
18
- * ```typescript
19
- * const map = await client.maps.get('world-1-level-1')
20
- * console.log('Map name:', map.name)
21
- * ```
22
- */
23
- get: (identifier: string) => Promise<MapData>;
24
- /**
25
- * Retrieves all elements for a specific map.
26
- *
27
- * @param mapId - The ID of the map to get elements for
28
- * @returns Promise resolving to array of map elements with game data
29
- *
30
- * @example
31
- * ```typescript
32
- * const elements = await client.maps.elements('map-123')
33
- * elements.forEach(element => {
34
- * console.log(`Element: ${element.elementSlug} - Game: ${element.game?.displayName || 'None'}`)
35
- * })
36
- * ```
37
- */
38
- elements: (mapId: string) => Promise<MapElementWithGame[]>;
39
- /**
40
- * Map objects sub-namespace for managing placed objects on maps
41
- */
42
- objects: {
43
- /**
44
- * Lists all placed objects for a specific map.
45
- *
46
- * @param mapId - The ID of the map to get objects for
47
- * @returns Promise resolving to array of map objects
48
- *
49
- * @example
50
- * ```typescript
51
- * const objects = await client.maps.objects.list('map-123')
52
- * objects.forEach(obj => {
53
- * console.log(`Object at (${obj.worldX}, ${obj.worldY})`)
54
- * })
55
- * ```
56
- */
57
- list: (mapId: string) => Promise<MapObjectWithItem[]>;
58
- /**
59
- * Creates a new placed object on a map.
60
- *
61
- * @param mapId - The ID of the map to place the object on
62
- * @param objectData - The object placement data
63
- * @returns Promise resolving to the created map object
64
- *
65
- * @example
66
- * ```typescript
67
- * const newObject = await client.maps.objects.create('map-123', {
68
- * worldX: 100,
69
- * worldY: 200,
70
- * width: 32,
71
- * height: 32,
72
- * metadata: { type: 'treasure_chest' }
73
- * })
74
- * console.log('Object created:', newObject.id)
75
- * ```
76
- */
77
- create: (mapId: string, objectData: CreateMapObjectData) => Promise<MapObjectWithItem>;
78
- /**
79
- * Deletes a placed object from a map.
80
- *
81
- * @param mapId - The ID of the map containing the object
82
- * @param objectId - The ID of the object to delete
83
- * @returns Promise that resolves when object is deleted
84
- *
85
- * @example
86
- * ```typescript
87
- * await client.maps.objects.delete('map-123', 'object-456')
88
- * console.log('Object deleted')
89
- * ```
90
- */
91
- delete: (mapId: string, objectId: string) => Promise<void>;
92
- };
93
- };
@@ -1,129 +0,0 @@
1
- import type { RealtimeChannel } from '@playcademy/realtime/server/types';
2
- /**
3
- * Client-side implementation of a realtime communication channel.
4
- * Manages a WebSocket connection to a specific game-scoped realtime channel.
5
- *
6
- * **Key Features**:
7
- * - Automatic connection management with reconnection on token refresh
8
- * - Type-safe message handling with JSON serialization/deserialization
9
- * - Proper cleanup and resource management
10
- * - Integration with the Playcademy messaging system for token updates
11
- *
12
- * **Connection Lifecycle**:
13
- * 1. `connect()` - Establishes WebSocket connection with authentication
14
- * 2. Message exchange via `send()` and `onMessage()` callbacks
15
- * 3. Automatic reconnection on token refresh events
16
- * 4. `close()` - Clean shutdown with proper resource cleanup
17
- *
18
- * @example
19
- * ```typescript
20
- * const client = new RealtimeChannelClient(
21
- * 'game-123',
22
- * 'chat',
23
- * () => getToken(),
24
- * 'ws://localhost:3000'
25
- * )
26
- *
27
- * await client.connect()
28
- *
29
- * client.onMessage((data) => {
30
- * console.log('Received:', data)
31
- * })
32
- *
33
- * client.send({ type: 'message', text: 'Hello!' })
34
- *
35
- * // Clean up when done
36
- * client.close()
37
- * ```
38
- */
39
- export declare class RealtimeChannelClient implements RealtimeChannel {
40
- private gameId;
41
- private _channelName;
42
- private getToken;
43
- private baseUrl;
44
- private ws?;
45
- private listeners;
46
- private isClosing;
47
- private tokenRefreshUnsubscribe?;
48
- constructor(gameId: string, _channelName: string, getToken: () => Promise<string>, baseUrl: string);
49
- /**
50
- * Establishes the WebSocket connection to the realtime server.
51
- *
52
- * **Connection Process**:
53
- * 1. Obtains fresh authentication token
54
- * 2. Constructs WebSocket URL with token and channel parameters
55
- * 3. Creates WebSocket connection
56
- * 4. Sets up event handlers for messages, errors, and disconnections
57
- * 5. Registers for token refresh events
58
- *
59
- * **URL Format**: `ws://host/path?token=<jwt>&c=<channel>`
60
- *
61
- * @throws Error if token retrieval fails or WebSocket connection fails
62
- */
63
- connect(): Promise<RealtimeChannel>;
64
- /**
65
- * Sets up WebSocket event handlers for message processing and connection management.
66
- *
67
- * **Event Handling**:
68
- * - `message`: Parses JSON and notifies all registered listeners
69
- * - `close`: Handles both expected and unexpected disconnections
70
- * - `error`: Logs WebSocket errors for debugging
71
- */
72
- private setupEventHandlers;
73
- /**
74
- * Sets up listener for token refresh events from the messaging system.
75
- * When a token refresh occurs, the WebSocket connection is closed and reopened
76
- * with the new token to maintain authentication.
77
- */
78
- private setupTokenRefreshListener;
79
- /**
80
- * Reconnects the WebSocket with a new authentication token.
81
- *
82
- * **Reconnection Process**:
83
- * 1. Close existing connection with TOKEN_REFRESH code
84
- * 2. Wait for close event to complete
85
- * 3. Re-establish connection with new token
86
- *
87
- * @param token - The new authentication token (currently unused, relies on getToken())
88
- */
89
- private reconnectWithNewToken;
90
- /**
91
- * Sends a message to all members of this channel.
92
- *
93
- * **Message Format**: JSON-serialized payload
94
- * **Delivery**: Best-effort, no acknowledgment or retry logic
95
- *
96
- * @param data - Any JSON-serializable data to send
97
- */
98
- send(data: unknown): void;
99
- /**
100
- * Registers a callback to be invoked when messages are received on this channel.
101
- *
102
- * **Message Processing**:
103
- * - Messages are automatically JSON-parsed before delivery
104
- * - Listener errors are caught and logged (won't affect other listeners)
105
- * - Multiple listeners can be registered for the same channel
106
- *
107
- * @param callback - Function to call when messages are received
108
- * @returns Unsubscribe function to remove this listener
109
- */
110
- onMessage(callback: (data: unknown) => void): () => void;
111
- /**
112
- * Closes the WebSocket connection and cleans up all resources.
113
- *
114
- * **Cleanup Process**:
115
- * 1. Mark as intentionally closing (prevents reconnection attempts)
116
- * 2. Remove token refresh listener
117
- * 3. Close WebSocket with normal closure code
118
- * 4. Clear all message listeners
119
- */
120
- close(): void;
121
- /**
122
- * Gets the name of this channel.
123
- */
124
- get channelName(): string;
125
- /**
126
- * Checks if the underlying WebSocket connection is currently open.
127
- */
128
- get isConnected(): boolean;
129
- }
@@ -1,90 +0,0 @@
1
- import type { RealtimeChannel } from '@playcademy/realtime/server/types';
2
- import type { PlaycademyClient } from '../../types';
3
- /**
4
- * Response type for the realtime token API
5
- */
6
- export interface RealtimeTokenResponse {
7
- token: string;
8
- }
9
- /**
10
- * Creates the realtime namespace for the PlaycademyClient.
11
- * Provides methods for realtime connectivity and features.
12
- *
13
- * @param client - The PlaycademyClient instance
14
- * @returns Realtime namespace with token-related methods and channel API
15
- */
16
- export declare function createRealtimeNamespace(client: PlaycademyClient): {
17
- /**
18
- * Token sub-namespace for realtime token management
19
- */
20
- token: {
21
- /**
22
- * Gets a realtime JWT token for establishing realtime connections.
23
- * This token is typically used for WebSocket connections or MQTT clients.
24
- *
25
- * @returns Promise resolving to token response
26
- *
27
- * @example
28
- * ```typescript
29
- * // Get a realtime token
30
- * const response = await client.realtime.token.get()
31
- * console.log('Realtime token:', response.token)
32
- *
33
- * // Use with a realtime client
34
- * const realtimeClient = new RealtimeClient({
35
- * token: response.token
36
- * })
37
- * ```
38
- */
39
- get: () => Promise<RealtimeTokenResponse>;
40
- };
41
- /**
42
- * Opens a realtime channel for game-scoped communication.
43
- *
44
- * **Channel Naming**:
45
- * - Channels are automatically scoped to the current game
46
- * - Channel names should be descriptive (e.g. "chat", "lobby", "map_forest")
47
- * - The "default" channel is used if no name is specified
48
- *
49
- * **Connection Management**:
50
- * - Each channel opens its own WebSocket connection
51
- * - Connections automatically handle token refresh
52
- * - Remember to call `channel.close()` when done to prevent resource leaks
53
- *
54
- * **Error Handling**:
55
- * - Throws if no `gameId` is configured on the client
56
- * - Throws if token retrieval fails
57
- * - Throws if WebSocket connection fails
58
- *
59
- * @param channel - Channel name (defaults to "default")
60
- * @param url - Optional WebSocket **base** URL (e.g. `ws://localhost:3000`).
61
- * If omitted, the client's `baseUrl` is used and automatically converted to
62
- * a WebSocket URL (`http` → `ws`, `https` → `wss`).
63
- * @returns Promise resolving to a `RealtimeChannel` instance
64
- *
65
- * @example
66
- * ```typescript
67
- * // Open the default channel
68
- * const channel = await client.realtime.open()
69
- *
70
- * // Listen for messages
71
- * const unsubscribe = channel.onMessage((data) => {
72
- * console.log('Received:', data)
73
- * })
74
- *
75
- * // Send a message
76
- * channel.send({ type: 'chat', message: 'Hello world!' })
77
- *
78
- * // Clean up when done
79
- * unsubscribe()
80
- * channel.close()
81
- *
82
- * // Open a named channel
83
- * const chatChannel = await client.realtime.open('chat')
84
- *
85
- * // Open a channel against a custom realtime endpoint
86
- * const localChannel = await client.realtime.open('dev', 'ws://localhost:3000')
87
- * ```
88
- */
89
- open(channel?: string, url?: string): Promise<RealtimeChannel>;
90
- };
@@ -1,222 +0,0 @@
1
- import { MessageEvents } from '../../messaging';
2
- import type { GameContextPayload, GameTokenResponse, PlaycademyClient } from '../../types';
3
- /**
4
- * Type for runtime event handlers - union of all possible handler signatures
5
- */
6
- type RuntimeEventHandler = ((context: GameContextPayload) => void) | ((data: {
7
- token: string;
8
- exp: number;
9
- }) => void) | (() => void) | ((isVisible: boolean) => void);
10
- /**
11
- * Creates the runtime namespace for the PlaycademyClient.
12
- * Provides methods for managing game runtime operations and lifecycle.
13
- *
14
- * @param client - The PlaycademyClient instance
15
- * @returns Runtime namespace with comprehensive game lifecycle management methods
16
- */
17
- export declare function createRuntimeNamespace(client: PlaycademyClient): {
18
- /**
19
- * Retrieves a game token for the specified game.
20
- * Optionally applies the token to the current client instance.
21
- *
22
- * @param gameId - The ID of the game to get a token for
23
- * @param options - Optional configuration
24
- * @param options.apply - Whether to automatically apply the token to this client
25
- * @returns Promise resolving to game token response
26
- *
27
- * @example
28
- * ```typescript
29
- * // Get token without applying it
30
- * const tokenResponse = await client.runtime.getGameToken('game-123')
31
- *
32
- * // Get token and apply it to current client
33
- * const tokenResponse = await client.runtime.getGameToken('game-123', { apply: true })
34
- * ```
35
- */
36
- getGameToken: (gameId: string, options?: {
37
- apply?: boolean;
38
- }) => Promise<GameTokenResponse>;
39
- /**
40
- * Gracefully exits the game runtime.
41
- * Automatically ends any active game session and emits an exit event.
42
- *
43
- * @returns Promise that resolves when exit is complete
44
- *
45
- * @example
46
- * ```typescript
47
- * // Clean up and exit the game
48
- * await client.runtime.exit()
49
- * ```
50
- */
51
- exit: () => Promise<void>;
52
- /**
53
- * Listens for game initialization events from the parent.
54
- * Called when the parent sends initial configuration and auth context.
55
- *
56
- * @param handler - Function to call when initialization occurs
57
- *
58
- * @example
59
- * ```typescript
60
- * client.runtime.onInit((context) => {
61
- * console.log(`Game ${context.gameId} initialized`)
62
- * console.log(`API base URL: ${context.baseUrl}`)
63
- * })
64
- * ```
65
- */
66
- onInit: (handler: (context: GameContextPayload) => void) => void;
67
- /**
68
- * Listens for token refresh events from the parent.
69
- * Called when the parent updates the authentication token.
70
- *
71
- * @param handler - Function to call when token is refreshed
72
- *
73
- * @example
74
- * ```typescript
75
- * client.runtime.onTokenRefresh(({ token, exp }) => {
76
- * console.log(`Token refreshed, expires at: ${new Date(exp)}`)
77
- * // Token is automatically applied to the client
78
- * })
79
- * ```
80
- */
81
- onTokenRefresh: (handler: (data: {
82
- token: string;
83
- exp: number;
84
- }) => void) => void;
85
- /**
86
- * Listens for pause events from the parent.
87
- * Called when the game should pause execution (e.g., user switches tabs).
88
- *
89
- * @param handler - Function to call when game should pause
90
- *
91
- * @example
92
- * ```typescript
93
- * client.runtime.onPause(() => {
94
- * game.pause()
95
- * audioManager.pauseAll()
96
- * })
97
- * ```
98
- */
99
- onPause: (handler: () => void) => void;
100
- /**
101
- * Listens for resume events from the parent.
102
- * Called when the game should resume execution after being paused.
103
- *
104
- * @param handler - Function to call when game should resume
105
- *
106
- * @example
107
- * ```typescript
108
- * client.runtime.onResume(() => {
109
- * game.resume()
110
- * audioManager.resumeAll()
111
- * })
112
- * ```
113
- */
114
- onResume: (handler: () => void) => void;
115
- /**
116
- * Listens for force exit events from the parent.
117
- * Called when the game must terminate immediately (emergency exit).
118
- *
119
- * @param handler - Function to call when game must force exit
120
- *
121
- * @example
122
- * ```typescript
123
- * client.runtime.onForceExit(() => {
124
- * game.emergencyCleanup()
125
- * // Game should exit immediately after cleanup
126
- * })
127
- * ```
128
- */
129
- onForceExit: (handler: () => void) => void;
130
- /**
131
- * Listens for overlay visibility events from the parent.
132
- * Called when UI overlays are shown/hidden over the game.
133
- *
134
- * @param handler - Function to call when overlay state changes
135
- *
136
- * @example
137
- * ```typescript
138
- * client.runtime.onOverlay((isVisible) => {
139
- * if (isVisible) {
140
- * game.showOverlayMode()
141
- * } else {
142
- * game.hideOverlayMode()
143
- * }
144
- * })
145
- * ```
146
- */
147
- onOverlay: (handler: (isVisible: boolean) => void) => void;
148
- /**
149
- * Signals that the game has finished loading and is ready to receive messages.
150
- * Should be called once after game initialization is complete.
151
- *
152
- * @example
153
- * ```typescript
154
- * // After game has loaded
155
- * await client.runtime.ready()
156
- * ```
157
- */
158
- ready: () => void;
159
- /**
160
- * Sends performance telemetry data to the parent.
161
- * Used for monitoring game performance and analytics.
162
- *
163
- * @param data - Performance metrics data
164
- * @param data.fps - Current frames per second
165
- * @param data.mem - Current memory usage in MB
166
- *
167
- * @example
168
- * ```typescript
169
- * // Send current performance metrics
170
- * client.runtime.sendTelemetry({
171
- * fps: game.getCurrentFPS(),
172
- * mem: performance.memory ? performance.memory.usedJSHeapSize / 1024 / 1024 : 0
173
- * })
174
- * ```
175
- */
176
- sendTelemetry: (data: {
177
- fps: number;
178
- mem: number;
179
- }) => void;
180
- /**
181
- * Removes a specific event listener.
182
- * Use this to stop listening for specific events.
183
- *
184
- * @param eventType - The message event type to stop listening for
185
- * @param handler - The exact handler function that was registered
186
- *
187
- * @example
188
- * ```typescript
189
- * const pauseHandler = () => game.pause()
190
- * client.runtime.onPause(pauseHandler)
191
- *
192
- * // Later, remove the specific handler
193
- * client.runtime.removeListener(MessageEvents.PAUSE, pauseHandler)
194
- * ```
195
- */
196
- removeListener: (eventType: MessageEvents, handler: RuntimeEventHandler) => void;
197
- /**
198
- * Removes all runtime event listeners.
199
- * Use this for cleanup when the game is shutting down.
200
- *
201
- * @example
202
- * ```typescript
203
- * // Clean up all runtime listeners before exit
204
- * client.runtime.removeAllListeners()
205
- * await client.runtime.exit()
206
- * ```
207
- */
208
- removeAllListeners: () => void;
209
- /**
210
- * Gets the count of active listeners for debugging purposes.
211
- *
212
- * @returns Object with listener counts by event type
213
- *
214
- * @example
215
- * ```typescript
216
- * const counts = client.runtime.getListenerCounts()
217
- * console.log(`Active listeners:`, counts)
218
- * ```
219
- */
220
- getListenerCounts: () => Record<string, number>;
221
- };
222
- export {};
@@ -1,55 +0,0 @@
1
- import type { UserScore } from '@playcademy/data/types';
2
- import type { PlaycademyClient } from '../../types';
3
- export interface ScoreSubmission {
4
- id: string;
5
- score: number;
6
- achievedAt: Date;
7
- }
8
- /**
9
- * Creates the scores namespace for the PlaycademyClient.
10
- * Provides methods for managing scores across the platform.
11
- *
12
- * @param client - The PlaycademyClient instance
13
- * @returns Scores namespace with submit and retrieval methods
14
- */
15
- export declare function createScoresNamespace(client: PlaycademyClient): {
16
- /**
17
- * Submits a score for a specific game.
18
- * Note: This still requires a gameId as scores must be associated with a game.
19
- *
20
- * @param gameId - The game ID to submit the score for
21
- * @param score - The score value to submit
22
- * @param metadata - Optional metadata about the score
23
- * @returns Promise resolving to the created score record
24
- *
25
- * @example
26
- * ```typescript
27
- * const scoreRecord = await client.scores.submit('game-123', 1250, {
28
- * level: 5,
29
- * difficulty: 'hard'
30
- * })
31
- * console.log('Score submitted:', scoreRecord.id)
32
- * ```
33
- */
34
- submit: (gameId: string, score: number, metadata?: Record<string, unknown>) => Promise<ScoreSubmission>;
35
- /**
36
- * Gets all scores for a specific user within a specific game.
37
- *
38
- * @param gameId - The game ID to get scores for
39
- * @param userId - The user ID to get scores for
40
- * @param options - Optional filtering options
41
- * @param options.limit - Maximum number of scores to return
42
- * @returns Promise resolving to array of user scores for the game
43
- *
44
- * @example
45
- * ```typescript
46
- * const gameScores = await client.scores.getByUser('game-123', 'user-456', {
47
- * limit: 10
48
- * })
49
- * console.log(`User has ${gameScores.length} scores in this game`)
50
- * ```
51
- */
52
- getByUser: (gameId: string, userId: string, options?: {
53
- limit?: number;
54
- }) => Promise<UserScore[]>;
55
- };