@playcademy/sdk 0.0.1-beta.15 → 0.0.1-beta.17

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
@@ -158,6 +158,10 @@ All methods returning data are strongly typed.
158
158
  - **`dev.keys`**: Create, list, revoke API keys for games.
159
159
  - **`admin.games`**: Pause/resume games.
160
160
  - **`admin.items`**: CRUD operations for items.
161
+ - **`admin.currencies`**: CRUD operations for currencies.
162
+ - **`admin.shopListings`**: CRUD operations for shop listings.
163
+ - **`shop`**: Player-facing shop operations.
164
+ - `view()`: Get shop items and currency information.
161
165
  - **`telemetry`**: Push metrics.
162
166
 
163
167
  ## Contributing
@@ -1,38 +1,108 @@
1
1
  import { type Method } from './request';
2
- import type { Game, GameWithManifest, UpsertGameMetadataInput, InsertItem, UpdateItem, InsertCurrency, UpdateCurrency, InsertShopListing, UpdateShopListing } from '@playcademy/types';
3
- import type { GameState, InventoryItemWithItem, ClientConfig, ClientEvents, LoginResponse, GameTokenResponse, StartSessionResponse, InventoryMutationResponse, DeveloperStatusValue, ShopViewResponse } from '../types';
2
+ import { init, login } from './static';
3
+ import type { ClientConfig, ClientEvents } from '../types';
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
+ */
4
8
  export declare class PlaycademyClient {
5
9
  private baseUrl;
6
10
  private token?;
7
11
  private gameId?;
8
12
  private listeners;
9
13
  private internalClientSessionId?;
10
- constructor(config: ClientConfig);
11
- private _initializeInternalSession;
14
+ /**
15
+ * Creates a new PlaycademyClient instance.
16
+ *
17
+ * @param config - Optional configuration object
18
+ * @param config.baseUrl - Base URL for API requests (defaults to '/api')
19
+ * @param config.token - Authentication token
20
+ * @param config.gameId - Game ID for automatic session management
21
+ */
22
+ constructor(config?: Partial<ClientConfig>);
23
+ /**
24
+ * Gets the effective base URL for API requests.
25
+ * Converts relative URLs to absolute URLs in browser environments.
26
+ *
27
+ * @returns The complete base URL for API requests
28
+ */
12
29
  getBaseUrl(): string;
13
- on<E extends keyof ClientEvents>(event: E, callback: (payload: ClientEvents[E]) => void): void;
14
- private emit;
30
+ /**
31
+ * Simple ping method for testing connectivity.
32
+ *
33
+ * @returns 'pong' string response
34
+ */
35
+ ping(): string;
36
+ /**
37
+ * Sets the authentication token for API requests.
38
+ * Emits an 'authChange' event when the token changes.
39
+ *
40
+ * @param token - The authentication token, or null to clear
41
+ */
15
42
  setToken(token: string | null): void;
43
+ /**
44
+ * Registers a callback to be called when authentication state changes.
45
+ *
46
+ * @param callback - Function to call when auth state changes
47
+ */
16
48
  onAuthChange(callback: (token: string | null) => void): void;
49
+ /**
50
+ * Registers an event listener for client events.
51
+ *
52
+ * @param event - The event type to listen for
53
+ * @param callback - Function to call when the event is emitted
54
+ */
55
+ on<E extends keyof ClientEvents>(event: E, callback: (payload: ClientEvents[E]) => void): void;
56
+ /**
57
+ * Emits an event to all registered listeners.
58
+ *
59
+ * @param event - The event type to emit
60
+ * @param payload - The event payload
61
+ */
62
+ private emit;
63
+ /**
64
+ * Makes an authenticated HTTP request to the API.
65
+ *
66
+ * @param path - API endpoint path
67
+ * @param method - HTTP method
68
+ * @param body - Request body (optional)
69
+ * @param headers - Additional headers (optional)
70
+ * @returns Promise resolving to the response data
71
+ */
17
72
  protected request<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
73
+ /**
74
+ * Ensures a gameId is available, throwing an error if not.
75
+ *
76
+ * @returns The gameId
77
+ * @throws PlaycademyError if no gameId is configured
78
+ */
18
79
  private _ensureGameId;
80
+ /**
81
+ * Initializes an internal game session for automatic session management.
82
+ * Called automatically when a gameId is provided in the constructor.
83
+ */
84
+ private _initializeInternalSession;
85
+ /** Authentication methods (logout) */
19
86
  auth: {
20
87
  logout: () => Promise<void>;
21
88
  };
89
+ /** Runtime methods (getGameToken, exit) */
22
90
  runtime: {
23
91
  getGameToken: (gameId: string, options?: {
24
92
  apply?: boolean;
25
- }) => Promise<GameTokenResponse>;
93
+ }) => Promise<import("..").GameTokenResponse>;
26
94
  exit: () => Promise<void>;
27
95
  };
96
+ /** Game management methods (fetch, list, saveState, loadState, sessions) */
28
97
  games: {
29
- fetch: (gameIdOrSlug: string) => Promise<GameWithManifest>;
30
- list: () => Promise<Array<Game>>;
98
+ fetch: (gameIdOrSlug: string) => Promise<import("@playcademy/types").GameWithManifest>;
99
+ list: () => Promise<Array<import("@playcademy/types").Game>>;
31
100
  saveState: (state: Record<string, unknown>) => Promise<void>;
32
- loadState: () => Promise<GameState>;
33
- startSession: (gameId?: string) => Promise<StartSessionResponse>;
101
+ loadState: () => Promise<import("..").GameState>;
102
+ startSession: (gameId?: string) => Promise<import("..").StartSessionResponse>;
34
103
  endSession: (sessionId: string, gameId?: string) => Promise<void>;
35
104
  };
105
+ /** User methods (me, inventory management) */
36
106
  users: {
37
107
  me: () => Promise<{
38
108
  id: string;
@@ -47,19 +117,20 @@ export declare class PlaycademyClient {
47
117
  developerStatus: "none" | "pending" | "approved";
48
118
  }>;
49
119
  inventory: {
50
- get: () => Promise<InventoryItemWithItem[]>;
51
- add: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
52
- spend: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
120
+ get: () => Promise<import("@playcademy/types").InventoryItemWithItem[]>;
121
+ add: (itemId: string, qty: number) => Promise<import("..").InventoryMutationResponse>;
122
+ spend: (itemId: string, qty: number) => Promise<import("..").InventoryMutationResponse>;
53
123
  };
54
124
  };
125
+ /** Developer tools (auth, games, keys management) */
55
126
  dev: {
56
127
  auth: {
57
128
  applyForDeveloper: () => Promise<void>;
58
- getDeveloperStatus: () => Promise<DeveloperStatusValue>;
129
+ getDeveloperStatus: () => Promise<import("..").DeveloperStatusValue>;
59
130
  };
60
131
  games: {
61
- upsert: (slug: string, metadata: UpsertGameMetadataInput, file: File | Blob) => Promise<Game>;
62
- update: (gameId: string, props: Partial<Game>) => Promise<void>;
132
+ upsert: (slug: string, metadata: import("@playcademy/types").UpsertGameMetadataInput, file: File | Blob) => Promise<import("@playcademy/types").Game>;
133
+ update: (gameId: string, props: Partial<import("@playcademy/types").Game>) => Promise<void>;
63
134
  delete: (gameId: string) => Promise<void>;
64
135
  };
65
136
  keys: {
@@ -80,6 +151,7 @@ export declare class PlaycademyClient {
80
151
  revokeKey: (keyId: string) => Promise<void>;
81
152
  };
82
153
  };
154
+ /** Map methods (elements) */
83
155
  maps: {
84
156
  elements: (mapId: string) => Promise<{
85
157
  id: string;
@@ -95,13 +167,14 @@ export declare class PlaycademyClient {
95
167
  interactionType: "game_entry" | "game_registry" | "info" | "teleport" | "door_in" | "door_out" | "npc_interaction" | "quest_trigger";
96
168
  }[]>;
97
169
  };
170
+ /** Admin methods (games, items, currencies, shop listings) */
98
171
  admin: {
99
172
  games: {
100
173
  pauseGame: (gameId: string) => Promise<void>;
101
174
  resumeGame: (gameId: string) => Promise<void>;
102
175
  };
103
176
  items: {
104
- createItem: (props: InsertItem) => Promise<{
177
+ create: (props: import("@playcademy/types").InsertItem) => Promise<{
105
178
  id: string;
106
179
  displayName: string;
107
180
  metadata: unknown;
@@ -111,7 +184,7 @@ export declare class PlaycademyClient {
111
184
  type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
112
185
  imageUrl: string | null;
113
186
  }>;
114
- getItem: (itemId: string) => Promise<{
187
+ get: (itemId: string) => Promise<{
115
188
  id: string;
116
189
  displayName: string;
117
190
  metadata: unknown;
@@ -121,7 +194,7 @@ export declare class PlaycademyClient {
121
194
  type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
122
195
  imageUrl: string | null;
123
196
  }>;
124
- listItems: () => Promise<{
197
+ list: () => Promise<{
125
198
  id: string;
126
199
  displayName: string;
127
200
  metadata: unknown;
@@ -131,7 +204,7 @@ export declare class PlaycademyClient {
131
204
  type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
132
205
  imageUrl: string | null;
133
206
  }[]>;
134
- updateItem: (itemId: string, props: UpdateItem) => Promise<{
207
+ update: (itemId: string, props: import("@playcademy/types").UpdateItem) => Promise<{
135
208
  id: string;
136
209
  displayName: string;
137
210
  metadata: unknown;
@@ -141,10 +214,10 @@ export declare class PlaycademyClient {
141
214
  type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
142
215
  imageUrl: string | null;
143
216
  }>;
144
- deleteItem: (itemId: string) => Promise<void>;
217
+ delete: (itemId: string) => Promise<void>;
145
218
  };
146
219
  currencies: {
147
- createCurrency: (props: InsertCurrency) => Promise<{
220
+ create: (props: import("@playcademy/types").InsertCurrency) => Promise<{
148
221
  symbol: string | null;
149
222
  id: string;
150
223
  createdAt: Date;
@@ -152,7 +225,7 @@ export declare class PlaycademyClient {
152
225
  itemId: string;
153
226
  isPrimary: boolean;
154
227
  }>;
155
- getCurrency: (currencyId: string) => Promise<{
228
+ get: (currencyId: string) => Promise<{
156
229
  symbol: string | null;
157
230
  id: string;
158
231
  createdAt: Date;
@@ -160,7 +233,7 @@ export declare class PlaycademyClient {
160
233
  itemId: string;
161
234
  isPrimary: boolean;
162
235
  }>;
163
- listCurrencies: () => Promise<{
236
+ list: () => Promise<{
164
237
  symbol: string | null;
165
238
  id: string;
166
239
  createdAt: Date;
@@ -168,7 +241,7 @@ export declare class PlaycademyClient {
168
241
  itemId: string;
169
242
  isPrimary: boolean;
170
243
  }[]>;
171
- updateCurrency: (currencyId: string, props: UpdateCurrency) => Promise<{
244
+ update: (currencyId: string, props: import("@playcademy/types").UpdateCurrency) => Promise<{
172
245
  symbol: string | null;
173
246
  id: string;
174
247
  createdAt: Date;
@@ -176,70 +249,74 @@ export declare class PlaycademyClient {
176
249
  itemId: string;
177
250
  isPrimary: boolean;
178
251
  }>;
179
- deleteCurrency: (currencyId: string) => Promise<void>;
252
+ delete: (currencyId: string) => Promise<void>;
180
253
  };
181
254
  shopListings: {
182
- createListing: (props: InsertShopListing) => Promise<{
255
+ create: (props: import("@playcademy/types").InsertShopListing) => Promise<{
183
256
  id: string;
184
257
  createdAt: Date;
185
258
  updatedAt: Date | null;
186
259
  itemId: string;
187
260
  currencyId: string;
188
- priceAmountMinor: number;
261
+ price: number;
189
262
  sellBackPercentage: number | null;
190
263
  stock: number | null;
191
264
  isActive: boolean;
192
265
  availableFrom: Date | null;
193
266
  availableUntil: Date | null;
194
267
  }>;
195
- getListing: (listingId: string) => Promise<{
268
+ get: (listingId: string) => Promise<{
196
269
  id: string;
197
270
  createdAt: Date;
198
271
  updatedAt: Date | null;
199
272
  itemId: string;
200
273
  currencyId: string;
201
- priceAmountMinor: number;
274
+ price: number;
202
275
  sellBackPercentage: number | null;
203
276
  stock: number | null;
204
277
  isActive: boolean;
205
278
  availableFrom: Date | null;
206
279
  availableUntil: Date | null;
207
280
  }>;
208
- listListings: () => Promise<{
281
+ list: () => Promise<{
209
282
  id: string;
210
283
  createdAt: Date;
211
284
  updatedAt: Date | null;
212
285
  itemId: string;
213
286
  currencyId: string;
214
- priceAmountMinor: number;
287
+ price: number;
215
288
  sellBackPercentage: number | null;
216
289
  stock: number | null;
217
290
  isActive: boolean;
218
291
  availableFrom: Date | null;
219
292
  availableUntil: Date | null;
220
293
  }[]>;
221
- updateListing: (listingId: string, props: UpdateShopListing) => Promise<{
294
+ update: (listingId: string, props: import("@playcademy/types").UpdateShopListing) => Promise<{
222
295
  id: string;
223
296
  createdAt: Date;
224
297
  updatedAt: Date | null;
225
298
  itemId: string;
226
299
  currencyId: string;
227
- priceAmountMinor: number;
300
+ price: number;
228
301
  sellBackPercentage: number | null;
229
302
  stock: number | null;
230
303
  isActive: boolean;
231
304
  availableFrom: Date | null;
232
305
  availableUntil: Date | null;
233
306
  }>;
234
- deleteListing: (listingId: string) => Promise<void>;
307
+ delete: (listingId: string) => Promise<void>;
235
308
  };
236
309
  };
310
+ /** Shop methods (view) */
237
311
  shop: {
238
- view: () => Promise<ShopViewResponse>;
312
+ view: () => Promise<import("..").ShopViewResponse>;
239
313
  };
314
+ /** Telemetry methods (pushMetrics) */
240
315
  telemetry: {
241
316
  pushMetrics: (metrics: Record<string, number>) => Promise<void>;
242
317
  };
243
- ping(): string;
244
- static login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
318
+ /** Auto-initializes a PlaycademyClient with context from the environment */
319
+ static init: typeof init;
320
+ /** Authenticates a user with email and password */
321
+ static login: typeof login;
245
322
  }