@playcademy/sdk 0.0.1-beta.9 → 0.0.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 +511 -124
- package/dist/core/auth/flows/popup.d.ts +14 -0
- package/dist/core/auth/flows/redirect.d.ts +15 -0
- package/dist/core/auth/flows/unified.d.ts +11 -0
- package/dist/core/auth/login.d.ts +20 -0
- package/dist/core/auth/oauth.d.ts +115 -0
- package/dist/core/auth/utils.d.ts +23 -0
- package/dist/core/cache/cooldown-cache.d.ts +31 -0
- package/dist/core/cache/index.d.ts +14 -0
- package/dist/core/cache/permanent-cache.d.ts +39 -0
- package/dist/core/cache/singleton-cache.d.ts +29 -0
- package/dist/core/cache/ttl-cache.d.ts +54 -0
- package/dist/core/cache/types.d.ts +23 -0
- package/dist/core/client.d.ts +444 -68
- package/dist/core/namespaces/achievements.d.ts +84 -0
- package/dist/core/namespaces/admin.d.ts +385 -0
- package/dist/core/namespaces/auth.d.ts +54 -0
- package/dist/core/namespaces/character.d.ts +205 -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 +173 -0
- package/dist/core/namespaces/identity.d.ts +91 -0
- package/dist/core/namespaces/index.d.ts +19 -0
- package/dist/core/namespaces/leaderboard.d.ts +48 -0
- package/dist/core/namespaces/levels.d.ts +90 -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 +90 -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 +35 -0
- package/dist/core/namespaces/telemetry.d.ts +28 -0
- package/dist/core/namespaces/timeback.d.ts +111 -0
- package/dist/core/namespaces/users.d.ts +172 -0
- package/dist/core/request.d.ts +1 -1
- package/dist/core/static/identity.d.ts +37 -0
- package/dist/core/static/index.d.ts +3 -0
- package/dist/core/static/init.d.ts +21 -0
- package/dist/core/static/login.d.ts +34 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2846 -0
- package/dist/messaging.d.ts +544 -0
- package/dist/types.d.ts +169 -8
- package/dist/types.js +748 -0
- package/package.json +18 -11
- package/dist/bus.d.ts +0 -37
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -377
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import type { DeveloperStatusValue, Game, InsertItemInput, InsertShopListingInput, Item, ShopListing, UpdateItemInput, UpdateShopListingInput, UpsertGameMetadataInput } from '@playcademy/data/types';
|
|
2
|
+
import type { DevUploadHooks, 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 status methods.
|
|
13
|
+
*/
|
|
14
|
+
status: {
|
|
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.status.apply()
|
|
23
|
+
* console.log('Developer application submitted')
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
apply: () => 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.status.get()
|
|
35
|
+
* if (status === 'approved') {
|
|
36
|
+
* console.log('Developer access granted')
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
get: () => 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 | null, hooks?: DevUploadHooks) => 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,173 @@
|
|
|
1
|
+
import type { FetchedGame, Game, GameStateData, LeaderboardEntry } from '@playcademy/data/types';
|
|
2
|
+
import type { GameTokenResponse, PlaycademyClient, StartSessionResponse } from '../../types';
|
|
3
|
+
import type { TTLCacheConfig } from '../cache/types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates the games namespace for the PlaycademyClient.
|
|
6
|
+
* Provides methods for managing games, game state, and game sessions.
|
|
7
|
+
*
|
|
8
|
+
* @param client - The PlaycademyClient instance
|
|
9
|
+
* @returns Games namespace with fetch, list, state, and session methods
|
|
10
|
+
*/
|
|
11
|
+
export declare function createGamesNamespace(client: PlaycademyClient): {
|
|
12
|
+
/**
|
|
13
|
+
* Fetches a game by ID or slug, including its manifest data for hosted games.
|
|
14
|
+
* For external games, returns the game data without a manifest.
|
|
15
|
+
*
|
|
16
|
+
* @param gameIdOrSlug - The game ID or slug to fetch
|
|
17
|
+
* @param options - Optional cache configuration (TTL/force)
|
|
18
|
+
* @returns Promise resolving to game data (with manifest for hosted games)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const game = await client.games.fetch('my-game-123')
|
|
23
|
+
* console.log('Game title:', game.displayName)
|
|
24
|
+
*
|
|
25
|
+
* // For hosted games:
|
|
26
|
+
* if ('manifest' in game) {
|
|
27
|
+
* console.log('Assets:', game.manifest.assets)
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // For external games:
|
|
31
|
+
* if (game.gameType === 'external') {
|
|
32
|
+
* console.log('External URL:', game.externalUrl)
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
fetch: (gameIdOrSlug: string, options?: TTLCacheConfig) => Promise<FetchedGame>;
|
|
37
|
+
/**
|
|
38
|
+
* Lists all available games.
|
|
39
|
+
* Results are cached for 60 seconds by default.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Optional cache configuration
|
|
42
|
+
* @param options.ttl - Custom TTL in milliseconds (0 to disable caching)
|
|
43
|
+
* @param options.force - Force refresh the cache
|
|
44
|
+
* @returns Promise resolving to array of games
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Use default 60 second cache
|
|
49
|
+
* const games = await client.games.list()
|
|
50
|
+
*
|
|
51
|
+
* // Custom 5 minute cache for dashboard
|
|
52
|
+
* const dashboardGames = await client.games.list({ ttl: 300_000 })
|
|
53
|
+
*
|
|
54
|
+
* // Force refresh on user action
|
|
55
|
+
* const freshGames = await client.games.list({ force: true })
|
|
56
|
+
*
|
|
57
|
+
* // Disable caching for admin panel
|
|
58
|
+
* const uncachedGames = await client.games.list({ ttl: 0 })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
list: (options?: TTLCacheConfig) => Promise<Array<Game>>;
|
|
62
|
+
/**
|
|
63
|
+
* Saves the current game state to the server.
|
|
64
|
+
* Requires a gameId to be configured in the client.
|
|
65
|
+
*
|
|
66
|
+
* @param state - The game state object to save
|
|
67
|
+
* @returns Promise that resolves when state is saved
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* await client.games.saveState({
|
|
72
|
+
* level: 5,
|
|
73
|
+
* score: 1250,
|
|
74
|
+
* inventory: ['sword', 'potion']
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
saveState: (state: Record<string, unknown>) => Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Loads the saved game state from the server.
|
|
81
|
+
* Requires a gameId to be configured in the client.
|
|
82
|
+
*
|
|
83
|
+
* @returns Promise resolving to the saved game state data
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const state = await client.games.loadState()
|
|
88
|
+
* console.log('Current level:', state.level)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
loadState: () => Promise<GameStateData>;
|
|
92
|
+
/**
|
|
93
|
+
* Starts a new game session.
|
|
94
|
+
*
|
|
95
|
+
* @param gameId - Optional game ID (uses client's gameId if not provided)
|
|
96
|
+
* @returns Promise resolving to session information
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const session = await client.games.startSession('game-123')
|
|
101
|
+
* console.log('Session ID:', session.sessionId)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
startSession: (gameId?: string) => Promise<StartSessionResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Ends an active game session.
|
|
107
|
+
* Automatically clears internal session tracking if ending the client's own session.
|
|
108
|
+
*
|
|
109
|
+
* @param sessionId - The session ID to end
|
|
110
|
+
* @param gameId - Optional game ID (uses client's gameId if not provided)
|
|
111
|
+
* @returns Promise that resolves when session is ended
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* await client.games.endSession('session-456', 'game-123')
|
|
116
|
+
* console.log('Session ended')
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
endSession: (sessionId: string, gameId?: string) => Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Token management sub-namespace
|
|
122
|
+
*/
|
|
123
|
+
token: {
|
|
124
|
+
/**
|
|
125
|
+
* Creates a game token for the specified game.
|
|
126
|
+
* This method replaces the old runtime.getGameToken() method.
|
|
127
|
+
*
|
|
128
|
+
* @param gameId - The ID of the game to create a token for
|
|
129
|
+
* @param options - Optional configuration
|
|
130
|
+
* @param options.apply - Whether to automatically apply the token to this client
|
|
131
|
+
* @returns Promise resolving to game token response
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Create token without applying it
|
|
136
|
+
* const tokenResponse = await client.games.token.create('game-123')
|
|
137
|
+
*
|
|
138
|
+
* // Create token and apply it to current client
|
|
139
|
+
* const tokenResponse = await client.games.token.create('game-123', { apply: true })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
create: (gameId: string, options?: {
|
|
143
|
+
apply?: boolean;
|
|
144
|
+
}) => Promise<GameTokenResponse>;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Leaderboard sub-namespace
|
|
148
|
+
*/
|
|
149
|
+
leaderboard: {
|
|
150
|
+
/**
|
|
151
|
+
* Gets the leaderboard for a specific game.
|
|
152
|
+
*
|
|
153
|
+
* @param gameId - The ID of the game to get leaderboard for
|
|
154
|
+
* @param options - Optional query parameters
|
|
155
|
+
* @param options.limit - Maximum number of entries to return
|
|
156
|
+
* @param options.offset - Number of entries to skip
|
|
157
|
+
* @returns Promise resolving to array of leaderboard entries
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Get top 10 scores
|
|
162
|
+
* const leaderboard = await client.games.leaderboard.get('game-123', { limit: 10 })
|
|
163
|
+
*
|
|
164
|
+
* // Get next 10 scores
|
|
165
|
+
* const moreScores = await client.games.leaderboard.get('game-123', { limit: 10, offset: 10 })
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
get: (gameId: string, options?: {
|
|
169
|
+
limit?: number;
|
|
170
|
+
offset?: number;
|
|
171
|
+
}) => Promise<LeaderboardEntry[]>;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { AuthOptions, AuthResult, PlaycademyClient } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the identity namespace for the PlaycademyClient.
|
|
4
|
+
* Provides methods for connecting external identity providers.
|
|
5
|
+
*
|
|
6
|
+
* @param client - The PlaycademyClient instance
|
|
7
|
+
* @returns Identity namespace with connection methods
|
|
8
|
+
*/
|
|
9
|
+
export declare function createIdentityNamespace(client: PlaycademyClient): {
|
|
10
|
+
/**
|
|
11
|
+
* Connects an external identity provider to the user's Playcademy account.
|
|
12
|
+
*
|
|
13
|
+
* For games in iframes: Uses popup flow to avoid navigation issues.
|
|
14
|
+
* For standalone apps: Uses redirect flow for traditional OAuth.
|
|
15
|
+
*
|
|
16
|
+
* @param options - Connection options including provider and callback URL
|
|
17
|
+
* @returns Promise resolving to the connection result
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Connect TimeBack identity
|
|
22
|
+
* const result = await client.identity.connect({
|
|
23
|
+
* provider: AuthProvider.TIMEBACK,
|
|
24
|
+
* callbackUrl: 'https://myapp.com/api/auth/callback',
|
|
25
|
+
* onStateChange: (state) => {
|
|
26
|
+
* console.log('Connection state:', state.message)
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* if (result.success) {
|
|
31
|
+
* console.log('Connected as:', result.user.email)
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Force popup mode even in standalone context
|
|
38
|
+
* const result = await client.identity.connect({
|
|
39
|
+
* provider: AuthProvider.TIMEBACK,
|
|
40
|
+
* callbackUrl: 'https://myapp.com/api/auth/callback',
|
|
41
|
+
* mode: 'popup'
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Provide custom OAuth configuration for external games
|
|
48
|
+
* const result = await client.identity.connect({
|
|
49
|
+
* provider: AuthProvider.TIMEBACK,
|
|
50
|
+
* callbackUrl: 'https://myapp.com/api/auth/callback',
|
|
51
|
+
* oauth: {
|
|
52
|
+
* clientId: 'my-oauth-client-id',
|
|
53
|
+
* // Optional: override default endpoints
|
|
54
|
+
* authorizationEndpoint: 'https://custom-idp.com/oauth2/authorize',
|
|
55
|
+
* tokenEndpoint: 'https://custom-idp.com/oauth2/token',
|
|
56
|
+
* scope: 'openid email profile custom_scope'
|
|
57
|
+
* }
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // The SDK automatically includes Playcademy user ID in the OAuth state
|
|
64
|
+
* const result = await client.identity.connect({
|
|
65
|
+
* provider: AuthProvider.TIMEBACK,
|
|
66
|
+
* callbackUrl: 'https://myapp.com/api/auth/callback'
|
|
67
|
+
* })
|
|
68
|
+
*
|
|
69
|
+
* // On your server callback, parse the state to get the user ID:
|
|
70
|
+
* import { PlaycademyClient } from '@playcademy/sdk'
|
|
71
|
+
*
|
|
72
|
+
* app.get('/api/auth/callback', async (req, res) => {
|
|
73
|
+
* const { csrfToken, data } = PlaycademyClient.identity.parseOAuthState(req.query.state)
|
|
74
|
+
* const playcademyUserId = data?.playcademy_user_id
|
|
75
|
+
* const gameId = data?.game_id
|
|
76
|
+
*
|
|
77
|
+
* // Now you can associate the OAuth user with the Playcademy user
|
|
78
|
+
* await linkAccounts(oauthUserId, playcademyUserId)
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
connect: (options: AuthOptions) => Promise<AuthResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the current identity connection context (for internal use).
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
_getContext: () => {
|
|
89
|
+
isInIframe: boolean;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { createAuthNamespace } from './auth';
|
|
2
|
+
export { createIdentityNamespace } from './identity';
|
|
3
|
+
export { createRuntimeNamespace } from './runtime';
|
|
4
|
+
export { createGamesNamespace } from './games';
|
|
5
|
+
export { createUsersNamespace } from './users';
|
|
6
|
+
export { createDevNamespace } from './dev';
|
|
7
|
+
export { createMapsNamespace } from './maps';
|
|
8
|
+
export { createAdminNamespace } from './admin';
|
|
9
|
+
export { createShopNamespace } from './shop';
|
|
10
|
+
export { createTelemetryNamespace } from './telemetry';
|
|
11
|
+
export { createLevelsNamespace } from './levels';
|
|
12
|
+
export { createCreditsNamespace } from './credits';
|
|
13
|
+
export { createLeaderboardNamespace } from './leaderboard';
|
|
14
|
+
export { createScoresNamespace } from './scores';
|
|
15
|
+
export { createCharacterNamespace } from './character';
|
|
16
|
+
export { createSpritesNamespace } from './sprites';
|
|
17
|
+
export { createRealtimeNamespace } from './realtime';
|
|
18
|
+
export { createAchievementsNamespace } from './achievements';
|
|
19
|
+
export { createTimebackNamespace } from './timeback';
|
|
@@ -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
|
+
};
|