@playcademy/sdk 0.0.1-beta.3 → 0.0.1-beta.30
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 +503 -124
- package/dist/core/client.d.ts +352 -54
- package/dist/core/namespaces/admin.d.ts +385 -0
- package/dist/core/namespaces/auth.d.ts +23 -0
- package/dist/core/namespaces/character.d.ts +146 -0
- package/dist/core/namespaces/credits.d.ts +51 -0
- package/dist/core/namespaces/dev.d.ts +323 -0
- package/dist/core/namespaces/games.d.ts +149 -0
- package/dist/core/namespaces/index.d.ts +16 -0
- package/dist/core/namespaces/leaderboard.d.ts +48 -0
- package/dist/core/namespaces/levels.d.ts +93 -0
- package/dist/core/namespaces/maps.d.ts +93 -0
- package/dist/core/namespaces/realtime.client.d.ts +129 -0
- package/dist/core/namespaces/realtime.d.ts +84 -0
- package/dist/core/namespaces/runtime.d.ts +222 -0
- package/dist/core/namespaces/scores.d.ts +55 -0
- package/dist/core/namespaces/shop.d.ts +25 -0
- package/dist/core/namespaces/sprites.d.ts +32 -0
- package/dist/core/namespaces/telemetry.d.ts +28 -0
- package/dist/core/namespaces/users.d.ts +183 -0
- package/dist/core/request.d.ts +1 -1
- package/dist/core/static/index.d.ts +2 -0
- package/dist/core/static/init.d.ts +21 -0
- package/dist/core/static/login.d.ts +24 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1924 -0
- package/dist/messaging.d.ts +522 -0
- package/dist/types.d.ts +15 -8
- package/dist/types.js +589 -0
- package/package.json +18 -10
- package/dist/bus.d.ts +0 -37
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -7427
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { InventoryItemWithItem } from '@playcademy/data/types';
|
|
2
|
+
import type { InventoryMutationResponse, PlaycademyClient } from '../../types';
|
|
3
|
+
export interface UserScore {
|
|
4
|
+
id: string;
|
|
5
|
+
score: number;
|
|
6
|
+
achievedAt: Date;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
gameId: string;
|
|
9
|
+
gameTitle: string;
|
|
10
|
+
gameSlug: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates the users namespace for the PlaycademyClient.
|
|
14
|
+
* Provides methods for managing user data and inventory operations.
|
|
15
|
+
*
|
|
16
|
+
* @param client - The PlaycademyClient instance
|
|
17
|
+
* @returns Users namespace with user profile and inventory methods
|
|
18
|
+
*/
|
|
19
|
+
export declare function createUsersNamespace(client: PlaycademyClient): {
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the current user's profile information.
|
|
22
|
+
*
|
|
23
|
+
* @returns Promise resolving to user profile data
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const user = await client.users.me()
|
|
28
|
+
* console.log('Username:', user.username)
|
|
29
|
+
* console.log('Email:', user.email)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
me: () => Promise<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
username: string | null;
|
|
36
|
+
email: string;
|
|
37
|
+
emailVerified: boolean;
|
|
38
|
+
image: string | null;
|
|
39
|
+
role: "admin" | "player" | "developer";
|
|
40
|
+
developerStatus: "none" | "pending" | "approved";
|
|
41
|
+
characterCreated: boolean;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Inventory management methods for the current user.
|
|
47
|
+
*/
|
|
48
|
+
inventory: {
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves the user's complete inventory.
|
|
51
|
+
*
|
|
52
|
+
* @returns Promise resolving to array of inventory items with item details
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const inventory = await client.users.inventory.get()
|
|
57
|
+
* inventory.forEach(item => {
|
|
58
|
+
* console.log(`${item.item.name}: ${item.quantity}`)
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
get: () => Promise<InventoryItemWithItem[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Adds items to the user's inventory.
|
|
65
|
+
* Accepts either an item UUID or slug.
|
|
66
|
+
* Emits an 'inventoryChange' event when successful.
|
|
67
|
+
*
|
|
68
|
+
* @param identifier - The item UUID or slug
|
|
69
|
+
* @param qty - The quantity to add (must be positive)
|
|
70
|
+
* @returns Promise resolving to mutation response with new total
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Using slug
|
|
75
|
+
* const result = await client.users.inventory.add('gold-coin', 100)
|
|
76
|
+
*
|
|
77
|
+
* // Using UUID
|
|
78
|
+
* const result = await client.users.inventory.add('550e8400-e29b-41d4-a716-446655440000', 100)
|
|
79
|
+
*
|
|
80
|
+
* console.log('New total:', result.newTotal)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
add: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Removes items from the user's inventory.
|
|
86
|
+
* Accepts either an item UUID or slug.
|
|
87
|
+
* Emits an 'inventoryChange' event when successful.
|
|
88
|
+
*
|
|
89
|
+
* @param identifier - The item UUID or slug
|
|
90
|
+
* @param qty - The quantity to remove (must be positive)
|
|
91
|
+
* @returns Promise resolving to mutation response with new total
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Using slug
|
|
96
|
+
* const result = await client.users.inventory.remove('HEALTH_POTION', 1)
|
|
97
|
+
*
|
|
98
|
+
* // Using UUID
|
|
99
|
+
* const result = await client.users.inventory.remove('uuid-456-789', 1)
|
|
100
|
+
*
|
|
101
|
+
* console.log('Remaining:', result.newTotal)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
remove: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the current quantity of an item.
|
|
107
|
+
* Accepts either an item UUID or slug.
|
|
108
|
+
*
|
|
109
|
+
* @param identifier - The item UUID or slug
|
|
110
|
+
* @returns Promise resolving to the current quantity (0 if not owned)
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const qty = await client.users.inventory.quantity('health-potion')
|
|
115
|
+
* const qty2 = await client.users.inventory.quantity('uuid-123-456')
|
|
116
|
+
* console.log('Health potions:', qty)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
quantity: (identifier: string) => Promise<number>;
|
|
120
|
+
/**
|
|
121
|
+
* Checks if the user has at least the specified quantity of an item.
|
|
122
|
+
* Accepts either an item UUID or slug.
|
|
123
|
+
*
|
|
124
|
+
* @param identifier - The item UUID or slug
|
|
125
|
+
* @param minQuantity - Minimum quantity required (defaults to 1)
|
|
126
|
+
* @returns Promise resolving to true if user has enough of the item
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const hasKey = await client.users.inventory.has('gold-coin')
|
|
131
|
+
* const hasEnoughGold = await client.users.inventory.has('gold-coin', 100)
|
|
132
|
+
* const hasPotion = await client.users.inventory.has('uuid-123-456', 5)
|
|
133
|
+
*
|
|
134
|
+
* if (hasKey && hasEnoughGold) {
|
|
135
|
+
* console.log('Can enter premium dungeon!')
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
has: (identifier: string, minQuantity?: number) => Promise<boolean>;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* User scores management methods.
|
|
143
|
+
*/
|
|
144
|
+
scores: {
|
|
145
|
+
/**
|
|
146
|
+
* Gets scores for a user across all games.
|
|
147
|
+
*
|
|
148
|
+
* @param userIdOrOptions - User ID or options object. If omitted, gets scores for the current user.
|
|
149
|
+
* @param options - Optional filtering options
|
|
150
|
+
* @param options.limit - Maximum number of scores to return
|
|
151
|
+
* @param options.gameId - Filter scores by specific game
|
|
152
|
+
* @returns Promise resolving to array of user scores
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Get all scores for current user
|
|
157
|
+
* const myScores = await client.users.scores.get()
|
|
158
|
+
*
|
|
159
|
+
* // Get scores for current user with options
|
|
160
|
+
* const myGameScores = await client.users.scores.get({
|
|
161
|
+
* gameId: 'game-456',
|
|
162
|
+
* limit: 20
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* // Get scores for a specific user
|
|
166
|
+
* const userScores = await client.users.scores.get('user-123')
|
|
167
|
+
*
|
|
168
|
+
* // Get scores for a specific user with options
|
|
169
|
+
* const userGameScores = await client.users.scores.get('user-123', {
|
|
170
|
+
* gameId: 'game-789',
|
|
171
|
+
* limit: 10
|
|
172
|
+
* })
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
get: (userIdOrOptions?: string | {
|
|
176
|
+
limit?: number;
|
|
177
|
+
gameId?: string;
|
|
178
|
+
}, options?: {
|
|
179
|
+
limit?: number;
|
|
180
|
+
gameId?: string;
|
|
181
|
+
}) => Promise<UserScore[]>;
|
|
182
|
+
};
|
|
183
|
+
};
|
package/dist/core/request.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PlaycademyClient } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
4
|
+
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
5
|
+
*
|
|
6
|
+
* This is the recommended way to initialize the SDK as it automatically:
|
|
7
|
+
* - Detects the runtime environment (iframe vs standalone)
|
|
8
|
+
* - Configures the client with the appropriate context
|
|
9
|
+
* - Sets up event listeners for token refresh
|
|
10
|
+
* - Exposes the client for debugging in development mode
|
|
11
|
+
*
|
|
12
|
+
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
13
|
+
* @throws Error if not running in a browser context
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const client = await PlaycademyClient.init()
|
|
18
|
+
* const user = await client.users.me()
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function init(): Promise<PlaycademyClient>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoginResponse } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Authenticates a user with email and password.
|
|
4
|
+
*
|
|
5
|
+
* This is a standalone authentication method that doesn't require an initialized client.
|
|
6
|
+
* Use this for login flows before creating a client instance.
|
|
7
|
+
*
|
|
8
|
+
* @param baseUrl - The base URL of the Playcademy API
|
|
9
|
+
* @param email - User's email address
|
|
10
|
+
* @param password - User's password
|
|
11
|
+
* @returns Promise resolving to authentication response with token
|
|
12
|
+
* @throws PlaycademyError if authentication fails or network error occurs
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* try {
|
|
17
|
+
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
18
|
+
* const client = new PlaycademyClient({ token: response.token })
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* console.error('Login failed:', error.message)
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Playcademy SDK - Main Entry Point
|
|
3
|
+
*
|
|
4
|
+
* This file serves as the primary entry point for the Playcademy SDK,
|
|
5
|
+
* providing access to the main client class and supporting utilities.
|
|
6
|
+
*/
|
|
7
|
+
export { PlaycademyClient } from './core/client';
|
|
8
|
+
export { messaging, MessageEvents } from './messaging';
|