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

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 CHANGED
@@ -162,6 +162,13 @@ All methods returning data are strongly typed.
162
162
  - **`admin.shopListings`**: CRUD operations for shop listings.
163
163
  - **`shop`**: Player-facing shop operations.
164
164
  - `view()`: Get shop items and currency information.
165
+ - **`levels`**: Player level and experience point management.
166
+ - `get()`: Get current user level information.
167
+ - `progress()`: Get level progress with XP to next level.
168
+ - `addXP(amount)`: Add XP to user.
169
+ - **`config`**:
170
+ - `list()`: Get all level configurations (full XP curve).
171
+ - `get(level)`: Get configuration for a specific level.
165
172
  - **`telemetry`**: Push metrics.
166
173
 
167
174
  ## Contributing
@@ -311,6 +311,21 @@ export declare class PlaycademyClient {
311
311
  shop: {
312
312
  view: () => Promise<import("..").ShopViewResponse>;
313
313
  };
314
+ /** Level methods (levels) */
315
+ levels: {
316
+ get: () => Promise<import("@playcademy/types").UserLevel>;
317
+ progress: () => Promise<{
318
+ level: number;
319
+ currentXp: number;
320
+ xpToNextLevel: number;
321
+ totalXpEarned: number;
322
+ }>;
323
+ addXP: (amount: number) => Promise<import("@playcademy/types").XPAddResult>;
324
+ config: {
325
+ list: () => Promise<import("@playcademy/types").LevelConfig[]>;
326
+ get: (level: number) => Promise<import("@playcademy/types").LevelConfig | null>;
327
+ };
328
+ };
314
329
  /** Telemetry methods (pushMetrics) */
315
330
  telemetry: {
316
331
  pushMetrics: (metrics: Record<string, number>) => Promise<void>;
@@ -7,3 +7,4 @@ export { createMapsNamespace } from './maps';
7
7
  export { createAdminNamespace } from './admin';
8
8
  export { createShopNamespace } from './shop';
9
9
  export { createTelemetryNamespace } from './telemetry';
10
+ export { createLevelsNamespace } from './levels';
@@ -0,0 +1,93 @@
1
+ import type { UserLevel, LevelConfig, XPAddResult } from '../../types';
2
+ import type { PlaycademyClient } from '../client';
3
+ /**
4
+ * Creates the levels namespace for the PlaycademyClient.
5
+ * Provides methods for managing user levels and experience points.
6
+ *
7
+ * @param client - The PlaycademyClient instance
8
+ * @returns Levels namespace with level and XP methods
9
+ */
10
+ export declare function createLevelsNamespace(client: PlaycademyClient): {
11
+ /**
12
+ * Retrieves the current user's level information.
13
+ *
14
+ * @returns Promise resolving to user level data
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const userLevel = await client.levels.get()
19
+ * console.log('Current level:', userLevel.currentLevel)
20
+ * console.log('Current XP:', userLevel.currentXp)
21
+ * console.log('Total XP earned:', userLevel.totalXpEarned)
22
+ * ```
23
+ */
24
+ get: () => Promise<UserLevel>;
25
+ /**
26
+ * Retrieves the current user's level progress information.
27
+ *
28
+ * @returns Promise resolving to level progress data
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const progress = await client.levels.progress()
33
+ * console.log('Level:', progress.level)
34
+ * console.log('XP to next level:', progress.xpToNextLevel)
35
+ * ```
36
+ */
37
+ progress: () => Promise<{
38
+ level: number;
39
+ currentXp: number;
40
+ xpToNextLevel: number;
41
+ totalXpEarned: number;
42
+ }>;
43
+ /**
44
+ * Adds XP to the current user.
45
+ * Emits 'xpGained' and 'levelUp' events when successful.
46
+ *
47
+ * @param amount - The amount of XP to add (must be positive)
48
+ * @returns Promise resolving to XP addition result
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const result = await client.levels.addXP(100)
53
+ * console.log('New level:', result.newLevel)
54
+ * console.log('Leveled up:', result.leveledUp)
55
+ * console.log('Credits awarded:', result.creditsAwarded)
56
+ * ```
57
+ */
58
+ addXP: (amount: number) => Promise<XPAddResult>;
59
+ /**
60
+ * Configuration methods for level system.
61
+ */
62
+ config: {
63
+ /**
64
+ * Retrieves all level configurations (full XP curve).
65
+ *
66
+ * @returns Promise resolving to array of level configurations
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const configs = await client.levels.config.list()
71
+ * configs.forEach(config => {
72
+ * console.log(`Level ${config.level}: ${config.xpRequired} XP, ${config.creditsReward} credits`)
73
+ * })
74
+ * ```
75
+ */
76
+ list: () => Promise<LevelConfig[]>;
77
+ /**
78
+ * Retrieves configuration for a specific level.
79
+ *
80
+ * @param level - The level number to get configuration for
81
+ * @returns Promise resolving to level configuration or null if not found
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const config = await client.levels.config.get(10)
86
+ * if (config) {
87
+ * console.log(`Level 10 requires ${config.xpRequired} XP`)
88
+ * }
89
+ * ```
90
+ */
91
+ get: (level: number) => Promise<LevelConfig | null>;
92
+ };
93
+ };
package/dist/index.js CHANGED
@@ -368,6 +368,45 @@ function createTelemetryNamespace(client) {
368
368
  };
369
369
  }
370
370
 
371
+ // src/core/namespaces/levels.ts
372
+ function createLevelsNamespace(client) {
373
+ return {
374
+ get: async () => {
375
+ return client["request"]("/users/level", "GET");
376
+ },
377
+ progress: async () => {
378
+ return client["request"]("/users/level/progress", "GET");
379
+ },
380
+ addXP: async (amount) => {
381
+ const currentUserLevel = await client["request"]("/users/level", "GET");
382
+ const oldLevel = currentUserLevel.currentLevel;
383
+ const payload = { amount };
384
+ const result = await client["request"]("/users/xp/add", "POST", payload);
385
+ client["emit"]("xpGained", {
386
+ amount,
387
+ totalXpEarned: result.totalXpEarned,
388
+ leveledUp: result.leveledUp
389
+ });
390
+ if (result.leveledUp) {
391
+ client["emit"]("levelUp", {
392
+ oldLevel,
393
+ newLevel: result.newLevel,
394
+ creditsAwarded: result.creditsAwarded
395
+ });
396
+ }
397
+ return result;
398
+ },
399
+ config: {
400
+ list: async () => {
401
+ return client["request"]("/levels/config", "GET");
402
+ },
403
+ get: async (level) => {
404
+ return client["request"](`/levels/config/${level}`, "GET");
405
+ }
406
+ }
407
+ };
408
+ }
409
+
371
410
  // src/core/namespaces/index.ts
372
411
  var init_namespaces = __esm(() => {
373
412
  init_runtime();
@@ -568,6 +607,7 @@ var init_client = __esm(() => {
568
607
  maps = createMapsNamespace(this);
569
608
  admin = createAdminNamespace(this);
570
609
  shop = createShopNamespace(this);
610
+ levels = createLevelsNamespace(this);
571
611
  telemetry = createTelemetryNamespace(this);
572
612
  static init = init;
573
613
  static login = login;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing } from '@playcademy/types';
1
+ import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, UserLevel, LevelConfig, XPAddResult, UserLevelWithConfig, XPActionInput } from '@playcademy/types';
2
2
  export interface ClientConfig {
3
3
  baseUrl: string;
4
4
  token?: string;
@@ -13,6 +13,16 @@ export interface ClientEvents {
13
13
  delta: number;
14
14
  newTotal: number;
15
15
  };
16
+ levelUp: {
17
+ oldLevel: number;
18
+ newLevel: number;
19
+ creditsAwarded: number;
20
+ };
21
+ xpGained: {
22
+ amount: number;
23
+ totalXpEarned: number;
24
+ leveledUp: boolean;
25
+ };
16
26
  }
17
27
  export type GameContextPayload = {
18
28
  token: string;
@@ -68,4 +78,4 @@ export interface ShopViewResponse {
68
78
  shopItems: ShopDisplayItem[];
69
79
  currencies: CurrencyInfo[];
70
80
  }
71
- export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, };
81
+ export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, UserLevel, LevelConfig, XPAddResult, UserLevelWithConfig, XPActionInput, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.21",
4
+ "version": "0.0.1-beta.22",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./dist/index.js",