@playcademy/sdk 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/index.d.ts +4013 -7
  2. package/dist/index.js +1820 -1785
  3. package/dist/server.d.ts +53 -0
  4. package/dist/server.js +50 -0
  5. package/dist/types.d.ts +4243 -41
  6. package/dist/types.js +1 -748
  7. package/package.json +10 -3
  8. package/dist/core/auth/flows/popup.d.ts +0 -14
  9. package/dist/core/auth/flows/redirect.d.ts +0 -15
  10. package/dist/core/auth/flows/unified.d.ts +0 -11
  11. package/dist/core/auth/login.d.ts +0 -20
  12. package/dist/core/auth/oauth.d.ts +0 -115
  13. package/dist/core/auth/utils.d.ts +0 -23
  14. package/dist/core/cache/cooldown-cache.d.ts +0 -31
  15. package/dist/core/cache/index.d.ts +0 -14
  16. package/dist/core/cache/permanent-cache.d.ts +0 -39
  17. package/dist/core/cache/singleton-cache.d.ts +0 -29
  18. package/dist/core/cache/ttl-cache.d.ts +0 -54
  19. package/dist/core/cache/types.d.ts +0 -23
  20. package/dist/core/client.d.ts +0 -521
  21. package/dist/core/errors.d.ts +0 -11
  22. package/dist/core/namespaces/achievements.d.ts +0 -84
  23. package/dist/core/namespaces/admin.d.ts +0 -385
  24. package/dist/core/namespaces/auth.d.ts +0 -54
  25. package/dist/core/namespaces/character.d.ts +0 -205
  26. package/dist/core/namespaces/credits.d.ts +0 -51
  27. package/dist/core/namespaces/dev.d.ts +0 -323
  28. package/dist/core/namespaces/games.d.ts +0 -173
  29. package/dist/core/namespaces/identity.d.ts +0 -98
  30. package/dist/core/namespaces/index.d.ts +0 -19
  31. package/dist/core/namespaces/leaderboard.d.ts +0 -48
  32. package/dist/core/namespaces/levels.d.ts +0 -90
  33. package/dist/core/namespaces/maps.d.ts +0 -93
  34. package/dist/core/namespaces/realtime.client.d.ts +0 -129
  35. package/dist/core/namespaces/realtime.d.ts +0 -90
  36. package/dist/core/namespaces/runtime.d.ts +0 -222
  37. package/dist/core/namespaces/scores.d.ts +0 -55
  38. package/dist/core/namespaces/shop.d.ts +0 -25
  39. package/dist/core/namespaces/sprites.d.ts +0 -35
  40. package/dist/core/namespaces/telemetry.d.ts +0 -28
  41. package/dist/core/namespaces/timeback.d.ts +0 -111
  42. package/dist/core/namespaces/users.d.ts +0 -172
  43. package/dist/core/request.d.ts +0 -24
  44. package/dist/core/static/identity.d.ts +0 -37
  45. package/dist/core/static/index.d.ts +0 -3
  46. package/dist/core/static/init.d.ts +0 -21
  47. package/dist/core/static/login.d.ts +0 -34
  48. package/dist/messaging.d.ts +0 -544
@@ -1,521 +0,0 @@
1
- import { init, login } from './static';
2
- import type { ClientConfig, ClientEvents } from '../types';
3
- import type { Method } from './request';
4
- /**
5
- * Main Playcademy SDK client for interacting with the platform API.
6
- * Provides namespaced access to all platform features including games, users, inventory, and more.
7
- */
8
- export declare class PlaycademyClient {
9
- private baseUrl;
10
- private token?;
11
- private gameId?;
12
- private listeners;
13
- private internalClientSessionId?;
14
- private authContext?;
15
- private initPayload?;
16
- /**
17
- * Creates a new PlaycademyClient instance.
18
- *
19
- * @param config - Optional configuration object
20
- * @param config.baseUrl - Base URL for API requests (defaults to '/api')
21
- * @param config.token - Authentication token
22
- * @param config.gameId - Game ID for automatic session management
23
- */
24
- constructor(config?: Partial<ClientConfig>);
25
- /**
26
- * Gets the effective base URL for API requests.
27
- * Converts relative URLs to absolute URLs in browser environments.
28
- *
29
- * @returns The complete base URL for API requests
30
- */
31
- getBaseUrl(): string;
32
- /**
33
- * Simple ping method for testing connectivity.
34
- *
35
- * @returns 'pong' string response
36
- */
37
- ping(): string;
38
- /**
39
- * Sets the authentication token for API requests.
40
- * Emits an 'authChange' event when the token changes.
41
- *
42
- * @param token - The authentication token, or null to clear
43
- */
44
- setToken(token: string | null): void;
45
- /**
46
- * Checks if the client has a valid API token for making Playcademy API requests.
47
- *
48
- * For games (iframe context): Checks if we have a valid token from the parent.
49
- * For Cademy (standalone): Checks if we have a token from better-auth.
50
- *
51
- * Note: This checks for API authentication, not whether a user has linked
52
- * their identity via OAuth.
53
- *
54
- * @returns true if API token exists, false otherwise
55
- *
56
- * @example
57
- * ```typescript
58
- * if (client.isAuthenticated()) {
59
- * // Can make API calls
60
- * const games = await client.games.list()
61
- * } else {
62
- * console.error('No API token available')
63
- * }
64
- * ```
65
- */
66
- isAuthenticated(): boolean;
67
- /**
68
- * Registers a callback to be called when authentication state changes.
69
- *
70
- * @param callback - Function to call when auth state changes
71
- */
72
- onAuthChange(callback: (token: string | null) => void): void;
73
- /**
74
- * Sets the authentication context for the client.
75
- * This is called during initialization to store environment info.
76
- * @internal
77
- */
78
- _setAuthContext(context: {
79
- isInIframe: boolean;
80
- }): void;
81
- /**
82
- * Registers an event listener for client events.
83
- *
84
- * @param event - The event type to listen for
85
- * @param callback - Function to call when the event is emitted
86
- */
87
- on<E extends keyof ClientEvents>(event: E, callback: (payload: ClientEvents[E]) => void): void;
88
- /**
89
- * Emits an event to all registered listeners.
90
- *
91
- * @param event - The event type to emit
92
- * @param payload - The event payload
93
- */
94
- private emit;
95
- /**
96
- * Makes an authenticated HTTP request to the API.
97
- *
98
- * @param path - API endpoint path
99
- * @param method - HTTP method
100
- * @param body - Request body (optional)
101
- * @param headers - Additional headers (optional)
102
- * @returns Promise resolving to the response data
103
- */
104
- protected request<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
105
- /**
106
- * Ensures a gameId is available, throwing an error if not.
107
- *
108
- * @returns The gameId
109
- * @throws PlaycademyError if no gameId is configured
110
- */
111
- private _ensureGameId;
112
- /**
113
- * Detects and sets the authentication context (iframe vs standalone).
114
- * Safe to call in any environment - isInIframe handles browser detection.
115
- */
116
- private detectAuthContext;
117
- /**
118
- * Initializes an internal game session for automatic session management.
119
- * Called automatically when a gameId is provided in the constructor.
120
- */
121
- private _initializeInternalSession;
122
- /** Platform API authentication methods (login, logout) */
123
- auth: {
124
- login: (credentials: {
125
- email: string;
126
- password: string;
127
- }) => Promise<{
128
- success: boolean;
129
- token?: string;
130
- error?: string;
131
- }>;
132
- logout: () => Promise<void>;
133
- };
134
- /** Identity provider connection methods (connect external accounts) */
135
- identity: {
136
- readonly user: import("@playcademy/data/types").AuthenticatedUser | null;
137
- connect: (options: import("../types").AuthOptions) => Promise<import("../types").AuthResult>;
138
- _getContext: () => {
139
- isInIframe: boolean;
140
- };
141
- };
142
- /** Runtime methods (getGameToken, exit) */
143
- runtime: {
144
- getGameToken: (gameId: string, options?: {
145
- apply?: boolean;
146
- }) => Promise<import("../types").GameTokenResponse>;
147
- exit: () => Promise<void>;
148
- onInit: (handler: (context: import("../types").GameContextPayload) => void) => void;
149
- onTokenRefresh: (handler: (data: {
150
- token: string;
151
- exp: number;
152
- }) => void) => void;
153
- onPause: (handler: () => void) => void;
154
- onResume: (handler: () => void) => void;
155
- onForceExit: (handler: () => void) => void;
156
- onOverlay: (handler: (isVisible: boolean) => void) => void;
157
- ready: () => void;
158
- sendTelemetry: (data: {
159
- fps: number;
160
- mem: number;
161
- }) => void;
162
- removeListener: (eventType: import("..").MessageEvents, handler: ((context: import("../types").GameContextPayload) => void) | ((data: {
163
- token: string;
164
- exp: number;
165
- }) => void) | (() => void) | ((isVisible: boolean) => void)) => void;
166
- removeAllListeners: () => void;
167
- getListenerCounts: () => Record<string, number>;
168
- };
169
- /** Game management methods (fetch, list, saveState, loadState, sessions) */
170
- games: {
171
- fetch: (gameIdOrSlug: string, options?: import("./cache/types").TTLCacheConfig) => Promise<import("@playcademy/data/types").FetchedGame>;
172
- list: (options?: import("./cache/types").TTLCacheConfig) => Promise<Array<import("@playcademy/data/types").Game>>;
173
- saveState: (state: Record<string, unknown>) => Promise<void>;
174
- loadState: () => Promise<import("@playcademy/data/types").GameStateData>;
175
- startSession: (gameId?: string) => Promise<import("../types").StartSessionResponse>;
176
- endSession: (sessionId: string, gameId?: string) => Promise<void>;
177
- token: {
178
- create: (gameId: string, options?: {
179
- apply?: boolean;
180
- }) => Promise<import("../types").GameTokenResponse>;
181
- };
182
- leaderboard: {
183
- get: (gameId: string, options?: {
184
- limit?: number;
185
- offset? /** Telemetry methods (pushMetrics) */: number;
186
- }) => Promise<import("@playcademy/data/types").LeaderboardEntry[]>;
187
- };
188
- };
189
- /** User methods (me, inventory management) */
190
- users: {
191
- me: () => Promise<import("@playcademy/data/types").AuthenticatedUser>;
192
- inventory: {
193
- get: () => Promise<import("@playcademy/data/types").InventoryItemWithItem[]>;
194
- add: (identifier: string, qty: number) => Promise<import("../types").InventoryMutationResponse>;
195
- remove: (identifier: string, qty: number) => Promise<import("../types").InventoryMutationResponse>;
196
- quantity: (identifier: string) => Promise<number>;
197
- has: (identifier: string, minQuantity?: number) => Promise<boolean>;
198
- };
199
- scores: {
200
- get: (userIdOrOptions?: string | {
201
- limit?: number;
202
- gameId?: string;
203
- }, options?: {
204
- limit?: number;
205
- gameId?: string;
206
- }) => Promise<import("./namespaces/users").UserScore[]>;
207
- };
208
- };
209
- /** Developer tools (auth, games, keys management) */
210
- dev: {
211
- status: {
212
- apply: () => Promise<void>;
213
- get: () => Promise<import("@playcademy/data/types").DeveloperStatusValue>;
214
- };
215
- games: {
216
- upsert: (slug: string, metadata: import("@playcademy/data/types").UpsertGameMetadataInput, file: File | Blob | null, hooks?: import("..").DevUploadHooks) => Promise<import("@playcademy/data/types").Game>;
217
- update: (gameId: string, props: Partial<import("@playcademy/data/types").Game>) => Promise<void>;
218
- delete: (gameId: string) => Promise<void>;
219
- };
220
- keys: {
221
- create: (label?: string) => Promise<{
222
- id: string;
223
- createdAt: Date;
224
- userId: string;
225
- label: string | null;
226
- keyHash: string;
227
- }>;
228
- list: () => Promise<{
229
- id: string;
230
- createdAt: Date;
231
- userId: string;
232
- label: string | null;
233
- keyHash: string;
234
- }[]>;
235
- revoke: (keyId: string) => Promise<void>;
236
- };
237
- items: {
238
- create: (gameId: string, slug: string, itemData: Omit<import("@playcademy/data/types").InsertItemInput, "slug" | "gameId">) => Promise<import("@playcademy/data/types").Item>;
239
- update: (gameId: string, itemId: string, updates: import("@playcademy/data/types").UpdateItemInput) => Promise<import("@playcademy/data/types").Item>;
240
- list: (gameId: string) => Promise<Array<import("@playcademy/data/types").Item>>;
241
- get: (gameId: string, slug: string) => Promise<import("@playcademy/data/types").Item>;
242
- delete: (gameId: string, itemId: string) => Promise<void>;
243
- shop: {
244
- create: (gameId: string, itemId: string, listingData: Omit<import("@playcademy/data/types").InsertShopListingInput, "itemId">) => Promise<import("@playcademy/data/types").ShopListing>;
245
- get: (gameId: string, itemId: string) => Promise<import("@playcademy/data/types").ShopListing | null>;
246
- update: (gameId: string, itemId: string, updates: import("@playcademy/data/types").UpdateShopListingInput) => Promise<import("@playcademy/data/types").ShopListing>;
247
- delete: (gameId: string, itemId: string) => Promise<void>;
248
- list: (gameId: string) => Promise<Array<import("@playcademy/data/types").ShopListing & {
249
- item: import("@playcademy/data/types").Item;
250
- }>>;
251
- };
252
- };
253
- };
254
- /** Map methods (elements) */
255
- maps: {
256
- get: (identifier: string) => Promise<import("@playcademy/data/types").MapData>;
257
- elements: (mapId: string) => Promise<import("@playcademy/data/types").MapElementWithGame[]>;
258
- objects: {
259
- list: (mapId: string) => Promise<import("@playcademy/data/types").MapObjectWithItem[]>;
260
- create: (mapId: string, objectData: import("@playcademy/data/types").CreateMapObjectData) => Promise<import("@playcademy/data/types").MapObjectWithItem>;
261
- delete: (mapId: string, objectId: string) => Promise<void>;
262
- };
263
- };
264
- /** Admin methods (games, items, currencies, shop listings) */
265
- admin: {
266
- games: {
267
- pauseGame: (gameId: string) => Promise<void>;
268
- resumeGame: (gameId: string) => Promise<void>;
269
- };
270
- items: {
271
- create: (props: import("@playcademy/data/types").InsertItemInput) => Promise<{
272
- description: string | null;
273
- id: string;
274
- createdAt: Date;
275
- slug: string;
276
- displayName: string;
277
- metadata: unknown;
278
- gameId: string | null;
279
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
280
- isPlaceable: boolean;
281
- imageUrl: string | null;
282
- }>;
283
- get: (itemId: string) => Promise<{
284
- description: string | null;
285
- id: string;
286
- createdAt: Date;
287
- slug: string;
288
- displayName: string;
289
- metadata: unknown;
290
- gameId: string | null;
291
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
292
- isPlaceable: boolean;
293
- imageUrl: string | null;
294
- }>;
295
- list: () => Promise<{
296
- description: string | null;
297
- id: string;
298
- createdAt: Date;
299
- slug: string;
300
- displayName: string;
301
- metadata: unknown;
302
- gameId: string | null;
303
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
304
- isPlaceable: boolean;
305
- imageUrl: string | null;
306
- }[]>;
307
- update: (itemId: string, props: import("@playcademy/data/types").UpdateItemInput) => Promise<{
308
- description: string | null;
309
- id: string;
310
- createdAt: Date;
311
- slug: string;
312
- displayName: string;
313
- metadata: unknown;
314
- gameId: string | null;
315
- type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "accessory" | "other";
316
- isPlaceable: boolean;
317
- imageUrl: string | null;
318
- }>;
319
- delete: (itemId: string) => Promise<void>;
320
- };
321
- currencies: {
322
- create: (props: import("@playcademy/data/types").InsertCurrencyInput) => Promise<{
323
- symbol: string | null;
324
- id: string;
325
- createdAt: Date;
326
- updatedAt: Date | null;
327
- itemId: string;
328
- isPrimary: boolean;
329
- }>;
330
- get: (currencyId: string) => Promise<{
331
- symbol: string | null;
332
- id: string;
333
- createdAt: Date;
334
- updatedAt: Date | null;
335
- itemId: string;
336
- isPrimary: boolean;
337
- }>;
338
- list: () => Promise<{
339
- symbol: string | null;
340
- id: string;
341
- createdAt: Date;
342
- updatedAt: Date | null;
343
- itemId: string;
344
- isPrimary: boolean;
345
- }[]>;
346
- update: (currencyId: string, props: import("@playcademy/data/types").UpdateCurrencyInput) => Promise<{
347
- symbol: string | null;
348
- id: string;
349
- createdAt: Date;
350
- updatedAt: Date | null;
351
- itemId: string;
352
- isPrimary: boolean;
353
- }>;
354
- delete: (currencyId: string) => Promise<void>;
355
- };
356
- shopListings: {
357
- create: (props: import("@playcademy/data/types").InsertShopListingInput) => Promise<{
358
- id: string;
359
- createdAt: Date;
360
- updatedAt: Date | null;
361
- itemId: string;
362
- currencyId: string;
363
- price: number;
364
- sellBackPercentage: number | null;
365
- stock: number | null;
366
- isActive: boolean;
367
- availableFrom: Date | null;
368
- availableUntil: Date | null;
369
- }>;
370
- get: (listingId: string) => Promise<{
371
- id: string;
372
- createdAt: Date;
373
- updatedAt: Date | null;
374
- itemId: string;
375
- currencyId: string;
376
- price: number;
377
- sellBackPercentage: number | null;
378
- stock: number | null;
379
- isActive: boolean;
380
- availableFrom: Date | null;
381
- availableUntil: Date | null;
382
- }>;
383
- list: () => Promise<{
384
- id: string;
385
- createdAt: Date;
386
- updatedAt: Date | null;
387
- itemId: string;
388
- currencyId: string;
389
- price: number;
390
- sellBackPercentage: number | null;
391
- stock: number | null;
392
- isActive: boolean;
393
- availableFrom: Date | null;
394
- availableUntil: Date | null;
395
- }[]>;
396
- update: (listingId: string, props: import("@playcademy/data/types").UpdateShopListingInput) => Promise<{
397
- id: string;
398
- createdAt: Date;
399
- updatedAt: Date | null;
400
- itemId: string;
401
- currencyId: string;
402
- price: number;
403
- sellBackPercentage: number | null;
404
- stock: number | null;
405
- isActive: boolean;
406
- availableFrom: Date | null;
407
- availableUntil: Date | null;
408
- }>;
409
- delete: (listingId: string) => Promise<void>;
410
- };
411
- };
412
- /** Shop methods (view) */
413
- shop: {
414
- view: () => Promise<import("@playcademy/data/types").ShopViewResponse>;
415
- };
416
- /** Level methods (levels) */
417
- levels: {
418
- get: () => Promise<import("@playcademy/data/types").UserLevel>;
419
- progress: (options?: import("./cache/types").CooldownCacheConfig) => Promise<{
420
- level: number;
421
- currentXp: number;
422
- xpToNextLevel: number;
423
- totalXP: number;
424
- }>;
425
- config: {
426
- list: () => Promise<import("@playcademy/data/types").LevelConfig[]>;
427
- get: (level: number) => Promise<import("@playcademy/data/types").LevelConfig | null>;
428
- };
429
- };
430
- /** TimeBack XP methods (today, total, history) */
431
- timeback: {
432
- xp: {
433
- today: (options?: {
434
- date?: string;
435
- timezone?: string;
436
- }) => Promise<import("@playcademy/data/types").TodayXpResponse>;
437
- total: () => Promise<import("@playcademy/data/types").TotalXpResponse>;
438
- history: (options?: {
439
- startDate?: string;
440
- endDate?: string;
441
- }) => Promise<import("@playcademy/data/types").XpHistoryResponse>;
442
- summary: (options?: {
443
- date?: string;
444
- timezone?: string;
445
- }) => Promise<import("./namespaces/timeback").XpSummaryResponse>;
446
- };
447
- };
448
- /** Telemetry methods (pushMetrics) */
449
- telemetry: {
450
- pushMetrics: (metrics: Record<string, number>) => Promise<void>;
451
- };
452
- /** Credits methods (credits management) */
453
- credits: {
454
- balance: () => Promise<number>;
455
- add: (amount: number) => Promise<number>;
456
- spend: (amount: number) => Promise<number>;
457
- };
458
- /** Platform-wide leaderboard methods (fetch, getUserRank) */
459
- leaderboard: {
460
- fetch: (options?: import("@playcademy/data/types").LeaderboardOptions) => Promise<import("@playcademy/data/types").GameLeaderboardEntry[]>;
461
- getUserRank: (gameId: string, userId: string) => Promise<import("@playcademy/data/types").UserRankResponse>;
462
- };
463
- /** Platform-wide scores methods (submit, getUserScores) */
464
- scores: {
465
- submit: (gameId: string, score: number, metadata?: Record<string, unknown>) => Promise<import("./namespaces/scores").ScoreSubmission>;
466
- getByUser: (gameId: string, userId: string, options?: {
467
- limit?: number;
468
- }) => Promise<import("@playcademy/data/types").UserScore[]>;
469
- };
470
- /** Character methods (get, create, update, components) */
471
- character: {
472
- get: (userId?: string) => Promise<import("@playcademy/data/types").PlayerCharacter | null>;
473
- create: (characterData: import("./namespaces/character").CreateCharacterData) => Promise<import("@playcademy/data/types").PlayerCharacter>;
474
- update: (updates: import("./namespaces/character").UpdateCharacterData) => Promise<import("@playcademy/data/types").PlayerCharacter>;
475
- components: {
476
- list: (options?: import("./namespaces/character").CharacterComponentsOptions & import("./cache/types").TTLCacheConfig) => Promise<import("@playcademy/data/types").CharacterComponentWithSpriteUrl[]>;
477
- clearCache: (key?: string) => void;
478
- getCacheKeys: () => string[];
479
- };
480
- accessories: {
481
- equip: (slot: string, componentId: string) => Promise<import("@playcademy/data/types").PlayerCharacterAccessory>;
482
- remove: (slot: string) => Promise<{
483
- success: boolean;
484
- }>;
485
- list: () => Promise<import("@playcademy/data/types").PlayerCharacterAccessory[]>;
486
- };
487
- };
488
- /** Sprites methods (templates) */
489
- sprites: {
490
- templates: {
491
- get: (slug: string) => Promise<import("@playcademy/data/types").SpriteTemplateData>;
492
- };
493
- };
494
- /** Realtime methods (token) */
495
- realtime: {
496
- token: {
497
- get: () => Promise<import("./namespaces/realtime").RealtimeTokenResponse>;
498
- };
499
- open(channel?: string, url?: string): Promise<import("@playcademy/realtime/server/types").RealtimeChannel>;
500
- };
501
- /** Achievements methods (list, history, progress) */
502
- achievements: {
503
- list: (options?: import("./cache/types").TTLCacheConfig) => Promise<import("@playcademy/data/types").AchievementCurrent[]>;
504
- history: {
505
- list: (queryOptions?: {
506
- limit?: number;
507
- }, cacheOptions?: import("./cache/types").TTLCacheConfig) => Promise<import("@playcademy/data/types").AchievementHistoryEntry[]>;
508
- };
509
- progress: {
510
- submit: (achievementId: string) => Promise<import("@playcademy/data/types").AchievementProgressResponse>;
511
- };
512
- };
513
- /** Auto-initializes a PlaycademyClient with context from the environment */
514
- static init: typeof init;
515
- /** Authenticates a user with email and password */
516
- static login: typeof login;
517
- /** Static identity utilities for OAuth operations */
518
- static identity: {
519
- parseOAuthState: typeof import("./auth/oauth").parseOAuthState;
520
- };
521
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Base error class for Cademy SDK specific errors.
3
- */
4
- export declare class PlaycademyError extends Error {
5
- constructor(message: string);
6
- }
7
- export declare class ApiError extends Error {
8
- status: number;
9
- details: unknown;
10
- constructor(status: number, message: string, details: unknown);
11
- }
@@ -1,84 +0,0 @@
1
- import type { AchievementCurrent, AchievementHistoryEntry, AchievementProgressResponse } from '@playcademy/data/types';
2
- import type { PlaycademyClient } from '../../types';
3
- import type { TTLCacheConfig } from '../cache/types';
4
- /**
5
- * Creates the achievements namespace for the PlaycademyClient.
6
- * Provides methods to list current achievements, read claim history,
7
- * and submit progress for an achievement.
8
- *
9
- * Method naming and structure follow existing conventions:
10
- * - Top-level listing via `list()`
11
- * - Nested sub-namespaces (e.g., `history.list`, `progress.submit`)
12
- *
13
- * @param client - The PlaycademyClient instance
14
- * @returns Achievements namespace with list/history/progress methods
15
- */
16
- export declare function createAchievementsNamespace(client: PlaycademyClient): {
17
- /**
18
- * Lists current-interval achievements with status (available/completed).
19
- * Results are cached for 5 seconds by default.
20
- *
21
- * @param options - Optional cache configuration
22
- * @param options.ttl - Custom TTL in milliseconds (0 to disable caching)
23
- * @param options.force - Force refresh the cache
24
- * @returns Promise resolving to array of current achievements
25
- *
26
- * @example
27
- * ```typescript
28
- * // Use default 5 second cache
29
- * const achievements = await client.achievements.list()
30
- *
31
- * // Force refresh on user action
32
- * const freshAchievements = await client.achievements.list({ force: true })
33
- *
34
- * // Disable caching for admin panel
35
- * const uncachedAchievements = await client.achievements.list({ ttl: 0 })
36
- * ```
37
- */
38
- list: (options?: TTLCacheConfig) => Promise<AchievementCurrent[]>;
39
- /**
40
- * History sub-namespace
41
- */
42
- history: {
43
- /**
44
- * Lists recent achievement claims for the current user.
45
- * Results are cached for 5 seconds by default.
46
- *
47
- * @param queryOptions - Query parameters for the request
48
- * @param queryOptions.limit - Maximum number of entries to return (default 20)
49
- * @param cacheOptions - Optional cache configuration
50
- * @param cacheOptions.ttl - Custom TTL in milliseconds (0 to disable caching)
51
- * @param cacheOptions.force - Force refresh the cache
52
- * @returns Promise resolving to array of achievement history entries
53
- *
54
- * @example
55
- * ```typescript
56
- * // Use default 5 second cache, get 20 entries
57
- * const history = await client.achievements.history.list()
58
- *
59
- * // Get 50 entries with cache
60
- * const moreHistory = await client.achievements.history.list({ limit: 50 })
61
- *
62
- * // Force refresh with custom limit
63
- * const freshHistory = await client.achievements.history.list(
64
- * { limit: 10 },
65
- * { force: true }
66
- * )
67
- * ```
68
- */
69
- list: (queryOptions?: {
70
- limit?: number;
71
- }, cacheOptions?: TTLCacheConfig) => Promise<AchievementHistoryEntry[]>;
72
- };
73
- /**
74
- * Progress sub-namespace
75
- */
76
- progress: {
77
- /**
78
- * Submits completion for an achievement (server validates idempotency).
79
- *
80
- * @param achievementId - The ID of the achievement to submit progress for
81
- */
82
- submit: (achievementId: string) => Promise<AchievementProgressResponse>;
83
- };
84
- };