@playcademy/sdk 0.0.1-beta.3 → 0.0.1-beta.30

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,385 @@
1
+ import type { InsertCurrencyInput, InsertItemInput, InsertShopListingInput, UpdateCurrencyInput, UpdateItemInput, UpdateShopListingInput } from '@playcademy/data/types';
2
+ import type { PlaycademyClient } 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: InsertItemInput) => Promise<{
63
+ id: string;
64
+ createdAt: Date;
65
+ slug: string;
66
+ displayName: string;
67
+ metadata: unknown;
68
+ gameId: string | null;
69
+ description: string | null;
70
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
71
+ isPlaceable: boolean;
72
+ imageUrl: string | null;
73
+ }>;
74
+ /**
75
+ * Retrieves a specific item by ID.
76
+ *
77
+ * @param itemId - The ID of the item to retrieve
78
+ * @returns Promise resolving to the item data
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const item = await client.admin.items.get('item-123')
83
+ * console.log('Item name:', item.name)
84
+ * ```
85
+ */
86
+ get: (itemId: string) => Promise<{
87
+ id: string;
88
+ createdAt: Date;
89
+ slug: string;
90
+ displayName: string;
91
+ metadata: unknown;
92
+ gameId: string | null;
93
+ description: string | null;
94
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
95
+ isPlaceable: boolean;
96
+ imageUrl: string | null;
97
+ }>;
98
+ /**
99
+ * Lists all items in the system.
100
+ *
101
+ * @returns Promise resolving to array of all items
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const items = await client.admin.items.list()
106
+ * console.log(`Found ${items.length} items`)
107
+ * ```
108
+ */
109
+ list: () => Promise<{
110
+ id: string;
111
+ createdAt: Date;
112
+ slug: string;
113
+ displayName: string;
114
+ metadata: unknown;
115
+ gameId: string | null;
116
+ description: string | null;
117
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
118
+ isPlaceable: boolean;
119
+ imageUrl: string | null;
120
+ }[]>;
121
+ /**
122
+ * Updates an existing item.
123
+ *
124
+ * @param itemId - The ID of the item to update
125
+ * @param props - Properties to update
126
+ * @returns Promise resolving to the updated item
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const updatedItem = await client.admin.items.update('item-123', {
131
+ * name: 'Enhanced Magic Sword'
132
+ * })
133
+ * ```
134
+ */
135
+ update: (itemId: string, props: UpdateItemInput) => Promise<{
136
+ id: string;
137
+ createdAt: Date;
138
+ slug: string;
139
+ displayName: string;
140
+ metadata: unknown;
141
+ gameId: string | null;
142
+ description: string | null;
143
+ type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
144
+ isPlaceable: boolean;
145
+ imageUrl: string | null;
146
+ }>;
147
+ /**
148
+ * Deletes an item from the system.
149
+ *
150
+ * @param itemId - The ID of the item to delete
151
+ * @returns Promise that resolves when item is deleted
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * await client.admin.items.delete('item-123')
156
+ * console.log('Item deleted')
157
+ * ```
158
+ */
159
+ delete: (itemId: string) => Promise<void>;
160
+ };
161
+ /**
162
+ * Currency management methods for administrators.
163
+ */
164
+ currencies: {
165
+ /**
166
+ * Creates a new currency in the system.
167
+ *
168
+ * @param props - Currency properties for creation
169
+ * @returns Promise resolving to the created currency
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const currency = await client.admin.currencies.create({
174
+ * name: 'Gold Coins',
175
+ * symbol: 'GC',
176
+ * decimals: 0
177
+ * })
178
+ * ```
179
+ */
180
+ create: (props: InsertCurrencyInput) => Promise<{
181
+ symbol: string | null;
182
+ id: string;
183
+ createdAt: Date;
184
+ updatedAt: Date | null;
185
+ itemId: string;
186
+ isPrimary: boolean;
187
+ }>;
188
+ /**
189
+ * Retrieves a specific currency by ID.
190
+ *
191
+ * @param currencyId - The ID of the currency to retrieve
192
+ * @returns Promise resolving to the currency data
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const currency = await client.admin.currencies.get('currency-123')
197
+ * console.log('Currency symbol:', currency.symbol)
198
+ * ```
199
+ */
200
+ get: (currencyId: string) => Promise<{
201
+ symbol: string | null;
202
+ id: string;
203
+ createdAt: Date;
204
+ updatedAt: Date | null;
205
+ itemId: string;
206
+ isPrimary: boolean;
207
+ }>;
208
+ /**
209
+ * Lists all currencies in the system.
210
+ *
211
+ * @returns Promise resolving to array of all currencies
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const currencies = await client.admin.currencies.list()
216
+ * currencies.forEach(c => console.log(`${c.name}: ${c.symbol}`))
217
+ * ```
218
+ */
219
+ list: () => Promise<{
220
+ symbol: string | null;
221
+ id: string;
222
+ createdAt: Date;
223
+ updatedAt: Date | null;
224
+ itemId: string;
225
+ isPrimary: boolean;
226
+ }[]>;
227
+ /**
228
+ * Updates an existing currency.
229
+ *
230
+ * @param currencyId - The ID of the currency to update
231
+ * @param props - Properties to update
232
+ * @returns Promise resolving to the updated currency
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const updatedCurrency = await client.admin.currencies.update('currency-123', {
237
+ * name: 'Premium Gold Coins'
238
+ * })
239
+ * ```
240
+ */
241
+ update: (currencyId: string, props: UpdateCurrencyInput) => Promise<{
242
+ symbol: string | null;
243
+ id: string;
244
+ createdAt: Date;
245
+ updatedAt: Date | null;
246
+ itemId: string;
247
+ isPrimary: boolean;
248
+ }>;
249
+ /**
250
+ * Deletes a currency from the system.
251
+ *
252
+ * @param currencyId - The ID of the currency to delete
253
+ * @returns Promise that resolves when currency is deleted
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * await client.admin.currencies.delete('currency-123')
258
+ * console.log('Currency deleted')
259
+ * ```
260
+ */
261
+ delete: (currencyId: string) => Promise<void>;
262
+ };
263
+ /**
264
+ * Shop listing management methods for administrators.
265
+ */
266
+ shopListings: {
267
+ /**
268
+ * Creates a new shop listing.
269
+ *
270
+ * @param props - Shop listing properties for creation
271
+ * @returns Promise resolving to the created shop listing
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * const listing = await client.admin.shopListings.create({
276
+ * itemId: 'item-123',
277
+ * price: 100,
278
+ * currencyId: 'currency-456'
279
+ * })
280
+ * ```
281
+ */
282
+ create: (props: InsertShopListingInput) => Promise<{
283
+ id: string;
284
+ createdAt: Date;
285
+ updatedAt: Date | null;
286
+ itemId: string;
287
+ currencyId: string;
288
+ price: number;
289
+ sellBackPercentage: number | null;
290
+ stock: number | null;
291
+ isActive: boolean;
292
+ availableFrom: Date | null;
293
+ availableUntil: Date | null;
294
+ }>;
295
+ /**
296
+ * Retrieves a specific shop listing by ID.
297
+ *
298
+ * @param listingId - The ID of the shop listing to retrieve
299
+ * @returns Promise resolving to the shop listing data
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * const listing = await client.admin.shopListings.get('listing-123')
304
+ * console.log('Listing price:', listing.price)
305
+ * ```
306
+ */
307
+ get: (listingId: string) => Promise<{
308
+ id: string;
309
+ createdAt: Date;
310
+ updatedAt: Date | null;
311
+ itemId: string;
312
+ currencyId: string;
313
+ price: number;
314
+ sellBackPercentage: number | null;
315
+ stock: number | null;
316
+ isActive: boolean;
317
+ availableFrom: Date | null;
318
+ availableUntil: Date | null;
319
+ }>;
320
+ /**
321
+ * Lists all shop listings in the system.
322
+ *
323
+ * @returns Promise resolving to array of all shop listings
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const listings = await client.admin.shopListings.list()
328
+ * console.log(`Found ${listings.length} shop listings`)
329
+ * ```
330
+ */
331
+ list: () => Promise<{
332
+ id: string;
333
+ createdAt: Date;
334
+ updatedAt: Date | null;
335
+ itemId: string;
336
+ currencyId: string;
337
+ price: number;
338
+ sellBackPercentage: number | null;
339
+ stock: number | null;
340
+ isActive: boolean;
341
+ availableFrom: Date | null;
342
+ availableUntil: Date | null;
343
+ }[]>;
344
+ /**
345
+ * Updates an existing shop listing.
346
+ *
347
+ * @param listingId - The ID of the shop listing to update
348
+ * @param props - Properties to update
349
+ * @returns Promise resolving to the updated shop listing
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * const updatedListing = await client.admin.shopListings.update('listing-123', {
354
+ * price: 150
355
+ * })
356
+ * ```
357
+ */
358
+ update: (listingId: string, props: UpdateShopListingInput) => Promise<{
359
+ id: string;
360
+ createdAt: Date;
361
+ updatedAt: Date | null;
362
+ itemId: string;
363
+ currencyId: string;
364
+ price: number;
365
+ sellBackPercentage: number | null;
366
+ stock: number | null;
367
+ isActive: boolean;
368
+ availableFrom: Date | null;
369
+ availableUntil: Date | null;
370
+ }>;
371
+ /**
372
+ * Deletes a shop listing from the system.
373
+ *
374
+ * @param listingId - The ID of the shop listing to delete
375
+ * @returns Promise that resolves when shop listing is deleted
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * await client.admin.shopListings.delete('listing-123')
380
+ * console.log('Shop listing deleted')
381
+ * ```
382
+ */
383
+ delete: (listingId: string) => Promise<void>;
384
+ };
385
+ };
@@ -0,0 +1,23 @@
1
+ import type { PlaycademyClient } from '../../types';
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,146 @@
1
+ import type { CharacterComponentWithSpriteUrl, PlayerCharacter } from '@playcademy/data/types';
2
+ import type { PlaycademyClient } from '../../types';
3
+ export interface CharacterComponentsOptions {
4
+ /**
5
+ * Optional level filter for components
6
+ * When provided, only components available at this level or below are returned
7
+ */
8
+ level?: number;
9
+ /**
10
+ * Whether to bypass the cache and force a fresh API request
11
+ * Default: false (use cache when available)
12
+ */
13
+ skipCache?: boolean;
14
+ }
15
+ export interface CreateCharacterData {
16
+ bodyComponentId: string;
17
+ eyesComponentId: string;
18
+ hairstyleComponentId: string;
19
+ outfitComponentId: string;
20
+ accessoryComponentId?: string | null;
21
+ }
22
+ export interface UpdateCharacterData {
23
+ bodyComponentId?: string;
24
+ eyesComponentId?: string;
25
+ hairstyleComponentId?: string;
26
+ outfitComponentId?: string;
27
+ accessoryComponentId?: string | null;
28
+ }
29
+ /**
30
+ * Creates the character namespace for the PlaycademyClient.
31
+ * Provides methods for managing player character configuration and components.
32
+ *
33
+ * @param client - The PlaycademyClient instance
34
+ * @returns Character namespace with get, create, update, and components methods
35
+ */
36
+ export declare function createCharacterNamespace(client: PlaycademyClient): {
37
+ /**
38
+ * Gets a player character configuration.
39
+ *
40
+ * @param userId - Optional user ID. If omitted, gets the current user's character
41
+ * @returns Promise resolving to player character data or null if no character exists
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Get current user's character
46
+ * const myCharacter = await client.character.get()
47
+ *
48
+ * // Get a specific user's character
49
+ * const otherCharacter = await client.character.get('user-123')
50
+ *
51
+ * if (myCharacter) {
52
+ * console.log('My character body:', myCharacter.bodyComponentId)
53
+ * }
54
+ * ```
55
+ */
56
+ get: (userId?: string) => Promise<PlayerCharacter | null>;
57
+ /**
58
+ * Creates a new player character.
59
+ *
60
+ * @param characterData - The character configuration data
61
+ * @returns Promise resolving to the created player character
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const character = await client.character.create({
66
+ * bodyComponentId: 'body-1',
67
+ * eyesComponentId: 'eyes-2',
68
+ * hairstyleComponentId: 'hair-3',
69
+ * outfitComponentId: 'outfit-4',
70
+ * accessoryComponentId: 'accessory-5'
71
+ * })
72
+ * console.log('Character created:', character.id)
73
+ * ```
74
+ */
75
+ create: (characterData: CreateCharacterData) => Promise<PlayerCharacter>;
76
+ /**
77
+ * Updates an existing player character.
78
+ *
79
+ * @param updates - Partial character data to update
80
+ * @returns Promise resolving to the updated player character
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const updatedCharacter = await client.character.update({
85
+ * hairstyleComponentId: 'new-hair-style',
86
+ * outfitComponentId: 'new-outfit'
87
+ * })
88
+ * console.log('Character updated:', updatedCharacter.id)
89
+ * ```
90
+ */
91
+ update: (updates: UpdateCharacterData) => Promise<PlayerCharacter>;
92
+ /**
93
+ * Character components sub-namespace
94
+ */
95
+ components: {
96
+ /**
97
+ * Lists available character components with optional level filtering.
98
+ * Results are cached in-memory by level to reduce API calls.
99
+ *
100
+ * @param options - Optional filtering options
101
+ * @param options.level - Filter components by required level
102
+ * @param options.skipCache - Bypass the cache and force fresh data (default: false)
103
+ * @returns Promise resolving to array of character components with sprite URLs
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // Get all components (cached if available)
108
+ * const allComponents = await client.character.components.list()
109
+ *
110
+ * // Get components for level 5+ (cached if available)
111
+ * const levelComponents = await client.character.components.list({ level: 5 })
112
+ *
113
+ * // Force fresh data from API
114
+ * const freshComponents = await client.character.components.list({ skipCache: true })
115
+ * ```
116
+ */
117
+ list: (options?: CharacterComponentsOptions & {
118
+ skipCache?: boolean;
119
+ }) => Promise<CharacterComponentWithSpriteUrl[]>;
120
+ /**
121
+ * Clears the component cache.
122
+ * Useful when you know the component data has changed and want to force fresh data.
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Clear all cached component data
127
+ * client.character.components.clearCache()
128
+ * ```
129
+ */
130
+ clearCache: () => void;
131
+ /**
132
+ * Returns a list of all the component cache keys currently stored.
133
+ * Primarily useful for debugging and cache inspection.
134
+ *
135
+ * @returns Array of cache keys (e.g., ['all', '1', '5'])
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // List all cache keys
140
+ * const cacheKeys = client.character.components.getCacheKeys()
141
+ * console.log('Cached levels:', cacheKeys)
142
+ * ```
143
+ */
144
+ getCacheKeys: () => string[];
145
+ };
146
+ };
@@ -0,0 +1,51 @@
1
+ import type { PlaycademyClient } from '../../types';
2
+ /**
3
+ * Creates the credits namespace for the PlaycademyClient.
4
+ * Provides convenient methods for working with Playcademy Credits (the primary platform currency).
5
+ *
6
+ * @param client - The PlaycademyClient instance
7
+ * @returns Credits namespace with balance and transaction methods
8
+ */
9
+ export declare function createCreditsNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * Gets the current balance of Playcademy Credits for the authenticated user.
12
+ * This is a convenience method that finds the primary currency in the user's inventory.
13
+ *
14
+ * @returns Promise resolving to the current credits balance
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const balance = await client.credits.balance()
19
+ * console.log('Current credits:', balance)
20
+ * ```
21
+ */
22
+ balance: () => Promise<number>;
23
+ /**
24
+ * Adds Playcademy Credits to the user's inventory.
25
+ * This is a convenience method that automatically finds the credits item ID.
26
+ *
27
+ * @param amount - The amount of credits to add (must be positive)
28
+ * @returns Promise resolving to the new total balance
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const newBalance = await client.credits.add(100)
33
+ * console.log('New balance after adding 100 credits:', newBalance)
34
+ * ```
35
+ */
36
+ add: (amount: number) => Promise<number>;
37
+ /**
38
+ * Spends (removes) Playcademy Credits from the user's inventory.
39
+ * This is a convenience method that automatically finds the credits item ID.
40
+ *
41
+ * @param amount - The amount of credits to spend (must be positive)
42
+ * @returns Promise resolving to the new total balance
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const newBalance = await client.credits.spend(50)
47
+ * console.log('New balance after spending 50 credits:', newBalance)
48
+ * ```
49
+ */
50
+ spend: (amount: number) => Promise<number>;
51
+ };