@playcademy/sdk 0.0.1-beta.2 → 0.0.1-beta.21

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.
@@ -0,0 +1,377 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ import type { InsertItem, UpdateItem, InsertCurrency, UpdateCurrency, InsertShopListing, UpdateShopListing } from '../../types';
3
+ /**
4
+ * Creates the admin namespace for the PlaycademyClient.
5
+ * Provides administrative methods for managing games, items, currencies, and shop listings.
6
+ * Requires admin privileges to access these endpoints.
7
+ *
8
+ * @param client - The PlaycademyClient instance
9
+ * @returns Admin namespace with game, item, currency, and shop listing management methods
10
+ */
11
+ export declare function createAdminNamespace(client: PlaycademyClient): {
12
+ /**
13
+ * Game administration methods.
14
+ */
15
+ games: {
16
+ /**
17
+ * Pauses a game, preventing new sessions from starting.
18
+ *
19
+ * @param gameId - The ID of the game to pause
20
+ * @returns Promise that resolves when game is paused
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * await client.admin.games.pauseGame('game-123')
25
+ * console.log('Game paused for maintenance')
26
+ * ```
27
+ */
28
+ pauseGame: (gameId: string) => Promise<void>;
29
+ /**
30
+ * Resumes a paused game, allowing new sessions to start.
31
+ *
32
+ * @param gameId - The ID of the game to resume
33
+ * @returns Promise that resolves when game is resumed
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * await client.admin.games.resumeGame('game-123')
38
+ * console.log('Game resumed')
39
+ * ```
40
+ */
41
+ resumeGame: (gameId: string) => Promise<void>;
42
+ };
43
+ /**
44
+ * Item management methods for administrators.
45
+ */
46
+ items: {
47
+ /**
48
+ * Creates a new item in the system.
49
+ *
50
+ * @param props - Item properties for creation
51
+ * @returns Promise resolving to the created item
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const item = await client.admin.items.create({
56
+ * name: 'Magic Sword',
57
+ * description: 'A powerful weapon',
58
+ * rarity: 'legendary'
59
+ * })
60
+ * ```
61
+ */
62
+ create: (props: InsertItem) => Promise<{
63
+ id: string;
64
+ displayName: string;
65
+ metadata: unknown;
66
+ createdAt: Date;
67
+ internalName: string;
68
+ description: string | null;
69
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
70
+ imageUrl: string | null;
71
+ }>;
72
+ /**
73
+ * Retrieves a specific item by ID.
74
+ *
75
+ * @param itemId - The ID of the item to retrieve
76
+ * @returns Promise resolving to the item data
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const item = await client.admin.items.get('item-123')
81
+ * console.log('Item name:', item.name)
82
+ * ```
83
+ */
84
+ get: (itemId: string) => Promise<{
85
+ id: string;
86
+ displayName: string;
87
+ metadata: unknown;
88
+ createdAt: Date;
89
+ internalName: string;
90
+ description: string | null;
91
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
92
+ imageUrl: string | null;
93
+ }>;
94
+ /**
95
+ * Lists all items in the system.
96
+ *
97
+ * @returns Promise resolving to array of all items
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const items = await client.admin.items.list()
102
+ * console.log(`Found ${items.length} items`)
103
+ * ```
104
+ */
105
+ list: () => Promise<{
106
+ id: string;
107
+ displayName: string;
108
+ metadata: unknown;
109
+ createdAt: Date;
110
+ internalName: string;
111
+ description: string | null;
112
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
113
+ imageUrl: string | null;
114
+ }[]>;
115
+ /**
116
+ * Updates an existing item.
117
+ *
118
+ * @param itemId - The ID of the item to update
119
+ * @param props - Properties to update
120
+ * @returns Promise resolving to the updated item
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const updatedItem = await client.admin.items.update('item-123', {
125
+ * name: 'Enhanced Magic Sword'
126
+ * })
127
+ * ```
128
+ */
129
+ update: (itemId: string, props: UpdateItem) => Promise<{
130
+ id: string;
131
+ displayName: string;
132
+ metadata: unknown;
133
+ createdAt: Date;
134
+ internalName: string;
135
+ description: string | null;
136
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
137
+ imageUrl: string | null;
138
+ }>;
139
+ /**
140
+ * Deletes an item from the system.
141
+ *
142
+ * @param itemId - The ID of the item to delete
143
+ * @returns Promise that resolves when item is deleted
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * await client.admin.items.delete('item-123')
148
+ * console.log('Item deleted')
149
+ * ```
150
+ */
151
+ delete: (itemId: string) => Promise<void>;
152
+ };
153
+ /**
154
+ * Currency management methods for administrators.
155
+ */
156
+ currencies: {
157
+ /**
158
+ * Creates a new currency in the system.
159
+ *
160
+ * @param props - Currency properties for creation
161
+ * @returns Promise resolving to the created currency
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const currency = await client.admin.currencies.create({
166
+ * name: 'Gold Coins',
167
+ * symbol: 'GC',
168
+ * decimals: 0
169
+ * })
170
+ * ```
171
+ */
172
+ create: (props: InsertCurrency) => Promise<{
173
+ symbol: string | null;
174
+ id: string;
175
+ createdAt: Date;
176
+ updatedAt: Date | null;
177
+ itemId: string;
178
+ isPrimary: boolean;
179
+ }>;
180
+ /**
181
+ * Retrieves a specific currency by ID.
182
+ *
183
+ * @param currencyId - The ID of the currency to retrieve
184
+ * @returns Promise resolving to the currency data
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const currency = await client.admin.currencies.get('currency-123')
189
+ * console.log('Currency symbol:', currency.symbol)
190
+ * ```
191
+ */
192
+ get: (currencyId: string) => Promise<{
193
+ symbol: string | null;
194
+ id: string;
195
+ createdAt: Date;
196
+ updatedAt: Date | null;
197
+ itemId: string;
198
+ isPrimary: boolean;
199
+ }>;
200
+ /**
201
+ * Lists all currencies in the system.
202
+ *
203
+ * @returns Promise resolving to array of all currencies
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const currencies = await client.admin.currencies.list()
208
+ * currencies.forEach(c => console.log(`${c.name}: ${c.symbol}`))
209
+ * ```
210
+ */
211
+ list: () => Promise<{
212
+ symbol: string | null;
213
+ id: string;
214
+ createdAt: Date;
215
+ updatedAt: Date | null;
216
+ itemId: string;
217
+ isPrimary: boolean;
218
+ }[]>;
219
+ /**
220
+ * Updates an existing currency.
221
+ *
222
+ * @param currencyId - The ID of the currency to update
223
+ * @param props - Properties to update
224
+ * @returns Promise resolving to the updated currency
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const updatedCurrency = await client.admin.currencies.update('currency-123', {
229
+ * name: 'Premium Gold Coins'
230
+ * })
231
+ * ```
232
+ */
233
+ update: (currencyId: string, props: UpdateCurrency) => Promise<{
234
+ symbol: string | null;
235
+ id: string;
236
+ createdAt: Date;
237
+ updatedAt: Date | null;
238
+ itemId: string;
239
+ isPrimary: boolean;
240
+ }>;
241
+ /**
242
+ * Deletes a currency from the system.
243
+ *
244
+ * @param currencyId - The ID of the currency to delete
245
+ * @returns Promise that resolves when currency is deleted
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * await client.admin.currencies.delete('currency-123')
250
+ * console.log('Currency deleted')
251
+ * ```
252
+ */
253
+ delete: (currencyId: string) => Promise<void>;
254
+ };
255
+ /**
256
+ * Shop listing management methods for administrators.
257
+ */
258
+ shopListings: {
259
+ /**
260
+ * Creates a new shop listing.
261
+ *
262
+ * @param props - Shop listing properties for creation
263
+ * @returns Promise resolving to the created shop listing
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const listing = await client.admin.shopListings.create({
268
+ * itemId: 'item-123',
269
+ * price: 100,
270
+ * currencyId: 'currency-456'
271
+ * })
272
+ * ```
273
+ */
274
+ create: (props: InsertShopListing) => Promise<{
275
+ id: string;
276
+ createdAt: Date;
277
+ updatedAt: Date | null;
278
+ itemId: string;
279
+ currencyId: string;
280
+ price: number;
281
+ sellBackPercentage: number | null;
282
+ stock: number | null;
283
+ isActive: boolean;
284
+ availableFrom: Date | null;
285
+ availableUntil: Date | null;
286
+ }>;
287
+ /**
288
+ * Retrieves a specific shop listing by ID.
289
+ *
290
+ * @param listingId - The ID of the shop listing to retrieve
291
+ * @returns Promise resolving to the shop listing data
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const listing = await client.admin.shopListings.get('listing-123')
296
+ * console.log('Listing price:', listing.price)
297
+ * ```
298
+ */
299
+ get: (listingId: string) => Promise<{
300
+ id: string;
301
+ createdAt: Date;
302
+ updatedAt: Date | null;
303
+ itemId: string;
304
+ currencyId: string;
305
+ price: number;
306
+ sellBackPercentage: number | null;
307
+ stock: number | null;
308
+ isActive: boolean;
309
+ availableFrom: Date | null;
310
+ availableUntil: Date | null;
311
+ }>;
312
+ /**
313
+ * Lists all shop listings in the system.
314
+ *
315
+ * @returns Promise resolving to array of all shop listings
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const listings = await client.admin.shopListings.list()
320
+ * console.log(`Found ${listings.length} shop listings`)
321
+ * ```
322
+ */
323
+ list: () => Promise<{
324
+ id: string;
325
+ createdAt: Date;
326
+ updatedAt: Date | null;
327
+ itemId: string;
328
+ currencyId: string;
329
+ price: number;
330
+ sellBackPercentage: number | null;
331
+ stock: number | null;
332
+ isActive: boolean;
333
+ availableFrom: Date | null;
334
+ availableUntil: Date | null;
335
+ }[]>;
336
+ /**
337
+ * Updates an existing shop listing.
338
+ *
339
+ * @param listingId - The ID of the shop listing to update
340
+ * @param props - Properties to update
341
+ * @returns Promise resolving to the updated shop listing
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * const updatedListing = await client.admin.shopListings.update('listing-123', {
346
+ * price: 150
347
+ * })
348
+ * ```
349
+ */
350
+ update: (listingId: string, props: UpdateShopListing) => Promise<{
351
+ id: string;
352
+ createdAt: Date;
353
+ updatedAt: Date | null;
354
+ itemId: string;
355
+ currencyId: string;
356
+ price: number;
357
+ sellBackPercentage: number | null;
358
+ stock: number | null;
359
+ isActive: boolean;
360
+ availableFrom: Date | null;
361
+ availableUntil: Date | null;
362
+ }>;
363
+ /**
364
+ * Deletes a shop listing from the system.
365
+ *
366
+ * @param listingId - The ID of the shop listing to delete
367
+ * @returns Promise that resolves when shop listing is deleted
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * await client.admin.shopListings.delete('listing-123')
372
+ * console.log('Shop listing deleted')
373
+ * ```
374
+ */
375
+ delete: (listingId: string) => Promise<void>;
376
+ };
377
+ };
@@ -0,0 +1,23 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ /**
3
+ * Creates the authentication namespace for the PlaycademyClient.
4
+ * Provides methods for managing user authentication state.
5
+ *
6
+ * @param client - The PlaycademyClient instance
7
+ * @returns Authentication namespace with logout method
8
+ */
9
+ export declare function createAuthNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * Logs out the current user and clears the authentication token.
12
+ * Sends a logout request to the server and removes the token from the client.
13
+ *
14
+ * @returns Promise that resolves when logout is complete
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * await client.auth.logout()
19
+ * console.log('User logged out successfully')
20
+ * ```
21
+ */
22
+ logout: () => Promise<void>;
23
+ };
@@ -0,0 +1,152 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ import type { Game, UpsertGameMetadataInput } from '@playcademy/types';
3
+ import type { DeveloperStatusValue } from '../../types';
4
+ /**
5
+ * Creates the developer namespace for the PlaycademyClient.
6
+ * Provides methods for developer account management, game publishing, and API key management.
7
+ *
8
+ * @param client - The PlaycademyClient instance
9
+ * @returns Developer namespace with auth, games, and keys methods
10
+ */
11
+ export declare function createDevNamespace(client: PlaycademyClient): {
12
+ /**
13
+ * Developer authentication and status methods.
14
+ */
15
+ auth: {
16
+ /**
17
+ * Applies for developer status for the current user.
18
+ *
19
+ * @returns Promise that resolves when application is submitted
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * await client.dev.auth.applyForDeveloper()
24
+ * console.log('Developer application submitted')
25
+ * ```
26
+ */
27
+ applyForDeveloper: () => Promise<void>;
28
+ /**
29
+ * Gets the current developer status for the user.
30
+ *
31
+ * @returns Promise resolving to developer status value
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const status = await client.dev.auth.getDeveloperStatus()
36
+ * if (status === 'approved') {
37
+ * console.log('Developer access granted')
38
+ * }
39
+ * ```
40
+ */
41
+ getDeveloperStatus: () => Promise<DeveloperStatusValue>;
42
+ };
43
+ /**
44
+ * Game management methods for developers.
45
+ */
46
+ games: {
47
+ /**
48
+ * Creates or updates a game with metadata and asset bundle.
49
+ *
50
+ * @param slug - The game slug (URL-friendly identifier)
51
+ * @param metadata - Game metadata (title, description, etc.)
52
+ * @param file - Game asset bundle file (zip)
53
+ * @returns Promise resolving to the created/updated game
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const gameFile = new File([zipData], 'game.zip')
58
+ * const game = await client.dev.games.upsert('my-game', {
59
+ * title: 'My Awesome Game',
60
+ * 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 a game.
101
+ *
102
+ * @param gameId - The game ID to create a key for
103
+ * @param label - Optional label for the key
104
+ * @returns Promise resolving to the created API key
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const key = await client.dev.keys.createKey('game-123', 'Production Key')
109
+ * console.log('API Key:', key.key)
110
+ * ```
111
+ */
112
+ createKey: (gameId: string, label?: string) => Promise<{
113
+ id: string;
114
+ createdAt: Date;
115
+ userId: string;
116
+ label: string | null;
117
+ keyHash: string;
118
+ }>;
119
+ /**
120
+ * Lists all API keys for a game.
121
+ *
122
+ * @param gameId - The game ID to list keys for
123
+ * @returns Promise resolving to array of API keys
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const keys = await client.dev.keys.listKeys('game-123')
128
+ * keys.forEach(key => console.log(`${key.label}: ${key.key}`))
129
+ * ```
130
+ */
131
+ listKeys: (gameId: string) => Promise<{
132
+ id: string;
133
+ createdAt: Date;
134
+ userId: string;
135
+ label: string | null;
136
+ keyHash: string;
137
+ }[]>;
138
+ /**
139
+ * Revokes (deletes) an API key.
140
+ *
141
+ * @param keyId - The key ID to revoke
142
+ * @returns Promise that resolves when key is revoked
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * await client.dev.keys.revokeKey('key-456')
147
+ * console.log('API key revoked')
148
+ * ```
149
+ */
150
+ revokeKey: (keyId: string) => Promise<void>;
151
+ };
152
+ };
@@ -0,0 +1,97 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ import type { Game, GameWithManifest } from '@playcademy/types';
3
+ import type { GameState, StartSessionResponse } from '../../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.
14
+ * Combines game metadata with the game's asset manifest.
15
+ *
16
+ * @param gameIdOrSlug - The game ID or slug to fetch
17
+ * @returns Promise resolving to game data with manifest
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const game = await client.games.fetch('my-game-123')
22
+ * console.log('Game title:', game.title)
23
+ * console.log('Assets:', game.manifest.assets)
24
+ * ```
25
+ */
26
+ fetch: (gameIdOrSlug: string) => Promise<GameWithManifest>;
27
+ /**
28
+ * Lists all available games.
29
+ *
30
+ * @returns Promise resolving to array of games
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const games = await client.games.list()
35
+ * games.forEach(game => console.log(game.title))
36
+ * ```
37
+ */
38
+ list: () => Promise<Array<Game>>;
39
+ /**
40
+ * Saves the current game state to the server.
41
+ * Requires a gameId to be configured in the client.
42
+ *
43
+ * @param state - The game state object to save
44
+ * @returns Promise that resolves when state is saved
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * await client.games.saveState({
49
+ * level: 5,
50
+ * score: 1250,
51
+ * inventory: ['sword', 'potion']
52
+ * })
53
+ * ```
54
+ */
55
+ saveState: (state: Record<string, unknown>) => Promise<void>;
56
+ /**
57
+ * Loads the saved game state from the server.
58
+ * Requires a gameId to be configured in the client.
59
+ *
60
+ * @returns Promise resolving to the saved game state
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const state = await client.games.loadState()
65
+ * console.log('Current level:', state.level)
66
+ * ```
67
+ */
68
+ loadState: () => Promise<GameState>;
69
+ /**
70
+ * Starts a new game session.
71
+ *
72
+ * @param gameId - Optional game ID (uses client's gameId if not provided)
73
+ * @returns Promise resolving to session information
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const session = await client.games.startSession('game-123')
78
+ * console.log('Session ID:', session.sessionId)
79
+ * ```
80
+ */
81
+ startSession: (gameId?: string) => Promise<StartSessionResponse>;
82
+ /**
83
+ * Ends an active game session.
84
+ * Automatically clears internal session tracking if ending the client's own session.
85
+ *
86
+ * @param sessionId - The session ID to end
87
+ * @param gameId - Optional game ID (uses client's gameId if not provided)
88
+ * @returns Promise that resolves when session is ended
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * await client.games.endSession('session-456', 'game-123')
93
+ * console.log('Session ended')
94
+ * ```
95
+ */
96
+ endSession: (sessionId: string, gameId?: string) => Promise<void>;
97
+ };
@@ -0,0 +1,9 @@
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';
@@ -0,0 +1,37 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ /**
3
+ * Creates the maps namespace for the PlaycademyClient.
4
+ * Provides methods for retrieving map data and elements.
5
+ *
6
+ * @param client - The PlaycademyClient instance
7
+ * @returns Maps namespace with element retrieval methods
8
+ */
9
+ export declare function createMapsNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * Retrieves all elements for a specific map.
12
+ *
13
+ * @param mapId - The ID of the map to get elements for
14
+ * @returns Promise resolving to array of map elements
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const elements = await client.maps.elements('map-123')
19
+ * elements.forEach(element => {
20
+ * console.log(`Element: ${element.type} at (${element.x}, ${element.y})`)
21
+ * })
22
+ * ```
23
+ */
24
+ elements: (mapId: string) => Promise<{
25
+ id: string;
26
+ metadata: ({
27
+ description?: string | undefined;
28
+ sourceTiledObjects?: Record<string, unknown>[] | undefined;
29
+ } & {
30
+ [k: string]: unknown;
31
+ }) | null;
32
+ gameId: string | null;
33
+ mapId: string | null;
34
+ elementSlug: string;
35
+ interactionType: "game_entry" | "game_registry" | "info" | "teleport" | "door_in" | "door_out" | "npc_interaction" | "quest_trigger";
36
+ }[]>;
37
+ };