@playcademy/sdk 0.0.1-beta.12 → 0.0.1-beta.14
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 +111 -6
- package/dist/runtime.js +19 -0
- package/dist/types.d.ts +22 -2
- 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, InsertItem, UpdateItem } from '@playcademy/types';
|
|
3
|
-
import type { GameState, InventoryItemWithItem, ClientConfig, ClientEvents, LoginResponse, GameTokenResponse, StartSessionResponse, InventoryMutationResponse, DeveloperStatusValue } from '../types';
|
|
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';
|
|
4
4
|
export declare class PlaycademyClient {
|
|
5
5
|
private baseUrl;
|
|
6
6
|
private token?;
|
|
@@ -105,40 +105,145 @@ export declare class PlaycademyClient {
|
|
|
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";
|
|
111
112
|
imageUrl: string | null;
|
|
112
113
|
}>;
|
|
113
114
|
getItem: (itemId: string) => Promise<{
|
|
114
115
|
id: string;
|
|
115
116
|
displayName: string;
|
|
116
117
|
metadata: unknown;
|
|
118
|
+
createdAt: Date;
|
|
117
119
|
internalName: string;
|
|
118
120
|
description: string | null;
|
|
119
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
121
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
120
122
|
imageUrl: string | null;
|
|
121
123
|
}>;
|
|
122
124
|
listItems: () => Promise<{
|
|
123
125
|
id: string;
|
|
124
126
|
displayName: string;
|
|
125
127
|
metadata: unknown;
|
|
128
|
+
createdAt: Date;
|
|
126
129
|
internalName: string;
|
|
127
130
|
description: string | null;
|
|
128
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
131
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
129
132
|
imageUrl: string | null;
|
|
130
133
|
}[]>;
|
|
131
134
|
updateItem: (itemId: string, props: UpdateItem) => Promise<{
|
|
132
135
|
id: string;
|
|
133
136
|
displayName: string;
|
|
134
137
|
metadata: unknown;
|
|
138
|
+
createdAt: Date;
|
|
135
139
|
internalName: string;
|
|
136
140
|
description: string | null;
|
|
137
|
-
type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
|
|
141
|
+
type: "currency" | "badge" | "trophy" | "collectible" | "consumable" | "unlock" | "upgrade" | "other";
|
|
138
142
|
imageUrl: string | null;
|
|
139
143
|
}>;
|
|
140
144
|
deleteItem: (itemId: string) => Promise<void>;
|
|
141
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;
|
|
241
|
+
}>;
|
|
242
|
+
deleteListing: (listingId: string) => Promise<void>;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
shop: {
|
|
246
|
+
view: () => Promise<ShopViewResponse>;
|
|
142
247
|
};
|
|
143
248
|
telemetry: {
|
|
144
249
|
pushMetrics: (metrics: Record<string, number>) => Promise<void>;
|
package/dist/runtime.js
CHANGED
|
@@ -314,6 +314,25 @@ class PlaycademyClient {
|
|
|
314
314
|
listItems: () => this.request("/items", "GET"),
|
|
315
315
|
updateItem: (itemId, props) => this.request(`/items/${itemId}`, "PATCH", props),
|
|
316
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")
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
shop = {
|
|
334
|
+
view: async () => {
|
|
335
|
+
return this.request("/shop/view", "GET");
|
|
317
336
|
}
|
|
318
337
|
};
|
|
319
338
|
telemetry = {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem } from '@playcademy/types';
|
|
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;
|
|
@@ -40,4 +40,24 @@ export type StartSessionResponse = {
|
|
|
40
40
|
export type InventoryMutationResponse = {
|
|
41
41
|
newTotal: number;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export interface ShopDisplayItem extends Item {
|
|
44
|
+
listingId: string;
|
|
45
|
+
shopPrice: string;
|
|
46
|
+
currencyId: string;
|
|
47
|
+
currencySymbol?: string | null;
|
|
48
|
+
currencyImageUrl?: string | null;
|
|
49
|
+
stock?: number | null;
|
|
50
|
+
sellBackPercentage?: number | null;
|
|
51
|
+
}
|
|
52
|
+
export interface UserCurrencyInfo {
|
|
53
|
+
id: string;
|
|
54
|
+
balance: number;
|
|
55
|
+
symbol?: string | null;
|
|
56
|
+
imageUrl?: string | null;
|
|
57
|
+
isPrimary: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ShopViewResponse {
|
|
60
|
+
shopItems: ShopDisplayItem[];
|
|
61
|
+
userCurrencies: UserCurrencyInfo[];
|
|
62
|
+
}
|
|
63
|
+
export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, };
|