@playcademy/sdk 0.0.1-beta.11 → 0.0.1-beta.13
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 +7 -7
- package/dist/core/client.d.ts +121 -15
- package/dist/runtime.js +26 -12
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ async function initializeAndUseClient() {
|
|
|
64
64
|
|
|
65
65
|
// If the token has appropriate permissions, you can access all namespaces:
|
|
66
66
|
// client.dev.games.upsert(...)
|
|
67
|
-
// client.admin.
|
|
67
|
+
// client.admin.items.createItem(...)
|
|
68
68
|
// Calling a method without sufficient token permissions will result in a server error.
|
|
69
69
|
|
|
70
70
|
// Example: Listen for auth changes (e.g., if token is refreshed or cleared by logout)
|
|
@@ -93,9 +93,9 @@ async function runGame() {
|
|
|
93
93
|
const { sessionId } = await client.games.startSession()
|
|
94
94
|
console.log('Session started:', sessionId)
|
|
95
95
|
|
|
96
|
-
// 2) Fetch player's inventory/
|
|
97
|
-
const
|
|
98
|
-
console.log('Player inventory:',
|
|
96
|
+
// 2) Fetch player's inventory/items
|
|
97
|
+
const items = await client.users.inventory.get()
|
|
98
|
+
console.log('Player inventory:', items)
|
|
99
99
|
|
|
100
100
|
// 3) Save game state (uses client.gameId implicitly)
|
|
101
101
|
await client.games.saveState({
|
|
@@ -136,8 +136,8 @@ All methods returning data are strongly typed.
|
|
|
136
136
|
- `me()`: Fetch current user details.
|
|
137
137
|
- **`inventory`**:
|
|
138
138
|
- `get()`: Get player inventory.
|
|
139
|
-
- `add(
|
|
140
|
-
- `spend(
|
|
139
|
+
- `add(itemId, qty)`: Add item to player inventory.
|
|
140
|
+
- `spend(itemId, qty)`: Spend item from player inventory.
|
|
141
141
|
- **`progress`**: Manages persistent progress data for a game (e.g., levels completed, scores, collectibles).
|
|
142
142
|
- `get(gameId?)`: Get the entire progress state for a game. `gameId` is optional and defaults to the client's current game context.
|
|
143
143
|
- `update(data, gameId?)`: Update the progress state for a game. `gameId` is optional. The `data` object can be structured to hold progress for various internal nodes or aspects of the game.
|
|
@@ -157,7 +157,7 @@ All methods returning data are strongly typed.
|
|
|
157
157
|
- **`dev.games`**: Upsert, update, delete games.
|
|
158
158
|
- **`dev.keys`**: Create, list, revoke API keys for games.
|
|
159
159
|
- **`admin.games`**: Pause/resume games.
|
|
160
|
-
- **`admin.
|
|
160
|
+
- **`admin.items`**: CRUD operations for items.
|
|
161
161
|
- **`telemetry`**: Push metrics.
|
|
162
162
|
|
|
163
163
|
## Contributing
|
package/dist/core/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Method } from './request';
|
|
2
|
-
import type { Game, GameWithManifest, UpsertGameMetadataInput,
|
|
3
|
-
import type { GameState,
|
|
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 } from '../types';
|
|
4
4
|
export declare class PlaycademyClient {
|
|
5
5
|
private baseUrl;
|
|
6
6
|
private token?;
|
|
@@ -47,9 +47,9 @@ export declare class PlaycademyClient {
|
|
|
47
47
|
developerStatus: "none" | "pending" | "approved";
|
|
48
48
|
}>;
|
|
49
49
|
inventory: {
|
|
50
|
-
get: () => Promise<
|
|
51
|
-
add: (
|
|
52
|
-
spend: (
|
|
50
|
+
get: () => Promise<InventoryItemWithItem[]>;
|
|
51
|
+
add: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
52
|
+
spend: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
55
|
dev: {
|
|
@@ -100,40 +100,146 @@ export declare class PlaycademyClient {
|
|
|
100
100
|
pauseGame: (gameId: string) => Promise<void>;
|
|
101
101
|
resumeGame: (gameId: string) => Promise<void>;
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
items: {
|
|
104
|
+
createItem: (props: InsertItem) => Promise<{
|
|
105
105
|
id: string;
|
|
106
106
|
displayName: string;
|
|
107
107
|
metadata: unknown;
|
|
108
|
+
createdAt: Date;
|
|
108
109
|
internalName: string;
|
|
109
110
|
description: string | null;
|
|
110
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
111
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
112
|
+
imageUrl: string | null;
|
|
111
113
|
}>;
|
|
112
|
-
|
|
114
|
+
getItem: (itemId: string) => Promise<{
|
|
113
115
|
id: string;
|
|
114
116
|
displayName: string;
|
|
115
117
|
metadata: unknown;
|
|
118
|
+
createdAt: Date;
|
|
116
119
|
internalName: string;
|
|
117
120
|
description: string | null;
|
|
118
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
121
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
122
|
+
imageUrl: string | null;
|
|
119
123
|
}>;
|
|
120
|
-
|
|
124
|
+
listItems: () => Promise<{
|
|
121
125
|
id: string;
|
|
122
126
|
displayName: string;
|
|
123
127
|
metadata: unknown;
|
|
128
|
+
createdAt: Date;
|
|
124
129
|
internalName: string;
|
|
125
130
|
description: string | null;
|
|
126
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
131
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
132
|
+
imageUrl: string | null;
|
|
127
133
|
}[]>;
|
|
128
|
-
|
|
134
|
+
updateItem: (itemId: string, props: UpdateItem) => Promise<{
|
|
129
135
|
id: string;
|
|
130
136
|
displayName: string;
|
|
131
137
|
metadata: unknown;
|
|
138
|
+
createdAt: Date;
|
|
132
139
|
internalName: string;
|
|
133
140
|
description: string | null;
|
|
134
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
141
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
142
|
+
imageUrl: string | null;
|
|
143
|
+
}>;
|
|
144
|
+
deleteItem: (itemId: string) => Promise<void>;
|
|
145
|
+
};
|
|
146
|
+
currencies: {
|
|
147
|
+
createCurrency: (props: InsertCurrency) => Promise<{
|
|
148
|
+
symbol: string | null;
|
|
149
|
+
id: string;
|
|
150
|
+
displayName: string;
|
|
151
|
+
createdAt: Date;
|
|
152
|
+
updatedAt: Date | null;
|
|
153
|
+
internalName: string;
|
|
154
|
+
imageUrl: string | null;
|
|
155
|
+
isPrimary: boolean;
|
|
156
|
+
}>;
|
|
157
|
+
getCurrency: (currencyId: string) => Promise<{
|
|
158
|
+
symbol: string | null;
|
|
159
|
+
id: string;
|
|
160
|
+
displayName: string;
|
|
161
|
+
createdAt: Date;
|
|
162
|
+
updatedAt: Date | null;
|
|
163
|
+
internalName: string;
|
|
164
|
+
imageUrl: string | null;
|
|
165
|
+
isPrimary: boolean;
|
|
166
|
+
}>;
|
|
167
|
+
listCurrencies: () => Promise<{
|
|
168
|
+
symbol: string | null;
|
|
169
|
+
id: string;
|
|
170
|
+
displayName: string;
|
|
171
|
+
createdAt: Date;
|
|
172
|
+
updatedAt: Date | null;
|
|
173
|
+
internalName: string;
|
|
174
|
+
imageUrl: string | null;
|
|
175
|
+
isPrimary: boolean;
|
|
176
|
+
}[]>;
|
|
177
|
+
updateCurrency: (currencyId: string, props: UpdateCurrency) => Promise<{
|
|
178
|
+
symbol: string | null;
|
|
179
|
+
id: string;
|
|
180
|
+
displayName: string;
|
|
181
|
+
createdAt: Date;
|
|
182
|
+
updatedAt: Date | null;
|
|
183
|
+
internalName: string;
|
|
184
|
+
imageUrl: string | null;
|
|
185
|
+
isPrimary: boolean;
|
|
186
|
+
}>;
|
|
187
|
+
deleteCurrency: (currencyId: string) => Promise<void>;
|
|
188
|
+
};
|
|
189
|
+
shopListings: {
|
|
190
|
+
createListing: (props: InsertShopListing) => Promise<{
|
|
191
|
+
id: string;
|
|
192
|
+
createdAt: Date;
|
|
193
|
+
updatedAt: Date | null;
|
|
194
|
+
itemId: string;
|
|
195
|
+
currencyId: string;
|
|
196
|
+
priceAmount: string;
|
|
197
|
+
sellBackPercentage: number | null;
|
|
198
|
+
stock: number | null;
|
|
199
|
+
isActive: boolean;
|
|
200
|
+
availableFrom: Date | null;
|
|
201
|
+
availableUntil: Date | null;
|
|
202
|
+
}>;
|
|
203
|
+
getListing: (listingId: string) => Promise<{
|
|
204
|
+
id: string;
|
|
205
|
+
createdAt: Date;
|
|
206
|
+
updatedAt: Date | null;
|
|
207
|
+
itemId: string;
|
|
208
|
+
currencyId: string;
|
|
209
|
+
priceAmount: string;
|
|
210
|
+
sellBackPercentage: number | null;
|
|
211
|
+
stock: number | null;
|
|
212
|
+
isActive: boolean;
|
|
213
|
+
availableFrom: Date | null;
|
|
214
|
+
availableUntil: Date | null;
|
|
215
|
+
}>;
|
|
216
|
+
listListings: () => Promise<{
|
|
217
|
+
id: string;
|
|
218
|
+
createdAt: Date;
|
|
219
|
+
updatedAt: Date | null;
|
|
220
|
+
itemId: string;
|
|
221
|
+
currencyId: string;
|
|
222
|
+
priceAmount: string;
|
|
223
|
+
sellBackPercentage: number | null;
|
|
224
|
+
stock: number | null;
|
|
225
|
+
isActive: boolean;
|
|
226
|
+
availableFrom: Date | null;
|
|
227
|
+
availableUntil: Date | null;
|
|
228
|
+
}[]>;
|
|
229
|
+
updateListing: (listingId: string, props: UpdateShopListing) => Promise<{
|
|
230
|
+
id: string;
|
|
231
|
+
createdAt: Date;
|
|
232
|
+
updatedAt: Date | null;
|
|
233
|
+
itemId: string;
|
|
234
|
+
currencyId: string;
|
|
235
|
+
priceAmount: string;
|
|
236
|
+
sellBackPercentage: number | null;
|
|
237
|
+
stock: number | null;
|
|
238
|
+
isActive: boolean;
|
|
239
|
+
availableFrom: Date | null;
|
|
240
|
+
availableUntil: Date | null;
|
|
135
241
|
}>;
|
|
136
|
-
|
|
242
|
+
deleteListing: (listingId: string) => Promise<void>;
|
|
137
243
|
};
|
|
138
244
|
};
|
|
139
245
|
telemetry: {
|
package/dist/runtime.js
CHANGED
|
@@ -256,19 +256,19 @@ class PlaycademyClient {
|
|
|
256
256
|
},
|
|
257
257
|
inventory: {
|
|
258
258
|
get: async () => this.request(`/inventory`, "GET"),
|
|
259
|
-
add: async (
|
|
260
|
-
const res = await this.request(`/inventory/add`, "POST", {
|
|
259
|
+
add: async (itemId, qty) => {
|
|
260
|
+
const res = await this.request(`/inventory/add`, "POST", { itemId, qty });
|
|
261
261
|
this.emit("inventoryChange", {
|
|
262
|
-
|
|
262
|
+
itemId,
|
|
263
263
|
delta: qty,
|
|
264
264
|
newTotal: res.newTotal
|
|
265
265
|
});
|
|
266
266
|
return res;
|
|
267
267
|
},
|
|
268
|
-
spend: async (
|
|
269
|
-
const res = await this.request(`/inventory/spend`, "POST", {
|
|
268
|
+
spend: async (itemId, qty) => {
|
|
269
|
+
const res = await this.request(`/inventory/spend`, "POST", { itemId, qty });
|
|
270
270
|
this.emit("inventoryChange", {
|
|
271
|
-
|
|
271
|
+
itemId,
|
|
272
272
|
delta: -qty,
|
|
273
273
|
newTotal: res.newTotal
|
|
274
274
|
});
|
|
@@ -308,12 +308,26 @@ class PlaycademyClient {
|
|
|
308
308
|
pauseGame: (gameId) => this.request(`/admin/games/${gameId}/pause`, "POST"),
|
|
309
309
|
resumeGame: (gameId) => this.request(`/admin/games/${gameId}/resume`, "POST")
|
|
310
310
|
},
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
311
|
+
items: {
|
|
312
|
+
createItem: (props) => this.request("/items", "POST", props),
|
|
313
|
+
getItem: (itemId) => this.request(`/items/${itemId}`, "GET"),
|
|
314
|
+
listItems: () => this.request("/items", "GET"),
|
|
315
|
+
updateItem: (itemId, props) => this.request(`/items/${itemId}`, "PATCH", props),
|
|
316
|
+
deleteItem: (itemId) => this.request(`/items/${itemId}`, "DELETE")
|
|
317
|
+
},
|
|
318
|
+
currencies: {
|
|
319
|
+
createCurrency: (props) => this.request("/currencies", "POST", props),
|
|
320
|
+
getCurrency: (currencyId) => this.request(`/currencies/${currencyId}`, "GET"),
|
|
321
|
+
listCurrencies: () => this.request("/currencies", "GET"),
|
|
322
|
+
updateCurrency: (currencyId, props) => this.request(`/currencies/${currencyId}`, "PATCH", props),
|
|
323
|
+
deleteCurrency: (currencyId) => this.request(`/currencies/${currencyId}`, "DELETE")
|
|
324
|
+
},
|
|
325
|
+
shopListings: {
|
|
326
|
+
createListing: (props) => this.request("/shop-listings", "POST", props),
|
|
327
|
+
getListing: (listingId) => this.request(`/shop-listings/${listingId}`, "GET"),
|
|
328
|
+
listListings: () => this.request("/shop-listings", "GET"),
|
|
329
|
+
updateListing: (listingId, props) => this.request(`/shop-listings/${listingId}`, "PATCH", props),
|
|
330
|
+
deleteListing: (listingId) => this.request(`/shop-listings/${listingId}`, "DELETE")
|
|
317
331
|
}
|
|
318
332
|
};
|
|
319
333
|
telemetry = {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { User,
|
|
1
|
+
import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing } from '@playcademy/types';
|
|
2
2
|
export interface ClientConfig {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
token?: string;
|
|
@@ -9,7 +9,7 @@ export interface ClientEvents {
|
|
|
9
9
|
token: string | null;
|
|
10
10
|
};
|
|
11
11
|
inventoryChange: {
|
|
12
|
-
|
|
12
|
+
itemId: string;
|
|
13
13
|
delta: number;
|
|
14
14
|
newTotal: number;
|
|
15
15
|
};
|
|
@@ -40,4 +40,4 @@ export type StartSessionResponse = {
|
|
|
40
40
|
export type InventoryMutationResponse = {
|
|
41
41
|
newTotal: number;
|
|
42
42
|
};
|
|
43
|
-
export type { User,
|
|
43
|
+
export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, };
|