@playcademy/sdk 0.0.1-beta.3 → 0.0.1-beta.31
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 +503 -124
- package/dist/core/client.d.ts +352 -54
- package/dist/core/namespaces/admin.d.ts +385 -0
- package/dist/core/namespaces/auth.d.ts +23 -0
- package/dist/core/namespaces/character.d.ts +146 -0
- package/dist/core/namespaces/credits.d.ts +51 -0
- package/dist/core/namespaces/dev.d.ts +323 -0
- package/dist/core/namespaces/games.d.ts +149 -0
- package/dist/core/namespaces/index.d.ts +16 -0
- package/dist/core/namespaces/leaderboard.d.ts +48 -0
- package/dist/core/namespaces/levels.d.ts +93 -0
- package/dist/core/namespaces/maps.d.ts +93 -0
- package/dist/core/namespaces/realtime.client.d.ts +129 -0
- package/dist/core/namespaces/realtime.d.ts +84 -0
- package/dist/core/namespaces/runtime.d.ts +222 -0
- package/dist/core/namespaces/scores.d.ts +55 -0
- package/dist/core/namespaces/shop.d.ts +25 -0
- package/dist/core/namespaces/sprites.d.ts +32 -0
- package/dist/core/namespaces/telemetry.d.ts +28 -0
- package/dist/core/namespaces/users.d.ts +183 -0
- package/dist/core/request.d.ts +1 -1
- package/dist/core/static/index.d.ts +2 -0
- package/dist/core/static/init.d.ts +21 -0
- package/dist/core/static/login.d.ts +24 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1845 -0
- package/dist/messaging.d.ts +522 -0
- package/dist/types.d.ts +15 -8
- package/dist/types.js +589 -0
- package/package.json +18 -10
- package/dist/bus.d.ts +0 -37
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -7427
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import type { DeveloperStatusValue, Game, InsertItemInput, InsertShopListingInput, Item, ShopListing, UpdateItemInput, UpdateShopListingInput, UpsertGameMetadataInput } from '@playcademy/data/types';
|
|
2
|
+
import type { PlaycademyClient } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the developer namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for developer account management, game publishing, API key management, and item management.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Developer namespace with auth, games, keys, and items methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDevNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Developer authentication and status methods.
|
|
13
|
+
*/
|
|
14
|
+
auth: {
|
|
15
|
+
/**
|
|
16
|
+
* Applies for developer status for the current user.
|
|
17
|
+
*
|
|
18
|
+
* @returns Promise that resolves when application is submitted
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* await client.dev.auth.applyForDeveloper()
|
|
23
|
+
* console.log('Developer application submitted')
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
applyForDeveloper: () => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the current developer status for the user.
|
|
29
|
+
*
|
|
30
|
+
* @returns Promise resolving to developer status value
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const status = await client.dev.auth.getStatus()
|
|
35
|
+
* if (status === 'approved') {
|
|
36
|
+
* console.log('Developer access granted')
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
getStatus: () => Promise<DeveloperStatusValue>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Game management methods for developers.
|
|
44
|
+
*/
|
|
45
|
+
games: {
|
|
46
|
+
/**
|
|
47
|
+
* Creates or updates a game with metadata and asset bundle.
|
|
48
|
+
*
|
|
49
|
+
* @param slug - The game slug (URL-friendly identifier)
|
|
50
|
+
* @param metadata - Game metadata (title, description, etc.)
|
|
51
|
+
* @param file - Game asset bundle file (zip)
|
|
52
|
+
* @returns Promise resolving to the created/updated game
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const gameFile = new File([zipData], 'game.zip')
|
|
57
|
+
* const game = await client.dev.games.upsert('my-game', {
|
|
58
|
+
* displayName: 'My Awesome Game',
|
|
59
|
+
* platform: 'web',
|
|
60
|
+
* metadata: { description: 'A fun puzzle game' }
|
|
61
|
+
* }, gameFile)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
upsert: (slug: string, metadata: UpsertGameMetadataInput, file: File | Blob) => Promise<Game>;
|
|
65
|
+
/**
|
|
66
|
+
* Updates specific properties of an existing game.
|
|
67
|
+
*
|
|
68
|
+
* @param gameId - The game ID to update
|
|
69
|
+
* @param props - Partial game properties to update
|
|
70
|
+
* @returns Promise that resolves when update is complete
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* await client.dev.games.update('game-123', {
|
|
75
|
+
* title: 'Updated Game Title',
|
|
76
|
+
* isPublic: true
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
update: (gameId: string, props: Partial<Game>) => Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Deletes a game permanently.
|
|
83
|
+
*
|
|
84
|
+
* @param gameId - The game ID to delete
|
|
85
|
+
* @returns Promise that resolves when deletion is complete
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* await client.dev.games.delete('game-123')
|
|
90
|
+
* console.log('Game deleted successfully')
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
delete: (gameId: string) => Promise<void>;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* API key management methods for developers.
|
|
97
|
+
*/
|
|
98
|
+
keys: {
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new API key for the developer.
|
|
101
|
+
*
|
|
102
|
+
* @param label - Optional label for the key
|
|
103
|
+
* @returns Promise resolving to the created API key
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const key = await client.dev.keys.create('Production Key')
|
|
108
|
+
* console.log('API Key:', key.apiKey)
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
create: (label?: string) => Promise<{
|
|
112
|
+
id: string;
|
|
113
|
+
createdAt: Date;
|
|
114
|
+
userId: string;
|
|
115
|
+
label: string | null;
|
|
116
|
+
keyHash: string;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Lists all API keys for the developer.
|
|
120
|
+
*
|
|
121
|
+
* @returns Promise resolving to array of API keys
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const keys = await client.dev.keys.list()
|
|
126
|
+
* keys.forEach(key => console.log(`${key.label}: ${key.id}`))
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
list: () => Promise<{
|
|
130
|
+
id: string;
|
|
131
|
+
createdAt: Date;
|
|
132
|
+
userId: string;
|
|
133
|
+
label: string | null;
|
|
134
|
+
keyHash: string;
|
|
135
|
+
}[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Revokes (deletes) an API key.
|
|
138
|
+
*
|
|
139
|
+
* @param keyId - The key ID to revoke
|
|
140
|
+
* @returns Promise that resolves when key is revoked
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* await client.dev.keys.revoke('key-456')
|
|
145
|
+
* console.log('API key revoked')
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
revoke: (keyId: string) => Promise<void>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Item management methods for developers.
|
|
152
|
+
* Allows developers to create and manage game-specific items.
|
|
153
|
+
*/
|
|
154
|
+
items: {
|
|
155
|
+
/**
|
|
156
|
+
* Creates a new game-scoped item.
|
|
157
|
+
*
|
|
158
|
+
* @param gameId - The game ID to create the item for
|
|
159
|
+
* @param slug - The item slug (unique within the game)
|
|
160
|
+
* @param itemData - Item properties (displayName, description, type, etc.)
|
|
161
|
+
* @returns Promise resolving to the created item
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const item = await client.dev.items.create('game-123', 'MAGIC_SWORD', {
|
|
166
|
+
* displayName: 'Magic Sword',
|
|
167
|
+
* description: 'A powerful enchanted blade',
|
|
168
|
+
* type: 'unlock',
|
|
169
|
+
* metadata: { rarity: 'epic' }
|
|
170
|
+
* })
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
create: (gameId: string, slug: string, itemData: Omit<InsertItemInput, "slug" | "gameId">) => Promise<Item>;
|
|
174
|
+
/**
|
|
175
|
+
* Updates an existing game-scoped item.
|
|
176
|
+
*
|
|
177
|
+
* @param gameId - The game ID
|
|
178
|
+
* @param itemId - The item ID to update
|
|
179
|
+
* @param updates - Partial item properties to update
|
|
180
|
+
* @returns Promise resolving to the updated item
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const updated = await client.dev.items.update('game-123', 'item-456', {
|
|
185
|
+
* displayName: 'Super Magic Sword',
|
|
186
|
+
* metadata: { rarity: 'legendary' }
|
|
187
|
+
* })
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
update: (gameId: string, itemId: string, updates: UpdateItemInput) => Promise<Item>;
|
|
191
|
+
/**
|
|
192
|
+
* Lists all items for a specific game.
|
|
193
|
+
*
|
|
194
|
+
* @param gameId - The game ID to list items for
|
|
195
|
+
* @returns Promise resolving to array of game-scoped items
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const items = await client.dev.items.list('game-123')
|
|
200
|
+
* items.forEach(item => console.log(`${item.slug}: ${item.displayName}`))
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
list: (gameId: string) => Promise<Array<Item>>;
|
|
204
|
+
/**
|
|
205
|
+
* Gets a specific item by slug within a game context.
|
|
206
|
+
* Uses the resolution endpoint to find the item.
|
|
207
|
+
*
|
|
208
|
+
* @param gameId - The game ID context
|
|
209
|
+
* @param slug - The item slug to retrieve
|
|
210
|
+
* @returns Promise resolving to the item
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const item = await client.dev.items.get('game-123', 'MAGIC_SWORD')
|
|
215
|
+
* console.log('Item:', item.displayName)
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
get: (gameId: string, slug: string) => Promise<Item>;
|
|
219
|
+
/**
|
|
220
|
+
* Deletes a game-scoped item.
|
|
221
|
+
*
|
|
222
|
+
* @param gameId - The game ID
|
|
223
|
+
* @param itemId - The item ID to delete
|
|
224
|
+
* @returns Promise that resolves when item is deleted
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* await client.dev.items.delete('game-123', 'item-456')
|
|
229
|
+
* console.log('Item deleted successfully')
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
delete: (gameId: string, itemId: string) => Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Shop listing management for game items.
|
|
235
|
+
* Allows developers to control if and how their items are sold.
|
|
236
|
+
*/
|
|
237
|
+
shop: {
|
|
238
|
+
/**
|
|
239
|
+
* Creates a shop listing for a game item.
|
|
240
|
+
*
|
|
241
|
+
* @param gameId - The game ID
|
|
242
|
+
* @param itemId - The item ID to list for sale
|
|
243
|
+
* @param listingData - Shop listing properties (price, currency, etc.)
|
|
244
|
+
* @returns Promise resolving to the created shop listing
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const listing = await client.dev.items.shop.create('game-123', 'item-456', {
|
|
249
|
+
* currencyId: 'credits-currency-id',
|
|
250
|
+
* price: 100,
|
|
251
|
+
* sellBackPercentage: 50,
|
|
252
|
+
* isActive: true
|
|
253
|
+
* })
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
create: (gameId: string, itemId: string, listingData: Omit<InsertShopListingInput, "itemId">) => Promise<ShopListing>;
|
|
257
|
+
/**
|
|
258
|
+
* Gets the shop listing for a specific game item.
|
|
259
|
+
*
|
|
260
|
+
* @param gameId - The game ID
|
|
261
|
+
* @param itemId - The item ID
|
|
262
|
+
* @returns Promise resolving to the shop listing, or null if no listing exists
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const listing = await client.dev.items.shop.get('game-123', 'item-456')
|
|
267
|
+
* if (listing) {
|
|
268
|
+
* console.log(`Item is listed for ${listing.price} credits`)
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
get: (gameId: string, itemId: string) => Promise<ShopListing | null>;
|
|
273
|
+
/**
|
|
274
|
+
* Updates an existing shop listing for a game item.
|
|
275
|
+
*
|
|
276
|
+
* @param gameId - The game ID
|
|
277
|
+
* @param itemId - The item ID
|
|
278
|
+
* @param updates - Partial shop listing properties to update
|
|
279
|
+
* @returns Promise resolving to the updated shop listing
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const updated = await client.dev.items.shop.update('game-123', 'item-456', {
|
|
284
|
+
* price: 150,
|
|
285
|
+
* isActive: false
|
|
286
|
+
* })
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
update: (gameId: string, itemId: string, updates: UpdateShopListingInput) => Promise<ShopListing>;
|
|
290
|
+
/**
|
|
291
|
+
* Removes the shop listing for a game item.
|
|
292
|
+
*
|
|
293
|
+
* @param gameId - The game ID
|
|
294
|
+
* @param itemId - The item ID
|
|
295
|
+
* @returns Promise that resolves when listing is removed
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* await client.dev.items.shop.delete('game-123', 'item-456')
|
|
300
|
+
* console.log('Item removed from shop')
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
delete: (gameId: string, itemId: string) => Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Lists all shop listings for a game.
|
|
306
|
+
*
|
|
307
|
+
* @param gameId - The game ID
|
|
308
|
+
* @returns Promise resolving to array of shop listings for the game
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const listings = await client.dev.items.shop.list('game-123')
|
|
313
|
+
* listings.forEach(listing => {
|
|
314
|
+
* console.log(`${listing.item.displayName}: ${listing.price}`)
|
|
315
|
+
* })
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
list: (gameId: string) => Promise<Array<ShopListing & {
|
|
319
|
+
item: Item;
|
|
320
|
+
}>>;
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Game, GameStateData, GameWithManifest, LeaderboardEntry } from '@playcademy/data/types';
|
|
2
|
+
import type { GameTokenResponse, PlaycademyClient, StartSessionResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the games namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for managing games, game state, and game sessions.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Games namespace with fetch, list, state, and session methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createGamesNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Fetches a game by ID or slug, including its manifest data.
|
|
13
|
+
* Combines game metadata with the game's asset manifest.
|
|
14
|
+
*
|
|
15
|
+
* @param gameIdOrSlug - The game ID or slug to fetch
|
|
16
|
+
* @returns Promise resolving to game data with manifest
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const game = await client.games.fetch('my-game-123')
|
|
21
|
+
* console.log('Game title:', game.title)
|
|
22
|
+
* console.log('Assets:', game.manifest.assets)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
fetch: (gameIdOrSlug: string) => Promise<GameWithManifest>;
|
|
26
|
+
/**
|
|
27
|
+
* Lists all available games.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise resolving to array of games
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const games = await client.games.list()
|
|
34
|
+
* games.forEach(game => console.log(game.title))
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
list: () => Promise<Array<Game>>;
|
|
38
|
+
/**
|
|
39
|
+
* Saves the current game state to the server.
|
|
40
|
+
* Requires a gameId to be configured in the client.
|
|
41
|
+
*
|
|
42
|
+
* @param state - The game state object to save
|
|
43
|
+
* @returns Promise that resolves when state is saved
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* await client.games.saveState({
|
|
48
|
+
* level: 5,
|
|
49
|
+
* score: 1250,
|
|
50
|
+
* inventory: ['sword', 'potion']
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
saveState: (state: Record<string, unknown>) => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Loads the saved game state from the server.
|
|
57
|
+
* Requires a gameId to be configured in the client.
|
|
58
|
+
*
|
|
59
|
+
* @returns Promise resolving to the saved game state data
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const state = await client.games.loadState()
|
|
64
|
+
* console.log('Current level:', state.level)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
loadState: () => Promise<GameStateData>;
|
|
68
|
+
/**
|
|
69
|
+
* Starts a new game session.
|
|
70
|
+
*
|
|
71
|
+
* @param gameId - Optional game ID (uses client's gameId if not provided)
|
|
72
|
+
* @returns Promise resolving to session information
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const session = await client.games.startSession('game-123')
|
|
77
|
+
* console.log('Session ID:', session.sessionId)
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
startSession: (gameId?: string) => Promise<StartSessionResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Ends an active game session.
|
|
83
|
+
* Automatically clears internal session tracking if ending the client's own session.
|
|
84
|
+
*
|
|
85
|
+
* @param sessionId - The session ID to end
|
|
86
|
+
* @param gameId - Optional game ID (uses client's gameId if not provided)
|
|
87
|
+
* @returns Promise that resolves when session is ended
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* await client.games.endSession('session-456', 'game-123')
|
|
92
|
+
* console.log('Session ended')
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
endSession: (sessionId: string, gameId?: string) => Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Token management sub-namespace
|
|
98
|
+
*/
|
|
99
|
+
token: {
|
|
100
|
+
/**
|
|
101
|
+
* Creates a game token for the specified game.
|
|
102
|
+
* This method replaces the old runtime.getGameToken() method.
|
|
103
|
+
*
|
|
104
|
+
* @param gameId - The ID of the game to create a token for
|
|
105
|
+
* @param options - Optional configuration
|
|
106
|
+
* @param options.apply - Whether to automatically apply the token to this client
|
|
107
|
+
* @returns Promise resolving to game token response
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Create token without applying it
|
|
112
|
+
* const tokenResponse = await client.games.token.create('game-123')
|
|
113
|
+
*
|
|
114
|
+
* // Create token and apply it to current client
|
|
115
|
+
* const tokenResponse = await client.games.token.create('game-123', { apply: true })
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
create: (gameId: string, options?: {
|
|
119
|
+
apply?: boolean;
|
|
120
|
+
}) => Promise<GameTokenResponse>;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Leaderboard sub-namespace
|
|
124
|
+
*/
|
|
125
|
+
leaderboard: {
|
|
126
|
+
/**
|
|
127
|
+
* Gets the leaderboard for a specific game.
|
|
128
|
+
*
|
|
129
|
+
* @param gameId - The ID of the game to get leaderboard for
|
|
130
|
+
* @param options - Optional query parameters
|
|
131
|
+
* @param options.limit - Maximum number of entries to return
|
|
132
|
+
* @param options.offset - Number of entries to skip
|
|
133
|
+
* @returns Promise resolving to array of leaderboard entries
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Get top 10 scores
|
|
138
|
+
* const leaderboard = await client.games.leaderboard.get('game-123', { limit: 10 })
|
|
139
|
+
*
|
|
140
|
+
* // Get next 10 scores
|
|
141
|
+
* const moreScores = await client.games.leaderboard.get('game-123', { limit: 10, offset: 10 })
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
get: (gameId: string, options?: {
|
|
145
|
+
limit?: number;
|
|
146
|
+
offset?: number;
|
|
147
|
+
}) => Promise<LeaderboardEntry[]>;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { createAuthNamespace } from './auth';
|
|
2
|
+
export { createRuntimeNamespace } from './runtime';
|
|
3
|
+
export { createGamesNamespace } from './games';
|
|
4
|
+
export { createUsersNamespace } from './users';
|
|
5
|
+
export { createDevNamespace } from './dev';
|
|
6
|
+
export { createMapsNamespace } from './maps';
|
|
7
|
+
export { createAdminNamespace } from './admin';
|
|
8
|
+
export { createShopNamespace } from './shop';
|
|
9
|
+
export { createTelemetryNamespace } from './telemetry';
|
|
10
|
+
export { createLevelsNamespace } from './levels';
|
|
11
|
+
export { createCreditsNamespace } from './credits';
|
|
12
|
+
export { createLeaderboardNamespace } from './leaderboard';
|
|
13
|
+
export { createScoresNamespace } from './scores';
|
|
14
|
+
export { createCharacterNamespace } from './character';
|
|
15
|
+
export { createSpritesNamespace } from './sprites';
|
|
16
|
+
export { createRealtimeNamespace } from './realtime';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { GameLeaderboardEntry, LeaderboardOptions, UserRankResponse } from '@playcademy/data/types';
|
|
2
|
+
import type { PlaycademyClient } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the leaderboard namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for accessing game-specific leaderboards.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Leaderboard namespace with fetch methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createLeaderboardNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Fetches the leaderboard for a specific game.
|
|
13
|
+
* Note: gameId is required as cross-game score comparisons are not meaningful.
|
|
14
|
+
*
|
|
15
|
+
* @param options - Query options for the leaderboard (gameId is required)
|
|
16
|
+
* @returns Promise resolving to array of leaderboard entries
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Get top 10 players for a specific game
|
|
21
|
+
* const gameTop10 = await client.leaderboard.fetch({
|
|
22
|
+
* gameId: 'game-123',
|
|
23
|
+
* limit: 10
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // Get weekly leaderboard for a specific game
|
|
27
|
+
* const weeklyGameLeaderboard = await client.leaderboard.fetch({
|
|
28
|
+
* timeframe: 'weekly',
|
|
29
|
+
* gameId: 'game-123'
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
fetch: (options?: LeaderboardOptions) => Promise<GameLeaderboardEntry[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the rank of a specific user within a game's leaderboard.
|
|
36
|
+
*
|
|
37
|
+
* @param gameId - The game ID to get the user's rank for
|
|
38
|
+
* @param userId - The user ID to get the rank for
|
|
39
|
+
* @returns Promise resolving to user rank information
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const userRank = await client.leaderboard.getUserRank('game-123', 'user-456')
|
|
44
|
+
* console.log(`User is rank ${userRank.rank} with score ${userRank.score}`)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
getUserRank: (gameId: string, userId: string) => Promise<UserRankResponse>;
|
|
48
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { LevelConfig, UserLevel, XPAddResult } from '@playcademy/data/types';
|
|
2
|
+
import type { PlaycademyClient } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the levels namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for managing user levels and experience points.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Levels namespace with level and XP methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createLevelsNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current user's level information.
|
|
13
|
+
*
|
|
14
|
+
* @returns Promise resolving to user level data
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const userLevel = await client.levels.get()
|
|
19
|
+
* console.log('Current level:', userLevel.currentLevel)
|
|
20
|
+
* console.log('Current XP:', userLevel.currentXp)
|
|
21
|
+
* console.log('Total XP earned:', userLevel.totalXP)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
get: () => Promise<UserLevel>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the current user's level progress information.
|
|
27
|
+
*
|
|
28
|
+
* @returns Promise resolving to level progress data
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const progress = await client.levels.progress()
|
|
33
|
+
* console.log('Level:', progress.level)
|
|
34
|
+
* console.log('XP to next level:', progress.xpToNextLevel)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
progress: () => Promise<{
|
|
38
|
+
level: number;
|
|
39
|
+
currentXp: number;
|
|
40
|
+
xpToNextLevel: number;
|
|
41
|
+
totalXP: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Adds XP to the current user.
|
|
45
|
+
* Emits 'xpGained' and 'levelUp' events when successful.
|
|
46
|
+
*
|
|
47
|
+
* @param amount - The amount of XP to add (must be positive)
|
|
48
|
+
* @returns Promise resolving to XP addition result
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const result = await client.levels.addXP(100)
|
|
53
|
+
* console.log('New level:', result.newLevel)
|
|
54
|
+
* console.log('Leveled up:', result.leveledUp)
|
|
55
|
+
* console.log('Credits awarded:', result.creditsAwarded)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
addXP: (amount: number) => Promise<XPAddResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration methods for level system.
|
|
61
|
+
*/
|
|
62
|
+
config: {
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves all level configurations (full XP curve).
|
|
65
|
+
*
|
|
66
|
+
* @returns Promise resolving to array of level configurations
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const configs = await client.levels.config.list()
|
|
71
|
+
* configs.forEach(config => {
|
|
72
|
+
* console.log(`Level ${config.level}: ${config.xpRequired} XP, ${config.creditsReward} credits`)
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
list: () => Promise<LevelConfig[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves configuration for a specific level.
|
|
79
|
+
*
|
|
80
|
+
* @param level - The level number to get configuration for
|
|
81
|
+
* @returns Promise resolving to level configuration or null if not found
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const config = await client.levels.config.get(10)
|
|
86
|
+
* if (config) {
|
|
87
|
+
* console.log(`Level 10 requires ${config.xpRequired} XP`)
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
get: (level: number) => Promise<LevelConfig | null>;
|
|
92
|
+
};
|
|
93
|
+
};
|